我可以在函数结尾跳过一个throw语句吗? [英] Can I have gdb jump past a throw statement at the end of a function?

查看:103
本文介绍了我可以在函数结尾跳过一个throw语句吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我调试时,我有时会发现重放最后几句代码是有用的。例如:

When I'm debugging, I sometimes find it useful to "replay" the last few statements of code. For example:

void foo (int & i) {
  i = 0;
  ++i;
  i++;
}

通过调试器运行这个过程,您可以在函数体,然后从 foo 中的任何语句中输入:jump file.cc:2,调试器将返回到 i = 0 。我感谢这并不总是完美的,但有时找到您要搜索的错误就足够了。

While running this through the debugger, you can add a breakpoint at the top of the function body, and then from any statement inside of foo if you type: "jump file.cc:2" the debugger will return back to i = 0. I appreciate that this isn't always perfect, but sometimes it can be enough to find the bug you're searching for.

我正在调查一个结果的问题抛出异常。异常被抛出在被调用的函数的底部,所以这样的东西就像:

I'm currently investigating a problem that results in an exception being thrown. The exception is being thrown at the bottom of a called function, so something like:

void bar ()
{
  throw int ();
}

void foo (int & i)
{
  i = 0;
  ++i;

  bar ();

  i++;
}

int main ()
{
  try
  {
    int i;
    foo (i);
  }
  catch (...)
  {
  }
}

我想要做的是在 throw int()之前放置一个断点,然后跳过那个语句,完成功能栏 - 这样我就可以跳回到foo中的 i = 0 行。

What I want to be able to do, is to put a breakpoint before throw int (), then to jump over just that statement, finish the function bar - so that I can then jump back up to the i = 0 line in foo.

有没有办法可以跳过 throw int(),或者完成 bar 而不执行throw语句?

Is there a way I can jump past throw int (), or finish out of bar without executing the throw statement?

问题似乎在 throw之后没有声明,所以我无处可以放置我想要的断点

The problem appears to be that there's no statement after the throw so I have nowhere to put the breakpoint I want to jump to.

更新:

要突出显示我的简单上面的例子:

To highlight what happens in my simple example above:

This GDB was configured as "i486-slackware-linux"...
(gdb) break bar
Breakpoint 1 at 0x804856a: file t.cc, line 3.
(gdb) run
Starting program: ..../t 

Breakpoint 1, bar () at t.cc:3
(gdb) break t.cc:4
Breakpoint 2 at 0x8048592: file t.cc, line 4.
(gdb) jump t.cc:4
Line 4 is not in `bar()'.  Jump anyway? (y or n) y
Continuing at 0x8048592.

Breakpoint 2, foo (i=@0xb80155eb) at t.cc:6

'bar'的闭合卷曲位于't.cc'的第4行,但gdb将此视为 foo 的断点。

The close curly for 'bar' is on line 4 of 't.cc', however gdb considers this as a breakpoint for foo.

推荐答案

我的错误拼写实际上已经提供了答案!

My bad spelling has actually provided me with the answer!

我的 没有工作,所以在寻找正确的拼写时,我最终偶然发现帮助堆栈:

My variation of "disassemble" was not working, so while looking for the correct spelling I eventually stumbled onto "help stack":


检查堆栈。
堆栈由堆栈帧组成。 GDB将数字分配给堆栈帧
从最内层(当前执行)帧计数。

Examining the stack. The stack is made up of stack frames. Gdb assigns numbers to stack frames counting from zero for the innermost (currently executing) frame.

在任何时候,gdb将一个帧标识为选定帧。
相对于所选帧完成变量查找。
当被调试的程序停止时,gdb选择最内层的框架。
以下命令可用于按号码或地址选择其他框架。

At any time gdb identifies one frame as the "selected" frame. Variable lookups are done with respect to the selected frame. When the program being debugged stops, gdb selects the innermost frame. The commands below can be used to select other frames by number or address.

命令列表:

backtrace - 打印所有堆栈帧的追溯

backtrace -- Print backtrace of all stack frames

bt - 打印所有堆栈帧的追溯

bt -- Print backtrace of all stack frames

下拉 - 选择并打印由此调用的堆栈框架

down -- Select and print stack frame called by this one

框架 - 选择并打印堆栈框架

frame -- Select and print a stack frame

return - 选择堆栈帧返回给它的调用者

return -- Make selected stack frame return to its caller

select-frame - 选择一个没有打印任何东西的堆栈帧

select-frame -- Select a stack frame without printing anything

up - 选择并打印调用这一个的堆栈框架

up -- Select and print stack frame that called this one

返回命令从上面的列表中我完全按照我想要的方式。

The return command from the above list does exactly what I want in this case.

感谢大家的帮助。

这篇关于我可以在函数结尾跳过一个throw语句吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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