public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM] archer-pmuldoon-python-breakpoints: Do not track breakpoints on the Python side of the API
@ 2010-10-11 16:23 pmuldoon
0 siblings, 0 replies; only message in thread
From: pmuldoon @ 2010-10-11 16:23 UTC (permalink / raw)
To: archer-commits
The branch, archer-pmuldoon-python-breakpoints has been updated
via 6b5779f3fefbeff1cb9d896f22aeb89e90d0b8e6 (commit)
from fad1b0a1b10a961c15f506d5256452478d4eb3da (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email.
- Log -----------------------------------------------------------------
commit 6b5779f3fefbeff1cb9d896f22aeb89e90d0b8e6
Author: Phil Muldoon <pmuldoon@redhat.com>
Date: Mon Oct 11 17:20:49 2010 +0100
Do not track breakpoints on the Python side of the API
-----------------------------------------------------------------------
Summary of changes:
gdb/breakpoint.c | 8 +---
gdb/breakpoint.h | 19 ++++++++-
gdb/defs.h | 4 ++
gdb/python/py-breakpoint.c | 100 +++++++++++++++++--------------------------
gdb/varobj.c | 2 -
5 files changed, 64 insertions(+), 69 deletions(-)
First 500 lines of diff:
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 1516989..b5a677e 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -345,12 +345,6 @@ static int executing_breakpoint_commands;
/* Are overlay event breakpoints enabled? */
static int overlay_events_enabled;
-/* Walk the following statement or block through all breakpoints.
- ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
- breakpoint. */
-
-#define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
-
#define ALL_BREAKPOINTS_SAFE(B,TMP) \
for (B = breakpoint_chain; \
B ? (TMP=B->next, 1): 0; \
@@ -5458,6 +5452,7 @@ set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
b->syscalls_to_be_caught = NULL;
b->ops = NULL;
b->condition_not_parsed = 0;
+ b->bp_object = NULL;
/* Add this breakpoint to the end of the chain
so that a list of breakpoints will come out in order
@@ -7720,6 +7715,7 @@ create_new_breakpoint (struct gdbarch *gdbarch,
b->ops = ops;
b->enable_state = enabled ? bp_enabled : bp_disabled;
b->pspace = current_program_space;
+ b->bp_object = NULL;
if (enabled && b->pspace->executing_startup
&& (b->type == bp_breakpoint
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index d6cd6c6..4eb2fe0 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -24,9 +24,21 @@
#include "value.h"
#include "vec.h"
+#if HAVE_PYTHON
+#include "python/python.h"
+#include "python/python-internal.h"
+#endif
+
struct value;
struct block;
+/* Walk the following statement or block through all breakpoints.
+ ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
+ breakpoint. */
+
+extern struct breakpoint *breakpoint_chain;
+#define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
+
/* This is the maximum number of bytes a breakpoint instruction can take.
Feel free to increase it. It's just used in a few places to size
arrays that should be independent of the target architecture. */
@@ -557,7 +569,12 @@ struct breakpoint
breakpoints, we will use this index to try to find the same
marker again. */
int static_trace_marker_id_idx;
- };
+
+ /* If this is a Python enabled GDB, store a reference to the
+ Python object that has been associated with this breakpoint
+ struct. */
+ PyObject *bp_object;
+};
typedef struct breakpoint *breakpoint_p;
DEF_VEC_P(breakpoint_p);
diff --git a/gdb/defs.h b/gdb/defs.h
index 9e4800c..643338e 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -1240,4 +1240,8 @@ void dummy_obstack_deallocate (void *object, void *data);
extern void initialize_progspace (void);
extern void initialize_inferiors (void);
+#ifndef HAVE_PYTHON
+typedef int PyObject;
+#endif
+
#endif /* #ifndef DEFS_H */
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index 6381a19..5984d5f 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -51,20 +51,13 @@ struct breakpoint_object
/* The gdb breakpoint object, or NULL if the breakpoint has been
deleted. */
struct breakpoint *bp;
- struct breakpoint_object *next;
};
-/* Top and bottom of the breakpoint chain. We store bottom so we do
- not have to constantly iterate through the chain when we add a new
- breakpoint. */
-struct breakpoint_object *top;
-struct breakpoint_object *bottom;
-
/* Require that BREAKPOINT be a valid breakpoint ID; throw a Python
exception if it is invalid. */
#define BPPY_REQUIRE_VALID(Breakpoint) \
do { \
- if (Breakpoint == NULL) \
+ if ((Breakpoint)->bp == NULL) \
return PyErr_Format (PyExc_RuntimeError, _("Breakpoint %d is invalid."), \
(Breakpoint)->number); \
} while (0)
@@ -73,7 +66,7 @@ struct breakpoint_object *bottom;
exception if it is invalid. This macro is for use in setter functions. */
#define BPPY_SET_REQUIRE_VALID(Breakpoint) \
do { \
- if (Breakpoint == NULL) \
+ if ((Breakpoint)->bp == NULL) \
{ \
PyErr_Format (PyExc_RuntimeError, _("Breakpoint %d is invalid."), \
(Breakpoint)->number); \
@@ -81,9 +74,6 @@ struct breakpoint_object *bottom;
} \
} while (0)
-/* Iterator for Python breakpoints linked-list. */
-#define ALL_PY_BREAKPOINTS(B) for (B = top; B; B = B->next)
-
/* This is used to initialize various gdb.bp_* constants. */
struct pybp_code
{
@@ -488,6 +478,7 @@ bppy_get_type (PyObject *self, void *closure)
}
/* Python function to get the visibility of the breakpoint. */
+
static PyObject *
bppy_get_visibility (PyObject *self, void *closure)
{
@@ -579,17 +570,9 @@ bppy_new (PyTypeObject *subtype, PyObject *args, PyObject *kwargs)
&spec, &type, &access_type, &internal))
return NULL;
- if (internal)
- {
- if (! PyBool_Check (internal))
- {
- PyErr_SetString (PyExc_TypeError,
- _("The value of `internal' keyword must be a boolean."));
- return NULL;
- }
- if (internal == Py_True)
- internal_bp = 1;
- }
+ if (internal && PyObject_IsTrue (internal))
+ internal_bp = 1;
+
result = subtype->tp_alloc (subtype, 0);
if (! result)
return NULL;
@@ -597,9 +580,6 @@ bppy_new (PyTypeObject *subtype, PyObject *args, PyObject *kwargs)
bppy_pending_object->number = -1;
bppy_pending_object->bp = NULL;
- /* We do not add the breakpoint to the linked-list yet; GDB
- has not created the breakpoint. */
- bppy_pending_object->next = NULL;
TRY_CATCH (except, RETURN_MASK_ALL)
{
switch (type)
@@ -651,7 +631,7 @@ PyObject *
gdbpy_breakpoints (PyObject *self, PyObject *args)
{
PyObject *result;
- breakpoint_object *b;
+ struct breakpoint *b;
if (bppy_live == 0)
Py_RETURN_NONE;
@@ -660,11 +640,22 @@ gdbpy_breakpoints (PyObject *self, PyObject *args)
if (result)
{
int i = 0;
- ALL_PY_BREAKPOINTS (b)
+ ALL_BREAKPOINTS (b)
{
- Py_INCREF (b);
- PyTuple_SetItem (result, i, (PyObject *) b);
- ++i;
+ /* Not all breakpoints will have the Python object created
+ alongside it. Only breakpoints that were created in
+ Python, or breakpoints that were created in Python that
+ triggered an observer->observable event to occur. */
+ if (b->bp_object)
+ {
+ if (PyTuple_SetItem (result, i, (PyObject *) b->bp_object) != 0)
+ {
+ Py_DECREF (result);
+ return NULL;
+ }
+ Py_INCREF (b->bp_object);
+ ++i;
+ }
}
}
return result;
@@ -682,6 +673,7 @@ gdbpy_breakpoint_created (int num)
breakpoint_object *newbp;
struct breakpoint *bp = NULL;
PyGILState_STATE state;
+ int error = 0;
bp = get_breakpoint (num);
if (! bp)
@@ -703,31 +695,24 @@ gdbpy_breakpoint_created (int num)
}
else
newbp = PyObject_New (breakpoint_object, &breakpoint_object_type);
+
if (newbp)
{
newbp->number = num;
newbp->bp = bp;
- newbp->next = NULL;
+ newbp->bp->bp_object = (PyObject *)newbp;
Py_INCREF (newbp);
}
else
{
PyErr_SetString (PyExc_RuntimeError,
_("Error while creating breakpoint from GDB."));
- return;
+ gdbpy_print_stack ();
+ error = 1;
}
- ++bppy_live;
-
- /* If this is the first breakpoint created, set the top and bottom
- of the linked list. */
- if (top == NULL)
- top = newbp;
-
- if (bottom)
- bottom->next = newbp;
-
- bottom = newbp;
+ if (! error)
+ ++bppy_live;
/* Just ignore errors here. */
PyErr_Clear ();
@@ -741,27 +726,25 @@ static void
gdbpy_breakpoint_deleted (int num)
{
PyGILState_STATE state;
- breakpoint_object *b = NULL;
+ struct breakpoint *b = NULL;
breakpoint_object *prev = NULL;
state = PyGILState_Ensure ();
- ALL_PY_BREAKPOINTS (b)
+ ALL_BREAKPOINTS (b)
{
if (b->number == num)
{
- if (b == top)
- top = b->next;
- else
- prev->next = b->next;
- if (b == bottom)
- bottom = prev;
-
- b->bp = NULL;
- Py_DECREF (b);
- --bppy_live;
+ breakpoint_object *bp_object =
+ ((breakpoint_object *)b->bp_object);
+
+ if (bp_object)
+ {
+ bp_object->bp = NULL;
+ --bppy_live;
+ Py_DECREF (bp_object);
+ }
break;
}
- prev = b;
}
PyGILState_Release (state);
}
@@ -782,9 +765,6 @@ gdbpy_initialize_breakpoints (void)
PyModule_AddObject (gdb_module, "Breakpoint",
(PyObject *) &breakpoint_object_type);
- top = NULL;
- bottom = NULL;
-
observer_attach_breakpoint_created (gdbpy_breakpoint_created);
observer_attach_breakpoint_deleted (gdbpy_breakpoint_deleted);
diff --git a/gdb/varobj.c b/gdb/varobj.c
index 56cb8ae..2f2e469 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -39,8 +39,6 @@
#if HAVE_PYTHON
#include "python/python.h"
#include "python/python-internal.h"
-#else
-typedef int PyObject;
#endif
/* Non-zero if we want to see trace of varobj level stuff. */
hooks/post-receive
--
Repository for Project Archer.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2010-10-11 16:23 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-11 16:23 [SCM] archer-pmuldoon-python-breakpoints: Do not track breakpoints on the Python side of the API pmuldoon
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).