From patchwork Thu Nov 10 22:19:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 17398 Received: (qmail 64540 invoked by alias); 10 Nov 2016 22:20:38 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 64357 invoked by uid 89); 10 Nov 2016 22:20:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=*self, Installation X-HELO: gproxy10-pub.mail.unifiedlayer.com Received: from gproxy10-pub.mail.unifiedlayer.com (HELO gproxy10-pub.mail.unifiedlayer.com) (69.89.20.226) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with SMTP; Thu, 10 Nov 2016 22:20:02 +0000 Received: (qmail 9485 invoked by uid 0); 10 Nov 2016 22:20:01 -0000 Received: from unknown (HELO cmgw2) (10.0.90.83) by gproxy10.mail.unifiedlayer.com with SMTP; 10 Nov 2016 22:20:01 -0000 Received: from box522.bluehost.com ([74.220.219.122]) by cmgw2 with id 6NKw1u0102f2jeq01NKz9r; Thu, 10 Nov 2016 15:19:59 -0700 X-Authority-Analysis: v=2.1 cv=PIacp5aC c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=L24OOQBejmoA:10 a=zstS-IiYAAAA:8 a=45yu5-OR4ZssfSPmeVgA:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 174-16-143-211.hlrn.qwest.net ([174.16.143.211]:60120 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_1) (envelope-from ) id 1c4xhO-0002sd-26; Thu, 10 Nov 2016 15:19:58 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 11/20] Use gdbpy_enter in py-unwind.c Date: Thu, 10 Nov 2016 15:19:38 -0700 Message-Id: <1478816387-27064-12-git-send-email-tom@tromey.com> In-Reply-To: <1478816387-27064-1-git-send-email-tom@tromey.com> References: <1478816387-27064-1-git-send-email-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1c4xhO-0002sd-26 X-Source-Sender: 174-16-143-211.hlrn.qwest.net (bapiya.Home) [174.16.143.211]:60120 X-Source-Auth: tom+tromey.com X-Email-Count: 12 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== Change py-unwind.c to use gdbpy_enter. 2016-11-10 Tom Tromey * python/py-unwind.c (pending_frame_invalidate): Remove. (pyuw_sniffer): Use gdbpy_enter and gdbpy_reference. --- gdb/ChangeLog | 5 ++++ gdb/python/py-unwind.c | 72 +++++++++++++++++++++++--------------------------- 2 files changed, 38 insertions(+), 39 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 8a5a159..2101045 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2016-11-10 Tom Tromey + * python/py-unwind.c (pending_frame_invalidate): Remove. + (pyuw_sniffer): Use gdbpy_enter and gdbpy_reference. + +2016-11-10 Tom Tromey + * python/py-xmethods.c (gdbpy_free_xmethod_worker_data) (gdbpy_clone_xmethod_worker_data): Use gdbpy_enter. diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c index 52184bd..c9638d8 100644 --- a/gdb/python/py-unwind.c +++ b/gdb/python/py-unwind.c @@ -28,6 +28,7 @@ #include "regcache.h" #include "valprint.h" #include "user-regs.h" +#include "py-ref.h" #define TRACE_PY_UNWIND(level, args...) if (pyuw_debug >= level) \ { fprintf_unfiltered (gdb_stdlog, args); } @@ -460,15 +461,6 @@ pending_framepy_create_unwind_info (PyObject *self, PyObject *args) frame_id_build_special (sp, pc, special)); } -/* Invalidate PendingFrame instance. */ - -static void -pending_frame_invalidate (void *pyo_pending_frame) -{ - if (pyo_pending_frame != NULL) - ((pending_frame_object *) pyo_pending_frame)->frame_info = NULL; -} - /* frame_unwind.this_id method. */ static void @@ -512,25 +504,26 @@ pyuw_sniffer (const struct frame_unwind *self, struct frame_info *this_frame, void **cache_ptr) { struct gdbarch *gdbarch = (struct gdbarch *) (self->unwind_data); - struct cleanup *cleanups = ensure_python_env (gdbarch, current_language); - PyObject *pyo_execute; - PyObject *pyo_pending_frame; - PyObject *pyo_unwind_info; cached_frame_info *cached_frame; + gdbpy_enter enter_py (gdbarch, current_language); + TRACE_PY_UNWIND (3, "%s (SP=%s, PC=%s)\n", __FUNCTION__, paddress (gdbarch, get_frame_sp (this_frame)), paddress (gdbarch, get_frame_pc (this_frame))); /* Create PendingFrame instance to pass to sniffers. */ - pyo_pending_frame = (PyObject *) PyObject_New (pending_frame_object, - &pending_frame_object_type); + pending_frame_object *pfo = PyObject_New (pending_frame_object, + &pending_frame_object_type); + gdbpy_reference pyo_pending_frame ((PyObject *) pfo); if (pyo_pending_frame == NULL) - goto error; - ((pending_frame_object *) pyo_pending_frame)->gdbarch = gdbarch; - ((pending_frame_object *) pyo_pending_frame)->frame_info = this_frame; - make_cleanup_py_decref (pyo_pending_frame); - make_cleanup (pending_frame_invalidate, (void *) pyo_pending_frame); + { + gdbpy_print_stack (); + return 0; + } + pfo->gdbarch = gdbarch; + scoped_restore invalidate_frame = make_scoped_restore (&pfo->frame_info, + this_frame); /* Run unwinders. */ if (gdb_python_module == NULL @@ -539,27 +532,36 @@ pyuw_sniffer (const struct frame_unwind *self, struct frame_info *this_frame, PyErr_SetString (PyExc_NameError, "Installation error: gdb.execute_unwinders function " "is missing"); - goto error; + gdbpy_print_stack (); + return 0; } - pyo_execute = PyObject_GetAttrString (gdb_python_module, "execute_unwinders"); + gdbpy_reference pyo_execute (PyObject_GetAttrString (gdb_python_module, + "execute_unwinders")); if (pyo_execute == NULL) - goto error; - make_cleanup_py_decref (pyo_execute); - pyo_unwind_info - = PyObject_CallFunctionObjArgs (pyo_execute, pyo_pending_frame, NULL); + { + gdbpy_print_stack (); + return 0; + } + + gdbpy_reference pyo_unwind_info + (PyObject_CallFunctionObjArgs (pyo_execute.get (), + pyo_pending_frame.get (), NULL)); if (pyo_unwind_info == NULL) - goto error; - make_cleanup_py_decref (pyo_unwind_info); + { + gdbpy_print_stack (); + return 0; + } if (pyo_unwind_info == Py_None) - goto cannot_unwind; + return 0; /* Received UnwindInfo, cache data. */ - if (PyObject_IsInstance (pyo_unwind_info, + if (PyObject_IsInstance (pyo_unwind_info.get (), (PyObject *) &unwind_info_object_type) <= 0) error (_("A Unwinder should return gdb.UnwindInfo instance.")); { - unwind_info_object *unwind_info = (unwind_info_object *) pyo_unwind_info; + unwind_info_object *unwind_info = + (unwind_info_object *) pyo_unwind_info.get (); int reg_count = VEC_length (saved_reg, unwind_info->saved_regs); saved_reg *reg; int i; @@ -590,15 +592,7 @@ pyuw_sniffer (const struct frame_unwind *self, struct frame_info *this_frame, } *cache_ptr = cached_frame; - do_cleanups (cleanups); return 1; - - error: - gdbpy_print_stack (); - /* Fallthrough. */ - cannot_unwind: - do_cleanups (cleanups); - return 0; } /* Frame cache release shim. */