From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id A7D0C385740B for ; Mon, 23 Aug 2021 10:10:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A7D0C385740B Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id D9B2A21F1B for ; Mon, 23 Aug 2021 10:10:52 +0000 (UTC) Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap1.suse-dmz.suse.de (Postfix) with ESMTPS id C59FF13A12 for ; Mon, 23 Aug 2021 10:10:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id ZuUtLyx0I2EpegAAGKfGzw (envelope-from ) for ; Mon, 23 Aug 2021 10:10:52 +0000 Date: Mon, 23 Aug 2021 12:10:51 +0200 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [committed][gdb/testsuite] Add dummy start and end CUs in dwarf assembly Message-ID: <20210823101048.GA4413@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Mon, 23 Aug 2021 10:11:04 -0000 Hi, Say one compiles a hello.c: ... $ gcc -g hello.c ... On openSUSE Leap 15.2 and Tumbleweed, the CU for hello.c is typically not the first in .debug_info, nor the last, due to presence of debug information in objects for sources like: - ../sysdeps/x86_64/start.S - init.c - ../sysdeps/x86_64/crti.S - elf-init.c - ../sysdeps/x86_64/crtn.S. On other systems, say ubuntu 18.04.5, the CU for hello.c is typically the first and the last in .debug_info. This difference has caused me to find some errors in the dwarf assembly using openSUSE, that didn't show up on other platforms. Force the same situation on other platforms by adding a dummy start and end CU. Tested on x86_64-linux. Committed to trunk. Thanks, - Tom [gdb/testsuite] Add dummy start and end CUs in dwarf assembly gdb/testsuite/ChangeLog: 2021-08-22 Tom de Vries PR testsuite/28235 * lib/dwarf.exp (Dwarf::dummy_cu): New proc. (Dwarf::assemble): Add dummy start and end CU. --- gdb/testsuite/lib/dwarf.exp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp index 52886d0701b..ce7b5983ab9 100644 --- a/gdb/testsuite/lib/dwarf.exp +++ b/gdb/testsuite/lib/dwarf.exp @@ -2252,6 +2252,13 @@ namespace eval Dwarf { } } + # Emit a dummy CU. + proc dummy_cu {} { + # Generate a CU with default options and empty body. + cu {} { + } + } + # The top-level interface to the DWARF assembler. # FILENAME is the name of the file where the generated assembly # code is written. @@ -2291,7 +2298,7 @@ namespace eval Dwarf { } set _output_file [open $filename w] - set _cu_count 0 + set _cu_count -1 _empty_array _deferred_output set _defer "" set _label_num 0 @@ -2304,11 +2311,19 @@ namespace eval Dwarf { set _debug_addr_index 0 + # Dummy CU at the start to ensure that the first CU in $body is not + # the first in .debug_info. + dummy_cu + # Not "uplevel" here, because we want to evaluate in this # namespace. This is somewhat bad because it means we can't # readily refer to outer variables. eval $body + # Dummy CU at the end to ensure that the last CU in $body is not + # the last in .debug_info. + dummy_cu + _write_deferred_output catch {close $_output_file}