This is the mail archive of the binutils@sourceware.cygnus.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Stack backtracing


G'day from .au

Two questions:

Has anyone had a shot at developing a standalone stack backtracer? 
There seem to be several floating around within particular applications
(GDB, most particularly).  This seems to be a useful candidate for
standaloneship.


Also, has anyone had a shot at developing a backtracer which works with
-fomit-frame-pointer?   Even better, one which will crawl across a mix
of frameless and frameful code?  (This would be useful for GDB).

Yes, it can be done.  Fairly straightforward, but very
architecture-dependent:

1: walk up the stack looking for addresses which point into the text
segment(s).

2: if you find one, parse the opcode preceding the one which the return
address points at.  Verify that it's a 'call' opcode of some sort.

3: If poss, work out what address that opcode is calling - verify that
it's less than the current PC (but not too much less than). 
Alternatively, if you have debug info available, verify that the call's
address is the start of the current function.

4: Repeat.

The Linux kernel does steps 1 and 4.

Cheers,
Andrew.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]