From patchwork Thu Apr 5 21:14:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 26618 Received: (qmail 40473 invoked by alias); 5 Apr 2018 21:16:03 -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 40233 invoked by uid 89); 5 Apr 2018 21:15:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gateway31.websitewelcome.com Received: from gateway31.websitewelcome.com (HELO gateway31.websitewelcome.com) (192.185.144.96) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 05 Apr 2018 21:15:28 +0000 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway31.websitewelcome.com (Postfix) with ESMTP id 780AA4F5A for ; Thu, 5 Apr 2018 16:15:17 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 4CE1fBmTFy2aL4CE1fb5KY; Thu, 05 Apr 2018 16:15:17 -0500 Received: from 75-166-37-45.hlrn.qwest.net ([75.166.37.45]:47524 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1f4CE1-003niR-79; Thu, 05 Apr 2018 16:15:17 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 03/12] Change last_examine_value to value_ref_ptr Date: Thu, 5 Apr 2018 15:14:58 -0600 Message-Id: <20180405211507.6103-4-tom@tromey.com> In-Reply-To: <20180405211507.6103-1-tom@tromey.com> References: <20180405211507.6103-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1f4CE1-003niR-79 X-Source-Sender: 75-166-37-45.hlrn.qwest.net (bapiya.Home) [75.166.37.45]:47524 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes This patch removes some manual reference count manipulation by changing last_examine_value to be a value_ref_ptr and then updating the users. ChangeLog 2018-04-05 Tom Tromey * printcmd.c (last_examine_address): Change type to value_ref_ptr. (do_examine, x_command): Update. --- gdb/ChangeLog | 6 ++++++ gdb/printcmd.c | 21 ++++++++------------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/gdb/printcmd.c b/gdb/printcmd.c index 8822ae12e9..a6d6d7e12d 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -78,7 +78,7 @@ static CORE_ADDR last_examine_address; /* Contents of last address examined. This is not valid past the end of the `x' command! */ -static struct value *last_examine_value; +static value_ref_ptr last_examine_value; /* Largest offset between a symbolic value and an address, that will be printed as `0x1234 '. */ @@ -1093,9 +1093,6 @@ do_examine (struct format_data fmt, struct gdbarch *gdbarch, CORE_ADDR addr) object. */ last_examine_address = next_address; - if (last_examine_value) - value_decref (last_examine_value); - /* The value to be displayed is not fetched greedily. Instead, to avoid the possibility of a fetched value not being used, its retrieval is delayed until the print code @@ -1105,12 +1102,10 @@ do_examine (struct format_data fmt, struct gdbarch *gdbarch, CORE_ADDR addr) the disassembler be modified so that LAST_EXAMINE_VALUE is left with the byte sequence from the last complete instruction fetched from memory? */ - last_examine_value = value_at_lazy (val_type, next_address); - - if (last_examine_value) - release_value (last_examine_value).release (); + last_examine_value + = release_value (value_at_lazy (val_type, next_address)); - print_formatted (last_examine_value, size, &opts, gdb_stdout); + print_formatted (last_examine_value.get (), size, &opts, gdb_stdout); /* Display any branch delay slots following the final insn. */ if (format == 'i' && count == 1) @@ -1668,12 +1663,12 @@ x_command (const char *exp, int from_tty) last_format = fmt.format; /* Set a couple of internal variables if appropriate. */ - if (last_examine_value) + if (last_examine_value != nullptr) { /* Make last address examined available to the user as $_. Use the correct pointer type. */ struct type *pointer_type - = lookup_pointer_type (value_type (last_examine_value)); + = lookup_pointer_type (value_type (last_examine_value.get ())); set_internalvar (lookup_internalvar ("_"), value_from_pointer (pointer_type, last_examine_address)); @@ -1682,10 +1677,10 @@ x_command (const char *exp, int from_tty) as $__. If the last value has not been fetched from memory then don't fetch it now; instead mark it by voiding the $__ variable. */ - if (value_lazy (last_examine_value)) + if (value_lazy (last_examine_value.get ())) clear_internalvar (lookup_internalvar ("__")); else - set_internalvar (lookup_internalvar ("__"), last_examine_value); + set_internalvar (lookup_internalvar ("__"), last_examine_value.get ()); } }