views:

78

answers:

1

Hi,

I'm trying to automate some debugging tasks. In certain cases, I print the value of $ra [this is a MIPS machine] and parts of the stack as hex addresses. During debugging, I use addr2line to convert them into file:line pairs.

I'd like to automate this procedure.

The problem is that addr2line returns a filename that equivelent to the value of __FILE__ at compilation time; i.e., the name of the file as passed to the compiler. This is usually foo.c, sometimes src/foo.c. As my project has several hundred directories in total, this may not be enough to uniquely identify the file (there may be 1/foo.c, 2/foo.c, etc). Even if it was deterministic, it seems rather inefficient to start running find in my screen for each argument [I suppose I could build a hash table and save them, but I'd like to keep this as a straightforward bash script]

GDB seems to get the right file. If I look at the actual source file with debugging symbols, I can also see that right after the filename there appears to be the full path to the __FILE__ [i.e., if __FILE__ is src/foo.c, and it's really in /home/me/projects/something/comp1/src/foo.c, I will see /home/me/projects/something/comp1 in the file. How can I get this progmatically?

Thanks.

+1  A: 

This is very surprising behavior. I'm unable to reproduce it in:

  • Linux with gcc 4.1.2 and addr2line 2.17.50.0.6

  • Cygwin with gcc 4.3.4 and gcc 3.4.4 and addr2line 2.20.51.20100410

addr2line should rely on the debug information stored in the executable. And the debug information should contain absolute paths (regardless of what source path was given to the compiler) in order to avoid any ambiguities when using a debugger. Everywhere I try it, addr2line always shows an absolute path.

Assuming you are using make for your build system, one option, albeit a probably painful one, would be to change your makefiles to use a non-recursive strategy (something you really ought to be doing anyway). With such a system, only a single instance of make is running, from a single working directory (usually the top-level of your source tree). Therefore all invocations of the compiler specify the full path to the source file (relative to the root of the source tree). This would solve your problem if, in fact, addr2line always shows the filenames as they were specified to the compiler. Not the best solution, but one that would work. And as a side benefit, you'd get all the advantages of non-recursive make.

Dan Moulding
I can't change the build system; this is a project w/ about 200 developers spread over 5 sites (4 countries), supporting about 150 different platforms. Build changes will not be taken lightly (and this way, each component maintains it's own makefile, following certain conventions, with the generic build instructions in common files)
Mikeage
I'm using addr2line 2.16.91.0.7 20060317, compiled for a MIPS platform. I wonder if something has been improved in the last 5 years. My compiler is GCC 3.4.6.
Mikeage
interesting. I just compiled 2.20.1 for my platform, and it shows a full path.Maybe this is a bug. Thanks for your answer.
Mikeage