时间:2021-07-01 10:21:17 帮助过:2人阅读
(gdb) l 1 #include<iostream> 2 using namespace std; 3 int sum(int arg1,int arg2) 4 { 5 return arg1+arg2; 6 } 7 int main() 8 { 9 int a=1; 10 int b=2; (gdb) 11 cout<<"sum = "<<sum(a,b)<<endl; 12 return 0; 13 14 } (gdb)
(gdb) n表示next单步进行
Breakpoint 1, main () at sum.cpp:11
11 cout<<"sum = "<<sum(a,b)<<endl;
(gdb) n
sum = 3
12 return 0;
(gdb)
gdb下查看变量的值:p 变量名
(gdb) p a
$1 = 1
(gdb) p b
$2 = 2
查看函数内存地址:
(gdb) p sum
3=int(int,int)0x80486a4<sum(int,int)>(gdb)psum(a,b)3=int(int,int)0x80486a4<sum(int,int)>(gdb)psum(a,b)4 = 3
调用函数
(gdb) p sum(100,200)
$5 = 300
断点调试就这么多了,有兴趣的可以学习设置观察点,捕捉点调试。
Linux gdb调试
标签: