aboutsummaryrefslogtreecommitdiff
path: root/gdb/ax-gdb.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2016-11-08 15:26:47 +0000
committerPedro Alves <palves@redhat.com>2016-11-08 15:26:47 +0000
commit833177a4a5c1a2a6cabe70bfe35ecf241b68d169 (patch)
treeda2e0cfdae4abf5ee493a243cae733166276f781 /gdb/ax-gdb.c
parent2f408ecb929bd56613e94cf1e84ace4692c78257 (diff)
downloadgdb-833177a4a5c1a2a6cabe70bfe35ecf241b68d169.zip
gdb-833177a4a5c1a2a6cabe70bfe35ecf241b68d169.tar.gz
gdb-833177a4a5c1a2a6cabe70bfe35ecf241b68d169.tar.bz2
'struct agent_expr *' -> unique_ptr<agent_expr>
This patch makes the gen_* functions return a unique_ptr instead of raw pointer: typedef gdb::unique_ptr<agent_expr> agent_expr_up; and then adjusts the codebase throughout to stop using make_cleanup_free_agent_expr. The cond_bytecode and cmd_bytecode fields of struct bp_location are owning pointers, so they're changed to be unique_ptr's instead of raw pointers. gdb/ChangeLog: 2016-11-08 Pedro Alves <palves@redhat.com> * ax-gdb.c (is_nontrivial_conversion): Use agent_expr_up. (gen_trace_for_var, gen_trace_for_expr, gen_eval_for_expr) (gen_trace_for_return_address, gen_printf): Use and return an agent_expr_up. Don't use make_cleanup_free_agent_expr. (agent_eval_command_one, maint_agent_printf_command): Use agent_expr_up. Don't use make_cleanup_free_agent_expr. * ax-gdb.h (gen_trace_for_expr, gen_trace_for_var) (gen_trace_for_return_address, gen_eval_for_expr, gen_printf): Use agent_expr_up. * ax-general.c (new_agent_expr): Rename to ... (agent_expr::agent_expr): ... this, and now a constructor. (free_agent_expr): Rename to ... (agent_expr::~agent_exp): ... this, and now a destructor. (do_free_agent_expr_cleanup, make_cleanup_free_agent_expr): Delete. * ax.h (struct agent_expr): Add ctor/dtor. (agent_expr_up): New typedef. (new_agent_expr, free_agent_expr, make_cleanup_free_agent_expr): Delete declarations. * breakpoint.c (parse_cond_to_aexpr): Use and return an agent_expr_up. Don't use make_cleanup_free_agent_expr. (build_target_condition_list): Adjust to use agent_expr_up. (parse_cmd_to_aexpr): Use and return an agent_expr_up. Don't use make_cleanup_free_agent_expr. (build_target_command_list): Adjust to use agent_expr_up. (force_breakpoint_reinsertion): Adjust to use agent_expr_up. (bp_location_dtor): Remove unnecessary free_agent_expr and xfree calls. * breakpoint.h (struct bp_target_info) <cond_bytecode, cmd_bytecode>: Now agent_expr_up's. * remote.c (remote_download_tracepoint): Adjust to use agent_expr_up and remove use of make_cleanup_free_agent_expr. * tracepoint.c (validate_actionline, collect_symbol): Adjust to use agent_expr_up and remove uses of make_cleanup_free_agent_expr. (collection_list::~collection_list): Call delete instead of free_agent_expr. (encode_actions_1): Adjust to use agent_expr_up and remove uses of make_cleanup_free_agent_expr. (add_aexpr): Change parameter type to agent_expr_up; Return a raw agent_expr pointer.
Diffstat (limited to 'gdb/ax-gdb.c')
-rw-r--r--gdb/ax-gdb.c140
1 files changed, 49 insertions, 91 deletions
diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c
index ccd16f2..1816ba6 100644
--- a/gdb/ax-gdb.c
+++ b/gdb/ax-gdb.c
@@ -910,7 +910,7 @@ gen_conversion (struct agent_expr *ax, struct type *from, struct type *to)
static int
is_nontrivial_conversion (struct type *from, struct type *to)
{
- struct agent_expr *ax = new_agent_expr (NULL, 0);
+ agent_expr_up ax (new agent_expr (NULL, 0));
int nontrivial;
/* Actually generate the code, and see if anything came out. At the
@@ -919,9 +919,8 @@ is_nontrivial_conversion (struct type *from, struct type *to)
floating point and the like, it may not be. Doing things this
way allows this function to be independent of the logic in
gen_conversion. */
- gen_conversion (ax, from, to);
+ gen_conversion (ax.get (), from, to);
nontrivial = ax->len > 0;
- free_agent_expr (ax);
return nontrivial;
}
@@ -2391,38 +2390,28 @@ gen_expr_binop_rest (struct expression *exp,
variable's name, and no parsed expression; for instance, when the
name comes from a list of local variables of a function. */
-struct agent_expr *
+agent_expr_up
gen_trace_for_var (CORE_ADDR scope, struct gdbarch *gdbarch,
struct symbol *var, int trace_string)
{
- struct cleanup *old_chain = 0;
- struct agent_expr *ax = new_agent_expr (gdbarch, scope);
+ agent_expr_up ax (new agent_expr (gdbarch, scope));
struct axs_value value;
- old_chain = make_cleanup_free_agent_expr (ax);
-
ax->tracing = 1;
ax->trace_string = trace_string;
- gen_var_ref (gdbarch, ax, &value, var);
+ gen_var_ref (gdbarch, ax.get (), &value, var);
/* If there is no actual variable to trace, flag it by returning
an empty agent expression. */
if (value.optimized_out)
- {
- do_cleanups (old_chain);
- return NULL;
- }
+ return agent_expr_up ();
/* Make sure we record the final object, and get rid of it. */
- gen_traced_pop (gdbarch, ax, &value);
+ gen_traced_pop (gdbarch, ax.get (), &value);
/* Oh, and terminate. */
- ax_simple (ax, aop_end);
+ ax_simple (ax.get (), aop_end);
- /* We have successfully built the agent expr, so cancel the cleanup
- request. If we add more cleanups that we always want done, this
- will have to get more complicated. */
- discard_cleanups (old_chain);
return ax;
}
@@ -2433,33 +2422,27 @@ gen_trace_for_var (CORE_ADDR scope, struct gdbarch *gdbarch,
record the value of all memory touched by the expression. The
caller can then use the ax_reqs function to discover which
registers it relies upon. */
-struct agent_expr *
+
+agent_expr_up
gen_trace_for_expr (CORE_ADDR scope, struct expression *expr,
int trace_string)
{
- struct cleanup *old_chain = 0;
- struct agent_expr *ax = new_agent_expr (expr->gdbarch, scope);
+ agent_expr_up ax (new agent_expr (expr->gdbarch, scope));
union exp_element *pc;
struct axs_value value;
- old_chain = make_cleanup_free_agent_expr (ax);
-
pc = expr->elts;
ax->tracing = 1;
ax->trace_string = trace_string;
value.optimized_out = 0;
- gen_expr (expr, &pc, ax, &value);
+ gen_expr (expr, &pc, ax.get (), &value);
/* Make sure we record the final object, and get rid of it. */
- gen_traced_pop (expr->gdbarch, ax, &value);
+ gen_traced_pop (expr->gdbarch, ax.get (), &value);
/* Oh, and terminate. */
- ax_simple (ax, aop_end);
+ ax_simple (ax.get (), aop_end);
- /* We have successfully built the agent expr, so cancel the cleanup
- request. If we add more cleanups that we always want done, this
- will have to get more complicated. */
- discard_cleanups (old_chain);
return ax;
}
@@ -2470,58 +2453,44 @@ gen_trace_for_expr (CORE_ADDR scope, struct expression *expr,
gen_trace_for_expr does. The generated bytecode sequence leaves
the result of expression evaluation on the top of the stack. */
-struct agent_expr *
+agent_expr_up
gen_eval_for_expr (CORE_ADDR scope, struct expression *expr)
{
- struct cleanup *old_chain = 0;
- struct agent_expr *ax = new_agent_expr (expr->gdbarch, scope);
+ agent_expr_up ax (new agent_expr (expr->gdbarch, scope));
union exp_element *pc;
struct axs_value value;
- old_chain = make_cleanup_free_agent_expr (ax);
-
pc = expr->elts;
ax->tracing = 0;
value.optimized_out = 0;
- gen_expr (expr, &pc, ax, &value);
+ gen_expr (expr, &pc, ax.get (), &value);
- require_rvalue (ax, &value);
+ require_rvalue (ax.get (), &value);
/* Oh, and terminate. */
- ax_simple (ax, aop_end);
+ ax_simple (ax.get (), aop_end);
- /* We have successfully built the agent expr, so cancel the cleanup
- request. If we add more cleanups that we always want done, this
- will have to get more complicated. */
- discard_cleanups (old_chain);
return ax;
}
-struct agent_expr *
+agent_expr_up
gen_trace_for_return_address (CORE_ADDR scope, struct gdbarch *gdbarch,
int trace_string)
{
- struct cleanup *old_chain = 0;
- struct agent_expr *ax = new_agent_expr (gdbarch, scope);
+ agent_expr_up ax (new agent_expr (gdbarch, scope));
struct axs_value value;
- old_chain = make_cleanup_free_agent_expr (ax);
-
ax->tracing = 1;
ax->trace_string = trace_string;
- gdbarch_gen_return_address (gdbarch, ax, &value, scope);
+ gdbarch_gen_return_address (gdbarch, ax.get (), &value, scope);
/* Make sure we record the final object, and get rid of it. */
- gen_traced_pop (gdbarch, ax, &value);
+ gen_traced_pop (gdbarch, ax.get (), &value);
/* Oh, and terminate. */
- ax_simple (ax, aop_end);
+ ax_simple (ax.get (), aop_end);
- /* We have successfully built the agent expr, so cancel the cleanup
- request. If we add more cleanups that we always want done, this
- will have to get more complicated. */
- discard_cleanups (old_chain);
return ax;
}
@@ -2529,21 +2498,18 @@ gen_trace_for_return_address (CORE_ADDR scope, struct gdbarch *gdbarch,
evaluate the arguments and pass everything to a special
bytecode. */
-struct agent_expr *
+agent_expr_up
gen_printf (CORE_ADDR scope, struct gdbarch *gdbarch,
CORE_ADDR function, LONGEST channel,
const char *format, int fmtlen,
struct format_piece *frags,
int nargs, struct expression **exprs)
{
- struct cleanup *old_chain = 0;
- struct agent_expr *ax = new_agent_expr (gdbarch, scope);
+ agent_expr_up ax (new agent_expr (gdbarch, scope));
union exp_element *pc;
struct axs_value value;
int tem;
- old_chain = make_cleanup_free_agent_expr (ax);
-
/* We're computing values, not doing side effects. */
ax->tracing = 0;
@@ -2553,26 +2519,21 @@ gen_printf (CORE_ADDR scope, struct gdbarch *gdbarch,
{
pc = exprs[tem]->elts;
value.optimized_out = 0;
- gen_expr (exprs[tem], &pc, ax, &value);
- require_rvalue (ax, &value);
+ gen_expr (exprs[tem], &pc, ax.get (), &value);
+ require_rvalue (ax.get (), &value);
}
/* Push function and channel. */
- ax_const_l (ax, channel);
- ax_const_l (ax, function);
+ ax_const_l (ax.get (), channel);
+ ax_const_l (ax.get (), function);
/* Issue the printf bytecode proper. */
- ax_simple (ax, aop_printf);
- ax_raw_byte (ax, nargs);
- ax_string (ax, format, fmtlen);
+ ax_simple (ax.get (), aop_printf);
+ ax_raw_byte (ax.get (), nargs);
+ ax_string (ax.get (), format, fmtlen);
/* And terminate. */
- ax_simple (ax, aop_end);
-
- /* We have successfully built the agent expr, so cancel the cleanup
- request. If we add more cleanups that we always want done, this
- will have to get more complicated. */
- discard_cleanups (old_chain);
+ ax_simple (ax.get (), aop_end);
return ax;
}
@@ -2580,8 +2541,6 @@ gen_printf (CORE_ADDR scope, struct gdbarch *gdbarch,
static void
agent_eval_command_one (const char *exp, int eval, CORE_ADDR pc)
{
- struct cleanup *old_chain = 0;
- struct agent_expr *agent;
const char *arg;
int trace_string = 0;
@@ -2591,33 +2550,33 @@ agent_eval_command_one (const char *exp, int eval, CORE_ADDR pc)
exp = decode_agent_options (exp, &trace_string);
}
+ agent_expr_up agent;
+
arg = exp;
if (!eval && strcmp (arg, "$_ret") == 0)
{
- agent = gen_trace_for_return_address (pc, get_current_arch (),
- trace_string);
- old_chain = make_cleanup_free_agent_expr (agent);
+ agent = gdb::move (gen_trace_for_return_address (pc, get_current_arch (),
+ trace_string));
}
else
{
expression_up expr = parse_exp_1 (&arg, pc, block_for_pc (pc), 0);
+
if (eval)
{
gdb_assert (trace_string == 0);
- agent = gen_eval_for_expr (pc, expr.get ());
+ agent = gdb::move (gen_eval_for_expr (pc, expr.get ()));
}
else
- agent = gen_trace_for_expr (pc, expr.get (), trace_string);
- old_chain = make_cleanup_free_agent_expr (agent);
+ agent = gdb::move (gen_trace_for_expr (pc, expr.get (), trace_string));
}
- ax_reqs (agent);
- ax_print (gdb_stdout, agent);
+ ax_reqs (agent.get ());
+ ax_print (gdb_stdout, agent.get ());
/* It would be nice to call ax_reqs here to gather some general info
about the expression, and then print out the result. */
- do_cleanups (old_chain);
dont_repeat ();
}
@@ -2695,7 +2654,6 @@ maint_agent_printf_command (char *exp, int from_tty)
{
struct cleanup *old_chain = 0;
struct expression *argvec[100];
- struct agent_expr *agent;
struct frame_info *fi = get_current_frame (); /* need current scope */
const char *cmdrest;
const char *format_start, *format_end;
@@ -2755,12 +2713,12 @@ maint_agent_printf_command (char *exp, int from_tty)
}
- agent = gen_printf (get_frame_pc (fi), get_current_arch (), 0, 0,
- format_start, format_end - format_start,
- fpieces, nargs, argvec);
- make_cleanup_free_agent_expr (agent);
- ax_reqs (agent);
- ax_print (gdb_stdout, agent);
+ agent_expr_up agent = gen_printf (get_frame_pc (fi), get_current_arch (),
+ 0, 0,
+ format_start, format_end - format_start,
+ fpieces, nargs, argvec);
+ ax_reqs (agent.get ());
+ ax_print (gdb_stdout, agent.get ());
/* It would be nice to call ax_reqs here to gather some general info
about the expression, and then print out the result. */