gdbµ÷ÊÔÏÂÁîµÄʹÓü°×ܽá
gdbÊÇÒ»¸öÓÃÓÚµ÷ÊÔ³ÌÐòµÄÇ¿Ê¢¹¤¾ß£¬¿ÉÈÃÓû§Öð²½Ö´ÐдúÂ룬¼ì²é±äÁ¿ÖµºÍÄÚ´æÄÚÈÝ£¬ÒÔ¼°ÉèÖöϵãºÍÊÓ²ìµã¡£³£ÓÃÏÂÁî°üÀ¨£ºÆô¶¯gdb£ºgdb program_nameÔËÐгÌÐò£ºrun argsÉèÖöϵ㣺break line_number/function_nameɾ³ý¶Ïµã£ºdelete break_numberµ¥²½Ö´ÐУºnext/step¼ì²é±äÁ¿£ºprint variable_name/display variable_nameÄÚ´æ¼ì²é£ºx/n format address/x/s address·´»ã
gdbµ÷ÊÔÏÂÁîµÄʹÓÃ
ʲôÊÇgdb£¿
gdb£¨GNUµ÷ÊÔÆ÷£©ÊÇÒ»ÖÖÇ¿Ê¢µÄ¹¤¾ß£¬ÓÃÓÚµ÷ÊÔC¡¢C++ºÍ»ã±àÓïÑÔ³ÌÐò¡£ËüÔÊÐí³ÌÐòÔ±Öð²½Ö´ÐдúÂ룬¼ì²é±äÁ¿ÖµºÍÄÚ´æÄÚÈÝ£¬ÒÔ¼°ÉèÖöϵãºÍÊÓ²ìµã¡£
³£ÓÃgdbÏÂÁî
Æô¶¯gdb
- gdb program_name
ÔËÐгÌÐò
- run args
ÉèÖöϵã
- break line_number
- break function_name
ɾ³ý¶Ïµã
- delete break_number
µ¥²½Ö´ÐÐ
- next£ºÖ´ÐÐÏÂÒ»ÐдúÂë¡£
- step£º½øÈ뺯Êý£¬Ö´ÐÐÏÂÒ»ÐдúÂë¡£
¼ì²é±äÁ¿
- print variable_name
- display variable_name£ºÒ»Á¬ÏÔʾ±äÁ¿Öµ¡£
ÄÚ´æ¼ì²é
- x/n format address£ºÏÔʾÄÚ´æÖеÄn¸öµ¥Î»¡£
- x/s address£ºÏÔʾÄÚ´æÖеÄ×Ö·û´®¡£
·´»ã±à
- disassemble function_name
ÊÓ²ìµã
- watch variable_name£ºµ±±äÁ¿Öµ±¬·¢×ª±äʱ×èÖ¹Ö´ÐС£
ÆäËûÓÐÓÃÏÂÁî
- list£ºÏÔʾĿ½ñÖÜΧ´úÂë¡£
- info£ºÏÔʾµ÷ÊÔ³ÌÐòÐÅÏ¢¡£
- help£º»ñÈ¡ÏÂÁî×ÊÖú¡£
ʹÓÃʾÀý
Òªµ÷ÊÔÒ»¸öÃûΪmy_programµÄC³ÌÐò£º
- Æô¶¯gdb£ºgdb my_program
- ÉèÖöϵ㣺break main
- ÔËÐгÌÐò£ºrun
- ÖðÐÐÖ´ÐУºnext
- ¼ì²é±äÁ¿£ºprint a
- ɾ³ý¶Ïµã£ºdelete 1
ÒÔÉϾÍÊÇgdbµ÷ÊÔÏÂÁîµÄʹÓü°×ܽáµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡