gdbµ÷ÊÔÔõôÓÃ
gdb ÊÇÓÃÓÚµ÷ÊÔ c/c++ ³ÌÐòµÄÇ¿Ê¢¹¤¾ß¡£Ê¹Óà gdb µÄ°ì·¨°üÀ¨£º±àÒë´øµ÷ÊÔÐÅÏ¢µÄ³ÌÐò¡£Æô¶¯ gdb¡£¼ÓÔسÌÐò¡£ÉèÖöϵ㡣ÔËÐгÌÐò¡£ÖðÐÐÖ´ÐС£Éó²éÄÚ´æºÍ¼Ä´æÆ÷¡£Ð޸ijÌÐòÖ´ÐÐÁ÷³Ì¡£
gdb µ÷ÊÔÈëÃÅ
gdb£¨GNU µ÷ÊÔÆ÷£©ÊÇÒ»¿îÇ¿Ê¢µÄ¹¤¾ß£¬¿ÉÓÃÓÚµ÷ÊÔ C/C++ ³ÌÐò¡£ËüÌṩÁËÖðÐÐÖ´ÐС¢Éó²éÄÚ´æºÍ¼Ä´æÆ÷ÄÚÈÝÒÔ¼°Ð޸ijÌÐòÖ´ÐÐÁ÷³ÌµÈ¹¦Ð§¡£
ÔõÑùʹÓà gdb
ʹÓà gdb µÄ°ì·¨ÈçÏ£º
- ±àÒë´øµ÷ÊÔÐÅÏ¢µÄÄ¿µÄ³ÌÐò£ºÊ¹Óà -g Ñ¡Ïî±àÒë³ÌÐò£¬ÒÔ±ãÌìÉúµ÷ÊÔÐÅÏ¢¡£
-
ÔËÐÐ gdb£ºÊ¹ÓÃÒÔÏÂÏÂÁîÆô¶¯ gdb£º
gdb ./program_name
µÇ¼ºó¸´ÖÆ
-
¼ÓÔسÌÐò£ºÊ¹ÓÃÒÔÏÂÏÂÁ³ÌÐò¼ÓÔص½ gdb ÖУº
file ./program_name
µÇ¼ºó¸´ÖÆ
-
ÉèÖöϵ㣺ʹÓÃÒÔÏÂÏÂÁîÔÚÖ¸¶¨ÐкÅÉèÖöϵ㣺
break
µÇ¼ºó¸´ÖÆ
-
ÔËÐгÌÐò£ºÊ¹ÓÃÒÔÏÂÏÂÁîÔËÐгÌÐò£º
run
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
-
ÖðÐÐÖ´ÐУºÊ¹ÓÃÒÔÏÂÏÂÁîÖðÐÐÖ´ÐгÌÐò£º
step
µÇ¼ºó¸´ÖÆ
-
Éó²éÄÚ´æºÍ¼Ä´æÆ÷£ºÊ¹ÓÃÒÔÏÂÏÂÁîÉó²é±äÁ¿ºÍ¼Ä´æÆ÷ÄÚÈÝ£º
print info registers
µÇ¼ºó¸´ÖÆ
-
Ð޸ijÌÐòÖ´ÐÐÁ÷³Ì£ºÊ¹ÓÃÒÔÏÂÏÂÁîÐ޸ijÌÐòÖ´ÐÐλÖãº
next continue jump
µÇ¼ºó¸´ÖÆ
ʾÀý
ÒÔÏÂÊÇÒ»¸öʹÓà gdb µ÷ÊÔ¼òÆÓ³ÌÐòµÄʾÀý£º
// main.cpp int main() { int x = 10; int y = 20; int sum = x + y; return 0; }
µÇ¼ºó¸´ÖÆ
-
±àÒë³ÌÐò£º
g++ -g main.cpp -o main
µÇ¼ºó¸´ÖÆ
-
Æô¶¯ gdb£º
gdb ./main
µÇ¼ºó¸´ÖÆ
-
¼ÓÔسÌÐò£º
file ./main
µÇ¼ºó¸´ÖÆ
-
ÉèÖöϵ㣺
break 6
µÇ¼ºó¸´ÖÆ
-
ÔËÐгÌÐò£º
run
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
-
µ±³ÌÐòÔÚµÚ 6 Ðд¦Í£ÏÂʱ£¬Ê¹Óà print ÏÂÁîÉó²é±äÁ¿ÄÚÈÝ£º
print x
µÇ¼ºó¸´ÖÆ
¿ÉÒÔͨ¹ýÊäÈë help ÏÂÁîÉó²é gdb µÄÆäËû¿ÉÓõÄÏÂÁî¡£
ÒÔÉϾÍÊÇgdbµ÷ÊÔÔõôÓõÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡