From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27612 invoked by alias); 13 Oct 2010 12:45:33 -0000 Received: (qmail 27600 invoked by uid 22791); 13 Oct 2010 12:45:28 -0000 X-SWARE-Spam-Status: No, hits=-5.6 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,TW_WB,TW_YB,T_FILL_THIS_FORM_SHORT,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; Wed, 13 Oct 2010 12:45:13 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o9DCj4YI013367 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 13 Oct 2010 08:45:04 -0400 Received: from localhost.localdomain.redhat.com (ovpn-113-25.phx2.redhat.com [10.3.113.25]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id o9DCj0Cm000379; Wed, 13 Oct 2010 08:45:02 -0400 From: Phil Muldoon To: Tom Tromey Cc: Pedro Alves , gdb-patches@sourceware.org, dan@codesourcery.com Subject: Re: [patch] Add visible flag to breakpoints. References: <201009301741.32379.pedro@codesourcery.com> <201010081435.15174.pedro@codesourcery.com> Reply-to: pmuldoon@redhat.com X-URL: http://www.redhat.com Date: Wed, 13 Oct 2010 12:45:00 -0000 In-Reply-To: (Tom Tromey's message of "Tue, 12 Oct 2010 15:34:44 -0600") 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-10/txt/msg00214.txt.bz2 Tom Tromey writes: >>>>>> "Phil" == Phil Muldoon writes: > > Phil> In this patch iteration I removed any form of storage/tracking of > Phil> breakpoints. Instead, as above, I placed a reference in the breakpoint > Phil> struct. > > I like this better. > > Phil> + if (internal && PyObject_IsTrue (internal)) > Phil> + internal_bp = 1; > > PyObject_IsTrue can return -1 on failure, so this code must account for > that. Oops done. Thanks. > Phil> + int i = 0; > Phil> + ALL_BREAKPOINTS (b) > > This instance of ALL_BREAKPOINTS should probably be replaced with some > kind of callback API, like the other iterate_over_* functions in gdb. I wrote an iterate function for this, much like the inferior iterator. I noticed in py-inferior.c we do not account for an error when adding to a list. (I'm pretty sure I wrote that too :( I'll fix this later. > Phil> + { > Phil> + /* Not all breakpoints will have a companion Python object. > Phil> + Only breakpoints that were created via bppy_new, or > Phil> + breakpoints that were created externally and are tracked by > Phil> + the Python Scripting API. */ > Phil> + if (b->py_bp_object) > Phil> + { > Phil> + if (PyTuple_SetItem (result, i, (PyObject *) b->py_bp_object) != 0) > > I think that cast to PyObject is unnecessary. As we use an iterator, we now set a list then convert it to an iterator later. This is like how we do it with inferior lists. (And it moves away from reference stealing that tuples do :( > Phil> @@ -667,9 +673,7 @@ gdbpy_breakpoint_created (int num) > Phil> breakpoint_object *newbp; > Phil> struct breakpoint *bp = NULL; > Phil> PyGILState_STATE state; > Phil> - > Phil> - if (num < 0) > Phil> - return; > Phil> + int error = 0; > > I am not certain that we want a new breakpoint object to be created for > internal breakpoints set by other modules. It seems potentially > harmful. I agree, fixed. > Phil> + newbp->bp->py_bp_object = (PyObject *)newbp; > > No cast. If I do not cast this, the compiler errors with: ../../archer/gdb/python/py-breakpoint.c: In function gdbpy_breakpoint_created: ../../archer/gdb/python/py-breakpoint.c:719: error: assignment from incompatible pointer type > Phil> + if (! error) > Phil> + ++bppy_live; > > You can get rid of the 'error' local and just push this back up into the > "ok" branch of the preceding 'if'. Ok. > Phil> /* Just ignore errors here. */ > Phil> PyErr_Clear (); > > I think this is redundant now. Ok. > Phil> + ALL_BREAKPOINTS (b) > Phil> + { > Phil> + if (b->number == num) > Phil> + { > Phil> + breakpoint_object *bp_obj = > Phil> + ((breakpoint_object *)b->py_bp_object); > > I think you can replace this ALL_BREAKPOINTS with a call to > get_breakpoint. Done. Latest patched attached. What do you think? Cheers, Phil -- diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index b4502e7..7ef97ec 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -4939,7 +4939,8 @@ breakpoint_1 (int bnum, int allflag, int (*filter) (const struct breakpoint *)) if (filter && !filter (b)) continue; - if (allflag || user_settable_breakpoint (b)) + if (allflag || (user_settable_breakpoint (b) + && b->number > 0)) { int addr_bit, type_len; @@ -5007,7 +5008,8 @@ breakpoint_1 (int bnum, int allflag, int (*filter) (const struct breakpoint *)) /* We only print out user settable breakpoints unless the allflag is set. */ - if (allflag || user_settable_breakpoint (b)) + if (allflag || (user_settable_breakpoint (b) + && b->number > 0)) print_one_breakpoint (b, &last_loc, print_address_bits, allflag); } } @@ -5456,6 +5458,7 @@ set_raw_breakpoint_without_location (struct gdbarch *gdbarch, b->syscalls_to_be_caught = NULL; b->ops = NULL; b->condition_not_parsed = 0; + b->py_bp_object = NULL; /* Add this breakpoint to the end of the chain so that a list of breakpoints will come out in order @@ -6914,7 +6917,8 @@ create_breakpoint_sal (struct gdbarch *gdbarch, char *cond_string, enum bptype type, enum bpdisp disposition, int thread, int task, int ignore_count, - struct breakpoint_ops *ops, int from_tty, int enabled) + struct breakpoint_ops *ops, int from_tty, + int enabled, int internal) { struct breakpoint *b = NULL; int i; @@ -6951,8 +6955,13 @@ create_breakpoint_sal (struct gdbarch *gdbarch, if (i == 0) { b = set_raw_breakpoint (gdbarch, sal, type); - set_breakpoint_count (breakpoint_count + 1); - b->number = breakpoint_count; + if (internal) + b->number = internal_breakpoint_number--; + else + { + set_breakpoint_count (breakpoint_count + 1); + b->number = breakpoint_count; + } b->thread = thread; b->task = task; @@ -7034,7 +7043,12 @@ Couldn't determine the static tracepoint marker to probe")); = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); b->ops = ops; - mention (b); + if (internal) + /* Do not mention breakpoints with a negative number, but do + notify observers. */ + observer_notify_breakpoint_created (b->number); + else + mention (b); } /* Remove element at INDEX_TO_REMOVE from SAL, shifting other @@ -7190,7 +7204,7 @@ create_breakpoints_sal (struct gdbarch *gdbarch, enum bptype type, enum bpdisp disposition, int thread, int task, int ignore_count, struct breakpoint_ops *ops, int from_tty, - int enabled) + int enabled, int internal) { int i; @@ -7201,7 +7215,8 @@ create_breakpoints_sal (struct gdbarch *gdbarch, create_breakpoint_sal (gdbarch, expanded, addr_string[i], cond_string, type, disposition, - thread, task, ignore_count, ops, from_tty, enabled); + thread, task, ignore_count, ops, + from_tty, enabled, internal); } } @@ -7464,25 +7479,24 @@ decode_static_tracepoint_spec (char **arg_p) return sals; } -/* Set a breakpoint. This function is shared between CLI and MI - functions for setting a breakpoint. This function has two major - modes of operations, selected by the PARSE_CONDITION_AND_THREAD - parameter. If non-zero, the function will parse arg, extracting - breakpoint location, address and thread. Otherwise, ARG is just the - location of breakpoint, with condition and thread specified by the - COND_STRING and THREAD parameters. Returns true if any breakpoint - was created; false otherwise. */ +/* Set a breakpoint. This function has two major modes of operations, + selected by the PARSE_CONDITION_AND_THREAD parameter. If non-zero, + the function will parse arg, extracting breakpoint location, + address and thread. Otherwise, ARG is just the location of + breakpoint, with condition and thread specified by the COND_STRING + and THREAD parameters. If INTERNAL is non-zero, the breakpoint + number will be allocated from the internal breakpoint count. + Returns true if any breakpoint was created; false otherwise. */ int -create_breakpoint (struct gdbarch *gdbarch, +create_new_breakpoint (struct gdbarch *gdbarch, char *arg, char *cond_string, int thread, int parse_condition_and_thread, int tempflag, enum bptype type_wanted, int ignore_count, enum auto_boolean pending_break_support, struct breakpoint_ops *ops, - int from_tty, - int enabled) + int from_tty, int enabled, int internal) { struct gdb_exception e; struct symtabs_and_lines sals; @@ -7658,12 +7672,15 @@ create_breakpoint (struct gdbarch *gdbarch, cond_string, type_wanted, tempflag ? disp_del : disp_donttouch, thread, task, ignore_count, ops, - from_tty, enabled); + from_tty, enabled, internal); do_cleanups (old_chain); /* Get the tracepoint we just created. */ - tp = get_breakpoint (breakpoint_count); + if (internal) + tp = get_breakpoint (internal_breakpoint_number); + else + tp = get_breakpoint (breakpoint_count); gdb_assert (tp != NULL); /* Given that its possible to have multiple markers with @@ -7679,7 +7696,7 @@ create_breakpoint (struct gdbarch *gdbarch, create_breakpoints_sal (gdbarch, sals, addr_string, cond_string, type_wanted, tempflag ? disp_del : disp_donttouch, thread, task, ignore_count, ops, from_tty, - enabled); + enabled, internal); } else { @@ -7688,8 +7705,13 @@ create_breakpoint (struct gdbarch *gdbarch, make_cleanup (xfree, copy_arg); b = set_raw_breakpoint_without_location (gdbarch, type_wanted); - set_breakpoint_count (breakpoint_count + 1); - b->number = breakpoint_count; + if (internal) + b->number = internal_breakpoint_number--; + else + { + set_breakpoint_count (breakpoint_count + 1); + b->number = breakpoint_count; + } b->thread = -1; b->addr_string = addr_string[0]; b->cond_string = NULL; @@ -7699,13 +7721,19 @@ create_breakpoint (struct gdbarch *gdbarch, b->ops = ops; b->enable_state = enabled ? bp_enabled : bp_disabled; b->pspace = current_program_space; + b->py_bp_object = NULL; if (enabled && b->pspace->executing_startup && (b->type == bp_breakpoint || b->type == bp_hardware_breakpoint)) b->enable_state = bp_startup_disabled; - mention (b); + if (internal) + /* Do not mention breakpoints with a negative number, but do + notify observers. */ + observer_notify_breakpoint_created (b->number); + else + mention (b); } if (sals.nelts > 1) @@ -7727,6 +7755,31 @@ create_breakpoint (struct gdbarch *gdbarch, return 1; } + +/* Set a breakpoint. This function is shared between CLI and MI + functions for setting a breakpoint. It wraps create_new_breakpoint + and never asks for an internal breakpoint number to be allocated + against the breakpoint. Returns true if any breakpoint was + created; false otherwise. */ + +int +create_breakpoint (struct gdbarch *gdbarch, + char *arg, char *cond_string, int thread, + int parse_condition_and_thread, + int tempflag, enum bptype type_wanted, + int ignore_count, + enum auto_boolean pending_break_support, + struct breakpoint_ops *ops, + int from_tty, + int enabled) +{ + return create_new_breakpoint (gdbarch, arg, cond_string, thread, + parse_condition_and_thread, tempflag, + type_wanted, ignore_count, + pending_break_support, + ops, from_tty, enabled, 0); +} + /* Set a breakpoint. ARG is a string describing breakpoint address, condition, and thread. @@ -11372,7 +11425,7 @@ save_breakpoints (char *filename, int from_tty, ALL_BREAKPOINTS (tp) { /* Skip internal and momentary breakpoints. */ - if (!user_settable_breakpoint (tp)) + if (!user_settable_breakpoint (tp) || tp->number < 0) continue; /* If we have a filter, only save the breakpoints it accepts. */ @@ -11410,7 +11463,7 @@ save_breakpoints (char *filename, int from_tty, ALL_BREAKPOINTS (tp) { /* Skip internal and momentary breakpoints. */ - if (!user_settable_breakpoint (tp)) + if (!user_settable_breakpoint (tp) || tp->number < 0) continue; /* If we have a filter, only save the breakpoints it accepts. */ @@ -11627,6 +11680,21 @@ save_command (char *arg, int from_tty) help_list (save_cmdlist, "save ", -1, gdb_stdout); } +struct breakpoint * +iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), + void *data) +{ + struct breakpoint *b, *temp; + + ALL_BREAKPOINTS_SAFE (b, temp) + { + if ((*callback) (b, data)) + return b; + } + + return NULL; +} + void _initialize_breakpoint (void) { diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index 9f7600a..d3fbc6a 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -24,6 +24,11 @@ #include "value.h" #include "vec.h" +#if HAVE_PYTHON +#include "python/python.h" +#include "python/python-internal.h" +#endif + struct value; struct block; @@ -557,7 +562,14 @@ struct breakpoint breakpoints, we will use this index to try to find the same marker again. */ int static_trace_marker_id_idx; - }; + + /* With a Python scripting enabled GDB, store a reference to the + Python object that has been associated with this breakpoint. + This is always NULL for a GDB that is not script enabled. It + can sometimes be NULL for enabled GDBs as not all breakpoint + types are tracked by the Python scripting API. */ + PyObject *py_bp_object; +}; typedef struct breakpoint *breakpoint_p; DEF_VEC_P(breakpoint_p); @@ -870,6 +882,18 @@ extern int create_breakpoint (struct gdbarch *gdbarch, char *arg, int from_tty, int enabled); +extern int create_new_breakpoint (struct gdbarch *gdbarch, char *arg, + char *cond_string, int thread, + int parse_condition_and_thread, + int tempflag, + enum bptype type_wanted, + int ignore_count, + enum auto_boolean pending_break_support, + struct breakpoint_ops *ops, + int from_tty, + int enabled, + int internal); + extern void insert_breakpoints (void); extern int remove_breakpoints (void); @@ -1101,4 +1125,15 @@ extern void check_tracepoint_command (char *line, void *closure); extern void start_rbreak_breakpoints (void); extern void end_rbreak_breakpoints (void); +/* Breakpoint iterator function. + + Calls a callback function once for each breakpoint, so long as the + callback function returns false. If the callback function returns + true, the iteration will end and the current breakpoint will be + returned. This can be useful for implementing a search for a + breakpoint with arbitrary attributes, or for applying an operation + to every breakpoint. */ +extern struct breakpoint *iterate_over_breakpoints (int (*) (struct breakpoint *, + void *), void *); + #endif /* !defined (BREAKPOINT_H) */ 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/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index c73e2f3..632d657 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -22552,7 +22552,7 @@ Return the symbol table's source absolute file name. Python code can manipulate breakpoints via the @code{gdb.Breakpoint} class. -@defmethod Breakpoint __init__ spec @r{[}type@r{]} @r{[}wp_class@r{]} +@defmethod Breakpoint __init__ spec @r{[}type@r{]} @r{[}wp_class@r{]} @r{[}internal@r{]} Create a new breakpoint. @var{spec} is a string naming the location of the breakpoint, or an expression that defines a watchpoint. The contents can be any location recognized by the @@ -22560,7 +22560,12 @@ watchpoint. The contents can be any location recognized by the command. The optional @var{type} denotes the breakpoint to create from the types defined later in this chapter. This argument can be either: @code{BP_BREAKPOINT} or @code{BP_WATCHPOINT}. @var{type} -defaults to @code{BP_BREAKPOINT}. The optional @var{wp_class} +defaults to @code{BP_BREAKPOINT}. The optional @var{internal} argument +allows the breakpoint to become invisible to the user. The breakpoint +will neither be reported when created, nor will it be listed in the +output from @code{info breakpoints} (but will be listed with the +@code{maint info breakpoints} command). The @var{internal} argument +has no effect with watchpoints. The optional @var{wp_class} argument defines the class of watchpoint to create, if @var{type} is defined as @code{BP_WATCHPOINT}. If a watchpoint class is not provided, it is assumed to be a @var{WP_WRITE} class. @@ -22638,6 +22643,13 @@ determine the actual breakpoint type or use-case. This attribute is not writable. @end defivar +@defivar Breakpoint visible +This attribute holds the breakpoint's visibility flag---the identifier used to +determine whether the breakpoint is visible to the user when set, or +when the @samp{info breakpoints} command is run. This attribute is +not writable. +@end defivar + The available types are represented by constants defined in the @code{gdb} module: diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index 0c70cbf..2eaeb07 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -34,17 +34,6 @@ typedef struct breakpoint_object breakpoint_object; static PyTypeObject breakpoint_object_type; -/* A dynamically allocated vector of breakpoint objects. Each - breakpoint has a number. A breakpoint is valid if its slot in this - vector is non-null. When a breakpoint is deleted, we drop our - reference to it and zero its slot; this is how we let the Python - object have a lifetime which is independent from that of the gdb - breakpoint. */ -static breakpoint_object **bppy_breakpoints; - -/* Number of slots in bppy_breakpoints. */ -static int bppy_slots; - /* Number of live breakpoints. */ static int bppy_live; @@ -68,7 +57,7 @@ struct breakpoint_object exception if it is invalid. */ #define BPPY_REQUIRE_VALID(Breakpoint) \ do { \ - if (! bpnum_is_valid ((Breakpoint)->number)) \ + if ((Breakpoint)->bp == NULL) \ return PyErr_Format (PyExc_RuntimeError, _("Breakpoint %d is invalid."), \ (Breakpoint)->number); \ } while (0) @@ -77,7 +66,7 @@ struct breakpoint_object exception if it is invalid. This macro is for use in setter functions. */ #define BPPY_SET_REQUIRE_VALID(Breakpoint) \ do { \ - if (! bpnum_is_valid ((Breakpoint)->number)) \ + if ((Breakpoint)->bp == NULL) \ { \ PyErr_Format (PyExc_RuntimeError, _("Breakpoint %d is invalid."), \ (Breakpoint)->number); \ @@ -115,18 +104,6 @@ static struct pybp_code pybp_watch_types[] = {NULL} /* Sentinel. */ }; -/* Evaluate to true if the breakpoint NUM is valid, false otherwise. */ -static int -bpnum_is_valid (int num) -{ - if (num >=0 - && num < bppy_slots - && bppy_breakpoints[num] != NULL) - return 1; - - return 0; -} - /* Python function which checks the validity of a breakpoint object. */ static PyObject * bppy_is_valid (PyObject *self, PyObject *args) @@ -500,6 +477,21 @@ bppy_get_type (PyObject *self, void *closure) return PyInt_FromLong (self_bp->bp->type); } +/* Python function to get the visibility of the breakpoint. */ + +static PyObject * +bppy_get_visibility (PyObject *self, void *closure) +{ + breakpoint_object *self_bp = (breakpoint_object *) self; + + BPPY_REQUIRE_VALID (self_bp); + + if (self_bp->bp->number < 0) + Py_RETURN_FALSE; + + Py_RETURN_TRUE; +} + /* Python function to get the breakpoint's number. */ static PyObject * bppy_get_number (PyObject *self, void *closure) @@ -566,16 +558,25 @@ static PyObject * bppy_new (PyTypeObject *subtype, PyObject *args, PyObject *kwargs) { PyObject *result; - static char *keywords[] = { "spec", "type", "wp_class", NULL }; + static char *keywords[] = { "spec", "type", "wp_class", "internal", NULL }; char *spec; int type = bp_breakpoint; int access_type = hw_write; + PyObject *internal = NULL; + int internal_bp = 0; volatile struct gdb_exception except; - if (! PyArg_ParseTupleAndKeywords (args, kwargs, "s|ii", keywords, - &spec, &type, &access_type)) + if (! PyArg_ParseTupleAndKeywords (args, kwargs, "s|iiO", keywords, + &spec, &type, &access_type, &internal)) return NULL; + if (internal) + { + internal_bp = PyObject_IsTrue (internal); + if (internal_bp == -1) + return NULL; + } + result = subtype->tp_alloc (subtype, 0); if (! result) return NULL; @@ -589,13 +590,13 @@ bppy_new (PyTypeObject *subtype, PyObject *args, PyObject *kwargs) { case bp_breakpoint: { - create_breakpoint (python_gdbarch, - spec, NULL, -1, - 0, - 0, bp_breakpoint, - 0, - AUTO_BOOLEAN_TRUE, - NULL, 0, 1); + create_new_breakpoint (python_gdbarch, + spec, NULL, -1, + 0, + 0, bp_breakpoint, + 0, + AUTO_BOOLEAN_TRUE, + NULL, 0, 1, internal_bp); break; } case bp_watchpoint: @@ -628,31 +629,50 @@ bppy_new (PyTypeObject *subtype, PyObject *args, PyObject *kwargs) +static int +build_bp_list (struct breakpoint *b, void *arg) +{ + PyObject *list = arg; + PyObject *bp = b->py_bp_object; + int iserr = 0; + + /* Not all breakpoints will have a companion Python object. + Only breakpoints that were created via bppy_new, or + breakpoints that were created externally and are tracked by + the Python Scripting API. */ + if (bp) + iserr = PyList_Append (list, bp); + + if (iserr == -1) + return 1; + + return 0; +} + /* Static function to return a tuple holding all breakpoints. */ PyObject * gdbpy_breakpoints (PyObject *self, PyObject *args) { - PyObject *result; + PyObject *list; if (bppy_live == 0) Py_RETURN_NONE; - result = PyTuple_New (bppy_live); - if (result) - { - int i, out = 0; + list = PyList_New (0); + if (!list) + return NULL; - for (i = 0; out < bppy_live; ++i) - { - if (! bppy_breakpoints[i]) - continue; - Py_INCREF (bppy_breakpoints[i]); - PyTuple_SetItem (result, out, (PyObject *) bppy_breakpoints[i]); - ++out; - } + /* If iteratre_over_breakpoints returns non NULL it signals an error + condition in our case. In that case abandon building the list and + return NULL. */ + if (iterate_over_breakpoints (build_bp_list, list) != NULL) + { + Py_DECREF (list); + return NULL; } - return result; + + return PyList_AsTuple (list); } @@ -668,13 +688,13 @@ gdbpy_breakpoint_created (int num) struct breakpoint *bp = NULL; PyGILState_STATE state; - if (num < 0) - return; - bp = get_breakpoint (num); if (! bp) return; + if (num < 0 && bppy_pending_object == NULL) + return; + if (bp->type != bp_breakpoint && bp->type != bp_watchpoint && bp->type != bp_hardware_watchpoint @@ -682,21 +702,6 @@ gdbpy_breakpoint_created (int num) && bp->type != bp_access_watchpoint) return; - if (num >= bppy_slots) - { - int old = bppy_slots; - - bppy_slots = bppy_slots * 2 + 10; - bppy_breakpoints - = (breakpoint_object **) xrealloc (bppy_breakpoints, - (bppy_slots - * sizeof (breakpoint_object *))); - memset (&bppy_breakpoints[old], 0, - (bppy_slots - old) * sizeof (PyObject *)); - } - - ++bppy_live; - state = PyGILState_Ensure (); if (bppy_pending_object) @@ -710,12 +715,16 @@ gdbpy_breakpoint_created (int num) { newbp->number = num; newbp->bp = bp; - bppy_breakpoints[num] = newbp; + newbp->bp->py_bp_object = (PyObject *) newbp; Py_INCREF (newbp); + ++bppy_live; + } + else + { + PyErr_SetString (PyExc_RuntimeError, + _("Error while creating breakpoint from GDB.")); + gdbpy_print_stack (); } - - /* Just ignore errors here. */ - PyErr_Clear (); PyGILState_Release (state); } @@ -726,14 +736,20 @@ static void gdbpy_breakpoint_deleted (int num) { PyGILState_STATE state; + struct breakpoint *bp = NULL; + breakpoint_object *bp_obj; state = PyGILState_Ensure (); - if (bpnum_is_valid (num)) + bp = get_breakpoint (num); + if (! bp) + return; + + bp_obj = ((breakpoint_object *) bp->py_bp_object); + if (bp_obj) { - bppy_breakpoints[num]->bp = NULL; - Py_DECREF (bppy_breakpoints[num]); - bppy_breakpoints[num] = NULL; + bp_obj->bp = NULL; --bppy_live; + Py_DECREF (bp_obj); } PyGILState_Release (state); } @@ -816,6 +832,8 @@ or None if no condition set."}, "Commands of the breakpoint, as specified by the user."}, { "type", bppy_get_type, NULL, "Type of breakpoint."}, + { "visible", bppy_get_visibility, NULL, + "Whether the breakpoint is visible to the user."}, { NULL } /* Sentinel. */ }; diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp index 7da94c4..9acc433 100644 --- a/gdb/testsuite/gdb.python/py-breakpoint.exp +++ b/gdb/testsuite/gdb.python/py-breakpoint.exp @@ -117,6 +117,33 @@ gdb_test "end" gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" "Get Breakpoint List" 0 gdb_test "python print blist\[len(blist)-1\].commands" "print \"Command for breakpoint has been executed.\".*print result" +# Start with a fresh gdb. +clean_restart ${testfile} + +if ![runto_main] then { + fail "Cannot run to main." + return 0 +} + +# Test invisible breakpooints. +delete_breakpoints +set ibp_location [gdb_get_line_number "Break at multiply."] +gdb_py_test_silent_cmd "python ibp = gdb.Breakpoint(\"$ibp_location\", internal=False)" "Set invisible breakpoint" 0 +gdb_py_test_silent_cmd "python ilist = gdb.breakpoints()" "Get Breakpoint List" 0 +gdb_test "python print ilist\[0\]" "" "Check invisible bp obj exists" +gdb_test "python print ilist\[0\].location" "py-breakpoint\.c:$ibp_location*" "Check breakpoint location" +gdb_test "python print ilist\[0\].visible" "True" "Check breakpoint visibility" +gdb_test "info breakpoints" "py-breakpoint\.c:$ibp_location.*" "Check info breakpoints shows visible breakpoints" +delete_breakpoints +gdb_py_test_silent_cmd "python ibp = gdb.Breakpoint(\"$ibp_location\", internal=True)" "Set invisible breakpoint" 0 +gdb_py_test_silent_cmd "python ilist = gdb.breakpoints()" "Get Breakpoint List" 0 +gdb_test "python print ilist\[0\]" "" "Check invisible bp obj exists" +gdb_test "python print ilist\[0\].location" "py-breakpoint\.c:$ibp_location*" "Check breakpoint location" +gdb_test "python print ilist\[0\].visible" "False" "Check breakpoint visibility" +gdb_test "info breakpoints" "No breakpoints or watchpoints.*" "Check info breakpoints does not show invisible breakpoints" +gdb_test "maint info breakpoints" "py-breakpoint\.c:$ibp_location.*" "Check maint info breakpoints shows invisible breakpoints" + + # Watchpoints # Start with a fresh gdb. clean_restart ${testfile} 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. */