From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ms9.webland.ch (ms9.webland.ch [92.43.217.109]) by sourceware.org (Postfix) with ESMTPS id 1BE5F383EC73 for ; Tue, 21 Jun 2022 08:19:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1BE5F383EC73 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=indel.ch Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=ms9.webland.ch Received: from macserver.private ([77.58.17.252]) by ms9.webland.ch (12.3.0 build 2 x64) with ASMTP id 01202206211019464999 for ; Tue, 21 Jun 2022 10:19:46 +0200 Received: from localhost (localhost [127.0.0.1]) by macserver.private (Postfix) with ESMTP id C03184C98FD1; Tue, 21 Jun 2022 10:19:45 +0200 (CEST) X-Virus-Scanned: amavisd-new at indel.ch Received: from macserver.private ([127.0.0.1]) by localhost (macserver.private [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id h0bMl3wr6Hsp; Tue, 21 Jun 2022 10:19:45 +0200 (CEST) Received: from localhost.localdomain (unknown [192.168.1.109]) by macserver.private (Postfix) with ESMTP id 9152A4C98FCA; Tue, 21 Jun 2022 10:19:45 +0200 (CEST) From: Christian Walther To: gdb-patches@sourceware.org Cc: Christian Walther Subject: [PATCH] Fix number of children of varobj with stub debug info Date: Tue, 21 Jun 2022 10:18:51 +0200 Message-Id: <20220621081851.4139622-1-walther@indel.ch> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CTCH: RefID="str=0001.0A782F19.62B17F23.0014,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0"; Spam="Unknown"; VOD="Unknown" X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jun 2022 08:19:55 -0000 GDB under some circumstances wrongly reports 'numchild="0"' on a variable object for a pointer to a C++ class instance when the type description from the debug info is a stub that does not include members. The code path is missing a call to check_typedef() to look up the complete type description. This commit adds it. Additional conditions for the bug to occur: 1. "print object" is set to "on" 2. The class has no run-time type identification (no vtable). Debug information of this kind is generated by Clang 13. --- Note: I am not certain whether this is the best place to insert the missing call, or whether placing it somewhere else would benefit other code paths too. It does fix my particular problem where I put it. Steps to reproduce: 1. Create the following three files: main.cpp ---------------- #include #include "c.h" extern "C" int main(int argc, char** argv) { C* c = new C(5); printf("Hello World! %d\n", c->getX()); return 0; } ---------------- c.h ---------------- class C { public: C(int ax); int getX(); private: int x; }; ---------------- c.cpp ---------------- #include "c.h" C::C(int ax) : x(ax) {} int C::getX() { return x; } ---------------- 2. Compile them with Clang 13: clang+llvm-13.0.1-x86_64-linux-gnu-ubuntu-18.04/bin/clang++ -g -O0 -c -o main.o main.cpp clang+llvm-13.0.1-x86_64-linux-gnu-ubuntu-18.04/bin/clang++ -g -O0 -c -o c.o c.cpp clang+llvm-13.0.1-x86_64-linux-gnu-ubuntu-18.04/bin/clang++ -g -o mini main.o c.o 3. Verify that the debug information of main.o only contains a stub definition of class C that does not include member x: readelf --debug-dump=info main.o It should look roughly like this and not contain any DW_TAG_member: <1><690>: Abbrev Number: 23 (DW_TAG_class_type) <691> DW_AT_name : (indirect string, offset: 0x265): C <695> DW_AT_declaration : 1 (I have not been able to reproduce this with clang+llvm-12.0.1-x86_64-linux-gnu-ubuntu-16.04, which generates a full definition, and clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04, which generates invalid debug info.) 4. Debug: gdb --interpreter mi2 --args mini -break-insert main.cpp:6 -gdb-set print object on -exec-run -var-create - * c -gdb-exit Expected result: ^done,name="var1",numchild="1",value="0x...",type="C *",thread-id="1",has_more="0" Actual result: ^done,name="var1",numchild="0",value="0x...",type="C *",thread-id="1",has_more="0" --- gdb/c-varobj.c | 1 + 1 file changed, 1 insertion(+) diff --git a/gdb/c-varobj.c b/gdb/c-varobj.c index 8fecbd57e08..0c0b1abe968 100644 --- a/gdb/c-varobj.c +++ b/gdb/c-varobj.c @@ -121,6 +121,7 @@ adjust_value_for_child_access (struct value **value, enclosing_type = value_actual_type (*value, 1, &real_type_found); if (real_type_found) { + enclosing_type = check_typedef(enclosing_type); *type = enclosing_type; *value = value_cast (enclosing_type, *value); } -- 2.25.1