您的当前位置:首页正文

gdb

2023-06-05 来源:步旅网
GDB󰀁󰀁󰀁󰀁󰀁󰀁

󰀂󰀂󰀁

AnnCharles@tom.com2003󰀁08󰀁18󰀃

Contents

1󰀂󰀅󰀇󰀊

2󰀃󰀌󰀋󰀏

2.1󰀎󰀐󰀇󰀍󰀌󰀐󰀆.........................................2.2󰀎󰀐󰀃󰀍󰀓󰀆..........................................3󰀈󰀈󰀆󰀌

4󰀅󰀎(breakpoint)

4.1󰀎󰀐󰀅󰀎............................................4.2󰀅󰀅󰀅󰀎............................................4.3󰀁󰀍󰀂󰀂󰀔󰀅󰀎(Enable&Disable)..............................4.4󰀆󰀆󰀅󰀎............................................4.5󰀃󰀃󰀅󰀎..............

..............................

5󰀅󰀅󰀓󰀆6󰀅󰀅󰀁󰀁7󰀅󰀅󰀐󰀃󰀆󰀊󰀆8󰀅󰀅󰀑󰀁󰀐󰀃󰀆9󰀉󰀃󰀅󰀏󰀐󰀃󰀆10󰀅󰀅󰀊󰀁󰀄

11󰀁󰀈frame

11.1󰀇󰀈󰀏frame...........................................11.2󰀅󰀅frame............................................11.3󰀁󰀓󰀑󰀁frame.........................................12󰀐󰀓󰀅󰀁󰀓󰀓󰀆

1

2344444667777888888899

13󰀐󰀓󰀅󰀐󰀅󰀊󰀆14󰀑󰀉󰀐󰀓󰀊󰀉

15󰀁󰀃

15.1󰀇󰀇1,󰀅󰀐󰀓󰀋󰀏󰀃󰀁󰀇󰀍󰀌󰀐󰀆,󰀂󰀃󰀍󰀓󰀆15.2󰀇󰀇2󰀃󰀁󰀃󰀁.................15.3󰀇󰀇3,󰀇󰀌...................15.4watchpoint󰀂display..............................................................................................................

999912131616󰀋󰀁󰀋󰀐󰀓17󰀋󰀆󰀋󰀐󰀓

2

1616

1󰀁󰀁󰀂󰀃

󰀇󰀐󰀓󰀋󰀏󰀂󰀁,󰀋󰀂󰀅󰀍󰀍󰀃󰀋󰀏,󰀅󰀈󰀄󰀅󰀕󰀁.󰀔󰀓󰀋󰀏󰀉󰀈.

§

Listing1:󰀔󰀓󰀆󰀉test.cc

#include24

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󰀅󰀃󰀈󰀇󰀍󰀅󰀅󰀇󰀍󰀌󰀐󰀆.showargs

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:21󰀁0,󰀁󰀍󰀆󰀎󰀐󰀇󰀃󰀅󰀎.󰀁1,󰀁󰀍󰀎󰀐󰀁󰀇󰀅󰀎.󰀁3,󰀁󰀍󰀎󰀐25󰀇󰀄󰀅󰀎.󰀁34,󰀁󰀍󰀎󰀐3󰀂4󰀇󰀄󰀅󰀎.

󰀉󰀉󰀆󰀏󰀅󰀅󰀈󰀊󰀎󰀊󰀆,󰀋󰀑󰀏󰀈󰀉󰀊󰀆󰀄󰀅󰀅,󰀇󰀃󰀉󰀈󰀊󰀒󰀆󰀊󰀁󰀂󰀐󰀆󰀈󰀋󰀇󰀆󰀉󰀆󰀊󰀄󰀅󰀅󰀊󰀆,󰀉:breakfoo(int)

breakfoo(int,int)•󰀇󰀅󰀍󰀃󰀆󰀁󰀄󰀅󰀍󰀌breaktest.cc:foo(int)

󰀇test.cc󰀁󰀄foo󰀊󰀆󰀄󰀁󰀂󰀂󰀈󰀈󰀇.•󰀅󰀍󰀌break11

󰀁󰀍󰀇󰀑󰀁󰀐󰀃󰀆󰀄󰀊11󰀌󰀈󰀈.󰀇󰀈󰀏󰀑󰀁󰀐󰀃󰀆?󰀑󰀁󰀐󰀃󰀆󰀏󰀊󰀋󰀏󰀈󰀈󰀇󰀄󰀁󰀉󰀂󰀄󰀐󰀃󰀆.󰀉󰀉󰀋󰀏󰀄󰀁󰀇󰀂󰀔,󰀑󰀁󰀐󰀃󰀆󰀏󰀊󰀄󰀇main󰀁󰀂󰀊󰀆󰀄󰀐󰀃󰀆.•󰀅󰀐󰀃󰀆󰀄󰀅󰀍󰀌breaktest.cc:11

󰀇test.cc󰀁󰀄󰀊11󰀌󰀎󰀁󰀅󰀎.

•󰀉󰀉󰀆󰀌󰀕󰀅󰀍󰀌,󰀇󰀄󰀍󰀌󰀄󰀅󰀈󰀎󰀐󰀅break+12break-10

󰀉󰀂󰀁󰀍󰀇󰀑󰀁󰀌󰀊12󰀌󰀇,󰀂󰀁10󰀌󰀇󰀎󰀐󰀅󰀎.

6

•󰀇󰀅󰀍󰀍󰀁󰀁󰀈󰀉󰀇󰀈󰀈󰀆󰀌.break*0x80485ba

󰀁󰀁󰀈󰀉󰀏󰀎󰀏󰀇󰀅󰀄󰀆󰀉󰀃(CodeSegment)󰀄󰀈󰀉,󰀆󰀂󰀏󰀆󰀁󰀃(DataSegment),󰀇󰀌󰀃(StackSegment),󰀇(Heap)󰀄󰀈󰀉.󰀄󰀃󰀈󰀂󰀂󰀂󰀐󰀓󰀑󰀅󰀈󰀁󰀇󰀐󰀓󰀊󰀆󰀄󰀇󰀆󰀌󰀃󰀆.

tbreak󰀁󰀍󰀌󰀅󰀅󰀎,󰀉󰀉󰀇󰀄󰀍󰀅󰀎󰀈󰀈󰀈,󰀇󰀈󰀄󰀍󰀅󰀎󰀑󰀇󰀄󰀔󰀃󰀃󰀈.hbreak󰀁󰀍󰀄󰀆󰀃󰀇󰀅󰀎.󰀍󰀃󰀂󰀃󰀄󰀄󰀆󰀂󰀁.

thbreak󰀁󰀍󰀄󰀆󰀃󰀇󰀄󰀌󰀅󰀅󰀎.󰀏tbreak󰀂hbreak󰀖󰀄󰀅.

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󰀇󰀍󰀁󰀍󰀅󰀎.

Address󰀂What󰀉󰀂󰀁󰀍󰀅󰀎󰀄󰀆󰀉󰀈󰀉󰀂󰀇󰀐󰀃󰀆󰀁󰀄󰀂󰀐.

󰀄󰀍󰀇󰀍󰀄󰀈󰀊󰀍󰀅󰀎󰀈󰀈󰀄󰀋󰀆,󰀂󰀍󰀋󰀈󰀈󰀄󰀅󰀇󰀎󰀉󰀍󰀍hit.󰀄󰀈󰀊󰀍󰀅󰀎󰀄󰀈󰀈󰀄󰀆󰀆.

4.3󰀁󰀂󰀂󰀁󰀆󰀁󰀃(Enable&Disable)

EnableDisble󰀅󰀎󰀋󰀇󰀃󰀇󰀋󰀍,󰀅󰀁󰀋󰀉󰀌.󰀄󰀇󰀆󰀒󰀄󰀇󰀍

enabledelete--󰀂󰀔󰀅󰀎,󰀏󰀏󰀍󰀍󰀇󰀅󰀎󰀇󰀈󰀈,󰀑󰀃󰀃󰀅󰀎.

󰀅infobreakpoints󰀇󰀍󰀅󰀅󰀅󰀎󰀅,󰀆󰀅󰀎󰀄Disp󰀅󰀃(field)󰀏del

enableonce--󰀋󰀂󰀔󰀍󰀋󰀅󰀎,󰀈󰀈󰀊󰀑󰀁󰀍.

󰀅infobreakpoints󰀇󰀍󰀅󰀅󰀅󰀎󰀅,󰀆󰀅󰀎󰀄Disp󰀅󰀃(field)󰀏dis

7

4.4󰀁󰀁󰀁󰀃

󰀆󰀆󰀅󰀎󰀏󰀊󰀑󰀋󰀏󰀃󰀌󰀕󰀅󰀎󰀇,󰀋󰀇󰀇󰀋󰀆󰀅󰀇󰀆󰀆󰀄󰀅,󰀌󰀈󰀈󰀈󰀈󰀇.󰀇󰀃󰀈󰀈󰀂󰀎󰀐󰀅󰀎󰀄󰀆󰀆.

󰀃󰀄󰀄󰀁󰀃󰀁,󰀎󰀐󰀅󰀎,󰀉󰀃󰀌󰀋󰀏,󰀆󰀊󰀎󰀐󰀅󰀎•breakif

󰀄󰀃󰀈󰀂󰀇󰀃󰀇󰀎󰀐󰀅󰀎󰀄󰀊󰀅󰀑󰀎󰀐󰀅󰀎󰀄󰀆󰀆.•condition󰀄󰀃󰀅󰀂󰀅󰀈󰀉󰀍󰀍󰀂󰀓󰀅󰀎󰀎󰀐󰀆󰀆.

COND󰀏󰀇󰀃󰀅󰀂󰀄󰀆󰀇󰀁󰀂󰀋.󰀇󰀈󰀏󰀅󰀂󰀄󰀆󰀇󰀁󰀂󰀋?󰀇󰀃󰀋󰀋󰀍󰀆󰀋󰀅,󰀇󰀇󰀍󰀅󰀎󰀇,󰀇󰀃󰀍󰀍󰀅󰀂󰀄C󰀋C++󰀆󰀇󰀁󰀂󰀋󰀉󰀅.󰀋󰀑󰀏󰀄,󰀐󰀆,󰀓󰀊󰀓󰀆,󰀅󰀓󰀓󰀆,󰀒󰀌󰀊󰀆󰀐󰀅󰀖󰀇󰀃.󰀏󰀏󰀌󰀄󰀉󰀉󰀆󰀇󰀁󰀂󰀋󰀁󰀄󰀇󰀊󰀆󰀐󰀅,󰀇󰀈󰀉󰀆󰀃󰀕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

󰀁󰀁󰀅󰀁󰀃󰀁󰀁󰀁󰀂󰀁󰀂󰀃󰀁󰀁

󰀍󰀃󰀄󰀃󰀈,󰀇󰀆󰀌󰀃󰀆󰀁󰀄󰀇󰀐󰀓󰀊󰀆,󰀊󰀒󰀐󰀆󰀉󰀁󰀄󰀂󰀐,󰀇󰀆󰀍󰀃󰀆,󰀆󰀍󰀌󰀄.󰀃󰀆󰀆󰀉󰀍󰀃󰀏󰀂󰀉󰀂󰀏.

GDB󰀉󰀈sourcedirectory󰀇󰀏󰀕󰀐󰀃󰀆󰀄.󰀇󰀃󰀅dir

NAME

󰀅󰀂󰀍󰀍󰀅󰀏󰀂󰀏.showdirectories

󰀅󰀅soucedirectory.

dir󰀇󰀍󰀉󰀉󰀁󰀇󰀅󰀐󰀆,󰀇󰀈󰀑󰀃󰀁sourcedirectory.

1011

11.1

󰀁󰀁󰀂󰀁󰀁󰀁󰀂frame

󰀂󰀂󰀄frame

frame󰀏󰀇󰀌󰀁󰀄󰀍󰀃,󰀁󰀍󰀍󰀍󰀊󰀆󰀐󰀅.󰀂󰀋󰀊󰀆󰀐󰀅,󰀉󰀌󰀐󰀆,󰀓󰀊󰀓󰀆󰀖󰀃󰀁󰀇󰀇󰀌󰀁,󰀇󰀍󰀍󰀊󰀆󰀄󰀇󰀅󰀇󰀊󰀁,󰀎󰀉󰀍󰀍frame.󰀂󰀆󰀆󰀊󰀄frame,󰀇󰀃󰀅󰀅󰀆󰀊󰀄󰀓󰀊󰀓󰀆󰀂󰀐󰀆󰀄󰀈.

11.2󰀂󰀁frame

backtraceorbt

9

11.3󰀁󰀄󰀅󰀁frame

frameupdown󰀁󰀃

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.2󰀂󰀁2󰀁󰀁󰀁󰀁

(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.3󰀂󰀁3,󰀂󰀂

(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.cc󰀄31󰀌)#10x080486d4inmain(argc=8,argv=0xbffffe94)attest.cc:52#20x420158d4in__libc_start_main()from/lib/i686/libc.so.6(󰀊󰀍󰀊󰀏frame󰀋󰀉,0󰀁󰀍󰀏󰀁frame)(gdb)infolocals(󰀅󰀅󰀁󰀇󰀓󰀊󰀓󰀆)Nolocals.

(gdb)infoargs(󰀅󰀅󰀁󰀇󰀐󰀆)a=1

(gdb)infoframe(󰀅󰀅󰀑󰀁frame)Stacklevel0,frameat0xbffffdf8:(framelevel󰀁󰀍frame󰀋󰀉)eip=0x80485a4infoo(int)(test.cc:31);savedeip0x80486d4calledbyframeat0xbffffe48sourcelanguagec++.

Arglistat0xbffffdf8,args:a=1

Localsat0xbffffdf8,Previousframe’sspis0x0Savedregisters:

ebpat0xbffffdf8,eipat0xbffffdfc

(󰀌󰀄󰀕󰀊󰀌󰀌󰀕󰀂󰀁󰀍󰀏󰀁󰀆󰀌󰀕󰀈󰀁󰀁󰀈󰀉0xbffffdf8,󰀇test.cc󰀄31󰀌󰀇)(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

:push%ebp0x80485bb:mov%esp,%ebp0x80485bd:push%ebx0x80485be:sub$0x34,%esp0x80485c1:and$0xfffffff0,%esp0x80485c4:mov$0x0,%eax0x80485c9:sub%eax,%esp0x80485cb:movl$0x1,0xfffffff8(%ebp)0x80485d2:movl$0x3,0xfffffff4(%ebp)0x80485d9:movl$0x0,0xfffffff0(%ebp)0x80485e0:sub$0xc,%esp0x80485e3:push$0x804899a0x80485e8:call0x804849c0x80485ed:add$0x10,%esp0x80485f0:sub$0xc,%esp0x80485f3:push$0x80489c00x80485f8:call0x804849c0x80485fd:add$0x10,%esp0x8048600:movl$0x0,0xfffffff0(%ebp)0x8048607:mov0xfffffff0(%ebp),%eax0x804860a:lea0x0(,%eax,4),%edx0x8048611:mov0xc(%ebp),%eax0x8048614:mov(%eax,%edx,1),%eax0x8048617:mov%eax,0xffffffec(%ebp)0x804861a:cmpl$0x0,0xffffffec(%ebp)0x804861e:jne0x80486220x8048620:jmp0x80486520x8048622:sub$0x4,%esp0x8048625:pushl0xffffffec(%ebp)0x8048628:pushl0xfffffff0(%ebp)0x804862b:push$0x80489ea0x8048630:call0x804849c0x8048635:add$0x10,%esp0x8048638:lea0xfffffff0(%ebp),%eax

16

0x804863b:incl(%eax)0x804863d:mov0xfffffff0(%ebp),%eax0x8048640:lea0x0(,%eax,4),%edx0x8048647:mov0xc(%ebp),%eax

---Typetocontinue,orqtoquit---q

15.4watchpoint󰀂display

watchpoint󰀏󰀅󰀎,󰀄󰀅󰀏󰀑󰀅󰀍󰀍󰀁󰀂󰀋󰀁󰀔󰀓󰀁󰀅,󰀋󰀏󰀈󰀈.display󰀏󰀄󰀔󰀃󰀁󰀓󰀆.󰀂VC󰀁󰀄Watch󰀊󰀂󰀇󰀄󰀍󰀋.deldisplay󰀂delwatchpoint󰀉󰀂󰀏󰀃󰀃󰀒󰀊.infodisplay󰀂showdisplay󰀉󰀂󰀏󰀅󰀅󰀒󰀊.

1617

󰀂󰀁󰀂󰀄󰀃󰀂󰀁󰀂󰀄󰀃

17

因篇幅问题不能全部显示,请点此查看更多更全内容