public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH] Fix Python gdb.Breakpoint.location crash
Date: Tue, 18 Sep 2018 12:29:00 -0000	[thread overview]
Message-ID: <20180918122853.19426-1-tom@tromey.com> (raw)

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(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index ddd2782d99c..3649111235c 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -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
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index e1db674647a..94afd503e92 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -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);
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index ad74bfdbf74..572494dba62 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -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
diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp
index 3ce0ea11dea..7d5fbccad3b 100644
--- a/gdb/testsuite/gdb.python/py-breakpoint.exp
+++ b/gdb/testsuite/gdb.python/py-breakpoint.exp
@@ -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 {} {
-- 
2.17.1

             reply	other threads:[~2018-09-18 12:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-18 12:29 Tom Tromey [this message]
2018-10-07  4:22 ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180918122853.19426-1-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).