Fix Python gdb.Breakpoint.location crash
authorTom Tromey <tom@tromey.com>
Tue, 18 Sep 2018 12:27:09 +0000 (06:27 -0600)
committerTom Tromey <tom@tromey.com>
Sun, 7 Oct 2018 04:17:45 +0000 (22:17 -0600)
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-10-06  Tom Tromey  <tom@tromey.com>

* python/py-breakpoint.c (bppy_get_location): Handle a
bp_breakpoint without a location.

gdb/testsuite/ChangeLog
2018-10-06  Tom Tromey  <tom@tromey.com>

* gdb.python/py-breakpoint.exp (check_last_event): Check location
of a "throw" catchpoint.

gdb/ChangeLog
gdb/python/py-breakpoint.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.python/py-breakpoint.exp

index 719647290d298b1d8d103f23f28de3835ee7c297..e6f821dc8f62369e8c0109e97360f6ccef521519 100644 (file)
@@ -1,3 +1,8 @@
+2018-10-06  Tom Tromey  <tom@tromey.com>
+
+       * python/py-breakpoint.c (bppy_get_location): Handle a
+       bp_breakpoint without a location.
+
 2018-10-06  Tom Tromey  <tom@tromey.com>
 
        * python/lib/gdb/function/strfns.py (_MemEq, _StrLen, _StrEq)
index e1db674647a394efefd819f171aa8794d9f49ac0..94afd503e92d9fdfcf08aedbc3eaf57759a2b767 100644 (file)
@@ -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);
index c78c09a15f7ae6f6689b4239f2f73851c2ef00ea..fc37967390e63ce920d2bbcf0f5d8891d781cbc2 100644 (file)
@@ -1,3 +1,8 @@
+2018-10-06  Tom Tromey  <tom@tromey.com>
+
+       * gdb.python/py-breakpoint.exp (check_last_event): Check location
+       of a "throw" catchpoint.
+
 2018-10-06  Sergio Durigan Junior  <sergiodj@redhat.com>
 
        * gdb.base/info-proc.exp: Update string expected from "help info
index 3ce0ea11deae07348a89957171db755fb89f99b4..7d5fbccad3b78564674c44722f5846f530ef1272 100644 (file)
@@ -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 {} {