ºìÁªLinuxÃÅ»§
Linux°ïÖú

gdbµ÷ÊÔ

·¢²¼Ê±¼ä:2010-03-07 12:57:37À´Ô´:ºìÁª×÷Õß:lele200882
Ò»£ºÁÐÎļþÇåµ¥
1£® List
(gdb) list line1,line2
¶þ£ºÖ´ÐгÌÐò
ÒªÏëÔËÐÐ×¼±¸µ÷ÊԵijÌÐò£¬¿ÉʹÓÃrunÃüÁÔÚËüºóÃæ¿ÉÒÔ¸úËæ·¢¸ø¸Ã³ÌÐòµÄÈκβÎÊý£¬°üÀ¨±ê×¼ÊäÈëºÍ±ê×¼Êä³ö˵Ã÷·û()ºÍÍâ¿ÇͨÅä·û£¨*¡¢£¿¡¢[¡¢]£©ÔÚÄÚ¡£
Èç¹ûÄãʹÓò»´ø²ÎÊýµÄrunÃüÁgdb¾ÍÔÙ´ÎʹÓÃÄã¸øÓèÇ°Ò»ÌõrunÃüÁîµÄ²ÎÊý£¬ÕâÊǺÜÓÐÓõġ£
ÀûÓÃset args ÃüÁî¾Í¿ÉÒÔÐ޸ķ¢Ë͸ø³ÌÐòµÄ²ÎÊý£¬¶øʹÓÃshow args ÃüÁî¾Í¿ÉÒԲ鿴Æäȱʡ²ÎÊýµÄÁÐ±í¡£
£¨gdb£©set args -b -x
(gdb) show args
backtraceÃüÁîΪ¶ÑÕ»ÌṩÏòºó¸ú×Ù¹¦ÄÜ¡£
Backtrace ÃüÁî²úÉúÒ»ÕÅÁÐ±í£¬°üº¬×Å´Ó×î½üµÄ¹ý³Ì¿ªÊ¼µÄËùÒÔÓÐЧ¹ý³ÌºÍµ÷ÓÃÕâЩ¹ý³ÌµÄ²ÎÊý¡£
Èý£ºÏÔʾÊý¾Ý
ÀûÓÃprint ÃüÁî¿ÉÒÔ¼ì²é¸÷¸ö±äÁ¿µÄÖµ¡£
(gdb) print p (pΪ±äÁ¿Ãû)
whatis ÃüÁî¿ÉÒÔÏÔʾij¸ö±äÁ¿µÄÀàÐÍ
(gdb) whatis p
type = int *
print ÊÇgdbµÄÒ»¸ö¹¦ÄܺÜÇ¿µÄÃüÁÀûÓÃËü¿ÉÒÔÏÔʾ±»µ÷ÊÔµÄÓïÑÔÖÐÈκÎÓÐЧµÄ±í´ïʽ¡£±í´ïʽ³ýÁË°üº¬Äã³ÌÐòÖеıäÁ¿Í⣬»¹¿ÉÒÔ°üº¬ÒÔÏÂÄÚÈÝ£º
l ¶Ô³ÌÐòÖк¯ÊýµÄµ÷ÓÃ
(gdb) print find_entry(1,0)
l Êý¾Ý½á¹¹ºÍÆäËû¸´ÔÓ¶ÔÏó
(gdb) print *table_start
$8={e=reference=¡¯\000¡¯,location=0x0,next=0x0}
l ÖµµÄÀúÊ·³É·Ö
(gdb)print $1 ($1ΪÀúÊ·¼Ç¼±äÁ¿,ÔÚÒÔºó¿ÉÒÔÖ±½ÓÒýÓà $1 µÄÖµ)
l ÈËΪÊý×é
ÈËΪÊý×éÌṩÁËÒ»ÖÖÈ¥ÏÔʾ´æ´¢Æ÷¿é£¨Êý×é½Ú»ò¶¯Ì¬·ÖÅäµÄ´æ´¢Çø£©ÄÚÈݵķ½·¨¡£ÔçÆڵĵ÷ÊÔ³ÌÐòûÓкܺõķ½·¨½«ÈÎÒâµÄÖ¸Õë»»³ÉÒ»¸öÊý×é¡£¾ÍÏñ¶Ô´ý²ÎÊýÒ»Ñù£¬ÈÃÎÒÃDz鿴ÄÚ´æÖÐÔÚ±äÁ¿hºóÃæµÄ10¸öÕûÊý£¬Ò»¸ö¶¯Ì¬Êý×éµÄÓï·¨ÈçÏÂËùʾ£º
base@length
Òò´Ë£¬ÒªÏëÏÔʾÔÚhºóÃæµÄ10¸öÔªËØ£¬¿ÉÒÔʹÓÃh@10£º
(gdb)print h@10
$13=(-1,345,23,-234,0,0,0,98,345,10)
ËÄ£º
¶Ïµã
(breakpoint)
breakÃüÁ¿ÉÒÔ¼òдΪb£©¿ÉÒÔÓÃÀ´ÔÚµ÷ÊԵijÌÐòÖÐÉèÖöϵ㣬¸ÃÃüÁîÓÐÈçÏÂËÄÖÖÐÎʽ£º
l break line-number ʹ³ÌÐòÇ¡ºÃÔÚÖ´Ðиø¶¨ÐÐ֮ǰֹͣ¡£
l break function-name ʹ³ÌÐòÇ¡ºÃÔÚ½øÈëÖ¸¶¨µÄº¯Êý֮ǰֹͣ¡£
l break line-or-function if condition Èç¹ûcondition£¨Ìõ¼þ£©ÊÇÕ棬³ÌÐòµ½´ïÖ¸¶¨Ðлòº¯Êýʱֹͣ¡£
l break routine-name ÔÚÖ¸¶¨Àý³ÌµÄÈë¿Ú´¦ÉèÖöϵã
Èç¹û¸Ã³ÌÐòÊÇÓɺܶàÔ­Îļþ¹¹³ÉµÄ£¬Äã¿ÉÒÔÔÚ¸÷¸öÔ­ÎļþÖÐÉèÖöϵ㣬¶ø²»ÊÇÔÚµ±Ç°µÄÔ­ÎļþÖÐÉèÖöϵ㣬Æä·½·¨ÈçÏ£º
(gdb) break filename:line-number
(gdb) break filename:function-name
ÒªÏëÉèÖÃÒ»¸öÌõ¼þ¶Ïµã£¬¿ÉÒÔÀûÓÃbreak ifÃüÁÈçÏÂËùʾ£º
(gdb) break line-or-function if expr
Àý£º
(gdb) break 46 if testsize==100
´Ó¶Ïµã¼ÌÐøÔËÐУºcountinue ÃüÁî
Î壮¶ÏµãµÄ¹ÜÀí
1£® ÏÔʾµ±Ç°gdbµÄ¶ÏµãÐÅÏ¢£º
(gdb) info break
Ëû»áÒÔÈçϵÄÐÎʽÏÔʾËùÓеĶϵãÐÅÏ¢£º
Num Type Disp Enb Address What
1 breakpoint keep y 0x000028bc in init_random at qsort2.c:155
2 breakpoint keep y 0x0000291c in init_organ at qsort2.c:168
(gdb)
2.ɾ³ýÖ¸¶¨µÄij¸ö¶Ïµã£º
(gdb) delete breakpoint 1
¸ÃÃüÁ»áɾ³ý±àºÅΪ1µÄ¶Ïµã£¬Èç¹û²»´ø±àºÅ²ÎÊý£¬½«É¾³ýËùÓеĶϵã
(gdb) delete breakpoint
3.½ûֹʹÓÃij¸ö¶Ïµã
(gdb) disable breakpoint 1
¸ÃÃüÁ½ûÖ¹¶Ïµã 1,ͬʱ¶ÏµãÐÅÏ¢µÄ (Enb)Óò½«±äΪ n
4£®ÔÊÐíʹÓÃij¸ö¶Ïµã
(gdb) enable breakpoint 1
¸ÃÃüÁÔÊÐí¶Ïµã 1,ͬʱ¶ÏµãÐÅÏ¢µÄ (Enb)Óò½«±äΪ y
5£®Çå³ýÔ­ÎļþÖÐijһ´úÂëÐÐÉϵÄËùÓжϵã
(gdb)clean number
×¢£ºnumber ΪԭÎļþµÄij¸ö´úÂëÐеÄÐкÅ
Áù£®±äÁ¿µÄ¼ì²éºÍ¸³Öµ
l whatis:ʶ±ðÊý×é»ò±äÁ¿µÄÀàÐÍ
l ptype:±ÈwhatisµÄ¹¦ÄܸüÇ¿£¬Ëû¿ÉÒÔÌṩһ¸ö½á¹¹µÄ¶¨Òå
l set variable:½«Öµ¸³Óè±äÁ¿
l print ³ýÁËÏÔʾһ¸ö±äÁ¿µÄÖµÍ⣬»¹¿ÉÒÔÓÃÀ´¸³Öµ
Æߣ®µ¥²½Ö´ÐÐ
l next
²»½øÈëµÄµ¥²½Ö´ÐÐ
l step
½øÈëµÄµ¥²½Ö´ÐÐ
Èç¹ûÒѾ­½øÈëÁËijº¯Êý£¬¶øÏëÍ˳ö¸Ãº¯Êý·µ»Øµ½ËüµÄµ÷Óú¯ÊýÖУ¬¿ÉʹÓÃÃüÁîfinish
°Ë£®º¯ÊýµÄµ÷ÓÃ
l call name µ÷ÓúÍÖ´ÐÐÒ»¸öº¯Êý
(gdb) call gen_and_sork( 1234,1,0 )
(gdb) call printf(¡°abcd¡±)
$1=4
l finish ½áÊøÖ´Ðе±Ç°º¯Êý£¬ÏÔʾÆä·µ»ØÖµ£¨Èç¹ûÓеĻ°£©
¾Å£®»úÆ÷ÓïÑÔ¹¤¾ß
ÓÐÒ»×éרÓõÄgdb±äÁ¿¿ÉÒÔÓÃÀ´¼ì²éºÍÐ޸ļÆËã»úµÄͨÓüĴæÆ÷£¬gdbÌṩÁËĿǰÿһ̨¼ÆËã»úÖÐʵ¼ÊʹÓõÄ4¸ö¼Ä´æÆ÷µÄ±ê×¼Ãû×Ö£º
l $pc £º ³ÌÐò¼ÆÊýÆ÷
l $fp £º Ö¡Ö¸Õ루µ±Ç°¶ÑÕ»Ö¡£©
l $sp £º Õ»Ö¸Õë
l $ps £º ´¦ÀíÆ÷״̬
Ê®£®ÐźÅ
gdb ͨ³£¿ÉÒÔ²¶×½µ½·¢Ë͸øËüµÄ´ó¶àÊýÐźţ¬Í¨¹ý²¶×½Ðźţ¬Ëü¾Í¿É¾ö¶¨¶ÔÓÚÕýÔÚÔËÐеĽø³ÌÒª×öЩʲô¹¤×÷¡£ÀýÈ磬°´CTRL-C½«ÖжÏÐźŷ¢Ë͸øgdb£¬Í¨³£¾Í»áÖÕÖ¹gdb¡£µ«ÊÇÄã»òÐí²»ÏëÖжÏgdb£¬ÕæÕýµÄÄ¿µÄÊÇÒªÖжÏgdbÕýÔÚÔËÐеijÌÐò£¬Òò´Ë£¬gdbҪץס¸ÃÐźŲ¢Í£Ö¹ËüÕýÔÚÔËÐеijÌÐò£¬ÕâÑù¾Í¿ÉÒÔÖ´ÐÐijЩµ÷ÊÔ²Ù×÷¡£
HandleÃüÁî¿É¿ØÖÆÐźŵĴ¦Àí£¬ËûÓÐÁ½¸ö²ÎÊý£¬Ò»¸öÊÇÐźÅÃû£¬ÁíÒ»¸öÊǽÓÊܵ½ÐźÅʱ¸Ã×÷ʲô¡£¼¸ÖÖ¿ÉÄܵIJÎÊýÊÇ£º
l nostop ½ÓÊÕµ½ÐźÅʱ£¬²»Òª½«Ëü·¢Ë͸ø³ÌÐò£¬Ò²²»ÒªÍ£Ö¹³ÌÐò¡£
l stop ½ÓÊܵ½ÐźÅʱֹͣ³ÌÐòµÄÖ´ÐУ¬´Ó¶øÔÊÐí³ÌÐòµ÷ÊÔ£»ÏÔʾһÌõ±íʾÒѽÓÊܵ½ÐźŵÄÏûÏ¢£¨½ûֹʹÓÃÏûÏ¢³ýÍ⣩
l print ½ÓÊܵ½ÐźÅʱÏÔʾһÌõÏûÏ¢
l noprint ½ÓÊܵ½ÐźÅʱ²»ÒªÏÔʾÏûÏ¢£¨¶øÇÒÒþº¬×Ų»Í£Ö¹³ÌÐòÔËÐУ©
l pass ½«Ðźŷ¢Ë͸ø³ÌÐò£¬´Ó¶øÔÊÐíÄãµÄ³ÌÐòÈ¥´¦ÀíËü¡¢Í£Ö¹ÔËÐлò²ÉÈ¡±ðµÄ¶¯×÷¡£
l nopass Í£Ö¹³ÌÐòÔËÐУ¬µ«²»Òª½«Ðźŷ¢Ë͸ø³ÌÐò¡£
ÀýÈ磬¼Ù¶¨Äã½Ø»ñSIGPIPEÐźţ¬ÒÔ·ÀÖ¹ÕýÔÚµ÷ÊԵijÌÐò½ÓÊܵ½¸ÃÐźţ¬¶øÇÒÖ»Òª¸ÃÐźÅÒ»µ½´ï£¬¾ÍÒªÇó¸Ã³ÌÐòÍ£Ö¹£¬²¢Í¨ÖªÄã¡£ÒªÍê³ÉÕâÒ»ÈÎÎñ£¬¿ÉÀûÓÃÈçÏÂÃüÁ
(gdb) handle SIGPIPE stop print
Çë×¢Ò⣬UNIXµÄÐźÅÃû×ÜÊDzÉÓôóд×Öĸ£¡Äã¿ÉÒÔÓÃÐźűàºÅÌæ´úÐźÅÃû
Èç¹ûÄãµÄ³ÌÐòÒªÖ´ÐÐÈκÎÐźŴ¦Àí²Ù×÷£¬¾ÍÐèÒªÄܹ»²âÊÔÆäÐźŴ¦Àí³ÌÐò£¬Îª´Ë£¬¾ÍÐèÒªÒ»ÖÖÄܽ«Ðźŷ¢Ë͸ø³ÌÐòµÄ¼ò±ã·½·¨£¬Õâ¾ÍÊÇsignalÃüÁîµÄÈÎÎñ¡£¸ÃÃüÁîµÄ²ÎÊýÊÇÒ»¸öÊý×Ö»òÕßÒ»¸öÃû×Ö£¬ÈçSIGINT¡£¼Ù¶¨ÄãµÄ³ÌÐòÒѽ«Ò»¸öרÓõÄSIGINT£¨¼üÅÌÊäÈ룬»òCTRL-C£»ÐźÅ2£©ÐźŴ¦Àí³ÌÐòÉèÖóɲÉȡij¸öÇåÀí¶¯×÷£¬ÒªÏë²âÊÔ¸ÃÐźŴ¦Àí³ÌÐò£¬Äã¿ÉÒÔÉèÖÃÒ»¸ö¶Ïµã²¢Ê¹ÓÃÈçÏÂÃüÁ
£¨gdb£© signal 2
continuing with signal SIGINT(2)
¸Ã³ÌÐò¼ÌÐøÖ´ÐУ¬µ«ÊÇÁ¢¼´´«Êä¸ÃÐźţ¬¶øÇÒ´¦Àí³ÌÐò¿ªÊ¼ÔËÐÐ.
ʮһ. Ô­ÎļþµÄËÑË÷
search text:¸ÃÃüÁî¿ÉÏÔʾÔÚµ±Ç°ÎļþÖаüº¬text´®µÄÏÂÒ»ÐС£
Reverse-search text:¸ÃÃüÁî¿ÉÒÔÏÔʾ°üº¬text µÄÇ°Ò»ÐС£
Ê®¶þ.UNIX½Ó¿Ú
shell ÃüÁî¿ÉÆô¶¯UNIXÍâ¿Ç£¬CTRL-DÍ˳öÍâ¿Ç£¬·µ»Øµ½ gdb.
Ê®Èý.ÃüÁîµÄÀúÊ·
ΪÁËÔÊÐíʹÓÃÀúÊ·ÃüÁ¿ÉʹÓà set history expansion on ÃüÁî
(gdb) set history expansion on
С½á£º³£ÓõÄgdbÃüÁî
backtrace ÏÔʾ³ÌÐòÖеĵ±Ç°Î»ÖúͱíʾÈçºÎµ½´ïµ±Ç°Î»ÖõÄÕ»¸ú×Ù£¨Í¬Òå´Ê£ºwhere£©
breakpoint ÔÚ³ÌÐòÖÐÉèÖÃÒ»¸ö¶Ïµã
cd ¸Ä±äµ±Ç°¹¤×÷Ŀ¼
clear ɾ³ý¸Õ²ÅÍ£Ö¹´¦µÄ¶Ïµã
commands ÃüÖжϵãʱ£¬Áгö½«ÒªÖ´ÐеÄÃüÁî
continue ´Ó¶Ïµã¿ªÊ¼¼ÌÐøÖ´ÐÐ
delete ɾ³ýÒ»¸ö¶Ïµã»ò¼à²âµã£»Ò²¿ÉÓëÆäËûÃüÁîÒ»ÆðʹÓÃ
display ³ÌÐòֹͣʱÏÔʾ±äÁ¿ºÍ±í´ïʱ
down ÏÂÒÆÕ»Ö¡£¬Ê¹µÃÁíÒ»¸öº¯Êý³ÉΪµ±Ç°º¯Êý
frame Ñ¡ÔñÏÂÒ»ÌõcontinueÃüÁîµÄÖ¡
info ÏÔʾÓë¸Ã³ÌÐòÓйصĸ÷ÖÖÐÅÏ¢
jump ÔÚÔ´³ÌÐòÖеÄÁíÒ»µã¿ªÊ¼ÔËÐÐ
kill Òì³£ÖÕÖ¹ÔÚgdb ¿ØÖÆÏÂÔËÐеijÌÐò
list ÁгöÏàÓ¦ÓÚÕýÔÚÖ´ÐеijÌÐòµÄÔ­ÎļþÄÚÈÝ
next Ö´ÐÐÏÂÒ»¸öÔ´³ÌÐòÐУ¬´Ó¶øÖ´ÐÐÆäÕûÌåÖеÄÒ»¸öº¯Êý
print ÏÔʾ±äÁ¿»ò±í´ïʽµÄÖµ
pwd ÏÔʾµ±Ç°¹¤×÷Ŀ¼
pype ÏÔʾһ¸öÊý¾Ý½á¹¹£¨ÈçÒ»¸ö½á¹¹»òC++ÀࣩµÄÄÚÈÝ
quit Í˳ögdb
reverse-search ÔÚÔ´ÎļþÖз´ÏòËÑË÷Õý¹æ±í´ïʽ
run Ö´ÐиóÌÐò
search ÔÚÔ´ÎļþÖÐËÑË÷Õý¹æ±í´ïʽ
set variable ¸ø±äÁ¿¸³Öµ
signal ½«Ò»¸öÐźŷ¢Ë͵½ÕýÔÚÔËÐеĽø³Ì
step Ö´ÐÐÏÂÒ»¸öÔ´³ÌÐòÐУ¬±ØҪʱ½øÈëÏÂÒ»¸öº¯Êý
undisplay displayÃüÁîµÄ·´ÃüÁ²»ÒªÏÔʾ±í´ïʽ
until ½áÊøµ±Ç°Ñ­»·
up ÉÏÒÆÕ»Ö¡£¬Ê¹ÁíÒ»º¯Êý³ÉΪµ±Ç°º¯Êý
watch ÔÚ³ÌÐòÖÐÉèÖÃÒ»¸ö¼à²âµã£¨¼´Êý¾Ý¶Ïµã£©
whatis ÏÔʾ±äÁ¿»òº¯ÊýÀàÐÍ
****************************************************
¡¡GNUµÄµ÷ÊÔÆ÷³ÆΪgdb£¬¸Ã³ÌÐòÊÇÒ»¸ö½»»¥Ê½¹¤¾ß£¬¹¤×÷ÔÚ×Ö·ûģʽ¡£ÔÚ X Window ϵͳÖУ¬ÓÐÒ»¸ögdbµÄÇ°¶ËͼÐι¤¾ß£¬³ÆΪxxgdb¡£gdb Êǹ¦ÄÜÇ¿´óµÄµ÷ÊÔ³ÌÐò£¬¿ÉÍê³ÉÈçϵĵ÷ÊÔÈÎÎñ£º
¡¡¡¡* ÉèÖöϵ㣻
¡¡¡¡* ¼àÊÓ³ÌÐò±äÁ¿µÄÖµ£»
¡¡¡¡* ³ÌÐòµÄµ¥²½Ö´ÐУ»
¡¡¡¡* Ð޸ıäÁ¿µÄÖµ¡£
¡¡¡¡ÔÚ¿ÉÒÔʹÓà gdb µ÷ÊÔ³ÌÐò֮ǰ£¬±ØÐëʹÓà -g Ñ¡Ïî±àÒëÔ´Îļþ¡£¿ÉÔÚ makefile ÖÐÈç϶¨Òå CFLAGS ±äÁ¿£º
¡¡¡¡ CFLAGS = -g
¡¡¡¡ ÔËÐÐ gdb µ÷ÊÔ³ÌÐòʱͨ³£Ê¹ÓÃÈçϵÄÃüÁ
¡¡¡¡ gdb progname
¡¡¡¡ÔÚ gdb Ìáʾ·û´¦¼üÈëhelp£¬½«ÁгöÃüÁîµÄ·ÖÀ࣬Ö÷ÒªµÄ·ÖÀàÓУº
¡¡¡¡* aliases£ºÃüÁî±ðÃû
¡¡¡¡* breakpoints£º¶Ïµã¶¨Ò壻
¡¡¡¡* data£ºÊý¾Ý²é¿´£»
¡¡¡¡* files£ºÖ¸¶¨²¢²é¿´Îļþ£»
¡¡¡¡* internals£ºÎ¬»¤ÃüÁ
¡¡¡¡* running£º³ÌÐòÖ´ÐУ»
¡¡¡¡* stack£ºµ÷ÓÃÕ»²é¿´£»
¡¡¡¡* statu£º×´Ì¬²é¿´£»
¡¡¡¡* tracepoints£º¸ú×Ù³ÌÐòÖ´ÐС£
¡¡¡¡¼üÈë help ºó¸úÃüÁîµÄ·ÖÀàÃû£¬¿É»ñµÃ¸ÃÀàÃüÁîµÄÏêϸÇåµ¥¡£
gdb µÄ³£ÓÃÃüÁî
ÃüÁî ½âÊÍ
¡¡¡¡break NUM ÔÚÖ¸¶¨µÄÐÐÉÏÉèÖöϵ㡣
¡¡¡¡bt ÏÔʾËùÓеĵ÷ÓÃÕ»Ö¡¡£¸ÃÃüÁî¿ÉÓÃÀ´ÏÔʾº¯ÊýµÄµ÷ÓÃ˳Ðò¡£
¡¡¡¡clear ɾ³ýÉèÖÃÔÚÌض¨Ô´Îļþ¡¢Ìض¨ÐÐÉϵĶϵ㡣ÆäÓ÷¨Îªclear FILENAME:NUM
¡¡¡¡continue ¼ÌÐøÖ´ÐÐÕýÔÚµ÷ÊԵijÌÐò¡£¸ÃÃüÁîÓÃÔÚ³ÌÐòÓÉÓÚ´¦ÀíÐźŻò¶Ïµã¶ø µ¼ÖÂÍ£Ö¹ÔËÐÐʱ¡£
¡¡¡¡display EXPR ÿ´Î³ÌÐòÍ£Ö¹ºóÏÔʾ±í´ïʽµÄÖµ¡£±í´ïʽÓɳÌÐò¶¨ÒåµÄ±äÁ¿×é³É¡£
¡¡¡¡file FILE ×°ÔØÖ¸¶¨µÄ¿ÉÖ´ÐÐÎļþ½øÐе÷ÊÔ¡£
¡¡¡¡help NAME ÏÔʾָ¶¨ÃüÁîµÄ°ïÖúÐÅÏ¢¡£
¡¡¡¡info break ÏÔʾµ±Ç°¶ÏµãÇåµ¥£¬°üÀ¨µ½´ï¶Ïµã´¦µÄ´ÎÊýµÈ¡£
¡¡¡¡info files ÏÔʾ±»µ÷ÊÔÎļþµÄÏêϸÐÅÏ¢¡£
¡¡¡¡info func ÏÔʾËùÓеĺ¯ÊýÃû³Æ¡£
¡¡¡¡info local ÏÔʾµ±º¯ÊýÖеľֲ¿±äÁ¿ÐÅÏ¢¡£
¡¡¡¡info prog ÏÔʾ±»µ÷ÊÔ³ÌÐòµÄÖ´ÐÐ״̬¡£
¡¡¡¡info var ÏÔʾËùÓеÄÈ«¾ÖºÍ¾²Ì¬±äÁ¿Ãû³Æ¡£
¡¡¡¡kill ÖÕÖ¹Õý±»µ÷ÊԵijÌÐò¡£
¡¡¡¡list ÏÔʾԴ´úÂë¶Î¡£
¡¡¡¡make ÔÚ²»Í˳ö gdb µÄÇé¿öÏÂÔËÐÐ make ¹¤¾ß¡£
¡¡¡¡next ÔÚ²»µ¥²½Ö´ÐнøÈëÆäËûº¯ÊýµÄÇé¿öÏ£¬ÏòÇ°Ö´ÐÐÒ»ÐÐÔ´´úÂë¡£
¡¡¡¡print EXPR ÏÔʾ±í´ïʽ EXPR µÄÖµ¡£
******gdb ʹÓ÷¶Àý************************
-----------------
Çåµ¥ Ò»¸öÓдíÎóµÄ C Ô´³ÌÐò bugging.c
´úÂë:
-----------------
1¡¡££i nclude
2
3¡¡static char buff [256];
4¡¡static char* string;
5¡¡int main ()
6¡¡{
7¡¡¡¡¡¡printf ("Please input a string: ");
8¡¡¡¡¡¡gets (string);¡¡¡¡
9¡¡¡¡ printf ("\nYour string is: %s\n", string);
10 }
-----------------
¡¡ ÉÏÃæÕâ¸ö³ÌÐò·Ç³£¼òµ¥£¬ÆäÄ¿µÄÊǽÓÊÜÓû§µÄÊäÈ룬Ȼºó½«Óû§µÄÊäÈë´òÓ¡³öÀ´¡£¸Ã³ÌÐòʹÓÃÁËÒ»¸öδ¾­¹ý³õʼ»¯µÄ×Ö·û´®µØÖ· string£¬Òò´Ë£¬±àÒë²¢ÔËÐÐÖ®ºó£¬½«³öÏÖ Segment Fault ´íÎó£º
$ gcc -o bugging -g bugging.c
$ ./bugging
Please input a string: asfd
Segmentation fault (core dumped)
ΪÁ˲éÕҸóÌÐòÖгöÏÖµÄÎÊÌ⣬ÎÒÃÇÀûÓà gdb£¬²¢°´ÈçϵIJ½Öè½øÐУº
1£®ÔËÐÐ gdb bugging ÃüÁװÈë bugging ¿ÉÖ´ÐÐÎļþ£»
2£®Ö´ÐÐ×°ÈëµÄ bugging ÃüÁî run£»
3£®Ê¹Óà where ÃüÁî²é¿´³ÌÐò³ö´íµÄµØ·½£»
4£®ÀûÓà list ÃüÁî²é¿´µ÷Óà gets º¯Êý¸½½üµÄ´úÂ룻
5£®Î¨Ò»Äܹ»µ¼Ö gets º¯Êý³ö´íµÄÒòËؾÍÊDZäÁ¿ string¡£ÓÃprintÃüÁî²é¿´ string µÄÖµ£»
6£®ÔÚ gdb ÖУ¬ÎÒÃÇ¿ÉÒÔÖ±½ÓÐ޸ıäÁ¿µÄÖµ£¬Ö»Òª½« string È¡Ò»¸öºÏ·¨µÄÖ¸ÕëÖµ¾Í¿ÉÒÔÁË£¬Îª´Ë£¬ÎÒÃÇÔÚµÚ8Ðд¦ÉèÖöϵã break 8£»
7£®³ÌÐòÖØÐÂÔËÐе½µÚ 8Ðд¦Í£Ö¹£¬Õâʱ£¬ÎÒÃÇ¿ÉÒÔÓà set variable ÃüÁîÐÞ¸Ä string µÄÈ¡Öµ£»
8£®È»ºó¼ÌÐøÔËÐУ¬½«¿´µ½ÕýÈ·µÄ³ÌÐòÔËÐнá¹û¡£
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 4 ÌõÆÀÂÛ

  1. Alepan ÓÚ 2011-05-20 00:29:22·¢±í:

    ²»´í£¬ÊÕ²ØÁË

  2. »¨¿ª»¨°Ü2011 ÓÚ 2011-02-12 18:13:43·¢±í:

    Èí¼þ¿ª·¢Õß·Ïßͼ£º´Óѧͽµ½¸ßÊÖ

  3. taotie ÓÚ 2010-08-26 12:07:09·¢±í:

    :0)1

  4. genesy ÓÚ 2010-03-08 13:23:05·¢±í:

    Â¥Ö÷ÐÒ¿àÁË£¬Ñ§Ï°ÁË