From 8e481c3ba86e512b39b16b41de24e87a17f7d968 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 22 Nov 2017 20:17:28 -0700 Subject: C++-ify parse_format_string This replaces parse_format_string with a class, removing some constructors along the way. While doing this, I found that one argument to gen_printf is unused, so I removed it. Also, I am not completely sure, but the use of `release' in maint_agent_printf_command and parse_cmd_to_aexpr seems like it may leak expressions. Regression tested by the buildbot. ChangeLog 2017-12-08 Tom Tromey * printcmd.c (ui_printf): Update. Use std::vector. * common/format.h (struct format_piece): Add constructor. : Now const. (class format_pieces): New class. (parse_format_string, free_format_pieces) (free_format_pieces_cleanup): Remove. * common/format.c (format_pieces::format_pieces): Rename from parse_format_string. Update. (free_format_pieces, free_format_pieces_cleanup): Remove. * breakpoint.c (parse_cmd_to_aexpr): Update. Use std::vector. * ax-gdb.h (gen_printf): Remove argument. * ax-gdb.c (gen_printf): Remove "frags" argument. (maint_agent_printf_command): Update. Use std::vector. gdbserver/ChangeLog 2017-12-08 Tom Tromey * ax.c (ax_printf): Update. --- gdb/gdbserver/ax.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'gdb/gdbserver/ax.c') diff --git a/gdb/gdbserver/ax.c b/gdb/gdbserver/ax.c index 35ed2c6..7e5a409 100644 --- a/gdb/gdbserver/ax.c +++ b/gdb/gdbserver/ax.c @@ -816,30 +816,29 @@ ax_printf (CORE_ADDR fn, CORE_ADDR chan, const char *format, int nargs, ULONGEST *args) { const char *f = format; - struct format_piece *fpieces; - int i, fp; - char *current_substring; + int i; + const char *current_substring; int nargs_wanted; ax_debug ("Printf of \"%s\" with %d args", format, nargs); - fpieces = parse_format_string (&f); + format_pieces fpieces (&f); nargs_wanted = 0; - for (fp = 0; fpieces[fp].string != NULL; fp++) - if (fpieces[fp].argclass != literal_piece) + for (auto &&piece : fpieces) + if (piece.argclass != literal_piece) ++nargs_wanted; if (nargs != nargs_wanted) error (_("Wrong number of arguments for specified format-string")); i = 0; - for (fp = 0; fpieces[fp].string != NULL; fp++) + for (auto &&piece : fpieces) { - current_substring = fpieces[fp].string; + current_substring = piece.string; ax_debug ("current substring is '%s', class is %d", - current_substring, fpieces[fp].argclass); - switch (fpieces[fp].argclass) + current_substring, piece.argclass); + switch (piece.argclass) { case string_arg: { @@ -914,11 +913,10 @@ ax_printf (CORE_ADDR fn, CORE_ADDR chan, const char *format, } /* Maybe advance to the next argument. */ - if (fpieces[fp].argclass != literal_piece) + if (piece.argclass != literal_piece) ++i; } - free_format_pieces (fpieces); fflush (stdout); } -- cgit v1.1