public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [committed][gdb/testsuite] Add dummy start and end CUs in dwarf assembly
Date: Mon, 23 Aug 2021 12:10:51 +0200	[thread overview]
Message-ID: <20210823101048.GA4413@delia> (raw)

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  <tdevries@suse.de>

	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}

                 reply	other threads:[~2021-08-23 10:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210823101048.GA4413@delia \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).