[PATCH] tracepoint: add new trace command "printf"[1] gdbserver
Hui Zhu
teawater@gmail.com
Fri Feb 4 16:01:00 GMT 2011
To make the gdbserver support %s.
Thanks,
Hui
2011-01-28 Hui Zhu <teawater@gmail.com>
* tracepoint.c (gdb_agent_op): Add gdb_agent_op_printf.
(gdb_agent_op_names): Add "printf".
(tp_printf): New function.
(eval_agent_expr): Handle gdb_agent_op_printf.
-------------- next part --------------
---
gdbserver/tracepoint.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
--- a/gdbserver/tracepoint.c
+++ b/gdbserver/tracepoint.c
@@ -517,6 +517,7 @@ enum gdb_agent_op
gdb_agent_op_setv = 0x2d,
gdb_agent_op_tracev = 0x2e,
gdb_agent_op_trace16 = 0x30,
+ gdb_agent_op_printf = 0x31,
gdb_agent_op_last
};
@@ -571,6 +572,7 @@ static const char *gdb_agent_op_names [g
"tracev",
"?undef?",
"trace16",
+ "printf",
};
struct agent_expr
@@ -4292,6 +4294,16 @@ unparse_agent_expr (struct agent_expr *a
#endif
+int
+tp_printf(const char *format, ...)
+{
+ va_list ap;
+ va_start (ap, format);
+ vprintf (format, ap);
+ va_end(ap);
+ return 0;
+}
+
/* The agent expression evaluator, as specified by the GDB docs. It
returns 0 if everything went OK, and a nonzero error code
otherwise. */
@@ -4634,6 +4646,40 @@ eval_agent_expr (struct tracepoint_hit_c
agent_tsv_read (tframe, arg);
break;
+ case gdb_agent_op_printf:
+ {
+ void *argv;
+ arg = aexpr->bytes[pc++];
+ argv = (void *)(unsigned long)top;
+ if (--sp >= 0)
+ top = stack[sp];
+
+ if (arg)
+ {
+ if (strstr ((char *)(aexpr->bytes + pc), "%s"))
+ {
+ int i;
+ unsigned char buf[100];
+
+ for (i = 0; i < 100; i++)
+ {
+ agent_mem_read (tframe, buf + i,
+ (CORE_ADDR) ((unsigned long)argv + i),
+ 1);
+ if (!buf[i])
+ break;
+ }
+ tp_printf ((char *)(aexpr->bytes + pc), buf);
+ }
+ else
+ tp_printf ((char *)(aexpr->bytes + pc), argv);
+ }
+ else
+ tp_printf ((char *)(aexpr->bytes + pc));
+ pc += strlen ((char *)aexpr->bytes + pc) + 1;
+ }
+ break;
+
/* GDB never (currently) generates any of these ops. */
case gdb_agent_op_float:
case gdb_agent_op_ref_float:
More information about the Gdb-patches
mailing list