[gdb/testsuite] Fix DUPLICATEs with remote-gdbserver-on-localhost

Fix some DUPLICATEs that we run into with target board
remote-gdbserver-on-localhost, by using test_with_prefix.

Tested on x86_64-linux, with native and target board
remote-gdbserver-on-localhost.
This commit is contained in:
Tom de Vries
2022-10-07 16:17:34 +02:00
parent 8ed73e3164
commit 7fe3f84145
5 changed files with 267 additions and 237 deletions

View File

@@ -35,22 +35,27 @@ set objfile [standard_output_file ${testfile}.o]
return -1
}
clean_restart ${binfile}
gdb_load_shlib ${binfile_lib}
with_test_prefix "first session" {
clean_restart ${binfile}
gdb_load_shlib ${binfile_lib}
if ![runto lib] {
return -1
}
if ![runto lib] {
return -1
}
if {![gdb_gcore_cmd $gcorefile "save a corefile"]} {
return -1
if {![gdb_gcore_cmd $gcorefile "save a corefile"]} {
return -1
}
}
# Now restart gdb and load the corefile.
clean_restart ${binfile}
gdb_load_shlib ${binfile_lib}
with_test_prefix "second session" {
clean_restart ${binfile}
gdb_load_shlib ${binfile_lib}
gdb_test "core ${gcorefile}" "Core was generated by .*" "re-load generated corefile"
gdb_test "core ${gcorefile}" "Core was generated by .*" \
"re-load generated corefile"
gdb_test "frame" "#0 \[^\r\n\]* lib .*" "library got loaded"
gdb_test "frame" "#0 \[^\r\n\]* lib .*" "library got loaded"
}

View File

@@ -57,8 +57,10 @@ gdb_test "info break" \
\[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendfunc1.*" \
"single pending breakpoint info (without symbols)"
gdb_load ${binfile}
gdb_load_shlib $lib_sl
with_test_prefix "first load" {
gdb_load ${binfile}
gdb_load_shlib $lib_sl
}
set pendfunc1_loc [gdb_get_line_number "y = x + 4" ${libfile}.c]
@@ -74,8 +76,10 @@ gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}
gdb_load_shlib $lib_sl
with_test_prefix "second load" {
gdb_load ${binfile}
gdb_load_shlib $lib_sl
}
#
# Test setting, querying, and modifying pending breakpoints

View File

@@ -85,19 +85,21 @@ proc do_test { lib1opts lib2opts lib1first } {
return -1
}
gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}
gdb_load_shlib $lib1
gdb_load_shlib $lib2
with_test_prefix $testopts {
gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}
gdb_load_shlib $lib1
gdb_load_shlib $lib2
runto_main
runto_main
gdb_breakpoint "bar"
gdb_breakpoint "bar"
gdb_test "continue" "Breakpoint .* \\.?bar .*${expected_file}\\..*" \
"run to breakpoint - $testopts"
gdb_test "continue" "Breakpoint .* \\.?bar .*${expected_file}\\..*" \
"run to breakpoint"
}
}
foreach lib1opts {{} {debug}} {

View File

@@ -97,48 +97,49 @@ if [prepare_for_testing "failed to prepare" ${testfile} \
return -1
}
# Do whatever is necessary to make sure that the shared library is
# loaded for remote targets.
gdb_load_shlib ${lib_so}
### First GDB session.
# Run to foo to make sure foo refers to the function, and not foo@PLT.
if ![runto foo qualified] then {
return
}
with_test_prefix "first session" {
# Do whatever is necessary to make sure that the shared library is
# loaded for remote targets.
gdb_load_shlib ${lib_so}
with_shared_gdb {
set session_options $exec_options
# Rather than start a new session, declare the current session the
# shared one. Otherwise, get_func_info would compile an executable
# in a temp dir, which means -Wl,-rpath,\\\$ORIGIN no longer finds
# the shared lib.
share_gdb ${srcdir}/${subdir}/$srcfile $session_options
get_func_info foo $session_options
get_func_info bar $session_options
# Using our running GDB session, determine sizes of several types.
set long_size [get_sizeof "long" -1]
set addr_size [get_sizeof "void *" -1]
set struct_A_size [get_sizeof "g_A" -1]
set struct_B_size [get_sizeof "g_B" -1]
# Retrieve struct offset of MBR in struct TP
proc get_offsetof { tp mbr } {
return [get_integer_valueof "&((${tp} *) 0)->${mbr}" -1]
# Run to foo to make sure foo refers to the function, and not foo@PLT.
if ![runto foo qualified] then {
return
}
# Use running GDB session to get struct offsets
set A_a [get_offsetof A a]
set A_x [get_offsetof A x]
set B_a [get_offsetof B a]
set B_b [get_offsetof B b]
set B_x2 [get_offsetof B x2]
with_shared_gdb {
set session_options $exec_options
# Rather than start a new session, declare the current session the
# shared one. Otherwise, get_func_info would compile an executable
# in a temp dir, which means -Wl,-rpath,\\\$ORIGIN no longer finds
# the shared lib.
share_gdb ${srcdir}/${subdir}/$srcfile $session_options
get_func_info foo $session_options
get_func_info bar $session_options
# Using our running GDB session, determine sizes of several types.
set long_size [get_sizeof "long" -1]
set addr_size [get_sizeof "void *" -1]
set struct_A_size [get_sizeof "g_A" -1]
set struct_B_size [get_sizeof "g_B" -1]
# Retrieve struct offset of MBR in struct TP
proc get_offsetof { tp mbr } {
return [get_integer_valueof "&((${tp} *) 0)->${mbr}" -1]
}
# Use running GDB session to get struct offsets
set A_a [get_offsetof A a]
set A_x [get_offsetof A x]
set B_a [get_offsetof B a]
set B_b [get_offsetof B b]
set B_x2 [get_offsetof B x2]
}
}
if { $long_size == -1 || $addr_size == -1 \
@@ -326,40 +327,43 @@ if {[gdb_compile_shlib [list $libsrc $asm_file] $lib_so \
### Second GDB session.
clean_restart $binfile
with_test_prefix "second session" {
clean_restart $binfile
# Again, do whatever is necessary to make sure that the shared library is
# loaded for remote targets.
gdb_load_shlib ${lib_so}
# Again, do whatever is necessary to make sure that the shared library is
# loaded for remote targets.
gdb_load_shlib ${lib_so}
if ![runto_main] then {
return
if ![runto_main] then {
return
}
# Step into foo so that we can finish out of it.
gdb_test "step" "foo .. at .* foo end.*" "step into foo"
# Finishing out of foo will create a value that will later need to
# be preserved when restarting the program.
gdb_test "finish" "= \\(class B \\*\\) ${::hex} .*" "finish out of foo"
# Dereferencing and printing the return value isn't necessary
# for reproducing the bug, but we should make sure that the
# return value is what we expect it to be.
gdb_test "p *$" { = {<A> = {a = 8, x = 9}, b = 10, x2 = 11}} \
"dereference return value"
# The original PR28030 reproducer stepped back into the shared object,
# so we'll do the same here:
gdb_test "step" "bar \\(.*" "step into bar"
}
# Step into foo so that we can finish out of it.
gdb_test "step" "foo .. at .* foo end.*" "step into foo"
# Finishing out of foo will create a value that will later need to
# be preserved when restarting the program.
gdb_test "finish" "= \\(class B \\*\\) ${::hex} .*" "finish out of foo"
# Dereferencing and printing the return value isn't necessary
# for reproducing the bug, but we should make sure that the
# return value is what we expect it to be.
gdb_test "p *$" { = {<A> = {a = 8, x = 9}, b = 10, x2 = 11}} \
"dereference return value"
# The original PR28030 reproducer stepped back into the shared object,
# so we'll do the same here:
gdb_test "step" "bar \\(.*" "step into bar"
### Third GDB session.
# We don't want a clean restart here since that will be too clean.
# The original reproducer for PR28030 set a breakpoint in the shared
# library and then restarted via "run". The command below does roughly
# the same thing. It's at this step that an internal error would
# occur for PR28030. The "message" argument tells runto to turn on
# the printing of PASSes while runto is doing its job.
runto "bar" message
with_test_prefix "third session" {
# We don't want a clean restart here since that will be too clean.
# The original reproducer for PR28030 set a breakpoint in the shared
# library and then restarted via "run". The command below does roughly
# the same thing. It's at this step that an internal error would
# occur for PR28030. The "message" argument tells runto to turn on
# the printing of PASSes while runto is doing its job.
runto "bar" message
}

View File

@@ -46,204 +46,219 @@ if { [skip_python_tests] } { continue }
# Test FinishBreakpoint in normal conditions
#
clean_restart ${testfile}
gdb_load_shlib ${lib_sl}
with_test_prefix "normal conditions" {
clean_restart ${testfile}
gdb_load_shlib ${lib_sl}
if ![runto_main] then {
return 0
if ![runto_main] then {
return 0
}
set python_file [gdb_remote_download host \
${srcdir}/${subdir}/${testfile}.py]
gdb_test_no_output "set confirm off" "disable confirmation"
gdb_test "source $python_file" "Python script imported.*" \
"import python scripts"
gdb_breakpoint "increase_1"
gdb_test "continue" "Breakpoint .*at.*" "continue to the function to finish"
# set FinishBreakpoint
gdb_test "python finishbp_default = gdb.FinishBreakpoint ()" \
"Temporary breakpoint.*" "set FinishBreakpoint with default frame value"
gdb_test "python finishbp = MyFinishBreakpoint (gdb.parse_and_eval ('a'), gdb.newest_frame ())" \
"Temporary breakpoint.*" "set FinishBreakpoint"
gdb_test "python print (finishbp.return_value)" "None.*" \
"check return_value at init"
# check normal bp hit
gdb_test "continue" "MyFinishBreakpoint stop with.*return_value is: -5.*#0.*increase.*" \
"check MyFinishBreakpoint hit"
gdb_test "python print (finishbp.return_value)" "-5.*" "check return_value"
gdb_test "python print (finishbp_default.hit_count)" "1.*" "check finishBP on default frame has been hit"
gdb_test "python print (finishbp.is_valid())" "False.*"\
"ensure that finish bp is invalid afer normal hit"
# check FinishBreakpoint in main no allowed
gdb_test "finish" "main.*" "return to main()"
gdb_test "python MyFinishBreakpoint (None, gdb.selected_frame ())" \
"ValueError: \"FinishBreakpoint\" not meaningful in the outermost frame..*" \
"check FinishBP not allowed in main"
}
set python_file [gdb_remote_download host \
${srcdir}/${subdir}/${testfile}.py]
gdb_test_no_output "set confirm off" "disable confirmation"
gdb_test "source $python_file" "Python script imported.*" \
"import python scripts, 1"
gdb_breakpoint "increase_1"
gdb_test "continue" "Breakpoint .*at.*" "continue to the function to finish"
# set FinishBreakpoint
gdb_test "python finishbp_default = gdb.FinishBreakpoint ()" \
"Temporary breakpoint.*" "set FinishBreakpoint with default frame value"
gdb_test "python finishbp = MyFinishBreakpoint (gdb.parse_and_eval ('a'), gdb.newest_frame ())" \
"Temporary breakpoint.*" "set FinishBreakpoint"
gdb_test "python print (finishbp.return_value)" "None.*" \
"check return_value at init"
# check normal bp hit
gdb_test "continue" "MyFinishBreakpoint stop with.*return_value is: -5.*#0.*increase.*" \
"check MyFinishBreakpoint hit"
gdb_test "python print (finishbp.return_value)" "-5.*" "check return_value"
gdb_test "python print (finishbp_default.hit_count)" "1.*" "check finishBP on default frame has been hit"
gdb_test "python print (finishbp.is_valid())" "False.*"\
"ensure that finish bp is invalid afer normal hit"
# check FinishBreakpoint in main no allowed
gdb_test "finish" "main.*" "return to main()"
gdb_test "python MyFinishBreakpoint (None, gdb.selected_frame ())" \
"ValueError: \"FinishBreakpoint\" not meaningful in the outermost frame..*" \
"check FinishBP not allowed in main"
#
# Test FinishBreakpoint with no debug symbol
#
clean_restart ${testfile}
gdb_load_shlib ${lib_sl}
with_test_prefix "no debug symbol" {
clean_restart ${testfile}
gdb_load_shlib ${lib_sl}
gdb_test "source $python_file" "Python script imported.*" \
"import python scripts, 2"
set cond_line [gdb_get_line_number "Condition Break."]
gdb_test "source $python_file" "Python script imported.*" \
"import python scripts"
set cond_line [gdb_get_line_number "Condition Break."]
if ![runto_main] then {
return 0
if ![runto_main] then {
return 0
}
gdb_test "print do_nothing" "no debug info.*" "ensure that shared lib has no debug info"
gdb_breakpoint "do_nothing" {temporary}
gdb_test "continue" "Temporary breakpoint .*in \\.?do_nothing.*" \
"continue to do_nothing"
gdb_test "python finishBP = SimpleFinishBreakpoint(gdb.newest_frame())" \
"SimpleFinishBreakpoint init" \
"set finish breakpoint for no debug symbol test"
gdb_test "continue" "SimpleFinishBreakpoint stop.*" "check FinishBreakpoint hit"
gdb_test "python print (finishBP.return_value)" "None" "check return value"
}
gdb_test "print do_nothing" "no debug info.*" "ensure that shared lib has no debug info"
gdb_breakpoint "do_nothing" {temporary}
gdb_test "continue" "Temporary breakpoint .*in \\.?do_nothing.*" \
"continue to do_nothing"
gdb_test "python finishBP = SimpleFinishBreakpoint(gdb.newest_frame())" \
"SimpleFinishBreakpoint init" \
"set finish breakpoint for no debug symbol test"
gdb_test "continue" "SimpleFinishBreakpoint stop.*" "check FinishBreakpoint hit"
gdb_test "python print (finishBP.return_value)" "None" "check return value without debug symbol"
#
# Test FinishBreakpoint in function returned by longjmp
#
clean_restart ${testfile}
gdb_load_shlib ${lib_sl}
with_test_prefix "function returned by longjump" {
clean_restart ${testfile}
gdb_load_shlib ${lib_sl}
gdb_test "source $python_file" "Python script imported.*" \
"import python scripts, 3"
gdb_test "source $python_file" "Python script imported.*" \
"import python scripts"
if ![runto call_longjmp_1] then {
return
if ![runto call_longjmp_1] then {
return
}
gdb_test "python finishbp = SimpleFinishBreakpoint(gdb.newest_frame())" \
"SimpleFinishBreakpoint init" \
"set finish breakpoint for longjmp test"
gdb_test "break [gdb_get_line_number "after longjmp."]" "Breakpoint.* at .*" \
"set BP after the jump"
gdb_test "continue" "SimpleFinishBreakpoint out of scope.*" \
"check FinishBP out of scope notification"
gdb_test "python print (finishbp.is_valid())" "False.*"\
"ensure that finish bp is invalid after out of scope notification"
}
gdb_test "python finishbp = SimpleFinishBreakpoint(gdb.newest_frame())" \
"SimpleFinishBreakpoint init" \
"set finish breakpoint for longjmp test"
gdb_test "break [gdb_get_line_number "after longjmp."]" "Breakpoint.* at .*" \
"set BP after the jump"
gdb_test "continue" "SimpleFinishBreakpoint out of scope.*" \
"check FinishBP out of scope notification"
gdb_test "python print (finishbp.is_valid())" "False.*"\
"ensure that finish bp is invalid afer out of scope notification"
#
# Test FinishBreakpoint in BP condition evaluation
# (finish in dummy frame)
#
clean_restart ${testfile}
gdb_load_shlib ${lib_sl}
with_test_prefix "finish in dummy frame" {
clean_restart ${testfile}
gdb_load_shlib ${lib_sl}
gdb_test "source $python_file" "Python script imported.*" \
"import python scripts, 4"
gdb_test "source $python_file" "Python script imported.*" \
"import python scripts"
if ![runto_main] then {
return 0
if ![runto_main] then {
return 0
}
gdb_test "break ${cond_line} if test_1(i,8)" "Breakpoint .* at .*" \
"set a conditional BP"
gdb_test "python TestBreakpoint()" "TestBreakpoint init" \
"set FinishBP in a breakpoint condition"
gdb_test "continue" \
"\"FinishBreakpoint\" cannot be set on a dummy frame.*" \
"don't allow FinishBreakpoint on dummy frames"
gdb_test "print i" "8" \
"check stopped location"
}
gdb_test "break ${cond_line} if test_1(i,8)" "Breakpoint .* at .*" \
"set a conditional BP"
gdb_test "python TestBreakpoint()" "TestBreakpoint init" \
"set FinishBP in a breakpoint condition"
gdb_test "continue" \
"\"FinishBreakpoint\" cannot be set on a dummy frame.*" \
"don't allow FinishBreakpoint on dummy frames"
gdb_test "print i" "8" \
"check stopped location for stop in dummy frame case"
#
# Test FinishBreakpoint in BP condition evaluation
# (finish in normal frame)
#
clean_restart ${testfile}
gdb_load_shlib ${lib_sl}
with_test_prefix "finish in normal frame" {
clean_restart ${testfile}
gdb_load_shlib ${lib_sl}
gdb_test "source $python_file" "Python script imported.*" \
"import python scripts, 5"
gdb_test "source $python_file" "Python script imported.*" \
"import python scripts"
if ![runto_main] then {
return 0
if ![runto_main] then {
return 0
}
gdb_test "break ${cond_line} if test(i,8)" \
"Breakpoint .* at .*" "set conditional BP"
gdb_test "python TestBreakpoint()" "TestBreakpoint init" "set BP in condition"
gdb_test "continue" \
"test don't stop: 1.*test don't stop: 2.*test stop.*Error in testing breakpoint condition.*The program being debugged stopped while in a function called from GDB.*" \
"stop in condition function"
gdb_test "continue" "Continuing.*" "finish condition evaluation"
gdb_test "continue" "Breakpoint.*" "stop at conditional breakpoint"
gdb_test "print i" "8" \
"check stopped location"
}
gdb_test "break ${cond_line} if test(i,8)" \
"Breakpoint .* at .*" "set conditional BP"
gdb_test "python TestBreakpoint()" "TestBreakpoint init" "set BP in condition"
gdb_test "continue" \
"test don't stop: 1.*test don't stop: 2.*test stop.*Error in testing breakpoint condition.*The program being debugged stopped while in a function called from GDB.*" \
"stop in condition function"
gdb_test "continue" "Continuing.*" "finish condition evaluation"
gdb_test "continue" "Breakpoint.*" "stop at conditional breakpoint"
gdb_test "print i" "8" \
"check stopped location for stop in normal frame case"
#
# Test FinishBreakpoint in explicit inferior function call
#
clean_restart ${testfile}
gdb_load_shlib ${lib_sl}
with_test_prefix "explicit inferior function call" {
clean_restart ${testfile}
gdb_load_shlib ${lib_sl}
gdb_test "source $python_file" "Python script imported.*" \
"import python scripts, 6"
gdb_test "source $python_file" "Python script imported.*" \
"import python scripts"
if ![runto_main] then {
return 0
if ![runto_main] then {
return 0
}
# return address in dummy frame
gdb_test "python TestExplicitBreakpoint('increase_1')" "Breakpoint.*at.*" \
"prepare TestExplicitBreakpoint, return addr in dummy frame"
gdb_test "print increase_1(&i)" \
"\"FinishBreakpoint\" cannot be set on a dummy frame.*" \
"don't allow FinishBreakpoint on dummy frames, return address in dummy frame"
# return address in normal frame
delete_breakpoints
gdb_test "python TestExplicitBreakpoint(\"increase_1\")" "Breakpoint.*at.*" \
"prepare TestExplicitBreakpoint, return addr in normal frame"
gdb_test "print increase(&i)" \
"SimpleFinishBreakpoint init.*SimpleFinishBreakpoint stop.*The program being debugged stopped while in a function called from GDB.*" \
"FinishBP stop"
}
# return address in dummy frame
gdb_test "python TestExplicitBreakpoint('increase_1')" "Breakpoint.*at.*" \
"prepare TestExplicitBreakpoint, return addr in dummy frame"
gdb_test "print increase_1(&i)" \
"\"FinishBreakpoint\" cannot be set on a dummy frame.*" \
"don't allow FinishBreakpoint on dummy frames, return address in dummy frame"
# return address in normal frame
delete_breakpoints
gdb_test "python TestExplicitBreakpoint(\"increase_1\")" "Breakpoint.*at.*" \
"prepare TestExplicitBreakpoint, return addr in normal frame"
gdb_test "print increase(&i)" \
"SimpleFinishBreakpoint init.*SimpleFinishBreakpoint stop.*The program being debugged stopped while in a function called from GDB.*" \
"FinishBP stop at during explicit function call"
#
# Test FinishBreakpoint when inferior exits
#
if ![runto "test_exec_exit"] then {
return 0
}
with_test_prefix "inferior exit" {
if ![runto "test_exec_exit"] then {
return 0
}
gdb_test_no_output "set var self_exec = 0" "switch to exit() test"
gdb_test "python SimpleFinishBreakpoint(gdb.newest_frame())" "SimpleFinishBreakpoint init" "set FinishBP after the exit()"
gdb_test "continue" "SimpleFinishBreakpoint out of scope.*" "catch out of scope after exit"
gdb_test_no_output "set var self_exec = 0" "switch to exit() test"
gdb_test "python SimpleFinishBreakpoint(gdb.newest_frame())" "SimpleFinishBreakpoint init" "set FinishBP after the exit()"
gdb_test "continue" "SimpleFinishBreakpoint out of scope.*" "catch out of scope after exit"
}
#
# Test FinishBreakpoint when inferior execs
#
if ![runto "test_exec_exit"] then {
return 0
}
with_test_prefix "inferior exec" {
if ![runto "test_exec_exit"] then {
return 0
}
gdb_test "python SimpleFinishBreakpoint(gdb.newest_frame())" "SimpleFinishBreakpoint init" "set FinishBP after the exec"
gdb_test "catch exec" "Catchpoint.*\(exec\).*"
gdb_test "continue" "SimpleFinishBreakpoint out of scope.*" "catch out of scope after exec"
gdb_test "python SimpleFinishBreakpoint(gdb.newest_frame())" "SimpleFinishBreakpoint init" "set FinishBP after the exec"
gdb_test "catch exec" "Catchpoint.*\(exec\).*"
gdb_test "continue" "SimpleFinishBreakpoint out of scope.*" "catch out of scope after exec"
}