mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-27 04:52:05 +08:00
d03de42190
Turns out there's a difference between loading the program with "gdb
PROGRAM", vs loading it with "(gdb) file PROGRAM". The latter results
in the objfile ending up with OBJF_USERLOADED set, while not with the
former. (That difference seems bogus, but still that's not the point
of this patch. We can revisit that afterwards.)
The new code that suppresses breakpoint removal errors for
add-symbol-file objects ends up being too greedy:
/* In some cases, we might not be able to remove a breakpoint in
a shared library that has already been removed, but we have
not yet processed the shlib unload event. Similarly for an
unloaded add-symbol-file object - the user might not yet have
had the chance to remove-symbol-file it. shlib_disabled will
be set if the library/object has already been removed, but
the breakpoint hasn't been uninserted yet, e.g., after
"nosharedlibrary" or "remove-symbol-file" with breakpoints
always-inserted mode. */
if (val
&& (bl->loc_type == bp_loc_software_breakpoint
&& (bl->shlib_disabled
|| solib_name_from_address (bl->pspace, bl->address)
|| userloaded_objfile_contains_address_p (bl->pspace,
bl->address))))
val = 0;
as it turns out that OBJF_USERLOADED can be set for objfiles loaded by
some other means not add-symbol-file. In this case, symbol-file (or
"file", which is really just "exec-file"+"symbol-file").
Recall that add-symbol-file is documented as:
(gdb) help add-symbol-file
Load symbols from FILE, assuming FILE has been dynamically loaded.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
And it's the "dynamically loaded" aspect that the breakpoint.c code
cares about. So make add-symbol-file set OBJF_SHARED on its objfiles
too, and tweak the breakpoint.c code to look for OBJF_SHARED instead
of OBJF_USERLOADED.
This restores back the missing breakpoint removal warning when we let
sss-bp-on-user-bp-2.exp run on native GNU/Linux
(https://sourceware.org/ml/gdb-patches/2014-06/msg00335.html):
(gdb) PASS: gdb.base/sss-bp-on-user-bp-2.exp: define stepi_del_break
stepi_del_break
warning: Error removing breakpoint 3
(gdb) FAIL: gdb.base/sss-bp-on-user-bp-2.exp: stepi_del_break
I say "restores" because this was GDB's behavior in 7.7 and earlier.
And, likewise, "file" with no arguments only started turning
breakpoints set in the main executable to "<pending>" with the
remote-symbol-file patch (63644780
). The old behavior is now
restored, and we break-unload-file.exp test now exercizes both "gdb;
file PROGRAM" and "gdb PROGRAM".
gdb/
2014-06-16 Pedro Alves <palves@redhat.com>
* breakpoint.c (insert_bp_location, remove_breakpoint_1): Adjust.
(disable_breakpoints_in_freed_objfile): Skip objfiles that don't
have OBJF_SHARED set.
* objfiles.c (userloaded_objfile_contains_address_p): Rename to...
(shared_objfile_contains_address_p): ... this. Check OBJF_SHARED
instead of OBJF_USERLOADED.
* objfiles.h (OBJF_SHARED): Update comment.
(userloaded_objfile_contains_address_p): Rename to ...
(shared_objfile_contains_address_p): ... this, and update
comments.
* symfile.c (add_symbol_file_command): Also set OBJF_SHARED in the
new objfile.
(remove_symbol_file_command): Skip objfiles that don't have
OBJF_SHARED set.
gdb/testsuite/
2014-06-16 Pedro Alves <palves@redhat.com>
* gdb.base/break-main-file-remove-fail.c: New file.
* gdb.base/break-main-file-remove-fail.exp: New file.
* gdb.base/break-unload-file.exp: Use build_executable instead of
prepare_for_testing.
(test_break): New parameter "initial_load". Handle it.
(top level): Add initial_load cmdline/file axis.
107 lines
2.9 KiB
Plaintext
107 lines
2.9 KiB
Plaintext
# Copyright 2014 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/>. */
|
|
|
|
# Test that GDB isn't silent if it fails to remove a breakpoint from
|
|
# the main program, independently of whether the program was loaded
|
|
# with "file PROGRAM" or directly from the command line with "gdb
|
|
# PROGRAM".
|
|
|
|
standard_testfile
|
|
|
|
if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
|
|
return -1
|
|
}
|
|
|
|
# Run the test proper. INITIAL_LOAD determines whether the program is
|
|
# initially loaded by the "file" command or by passing it to GDB on
|
|
# the command line.
|
|
proc test_remove_bp { initial_load } {
|
|
with_test_prefix "$initial_load" {
|
|
global srcdir subdir binfile
|
|
global gdb_prompt hex
|
|
global GDBFLAGS
|
|
|
|
gdb_exit
|
|
|
|
set saved_gdbflags $GDBFLAGS
|
|
|
|
# See "used to behave differently" further below.
|
|
if { $initial_load == "file" } {
|
|
gdb_start
|
|
gdb_file_cmd $binfile
|
|
} else {
|
|
global last_loaded_file
|
|
|
|
# gdb_file_cmd sets this. This is what gdb_reload
|
|
# implementations use as binary.
|
|
set last_loaded_file $binfile
|
|
|
|
set GDBFLAGS "$GDBFLAGS $binfile"
|
|
gdb_start
|
|
}
|
|
gdb_reinitialize_dir $srcdir/$subdir
|
|
gdb_reload
|
|
set GDBFLAGS $saved_gdbflags
|
|
|
|
if ![runto start] {
|
|
fail "Can't run to start"
|
|
return
|
|
}
|
|
|
|
delete_breakpoints
|
|
|
|
# So we can easily control when are breakpoints removed.
|
|
gdb_test_no_output "set breakpoint always-inserted on"
|
|
|
|
set bp_addr ""
|
|
|
|
set test "break foo"
|
|
gdb_test_multiple $test $test {
|
|
-re "Breakpoint .* at ($hex).*$gdb_prompt $" {
|
|
set bp_addr $expect_out(1,string)
|
|
pass $test
|
|
}
|
|
}
|
|
|
|
if {$bp_addr == ""} {
|
|
unsupported "can't extract foo's address"
|
|
return
|
|
}
|
|
|
|
gdb_test "info break" "y.*$hex.*in foo at.*" \
|
|
"breakpoint is set"
|
|
|
|
# Now unmap the page where the breakpoint is set. Trying to
|
|
# remove the memory breakpoint afterwards should fail, and GDB
|
|
# should warn the user about it.
|
|
set pagesize [get_integer_valueof "pg_size" 0]
|
|
set align_addr [expr $bp_addr - $bp_addr % $pagesize]
|
|
set munmap [get_integer_valueof "munmap ($align_addr, $pagesize)" -1]
|
|
|
|
if {$munmap != 0} {
|
|
unsupported "can't munmap foo's page"
|
|
return
|
|
}
|
|
|
|
gdb_test "delete \$bpnum" \
|
|
"warning: Error removing breakpoint .*" \
|
|
"failure to remove breakpoint warns"
|
|
}
|
|
}
|
|
|
|
foreach initial_load { "cmdline" "file" } {
|
|
test_remove_bp $initial_load
|
|
}
|