4

I am trying to implement backtrace like function call myself . I have been successfully able to unroll stack and i have all return address present on my stack . Now i want to get function name, variable name input to my function from this information. Also i want to do this programmatically i.e at run time i should be able to get info about all the functions that have been called till now in my program. Lets assume i am fine compiling my with -g flag while compiling.

I am trying to use dladdr() function to get function name, but this did not work . It gives me error that "error: unknown type name ‘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 researching bfd library , but didnt have good example/tutorial , any help ? I am using ubunutu 14.04

1 Answer 1

2

Per the man page, be sure to #define _GNU_SOURCE before you #include <dlfcn.h>. This structure, and dladdr(), are GNU extensions.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.