From patchwork Sat Jul 22 04:02:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 21729 Received: (qmail 58125 invoked by alias); 22 Jul 2017 04:16:09 -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 51591 invoked by uid 89); 22 Jul 2017 04:11:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.5 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= X-HELO: gproxy4.mail.unifiedlayer.com Received: from gproxy4-pub.mail.unifiedlayer.com (HELO gproxy4.mail.unifiedlayer.com) (69.89.23.142) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 22 Jul 2017 04:11:20 +0000 Received: from CMOut01 (unknown [10.0.90.82]) by gproxy4.mail.unifiedlayer.com (Postfix) with ESMTP id 1E5C9176DEE for ; Fri, 21 Jul 2017 22:02:20 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by CMOut01 with id ng2G1v00m2f2jeq01g2KLp; Fri, 21 Jul 2017 22:02:20 -0600 X-Authority-Analysis: v=2.2 cv=INByMknG c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=G3gG6ho9WtcA:10 a=zstS-IiYAAAA:8 a=J4et7b0mE_BsuhHa_wsA:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 174-29-39-24.hlrn.qwest.net ([174.29.39.24]:46080 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1dYlcO-003ptJ-GZ; Fri, 21 Jul 2017 22:02:16 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA v3 2/4] C++-ify break-catch-throw Date: Fri, 21 Jul 2017 22:02:10 -0600 Message-Id: <20170722040212.15731-3-tom@tromey.com> In-Reply-To: <20170722040212.15731-1-tom@tromey.com> References: <20170722040212.15731-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1dYlcO-003ptJ-GZ X-Source-Sender: 174-29-39-24.hlrn.qwest.net (bapiya.Home) [174.29.39.24]:46080 X-Source-Auth: tom+tromey.com X-Email-Count: 3 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes This changes exception_catchpoint's "exception_rx' member to be a std::string, and updating the users. ChangeLog 2017-06-04 Tom Tromey * break-catch-throw.c (struct exception_catchpoint) : Now a std::string. (~exception_catchpoint): Remove. (print_one_detail_exception_catchpoint): Update. (handle_gnu_v3_exceptions): Change type of except_rx. (extract_exception_regexp): Return a std::string. (catch_exception_command_1): Update. --- gdb/ChangeLog | 10 ++++++++++ gdb/break-catch-throw.c | 40 +++++++++++++--------------------------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 1540f1c..a3a23b6 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,15 @@ 2017-06-04 Tom Tromey + * break-catch-throw.c (struct exception_catchpoint) + : Now a std::string. + (~exception_catchpoint): Remove. + (print_one_detail_exception_catchpoint): Update. + (handle_gnu_v3_exceptions): Change type of except_rx. + (extract_exception_regexp): Return a std::string. + (catch_exception_command_1): Update. + +2017-06-04 Tom Tromey + * break-catch-sig.c (gdb_signal_type): Remove typedef. (struct signal_catchpoint) : Now a std::vector. diff --git a/gdb/break-catch-throw.c b/gdb/break-catch-throw.c index 0074d06..e71a885 100644 --- a/gdb/break-catch-throw.c +++ b/gdb/break-catch-throw.c @@ -76,16 +76,14 @@ static struct breakpoint_ops gnu_v3_exception_catchpoint_ops; struct exception_catchpoint : public breakpoint { - ~exception_catchpoint () override; - /* The kind of exception catchpoint. */ enum exception_event_kind kind; - /* If non-NULL, an xmalloc'd string holding the source form of the - regular expression to match against. */ + /* If not empty, a string holding the source form of the regular + expression to match against. */ - char *exception_rx; + std::string exception_rx; /* If non-NULL, a compiled regular expression which is used to determine which exceptions to stop on. */ @@ -140,13 +138,6 @@ classify_exception_breakpoint (struct breakpoint *b) return cp->kind; } -/* exception_catchpoint destructor. */ - -exception_catchpoint::~exception_catchpoint () -{ - xfree (this->exception_rx); -} - /* Implement the 'check_status' method. */ static void @@ -319,10 +310,10 @@ print_one_detail_exception_catchpoint (const struct breakpoint *b, const struct exception_catchpoint *cp = (const struct exception_catchpoint *) b; - if (cp->exception_rx != NULL) + if (!cp->exception_rx.empty ()) { uiout->text (_("\tmatching: ")); - uiout->field_string ("regexp", cp->exception_rx); + uiout->field_string ("regexp", cp->exception_rx.c_str ()); uiout->text ("\n"); } } @@ -371,15 +362,15 @@ print_recreate_exception_catchpoint (struct breakpoint *b, } static void -handle_gnu_v3_exceptions (int tempflag, char *except_rx, +handle_gnu_v3_exceptions (int tempflag, std::string &&except_rx, const char *cond_string, enum exception_event_kind ex_event, int from_tty) { std::unique_ptr pattern; - if (except_rx != NULL) + if (!except_rx.empty ()) { - pattern.reset (new compiled_regex (except_rx, REG_NOSUB, + pattern.reset (new compiled_regex (except_rx.c_str (), REG_NOSUB, _("invalid type-matching regexp"))); } @@ -410,7 +401,7 @@ handle_gnu_v3_exceptions (int tempflag, char *except_rx, STRING is updated to point to the "if" token, if it exists, or to the end of the string. */ -static char * +static std::string extract_exception_regexp (const char **string) { const char *start; @@ -435,8 +426,8 @@ extract_exception_regexp (const char **string) *string = last; if (last_space > start) - return savestring (start, last_space - start); - return NULL; + return std::string (start, last_space - start); + return std::string (); } /* Deal with "catch catch", "catch throw", and "catch rethrow" @@ -447,17 +438,14 @@ catch_exception_command_1 (enum exception_event_kind ex_event, char *arg_entry, int tempflag, int from_tty) { - char *except_rx; const char *cond_string = NULL; - struct cleanup *cleanup; const char *arg = arg_entry; if (!arg) arg = ""; arg = skip_spaces_const (arg); - except_rx = extract_exception_regexp (&arg); - cleanup = make_cleanup (xfree, except_rx); + std::string except_rx = extract_exception_regexp (&arg); cond_string = ep_parse_optional_if_clause (&arg); @@ -469,10 +457,8 @@ catch_exception_command_1 (enum exception_event_kind ex_event, && ex_event != EX_EVENT_RETHROW) error (_("Unsupported or unknown exception event; cannot catch it")); - handle_gnu_v3_exceptions (tempflag, except_rx, cond_string, + handle_gnu_v3_exceptions (tempflag, std::move (except_rx), cond_string, ex_event, from_tty); - - discard_cleanups (cleanup); } /* Implementation of "catch catch" command. */