From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 05/12] Change value history to use value_ref_ptr
Date: Thu, 05 Apr 2018 21:16:00 -0000 [thread overview]
Message-ID: <20180405211507.6103-6-tom@tromey.com> (raw)
In-Reply-To: <20180405211507.6103-1-tom@tromey.com>
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 <tom@tromey.com>
* 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_ref_ptr> value_history;
\f
/* 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
next prev parent reply other threads:[~2018-04-05 21:16 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-05 21:16 [RFA 00/12] (somewhat) clean up struct value ownership Tom Tromey
2018-04-05 21:16 ` [RFA 10/12] Change value::parent to a value_ref_ptr Tom Tromey
2018-04-05 21:16 ` [RFA 12/12] Change value::contents to be a unique_xmalloc_ptr Tom Tromey
2018-04-05 21:16 ` [RFA 09/12] Use new and delete for values Tom Tromey
2018-04-05 21:16 ` [RFA 11/12] Remove range_s VEC Tom Tromey
2018-04-05 21:16 ` Tom Tromey [this message]
2018-04-05 21:16 ` [RFA 01/12] Introduce a gdb_ref_ptr specialization for struct value Tom Tromey
2018-04-06 19:29 ` Pedro Alves
2018-04-05 21:16 ` [RFA 02/12] Change breakpoints to use value_ref_ptr Tom Tromey
2018-04-06 19:31 ` Pedro Alves
2018-04-06 21:31 ` Tom Tromey
2018-04-05 21:16 ` [RFA 07/12] Remove free_value_chain Tom Tromey
2018-04-05 21:16 ` [RFA 06/12] Remove free_all_values Tom Tromey
2018-04-05 21:16 ` [RFA 08/12] Remove value::next and value::released Tom Tromey
2018-04-06 19:32 ` Pedro Alves
2018-04-06 21:40 ` Tom Tromey
2018-04-05 21:16 ` [RFA 03/12] Change last_examine_value to value_ref_ptr Tom Tromey
2018-04-05 21:16 ` [RFA 04/12] Change varobj to use value_ref_ptr Tom Tromey
2018-04-06 19:33 ` [RFA 00/12] (somewhat) clean up struct value ownership Pedro Alves
2018-04-06 21:20 ` Tom Tromey
2018-04-06 21:44 ` Tom Tromey
2018-04-08 21:32 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180405211507.6103-6-tom@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox