public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Relative Path for Source File
@ 2008-09-11 13:22 Jiafu Gao
  2008-09-11 13:50 ` Eljay Love-Jensen
  0 siblings, 1 reply; 2+ messages in thread
From: Jiafu Gao @ 2008-09-11 13:22 UTC (permalink / raw)
  To: gcc-help

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


      

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

* Re: Relative Path for Source File
  2008-09-11 13:22 Relative Path for Source File Jiafu Gao
@ 2008-09-11 13:50 ` Eljay Love-Jensen
  0 siblings, 0 replies; 2+ messages in thread
From: Eljay Love-Jensen @ 2008-09-11 13:50 UTC (permalink / raw)
  To: Jiafu Gao, GCC-help

Hi Jiafu,

> 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

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

end of thread, other threads:[~2008-09-11 13:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-11 13:22 Relative Path for Source File Jiafu Gao
2008-09-11 13:50 ` Eljay Love-Jensen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).