常见的几种error:
SIGQUIT 3 Quit from keyboard(ctr+)
SIGILL 4 Illegal Instruction
SIGABRT 6 Abort signal from abort (call abort)
SIGFPE 8 Floating point exception (div 0)
SIGSEGV 11 Invalid memory reference
SIGBUS 7 Bus error
SIGSYS 31 invalid system call
SIGTRAP 5 Trace/breakpoint trap
SIGXCPU 24 CPU time limit exceeded
SIGXFSZ 25 File size limit exceeded
SIGABRT(signal 6)
- new失败, memory leak造成momory不够
- delete失败, 多次delete同一块memory应用程序抛出的异常
- 多次free:
char *p = malloc(100);
free(p);
free(p);
- fclose多次:
FILE *fp = fopen(“test.txt”, “wb+”);
printf(“%p\n”, fp);
fclose(fp);
printf(“%p\n”, fp);
fclose(fp);
SIGSEGV(signal 11)
- 多为memory越界,比如访问已经被delete掉的memory
//call NULL pointer
struct hello p = NULL;
printf(“%d\n”, p->a);
//fclose NULL pointer
FILE fp = NULL;
fclose(fp);
SIGPIPE(signal 13)
堆栈相关
1 2 3 4 5 6 7 8 9
| //Check call stack (gdb) bt #0 0x00008634 in core (out=0x0) at core.c:9 #1 0x000086e8 in main (argc=1, argv=0xbe85db74) at core.c:25
//Select stack frame (gdb) f 1 #1 0x000086e8 in main (argc=1, argv=0xbe85db74) at core.c:25 25 core(NULL);
|
变量相关
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| //Check variable: (gdb) print out $1 = (int *) 0x0
//Check function arguments: (gdb) info args argc = 1 argv = 0xbe85db74
//Check local variables: (gdb) info locals tmp = 2 out = 0xbe85da14 coredump = {rlim_cur = 4294967295, rlim_max = 4294967295} flg = 0
|
线程相关
1 2 3 4 5 6 7 8 9 10 11
| //打印出所有线程的bt信息,但是有时候印不全 (gdb) thread apply all bt
//打印出所有的线程 (gdb) info thread
//切换到线程1来打印bt信息: (gdb) thread 1 [Switching to thread 1 (LWP 1192)] #0 0xf5d89a48 in ioctl () from ./symbols/lib/libc.so.6 (gdb) bt
|
指针相关
1 2 3 4 5 6 7 8 9
| //把PC的执行的指令显示出来 (gdb) x/i $pc => 0x40e254 <android::BpInterface<ITvManagerClient>::~BpInterface()+12>: str r0, [r11, #-8]
//反汇编某个文件 $arm-none-linux-gnueabi-gdb libcore.so (gdb) disassemble 0x508 Dump of assembler code for function functest: 0x00000508 <+40>: str r2, [r3]
|