尊龙凯时人生就是博

gdbµ÷ÊÔ¹¤¾ßµÄʹÓÃ

gdbÊÇÒ»¿îÓÃÓÚµ÷ÊÔc¡¢c++µÈÓïÑÔ³ÌÐòµÄÇ¿Ê¢ÏÂÁîÐй¤¾ß£¬¿ÉÈóÌÐòÔ±ÔÚÖ´ÐÐÀú³ÌÖмàÊӺͿØÖƳÌÐòÁ÷£¬ÒÔ±ãʶ±ð²¢ÐÞ¸´¹ýʧ ¡£³£¼ûÏÂÁî°üÀ¨£ºÉèÖöϵ㣺break [ÐкÅ]×îÏȵ÷ÊÔ£ºrun´òÓ¡±äÁ¿Öµ£ºp [±äÁ¿Ãû]ÖðÐÐÖ´ÐдúÂ룺nµ¥²½½øÈ뺯Êý£ºs´òӡŲÓÿÍÕ»£ºbt

gdbµ÷ÊÔ¹¤¾ßµÄʹÓÃ

ʲôÊÇgdb £¿

gdb£¨GNUµ÷ÊÔÆ÷£©ÊÇÒ»¸öÇ¿Ê¢µÄÏÂÁîÐй¤¾ß£¬ÓÃÓÚµ÷ÊÔC¡¢C++¡¢FortranµÈ¶àÖÖ±à³ÌÓïÑԵijÌÐò ¡£ËüÊÇLinuxºÍUnixϵͳÖÐÆÕ±éʹÓõĵ÷ÊÔÇéÐÎ ¡£

gdbµÄÓÃ;

gdbÔÊÐí³ÌÐòÔ±ÔÚ³ÌÐòÖ´ÐÐÀú³ÌÖмàÊӺͿØÖƳÌÐòµÄÖ´ÐÐÁ÷£¬ÒÔ±ãʶ±ðºÍÐÞ¸´¹ýʧ ¡£ËüÌṩÁËһϵÁÐÏÂÁÓÃÓÚ£º

  • ÉèÖöϵãÒÔÔÚÌض¨µãÔÝÍ£³ÌÐò
  • ¼ì²é±äÁ¿µÄÖµºÍÊý¾Ý½á¹¹
  • ÖðÐÐÖ´ÐдúÂë²¢ÉèÖÃÊÓ²ìµã
  • ´òӡŲÓÿÍÕ»ºÍ¼Ä´æÆ÷Öµ
  • ÐÞ¸ÄÄÚ´æºÍ¼Ä´æÆ÷Öµ

ʹÓÃgdb

  1. Æô¶¯gdb

    gdb [program_name]

    µÇ¼ºó¸´ÖÆ

  2. ÉèÖöϵã

    break [line_number]

    µÇ¼ºó¸´ÖÆ

  3. ×îÏȵ÷ÊÔ

    run

    µÇ¼ºó¸´ÖÆ

  4. Ö´ÐÐÏÂÁî

    ÔÚgdb¿ØÖÆ̨ÖУ¬Äú¿ÉÒÔʹÓÃÏÂÁîÀ´¼ì²é±äÁ¿¡¢ÉèÖÃÊÓ²ìµã¡¢Ð޸Ĵ洢Æ÷µÈ ¡£ÒÔÏÂÊÇһЩ³£¼ûÏÂÁ

    • n£ºÖðÐÐÖ´ÐдúÂë
    • p£º´òÓ¡±äÁ¿µÄÖµ
    • w£ºÉèÖÃÊÓ²ìµã
    • x£º¼ì²é´æ´¢Æ÷
    • s£ºµ¥²½½øÈ뺯Êý
    • bt£º´òӡŲÓÿÍÕ»
  5. Í˳ögdb

    quit

    µÇ¼ºó¸´ÖÆ

ʾÀý

¼ÙÉèÎÒÃÇÓÐÒ»¸öÃûΪmy_program.cµÄ³ÌÐò£¬ÆäÖаüÀ¨Ò»¸ö°üÀ¨¹ýʧµÄº¯Êý£º

#include <stdio.h>

int divide_by_zero(int a) {
  return a / 0;
}

int main() {
  int x = 5;
  printf("%d\n", divide_by_zero(x));
  return 0;
}</stdio.h>

µÇ¼ºó¸´ÖÆ

ÎÒÃÇ¿ÉÒÔʹÓÃgdbÀ´µ÷ÊÔÕâ¸ö³ÌÐò£º

gdb my_program
(gdb) break 11
(gdb) run
(gdb) list 10,15
10  #include <stdio.h>
11  int divide_by_zero(int a) {
12    return a / 0;
13  }
14  
15  int main() {
(gdb) p divide_by_zero(x)
Can't read variable x in this context.
(gdb) p x
$1 = 5
(gdb) n
Program received signal SIGFPE, Arithmetic exception.
0x0000000000400595 in divide_by_zero (a=5) at my_program.c:12
12          return a / 0;
(gdb) list
11  int divide_by_zero(int a) {
12    return a / 0;
13  }
14  
15  int main() {
(gdb) print a
$2 = 5
(gdb) quit</stdio.h>

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄʾÀýÖУ¬ÎÒÃÇÔÚµÚ11ÐÐÉèÖÃÁËÒ»¸ö¶Ïµã£¬È»ºóÔËÐгÌÐò ¡£µ±³ÌÐòÔڶϵ㴦ÔÝͣʱ£¬ÎÒÃÇ´òÓ¡Á˱äÁ¿xµÄÖµ£¬²¢ÊµÑé´òÓ¡divide_by_zero(x)µÄÖµ ¡£ÓÉÓÚxÔÚdivide_by_zeroº¯ÊýÖÐδ½ç˵£¬Òò´ËÎÒÃÇ¿´µ½ÁËÒ»¸ö¹ýʧ ¡£½ÓÏÂÀ´£¬ÎÒÃÇÖðÐÐÖ´ÐдúÂ룬ֱµ½³ÌÐòÍ߽⣬Ȼºó´òÓ¡Á˹ýʧÐÅÏ¢ºÍŲÓÿÍÕ» ¡£

ÒÔÉϾÍÊÇgdbµ÷ÊÔ¹¤¾ßµÄʹÓõÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是博

18523999891

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

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

QR code
sitemap¡¢ÍøÕ¾µØͼ