gdb/valgrind/coredump to debug c/cpp program

gdb/valgrind/coredump 调试
1、gdb 调试 while/for 循环

①如果在调试 while/for的时候,可以用until xxx(其中,xxx代表 行号)直接跳转到循环后面的第xxx行。

advance xxx,

参考:

2、gdb + backTrace(後向追蹤)

3、gdb + assembly (彙編/汇编)
在gdb进行 运行/run 的时候,输入 layout asm。同时,可以在 list 和 layout asm之间进行转换。

4、利用Valgrind進行內存的跟蹤
Valgrind ./xxx (其中,xxx是程序的名字)

==4210== Invalid write of size 2
==4210==    at 0x400A321: memcpy (vg_replace_strmem.c:1019)
==4210==    by 0x804E070: Pvs_QueryUserFromDev(char*, char*, char*, int, char*) (Pvs_SockCntl.cpp:1097)
==4210==    by 0x80498A9: QueryAllUserFromDev(char*, char*, char*) (test.cpp:251)
==4210==    by 0x804A6B7: main (test.cpp:669)
==4210==  Address 0x43894b4 is 8 bytes after a block of size 4 free'd
==4210==    at 0x4006AF7: operator delete[](void*) (vg_replace_malloc.c:620)
==4210==    by 0x804AC38: Pvs_TrimToInt(char*, int) (Pvs_CodeCntl.cpp:70)
==4210==    by 0x804DFA9: Pvs_QueryUserFromDev(char*, char*, char*, int, char*) (Pvs_SockCntl.cpp:1087)
==4210==    by 0x80498A9: QueryAllUserFromDev(char*, char*, char*) (test.cpp:251)
==4210==    by 0x804A6B7: main (test.cpp:669)
==4210==  Block was alloc'd at
==4210==    at 0x400801E: operator new[](unsigned int) (vg_replace_malloc.c:416)
==4210==    by 0x804AB98: Pvs_TrimToInt(char*, int) (Pvs_CodeCntl.cpp:55)
==4210==    by 0x804DFA9: Pvs_QueryUserFromDev(char*, char*, char*, int, char*) (Pvs_SockCntl.cpp:1087)
==4210==    by 0x80498A9: QueryAllUserFromDev(char*, char*, char*) (test.cpp:251)
==4210==    by 0x804A6B7: main (test.cpp:669)

5、开启 core dump 等 gdb 输出

REFER: Linux Core Dump


1、5.2 Continuing and Stepping

posted @ 2016-11-28 12:46  xiulug  阅读(371)  评论(0编辑  收藏  举报