Skip to content

Commit 9b4400c

Browse files
Move documentation to a separate file
1 parent c6040bd commit 9b4400c

File tree

3 files changed

+169
-154
lines changed

3 files changed

+169
-154
lines changed

docs/reference-manual/native-image/guides/debug-native-executables-with-gdb.md

Lines changed: 2 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -562,159 +562,7 @@ void svm_dbg_print_fatalErrorDiagnostics(graal_isolatethread_t* thread, size_t s
562562
void svm_dbg_print_locationInfo(graal_isolatethread_t* thread, size_t mem);
563563
```
564564

565-
### Debugging with _gdb-debughelpers.py_
566-
567-
The [GDB Python API](https://sourceware.org/gdb/current/onlinedocs/gdb/Python.html) is used to provide a reasonably good experience for debugging native executables or shared libraries.
568-
It requires GDB with Python support.
569-
The debugging extension is tested against GDB 13.2 and supports the new debuginfo generation introduced in GraalVM for JDK 17 and later.
570-
571-
> Note: The _gdb-debughelpers.py_ file does not work with versions older than version 13.2 of `gdb` or versions older than GraalVM for JDK17/GraalVM for JDK 20.
572-
573-
The Python script _gdb-debughelpers.py_ can be found in _<GRAALVM\_HOME>/lib/svm/debug_ directory.
574-
If debuginfo generation is enabled (see [Build a Native Executable with Debug Information](#build-a-native-executable-with-debug-information)), the script is copied to the build directory.
575-
The `native-image` tool adds the debugging section `.debug_gdb_scripts` to the debug info file, which causes GDB to automatically load _gdb-debughelpers.py_ from the current working directory.
576-
577-
For [security reasons](https://sourceware.org/gdb/current/onlinedocs/gdb/Auto_002dloading-safe-path.html)
578-
the first time GDB encounters a native executable or shared library that requests a specific Python file to be loaded it will print a warning:
579-
580-
> Reading symbols from svmbuild/images/<imagename>...
581-
> warning: File "<CWD>/gdb-debughelpers.py" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
582-
>
583-
> To enable execution of this file add
584-
>         add-auto-load-safe-path <CWD>/gdb-debughelpers.py
585-
> line to your configuration file "<HOME>/.gdbinit".
586-
> To completely disable this security protection add
587-
>         add-auto-load-safe-path /
588-
> line to your configuration file "<HOME>/.gdbinit".
589-
> For more information about this security protection see the
590-
> "Auto-loading safe path" section in the GDB manual. E.g., run from the shell:
591-
>         info "(gdb)Auto-loading safe path"
592-
593-
To solve this, either add the current working directory to _~/.gdbinit_ as follows:
594-
595-
echo "add-auto-load-safe-path <CWD>/gdb-debughelpers.py" >> ~/.gdbinit
596-
597-
or pass the path as a command line argument to `gdb`:
598-
599-
gdb -iex "set auto-load safe-path <CWD>/gdb-debughelpers.py" <imagename>
600-
601-
Both enable GDB to auto-load _gdb-debughelpers.py_ from the current working directory.
602-
603-
Auto-loading is the recommended way to provide the script to GDB.
604-
However, it is possible to manually load the script from GDB explicitly with:
605-
606-
(gdb) source gdb-debughelpers.py
607-
608-
609-
#### SVM Pretty Printing Support
610-
611-
Loading _gdb-debughelpers.py_ registers a new pretty printer to GDB, which adds an extra level of convenience for debugging native executables or shared libraries.
612-
This pretty printer handles the printing of Java Objects, Arrays, Strings, and Enums for debugging native executables or shared libraries.
613-
If the Java application uses `@CStruct` and `@CPointer` annotations to access C data structures, the pretty printer will also try to print them as if they were Java data structures.
614-
If the C data structures cannot be printed by the SVM pretty printer, printing is done by GDB.
615-
616-
The pretty printer also supports printing of the primitive value instead of a Java Object for boxed primitives.
617-
618-
Whenever printing is done via the `p` alias of the `print` command the pretty printer intercepts that call to perform type casts to the respective runtime types of Java Objects.
619-
This also applies for auto-completion when using the `p` alias.
620-
This means that if the static type is different to the runtime type, the `print` command uses the static type, which leaves the user to discover the runtime type and typecast it.
621-
Additionally, the `p` alias understands Java field and array access and function calls for Java Objects.
622-
623-
##### Limitations
624-
625-
The `print` command still uses its default implementation, as there is no way to overwrite it, while still keeping the capability of the default `print` command.
626-
Overriding would cause printing non-Java Objects to not work properly.
627-
Therefore, only the `p` alias for the `print` command is overwritten by the SVM pretty printer, such that the user can still make use of the default GDB `print` command.
628-
629-
630-
#### Options to Control the Behavior of the SVM Pretty Printer
631-
632-
In addition to the enhanced `p` alias, _gdb-debughelpers.py_ introduces some GDB parameters to customize the behavior of the SVM Pretty Printer.
633-
Parameters in GDB can be controlled with `set <param> <value>` and `show <param>` commands, and thus integrate with GDB's customization options.
634-
635-
* ##### svm-print on/off
636-
637-
Use this command to enable/disable the SVM Pretty Printer.
638-
This also resets the `print` command alias `p` to its default behavior.
639-
Alternatively SVM pretty printing can be suppressed with the
640-
[`raw` printing option of GDB's `print` command](https://sourceware.org/gdb/current/onlinedocs/gdb/Output-Formats.html):
641-
642-
(gdb) show svm-print
643-
The current value of 'svm-print' is "on".
644-
(gdb) print str
645-
$1 = "string"
646-
(gdb) print/r str
647-
$2 = (java.lang.String *) 0x7ffff689d2d0
648-
(gdb) set svm-print off
649-
1 printer disabled
650-
1 of 2 printers enabled
651-
652-
(gdb) print str
653-
$3 = (java.lang.String *) 0x7ffff689d2d0
654-
655-
* ##### svm-print-string-limit &lt;int&gt;
656-
657-
Customizes the maximum length for pretty printing a Java String.
658-
The default value is `200`.
659-
Set to `-1` or `unlimited` for unlimited printing of a Java String.
660-
This does not change the limit for a C String, which can be controlled with GDB's `set print characters` command.
661-
662-
* ##### svm-print-element-limit &lt;int&gt;
663-
664-
Customizes the maximum number of elements for pretty printing a Java Array, ArrayList, and HashMap.
665-
The default value is `10`.
666-
Set to `-1` or `unlimited` to print an unlimited number of elements.
667-
This does not change the limit for a C array, which can be controlled with GDB's `set print elements` command.
668-
However, GDB's parameter `print elements` is the upper bound for `svm-print-element-limit`.
669-
670-
* ##### svm-print-field-limit &lt;int&gt;
671-
672-
Customizes the maximum number of elements for pretty printing fields of a Java Object.
673-
The default value is `50`.
674-
Set to `-1` or `unlimited` to print an unlimited number of fields.
675-
GDB's parameter `print elements` is the upper bound for `svm-print-field-limit`.
676-
677-
* ##### svm-print-depth-limit &lt;int&gt;
678-
679-
Customizes the maximum depth of recursive svm pretty printing.
680-
The default value is `1`.
681-
The children of direct children are printed (a sane default to make contents of boxed values visible).
682-
Set to `-1` or `unlimited` to print unlimited depth.
683-
GDB's parameter `print max-depth` is the upper bound for `svm-print-depth-limit`.
684-
685-
* ##### svm-use-hlrep on/off
686-
687-
Use this command to enable/disable pretty printing for higher level representations.
688-
It provides a more data-oriented view on some Java data structures with a known internal structure such as Lists or Maps.
689-
Currently supports ArrayList and HashMap.
690-
691-
* ##### svm-infer-generics &lt;int&gt;
692-
693-
Customizes the number of elements taken into account to infer the generic type of higher level representations.
694-
The default value is `10`.
695-
Set to `0` to not infer generic types and `-1` or `unlimited` to infer the generic type with all elements.
696-
697-
* ##### svm-print-address absolute/on/off
698-
699-
Use this command to enable/disable printing of addresses in addition to regular pretty printing.
700-
When `absolute` mode is used even compressed references are shown as absolute addresses.
701-
Printing addresses is disabled by default.
702-
703-
* ##### svm-print-static-fields on/off
704-
705-
Per default static field members are not shown during pretty printing of Java objects.
706-
This command customizes this behavior.
707-
708-
* ##### svm-complete-static-variables on/off
709-
710-
Per default auto-completion for static fields is enabled for the enhanced `p` alias.
711-
This command enables/disables completion for static field members.
712-
713-
* ##### svm-selfref-check on/off
714-
715-
To avoid endless recursion in pretty printing a self-referential data structure _gdb-debughelpers.py_ detects such cases and prevents further expansion.
716-
For testing, this feature can be temporary disabled (usually you wouldn't want to do this).
717-
718565
### Related Documentation
719566

720-
* [Debug Info Feature](../DebugInfo.md)
567+
* [Debug Info Feature](../DebugInfo.md)
568+
* [Debug Native Executables with a Python Helper Script](debug-native-executables-with-python-helper.md)
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
---
2+
layout: ni-docs
3+
toc_group: how-to-guides
4+
link_title: Debug Native Executables with a Python Helper Script
5+
permalink: /reference-manual/native-image/guides/debug-native-image-process-with-python-helper-script/
6+
---
7+
# Debug Native Executables with a Python Helper Script
8+
9+
### Debugging with _gdb-debughelpers.py_
10+
11+
The [GDB Python API](https://sourceware.org/gdb/current/onlinedocs/gdb/Python.html) is used to provide a reasonably good experience for debugging native executables or shared libraries.
12+
It requires GDB with Python support.
13+
The debugging extension is tested against GDB 13.2 and supports the new debuginfo generation introduced in GraalVM for JDK 17 and later.
14+
15+
> Note: The _gdb-debughelpers.py_ file does not work with versions older than version 13.2 of `gdb` or versions older than GraalVM for JDK17.
16+
17+
The Python script _gdb-debughelpers.py_ can be found in _&lt;GRAALVM\_HOME&gt;/lib/svm/debug_ directory.
18+
If debuginfo generation is enabled (see [Build a Native Executable with Debug Information](debug-native-executables-with-gdb.md#build-a-native-executable-with-debug-information)), the script is copied to the build directory.
19+
The `native-image` tool adds the debugging section `.debug_gdb_scripts` to the debug info file, which causes GDB to automatically load _gdb-debughelpers.py_ from the current working directory.
20+
21+
For [security reasons](https://sourceware.org/gdb/current/onlinedocs/gdb/Auto_002dloading-safe-path.html)
22+
the first time GDB encounters a native executable or shared library that requests a specific Python file to be loaded it will print a warning:
23+
24+
> Reading symbols from svmbuild/images/<imagename>...
25+
> warning: File "<CWD>/gdb-debughelpers.py" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
26+
>
27+
> To enable execution of this file add
28+
>         add-auto-load-safe-path <CWD>/gdb-debughelpers.py
29+
> line to your configuration file "<HOME>/.gdbinit".
30+
> To completely disable this security protection add
31+
>         add-auto-load-safe-path /
32+
> line to your configuration file "<HOME>/.gdbinit".
33+
> For more information about this security protection see the
34+
> "Auto-loading safe path" section in the GDB manual. E.g., run from the shell:
35+
>         info "(gdb)Auto-loading safe path"
36+
37+
To solve this, either add the current working directory to _~/.gdbinit_ as follows:
38+
39+
echo "add-auto-load-safe-path <CWD>/gdb-debughelpers.py" >> ~/.gdbinit
40+
41+
or pass the path as a command line argument to `gdb`:
42+
43+
gdb -iex "set auto-load safe-path <CWD>/gdb-debughelpers.py" <imagename>
44+
45+
Both enable GDB to auto-load _gdb-debughelpers.py_ from the current working directory.
46+
47+
Auto-loading is the recommended way to provide the script to GDB.
48+
However, it is possible to manually load the script from GDB explicitly with:
49+
50+
(gdb) source gdb-debughelpers.py
51+
52+
53+
#### SVM Pretty Printing Support
54+
55+
Loading _gdb-debughelpers.py_ registers a new pretty printer to GDB, which adds an extra level of convenience for debugging native executables or shared libraries.
56+
This pretty printer handles the printing of Java Objects, Arrays, Strings, and Enums for debugging native executables or shared libraries.
57+
If the Java application uses `@CStruct` and `@CPointer` annotations to access C data structures, the pretty printer will also try to print them as if they were Java data structures.
58+
If the C data structures cannot be printed by the SVM pretty printer, printing is done by GDB.
59+
60+
The pretty printer also supports printing of the primitive value instead of a Java Object for boxed primitives.
61+
62+
Whenever printing is done via the `p` alias of the `print` command the pretty printer intercepts that call to perform type casts to the respective runtime types of Java Objects.
63+
This also applies for auto-completion when using the `p` alias.
64+
This means that if the static type is different to the runtime type, the `print` command uses the static type, which leaves the user to discover the runtime type and typecast it.
65+
Additionally, the `p` alias understands Java field and array access and function calls for Java Objects.
66+
67+
##### Limitations
68+
69+
The `print` command still uses its default implementation, as there is no way to overwrite it, while still keeping the capability of the default `print` command.
70+
Overriding would cause printing non-Java Objects to not work properly.
71+
Therefore, only the `p` alias for the `print` command is overwritten by the SVM pretty printer, such that the user can still make use of the default GDB `print` command.
72+
73+
74+
#### Options to Control the Behavior of the SVM Pretty Printer
75+
76+
In addition to the enhanced `p` alias, _gdb-debughelpers.py_ introduces some GDB parameters to customize the behavior of the SVM Pretty Printer.
77+
Parameters in GDB can be controlled with `set <param> <value>` and `show <param>` commands, and thus integrate with GDB's customization options.
78+
79+
* ##### svm-print on/off
80+
81+
Use this command to enable/disable the SVM Pretty Printer.
82+
This also resets the `print` command alias `p` to its default behavior.
83+
Alternatively SVM pretty printing can be suppressed with the
84+
[`raw` printing option of GDB's `print` command](https://sourceware.org/gdb/current/onlinedocs/gdb/Output-Formats.html):
85+
86+
(gdb) show svm-print
87+
The current value of 'svm-print' is "on".
88+
(gdb) print str
89+
$1 = "string"
90+
(gdb) print/r str
91+
$2 = (java.lang.String *) 0x7ffff689d2d0
92+
(gdb) set svm-print off
93+
1 printer disabled
94+
1 of 2 printers enabled
95+
96+
(gdb) print str
97+
$3 = (java.lang.String *) 0x7ffff689d2d0
98+
99+
* ##### svm-print-string-limit &lt;int&gt;
100+
101+
Customizes the maximum length for pretty printing a Java String.
102+
The default value is `200`.
103+
Set to `-1` or `unlimited` for unlimited printing of a Java String.
104+
This does not change the limit for a C String, which can be controlled with GDB's `set print characters` command.
105+
106+
* ##### svm-print-element-limit &lt;int&gt;
107+
108+
Customizes the maximum number of elements for pretty printing a Java Array, ArrayList, and HashMap.
109+
The default value is `10`.
110+
Set to `-1` or `unlimited` to print an unlimited number of elements.
111+
This does not change the limit for a C array, which can be controlled with GDB's `set print elements` command.
112+
However, GDB's parameter `print elements` is the upper bound for `svm-print-element-limit`.
113+
114+
* ##### svm-print-field-limit &lt;int&gt;
115+
116+
Customizes the maximum number of elements for pretty printing fields of a Java Object.
117+
The default value is `50`.
118+
Set to `-1` or `unlimited` to print an unlimited number of fields.
119+
GDB's parameter `print elements` is the upper bound for `svm-print-field-limit`.
120+
121+
* ##### svm-print-depth-limit &lt;int&gt;
122+
123+
Customizes the maximum depth of recursive svm pretty printing.
124+
The default value is `1`.
125+
The children of direct children are printed (a sane default to make contents of boxed values visible).
126+
Set to `-1` or `unlimited` to print unlimited depth.
127+
GDB's parameter `print max-depth` is the upper bound for `svm-print-depth-limit`.
128+
129+
* ##### svm-use-hlrep on/off
130+
131+
Use this command to enable/disable pretty printing for higher level representations.
132+
It provides a more data-oriented view on some Java data structures with a known internal structure such as Lists or Maps.
133+
Currently supports ArrayList and HashMap.
134+
135+
* ##### svm-infer-generics &lt;int&gt;
136+
137+
Customizes the number of elements taken into account to infer the generic type of higher level representations.
138+
The default value is `10`.
139+
Set to `0` to not infer generic types and `-1` or `unlimited` to infer the generic type with all elements.
140+
141+
* ##### svm-print-address absolute/on/off
142+
143+
Use this command to enable/disable printing of addresses in addition to regular pretty printing.
144+
When `absolute` mode is used even compressed references are shown as absolute addresses.
145+
Printing addresses is disabled by default.
146+
147+
* ##### svm-print-static-fields on/off
148+
149+
Per default static field members are not shown during pretty printing of Java objects.
150+
This command customizes this behavior.
151+
152+
* ##### svm-complete-static-variables on/off
153+
154+
Per default auto-completion for static fields is enabled for the enhanced `p` alias.
155+
This command enables/disables completion for static field members.
156+
157+
* ##### svm-selfref-check on/off
158+
159+
To avoid endless recursion in pretty printing a self-referential data structure _gdb-debughelpers.py_ detects such cases and prevents further expansion.
160+
For testing, this feature can be temporary disabled (usually you wouldn't want to do this).
161+
162+
163+
### Related Documentation
164+
165+
* [Debug Info Feature](../DebugInfo.md)
166+
* [Debug Native Executables with GDB](debug-native-executables-with-gdb.md)

docs/reference-manual/native-image/guides/guides.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Here you will learn how to:
2525
- [Containerize a Native Executable and Run in a Docker Container](containerise-native-executable-with-docker.md)
2626
- [Create a Heap Dump from a Native Executable](create-heap-dump-from-native-executable.md)
2727
- [Debug Native Executables with GDB](debug-native-executables-with-gdb.md)
28+
- [Debug Native Executables with a Python Helper Script](debug-native-executables-with-python-helper.md)
2829
- [Include Reachability Metadata Using the Native Image Gradle Plugin](include-reachability-metadata-gradle.md)
2930
- [Include Reachability Metadata Using the Native Image Maven Plugin](include-reachability-metadata-maven.md)
3031
- [Include Resources in a Native Executable](include-resources.md)

0 commit comments

Comments
 (0)