gdb调试如何跟踪进入另外一个包含文件的内部函数进行调试?

B2China 2004-08-30 02:35:44
假定文件: myfunc.c
#include <stdio.h>

int max(int x,int y)
{
return x<y?x:y;
}


主函数文件: test.c
 #include <unistd.h>
#include "myfunc.c"
 static char buff [256];
 static char* string;
 int main ()
 {
int x,y,z;

  printf ("Please input a string: ");
  gets (string);  
  printf ("\nYour string is: %s\n", string);

x = 5;y = 10;
z = max(x,y);
printf("\nmax(%d,%d) = %d",x,y,z) ;
}

在上面的程序中,包含文件myfunc.c的求最大值的函数逻辑是错误的,实际上是求最小值,
因此,需要跟踪进入该函数的内部进行调试,用GDB如何跟踪进入该函数的内部呢?

请问实现该调试功能的调试命令如何写?
...全文
1884 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
yanghuajia 2004-08-30
  • 打赏
  • 举报
回复
设断点 b 函数名
tibet 2004-08-30
  • 打赏
  • 举报
回复
设断点 b 文件名:行数
B2China 2004-08-30
  • 打赏
  • 举报
回复
假设还有一个myclass.c文件(位于当前目录),main.c 加上#include "myclass.c":

myclass::func1()
{
}
myclass::func2()
{
}
如何跟踪进入到func1、func2进行调试呢?
B2China 2004-08-30
  • 打赏
  • 举报
回复
对啊,我的main.c 在当前目录, myfunc.c 在上一级目录下的func目录下,

该怎么写调试命令呢?

xu_guanghui 2004-08-30
  • 打赏
  • 举报
回复
用GDB 跟踪进去后
>b max
>s
>s
单独跟踪进去就可以了
如果myfunc.c 和test.c 不在同一个目录下面
可以设置一下路径
>directroy .... (myfunc.c所在的路径)

23,120

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧