logo资料库

GDB调试工具指南(完全版).pdf

第1页 / 共17页
第2页 / 共17页
第3页 / 共17页
第4页 / 共17页
第5页 / 共17页
第6页 / 共17页
第7页 / 共17页
第8页 / 共17页
资料共17页,剩余部分请下载后查看
GDBN`H X AnnCharles@tom.com 2003c0818F Contents 1 OOO 2 $$$111§§§SSS 2.1 •-1ºŒ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.2 ‚C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 111 4 :::(breakpoint) 4.1 : . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.2 w: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.3 ’4˜:(Enable & Disable) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.4 ^: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.5 : . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 wwwCCC 6 wwwSSS 7 www'''&&&EEE 8 wwwccc''' 9 XXXØØØ''' 10 wwwMMM 11 ’’’uuuframe 11.1 o·frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 wframe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.3 UCcframe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 NNN```UUUCCCCCC 1 2 3 4 4 4 4 4 6 6 7 7 7 7 8 8 8 8 8 8 8 9 9
13 NNN```NNN^^^………ŒŒŒ 14 ???NNN``` 9 9 15 ~~~fff 9 15.1 ?1,^N`§S<•-1ºŒ,‚C . . . . . . . . . . . . . . . . . . . . . . . . 9 15.2 ?2
1 OOO 3N`§Sc,yO§S,^u‘†~. `§SXe. Listing 1: `Łtest.cc c l a s s SampleParentClass f public : v i r t u a l void PrintMe ( ) f p r i n t f ( " I am p a r e n t c l a s s . n n" ) ; g v i r t u a l void PrintMe ( const char s ) f p r i n t f ( " I am p a r e n t c l a s s . n n%s nn" , g c l a s s SampleParentClass next ; const char name ; s ) ; g ; c l a s s S a m p l e C h i l d C l a ss : public SampleParentClass f v i r t u a l void PrintMe ( ) f p r i n t f ( " I am c h i l d c l a s s . nnMy name i s % s nn" , name ) ; g v i r t u a l void PrintMe ( const char s ) f p r i n t f ( " I am c h i l d c l a s s . nnMy name i s % s nn%s nn" , name , g s ) ; 1 #include < s t d i o . h> 2 #include < s t d l i b . h> 3 4 extern char e n v i r o n ; 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 g ; int f o o ( int a , f g int f o o ( int a ) f int a = 1 ; int b = 3 ; int i = 0 ; char p ; int b ) p r i n t f ( "a i s %dnn" ) ; return a + 1 ; g int main ( int a r g c , char argv ) f int r = 0 ; p r i n t f ( "a i s %d , b i s %dnn" , a , b ) ; r = a + b ; return r ; 3
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 i , p ) ; i , p ) ; c l a s s // b r e a k p o i n t p r i n t f ( " H e l l o GDBnn" ) ; p r i n t f ("command l i n e argumentsnn" ) ; for ( i = 0 , p = argv [ i ] ; p ! = NULL ; p = argv[++ i ] ) f p r i n t f ("%d : n t%s nn" , g p r i n t f ("enviromentnn" ) ; for ( i = 0 , p = e n v i r o n [ i ] ; p ! = NULL ; p = e n v i r o n[++ i ] ) f p r i n t f ("%d : n t%s nn" , g / / t e s t o v e r l o a d f u n c t i o n f o o ( a , b ) ; f o o ( a ) ; / / t e s t SampleParentClass o b j ; o b j = new S a m p l e C h i l d C l as s ( ) ; o b j>name = " head " ; o b j>next = new S a m p l e C h i l d C l a s s ( ) ; o b j>next>name = " C h a r l e s " ; o b j>next>next = new S a m p l e C h i l d C l a ss ( ) ; o b j>next>next>name = " Smith " ; o b j>next>next>next = new S a m p l e C h i l d C l a ss ( ) ; o b j>next>next>next>name = " t a i l " ; o b j>next>next>next>next = NULL ; SampleParentClass o b j 2 ; for ( o b j 2 = o b j ; o b j 2 ! = NULL ; o b j 2 = o b j 2>next ) f o b j 2>PrintMe ( ) ; o b j 2>PrintMe ( " I wanna say something . n n" ) ; g delete o b j ; return 0 ; // b r e a k p o i n t g ?¨ø§S g++ -g -o t test.cc -g^u)N`&E. os˘SN`. ˇ•muL§¥,3codingª,Łm’N`Łmı. k,• @§SATkø(J,·§S(J•, •ˇ~sØmƒ§ SovkU•ˇ1, ”, –Jp•mu˙. 2 $$$111§§§SSS file run 4
le ^u‰IN`1§S'¶¡,\1N`&E. –^gdb•-1ºŒ \11'. run ø•-^uؘ§S. 2.1 •••---111ºººŒŒŒ k«{ set args ^–e•-w•-1ºŒ. show args 2.2 ‚‚‚CCC 3 111 step $1,‹a\…Œp¡. next $11,‹a\…Œp¡. nish $1…Œ£. until $1,1. 4 :::(breakpoint) N`§SVg·6˚§S~$1,wc§SG. :·§S6˚/. 4.1 ::: kA«{–: break ARGS tbreak ARGS hbreak ARGS thbreak ARGS rbreak REGEXP k0break,ø·~^. ƒ{aq,¡0ƒbreak:. ARGSL«:/. k–eA«„. …Œ\?6˚~X: break main 5
L«3main …Œm'6˚$1. XJˇ›1(Overload),kı…Œk¶i,@oU^…Œ5I£: . k«„,XJ·›1a⁄…Œ,XPrintMe, @o‹5Ł,^r–J. (gdb) break SampleChildClass::PrintMe [0] cancel [1] all [2] SampleChildClass::PrintMe(char const*) at test.cc:25 [3] SampleChildClass::PrintMe() at test.cc:21 U0 , L«?:. U1 , L«⁄k:. U3 , L«25?:. U3 4, L«3 4 ?:. XJ·›1a⁄…Œ, ·˚ˇ…Œ›1, –ˇL‰\ºŒa.5«' ›1…Œ,X: break foo(int) break foo(int,int) 3,'¥,1 break test.cc:foo(int) 3test.cc¥foo…Œ\˚e5. ,1 break 11 L«3c'11116˚. o·c'? c'·§S6˚?⁄ØA '. XJ§Svk˜,c'·„kmain\…Œ'. ,',1 break test.cc:11 3test.cc ¥1111:. XJ1,1,3ø1NC break +12 break -10 'OL«3c1121?,c101?:. 6
3,S/?6˚1. break *0x80485ba S/7L·kŁª(Code Segment)/,U·Œª(Data Segment),ª(Stack Segment), (Heap)/. ø«{AON`•uvkN`&E1'. tbreak L«:, XJ3ø:6˚,@oø:g˜. hbreak L«M9ˇ:. NM’. thbreak L«M9ˇ:.·tbreak hbreakE. rbreak ¡ºŒ·KL“, ·TKL“⁄k…Œ¶¡⁄:. KL“{grep •-aq. Nºgrep•-. KL“·Unixe˜£,Øı §S^,Xperl,vi,emacs,sed,awk,grep. –w,:’,•§S–{z.3¡0. 4.2 www::: zg:,‹z:':,l1m',g4O. info breakpoints –^^5w:. Num Type 1 2 breakpoint breakpoint Disp Enb Address keep y keep y What 0x080485a4 in foo(int) at test.cc:38 0x080485ca in main at test.cc:44 Num L«:. Type L«:a.. Disp L«:G. del L«:6˚(hit), g˜:. keep L«:6˚, UY– :, dis L«:6˚,’4:(disable). Enb L«:·˜˜(Enable). §S$1disable:,‹6˚. –^enable •-˜:. ^disable •-’4:. Address What 'OL«:Ł/3'¥. ø•-‹w«:6˚gŒ,zg6˚hit. ‹w«:6˚^. 4.3 ’’’444˜˜˜:::(Enable & Disable) Enable Disble :–kı,^'. k?•- enable delete -- ˜:,·3:?6˚,:. ^info breakpoints •-w:,T:Dispiª(field)·del enable once -- ˜g:,6˚’4. ^info breakpoints •-w:,T:Dispiª(field)·dis 7
4.4 ^^^::: ^:·§S$1:?, k3v,^,‹6˚e5. k–e{: ^. –~f¥,:,k$1§S,,: break if ø«{–3::^. condition ø«{^uØfi:^. COND·?{6L“. o·{6L“? –P4^†,3@:?,? {C‰C++ 6L“Ø.·‘,ºŒ,C,C,$…ŒN^–. · 5¿XJ6L“¥„k…ŒN^, @o˜GDB ‹N^ø…Œ,·\§S·‹N^ . øU‹kN`§S§SgC$1,(J. 4.5 ::: delete breakpoints :–kı,^'. XJ‰:,@o‹⁄k:. 5 wwwCCC print /fmt expr ·?{L“. fmt ·“‰´,XeL. x 8?“ d ?“ u ˆ˛Œ o l?“ t ?“ a ^8?“
8
分享到:
收藏