AnnCharles@tom.com20030818
Contents
1
2
2.1.........................................2.2..........................................3
4(breakpoint)
4.1............................................4.2............................................4.3(Enable&Disable)..............................4.4............................................4.5..............
..............................
5678910
11frame
11.1frame...........................................11.2frame............................................11.3frame.........................................12
1
2344444667777888888899
1314
15
15.11,,15.22.................15.33,...................15.4watchpointdisplay..............................................................................................................
99991213161617
2
1616
1
,,..
§
Listing1:test.cc
#include classSampleParentClass{6 virtualvoidPrintMe(){ 8 }virtualvoidPrintMe(constchar∗s){ 10 } 12 constchar∗name; 14 classSampleChildClass:publicSampleParentClass{16 printf(”Iamchildclass.\\nMynameis%s\\n”,name); 18 printf(”Iamchildclass.\\nMynameis%s\\n%s\\n”,name,s); 20 };22 {24 printf(”ais%d,bis%d\\n”,a,b); 26 returnr; 28 intfoo(inta)30 printf(”ais%d\\n”); 32 }34 intmain(intargc,char∗∗argv)36 inta=1; 38 inti=0; 40 41 printf(”−−−−−−−−−−−−−commandlinearguments−−−−−\\n”); 43 printf(”%d:\%s\\n”,i,p); 45 printf(”−−−−−−−−−−−−−enviroment−−−−−−−−−−−−−−−−−−\\n”); 47 printf(”%d:\%s\\n”,i,p); 49 //testoverloadfunction 51 foo(a); 53 SampleParentClass∗obj; 55 obj−>name=”head”; 57 obj−>next−>name=”Charles”; 59 obj−>next−>next−>name=”Smith”; 61 obj−>next−>next−>next−>name=”tail”; 63 SampleParentClass∗obj2; 65 obj2−>PrintMe(); 67 } 69 return0; 71 ¥ //breakpoint //breakpoint file,.gdb. run. 2.1 •setargs 2.2 3 •step,.•next,.•finish.•until. 4 4.1 (breakpoint) ,.. •breakARGS•tbreakARGS•hbreakARGS•thbreakARGS•rbreakREGEXP break,.,break.ARGS..•:breakmain 5 main. (Overload),,. ,,PrintMe,,.(gdb)breakSampleChildClass::PrintMe[0]cancel[1]all [2]SampleChildClass::PrintMe(charconst*)attest.cc:25[3]SampleChildClass::PrintMe()attest.cc:210,.1,.3,25.34,34. ,,,:breakfoo(int) breakfoo(int,int)•breaktest.cc:foo(int) test.ccfoo.•break11 11.?.,main.•breaktest.cc:11 test.cc11. •,break+12break-10 12,10. 6 •.break*0x80485ba (CodeSegment),(DataSegment),(StackSegment),(Heap).. tbreak,,.hbreak.. thbreak.tbreakhbreak. rbreak,.grep.grep.Unix,,perl,vi,emacs,sed,awk,grep. ,,.. 4.2 ,,1,.infobreakpoints.NumType1breakpoint2breakpoint DispEnbAddressWhat keepy0x080485a4infoo(int)attest.cc:38keepy0x080485cainmainattest.cc:44 Num. Type. Disp.del(hit),.keep,,dis,(disable). Enb(Enable).disable,.enable.disable. AddressWhat. ,hit.. 4.3(Enable&Disable) Enable enabledelete--,,. infobreakpoints,Disp(field)del enableonce--,. infobreakpoints,Disp(field)dis 7 4.4 ,,.. ,,,•break .•condition COND.?,,CC++.,,,,.,GDB,.,. 4.5 deletebreakpoints ,. 5 print/fmt expr.fmt,.x u t ,c a,,,, 6 x/ 8 Address,0x8799f000p&var p,var.fmt,NFU,N. F,print. U.bhwg,,(),(),(8) 7 infosources 89 ,,,,.. GDBsourcedirectory.dir NAME .showdirectories soucedirectory. dir,sourcedirectory. 1011 11.1 frame frame frame,.,,,,frame.frame,. 11.2frame backtraceorbt 9 11.3frame frame 12 ,.. 13 . 1415 15.1 1,, ,.. GNUgdbRedHatLinux(5.2.1-4) Copyright2002FreeSoftwareFoundation,Inc. GDBisfreesoftware,coveredbytheGNUGeneralPublicLicense,andyouarewelcometochangeitand/ordistributecopiesofitundercertainconditions.Type\"showcopying\"toseetheconditions. ThereisabsolutelynowarrantyforGDB.Type\"showwarranty\"fordetails.ThisGDBwasconfiguredas\"i386-redhat-linux\"...(gdb)setargsabcdefg()(gdb)showargs() Argumentlisttogiveprogrambeingdebuggedwhenitisstartedis\"abcdefg\".(gdb)unsetenv()Deleteallenvironmentvariables?(yorn)y(gdb)setenvironmentVAR1=test()(gdb)setenvironmentVAR2=var2value(gdb)showenvironment()VAR1=test VAR2=var2value(gdb)break51(51)Breakpoint1at0x80486b8:filetest.cc,line51.(gdb)list51(51) 10 46printf(\"-------------enviroment------------------\\n\");47for(i=0,p=environ[i];p!=NULL;p=environ[++i]){48printf(\"%d:\%s\\n\i,p);49}50//testoverloadfunction51foo(a,b);52foo(a);53//testclass54SampleParentClass*obj;55obj=newSampleChildClass();(gdb)run() Startingprogram:/home/Charles/workplace/gdb_book/tabcdefgHelloGDB()-------------commandlinearguments-----0:/home/Charles/workplace/gdb_book/t1:a2:b3:c4:d5:e6:f7:g -------------enviroment------------------0:VAR1=test1:PWD=/home/Charles/workplace/gdb_book2:VAR2=var2value3:SHLVL=0Breakpoint1,main(argc=8,argv=0xbffffe94)attest.cc:51()51foo(a,b);(gdb)set$i=0 (gdb)setvariablep=argv[$i]()(gdb)whilep!=0()>printp=argv[$i++]>end $1=0xbfffff61\"/home/Charles/workplace/gdb_book/t\"$2=0xbfffff84\"a\"$3=0xbfffff86\"b\"$4=0xbfffff88\"c\"$5=0xbfffff8a\"d\"$6=0xbfffff8c\"e\"$7=0xbfffff8e\"f\"$8=0xbfffff90\"g\"$9=0x0 (gdb)printargv[$i]($i++)$20=0xbfffff92\"VAR1=test\" 11 (gdb)setvariablep=argv[$i](gdb)whilep!=0()>printp=argv[$i++]>end $21=0xbfffff92\"VAR1=test\" $22=0xbfffff9c\"PWD=/home/Charles/workplace/gdb_book\"$23=0xbfffffc1\"VAR2=var2value\"$24=0xbfffffd1\"SHLVL=0\"$25=0x0 (,p.p.)(gdb)set$p=argv[0](gdb)set$i=0(gdb)while$p!=0 >print$p=argv[$i++]>end $134=0xbfffff61\"/home/Charles/workplace/gdb_book/t\"$135=0xbfffff84\"a\"$136=0xbfffff86\"b\"$137=0xbfffff88\"c\"$138=0xbfffff8a\"d\"$139=0xbfffff8c\"e\"$140=0xbfffff8e\"f\"$141=0xbfffff90\"g\"$142=0x0() (gdb)set$i=0 (gdb)whileargv[$i]!=0>printargv[$i++]>end $226=0xbfffff61\"/home/Charles/workplace/gdb_book/t\"$227=0xbfffff84\"a\"$228=0xbfffff86\"b\"$229=0xbfffff88\"c\"$230=0xbfffff8a\"d\"$231=0xbfffff8c\"e\"$232=0xbfffff8e\"f\"$233=0xbfffff90\"g\" (,)(gdb)xargv[0]0xbfffff61:0x6d6f682f(gdb)x/10cbargv[0]((b),10(10),(c))0xbfffff61:47’/’104’h’111’o’109’m’101’e’47’/’67’C’104’h’0xbfffff69:97’a’114’r’(gdb)x/10tb(,) 12 0xbfffff6b:01101100011001010111001100101111011101110110111101110010011010110xbfffff73:0111000001101100(gdb)x/10th()0xbfffff7f:011010110110111101110100001011110110000100000000011000100000001100011000000000110010000000000011001010000000001100110000000000xbfffff8f:01100111000000000101011000000000(gdb) 15.22 (gdb)break64()Breakpoint2at0x8048816:filetest.cc,line64.(gdb)commands2 (,,’’2’’,) Typecommandsforwhenbreakpoint2ishit,oneperline.Endwithalinesayingjust\"end\".>silent()>set$p=obj>while$p!=0 >print$p->name>set$p=$p->next>end>cont(.) (,,,,,)>end ais1,bis3()ais1 $234=0x8048a2b\"head\"(,)$235=0x8048a30\"Charles\"$236=0x8048a38\"Smith\"$237=0x8048a3e\"tail\"Iamchildclass.()MynameisheadIamchildclass.Mynameishead Iwannasaysomething.Iamchildclass.MynameisCharlesIamchildclass.MynameisCharles Iwannasaysomething. 13 Iamchildclass.MynameisSmithIamchildclass.MynameisSmith Iwannasaysomething.Iamchildclass.MynameistailIamchildclass.Mynameistail Iwannasaysomething. Programexitednormally.() 15.33, (gdb)delbreakpoints()Deleteallbreakpoints?(yorn)y(gdb)breakfoo(int)(foo(inta),foo(inta,intb))Breakpoint3at0x80485a4:filetest.cc,line31.(gdb)infobreakpoints()NumTypeDispEnbAddressWhat3breakpointkeepy0x080485a4infoo(int)attest.cc:31 breakpointalreadyhit1time (gdb)run Startingprogram:/home/Charles/workplace/gdb_book/tabcdefgHelloGDB -------------commandlinearguments-----0:/home/Charles/workplace/gdb_book/t1:a2:b3:c4:d5:e6:f7:g -------------enviroment------------------0:VAR1=test1:PWD=/home/Charles/workplace/gdb_book2:VAR2=var2value3:SHLVL=0ais1,bis3 Breakpoint3,foo(int)(a=1)attest.cc:31 14 31printf(\"ais%d\\n\");(gdb)bt()#0foo(int)(a=1)attest.cc:31(test.cc31)#10x080486d4inmain(argc=8,argv=0xbffffe94)attest.cc:52#20x420158d4in__libc_start_main()from/lib/i686/libc.so.6(frame,0frame)(gdb)infolocals()Nolocals. (gdb)infoargs()a=1 (gdb)infoframe(frame)Stacklevel0,frameat0xbffffdf8:(framelevelframe)eip=0x80485a4infoo(int)(test.cc:31);savedeip0x80486d4calledbyframeat0xbffffe48sourcelanguagec++. Arglistat0xbffffdf8,args:a=1 Localsat0xbffffdf8,Previousframe’sspis0x0Savedregisters: ebpat0xbffffdf8,eipat0xbffffdfc (0xbffffdf8,test.cc31)(gdb)up(frame)#10x080486d4inmain(argc=8,argv=0xbffffe94)attest.cc:5252foo(a);(gdb)infoframe Stacklevel1,frameat0xbffffe48: eip=0x80486d4inmain(test.cc:52);savedeip0x420158d4calledbyframeat0xbffffe68,callerofframeat0xbffffdf8sourcelanguagec++. Arglistat0xbffffe48,args:argc=8,argv=0xbffffe94Localsat0xbffffe48,Previousframe’sspis0x0Savedregisters: ebxat0xbffffe44,ebpat0xbffffe48,eipat0xbffffe4c(gdb)infolocalsa=1b=3i=4p=0x0 obj=(SampleParentClass*)0x4212aa78obj2=(SampleParentClass*)0x80484ea(gdb)infoargsargc=8 argv=(char**)0xbffffe94(gdb)frame0(frame)#0foo(int)(a=1)attest.cc:3131printf(\"ais%d\\n\");(gdb)return10(,10) 15 Makefoo(int)returnnow?(yorn)y #00x080486d4inmain(argc=8,argv=0xbffffe94)attest.cc:5252foo(a); (gdb)callprintf(\"thisistest\\0\(,.)ais1,bis2(foo(1,2))$242=12(,printf)(gdb)callfflush(0)(fflush())thisistest$243=0 (gdb)disassemble()Dumpofassemblercodeforfunctionmain:0x80485ba 16 0x804863b ---Type 15.4watchpointdisplay watchpoint,,.display.VCWatch.deldisplaydelwatchpoint.infodisplayshowdisplay. 1617 17 因篇幅问题不能全部显示,请点此查看更多更全内容