免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4523 | 回复: 3
打印 上一主题 下一主题

求助:能否使coredump文件包含动态链接库内部的信息? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-07-05 21:38 |只看该作者 |倒序浏览
求助:在程序中dlopen动态打开动态链接库libapp.so,如果此so有错误,则生成的coredump文件里无法定位到具体位置,只能定位到函数符号

.o在编译的时候已经加了 -g

请问:这是否是linux 的 loader机制的限制?

      也就是说,coredump文件只能输出进程空间,对动态加载的so无法记录?

      非常感谢!

论坛徽章:
0
2 [报告]
发表于 2010-07-06 10:57 |只看该作者
补充一下我的demo

********************************************

链接库:

#include <stdio.h>
#include <stdlib.h>

int fun_dll()
{
    void *pTmp = NULL;

    printf("In dll\n");

    memcpy(pTmp,0,sizeof(100));  //这行代码操作空指针,会引起coredump

    return 1;
}


*******************************************

主程序:


#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>


typedef int (*LPFun)(void);

int main()
{
    int ires = 0;

    LPFun lpFun = NULL;

    void *pHandle = dlopen("libdlldemo.so",RTLD_LAZY);

    if(NULL == pHandle)
    {
       printf("open libdlldemo failed\n");
       return 1;
    }
    else
    {
       printf("open libdlldemo succ\n");
    }

    lpFun = dlsym(pHandle,"fun_dll");
    if(NULL == lpFun)
    {
       printf("dlsym failed\n");
       return 2;
    }

    ires = lpFun();  //在这里调用动态库的函数

    dlclose(pHandle);

    return 0;
}

论坛徽章:
0
3 [报告]
发表于 2010-07-06 10:59 |只看该作者
本帖最后由 fighter10383 于 2010-07-06 11:03 编辑

这样是会引发异常的,生成的core文件信息如下:

**************************************************

***@****:~/dllerrdemo> gdb main core
GNU gdb 6.3
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i586-suse-linux"...Using host libthread_db library "/lib/tls/libthread_db.so.1".

Core was generated by `./main'.
Program terminated with signal 11, Segmentation fault.

warning: current_sos: Can't read pathname for load map: 输入/输出错误

Reading symbols from /usr/lib/libcwait.so...done.
Loaded symbols for /usr/lib/libcwait.so
Reading symbols from /lib/libdl.so.2...done.
Loaded symbols for /lib/libdl.so.2
Reading symbols from /lib/tls/libc.so.6...done.
Loaded symbols for /lib/tls/libc.so.6
Reading symbols from /lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
Reading symbols from /home/zxin10/lib/libdlldemo.so...done.
Loaded symbols for /home/zxin10/lib/libdlldemo.so
#0  0x400a340c in memcpy () from /lib/tls/libc.so.6
(gdb) where
#0  0x400a340c in memcpy () from /lib/tls/libc.so.6
#1  0x4001b694 in fun_dll () from /home/zxin10/lib/libdlldemo.so
#2  0x08048544 in main () at main.c:33

论坛徽章:
0
4 [报告]
发表于 2010-07-06 11:02 |只看该作者
也就是说,用gdb分析这个coredump,是无法跟踪到 fun_dll函数内部的(因为它是动态打开的共享库)

能不能认为:coredump文件只能输出进程空间,对动态加载的so无法记录?

恳切的咨询:这是不是liunx的动态加载机制决定的?谢谢

编译参数:

-g3
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP