An instruction pointer for a function name, input parameters ,?

I am trying to implement the backtrace call itself as a function. I was able to expand the stack successfully, and I have all the return address present on my stack. Now I want to get the name of the function, the name of the variable name for my function from this information. I also want to do this programmatically, at runtime I should get information about all the functions that have been called so far in my program. Suppose I compile my -g flag well at compile time.

I am trying to use the dladdr () function to get the function name, but this did not work. This gives me the error that “error: unknown name like“ Dl_info ”. Here is my code snippet:

const char * get_func_name(void *ip){
        Dl_info info;
        int ret;
        ret = dladdr(ip,&info);
        if(ret < 0)
                return NULL;
        return info.dli_fname;
}

I tried to research the bfd library, but I didn't have a good example / tutorial, no help? I am using ubunutu 14.04

+4
source share
1 answer

The manual page is required #define _GNU_SOURCEbefore #include <dlfcn.h>. This structure dladdr()are extensions of GNU.

+2
source

Source: https://habr.com/ru/post/1653876/


All Articles