如何在使用gdb调试递归函数时跳过一部分 [英] how to skip a portion while debugging a recursive function with gdb

查看:377
本文介绍了如何在使用gdb调试递归函数时跳过一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  void 
quicksort(int * num,int p,int r ,int june)
{
int q,bbc,ccd;
if(p {
call ++;
q = partition(num,p,r,june); //< - 我想在gdb session中跳过这个调用
bbc = q - 1 - p + 1; //< - 并希望从这里一步一步地继续执行
quicksort(num,p,q - 1,bbc);
ccd = r-q + 1;
quicksort(num,q + 1,r,ccd);
}
} //因为它是一个递归函数,每次调用quicksort时,partition也会被执行我只想把调试的重点放在quicksort
我想跳过gdb显示分区的步骤,也就是我知道的函数分区是正确的,所以做什么分区,然后跳转到下一条指令

  bbc = q  -  1  -  p + 1; 

并且在我的调试会话中不显示有关分区的信息。
所以我怎样才能跳过这部分并继续调试quicksort。

解决方案

我想你正在寻找一个 step over


Step Over与Step Into,
相同,除了当它到达一个呼叫对于
的另一个程序,它不会将
放入程序中。该过程将运行
,并且您将被带到当前
过程中的
next语句。




在GDB中,通过发出 next 命令来完成此操作。
在gdb中运行 q = partition(num,p,r,june); 行时,输入 next

你可以在这个中找到有关步入gdb的详细信息, http://www.delorie.com/gnu/docs/gdb/gdb_38.html =nofollowtitle =步调参考>参考资料

Here is a function in my program

void
quicksort (int *num, int p, int r, int june)
{
  int q, bbc, ccd;
  if (p < r)
    {
      call++;
      q = partition (num, p, r, june);//<--I want to skip this call in gdb session
      bbc = q - 1 - p + 1;//<-- and want to continue execution step by step from here
      quicksort (num, p, q - 1, bbc);
           ccd=r-q+1;
      quicksort (num, q + 1, r, ccd);
    }
} //since it is a recursive function each time quicksort is called partition is also executed I want to focus my debugging only to quicksort

If you notice it calls another function partition in between.While running in a gdb session I want to skip the gdb showing me steps of parition i.e. I know function partition is correct so do what partition does and then jump to next instruction

     bbc = q - 1 - p + 1;

and in my debugging session do not show info about partition. So how can I skip that part and continue debugging quicksort.

解决方案

I think you are looking for a step over.

Step Over is the same as Step Into, except that when it reaches a call for another procedure, it will not step into the procedure. The procedure will run, and you will be brought to the next statement in the current procedure.

In GDB, you do this by issuing the next command. When you are running the q = partition (num, p, r, june); line in gdb, type next and it will just execute the partition function without going into its code in detail.

You can find detailed information about stepping in gdb in this reference.

这篇关于如何在使用gdb调试递归函数时跳过一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆