8

I need to get some debugging libraries/tools to trace back the stack information print out to the stdout.

Python's traceback library can be an example.

What can be the C++ equivalent to Python's traceback library?

prosseek
  • 182,215
  • 215
  • 566
  • 871
  • I remember looking for something like this a while ago, but I didn't have much luck. I think it may venture too much into "implementation-defined" territory. I look forward to see what other folks recommend, though. – dappawit Mar 04 '11 at 00:29
  • 4
    This http://stackoverflow.com/questions/691719/c-display-stack-trace-on-exception pretty much covers it. – Eugen Constantin Dinca Mar 04 '11 at 00:36

5 Answers5

2

This is platform-specific, and also depends on how you're compiling code. If you compile code with gcc using -fomit-frame-pointer it's very hard to get a useful backtrace, generally requiring heuristics. If you're using any libraries that use that flag you'll also run into problems--it's often used for heavily optimized libraries (eg. nVidia's OpenGL libraries).

This isn't a self-contained solution, as it's part of a larger engine, but the code is helpful:

This includes backtracing with the frame pointer with gcc when available and heuristic backtracing when it isn't; this can tend to give spurious entries in the trace, but for getting a backtrace for a crash report it's much better than losing the trace entirely.

There's other related code in those directories you'd want to look at to make use of that code (symbol lookups, signal handling); those links are a good starting point.

Glenn Maynard
  • 55,829
  • 10
  • 121
  • 131
1

There's now cpp-traceback, it's exactly Python-style tracebacks for C++.

dhaffey
  • 1,354
  • 9
  • 12
1

Try google core dumper, it will give you a core dump when you need it.

hhafez
  • 38,949
  • 39
  • 113
  • 143
  • Core dumps can be very useful, but as they can be large they're not always ideal for things like crash reports. (Windows has somewhat more thorough support for this with "minidumps", allowing you to specify what information should be included.) – Glenn Maynard Mar 04 '11 at 00:53
0

I have had success with libunwind in the past. I know it works well with linux, but not sure how Windows is, although it claims to be portable.

JaredC
  • 5,150
  • 1
  • 20
  • 45
0

If you are looking for getting a 'stack trace' in case of crash, try 'google breakpad'

Nitin Bhide
  • 1,685
  • 14
  • 15