You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/reference-manual/native-image/guides/debug-native-executables-with-gdb.md
+53-6Lines changed: 53 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,17 +30,64 @@ This will enable source-level debugging, and the debugger (GDB) then correlates
30
30
- Linux AMD64
31
31
- GDB 10.1 or higher
32
32
33
-
Follow the steps to test debugging a native executable with GDB. The below workflow is know to work on Linux OS with GDB 10.1.
34
-
35
-
1. Save the following code to the file named _GDBDemo.java_.
33
+
Follow the steps to test debugging a native executable with GDB. The below workflow is known to work on Linux with GDB 10.1.
34
+
35
+
1. Save the following code to the file named _GDBDemo.java_.
36
+
37
+
```java
38
+
publicclassGDBDemo {
39
+
staticlong fieldUsed =1000;
40
+
41
+
publicstaticvoidmain(String[] args) {
42
+
if (args.length >0) {
43
+
int n =-1;
44
+
try {
45
+
n =Integer.parseInt(args[0]);
46
+
} catch (NumberFormatException ex) {
47
+
System.out.println(args[0] +" is not a number!");
48
+
}
49
+
if (n <0) {
50
+
System.out.println(args[0] +" is negative.");
51
+
}
52
+
double f = factorial(n);
53
+
System.out.println(n +"! = "+ f);
54
+
}
55
+
56
+
if (false)
57
+
neverCalledMethod();
58
+
59
+
StringBuilder text =newStringBuilder();
60
+
text.append("Hello World from GraalVM Native Image and GDB in Java.\n");
61
+
System.out.println(text.toString());
62
+
}
63
+
64
+
staticvoidneverCalledMethod() {
65
+
System.out.println("This method is unreachable and will not be included in the native executable.");
66
+
}
67
+
68
+
staticdoublefactorial(intn) {
69
+
if (n ==0) {
70
+
return1;
71
+
}
72
+
if (n >= fieldUsed) {
73
+
returnDouble.POSITIVE_INFINITY;
74
+
}
75
+
double f =1;
76
+
while (n >1) {
77
+
f *= n--;
78
+
}
79
+
return f;
80
+
}
81
+
}
82
+
```
36
83
37
84
2.Compile it and generate a native executable with debug information:
38
85
39
86
```shell
40
-
$JAVA_HOME/bin/javac JFRDemo.java
87
+
$JAVA_HOME/bin/javac GDBDemo.java
41
88
```
42
89
```shell
43
-
native-image -g -O0 JFRDemo
90
+
native-image -g -O0GDBDemo
44
91
```
45
92
The `-g` option instructs `native-image` to generate debug information. The resulting native executable will contain debug records in a format GDB understands.
46
93
@@ -49,7 +96,7 @@ Follow the steps to test debugging a native executable with GDB. The below workf
49
96
3.Launch the debugger and run your native executable:
0 commit comments