Linux程序调试--Bus Error
(2012-06-27 16:33:15)
标签:
buserrorlinuxdebugit |
分类: Linux/Shell |
Bus Error究竟是指什么
一
SIGBUS与SIGSEGV信号的一般区别如下:
二
1 int main(){
#include <stdlib.h>
int main( int argc, char ** argv) {
int * iptr;
char * cptr;
#if defined(__GNUC__)
# if defined(__i386__)
__asm__( "pushf/n orl $0x40000,(%esp)/n popf" ) ;
# elif defined(__x86_64__)
__asm__( "pushf/n orl $0x40000,(%rsp)/n popf" ) ;
# endif
#endif
cptr = malloc( sizeof ( int ) + 1) ;
iptr = ( int * ) ++ cptr;
* iptr = 42 ;
return 0 ;
}
$ gcc -ansi sigbus.c -o sigbus
$ ./sigbus
Bus error
$ gdb ./sigbus
(gdb) r
Program received signal SIGBUS
, Bus error.
0x080483ba in main ()
(gdb) x/i $pc
0x80483ba <main+54>: mov DWORD PTR [eax],0x2a
(gdb) p/x $eax
$1 = 0x804a009
(gdb) p/t $eax & (sizeof(int) - 1)
$2 = 1
三,编译器和硬件平台相关性
short array[10] __attribute__ ((aligned (4)));
union {
short s;
int i;
}