From patchwork Tue Apr 11 15:01:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 19966 Received: (qmail 114983 invoked by alias); 11 Apr 2017 15:01:48 -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 114626 invoked by uid 89); 11 Apr 2017 15:01:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=destroys X-HELO: gproxy8.mail.unifiedlayer.com Received: from gproxy8-pub.mail.unifiedlayer.com (HELO gproxy8.mail.unifiedlayer.com) (67.222.33.93) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 11 Apr 2017 15:01:44 +0000 Received: from cmgw2 (unknown [10.0.90.83]) by gproxy8.mail.unifiedlayer.com (Postfix) with ESMTP id 4C9FE1AB5BF for ; Tue, 11 Apr 2017 09:01:27 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw2 with id 731Q1v00N2f2jeq0131TN1; Tue, 11 Apr 2017 09:01:27 -0600 X-Authority-Analysis: v=2.2 cv=LIwWeNe9 c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=AzvcPWV-tVgA:10 a=zstS-IiYAAAA:8 a=FMQDh5jUagKio6oq_KEA:9 a=M85reL8Itv1ADXav:21 a=Pf0CCB1L6HVXax6k:21 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-65-226.hlrn.qwest.net ([75.166.65.226]:50042 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1cxxIJ-0007Ml-Ih; Tue, 11 Apr 2017 09:01:23 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA v2 16/17] Add a constructor and destructor to linespec_result Date: Tue, 11 Apr 2017 09:01:11 -0600 Message-Id: <20170411150112.23207-17-tom@tromey.com> In-Reply-To: <20170411150112.23207-1-tom@tromey.com> References: <20170411150112.23207-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1cxxIJ-0007Ml-Ih X-Source-Sender: 75-166-65-226.hlrn.qwest.net (bapiya.Home) [75.166.65.226]:50042 X-Source-Auth: tom+tromey.com X-Email-Count: 17 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== linespec_result is only ever allocated on the stack, so it's relatively easy to convert to having a constructor and a destructor. This patch makes this change. This removes some cleanups. 2017-04-11 Tom Tromey * linespec.h (struct linespec_result): Add constructor and destructor. (init_linespec_result, destroy_linespec_result) (make_cleanup_destroy_linespec_result): Don't declare. * linespec.c (init_linespec_result): Remove. (linespec_result::~linespec_result): Rename from destroy_linespec_result. Update. (cleanup_linespec_result, make_cleanup_destroy_linespec_result): Remove. * breakpoint.c (create_breakpoint, break_range_command) (decode_location_default): Update. * ax-gdb.c (agent_command_1): Update. --- gdb/ChangeLog | 15 +++++++++++++++ gdb/ax-gdb.c | 5 +---- gdb/breakpoint.c | 19 +------------------ gdb/linespec.c | 35 ++++------------------------------- gdb/linespec.h | 30 ++++++++++++++---------------- 5 files changed, 35 insertions(+), 69 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 3faadc2..fc600b1 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,20 @@ 2017-04-11 Tom Tromey + * linespec.h (struct linespec_result): Add constructor and + destructor. + (init_linespec_result, destroy_linespec_result) + (make_cleanup_destroy_linespec_result): Don't declare. + * linespec.c (init_linespec_result): Remove. + (linespec_result::~linespec_result): Rename from + destroy_linespec_result. Update. + (cleanup_linespec_result, make_cleanup_destroy_linespec_result): + Remove. + * breakpoint.c (create_breakpoint, break_range_command) + (decode_location_default): Update. + * ax-gdb.c (agent_command_1): Update. + +2017-04-11 Tom Tromey + * remote.c (remote_download_tracepoint): Update. * python/py-breakpoint.c (bppy_get_location): Update. * guile/scm-breakpoint.c (bpscm_print_breakpoint_smob) diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c index 7206022..fae2e2d 100644 --- a/gdb/ax-gdb.c +++ b/gdb/ax-gdb.c @@ -2603,15 +2603,13 @@ agent_command_1 (char *exp, int eval) struct linespec_result canonical; int ix; struct linespec_sals *iter; - struct cleanup *old_chain; exp = skip_spaces (exp); - init_linespec_result (&canonical); + event_location_up location = new_linespec_location (&exp); decode_line_full (location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, (struct symtab *) NULL, 0, &canonical, NULL, NULL); - old_chain = make_cleanup_destroy_linespec_result (&canonical); exp = skip_spaces (exp); if (exp[0] == ',') { @@ -2625,7 +2623,6 @@ agent_command_1 (char *exp, int eval) for (i = 0; i < iter->sals.nelts; i++) agent_eval_command_one (exp, eval, iter->sals.sals[i].pc); } - do_cleanups (old_chain); } else agent_eval_command_one (exp, eval, get_frame_pc (get_current_frame ())); diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index afc8309..42f344a 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -9726,7 +9726,6 @@ create_breakpoint (struct gdbarch *gdbarch, unsigned flags) { struct linespec_result canonical; - struct cleanup *old_chain; struct cleanup *bkpt_chain = NULL; int pending = 0; int task = 0; @@ -9738,8 +9737,6 @@ create_breakpoint (struct gdbarch *gdbarch, if (extra_string != NULL && *extra_string == '\0') extra_string = NULL; - init_linespec_result (&canonical); - TRY { ops->create_sals_from_location (location, &canonical, type_wanted); @@ -9779,9 +9776,6 @@ create_breakpoint (struct gdbarch *gdbarch, if (!pending && VEC_empty (linespec_sals, canonical.sals)) return 0; - /* Create a chain of things that always need to be cleaned up. */ - old_chain = make_cleanup_destroy_linespec_result (&canonical); - /* ----------------------------- SNIP ----------------------------- Anything added to the cleanup chain beyond this point is assumed to be part of a breakpoint. If the breakpoint create succeeds @@ -9922,8 +9916,6 @@ create_breakpoint (struct gdbarch *gdbarch, /* That's it. Discard the cleanups for data inserted into the breakpoint. */ discard_cleanups (bkpt_chain); - /* But cleanup everything else. */ - do_cleanups (old_chain); /* error call may happen here - have BKPT_CHAIN already discarded. */ update_global_location_list (UGLL_MAY_INSERT); @@ -10372,13 +10364,10 @@ break_range_command (char *arg, int from_tty) if (arg == NULL || arg[0] == '\0') error(_("No address range specified.")); - init_linespec_result (&canonical_start); - arg_start = arg; event_location_up start_location = string_to_event_location (&arg, current_language); parse_breakpoint_sals (start_location.get (), &canonical_start); - cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start); if (arg[0] != ',') error (_("Too few arguments.")); @@ -10393,14 +10382,13 @@ break_range_command (char *arg, int from_tty) sal_start = lsal_start->sals.sals[0]; addr_string_start = savestring (arg_start, arg - arg_start); - make_cleanup (xfree, addr_string_start); + cleanup_bkpt = make_cleanup (xfree, addr_string_start); arg++; /* Skip the comma. */ arg = skip_spaces (arg); /* Parse the end location. */ - init_linespec_result (&canonical_end); arg_start = arg; /* We call decode_line_full directly here instead of using @@ -10414,8 +10402,6 @@ break_range_command (char *arg, int from_tty) sal_start.symtab, sal_start.line, &canonical_end, NULL, NULL); - make_cleanup_destroy_linespec_result (&canonical_end); - if (VEC_empty (linespec_sals, canonical_end.sals)) error (_("Could not find location of the end of the range.")); @@ -14487,7 +14473,6 @@ decode_location_default (struct breakpoint *b, { struct linespec_result canonical; - init_linespec_result (&canonical); decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace, (struct symtab *) NULL, 0, &canonical, multiple_symbols_all, @@ -14506,8 +14491,6 @@ decode_location_default (struct breakpoint *b, contents. */ lsal->sals.sals = NULL; } - - destroy_linespec_result (&canonical); } /* Prepare the global context for a re-set of breakpoint B. */ diff --git a/gdb/linespec.c b/gdb/linespec.c index bccabaf..51fa128 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -3887,45 +3887,18 @@ symbol_to_sal (struct symtab_and_line *result, return 0; } -/* See the comment in linespec.h. */ - -void -init_linespec_result (struct linespec_result *lr) -{ - memset (lr, 0, sizeof (*lr)); -} - -/* See the comment in linespec.h. */ - -void -destroy_linespec_result (struct linespec_result *ls) +linespec_result::~linespec_result () { int i; struct linespec_sals *lsal; - delete_event_location (ls->location); - for (i = 0; VEC_iterate (linespec_sals, ls->sals, i, lsal); ++i) + delete_event_location (location); + for (i = 0; VEC_iterate (linespec_sals, sals, i, lsal); ++i) { xfree (lsal->canonical); xfree (lsal->sals.sals); } - VEC_free (linespec_sals, ls->sals); -} - -/* Cleanup function for a linespec_result. */ - -static void -cleanup_linespec_result (void *a) -{ - destroy_linespec_result ((struct linespec_result *) a); -} - -/* See the comment in linespec.h. */ - -struct cleanup * -make_cleanup_destroy_linespec_result (struct linespec_result *ls) -{ - return make_cleanup (cleanup_linespec_result, ls); + VEC_free (linespec_sals, sals); } /* Return the quote characters permitted by the linespec parser. */ diff --git a/gdb/linespec.h b/gdb/linespec.h index 4e69895..7459ff8 100644 --- a/gdb/linespec.h +++ b/gdb/linespec.h @@ -54,12 +54,23 @@ typedef struct linespec_sals linespec_sals; DEF_VEC_O (linespec_sals); /* An instance of this may be filled in by decode_line_1. The caller - must call init_linespec_result to initialize it and - destroy_linespec_result to destroy it. The caller must make copies - of any data that it needs to keep. */ + must make copies of any data that it needs to keep. */ struct linespec_result { + linespec_result () + : special_display (0), + pre_expanded (0), + location (NULL), + sals (NULL) + { + } + + ~linespec_result (); + + linespec_result (const linespec_result &) = delete; + linespec_result &operator= (const linespec_result &) = delete; + /* If non-zero, the linespec should be displayed to the user. This is used by "unusual" linespecs where the ordinary `info break' display mechanism would do the wrong thing. */ @@ -80,19 +91,6 @@ struct linespec_result VEC (linespec_sals) *sals; }; -/* Initialize a linespec_result. */ - -extern void init_linespec_result (struct linespec_result *); - -/* Destroy a linespec_result. */ - -extern void destroy_linespec_result (struct linespec_result *); - -/* Return a cleanup that destroys a linespec_result. */ - -extern struct cleanup * - make_cleanup_destroy_linespec_result (struct linespec_result *); - /* Decode a linespec using the provided default symtab and line. */ extern struct symtabs_and_lines