Skip to content

Commit 6a19e27

Browse files
committed
gnatcheck: log debug information in a file
The gnatcheck worker now saves some debug information in a log file. At this point those information are limited to the Ada stack traces generated by Libadaland during failures occuring while traversing generic instantiations.
1 parent fda5324 commit 6a19e27

File tree

8 files changed

+49
-9
lines changed

8 files changed

+49
-9
lines changed

lkql_checker/src/gnatcheck-compiler.adb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1581,7 +1581,8 @@ package body Gnatcheck.Compiler is
15811581
function Spawn_Gnatcheck_Worker
15821582
(Rule_File : String;
15831583
Msg_File : String;
1584-
Source_File : String) return Process_Id
1584+
Source_File : String;
1585+
Log_File : String) return Process_Id
15851586
is
15861587
use GNAT.String_Split;
15871588

@@ -1662,6 +1663,10 @@ package body Gnatcheck.Compiler is
16621663
Args (Num_Args) := new String'("-d");
16631664
end if;
16641665

1666+
Num_Args := @ + 1;
1667+
Args (Num_Args) :=
1668+
new String'("--log-file=" & Log_File);
1669+
16651670
if Arg.Follow_Symbolic_Links.Get then
16661671
Num_Args := @ + 1;
16671672
Args (Num_Args) := new String'("-eL");

lkql_checker/src/gnatcheck-compiler.ads

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,13 @@ package Gnatcheck.Compiler is
162162
function Spawn_Gnatcheck_Worker
163163
(Rule_File : String;
164164
Msg_File : String;
165-
Source_File : String) return Process_Id;
165+
Source_File : String;
166+
Log_File : String) return Process_Id;
166167
-- Spawn a gnatcheck worker (LKQL) on the main project file with the
167168
-- relevant options on the rules given by Rule_File, redirecting the
168169
-- output to Msg_File. Source_File is the name of a file listing all the
169-
-- source files to analyze.
170+
-- source files to analyze. Log_File is the name of a file used to store
171+
-- worker's logs.
170172

171173
function Spawn_LKQL_Rule_File_Parser
172174
(LKQL_RF_Name : String;

lkql_checker/src/gnatcheck_main.adb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,8 @@ procedure Gnatcheck_Main is
352352
Spawn_Gnatcheck_Worker
353353
(File_Name ("rules", 0),
354354
File_Name ("out", Job),
355-
File_Name ("files", Job));
355+
File_Name ("files", Job),
356+
File_Name ("log", Job));
356357

357358
if Next_SF > Last_Argument_Source then
358359
Total_Jobs := @ - Num_Jobs + Job;

lkql_jit/cli/src/main/java/com/adacore/lkql_jit/cli/GNATCheckWorker.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
import com.adacore.lkql_jit.options.LKQLOptions;
99
import com.adacore.lkql_jit.options.RuleInstance;
1010
import java.io.File;
11+
import java.io.FileNotFoundException;
12+
import java.io.FileOutputStream;
1113
import java.io.IOException;
14+
import java.io.OutputStream;
15+
import java.nio.file.FileSystems;
1216
import java.nio.file.Files;
1317
import java.nio.file.Paths;
1418
import java.util.*;
@@ -94,6 +98,11 @@ public static class Args implements Callable<Integer> {
9498
@CommandLine.Option(names = "--files-from", description = "The file containing the files")
9599
public String filesFrom = null;
96100

101+
@CommandLine.Option(
102+
names = "--log-file",
103+
description = "The file used by the worker to output logs")
104+
public String gnatcheckLogFile = null;
105+
97106
@CommandLine.Option(
98107
names = "--ignore-project-switches",
99108
description =
@@ -244,6 +253,18 @@ protected int executeScript(Context.Builder contextBuilder) {
244253
// Finally, pass the options to the LKQL engine
245254
contextBuilder.option("lkql.options", optionsBuilder.build().toJson().toString());
246255

256+
try {
257+
// Install a log handler only if gnatcheckLogFile is set
258+
if (this.args.gnatcheckLogFile != null) {
259+
var logFile = FileSystems.getDefault().getPath(this.args.gnatcheckLogFile);
260+
OutputStream outputStream = new FileOutputStream(logFile.toFile());
261+
contextBuilder.logHandler(outputStream);
262+
}
263+
} catch (FileNotFoundException e) {
264+
System.err.println(
265+
"WORKER_ERROR: Could not create log file: " + this.args.gnatcheckLogFile);
266+
}
267+
247268
// Create the context and run the script in it
248269
try (Context context = contextBuilder.build()) {
249270
final Source source = Source.newBuilder("lkql", checkerSource, "checker.lkql").build();

lkql_jit/language/src/main/java/com/adacore/lkql_jit/LKQLContext.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.adacore.lkql_jit.utils.source_location.LalLocationWrapper;
2222
import com.oracle.truffle.api.CompilerDirectives;
2323
import com.oracle.truffle.api.TruffleLanguage;
24+
import com.oracle.truffle.api.TruffleLogger;
2425
import com.oracle.truffle.api.source.Source;
2526
import java.io.File;
2627
import java.util.*;
@@ -301,6 +302,11 @@ public String getConfigFile() {
301302
return this.getOptions().configFile().orElse("");
302303
}
303304

305+
@CompilerDirectives.TruffleBoundary
306+
public TruffleLogger getLogger() {
307+
return TruffleLogger.getLogger(Constants.LKQL_ID);
308+
}
309+
304310
/** Return the list of scenario variables to specify when loading the GPR project file. */
305311
public Libadalang.ScenarioVariable[] getScenarioVars() {
306312
if (this.scenarioVars == null) {

lkql_jit/language/src/main/java/com/adacore/lkql_jit/checker/built_ins/NodeCheckerFunction.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ public Object alwaysTrue(VirtualFrame frame, Libadalang.AdaNode root) {
111111
e.getMessage(),
112112
new LalLocationWrapper(currentNode, context.linesCache),
113113
new SourceSectionWrapper(this.callNode.getSourceSection()));
114+
if (context.isCheckerDebug()) {
115+
context.getLogger().severe(e.getMessage());
116+
context.getLogger()
117+
.severe(e.adaStackTrace.orElse("ERROR: can't get Ada stack trace"));
118+
}
114119
continue;
115120
}
116121

testsuite/tests/gnatcheck/subdirs/test.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ main.adb:3:05: goto statement
99
main.adb:6:05: error: "Put_Line" is undefined
1010
main.adb:6:05: error: possible missing "with Ada.Text_IO; use Ada.Text_IO"
1111
no internal error detected
12-
Content of custom_subdirs/gnatcheck : ['main.adb.stderr', 'main.adb.stdout', 'restriction_pragmas.adc']
12+
Content of custom_subdirs/gnatcheck : ['gnatcheck-log1.TMP', 'main.adb.stderr', 'main.adb.stdout', 'restriction_pragmas.adc']
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
With target in project file
22
===========================
33

4-
<gnatcheck_worker_exe> -Pwith_target.gpr --target=x86_64-linux -d --files-from=<working-dir>/gnatcheck/gnatcheck-files1.TMP --rules-from=<working-dir>/gnatcheck/gnatcheck-rules0.TMP
4+
<gnatcheck_worker_exe> -Pwith_target.gpr --target=x86_64-linux -d --log-file=<working-dir>/gnatcheck/gnatcheck-log1.TMP --files-from=<working-dir>/gnatcheck/gnatcheck-files1.TMP --rules-from=<working-dir>/gnatcheck/gnatcheck-rules0.TMP
55
main.adb:3:04: goto statement
66

77
With target in config file
88
==========================
99

10-
<gnatcheck_worker_exe> -Pwithout_target.gpr --target=x86_64-linux -d --files-from=<working-dir>/gnatcheck/gnatcheck-files1.TMP --rules-from=<working-dir>/gnatcheck/gnatcheck-rules0.TMP
10+
<gnatcheck_worker_exe> -Pwithout_target.gpr --target=x86_64-linux -d --log-file=<working-dir>/gnatcheck/gnatcheck-log1.TMP --files-from=<working-dir>/gnatcheck/gnatcheck-files1.TMP --rules-from=<working-dir>/gnatcheck/gnatcheck-rules0.TMP
1111
main.adb:3:04: goto statement
1212

1313
With target through command-line
1414
================================
1515

16-
<gnatcheck_worker_exe> -Pwithout_target.gpr --target=x86_64-linux -d --files-from=<working-dir>/gnatcheck/gnatcheck-files1.TMP --rules-from=<working-dir>/gnatcheck/gnatcheck-rules0.TMP
16+
<gnatcheck_worker_exe> -Pwithout_target.gpr --target=x86_64-linux -d --log-file=<working-dir>/gnatcheck/gnatcheck-log1.TMP --files-from=<working-dir>/gnatcheck/gnatcheck-files1.TMP --rules-from=<working-dir>/gnatcheck/gnatcheck-rules0.TMP
1717
main.adb:3:04: goto statement
1818

1919
Without any target specified
2020
============================
2121

22-
<gnatcheck_worker_exe> -Pwithout_target.gpr --target=x86_64-linux -d --files-from=<working-dir>/gnatcheck/gnatcheck-files1.TMP --rules-from=<working-dir>/gnatcheck/gnatcheck-rules0.TMP
22+
<gnatcheck_worker_exe> -Pwithout_target.gpr --target=x86_64-linux -d --log-file=<working-dir>/gnatcheck/gnatcheck-log1.TMP --files-from=<working-dir>/gnatcheck/gnatcheck-files1.TMP --rules-from=<working-dir>/gnatcheck/gnatcheck-rules0.TMP
2323
main.adb:3:04: goto statement

0 commit comments

Comments
 (0)