From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9854 invoked by alias); 16 Nov 2010 10:51:28 -0000 Received: (qmail 9843 invoked by uid 22791); 16 Nov 2010 10:51:27 -0000 X-SWARE-Spam-Status: No, hits=-5.7 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 16 Nov 2010 10:51:22 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oAGApLPU014319 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 16 Nov 2010 05:51:21 -0500 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id oAGApKv1004772 for ; Tue, 16 Nov 2010 05:51:20 -0500 From: Phil Muldoon To: gdb-patches@sourceware.org Subject: PR Python/12212 Reply-to: pmuldoon@redhat.com X-URL: http://www.redhat.com Date: Tue, 16 Nov 2010 10:51:00 -0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-11/txt/msg00199.txt.bz2 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 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 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}