public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCHv3 1/2] gdb: have mdict_size always return a symbol count
Date: Fri, 19 May 2023 22:27:57 +0100	[thread overview]
Message-ID: <ca11ca3d286b77ef56ed6fc935e05aeee33e3de1.1684529933.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1684529933.git.aburgess@redhat.com>

In the next commit we would like to have mdict_size return the number
of symbols in the dictionary, currently mdict_size is just a
heuristic, sometimes it returns the number of symbols, and sometimes
the number of buckets in a hashing dictionary (see size_hashed in
dictionary.c).

Currently this vague notion of size is good enough, the only place
mdict_size is used is in a maintenance command in order to print a
message containing the size of the dictionary ... so we don't really
care that the value isn't correct.

However, in the next commit we do want the size returned to be the
number of symbols in the dictionary, so this commit makes mdict_size
return the symbol count in all cases.

The new use is still not on a hot path -- it's going to be a Python
__repr__ method, so all I do in this commit is have size_hashed walk
the dictionary and count the entries, obviously this could be slow if
we have a large number of symbols, but for now I'm not worrying about
that case.  We could always store the symbol count if we wanted, but
that would increase the size of every dictionary for a use case that
isn't going to be hit that often.

I've updated the text in 'maint print symbols' so that we don't talk
about the size being 'syms/buckets', but just 'symbols' now.
---
 gdb/dictionary.c | 13 ++++++++++++-
 gdb/dictionary.h |  3 +--
 gdb/symmisc.c    |  2 +-
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/gdb/dictionary.c b/gdb/dictionary.c
index 4f8df240a3e..f3dfe092830 100644
--- a/gdb/dictionary.c
+++ b/gdb/dictionary.c
@@ -650,7 +650,18 @@ insert_symbol_hashed (struct dictionary *dict,
 static int
 size_hashed (const struct dictionary *dict)
 {
-  return DICT_HASHED_NBUCKETS (dict);
+  int nbuckets = DICT_HASHED_NBUCKETS (dict);
+  int total = 0;
+
+  for (int i = 0; i < nbuckets; ++i)
+    {
+      for (struct symbol *sym = DICT_HASHED_BUCKET (dict, i);
+	   sym != nullptr;
+	   sym = sym->hash_next)
+	total++;
+    }
+
+  return total;
 }
 
 /* Functions only for DICT_HASHED_EXPANDABLE.  */
diff --git a/gdb/dictionary.h b/gdb/dictionary.h
index d982396cb31..44bd075fcf2 100644
--- a/gdb/dictionary.h
+++ b/gdb/dictionary.h
@@ -159,8 +159,7 @@ extern struct symbol *
 extern struct symbol *mdict_iter_match_next (const lookup_name_info &name,
 					     struct mdict_iterator *miterator);
 
-/* Return some notion of the size of the multidictionary: the number of
-   symbols if we have that, the number of hash buckets otherwise.  */
+/* Return the number of symbols in multidictionary MDICT.  */
 
 extern int mdict_size (const struct multidictionary *mdict);
 
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index ff7f31f885f..e414dea7bf6 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -286,7 +286,7 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
 	  /* drow/2002-07-10: We could save the total symbols count
 	     even if we're using a hashtable, but nothing else but this message
 	     wants it.  */
-	  gdb_printf (outfile, ", %d syms/buckets in ",
+	  gdb_printf (outfile, ", %d symbols in ",
 		      mdict_size (b->multidict ()));
 	  gdb_puts (paddress (gdbarch, b->start ()), outfile);
 	  gdb_printf (outfile, "..");
-- 
2.25.4


  reply	other threads:[~2023-05-19 21:28 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <3Cc9d2dc49-45c7-d6b9-c567-4ec78dd870a0>
2023-01-11  0:35 ` [PATCH] Add __repr__() implementation to a few Python types Matheus Branco Borella
2023-01-18 17:05   ` Bruno Larsen
2023-01-18 18:02   ` Andrew Burgess
2023-01-19  8:23     ` Bruno Larsen
2023-01-20  1:43     ` Matheus Branco Borella
2023-01-20 16:45       ` Andrew Burgess
2023-01-24 14:45       ` Andrew Burgess
2023-05-18  3:33         ` Matheus Branco Borella
2023-05-19 21:27           ` [PATCHv3 0/2] " Andrew Burgess
2023-05-19 21:27             ` Andrew Burgess [this message]
2023-05-19 21:27             ` [PATCHv3 2/2] gdb: add " Andrew Burgess
2023-06-07 17:05             ` [PATCHv3 0/2] Add " Matheus Branco Borella
2023-06-08 18:46               ` Andrew Burgess
2023-06-09 12:33               ` Andrew Burgess
2023-07-04 11:09                 ` Andrew Burgess

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=ca11ca3d286b77ef56ed6fc935e05aeee33e3de1.1684529933.git.aburgess@redhat.com \
    --to=aburgess@redhat.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).