Discussion:
Relative Path for Source File
Jiafu Gao
2008-09-11 13:21:40 UTC
Permalink
Hi,

Is there a way in gcc to specify a relative path for source file so that gdb can use the relative path to look for the source?

Let me explain it by an example. Suppose we have the following sources:
src: a.c, makefile
src/sub1: b.c, makefile
src/sub2: d.c, makefile
The
master makefile in src will compile a.c and there go to all sub
directories (sub1 and sub2) and run its makefiles. Suppose a.c links
with the libararies produced by sub directories, and produce an
executable a.out. Now when we start gdb to debug a.out, it could not
find source file b.c and d.c since sub1 and sub2 are not in the source
file search path. In this case, we can add these two paths in to gdb
source path. However, in reality, there are lots of subdirectories,
some of them are more than 1 level deep. It becomes tedious soon to add
all these path to search path.

Now
if we have an option in gcc to specify a relative path (e.g., in sub1,
we tell gcc to remember the relative path sub1 in the debug info), we
don't add sub1, sub2 to source path. Most importantly, if the a.out is
in different directory (even different machine), we only need to add
root directoy (src in this case) to gdb's source path.

I did some research, and could not find an answer. Is this possible in gcc? Any help will be greatly appreciated.

Best regards,

Jiafu
Eljay Love-Jensen
2008-09-11 13:48:33 UTC
Permalink
Hi Jiafu,
Post by Jiafu Gao
I did some research, and could not find an answer. Is this possible in gcc?
Any help will be greatly appreciated.
I don't know if it is an available feature of GCC.

If it is not an available feature of GCC, it is "possible"... in that you
have GCC source code at your disposal and you could make a one-off GCC which
incorporates that feature. I presume that's more than you'd want to tackle
(it would be more than I'd want to tackle).

However...

Read gdb documentation section 7.5:
http://sourceware.org/gdb/current/onlinedocs/gdb_8.html

What you probably should do is configure gdb with multiple dir commands to
specify the locations of all your source directories. To make debugging
easier, you could put all those dir commands in your .gdbinit in your
executable's directory, or ~/.gdbinit file, depending on how/where you
prefer to run gdb.

HTH,
--Eljay

Continue reading on narkive:
Loading...