From patchwork Thu Mar 2 22:04:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Frager, Neal via Binutils" X-Patchwork-Id: 63602 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp93282wrd; Thu, 2 Mar 2023 14:07:29 -0800 (PST) X-Google-Smtp-Source: AK7set91v1yf+iiRWULapP8QgsmpBaduDKZkNfU0CQDrv+0xlrlL/jeeDL0OCPLBaPI7kyQLa4iM X-Received: by 2002:a17:907:1c28:b0:896:427b:148 with SMTP id nc40-20020a1709071c2800b00896427b0148mr16035289ejc.1.1677794849212; Thu, 02 Mar 2023 14:07:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677794849; cv=none; d=google.com; s=arc-20160816; b=qWnDvOCn0sp6B3zA5HSzqoWmwwXuJ7mSx8RTYoiDMwyRsLIWQGRfc9IwLqg1UrDidZ b4ib7MDreMuebZuKt1Q8lmq4+G1+lpx/lUn3WL8oRS09g7dWaG3kbsYgS3UbA0Js0eZx ReQljWwfkqEvR0eOcsewn4mAOFtgYd/GTQ7zjyAvwe49CKFyGMQKfRqnYfZQjvNQSror 9e/16XDJXym06CYxdEC6eWfM6ZaLpz4Cj+F8ilr+eafsA18uCFYtAAAEpCpm4+01UQui HviB2q51vOZpByrLeuCTwIahHSkIjtmU7roCFZDF90kMBcpMYm3mSbxMKfmKO8xUhqBy eshg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=q4YyzIPYBDmCuC/0VSADoH3E8OeH41eqx4ZMlbZ4Qt0=; b=aaj6COTqD3SS1E3dhfYQx03ZTouszk2c96sexYd3yFzggbplsw0M+lBvNd6oEua0Zo gcS1mjT4DxoB3gd9cvBP4ylNAPuB3urJT6OH93BGe7pctEWHNijWGUjw4QWEz23TCtf9 DiPgH48ayk1ptzmAasVYxiAQQYKibueA8RGjJ1BQ9tsRtguo3LwRhjlSW2fS13XOpBxP B6+frbFySA9KrNerxOql0ZlwqSP+kIkdACg5XGbHUYBFik2cjpYDqPWfkUuM4Vtycx5S UdPzppkNhAkutk5MxSfbxsIr0fzCRrTNI0EOB1a/TTzoDCnfByaArtkcvrR4ZyLiNUZs KMNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=XahgjpWC; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id dx13-20020a170906a84d00b008b23ed7e385si388161ejb.91.2023.03.02.14.07.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 14:07:29 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=XahgjpWC; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4908B384841D for ; Thu, 2 Mar 2023 22:05:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4908B384841D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677794740; bh=q4YyzIPYBDmCuC/0VSADoH3E8OeH41eqx4ZMlbZ4Qt0=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=XahgjpWCdzM5at+JOL/hG0YWluPJwCOA8+OWpKalL6WS11Q4KD+vY0IVfwlBIF7WV hdWZqnZMrhifS6s82gjL9Lzcy8TkmfFu2Xu5NvGZRbojRqFhHN+vnx50MrQUMEAdVV HRe4rkCe0vfuYWrF9jZhhFh/+Y5lOTCO8ucHrs9s= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from emagii.se (www.emagii.com [185.133.207.17]) by sourceware.org (Postfix) with ESMTPS id B0AFD385781A for ; Thu, 2 Mar 2023 22:04:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B0AFD385781A Received: from valinor.ownit.se (84-55-68-216.customers.ownit.se [84.55.68.216]) by emagii.se (Postfix) with ESMTPSA id 5C6031201D6; Thu, 2 Mar 2023 23:04:29 +0100 (CET) Received-SPF: pass (emagii.beebytevps.io: connection is authenticated) To: binutils@sourceware.org Cc: nickc@redhat.com, Simon Marchi , Tom Tromey Subject: [PATCH v9 04/11] gdb: add HtabPrinter to gdb-gdb.py.in Date: Thu, 2 Mar 2023 23:04:01 +0100 Message-Id: <20230302220408.1925678-5-binutils@emagii.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230302220408.1925678-1-binutils@emagii.com> References: <20230302220408.1925678-1-binutils@emagii.com> MIME-Version: 1.0 X-PPP-Message-ID: <167779466962.1167706.6231515105395084328@localhost.localdomain> X-PPP-Vhost: emagii.com X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_FAIL, SPF_PASS, 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: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ulf Samuelsson via Binutils From: "Frager, Neal via Binutils" Reply-To: binutils@emagii.com Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759295411399518927?= X-GMAIL-MSGID: =?utf-8?q?1759295411399518927?= From: Simon Marchi 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 --- 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 }