This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch 2/5] [ppc64] testsuite: break-interp.exp: Fix errors


Hi,

as suggested by Luis Machado the `dl_main' breakpoint currently in use by this
testcase is too early.  On ppc64 `_start' symbol is the function descriptor
while `._start' is the real function code.  But for PIE the function
descriptor must be relocated first by ld.so.

`dl_main' was chosen before as it is just a nice symbol usable for both the
`break' command and for checking in the `bt' command output etc.
But `_dl_debug_state' is a more suitable ld.so point for such stop - such as
due to the relocations.  Just `break' at `_dl_debug_state' does not work much
transparently as GDB has an internal breakpoint there.  Also it may not be
called `_dl_debug_state' on target ld.so but as this testcase is already linux
specific this assumption is made (`dl_main' also was not much crossplatform
before).


Thanks,
Jan


gdb/testsuite/
2010-09-27  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Fix missing _start PIE relocation on ppc64 due to stop on dl_main.
	* break-interp.exp (reach): Move the core body ...
	(reach_1): ... here.  Use stop-on-solib-events for _dl_debug_state.
	(test_ld): Provide always real argument, even to the linker.  Replace
	dl_main by _dl_debug_state.

--- a/gdb/testsuite/gdb.base/break-interp.exp
+++ b/gdb/testsuite/gdb.base/break-interp.exp
@@ -108,47 +108,87 @@ proc strip_debug {dest} {
     }
 }
 
-# `runto' does not check we stopped really at the function we specified.
-# DISPLACEMENT can be "NONE" for no message to be present, "ZERO" for
-# displacement of 0 bytes to be present, "NONZERO" for displacement of non-0
-# bytes to be present and "PRESENT" if both "ZERO" and "NONZERO" are valid.
-proc reach {func command displacement} {
+# Implementation of reach.
+
+proc reach_1 {func command displacement} {
     global gdb_prompt expect_out
 
-    global pf_prefix
-    set old_ldprefix $pf_prefix
-    lappend pf_prefix "reach-$func:"
+    if {$func == "_dl_debug_state"} {
+	# Breakpoint on _dl_debug_state can have problems due to its overlap
+	# with the existing internal breakpoint from GDB.
+	gdb_test_no_output "set stop-on-solib-events 1"
+    } elseif {! [gdb_breakpoint $func allow-pending]} {
+	return
+    }
 
-    if [gdb_breakpoint $func allow-pending] {
-	set test "reach"
-	set test_displacement "seen displacement message as $displacement"
-	gdb_test_multiple $command $test {
-	    -re "Using PIE \\(Position Independent Executable\\) displacement (0x\[0-9a-f\]+) " {
-		# Missing "$gdb_prompt $" is intentional.
-		if {$expect_out(1,string) == "0x0"} {
-		    set case "ZERO"
-		} else {
-		    set case "NONZERO"
-		}
-		if {$displacement == $case || $displacement == "PRESENT"} {
-		    pass $test_displacement
-		    set displacement "FOUND-$displacement"
-		} else {
-		    fail $test_displacement
-		}
-		exp_continue
+    set test "reach"
+    set test_displacement "seen displacement message as $displacement"
+    set debug_state_count 0
+    gdb_test_multiple $command $test {
+	-re "Using PIE \\(Position Independent Executable\\) displacement (0x\[0-9a-f\]+) " {
+	    # Missing "$gdb_prompt $" is intentional.
+	    if {$expect_out(1,string) == "0x0"} {
+		set case "ZERO"
+	    } else {
+		set case "NONZERO"
 	    }
-	    -re "Breakpoint \[0-9\]+, \\.?$func \\(.*\\) at .*:\[0-9\]+\r\n.*$gdb_prompt $" {
+	    if {$displacement == $case || $displacement == "PRESENT"} {
+		pass $test_displacement
+		set displacement "FOUND-$displacement"
+	    } else {
+		fail $test_displacement
+	    }
+	    exp_continue
+	}
+	-re "Breakpoint \[0-9\]+, \\.?$func \\(.*\\) at .*:\[0-9\]+\r\n.*$gdb_prompt $" {
+	    if {$func == "_dl_debug_state"} {
+		fail $test
+	    } else {
 		pass $test
 	    }
-	    -re "Breakpoint \[0-9\]+, \[0-9xa-f\]+ in \\.?$func \\(\\).*\r\n$gdb_prompt $" {
+	}
+	-re "Breakpoint \[0-9\]+, \[0-9xa-f\]+ in \\.?$func \\(\\).*\r\n$gdb_prompt $" {
+	    if {$func == "_dl_debug_state"} {
+		fail $test
+	    } else {
 		pass $test
 	    }
 	}
-	if ![regexp {^(NONE|FOUND-.*)$} $displacement] {
-	    fail $test_displacement
+	-re "Stopped due to shared library event\r\n$gdb_prompt $" {
+	    if {$func == "_dl_debug_state"} {
+		if {$debug_state_count == 0} {
+		    # First stop does not yet relocate the _start function
+		    # descriptor on ppc64.
+		    set debug_state_count 1
+		    send_gdb "continue\n"
+		    exp_continue
+		} else {
+		    pass $test
+		}
+	    } else {
+		fail $test
+	    }
 	}
     }
+    if ![regexp {^(NONE|FOUND-.*)$} $displacement] {
+	fail $test_displacement
+    }
+
+    if {$func == "_dl_debug_state"} {
+	gdb_test_no_output "set stop-on-solib-events 0"
+    }
+}
+
+# `runto' does not check we stopped really at the function we specified.
+# DISPLACEMENT can be "NONE" for no message to be present, "ZERO" for
+# displacement of 0 bytes to be present, "NONZERO" for displacement of non-0
+# bytes to be present and "PRESENT" if both "ZERO" and "NONZERO" are valid.
+proc reach {func command displacement} {
+    global pf_prefix
+    set old_ldprefix $pf_prefix
+    lappend pf_prefix "reach-$func:"
+
+    reach_1 $func $command $displacement
 
     set pf_prefix $old_ldprefix
 }
@@ -344,9 +384,18 @@ proc test_ld {file ifmain trynosym displacement} {
     # prevents that from happening.  So turn it off.
     gdb_test "set disable-randomization off"
 
-    reach "dl_main" "run segv" $displacement
+    if $ifmain {
+	gdb_test_no_output "set args segv"
+    } else {
+	global objdir binfile_test
+
+	# ld.so needs some executable to run to reach _dl_debug_state.
+	gdb_test_no_output "set args ${objdir}/${subdir}/$binfile_test"
+    }
+
+    reach "_dl_debug_state" "run" $displacement
 
-    gdb_test "bt" "#0 +\[^\r\n\]*\\mdl_main\\M.*" "dl bt"
+    gdb_test "bt" "#0 +\[^\r\n\]*\\m_dl_debug_state\\M.*" "dl bt"
 
     if $ifmain {
 	reach "main" continue "NONE"
@@ -358,7 +407,7 @@ proc test_ld {file ifmain trynosym displacement} {
 
     # Try re-run if the new PIE displacement takes effect.
     gdb_test "kill" "" "kill" {Kill the program being debugged\? \(y or n\) } "y"
-    reach "dl_main" "run segv" $displacement
+    reach "_dl_debug_state" "run" $displacement
 
     if $ifmain {
 	test_core $file $displacement
@@ -391,7 +440,7 @@ proc test_ld {file ifmain trynosym displacement} {
     gdb_test "exec-file $file" "exec-file $escapedfile" "load"
 
     if $ifmain {
-	reach "dl_main" run $displacement
+	reach "_dl_debug_state" run $displacement
 
 	set test "info files"
 	set entrynohex ""


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]