From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 40632 invoked by alias); 5 Apr 2018 21:16:05 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 40258 invoked by uid 89); 5 Apr 2018 21:15:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.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_HELO_PASS autolearn=ham version=3.3.2 spammy=c'est X-HELO: gateway30.websitewelcome.com Received: from gateway30.websitewelcome.com (HELO gateway30.websitewelcome.com) (192.185.197.25) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 05 Apr 2018 21:15:28 +0000 Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway30.websitewelcome.com (Postfix) with ESMTP id 14B8A27A56 for ; Thu, 5 Apr 2018 16:15:18 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 4CE2f8cXs7Ovo4CE2fRY1I; Thu, 05 Apr 2018 16:15:18 -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-RN; Thu, 05 Apr 2018 16:15:17 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 05/12] Change value history to use value_ref_ptr Date: Thu, 05 Apr 2018 21:16:00 -0000 Message-Id: <20180405211507.6103-6-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-RN 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: 6 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-SW-Source: 2018-04/txt/msg00087.txt.bz2 This simplifies the value history implementation by replacing the current data structure with a std::vector, and by making the value history simply hold a reference to each value. ChangeLog 2018-04-05 Tom Tromey * value.c (VALUE_HISTORY_CHUNK, struct value_history_chunk) (value_history_chain, value_history_count): Remove. (value_history): New global. (record_latest_value, access_value_history, show_values) (preserve_values): Update. --- gdb/ChangeLog | 8 ++++++++ gdb/value.c | 66 +++++++++++------------------------------------------------ 2 files changed, 20 insertions(+), 54 deletions(-) diff --git a/gdb/value.c b/gdb/value.c index 013fcfe3ed..677ec42e63 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -881,25 +881,10 @@ value_contents_eq (const struct value *val1, LONGEST offset1, } -/* The value-history records all the values printed - by print commands during this session. Each chunk - records 60 consecutive values. The first chunk on - the chain records the most recent values. - The total number of values is in value_history_count. */ +/* The value-history records all the values printed by print commands + during this session. */ -#define VALUE_HISTORY_CHUNK 60 - -struct value_history_chunk - { - struct value_history_chunk *next; - struct value *values[VALUE_HISTORY_CHUNK]; - }; - -/* Chain of chunks now in use. */ - -static struct value_history_chunk *value_history_chain; - -static int value_history_count; /* Abs number of last entry stored. */ +static std::vector value_history; /* List of all value objects currently allocated @@ -1898,24 +1883,9 @@ record_latest_value (struct value *val) but the current contents of that location. c'est la vie... */ val->modifiable = 0; - /* Here we treat value_history_count as origin-zero - and applying to the value being stored now. */ - - i = value_history_count % VALUE_HISTORY_CHUNK; - if (i == 0) - { - struct value_history_chunk *newobj = XCNEW (struct value_history_chunk); + value_history.push_back (release_value (val)); - newobj->next = value_history_chain; - value_history_chain = newobj; - } - - value_history_chain->values[i] = release_value (val).release (); - - /* Now we regard value_history_count as origin-one - and applying to the value just stored. */ - - return ++value_history_count; + return value_history.size (); } /* Return a copy of the value in the history with sequence number NUM. */ @@ -1923,12 +1893,11 @@ record_latest_value (struct value *val) struct value * access_value_history (int num) { - struct value_history_chunk *chunk; int i; int absnum = num; if (absnum <= 0) - absnum += value_history_count; + absnum += value_history.size (); if (absnum <= 0) { @@ -1939,20 +1908,12 @@ access_value_history (int num) else error (_("History does not go back to $$%d."), -num); } - if (absnum > value_history_count) + if (absnum > value_history.size ()) error (_("History has not yet reached $%d."), absnum); absnum--; - /* Now absnum is always absolute and origin zero. */ - - chunk = value_history_chain; - for (i = (value_history_count - 1) / VALUE_HISTORY_CHUNK - - absnum / VALUE_HISTORY_CHUNK; - i > 0; i--) - chunk = chunk->next; - - return value_copy (chunk->values[absnum % VALUE_HISTORY_CHUNK]); + return value_copy (value_history[absnum].get ()); } static void @@ -1972,13 +1933,13 @@ show_values (const char *num_exp, int from_tty) else { /* "show values" means print the last 10 values. */ - num = value_history_count - 9; + num = value_history.size () - 9; } if (num <= 0) num = 1; - for (i = num; i < num + 10 && i <= value_history_count; i++) + for (i = num; i < num + 10 && i <= value_history.size (); i++) { struct value_print_options opts; @@ -2626,7 +2587,6 @@ void preserve_values (struct objfile *objfile) { htab_t copied_types; - struct value_history_chunk *cur; struct internalvar *var; int i; @@ -2634,10 +2594,8 @@ preserve_values (struct objfile *objfile) it is soon to be deleted. */ copied_types = create_copied_types_hash (objfile); - for (cur = value_history_chain; cur; cur = cur->next) - for (i = 0; i < VALUE_HISTORY_CHUNK; i++) - if (cur->values[i]) - preserve_one_value (cur->values[i], objfile, copied_types); + for (const value_ref_ptr &item : value_history) + preserve_one_value (item.get (), objfile, copied_types); for (var = internalvars; var; var = var->next) preserve_one_internalvar (var, objfile, copied_types); -- 2.13.6