[Converted from Gnats 2540] Most of the GCC suite now takes a --sysroot command line argument specifying where to look for the system headers, libraries, etc. GDB has a new "set sysroot" command which does the same thing, and that's very handy. However, GDB really needs this to be available as a command-line option as well. The problem is that if I run "gdb <targ> <core>" it will try to read the various libraries, etc. before I get any command-line prompt, and it will of course fail because the ones it finds are not the right sysroot ones. Only after I get a long list of error messages do I get a prompt and the ability to "set sysroot ..." whereupon GDB can now find the right libraries etc. Even if I try something like "gdb -ex 'set sysroot ...' <targ> <core>" it won't help, because GDB will internalize the executable and core before running the set sysroot command. What I would really like is a --sysroot=... option to GDB, just like I have for GCC. In this case GDB can see that option and process it first, before it tries to read in the exec file or the core file. This will keep everything loading in the right order and avoid lots of warnings and error messages. Release: gdb-6.8 Environment: --host=i686-pc-linux-gnu --target=powerpc-linux-gnu
From: Daniel Jacobowitz <drow@false.org> To: psmith@gnu.org Cc: gdb-gnats@sources.redhat.com Subject: Re: gdb/2540: GDB needs a --sysroot command line option Date: Tue, 21 Oct 2008 18:12:53 -0400 On Tue, Oct 21, 2008 at 09:59:56PM -0000, psmith@gnu.org wrote: > Even if I try something like "gdb -ex 'set sysroot ...' <targ> <core>" it won't help, because GDB will internalize the executable and core before running the set sysroot command. I think that this is the actual bug; we should have a way to run commands before or after loading. I usually work around it with this awkward form: gdb -ex 'set sysroot ...' -ex 'core-file core' <targ> -- Daniel Jacobowitz CodeSourcery
> I think that this is the actual bug; we should have a way to run > commands before or after loading. Indeed, and we have "-iex" for that nowadays: $ gdb --help ... --eval-command=COMMAND, -ex Execute a single GDB command. May be used multiple times and in conjunction with --command. --init-eval-command=COMMAND, -iex Like -ex but before loading inferior.
I agree that these new options make things possible. But it sure would be nice to support the common flag that other tools already support, and have it do the right thing.
I came up with similar on Ubuntu LTS looking at a core file. Looks like snaps include allt heir own libs (I'm not really a fan of this approach DLL hell, but anyway) Would be great to have this feature. $ gdb -c chrome_S6_1594713950.core /snap/chromium/1213/usr/lib/chromium-browser/chrome GNU gdb (Ubuntu 9.1-0ubuntu1) 9.1 <snip> For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from /snap/chromium/1213/usr/lib/chromium-browser/chrome... (No debugging symbols found in /snap/chromium/1213/usr/lib/chromium-browser/chrome) [New LWP 927798] warning: .dynamic section for "/lib/x86_64-linux-gnu/libpthread.so.0" is not at the expected address (wrong library or version mismatch?) warning: .dynamic section for "/lib/x86_64-linux-gnu/librt.so.1" is not at the expected address (wrong library or version mismatch?) warning: .dynamic section for "/lib/x86_64-linux-gnu/libsystemd.so.0" is not at the expected address (wrong library or version mismatch?) warning: .dynamic section for "/lib/x86_64-linux-gnu/libmount.so.1" is not at the expected address (wrong library or version mismatch?) warning: .dynamic section for "/lib/x86_64-linux-gnu/liblzma.so.5" is not at the expected address (wrong library or version mismatch?) warning: .dynamic section for "/usr/lib/x86_64-linux-gnu/liblz4.so.1" is not at the expected address (wrong library or version mismatch?) warning: .dynamic section for "/lib/x86_64-linux-gnu/libblkid.so.1" is not at the expected address (wrong library or version mismatch?) warning: .dynamic section for "/lib/x86_64-linux-gnu/libgpg-error.so.0" is not at the expected address (wrong library or version mismatch?) warning: .dynamic section for "/lib/x86_64-linux-gnu/libuuid.so.1" is not at the expected address (wrong library or version mismatch?) warning: Could not load shared library symbols for /lib/x86_64-linux-gnu/libgcrypt.so.20. Do you need "set solib-search-path" or "set sysroot"?
Doesn't gdb -iex "set sysroot /whatever" -c chrome_S6_1594713950.core /snap/chromium/1213/usr/lib/chromium-browser/chrome work? Is that really significally worse than: gdb --sysroot /whatever -c chrome_S6_1594713950.core /snap/chromium/1213/usr/lib/chromium-browser/chrome ? You'd just be saving a few keystrokes.
(In reply to Pedro Alves from comment #5) > Doesn't > > gdb -iex "set sysroot /whatever" -c chrome_S6_1594713950.core > /snap/chromium/1213/usr/lib/chromium-browser/chrome > > work? > > Is that really significally worse than: > > gdb --sysroot /whatever -c chrome_S6_1594713950.core > /snap/chromium/1213/usr/lib/chromium-browser/chrome > > ? > > You'd just be saving a few keystrokes. Maybe this could be documented in the GDB manual? https://sourceware.org/gdb/current/onlinedocs/gdb/Invocation.html#Invocation