Skip to content
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

nagisa opened this issue Apr 22, 2016 · 6 comments

Missing auto-load script in gdb #33159

nagisa opened this issue Apr 22, 2016 · 6 comments


Copy link

@nagisa nagisa commented Apr 22, 2016

When compiled with -g, we produce binaries which contain a 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.

Copy link

@jimblandy 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, 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/", line 11, in <module>
    import gdb_rust_pretty_printing
ImportError: No module named gdb_rust_pretty_printing

CC @tromey

Copy link

@bsed bsed commented Jun 17, 2017

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

@bobtwinkles 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/ b/src/etc/
index 755cac153d..48eba096fc 100644
--- a/src/etc/
+++ b/src/etc/
@@ -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__))
 import gdb_rust_pretty_printing
Copy link

@PhilipDaniels PhilipDaniels commented Apr 24, 2018

For info, I've been experimenting debugging Rust programs using 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?

Copy link

@Mrknister 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

Copy link

@wllenyj wllenyj commented Jul 23, 2021

I have this problem when I debug rust programs directly with gdb.

But when I use rust-gdb debugging, I don't have that problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
8 participants