how to skip a portion while debugging a recursive function with gdb

半世苍凉 提交于 2020-01-04 13:59:46

问题


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.


回答1:


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.

  • Quote from http://www.developerfusion.com/article/33/debugging/4/

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.




回答2:


b <line number>

will set a break point

c

will continue until the next breakpoint.




回答3:


You can either set a breakpoint for the line after partition:

b <line number>

Then use c to continue until the breakpoint.

Or you can use n to skip over the partition call (that is, type n when you reach the partition call, and it will skip the body of the function).

Or you can type finish to exit the partition function after entering it.



来源:https://stackoverflow.com/questions/6428524/how-to-skip-a-portion-while-debugging-a-recursive-function-with-gdb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!