Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can one grab a stack trace in C?

I know there's no standard C function to do this. I was wondering what are the techniques to to this on Windows and *nix? (Windows XP is my most important OS to do this on right now.)

like image 985
Kevin Avatar asked Sep 19 '08 21:09

Kevin


People also ask

How do you analyze a stack trace?

Analyze external stack tracesFrom the main menu, select Code | Analyze Stack Trace or Thread Dump. In the Analyze Stack Trace dialog that opens, paste the external stack trace or thread dump into the Put a stacktrace here: text area. Click OK. The stack trace is displayed in the Run tool window.

How do I get stack trace in Visual Studio?

To open the Call Stack window in Visual Studio, from the Debug menu, choose Windows>Call Stack. To set the local context to a particular row in the stack trace display, select and hold (or double click) the first column of the row.

What is a stack trace and how can I use it to debug my application errors?

This also implies that a stack trace is printed top-down. The stack trace first prints the function call that caused the error and then prints the previous underlying calls that led up to the faulty call. Therefore, reading the first line of the stack trace shows you the exact function call that threw an error.


1 Answers

glibc provides backtrace() function.

http://www.gnu.org/software/libc/manual/html_node/Backtraces.html

like image 181
sanxiyn Avatar answered Oct 08 '22 21:10

sanxiyn