gdbµ÷ÊÔÉó²é±äÁ¿ÖµµÄÏÂÁî
gdb ÖÐÉó²é±äÁ¿ÖµµÄÏÂÁîÓУºprint £ºÖ±½Ó´òÓ¡±äÁ¿Öµ¡£p £º´òÓ¡±í´ïʽÖбäÁ¿µÄÖµ¡£display £ÔÃĿε÷ÊÔÆ÷×èֹʱ´òÓ¡±äÁ¿µÄÖµ¡£watch £º±äÁ¿Öµ×ª±äʱÌìÉú֪ͨ¡£
gdbÉó²é±äÁ¿ÖµµÄÏÂÁî
ÔÚGDBµ÷ÊÔÆ÷ÖУ¬Óм¸¸öÏÂÁî¿ÉÒÔÓÃÀ´Éó²é±äÁ¿µÄÖµ£º
- print £ºÖ±½Ó´òÓ¡±äÁ¿µÄÖµ¡£
- p £º´òÓ¡±í´ïʽÖбäÁ¿µÄÖµ¡£
- display £ºÔÚÿ´Îµ÷ÊÔÆ÷×èֹʱ´òÓ¡±äÁ¿µÄÖµ¡£
- watch £ºÔÚ±äÁ¿µÄÖµ±¬·¢×ª±äʱÌìÉú֪ͨ¡£
ʾÀý
¼ÙÉèÎÒÃÇÓÐÒ»¸öÃûΪ my_array µÄÕûÊýÊý×飺
int my_array[] = {1, 2, 3, 4, 5};
µÇ¼ºó¸´ÖÆ
ʹÓà print ÏÂÁî
ÎÒÃÇ¿ÉÒÔʹÓà print ÏÂÁîÖ±½Ó´òÓ¡Êý×éÔªËصÄÖµ£º
(gdb) print my_array[0] $1 = 1
µÇ¼ºó¸´ÖÆ
ʹÓà p ÏÂÁî
ÎÒÃÇ»¹¿ÉÒÔʹÓà p ÏÂÁî´òÓ¡Êý×éÖÐËùÓÐÔªËصÄÖµ£º
(gdb) p my_array $2 = {1, 2, 3, 4, 5}
µÇ¼ºó¸´ÖÆ
ʹÓà display ÏÂÁî
ÎÒÃÇ¿ÉÒÔʹÓà display ÏÂÁîÔÚÿ´Îµ÷ÊÔÆ÷×èֹʱ´òÓ¡Êý×éÔªËصÄÖµ£º
(gdb) display my_array[0] Display of variable my_array[0] = 1
µÇ¼ºó¸´ÖÆ
ʹÓà watch ÏÂÁî
ÎÒÃÇ¿ÉÒÔʹÓà watch ÏÂÁîÔÚ±äÁ¿ my_array[0] µÄÖµ±¬·¢×ª±äʱÌìÉú֪ͨ£º
(gdb) watch my_array[0] Hardware watchpoint 1: my_array[0] Watchpoint 1: my_array[0] Old value = 1 New value = 2
µÇ¼ºó¸´ÖÆ
ÒÔÉϾÍÊÇgdbµ÷ÊÔÉó²é±äÁ¿ÖµµÄÏÂÁîµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡
ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£