[Crash-utility] [PATCH] Use backtrace() instead of __builtin_return_address()

Bernhard Walle bwalle at suse.de
Wed May 14 08:29:41 UTC 2008


* Dave Anderson [2008-05-13 15:16]:
> 
> A few questions on this one...
> 
> Do you know if this works OK on ia64, s390 and s390x?

I made a test program (attached) and attached the result on all
architectures. In fact, s390 and s390x produced even 100 % correct
backtraces when the program was optimised with -O2. All other
architectures leave out frames in that case, but I think that's
limitation when frame pointers are omitted that is impossible to work
around.

> Compiling with warnings turned on yields:
> 
>    defs.h:1804: warning: implicit declaration of function ‘backtrace’

I forgot the <execinfo.h> include.

> I haven't looked at the glibc sources, but I'm presuming it's
> a "void backtrace(int)".

Indeed, it's int backtrace(void **buffer, int size). In my patch I
ignored the return value. The new patch (attached) corrects that
mistake. I'm not sure if it's necessary to zero out the rest since the
memory already was initialised with 0, but to be on the save side I
think it's not bad to do it.

Since sizeof(unsigned long) == sizeof(void *) on all architectures
crash supports, the "wrong" type of buffer should be ok. In fact,
__builtin_return_address() returns also an address, i.e. void * and
not a long. Conforming strictly to C99, we should use uintptr_t. I
don't know what the crash programming guide lines say, i.e. how old the
compiler can be where crash is used. I think we should not introduce
a C99 requirement because of that small patch here.


A few words on the test program: I used backtrace_symbols_fd() to
print out the backtrace here because I was too lazy to "port" the crash
nm magic to the test program. However, the program needs to be compiled
with -rdynamic to make that work. That's also documented in
backtrace(3) manual page. So for crash, the nm magic is a big "ugly"
but it works better than the backtrace_symbols_fd() here. But for the
test program I was only interesting in the values backtrace() produces,
not in resolving, so I think that should be ok.


	Bernhard
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.c
Type: text/x-csrc
Size: 633 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/crash-utility/attachments/20080514/13a46ebf/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: results
Type: application/octet-stream
Size: 4526 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/crash-utility/attachments/20080514/13a46ebf/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: crash-builtin-return-addr
Type: application/octet-stream
Size: 2474 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/crash-utility/attachments/20080514/13a46ebf/attachment-0001.obj>


More information about the Crash-utility mailing list