New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing auto-load script in gdb #33159

Open
nagisa opened this Issue Apr 22, 2016 · 5 comments

Comments

Projects
None yet
7 participants
@nagisa
Copy link
Contributor

nagisa commented Apr 22, 2016

When compiled with -g, we produce binaries which contain a gdb_load_rust_pretty_printers.py in .debug_gdb_scripts section. This makes gdb complain about missing scripts when run under plain gdb as opposed to the rust-gdb wrapper script.

Distribution puts this script into $INSTALL_ROOT/lib/rustlib/etc, which is someplace gdb wouldn’t ever look at by default. Some experimentation suggests that placing the scripts at gdb’s DATA-DIRECTORY/python/gdb/printer/ will at least make gdb detect the presence of the script, but then it fails to load the module due to import errors.

@nagisa nagisa added the A-debuginfo label Apr 22, 2016

@jimblandy

This comment has been minimized.

Copy link
Contributor

jimblandy commented Mar 10, 2017

Looking into GDB's source code, GDB uses the function find_and_open_script to search for the files listed in the .debug_gdb_scripts ELF section. This function actually uses the source file search path (the one set with GDB's dir command) to find the script, apparently on the assumption that the .debug_gdb_scripts section is associated with the specific executable, not the toolchain.

As an experiment, I added this to my .gdbinit:

add-auto-load-safe-path /home/jimb/.rustup/toolchains
dir /home/jimb/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/etc

This did help GDB find gdb_load_rust_pretty_printers.py, but then of course that file doesn't add its directory to Python's path, so the import fails:

Traceback (most recent call last):
  File "/home/jimb/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/etc/gdb_load_rust_pretty_printers.py", line 11, in <module>
    import gdb_rust_pretty_printing
ImportError: No module named gdb_rust_pretty_printing
(gdb) 

CC @tromey

@bsed

This comment has been minimized.

Copy link

bsed commented Jun 17, 2017

Traceback (most recent call last):
  File "/home/kelvin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/etc/gdb_load_rust_pretty_printers.py", line 11, in <module>
    import gdb_rust_pretty_printing
ImportError: No module named 'gdb_rust_pretty_printing'
@bobtwinkles

This comment has been minimized.

Copy link
Contributor

bobtwinkles commented Mar 22, 2018

This super hacky patch will let GDB load the files correctly, at least on my machine

diff --git a/src/etc/gdb_load_rust_pretty_printers.py b/src/etc/gdb_load_rust_pretty_printers.py
index 755cac153d..48eba096fc 100644
--- a/src/etc/gdb_load_rust_pretty_printers.py
+++ b/src/etc/gdb_load_rust_pretty_printers.py
@@ -8,5 +8,12 @@
 # option. This file may not be copied, modified, or distributed
 # except according to those terms.
 
+# Hacky fix for paths being annoying
+import sys
+from os import path
+self_dir = path.dirname(path.realpath(__file__))
+sys.path.append(self_dir)
+
 import gdb_rust_pretty_printing
 gdb_rust_pretty_printing.register_printers(gdb.current_objfile())
@PhilipDaniels

This comment has been minimized.

Copy link
Contributor

PhilipDaniels commented Apr 24, 2018

For info, I've been experimenting debugging Rust programs using https://github.com/cs01/gdbgui Just got the basic setup working, I can confirm that the two hacks here (edit the py file, create .gdbinit) suppressed the warning.

I'm not sure what the pretty printers are capable of though, is there documentation anywhere?

@Mrknister

This comment has been minimized.

Copy link

Mrknister commented May 29, 2018

I had the same problem and found out that you can also just set the PYTHONPATH environment variable instead of changin the python script.

export PYTHONPATH=$PYTHONPATH:~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment