From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 054453858C56 for ; Tue, 21 Jun 2022 14:25:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 054453858C56 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-390-mlSRxmi1P6-1cfbLvdDX6w-1; Tue, 21 Jun 2022 10:24:57 -0400 X-MC-Unique: mlSRxmi1P6-1cfbLvdDX6w-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 29B072999B35; Tue, 21 Jun 2022 14:24:57 +0000 (UTC) Received: from [10.97.116.36] (ovpn-116-36.gru2.redhat.com [10.97.116.36]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6E0401121314; Tue, 21 Jun 2022 14:24:56 +0000 (UTC) Message-ID: Date: Tue, 21 Jun 2022 11:24:54 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH] Fix number of children of varobj with stub debug info To: Christian Walther , gdb-patches@sourceware.org References: <20220621081851.4139622-1-walther@indel.ch> From: Bruno Larsen In-Reply-To: <20220621081851.4139622-1-walther@indel.ch> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, 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 14:25:03 -0000 On 6/21/22 05:18, Christian Walther wrote: > 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). Hi! Thanks for looking at this! The mention to "print object on" looks very weird to me. The fact that without it GDB works fine makes me think that the different code path should be fixed. Looking at the comments, c-varobj.c:111 says that: /* The 'get_target_type' function calls check_typedef on result, so we can immediately check type code. No need to call check_typedef here. */ So I'd say that going specifically against this comment is not a good idea. My guess for a better solution would be checking if the type we already had (either from line 75 or line 105) matches the enclosing type, in which case we would keep the previous variable, or check which is more complete. Sorry I can't give more help, I'm still new to GDB. Also, for a version 2, it would be nice if you could provide a test case. We have a mechanism for generating custom DWARF information for compiled programs, called dwarf assembler(sorry if you knew this already). This way we can ensure GDB never regresses. Finally, please be sure to check the contribution checklist (https://sourceware.org/gdb/wiki/ContributionChecklist). You must add a whitespace before the ( for function calls. Cheers! Bruno Larsen > > 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); > }