What is the difference between dprintf and break + commands + continue?

For example:

dprintf main,"hello\n" run 

It produces the same result as:

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

Is there a significant advantage when using dprintf over commands , for example. is it much faster (if so, why?) or has several different functions?

Or is it basically a convenience team?

Source

In source 7.9.1, breakpoint.c:dprintf_command , which defines dprintf , calls create_breakpoint , which also calls break_command , 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 to initialize_breakpoint_ops .

dprintf keeps a list of command lines similar to commands , depending on the settings. It:

  • set to update_dprintf_command_list
  • which is called after checking type == bp_dprintf inside init_breakpoint_sal
  • which is called create_breakpoint .

When a breakpoint is reached:

  • bpstat_stop_status is called and calls b->ops->after_condition_true (bs); for reached breakpoint
  • after_condition_true for dprintf is dprintf_after_condition_true
  • bpstat_do_actions_1 runs commands
0
gdb
Jul 27 '15 at 13:04 on
source share
1 answer

There are two main differences.

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

More useful, however, dprintf does not interfere with next . If you write a breakpoint and use commands , and then next over such a breakpoint, gdb will forget about next and will act as if you typed continue . This is a long-standing oddity in the gdb scripting language. dprintf does not suffer from this problem. (If you need similar functionality from a regular breakpoint, you can do this with Python.)

+2
Jul 27 '15 at 16:20
source share



All Articles