From 4d01a485d29732b19743e8b138897f3509e071b0 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Tue, 8 Nov 2016 15:26:43 +0000 Subject: 'struct expression *' -> gdb::unique_xmalloc_ptr This patch makes parse_expression and friends return a unique_ptr instead of raw pointer [1]: typedef gdb::unique_malloc_ptr expression_up; and then adjusts the codebase throughout to stop using cleanups to manage lifetime of expression pointers. Whenever I found a structure owning an expression pointer, I made it store a unique_ptr instead of a raw pointer, which then requires using new/delete of the holding structure, instead of XNEW/xfree. [1] - I'd like to set the rule that types named with an "_up" suffix are unique_ptr typedefs. Note I used gdb::unique_xmalloc_ptr instead of gdb::unique_ptr, simply because we still use xmalloc instead of new to allocate expression objects. Once that's changed, all we need to do is change the expression_up typedef and the smart pointer will then call delete instead of xfree. gdb/ChangeLog: 2016-11-08 Pedro Alves * ada-lang.c (ada_read_renaming_var_value): Use expression_up. (struct ada_catchpoint_location) : Now an expression_up. (ada_catchpoint_location_dtor): Reset excep_cond_expr instead of using xfree. (create_excep_cond_exprs): Use expression_up and gdb::move. (allocate_location_exception): Use new instead of XNEW. (should_stop_exception): Likewise. Adjust to use expression_up. (create_ada_exception_catchpoint): Use new instead of XNEW. * ax-gdb.c (agent_eval_command_one): Use expression_up instead of cleanups. (maint_agent_printf_command): Use expression_up. * break-catch-sig.c (create_signal_catchpoint): Use new instead of XNEW. * break-catch-syscall.c (create_syscall_event_catchpoint): Likewise. * break-catch-throw.c (handle_gnu_v3_exceptions): Use new instead of XCNEW. Use gdb::unique_ptr instead of cleanups. * breakpoint.c (set_breakpoint_condition, update_watchpoint) (parse_cmd_to_aexpr, watchpoint_check) (bpstat_check_breakpoint_conditions, watchpoint_locations_match): Adjust to use expression_up. (init_bp_location): Adjust. (free_bp_location): Use delete instead of xfree. (set_raw_breakpoint_without_location, set_raw_breakpoint) (add_solib_catchpoint, create_fork_vfork_event_catchpoint) (new_single_step_breakpoint, create_breakpoint_sal): Use new instead of XNEW. (find_condition_and_thread): Adjust to use expression_up. (create_breakpoint): Use new instead of XNEW. (dtor_watchpoint): Don't xfree expression pointers, they're unique_ptr's now. (insert_watchpoint, remove_watchpoint): Adjust. (watch_command_1): Use expression_up. Use new instead of XCNEW. (catch_exec_command_1): Use new instead of XNEW. (bp_location_dtor): Don't xfree expression pointers, they're unique_ptr's now. (base_breakpoint_allocate_location) (strace_marker_create_breakpoints_sal): Use new instead of XNEW. (delete_breakpoint): Use delete instead of xfree. * breakpoint.h (struct bp_location) : Now an unique_ptr instead of a raw pointer. (struct watchpoint) : Likewise. * cli/cli-script.c (execute_control_command): Use expression_up instead of cleanups. * dtrace-probe.c (dtrace_process_dof_probe): Use expression_up. * eval.c (parse_and_eval_address, parse_and_eval_long) (parse_and_eval, parse_to_comma_and_eval, parse_and_eval_type): Use expression_up instead of cleanups. * expression.h (expression_up): New typedef. (parse_expression, parse_expression_with_language, parse_exp_1): Change return type to expression_up. * mi/mi-main.c (mi_cmd_data_evaluate_expression) (print_variable_or_computed): Use expression_up. * objc-lang.c (print_object_command): Use expression_up instead of cleanups. * parse.c (parse_exp_1, parse_exp_in_context) (parse_exp_in_context_1, parse_expression) (parse_expression_with_language): Return an expression_up instead of a raw pointer. (parse_expression_for_completion): Use expression_up. * printcmd.c (struct display) : Now an expression_up instead of a raw pointer. (print_command_1, output_command_const, set_command, x_command): Use expression_up instead of cleanups. (display_command): Likewise. Use new instead of XNEW. (free_display): Use delete instead of xfree. (do_one_display): Adjust to use expression_up. * remote.c (remote_download_tracepoint): Likewise. * stack.c (return_command): Likewise. * tracepoint.c (validate_actionline, encode_actions_1): Use expression_up instead of cleanups. * typeprint.c (whatis_exp, maintenance_print_type): Likewise. * value.c (init_if_undefined_command): Likewise. * varobj.c (struct varobj_root) : Now an expression_up instead of a raw pointer. (varobj_create): Adjust. (varobj_set_value): Use an expression_up instead of cleanups. (new_root_variable): Use new instead of XNEW. (free_variable): Use delete instead of xfree. (value_of_root_1): Use std::swap. --- gdb/ada-lang.c | 37 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 25 deletions(-) (limited to 'gdb/ada-lang.c') diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index be2f47a..d1a39bc 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -4454,17 +4454,10 @@ ada_read_renaming_var_value (struct symbol *renaming_sym, const struct block *block) { const char *sym_name; - struct expression *expr; - struct value *value; - struct cleanup *old_chain = NULL; sym_name = SYMBOL_LINKAGE_NAME (renaming_sym); - expr = parse_exp_1 (&sym_name, 0, block, 0); - old_chain = make_cleanup (free_current_contents, &expr); - value = evaluate_expression (expr); - - do_cleanups (old_chain); - return value; + expression_up expr = parse_exp_1 (&sym_name, 0, block, 0); + return evaluate_expression (expr.get ()); } @@ -12308,7 +12301,7 @@ struct ada_catchpoint_location /* The condition that checks whether the exception that was raised is the specific exception the user specified on catchpoint creation. */ - struct expression *excep_cond_expr; + expression_up excep_cond_expr; }; /* Implement the DTOR method in the bp_location_ops structure for all @@ -12319,7 +12312,7 @@ ada_catchpoint_location_dtor (struct bp_location *bl) { struct ada_catchpoint_location *al = (struct ada_catchpoint_location *) bl; - xfree (al->excep_cond_expr); + al->excep_cond_expr.reset (); } /* The vtable to be used in Ada catchpoint locations. */ @@ -12371,7 +12364,7 @@ create_excep_cond_exprs (struct ada_catchpoint *c) { struct ada_catchpoint_location *ada_loc = (struct ada_catchpoint_location *) bl; - struct expression *exp = NULL; + expression_up exp; if (!bl->shlib_disabled) { @@ -12380,26 +12373,20 @@ create_excep_cond_exprs (struct ada_catchpoint *c) s = cond_string; TRY { - exp = parse_exp_1 (&s, bl->address, - block_for_pc (bl->address), 0); + exp = gdb::move (parse_exp_1 (&s, bl->address, + block_for_pc (bl->address), + 0)); } CATCH (e, RETURN_MASK_ERROR) { warning (_("failed to reevaluate internal exception condition " "for catchpoint %d: %s"), c->base.number, e.message); - /* There is a bug in GCC on sparc-solaris when building with - optimization which causes EXP to change unexpectedly - (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56982). - The problem should be fixed starting with GCC 4.9. - In the meantime, work around it by forcing EXP back - to NULL. */ - exp = NULL; } END_CATCH } - ada_loc->excep_cond_expr = exp; + ada_loc->excep_cond_expr = gdb::move (exp); } do_cleanups (old_chain); @@ -12427,7 +12414,7 @@ allocate_location_exception (enum ada_exception_catchpoint_kind ex, { struct ada_catchpoint_location *loc; - loc = XNEW (struct ada_catchpoint_location); + loc = new ada_catchpoint_location (); init_bp_location (&loc->base, &ada_catchpoint_location_ops, self); loc->excep_cond_expr = NULL; return &loc->base; @@ -12479,7 +12466,7 @@ should_stop_exception (const struct bp_location *bl) struct value *mark; mark = value_mark (); - stop = value_true (evaluate_expression (ada_loc->excep_cond_expr)); + stop = value_true (evaluate_expression (ada_loc->excep_cond_expr.get ())); value_free_to_mark (mark); } CATCH (ex, RETURN_MASK_ALL) @@ -13143,7 +13130,7 @@ create_ada_exception_catchpoint (struct gdbarch *gdbarch, struct symtab_and_line sal = ada_exception_sal (ex_kind, excep_string, &addr_string, &ops); - c = XNEW (struct ada_catchpoint); + c = new ada_catchpoint (); init_ada_exception_breakpoint (&c->base, gdbarch, sal, addr_string, ops, tempflag, disabled, from_tty); c->excep_string = excep_string; -- cgit v1.1