aboutsummaryrefslogtreecommitdiff
path: root/gdb/printcmd.c
diff options
context:
space:
mode:
authorHui Zhu <teawater@gmail.com>2011-02-21 08:38:14 +0000
committerHui Zhu <teawater@gmail.com>2011-02-21 08:38:14 +0000
commitd0e92d82d87a287847fcd66da278836f7136a3ef (patch)
tree432a9056a4ff0e356ff223fbe228aedef40ba131 /gdb/printcmd.c
parentc0c8b2f268cd3a8735abed708e08aedd2edd26be (diff)
downloadgdb-d0e92d82d87a287847fcd66da278836f7136a3ef.zip
gdb-d0e92d82d87a287847fcd66da278836f7136a3ef.tar.gz
gdb-d0e92d82d87a287847fcd66da278836f7136a3ef.tar.bz2
2011-02-21 Hui Zhu <teawater@gmail.com>
* Makefile.in (HFILES_NO_SRCDIR): Add printcmd.h. * ax-gdb.c (gen_printf_expr_callback): New function. * ax-gdb.h (gen_printf_expr_callback): Forward declare. * ax-general.c (ax_memcpy): New function. (ax_print): Handle "printf". (ax_reqs): Ditto. * ax.h (ax_memcpy): Forward declare. * common/ax.def (invalid2): Removed. (printf): New entry. * printcmd.c (printcmd.h): New include. (string_printf): New function. (ui_printf): Removed. (printf_command): Remove static. Call string_printf. (eval_command): Call string_printf. * printcmd.h: New file. * tracepoint.c (validate_actionline, encode_actions_1): handle printf_command.
Diffstat (limited to 'gdb/printcmd.c')
-rw-r--r--gdb/printcmd.c38
1 files changed, 29 insertions, 9 deletions
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 6576dce..d89004b 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -49,6 +49,7 @@
#include "parser-defs.h"
#include "charset.h"
#include "arch-utils.h"
+#include "printcmd.h"
#ifdef TUI
#include "tui/tui.h" /* For tui_active et al. */
@@ -1960,10 +1961,9 @@ print_variable_and_value (const char *name, struct symbol *var,
fprintf_filtered (stream, "\n");
}
-/* printf "printf format string" ARG to STREAM. */
-
-static void
-ui_printf (char *arg, struct ui_file *stream)
+void
+string_printf (char *arg, struct ui_file *stream, printf_callback callback,
+ void *loc_v, void *aexpr_v)
{
char *f = NULL;
char *s = arg;
@@ -1974,6 +1974,8 @@ ui_printf (char *arg, struct ui_file *stream)
int nargs = 0;
int allocated_args = 20;
struct cleanup *old_cleanups;
+ struct bp_location *loc = loc_v;
+ struct agent_expr *aexpr = aexpr_v;
val_args = xmalloc (allocated_args * sizeof (struct value *));
old_cleanups = make_cleanup (free_current_contents, &val_args);
@@ -2296,26 +2298,42 @@ ui_printf (char *arg, struct ui_file *stream)
/* Now, parse all arguments and evaluate them.
Store the VALUEs in VAL_ARGS. */
+ if (callback)
+ current_substring = substrings;
while (*s != '\0')
{
char *s1;
+ s1 = s;
if (nargs == allocated_args)
val_args = (struct value **) xrealloc ((char *) val_args,
(allocated_args *= 2)
* sizeof (struct value *));
- s1 = s;
- val_args[nargs] = parse_to_comma_and_eval (&s1);
+ if (callback)
+ {
+ if (nargs >= nargs_wanted)
+ error (_("Wrong number of arguments for specified "
+ "format-string"));
+ callback (current_substring, &s1, loc, aexpr);
+ current_substring += strlen (current_substring) + 1;
+ }
+ else
+ val_args[nargs] = parse_to_comma_and_eval (&s1);
nargs++;
s = s1;
if (*s == ',')
s++;
}
+ if (callback)
+ callback (last_arg, NULL, loc, aexpr);
if (nargs != nargs_wanted)
error (_("Wrong number of arguments for specified format-string"));
+ if (!stream)
+ goto after_print;
+
/* Now actually print them. */
current_substring = substrings;
for (i = 0; i < nargs; i++)
@@ -2670,15 +2688,17 @@ ui_printf (char *arg, struct ui_file *stream)
by default, which will warn here if there is no argument. */
fprintf_filtered (stream, last_arg, 0);
}
+
+after_print:
do_cleanups (old_cleanups);
}
/* Implement the "printf" command. */
-static void
+void
printf_command (char *arg, int from_tty)
{
- ui_printf (arg, gdb_stdout);
+ string_printf (arg, gdb_stdout, NULL, NULL, NULL);
}
/* Implement the "eval" command. */
@@ -2690,7 +2710,7 @@ eval_command (char *arg, int from_tty)
struct cleanup *cleanups = make_cleanup_ui_file_delete (ui_out);
char *expanded;
- ui_printf (arg, ui_out);
+ string_printf (arg, ui_out, NULL, NULL, NULL);
expanded = ui_file_xstrdup (ui_out, NULL);
make_cleanup (xfree, expanded);