forked from Imagelibrary/binutils-gdb
In some runtimes, there may be a "main" function in some class or namespace. The breakpoint created by runto_main may therefore have unexpected locations on some other functions than the actual main. These breakpoint locations can unexpectedly get hit during tests and lead to failures. I saw this while playing with AMD's ROCm toolchain -- I wrote a board file to run the testsuite against device kernels. There, the runtime calls a "main" function before the device kernel code is reached: Thread 4 "bit_extract" hit Breakpoint 1, 0x00007ffeea140960 in lld:🧝:LinkerDriver::main(llvm::ArrayRef<char const*>) () from /opt/rocm/lib/libamd_comgr.so.1 (gdb) bt #0 0x00007ffeea140960 in lld:🧝:LinkerDriver::main(llvm::ArrayRef<char const*>) () from /opt/rocm/lib/libamd_comgr.so.1 #1 0x00007ffeea2257a5 in lld:🧝:link(llvm::ArrayRef<char const*>, bool, llvm::raw_ostream&, llvm::raw_ostream&) () from /opt/rocm/lib/libamd_comgr.so.1 #2 0x00007ffeea1bc374 in COMGR::linkWithLLD(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&) () from /opt/rocm/lib/libamd_comgr.so.1 #3 0x00007ffeea1bfb09 in COMGR::InProcessDriver::execute(llvm::ArrayRef<char const*>) () from /opt/rocm/lib/libamd_comgr.so.1 #4 0x00007ffeea1c4da9 in COMGR::AMDGPUCompiler::linkToExecutable() () from /opt/rocm/lib/libamd_comgr.so.1 #5 0x00007ffeea1fde20 in dispatchCompilerAction(amd_comgr_action_kind_s, COMGR::DataAction*, COMGR::DataSet*, COMGR::DataSet*, llvm::raw_ostream&) () from /opt/rocm/lib/libamd_comgr.so.1 #6 0x00007ffeea203a87 in amd_comgr_do_action () from /opt/rocm/lib/libamd_comgr.so.1 ... To avoid that, pass "qualified" to runto, in runto_main, so that gdb_breakpoint ends up creating a breakpoint with -qualified. This avoids creating breakpoints locations for other unrelated "main" functions. Note: I first tried making runto itself use "-qualified", but that caused regressions in the gdb.ada/ tests, which use runto without specifying the whole fully-qualified function name (i.e., without the package). So I end up restricting the -qualified to runto_main/mi_runto_main. The gdb.base/ui-redirect.exp change is necessary because that testcase is looking at what "save breakpoint" generates. gdb/testsuite/ChangeLog: * gdb.base/ui-redirect.exp: Expect "break -qualified main" in saved breakpoints file. * gdb.guile/scm-breakpoint.exp: Expect "-qualified main" when inspecting breakpoint list. * lib/gdb.exp (runto_main): Add "qualified" to options. * lib/mi-support.exp (mi_runto_helper): Add 'qualified' parameter, and handle it. (mi_runto_main): Pass 1 as qualified argument. Change-Id: I51468359ab0a518f05f7c0394c97f7e33b45fe69
136 lines
4.3 KiB
Plaintext
136 lines
4.3 KiB
Plaintext
# Copyright (C) 2010-2020 Free Software Foundation, Inc.
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
# Do not run if gdb debug is enabled as it will interfere with log redirect.
|
|
if [gdb_debug_enabled] {
|
|
untested "debug is enabled"
|
|
return 0
|
|
}
|
|
|
|
if { [prepare_for_testing "failed to prepare" ui-redirect start.c] } {
|
|
return -1
|
|
}
|
|
|
|
if ![runto_main] {
|
|
fail "can't run to main"
|
|
return -1
|
|
}
|
|
|
|
set test "commands"
|
|
gdb_test_multiple $test $test {
|
|
-re "End with a line saying just \"end\"\\.\r\n>$" {
|
|
pass $test
|
|
}
|
|
}
|
|
|
|
set test "print 1"
|
|
gdb_test_multiple $test $test {
|
|
-re "\r\n>$" {
|
|
pass $test
|
|
}
|
|
}
|
|
gdb_test_no_output "end"
|
|
|
|
gdb_breakpoint "foo"
|
|
gdb_breakpoint "bar"
|
|
|
|
set cmds [multi_line_input \
|
|
"break -qualified main" \
|
|
" commands" \
|
|
" print 1" \
|
|
" end" \
|
|
"break foo" \
|
|
"break bar"]
|
|
set cmds "$cmds\n"
|
|
set outdir [standard_output_file {}]
|
|
set cmds_file "$outdir/cmds.txt"
|
|
|
|
with_test_prefix "userdefined" {
|
|
set test "define userdefined"
|
|
gdb_test_multiple $test $test {
|
|
-re "End with a line saying just \"end\"\\.\r\n>$" {
|
|
pass $test
|
|
}
|
|
}
|
|
|
|
set test "bt"
|
|
gdb_test_multiple $test $test {
|
|
-re "\r\n>$" {
|
|
pass $test
|
|
}
|
|
}
|
|
|
|
gdb_test_no_output "end"
|
|
}
|
|
|
|
with_test_prefix "logging" {
|
|
gdb_test_no_output "set logging file /dev/null"
|
|
gdb_test "set logging on" \
|
|
"Copying output to /dev/null.*Copying debug output to /dev/null\\."
|
|
gdb_test "save breakpoints $cmds_file" "Saved to file '$cmds_file'\\." \
|
|
"save breakpoints cmds.txt"
|
|
cmp_file_string "$cmds_file" "$cmds" "cmds.txt"
|
|
gdb_test "userdefined" "#0 main ().*"
|
|
gdb_test "set logging off" "Done logging to /dev/null\\."
|
|
gdb_test "help" "List of classes of commands:.*"
|
|
}
|
|
|
|
with_test_prefix "redirect" {
|
|
gdb_test "set logging redirect on"
|
|
gdb_test "set logging on" \
|
|
"Redirecting output to /dev/null.*Copying debug output to /dev/null\\."
|
|
gdb_test_no_output "save breakpoints $cmds_file" "save breakpoints cmds.txt"
|
|
cmp_file_string "$cmds_file" "$cmds" "cmds.txt"
|
|
gdb_test_no_output "userdefined"
|
|
gdb_test "set logging off" "Done logging to /dev/null\\."
|
|
gdb_test "help" "List of classes of commands:.*"
|
|
}
|
|
|
|
with_test_prefix "redirect while already logging" {
|
|
gdb_test_no_output "set logging redirect off"
|
|
gdb_test "set logging on" \
|
|
"Copying output to /dev/null.*Copying debug output to /dev/null\\."
|
|
gdb_test "set logging redirect on" \
|
|
".*warning: Currently logging .*Turn the logging off and on to make the new setting effective.*"
|
|
gdb_test "save breakpoints $cmds_file" "Saved to file '$cmds_file'\\." \
|
|
"save breakpoints cmds.txt"
|
|
cmp_file_string "$cmds_file" "$cmds" "cmds.txt"
|
|
gdb_test "userdefined" "#0 main ().*"
|
|
gdb_test "set logging off" "Done logging to /dev/null\\."
|
|
gdb_test "help" "List of classes of commands:.*"
|
|
gdb_test_no_output "set logging redirect off"
|
|
}
|
|
|
|
with_test_prefix "debugging" {
|
|
gdb_test "set debug infrun 1"
|
|
gdb_test "set logging on" \
|
|
"Copying output to /dev/null.*Copying debug output to /dev/null\\."
|
|
gdb_test "continue" {Continuing.*\[infrun\] .*\[infrun\] .*Breakpoint [0-9]+, foo.*}
|
|
gdb_test "set debug infrun 0"
|
|
gdb_test "set logging off" "Done logging to /dev/null\\."
|
|
gdb_test "help" "List of classes of commands:.*"
|
|
}
|
|
|
|
with_test_prefix "redirect debugging" {
|
|
gdb_test_no_output "set logging debugredirect on"
|
|
gdb_test "set debug infrun 1"
|
|
gdb_test "set logging on" \
|
|
"Copying output to /dev/null.*Redirecting debug output to /dev/null\\."
|
|
gdb_test "continue" "Continuing.*((?!infrun).).*Breakpoint \[0-9\]+, bar.*"
|
|
gdb_test "set debug infrun 0"
|
|
gdb_test "set logging off" "Done logging to /dev/null\\."
|
|
gdb_test "help" "List of classes of commands:.*"
|
|
}
|