Fix Python gdb.Breakpoint.location crash
Commit Message
I noticed today that gdb.Breakpoint.location will crash when applied
to a catchpoint made with "catch throw".
The bug is that "catch throw" makes a breakpoint that is of type
bp_breakpoint, but which does not have a location.
Regression tested on x86-64 Fedora 28.
gdb/ChangeLog
2018-09-18 Tom Tromey <tom@tromey.com>
* python/py-breakpoint.c (bppy_get_location): Handle a
bp_breakpoint without a location.
gdb/testsuite/ChangeLog
2018-09-18 Tom Tromey <tom@tromey.com>
* gdb.python/py-breakpoint.exp (check_last_event): Check location
of a "throw" catchpoint.
---
gdb/ChangeLog | 5 +++++
gdb/python/py-breakpoint.c | 7 ++++++-
gdb/testsuite/ChangeLog | 5 +++++
gdb/testsuite/gdb.python/py-breakpoint.exp | 5 +++++
4 files changed, 21 insertions(+), 1 deletion(-)
Comments
>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:
Tom> I noticed today that gdb.Breakpoint.location will crash when applied
Tom> to a catchpoint made with "catch throw".
Tom> The bug is that "catch throw" makes a breakpoint that is of type
Tom> bp_breakpoint, but which does not have a location.
Tom> Regression tested on x86-64 Fedora 28.
Tom> gdb/ChangeLog
Tom> 2018-09-18 Tom Tromey <tom@tromey.com>
Tom> * python/py-breakpoint.c (bppy_get_location): Handle a
Tom> bp_breakpoint without a location.
I'm checking this in now.
Tom
@@ -1,3 +1,8 @@
+2018-09-18 Tom Tromey <tom@tromey.com>
+
+ * python/py-breakpoint.c (bppy_get_location): Handle a
+ bp_breakpoint without a location.
+
2018-09-18 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
* utils.c (dump_core) [HAVE_SETRLIMIT]: Cast RLIM_INFINITY to
@@ -391,7 +391,12 @@ bppy_get_location (PyObject *self, void *closure)
if (obj->bp->type != bp_breakpoint)
Py_RETURN_NONE;
- str = event_location_to_string (obj->bp->location.get ());
+ struct event_location *location = obj->bp->location.get ();
+ /* "catch throw" makes a breakpoint of type bp_breakpoint that does
+ not have a location. */
+ if (location == nullptr)
+ Py_RETURN_NONE;
+ str = event_location_to_string (location);
if (! str)
str = "";
return host_string_to_python_string (str);
@@ -1,3 +1,8 @@
+2018-09-18 Tom Tromey <tom@tromey.com>
+
+ * gdb.python/py-breakpoint.exp (check_last_event): Check location
+ of a "throw" catchpoint.
+
2018-09-17 Simon Marchi <simon.marchi@polymtl.ca>
PR python/23669
@@ -616,6 +616,11 @@ proc_with_prefix test_bkpt_explicit_loc {} {
gdb_test "python bp1 = gdb.Breakpoint (function=\"blah\")" \
"Function \"blah\" not defined.*" \
"set invalid explicit breakpoint by missing function"
+
+ delete_breakpoints
+ gdb_test "catch throw" "Catchpoint .* \\(throw\\)"
+ gdb_test "python print (gdb.breakpoints()\[0\].location)" None \
+ "Examine location of catchpoint"
}
proc_with_prefix test_bkpt_qualified {} {