dprintf vs break +命令+继续有什么区别? [英] What is the difference between dprintf vs break + commands + continue?

查看:221
本文介绍了dprintf vs break +命令+继续有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

  dprintf main,hello\\\

run

code>

产生与以下相同的输出:

  break main 
命令
silent
printfhello\\\

continue
end
run

使用 dprintf 优于命令,例如它是相当快(如果是这样为什么?),或有一些不同的功能?



或者它主要是一个方便的命令?





在7.9.1源文件中, breakpoint.c:dprintf_command ,它定义 dprintf ,调用 create_breakpoint ,这也是 break_command 调用,所以它们似乎都使用相同的底层机制。



主要区别在于 dprintf 传递 dprintf_breakpoint_ops 结构,该结构具有不同的回调函数,并初始化为 initialize_breakpoint_ops



dprintf 存储的命令字符串列表非常类似于命令命令,具体取决于设置。它们是:
$ b


  • 设置为 update_dprintf_command_list

  • 类型== bp_dprintf 内部检查 init_breakpoint_sal
  • 之后被调用
  • 它被 create_breakpoint



调用当达到断点时:


  • bpstat_stop_status 被调用并调用 b-> ops-> after_condition_true(bs); 获得了断点
  • after_condition_true for dprintf dprintf_after_condition_true

  • bpstat_do_actions_1 运行命令


解决方案

有两个主要区别。

首先, dprintf 具有一些额外的输出模式,可用于使其以其他方式工作。有关更多信息,请参阅 help set dprintf-channel 或手册。我认为这些模式是 dprintf 作为单独实体添加的原因;尽管同时它们相当专业化,不太可能引起普遍关注。



更有用的是, dprintf 不会干扰下一步。如果你写了一个断点并使用命令,然后 next 在这个断点上,gdb将会忘记 next ,就像您输入了 continue 一样。这在gdb脚本语言中长期存在。 dprintf 不会遇到这个问题。 (如果你需要一个普通断点的类似功能,你可以从Python中完成。)


For example:

dprintf main,"hello\n"
run

Generates the same output as:

break main
commands
  silent
  printf "hello\n"
  continue
end
run

Is there a significant advantage to using dprintf over commands, e.g. it is considerably faster (if so why?), or has some different functionality?

Or is it mostly a convenience command?

Source

In the 7.9.1 source, breakpoint.c:dprintf_command, which defines dprintf, calls create_breakpoint which is also what break_command calls, so they both seem to use the same underlying mechanism.

The main difference is that dprintf passes the dprintf_breakpoint_ops structure, which has different callbacks and gets initialized at initialize_breakpoint_ops.

dprintf stores list of command strings much like that of commands command, depending on the settings. They are:

  • set at update_dprintf_command_list
  • which gets called on after a type == bp_dprintf check inside init_breakpoint_sal
  • which gets called by create_breakpoint.

When a breakpoint is reached:

  • bpstat_stop_status gets called and invokes b->ops->after_condition_true (bs); for the breakpoint reached
  • after_condition_true for dprintf is dprintf_after_condition_true
  • bpstat_do_actions_1 runs the commands

解决方案

There are two main differences.

First, dprintf has some additional output modes that can be used to make it work in other ways. See help set dprintf-channel, or the manual, for more information. I think these modes are the reason that dprintf was added as a separate entity; though at the same time they are fairly specialized and unlikely to be of general interest.

More usefully, though, dprintf doesn't interfere with next. If you write a breakpoint and use commands, and then next over such a breakpoint, gdb will forget about the next and act as if you had typed continue. This is a longstanding oddity in the gdb scripting language. dprintf doesn't suffer from this problem. (If you need similar functionality from an ordinary breakpoint, you can do this from Python.)

这篇关于dprintf vs break +命令+继续有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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