aboutsummaryrefslogtreecommitdiff
path: root/gdb/ax-general.c
diff options
context:
space:
mode:
authorStan Shebs <shebs@codesourcery.com>2012-07-02 15:29:39 +0000
committerStan Shebs <shebs@codesourcery.com>2012-07-02 15:29:39 +0000
commitd3ce09f5bf7a7e8f97c3f1c9888e886ee267c2f2 (patch)
tree782811ca1df7a4f775823d1918d0b571fdac9b5a /gdb/ax-general.c
parenta47edf2745dd6414d635e4b372d416035c7b8c12 (diff)
downloadgdb-d3ce09f5bf7a7e8f97c3f1c9888e886ee267c2f2.zip
gdb-d3ce09f5bf7a7e8f97c3f1c9888e886ee267c2f2.tar.gz
gdb-d3ce09f5bf7a7e8f97c3f1c9888e886ee267c2f2.tar.bz2
Add target-side support for dynamic printf.
* NEWS: Mention the additional style. * breakpoint.h (struct bp_target_info): New fields tcommands, persist. (struct bp_location): New field cmd_bytecode. * breakpoint.c: Include format.h. (disconnected_dprintf): New global. (parse_cmd_to_aexpr): New function. (build_target_command_list): New function. (insert_bp_location): Call it. (remove_breakpoints_pid): Skip dprintf breakpoints. (print_one_breakpoint_location): Ditto. (dprintf_style_agent): New global. (dprintf_style_enums): Add dprintf_style_agent. (update_dprintf_command_list): Add agent case. (agent_printf_command): New function. (_initialize_breakpoint): Add new commands. * common/ax.def (printf): New bytecode. * ax.h (ax_string): Declare. * ax-gdb.h (gen_printf): Declare. * ax-gdb.c: Include cli-utils.h, format.h. (gen_printf): New function. (maint_agent_print_command): New function. (_initialize_ax_gdb): Add maint agent-printf command. * ax-general.c (ax_string): New function. (ax_print): Add printf disassembly. * Makefile.in (SFILES): Add format.c (COMMON_OBS): Add format.o. * common/format.h: New file. * common/format.c: New file. * printcmd.c: Include format.h. (ui_printf): Call parse_format_string. * remote.c (remote_state): New field breakpoint_commands. (PACKET_BreakpointCommands): New enum. (remote_breakpoint_commands_feature): New function. (remote_protocol_features): Add new BreakpointCommands entry. (remote_can_run_breakpoint_commands): New function. (remote_add_target_side_commands): New function. (remote_insert_breakpoint): Call it. (remote_insert_hw_breakpoint): Ditto. (_initialize_remote): Add new packet configuration for target-side breakpoint commands. * target.h (struct target_ops): New field to_can_run_breakpoint_commands. (target_can_run_breakpoint_commands): New macro. * target.c (update_current_target): Handle to_can_run_breakpoint_commands. [gdbserver] * Makefile.in (WARN_CFLAGS_NO_FORMAT): Define. (ax.o): Add it to build rule. (ax-ipa.o): Ditto. (OBS): Add format.o. (IPA_OBS): Add format.o. * server.c (handle_query): Claim support for breakpoint commands. (process_point_options): Add command case. (process_serial_event): Leave running if there are printfs in effect. * mem-break.h (any_persistent_commands): Declare. (add_breakpoint_commands): Declare. (gdb_no_commands_at_breakpoint): Declare. (run_breakpoint_commands): Declare. * mem-break.c (struct point_command_list): New struct. (struct breakpoint): New field command_list. (any_persistent_commands): New function. (add_commands_to_breakpoint): New function. (add_breakpoint_commands): New function. (gdb_no_commands_at_breakpoint): New function. (run_breakpoint_commands): New function. * linux-low.c (linux_wait_1): Test for and run breakpoint commands locally. * ax.c: Include format.h. (ax_printf): New function. (gdb_eval_agent_expr): Add printf opcode. [doc] * gdb.texinfo (Dynamic Printf): Mention agent style and disconnected dprintf. (Maintenance Commands): Describe maint agent-printf. (General Query Packets): Mention BreakpointCommands feature. (Packets): Document commands extension to Z0 packet. * agentexpr.texi (Bytecode Descriptions): Document printf bytecode. [testsuite] * gdb.base/dprintf.exp: Add agent style tests.
Diffstat (limited to 'gdb/ax-general.c')
-rw-r--r--gdb/ax-general.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/gdb/ax-general.c b/gdb/ax-general.c
index 4f1ea20..6ea6f14 100644
--- a/gdb/ax-general.c
+++ b/gdb/ax-general.c
@@ -330,6 +330,30 @@ ax_tsv (struct agent_expr *x, enum agent_op op, int num)
x->buf[x->len + 2] = (num) & 0xff;
x->len += 3;
}
+
+/* Append a string to the expression. Note that the string is going
+ into the bytecodes directly, not on the stack. As a precaution,
+ include both length as prefix, and terminate with a NUL. (The NUL
+ is counted in the length.) */
+
+void
+ax_string (struct agent_expr *x, char *str, int slen)
+{
+ int i;
+
+ /* Make sure the string length is reasonable. */
+ if (slen < 0 || slen > 0xffff)
+ internal_error (__FILE__, __LINE__,
+ _("ax-general.c (ax_string): string "
+ "length is %d, out of allowed range"), slen);
+
+ grow_expr (x, 2 + slen + 1);
+ x->buf[x->len++] = ((slen + 1) >> 8) & 0xff;
+ x->buf[x->len++] = (slen + 1) & 0xff;
+ for (i = 0; i < slen; ++i)
+ x->buf[x->len++] = str[i];
+ x->buf[x->len++] = '\0';
+}
@@ -391,6 +415,19 @@ ax_print (struct ui_file *f, struct agent_expr *x)
print_longest (f, 'd', 0,
read_const (x, i + 1, aop_map[op].op_size));
}
+ /* Handle the complicated printf arguments specially. */
+ else if (op == aop_printf)
+ {
+ int slen, nargs;
+
+ i++;
+ nargs = x->buf[i++];
+ slen = x->buf[i++];
+ slen = slen * 256 + x->buf[i++];
+ fprintf_filtered (f, _(" \"%s\", %d args"),
+ &(x->buf[i]), nargs);
+ i += slen - 1;
+ }
fprintf_filtered (f, "\n");
i += 1 + aop_map[op].op_size;