Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Phil Muldoon <pmuldoon@redhat.com>
To: gdb-patches@sourceware.org
Subject: PR Python/12212
Date: Tue, 16 Nov 2010 10:51:00 -0000	[thread overview]
Message-ID: <m37hgdmti0.fsf@redhat.com> (raw)


This patches fixes a case where the API can request the currently
selected thread from GDB when no inferior is loaded.  This triggers an
error via assert.  Handle it in Python code instead.

Cheers,

Phil

--

2010-11-16  Phil Muldoon  <pmuldoon@redhat.com>

        PR python/12212 

	* python/py-infthread.c (gdbpy_selected_thread): Raise an error if
	find_thread_object returns NULL.
	* python/py-inferior.c (find_thread_object): Check if PIDGET
	returns 0.

2010-11-16  Phil Muldoon  <pmuldoon@redhat.com>

        PR python/12212 

	* gdb.python/python.exp: Check that selected_thread raises an
          error when no inferior is loaded.

--

diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index b1ddb168..6382dab 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -130,6 +130,9 @@ find_thread_object (ptid_t ptid)
   PyObject *inf_obj;
 
   pid = PIDGET (ptid);
+  if (pid == 0)
+    return NULL;
+
   inf_obj = find_inferior_object (pid);
 
   if (inf_obj)
diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
index 86aba50..188f8bd 100644
--- a/gdb/python/py-infthread.c
+++ b/gdb/python/py-infthread.c
@@ -175,13 +175,16 @@ gdbpy_selected_thread (PyObject *self, PyObject *args)
   PyObject *thread_obj;
 
   thread_obj = (PyObject *) find_thread_object (inferior_ptid);
-  if (thread_obj)
+
+  if (!thread_obj)
     {
-      Py_INCREF (thread_obj);
-      return thread_obj;
+      PyErr_SetString (PyExc_RuntimeError,
+		       _("Cannot return currently selected thread."));
+      return NULL;
     }
 
-  Py_RETURN_NONE;
+  Py_INCREF (thread_obj);
+  return thread_obj;
 }
 
 
diff --git a/gdb/testsuite/gdb.python/python.exp b/gdb/testsuite/gdb.python/python.exp
index dd9175a..a860dd1 100644
--- a/gdb/testsuite/gdb.python/python.exp
+++ b/gdb/testsuite/gdb.python/python.exp
@@ -146,6 +146,9 @@ gdb_test_no_output "python a = gdb.execute('help', to_string=True)" "collect hel
 
 gdb_test "python print a" ".*aliases -- Aliases of other commands.*" "verify help to uiout"
 
+# Test PR 12212, using InfThread.selected_thread() when no inferior is
+# loaded.
+gdb_test "python print gdb.selected_thread()" "RuntimeError: Cannot return currently selected thread.*" "selected_thread and no inferior"
 # Start with a fresh gdb.
 clean_restart ${testfile}
 


             reply	other threads:[~2010-11-16 10:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-16 10:51 Phil Muldoon [this message]
2010-11-16 18:40 ` Tom Tromey
2010-11-16 17:47   ` Phil Muldoon
2010-11-16 19:01     ` Tom Tromey
2010-11-16 20:17       ` Phil Muldoon
2010-11-16 21:27         ` Tom Tromey
2010-11-23 13:35           ` Phil Muldoon

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=m37hgdmti0.fsf@redhat.com \
    --to=pmuldoon@redhat.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