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?
I imagine that dprinf could be in theory faster as it could in theory compile and inject code with a mechanism analogous to the compile code GDB command.
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_dprintfcheck insideinit_breakpoint_sal - which gets called by
create_breakpoint.
When a breakpoint is reached:
bpstat_stop_statusgets called and invokesb->ops->after_condition_true (bs);for the breakpoint reachedafter_condition_truefordprintfisdprintf_after_condition_truebpstat_do_actions_1runs the commands