本文介绍了如何在使用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

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

你可以在这个。

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 sessionI 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.

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调试递归函数时跳过一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 05:58