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

LinuxÏÂʹÓÃGDB¾ÙÐе÷ÊԵĻù±¾ÉèÖÃÖ¸ÄÏ

linuxÏÂʹÓÃgdb¾ÙÐе÷ÊԵĻù±¾ÉèÖÃÖ¸ÄÏ

СÐò£º

´úÂëµ÷ÊÔÊÇÈí¼þ¿ª·¢Àú³ÌÖв»¿É»òȱµÄÒ»²½£¬Ëü¿ÉÒÔ×ÊÖú¿ª·¢Ö°Ô±¶¨Î»Ï¢Õù¾öÎÊÌâ¡£ÔÚLinuxÇéÐÎÏ£¬GDB£¨GNUµ÷ÊÔÆ÷£©ÊÇÒ»¿î¹¦Ð§Ç¿Ê¢µÄµ÷ÊÔ¹¤¾ß£¬¿ÉÓÃÓÚµ÷ÊÔC¡¢C++µÈ±à³ÌÓïÑÔ¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚLinuxÇéÐÎÏÂÉèÖúÍʹÓÃGDB¾ÙÐдúÂëµ÷ÊÔ£¬²¢ÌṩһЩ³£ÓÃÖ¸ÁîºÍʾÀý¡£

Ò»¡¢×°ÖÃGDB

ÔÚÖÕ¶ËÖÐÊäÈëÒÔÏÂÏÂÁîÒÔ×°ÖÃGDB£º

sudo apt-get install gdb

µÇ¼ºó¸´ÖÆ

×°ÖÃÍê³Éºó£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÑéÖ¤GDBÊÇ·ñÀÖ³É×°Öãº

gdb --version

µÇ¼ºó¸´ÖÆ

¶þ¡¢±àÒë´úÂëÒÔÖ§³Öµ÷ÊÔ

ÔÚ±àÒë´úÂëʱ£¬ÐèÒªÌí¼Ó-g²ÎÊýÒÔÖ§³Öµ÷ÊÔ¡£ÀýÈ磬¹ØÓÚCÓïÑԵĴúÂ룬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁî±àÒ룺

gcc -g -o program program.c

µÇ¼ºó¸´ÖÆ

Õ⽫ÌìÉúÒ»¸ö¿ÉÖ´ÐÐÎļþprogram£¬ÆäÖаüÀ¨µ÷ÊÔÐÅÏ¢¡£

Èý¡¢Æô¶¯GDBµ÷ÊÔÆ÷

ÔÚÖÕ¶ËÖÐÊäÈëÒÔÏÂÏÂÁîÒÔÆô¶¯GDBµ÷ÊÔÆ÷£º

gdb program

µÇ¼ºó¸´ÖÆ

ÕâÀïµÄprogramÊÇÐèÒªµ÷ÊԵĿÉÖ´ÐÐÎļþÃû¡£

ËÄ¡¢É趨¶Ïµã

ÔÚGDBÖУ¬¶ÏµãÓÃÓÚÖ¸¶¨³ÌÐòÖ´ÐÐÀú³ÌÖеÄ×èÖ¹µã£¬ÒÔ±ã¾ÙÐе÷ÊÔ¡£¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÔÚ´úÂëÖÐÉ趨¶Ïµã£º

break ÎļþÃû:ÐкÅ

µÇ¼ºó¸´ÖÆ

ÀýÈ磬ÔÚ´úÂëµÄµÚ10ÐÐÉ趨¶Ïµã£º

break program.c:10

µÇ¼ºó¸´ÖÆ

Îå¡¢ÔËÐгÌÐò

ʹÓÃÒÔÏÂÏÂÁîÔËÐгÌÐò£º

run

µÇ¼ºó¸´ÖÆ

³ÌÐòÔËÐк󣬻áÔÚÉ趨µÄ¶Ïµã´¦×èÖ¹Ö´ÐС£

Áù¡¢Éó²é±äÁ¿Öµ

ÔÚµ÷ÊÔÀú³ÌÖУ¬¾­³£ÐèÒªÉó²é±äÁ¿µÄÖµÒÔ×ÊÖú¶¨Î»ÎÊÌâ¡£¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÉó²é±äÁ¿Öµ£º

print ±äÁ¿Ãû

µÇ¼ºó¸´ÖÆ

ÀýÈ磬Éó²é±äÁ¿xµÄÖµ£º

print x

µÇ¼ºó¸´ÖÆ

Æß¡¢µ¥²½Ö´ÐÐ

µ¥²½Ö´ÐÐÊÇÖ¸ÖðÐÐÖ´ÐгÌÐò£¬²¢Éó²éÿÐдúÂëµÄÖ´ÐÐЧ¹û¡£ÒÔÏÂÊdz£Óõĵ¥²½Ö´ÐÐÏÂÁ

next£ºÖ´ÐÐÏÂÒ»ÐдúÂ룬µ«²»»á½øÈ뺯ÊýÄÚ²¿£»

step£ºÖ´ÐÐÏÂÒ»ÐдúÂ룬²¢½øÈ뺯ÊýÄÚ²¿£»

finish£ºÖ´ÐÐÍêÕû¸öº¯Êý£¬È»ºó×èÖ¹¡£

°Ë¡¢¼ÌÐøÖ´ÐгÌÐò

ÔÚGDBÖУ¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁî¼ÌÐøÖ´ÐгÌÐò£º

continue

µÇ¼ºó¸´ÖÆ

³ÌÐò»á¼ÌÐøÖ´ÐУ¬Ö±µ½Óöµ½ÏÂÒ»¸ö¶Ïµã»ò³ÌÐò¿¢Ê¡£

¾Å¡¢Í˳öGDBµ÷ÊÔÆ÷

ÔÚGDBµ÷ÊÔ¿¢Êºó£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÍ˳ö£º

quit

µÇ¼ºó¸´ÖÆ

´úÂëʾÀý£º

ÏÂÃæÊÇÒ»¸ö¼òÆÓµÄC´úÂëʾÀý£¬ÓÃÓÚÑÝʾGDBµÄµ÷ÊÔÀú³Ì¡£

#include <stdio.h>

int main() {
    int x = 10;

    printf("xµÄ³õʼֵ£º%d
", x);

    x += 5;

    printf("xµÄÖµÔöÌíºó£º%d
", x);

    return 0;
}

µÇ¼ºó¸´ÖÆ

¼ÙÉèÉúÑÄΪprogram.cÎļþ£¬²¢Ê¹ÓÃÉÏÊöÌáµ½µÄ±àÒëÏÂÁî¾ÙÐбàÒ롣Ȼºó¿ÉÒÔƾ֤ÒÔÉÏ°ì·¨Æô¶¯GDBµ÷ÊÔÆ÷£¬²¢¾ÙÐе÷ÊÔ²Ù×÷¡£

×ܽ᣺

±¾ÎÄÏÈÈÝÁËÔÚLinuxÇéÐÎÏÂʹÓÃGDB¾ÙÐдúÂëµ÷ÊԵĻù±¾ÉèÖúͳ£ÓÃÖ¸Áͨ¹ýºÏÀíʹÓÃGDB£¬¿ª·¢Ö°Ô±¿ÉÒÔ¸ü¸ßЧµØ¶¨Î»Ï¢Õù¾ö´úÂëÖеÄÎÊÌ⡣ϣÍû±¾ÎĶԳõѧÕßÓÐËù×ÊÖú£¬²¢ÄÜΪ¸÷ÈËÕÆÎÕLinuxϵ÷ÊÔ¹¤¾ßÌṩָµ¼¡£

£¨×Ü×ÖÊý£º684×Ö£©

ÒÔÉϾÍÊÇLinuxÏÂʹÓÃGDB¾ÙÐе÷ÊԵĻù±¾ÉèÖÃÖ¸ÄϵÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

QR code
ÍøÕ¾µØͼ