From patchwork Sun Aug 20 13:54:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 22243 Received: (qmail 100708 invoked by alias); 20 Aug 2017 14:06:31 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 100625 invoked by uid 89); 20 Aug 2017 14:06:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=junk, Junk, splits X-HELO: gproxy5-pub.mail.unifiedlayer.com Received: from gproxy5-pub.mail.unifiedlayer.com (HELO gproxy5-pub.mail.unifiedlayer.com) (67.222.38.55) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 20 Aug 2017 14:06:22 +0000 Received: from cmgw2 (unknown [10.0.90.83]) by gproxy5.mail.unifiedlayer.com (Postfix) with ESMTP id E47941407B1 for ; Sun, 20 Aug 2017 07:54:07 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw2 with id zRu41v00f2f2jeq01Ru7ZS; Sun, 20 Aug 2017 07:54:07 -0600 X-Authority-Analysis: v=2.2 cv=T7z8d7CQ c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=KeKAF7QvOSUA:10 a=zstS-IiYAAAA:8 a=0o_M4se4w1Y5CgMCoCQA:9 a=jMkuYxM8iZyjwK5Z:21 a=J5_lkVVenX6cBUx3:21 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-24-97.hlrn.qwest.net ([75.166.24.97]:52042 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1djQg0-002nd1-OA; Sun, 20 Aug 2017 07:54:04 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 2/2] Change install_breakpoint to take a std::unique_ptr Date: Sun, 20 Aug 2017 07:54:02 -0600 Message-Id: <20170820135402.1213-3-tom@tromey.com> In-Reply-To: <20170820135402.1213-1-tom@tromey.com> References: <20170820135402.1213-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1djQg0-002nd1-OA X-Source-Sender: 75-166-24-97.hlrn.qwest.net (bapiya.Home) [75.166.24.97]:52042 X-Source-Auth: tom+tromey.com X-Email-Count: 3 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes This changes install_breakpoint to take a std::unique_ptr rvalue-ref argument. This makes it clear that install_breakpoint takes ownership of the pointer, and prevents bugs like the one fixed by the previous patch. gdb/ChangeLog 2017-08-19 Tom Tromey * breakpoint.h (install_breakpoint): Update. * breakpoint.c (add_solib_catchpoint): Update. (install_breakpoint): Change argument to a std::unique_ptr. (create_fork_vfork_event_catchpoint): Use std::unique_ptr. (create_breakpoint_sal, create_breakpoint): Update. (watch_command_1, catch_exec_command_1) (strace_marker_create_breakpoints_sal): Use std::unique_ptr. * break-catch-throw.c (handle_gnu_v3_exceptions): Use std::unique_ptr. * break-catch-syscall.c (create_syscall_event_catchpoint): Use std::unique_ptr. * break-catch-sig.c (create_signal_catchpoint): Use std::unique_ptr. * ada-lang.c (create_ada_exception_catchpoint): Use std::unique_ptr. --- gdb/ChangeLog | 18 +++++++++++++++ gdb/ada-lang.c | 11 +++++----- gdb/break-catch-sig.c | 7 +++--- gdb/break-catch-syscall.c | 7 +++--- gdb/break-catch-throw.c | 3 +-- gdb/breakpoint.c | 56 +++++++++++++++++++---------------------------- gdb/breakpoint.h | 2 +- 7 files changed, 54 insertions(+), 50 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 339ab3a..8f0a22f 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,23 @@ 2017-08-19 Tom Tromey + * breakpoint.h (install_breakpoint): Update. + * breakpoint.c (add_solib_catchpoint): Update. + (install_breakpoint): Change argument to a std::unique_ptr. + (create_fork_vfork_event_catchpoint): Use std::unique_ptr. + (create_breakpoint_sal, create_breakpoint): Update. + (watch_command_1, catch_exec_command_1) + (strace_marker_create_breakpoints_sal): Use std::unique_ptr. + * break-catch-throw.c (handle_gnu_v3_exceptions): Use + std::unique_ptr. + * break-catch-syscall.c (create_syscall_event_catchpoint): Use + std::unique_ptr. + * break-catch-sig.c (create_signal_catchpoint): Use + std::unique_ptr. + * ada-lang.c (create_ada_exception_catchpoint): Use + std::unique_ptr. + +2017-08-19 Tom Tromey + * breakpoint.c (add_solib_catchpoint): Use std::unique_ptr. 2017-08-18 Tom Tromey diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 280247b..476f700 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -13010,20 +13010,19 @@ create_ada_exception_catchpoint (struct gdbarch *gdbarch, int disabled, int from_tty) { - struct ada_catchpoint *c; char *addr_string = NULL; const struct breakpoint_ops *ops = NULL; struct symtab_and_line sal = ada_exception_sal (ex_kind, excep_string, &addr_string, &ops); - c = new ada_catchpoint (); - init_ada_exception_breakpoint (c, gdbarch, sal, addr_string, + std::unique_ptr c (new ada_catchpoint ()); + init_ada_exception_breakpoint (c.get (), gdbarch, sal, addr_string, ops, tempflag, disabled, from_tty); c->excep_string = excep_string; - create_excep_cond_exprs (c); + create_excep_cond_exprs (c.get ()); if (cond_string != NULL) - set_breakpoint_condition (c, cond_string, from_tty); - install_breakpoint (0, c, 1); + set_breakpoint_condition (c.get (), cond_string, from_tty); + install_breakpoint (0, std::move (c), 1); } /* Implement the "catch exception" command. */ diff --git a/gdb/break-catch-sig.c b/gdb/break-catch-sig.c index 98888c9..9b8cf64 100644 --- a/gdb/break-catch-sig.c +++ b/gdb/break-catch-sig.c @@ -317,15 +317,14 @@ static void create_signal_catchpoint (int tempflag, std::vector &&filter, bool catch_all) { - struct signal_catchpoint *c; struct gdbarch *gdbarch = get_current_arch (); - c = new signal_catchpoint (); - init_catchpoint (c, gdbarch, tempflag, NULL, &signal_catchpoint_ops); + std::unique_ptr c (new signal_catchpoint ()); + init_catchpoint (c.get (), gdbarch, tempflag, NULL, &signal_catchpoint_ops); c->signals_to_be_caught = std::move (filter); c->catch_all = catch_all; - install_breakpoint (0, c, 1); + install_breakpoint (0, std::move (c), 1); } diff --git a/gdb/break-catch-syscall.c b/gdb/break-catch-syscall.c index 701645e..1be29be 100644 --- a/gdb/break-catch-syscall.c +++ b/gdb/break-catch-syscall.c @@ -370,14 +370,13 @@ static void create_syscall_event_catchpoint (int tempflag, std::vector &&filter, const struct breakpoint_ops *ops) { - struct syscall_catchpoint *c; struct gdbarch *gdbarch = get_current_arch (); - c = new syscall_catchpoint (); - init_catchpoint (c, gdbarch, tempflag, NULL, ops); + std::unique_ptr c (new syscall_catchpoint ()); + init_catchpoint (c.get (), gdbarch, tempflag, NULL, ops); c->syscalls_to_be_caught = std::move (filter); - install_breakpoint (0, c, 1); + install_breakpoint (0, std::move (c), 1); } /* Splits the argument using space as delimiter. */ diff --git a/gdb/break-catch-throw.c b/gdb/break-catch-throw.c index 5318e5f..b5322fc 100644 --- a/gdb/break-catch-throw.c +++ b/gdb/break-catch-throw.c @@ -387,8 +387,7 @@ handle_gnu_v3_exceptions (int tempflag, std::string &&except_rx, re_set_exception_catchpoint (cp.get ()); - install_breakpoint (0, cp.get (), 1); - cp.release (); + install_breakpoint (0, std::move (cp), 1); } /* Look for an "if" token in *STRING. The "if" token must be preceded diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 135741a..b0881ec 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -8485,7 +8485,7 @@ add_solib_catchpoint (const char *arg, int is_load, int is_temp, int enabled) c->enable_state = enabled ? bp_enabled : bp_disabled; - install_breakpoint (0, c.release (), 1); + install_breakpoint (0, std::move (c), 1); } /* A helper function that does all the work for "catch load" and @@ -8540,8 +8540,10 @@ init_catchpoint (struct breakpoint *b, } void -install_breakpoint (int internal, struct breakpoint *b, int update_gll) +install_breakpoint (int internal, std::unique_ptr &&arg, int update_gll) { + breakpoint *b = arg.release (); + add_to_breakpoint_chain (b); set_breakpoint_number (internal, b); if (is_tracepoint (b)) @@ -8559,13 +8561,13 @@ create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, int tempflag, const char *cond_string, const struct breakpoint_ops *ops) { - struct fork_catchpoint *c = new fork_catchpoint (); + std::unique_ptr c (new fork_catchpoint ()); - init_catchpoint (c, gdbarch, tempflag, cond_string, ops); + init_catchpoint (c.get (), gdbarch, tempflag, cond_string, ops); c->forked_inferior_pid = null_ptid; - install_breakpoint (0, c, 1); + install_breakpoint (0, std::move (c), 1); } /* Exec catchpoints. */ @@ -9308,7 +9310,7 @@ create_breakpoint_sal (struct gdbarch *gdbarch, enabled, internal, flags, display_canonical); - install_breakpoint (internal, b.release (), 0); + install_breakpoint (internal, std::move (b), 0); } /* Add SALS.nelts breakpoints to the breakpoint table. For each @@ -9798,7 +9800,7 @@ create_breakpoint (struct gdbarch *gdbarch, && type_wanted != bp_hardware_breakpoint) || thread != -1) b->pspace = current_program_space; - install_breakpoint (internal, b.release (), 0); + install_breakpoint (internal, std::move (b), 0); } if (VEC_length (linespec_sals, canonical.sals) > 1) @@ -10961,7 +10963,6 @@ watch_command_1 (const char *arg, int accessflag, int from_tty, the hardware watchpoint. */ int use_mask = 0; CORE_ADDR mask = 0; - struct watchpoint *w; char *expression; struct cleanup *back_to; @@ -11182,13 +11183,13 @@ watch_command_1 (const char *arg, int accessflag, int from_tty, else bp_type = bp_hardware_watchpoint; - w = new watchpoint (); + std::unique_ptr w (new watchpoint ()); if (use_mask) - init_raw_breakpoint_without_location (w, NULL, bp_type, + init_raw_breakpoint_without_location (w.get (), NULL, bp_type, &masked_watchpoint_breakpoint_ops); else - init_raw_breakpoint_without_location (w, NULL, bp_type, + init_raw_breakpoint_without_location (w.get (), NULL, bp_type, &watchpoint_breakpoint_ops); w->thread = thread; w->disposition = disp_donttouch; @@ -11243,26 +11244,17 @@ watch_command_1 (const char *arg, int accessflag, int from_tty, /* The scope breakpoint is related to the watchpoint. We will need to act on them together. */ w->related_breakpoint = scope_breakpoint; - scope_breakpoint->related_breakpoint = w; + scope_breakpoint->related_breakpoint = w.get (); } if (!just_location) value_free_to_mark (mark); - TRY - { - /* Finally update the new watchpoint. This creates the locations - that should be inserted. */ - update_watchpoint (w, 1); - } - CATCH (e, RETURN_MASK_ALL) - { - delete_breakpoint (w); - throw_exception (e); - } - END_CATCH + /* Finally update the new watchpoint. This creates the locations + that should be inserted. */ + update_watchpoint (w.get (), 1); - install_breakpoint (internal, w, 1); + install_breakpoint (internal, std::move (w), 1); do_cleanups (back_to); } @@ -11710,7 +11702,6 @@ catch_exec_command_1 (char *arg_entry, int from_tty, struct cmd_list_element *command) { const char *arg = arg_entry; - struct exec_catchpoint *c; struct gdbarch *gdbarch = get_current_arch (); int tempflag; const char *cond_string = NULL; @@ -11731,12 +11722,12 @@ catch_exec_command_1 (char *arg_entry, int from_tty, if ((*arg != '\0') && !isspace (*arg)) error (_("Junk at end of arguments.")); - c = new exec_catchpoint (); - init_catchpoint (c, gdbarch, tempflag, cond_string, + std::unique_ptr c (new exec_catchpoint ()); + init_catchpoint (c.get (), gdbarch, tempflag, cond_string, &catch_exec_breakpoint_ops); c->exec_pathname = NULL; - install_breakpoint (0, c, 1); + install_breakpoint (0, std::move (c), 1); } void @@ -13559,7 +13550,6 @@ strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, for (i = 0; i < lsal->sals.nelts; ++i) { struct symtabs_and_lines expanded; - struct tracepoint *tp; event_location_up location; expanded.nelts = 1; @@ -13567,8 +13557,8 @@ strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, location = copy_event_location (canonical->location.get ()); - tp = new tracepoint (); - init_breakpoint_sal (tp, gdbarch, expanded, + std::unique_ptr tp (new tracepoint ()); + init_breakpoint_sal (tp.get (), gdbarch, expanded, std::move (location), NULL, std::move (cond_string), std::move (extra_string), @@ -13584,7 +13574,7 @@ strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, corresponds to this one */ tp->static_trace_marker_id_idx = i; - install_breakpoint (internal, tp, 0); + install_breakpoint (internal, std::move (tp), 0); } } diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index d955184..dc2b098 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -1296,7 +1296,7 @@ extern void init_catchpoint (struct breakpoint *b, the internal breakpoint count. If UPDATE_GLL is non-zero, update_global_location_list will be called. */ -extern void install_breakpoint (int internal, struct breakpoint *b, +extern void install_breakpoint (int internal, std::unique_ptr &&b, int update_gll); /* Flags that can be passed down to create_breakpoint, etc., to affect