Talk about printing the stack of function calls in linux kernel

  • 2020-05-15 03:23:11
  • OfStack

In Linux kernel debugging, the common method of printing the function call stack is as simple as adding:

dump_stack (); Or __backtrace (); Can be

dump_stack() is defined in ~/kernel/ lib/ Dump_stack.c


void dump_stack(void)
{
 printk(KERN_NOTICE
 "This architecture does not implement dump_stack()/n");
}
__backtrace() In the definition of ~/kernel/arch/arm/lib/backtrace.S In the 
 
ENTRY(__backtrace)
 mov r1, #0x10
 mov r0, fp

In debugging the linux application, the method used is:


backtrace
backtrace_symbols

You can add the following code to the function:


void *bt[20]; 
 char **strings; 
 size_t sz;
 sz = backtrace(bt, 20); 
 strings = backtrace_symbols(bt, sz); 
    for(i = 0; i < sz; ++i) 
        fprintf(stderr, "%s/n", strings[i]);

Related articles: