相关疑难解决方法(0)

dladdr不返回函数名称

我正在尝试使用dladdr。它可以正确找到该库,但是找不到函数名称。我可以调用objdump,做一些数学运算,然后获取传递dladdr的函数的地址。如果objdump可以看到它,为什么不能dladdr?

这是我的功能:

const char *FuncName(const void *pFunc)
{
Dl_info  DlInfo;
int  nRet;

    // Lookup the name of the function given the function pointer
    if ((nRet = dladdr(pFunc, &DlInfo)) != 0)
        return DlInfo.dli_sname;
    return NULL;
}
Run Code Online (Sandbox Code Playgroud)

这是显示我得到的gdb成绩单。

Program received signal SIGINT, Interrupt.
[Switching to Thread 0xf7f4c6c0 (LWP 28365)]
0xffffe410 in __kernel_vsyscall ()
(gdb) p MatchRec8Cmp
$2 = {void (TCmp *, TWork *, TThread *)} 0xf1b62e73 <MatchRec8Cmp>
(gdb) call FuncName(MatchRec8Cmp)
$3 = 0x0
(gdb) call FuncName(0xf1b62e73)
$4 = 0x0
(gdb) b FuncName …
Run Code Online (Sandbox Code Playgroud)

c linux elf

5
推荐指数
2
解决办法
1万
查看次数

gcc编译器标志和符号表之间的不兼容函数地址

我已经编译了一个项目(openssh,但这并不重要)

CFLAGS="-ggdb3 -O0 -lm -finstrument-functions"
Run Code Online (Sandbox Code Playgroud)

符号表是(小提取):

nm -o somepath/sbin/sshd
/mypath/install/sbin/sshd:000f3548 d auth_method
/mypath/install/sbin/sshd:0001a90f t auth_openfile
/mypath/install/sbin/sshd:0001ab90 T auth_openkeyfile
/mypath/install/sbin/sshd:0001ac31 T auth_openprincipals
/mypath/install/sbin/sshd:0001d73a T auth_parse_options
/mypath/install/sbin/sshd:0000e362 T auth_password
Run Code Online (Sandbox Code Playgroud)

我打印函数地址时获得的__cyg_profile_func_enter|exit是:

0xb768f8ee
0xb768f66c
0xb768f66c
0xb76d9ae8
Run Code Online (Sandbox Code Playgroud)

显然是不一样的范围,在看了所有的数字后确认.

据我所知,nm提供偏移地址.什么__cyg_profile_func_enter时候项目中有很多文件?是否还有其他转换功能?

gcc文档中,不应该:

          void __cyg_profile_func_enter (void *this_fn,
                                         void *call_site);
          void __cyg_profile_func_exit  (void *this_fn,
                                         void *call_site);

The first argument is the address of the start of the current function, which may be looked up exactly in the symbol table.
Run Code Online (Sandbox Code Playgroud)

那么,我想让它做什么工作呢?

编辑:我的ptrace.c,我添加了一个互斥锁 …

gcc profiling debug-symbols

5
推荐指数
1
解决办法
246
查看次数

标签 统计

c ×1

debug-symbols ×1

elf ×1

gcc ×1

linux ×1

profiling ×1