Skip to content

Commit c6040bd

Browse files
Update documentation
1 parent 35b89b2 commit c6040bd

File tree

1 file changed

+49
-45
lines changed

1 file changed

+49
-45
lines changed

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

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -562,25 +562,26 @@ 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 `svmhelpers.py`
565+
### Debugging with _gdb-debughelpers.py_
566566

567-
To provide a reasonably good experience for debugging native images [GDBs Python API](https://sourceware.org/gdb/current/onlinedocs/gdb/Python.html) is used.
568-
This requires GDB with python support, the debugging extension is tested against GDB 13.2 and supports the new debuginfo generation introduced in GraalVM for JDK 17 and GraalVM for JDK 20.
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.
569570

570-
##### ⚠️ The `svmhelpers.py` file does not work with older versions than GDB 13.2 and GraalVM for JDK17/GraalVM for JDK 20.
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.
571572
572-
The python script `svmhelpers.py` can be found in `<GRAALVM_HOME>/lib/svm/debug`.
573-
If debug info generation is enabled, the script is copied to the build directory.
574-
The native image generator adds the debugging section `.debug_gdb_scripts` to the debug info file, which causes GDB to automatically load `svmhelpers.py` from the current working directory.
573+
The Python script _gdb-debughelpers.py_ can be found in _&lt;GRAALVM\_HOME&gt;/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.
575576

576577
For [security reasons](https://sourceware.org/gdb/current/onlinedocs/gdb/Auto_002dloading-safe-path.html)
577-
the first time GDB encounters an image that requests a specific python file to be loaded it will complain:
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:
578579

579580
> Reading symbols from svmbuild/images/<imagename>...
580-
> warning: File "<CWD>/svmhelpers.py" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
581+
> warning: File "<CWD>/gdb-debughelpers.py" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
581582
>
582583
> To enable execution of this file add
583-
>         add-auto-load-safe-path <CWD>/svmhelpers.py
584+
>         add-auto-load-safe-path <CWD>/gdb-debughelpers.py
584585
> line to your configuration file "<HOME>/.gdbinit".
585586
> To completely disable this security protection add
586587
>         add-auto-load-safe-path /
@@ -589,54 +590,54 @@ the first time GDB encounters an image that requests a specific python file to b
589590
> "Auto-loading safe path" section in the GDB manual. E.g., run from the shell:
590591
>         info "(gdb)Auto-loading safe path"
591592
592-
To solve this, either add the current working directory to `~\.gdbinit`,
593+
To solve this, either add the current working directory to _~/.gdbinit_ as follows:
593594

594-
echo "add-auto-load-safe-path <CWD>" >> ~/.gdbinit
595+
echo "add-auto-load-safe-path <CWD>/gdb-debughelpers.py" >> ~/.gdbinit
595596

596-
or, for a more permanent solution add
597+
or pass the path as a command line argument to `gdb`:
597598

598-
echo "add-auto-load-safe-path ./svmhelpers.py" >> ~/.gdbinit
599+
gdb -iex "set auto-load safe-path <CWD>/gdb-debughelpers.py" <imagename>
599600

600-
which allows GDB to auto-load `svmhelpers.py` from the current working directory in all debugging sessions.
601+
Both enable GDB to auto-load _gdb-debughelpers.py_ from the current working directory.
601602

602603
Auto-loading is the recommended way to provide the script to GDB.
603604
However, it is possible to manually load the script from GDB explicitly with:
604605

605-
(gdb) source svmhelpers.py
606+
(gdb) source gdb-debughelpers.py
606607

607608

608609
#### SVM Pretty Printing Support
609610

610-
The loading of `svmhelpers.py` registers a new pretty printer to GDB, which adds an extra level of convenience for debugging native images.
611-
This pretty printer handles the printing of Java Objects, Arrays, Strings and Enums for debugging native images.
612-
If the Java application uses `@CStruct` and `@CPointer` annotations for accessing C data structures, the pretty printer will also try to print them as if they were Java data structures.
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.
613614
If the C data structures cannot be printed by the SVM pretty printer, printing is done by GDB.
614615

615616
The pretty printer also supports printing of the primitive value instead of a Java Object for boxed primitives.
616617

617618
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.
618619
This also applies for auto-completion when using the `p` alias.
619-
This means that if the static type is different to the runtime type, the `print` command uses the static types, which leaves finding out the runtime types and type casting to the user.
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.
620621
Additionally, the `p` alias understands Java field and array access and function calls for Java Objects.
621622

622623
##### Limitations
623624

624625
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.
625-
This would cause printing non-Java Objects to not work properly.
626-
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 GDBs 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.
627628

628629

629-
#### Options for controlling the behavior of the SVM Pretty Printer
630+
#### Options to Control the Behavior of the SVM Pretty Printer
630631

631-
In addition to the enhanced `p` alias, `svmhelpers.py` introduces some GDB parameters to customize the behavior of the SVM Pretty Printer.
632-
Parameters in GDB can be interacted with `set <param> <value>` and `show <param>` and therefore, integrates into GDBs customization options.
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.
633634

634635
* ##### svm-print on/off
635636

636637
Use this command to enable/disable the SVM Pretty Printer.
637638
This also resets the `print` command alias `p` to its default behavior.
638639
Alternatively SVM pretty printing can be suppressed with the
639-
[raw printing option of GDBs print command](https://sourceware.org/gdb/current/onlinedocs/gdb/Output-Formats.html):
640+
[`raw` printing option of GDB's `print` command](https://sourceware.org/gdb/current/onlinedocs/gdb/Output-Formats.html):
640641

641642
(gdb) show svm-print
642643
The current value of 'svm-print' is "on".
@@ -653,42 +654,45 @@ Alternatively SVM pretty printing can be suppressed with the
653654

654655
* ##### svm-print-string-limit &lt;int&gt;
655656

656-
Allows to customize the maximum length for pretty printing Java Strings.
657-
The default value is `200`, set to `-1` or `unlimited` for unlimited printing of Java Strings.
658-
This does not change the limit for c strings, which can be controlled with GDBs `set print characters`.
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.
659661

660662
* ##### svm-print-element-limit &lt;int&gt;
661663

662-
Allows to customize the maximum number of elements for pretty printing Java Arrays, ArrayLists and HashMaps.
663-
The default value is `10`, set to `-1` or `unlimited` for printing unlimited number of elements.
664-
This does not change the limit for c arrays, which can be controlled with GDBs `set print elements`.
665-
However, GDBs parameter `print elements` is the upper bound for `svm-print-element-limit`.
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`.
666669

667670
* ##### svm-print-field-limit &lt;int&gt;
668671

669-
Allows to customize the maximum number of elements for pretty printing fields of Java Objects.
670-
The default value is `50`, set to `-1` or `unlimited` for printing unlimited number of fields.
671-
GDBs parameter `print elements` is the upper bound for `svm-print-field-limit`.
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`.
672676

673677
* ##### svm-print-depth-limit &lt;int&gt;
674678

675-
Allows to customize the maximum depth of recursive svm pretty printing.
679+
Customizes the maximum depth of recursive svm pretty printing.
676680
The default value is `1`.
677681
The children of direct children are printed (a sane default to make contents of boxed values visible).
678-
Set to `-1` or `unlimited` for printing unlimited depth.
679-
GDBs parameter `print max-depth` is the upper bound for `svm-print-depth-limit`.
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`.
680684

681685
* ##### svm-use-hlrep on/off
682686

683687
Use this command to enable/disable pretty printing for higher level representations.
684-
It provides a more data oriented view on some Java data structures with a known internal structure such as Lists or Maps.
688+
It provides a more data-oriented view on some Java data structures with a known internal structure such as Lists or Maps.
685689
Currently supports ArrayList and HashMap.
686690

687691
* ##### svm-infer-generics &lt;int&gt;
688692

689-
Allows to customize the amount of elements taken into account for inferring the generic type of higher level representations.
693+
Customizes the number of elements taken into account to infer the generic type of higher level representations.
690694
The default value is `10`.
691-
Set to `0` for not inferring generic types and `-1` or `unlimited` for inferring the generic type over all elements.
695+
Set to `0` to not infer generic types and `-1` or `unlimited` to infer the generic type with all elements.
692696

693697
* ##### svm-print-address absolute/on/off
694698

@@ -699,16 +703,16 @@ Printing addresses is disabled by default.
699703
* ##### svm-print-static-fields on/off
700704

701705
Per default static field members are not shown during pretty printing of Java objects.
702-
This command allows to customize this behavior.
706+
This command customizes this behavior.
703707

704708
* ##### svm-complete-static-variables on/off
705709

706710
Per default auto-completion for static fields is enabled for the enhanced `p` alias.
707-
This command allows to enable/disable completion for static field members.
711+
This command enables/disables completion for static field members.
708712

709713
* ##### svm-selfref-check on/off
710714

711-
To avoid endless recursion in pretty printing self-referential data structures `svmhelpers.py` detects such cases and prevents further expansion.
715+
To avoid endless recursion in pretty printing a self-referential data structure _gdb-debughelpers.py_ detects such cases and prevents further expansion.
712716
For testing, this feature can be temporary disabled (usually you wouldn't want to do this).
713717

714718
### Related Documentation

0 commit comments

Comments
 (0)