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 <tom@tromey.com> * printcmd.c (ui_printf): Update. Use std::vector. * common/format.h (struct format_piece): Add constructor. <string>: 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 <tom@tromey.com> * ax.c (ax_printf): Update.
This commit is contained in:
parent
10af2a65c8
commit
8e481c3ba8
9 changed files with 89 additions and 136 deletions
|
@ -2226,12 +2226,8 @@ build_target_condition_list (struct bp_location *bl)
|
|||
static agent_expr_up
|
||||
parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd)
|
||||
{
|
||||
struct cleanup *old_cleanups = 0;
|
||||
struct expression **argvec;
|
||||
const char *cmdrest;
|
||||
const char *format_start, *format_end;
|
||||
struct format_piece *fpieces;
|
||||
int nargs;
|
||||
struct gdbarch *gdbarch = get_current_arch ();
|
||||
|
||||
if (cmd == NULL)
|
||||
|
@ -2248,9 +2244,7 @@ parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd)
|
|||
|
||||
format_start = cmdrest;
|
||||
|
||||
fpieces = parse_format_string (&cmdrest);
|
||||
|
||||
old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces);
|
||||
format_pieces fpieces (&cmdrest);
|
||||
|
||||
format_end = cmdrest;
|
||||
|
||||
|
@ -2268,17 +2262,14 @@ parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd)
|
|||
|
||||
/* For each argument, make an expression. */
|
||||
|
||||
argvec = (struct expression **) alloca (strlen (cmd)
|
||||
* sizeof (struct expression *));
|
||||
|
||||
nargs = 0;
|
||||
std::vector<struct expression *> argvec;
|
||||
while (*cmdrest != '\0')
|
||||
{
|
||||
const char *cmd1;
|
||||
|
||||
cmd1 = cmdrest;
|
||||
expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1);
|
||||
argvec[nargs++] = expr.release ();
|
||||
argvec.push_back (expr.release ());
|
||||
cmdrest = cmd1;
|
||||
if (*cmdrest == ',')
|
||||
++cmdrest;
|
||||
|
@ -2292,7 +2283,7 @@ parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd)
|
|||
{
|
||||
aexpr = gen_printf (scope, gdbarch, 0, 0,
|
||||
format_start, format_end - format_start,
|
||||
fpieces, nargs, argvec);
|
||||
argvec.size (), argvec.data ());
|
||||
}
|
||||
CATCH (ex, RETURN_MASK_ERROR)
|
||||
{
|
||||
|
@ -2302,8 +2293,6 @@ parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd)
|
|||
}
|
||||
END_CATCH
|
||||
|
||||
do_cleanups (old_cleanups);
|
||||
|
||||
/* We have a valid agent expression, return it. */
|
||||
return aexpr;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue