From patchwork Wed Jul 17 16:10:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 94083 Return-Path: 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 93E5D385E83A for ; Wed, 17 Jul 2024 16:11:46 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 04386385DDCC for ; Wed, 17 Jul 2024 16:11:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 04386385DDCC Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=polymtl.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=polymtl.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 04386385DDCC Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=132.207.4.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721232677; cv=none; b=nwoJE4LruLvUDewhovSBrmQLAXEbQI110WEXE8HzK8hA1N7Um2+P1nOvEJZoy0bpCTKgwg4bfHSkeCtL2f72S3ykVb41U6vrigmS/SOgCyF4frj+3BhlHLxIPlP1lz45LRRmjc8WdeboG3tPzZ1L7zvrHxtasIuFqqoaCs/F8lE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721232677; c=relaxed/simple; bh=O5CSAUozzXKON6ufUqzMBqFrFtW6A+NvDAt/6X3JmJM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=MElWSe7bvd0t3xrJDuozU87dR3Whe5PmdQcomdrtNySlfRLRXtOcjO/vufqH44Lj9Ar3P4x3dFjX+hl1ayFVzkWycDwGrBzgPeaXRRWh+NkpQWnGvrqmDhNHi2j/Lnqnf0mVQJEsKhE2a+D8Oka2+NdOwW/EpueZ/f1/0xxurH4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 46HGB04P052968 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 17 Jul 2024 12:11:04 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 46HGB04P052968 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=default; t=1721232665; bh=/IHaVHQ+o/AxXO22fVFVuVXDxjg+ssjLfjWn5vGFnMA=; h=From:To:Cc:Subject:Date:From; b=jOdS0Ti2ogjCogs3agWD2YC8PAMMZIqaTnIP3XJahtngxucdmgwzABzQVMDnLTxcs YdMBQVEOH7FzYK+X+uCRwAe7LLE1ys6K8O8Q4RKBOL41NGPazcNDkzZiSW6jLjY3SS 5zckb+iHx6k4s4lTOowl+DJC4DcncW+zRsqiC6Fk= Received: from simark.localdomain (modemcable238.237-201-24.mc.videotron.ca [24.201.237.238]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id DAD091E097; Wed, 17 Jul 2024 12:10:59 -0400 (EDT) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH] gdb-gdb.py: strip typedefs in intrusive_list printer assertion Date: Wed, 17 Jul 2024 12:10:57 -0400 Message-ID: <20240717161059.2458133-1-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Wed, 17 Jul 2024 16:11:00 +0000 X-Spam-Status: No, score=-3188.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org When debugging gdb itself and trying to print a intrusive_list that has more than one element, I get: File "/home/simark/build/binutils-gdb-all-targets/gdb/gdb-gdb.py", line 365, in _children_generator node_ptr = self._as_node_ptr(elem_ptr) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/simark/build/binutils-gdb-all-targets/gdb/gdb-gdb.py", line 345, in _as_node_ptr assert elem_ptr.type.code == gdb.TYPE_CODE_PTR ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AssertionError This is because node_ptr is a typedef (intrusive_list_base_iterator::pointer). Add a call to strip_typedefs to get to the real type. Enhance gdb.gdb/python-helper.exp with a test that would have caught this bug. Change-Id: I3eaca8de5ed06d05756ed979332b6a431e15b700 --- gdb/gdb-gdb.py.in | 2 +- gdb/testsuite/gdb.gdb/python-helper.exp | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) base-commit: 0ed152c5c6b3c72fc505b331ed77e08b438d643a diff --git a/gdb/gdb-gdb.py.in b/gdb/gdb-gdb.py.in index b5a7fa4f3903..7cab6941f02c 100644 --- a/gdb/gdb-gdb.py.in +++ b/gdb/gdb-gdb.py.in @@ -342,7 +342,7 @@ class IntrusiveListPrinter: corresponding intrusive_list_node. """ - assert elem_ptr.type.code == gdb.TYPE_CODE_PTR + assert elem_ptr.type.strip_typedefs().code == gdb.TYPE_CODE_PTR if self._uses_member_node(): # Node as a member: add the member node offset from to the element's diff --git a/gdb/testsuite/gdb.gdb/python-helper.exp b/gdb/testsuite/gdb.gdb/python-helper.exp index 8a8afb12257b..4589edc388fd 100644 --- a/gdb/testsuite/gdb.gdb/python-helper.exp +++ b/gdb/testsuite/gdb.gdb/python-helper.exp @@ -111,6 +111,16 @@ proc test_python_helper {} { } } + # Add a second inferior, useful to the intrusive_list pretty-printer test + # below. + send_inferior "add-inferior\n" + gdb_test_multiple "" "add second inferior in inner GDB" { + -i "$inferior_spawn_id" + -re "Added inferior 2\r\n$gdb_prompt $" { + pass $gdb_test_name + } + } + # Send Ctrl-C to the inner GDB, this should kick us back to the # prompt of the outer GDB. send_inferior "\003" @@ -253,6 +263,11 @@ 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}.*\\}" + # Test the intrusive_list pretty-printer. A bug occured in the + # pretty-printer for lists with more than one element. Verify that + # we see both elements of the inferior_list list being printed. + gdb_test -prompt $outer_prompt_re "print inferior_list" "intrusive list of inferior = {.*, num = 1,.*, num = 2,.*}" + return 0 }