Kernel call stack trace?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Kernel call stack trace?

Post 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?
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: Kernel call stack trace?

Post 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);
Post Reply