From: binutils@emagii.com
To: binutils@sourceware.org
Cc: nickc@redhat.com, Simon Marchi <simon.marchi@efficios.com>,
Tom Tromey <tom@tromey.com>
Subject: [PATCH v9 04/11] gdb: add HtabPrinter to gdb-gdb.py.in
Date: Thu, 2 Mar 2023 23:04:01 +0100 [thread overview]
Message-ID: <20230302220408.1925678-5-binutils@emagii.com> (raw)
In-Reply-To: <20230302220408.1925678-1-binutils@emagii.com>
From: Simon Marchi <simon.marchi@efficios.com>
When debugging GDB, I find it a bit tedious to inspect htab_t objects.
It is possible to find the entries by poking at the fields, but it's
annoying to do each time. I think a pretty printer would help. Add a
basic one to gdb-gdb.py.
The pretty printer advertises itself as "array-like", and the result
looks like:
(top-gdb) p bfcache
$3 = htab_t with 3 elements = {0x6210003252a0, 0x62100032caa0, 0x62100033baa0}
The htab_t itself doesn't know about the type of pointed objects. But
it's easy enough to cast the addresses to the right type to use them:
(top-gdb) print *((btrace_frame_cache *) 0x6210003252a0)
$6 = {tp = 0x61700002ed80, frame = 0x6210003251e0, bfun = 0x62000000b390}
Change-Id: Ia692e3555fe7a117b7ec087840246b1260a704c6
Reviewed-By: Tom Tromey <tom@tromey.com>
---
gdb/gdb-gdb.py.in | 31 +++++++++++++++++++++++++
gdb/testsuite/gdb.gdb/python-helper.exp | 3 +++
2 files changed, 34 insertions(+)
diff --git a/gdb/gdb-gdb.py.in b/gdb/gdb-gdb.py.in
index 95b7d84966f..56d063cd506 100644
--- a/gdb/gdb-gdb.py.in
+++ b/gdb/gdb-gdb.py.in
@@ -369,6 +369,35 @@ class IntrusiveListPrinter:
return self._children_generator()
+class HtabPrinter:
+ """Pretty-printer for htab_t hash tables."""
+
+ def __init__(self, val):
+ self._val = val
+
+ def display_hint(self):
+ return "array"
+
+ def to_string(self):
+ n = int(self._val["n_elements"]) - int(self._val["n_deleted"])
+ return "htab_t with {} elements".format(n)
+
+ def children(self):
+ size = int(self._val["size"])
+ entries = self._val["entries"]
+
+ child_i = 0
+ for entries_i in range(size):
+ entry = entries[entries_i]
+ # 0 (NULL pointer) means there's nothing, 1 (HTAB_DELETED_ENTRY)
+ # means there was something, but is now deleted.
+ if int(entry) in (0, 1):
+ continue
+
+ yield (str(child_i), entry)
+ child_i += 1
+
+
def type_lookup_function(val):
"""A routine that returns the correct pretty printer for VAL
if appropriate. Returns None otherwise.
@@ -383,6 +412,8 @@ def type_lookup_function(val):
return CoreAddrPrettyPrinter(val)
elif tag is not None and tag.startswith("intrusive_list<"):
return IntrusiveListPrinter(val)
+ elif name == "htab_t":
+ return HtabPrinter(val)
return None
diff --git a/gdb/testsuite/gdb.gdb/python-helper.exp b/gdb/testsuite/gdb.gdb/python-helper.exp
index f1e95fbe5ee..16b419984cf 100644
--- a/gdb/testsuite/gdb.gdb/python-helper.exp
+++ b/gdb/testsuite/gdb.gdb/python-helper.exp
@@ -208,6 +208,9 @@ proc test_python_helper {} {
" cplus_stuff = $hex}"]
gdb_test -prompt $outer_prompt_re "print *type->main_type" $answer
+ # Test the htab_t pretty-printer.
+ gdb_test -prompt $outer_prompt_re "print all_bfds" "htab_t with ${::decimal} elements = \\{${::hex}.*\\}"
+
return 0
}
--
2.34.1
next prev parent reply other threads:[~2023-03-02 22:04 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-02 22:03 [PATCH v9 0/11 Add support for CRC64 generation in linker binutils
2023-03-02 22:03 ` [PATCH v9 01/11] [gdb/testsuite] Fix gdb.rust/watch.exp on ppc64le binutils
2023-03-02 22:03 ` [PATCH v9 02/11] Remove value_in binutils
2023-03-02 22:04 ` [PATCH v9 03/11] [gdb/testsuite] Fix gdb.python/py-breakpoint.exp timeouts binutils
2023-03-02 22:04 ` binutils [this message]
2023-03-02 22:04 ` [PATCH v9 05/11] Automatic date update in version.in binutils
2023-03-02 22:04 ` [PATCH v9 06/11] Memory leak in gas do_repeat binutils
2023-03-02 22:04 ` [PATCH v9 07/11] gas s_fill caused internal error in frag_new binutils
2023-03-02 22:04 ` [PATCH v9 08/11] Catch overflow in gas s_space binutils
2023-03-02 22:04 ` [PATCH v9 09/11] [gdb/testsuite] Add another xfail case in gdb.python/py-record-btrace.exp binutils
2023-03-02 22:04 ` [PATCH v9 10/11] Fix btrace regression binutils
2023-03-02 22:04 ` [PATCH v9 11/11] Fix typo with my email address binutils
2023-03-02 23:09 ` [PATCH v9 0/11 Add support for CRC64 generation in linker Ulf Samuelsson
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=20230302220408.1925678-5-binutils@emagii.com \
--to=binutils@emagii.com \
--cc=binutils@sourceware.org \
--cc=nickc@redhat.com \
--cc=simon.marchi@efficios.com \
--cc=tom@tromey.com \
/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).