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
To provide a reasonably good experience for debugging native images [GDBs Python API](https://sourceware.org/gdb/current/onlinedocs/gdb/Python.html) is used.
534
+
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.
535
+
536
+
##### ⚠️ The `svmhelpers.py` file does not work with older versions than GDB 13.2 and GraalVM for JDK17/GraalVM for JDK 20.
537
+
538
+
The python script `svmhelpers.py` can be found in `<GRAALVM_HOME>/lib/svm/debug`.
539
+
If debug info generation is enabled, the script is copied to the build directory.
540
+
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.
541
+
542
+
For [security reasons](https://sourceware.org/gdb/current/onlinedocs/gdb/Auto_002dloading-safe-path.html)
543
+
the first time GDB encounters an image that requests a specific python file to be loaded it will complain:
544
+
545
+
> Reading symbols from svmbuild/images/<imagename>...
546
+
> warning: File "<CWD>/svmhelpers.py" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
547
+
>
548
+
> To enable execution of this file add
549
+
> add-auto-load-safe-path <CWD>/svmhelpers.py
550
+
> line to your configuration file "<HOME>/.gdbinit".
551
+
> To completely disable this security protection add
552
+
> add-auto-load-safe-path /
553
+
> line to your configuration file "<HOME>/.gdbinit".
554
+
> For more information about this security protection see the
555
+
> "Auto-loading safe path" section in the GDB manual. E.g., run from the shell:
556
+
> info "(gdb)Auto-loading safe path"
557
+
558
+
To solve this, either add the current working directory to `~\.gdbinit`,
which allows GDB to auto-load `svmhelpers.py` from the current working directory in all debugging sessions.
567
+
568
+
Auto-loading is the recommended way to provide the script to GDB.
569
+
However, it is possible to manually load the script from GDB explicitly with:
570
+
571
+
(gdb) source svmhelpers.py
572
+
573
+
574
+
#### SVM Pretty Printing Support
575
+
576
+
The loading of `svmhelpers.py` registers a new pretty printer to GDB, which adds an extra level of convenience for debugging native images.
577
+
This pretty printer handles the printing of Java Objects, Arrays, Strings and Enums for debugging native images.
578
+
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.
579
+
If the C data structures cannot be printed by the SVM pretty printer, printing is done by GDB.
580
+
581
+
The pretty printer also supports printing of the primitive value instead of a Java Object for boxed primitives.
582
+
583
+
Whenever printing is done via the `p` (alias for `print`) the pretty printer intercepts that call to perform type casts to the respective runtime types of Java Objects.
584
+
This also applies for auto-completion when using the `p` command.
585
+
This means, if the static type is different to the runtime type, `print` uses the static types, which leaves finding out the runtime types and type casting to the user.
586
+
Additionally, the `p` command understands Java field and array access and function calls for Java Objects.
587
+
588
+
##### Limitations
589
+
590
+
The `print` still uses its default implementation, as there is no way to overwrite it, while still keeping the capability of the default `print` command.
591
+
This would cause printing non-Java Objects to not work properly.
592
+
Therefore, only the alias `p` for the `print` command is overwritten by the SVM pretty printer, such that the user can still make use of GDBs default `print` command.
593
+
594
+
595
+
#### Options for controlling the behavior of the SVM Pretty Printer
596
+
597
+
In addition to the enhanced `p` command `svmhelpers.py` introduces some GDB parameters to customize the behavior of the SVM Pretty Printer.
598
+
Parameters in GDB can be interacted with `set <param> <value>` and `show <param>` and therefore, integrates into GDBs customization options.
599
+
600
+
*##### svm-print on/off
601
+
602
+
Use this command to enable/disable the SVM Pretty Printer.
603
+
This also resets the `print` command alias `p` to its default behavior.
604
+
Alternatively SVM pretty printing can be suppressed with the
605
+
[raw printing option of GDBs print command](https://sourceware.org/gdb/current/onlinedocs/gdb/Output-Formats.html):
606
+
607
+
(gdb) show svm-print
608
+
The current value of 'svm-print' is "on".
609
+
(gdb) print str
610
+
$1 = "string"
611
+
(gdb) print/r str
612
+
$2 = (java.lang.String *) 0x7ffff689d2d0
613
+
(gdb) set svm-print off
614
+
1 printer disabled
615
+
1 of 2 printers enabled
616
+
617
+
(gdb) print str
618
+
$3 = (java.lang.String *) 0x7ffff689d2d0
619
+
620
+
*##### svm-print-string-limit <int>
621
+
622
+
Allows to customize the maximum length for pretty printing Java Strings.
623
+
The default value is 200, set to -1 or _unlimited_ for unlimited printing of Java Strings.
624
+
This does not change the limit for c strings, which can be controlled with GDBs `set print characters`.
625
+
626
+
*##### svm-print-element-limit <int>
627
+
628
+
Allows to customize the maximum number of elements for pretty printing Java Arrays, ArrayLists and HashMaps.
629
+
The default value is 10, set to -1 or _unlimited_ for printing unlimited number of elements.
630
+
This does not change the limit for c arrays, which can be controlled with GDBs `set print elements`.
631
+
However, GDBs parameter `print elements` is the upper bound for `svm-print-element-limit`.
632
+
633
+
*##### svm-print-field-limit <int>
634
+
635
+
Allows to customize the maximum number of elements for pretty printing fields of Java Objects.
636
+
The default value is 50, set to -1 or _unlimited_ for printing unlimited number of fields.
637
+
GDBs parameter `print elements` is the upper bound for `svm-print-field-limit`.
638
+
639
+
*##### svm-print-depth-limit <int>
640
+
641
+
Allows to customize the maximum depth of recursive svm pretty printing.
642
+
The default value is 1.
643
+
The children of direct children are printed (a sane default to make contents of boxed values visible).
644
+
Set to -1 or _unlimited_ for printing unlimited depth.
645
+
GDBs parameter `print max-depth` is the upper bound for `svm-print-depth-limit`.
646
+
647
+
*##### svm-use-hlrep on/off
648
+
649
+
Use this command to enable/disable pretty printing for higher level representations.
650
+
It provides a more data oriented view on some Java data structures with a known internal structure such as Lists or Maps.
651
+
Currently supports ArrayList and HashMap.
652
+
653
+
*##### svm-infer-generics <int>
654
+
655
+
Allows to customize the amount of elements taken into account for inferring the generic type of higher level representations.
656
+
The default value is 10.
657
+
Set to 0 for not inferring generic types and -1 or _unlimited_ for inferring the generic type over all elements.
658
+
659
+
*##### svm-print-address absolute/on/off
660
+
661
+
Use this command to enable/disable printing of addresses in addition to regular pretty printing.
662
+
When `absolute` mode is used even compressed references are shown as absolute addresses.
663
+
Printing addresses is disabled by default.
664
+
665
+
*##### svm-print-static-fields on/off
666
+
667
+
Per default static field members are not shown during pretty printing of Java objects.
668
+
This command allows to customize this behavior.
669
+
670
+
*##### svm-complete-static-variables on/off
671
+
672
+
Per default static field members completion is provided by the **p** command.
673
+
This command allows to enable/disable completion for static field members.
674
+
675
+
*##### svm-selfref-check on/off
676
+
677
+
To avoid endless recursion in pretty printing self-referential data structures `svmhelpers.py` detects such cases and prevents further expansion.
678
+
For testing, this feature can be temporary disabled (usually you wouldn't want to do this).
0 commit comments