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


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

Re: [Q]: Obtaining Stack Trace


>>>>> "Olaf" == Olaf Bachmann <obachman@mathematik.uni-kl.de> writes:
Olaf> Hi, I'm writing a new memory management system for our Computer
Olaf> Algebra system Singular (written in C). For a special debug
Olaf> mode, I'd like to associate (and store) with each allocated
Olaf> address enough (stack) information, so that, on a later request,
Olaf> I basically get what the gdb command 'backtrace' had printed at
Olaf> the time the allocation request was made.

Does your program have to access/output the symbols/line numbers, or
are just the addresses of the stack trace sufficent?  

If you can get by with just the addresses, its fairly easy to record
the return addresses for the last few stack frames.  If you're using
gcc, you can use the __builtin_return_address() extension.  If not,
it's not that much more difficult to write an assembly function to
walk the stack for your target.

When a failure has been detected, I simply output the addresses.  I
then use gdb or addr2line to map those addresses to lines of code.
You don't get the arguments passed to the functions, but I've almost
always been able to determine what went wrong.

        --jtc

-- 
J.T. Conklin
RedBack Networks

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