mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-21 04:42:53 +08:00
cb1e4e32c2
Currently, with:
(gdb) catch catch
Catchpoint 1 (catch)
(gdb) catch throw
Catchpoint 2 (throw)
(gdb) catch rethrow
Catchpoint 3 (rethrow)
You get:
(gdb) info breakpoints
Num Type Disp Enb Address What
1 breakpoint keep y 0x0000000000b122af exception catch
2 breakpoint keep y 0x0000000000b1288d exception throw
3 breakpoint keep y 0x0000000000b12931 exception rethrow
I think it doesn't make much sense usability-wise, to show a
catchpoint as a breakpoint. The fact that GDB sets a breakpoint at
some magic address in the C++ run time is an implementation detail,
IMO. And as seen in the previous patch, such a catchpoint can end up
with more than one location/address even, so showing a single address
isn't entirely accurate.
This commit hides the addresses from view, and makes GDB show
"catchpoint" for type as well:
(gdb) info breakpoints
Num Type Disp Enb Address What
1 catchpoint keep y exception catch
2 catchpoint keep y exception throw
3 catchpoint keep y exception rethrow
This comment in the code seems telling:
/* We need to reset 'type' in order for code in breakpoint.c to do
the right thing. */
cp->type = bp_breakpoint;
It kind of suggests that the reason catchpoints end up shown as
breakpoints was that it was easier to implement them that way, rather
than a desired property.
This commit fixes things up to make it possible to have bp_catch
breakpoints have software/hardware breakpoint locations, thus
eliminating the need for that hack:
- redo breakpoint_address_is_meaningful in terms of the location's
type rather than breakpoint type.
- teach bpstat_what about stepping over the catchpoint locations.
- install a allocate_location method for "catch catch/throw/rethrow",
one that forces the location type.
Note that this also reverts the gdb hunk from:
commit 2a8be20359
Commit: Tom Tromey <tom@tromey.com>
CommitDate: Sat Oct 6 22:17:45 2018 -0600
Fix Python gdb.Breakpoint.location crash
because now "catch throw" catchpoints hit the
if (obj->bp->type != bp_breakpoint)
Py_RETURN_NONE;
check above, and, adjusts the testcase to no longer expect to see the
catchpoint in the gdb.breakpoints() list.
(Note: might make sense to do the same to Ada exception catchpoints.)
gdb/ChangeLog:
2019-07-09 Pedro Alves <palves@redhat.com>
* break-catch-throw.c (print_one_exception_catchpoint): Skip the
"addr" field.
(allocate_location_exception_catchpoint): New.
(handle_gnu_v3_exceptions): Don't reset 'type' to bp_breakpoint.
(initialize_throw_catchpoint_ops): Install
allocate_location_exception_catchpoint as allocate_location
method.
* breakpoint.c (bpstat_what) <bp_catch>: Set action to
BPSTAT_WHAT_SINGLE if not stopping and the location's type is not
bp_loc_other.
(breakpoint_address_is_meaningful): Delete.
(bl_address_is_meaningful): New.
(breakpoint_locations_match): Adjust comment.
(bp_location_from_bp_type): New, factored out of...
(bp_location::bp_location(breakpoint *)): ... this.
(bp_location::bp_location(breakpoint *, bp_loc_type)): New,
factored out of...
(bp_location::bp_location(breakpoint *)): ... this. Reimplement.
(bp_loc_is_permanent): Use bl_address_is_meaningful instead of
breakpoint_address_is_meaningful.
(bp_locations_compare): Adjust comment.
(update_global_location_list): Use bl_address_is_meaningful
instead of breakpoint_address_is_meaningful.
* breakpoint.h (bp_location::bp_location(breakpoint *)): New
explicit.
(bp_location::bp_location(breakpoint *, bp_loc_type)): Declare.
* python/py-breakpoint.c (bppy_get_location): No longer check
whether location is null.
gdb/doc/ChangeLog:
2019-07-09 Pedro Alves <palves@redhat.com>
* gdb.texinfo (C++ Exception GDB/MI Catchpoint Commands): Adjust
examples to show type=catchpoint instead of type=breakpoint and an
address.
gdb/testsuite/ChangeLog:
2019-07-09 Pedro Alves <palves@redhat.com>
* gdb.cp/catch-multi-stdlib.exp: Adjust expected "info
breakpoints" output.
* gdb.cp/exception.exp: Adjust expected "info breakpoints" output.
* gdb.python/py-breakpoint.exp: No longer expect that "catch
throw" creates breakpoint.
* gdb.mi/mi-catch-cpp-exceptions.exp (setup_catchpoint): Expect
'type="catchpoint"'.
88 lines
3.0 KiB
Plaintext
88 lines
3.0 KiB
Plaintext
# Copyright 2019 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/>.
|
|
|
|
# Regression test for a GDB internal error that would trigger if a
|
|
# "catch catch" catchpoint ended up with multiple locations. This
|
|
# testcase exercises that scenario by building the binary with
|
|
# -static-libgcc/-static-libstdc++ and a shared library that depends
|
|
# on the libstc++.so DSO (which is how GDB was built and revealed the
|
|
# bug), and vice versa.
|
|
|
|
if {[skip_shlib_tests]} {
|
|
return 0
|
|
}
|
|
|
|
# STATIC_BIN indicates whether to build the main binary with
|
|
# -static-libgcc/-static-libstdc++. STATIC_LIB is the same, but for
|
|
# the shared library.
|
|
proc test_multi_libstdcpp {static_bin static_lib} {
|
|
global srcdir subdir
|
|
global decimal hex
|
|
|
|
# Library file.
|
|
set libname "except-multi-location-lib"
|
|
set srcfile_lib ${srcdir}/${subdir}/${libname}.cc
|
|
set binfile_lib [standard_output_file ${libname}-$static_bin-$static_lib.so]
|
|
set lib_flags {debug c++}
|
|
if {$static_lib} {
|
|
lappend lib_flags additional_flags=-static-libgcc additional_flags=-static-libstdc++
|
|
}
|
|
|
|
# Binary file.
|
|
set testfile "except-multi-location-main"
|
|
set srcfile ${srcdir}/${subdir}/${testfile}.cc
|
|
set binfile [standard_output_file ${testfile}-$static_bin-$static_lib]
|
|
set bin_flags [list debug c++ shlib=${binfile_lib}]
|
|
if {$static_bin} {
|
|
lappend bin_flags additional_flags=-static-libgcc additional_flags=-static-libstdc++
|
|
}
|
|
|
|
if { [gdb_compile_shlib ${srcfile_lib} ${binfile_lib} $lib_flags] != ""
|
|
|| [gdb_compile ${srcfile} ${binfile} executable $bin_flags] != "" } {
|
|
untested "failed to compile"
|
|
return -1
|
|
}
|
|
|
|
clean_restart
|
|
|
|
gdb_load ${binfile}
|
|
gdb_load_shlib $binfile_lib
|
|
|
|
if ![runto_main] {
|
|
fail "can't run to main"
|
|
return 0
|
|
}
|
|
|
|
gdb_test "catch catch" "Catchpoint \[0-9\]+ \\(catch\\)" \
|
|
"catch catch"
|
|
gdb_test "catch throw" "Catchpoint \[0-9\]+ \\(throw\\)" \
|
|
"catch throw"
|
|
gdb_test "catch rethrow" "Catchpoint \[0-9\]+ \\(rethrow\\)" \
|
|
"catch rethrow"
|
|
|
|
set ws "\[ \t\]*"
|
|
gdb_test "info breakpoints" \
|
|
[multi_line \
|
|
"${decimal}${ws}catchpoint${ws}keep${ws}y${ws}exception catch" \
|
|
"${decimal}${ws}catchpoint${ws}keep${ws}y${ws}exception throw" \
|
|
"${decimal}${ws}catchpoint${ws}keep${ws}y${ws}exception rethrow"]
|
|
}
|
|
|
|
# Try different static/not-static combinations.
|
|
foreach_with_prefix static_lib {"0" "1"} {
|
|
foreach_with_prefix static_bin {"0" "1"} {
|
|
test_multi_libstdcpp $static_lib $static_bin
|
|
}
|
|
}
|