From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 11/20] Use gdbpy_enter in py-unwind.c
Date: Thu, 10 Nov 2016 22:20:00 -0000 [thread overview]
Message-ID: <1478816387-27064-12-git-send-email-tom@tromey.com> (raw)
In-Reply-To: <1478816387-27064-1-git-send-email-tom@tromey.com>
Change py-unwind.c to use gdbpy_enter.
2016-11-10 Tom Tromey <tom@tromey.com>
* 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 <tom@tromey.com>
+ * python/py-unwind.c (pending_frame_invalidate): Remove.
+ (pyuw_sniffer): Use gdbpy_enter and gdbpy_reference.
+
+2016-11-10 Tom Tromey <tom@tromey.com>
+
* 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. */
--
2.7.4
next prev parent reply other threads:[~2016-11-10 22:20 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-10 22:20 [RFA 00/20] more use of C++ in the Python layer Tom Tromey
2016-11-10 22:20 ` [RFA 15/20] Use gdbpy_enter in python_interactive_command Tom Tromey
2016-11-10 22:20 ` [RFA 04/20] Use gdbpy_enter in py-finishbreakpoint.c Tom Tromey
2016-11-10 22:20 ` [RFA 08/20] Use gdbpy_enter in python.c Tom Tromey
2016-11-10 22:20 ` [RFA 01/20] Introduce gdbpy_enter Tom Tromey
2016-11-10 23:19 ` Pedro Alves
2016-11-10 22:20 ` [RFA 07/20] Use gdbpy_enter in py-progspace.c Tom Tromey
2016-11-10 22:20 ` [RFA 05/20] Use gdbpy_enter in py-inferior.c Tom Tromey
2016-11-10 22:20 ` [RFA 14/20] Use gdbpy_enter in gdbpy_before_prompt_hook Tom Tromey
2016-11-10 23:19 ` Pedro Alves
2016-11-12 17:04 ` Tom Tromey
2016-11-10 22:20 ` [RFA 06/20] Use gdbpy_enter in py-objfile.c Tom Tromey
2016-11-10 22:20 ` [RFA 13/20] Use gdbpy_enter in py-prettyprint.c Tom Tromey
2016-11-10 22:20 ` [RFA 02/20] Use gdbpy_enter in py-breakpoint.c Tom Tromey
2016-11-10 22:20 ` [RFA 09/20] Use gdbpy_enter in py-type.c Tom Tromey
2016-11-10 22:20 ` [RFA 16/20] Use gdbpy_enter in gdbpy_get_matching_xmethod_workers Tom Tromey
2016-11-10 23:19 ` Pedro Alves
2016-11-11 3:19 ` Tom Tromey
2016-11-11 3:24 ` Pedro Alves
2016-11-12 17:09 ` Tom Tromey
2016-11-10 22:20 ` [RFA 17/20] Use gdbpy_reference in invoke_match_method Tom Tromey
2016-11-10 22:20 ` Tom Tromey [this message]
2016-11-10 22:20 ` [RFA 10/20] Use gdbpy_enter in py-xmethods.c Tom Tromey
2016-11-10 22:20 ` [RFA 03/20] Use gdbpy_enter in py-cmd.c Tom Tromey
2016-11-10 22:26 ` [RFA 12/20] Introduce htab_up and use gdbpy_enter in py-framefilter.c Tom Tromey
2016-11-10 22:26 ` [RFA 19/20] Introduce gdbpy_enter_varobj and use it Tom Tromey
2016-11-10 22:26 ` [RFA 18/20] Use gdbpy_enter in py-xmethod.c Tom Tromey
2016-11-10 22:26 ` [RFA 20/20] Use gdbpy_enter_varobj in py-varobj.c Tom Tromey
2016-11-10 23:52 ` [RFA 00/20] more use of C++ in the Python layer Pedro Alves
2016-11-11 3:19 ` Tom Tromey
2016-11-12 17:24 ` Tom Tromey
2016-11-15 14:57 ` Pedro Alves
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=1478816387-27064-12-git-send-email-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