diff options
author | Stan Shebs <shebs@codesourcery.com> | 2012-05-14 15:38:41 +0000 |
---|---|---|
committer | Stan Shebs <shebs@codesourcery.com> | 2012-05-14 15:38:41 +0000 |
commit | e7e0cddfb0d4c4823cc7ed48c727e12f0e11a600 (patch) | |
tree | 3826eb4389246147dbdd6509abc94cb47f1b9e6c /gdb/doc | |
parent | 27d799802ad136a2b59220c1822c4a6e592d830b (diff) | |
download | gdb-e7e0cddfb0d4c4823cc7ed48c727e12f0e11a600.zip gdb-e7e0cddfb0d4c4823cc7ed48c727e12f0e11a600.tar.gz gdb-e7e0cddfb0d4c4823cc7ed48c727e12f0e11a600.tar.bz2 |
2012-05-14 Stan Shebs <stan@codesourcery.com>
Add dynamic printf.
* breakpoint.h (enum bptype): New type bp_dprintf.
(struct breakpoint): New field extra_string.
(struct breakpoint_ops): Add arg to create_breakpoints_sal.
(create_breakpoint): Add extra_string arg.
* breakpoint.c (dprintf_breakpoint_ops): New.
(is_breakpoint): Add bp_dprintf.
(bpstat_what): Add dprintf case.
(bptype_string): Ditto.
(print_one_breakpoint_location): Ditto.
(init_bp_location): Ditto.
(bkpt_print_mention): Ditto.
(dprintf_style_enums): New array.
(dprintf_style): New global.
(dprintf_function): New global.
(dprintf_channel): New global.
(update_dprintf_command_list): New function.
(update_dprintf_commands): New function.
(init_breakpoint_sal): Add extra_string argument, handle it.
(create_breakpoint_sal): Add extra_string argument.
(create_breakpoints_sal): Add extra_string argument, update callers.
(find_condition_and_thread): Add extra argument.
(create_breakpoint): Add extra_string argument, record it.
(dprintf_command): New function.
(break_command_1): Add arg to create_breakpoint call.
(handle_gnu_v3_exceptions): Ditto.
(trace_command): Ditto.
(ftrace_command): Ditto.
(strace_command): Ditto.
(bkpt_print_mention): Add dprintf case.
(create_breakpoint_sal_default): Add extra_string argument.
(_initialize_breakpoint): Add new commands.
* mi/mi-cmd-break.c (mi_cmd_break_insert): Add arg to call.
* python/py-breakpoint.c (bppy_init): Ditto.
* python/py-finishbreakpoint.c (bpfinishpy_init): Ditto.
* gdb.texinfo (Dynamic Printf): New subsection.
* gdb.base/dprintf.c: New file.
* gdb.base/dprintf.exp: New file.
Diffstat (limited to 'gdb/doc')
-rw-r--r-- | gdb/doc/ChangeLog | 4 | ||||
-rw-r--r-- | gdb/doc/gdb.texinfo | 84 |
2 files changed, 88 insertions, 0 deletions
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index 8eef588..4ee5c63 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,7 @@ +2012-05-14 Stan Shebs <stan@codesourcery.com> + + * gdb.texinfo (Dynamic Printf): New subsection. + 2012-05-13 Siva Chandra Reddy <sivachandra@google.com> * gdb.texinfo (Basic Python): Add description about the function diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index a5c6879..7bfb964 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -3341,6 +3341,7 @@ all breakpoints in that range are operated on. * Disabling:: Disabling breakpoints * Conditions:: Break conditions * Break Commands:: Breakpoint command lists +* Dynamic Printf:: Dynamic printf * Save Breakpoints:: How to save breakpoints in a file * Static Probe Points:: Listing static probe points * Error in Breakpoints:: ``Cannot insert breakpoints'' @@ -4628,6 +4629,89 @@ cont end @end smallexample +@node Dynamic Printf +@subsection Dynamic Printf + +@cindex dynamic printf +@cindex dprintf +The dynamic printf command @code{dprintf} combines a breakpoint with +formatted printing of your program's data to give you the effect of +inserting @code{printf} calls into your program on-the-fly, without +having to recompile it. + +In its most basic form, the output goes to the GDB console. However, +you can set the variable @code{dprintf-style} for alternate handling. +For instance, you can ask to format the output by calling your +program's @code{printf} function. This has the advantage that the +characters go to the program's output device, so they can recorded in +redirects to files and so forth. + +@table @code +@kindex dprintf +@item dprintf @var{location},@var{template},@var{expression}[,@var{expression}@dots{}] +Whenever execution reaches @var{location}, print the values of one or +more @var{expressions} under the control of the string @var{template}. +To print several values, separate them with commas. + +@item set dprintf-style @var{style} +Set the dprintf output to be handled in one of several different +styles enumerated below. A change of style affects all existing +dynamic printfs immediately. (If you need individual control over the +print commands, simply define normal breakpoints with +explicitly-supplied command lists.) + +@item gdb +@kindex dprintf-style gdb +Handle the output using the @value{GDBN} @code{printf} command. + +@item call +@kindex dprintf-style call +Handle the output by calling a function in your program (normally +@code{printf}). + +@item set dprintf-function @var{function} +Set the function to call if the dprintf style is @code{call}. By +default its value is @code{printf}. You may set it to any expression. +that @value{GDBN} can evaluate to a function, as per the @code{call} +command. + +@item set dprintf-channel @var{channel} +Set a ``channel'' for dprintf. If set to a non-empty value, +@value{GDBN} will evaluate it as an expression and pass the result as +a first argument to the @code{dprintf-function}, in the manner of +@code{fprintf} and similar functions. Otherwise, the dprintf format +string will be the first argument, in the manner of @code{printf}. + +As an example, if you wanted @code{dprintf} output to go to a logfile +that is a standard I/O stream assigned to the variable @code{mylog}, +you could do the following: + +@example +(gdb) set dprintf-style call +(gdb) set dprintf-function fprintf +(gdb) set dprintf-channel mylog +(gdb) dprintf 25,"at line 25, glob=%d\n",glob +Dprintf 1 at 0x123456: file main.c, line 25. +(gdb) info break +1 dprintf keep y 0x00123456 in main at main.c:25 + call (void) fprintf (mylog,"at line 25, glob=%d\n",glob) + continue +(gdb) +@end example + +Note that the @code{info break} displays the dynamic printf commands +as normal breakpoint commands; you can thus easily see the effect of +the variable settings. + +@end table + +@value{GDBN} does not check the validity of function and channel, +relying on you to supply values that are meaningful for the contexts +in which they are being used. For instance, the function and channel +may be the values of local variables, but if that is the case, then +all enabled dynamic prints must be at locations within the scope of +those locals. If evaluation fails, @value{GDBN} will report an error. + @node Save Breakpoints @subsection How to save breakpoints to a file |