Reprinted please indicate the source: http://blog.csdn.net/horkychen
 
When searching for problems,If you do not want to interrupt the program running, output the function execution sequence under a certain condition to help determineBit.
 
 
In xcode, You can edit the action in the breakpoint settings to debug.GER command, if you useGDBAs a debugger (Project settings ),EnterBacktraceAs follows:
 
 
Remember to check "automatically continue after evaluating" so that the program will not stop at this breakpoint, but will continue to run.
 
 
Running result:
 
#0 A (I = 5) at/xxxx/testbacktrace/Main. C: 20
 
#1 0x0000000100000e72 in main (argc = 1, argv = 0x7fff5fbffa88) at/xxxx/testbacktrace/Main. C: 25
 
 
If you useLldbAs the debugger, enterBTThe running result is as follows:
 
* Thread #1: tid = 0x2503, 0x0000000102238e37 testbacktrace 'a + 7 at main. C: 20, stop reason = breakpoint 1.1
 
Frame #0: 0x0000000102238e37 testbacktrace 'a + 7 at main. C: 20
 
Frame #1: 0x0000000102238e72 testbacktrace 'main + 34 at main. C: 25
 
Frame #2: 0x0000000102238d44 testbacktrace 'start + 52
 
 
 
The debugger options are as follows:
 
 
 
 
You can also call the backtrace function in the code.When you debug a multi-process program,The debugger may fail to attach the target process in a timely manner,This method is useful.
 
# Include <execinfo. h>
 
Void printcallstack (void)
 
{
 
Void * callstack [1, 128];
 
Int I, frames = backtrace (callstack, 128 );
 
Char ** STRs = backtrace_symbols (callstack, frames );
 
For (I = 0; I <frames; ++ I)
 
{
 
Printf ("% s \ n", STRs [I]);
 
}
 
Free (STRs );
 
}
 
 
Int A (int I)
 
{
 
Printcallstack ();
 
Return I + 1;
 
}
 
...
 
 
Output result:
 
0 testbacktrace 0x00000001013ddd6a printcallstack + 42
 
1 testbacktrace 0x00000001013dde30 A + 16
 
2 testbacktrace 0x00000001013dde72 main + 34
 
3 testbacktrace 0x00000001013ddd34 start + 52
 
 
In Visual Studio in windows, there is a similar practice. You should understand it by posting two images:
 
 
* For the second method of windows, refer to capturestackb Use of the acktrace function:1. msdn2. Win32-backtrace from C code