Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* how to determine location of source?
@ 2009-03-03  0:57 Brendan Miller
  2009-03-03  1:05 ` Joel Brobecker
  0 siblings, 1 reply; 7+ messages in thread
From: Brendan Miller @ 2009-03-03  0:57 UTC (permalink / raw)
  To: gdb

According to documentation I read, debug binaries have the location of
the source embedded in them. How do I extract this location from the
binary? Can GDB do this?

Also, is there an environment variable or config file that can control
the directories that source is looked for in?


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: how to determine location of source?
  2009-03-03  0:57 how to determine location of source? Brendan Miller
@ 2009-03-03  1:05 ` Joel Brobecker
       [not found]   ` <ef38762f0903021735v54143dd4ga38ed350616357a2@mail.gmail.com>
  0 siblings, 1 reply; 7+ messages in thread
From: Joel Brobecker @ 2009-03-03  1:05 UTC (permalink / raw)
  To: Brendan Miller; +Cc: gdb

> According to documentation I read, debug binaries have the location of
> the source embedded in them. How do I extract this location from the
> binary? Can GDB do this?

I haven't need this type of info much, but "info sources" has been
handy sometimes.

> Also, is there an environment variable or config file that can control
> the directories that source is looked for in?

There are several ways of doing this depending of what you are trying
to do. There is the "dir" command. But perhaps you have moved the
sources elsewhere, and want to translate the encoded source locations
into your new location. Have a look at "set substitute-path".
That's as much as remember off the top of my head.

PS: Sounds like you could benefit greatly from reading the GDB
    documentation. Best advice I ever received in my first year
    of Engineering School.

-- 
Joel


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Fwd: how to determine location of source?
       [not found]   ` <ef38762f0903021735v54143dd4ga38ed350616357a2@mail.gmail.com>
@ 2009-03-03  1:39     ` Brendan Miller
  2009-03-03  1:52       ` Joel Brobecker
  0 siblings, 1 reply; 7+ messages in thread
From: Brendan Miller @ 2009-03-03  1:39 UTC (permalink / raw)
  To: gdb

Er, I meant to send this to the GDB list originally so I could clarify
what I'm trying to do.


---------- Forwarded message ----------
From: Brendan Miller <catphive@catphive.net>
Date: Mon, Mar 2, 2009 at 5:35 PM
Subject: Re: how to determine location of source?
To: Joel Brobecker <brobecker@adacore.com>


On Mon, Mar 2, 2009 at 5:04 PM, Joel Brobecker <brobecker@adacore.com> wrote:
> Have a look at "set substitute-path".
Right, but before I can use that I need to know what the original path
was so I can do the substitution. My binaries come from a daily build,
and I can't know what particular path the build machine made them on
without inspecting the binaries themselves.

I did read the gdb documentation here, scroll down to the Specifying
Source Directories section:
http://sourceware.org/gdb/download/onlinedocs/gdb_8.html#SEC51

which is why I was posting on the list, because the documentation is
incomplete, or maybe I just missed something. It says that GDB
inspects the source path embeded in the binary, but I can't find where
it says how the user can do it.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Fwd: how to determine location of source?
  2009-03-03  1:39     ` Fwd: " Brendan Miller
@ 2009-03-03  1:52       ` Joel Brobecker
  2009-03-03  2:22         ` Brendan Miller
  0 siblings, 1 reply; 7+ messages in thread
From: Joel Brobecker @ 2009-03-03  1:52 UTC (permalink / raw)
  To: Brendan Miller; +Cc: gdb

> Right, but before I can use that I need to know what the original path
> was so I can do the substitution. My binaries come from a daily build,
> and I can't know what particular path the build machine made them on
> without inspecting the binaries themselves.

If the build was a different machine, the chances are GDB will not
be able to find the sources by default, as the paths in the debugging
info are invalid for your machine.  In that case, if the sources on
your host are inside one or two directories, the "dir" command might
be sufficient and the easiest to use. Plus, it'll always work.

Otherwise, you have several options. There are some tools out there
that allow you to inspect the debugging information.  The one I like
the most is "readelf". The "set substitute-path" should work.

> I did read the gdb documentation here,

As I said to Brendan as a reply to his first (private) reply,
I almost immediately regretted the way I said it. It was a genuine
advice, and yet I made it sounds like a retort.

> scroll down to the Specifying
> Source Directories section:
> http://sourceware.org/gdb/download/onlinedocs/gdb_8.html#SEC51
> 
> which is why I was posting on the list, because the documentation is
> incomplete, or maybe I just missed something.

Yes, perhaps a reference to some of the GDB commands that can be used
to get that piece of info might be useful. The fee for the help you
are getting here is a patch to the GDB documentation. Thank you! :)

So, doesn't "info sources" give you the kind of info you're looking
for. It's a little verbose, but I don't do see anything that's
directly accessible.  Otherwise, you have "maintenance print
psymbols PSYMS" that also gives you something you can use, but
it's printed on a separate file, and contains even more info.
That's all I can think of for now.

-- 
Joel


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Fwd: how to determine location of source?
  2009-03-03  1:52       ` Joel Brobecker
@ 2009-03-03  2:22         ` Brendan Miller
  2009-03-03  2:39           ` Joel Brobecker
  0 siblings, 1 reply; 7+ messages in thread
From: Brendan Miller @ 2009-03-03  2:22 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb

No big deal. There are still parts of the manual I haven't read,
although I thought I'd checked out the stuff most relevant to my
question.

On Mon, Mar 2, 2009 at 5:52 PM, Joel Brobecker <brobecker@adacore.com> wrote:
> So, doesn't "info sources" give you the kind of info you're looking
> for. It's a little verbose, but I don't do see anything that's
> directly accessible.  Otherwise, you have "maintenance print
> psymbols PSYMS" that also gives you something you can use, but
> it's printed on a separate file, and contains even more info.

Hmm... info sources and maintenance print psymbols PSYMS gives me
relative, not absolute paths. Maybe that's all that's encoded into my
binaries by our build process, which would be cumbersome from my
purposes since I have differen't so's built in different directories.
I'm not really sure how source path encoding was handled by GCC, but
the examples in the manual made me think that absolute paths were the
norm.

Thanks,
Brendan


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Fwd: how to determine location of source?
  2009-03-03  2:22         ` Brendan Miller
@ 2009-03-03  2:39           ` Joel Brobecker
       [not found]             ` <ef38762f0903021927oe1429aakef0d6971ef9be5@mail.gmail.com>
  0 siblings, 1 reply; 7+ messages in thread
From: Joel Brobecker @ 2009-03-03  2:39 UTC (permalink / raw)
  To: Brendan Miller; +Cc: gdb

> Hmm... info sources and maintenance print psymbols PSYMS gives me
> relative, not absolute paths. Maybe that's all that's encoded into my
> binaries

Yes and no. I will assume that you are building on a target that
runs ELF binaries and that your debugging info is DWARF, but the
principles are the same regardless.

Usually, what the compiler provides a debugging information is
one attribute that tells you the name of the directory from which
the compilation was done. Check out the DW_AT_comp_dir attribute,
and then one attribute that gives you the name of the source file
as it was given to GCC.

   /my/sources% gcc -c -g subdir/foo.c

Will result in:
   DW_AT_comp_dir = /my/sources
   DW_AT_name = subdir/foo.c

This is of course not standardized, so any combination of comp_dir/name
can happen, but this is what GCC does as far as I know. The DWARF
dumper will give you that info.

-- 
Joel


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Fwd: Fwd: how to determine location of source?
       [not found]             ` <ef38762f0903021927oe1429aakef0d6971ef9be5@mail.gmail.com>
@ 2009-03-03  3:27               ` Brendan Miller
  0 siblings, 0 replies; 7+ messages in thread
From: Brendan Miller @ 2009-03-03  3:27 UTC (permalink / raw)
  To: gdb

Er, sorry, I keep forgetting to hit reply to all.


---------- Forwarded message ----------
From: Brendan Miller <catphive@catphive.net>
Date: Mon, Mar 2, 2009 at 7:27 PM
Subject: Re: Fwd: how to determine location of source?
To: Joel Brobecker <brobecker@adacore.com>


On Mon, Mar 2, 2009 at 6:38 PM, Joel Brobecker <brobecker@adacore.com> wrote:
>> Hmm... info sources and maintenance print psymbols PSYMS gives me
>> relative, not absolute paths. Maybe that's all that's encoded into my
>> binaries
>
> Yes and no. I will assume that you are building on a target that
> runs ELF binaries and that your debugging info is DWARF, but the
> principles are the same regardless.
>
> Usually, what the compiler provides a debugging information is
> one attribute that tells you the name of the directory from which
> the compilation was done. Check out the DW_AT_comp_dir attribute,
> and then one attribute that gives you the name of the source file
> as it was given to GCC.
>
>   /my/sources% gcc -c -g subdir/foo.c
>
> Will result in:
>   DW_AT_comp_dir = /my/sources
>   DW_AT_name = subdir/foo.c

Ah, excellent, I was able to get at that information with readelf -w

Brendan


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2009-03-03  3:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-03  0:57 how to determine location of source? Brendan Miller
2009-03-03  1:05 ` Joel Brobecker
     [not found]   ` <ef38762f0903021735v54143dd4ga38ed350616357a2@mail.gmail.com>
2009-03-03  1:39     ` Fwd: " Brendan Miller
2009-03-03  1:52       ` Joel Brobecker
2009-03-03  2:22         ` Brendan Miller
2009-03-03  2:39           ` Joel Brobecker
     [not found]             ` <ef38762f0903021927oe1429aakef0d6971ef9be5@mail.gmail.com>
2009-03-03  3:27               ` Fwd: " Brendan Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox