C????: ???gdb????
?????Vamei ???????[ 2016/11/23 10:18:12 ] ????????.NET C????
????gdb??the GNU Debugger????????????UNIX?????????(debugger)?????????C?? C++?? Objective-C?? Java?? Fortran?????debug??
??????gdb?У???????????????(break point)????????????е????????????????????????????????????????????????????IDE?У?gdb?????λ????檔
???????????????gdb????????????????C???????????????????????Mac OS????
???????gdb
???????????????C?????(?????bug?????????gdb???????????е????)
?????????????test.c??????????????main()??mean.c?????ж?????mean()??????????main()?е??á?
????test.c
#define ARRAYSIZE 4
float mean(float?? float);
int main()
{
int i;
float a=4.5;
float b=5.5;
float rlt=0.0;
float array_a[ARRAYSIZE]={1.0?? 2.0?? 3.0?? 4.0};
float array_b[ARRAYSIZE]={4.0?? 3.0?? 2.0?? 1.0};
float array_rlt[ARRAYSIZE];
for(i = 0; i < ARRAYSIZE - 1; i++) {
array_rlt[i] = mean(array_a[i]?? array_b[i]);
}
rlt = mean(a?? b);
return 0;
}
????mean.c
????float mean(float a?? float b)
????{
????return (a + b)/2.0;
????}
???????gcc????????????????????????gdb????е???????????-g???(??????????debugging???):
????$gcc -g -o test test.c mean.c
????????main??????????
????(???б???????:
????$chmod +x test
??????????????????????)
????????gdb????????????:
????$gdb test
????????gdb??????????С?
???????????
????????????????????е???????????9?г???:
????(gdb) list 9
????????????9???????????10?е?????????????????????????????????????????£??????????????test.c:
????int main()
????{
????int i;
????float a=4.5;
????float b=5.5;
????float rlt=0.0;
????float array_a[ARRAYSIZE]={1.0?? 2.0?? 3.0?? 4.0};
????float array_b[ARRAYSIZE]={4.0?? 3.0?? 2.0?? 1.0};
??????????mean.c?е?????????????????:
????(gdb) list mean.c:1
??????????????????г???????е??Χ:
????(gdb) list 5?? 15
?????????5-15?е????
????????????????????:
????(gdb) list mean
??????????
??????????????г???:
????(gdb) run
??????????????????
???????г?????????????????gdb????????????????ó?????????????
???????(break point)?????????е????λ?á???gdb?У??????????е???λ????????????????????????????????????????????????
???????????????????????????????:
????(gdb) break 16
????????test.c???16????????
????????????????????:
????(gdb) info break
????????????????????????????????????????????:
????(gdb) delete 1
???????????????ж??:
????(gdb) delete breakpoints
?????????
???????????????run???г??????????е?16????????gdb???:
????Breakpoint 1?? main () at test.c:16
????16 for(i = 0; i < ARRAYSIZE - 1; i++) {
???????????????:
????(gdb) list
???????????????????:
????(gdb) print a
????(gdb) print array_a
?????????е???????:
????(gdb) info local
?????????????? (???????????????Linux?????????):
????(gdb) info stack
???????????????????
????(gdb) set var a=0.0
????(gdb) set var array_a={0.0?? 0.0?? 1.0?? 1.0}
?????????????????????????????????
?????????????????????:
????(gdb) break mean.c:2
????????????????a?????????main()?????????mean()???????????function::variable????????:
????(gdb) print mean::a
???????п???
?????ó???????????????????:
????(gdb) step
?????????????????????????????У????????????:
????(gdb) continue
???????run?????????С?
????????
????????????gdb????????????:
????(gdb) help
??????????????????:
????(gdb) help info
???????
??????????????????gdb:
????(gdb) quit
????debug
???????????????bug??C????demo.c
#include <stdio.h>
struct node {
int element;
};
typedef struct node *PNode;
int main()
{
int i;
PNode np=NULL;
for (i=0; i<10; i++) {
printf("Hello World!");
}
printf("%d
"?? np->element);
}
??????????????????????н?????:
????Segmentation fault
???????????gdb??????????
????Updata:
?????????????????: gdb?????????????????????д??????c????continue??b????break??q????quit??
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11