From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway34.websitewelcome.com (gateway34.websitewelcome.com [192.185.148.200]) by sourceware.org (Postfix) with ESMTPS id 7C3F03858402 for ; Tue, 5 Oct 2021 00:14:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7C3F03858402 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tromey.com Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway34.websitewelcome.com (Postfix) with ESMTP id 0A03C452D7 for ; Mon, 4 Oct 2021 19:14:56 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id XY6hmDQttG0jLXY6imEf6u; Mon, 04 Oct 2021 19:14:56 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=n0g/xhIAHL4oPrN0OIa6dma4XJfrbrg2Sjuf4mk1D/8=; b=q9P9P3P+w8Rb6rtyz5xyFGweUe HK3vL85dBzXV1HnxD0NVBUmC+W2ERmNrbRFZmb0ahMPNw8s3TAmWKW9jgHDYtmh+ChLjzEyfqyzNA i5p3S9rvan1mggs5CLyUGzCz+; Received: from 174-16-0-219.hlrn.qwest.net ([174.16.0.219]:43158 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mXY6h-00196D-Oj; Mon, 04 Oct 2021 18:14:55 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 3/6] Use unique_xmalloc_ptr in watchpoint Date: Mon, 4 Oct 2021 18:14:50 -0600 Message-Id: <20211005001453.2957929-4-tom@tromey.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211005001453.2957929-1-tom@tromey.com> References: <20211005001453.2957929-1-tom@tromey.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 174.16.0.219 X-Source-L: No X-Exim-ID: 1mXY6h-00196D-Oj X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 174-16-0-219.hlrn.qwest.net (localhost.localdomain) [174.16.0.219]:43158 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3031.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Oct 2021 00:14:58 -0000 This changes struct watchpoint to use unique_xmalloc_ptr in a couple of places, removing a bit of manual memory management. --- gdb/breakpoint.c | 33 ++++++++++++++------------------- gdb/breakpoint.h | 6 ++---- gdb/guile/scm-breakpoint.c | 2 +- gdb/python/py-breakpoint.c | 2 +- 4 files changed, 18 insertions(+), 25 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 8016dd3b83f..477c03b7de3 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -1844,7 +1844,9 @@ update_watchpoint (struct watchpoint *b, int reparse) const char *s; b->exp.reset (); - s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; + s = (b->exp_string_reparse + ? b->exp_string_reparse.get () + : b->exp_string.get ()); b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); /* If the meaning of expression itself changed, the old value is no longer relevant. We don't want to report a watchpoint hit @@ -6131,7 +6133,7 @@ print_one_breakpoint_location (struct breakpoint *b, if (opts.addressprint) uiout->field_skip ("addr"); annotate_field (5); - uiout->field_string ("what", w->exp_string); + uiout->field_string ("what", w->exp_string.get ()); } else if (!is_catchpoint (b) || is_exception_catchpoint (b) || is_ada_exception_catchpoint (b)) @@ -6358,7 +6360,7 @@ print_one_breakpoint_location (struct breakpoint *b, { struct watchpoint *w = (struct watchpoint *) b; - uiout->field_string ("original-location", w->exp_string); + uiout->field_string ("original-location", w->exp_string.get ()); } else if (b->location != NULL && event_location_to_string (b->location.get ()) != NULL) @@ -10053,14 +10055,6 @@ watchpoint_exp_is_const (const struct expression *exp) return exp->op->constant_p (); } -/* Watchpoint destructor. */ - -watchpoint::~watchpoint () -{ - xfree (this->exp_string); - xfree (this->exp_string_reparse); -} - /* Implement the "re_set" breakpoint_ops method for watchpoints. */ static void @@ -10295,7 +10289,7 @@ print_mention_watchpoint (struct breakpoint *b) ui_out_emit_tuple tuple_emitter (uiout, tuple_name); uiout->field_signed ("number", b->number); uiout->text (": "); - uiout->field_string ("exp", w->exp_string); + uiout->field_string ("exp", w->exp_string.get ()); } /* Implement the "print_recreate" breakpoint_ops method for @@ -10323,7 +10317,7 @@ print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) _("Invalid watchpoint type.")); } - fprintf_unfiltered (fp, " %s", w->exp_string); + fprintf_unfiltered (fp, " %s", w->exp_string.get ()); print_recreate_thread (b, fp); } @@ -10488,7 +10482,7 @@ print_mention_masked_watchpoint (struct breakpoint *b) ui_out_emit_tuple tuple_emitter (uiout, tuple_name); uiout->field_signed ("number", b->number); uiout->text (": "); - uiout->field_string ("exp", w->exp_string); + uiout->field_string ("exp", w->exp_string.get ()); } /* Implement the "print_recreate" breakpoint_ops method for @@ -10515,7 +10509,7 @@ print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) _("Invalid hardware watchpoint type.")); } - fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, + fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string.get (), phex (w->hw_wp_mask, sizeof (CORE_ADDR))); print_recreate_thread (b, fp); } @@ -10794,13 +10788,14 @@ watch_command_1 (const char *arg, int accessflag, int from_tty, CORE_ADDR addr = value_as_address (val.get ()); w->exp_string_reparse - = current_language->watch_location_expression (t, addr).release (); + = current_language->watch_location_expression (t, addr); - w->exp_string = xstrprintf ("-location %.*s", - (int) (exp_end - exp_start), exp_start); + w->exp_string.reset (xstrprintf ("-location %.*s", + (int) (exp_end - exp_start), + exp_start)); } else - w->exp_string = savestring (exp_start, exp_end - exp_start); + w->exp_string.reset (savestring (exp_start, exp_end - exp_start)); if (use_mask) { diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index 2b15622f98d..ad64f8320e9 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -831,13 +831,11 @@ struct breakpoint struct watchpoint : public breakpoint { - ~watchpoint () override; - /* String form of exp to use for displaying to the user (malloc'd), or NULL if none. */ - char *exp_string; + gdb::unique_xmalloc_ptr exp_string; /* String form to use for reparsing of EXP (malloc'd) or NULL. */ - char *exp_string_reparse; + gdb::unique_xmalloc_ptr exp_string_reparse; /* The expression we are watching, or NULL if not a watchpoint. */ expression_up exp; diff --git a/gdb/guile/scm-breakpoint.c b/gdb/guile/scm-breakpoint.c index 67484e440f5..f48671f0ea9 100644 --- a/gdb/guile/scm-breakpoint.c +++ b/gdb/guile/scm-breakpoint.c @@ -883,7 +883,7 @@ gdbscm_breakpoint_expression (SCM self) wp = (struct watchpoint *) bp_smob->bp; - const char *str = wp->exp_string; + const char *str = wp->exp_string.get (); if (! str) str = ""; diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index edff03282a1..7ec73af016b 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -433,7 +433,7 @@ bppy_get_expression (PyObject *self, void *closure) wp = (struct watchpoint *) obj->bp; - str = wp->exp_string; + str = wp->exp_string.get (); if (! str) str = ""; -- 2.31.1