ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 可恶的

可恶的

原创 Linux操作系统 作者:Tom 时间:2007-08-03 00:00:00 0 删除 编辑

今天在集成菲律宾的程序时发现一个问题,用我机器的XLITE测试时,程序ok,但是用另外一台机器的XLITE测试时,程序就会core down,Program received signal SIGSEGV, Segmentation fault,弄了一下午也没有什么头绪。


上msn咨询了下小刘兄弟,按照他的指引肯定是在出错附近代码问题,而且肯定是内存越界的问题;

开始gdb跟踪,发现在底层抵用的函数时,上层的消息就被踩了,终于发现在处理函数的地方又一个打印的宏,宏里面只申请了120个字节,结果打印的内容超过120了,导致错误。

关于SIGSEGV错误需要很注意了。

A segmentation fault (often shortened to segfault) is a particular error condition that can occur during the operation of computer software. In short, a segmentation fault occurs when a program attempts to access a memory location that it is not allowed to access, or attempts to access a memory location in a way that is not allowed (e.g., attempts to write to a read-only location, or to overwrite part of the operating system). Systems based on processors like the Motorola 68000 tend to refer to these events as Address or Bus errors.

Segmentation is one approach to memory management and protection in the operating system. It has been superseded by paging for most purposes, but much of the terminology of segmentation is still used, "segmentation fault" being an example. Some operating systems still have segmentation at some logical level although paging is used as the main memory management policy.

On Unix-like operating systems, a process that accesses invalid memory receives the SIGSEGV signal. On Microsoft Windows, a process that accesses invalid memory receives the STATUS_ACCESS_VIOLATION exception.

所谓的段错误就是指访问的内存超出了系统所给这个程序的内存空间,通常这个值是由gdtr来保存的,他是一个48位的寄存器,其中的32位是保存由它指向的gdt表,后13位保存相应于gdt的下标,最后3位包括了程序是否在内存中以及程序的在cpu中的运行级别,指向的gdt是由以64位为一个单位的表,在这张表中就保存着程序运行的代码段以及数据段的起始地址以及与此相应的段限和页面交换还有程序运行级别还有内存粒度等等的信息。一旦一个程序发生了越界访问,cpu就会产生相应的异常保护,于是segmentation fault就出现了

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/2008/viewspace-45228/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2007-12-28

  • 博文量
    109
  • 访问量
    1260873