Message ID | 20230209195056.100681-1-simon.marchi@efficios.com |
---|---|
State | New |
Headers |
Return-Path: <gdb-patches-bounces+patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C9F9A3857B98 for <patchwork@sourceware.org>; Thu, 9 Feb 2023 19:51:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C9F9A3857B98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675972301; bh=jifzJPObiWhOIQy+JoEZXiws1VzKAnd2vKQgLsLynKQ=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=R+PW/FeA8GlJfm2bpCyt3GQo7r+nXoZyMPAKlCkzoWfUDkNDycJyZsH7VjJEVGikk WsuNe4LmG0UmsHnJuny7SS6CsSlavnYop7uxfDg6pS3ST0KzpOQr26VRqh6fUnBZeB 85j6O4WBWbWTbG4BbdeQbB05+E5uCC5vTundAV8g= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id 267F2385B51F for <gdb-patches@sourceware.org>; Thu, 9 Feb 2023 19:50:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 267F2385B51F X-ASG-Debug-ID: 1675972257-0c856e762aa3d400001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id FcsqBOWCh5Oqkd3h (version=TLSv1 cipher=AES128-SHA bits=128 verify=NO); Thu, 09 Feb 2023 14:50:57 -0500 (EST) X-Barracuda-Envelope-From: simon.marchi@efficios.com X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from smarchi-efficios.internal.efficios.com (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) by smtp.ebox.ca (Postfix) with ESMTP id 2BA21441B21; Thu, 9 Feb 2023 14:50:57 -0500 (EST) X-Barracuda-RBL-IP: 192.222.180.24 X-Barracuda-Effective-Source-IP: 192-222-180-24.qc.cable.ebox.net[192.222.180.24] X-Barracuda-Apparent-Source-IP: 192.222.180.24 To: gdb-patches@sourceware.org Cc: Simon Marchi <simon.marchi@efficios.com> Subject: [PATCH] gdb: add HtabPrinter to gdb-gdb.py.in Date: Thu, 9 Feb 2023 14:50:56 -0500 X-ASG-Orig-Subj: [PATCH] gdb: add HtabPrinter to gdb-gdb.py.in Message-Id: <20230209195056.100681-1-simon.marchi@efficios.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1675972257 X-Barracuda-Encrypted: AES128-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-BRTS-Status: 1 X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-Scan-Msg-Size: 2594 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=5.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.104553 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-Spam-Status: No, score=-3498.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list <gdb-patches.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=subscribe> From: Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> Reply-To: Simon Marchi <simon.marchi@efficios.com> Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" <gdb-patches-bounces+patchwork=sourceware.org@sourceware.org> |
Series |
gdb: add HtabPrinter to gdb-gdb.py.in
|
|
Commit Message
Simon Marchi
Feb. 9, 2023, 7:50 p.m. UTC
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 --- gdb/gdb-gdb.py.in | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
Comments
> diff --git a/gdb/gdb-gdb.py.in b/gdb/gdb-gdb.py.in > index 95b7d84966f0..31ce80bb1e44 100644 > --- a/gdb/gdb-gdb.py.in > +++ b/gdb/gdb-gdb.py.in > @@ -369,6 +369,40 @@ class IntrusiveListPrinter: > return self._children_generator() > > > +class HtabPrinter: > + """Pretty-printer for htab_t hash tables.""" > + > + def __init__(self, val): > + self._val = val > + self._entries = val["entries"] > + self._size = int(val["size"]) Just after sending, I realized that _entries and _size aren't necessary. I removed them locally. Simon
>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes: Simon> When debugging GDB, I find it a bit tedious to inspect htab_t objects. Simon> It is possible to find the entries by poking at the fields, but it's Simon> annoying to do each time. I think a pretty printer would help. Add a Simon> basic one to gdb-gdb.py. I could have used this today :-} Simon> + def _children_generator(self): Simon> + size = int(self._val["size"]) Simon> + entries = self._val["entries"] Simon> + Simon> + child_i = 0 Simon> + for entries_i in range(size): Simon> + entry = entries[entries_i] Simon> + # 0 (NULL pointer) means there's nothing, 1 (HTAB_DELETED_ENTRY) Simon> + # means there was something, but is now deleted. Simon> + if int(entry) in (0, 1): Simon> + continue Simon> + Simon> + yield (str(child_i), entry) Simon> + child_i += 1 Simon> + Simon> + def children(self): Simon> + return self._children_generator() I don't think the indirection here is needed, you can just have children yield. But, either way seems fine to me. Reviewed-By: Tom Tromey <tom@tromey.com> Tom
On 2/27/23 13:10, Tom Tromey wrote: >>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes: > > Simon> When debugging GDB, I find it a bit tedious to inspect htab_t objects. > Simon> It is possible to find the entries by poking at the fields, but it's > Simon> annoying to do each time. I think a pretty printer would help. Add a > Simon> basic one to gdb-gdb.py. > > I could have used this today :-} > > Simon> + def _children_generator(self): > Simon> + size = int(self._val["size"]) > Simon> + entries = self._val["entries"] > Simon> + > Simon> + child_i = 0 > Simon> + for entries_i in range(size): > Simon> + entry = entries[entries_i] > Simon> + # 0 (NULL pointer) means there's nothing, 1 (HTAB_DELETED_ENTRY) > Simon> + # means there was something, but is now deleted. > Simon> + if int(entry) in (0, 1): > Simon> + continue > Simon> + > Simon> + yield (str(child_i), entry) > Simon> + child_i += 1 > Simon> + > Simon> + def children(self): > Simon> + return self._children_generator() > > I don't think the indirection here is needed, you can just have children > yield. But, either way seems fine to me. > > Reviewed-By: Tom Tromey <tom@tromey.com> Ah, you're right. Well, here's an updated version that also adds a test in gdb.gdb/python-helper.exp. From 69259c470aaad72b28b4d34a5f1d0a999f660582 Mon Sep 17 00:00:00 2001 From: Simon Marchi <simon.marchi@efficios.com> Date: Thu, 9 Feb 2023 14:50:56 -0500 Subject: [PATCH] gdb: add HtabPrinter to gdb-gdb.py.in 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 95b7d84966f0..56d063cd506b 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 f1e95fbe5ee7..16b419984cf3 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 } base-commit: 26c294bd1b8d95b421487294863eb1560b65580d
>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
Simon> Ah, you're right. Well, here's an updated version that also adds a test
Simon> in gdb.gdb/python-helper.exp.
Looks great, thank you.
Tom
On 2/28/23 09:30, Tom Tromey wrote: >>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes: > > Simon> Ah, you're right. Well, here's an updated version that also adds a test > Simon> in gdb.gdb/python-helper.exp. > > Looks great, thank you. > > Tom Pushed, thanks! Simon
diff --git a/gdb/gdb-gdb.py.in b/gdb/gdb-gdb.py.in index 95b7d84966f0..31ce80bb1e44 100644 --- a/gdb/gdb-gdb.py.in +++ b/gdb/gdb-gdb.py.in @@ -369,6 +369,40 @@ class IntrusiveListPrinter: return self._children_generator() +class HtabPrinter: + """Pretty-printer for htab_t hash tables.""" + + def __init__(self, val): + self._val = val + self._entries = val["entries"] + self._size = int(val["size"]) + + 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_generator(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 children(self): + return self._children_generator() + + def type_lookup_function(val): """A routine that returns the correct pretty printer for VAL if appropriate. Returns None otherwise. @@ -383,6 +417,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