From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 79D94386F43F for ; Wed, 22 Apr 2020 06:42:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 79D94386F43F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id CFAE3AA4F; Wed, 22 Apr 2020 06:42:16 +0000 (UTC) Subject: Re: [PATCH][gdb/symtab] Store external var decls in psymtab From: Tom de Vries To: gdb-patches@sourceware.org Cc: Tom Tromey References: <20200408150720.GA12386@delia> Autocrypt: addr=tdevries@suse.de; keydata= xsBNBF0ltCcBCADDhsUnMMdEXiHFfqJdXeRvgqSEUxLCy/pHek88ALuFnPTICTwkf4g7uSR7 HvOFUoUyu8oP5mNb4VZHy3Xy8KRZGaQuaOHNhZAT1xaVo6kxjswUi3vYgGJhFMiLuIHdApoc u5f7UbV+egYVxmkvVLSqsVD4pUgHeSoAcIlm3blZ1sDKviJCwaHxDQkVmSsGXImaAU+ViJ5l CwkvyiiIifWD2SoOuFexZyZ7RUddLosgsO0npVUYbl6dEMq2a5ijGF6/rBs1m3nAoIgpXk6P TCKlSWVW6OCneTaKM5C387972qREtiArTakRQIpvDJuiR2soGfdeJ6igGA1FZjU+IsM5ABEB AAHNH1RvbSBkZSBWcmllcyA8dGRldnJpZXNAc3VzZS5kZT7CwKsEEwEIAD4WIQSsnSe5hKbL MK1mGmjuhV2rbOJEoAUCXSW0JwIbAwUJA8JnAAULCQgHAgYVCgkICwIEFgIDAQIeAQIXgAAh CRDuhV2rbOJEoBYhBKydJ7mEpsswrWYaaO6FXats4kSgc48H/Ra2lq5p3dHsrlQLqM7N68Fo eRDf3PMevXy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EGwM22dP8OUY6SC94x1G81A9/xbtm9LQxKm0EiDH8KBMLfQ== Message-ID: Date: Wed, 22 Apr 2020 08:42:15 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200408150720.GA12386@delia> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-17.0 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Wed, 22 Apr 2020 06:42:20 -0000 On 08-04-2020 17:07, Tom de Vries wrote: > Hi, > > Consider a test-case consisting of source file test.c: > ... > extern int aaa; > int > main (void) > { > return 0; > } > ... > and test-2.c: > ... > int aaa = 33; > ... > compiled with debug info only for test.c: > ... > $ gcc -c test.c -g; gcc -c test2.c; gcc test.o test2.o -g > ... > > When trying to print aaa, we get: > ... > $ gdb -batch a.out -ex "print aaa" > 'aaa' has unknown type; cast it to its declared type > ... > but with -readnow we have: > ... > $ gdb -readnow -batch a.out -ex "print aaa" > $1 = 33 > ... > > In the -readnow case, the symbol for aaa in the full symtab has > LOC_UNRESOLVED, and the symbol type is combined with the minimal symbol > address, to read the value and print it without cast. > > Without the -readnow, we create partial symbols, but the aaa decl is missing > from the partial symtabs, so we find it only in the minimal symbols, resulting > in the cast request. If the aaa decl would have been in the partial symtabs, > it would have been found, and the full symtab would have been expanded, after > which things would be as with -readnow. > > The function add_partial_symbol has a comment on the LOC_UNRESOLVED + > minimal symbol addres construct at DW_TAG_variable handling: > ... > else if (pdi->is_external) > { > /* Global Variable. > Don't enter into the minimal symbol tables as there is > a minimal symbol table entry from the ELF symbols already. > Enter into partial symbol table if it has a location > descriptor or a type. > If the location descriptor is missing, new_symbol will create > a LOC_UNRESOLVED symbol, the address of the variable will then > be determined from the minimal symbol table whenever the variable > is referenced. > ... > but it's not triggered due to this test in scan_partial_symbols: > ... > case DW_TAG_variable: > ... > if (!pdi->is_declaration) > { > add_partial_symbol (pdi, cu); > } > ... > > Fix this in scan_partial_symbols by allowing external variable decls to be > added to the partial symtabs. > > Build and reg-tested on x86_64-linux. > > The patch caused this regression: > ... > (gdb) print a_thread_local^M > Cannot find thread-local storage for process 0, executable file tls/tls:^M > Cannot find thread-local variables on this target^M > (gdb) FAIL: gdb.threads/tls.exp: print a_thread_local > ... > while without the patch we have: > ... > (gdb) print a_thread_local^M > Cannot read `a_thread_local' without registers^M > (gdb) PASS: gdb.threads/tls.exp: print a_thread_local > ... > > However, without the patch but with -readnow we have the same FAIL as with the > patch. In other words, the patch has the effect that we get the same result > with and without -readnow. > > This can be explained as follows. Without the patch, and without -readnow, we > have two a_thread_locals, the def and the decl: > ... > $ gdb -batch outputs/gdb.threads/tls/tls \ > -ex "maint expand-symtabs" \ > -ex "print a_thread_local" \ > -ex "maint print symbols" \ > | grep "a_thread_local;" > Cannot read `a_thread_local' without registers > int a_thread_local; computed at runtime > int a_thread_local; unresolved > ... > while without the patch and with -readnow, we have the opposite order: > ... > $ gdb -readnow -batch outputs/gdb.threads/tls/tls \ > -ex "maint expand-symtabs" \ > -ex "print a_thread_local" \ > -ex "maint print symbols" \ > | grep "a_thread_local;" > Cannot find thread-local storage for process 0, executable file tls/tls: > Cannot find thread-local variables on this target > int a_thread_local; unresolved > int a_thread_local; computed at runtime > ... > > With the patch we have the same order with and without -readnow, but just a > different one than before without -readnow. > > AFAIU, the fact that we pick the unresolved symbol over the computed at > runtime symbol is some variant of PR24985 - "Cannot print value of global > variable because decl in one CU shadows def in other CU". > > Mark the "Cannot find thread-local variables on this target" variant a PR24985 > kfail. > > OK for trunk? Committed ( https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=317d2668d01c7ddc9545029bf56d2b8c4d2bbfeb ). Thanks, - Tom