免费注册 查看新帖 |

Chinaunix

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

程序为什么coredump? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-05-29 16:22 |只看该作者 |倒序浏览
我在hp 11下写了一个动态库的程序,运行正常,但退出时coredump。请各位大侠指点。
    我的动态库程序libtest.cpp如下:
  

  1. #include <iostream.h>;

  2. extern "C" {
  3. int memory (  )
  4. {
  5.         cout << "Enter Share Lib" << endl;
  6.         return 1;
  7. }

  8. }
复制代码

我的主程序main.cpp如下:

  1. #include <stdio.h>;
  2. #include <dl.h>;
  3. #include <stdlib.h>;
  4. #include <unistd.h>;

  5. int main ( int argc , char **argv )
  6. {               
  7.         shl_t hndl;
  8.         int  (*memory)();
  9.        
  10.         if ((hndl = shl_load("/home/test/yh/stl/bas1/libtest.sl",BIND_IMMEDIATE| BIND_NONFATAL, 0L)) == NULL)
  11.                    perror("shl_load: error loading libtest.sl"), exit(1);
  12.                   
  13.            if (shl_findsym(&hndl, "memory", TYPE_PROCEDURE,(void *) &memory))
  14.                 perror("shl_findsym: error loading libtest.sl"), exit(1);
  15.                   
  16.            printf("ret := %d\n" , (*memory)() );
  17.                           
  18.         shl_unload(hndl);

  19.         printf("close share lib\n");
  20.         exit(0);
  21. }

复制代码


编译命令如下:

  1. aCC +DA2.0W -c +Z  libtest.cpp
  2. ld -E -b  -o  libtest.sl libtest.o
  3. aCC +DA2.0W main.cpp -o main -ldld
复制代码


运行结果如下:

  1. $ ./main
  2. Enter Share Lib
  3. ret := 1
  4. close share lib
  5. Memory fault(coredump)
复制代码


请问这是为什么?

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
2 [报告]
发表于 2003-05-29 17:40 |只看该作者

程序为什么coredump?

把main的最后的exit(0);换成return 0;看看core码?


如果还core把core文件用gdb调试的信息贴上来

的确有点变态!

论坛徽章:
0
3 [报告]
发表于 2003-05-29 20:55 |只看该作者

程序为什么coredump?

内存访问错误!看看有没有什么地方用错指针,或者是字符串后“\0”的问题

论坛徽章:
0
4 [报告]
发表于 2003-05-30 09:09 |只看该作者

程序为什么coredump?

蓝色键盘,我按照你说的做了,还是一样。
    下面时调试信息
  

  1. gdb -c core
  2. Detected 64-bit corefile.
  3. Invoking /opt/langtools/bin/gdb64.
  4. HP gdb 3.1.5 for PA-RISC 2.0 (wide), HP-UX 11.00.
  5. Copyright 1986 - 2001 Free Software Foundation, Inc.
  6. Hewlett-Packard Wildebeest 3.1.5 (based on GDB) is covered by the
  7. GNU General Public License. Type "show copying" to see the conditions to
  8. change it and/or distribute copies. Type "show warranty" for warranty/support.

  9. Reading symbols from main...(no debugging symbols found)...done.
  10. Core was generated by `main'.
  11. Program terminated with signal 11, Segmentation fault.
  12. (no debugging symbols found)...
  13. warning: The shared libraries were not privately mapped; setting a
  14. breakpoint in a shared library will not work until you rerun the program.

  15. (no debugging symbols found)...
  16. (no debugging symbols found)...(no debugging symbols found)...
  17. (no debugging symbols found)...(no debugging symbols found)...
  18. (no debugging symbols found)...(no debugging symbols found)...
  19. (no debugging symbols found)...#0  0xc000000000064d60 in __cxxTerm+0x18 ()
  20.    from /usr/lib/pa20_64/libCsup.2
  21. (gdb) where
  22. #0  0xc000000000064d60 in __cxxTerm+0x18 () from /usr/lib/pa20_64/libCsup.2
  23. #1  0xc000000000184ea0 in exit+0x88 () from /usr/lib/pa20_64/libc.2
  24. #2  0xc000000000017834 in UT_exit+0x2c () from /usr/lib/pa20_64/dld.sl
  25. #3  0xc00000000001861c in exit+0x14 () from /usr/lib/pa20_64/dld.sl
  26. #4  0xc0000000000218c0 in $START$+0xb0 () from /usr/lib/pa20_64/dld.sl
  27. Error accessing memory address 0x0: Invalid argument.
  28.    
复制代码

请问这是什么回事?

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
5 [报告]
发表于 2003-05-30 09:20 |只看该作者

程序为什么coredump?

no debugging symbols found

编译的时候-g加上调试信息。

Program terminated with signal 11, Segmentation fault


检查包含的头文件和连接的库
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP