GDB调试之直接调用函数 (十九)
常用命令:
- p表达式:求表达式的值并显示结果值。表达式可以包括对正在调试的程序中的函数的调用,即使函数返回值是void,也会显示。
- call表达式:求表达式的值并显示结果值,如果是函数调用,返回值是void的话,不显示void返回值。
调试代码如下:
#include <iostream>
#include <cstring>
using namespace std;
int test(int x,int y)
{
cout << "x=" << x << "y=" << y << endl;
return x + y;
}
void fun(int x)
{
cout << "x=" << x << endl;
}
int test_work(const char*name,int age)
{
cout << "name=" << name << ",age=" << age << endl;
return 0;
}
int main(int argc,char** argv)
{
int age = 25;
char name[100]={0};
strcpy(name,"SimpleSoft");
test_work(name,age);
memset(name,0,sizeof(name));
age = test(10,20);
return 0;
}
调试结果如下:

在函数处添加断点后,再使用call调用此函数:

上述都是调用自定义函数,下面是如何来调用系统函数:

当运行程序没有调试信息调用自定义函数:


浙公网安备 33010602011771号