Page 1 of 1

Kernel call stack trace?

Posted: Fri Feb 13, 2015 4:49 am
by Roman
How can it be implemented? I've managed to find a macro called __FUNCTION__, but how can I write it to a buffer on each call? Maybe, there's an attribute for hooking prologue?

Re: Kernel call stack trace?

Posted: Fri Feb 13, 2015 5:12 am
by Nable
Did you read about libbacktrace?
The general idea behind getting backtrace is that it's a two-stage process:
0. Invoke bt_get_backtrace or similar function.
1. It parses the chain of saved frame pointers and return addresses (with some minor architecture-specific details you can get these addresses from stack).
2. Resolve return addresses to function names by parsing debug information (if it's present in your executable image or some separate file).

You can also look here:
man 3 backtrace wrote:

Code: Select all

BACKTRACE(3)              Linux Programmer's Manual              BACKTRACE(3)

NAME
       backtrace,   backtrace_symbols,  backtrace_symbols_fd  -  support  for
       application self-debugging

SYNOPSIS
       #include <execinfo.h>

       int backtrace(void **buffer, int size);

       char **backtrace_symbols(void *const *buffer, int size);

       void backtrace_symbols_fd(void *const *buffer, int size, int fd);