Fix #111961 r=Mark-Simulacrum

Makes the Python pretty printer library source'able from within
GDB after spawn.

This makes `rust-gdb` not the required approach. It also provides the possibility
for GUI:s that wrap GDB, to debug Rust using the pretty printer library; as well
as other projects such as for instance Pernosco, which previously was not possible.

This won't introduce any new unexpected behaviors for users of `rust-gdb`
This commit is contained in:
Simon Farre 2023-05-25 22:22:00 +02:00
parent cade26637f
commit c5145dc87a

View File

@ -1,3 +1,14 @@
# Add this folder to the python sys path; GDB Python-interpreter will now find modules in this path
import sys
from os import path
self_dir = path.dirname(path.realpath(__file__))
sys.path.append(self_dir)
import gdb
import gdb_lookup
gdb_lookup.register_printers(gdb.current_objfile())
# current_objfile can be none; even with `gdb foo-app`; sourcing this file after gdb init now works
try:
gdb_lookup.register_printers(gdb.current_objfile())
except Exception:
gdb_lookup.register_printers(gdb.selected_inferior().progspace)