×ðÁú¿­Ê±¹ÙÍøµÇ¼

gdbµ÷ÊÔÒªÁì gdbµ÷ÊÔÒªÁìÏêϸ°ì·¨Ïê½â

gdb µ÷ÊÔ c/c++ ³ÌÐò¹²ÓÐ 9 ¸ö°ì·¨£º1. ×°Öà gdb£»2. ±àÒë³ÌÐò²¢Ìí¼Ó -g Ñ¡Ï3. Æô¶¯ gdb ²¢¼ÓÔØ¿ÉÖ´ÐÐÎļþ£»4. ÉèÖöϵ㣻5. ÔËÐгÌÐò£»6. ¼ì²é±äÁ¿Öµ£»7. ²½¹ý¡¢²½Èë»ò²½³ö£»8. Éó²éŲÓÿÍÕ»£»9. Í˳ö gdb¡£

gdb µ÷ÊÔÒªÁì

gdb£¨GNU µ÷ÊÔÆ÷£©ÊÇÒ»¸ö¹¦Ð§Ç¿Ê¢µÄ¹¤¾ß£¬ÓÃÓÚµ÷ÊÔ C¡¢C++ ºÍÆäËû±à³ÌÓïÑÔ±àдµÄ³ÌÐò¡£

Ïêϸ°ì·¨£º

1. ×°ÖÃ gdb

ÔÚ Linux ϵͳÖУ¬Ê¹ÓÃÒÔÏÂÏÂÁî×°Öà gdb£º

sudo apt-get install gdb

µÇ¼ºó¸´ÖÆ

ÔÚ macOS ÖУ¬Ê¹Óà Homebrew ×°Öãº

brew install gdb

µÇ¼ºó¸´ÖÆ

2. ±àÒë³ÌÐò

ʹÓñàÒëÆ÷£¨Èç gcc£©±àÒë³ÌÐò£¬²¢Ìí¼Ó -g Ñ¡ÏîÒÔÌìÉúµ÷ÊÔÐÅÏ¢£º

gcc -g example.c -o example

µÇ¼ºó¸´ÖÆ

3. Æô¶¯ gdb

ÔÚÖÕ¶ËÖУ¬Ê¹ÓÃÒÔÏÂÏÂÁîÆô¶¯ gdb ²¢¼ÓÔØ¿ÉÖ´ÐÐÎļþ£º

gdb example

µÇ¼ºó¸´ÖÆ

4. ÉèÖöϵã

ÔÚ³ÌÐòÖÐÉèÖöϵ㣬ÒÔÔÝÍ£Ö´Ðв¢¼ì²é±äÁ¿Öµ£º

break 

µÇ¼ºó¸´ÖÆ

5. ÔËÐгÌÐò

ʹÓÃÒÔÏÂÏÂÁîÔËÐгÌÐò²¢Óöµ½¶ÏµãʱÔÝÍ££º

run

µÇ¼ºó¸´ÖÆ

6. ¼ì²é±äÁ¿

Ôڶϵ㴦£¬Ê¹ÓÃÒÔÏÂÏÂÁî¼ì²é±äÁ¿Öµ£º

print 

µÇ¼ºó¸´ÖÆ

7. ²½¹ý/²½Èë/²½³ö

  • next£º²½¹ýÄ¿½ñÐС£
  • step£º²½È뺯ÊýŲÓá£
  • finish£º²½³öÄ¿½ñº¯Êý¡£

8. Éó²éŲÓÿÍÕ»

ʹÓÃÒÔÏÂÏÂÁîÉó²éÄ¿½ñŲÓÿÍÕ»£º

backtrace

µÇ¼ºó¸´ÖÆ

9. Í˳ö gdb

ʹÓÃÒÔÏÂÏÂÁîÍ˳ö gdb£º

quit

µÇ¼ºó¸´ÖÆ

ÒÔÉϾÍÊÇgdbµ÷ÊÔÒªÁì gdbµ÷ÊÔÒªÁìÏêϸ°ì·¨Ïê½âµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ