免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 20919 | 回复: 9

core dump 与bus error是什么样的错误? [复制链接]

论坛徽章:
0
发表于 2005-06-25 23:21 |显示全部楼层
应该从哪些方面考虑解决?




我是绝对的菜鸟!!

论坛徽章:
2
亥猪
日期:2014-03-19 16:36:35午马
日期:2014-11-23 23:48:46
发表于 2005-06-26 09:29 |显示全部楼层

core dump 与bus error是什么样的错误?


  1. If the program displays this message:

  2.         Bus error
  3. or
  4.         Segmentation fault

  5. ... then the program was trying to access a memory location outside its
  6. address space.  The computer detected this problem and sent a signal to your
  7. program, which caused it to abort.

  8. Things that cause bus errors and segmentation violations are typically
  9. out-of-bounds array references and/or references through uninitialized or
  10. mangled pointers.
  11. If you need to debug your program, you may want to enable a core dump.
  12. Usually, those two messages above would also have "(core dumped)" by them,
  13. indicating that the program wrote an image of its current memory into a file
  14. called "core" in that directory.
复制代码

论坛徽章:
0
发表于 2005-06-26 13:45 |显示全部楼层

core dump 与bus error是什么样的错误?

core dump一般应是内存溢出
bus error 应该是字节对齐问题

论坛徽章:
2
亥猪
日期:2014-03-19 16:36:35午马
日期:2014-11-23 23:48:46
发表于 2005-06-26 16:34 |显示全部楼层

core dump 与bus error是什么样的错误?

乱说

论坛徽章:
0
发表于 2005-06-26 18:18 |显示全部楼层

core dump 与bus error是什么样的错误?

我有一个程序,递归转非递归,自己定义栈,在Linux下运行没有问题,但是在FreeBSD下有时Bus Error,有时segmentation fault,都是用GCC3编译的,奇怪。

论坛徽章:
0
发表于 2005-06-26 18:26 |显示全部楼层

core dump 与bus error是什么样的错误?

[quote]原帖由 "ryuken2008"]我有一个程序,递归转非递归,自己定义栈,在Linux下运行没有问题,但是在FreeBSD下有时Bus Error,有时segmentation fault,都是用GCC3编译的,奇怪。[/quote 发表:


猜一下,在有内存对齐的地方加上__attribute__((packed))或者__attribute__((align(16)))看看行不?Linux上的GCC是默认16字节对齐的。

论坛徽章:
0
发表于 2005-06-26 19:11 |显示全部楼层

core dump 与bus error是什么样的错误?

[quote]原帖由 "ryuken2008"]我有一个程序,递归转非递归,自己定义栈,在Linux下运行没有问题,但是在FreeBSD下有时Bus Error,有时segmentation fault,都是用GCC3编译的,奇怪。[/quote 发表:


我的blog上有篇文章讲这个的,

SIGSEGV就是指针地址是非法引起的

SIGBUS, 在不同的系统上定义是不同的,
SIGBUS sparc是字节对齐问题,

在x86/FreeBSD、x86/NetBSD、x86/OpenBSD平台上,越过栈底的地址访问导致SIGBUS信号,而不是SIGSEGV信号

论坛徽章:
0
发表于 2014-07-04 09:27 |显示全部楼层
今天恰巧遇到了,就把我的例子写出来:
  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <sys/stat.h>
  4. #include <fcntl.h>
  5. #include <unistd.h>
  6. #include <sys/mman.h>
  7. #include <string.h>

  8. int main()
  9. {
  10.   int fd;
  11.   char *start;
  12.   char buf[100];

  13.   fd = open("testfile", O_RDWR);
  14.   if(fd < 0)
  15.   {
  16.     printf("fd < 0\n");
  17.     return 0;
  18.   }
  19.   start = mmap(NULL, 100, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);

  20.   strcpy(buf, start);

  21.   printf("buf = %s\n", buf);

  22.   strcpy(start, "Buf Is Not Null!");

  23.   munmap(start, 100);

  24.   close(fd);

  25.   return 0;
  26. }
复制代码
如果如上的testfile为空的话就会出现(注意:这里的为空是换行符都不能有):
Bus error (core dumped)

测试环境:
Linux ubuntu 3.5.0-40-generic #62-Ubuntu SMP Thu Aug 22 00:57:36 UTC 2013 i686 i686 i686 GNU/Linux

论坛徽章:
1
2015年亚洲杯之中国
日期:2015-02-25 15:48:22
发表于 2015-10-27 15:05 |显示全部楼层
请问这个错误发生的原因找到了吗? 回复 8# kangear


   

论坛徽章:
84
每日论坛发贴之星
日期:2015-12-29 06:20:00每日论坛发贴之星
日期:2016-01-16 06:20:00每周论坛发贴之星
日期:2016-01-17 22:22:00程序设计版块每日发帖之星
日期:2016-01-20 06:20:00每日论坛发贴之星
日期:2016-01-20 06:20:00程序设计版块每日发帖之星
日期:2016-01-21 06:20:00每日论坛发贴之星
日期:2016-01-21 06:20:00程序设计版块每日发帖之星
日期:2016-01-23 06:20:00程序设计版块每日发帖之星
日期:2016-01-31 06:20:00数据库技术版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-14 06:20:00
发表于 2015-10-27 16:58 |显示全部楼层
竟然是十年前的帖子
    gvim  albcamus  好熟悉的ID

温习一下:
GNU libc 手册的解释:
http://www.gnu.org/software/libc ... -Error-Signals.html
  1.     Macro: int SIGSEGV

  2.     This signal is generated when a program tries to read or write outside the memory that is allocated for it, or to write memory that can only be read. (Actually, the signals only occur when the program goes far enough outside to be detected by the system’s memory protection mechanism.) The name is an abbreviation for “segmentation violation”.

  3.     Common ways of getting a SIGSEGV condition include dereferencing a null or uninitialized pointer, or when you use a pointer to step through an array, but fail to check for the end of the array. It varies among systems whether dereferencing a null pointer generates SIGSEGV or SIGBUS.

  4. Macro: int SIGBUS

  5.     This signal is generated when an invalid pointer is dereferenced. Like SIGSEGV, this signal is typically the result of dereferencing an uninitialized pointer. The difference between the two is that SIGSEGV indicates an invalid access to valid memory, while SIGBUS indicates an access to an invalid address. In particular, SIGBUS signals often result from dereferencing a misaligned pointer, such as referring to a four-word integer at an address not divisible by four. (Each kind of computer has its own requirements for address alignment.)

  6.     The name of this signal is an abbreviation for “bus error”.
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP