下一个命令后如何防止gdb停止 [英] How to prevent gdb to stop after next command

查看:48
本文介绍了下一个命令后如何防止gdb停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试定义一连串命令,这些命令应在gdb中的断点后调用:

I am trying to define a chain of commands, which shall be invoked after a breakpoint in gdb:

    break some_function
    commands
       up
       next
       printf "some_string"
       continue
    end

在这种情况下(例如),我想在some_function处中断,在堆栈框架中向上移动,并通过下一条命令跳到该函数的后面,然后打印"some_string"(或某些变量,该变量已由功能),然后继续.但这是行不通的,因为gdb只会在下一条命令之后停止,并等待用户输入某些内容,而无视以下命令.

In this case (for example) I want to break at some_function, go up in the stack frame and jump right behind this function via the next command, then print "some_string" (or maybe some variable, which was changed by the function) and then just to continue. But that doesn't work, since gdb will just stop after the next command and wait for the user to input something, disregarding the following commands.

好的,我上面给出的示例与我的描述不正确.我真正想要的(感谢评论员尼古拉,见下文)是这样的:

Ok, the example I gave above did not correctly fit my description. What I really wanted (Thanks goes to the commenter Nikolai, see below) was something like that:

    break some_function
    commands
       finish
       printf "some_string"
       continue
    end

这将在'some_function'处中断,执行该函数,在执行'some_function'字符串'some_string'之后立即返回并打印.我以前对下一个命令所遇到的问题现在与finish命令一起出现:执行将在此命令后停止,并且gdb将等待用户输入,而无视以下printf和continue语句.很抱歉,这个问题有点令人困惑.我本人对此并不满意,但是再次发布它并不是一个更好的解决方案(因为评论会丢失并且会交叉发布).

This shall break at 'some_function', execute that function, return and print right after the execution of 'some_function' the string 'some_string'. The problem I had previously with the next command now appears with the finish command: execution will stop after this command and gdb will wait for user input, disregarding the following printf and continue statements. I am sorry, that this question got a bit confusing. I am not happy about it myself, but posting it again, wouldn't be a better solution (since the comments would be lost and it would be cross-posting).

推荐答案

好的,我想我自己找到了答案:gdb似乎在内部为finish和下一个命令设置了一个断点.但是,可以定义一个钩子来克服在此断点处的断裂.我认为最好的方法是生成自己的Finish(或下一条命令)版本,以避免产生副作用,所以这是可以做的事情:

Ok, I think I found the answer myself: gdb seems to set internally a breakpoint to the finish and the next command. However, one can define a hook, to overcome breaking at this breakpoint. The best method I think is to generate an own version of the finish (or the next command) to avoid side effects, so this is what one can do:

    define myfinish
      finish
    end

    define hook-myfinish
      printf "some_string"
      continue
    end

    break some_function
    commands
      myfinish
    end

建议在breaks命令部分的开头使用 silent 语句,以禁止显示打破时的额外输出:

It is advisable to use the silent statement at the beginning of the breaks commands section, to suppress additional output when breaking:

    break some_function
    commands
      silent
      myfinish
    end

这篇关于下一个命令后如何防止gdb停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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