Bug 9645 - GDB needs a --sysroot command line option
Summary: GDB needs a --sysroot command line option
Status: ASSIGNED
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: 6.8
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-10-21 22:08 UTC by Paul Smith
Modified: 2020-07-23 13:38 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Smith 2008-10-21 22:08:01 UTC
[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
Comment 1 drow@false.org 2008-10-21 22:12:53 UTC
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
Comment 2 Pedro Alves 2017-07-19 09:23:17 UTC
> 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.
Comment 3 Paul Smith 2018-02-13 18:43:56 UTC
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.
Comment 4 Jonny Grant 2020-07-14 10:23:30 UTC
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"?
Comment 5 Pedro Alves 2020-07-14 10:54:09 UTC
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.
Comment 6 Jonny Grant 2020-07-23 13:38:51 UTC
(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