dump function call trace: You can get the function call graph, some of the time for tracking bug, understand the program structure is of particular importance.
Kernel function call trace
The kernel provides dump_stack () function, use this function, you can print out the current function call path.
dump_stack is an architecture-related functions, for the arm platform, implementation of this function position arch/arm/kernel/traps.c
Application layer function call trace
glibc provides a backtrace and backtrace_symbols function, the application layer can use their print function calls
backtrace, backtrace_symbols examples of the use
- # Include <stdio.h>
- # Include <stdlib.h>
- # Include <execinfo.h>
- void do_backtrace ()
- {
- # Define BACKTRACE_SIZ 100
- void * array [BACKTRACE_SIZ];
- int size, i;
- char ** strings;
- size = backtrace (array, BACKTRACE_SIZ);
- strings = backtrace_symbols (array, size);
- for (i = 0; i <size; + + i) {
- printf ( "% P:% s \ N" , array [i], strings [i]);
- }
- printf ( "----------------------------------------------- ---------- \ N " );
- free (strings);
- }
- int foo ()
- {
- do_backtrace ();
- }
- int Bar ( void )
- {
- foo ();
- return 0;
- }
- int Boo ( void )
- {
- bar ();
- return 0;
- }
- int baz ( void )
- {
- boo ();
- return 0;
- }
- int main ( void )
- {
- baz ();
- return 0;
- }
No comments:
Post a Comment