From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id AB6ED3858D1E for ; Sat, 11 Mar 2023 03:15:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AB6ED3858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca Received: from [10.0.0.11] (unknown [217.28.27.60]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 36CAF1E128; Fri, 10 Mar 2023 22:15:51 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1678504551; bh=wMIFTRhwNHNWbUmp5xsYI5oVIerokfd45mmEXQmbZPQ=; h=Date:Subject:To:References:From:In-Reply-To:From; b=N3mN7eMq+0OjLVb7T6CuvhoXI33/OdYForRqGQ3K12d7LrnW76FZ2PxNGPxmVNEmz mLBLgoKJguPIT7MUVeBZHt8OYOaRRN6GaMtjf4QyGHktVJo6nOSseSFEmGsXnT9zDq ZvUNFQuf4NpbooGurBEoFnxHuOpNFVrrCfGbXnQk= Message-ID: <41ac36c3-2c31-c78b-9d48-57be9402bf14@simark.ca> Date: Fri, 10 Mar 2023 22:15:50 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [PATCH] Fix htab_t pretty-printer for NULL values Content-Language: en-US To: Tom Tromey , gdb-patches@sourceware.org References: <20230308205628.4021427-1-tom@tromey.com> From: Simon Marchi In-Reply-To: <20230308205628.4021427-1-tom@tromey.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,SPF_HELO_PASS,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 List-Id: On 3/8/23 15:56, Tom Tromey wrote: > I was debugging gdb and was surprised to see this in a > compunit_symtab: > > m_call_site_htab = , > > Debugging showed that the field was not uninitialized; rather, the > htab_t pretty-printer did not cope with NULL. > --- > gdb/gdb-gdb.py.in | 5 +++++ > gdb/testsuite/gdb.gdb/python-helper.exp | 2 ++ > 2 files changed, 7 insertions(+) > > diff --git a/gdb/gdb-gdb.py.in b/gdb/gdb-gdb.py.in > index 56d063cd506..567ec41b305 100644 > --- a/gdb/gdb-gdb.py.in > +++ b/gdb/gdb-gdb.py.in > @@ -379,10 +379,15 @@ class HtabPrinter: > return "array" > > def to_string(self): > + if int(self._val) == 0: > + return "(null)" > n = int(self._val["n_elements"]) - int(self._val["n_deleted"]) > return "htab_t with {} elements".format(n) It would make me tremendously happy if you put a blank line after the return null :). > > def children(self): > + if int(self._val) == 0: > + return > + > size = int(self._val["size"]) > entries = self._val["entries"] > > diff --git a/gdb/testsuite/gdb.gdb/python-helper.exp b/gdb/testsuite/gdb.gdb/python-helper.exp > index 16b419984cf..be0b311e8ca 100644 > --- a/gdb/testsuite/gdb.gdb/python-helper.exp > +++ b/gdb/testsuite/gdb.gdb/python-helper.exp > @@ -211,6 +211,8 @@ proc test_python_helper {} { > # Test the htab_t pretty-printer. > gdb_test -prompt $outer_prompt_re "print all_bfds" "htab_t with ${::decimal} elements = \\{${::hex}.*\\}" > > + gdb_test -prompt $outer_prompt_re "print (htab_t) 0x0" \ > + [string_to_regexp " = (null)"] Instead of hardcoding (null), what about not selecting the pretty printer when the value is nullptr? Like this: diff --git a/gdb/gdb-gdb.py.in b/gdb/gdb-gdb.py.in index 567ec41b305b..5092512eaca9 100644 --- a/gdb/gdb-gdb.py.in +++ b/gdb/gdb-gdb.py.in @@ -379,15 +379,10 @@ class HtabPrinter: return "array" def to_string(self): - if int(self._val) == 0: - return "(null)" n = int(self._val["n_elements"]) - int(self._val["n_deleted"]) return "htab_t with {} elements".format(n) def children(self): - if int(self._val) == 0: - return - size = int(self._val["size"]) entries = self._val["entries"] @@ -418,7 +413,9 @@ def type_lookup_function(val): elif tag is not None and tag.startswith("intrusive_list<"): return IntrusiveListPrinter(val) elif name == "htab_t": - return HtabPrinter(val) + if int(val) != 0: + return HtabPrinter(val) + return None Can the value's value change after a pretty printer was selected for it? In that case, my idea wouldn't work, because the value could become nullptr under the pretty printer's feet. Simon