about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorSimon Farre <simon.farre.cx@gmail.com>2023-05-25 22:22:00 +0200
committerSimon Farre <simon.farre.cx@gmail.com>2023-06-05 13:56:31 +0200
commitc5145dc87a2b750a12e8f36d84ff6fb4f8edfdf4 (patch)
treef971777d76cf4d1561abd1d8ee69cf9d3f7637d4 /src
parentcade26637fe1c23965ce644299ed5200db7c92dd (diff)
downloadrust-c5145dc87a2b750a12e8f36d84ff6fb4f8edfdf4.tar.gz
rust-c5145dc87a2b750a12e8f36d84ff6fb4f8edfdf4.zip
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`
Diffstat (limited to 'src')
-rw-r--r--src/etc/gdb_load_rust_pretty_printers.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/etc/gdb_load_rust_pretty_printers.py b/src/etc/gdb_load_rust_pretty_printers.py
index 856b5df2de7..491b6ba9e9e 100644
--- a/src/etc/gdb_load_rust_pretty_printers.py
+++ b/src/etc/gdb_load_rust_pretty_printers.py
@@ -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)