Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] gdb/testsuite: make gdb.dwarf2/dw2-empty-inline-ranges.exp work when ASLR can't be disabled
@ 2026-02-05 20:42 Simon Marchi
  2026-02-06 14:14 ` Andrew Burgess
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2026-02-05 20:42 UTC (permalink / raw)
  To: gdb-patches; +Cc: Luis, Simon Marchi

A colleague that goes by the name "Luis Machado" reported a failure when
running gdb.dwarf2/dw2-empty-inline-ranges.exp.  After investigation, we
found that the conditions for the test to fail are:

 - running in an environment where GDB can't disable address space
   randomization (such as in a container where that capability is
   removed)

 - a toolchain generating position-independent executables

The test does a first run to grab the addresses of a few labels defined
in the source file.  It then crafts the DWARF using these addresses.
And then it does a second run for the actual test stuff.

When the executable is PIE and ASLR is active, then the addresses in
both runs don't agree, which the test doesn't expect.

It is possible to emulate the failure by inserting some:

    gdb_test_no_output "set disable-randomization off"

after both "prepare_for_testing" calls.  The (first) failure then
manifests as:

    FAIL: gdb.dwarf2/dw2-empty-inline-ranges.exp: dwarf_version=4: empty_loc=start: entry_pc_type=empty: stopped at entry-pc

This test compares the expected stop PC "entry_pc" with the actual stop
PC "pc".  In my example run, they were indeed different:

    pc       = 0x5603ec67a159
    entry_pc = 0x55baba6a9159

The simplest way to fix this, which this patch implements, is to use
"nopie" when building the binaries.  I don't think this affects the
effectiveness of the test.

Also, in the first run, it is longer necessary to run the inferior
before grabbing the addresses, they are going to be the same with a
non-PIE executable.  So remove that.

Change-Id: I3e9b1c056c30a49e01e1a1d3bf28f7e0e409f3c9
---
 gdb/testsuite/gdb.dwarf2/dw2-empty-inline-ranges.exp | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/gdb/testsuite/gdb.dwarf2/dw2-empty-inline-ranges.exp b/gdb/testsuite/gdb.dwarf2/dw2-empty-inline-ranges.exp
index ef75f642ac7d..16cd6ecbcfde 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-empty-inline-ranges.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-empty-inline-ranges.exp
@@ -56,11 +56,7 @@ get_func_info main
 # Compile the source file and load the executable into GDB so we can
 # extract some addresses needed for creating the DWARF.
 if { [prepare_for_testing "failed to prepare" ${testfile} \
-	  [list ${srcfile}]] } {
-    return -1
-}
-
-if {![runto_main]} {
+	  [list ${srcfile}] {debug nopie}] } {
     return -1
 }
 
@@ -187,7 +183,7 @@ proc run_test { dwarf_version empty_loc entry_pc_type } {
     write_asm_file $asm_file $dwarf_version $ranges $entry_pc_label
 
     if {[prepare_for_testing "failed to prepare" $this_testfile \
-	     [list $::srcfile $asm_file] {nodebug}]} {
+	     [list $::srcfile $asm_file] {nodebug nopie}]} {
 	return
     }
 

base-commit: 458328833813d78831a0b1a24a0984db91c95fc0
-- 
2.53.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-02-06 14:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-05 20:42 [PATCH] gdb/testsuite: make gdb.dwarf2/dw2-empty-inline-ranges.exp work when ASLR can't be disabled Simon Marchi
2026-02-06 14:14 ` Andrew Burgess
2026-02-06 14:56   ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox