* Re: [0/27] RFC: fix reports from the CPython checker
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
@ 2013-04-19 14:32 ` Eli Zaretskii
2013-04-19 18:08 ` Tom Tromey
2013-04-19 14:34 ` Tom Tromey
` (29 subsequent siblings)
30 siblings, 1 reply; 66+ messages in thread
From: Eli Zaretskii @ 2013-04-19 14:32 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches, Pierre Muller
> From: Tom Tromey <tromey@redhat.com>
> Date: Fri, 19 Apr 2013 08:13:51 -0600
>
> The Python plugin for GCC comes with an analyzer that checks the usage
> of the CPython API:
>
> https://gcc-python-plugin.readthedocs.org/en/latest/cpychecker.html
>
> I ran this checker on gdb and fixed a number of bugs that it pointed
> out.
>
> Unfortunately the checker still has a large number of false reports.
> Some of these are due to oddities in gdb -- cleanups mostly -- but some
> are bugs in the checker itself. I've filed bug reports against the
> checker (and fixed some bugs as well); and will file more later.
>
> I built and regtested this series on x86-64 Fedora 18.
>
> I think most of the patches are pretty obvious.
>
> I intend to run the checker periodically and fix problems.
Would it be a good idea to run it automatically by ARI?
^ permalink raw reply [flat|nested] 66+ messages in thread* Re: [0/27] RFC: fix reports from the CPython checker
2013-04-19 14:32 ` Eli Zaretskii
@ 2013-04-19 18:08 ` Tom Tromey
0 siblings, 0 replies; 66+ messages in thread
From: Tom Tromey @ 2013-04-19 18:08 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: gdb-patches, Pierre Muller
>>>>> "Eli" == Eli Zaretskii <eliz@gnu.org> writes:
Eli> Would it be a good idea to run it automatically by ARI?
I don't think so. I wouldn't mind if someone wants to try, but it isn't
totally easy to run (the checker explodes on some non-Python-using files
in gdb, so I only run it on the Python-using files) and it still gives a
lot of false reports (105 by my count) plus a couple unhandled
exceptions from the checker.
Tom
^ permalink raw reply [flat|nested] 66+ messages in thread
* Re: [0/27] RFC: fix reports from the CPython checker
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
2013-04-19 14:32 ` Eli Zaretskii
@ 2013-04-19 14:34 ` Tom Tromey
2013-04-19 14:36 ` Tom Tromey
` (28 subsequent siblings)
30 siblings, 0 replies; 66+ messages in thread
From: Tom Tromey @ 2013-04-19 14:34 UTC (permalink / raw)
To: gdb-patches
>>>>> "Tom" == Tom Tromey <tromey@redhat.com> writes:
The title here says 0/27 but really it should be 0/28.
Sorry about that.
Tom
^ permalink raw reply [flat|nested] 66+ messages in thread* Re: [0/27] RFC: fix reports from the CPython checker
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
2013-04-19 14:32 ` Eli Zaretskii
2013-04-19 14:34 ` Tom Tromey
@ 2013-04-19 14:36 ` Tom Tromey
2013-04-19 14:36 ` [PATCH 01/28] introduce CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF and use it Tom Tromey
` (27 subsequent siblings)
30 siblings, 0 replies; 66+ messages in thread
From: Tom Tromey @ 2013-04-19 14:36 UTC (permalink / raw)
To: gdb-patches
This adds the borrowed-ref attribute from the CPython checker, and
then updates the code to use it in various places. This attribute
tells the checker that a function returns a borrowed reference.
* python/py-threadevent.c (get_event_thread): Use
CPYCHECKER_RETURNS_BORROWED_REF.
* python/python-internal.h (CPYCHECKER_RETURNS_BORROWED_REF):
New define.
(pspace_to_pspace_object, objfile_to_objfile_object)
(find_thread_object): Use it.
---
gdb/python/py-threadevent.c | 3 +++
gdb/python/python-internal.h | 16 +++++++++++++---
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/gdb/python/py-threadevent.c b/gdb/python/py-threadevent.c
index 7e13f14..ea9de89 100644
--- a/gdb/python/py-threadevent.c
+++ b/gdb/python/py-threadevent.c
@@ -24,6 +24,9 @@
This function returns the currently stopped thread in non-stop mode and
Py_None otherwise. In each case it returns a borrowed reference. */
+static PyObject *get_event_thread (void)
+ CPYCHECKER_RETURNS_BORROWED_REF;
+
static PyObject *
get_event_thread (void)
{
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 802dd33..394a148 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -20,6 +20,13 @@
#ifndef GDB_PYTHON_INTERNAL_H
#define GDB_PYTHON_INTERNAL_H
+#ifdef WITH_CPYCHECKER_RETURNS_BORROWED_REF_ATTRIBUTE
+#define CPYCHECKER_RETURNS_BORROWED_REF \
+ __attribute__ ((cpychecker_returns_borrowed_ref))
+#else
+#define CPYCHECKER_RETURNS_BORROWED_REF
+#endif
+
#ifdef WITH_CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF_ATTRIBUTE
#define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG) \
__attribute__ ((cpychecker_type_object_for_typedef (ARG)))
@@ -263,16 +270,19 @@ PyObject *value_to_value_object (struct value *v);
PyObject *type_to_type_object (struct type *);
PyObject *frame_info_to_frame_object (struct frame_info *frame);
-PyObject *pspace_to_pspace_object (struct program_space *);
+PyObject *pspace_to_pspace_object (struct program_space *)
+ CPYCHECKER_RETURNS_BORROWED_REF;
PyObject *pspy_get_printers (PyObject *, void *);
-PyObject *objfile_to_objfile_object (struct objfile *);
+PyObject *objfile_to_objfile_object (struct objfile *)
+ CPYCHECKER_RETURNS_BORROWED_REF;
PyObject *objfpy_get_printers (PyObject *, void *);
PyObject *gdbarch_to_arch_object (struct gdbarch *gdbarch);
thread_object *create_thread_object (struct thread_info *tp);
-thread_object *find_thread_object (ptid_t ptid);
+thread_object *find_thread_object (ptid_t ptid)
+ CPYCHECKER_RETURNS_BORROWED_REF;
PyObject *find_inferior_object (int pid);
PyObject *inferior_to_inferior_object (struct inferior *inferior);
--
1.8.1.4
^ permalink raw reply [flat|nested] 66+ messages in thread* [PATCH 01/28] introduce CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF and use it
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
` (2 preceding siblings ...)
2013-04-19 14:36 ` Tom Tromey
@ 2013-04-19 14:36 ` Tom Tromey
2013-05-15 15:57 ` Pedro Alves
2013-04-19 14:36 ` [PATCH 03/28] PyObject_GetAttrString returns a new ref Tom Tromey
` (26 subsequent siblings)
30 siblings, 1 reply; 66+ messages in thread
From: Tom Tromey @ 2013-04-19 14:36 UTC (permalink / raw)
To: gdb-patches
This introduces the CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF attribute and
changes the Python code to use it. This attribute associates a Python
type object with a particular implementation type. The checker uses
this information to improve its analysis in some cases.
* python/py-arch.c (arch_object_type): Use
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-block.c (block_syms_iterator_object_type):
Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-bpevent.c (breakpoint_event_object_type):
Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-cmd.c (cmdpy_object_type): Use
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-continueevent.c (continue_event_object_type):
Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-event.h (GDBPY_NEW_EVENT_TYPE):
Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-events.h (thread_event_object_type):
Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-evtregistry.c (eventregistry_object_type): Use
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-exitedevent.c (exited_event_object_type):
Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-finishbreakpoint.c (finish_breakpoint_object_type):
Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-function.c (fnpy_object_type): Use
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-inferior.c (inferior_object_type, membuf_object_type):
Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-infthread.c (thread_object_type): Use
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-lazy-string.c (lazy_string_object_type):
Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-newobjfileevent.c (new_objfile_event_object_type):
Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-objfile.c (objfile_object_type): Use
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-param.c (parmpy_object_type):
Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-progspace.c (pspace_object_type):
Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-signalevent.c (signal_event_object_type):
Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-symtab.c (symtab_object_type, sal_object_type): Use
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-type.c (type_object_type, field_object_type)
(type_iterator_object_type): Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-internal.h (CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF): New
define.
(value_object_type, block_object_type, symbol_object_type)
(event_object_type, stop_event_object_type, breakpoint_object_type)
(frame_object_type): Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
---
gdb/python/py-arch.c | 4 +++-
gdb/python/py-block.c | 3 ++-
gdb/python/py-bpevent.c | 3 ++-
gdb/python/py-cmd.c | 3 ++-
gdb/python/py-continueevent.c | 3 ++-
gdb/python/py-event.h | 5 +++--
gdb/python/py-events.h | 3 ++-
gdb/python/py-evtregistry.c | 3 ++-
gdb/python/py-exitedevent.c | 3 ++-
gdb/python/py-finishbreakpoint.c | 5 +++--
gdb/python/py-function.c | 3 ++-
gdb/python/py-inferior.c | 6 ++++--
gdb/python/py-infthread.c | 3 ++-
gdb/python/py-lazy-string.c | 3 ++-
gdb/python/py-newobjfileevent.c | 3 ++-
gdb/python/py-objfile.c | 3 ++-
gdb/python/py-param.c | 3 ++-
gdb/python/py-progspace.c | 3 ++-
gdb/python/py-signalevent.c | 3 ++-
gdb/python/py-symtab.c | 6 ++++--
gdb/python/py-type.c | 9 ++++++---
gdb/python/python-internal.h | 28 +++++++++++++++++++++-------
22 files changed, 74 insertions(+), 34 deletions(-)
diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c
index ddfebdb..7eb6eea 100644
--- a/gdb/python/py-arch.c
+++ b/gdb/python/py-arch.c
@@ -29,7 +29,9 @@ typedef struct arch_object_type_object {
} arch_object;
static struct gdbarch_data *arch_object_data = NULL;
-static PyTypeObject arch_object_type;
+
+static PyTypeObject arch_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("arch_object");
/* Associates an arch_object with GDBARCH as gdbarch_data via the gdbarch
post init registration mechanism (gdbarch_data_register_post_init). */
diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c
index f0b8322..afc8959 100644
--- a/gdb/python/py-block.c
+++ b/gdb/python/py-block.c
@@ -78,7 +78,8 @@ typedef struct {
} \
} while (0)
-static PyTypeObject block_syms_iterator_object_type;
+static PyTypeObject block_syms_iterator_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("block_syms_iterator_object");
static const struct objfile_data *blpy_objfile_data_key;
static PyObject *
diff --git a/gdb/python/py-bpevent.c b/gdb/python/py-bpevent.c
index dad93dc..5238ad8 100644
--- a/gdb/python/py-bpevent.c
+++ b/gdb/python/py-bpevent.c
@@ -20,7 +20,8 @@
#include "defs.h"
#include "py-stopevent.h"
-static PyTypeObject breakpoint_event_object_type;
+static PyTypeObject breakpoint_event_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
/* Create and initialize a BreakpointEvent object. This acquires new
references to BREAKPOINT_LIST and FIRST_BP. */
diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
index 161b4bc..3da9960 100644
--- a/gdb/python/py-cmd.c
+++ b/gdb/python/py-cmd.c
@@ -68,7 +68,8 @@ struct cmdpy_object
typedef struct cmdpy_object cmdpy_object;
-static PyTypeObject cmdpy_object_type;
+static PyTypeObject cmdpy_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("cmdpy_object");
/* Constants used by this module. */
static PyObject *invoke_cst;
diff --git a/gdb/python/py-continueevent.c b/gdb/python/py-continueevent.c
index 6412c01..c1f8f65 100644
--- a/gdb/python/py-continueevent.c
+++ b/gdb/python/py-continueevent.c
@@ -20,7 +20,8 @@
#include "defs.h"
#include "py-event.h"
-static PyTypeObject continue_event_object_type;
+static PyTypeObject continue_event_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
static PyObject *
create_continue_event_object (void)
diff --git a/gdb/python/py-event.h b/gdb/python/py-event.h
index 86da974..970595b 100644
--- a/gdb/python/py-event.h
+++ b/gdb/python/py-event.h
@@ -46,8 +46,9 @@
#define GDBPY_NEW_EVENT_TYPE(name, py_path, py_name, doc, base, qual) \
\
- qual PyTypeObject name##_event_object_type = \
- { \
+ qual PyTypeObject name##_event_object_type \
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object") \
+ = { \
PyVarObject_HEAD_INIT (NULL, 0) \
py_path, /* tp_name */ \
sizeof (event_object), /* tp_basicsize */ \
diff --git a/gdb/python/py-events.h b/gdb/python/py-events.h
index 537bcc9..4ec3832 100644
--- a/gdb/python/py-events.h
+++ b/gdb/python/py-events.h
@@ -24,7 +24,8 @@
#include "python-internal.h"
#include "inferior.h"
-extern PyTypeObject thread_event_object_type;
+extern PyTypeObject thread_event_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
/* Stores a list of objects to be notified when the event for which this
registry tracks occurs. */
diff --git a/gdb/python/py-evtregistry.c b/gdb/python/py-evtregistry.c
index 2e338cc..c8003af 100644
--- a/gdb/python/py-evtregistry.c
+++ b/gdb/python/py-evtregistry.c
@@ -23,7 +23,8 @@
events_object gdb_py_events;
-static PyTypeObject eventregistry_object_type;
+static PyTypeObject eventregistry_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("eventregistry_object");
/* Implementation of EventRegistry.connect () -> NULL.
Add FUNCTION to the list of listeners. */
diff --git a/gdb/python/py-exitedevent.c b/gdb/python/py-exitedevent.c
index 725518b..49c3100 100644
--- a/gdb/python/py-exitedevent.c
+++ b/gdb/python/py-exitedevent.c
@@ -20,7 +20,8 @@
#include "defs.h"
#include "py-event.h"
-static PyTypeObject exited_event_object_type;
+static PyTypeObject exited_event_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
static PyObject *
create_exited_event_object (const LONGEST *exit_code, struct inferior *inf)
diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c
index 6e095b5..b52bd7e 100644
--- a/gdb/python/py-finishbreakpoint.c
+++ b/gdb/python/py-finishbreakpoint.c
@@ -31,8 +31,6 @@
#include "inferior.h"
#include "block.h"
-static PyTypeObject finish_breakpoint_object_type;
-
/* Function that is called when a Python finish bp is found out of scope. */
static char * const outofscope_func = "out_of_scope";
@@ -55,6 +53,9 @@ struct finish_breakpoint_object
PyObject *return_value;
};
+static PyTypeObject finish_breakpoint_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("finish_breakpoint_object");
+
/* Python function to get the 'return_value' attribute of
FinishBreakpoint. */
diff --git a/gdb/python/py-function.c b/gdb/python/py-function.c
index bd25263..e2ba19f 100644
--- a/gdb/python/py-function.c
+++ b/gdb/python/py-function.c
@@ -29,7 +29,8 @@
#include "expression.h"
#include "language.h"
-static PyTypeObject fnpy_object_type;
+static PyTypeObject fnpy_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("PyObject");
\f
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index 9c84904..d4ff90b 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -51,7 +51,8 @@ typedef struct
int nthreads;
} inferior_object;
-static PyTypeObject inferior_object_type;
+static PyTypeObject inferior_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("inferior_object");
static const struct inferior_data *infpy_inf_data_key;
@@ -64,7 +65,8 @@ typedef struct {
CORE_ADDR length;
} membuf_object;
-static PyTypeObject membuf_object_type;
+static PyTypeObject membuf_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("membuf_object");
/* Require that INFERIOR be a valid inferior ID. */
#define INFPY_REQUIRE_VALID(Inferior) \
diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
index a5a083f..a0545ec 100644
--- a/gdb/python/py-infthread.c
+++ b/gdb/python/py-infthread.c
@@ -23,7 +23,8 @@
#include "inferior.h"
#include "python-internal.h"
-static PyTypeObject thread_object_type;
+static PyTypeObject thread_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("thread_object");
/* Require that INFERIOR be a valid inferior ID. */
#define THPY_REQUIRE_VALID(Thread) \
diff --git a/gdb/python/py-lazy-string.c b/gdb/python/py-lazy-string.c
index 6835067..df54cf4 100644
--- a/gdb/python/py-lazy-string.c
+++ b/gdb/python/py-lazy-string.c
@@ -47,7 +47,8 @@ typedef struct {
struct type *type;
} lazy_string_object;
-static PyTypeObject lazy_string_object_type;
+static PyTypeObject lazy_string_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("lazy_string_object");
static PyObject *
stpy_get_address (PyObject *self, void *closure)
diff --git a/gdb/python/py-newobjfileevent.c b/gdb/python/py-newobjfileevent.c
index 538e2d8..d781e92 100644
--- a/gdb/python/py-newobjfileevent.c
+++ b/gdb/python/py-newobjfileevent.c
@@ -20,7 +20,8 @@
#include "defs.h"
#include "py-event.h"
-static PyTypeObject new_objfile_event_object_type;
+static PyTypeObject new_objfile_event_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
static PyObject *
create_new_objfile_event_object (struct objfile *objfile)
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index db51f50..e5e5408 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -37,7 +37,8 @@ typedef struct
PyObject *type_printers;
} objfile_object;
-static PyTypeObject objfile_object_type;
+static PyTypeObject objfile_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("objfile_object");
static const struct objfile_data *objfpy_objfile_data_key;
diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c
index acb48cd..176bbc2 100644
--- a/gdb/python/py-param.c
+++ b/gdb/python/py-param.c
@@ -89,7 +89,8 @@ struct parmpy_object
typedef struct parmpy_object parmpy_object;
-static PyTypeObject parmpy_object_type;
+static PyTypeObject parmpy_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("parmpy_object");
/* Some handy string constants. */
static PyObject *set_doc_cst;
diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c
index 45a5193..fa9a193 100644
--- a/gdb/python/py-progspace.c
+++ b/gdb/python/py-progspace.c
@@ -39,7 +39,8 @@ typedef struct
PyObject *type_printers;
} pspace_object;
-static PyTypeObject pspace_object_type;
+static PyTypeObject pspace_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("pspace_object");
static const struct program_space_data *pspy_pspace_data_key;
diff --git a/gdb/python/py-signalevent.c b/gdb/python/py-signalevent.c
index 3d64936..1d723f0 100644
--- a/gdb/python/py-signalevent.c
+++ b/gdb/python/py-signalevent.c
@@ -20,7 +20,8 @@
#include "defs.h"
#include "py-stopevent.h"
-static PyTypeObject signal_event_object_type;
+static PyTypeObject signal_event_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
PyObject *
create_signal_event_object (enum gdb_signal stop_signal)
diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c
index 6fa8ecb..94c05be 100644
--- a/gdb/python/py-symtab.c
+++ b/gdb/python/py-symtab.c
@@ -37,7 +37,8 @@ typedef struct stpy_symtab_object {
struct stpy_symtab_object *next;
} symtab_object;
-static PyTypeObject symtab_object_type;
+static PyTypeObject symtab_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("symtab_object");
static const struct objfile_data *stpy_objfile_data_key;
/* Require a valid symbol table. All access to symtab_object->symtab
@@ -67,7 +68,8 @@ typedef struct salpy_sal_object {
struct salpy_sal_object *next;
} sal_object;
-static PyTypeObject sal_object_type;
+static PyTypeObject sal_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("sal_object");
static const struct objfile_data *salpy_objfile_data_key;
/* Require a valid symbol table and line object. All access to
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 051cff0..7cc89ca 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -44,7 +44,8 @@ typedef struct pyty_type_object
struct pyty_type_object *next;
} type_object;
-static PyTypeObject type_object_type;
+static PyTypeObject type_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("type_object");
/* A Field object. */
typedef struct pyty_field_object
@@ -55,7 +56,8 @@ typedef struct pyty_field_object
PyObject *dict;
} field_object;
-static PyTypeObject field_object_type;
+static PyTypeObject field_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("field_object");
/* A type iterator object. */
typedef struct {
@@ -68,7 +70,8 @@ typedef struct {
struct pyty_type_object *source;
} typy_iterator_object;
-static PyTypeObject type_iterator_object_type;
+static PyTypeObject type_iterator_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("typy_iterator_object");
/* This is used to initialize various gdb.TYPE_ constants. */
struct pyty_code
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index ea97226..802dd33 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -20,6 +20,13 @@
#ifndef GDB_PYTHON_INTERNAL_H
#define GDB_PYTHON_INTERNAL_H
+#ifdef WITH_CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF_ATTRIBUTE
+#define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG) \
+ __attribute__ ((cpychecker_type_object_for_typedef (ARG)))
+#else
+#define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG)
+#endif
+
#include <stdio.h>
/* Python 2.4 doesn't include stdint.h soon enough to get {u,}intptr_t
@@ -151,14 +158,21 @@ struct inferior;
extern PyObject *gdb_module;
extern PyObject *gdb_python_module;
-extern PyTypeObject value_object_type;
-extern PyTypeObject block_object_type;
-extern PyTypeObject symbol_object_type;
-extern PyTypeObject event_object_type;
+extern PyTypeObject value_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("value_object");
+extern PyTypeObject block_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF("block_object");
+extern PyTypeObject symbol_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("symbol_object");
+extern PyTypeObject event_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
extern PyTypeObject events_object_type;
-extern PyTypeObject stop_event_object_type;
-extern PyTypeObject breakpoint_object_type;
-extern PyTypeObject frame_object_type;
+extern PyTypeObject stop_event_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
+extern PyTypeObject breakpoint_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("breakpoint_object");
+extern PyTypeObject frame_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("frame_object");
typedef struct breakpoint_object
{
--
1.8.1.4
^ permalink raw reply [flat|nested] 66+ messages in thread* Re: [PATCH 01/28] introduce CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF and use it
2013-04-19 14:36 ` [PATCH 01/28] introduce CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF and use it Tom Tromey
@ 2013-05-15 15:57 ` Pedro Alves
2013-05-20 20:08 ` Tom Tromey
0 siblings, 1 reply; 66+ messages in thread
From: Pedro Alves @ 2013-05-15 15:57 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 04/19/2013 03:27 PM, Tom Tromey wrote:
> --- a/gdb/python/python-internal.h
> +++ b/gdb/python/python-internal.h
> @@ -20,6 +20,13 @@
> #ifndef GDB_PYTHON_INTERNAL_H
> #define GDB_PYTHON_INTERNAL_H
>
> +#ifdef WITH_CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF_ATTRIBUTE
> +#define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG) \
> + __attribute__ ((cpychecker_type_object_for_typedef (ARG)))
> +#else
> +#define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG)
> +#endif
Could we have a comment here with a short hint at what this is
all about? I assume from the patch that
WITH_CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF_ATTRIBUTE is defined
by cpychecker itself (not autoconf/config.h), but I can see
future readers getting confused.
Thanks,
--
Pedro Alves
^ permalink raw reply [flat|nested] 66+ messages in thread
* Re: [PATCH 01/28] introduce CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF and use it
2013-05-15 15:57 ` Pedro Alves
@ 2013-05-20 20:08 ` Tom Tromey
2013-05-21 0:20 ` Pedro Alves
0 siblings, 1 reply; 66+ messages in thread
From: Tom Tromey @ 2013-05-20 20:08 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches
>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
>> +#ifdef WITH_CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF_ATTRIBUTE
>> +#define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG) \
>> + __attribute__ ((cpychecker_type_object_for_typedef (ARG)))
Pedro> Could we have a comment here with a short hint at what this is
Pedro> all about? I assume from the patch that
Pedro> WITH_CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF_ATTRIBUTE is defined
Pedro> by cpychecker itself (not autoconf/config.h), but I can see
Pedro> future readers getting confused.
Sure thing.
Here is the patch I am checking in.
Tom
* python/py-arch.c (arch_object_type): Use
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-block.c (block_syms_iterator_object_type):
Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-bpevent.c (breakpoint_event_object_type):
Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-cmd.c (cmdpy_object_type): Use
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-continueevent.c (continue_event_object_type):
Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-event.h (GDBPY_NEW_EVENT_TYPE):
Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-events.h (thread_event_object_type):
Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-evtregistry.c (eventregistry_object_type): Use
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-exitedevent.c (exited_event_object_type):
Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-finishbreakpoint.c (finish_breakpoint_object_type):
Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-function.c (fnpy_object_type): Use
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-inferior.c (inferior_object_type, membuf_object_type):
Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-infthread.c (thread_object_type): Use
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-lazy-string.c (lazy_string_object_type):
Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-newobjfileevent.c (new_objfile_event_object_type):
Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-objfile.c (objfile_object_type): Use
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-param.c (parmpy_object_type):
Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-progspace.c (pspace_object_type):
Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-signalevent.c (signal_event_object_type):
Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-symtab.c (symtab_object_type, sal_object_type): Use
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-type.c (type_object_type, field_object_type)
(type_iterator_object_type): Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
* python/py-internal.h (CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF): New
define.
(value_object_type, block_object_type, symbol_object_type)
(event_object_type, stop_event_object_type, breakpoint_object_type)
(frame_object_type): Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
---
gdb/python/py-arch.c | 4 +++-
gdb/python/py-block.c | 3 ++-
gdb/python/py-bpevent.c | 3 ++-
gdb/python/py-cmd.c | 3 ++-
gdb/python/py-continueevent.c | 3 ++-
gdb/python/py-event.h | 5 +++--
gdb/python/py-events.h | 3 ++-
gdb/python/py-evtregistry.c | 3 ++-
gdb/python/py-exitedevent.c | 3 ++-
gdb/python/py-finishbreakpoint.c | 5 +++--
gdb/python/py-function.c | 3 ++-
gdb/python/py-inferior.c | 6 ++++--
gdb/python/py-infthread.c | 3 ++-
gdb/python/py-lazy-string.c | 3 ++-
gdb/python/py-newobjfileevent.c | 3 ++-
gdb/python/py-objfile.c | 3 ++-
gdb/python/py-param.c | 3 ++-
gdb/python/py-progspace.c | 3 ++-
gdb/python/py-signalevent.c | 3 ++-
gdb/python/py-symtab.c | 6 ++++--
gdb/python/py-type.c | 9 ++++++---
gdb/python/python-internal.h | 34 +++++++++++++++++++++++++++-------
22 files changed, 80 insertions(+), 34 deletions(-)
diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c
index ddfebdb..7eb6eea 100644
--- a/gdb/python/py-arch.c
+++ b/gdb/python/py-arch.c
@@ -29,7 +29,9 @@ typedef struct arch_object_type_object {
} arch_object;
static struct gdbarch_data *arch_object_data = NULL;
-static PyTypeObject arch_object_type;
+
+static PyTypeObject arch_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("arch_object");
/* Associates an arch_object with GDBARCH as gdbarch_data via the gdbarch
post init registration mechanism (gdbarch_data_register_post_init). */
diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c
index f0b8322..afc8959 100644
--- a/gdb/python/py-block.c
+++ b/gdb/python/py-block.c
@@ -78,7 +78,8 @@ typedef struct {
} \
} while (0)
-static PyTypeObject block_syms_iterator_object_type;
+static PyTypeObject block_syms_iterator_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("block_syms_iterator_object");
static const struct objfile_data *blpy_objfile_data_key;
static PyObject *
diff --git a/gdb/python/py-bpevent.c b/gdb/python/py-bpevent.c
index dad93dc..5238ad8 100644
--- a/gdb/python/py-bpevent.c
+++ b/gdb/python/py-bpevent.c
@@ -20,7 +20,8 @@
#include "defs.h"
#include "py-stopevent.h"
-static PyTypeObject breakpoint_event_object_type;
+static PyTypeObject breakpoint_event_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
/* Create and initialize a BreakpointEvent object. This acquires new
references to BREAKPOINT_LIST and FIRST_BP. */
diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
index 161b4bc..3da9960 100644
--- a/gdb/python/py-cmd.c
+++ b/gdb/python/py-cmd.c
@@ -68,7 +68,8 @@ struct cmdpy_object
typedef struct cmdpy_object cmdpy_object;
-static PyTypeObject cmdpy_object_type;
+static PyTypeObject cmdpy_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("cmdpy_object");
/* Constants used by this module. */
static PyObject *invoke_cst;
diff --git a/gdb/python/py-continueevent.c b/gdb/python/py-continueevent.c
index 6412c01..c1f8f65 100644
--- a/gdb/python/py-continueevent.c
+++ b/gdb/python/py-continueevent.c
@@ -20,7 +20,8 @@
#include "defs.h"
#include "py-event.h"
-static PyTypeObject continue_event_object_type;
+static PyTypeObject continue_event_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
static PyObject *
create_continue_event_object (void)
diff --git a/gdb/python/py-event.h b/gdb/python/py-event.h
index 86da974..970595b 100644
--- a/gdb/python/py-event.h
+++ b/gdb/python/py-event.h
@@ -46,8 +46,9 @@
#define GDBPY_NEW_EVENT_TYPE(name, py_path, py_name, doc, base, qual) \
\
- qual PyTypeObject name##_event_object_type = \
- { \
+ qual PyTypeObject name##_event_object_type \
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object") \
+ = { \
PyVarObject_HEAD_INIT (NULL, 0) \
py_path, /* tp_name */ \
sizeof (event_object), /* tp_basicsize */ \
diff --git a/gdb/python/py-events.h b/gdb/python/py-events.h
index 537bcc9..4ec3832 100644
--- a/gdb/python/py-events.h
+++ b/gdb/python/py-events.h
@@ -24,7 +24,8 @@
#include "python-internal.h"
#include "inferior.h"
-extern PyTypeObject thread_event_object_type;
+extern PyTypeObject thread_event_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
/* Stores a list of objects to be notified when the event for which this
registry tracks occurs. */
diff --git a/gdb/python/py-evtregistry.c b/gdb/python/py-evtregistry.c
index 2e338cc..c8003af 100644
--- a/gdb/python/py-evtregistry.c
+++ b/gdb/python/py-evtregistry.c
@@ -23,7 +23,8 @@
events_object gdb_py_events;
-static PyTypeObject eventregistry_object_type;
+static PyTypeObject eventregistry_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("eventregistry_object");
/* Implementation of EventRegistry.connect () -> NULL.
Add FUNCTION to the list of listeners. */
diff --git a/gdb/python/py-exitedevent.c b/gdb/python/py-exitedevent.c
index 725518b..49c3100 100644
--- a/gdb/python/py-exitedevent.c
+++ b/gdb/python/py-exitedevent.c
@@ -20,7 +20,8 @@
#include "defs.h"
#include "py-event.h"
-static PyTypeObject exited_event_object_type;
+static PyTypeObject exited_event_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
static PyObject *
create_exited_event_object (const LONGEST *exit_code, struct inferior *inf)
diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c
index 6e095b5..b52bd7e 100644
--- a/gdb/python/py-finishbreakpoint.c
+++ b/gdb/python/py-finishbreakpoint.c
@@ -31,8 +31,6 @@
#include "inferior.h"
#include "block.h"
-static PyTypeObject finish_breakpoint_object_type;
-
/* Function that is called when a Python finish bp is found out of scope. */
static char * const outofscope_func = "out_of_scope";
@@ -55,6 +53,9 @@ struct finish_breakpoint_object
PyObject *return_value;
};
+static PyTypeObject finish_breakpoint_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("finish_breakpoint_object");
+
/* Python function to get the 'return_value' attribute of
FinishBreakpoint. */
diff --git a/gdb/python/py-function.c b/gdb/python/py-function.c
index bd25263..e2ba19f 100644
--- a/gdb/python/py-function.c
+++ b/gdb/python/py-function.c
@@ -29,7 +29,8 @@
#include "expression.h"
#include "language.h"
-static PyTypeObject fnpy_object_type;
+static PyTypeObject fnpy_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("PyObject");
\f
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index cee3a0d..d35d09a 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -51,7 +51,8 @@ typedef struct
int nthreads;
} inferior_object;
-static PyTypeObject inferior_object_type;
+static PyTypeObject inferior_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("inferior_object");
static const struct inferior_data *infpy_inf_data_key;
@@ -64,7 +65,8 @@ typedef struct {
CORE_ADDR length;
} membuf_object;
-static PyTypeObject membuf_object_type;
+static PyTypeObject membuf_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("membuf_object");
/* Require that INFERIOR be a valid inferior ID. */
#define INFPY_REQUIRE_VALID(Inferior) \
diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
index a5a083f..a0545ec 100644
--- a/gdb/python/py-infthread.c
+++ b/gdb/python/py-infthread.c
@@ -23,7 +23,8 @@
#include "inferior.h"
#include "python-internal.h"
-static PyTypeObject thread_object_type;
+static PyTypeObject thread_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("thread_object");
/* Require that INFERIOR be a valid inferior ID. */
#define THPY_REQUIRE_VALID(Thread) \
diff --git a/gdb/python/py-lazy-string.c b/gdb/python/py-lazy-string.c
index 6835067..df54cf4 100644
--- a/gdb/python/py-lazy-string.c
+++ b/gdb/python/py-lazy-string.c
@@ -47,7 +47,8 @@ typedef struct {
struct type *type;
} lazy_string_object;
-static PyTypeObject lazy_string_object_type;
+static PyTypeObject lazy_string_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("lazy_string_object");
static PyObject *
stpy_get_address (PyObject *self, void *closure)
diff --git a/gdb/python/py-newobjfileevent.c b/gdb/python/py-newobjfileevent.c
index 538e2d8..d781e92 100644
--- a/gdb/python/py-newobjfileevent.c
+++ b/gdb/python/py-newobjfileevent.c
@@ -20,7 +20,8 @@
#include "defs.h"
#include "py-event.h"
-static PyTypeObject new_objfile_event_object_type;
+static PyTypeObject new_objfile_event_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
static PyObject *
create_new_objfile_event_object (struct objfile *objfile)
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index 6fa3035..27f3463 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -39,7 +39,8 @@ typedef struct
PyObject *type_printers;
} objfile_object;
-static PyTypeObject objfile_object_type;
+static PyTypeObject objfile_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("objfile_object");
static const struct objfile_data *objfpy_objfile_data_key;
diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c
index acb48cd..176bbc2 100644
--- a/gdb/python/py-param.c
+++ b/gdb/python/py-param.c
@@ -89,7 +89,8 @@ struct parmpy_object
typedef struct parmpy_object parmpy_object;
-static PyTypeObject parmpy_object_type;
+static PyTypeObject parmpy_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("parmpy_object");
/* Some handy string constants. */
static PyObject *set_doc_cst;
diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c
index 104b36d..5d4911a 100644
--- a/gdb/python/py-progspace.c
+++ b/gdb/python/py-progspace.c
@@ -41,7 +41,8 @@ typedef struct
PyObject *type_printers;
} pspace_object;
-static PyTypeObject pspace_object_type;
+static PyTypeObject pspace_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("pspace_object");
static const struct program_space_data *pspy_pspace_data_key;
diff --git a/gdb/python/py-signalevent.c b/gdb/python/py-signalevent.c
index 3d64936..1d723f0 100644
--- a/gdb/python/py-signalevent.c
+++ b/gdb/python/py-signalevent.c
@@ -20,7 +20,8 @@
#include "defs.h"
#include "py-stopevent.h"
-static PyTypeObject signal_event_object_type;
+static PyTypeObject signal_event_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
PyObject *
create_signal_event_object (enum gdb_signal stop_signal)
diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c
index 6fa8ecb..94c05be 100644
--- a/gdb/python/py-symtab.c
+++ b/gdb/python/py-symtab.c
@@ -37,7 +37,8 @@ typedef struct stpy_symtab_object {
struct stpy_symtab_object *next;
} symtab_object;
-static PyTypeObject symtab_object_type;
+static PyTypeObject symtab_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("symtab_object");
static const struct objfile_data *stpy_objfile_data_key;
/* Require a valid symbol table. All access to symtab_object->symtab
@@ -67,7 +68,8 @@ typedef struct salpy_sal_object {
struct salpy_sal_object *next;
} sal_object;
-static PyTypeObject sal_object_type;
+static PyTypeObject sal_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("sal_object");
static const struct objfile_data *salpy_objfile_data_key;
/* Require a valid symbol table and line object. All access to
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 051cff0..7cc89ca 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -44,7 +44,8 @@ typedef struct pyty_type_object
struct pyty_type_object *next;
} type_object;
-static PyTypeObject type_object_type;
+static PyTypeObject type_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("type_object");
/* A Field object. */
typedef struct pyty_field_object
@@ -55,7 +56,8 @@ typedef struct pyty_field_object
PyObject *dict;
} field_object;
-static PyTypeObject field_object_type;
+static PyTypeObject field_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("field_object");
/* A type iterator object. */
typedef struct {
@@ -68,7 +70,8 @@ typedef struct {
struct pyty_type_object *source;
} typy_iterator_object;
-static PyTypeObject type_iterator_object_type;
+static PyTypeObject type_iterator_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("typy_iterator_object");
/* This is used to initialize various gdb.TYPE_ constants. */
struct pyty_code
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 7337bff..b6a2e76 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -20,6 +20,19 @@
#ifndef GDB_PYTHON_INTERNAL_H
#define GDB_PYTHON_INTERNAL_H
+/* These WITH_* macros are defined by the CPython API checker that
+ comes with the Python plugin for GCC. See:
+ https://gcc-python-plugin.readthedocs.org/en/latest/cpychecker.html
+ The checker defines a WITH_ macro for each attribute it
+ exposes. */
+
+#ifdef WITH_CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF_ATTRIBUTE
+#define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG) \
+ __attribute__ ((cpychecker_type_object_for_typedef (ARG)))
+#else
+#define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG)
+#endif
+
#include <stdio.h>
/* Python 2.4 doesn't include stdint.h soon enough to get {u,}intptr_t
@@ -151,14 +164,21 @@ struct inferior;
extern PyObject *gdb_module;
extern PyObject *gdb_python_module;
-extern PyTypeObject value_object_type;
-extern PyTypeObject block_object_type;
-extern PyTypeObject symbol_object_type;
-extern PyTypeObject event_object_type;
+extern PyTypeObject value_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("value_object");
+extern PyTypeObject block_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF("block_object");
+extern PyTypeObject symbol_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("symbol_object");
+extern PyTypeObject event_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
extern PyTypeObject events_object_type;
-extern PyTypeObject stop_event_object_type;
-extern PyTypeObject breakpoint_object_type;
-extern PyTypeObject frame_object_type;
+extern PyTypeObject stop_event_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
+extern PyTypeObject breakpoint_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("breakpoint_object");
+extern PyTypeObject frame_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("frame_object");
typedef struct breakpoint_object
{
--
1.8.1.4
^ permalink raw reply [flat|nested] 66+ messages in thread* Re: [PATCH 01/28] introduce CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF and use it
2013-05-20 20:08 ` Tom Tromey
@ 2013-05-21 0:20 ` Pedro Alves
0 siblings, 0 replies; 66+ messages in thread
From: Pedro Alves @ 2013-05-21 0:20 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 05/20/2013 09:08 PM, Tom Tromey wrote:
>>>>>> >>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
>>> >> +#ifdef WITH_CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF_ATTRIBUTE
>>> >> +#define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG) \
>>> >> + __attribute__ ((cpychecker_type_object_for_typedef (ARG)))
> Pedro> Could we have a comment here with a short hint at what this is
> Pedro> all about? I assume from the patch that
> Pedro> WITH_CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF_ATTRIBUTE is defined
> Pedro> by cpychecker itself (not autoconf/config.h), but I can see
> Pedro> future readers getting confused.
>
> Sure thing.
> Here is the patch I am checking in.
...
> --- a/gdb/python/python-internal.h
> +++ b/gdb/python/python-internal.h
> @@ -20,6 +20,19 @@
> #ifndef GDB_PYTHON_INTERNAL_H
> #define GDB_PYTHON_INTERNAL_H
>
> +/* These WITH_* macros are defined by the CPython API checker that
> + comes with the Python plugin for GCC. See:
> + https://gcc-python-plugin.readthedocs.org/en/latest/cpychecker.html
> + The checker defines a WITH_ macro for each attribute it
> + exposes. */
> +
> +#ifdef WITH_CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF_ATTRIBUTE
> +#define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG) \
> + __attribute__ ((cpychecker_type_object_for_typedef (ARG)))
> +#else
> +#define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG)
> +#endif
> +
That's perfect. Thanks!
--
--
Pedro Alves
^ permalink raw reply [flat|nested] 66+ messages in thread
* [PATCH 03/28] PyObject_GetAttrString returns a new ref
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
` (3 preceding siblings ...)
2013-04-19 14:36 ` [PATCH 01/28] introduce CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF and use it Tom Tromey
@ 2013-04-19 14:36 ` Tom Tromey
2013-04-19 14:37 ` [PATCH 04/28] add missing decref in before_prompt_hook Tom Tromey
` (25 subsequent siblings)
30 siblings, 0 replies; 66+ messages in thread
From: Tom Tromey @ 2013-04-19 14:36 UTC (permalink / raw)
To: gdb-patches
This fixes a bug in py-function.c pointed out by the checker.
PyObject_GetAttrString returns a new ref, so we must decref it.
---
gdb/python/py-function.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/gdb/python/py-function.c b/gdb/python/py-function.c
index e2ba19f..395eeda 100644
--- a/gdb/python/py-function.c
+++ b/gdb/python/py-function.c
@@ -175,14 +175,20 @@ fnpy_init (PyObject *self, PyObject *args, PyObject *kwds)
if (PyObject_HasAttrString (self, "__doc__"))
{
PyObject *ds_obj = PyObject_GetAttrString (self, "__doc__");
- if (ds_obj && gdbpy_is_string (ds_obj))
+ if (ds_obj != NULL)
{
- docstring = python_string_to_host_string (ds_obj);
- if (docstring == NULL)
+ if (gdbpy_is_string (ds_obj))
{
- Py_DECREF (self);
- return -1;
+ docstring = python_string_to_host_string (ds_obj);
+ if (docstring == NULL)
+ {
+ Py_DECREF (self);
+ Py_DECREF (ds_obj);
+ return -1;
+ }
}
+
+ Py_DECREF (ds_obj);
}
}
if (! docstring)
--
1.8.1.4
^ permalink raw reply [flat|nested] 66+ messages in thread* [PATCH 04/28] add missing decref in before_prompt_hook
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
` (4 preceding siblings ...)
2013-04-19 14:36 ` [PATCH 03/28] PyObject_GetAttrString returns a new ref Tom Tromey
@ 2013-04-19 14:37 ` Tom Tromey
2013-04-19 14:38 ` [PATCH 06/28] fix py-evtregistry.c refcount bug Tom Tromey
` (24 subsequent siblings)
30 siblings, 0 replies; 66+ messages in thread
From: Tom Tromey @ 2013-04-19 14:37 UTC (permalink / raw)
To: gdb-patches
The checker noticed a missing decref in before_prompt_hook.
* python/python.c (before_prompt_hook): Add cleanup to
decref 'hook'.
---
gdb/python/python.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 67d06e5..5ef9e0a 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -900,6 +900,8 @@ before_prompt_hook (const char *current_gdb_prompt)
if (hook == NULL)
goto fail;
+ make_cleanup_py_decref (hook);
+
if (PyCallable_Check (hook))
{
PyObject *result;
--
1.8.1.4
^ permalink raw reply [flat|nested] 66+ messages in thread* [PATCH 06/28] fix py-evtregistry.c refcount bug
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
` (5 preceding siblings ...)
2013-04-19 14:37 ` [PATCH 04/28] add missing decref in before_prompt_hook Tom Tromey
@ 2013-04-19 14:38 ` Tom Tromey
2013-04-23 0:23 ` Tom Tromey
2013-04-19 14:38 ` [PATCH 05/28] py-cmd.c error-checking bug fix Tom Tromey
` (23 subsequent siblings)
30 siblings, 1 reply; 66+ messages in thread
From: Tom Tromey @ 2013-04-19 14:38 UTC (permalink / raw)
To: gdb-patches
The checker found a refcounting bug in py-evtregistry.c.
This fixes it. It also adds CPYCHECKER_STEALS_REFERENCE_TO_ARG.
I think I meant to split this patch and forgot, sorry about that.
* py-evtregistry.c (create_event_object): Decref
eventregistry_object if PyList_New fails.
* python/py-event.h (evpy_emit_event): Use
CPYCHECKER_STEALS_REFERENCE_TO_ARG.
* python/python-internal.h (CPYCHECKER_STEALS_REFERENCE_TO_ARG):
New macro.
---
gdb/python/py-event.h | 3 ++-
gdb/python/py-evtregistry.c | 5 ++++-
gdb/python/python-internal.h | 7 +++++++
3 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/gdb/python/py-event.h b/gdb/python/py-event.h
index 970595b..1db8bd2 100644
--- a/gdb/python/py-event.h
+++ b/gdb/python/py-event.h
@@ -106,7 +106,8 @@ extern int emit_continue_event (ptid_t ptid);
extern int emit_exited_event (const LONGEST *exit_code, struct inferior *inf);
extern int evpy_emit_event (PyObject *event,
- eventregistry_object *registry);
+ eventregistry_object *registry)
+ CPYCHECKER_STEALS_REFERENCE_TO_ARG (1);
extern PyObject *create_event_object (PyTypeObject *py_type);
extern PyObject *create_thread_event_object (PyTypeObject *py_type);
diff --git a/gdb/python/py-evtregistry.c b/gdb/python/py-evtregistry.c
index c8003af..05c8586 100644
--- a/gdb/python/py-evtregistry.c
+++ b/gdb/python/py-evtregistry.c
@@ -89,7 +89,10 @@ create_eventregistry_object (void)
eventregistry_obj->callbacks = PyList_New (0);
if (!eventregistry_obj->callbacks)
- return NULL;
+ {
+ Py_DECREF (eventregistry_obj);
+ return NULL;
+ }
return eventregistry_obj;
}
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 394a148..5fbb472 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -34,6 +34,13 @@
#define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG)
#endif
+#ifdef WITH_CPYCHECKER_STEALS_REFERENCE_TO_ARG_ATTRIBUTE
+#define CPYCHECKER_STEALS_REFERENCE_TO_ARG(n) \
+ __attribute__ ((cpychecker_steals_reference_to_arg (n)))
+#else
+#define CPYCHECKER_STEALS_REFERENCE_TO_ARG(n)
+#endif
+
#include <stdio.h>
/* Python 2.4 doesn't include stdint.h soon enough to get {u,}intptr_t
--
1.8.1.4
^ permalink raw reply [flat|nested] 66+ messages in thread* Re: [PATCH 06/28] fix py-evtregistry.c refcount bug
2013-04-19 14:38 ` [PATCH 06/28] fix py-evtregistry.c refcount bug Tom Tromey
@ 2013-04-23 0:23 ` Tom Tromey
0 siblings, 0 replies; 66+ messages in thread
From: Tom Tromey @ 2013-04-23 0:23 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 294 bytes --]
>>>>> "Tom" == Tom Tromey <tromey@redhat.com> writes:
Tom> The checker found a refcounting bug in py-evtregistry.c.
Tom> This fixes it. It also adds CPYCHECKER_STEALS_REFERENCE_TO_ARG.
Tom> I think I meant to split this patch and forgot, sorry about that.
I went ahead and split this.
Tom
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: fix py-evtregistry.c refcount bug --]
[-- Type: text/x-patch, Size: 897 bytes --]
From c2dee2f4e0c0665fe308e596969d5bb3076fdc09 Mon Sep 17 00:00:00 2001
From: Tom Tromey <tromey@redhat.com>
Date: Mon, 22 Apr 2013 12:23:19 -0600
Subject: [PATCH 07/33] fix py-evtregistry.c refcount bug
The checker found a refcounting bug in py-evtregistry.c.
* py-evtregistry.c (create_event_object): Decref
eventregistry_object if PyList_New fails.
---
gdb/python/py-evtregistry.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/gdb/python/py-evtregistry.c b/gdb/python/py-evtregistry.c
index c8003af..05c8586 100644
--- a/gdb/python/py-evtregistry.c
+++ b/gdb/python/py-evtregistry.c
@@ -89,7 +89,10 @@ create_eventregistry_object (void)
eventregistry_obj->callbacks = PyList_New (0);
if (!eventregistry_obj->callbacks)
- return NULL;
+ {
+ Py_DECREF (eventregistry_obj);
+ return NULL;
+ }
return eventregistry_obj;
}
--
1.8.1.4
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: add CPYCHECKER_STEALS_REFERENCE_TO_ARG --]
[-- Type: text/x-patch, Size: 1958 bytes --]
From 8091b73a70c56a7be474c23efa2a8ab598a7b186 Mon Sep 17 00:00:00 2001
From: Tom Tromey <tromey@redhat.com>
Date: Mon, 22 Apr 2013 12:23:48 -0600
Subject: [PATCH 08/33] add CPYCHECKER_STEALS_REFERENCE_TO_ARG
The checker provides an attribute that can be used to indicate that a
function steals a reference to an argument. This patch adds a macro
for this attribute to gdb and changes one spot to use it.
* python/py-event.h (evpy_emit_event): Use
CPYCHECKER_STEALS_REFERENCE_TO_ARG.
* python/python-internal.h (CPYCHECKER_STEALS_REFERENCE_TO_ARG):
New macro.
---
gdb/python/py-event.h | 3 ++-
gdb/python/python-internal.h | 7 +++++++
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/gdb/python/py-event.h b/gdb/python/py-event.h
index 970595b..1db8bd2 100644
--- a/gdb/python/py-event.h
+++ b/gdb/python/py-event.h
@@ -106,7 +106,8 @@ extern int emit_continue_event (ptid_t ptid);
extern int emit_exited_event (const LONGEST *exit_code, struct inferior *inf);
extern int evpy_emit_event (PyObject *event,
- eventregistry_object *registry);
+ eventregistry_object *registry)
+ CPYCHECKER_STEALS_REFERENCE_TO_ARG (1);
extern PyObject *create_event_object (PyTypeObject *py_type);
extern PyObject *create_thread_event_object (PyTypeObject *py_type);
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 394a148..5fbb472 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -34,6 +34,13 @@
#define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG)
#endif
+#ifdef WITH_CPYCHECKER_STEALS_REFERENCE_TO_ARG_ATTRIBUTE
+#define CPYCHECKER_STEALS_REFERENCE_TO_ARG(n) \
+ __attribute__ ((cpychecker_steals_reference_to_arg (n)))
+#else
+#define CPYCHECKER_STEALS_REFERENCE_TO_ARG(n)
+#endif
+
#include <stdio.h>
/* Python 2.4 doesn't include stdint.h soon enough to get {u,}intptr_t
--
1.8.1.4
^ permalink raw reply [flat|nested] 66+ messages in thread
* [PATCH 05/28] py-cmd.c error-checking bug fix
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
` (6 preceding siblings ...)
2013-04-19 14:38 ` [PATCH 06/28] fix py-evtregistry.c refcount bug Tom Tromey
@ 2013-04-19 14:38 ` Tom Tromey
2013-05-15 16:01 ` Pedro Alves
2013-04-19 14:39 ` [PATCH 07/28] remove unused declaration Tom Tromey
` (22 subsequent siblings)
30 siblings, 1 reply; 66+ messages in thread
From: Tom Tromey @ 2013-04-19 14:38 UTC (permalink / raw)
To: gdb-patches
The checker found an error-checking bug in py-cmd.c.
This fixes it.
* py-cmd.c (gdbpy_string_to_argv): Check result of
PyList_New.
---
gdb/python/py-cmd.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
index 3da9960..ca9e415 100644
--- a/gdb/python/py-cmd.c
+++ b/gdb/python/py-cmd.c
@@ -668,6 +668,8 @@ gdbpy_string_to_argv (PyObject *self, PyObject *args)
return NULL;
py_argv = PyList_New (0);
+ if (py_argv == NULL)
+ return NULL;
/* buildargv uses NULL to represent an empty argument list, but we can't use
that in Python. Instead, if ARGS is "" then return an empty list.
--
1.8.1.4
^ permalink raw reply [flat|nested] 66+ messages in thread* Re: [PATCH 05/28] py-cmd.c error-checking bug fix
2013-04-19 14:38 ` [PATCH 05/28] py-cmd.c error-checking bug fix Tom Tromey
@ 2013-05-15 16:01 ` Pedro Alves
2013-05-15 16:20 ` Tom Tromey
0 siblings, 1 reply; 66+ messages in thread
From: Pedro Alves @ 2013-05-15 16:01 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 04/19/2013 03:29 PM, Tom Tromey wrote:
> diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
> index 3da9960..ca9e415 100644
> --- a/gdb/python/py-cmd.c
> +++ b/gdb/python/py-cmd.c
> @@ -668,6 +668,8 @@ gdbpy_string_to_argv (PyObject *self, PyObject *args)
> return NULL;
>
> py_argv = PyList_New (0);
> + if (py_argv == NULL)
> + return NULL;
>
Shouldn't this be 'malloc_failure (0)' instead of returning NULL?
--
Pedro Alves
^ permalink raw reply [flat|nested] 66+ messages in thread
* Re: [PATCH 05/28] py-cmd.c error-checking bug fix
2013-05-15 16:01 ` Pedro Alves
@ 2013-05-15 16:20 ` Tom Tromey
2013-05-15 16:29 ` Pedro Alves
0 siblings, 1 reply; 66+ messages in thread
From: Tom Tromey @ 2013-05-15 16:20 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches
>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
Pedro> On 04/19/2013 03:29 PM, Tom Tromey wrote:
>> diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
>> index 3da9960..ca9e415 100644
>> --- a/gdb/python/py-cmd.c
>> +++ b/gdb/python/py-cmd.c
>> @@ -668,6 +668,8 @@ gdbpy_string_to_argv (PyObject *self, PyObject *args)
>> return NULL;
>>
>> py_argv = PyList_New (0);
>> + if (py_argv == NULL)
>> + return NULL;
>>
Pedro> Shouldn't this be 'malloc_failure (0)' instead of returning NULL?
In the Python layer we follow Python conventions for error handling.
Here, PyList_New failed and set the Python exception.
We just propagate that to our caller.
Tom
^ permalink raw reply [flat|nested] 66+ messages in thread
* Re: [PATCH 05/28] py-cmd.c error-checking bug fix
2013-05-15 16:20 ` Tom Tromey
@ 2013-05-15 16:29 ` Pedro Alves
0 siblings, 0 replies; 66+ messages in thread
From: Pedro Alves @ 2013-05-15 16:29 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 05/15/2013 05:20 PM, Tom Tromey wrote:
> Pedro> Shouldn't this be 'malloc_failure (0)' instead of returning NULL?
>
> In the Python layer we follow Python conventions for error handling.
> Here, PyList_New failed and set the Python exception.
> We just propagate that to our caller.
I see. Thanks for the explanation.
--
Pedro Alves
^ permalink raw reply [flat|nested] 66+ messages in thread
* [PATCH 07/28] remove unused declaration
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
` (7 preceding siblings ...)
2013-04-19 14:38 ` [PATCH 05/28] py-cmd.c error-checking bug fix Tom Tromey
@ 2013-04-19 14:39 ` Tom Tromey
2013-04-19 14:40 ` [PATCH 08/28] use CPYCHECKER_SETS_EXCEPTION Tom Tromey
` (21 subsequent siblings)
30 siblings, 0 replies; 66+ messages in thread
From: Tom Tromey @ 2013-04-19 14:39 UTC (permalink / raw)
To: gdb-patches
I happened to notice that we declare but do not define
events_object_type. This removes it.
* python/python-internal.h (events_object_type): Remove.
---
gdb/python/python-internal.h | 1 -
1 file changed, 1 deletion(-)
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 5fbb472..8eb1774 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -180,7 +180,6 @@ extern PyTypeObject symbol_object_type
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("symbol_object");
extern PyTypeObject event_object_type
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
-extern PyTypeObject events_object_type;
extern PyTypeObject stop_event_object_type
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
extern PyTypeObject breakpoint_object_type
--
1.8.1.4
^ permalink raw reply [flat|nested] 66+ messages in thread* [PATCH 08/28] use CPYCHECKER_SETS_EXCEPTION
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
` (8 preceding siblings ...)
2013-04-19 14:39 ` [PATCH 07/28] remove unused declaration Tom Tromey
@ 2013-04-19 14:40 ` Tom Tromey
2013-04-19 14:41 ` [PATCH 09/28] introduce and use CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION Tom Tromey
` (20 subsequent siblings)
30 siblings, 0 replies; 66+ messages in thread
From: Tom Tromey @ 2013-04-19 14:40 UTC (permalink / raw)
To: gdb-patches
The checker defines an attribute that can be used to indicate that a
function sets the Python exception.
This patch introduces a new macro for this attribute and changes gdb
to use it. I also changed gdbpy_convert_exception to return 'void'.
This is friendlier to the checker, which didn't recognize our current
convention; but also turns out to clean up the code a little.
* python/py-arch.c (archpy_disassemble): Update.
* python/py-type.c (typy_get_composite, typy_lookup_typename)
(typy_lookup_type): Use GDB_PY_HANDLE_EXCEPTION.
* python/py-utils.c (gdbpy_convert_exception): Return 'void'.
* python/python-internal.h (CPYCHECKER_SETS_EXCEPTION): New
macro.
(GDB_PY_HANDLE_EXCEPTION): Update.
(gdbpy_convert_exception): Update. Use CPYCHECKER_SETS_EXCEPTION.
---
gdb/python/py-arch.c | 3 ++-
gdb/python/py-type.c | 20 +++-----------------
gdb/python/py-utils.c | 6 +++---
gdb/python/python-internal.h | 22 ++++++++++++++++------
4 files changed, 24 insertions(+), 27 deletions(-)
diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c
index 7eb6eea..146a642 100644
--- a/gdb/python/py-arch.c
+++ b/gdb/python/py-arch.c
@@ -200,7 +200,8 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
Py_DECREF (result_list);
ui_file_delete (memfile);
- return gdbpy_convert_exception (except);
+ gdbpy_convert_exception (except);
+ return NULL;
}
as = ui_file_xstrdup (memfile, NULL);
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 7cc89ca..b289a89 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -443,13 +443,7 @@ typy_get_composite (struct type *type)
{
CHECK_TYPEDEF (type);
}
- /* Don't use GDB_PY_HANDLE_EXCEPTION here because that returns
- a (NULL) pointer of the wrong type. */
- if (except.reason < 0)
- {
- gdbpy_convert_exception (except);
- return NULL;
- }
+ GDB_PY_HANDLE_EXCEPTION (except);
if (TYPE_CODE (type) != TYPE_CODE_PTR
&& TYPE_CODE (type) != TYPE_CODE_REF)
@@ -732,11 +726,7 @@ typy_lookup_typename (const char *type_name, const struct block *block)
type = lookup_typename (python_language, python_gdbarch,
type_name, block, 0);
}
- if (except.reason < 0)
- {
- gdbpy_convert_exception (except);
- return NULL;
- }
+ GDB_PY_HANDLE_EXCEPTION (except);
return type;
}
@@ -785,11 +775,7 @@ typy_lookup_type (struct demangle_component *demangled,
break;
}
}
- if (except.reason < 0)
- {
- gdbpy_convert_exception (except);
- return NULL;
- }
+ GDB_PY_HANDLE_EXCEPTION (except);
}
/* If we have a type from the switch statement above, just return
diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
index b280c8c..4cd35a0 100644
--- a/gdb/python/py-utils.c
+++ b/gdb/python/py-utils.c
@@ -272,9 +272,9 @@ gdbpy_exception_to_string (PyObject *ptype, PyObject *pvalue)
/* Convert a GDB exception to the appropriate Python exception.
- This sets the Python error indicator, and returns NULL. */
+ This sets the Python error indicator. */
-PyObject *
+void
gdbpy_convert_exception (struct gdb_exception exception)
{
PyObject *exc_class;
@@ -286,7 +286,7 @@ gdbpy_convert_exception (struct gdb_exception exception)
else
exc_class = gdbpy_gdb_error;
- return PyErr_Format (exc_class, "%s", exception.message);
+ PyErr_Format (exc_class, "%s", exception.message);
}
/* Converts OBJ to a CORE_ADDR value.
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 8eb1774..57fcc74 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -41,6 +41,12 @@
#define CPYCHECKER_STEALS_REFERENCE_TO_ARG(n)
#endif
+#ifdef WITH_CPYCHECKER_SETS_EXCEPTION_ATTRIBUTE
+#define CPYCHECKER_SETS_EXCEPTION __attribute__ ((cpychecker_sets_exception))
+#else
+#define CPYCHECKER_SETS_EXCEPTION
+#endif
+
#include <stdio.h>
/* Python 2.4 doesn't include stdint.h soon enough to get {u,}intptr_t
@@ -343,11 +349,14 @@ extern const struct language_defn *python_language;
/* Use this after a TRY_EXCEPT to throw the appropriate Python
exception. */
-#define GDB_PY_HANDLE_EXCEPTION(Exception) \
- do { \
- if (Exception.reason < 0) \
- return gdbpy_convert_exception (Exception); \
- } while (0)
+#define GDB_PY_HANDLE_EXCEPTION(Exception) \
+ do { \
+ if (Exception.reason < 0) \
+ { \
+ gdbpy_convert_exception (Exception); \
+ return NULL; \
+ } \
+ } while (0)
/* Use this after a TRY_EXCEPT to throw the appropriate Python
exception. This macro is for use inside setter functions. */
@@ -405,7 +414,8 @@ extern PyObject *gdbpy_gdb_error;
extern PyObject *gdbpy_gdb_memory_error;
extern PyObject *gdbpy_gdberror_exc;
-extern PyObject *gdbpy_convert_exception (struct gdb_exception);
+extern void gdbpy_convert_exception (struct gdb_exception)
+ CPYCHECKER_SETS_EXCEPTION;
int get_addr_from_python (PyObject *obj, CORE_ADDR *addr);
--
1.8.1.4
Tom
^ permalink raw reply [flat|nested] 66+ messages in thread* [PATCH 09/28] introduce and use CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
` (9 preceding siblings ...)
2013-04-19 14:40 ` [PATCH 08/28] use CPYCHECKER_SETS_EXCEPTION Tom Tromey
@ 2013-04-19 14:41 ` Tom Tromey
2013-04-19 14:41 ` [PATCH 10/28] add decref to cmdpy_init Tom Tromey
` (19 subsequent siblings)
30 siblings, 0 replies; 66+ messages in thread
From: Tom Tromey @ 2013-04-19 14:41 UTC (permalink / raw)
To: gdb-patches
The checker provides an attribute that indicates that a function sets
the Python exception if it returns a negative value. This patch
introduces a new macro for this attribute and changes gdb to use it
where appropriate.
* python/py-event.h (gdbpy_initialize_event_generic): Use
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION.
* python/py-evts.c (add_new_registry): Use
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION.
* python/python-internal.h
(CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION): New macro.
---
gdb/python/py-event.h | 7 ++++---
gdb/python/py-evts.c | 2 +-
gdb/python/python-internal.h | 7 +++++++
3 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/gdb/python/py-event.h b/gdb/python/py-event.h
index 1db8bd2..4850f1a 100644
--- a/gdb/python/py-event.h
+++ b/gdb/python/py-event.h
@@ -115,8 +115,9 @@ extern int emit_new_objfile_event (struct objfile *objfile);
extern void evpy_dealloc (PyObject *self);
extern int evpy_add_attribute (PyObject *event,
- char *name, PyObject *attr);
-int gdbpy_initialize_event_generic (PyTypeObject *type, char *name);
-
+ char *name, PyObject *attr)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_event_generic (PyTypeObject *type, char *name)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
#endif /* GDB_PY_EVENT_H */
diff --git a/gdb/python/py-evts.c b/gdb/python/py-evts.c
index 4c079e2..427b6d5 100644
--- a/gdb/python/py-evts.c
+++ b/gdb/python/py-evts.c
@@ -37,7 +37,7 @@ static struct PyModuleDef EventModuleDef =
/* Initialize python events. */
-static int
+static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
add_new_registry (eventregistry_object **registryp, char *name)
{
*registryp = create_eventregistry_object ();
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 57fcc74..b887b66 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -47,6 +47,13 @@
#define CPYCHECKER_SETS_EXCEPTION
#endif
+#ifdef WITH_CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION_ATTRIBUTE
+#define CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION \
+ __attribute__ ((cpychecker_negative_result_sets_exception))
+#else
+#define CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
+#endif
+
#include <stdio.h>
/* Python 2.4 doesn't include stdint.h soon enough to get {u,}intptr_t
--
1.8.1.4
^ permalink raw reply [flat|nested] 66+ messages in thread* [PATCH 10/28] add decref to cmdpy_init
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
` (10 preceding siblings ...)
2013-04-19 14:41 ` [PATCH 09/28] introduce and use CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION Tom Tromey
@ 2013-04-19 14:41 ` Tom Tromey
2013-04-19 14:41 ` [PATCH 11/28] use iterator protocol and avoid refcount bugs Tom Tromey
` (18 subsequent siblings)
30 siblings, 0 replies; 66+ messages in thread
From: Tom Tromey @ 2013-04-19 14:41 UTC (permalink / raw)
To: gdb-patches
The checker pointed out some missing decrefs in cmdpy_init.
This patch adds them.
* python/py-cmd.c (cmdpy_init): Decref 'ds_obj'.
---
gdb/python/py-cmd.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
index ca9e415..6516e1f 100644
--- a/gdb/python/py-cmd.c
+++ b/gdb/python/py-cmd.c
@@ -499,9 +499,12 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kw)
{
xfree (cmd_name);
xfree (pfx_name);
+ Py_DECREF (ds_obj);
return -1;
}
}
+
+ Py_XDECREF (ds_obj);
}
if (! docstring)
docstring = xstrdup (_("This command is not documented."));
--
1.8.1.4
^ permalink raw reply [flat|nested] 66+ messages in thread* [PATCH 11/28] use iterator protocol and avoid refcount bugs
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
` (11 preceding siblings ...)
2013-04-19 14:41 ` [PATCH 10/28] add decref to cmdpy_init Tom Tromey
@ 2013-04-19 14:41 ` Tom Tromey
2013-04-19 14:42 ` [PATCH 12/28] add decref in evpy_emit_event Tom Tromey
` (17 subsequent siblings)
30 siblings, 0 replies; 66+ messages in thread
From: Tom Tromey @ 2013-04-19 14:41 UTC (permalink / raw)
To: gdb-patches
The checker pointed out some refcounting bugs in cmdpy_completer.
And, while looking at it, I noticed that it was not using the iterator
protocol. I couldn't think of a reason why not; and using an iterator
cleaned up the code, so this patch does that.
* python/py-cmd.c (cmdpy_completer): Use iterator protocol.
Correctly decref.
---
gdb/python/py-cmd.c | 49 ++++++++++++++++++++++++++++---------------------
1 file changed, 28 insertions(+), 21 deletions(-)
diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
index 6516e1f..26823c7 100644
--- a/gdb/python/py-cmd.c
+++ b/gdb/python/py-cmd.c
@@ -247,26 +247,40 @@ cmdpy_completer (struct cmd_list_element *command,
make_cleanup_py_decref (resultobj);
result = NULL;
- if (PySequence_Check (resultobj))
+ if (PyInt_Check (resultobj))
{
- Py_ssize_t i, len = PySequence_Size (resultobj);
- Py_ssize_t out;
+ /* User code may also return one of the completion constants,
+ thus requesting that sort of completion. */
+ long value;
+
+ if (! gdb_py_int_as_long (resultobj, &value))
+ {
+ /* Ignore. */
+ PyErr_Clear ();
+ }
+ else if (value >= 0 && value < (long) N_COMPLETERS)
+ result = completers[value].completer (command, text, word);
+ }
+ else
+ {
+ PyObject *iter = PyObject_GetIter (resultobj);
+ PyObject *elt;
- if (len < 0)
+ if (iter == NULL)
goto done;
- for (i = out = 0; i < len; ++i)
+ while ((elt = PyIter_Next (iter)) != NULL)
{
- PyObject *elt = PySequence_GetItem (resultobj, i);
char *item;
- if (elt == NULL || ! gdbpy_is_string (elt))
+ if (! gdbpy_is_string (elt))
{
/* Skip problem elements. */
- PyErr_Clear ();
+ Py_DECREF (elt);
continue;
}
item = python_string_to_host_string (elt);
+ Py_DECREF (elt);
if (item == NULL)
{
/* Skip problem elements. */
@@ -275,20 +289,13 @@ cmdpy_completer (struct cmd_list_element *command,
}
VEC_safe_push (char_ptr, result, item);
}
- }
- else if (PyInt_Check (resultobj))
- {
- /* User code may also return one of the completion constants,
- thus requesting that sort of completion. */
- long value;
- if (! gdb_py_int_as_long (resultobj, &value))
- {
- /* Ignore. */
- PyErr_Clear ();
- }
- else if (value >= 0 && value < (long) N_COMPLETERS)
- result = completers[value].completer (command, text, word);
+ Py_DECREF (iter);
+
+ /* If we got some results, ignore problems. Otherwise, report
+ the problem. */
+ if (result != NULL && PyErr_Occurred ())
+ PyErr_Clear ();
}
done:
--
1.8.1.4
^ permalink raw reply [flat|nested] 66+ messages in thread* [PATCH 12/28] add decref in evpy_emit_event
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
` (12 preceding siblings ...)
2013-04-19 14:41 ` [PATCH 11/28] use iterator protocol and avoid refcount bugs Tom Tromey
@ 2013-04-19 14:42 ` Tom Tromey
2013-04-19 14:43 ` [PATCH 14/28] add gdb_assert_not_reached Tom Tromey
` (16 subsequent siblings)
30 siblings, 0 replies; 66+ messages in thread
From: Tom Tromey @ 2013-04-19 14:42 UTC (permalink / raw)
To: gdb-patches
The checker noticed a missing decref in evpy_emit_event.
* python/py-event.c (evpy_emit_event): Decref the
result of PyObject_CallFunctionObjArgs.
---
gdb/python/py-event.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/gdb/python/py-event.c b/gdb/python/py-event.c
index 2c18e2f..afd07fe 100644
--- a/gdb/python/py-event.c
+++ b/gdb/python/py-event.c
@@ -111,16 +111,23 @@ evpy_emit_event (PyObject *event,
for (i = 0; i < PyList_Size (callback_list_copy); i++)
{
PyObject *func = PyList_GetItem (callback_list_copy, i);
+ PyObject *func_result;
if (func == NULL)
goto fail;
- if (!PyObject_CallFunctionObjArgs (func, event, NULL))
+ func_result = PyObject_CallFunctionObjArgs (func, event, NULL);
+
+ if (func_result == NULL)
{
/* Print the trace here, but keep going -- we want to try to
call all of the callbacks even if one is broken. */
gdbpy_print_stack ();
}
+ else
+ {
+ Py_DECREF (func_result);
+ }
}
Py_XDECREF (callback_list_copy);
--
1.8.1.4
^ permalink raw reply [flat|nested] 66+ messages in thread* [PATCH 14/28] add gdb_assert_not_reached
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
` (13 preceding siblings ...)
2013-04-19 14:42 ` [PATCH 12/28] add decref in evpy_emit_event Tom Tromey
@ 2013-04-19 14:43 ` Tom Tromey
2013-04-19 14:43 ` [PATCH 13/28] fix get_addr_from_python Tom Tromey
` (15 subsequent siblings)
30 siblings, 0 replies; 66+ messages in thread
From: Tom Tromey @ 2013-04-19 14:43 UTC (permalink / raw)
To: gdb-patches
This patch adds a gdb_assert_not_reached to a switch in
make_fielditem. This avoids a checker complaint.
* python/py-type.c (make_fielditem): Add gdb_assert_not_reached
as 'default' in the switch.
---
gdb/python/py-type.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index b289a89..e29ae81 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -301,6 +301,8 @@ make_fielditem (struct type *type, int i, enum gdbpy_iter_kind kind)
case iter_values:
item = convert_field (type, i);
break;
+ default:
+ gdb_assert_not_reached ("invalid gdbpy_iter_kind");
}
return item;
--
1.8.1.4
^ permalink raw reply [flat|nested] 66+ messages in thread* [PATCH 13/28] fix get_addr_from_python
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
` (14 preceding siblings ...)
2013-04-19 14:43 ` [PATCH 14/28] add gdb_assert_not_reached Tom Tromey
@ 2013-04-19 14:43 ` Tom Tromey
2013-04-19 14:43 ` [PATCH 15/28] fix bug in gdbpy_initialize_event_generic Tom Tromey
` (14 subsequent siblings)
30 siblings, 0 replies; 66+ messages in thread
From: Tom Tromey @ 2013-04-19 14:43 UTC (permalink / raw)
To: gdb-patches
get_addr_from_python confused the checker and so I decided to change
it to a form that it found more palatable. In particular now it
returns a negative value on error (using
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION), and it can no longer throw
a gdb exception. This let me hoist calls to it out of some
TRY_CATCHes.
* python/py-inferior.c (gdbpy_inferiors): Update. Hoist
get_addr_from_python calls out of TRY_CATCH.
(infpy_write_memory, infpy_search_memory): Likewise.
* python/py-utils.c (get_addr_from_python): Return negative
value on error. Use TRY_CATCH.
* python/python-internal.h (get_addr_from_python): Use
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION.
---
gdb/python/py-inferior.c | 103 ++++++++++++++++++-------------------------
gdb/python/py-utils.c | 21 ++++++---
gdb/python/python-internal.h | 3 +-
3 files changed, 59 insertions(+), 68 deletions(-)
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index d4ff90b..45b79ce 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -406,7 +406,6 @@ gdbpy_inferiors (PyObject *unused, PyObject *unused2)
static PyObject *
infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
{
- int error = 0;
CORE_ADDR addr, length;
void *buffer = NULL;
membuf_object *membuf_obj;
@@ -418,15 +417,12 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
&addr_obj, &length_obj))
return NULL;
+ if (get_addr_from_python (addr_obj, &addr) < 0
+ || get_addr_from_python (length_obj, &length) < 0)
+ return NULL;
+
TRY_CATCH (except, RETURN_MASK_ALL)
{
- if (!get_addr_from_python (addr_obj, &addr)
- || !get_addr_from_python (length_obj, &length))
- {
- error = 1;
- break;
- }
-
buffer = xmalloc (length);
read_memory (addr, buffer, length);
@@ -437,12 +433,6 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
GDB_PY_HANDLE_EXCEPTION (except);
}
- if (error)
- {
- xfree (buffer);
- return NULL;
- }
-
membuf_obj = PyObject_New (membuf_object, &membuf_object_type);
if (membuf_obj == NULL)
{
@@ -477,7 +467,6 @@ static PyObject *
infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw)
{
Py_ssize_t buf_len;
- int error = 0;
const char *buffer;
CORE_ADDR addr, length;
PyObject *addr_obj, *length_obj = NULL;
@@ -500,21 +489,16 @@ infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw)
return NULL;
#endif
+ if (get_addr_from_python (addr_obj, &addr) < 0)
+ goto fail;
+
+ if (!length_obj)
+ length = buf_len;
+ else if (get_addr_from_python (length_obj, &length) < 0)
+ goto fail;
+
TRY_CATCH (except, RETURN_MASK_ALL)
{
- if (!get_addr_from_python (addr_obj, &addr))
- {
- error = 1;
- break;
- }
-
- if (!length_obj)
- length = buf_len;
- else if (!get_addr_from_python (length_obj, &length))
- {
- error = 1;
- break;
- }
write_memory_with_notification (addr, buffer, length);
}
#ifdef IS_PY3K
@@ -522,11 +506,13 @@ infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw)
#endif
GDB_PY_HANDLE_EXCEPTION (except);
-
- if (error)
- return NULL;
-
Py_RETURN_NONE;
+
+ fail:
+#ifdef IS_PY3K
+ PyBuffer_Release (&pybuf);
+#endif
+ return NULL;
}
/* Destructor of Membuf objects. */
@@ -662,34 +648,26 @@ infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw)
return NULL;
#endif
- if (get_addr_from_python (start_addr_obj, &start_addr)
- && get_addr_from_python (length_obj, &length))
- {
- if (!length)
- {
- PyErr_SetString (PyExc_ValueError,
- _("Search range is empty."));
+ if (get_addr_from_python (start_addr_obj, &start_addr) < 0)
+ goto fail;
+
+ if (get_addr_from_python (length_obj, &length) < 0)
+ goto fail;
-#ifdef IS_PY3K
- PyBuffer_Release (&pybuf);
-#endif
- return NULL;
- }
- /* Watch for overflows. */
- else if (length > CORE_ADDR_MAX
- || (start_addr + length - 1) < start_addr)
- {
- PyErr_SetString (PyExc_ValueError,
- _("The search range is too large."));
-
-#ifdef IS_PY3K
- PyBuffer_Release (&pybuf);
-#endif
- return NULL;
- }
+ if (!length)
+ {
+ PyErr_SetString (PyExc_ValueError,
+ _("Search range is empty."));
+ goto fail;
+ }
+ /* Watch for overflows. */
+ else if (length > CORE_ADDR_MAX
+ || (start_addr + length - 1) < start_addr)
+ {
+ PyErr_SetString (PyExc_ValueError,
+ _("The search range is too large."));
+ goto fail;
}
- else
- return NULL;
TRY_CATCH (except, RETURN_MASK_ALL)
{
@@ -697,16 +675,21 @@ infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw)
buffer, pattern_size,
&found_addr);
}
- GDB_PY_HANDLE_EXCEPTION (except);
-
#ifdef IS_PY3K
PyBuffer_Release (&pybuf);
#endif
+ GDB_PY_HANDLE_EXCEPTION (except);
if (found)
return PyLong_FromLong (found_addr);
else
Py_RETURN_NONE;
+
+ fail:
+#ifdef IS_PY3K
+ PyBuffer_Release (&pybuf);
+#endif
+ return NULL;
}
/* Implementation of gdb.Inferior.is_valid (self) -> Boolean.
diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
index 4cd35a0..6a7e9e4 100644
--- a/gdb/python/py-utils.c
+++ b/gdb/python/py-utils.c
@@ -291,39 +291,46 @@ gdbpy_convert_exception (struct gdb_exception exception)
/* Converts OBJ to a CORE_ADDR value.
- Returns 1 on success or 0 on failure, with a Python exception set. This
- function can also throw GDB exceptions.
+ Returns 0 on success or -1 on failure, with a Python exception set.
*/
int
get_addr_from_python (PyObject *obj, CORE_ADDR *addr)
{
if (gdbpy_is_value_object (obj))
- *addr = value_as_address (value_object_to_value (obj));
+ {
+ volatile struct gdb_exception except;
+
+ TRY_CATCH (except, RETURN_MASK_ALL)
+ {
+ *addr = value_as_address (value_object_to_value (obj));
+ }
+ GDB_PY_SET_HANDLE_EXCEPTION (except);
+ }
else
{
PyObject *num = PyNumber_Long (obj);
gdb_py_ulongest val;
if (num == NULL)
- return 0;
+ return -1;
val = gdb_py_long_as_ulongest (num);
Py_XDECREF (num);
if (PyErr_Occurred ())
- return 0;
+ return -1;
if (sizeof (val) > sizeof (CORE_ADDR) && ((CORE_ADDR) val) != val)
{
PyErr_SetString (PyExc_ValueError,
_("Overflow converting to address."));
- return 0;
+ return -1;
}
*addr = val;
}
- return 1;
+ return 0;
}
/* Convert a LONGEST to the appropriate Python object -- either an
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index b887b66..5c3fe51 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -424,7 +424,8 @@ extern PyObject *gdbpy_gdberror_exc;
extern void gdbpy_convert_exception (struct gdb_exception)
CPYCHECKER_SETS_EXCEPTION;
-int get_addr_from_python (PyObject *obj, CORE_ADDR *addr);
+int get_addr_from_python (PyObject *obj, CORE_ADDR *addr)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
PyObject *gdb_py_object_from_longest (LONGEST l);
PyObject *gdb_py_object_from_ulongest (ULONGEST l);
--
1.8.1.4
^ permalink raw reply [flat|nested] 66+ messages in thread* [PATCH 15/28] fix bug in gdbpy_initialize_event_generic
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
` (15 preceding siblings ...)
2013-04-19 14:43 ` [PATCH 13/28] fix get_addr_from_python Tom Tromey
@ 2013-04-19 14:43 ` Tom Tromey
2013-04-19 14:44 ` [PATCH 16/28] reference count in bpfinishpy_out_of_scope Tom Tromey
` (13 subsequent siblings)
30 siblings, 0 replies; 66+ messages in thread
From: Tom Tromey @ 2013-04-19 14:43 UTC (permalink / raw)
To: gdb-patches
The checker noticed that gdbpy_initialize_event_generic could do an
extra decref of 'type' if PyType_Ready failed. This fixes the bug.
* python/py-event.c (gdbpy_initialize_event_generic): Return
early if PyType_Ready fails.
---
gdb/python/py-event.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gdb/python/py-event.c b/gdb/python/py-event.c
index afd07fe..72d57cb 100644
--- a/gdb/python/py-event.c
+++ b/gdb/python/py-event.c
@@ -76,7 +76,7 @@ gdbpy_initialize_event_generic (PyTypeObject *type,
char *name)
{
if (PyType_Ready (type) < 0)
- goto fail;
+ return -1;
Py_INCREF (type);
if (PyModule_AddObject (gdb_module, name, (PyObject *) type) < 0)
--
1.8.1.4
Tom
^ permalink raw reply [flat|nested] 66+ messages in thread* [PATCH 16/28] reference count in bpfinishpy_out_of_scope
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
` (16 preceding siblings ...)
2013-04-19 14:43 ` [PATCH 15/28] fix bug in gdbpy_initialize_event_generic Tom Tromey
@ 2013-04-19 14:44 ` Tom Tromey
2013-04-19 14:47 ` [PATCH 17/28] convert python init functions to do error-checking Tom Tromey
` (12 subsequent siblings)
30 siblings, 0 replies; 66+ messages in thread
From: Tom Tromey @ 2013-04-19 14:44 UTC (permalink / raw)
To: gdb-patches
The checker noticed a missing decref in bpfinishpy_out_of_scope.
* python/py-finishbreakpoint.c (bpfinishpy_out_of_scope):
Decref the reslut of PyObject_CallMethod.
---
gdb/python/py-finishbreakpoint.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c
index b52bd7e..f65e026 100644
--- a/gdb/python/py-finishbreakpoint.c
+++ b/gdb/python/py-finishbreakpoint.c
@@ -326,8 +326,12 @@ bpfinishpy_out_of_scope (struct finish_breakpoint_object *bpfinish_obj)
if (bpfinish_obj->py_bp.bp->enable_state == bp_enabled
&& PyObject_HasAttrString (py_obj, outofscope_func))
{
- if (!PyObject_CallMethod (py_obj, outofscope_func, NULL))
- gdbpy_print_stack ();
+ PyObject *meth_result;
+
+ meth_result = PyObject_CallMethod (py_obj, outofscope_func, NULL);
+ if (meth_result == NULL)
+ gdbpy_print_stack ();
+ Py_XDECREF (meth_result);
}
delete_breakpoint (bpfinish_obj->py_bp.bp);
--
1.8.1.4
^ permalink raw reply [flat|nested] 66+ messages in thread* [PATCH 17/28] convert python init functions to do error-checking
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
` (17 preceding siblings ...)
2013-04-19 14:44 ` [PATCH 16/28] reference count in bpfinishpy_out_of_scope Tom Tromey
@ 2013-04-19 14:47 ` Tom Tromey
2013-04-19 15:40 ` [PATCH 18/28] check gdb_python_initialized everywhere Tom Tromey
` (11 subsequent siblings)
30 siblings, 0 replies; 66+ messages in thread
From: Tom Tromey @ 2013-04-19 14:47 UTC (permalink / raw)
To: gdb-patches
The checker pointed out that we did not do Python error checking in
any of our module initialization functions. There is no deep reason
for this -- just that it is common in the Python world to work this
way. However, it seems cleaner to me to be correct, and it makes the
checker quieter besides.
This changes nearly all of the Python initialization functions to
return -1 on error.
This also introduces gdb_python_initialized, which is set to a
non-zero value if initialization went properly. A subsequent patch
will use this to disable Python support if initialization failed.
* python/py-arch.c (gdbpy_initialize_arch): Return 'int'.
Check errors.
* python/py-auto-load.c (gdbpy_initialize_auto_load): Return 'int'.
* python/py-block.c (gdbpy_initialize_blocks): Return 'int'.
Check errors.
* python/py-breakpoint.c (gdbpy_initialize_breakpoints): Return 'int'.
Check errors.
* python/py-cmd.c (gdbpy_initialize_commands): Return 'int'.
Check errors.
* python/py-event.c (gdbpy_initialize_event): Return 'int'.
Check errors.
* python/py-event.h (GDBPY_NEW_EVENT_TYPE): Change generated
init function to return 'int'.
* python/py-evtregistry.c (gdbpy_initialize_eventregistry):
Return 'int'. Check errors.
* python/py-evts.c (gdbpy_initialize_py_events): Return 'int'.
Check errors.
* python/py-finishbreakpoint.c (gdbpy_initialize_finishbreakpoints):
Return 'int'. Check errors.
* python/py-frame.c (gdbpy_initialize_frames): Return 'int'.
Check errors.
* python/py-function.c (gdbpy_initialize_functions): Return 'int'.
Check errors.
* python/py-gdb-readline.c (gdbpy_initialize_gdb_readline):
Check errors.
* python/py-inferior.c (gdbpy_initialize_inferior): Return 'int'.
Check errors.
* python/py-infthread.c (gdbpy_initialize_thread): Return 'int'.
Check errors.
* python/py-lazy-string.c (gdbpy_initialize_lazy_string): Return 'int'.
Check errors.
* python/py-objfile.c (gdbpy_initialize_objfile): Return 'int'.
Check errors.
* python/py-param.c (gdbpy_initialize_parameters): Return 'int'.
Check errors.
* python/py-progspace.c (gdbpy_initialize_pspace): Return 'int'.
Check errors.
* python/py-symbol.c (gdbpy_initialize_symbols): Return 'int'.
Check errors.
* python/py-symtab.c (gdbpy_initialize_symtabs): Return 'int'.
Check errors.
* python/py-type.c (gdbpy_initialize_types): Return 'int'.
Check errors.
* python/py-value.c (gdbpy_initialize_values): Return 'int'.
Check errors.
* python/python-internal.h (gdbpy_initialize_auto_load,
gdbpy_initialize_values, gdbpy_initialize_frames,
gdbpy_initialize_symtabs, gdbpy_initialize_commands,
gdbpy_initialize_symbols, gdbpy_initialize_symtabs,
gdbpy_initialize_blocks, gdbpy_initialize_types,
gdbpy_initialize_functions, gdbpy_initialize_pspace,
gdbpy_initialize_objfile, gdbpy_initialize_breakpoints,
gdbpy_initialize_finishbreakpoints,
gdbpy_initialize_lazy_string, gdbpy_initialize_parameters,
gdbpy_initialize_thread, gdbpy_initialize_inferior,
gdbpy_initialize_eventregistry, gdbpy_initialize_event,
gdbpy_initialize_py_events, gdbpy_initialize_stop_event,
gdbpy_initialize_signal_event,
gdbpy_initialize_breakpoint_event,
gdbpy_initialize_continue_event,
gdbpy_initialize_exited_event, gdbpy_initialize_thread_event,
gdbpy_initialize_new_objfile_event, gdbpy_initialize_arch):
Update. Use CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION.
* python/python.c (gdb_python_initialized): New global.
(gdbpy_initialize_events): Return 'int'. Check errors.
(_initialize_python): Check errors. Set
gdb_python_initialized.
---
gdb/python/py-arch.c | 8 +--
gdb/python/py-auto-load.c | 4 +-
gdb/python/py-block.c | 14 +++--
gdb/python/py-breakpoint.c | 14 +++--
gdb/python/py-cmd.c | 19 ++++--
gdb/python/py-event.c | 6 +-
gdb/python/py-event.h | 6 +-
gdb/python/py-evtregistry.c | 8 +--
gdb/python/py-evts.c | 19 +++---
gdb/python/py-finishbreakpoint.c | 11 ++--
gdb/python/py-frame.c | 32 ++++++----
gdb/python/py-function.c | 7 ++-
gdb/python/py-gdb-readline.c | 7 +--
gdb/python/py-inferior.c | 15 ++---
gdb/python/py-infthread.c | 8 +--
gdb/python/py-lazy-string.c | 5 +-
gdb/python/py-objfile.c | 8 +--
gdb/python/py-param.c | 14 ++---
gdb/python/py-progspace.c | 8 +--
gdb/python/py-symbol.c | 79 +++++++++++++++----------
gdb/python/py-symtab.c | 15 ++---
gdb/python/py-type.c | 22 ++++---
gdb/python/py-value.c | 9 ++-
gdb/python/python-internal.h | 87 ++++++++++++++++++---------
gdb/python/python.c | 123 ++++++++++++++++++++++++++-------------
25 files changed, 331 insertions(+), 217 deletions(-)
diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c
index 146a642..7920fbb 100644
--- a/gdb/python/py-arch.c
+++ b/gdb/python/py-arch.c
@@ -231,17 +231,17 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
/* Initializes the Architecture class in the gdb module. */
-void
+int
gdbpy_initialize_arch (void)
{
arch_object_data = gdbarch_data_register_post_init (arch_object_data_init);
arch_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&arch_object_type) < 0)
- return;
+ return -1;
Py_INCREF (&arch_object_type);
- PyModule_AddObject (gdb_module, "Architecture",
- (PyObject *) &arch_object_type);
+ return PyModule_AddObject (gdb_module, "Architecture",
+ (PyObject *) &arch_object_type);
}
static PyMethodDef arch_object_methods [] = {
diff --git a/gdb/python/py-auto-load.c b/gdb/python/py-auto-load.c
index 53a8eb5..fa07432 100644
--- a/gdb/python/py-auto-load.c
+++ b/gdb/python/py-auto-load.c
@@ -238,7 +238,7 @@ info_auto_load_python_scripts (char *pattern, int from_tty)
auto_load_info_scripts (pattern, from_tty, &script_language_python);
}
\f
-void
+int
gdbpy_initialize_auto_load (void)
{
struct cmd_list_element *cmd;
@@ -281,6 +281,8 @@ Usage: info auto-load python-scripts [REGEXP]"),
cmd = add_info ("auto-load-scripts", info_auto_load_python_scripts, _("\
Print the list of automatically loaded Python scripts, deprecated."));
deprecate_cmd (cmd, "info auto-load python-scripts");
+
+ return 0;
}
#else /* ! HAVE_PYTHON */
diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c
index afc8959..f2d9000 100644
--- a/gdb/python/py-block.c
+++ b/gdb/python/py-block.c
@@ -425,16 +425,16 @@ del_objfile_blocks (struct objfile *objfile, void *datum)
}
}
-void
+int
gdbpy_initialize_blocks (void)
{
block_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&block_object_type) < 0)
- return;
+ return -1;
block_syms_iterator_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&block_syms_iterator_object_type) < 0)
- return;
+ return -1;
/* Register an objfile "free" callback so we can properly
invalidate blocks when an object file is about to be
@@ -443,11 +443,13 @@ gdbpy_initialize_blocks (void)
= register_objfile_data_with_cleanup (NULL, del_objfile_blocks);
Py_INCREF (&block_object_type);
- PyModule_AddObject (gdb_module, "Block", (PyObject *) &block_object_type);
+ if (PyModule_AddObject (gdb_module, "Block",
+ (PyObject *) &block_object_type) < 0)
+ return -1;
Py_INCREF (&block_syms_iterator_object_type);
- PyModule_AddObject (gdb_module, "BlockIterator",
- (PyObject *) &block_syms_iterator_object_type);
+ return PyModule_AddObject (gdb_module, "BlockIterator",
+ (PyObject *) &block_syms_iterator_object_type);
}
\f
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index 5e5f9b3..b1b6e93 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -859,18 +859,19 @@ gdbpy_breakpoint_deleted (struct breakpoint *b)
\f
/* Initialize the Python breakpoint code. */
-void
+int
gdbpy_initialize_breakpoints (void)
{
int i;
breakpoint_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&breakpoint_object_type) < 0)
- return;
+ return -1;
Py_INCREF (&breakpoint_object_type);
- PyModule_AddObject (gdb_module, "Breakpoint",
- (PyObject *) &breakpoint_object_type);
+ if (PyModule_AddObject (gdb_module, "Breakpoint",
+ (PyObject *) &breakpoint_object_type) < 0)
+ return -1;
observer_attach_breakpoint_created (gdbpy_breakpoint_created);
observer_attach_breakpoint_deleted (gdbpy_breakpoint_deleted);
@@ -882,7 +883,7 @@ gdbpy_initialize_breakpoints (void)
/* Cast needed for Python 2.4. */
(char *) pybp_codes[i].name,
pybp_codes[i].code) < 0)
- return;
+ return -1;
}
/* Add watchpoint types constants. */
@@ -892,9 +893,10 @@ gdbpy_initialize_breakpoints (void)
/* Cast needed for Python 2.4. */
(char *) pybp_watch_types[i].name,
pybp_watch_types[i].code) < 0)
- return;
+ return -1;
}
+ return 0;
}
\f
diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
index 26823c7..ba765e0 100644
--- a/gdb/python/py-cmd.c
+++ b/gdb/python/py-cmd.c
@@ -564,14 +564,14 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kw)
/* Initialize the 'commands' code. */
-void
+int
gdbpy_initialize_commands (void)
{
int i;
cmdpy_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&cmdpy_object_type) < 0)
- return;
+ return -1;
/* Note: alias and user are special; pseudo appears to be unused,
and there is no reason to expose tui or xdb, I think. */
@@ -592,20 +592,27 @@ gdbpy_initialize_commands (void)
|| PyModule_AddIntConstant (gdb_module, "COMMAND_MAINTENANCE",
class_maintenance) < 0
|| PyModule_AddIntConstant (gdb_module, "COMMAND_USER", class_user) < 0)
- return;
+ return -1;
for (i = 0; i < N_COMPLETERS; ++i)
{
if (PyModule_AddIntConstant (gdb_module, completers[i].name, i) < 0)
- return;
+ return -1;
}
Py_INCREF (&cmdpy_object_type);
- PyModule_AddObject (gdb_module, "Command",
- (PyObject *) &cmdpy_object_type);
+ if (PyModule_AddObject (gdb_module, "Command",
+ (PyObject *) &cmdpy_object_type) < 0)
+ return -1;
invoke_cst = PyString_FromString ("invoke");
+ if (invoke_cst == NULL)
+ return -1;
complete_cst = PyString_FromString ("complete");
+ if (complete_cst == NULL)
+ return -1;
+
+ return 0;
}
\f
diff --git a/gdb/python/py-event.c b/gdb/python/py-event.c
index 72d57cb..04f33ab 100644
--- a/gdb/python/py-event.c
+++ b/gdb/python/py-event.c
@@ -60,11 +60,11 @@ evpy_add_attribute (PyObject *event, char *name, PyObject *attr)
/* Initialize the Python event code. */
-void
+int
gdbpy_initialize_event (void)
{
- gdbpy_initialize_event_generic (&event_object_type,
- "Event");
+ return gdbpy_initialize_event_generic (&event_object_type,
+ "Event");
}
/* Initialize the given event type. If BASE is not NULL it will
diff --git a/gdb/python/py-event.h b/gdb/python/py-event.h
index 4850f1a..f0ff629 100644
--- a/gdb/python/py-event.h
+++ b/gdb/python/py-event.h
@@ -88,11 +88,11 @@
0 /* tp_alloc */ \
}; \
\
-void \
+int \
gdbpy_initialize_##name##_event (void) \
{ \
- gdbpy_initialize_event_generic (&name##_event_object_type, \
- py_name); \
+ return gdbpy_initialize_event_generic (&name##_event_object_type, \
+ py_name); \
}
typedef struct
diff --git a/gdb/python/py-evtregistry.c b/gdb/python/py-evtregistry.c
index 05c8586..d7cbe64 100644
--- a/gdb/python/py-evtregistry.c
+++ b/gdb/python/py-evtregistry.c
@@ -106,15 +106,15 @@ evregpy_dealloc (PyObject *self)
/* Initialize the Python event registry code. */
-void
+int
gdbpy_initialize_eventregistry (void)
{
if (PyType_Ready (&eventregistry_object_type) < 0)
- return;
+ return -1;
Py_INCREF (&eventregistry_object_type);
- PyModule_AddObject (gdb_module, "EventRegistry",
- (PyObject *) &eventregistry_object_type);
+ return PyModule_AddObject (gdb_module, "EventRegistry",
+ (PyObject *) &eventregistry_object_type);
}
/* Retern the number of listeners currently connected to this
diff --git a/gdb/python/py-evts.c b/gdb/python/py-evts.c
index 427b6d5..bb384e3 100644
--- a/gdb/python/py-evts.c
+++ b/gdb/python/py-evts.c
@@ -57,7 +57,7 @@ add_new_registry (eventregistry_object **registryp, char *name)
return -1;
}
-void
+int
gdbpy_initialize_py_events (void)
{
#ifdef IS_PY3K
@@ -67,19 +67,19 @@ gdbpy_initialize_py_events (void)
#endif
if (!gdb_py_events.module)
- goto fail;
+ return -1;
if (add_new_registry (&gdb_py_events.stop, "stop") < 0)
- goto fail;
+ return -1;
if (add_new_registry (&gdb_py_events.cont, "cont") < 0)
- goto fail;
+ return -1;
if (add_new_registry (&gdb_py_events.exited, "exited") < 0)
- goto fail;
+ return -1;
if (add_new_registry (&gdb_py_events.new_objfile, "new_objfile") < 0)
- goto fail;
+ return -1;
#ifndef IS_PY3K
Py_INCREF (gdb_py_events.module);
@@ -87,10 +87,7 @@ gdbpy_initialize_py_events (void)
if (PyModule_AddObject (gdb_module,
"events",
(PyObject *) gdb_py_events.module) < 0)
- goto fail;
-
- return;
+ return -1;
- fail:
- gdbpy_print_stack ();
+ return 0;
}
diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c
index f65e026..5fd1f4b 100644
--- a/gdb/python/py-finishbreakpoint.c
+++ b/gdb/python/py-finishbreakpoint.c
@@ -407,18 +407,21 @@ bpfinishpy_handle_exit (struct inferior *inf)
/* Initialize the Python finish breakpoint code. */
-void
+int
gdbpy_initialize_finishbreakpoints (void)
{
if (PyType_Ready (&finish_breakpoint_object_type) < 0)
- return;
+ return -1;
Py_INCREF (&finish_breakpoint_object_type);
- PyModule_AddObject (gdb_module, "FinishBreakpoint",
- (PyObject *) &finish_breakpoint_object_type);
+ if (PyModule_AddObject (gdb_module, "FinishBreakpoint",
+ (PyObject *) &finish_breakpoint_object_type) < 0)
+ return -1;
observer_attach_normal_stop (bpfinishpy_handle_stop);
observer_attach_inferior_exit (bpfinishpy_handle_exit);
+
+ return 0;
}
static PyGetSetDef finish_breakpoint_object_getset[] = {
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index e2eb9c5..75e84ac 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -610,33 +610,41 @@ frapy_richcompare (PyObject *self, PyObject *other, int op)
/* Sets up the Frame API in the gdb module. */
-void
+int
gdbpy_initialize_frames (void)
{
frame_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&frame_object_type) < 0)
- return;
+ return -1;
/* Note: These would probably be best exposed as class attributes of
Frame, but I don't know how to do it except by messing with the
type's dictionary. That seems too messy. */
- PyModule_AddIntConstant (gdb_module, "NORMAL_FRAME", NORMAL_FRAME);
- PyModule_AddIntConstant (gdb_module, "DUMMY_FRAME", DUMMY_FRAME);
- PyModule_AddIntConstant (gdb_module, "INLINE_FRAME", INLINE_FRAME);
- PyModule_AddIntConstant (gdb_module, "TAILCALL_FRAME", TAILCALL_FRAME);
- PyModule_AddIntConstant (gdb_module, "SIGTRAMP_FRAME", SIGTRAMP_FRAME);
- PyModule_AddIntConstant (gdb_module, "ARCH_FRAME", ARCH_FRAME);
- PyModule_AddIntConstant (gdb_module, "SENTINEL_FRAME", SENTINEL_FRAME);
+ if (PyModule_AddIntConstant (gdb_module, "NORMAL_FRAME", NORMAL_FRAME) < 0
+ || PyModule_AddIntConstant (gdb_module, "DUMMY_FRAME", DUMMY_FRAME) < 0
+ || PyModule_AddIntConstant (gdb_module, "INLINE_FRAME", INLINE_FRAME) < 0
+ || PyModule_AddIntConstant (gdb_module, "TAILCALL_FRAME",
+ TAILCALL_FRAME) < 0
+ || PyModule_AddIntConstant (gdb_module, "SIGTRAMP_FRAME",
+ SIGTRAMP_FRAME) < 0
+ || PyModule_AddIntConstant (gdb_module, "ARCH_FRAME", ARCH_FRAME) < 0
+ || PyModule_AddIntConstant (gdb_module, "SENTINEL_FRAME",
+ SENTINEL_FRAME) < 0)
+ return -1;
#define SET(name, description) \
- PyModule_AddIntConstant (gdb_module, "FRAME_"#name, name);
+ if (PyModule_AddIntConstant (gdb_module, "FRAME_"#name, name) < 0) \
+ return -1;
#define FIRST_ERROR(name) \
- PyModule_AddIntConstant (gdb_module, "FRAME_"#name, name);
+ if (PyModule_AddIntConstant (gdb_module, "FRAME_"#name, name) < 0) \
+ return -1;
#include "unwind_stop_reasons.def"
#undef SET
+#undef FIRST_ERROR
Py_INCREF (&frame_object_type);
- PyModule_AddObject (gdb_module, "Frame", (PyObject *) &frame_object_type);
+ return PyModule_AddObject (gdb_module, "Frame",
+ (PyObject *) &frame_object_type);
}
\f
diff --git a/gdb/python/py-function.c b/gdb/python/py-function.c
index 395eeda..57cdfae 100644
--- a/gdb/python/py-function.c
+++ b/gdb/python/py-function.c
@@ -200,15 +200,16 @@ fnpy_init (PyObject *self, PyObject *args, PyObject *kwds)
/* Initialize internal function support. */
-void
+int
gdbpy_initialize_functions (void)
{
fnpy_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&fnpy_object_type) < 0)
- return;
+ return -1;
Py_INCREF (&fnpy_object_type);
- PyModule_AddObject (gdb_module, "Function", (PyObject *) &fnpy_object_type);
+ return PyModule_AddObject (gdb_module, "Function",
+ (PyObject *) &fnpy_object_type);
}
\f
diff --git a/gdb/python/py-gdb-readline.c b/gdb/python/py-gdb-readline.c
index ca7e4a6..d6576a3 100644
--- a/gdb/python/py-gdb-readline.c
+++ b/gdb/python/py-gdb-readline.c
@@ -93,7 +93,7 @@ gdbpy_initialize_gdb_readline (void)
and prevent conflicts. For now, this file implements a
sys.meta_path finder that simply fails to import the readline
module. */
- PyRun_SimpleString ("\
+ if (PyRun_SimpleString ("\
import sys\n\
\n\
class GdbRemoveReadlineFinder:\n\
@@ -106,8 +106,7 @@ class GdbRemoveReadlineFinder:\n\
raise ImportError('readline module disabled under GDB')\n\
\n\
sys.meta_path.append(GdbRemoveReadlineFinder())\n\
-");
-
- PyOS_ReadlineFunctionPointer = gdbpy_readline_wrapper;
+") == 0)
+ PyOS_ReadlineFunctionPointer = gdbpy_readline_wrapper;
}
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index 45b79ce..b11d786 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -762,15 +762,16 @@ gdbpy_selected_inferior (PyObject *self, PyObject *args)
return inf_obj;
}
-void
+int
gdbpy_initialize_inferior (void)
{
if (PyType_Ready (&inferior_object_type) < 0)
- return;
+ return -1;
Py_INCREF (&inferior_object_type);
- PyModule_AddObject (gdb_module, "Inferior",
- (PyObject *) &inferior_object_type);
+ if (PyModule_AddObject (gdb_module, "Inferior",
+ (PyObject *) &inferior_object_type) < 0)
+ return -1;
infpy_inf_data_key =
register_inferior_data_with_cleanup (NULL, py_free_inferior);
@@ -784,11 +785,11 @@ gdbpy_initialize_inferior (void)
membuf_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&membuf_object_type) < 0)
- return;
+ return -1;
Py_INCREF (&membuf_object_type);
- PyModule_AddObject (gdb_module, "Membuf", (PyObject *)
- &membuf_object_type);
+ return PyModule_AddObject (gdb_module, "Membuf", (PyObject *)
+ &membuf_object_type);
}
static PyGetSetDef inferior_object_getset[] =
diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
index a0545ec..7a5f262 100644
--- a/gdb/python/py-infthread.c
+++ b/gdb/python/py-infthread.c
@@ -255,15 +255,15 @@ gdbpy_selected_thread (PyObject *self, PyObject *args)
-void
+int
gdbpy_initialize_thread (void)
{
if (PyType_Ready (&thread_object_type) < 0)
- return;
+ return -1;
Py_INCREF (&thread_object_type);
- PyModule_AddObject (gdb_module, "InferiorThread",
- (PyObject *) &thread_object_type);
+ return PyModule_AddObject (gdb_module, "InferiorThread",
+ (PyObject *) &thread_object_type);
}
diff --git a/gdb/python/py-lazy-string.c b/gdb/python/py-lazy-string.c
index df54cf4..ea193a9 100644
--- a/gdb/python/py-lazy-string.c
+++ b/gdb/python/py-lazy-string.c
@@ -160,13 +160,14 @@ gdbpy_create_lazy_string_object (CORE_ADDR address, long length,
return (PyObject *) str_obj;
}
-void
+int
gdbpy_initialize_lazy_string (void)
{
if (PyType_Ready (&lazy_string_object_type) < 0)
- return;
+ return -1;
Py_INCREF (&lazy_string_object_type);
+ return 0;
}
/* Determine whether the printer object pointed to by OBJ is a
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index e5e5408..53f8829 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -240,18 +240,18 @@ objfile_to_objfile_object (struct objfile *objfile)
return (PyObject *) object;
}
-void
+int
gdbpy_initialize_objfile (void)
{
objfpy_objfile_data_key
= register_objfile_data_with_cleanup (NULL, py_free_objfile);
if (PyType_Ready (&objfile_object_type) < 0)
- return;
+ return -1;
Py_INCREF (&objfile_object_type);
- PyModule_AddObject (gdb_module, "Objfile",
- (PyObject *) &objfile_object_type);
+ return PyModule_AddObject (gdb_module, "Objfile",
+ (PyObject *) &objfile_object_type);
}
\f
diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c
index 176bbc2..2cc17b6 100644
--- a/gdb/python/py-param.c
+++ b/gdb/python/py-param.c
@@ -749,33 +749,33 @@ parmpy_init (PyObject *self, PyObject *args, PyObject *kwds)
\f
/* Initialize the 'parameters' module. */
-void
+int
gdbpy_initialize_parameters (void)
{
int i;
parmpy_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&parmpy_object_type) < 0)
- return;
+ return -1;
set_doc_cst = PyString_FromString ("set_doc");
if (! set_doc_cst)
- return;
+ return -1;
show_doc_cst = PyString_FromString ("show_doc");
if (! show_doc_cst)
- return;
+ return -1;
for (i = 0; parm_constants[i].name; ++i)
{
if (PyModule_AddIntConstant (gdb_module,
parm_constants[i].name,
parm_constants[i].value) < 0)
- return;
+ return -1;
}
Py_INCREF (&parmpy_object_type);
- PyModule_AddObject (gdb_module, "Parameter",
- (PyObject *) &parmpy_object_type);
+ return PyModule_AddObject (gdb_module, "Parameter",
+ (PyObject *) &parmpy_object_type);
}
\f
diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c
index fa9a193..f964fe0 100644
--- a/gdb/python/py-progspace.c
+++ b/gdb/python/py-progspace.c
@@ -236,18 +236,18 @@ pspace_to_pspace_object (struct program_space *pspace)
return (PyObject *) object;
}
-void
+int
gdbpy_initialize_pspace (void)
{
pspy_pspace_data_key
= register_program_space_data_with_cleanup (NULL, py_free_pspace);
if (PyType_Ready (&pspace_object_type) < 0)
- return;
+ return -1;
Py_INCREF (&pspace_object_type);
- PyModule_AddObject (gdb_module, "Progspace",
- (PyObject *) &pspace_object_type);
+ return PyModule_AddObject (gdb_module, "Progspace",
+ (PyObject *) &pspace_object_type);
}
\f
diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
index def0fdd..7629f70 100644
--- a/gdb/python/py-symbol.c
+++ b/gdb/python/py-symbol.c
@@ -474,11 +474,11 @@ del_objfile_symbols (struct objfile *objfile, void *datum)
}
}
-void
+int
gdbpy_initialize_symbols (void)
{
if (PyType_Ready (&symbol_object_type) < 0)
- return;
+ return -1;
/* Register an objfile "free" callback so we can properly
invalidate symbol when an object file that is about to be
@@ -486,37 +486,54 @@ gdbpy_initialize_symbols (void)
sympy_objfile_data_key
= register_objfile_data_with_cleanup (NULL, del_objfile_symbols);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_UNDEF", LOC_UNDEF);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_CONST", LOC_CONST);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_STATIC", LOC_STATIC);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REGISTER", LOC_REGISTER);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_ARG", LOC_ARG);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REF_ARG", LOC_REF_ARG);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_LOCAL", LOC_LOCAL);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_TYPEDEF", LOC_TYPEDEF);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_LABEL", LOC_LABEL);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_BLOCK", LOC_BLOCK);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_CONST_BYTES",
- LOC_CONST_BYTES);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_UNRESOLVED",
- LOC_UNRESOLVED);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_OPTIMIZED_OUT",
- LOC_OPTIMIZED_OUT);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_COMPUTED", LOC_COMPUTED);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REGPARM_ADDR",
- LOC_REGPARM_ADDR);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_UNDEF_DOMAIN", UNDEF_DOMAIN);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_VAR_DOMAIN", VAR_DOMAIN);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_STRUCT_DOMAIN", STRUCT_DOMAIN);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LABEL_DOMAIN", LABEL_DOMAIN);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_VARIABLES_DOMAIN",
- VARIABLES_DOMAIN);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_FUNCTIONS_DOMAIN",
- FUNCTIONS_DOMAIN);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_TYPES_DOMAIN", TYPES_DOMAIN);
+ if (PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_UNDEF", LOC_UNDEF) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_CONST",
+ LOC_CONST) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_STATIC",
+ LOC_STATIC) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REGISTER",
+ LOC_REGISTER) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_ARG",
+ LOC_ARG) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REF_ARG",
+ LOC_REF_ARG) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_LOCAL",
+ LOC_LOCAL) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_TYPEDEF",
+ LOC_TYPEDEF) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_LABEL",
+ LOC_LABEL) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_BLOCK",
+ LOC_BLOCK) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_CONST_BYTES",
+ LOC_CONST_BYTES) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_UNRESOLVED",
+ LOC_UNRESOLVED) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_OPTIMIZED_OUT",
+ LOC_OPTIMIZED_OUT) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_COMPUTED",
+ LOC_COMPUTED) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REGPARM_ADDR",
+ LOC_REGPARM_ADDR) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_UNDEF_DOMAIN",
+ UNDEF_DOMAIN) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_VAR_DOMAIN",
+ VAR_DOMAIN) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_STRUCT_DOMAIN",
+ STRUCT_DOMAIN) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LABEL_DOMAIN",
+ LABEL_DOMAIN) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_VARIABLES_DOMAIN",
+ VARIABLES_DOMAIN) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_FUNCTIONS_DOMAIN",
+ FUNCTIONS_DOMAIN) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_TYPES_DOMAIN",
+ TYPES_DOMAIN) < 0)
+ return -1;
Py_INCREF (&symbol_object_type);
- PyModule_AddObject (gdb_module, "Symbol", (PyObject *) &symbol_object_type);
+ return PyModule_AddObject (gdb_module, "Symbol",
+ (PyObject *) &symbol_object_type);
}
\f
diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c
index 94c05be..80a2282 100644
--- a/gdb/python/py-symtab.c
+++ b/gdb/python/py-symtab.c
@@ -484,16 +484,16 @@ del_objfile_sal (struct objfile *objfile, void *datum)
}
}
-void
+int
gdbpy_initialize_symtabs (void)
{
symtab_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&symtab_object_type) < 0)
- return;
+ return -1;
sal_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&sal_object_type) < 0)
- return;
+ return -1;
/* Register an objfile "free" callback so we can properly
invalidate symbol tables, and symbol table and line data
@@ -505,12 +505,13 @@ gdbpy_initialize_symtabs (void)
= register_objfile_data_with_cleanup (NULL, del_objfile_sal);
Py_INCREF (&symtab_object_type);
- PyModule_AddObject (gdb_module, "Symtab",
- (PyObject *) &symtab_object_type);
+ if (PyModule_AddObject (gdb_module, "Symtab",
+ (PyObject *) &symtab_object_type) < 0)
+ return -1;
Py_INCREF (&sal_object_type);
- PyModule_AddObject (gdb_module, "Symtab_and_line",
- (PyObject *) &sal_object_type);
+ return PyModule_AddObject (gdb_module, "Symtab_and_line",
+ (PyObject *) &sal_object_type);
}
\f
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index e29ae81..05e251b 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -1521,7 +1521,7 @@ gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw)
return (PyObject *) type_to_type_object (type);
}
-void
+int
gdbpy_initialize_types (void)
{
int i;
@@ -1530,11 +1530,11 @@ gdbpy_initialize_types (void)
= register_objfile_data_with_cleanup (save_objfile_types, NULL);
if (PyType_Ready (&type_object_type) < 0)
- return;
+ return -1;
if (PyType_Ready (&field_object_type) < 0)
- return;
+ return -1;
if (PyType_Ready (&type_iterator_object_type) < 0)
- return;
+ return -1;
for (i = 0; pyty_codes[i].name; ++i)
{
@@ -1542,18 +1542,22 @@ gdbpy_initialize_types (void)
/* Cast needed for Python 2.4. */
(char *) pyty_codes[i].name,
pyty_codes[i].code) < 0)
- return;
+ return -1;
}
Py_INCREF (&type_object_type);
- PyModule_AddObject (gdb_module, "Type", (PyObject *) &type_object_type);
+ if (PyModule_AddObject (gdb_module, "Type",
+ (PyObject *) &type_object_type) < 0)
+ return -1;
Py_INCREF (&type_iterator_object_type);
- PyModule_AddObject (gdb_module, "TypeIterator",
- (PyObject *) &type_iterator_object_type);
+ if (PyModule_AddObject (gdb_module, "TypeIterator",
+ (PyObject *) &type_iterator_object_type) < 0)
+ return -1;
Py_INCREF (&field_object_type);
- PyModule_AddObject (gdb_module, "Field", (PyObject *) &field_object_type);
+ return PyModule_AddObject (gdb_module, "Field",
+ (PyObject *) &field_object_type);
}
\f
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 11cc038..d8d90c7 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -1385,16 +1385,15 @@ gdbpy_is_value_object (PyObject *obj)
return PyObject_TypeCheck (obj, &value_object_type);
}
-void
+int
gdbpy_initialize_values (void)
{
if (PyType_Ready (&value_object_type) < 0)
- return;
+ return -1;
Py_INCREF (&value_object_type);
- PyModule_AddObject (gdb_module, "Value", (PyObject *) &value_object_type);
-
- values_in_python = NULL;
+ return PyModule_AddObject (gdb_module, "Value",
+ (PyObject *) &value_object_type);
}
\f
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 5c3fe51..63d020d 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -316,35 +316,64 @@ struct frame_info *frame_object_to_frame_info (PyObject *frame_obj);
struct gdbarch *arch_object_to_gdbarch (PyObject *obj);
void gdbpy_initialize_gdb_readline (void);
-void gdbpy_initialize_auto_load (void);
-void gdbpy_initialize_values (void);
-void gdbpy_initialize_frames (void);
-void gdbpy_initialize_symtabs (void);
-void gdbpy_initialize_commands (void);
-void gdbpy_initialize_symbols (void);
-void gdbpy_initialize_symtabs (void);
-void gdbpy_initialize_blocks (void);
-void gdbpy_initialize_types (void);
-void gdbpy_initialize_functions (void);
-void gdbpy_initialize_pspace (void);
-void gdbpy_initialize_objfile (void);
-void gdbpy_initialize_breakpoints (void);
-void gdbpy_initialize_finishbreakpoints (void);
-void gdbpy_initialize_lazy_string (void);
-void gdbpy_initialize_parameters (void);
-void gdbpy_initialize_thread (void);
-void gdbpy_initialize_inferior (void);
-void gdbpy_initialize_eventregistry (void);
-void gdbpy_initialize_event (void);
-void gdbpy_initialize_py_events (void);
-void gdbpy_initialize_stop_event (void);
-void gdbpy_initialize_signal_event (void);
-void gdbpy_initialize_breakpoint_event (void);
-void gdbpy_initialize_continue_event (void);
-void gdbpy_initialize_exited_event (void);
-void gdbpy_initialize_thread_event (void);
-void gdbpy_initialize_new_objfile_event (void);
-void gdbpy_initialize_arch (void);
+int gdbpy_initialize_auto_load (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_values (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_frames (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_symtabs (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_commands (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_symbols (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_symtabs (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_blocks (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_types (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_functions (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_pspace (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_objfile (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_breakpoints (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_finishbreakpoints (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_lazy_string (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_parameters (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_thread (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_inferior (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_eventregistry (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_event (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_py_events (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_stop_event (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_signal_event (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_breakpoint_event (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_continue_event (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_exited_event (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_thread_event (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_new_objfile_event (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_arch (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
struct cleanup *make_cleanup_py_decref (PyObject *py);
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 5ef9e0a..51f8cd5 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -73,6 +73,11 @@ static const char *gdbpy_should_print_stack = python_excp_message;
#include "interps.h"
#include "event-top.h"
+/* True if Python has been successfully initialized, false
+ otherwise. */
+
+int gdb_python_initialized;
+
static PyMethodDef GdbMethods[];
#ifdef IS_PY3K
@@ -871,7 +876,7 @@ gdbpy_post_event (PyObject *self, PyObject *args)
}
/* Initialize the Python event handler. */
-static void
+static int
gdbpy_initialize_events (void)
{
if (serial_pipe (gdbpy_event_fds) == 0)
@@ -879,6 +884,8 @@ gdbpy_initialize_events (void)
gdbpy_event_list_end = &gdbpy_event_list;
serial_async (gdbpy_event_fds[0], gdbpy_run_events, NULL);
}
+
+ return 0;
}
\f
@@ -1580,74 +1587,108 @@ message == an error message without a stack will be printed."),
#else
gdb_module = Py_InitModule ("_gdb", GdbMethods);
#endif
+ if (gdb_module == NULL)
+ goto fail;
/* The casts to (char*) are for python 2.4. */
- PyModule_AddStringConstant (gdb_module, "VERSION", (char*) version);
- PyModule_AddStringConstant (gdb_module, "HOST_CONFIG", (char*) host_name);
- PyModule_AddStringConstant (gdb_module, "TARGET_CONFIG",
- (char*) target_name);
+ if (PyModule_AddStringConstant (gdb_module, "VERSION", (char*) version) < 0
+ || PyModule_AddStringConstant (gdb_module, "HOST_CONFIG",
+ (char*) host_name) < 0
+ || PyModule_AddStringConstant (gdb_module, "TARGET_CONFIG",
+ (char*) target_name) < 0)
+ goto fail;
/* Add stream constants. */
- PyModule_AddIntConstant (gdb_module, "STDOUT", 0);
- PyModule_AddIntConstant (gdb_module, "STDERR", 1);
- PyModule_AddIntConstant (gdb_module, "STDLOG", 2);
+ if (PyModule_AddIntConstant (gdb_module, "STDOUT", 0) < 0
+ || PyModule_AddIntConstant (gdb_module, "STDERR", 1) < 0
+ || PyModule_AddIntConstant (gdb_module, "STDLOG", 2) < 0)
+ goto fail;
gdbpy_gdb_error = PyErr_NewException ("gdb.error", PyExc_RuntimeError, NULL);
- PyModule_AddObject (gdb_module, "error", gdbpy_gdb_error);
+ if (gdbpy_gdb_error == NULL
+ || PyModule_AddObject (gdb_module, "error", gdbpy_gdb_error) < 0)
+ goto fail;
gdbpy_gdb_memory_error = PyErr_NewException ("gdb.MemoryError",
gdbpy_gdb_error, NULL);
- PyModule_AddObject (gdb_module, "MemoryError", gdbpy_gdb_memory_error);
+ if (gdbpy_gdb_memory_error == NULL
+ || PyModule_AddObject (gdb_module, "MemoryError",
+ gdbpy_gdb_memory_error) < 0)
+ goto fail;
gdbpy_gdberror_exc = PyErr_NewException ("gdb.GdbError", NULL, NULL);
- PyModule_AddObject (gdb_module, "GdbError", gdbpy_gdberror_exc);
+ if (gdbpy_gdberror_exc == NULL
+ || PyModule_AddObject (gdb_module, "GdbError", gdbpy_gdberror_exc) < 0)
+ goto fail;
gdbpy_initialize_gdb_readline ();
- gdbpy_initialize_auto_load ();
- gdbpy_initialize_values ();
- gdbpy_initialize_frames ();
- gdbpy_initialize_commands ();
- gdbpy_initialize_symbols ();
- gdbpy_initialize_symtabs ();
- gdbpy_initialize_blocks ();
- gdbpy_initialize_functions ();
- gdbpy_initialize_parameters ();
- gdbpy_initialize_types ();
- gdbpy_initialize_pspace ();
- gdbpy_initialize_objfile ();
- gdbpy_initialize_breakpoints ();
- gdbpy_initialize_finishbreakpoints ();
- gdbpy_initialize_lazy_string ();
- gdbpy_initialize_thread ();
- gdbpy_initialize_inferior ();
- gdbpy_initialize_events ();
-
- gdbpy_initialize_eventregistry ();
- gdbpy_initialize_py_events ();
- gdbpy_initialize_event ();
- gdbpy_initialize_stop_event ();
- gdbpy_initialize_signal_event ();
- gdbpy_initialize_breakpoint_event ();
- gdbpy_initialize_continue_event ();
- gdbpy_initialize_exited_event ();
- gdbpy_initialize_thread_event ();
- gdbpy_initialize_new_objfile_event () ;
- gdbpy_initialize_arch ();
+
+ if (gdbpy_initialize_auto_load () < 0
+ || gdbpy_initialize_values () < 0
+ || gdbpy_initialize_frames () < 0
+ || gdbpy_initialize_commands () < 0
+ || gdbpy_initialize_symbols () < 0
+ || gdbpy_initialize_symtabs () < 0
+ || gdbpy_initialize_blocks () < 0
+ || gdbpy_initialize_functions () < 0
+ || gdbpy_initialize_parameters () < 0
+ || gdbpy_initialize_types () < 0
+ || gdbpy_initialize_pspace () < 0
+ || gdbpy_initialize_objfile () < 0
+ || gdbpy_initialize_breakpoints () < 0
+ || gdbpy_initialize_finishbreakpoints () < 0
+ || gdbpy_initialize_lazy_string () < 0
+ || gdbpy_initialize_thread () < 0
+ || gdbpy_initialize_inferior () < 0
+ || gdbpy_initialize_events () < 0
+ || gdbpy_initialize_eventregistry () < 0
+ || gdbpy_initialize_py_events () < 0
+ || gdbpy_initialize_event () < 0
+ || gdbpy_initialize_stop_event () < 0
+ || gdbpy_initialize_signal_event () < 0
+ || gdbpy_initialize_breakpoint_event () < 0
+ || gdbpy_initialize_continue_event () < 0
+ || gdbpy_initialize_exited_event () < 0
+ || gdbpy_initialize_thread_event () < 0
+ || gdbpy_initialize_new_objfile_event () < 0
+ || gdbpy_initialize_arch () < 0)
+ goto fail;
observer_attach_before_prompt (before_prompt_hook);
gdbpy_to_string_cst = PyString_FromString ("to_string");
+ if (gdbpy_to_string_cst == NULL)
+ goto fail;
gdbpy_children_cst = PyString_FromString ("children");
+ if (gdbpy_children_cst == NULL)
+ goto fail;
gdbpy_display_hint_cst = PyString_FromString ("display_hint");
+ if (gdbpy_display_hint_cst == NULL)
+ goto fail;
gdbpy_doc_cst = PyString_FromString ("__doc__");
+ if (gdbpy_doc_cst == NULL)
+ goto fail;
gdbpy_enabled_cst = PyString_FromString ("enabled");
+ if (gdbpy_enabled_cst == NULL)
+ goto fail;
gdbpy_value_cst = PyString_FromString ("value");
+ if (gdbpy_value_cst == NULL)
+ goto fail;
/* Release the GIL while gdb runs. */
PyThreadState_Swap (NULL);
PyEval_ReleaseLock ();
make_final_cleanup (finalize_python, NULL);
+
+ gdb_python_initialized = 1;
+ return;
+
+ fail:
+ gdbpy_print_stack ();
+ /* Do not set 'gdb_python_initialized'. */
+ return;
+
#endif /* HAVE_PYTHON */
}
--
1.8.1.4
^ permalink raw reply [flat|nested] 66+ messages in thread* [PATCH 18/28] check gdb_python_initialized everywhere
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
` (18 preceding siblings ...)
2013-04-19 14:47 ` [PATCH 17/28] convert python init functions to do error-checking Tom Tromey
@ 2013-04-19 15:40 ` Tom Tromey
2013-04-23 1:09 ` Tom Tromey
2013-04-19 16:20 ` [PATCH 19/28] add missing decref in py-param.c Tom Tromey
` (10 subsequent siblings)
30 siblings, 1 reply; 66+ messages in thread
From: Tom Tromey @ 2013-04-19 15:40 UTC (permalink / raw)
To: gdb-patches
This patch changes the rest of gdb to use gdb_python_initialized. It
also changes ensure_python_env to throw an exception if Python is not
initialized. In some spots no other checks were needed -- there is no
way to reach some of the calls to ensure_python_env unless some
previous call into Python was made.
value_get_print_value had to be reindented, which is why that part of
the patch looks odd.
While sending out the series I realized I had meant to write a test case
for this patch but forgot to. I will hold on to this one until I write
it.
* mi/mi-main.c: Include python-internal.h.
(mi_cmd_list_features): Check gdb_python_initialized.
* python/py-inferior.c (python_on_normal_stop, python_on_resume)
(python_inferior_exit, python_new_objfile, add_thread_object)
(delete_thread_object, py_free_inferior): Check
gdb_python_initialized.
* python/py-prettyprint.c (apply_val_pretty_printer): Check
gdb_python_initialized.
* python/py-type.c (save_objfile_types): Check
gdb_python_initialized.
* python/python-internal.h (gdb_python_initialized): Declare.
* python/python.c (ensure_python_env): Throw exception if
Python not initialized.
(before_prompt_hook, source_python_script_for_objfile)
(start_type_printers, apply_type_printers,
free_type_printers): Check gdb_python_initialized.
* varobj.c (varobj_get_display_hint)
(dynamic_varobj_has_child_method, update_dynamic_varobj_children)
(install_new_value_visualizer, varobj_set_visualizer)
(value_get_print_value): Check gdb_python_initialized.
---
gdb/mi/mi-main.c | 6 +-
gdb/python/py-inferior.c | 21 +++++
gdb/python/py-prettyprint.c | 3 +
gdb/python/py-type.c | 3 +
gdb/python/python-internal.h | 2 +
gdb/python/python.c | 19 +++++
gdb/varobj.c | 182 ++++++++++++++++++++++++-------------------
7 files changed, 153 insertions(+), 83 deletions(-)
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 94fda8f..9428e8c 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -52,6 +52,9 @@
#include "ctf.h"
#include "ada-lang.h"
#include "linespec.h"
+#ifdef HAVE_PYTHON
+#include "python/python-internal.h"
+#endif
#include <ctype.h>
#include <sys/time.h>
@@ -1757,7 +1760,8 @@ mi_cmd_list_features (char *command, char **argv, int argc)
ui_out_field_string (uiout, NULL, "ada-task-info");
#if HAVE_PYTHON
- ui_out_field_string (uiout, NULL, "python");
+ if (gdb_python_initialized)
+ ui_out_field_string (uiout, NULL, "python");
#endif
do_cleanups (cleanup);
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index b11d786..1ab58e6 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -85,6 +85,9 @@ python_on_normal_stop (struct bpstats *bs, int print_frame)
struct cleanup *cleanup;
enum gdb_signal stop_signal;
+ if (!gdb_python_initialized)
+ return;
+
if (!find_thread_ptid (inferior_ptid))
return;
@@ -103,6 +106,9 @@ python_on_resume (ptid_t ptid)
{
struct cleanup *cleanup;
+ if (!gdb_python_initialized)
+ return;
+
cleanup = ensure_python_env (target_gdbarch (), current_language);
if (emit_continue_event (ptid) < 0)
@@ -117,6 +123,9 @@ python_inferior_exit (struct inferior *inf)
struct cleanup *cleanup;
const LONGEST *exit_code = NULL;
+ if (!gdb_python_initialized)
+ return;
+
cleanup = ensure_python_env (target_gdbarch (), current_language);
if (inf->has_exit_code)
@@ -139,6 +148,9 @@ python_new_objfile (struct objfile *objfile)
if (objfile == NULL)
return;
+ if (!gdb_python_initialized)
+ return;
+
cleanup = ensure_python_env (get_objfile_arch (objfile), current_language);
if (emit_new_objfile_event (objfile) < 0)
@@ -231,6 +243,9 @@ add_thread_object (struct thread_info *tp)
inferior_object *inf_obj;
struct threadlist_entry *entry;
+ if (!gdb_python_initialized)
+ return;
+
cleanup = ensure_python_env (python_gdbarch, python_language);
thread_obj = create_thread_object (tp);
@@ -260,6 +275,9 @@ delete_thread_object (struct thread_info *tp, int ignore)
inferior_object *inf_obj;
struct threadlist_entry **entry, *tmp;
+ if (!gdb_python_initialized)
+ return;
+
cleanup = ensure_python_env (python_gdbarch, python_language);
inf_obj = (inferior_object *) find_inferior_object (PIDGET(tp->ptid));
@@ -728,6 +746,9 @@ py_free_inferior (struct inferior *inf, void *datum)
inferior_object *inf_obj = datum;
struct threadlist_entry *th_entry, *th_tmp;
+ if (!gdb_python_initialized)
+ return;
+
cleanup = ensure_python_env (python_gdbarch, python_language);
inf_obj->inferior = NULL;
diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
index dbf6c22..c337334 100644
--- a/gdb/python/py-prettyprint.c
+++ b/gdb/python/py-prettyprint.c
@@ -708,6 +708,9 @@ apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
if (!value_bytes_available (val, embedded_offset, TYPE_LENGTH (type)))
return 0;
+ if (!gdb_python_initialized)
+ return 0;
+
cleanups = ensure_python_env (gdbarch, language);
/* Instantiate the printer. */
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 05e251b..dd3a751 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -1192,6 +1192,9 @@ save_objfile_types (struct objfile *objfile, void *datum)
htab_t copied_types;
struct cleanup *cleanup;
+ if (!gdb_python_initialized)
+ return;
+
/* This prevents another thread from freeing the objects we're
operating on. */
cleanup = ensure_python_env (get_objfile_arch (objfile), current_language);
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 63d020d..4a9405f 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -183,6 +183,8 @@ struct program_space;
struct bpstats;
struct inferior;
+extern int gdb_python_initialized;
+
extern PyObject *gdb_module;
extern PyObject *gdb_python_module;
extern PyTypeObject value_object_type
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 51f8cd5..a7b1b44 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -150,6 +150,10 @@ ensure_python_env (struct gdbarch *gdbarch,
{
struct python_env *env = xmalloc (sizeof *env);
+ /* We should not ever enter Python unless initialized. */
+ if (!gdb_python_initialized)
+ error (_("Python not initialized"));
+
env->state = PyGILState_Ensure ();
env->gdbarch = python_gdbarch;
env->language = python_language;
@@ -896,6 +900,9 @@ before_prompt_hook (const char *current_gdb_prompt)
struct cleanup *cleanup;
char *prompt = NULL;
+ if (!gdb_python_initialized)
+ return;
+
cleanup = ensure_python_env (get_current_arch (), current_language);
if (gdb_python_module
@@ -1159,6 +1166,9 @@ source_python_script_for_objfile (struct objfile *objfile, FILE *file,
{
struct cleanup *cleanups;
+ if (!gdb_python_initialized)
+ return;
+
cleanups = ensure_python_env (get_objfile_arch (objfile), current_language);
gdbpy_current_objfile = objfile;
@@ -1220,6 +1230,9 @@ start_type_printers (void)
struct cleanup *cleanups;
PyObject *type_module, *func, *result_obj = NULL;
+ if (!gdb_python_initialized)
+ return NULL;
+
cleanups = ensure_python_env (get_current_arch (), current_language);
type_module = PyImport_ImportModule ("gdb.types");
@@ -1266,6 +1279,9 @@ apply_type_printers (void *printers, struct type *type)
if (printers_obj == NULL)
return NULL;
+ if (!gdb_python_initialized)
+ return NULL;
+
cleanups = ensure_python_env (get_current_arch (), current_language);
type_obj = type_to_type_object (type);
@@ -1324,6 +1340,9 @@ free_type_printers (void *arg)
if (printers == NULL)
return;
+ if (!gdb_python_initialized)
+ return;
+
cleanups = ensure_python_env (get_current_arch (), current_language);
Py_DECREF (printers);
do_cleanups (cleanups);
diff --git a/gdb/varobj.c b/gdb/varobj.c
index 467e59a..70ed28f 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -935,7 +935,12 @@ varobj_get_display_hint (struct varobj *var)
char *result = NULL;
#if HAVE_PYTHON
- struct cleanup *back_to = varobj_ensure_python_env (var);
+ struct cleanup *back_to;
+
+ if (!gdb_python_initialized)
+ return NULL;
+
+ back_to = varobj_ensure_python_env (var);
if (var->pretty_printer)
result = gdbpy_get_display_hint (var->pretty_printer);
@@ -1067,6 +1072,9 @@ dynamic_varobj_has_child_method (struct varobj *var)
PyObject *printer = var->pretty_printer;
int result;
+ if (!gdb_python_initialized)
+ return 0;
+
back_to = varobj_ensure_python_env (var);
result = PyObject_HasAttr (printer, gdbpy_children_cst);
do_cleanups (back_to);
@@ -1092,6 +1100,9 @@ update_dynamic_varobj_children (struct varobj *var,
int i;
PyObject *printer = var->pretty_printer;
+ if (!gdb_python_initialized)
+ return 0;
+
back_to = varobj_ensure_python_env (var);
*cchanged = 0;
@@ -1623,6 +1634,9 @@ install_new_value_visualizer (struct varobj *var)
#if HAVE_PYTHON
/* If the constructor is None, then we want the raw value. If VAR
does not have a value, just skip this. */
+ if (!gdb_python_initialized)
+ return;
+
if (var->constructor != Py_None && var->value)
{
struct cleanup *cleanup;
@@ -1899,6 +1913,9 @@ varobj_set_visualizer (struct varobj *var, const char *visualizer)
PyObject *mainmod, *globals, *constructor;
struct cleanup *back_to;
+ if (!gdb_python_initialized)
+ return;
+
back_to = varobj_ensure_python_env (var);
mainmod = PyImport_AddModule ("__main__");
@@ -2862,92 +2879,93 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
gdbarch = get_type_arch (value_type (value));
#if HAVE_PYTHON
- {
- PyObject *value_formatter = var->pretty_printer;
+ if (gdb_python_initialized)
+ {
+ PyObject *value_formatter = var->pretty_printer;
- varobj_ensure_python_env (var);
+ varobj_ensure_python_env (var);
- if (value_formatter)
- {
- /* First check to see if we have any children at all. If so,
- we simply return {...}. */
- if (dynamic_varobj_has_child_method (var))
- {
- do_cleanups (old_chain);
- return xstrdup ("{...}");
- }
+ if (value_formatter)
+ {
+ /* First check to see if we have any children at all. If so,
+ we simply return {...}. */
+ if (dynamic_varobj_has_child_method (var))
+ {
+ do_cleanups (old_chain);
+ return xstrdup ("{...}");
+ }
- if (PyObject_HasAttr (value_formatter, gdbpy_to_string_cst))
- {
- struct value *replacement;
- PyObject *output = NULL;
+ if (PyObject_HasAttr (value_formatter, gdbpy_to_string_cst))
+ {
+ struct value *replacement;
+ PyObject *output = NULL;
- output = apply_varobj_pretty_printer (value_formatter,
- &replacement,
- stb);
+ output = apply_varobj_pretty_printer (value_formatter,
+ &replacement,
+ stb);
- /* If we have string like output ... */
- if (output)
- {
- make_cleanup_py_decref (output);
-
- /* If this is a lazy string, extract it. For lazy
- strings we always print as a string, so set
- string_print. */
- if (gdbpy_is_lazy_string (output))
- {
- gdbpy_extract_lazy_string (output, &str_addr, &type,
- &len, &encoding);
- make_cleanup (free_current_contents, &encoding);
- string_print = 1;
- }
- else
- {
- /* If it is a regular (non-lazy) string, extract
- it and copy the contents into THEVALUE. If the
- hint says to print it as a string, set
- string_print. Otherwise just return the extracted
- string as a value. */
-
- char *s = python_string_to_target_string (output);
-
- if (s)
- {
- char *hint;
-
- hint = gdbpy_get_display_hint (value_formatter);
- if (hint)
- {
- if (!strcmp (hint, "string"))
- string_print = 1;
- xfree (hint);
- }
-
- len = strlen (s);
- thevalue = xmemdup (s, len + 1, len + 1);
- type = builtin_type (gdbarch)->builtin_char;
- xfree (s);
-
- if (!string_print)
- {
- do_cleanups (old_chain);
- return thevalue;
- }
-
- make_cleanup (xfree, thevalue);
- }
- else
- gdbpy_print_stack ();
- }
- }
- /* If the printer returned a replacement value, set VALUE
- to REPLACEMENT. If there is not a replacement value,
- just use the value passed to this function. */
- if (replacement)
- value = replacement;
- }
- }
- }
+ /* If we have string like output ... */
+ if (output)
+ {
+ make_cleanup_py_decref (output);
+
+ /* If this is a lazy string, extract it. For lazy
+ strings we always print as a string, so set
+ string_print. */
+ if (gdbpy_is_lazy_string (output))
+ {
+ gdbpy_extract_lazy_string (output, &str_addr, &type,
+ &len, &encoding);
+ make_cleanup (free_current_contents, &encoding);
+ string_print = 1;
+ }
+ else
+ {
+ /* If it is a regular (non-lazy) string, extract
+ it and copy the contents into THEVALUE. If the
+ hint says to print it as a string, set
+ string_print. Otherwise just return the extracted
+ string as a value. */
+
+ char *s = python_string_to_target_string (output);
+
+ if (s)
+ {
+ char *hint;
+
+ hint = gdbpy_get_display_hint (value_formatter);
+ if (hint)
+ {
+ if (!strcmp (hint, "string"))
+ string_print = 1;
+ xfree (hint);
+ }
+
+ len = strlen (s);
+ thevalue = xmemdup (s, len + 1, len + 1);
+ type = builtin_type (gdbarch)->builtin_char;
+ xfree (s);
+
+ if (!string_print)
+ {
+ do_cleanups (old_chain);
+ return thevalue;
+ }
+
+ make_cleanup (xfree, thevalue);
+ }
+ else
+ gdbpy_print_stack ();
+ }
+ }
+ /* If the printer returned a replacement value, set VALUE
+ to REPLACEMENT. If there is not a replacement value,
+ just use the value passed to this function. */
+ if (replacement)
+ value = replacement;
+ }
+ }
+ }
#endif
get_formatted_print_options (&opts, format_code[(int) format]);
--
1.8.1.4
^ permalink raw reply [flat|nested] 66+ messages in thread* Re: [PATCH 18/28] check gdb_python_initialized everywhere
2013-04-19 15:40 ` [PATCH 18/28] check gdb_python_initialized everywhere Tom Tromey
@ 2013-04-23 1:09 ` Tom Tromey
2013-05-07 17:57 ` Doug Evans
2013-05-21 8:22 ` new FAIL python-selftest.exp in gdbserver mode [Re: [PATCH 18/28] check gdb_python_initialized everywhere] Jan Kratochvil
0 siblings, 2 replies; 66+ messages in thread
From: Tom Tromey @ 2013-04-23 1:09 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 471 bytes --]
>>>>> "Tom" == Tom Tromey <tromey@redhat.com> writes:
Tom> While sending out the series I realized I had meant to write a test case
Tom> for this patch but forgot to. I will hold on to this one until I write
Tom> it.
This required a two-part series.
The first patch just cleans up the existing gdb.gdb tests to remove
duplication and to make it simpler to add new tests here.
The second patch is the actual test case.
Built and regtested on x86-64 Fedora 18.
Tom
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: consolidate some code in gdb.gdb --]
[-- Type: text/x-patch, Size: 21003 bytes --]
From 7b014fea57c4efd58feed859337e7cbb6e98255b Mon Sep 17 00:00:00 2001
From: Tom Tromey <tromey@redhat.com>
Date: Mon, 22 Apr 2013 11:50:35 -0600
Subject: [PATCH 32/33] consolidate some code in gdb.gdb
This patch consolidates some code in gdb.gdb. This makes it simpler
to add new self-tests.
* lib/selftest-support.exp: New file.
* gdb.gdb/complaints.exp: Load selftest-support.exp. Use
do_self_tests.
(setup_test, find_gdb): Remove.
* gdb.gdb/observer.exp: Load selftest-support.exp. Use
do_self_tests.
(setup_test, find_gdb): Remove.
(test_observer): Don't call setup_test. Remove argument.
* gdb.gdb/selftest.exp: Load selftest-support.exp.
(find_gdb): Remove.
* gdb.gdb/complaints.exp: Load selftest-support.exp. Use
do_self_tests.
(setup_test, find_gdb): Remove.
(test_with_self): Don't call setup_test. Remove argument.
---
gdb/testsuite/gdb.gdb/complaints.exp | 126 ++---------------------------
gdb/testsuite/gdb.gdb/observer.exp | 125 +---------------------------
gdb/testsuite/gdb.gdb/selftest.exp | 24 +-----
gdb/testsuite/gdb.gdb/xfullpath.exp | 125 +---------------------------
gdb/testsuite/lib/selftest-support.exp | 144 +++++++++++++++++++++++++++++++++
5 files changed, 157 insertions(+), 387 deletions(-)
create mode 100644 gdb/testsuite/lib/selftest-support.exp
diff --git a/gdb/testsuite/gdb.gdb/complaints.exp b/gdb/testsuite/gdb.gdb/complaints.exp
index f298725..932dfd5 100644
--- a/gdb/testsuite/gdb.gdb/complaints.exp
+++ b/gdb/testsuite/gdb.gdb/complaints.exp
@@ -17,6 +17,7 @@
# derived from xfullpath.exp (written by Joel Brobecker), derived from
# selftest.exp (written by Rob Savoye).
+load_lib selftest-support.exp
# are we on a target board
if { [is_remote target] || ![isnative] } then {
@@ -28,79 +29,6 @@ if [target_info exists gdb,noinferiorio] {
return
}
-proc setup_test { executable } {
- global gdb_prompt
- global timeout
- global INTERNAL_GDBFLAGS
-
- # load yourself into the debugger
- # This can take a relatively long time, particularly for testing where
- # the executable is being accessed over a network, or where gdb does not
- # support partial symbols for a particular target and has to load the
- # entire symbol table. Set the timeout to 10 minutes, which should be
- # adequate for most environments (it *has* timed out with 5 min on a
- # SPARCstation SLC under moderate load, so this isn't unreasonable).
- # After gdb is started, set the timeout to 30 seconds for the duration
- # of this test, and then back to the original value.
-
- set oldtimeout $timeout
- set timeout 600
- verbose "Timeout is now $timeout seconds" 2
-
- global gdb_file_cmd_debug_info
- set gdb_file_cmd_debug_info "unset"
-
- set result [gdb_load $executable]
- set timeout $oldtimeout
- verbose "Timeout is now $timeout seconds" 2
-
- if { $result != 0 } then {
- return -1
- }
-
- if { $gdb_file_cmd_debug_info != "debug" } then {
- untested "No debug information, skipping testcase."
- return -1
- }
-
- # Set a breakpoint at main
- gdb_test "break captured_command_loop" \
- "Breakpoint.*at.* file.*, line.*" \
- "breakpoint in captured_command_loop"
-
- # run yourself
- # It may take a very long time for the inferior gdb to start (lynx),
- # so we bump it back up for the duration of this command.
- set timeout 600
-
- set description "run until breakpoint at captured_command_loop"
- gdb_test_multiple "run $INTERNAL_GDBFLAGS" "$description" {
- -re "Starting program.*Breakpoint \[0-9\]+,.*captured_command_loop .data.* at .*main.c:.*$gdb_prompt $" {
- pass "$description"
- }
- -re "Starting program.*Breakpoint \[0-9\]+,.*captured_command_loop .data.*$gdb_prompt $" {
- xfail "$description (line numbers scrambled?)"
- }
- -re "vfork: No more processes.*$gdb_prompt $" {
- fail "$description (out of virtual memory)"
- set timeout $oldtimeout
- verbose "Timeout is now $timeout seconds" 2
- return -1
- }
- -re ".*$gdb_prompt $" {
- fail "$description"
- set timeout $oldtimeout
- verbose "Timeout is now $timeout seconds" 2
- return -1
- }
- }
-
- set timeout $oldtimeout
- verbose "Timeout is now $timeout seconds" 2
-
- return 0
-}
-
proc test_initial_complaints { } {
global gdb_prompt
@@ -221,51 +149,9 @@ proc test_empty_complaints { } {
return 0
}
-# Find a pathname to a file that we would execute if the shell was asked
-# to run $arg using the current PATH.
-
-proc find_gdb { arg } {
-
- # If the arg directly specifies an existing executable file, then
- # simply use it.
-
- if [file executable $arg] then {
- return $arg
- }
-
- set result [which $arg]
- if [string match "/" [ string range $result 0 0 ]] then {
- return $result
- }
-
- # If everything fails, just return the unqualified pathname as default
- # and hope for best.
-
- return $arg
-}
-
-# Run the test with self.
-# Copy the file executable file in case this OS doesn't like to edit its own
-# text space.
-
-set GDB_FULLPATH [find_gdb $GDB]
-
-# Remove any old copy lying around.
-remote_file host delete x$tool
-
-gdb_start
-
-set file [remote_download host $GDB_FULLPATH x$tool]
-
-set setup_result [setup_test $file ]
-if {$setup_result <0} then {
- return -1
+do_self_tests captured_command_loop {
+ test_initial_complaints
+ test_serial_complaints
+ test_short_complaints
+ test_empty_complaints
}
-
-test_initial_complaints
-test_serial_complaints
-test_short_complaints
-test_empty_complaints
-
-gdb_exit;
-catch "remote_file host delete $file";
diff --git a/gdb/testsuite/gdb.gdb/observer.exp b/gdb/testsuite/gdb.gdb/observer.exp
index 9397146..32030d8 100644
--- a/gdb/testsuite/gdb.gdb/observer.exp
+++ b/gdb/testsuite/gdb.gdb/observer.exp
@@ -16,85 +16,13 @@
# This file was written by Joel Brobecker (brobecker@gnat.com), derived
# from xfullpath.exp.
+load_lib selftest-support.exp
# are we on a target board
if { [is_remote target] || ![isnative] } then {
return
}
-proc setup_test { executable } {
- global gdb_prompt
- global timeout
- global INTERNAL_GDBFLAGS
-
- # load yourself into the debugger
- # This can take a relatively long time, particularly for testing where
- # the executable is being accessed over a network, or where gdb does not
- # support partial symbols for a particular target and has to load the
- # entire symbol table. Set the timeout to 10 minutes, which should be
- # adequate for most environments (it *has* timed out with 5 min on a
- # SPARCstation SLC under moderate load, so this isn't unreasonable).
- # After gdb is started, set the timeout to 30 seconds for the duration
- # of this test, and then back to the original value.
-
- set oldtimeout $timeout
- set timeout 600
- verbose "Timeout is now $timeout seconds" 2
-
- global gdb_file_cmd_debug_info
- set gdb_file_cmd_debug_info "unset"
-
- set result [gdb_load $executable]
- set timeout $oldtimeout
- verbose "Timeout is now $timeout seconds" 2
-
- if { $result != 0 } then {
- return -1
- }
-
- if { $gdb_file_cmd_debug_info != "debug" } then {
- untested "No debug information, skipping testcase."
- return -1
- }
-
- # Set a breakpoint at main
- gdb_test "break captured_main" \
- "Breakpoint.*at.* file.*, line.*" \
- "breakpoint in captured_main"
-
- # run yourself
- # It may take a very long time for the inferior gdb to start (lynx),
- # so we bump it back up for the duration of this command.
- set timeout 600
-
- set description "run until breakpoint at captured_main"
- gdb_test_multiple "run $INTERNAL_GDBFLAGS" "$description" {
- -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.* at .*main.c:.*$gdb_prompt $" {
- pass "$description"
- }
- -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.*$gdb_prompt $" {
- xfail "$description (line numbers scrambled?)"
- }
- -re "vfork: No more processes.*$gdb_prompt $" {
- fail "$description (out of virtual memory)"
- set timeout $oldtimeout
- verbose "Timeout is now $timeout seconds" 2
- return -1
- }
- -re ".*$gdb_prompt $" {
- fail "$description"
- set timeout $oldtimeout
- verbose "Timeout is now $timeout seconds" 2
- return -1
- }
- }
-
- set timeout $oldtimeout
- verbose "Timeout is now $timeout seconds" 2
-
- return 0
-}
-
proc attach_first_observer { message } {
gdb_test_no_output "set \$first_obs = observer_attach_test_notification (&observer_test_first_notification_function)" \
"$message; attach first observer"
@@ -160,13 +88,7 @@ proc test_notifications { first second third message args } {
check_counters $first $second $third $message
}
-proc test_observer { executable } {
-
- set setup_result [setup_test $executable]
- if {$setup_result <0} then {
- return -1
- }
-
+proc test_observer {} {
# First, try sending a notification without any observer attached.
test_notifications 0 0 0 "no observer attached"
@@ -223,45 +145,4 @@ proc test_observer { executable } {
return 0
}
-# Find a pathname to a file that we would execute if the shell was asked
-# to run $arg using the current PATH.
-
-proc find_gdb { arg } {
-
- # If the arg directly specifies an existing executable file, then
- # simply use it.
-
- if [file executable $arg] then {
- return $arg
- }
-
- set result [which $arg]
- if [string match "/" [ string range $result 0 0 ]] then {
- return $result
- }
-
- # If everything fails, just return the unqualified pathname as default
- # and hope for best.
-
- return $arg
-}
-
-# Run the test with self.
-# Copy the file executable file in case this OS doesn't like to edit its own
-# text space.
-
-set GDB_FULLPATH [find_gdb $GDB]
-
-# Remove any old copy lying around.
-remote_file host delete x$tool
-
-gdb_start
-set file [remote_download host $GDB_FULLPATH x$tool]
-set result [test_observer $file];
-gdb_exit;
-catch "remote_file host delete $file";
-
-if {$result <0} then {
- warning "Couldn't test self"
- return -1
-}
+do_self_tests captured_main test_observer
diff --git a/gdb/testsuite/gdb.gdb/selftest.exp b/gdb/testsuite/gdb.gdb/selftest.exp
index 55e13cf..b3350fa 100644
--- a/gdb/testsuite/gdb.gdb/selftest.exp
+++ b/gdb/testsuite/gdb.gdb/selftest.exp
@@ -15,6 +15,7 @@
# This file was written by Rob Savoye. (rob@cygnus.com)
+load_lib selftest-support.exp
# are we on a target board
if { [is_remote target] || ![isnative] } then {
@@ -468,29 +469,6 @@ proc test_with_self { executable } {
return 0
}
-# Find a pathname to a file that we would execute if the shell was asked
-# to run $arg using the current PATH.
-
-proc find_gdb { arg } {
-
- # If the arg directly specifies an existing executable file, then
- # simply use it.
-
- if [file executable $arg] then {
- return $arg
- }
-
- set result [which $arg]
- if [string match "/" [ string range $result 0 0 ]] then {
- return $result
- }
-
- # If everything fails, just return the unqualified pathname as default
- # and hope for best.
-
- return $arg
-}
-
# Run the test with self.
# Copy the file executable file in case this OS doesn't like to edit its own
# text space.
diff --git a/gdb/testsuite/gdb.gdb/xfullpath.exp b/gdb/testsuite/gdb.gdb/xfullpath.exp
index 9516a4f..5bc01c6 100644
--- a/gdb/testsuite/gdb.gdb/xfullpath.exp
+++ b/gdb/testsuite/gdb.gdb/xfullpath.exp
@@ -16,92 +16,14 @@
# This file was written by Joel Brobecker. (brobecker@gnat.com), derived
# from selftest.exp, written by Rob Savoye.
+load_lib selftest-support.exp
# are we on a target board
if { [is_remote target] || ![isnative] } then {
return
}
-proc setup_test { executable } {
- global gdb_prompt
- global timeout
- global INTERNAL_GDBFLAGS
-
- # load yourself into the debugger
- # This can take a relatively long time, particularly for testing where
- # the executable is being accessed over a network, or where gdb does not
- # support partial symbols for a particular target and has to load the
- # entire symbol table. Set the timeout to 10 minutes, which should be
- # adequate for most environments (it *has* timed out with 5 min on a
- # SPARCstation SLC under moderate load, so this isn't unreasonable).
- # After gdb is started, set the timeout to 30 seconds for the duration
- # of this test, and then back to the original value.
-
- set oldtimeout $timeout
- set timeout 600
- verbose "Timeout is now $timeout seconds" 2
-
- global gdb_file_cmd_debug_info
- set gdb_file_cmd_debug_info "unset"
-
- set result [gdb_load $executable]
- set timeout $oldtimeout
- verbose "Timeout is now $timeout seconds" 2
-
- if { $result != 0 } then {
- return -1
- }
-
- if { $gdb_file_cmd_debug_info != "debug" } then {
- untested "No debug information, skipping testcase."
- return -1
- }
-
- # Set a breakpoint at main
- gdb_test "break captured_main" \
- "Breakpoint.*at.* file.*, line.*" \
- "breakpoint in captured_main"
-
- # run yourself
- # It may take a very long time for the inferior gdb to start (lynx),
- # so we bump it back up for the duration of this command.
- set timeout 600
-
- set description "run until breakpoint at captured_main"
- gdb_test_multiple "run $INTERNAL_GDBFLAGS" "$description" {
- -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.* at .*main.c:.*$gdb_prompt $" {
- pass "$description"
- }
- -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.*$gdb_prompt $" {
- xfail "$description (line numbers scrambled?)"
- }
- -re "vfork: No more processes.*$gdb_prompt $" {
- fail "$description (out of virtual memory)"
- set timeout $oldtimeout
- verbose "Timeout is now $timeout seconds" 2
- return -1
- }
- -re ".*$gdb_prompt $" {
- fail "$description"
- set timeout $oldtimeout
- verbose "Timeout is now $timeout seconds" 2
- return -1
- }
- }
-
- set timeout $oldtimeout
- verbose "Timeout is now $timeout seconds" 2
-
- return 0
-}
-
-proc test_with_self { executable } {
-
- set setup_result [setup_test $executable]
- if {$setup_result <0} then {
- return -1
- }
-
+proc test_with_self {} {
# A file which contains a directory prefix
gdb_test "print gdb_realpath (\"./xfullpath.exp\")" \
".\[0-9\]+ =.*\".*/xfullpath.exp\"" \
@@ -140,45 +62,4 @@ proc test_with_self { executable } {
return 0
}
-# Find a pathname to a file that we would execute if the shell was asked
-# to run $arg using the current PATH.
-
-proc find_gdb { arg } {
-
- # If the arg directly specifies an existing executable file, then
- # simply use it.
-
- if [file executable $arg] then {
- return $arg
- }
-
- set result [which $arg]
- if [string match "/" [ string range $result 0 0 ]] then {
- return $result
- }
-
- # If everything fails, just return the unqualified pathname as default
- # and hope for best.
-
- return $arg
-}
-
-# Run the test with self.
-# Copy the file executable file in case this OS doesn't like to edit its own
-# text space.
-
-set GDB_FULLPATH [find_gdb $GDB]
-
-# Remove any old copy lying around.
-remote_file host delete x$tool
-
-gdb_start
-set file [remote_download host $GDB_FULLPATH x$tool]
-set result [test_with_self $file];
-gdb_exit;
-catch "remote_file host delete $file";
-
-if {$result <0} then {
- warning "Couldn't test self"
- return -1
-}
+do_self_tests captured_main test_with_self
diff --git a/gdb/testsuite/lib/selftest-support.exp b/gdb/testsuite/lib/selftest-support.exp
new file mode 100644
index 0000000..c375849
--- /dev/null
+++ b/gdb/testsuite/lib/selftest-support.exp
@@ -0,0 +1,144 @@
+# Copyright 2003-2013 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Find a pathname to a file that we would execute if the shell was asked
+# to run $arg using the current PATH.
+
+proc find_gdb { arg } {
+
+ # If the arg directly specifies an existing executable file, then
+ # simply use it.
+
+ if [file executable $arg] then {
+ return $arg
+ }
+
+ set result [which $arg]
+ if [string match "/" [ string range $result 0 0 ]] then {
+ return $result
+ }
+
+ # If everything fails, just return the unqualified pathname as default
+ # and hope for best.
+
+ return $arg
+}
+
+# A helper proc that sets up for self-testing.
+# EXECUTABLE is the gdb to use.
+# FUNCTION is the function to break in, either captured_main
+# or captured_command_loop.
+
+proc selftest_setup { executable function } {
+ global gdb_prompt
+ global timeout
+ global INTERNAL_GDBFLAGS
+
+ # load yourself into the debugger
+ # This can take a relatively long time, particularly for testing where
+ # the executable is being accessed over a network, or where gdb does not
+ # support partial symbols for a particular target and has to load the
+ # entire symbol table. Set the timeout to 10 minutes, which should be
+ # adequate for most environments (it *has* timed out with 5 min on a
+ # SPARCstation SLC under moderate load, so this isn't unreasonable).
+ # After gdb is started, set the timeout to 30 seconds for the duration
+ # of this test, and then back to the original value.
+
+ set oldtimeout $timeout
+ set timeout 600
+ verbose "Timeout is now $timeout seconds" 2
+
+ global gdb_file_cmd_debug_info
+ set gdb_file_cmd_debug_info "unset"
+
+ set result [gdb_load $executable]
+ set timeout $oldtimeout
+ verbose "Timeout is now $timeout seconds" 2
+
+ if { $result != 0 } then {
+ return -1
+ }
+
+ if { $gdb_file_cmd_debug_info != "debug" } then {
+ untested "No debug information, skipping testcase."
+ return -1
+ }
+
+ # Set a breakpoint at main
+ gdb_test "break $function" \
+ "Breakpoint.*at.* file.*, line.*" \
+ "breakpoint in $function"
+
+ # run yourself
+ # It may take a very long time for the inferior gdb to start (lynx),
+ # so we bump it back up for the duration of this command.
+ set timeout 600
+
+ set description "run until breakpoint at $function"
+ gdb_test_multiple "run $INTERNAL_GDBFLAGS" "$description" {
+ -re "Starting program.*Breakpoint \[0-9\]+,.*$function .data.* at .*main.c:.*$gdb_prompt $" {
+ pass "$description"
+ }
+ -re "Starting program.*Breakpoint \[0-9\]+,.*$function .data.*$gdb_prompt $" {
+ xfail "$description (line numbers scrambled?)"
+ }
+ -re "vfork: No more processes.*$gdb_prompt $" {
+ fail "$description (out of virtual memory)"
+ set timeout $oldtimeout
+ verbose "Timeout is now $timeout seconds" 2
+ return -1
+ }
+ -re ".*$gdb_prompt $" {
+ fail "$description"
+ set timeout $oldtimeout
+ verbose "Timeout is now $timeout seconds" 2
+ return -1
+ }
+ }
+
+ set timeout $oldtimeout
+ verbose "Timeout is now $timeout seconds" 2
+
+ return 0
+}
+
+# A simple way to run some self-tests.
+
+proc do_self_tests {function body} {
+ global GDB tool
+
+ # Run the test with self. Copy the file executable file in case
+ # this OS doesn't like to edit its own text space.
+
+ set GDB_FULLPATH [find_gdb $GDB]
+
+ # Remove any old copy lying around.
+ remote_file host delete x$tool
+
+ gdb_start
+ set file [remote_download host $GDB_FULLPATH x$tool]
+
+ set result [selftest_setup $file $function]
+ if {$result == 0} then {
+ set result [uplevel $body]
+ }
+
+ gdb_exit
+ catch "remote_file host delete $file"
+
+ if {$result < 0} then {
+ warning "Couldn't test self"
+ }
+}
--
1.8.1.4
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: add gdb_python_initialized test case --]
[-- Type: text/x-patch, Size: 1959 bytes --]
From 97555d151da89029f17b7e55bc62ff99ff77a545 Mon Sep 17 00:00:00 2001
From: Tom Tromey <tromey@redhat.com>
Date: Mon, 22 Apr 2013 12:11:11 -0600
Subject: [PATCH 33/33] add gdb_python_initialized test case
* gdb.gdb/python-selftest.exp: New file.
---
gdb/testsuite/gdb.gdb/python-selftest.exp | 34 +++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
create mode 100644 gdb/testsuite/gdb.gdb/python-selftest.exp
diff --git a/gdb/testsuite/gdb.gdb/python-selftest.exp b/gdb/testsuite/gdb.gdb/python-selftest.exp
new file mode 100644
index 0000000..71d5b61
--- /dev/null
+++ b/gdb/testsuite/gdb.gdb/python-selftest.exp
@@ -0,0 +1,34 @@
+# Copyright 2013 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# This file was written by Andrew Cagney (cagney at redhat dot com),
+# derived from xfullpath.exp (written by Joel Brobecker), derived from
+# selftest.exp (written by Rob Savoye).
+
+load_lib selftest-support.exp
+load_lib gdb-python.exp
+
+proc selftest_python {} {
+ if {[skip_python_tests]} {
+ return -1
+ }
+
+ gdb_test_no_output "set variable gdb_python_initialized = 0"
+ gdb_test "call catch_command_errors(execute_command, \"python print 5\", 0, RETURN_MASK_ALL)" \
+ "Python not initialized.* = 0"
+ return 0
+}
+
+do_self_tests captured_command_loop selftest_python
--
1.8.1.4
^ permalink raw reply [flat|nested] 66+ messages in thread* Re: [PATCH 18/28] check gdb_python_initialized everywhere
2013-04-23 1:09 ` Tom Tromey
@ 2013-05-07 17:57 ` Doug Evans
2013-05-07 18:06 ` Tom Tromey
2013-05-07 18:06 ` Doug Evans
2013-05-21 8:22 ` new FAIL python-selftest.exp in gdbserver mode [Re: [PATCH 18/28] check gdb_python_initialized everywhere] Jan Kratochvil
1 sibling, 2 replies; 66+ messages in thread
From: Doug Evans @ 2013-05-07 17:57 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On Mon, Apr 22, 2013 at 11:27 AM, Tom Tromey <tromey@redhat.com> wrote:
>>>>>> "Tom" == Tom Tromey <tromey@redhat.com> writes:
>
> Tom> While sending out the series I realized I had meant to write a test case
> Tom> for this patch but forgot to. I will hold on to this one until I write
> Tom> it.
>
> This required a two-part series.
>
> The first patch just cleans up the existing gdb.gdb tests to remove
> duplication and to make it simpler to add new tests here.
>
> The second patch is the actual test case.
>
> Built and regtested on x86-64 Fedora 18.
Hi.
I could use selftest-support in a test I'm writing.
Can you check this in?
TIA
^ permalink raw reply [flat|nested] 66+ messages in thread
* Re: [PATCH 18/28] check gdb_python_initialized everywhere
2013-05-07 17:57 ` Doug Evans
@ 2013-05-07 18:06 ` Tom Tromey
2013-05-07 18:06 ` Doug Evans
1 sibling, 0 replies; 66+ messages in thread
From: Tom Tromey @ 2013-05-07 18:06 UTC (permalink / raw)
To: Doug Evans; +Cc: gdb-patches
>>>>> "Doug" == Doug Evans <dje@google.com> writes:
Doug> I could use selftest-support in a test I'm writing.
Doug> Can you check this in?
Sure, I'm checking in the first patch from there now.
Tom
^ permalink raw reply [flat|nested] 66+ messages in thread
* Re: [PATCH 18/28] check gdb_python_initialized everywhere
2013-05-07 17:57 ` Doug Evans
2013-05-07 18:06 ` Tom Tromey
@ 2013-05-07 18:06 ` Doug Evans
2013-05-07 18:13 ` Tom Tromey
2013-05-15 16:43 ` Pedro Alves
1 sibling, 2 replies; 66+ messages in thread
From: Doug Evans @ 2013-05-07 18:06 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On Tue, May 7, 2013 at 10:57 AM, Doug Evans <dje@google.com> wrote:
> On Mon, Apr 22, 2013 at 11:27 AM, Tom Tromey <tromey@redhat.com> wrote:
>>>>>>> "Tom" == Tom Tromey <tromey@redhat.com> writes:
>>
>> Tom> While sending out the series I realized I had meant to write a test case
>> Tom> for this patch but forgot to. I will hold on to this one until I write
>> Tom> it.
>>
>> This required a two-part series.
>>
>> The first patch just cleans up the existing gdb.gdb tests to remove
>> duplication and to make it simpler to add new tests here.
>>
>> The second patch is the actual test case.
>>
>> Built and regtested on x86-64 Fedora 18.
>
> Hi.
> I could use selftest-support in a test I'm writing.
>
> Can you check this in?
> TIA
Blech. I never liked adding one's name to files.
The data is useless after a few years and does a disservice to all
those who come after.
I bring this up because this text in python-selftest.exp is completely bogus.
+# This file was written by Andrew Cagney (cagney at redhat dot com),
+# derived from xfullpath.exp (written by Joel Brobecker), derived from
+# selftest.exp (written by Rob Savoye).
^ permalink raw reply [flat|nested] 66+ messages in thread
* Re: [PATCH 18/28] check gdb_python_initialized everywhere
2013-05-07 18:06 ` Doug Evans
@ 2013-05-07 18:13 ` Tom Tromey
2013-05-15 16:43 ` Pedro Alves
1 sibling, 0 replies; 66+ messages in thread
From: Tom Tromey @ 2013-05-07 18:13 UTC (permalink / raw)
To: Doug Evans; +Cc: gdb-patches
>>>>> "Doug" == Doug Evans <dje@google.com> writes:
Doug> I bring this up because this text in python-selftest.exp is
Doug> completely bogus.
Hah. I'll fix it on the branch.
Tom
^ permalink raw reply [flat|nested] 66+ messages in thread
* Re: [PATCH 18/28] check gdb_python_initialized everywhere
2013-05-07 18:06 ` Doug Evans
2013-05-07 18:13 ` Tom Tromey
@ 2013-05-15 16:43 ` Pedro Alves
2013-05-15 17:39 ` Remove my name from a couple tests (Re: [PATCH 18/28] check gdb_python_initialized everywhere) Pedro Alves
1 sibling, 1 reply; 66+ messages in thread
From: Pedro Alves @ 2013-05-15 16:43 UTC (permalink / raw)
To: Doug Evans; +Cc: Tom Tromey, gdb-patches
On 05/07/2013 07:05 PM, Doug Evans wrote:
> On Tue, May 7, 2013 at 10:57 AM, Doug Evans <dje@google.com> wrote:
>> On Mon, Apr 22, 2013 at 11:27 AM, Tom Tromey <tromey@redhat.com> wrote:
>>>>>>>> "Tom" == Tom Tromey <tromey@redhat.com> writes:
>>>
>>> Tom> While sending out the series I realized I had meant to write a test case
>>> Tom> for this patch but forgot to. I will hold on to this one until I write
>>> Tom> it.
>>>
>>> This required a two-part series.
>>>
>>> The first patch just cleans up the existing gdb.gdb tests to remove
>>> duplication and to make it simpler to add new tests here.
>>>
>>> The second patch is the actual test case.
>>>
>>> Built and regtested on x86-64 Fedora 18.
>>
>> Hi.
>> I could use selftest-support in a test I'm writing.
>>
>> Can you check this in?
>> TIA
>
> Blech. I never liked adding one's name to files.
> The data is useless after a few years and does a disservice to all
> those who come after.
I agree. I see I ended up with my name mentioned in a
couple tests. I think I'll remove it.
I saw that glibc recently-ish started rejecting
submissions that included "contributed by"/"written by"/etc.
statements, even.
>
> I bring this up because this text in python-selftest.exp is completely bogus.
>
> +# This file was written by Andrew Cagney (cagney at redhat dot com),
> +# derived from xfullpath.exp (written by Joel Brobecker), derived from
> +# selftest.exp (written by Rob Savoye).
--
Pedro Alves
^ permalink raw reply [flat|nested] 66+ messages in thread
* Remove my name from a couple tests (Re: [PATCH 18/28] check gdb_python_initialized everywhere)
2013-05-15 16:43 ` Pedro Alves
@ 2013-05-15 17:39 ` Pedro Alves
0 siblings, 0 replies; 66+ messages in thread
From: Pedro Alves @ 2013-05-15 17:39 UTC (permalink / raw)
Cc: Doug Evans, Tom Tromey, gdb-patches
On 05/15/2013 05:43 PM, Pedro Alves wrote:
> On 05/07/2013 07:05 PM, Doug Evans wrote:
>> Blech. I never liked adding one's name to files.
>> The data is useless after a few years and does a disservice to all
>> those who come after.
>
> I agree. I see I ended up with my name mentioned in a
> couple tests. I think I'll remove it.
>
> I saw that glibc recently-ish started rejecting
> submissions that included "contributed by"/"written by"/etc.
> statements, even.
>
>>
>> I bring this up because this text in python-selftest.exp is completely bogus.
>>
>> +# This file was written by Andrew Cagney (cagney at redhat dot com),
>> +# derived from xfullpath.exp (written by Joel Brobecker), derived from
>> +# selftest.exp (written by Rob Savoye).
Done.
---
Remove my name from a couple tests.
Tested on x86_64 Fedora 17.
gdb/testsuite/
2013-05-15 Pedro Alves <palves@redhat.com>
* gdb.base/fixsection.c: Remove attribution.
* gdb.base/watch-read.exp: Ditto.
---
gdb/testsuite/gdb.base/fixsection.c | 4 +---
gdb/testsuite/gdb.base/watch-read.exp | 2 --
2 files changed, 1 insertion(+), 5 deletions(-)
diff --git a/gdb/testsuite/gdb.base/fixsection.c b/gdb/testsuite/gdb.base/fixsection.c
index d2eff9a..a55fd00 100644
--- a/gdb/testsuite/gdb.base/fixsection.c
+++ b/gdb/testsuite/gdb.base/fixsection.c
@@ -11,9 +11,7 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- This file was written by Pedro Alves (pedro@codesourcery.com). */
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <stdio.h>
#include <stdlib.h>
diff --git a/gdb/testsuite/gdb.base/watch-read.exp b/gdb/testsuite/gdb.base/watch-read.exp
index 0de28e5..9a5e388 100644
--- a/gdb/testsuite/gdb.base/watch-read.exp
+++ b/gdb/testsuite/gdb.base/watch-read.exp
@@ -15,8 +15,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-# This file was written by Pedro Alves <pedro@codesourcery.com>
-
# This file is part of the gdb testsuite.
#
^ permalink raw reply [flat|nested] 66+ messages in thread
* new FAIL python-selftest.exp in gdbserver mode [Re: [PATCH 18/28] check gdb_python_initialized everywhere]
2013-04-23 1:09 ` Tom Tromey
2013-05-07 17:57 ` Doug Evans
@ 2013-05-21 8:22 ` Jan Kratochvil
2013-06-17 16:59 ` RFC: fix python-selftest.exp failure (Was: new FAIL python-selftest.exp in gdbserver mode [Re: [PATCH 18/28] check gdb_python_initialized everywhere]) Tom Tromey
1 sibling, 1 reply; 66+ messages in thread
From: Jan Kratochvil @ 2013-05-21 8:22 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On Mon, 22 Apr 2013 20:27:53 +0200, Tom Tromey wrote:
> * gdb.gdb/python-selftest.exp: New file.
commit 35c1e5efc16caf256acb5c76df8f02a3f1de246e
Author: Tom Tromey <tromey@redhat.com>
Date: Mon May 20 20:43:28 2013 +0000
although the problem is in some of the testsuite/lib/ files.
in gdbserver mode:
Running gdb/testsuite/gdb.gdb/python-selftest.exp ...
PASS: gdb.gdb/python-selftest.exp: breakpoint in captured_command_loop
ERROR: tcl error sourcing gdb/testsuite/gdb.gdb/python-selftest.exp.
ERROR: gdbserver does not support run -nw -nx -data-directory /unsafegdb/testsuite.unix.-m64/../data-directory without extended-remote
while executing
"error "gdbserver does not support $command without extended-remote""
(procedure "gdb_test_multiple" line 23)
invoked from within
"gdb_test_multiple "run $INTERNAL_GDBFLAGS" "$description" {
-re "Starting program.*Breakpoint \[0-9\]+,.*$function .data.* at .*main.c:.*$gdb_..."
(procedure "selftest_setup" line 45)
invoked from within
"selftest_setup $file $function"
(procedure "do_self_tests" line 15)
invoked from within
"do_self_tests captured_command_loop selftest_python"
(file "gdb/testsuite/gdb.gdb/python-selftest.exp" line 30)
invoked from within
"source gdb/testsuite/gdb.gdb/python-selftest.exp"
("uplevel" body line 1)
invoked from within
"uplevel #0 source gdb/testsuite/gdb.gdb/python-selftest.exp"
invoked from within
"catch "uplevel #0 source $test_file_name""
Regards,
Jan
^ permalink raw reply [flat|nested] 66+ messages in thread* RFC: fix python-selftest.exp failure (Was: new FAIL python-selftest.exp in gdbserver mode [Re: [PATCH 18/28] check gdb_python_initialized everywhere])
2013-05-21 8:22 ` new FAIL python-selftest.exp in gdbserver mode [Re: [PATCH 18/28] check gdb_python_initialized everywhere] Jan Kratochvil
@ 2013-06-17 16:59 ` Tom Tromey
2013-06-17 17:10 ` Jan Kratochvil
0 siblings, 1 reply; 66+ messages in thread
From: Tom Tromey @ 2013-06-17 16:59 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: gdb-patches
Jan> in gdbserver mode:
Jan> Running gdb/testsuite/gdb.gdb/python-selftest.exp ...
Jan> PASS: gdb.gdb/python-selftest.exp: breakpoint in captured_command_loop
Jan> ERROR: tcl error sourcing gdb/testsuite/gdb.gdb/python-selftest.exp.
Jan> ERROR: gdbserver does not support run -nw -nx -data-directory /unsafegdb/testsuite.unix.-m64/../data-directory without extended-remote
[...]
python-selftest.exp fails with an error when using the
native-gdbserver.exp board.
The bug is that the selftest code doesn't work in this situation. It
never has.
This patch fixes the problem by pushing the needed check into
do_self_tests. This helps prevent the problem in the future.
* lib/selftest-support.exp (do_self_tests): Reject remote or
non-native targets.
* gdb.gdb/complaints.exp: Remove check.
* gdb.gdb/observer.exp: Remove check.
* gdb.gdb/xfullpath.exp: Remove check.
* gdb.gdb/complaints.exp: Remove check.
---
gdb/testsuite/gdb.gdb/complaints.exp | 5 -----
gdb/testsuite/gdb.gdb/observer.exp | 5 -----
gdb/testsuite/gdb.gdb/xfullpath.exp | 5 -----
gdb/testsuite/lib/selftest-support.exp | 5 +++++
4 files changed, 5 insertions(+), 15 deletions(-)
diff --git a/gdb/testsuite/gdb.gdb/complaints.exp b/gdb/testsuite/gdb.gdb/complaints.exp
index 932dfd5..e5f6e4a 100644
--- a/gdb/testsuite/gdb.gdb/complaints.exp
+++ b/gdb/testsuite/gdb.gdb/complaints.exp
@@ -19,11 +19,6 @@
load_lib selftest-support.exp
-# are we on a target board
-if { [is_remote target] || ![isnative] } then {
- return
-}
-
if [target_info exists gdb,noinferiorio] {
verbose "Skipping because of no inferiorio capabilities."
return
diff --git a/gdb/testsuite/gdb.gdb/observer.exp b/gdb/testsuite/gdb.gdb/observer.exp
index 32030d8..b70c2b1 100644
--- a/gdb/testsuite/gdb.gdb/observer.exp
+++ b/gdb/testsuite/gdb.gdb/observer.exp
@@ -18,11 +18,6 @@
load_lib selftest-support.exp
-# are we on a target board
-if { [is_remote target] || ![isnative] } then {
- return
-}
-
proc attach_first_observer { message } {
gdb_test_no_output "set \$first_obs = observer_attach_test_notification (&observer_test_first_notification_function)" \
"$message; attach first observer"
diff --git a/gdb/testsuite/gdb.gdb/xfullpath.exp b/gdb/testsuite/gdb.gdb/xfullpath.exp
index 5bc01c6..d758a18 100644
--- a/gdb/testsuite/gdb.gdb/xfullpath.exp
+++ b/gdb/testsuite/gdb.gdb/xfullpath.exp
@@ -18,11 +18,6 @@
load_lib selftest-support.exp
-# are we on a target board
-if { [is_remote target] || ![isnative] } then {
- return
-}
-
proc test_with_self {} {
# A file which contains a directory prefix
gdb_test "print gdb_realpath (\"./xfullpath.exp\")" \
diff --git a/gdb/testsuite/lib/selftest-support.exp b/gdb/testsuite/lib/selftest-support.exp
index c375849..fc4bccc 100644
--- a/gdb/testsuite/lib/selftest-support.exp
+++ b/gdb/testsuite/lib/selftest-support.exp
@@ -119,6 +119,11 @@ proc selftest_setup { executable function } {
proc do_self_tests {function body} {
global GDB tool
+ # Are we on a target board.
+ if { [is_remote target] || ![isnative] } then {
+ return
+ }
+
# Run the test with self. Copy the file executable file in case
# this OS doesn't like to edit its own text space.
--
1.8.1.4
^ permalink raw reply [flat|nested] 66+ messages in thread
* [PATCH 19/28] add missing decref in py-param.c
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
` (19 preceding siblings ...)
2013-04-19 15:40 ` [PATCH 18/28] check gdb_python_initialized everywhere Tom Tromey
@ 2013-04-19 16:20 ` Tom Tromey
2013-04-19 16:34 ` [PATCH 20/28] make set_sal follow negative result convention Tom Tromey
` (9 subsequent siblings)
30 siblings, 0 replies; 66+ messages in thread
From: Tom Tromey @ 2013-04-19 16:20 UTC (permalink / raw)
To: gdb-patches
The checker found a missing decref in compute_enum_values.
* python/py-param.c (compute_enum_values): Decref 'item'.
---
gdb/python/py-param.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c
index 2cc17b6..fbd9a77 100644
--- a/gdb/python/py-param.c
+++ b/gdb/python/py-param.c
@@ -611,12 +611,14 @@ compute_enum_values (parmpy_object *self, PyObject *enum_values)
}
if (! gdbpy_is_string (item))
{
+ Py_DECREF (item);
do_cleanups (back_to);
PyErr_SetString (PyExc_RuntimeError,
_("The enumeration item not a string."));
return 0;
}
self->enumeration[i] = python_string_to_host_string (item);
+ Py_DECREF (item);
if (self->enumeration[i] == NULL)
{
do_cleanups (back_to);
--
1.8.1.4
^ permalink raw reply [flat|nested] 66+ messages in thread* [PATCH 20/28] make set_sal follow negative result convention
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
` (20 preceding siblings ...)
2013-04-19 16:20 ` [PATCH 19/28] add missing decref in py-param.c Tom Tromey
@ 2013-04-19 16:34 ` Tom Tromey
2013-04-19 16:44 ` [PATCH 21/28] fix refcounting in gdbpy_run_events Tom Tromey
` (8 subsequent siblings)
30 siblings, 0 replies; 66+ messages in thread
From: Tom Tromey @ 2013-04-19 16:34 UTC (permalink / raw)
To: gdb-patches
This changes set_sal to follow the "negative means error" convention.
This lets the checker understand it.
* python/py-symtab.c (set_sal): Use
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION. Return -1 on error.
(symtab_and_line_to_sal_object): Update.
---
gdb/python/py-symtab.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c
index 80a2282..fe26b4c 100644
--- a/gdb/python/py-symtab.c
+++ b/gdb/python/py-symtab.c
@@ -315,9 +315,8 @@ salpy_dealloc (PyObject *self)
and initialized, populate the sal_object with the struct sal data.
Also, register the sal_object life-cycle with the life-cycle of the
object file associated with this sal, if needed. If a failure
- occurs during the sal population, this function will return
- NULL. */
-static int
+ occurs during the sal population, this function will return -1. */
+static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
set_sal (sal_object *sal_obj, struct symtab_and_line sal)
{
symtab_object *symtab_obj;
@@ -328,7 +327,7 @@ set_sal (sal_object *sal_obj, struct symtab_and_line sal)
/* If a symtab existed in the sal, but it cannot be duplicated,
we exit. */
if (symtab_obj == NULL)
- return 0;
+ return -1;
}
else
{
@@ -356,7 +355,7 @@ set_sal (sal_object *sal_obj, struct symtab_and_line sal)
else
sal_obj->next = NULL;
- return 1;
+ return 0;
}
/* Given a symtab, and a symtab_object that has previously been
@@ -398,7 +397,6 @@ symtab_to_symtab_object (struct symtab *symtab)
that encapsulates the symtab_and_line structure from GDB. */
PyObject *
symtab_and_line_to_sal_object (struct symtab_and_line sal)
-
{
sal_object *sal_obj;
int success = 0;
@@ -406,8 +404,7 @@ symtab_and_line_to_sal_object (struct symtab_and_line sal)
sal_obj = PyObject_New (sal_object, &sal_object_type);
if (sal_obj)
{
- success = set_sal (sal_obj, sal);
- if (!success)
+ if (set_sal (sal_obj, sal) < 0)
{
Py_DECREF (sal_obj);
return NULL;
--
1.8.1.4
^ permalink raw reply [flat|nested] 66+ messages in thread* [PATCH 21/28] fix refcounting in gdbpy_run_events
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
` (21 preceding siblings ...)
2013-04-19 16:34 ` [PATCH 20/28] make set_sal follow negative result convention Tom Tromey
@ 2013-04-19 16:44 ` Tom Tromey
2013-04-19 16:55 ` [PATCH 22/28] remove erroneous incref from gdbpy_initialize_py_events Tom Tromey
` (7 subsequent siblings)
30 siblings, 0 replies; 66+ messages in thread
From: Tom Tromey @ 2013-04-19 16:44 UTC (permalink / raw)
To: gdb-patches
The checker noticed a missing decref in gdbpy_run_events.
* python/python.c (gdbpy_run_events): Decref the result
of PyObject_CallObject.
---
gdb/python/python.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/gdb/python/python.c b/gdb/python/python.c
index a7b1b44..de21cdb 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -819,6 +819,8 @@ gdbpy_run_events (struct serial *scb, void *context)
while (gdbpy_event_list)
{
+ PyObject *call_result;
+
/* Dispatching the event might push a new element onto the event
loop, so we update here "atomically enough". */
struct gdbpy_event *item = gdbpy_event_list;
@@ -827,9 +829,11 @@ gdbpy_run_events (struct serial *scb, void *context)
gdbpy_event_list_end = &gdbpy_event_list;
/* Ignore errors. */
- if (PyObject_CallObject (item->event, NULL) == NULL)
+ call_result = PyObject_CallObject (item->event, NULL);
+ if (call_result == NULL)
PyErr_Clear ();
+ Py_XDECREF (call_result);
Py_DECREF (item->event);
xfree (item);
}
--
1.8.1.4
^ permalink raw reply [flat|nested] 66+ messages in thread* [PATCH 22/28] remove erroneous incref from gdbpy_initialize_py_events
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
` (22 preceding siblings ...)
2013-04-19 16:44 ` [PATCH 21/28] fix refcounting in gdbpy_run_events Tom Tromey
@ 2013-04-19 16:55 ` Tom Tromey
2013-04-19 17:15 ` [PATCH 23/28] use explicit decrefs rather than cleanups in some cases Tom Tromey
` (6 subsequent siblings)
30 siblings, 0 replies; 66+ messages in thread
From: Tom Tromey @ 2013-04-19 16:55 UTC (permalink / raw)
To: gdb-patches
The checker noticed a bogus incref in gdbpy_initialize_py_events.
* python/py-evts.c (gdbpy_initialize_py_events): Don't
incref the module.
---
gdb/python/py-evts.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/gdb/python/py-evts.c b/gdb/python/py-evts.c
index bb384e3..4828bda 100644
--- a/gdb/python/py-evts.c
+++ b/gdb/python/py-evts.c
@@ -81,9 +81,6 @@ gdbpy_initialize_py_events (void)
if (add_new_registry (&gdb_py_events.new_objfile, "new_objfile") < 0)
return -1;
-#ifndef IS_PY3K
- Py_INCREF (gdb_py_events.module);
-#endif
if (PyModule_AddObject (gdb_module,
"events",
(PyObject *) gdb_py_events.module) < 0)
--
1.8.1.4
^ permalink raw reply [flat|nested] 66+ messages in thread* [PATCH 23/28] use explicit decrefs rather than cleanups in some cases
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
` (23 preceding siblings ...)
2013-04-19 16:55 ` [PATCH 22/28] remove erroneous incref from gdbpy_initialize_py_events Tom Tromey
@ 2013-04-19 17:15 ` Tom Tromey
2013-04-19 17:46 ` [PATCH 24/28] introduce gdb_pymodule_addobject Tom Tromey
` (5 subsequent siblings)
30 siblings, 0 replies; 66+ messages in thread
From: Tom Tromey @ 2013-04-19 17:15 UTC (permalink / raw)
To: gdb-patches
The checker doesn't understand cleanups, and probably never will.
However, in a few places, I think we use cleanups where explicit
decref calls are just as clean. So, this patch changes those spots
and silences the checker.
There are other spots using decref cleanups that can't readily be
changed. For example, the pretty-printing code calls into parts of
gdb that can throw, and so cleanups must be used.
* python/py-cmd.c (cmdpy_completer): Use explicit decref.
* python/py-param.c (get_set_value, get_show_value): Use
explicit decrefs.
* python/python.c (start_type_printers, apply_type_printers):
Use explicit decrefs.
---
gdb/python/py-cmd.c | 2 +-
gdb/python/py-param.c | 11 +++++------
gdb/python/python.c | 17 +++++++++--------
3 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
index ba765e0..22eff25 100644
--- a/gdb/python/py-cmd.c
+++ b/gdb/python/py-cmd.c
@@ -244,7 +244,6 @@ cmdpy_completer (struct cmd_list_element *command,
PyErr_Clear ();
goto done;
}
- make_cleanup_py_decref (resultobj);
result = NULL;
if (PyInt_Check (resultobj))
@@ -300,6 +299,7 @@ cmdpy_completer (struct cmd_list_element *command,
done:
+ Py_XDECREF (resultobj);
do_cleanups (cleanup);
return result;
diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c
index fbd9a77..a81ab66 100644
--- a/gdb/python/py-param.c
+++ b/gdb/python/py-param.c
@@ -374,8 +374,6 @@ get_set_value (char *args, int from_tty,
if (! set_doc_func)
goto error;
- make_cleanup_py_decref (set_doc_func);
-
if (PyObject_HasAttr (obj, set_doc_func))
{
set_doc_string = call_doc_function (obj, set_doc_func, NULL);
@@ -393,10 +391,12 @@ get_set_value (char *args, int from_tty,
make_cleanup (xfree, set_doc_string);
fprintf_filtered (gdb_stdout, "%s\n", set_doc_string);
+ Py_XDECREF (set_doc_func);
do_cleanups (cleanup);
return;
error:
+ Py_XDECREF (set_doc_func);
gdbpy_print_stack ();
do_cleanups (cleanup);
return;
@@ -422,8 +422,6 @@ get_show_value (struct ui_file *file, int from_tty,
if (! show_doc_func)
goto error;
- make_cleanup_py_decref (show_doc_func);
-
if (PyObject_HasAttr (obj, show_doc_func))
{
PyObject *val_obj = PyString_FromString (value);
@@ -431,9 +429,8 @@ get_show_value (struct ui_file *file, int from_tty,
if (! val_obj)
goto error;
- make_cleanup_py_decref (val_obj);
-
show_doc_string = call_doc_function (obj, show_doc_func, val_obj);
+ Py_DECREF (val_obj);
if (! show_doc_string)
goto error;
@@ -451,10 +448,12 @@ get_show_value (struct ui_file *file, int from_tty,
fprintf_filtered (file, "%s %s\n", show_doc_string, value);
}
+ Py_XDECREF (show_doc_func);
do_cleanups (cleanup);
return;
error:
+ Py_XDECREF (show_doc_func);
gdbpy_print_stack ();
do_cleanups (cleanup);
return;
diff --git a/gdb/python/python.c b/gdb/python/python.c
index de21cdb..ab84bad 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1232,7 +1232,7 @@ void *
start_type_printers (void)
{
struct cleanup *cleanups;
- PyObject *type_module, *func, *result_obj = NULL;
+ PyObject *type_module, *func = NULL, *result_obj = NULL;
if (!gdb_python_initialized)
return NULL;
@@ -1245,7 +1245,6 @@ start_type_printers (void)
gdbpy_print_stack ();
goto done;
}
- make_cleanup_py_decref (type_module);
func = PyObject_GetAttrString (type_module, "get_type_recognizers");
if (func == NULL)
@@ -1253,13 +1252,14 @@ start_type_printers (void)
gdbpy_print_stack ();
goto done;
}
- make_cleanup_py_decref (func);
result_obj = PyObject_CallFunctionObjArgs (func, (char *) NULL);
if (result_obj == NULL)
gdbpy_print_stack ();
done:
+ Py_XDECREF (type_module);
+ Py_XDECREF (func);
do_cleanups (cleanups);
return result_obj;
}
@@ -1276,7 +1276,8 @@ char *
apply_type_printers (void *printers, struct type *type)
{
struct cleanup *cleanups;
- PyObject *type_obj, *type_module, *func, *result_obj;
+ PyObject *type_obj, *type_module = NULL, *func = NULL;
+ PyObject *result_obj = NULL;
PyObject *printers_obj = printers;
char *result = NULL;
@@ -1294,7 +1295,6 @@ apply_type_printers (void *printers, struct type *type)
gdbpy_print_stack ();
goto done;
}
- make_cleanup_py_decref (type_obj);
type_module = PyImport_ImportModule ("gdb.types");
if (type_module == NULL)
@@ -1302,7 +1302,6 @@ apply_type_printers (void *printers, struct type *type)
gdbpy_print_stack ();
goto done;
}
- make_cleanup_py_decref (type_module);
func = PyObject_GetAttrString (type_module, "apply_type_recognizers");
if (func == NULL)
@@ -1310,7 +1309,6 @@ apply_type_printers (void *printers, struct type *type)
gdbpy_print_stack ();
goto done;
}
- make_cleanup_py_decref (func);
result_obj = PyObject_CallFunctionObjArgs (func, printers_obj,
type_obj, (char *) NULL);
@@ -1319,7 +1317,6 @@ apply_type_printers (void *printers, struct type *type)
gdbpy_print_stack ();
goto done;
}
- make_cleanup_py_decref (result_obj);
if (result_obj != Py_None)
{
@@ -1329,6 +1326,10 @@ apply_type_printers (void *printers, struct type *type)
}
done:
+ Py_XDECREF (type_obj);
+ Py_XDECREF (type_module);
+ Py_XDECREF (func);
+ Py_XDECREF (result_obj);
do_cleanups (cleanups);
return result;
}
--
1.8.1.4
^ permalink raw reply [flat|nested] 66+ messages in thread* [PATCH 24/28] introduce gdb_pymodule_addobject
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
` (24 preceding siblings ...)
2013-04-19 17:15 ` [PATCH 23/28] use explicit decrefs rather than cleanups in some cases Tom Tromey
@ 2013-04-19 17:46 ` Tom Tromey
2013-05-21 7:58 ` [patch] Compilation regression with python-2.6 [Re: [PATCH 24/28] introduce gdb_pymodule_addobject] Jan Kratochvil
2013-06-03 12:50 ` Python 2.4 compile failure (Re: [PATCH 24/28] introduce gdb_pymodule_addobject) Ulrich Weigand
2013-04-19 17:49 ` [PATCH 25/28] some py-frame.c changes to make the checker work better Tom Tromey
` (4 subsequent siblings)
30 siblings, 2 replies; 66+ messages in thread
From: Tom Tromey @ 2013-04-19 17:46 UTC (permalink / raw)
To: gdb-patches
The checker pointed out that this common idiom in gdb is wrong:
- Py_INCREF (&arch_object_type);
- return PyModule_AddObject (gdb_module, "Architecture",
- (PyObject *) &arch_object_type);
This is buggy because if PyModule_AddObject fails, then the reference
will not be stolen. So, the object will be leaked.
This isn't extremely important, as such failures probably won't
actually happen. Nevertheless it is better to be clean; and also
remove false reports from the checker.
This patch does so by introducing a wrapper function for
PyModule_AddObject that doesn't steal a reference.
* python/py-arch.c (gdbpy_initialize_arch): Use
gdb_pymodule_addobject.
* python/py-block.c (gdbpy_initialize_blocks): Use
gdb_pymodule_addobject.
* python/py-breakpoint.c (gdbpy_initialize_breakpoints): Use
gdb_pymodule_addobject.
* python/py-cmd.c (gdbpy_initialize_breakpoints): Use
gdb_pymodule_addobject.
* python/py-event.c (gdbpy_initialize_event_generic): Use
gdb_pymodule_addobject.
* python/py-evtregistry.c (gdbpy_initialize_eventregistry): Use
gdb_pymodule_addobject.
* python/py-evts.c (add_new_registry): Use
gdb_pymodule_addobject.
(gdbpy_initialize_py_events): Likewise.
* python/py-finishbreakpoint.c
(gdbpy_initialize_finishbreakpoints): Use
gdb_pymodule_addobject.
* python/py-frame.c (gdbpy_initialize_frames): Use
gdb_pymodule_addobject.
* python/py-function.c (gdbpy_initialize_functions): Use
gdb_pymodule_addobject.
* python/py-inferior.c (gdbpy_initialize_inferior): Use
gdb_pymodule_addobject.
* python/py-infthread.c (gdbpy_initialize_thread): Use
gdb_pymodule_addobject.
* python/py-objfile.c (gdbpy_initialize_objfile): Use
gdb_pymodule_addobject.
* python/py-param.c (gdbpy_initialize_parameters): Use
gdb_pymodule_addobject.
* python/py-progspace.c (gdbpy_initialize_pspace): Use
gdb_pymodule_addobject.
* python/py-symbol.c (gdbpy_initialize_symbols): Use
gdb_pymodule_addobject.
* python/py-symtab.c (gdbpy_initialize_symtabs): Use
gdb_pymodule_addobject.
* python/py-type.c (gdbpy_initialize_types): Use
gdb_pymodule_addobject.
* python/py-utils.c (gdb_pymodule_addobject): New function.
* python/py-value.c (gdbpy_initialize_values): Use
gdb_pymodule_addobject.
* python/python-internal.h (gdb_pymodule_addobject): Declare.
* python/python.c (_initialize_python): Use
gdb_pymodule_addobject.
---
gdb/python/py-arch.c | 5 ++---
gdb/python/py-block.c | 10 ++++------
gdb/python/py-breakpoint.c | 5 ++---
gdb/python/py-cmd.c | 5 ++---
gdb/python/py-event.c | 10 +---------
gdb/python/py-evtregistry.c | 5 ++---
gdb/python/py-evts.c | 23 +++++++++--------------
gdb/python/py-finishbreakpoint.c | 5 ++---
gdb/python/py-frame.c | 5 ++---
gdb/python/py-function.c | 5 ++---
gdb/python/py-inferior.c | 10 ++++------
gdb/python/py-infthread.c | 5 ++---
gdb/python/py-objfile.c | 5 ++---
gdb/python/py-param.c | 5 ++---
gdb/python/py-progspace.c | 5 ++---
gdb/python/py-symbol.c | 5 ++---
gdb/python/py-symtab.c | 10 ++++------
gdb/python/py-type.c | 15 ++++++---------
gdb/python/py-utils.c | 15 +++++++++++++++
gdb/python/py-value.c | 5 ++---
gdb/python/python-internal.h | 4 ++++
gdb/python/python.c | 11 ++++++-----
22 files changed, 79 insertions(+), 94 deletions(-)
diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c
index 7920fbb..7098a8a 100644
--- a/gdb/python/py-arch.c
+++ b/gdb/python/py-arch.c
@@ -239,9 +239,8 @@ gdbpy_initialize_arch (void)
if (PyType_Ready (&arch_object_type) < 0)
return -1;
- Py_INCREF (&arch_object_type);
- return PyModule_AddObject (gdb_module, "Architecture",
- (PyObject *) &arch_object_type);
+ return gdb_pymodule_addobject (gdb_module, "Architecture",
+ (PyObject *) &arch_object_type);
}
static PyMethodDef arch_object_methods [] = {
diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c
index f2d9000..c74ac2c 100644
--- a/gdb/python/py-block.c
+++ b/gdb/python/py-block.c
@@ -442,14 +442,12 @@ gdbpy_initialize_blocks (void)
blpy_objfile_data_key
= register_objfile_data_with_cleanup (NULL, del_objfile_blocks);
- Py_INCREF (&block_object_type);
- if (PyModule_AddObject (gdb_module, "Block",
- (PyObject *) &block_object_type) < 0)
+ if (gdb_pymodule_addobject (gdb_module, "Block",
+ (PyObject *) &block_object_type) < 0)
return -1;
- Py_INCREF (&block_syms_iterator_object_type);
- return PyModule_AddObject (gdb_module, "BlockIterator",
- (PyObject *) &block_syms_iterator_object_type);
+ return gdb_pymodule_addobject (gdb_module, "BlockIterator",
+ (PyObject *) &block_syms_iterator_object_type);
}
\f
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index b1b6e93..d958f30 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -868,9 +868,8 @@ gdbpy_initialize_breakpoints (void)
if (PyType_Ready (&breakpoint_object_type) < 0)
return -1;
- Py_INCREF (&breakpoint_object_type);
- if (PyModule_AddObject (gdb_module, "Breakpoint",
- (PyObject *) &breakpoint_object_type) < 0)
+ if (gdb_pymodule_addobject (gdb_module, "Breakpoint",
+ (PyObject *) &breakpoint_object_type) < 0)
return -1;
observer_attach_breakpoint_created (gdbpy_breakpoint_created);
diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
index 22eff25..8b6252e 100644
--- a/gdb/python/py-cmd.c
+++ b/gdb/python/py-cmd.c
@@ -600,9 +600,8 @@ gdbpy_initialize_commands (void)
return -1;
}
- Py_INCREF (&cmdpy_object_type);
- if (PyModule_AddObject (gdb_module, "Command",
- (PyObject *) &cmdpy_object_type) < 0)
+ if (gdb_pymodule_addobject (gdb_module, "Command",
+ (PyObject *) &cmdpy_object_type) < 0)
return -1;
invoke_cst = PyString_FromString ("invoke");
diff --git a/gdb/python/py-event.c b/gdb/python/py-event.c
index 04f33ab..9f5134d 100644
--- a/gdb/python/py-event.c
+++ b/gdb/python/py-event.c
@@ -78,15 +78,7 @@ gdbpy_initialize_event_generic (PyTypeObject *type,
if (PyType_Ready (type) < 0)
return -1;
- Py_INCREF (type);
- if (PyModule_AddObject (gdb_module, name, (PyObject *) type) < 0)
- goto fail;
-
- return 0;
-
- fail:
- Py_XDECREF (type);
- return -1;
+ return gdb_pymodule_addobject (gdb_module, name, (PyObject *) type);
}
diff --git a/gdb/python/py-evtregistry.c b/gdb/python/py-evtregistry.c
index d7cbe64..0eeb853 100644
--- a/gdb/python/py-evtregistry.c
+++ b/gdb/python/py-evtregistry.c
@@ -112,9 +112,8 @@ gdbpy_initialize_eventregistry (void)
if (PyType_Ready (&eventregistry_object_type) < 0)
return -1;
- Py_INCREF (&eventregistry_object_type);
- return PyModule_AddObject (gdb_module, "EventRegistry",
- (PyObject *) &eventregistry_object_type);
+ return gdb_pymodule_addobject (gdb_module, "EventRegistry",
+ (PyObject *) &eventregistry_object_type);
}
/* Retern the number of listeners currently connected to this
diff --git a/gdb/python/py-evts.c b/gdb/python/py-evts.c
index 4828bda..971c520 100644
--- a/gdb/python/py-evts.c
+++ b/gdb/python/py-evts.c
@@ -40,21 +40,16 @@ static struct PyModuleDef EventModuleDef =
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
add_new_registry (eventregistry_object **registryp, char *name)
{
+ int result;
+
*registryp = create_eventregistry_object ();
if (*registryp == NULL)
- goto fail;
-
- if (PyModule_AddObject (gdb_py_events.module,
- name,
- (PyObject *)(*registryp)) < 0)
- goto fail;
-
- return 0;
+ return -1;
- fail:
- Py_XDECREF (*registryp);
- return -1;
+ return gdb_pymodule_addobject (gdb_py_events.module,
+ name,
+ (PyObject *)(*registryp));
}
int
@@ -81,9 +76,9 @@ gdbpy_initialize_py_events (void)
if (add_new_registry (&gdb_py_events.new_objfile, "new_objfile") < 0)
return -1;
- if (PyModule_AddObject (gdb_module,
- "events",
- (PyObject *) gdb_py_events.module) < 0)
+ if (gdb_pymodule_addobject (gdb_module,
+ "events",
+ (PyObject *) gdb_py_events.module) < 0)
return -1;
return 0;
diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c
index 5fd1f4b..ca20439 100644
--- a/gdb/python/py-finishbreakpoint.c
+++ b/gdb/python/py-finishbreakpoint.c
@@ -413,9 +413,8 @@ gdbpy_initialize_finishbreakpoints (void)
if (PyType_Ready (&finish_breakpoint_object_type) < 0)
return -1;
- Py_INCREF (&finish_breakpoint_object_type);
- if (PyModule_AddObject (gdb_module, "FinishBreakpoint",
- (PyObject *) &finish_breakpoint_object_type) < 0)
+ if (gdb_pymodule_addobject (gdb_module, "FinishBreakpoint",
+ (PyObject *) &finish_breakpoint_object_type) < 0)
return -1;
observer_attach_normal_stop (bpfinishpy_handle_stop);
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index 75e84ac..435eb50 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -642,9 +642,8 @@ gdbpy_initialize_frames (void)
#undef SET
#undef FIRST_ERROR
- Py_INCREF (&frame_object_type);
- return PyModule_AddObject (gdb_module, "Frame",
- (PyObject *) &frame_object_type);
+ return gdb_pymodule_addobject (gdb_module, "Frame",
+ (PyObject *) &frame_object_type);
}
\f
diff --git a/gdb/python/py-function.c b/gdb/python/py-function.c
index 57cdfae..fc0d4dd 100644
--- a/gdb/python/py-function.c
+++ b/gdb/python/py-function.c
@@ -207,9 +207,8 @@ gdbpy_initialize_functions (void)
if (PyType_Ready (&fnpy_object_type) < 0)
return -1;
- Py_INCREF (&fnpy_object_type);
- return PyModule_AddObject (gdb_module, "Function",
- (PyObject *) &fnpy_object_type);
+ return gdb_pymodule_addobject (gdb_module, "Function",
+ (PyObject *) &fnpy_object_type);
}
\f
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index 1ab58e6..a603f19 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -789,9 +789,8 @@ gdbpy_initialize_inferior (void)
if (PyType_Ready (&inferior_object_type) < 0)
return -1;
- Py_INCREF (&inferior_object_type);
- if (PyModule_AddObject (gdb_module, "Inferior",
- (PyObject *) &inferior_object_type) < 0)
+ if (gdb_pymodule_addobject (gdb_module, "Inferior",
+ (PyObject *) &inferior_object_type) < 0)
return -1;
infpy_inf_data_key =
@@ -808,9 +807,8 @@ gdbpy_initialize_inferior (void)
if (PyType_Ready (&membuf_object_type) < 0)
return -1;
- Py_INCREF (&membuf_object_type);
- return PyModule_AddObject (gdb_module, "Membuf", (PyObject *)
- &membuf_object_type);
+ return gdb_pymodule_addobject (gdb_module, "Membuf", (PyObject *)
+ &membuf_object_type);
}
static PyGetSetDef inferior_object_getset[] =
diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
index 7a5f262..d46f573 100644
--- a/gdb/python/py-infthread.c
+++ b/gdb/python/py-infthread.c
@@ -261,9 +261,8 @@ gdbpy_initialize_thread (void)
if (PyType_Ready (&thread_object_type) < 0)
return -1;
- Py_INCREF (&thread_object_type);
- return PyModule_AddObject (gdb_module, "InferiorThread",
- (PyObject *) &thread_object_type);
+ return gdb_pymodule_addobject (gdb_module, "InferiorThread",
+ (PyObject *) &thread_object_type);
}
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index 53f8829..7a257ca 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -249,9 +249,8 @@ gdbpy_initialize_objfile (void)
if (PyType_Ready (&objfile_object_type) < 0)
return -1;
- Py_INCREF (&objfile_object_type);
- return PyModule_AddObject (gdb_module, "Objfile",
- (PyObject *) &objfile_object_type);
+ return gdb_pymodule_addobject (gdb_module, "Objfile",
+ (PyObject *) &objfile_object_type);
}
\f
diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c
index a81ab66..9f56c3a 100644
--- a/gdb/python/py-param.c
+++ b/gdb/python/py-param.c
@@ -774,9 +774,8 @@ gdbpy_initialize_parameters (void)
return -1;
}
- Py_INCREF (&parmpy_object_type);
- return PyModule_AddObject (gdb_module, "Parameter",
- (PyObject *) &parmpy_object_type);
+ return gdb_pymodule_addobject (gdb_module, "Parameter",
+ (PyObject *) &parmpy_object_type);
}
\f
diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c
index f964fe0..68fe217 100644
--- a/gdb/python/py-progspace.c
+++ b/gdb/python/py-progspace.c
@@ -245,9 +245,8 @@ gdbpy_initialize_pspace (void)
if (PyType_Ready (&pspace_object_type) < 0)
return -1;
- Py_INCREF (&pspace_object_type);
- return PyModule_AddObject (gdb_module, "Progspace",
- (PyObject *) &pspace_object_type);
+ return gdb_pymodule_addobject (gdb_module, "Progspace",
+ (PyObject *) &pspace_object_type);
}
\f
diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
index 7629f70..8afe52d 100644
--- a/gdb/python/py-symbol.c
+++ b/gdb/python/py-symbol.c
@@ -531,9 +531,8 @@ gdbpy_initialize_symbols (void)
TYPES_DOMAIN) < 0)
return -1;
- Py_INCREF (&symbol_object_type);
- return PyModule_AddObject (gdb_module, "Symbol",
- (PyObject *) &symbol_object_type);
+ return gdb_pymodule_addobject (gdb_module, "Symbol",
+ (PyObject *) &symbol_object_type);
}
\f
diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c
index fe26b4c..006946c 100644
--- a/gdb/python/py-symtab.c
+++ b/gdb/python/py-symtab.c
@@ -501,14 +501,12 @@ gdbpy_initialize_symtabs (void)
salpy_objfile_data_key
= register_objfile_data_with_cleanup (NULL, del_objfile_sal);
- Py_INCREF (&symtab_object_type);
- if (PyModule_AddObject (gdb_module, "Symtab",
- (PyObject *) &symtab_object_type) < 0)
+ if (gdb_pymodule_addobject (gdb_module, "Symtab",
+ (PyObject *) &symtab_object_type) < 0)
return -1;
- Py_INCREF (&sal_object_type);
- return PyModule_AddObject (gdb_module, "Symtab_and_line",
- (PyObject *) &sal_object_type);
+ return gdb_pymodule_addobject (gdb_module, "Symtab_and_line",
+ (PyObject *) &sal_object_type);
}
\f
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index dd3a751..63629fe 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -1548,19 +1548,16 @@ gdbpy_initialize_types (void)
return -1;
}
- Py_INCREF (&type_object_type);
- if (PyModule_AddObject (gdb_module, "Type",
- (PyObject *) &type_object_type) < 0)
+ if (gdb_pymodule_addobject (gdb_module, "Type",
+ (PyObject *) &type_object_type) < 0)
return -1;
- Py_INCREF (&type_iterator_object_type);
- if (PyModule_AddObject (gdb_module, "TypeIterator",
- (PyObject *) &type_iterator_object_type) < 0)
+ if (gdb_pymodule_addobject (gdb_module, "TypeIterator",
+ (PyObject *) &type_iterator_object_type) < 0)
return -1;
- Py_INCREF (&field_object_type);
- return PyModule_AddObject (gdb_module, "Field",
- (PyObject *) &field_object_type);
+ return gdb_pymodule_addobject (gdb_module, "Field",
+ (PyObject *) &field_object_type);
}
\f
diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
index 6a7e9e4..cf82734 100644
--- a/gdb/python/py-utils.c
+++ b/gdb/python/py-utils.c
@@ -409,3 +409,18 @@ gdb_py_generic_dict (PyObject *self, void *closure)
Py_INCREF (result);
return result;
}
+
+/* Like PyModule_AddObject, but does not steal a reference to
+ OBJECT. */
+
+int
+gdb_pymodule_addobject (PyObject *module, const char *name, PyObject *object)
+{
+ int result;
+
+ Py_INCREF (object);
+ result = PyModule_AddObject (module, name, object);
+ if (result < 0)
+ Py_DECREF (object);
+ return result;
+}
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index d8d90c7..e4f4263 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -1391,9 +1391,8 @@ gdbpy_initialize_values (void)
if (PyType_Ready (&value_object_type) < 0)
return -1;
- Py_INCREF (&value_object_type);
- return PyModule_AddObject (gdb_module, "Value",
- (PyObject *) &value_object_type);
+ return gdb_pymodule_addobject (gdb_module, "Value",
+ (PyObject *) &value_object_type);
}
\f
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 4a9405f..a2a5079 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -464,4 +464,8 @@ int gdb_py_int_as_long (PyObject *, long *);
PyObject *gdb_py_generic_dict (PyObject *self, void *closure);
+int gdb_pymodule_addobject (PyObject *module, const char *name,
+ PyObject *object)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+
#endif /* GDB_PYTHON_INTERNAL_H */
diff --git a/gdb/python/python.c b/gdb/python/python.c
index ab84bad..4f69c32 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1630,19 +1630,20 @@ message == an error message without a stack will be printed."),
gdbpy_gdb_error = PyErr_NewException ("gdb.error", PyExc_RuntimeError, NULL);
if (gdbpy_gdb_error == NULL
- || PyModule_AddObject (gdb_module, "error", gdbpy_gdb_error) < 0)
+ || gdb_pymodule_addobject (gdb_module, "error", gdbpy_gdb_error) < 0)
goto fail;
gdbpy_gdb_memory_error = PyErr_NewException ("gdb.MemoryError",
gdbpy_gdb_error, NULL);
if (gdbpy_gdb_memory_error == NULL
- || PyModule_AddObject (gdb_module, "MemoryError",
- gdbpy_gdb_memory_error) < 0)
+ || gdb_pymodule_addobject (gdb_module, "MemoryError",
+ gdbpy_gdb_memory_error) < 0)
goto fail;
gdbpy_gdberror_exc = PyErr_NewException ("gdb.GdbError", NULL, NULL);
if (gdbpy_gdberror_exc == NULL
- || PyModule_AddObject (gdb_module, "GdbError", gdbpy_gdberror_exc) < 0)
+ || gdb_pymodule_addobject (gdb_module, "GdbError",
+ gdbpy_gdberror_exc) < 0)
goto fail;
gdbpy_initialize_gdb_readline ();
@@ -1789,7 +1790,7 @@ finish_python_initialization (void)
return;
}
- if (PyModule_AddObject (m, "gdb", gdb_python_module))
+ if (gdb_pymodule_addobject (m, "gdb", gdb_python_module) < 0)
goto fail;
/* Keep the reference to gdb_python_module since it is in a global
--
1.8.1.4
^ permalink raw reply [flat|nested] 66+ messages in thread* [patch] Compilation regression with python-2.6 [Re: [PATCH 24/28] introduce gdb_pymodule_addobject]
2013-04-19 17:46 ` [PATCH 24/28] introduce gdb_pymodule_addobject Tom Tromey
@ 2013-05-21 7:58 ` Jan Kratochvil
2013-05-21 13:30 ` Tom Tromey
2013-05-21 16:05 ` Pedro Alves
2013-06-03 12:50 ` Python 2.4 compile failure (Re: [PATCH 24/28] introduce gdb_pymodule_addobject) Ulrich Weigand
1 sibling, 2 replies; 66+ messages in thread
From: Jan Kratochvil @ 2013-05-21 7:58 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On Fri, 19 Apr 2013 16:42:12 +0200, Tom Tromey wrote:
> --- a/gdb/python/py-utils.c
> +++ b/gdb/python/py-utils.c
[...]
> +int
> +gdb_pymodule_addobject (PyObject *module, const char *name, PyObject *object)
> +{
> + int result;
> +
> + Py_INCREF (object);
> + result = PyModule_AddObject (module, name, object);
> + if (result < 0)
> + Py_DECREF (object);
> + return result;
> +}
commit 62234c99e3a311c07838ebaea38198d7f4239d0c
Author: Tom Tromey <tromey@redhat.com>
Date: Mon May 20 20:36:18 2013 +0000
CentOS-6.4 x86_64
./python/py-utils.c: In function ‘gdb_pymodule_addobject’:
./python/py-utils.c:445: error: suggest explicit braces to avoid ambiguous ‘else’
python-devel-2.7.3-13.fc18.x86_64
/usr/include/python2.7/object.h
#define Py_DECREF(op) \
do { \
if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \
--((PyObject*)(op))->ob_refcnt != 0) \
_Py_CHECK_REFCNT(op) \
else \
_Py_Dealloc((PyObject *)(op)); \
} while (0)
python-devel-2.6.6-36.el6.x86_64
/usr/include/python2.6/object.h
#define Py_DECREF(op) \
if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \
--((PyObject*)(op))->ob_refcnt != 0) \
_Py_CHECK_REFCNT(op) \
else \
_Py_Dealloc((PyObject *)(op))
I will check it in today.
Regards,
Jan
gdb/
2013-05-21 Jan Kratochvil <jan.kratochvil@redhat.com>
Workaround Python 2.6.
* python/py-utils.c (gdb_pymodule_addobject): Wrap Py_DECREF into
a block.
diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
index d87eb8c..23fcf3f 100644
--- a/gdb/python/py-utils.c
+++ b/gdb/python/py-utils.c
@@ -443,6 +443,9 @@ gdb_pymodule_addobject (PyObject *module, const char *name, PyObject *object)
Py_INCREF (object);
result = PyModule_AddObject (module, name, object);
if (result < 0)
- Py_DECREF (object);
+ {
+ /* Python 2.6 did not wrap Py_DECREF in do { } while (0);. */
+ Py_DECREF (object);
+ }
return result;
}
^ permalink raw reply [flat|nested] 66+ messages in thread* Re: [patch] Compilation regression with python-2.6 [Re: [PATCH 24/28] introduce gdb_pymodule_addobject]
2013-05-21 7:58 ` [patch] Compilation regression with python-2.6 [Re: [PATCH 24/28] introduce gdb_pymodule_addobject] Jan Kratochvil
@ 2013-05-21 13:30 ` Tom Tromey
2013-05-21 15:02 ` [commit] " Jan Kratochvil
2013-05-21 16:05 ` Pedro Alves
1 sibling, 1 reply; 66+ messages in thread
From: Tom Tromey @ 2013-05-21 13:30 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: gdb-patches
>>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:
Jan> ./python/py-utils.c: In function ‘gdb_pymodule_addobject’:
Jan> ./python/py-utils.c:445: error: suggest explicit braces to avoid ambiguous ‘else’
Jan> I will check it in today.
Thanks Jan. I wonder why this doesn't trigger here.
Tom
^ permalink raw reply [flat|nested] 66+ messages in thread
* Re: [patch] Compilation regression with python-2.6 [Re: [PATCH 24/28] introduce gdb_pymodule_addobject]
2013-05-21 7:58 ` [patch] Compilation regression with python-2.6 [Re: [PATCH 24/28] introduce gdb_pymodule_addobject] Jan Kratochvil
2013-05-21 13:30 ` Tom Tromey
@ 2013-05-21 16:05 ` Pedro Alves
2013-05-21 16:14 ` Jan Kratochvil
1 sibling, 1 reply; 66+ messages in thread
From: Pedro Alves @ 2013-05-21 16:05 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: Tom Tromey, gdb-patches
On 05/21/2013 08:58 AM, Jan Kratochvil wrote:
> ./python/py-utils.c: In function ‘gdb_pymodule_addobject’:
> ./python/py-utils.c:445: error: suggest explicit braces to avoid ambiguous ‘else’
>
> python-devel-2.7.3-13.fc18.x86_64
> /usr/include/python2.7/object.h
> #define Py_DECREF(op) \
> do { \
> if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \
> --((PyObject*)(op))->ob_refcnt != 0) \
> _Py_CHECK_REFCNT(op) \
> else \
> _Py_Dealloc((PyObject *)(op)); \
> } while (0)
>
> python-devel-2.6.6-36.el6.x86_64
> /usr/include/python2.6/object.h
> #define Py_DECREF(op) \
> if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \
> --((PyObject*)(op))->ob_refcnt != 0) \
> _Py_CHECK_REFCNT(op) \
> else \
> _Py_Dealloc((PyObject *)(op))
>
> gdb/
> 2013-05-21 Jan Kratochvil <jan.kratochvil@redhat.com>
>
> Workaround Python 2.6.
> * python/py-utils.c (gdb_pymodule_addobject): Wrap Py_DECREF into
> a block.
>
> diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
> index d87eb8c..23fcf3f 100644
> --- a/gdb/python/py-utils.c
> +++ b/gdb/python/py-utils.c
> @@ -443,6 +443,9 @@ gdb_pymodule_addobject (PyObject *module, const char *name, PyObject *object)
> Py_INCREF (object);
> result = PyModule_AddObject (module, name, object);
> if (result < 0)
> - Py_DECREF (object);
> + {
> + /* Python 2.6 did not wrap Py_DECREF in do { } while (0);. */
> + Py_DECREF (object);
> + }
> return result;
> }
>
How about we handle this in a central place with something like:
static inline void
gdb_Py_DECREF (void *op)
{
Py_DECREF (op);
}
#undef Py_DECREF
#define Py_DECREF(op) gdb_Py_DECREF (op)
in gdb/python/python-internal.h? Then code that uses the macro wouldn't need to care.
I went ahead and did a quick attempt at it. I checked the gdb.python/ tests all still passed for me.
WDYT?
---
gdb/python/py-utils.c | 11 ++---------
gdb/python/python-internal.h | 12 ++++++++++++
2 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
index e78dee0..80bacf7 100644
--- a/gdb/python/py-utils.c
+++ b/gdb/python/py-utils.c
@@ -31,12 +31,8 @@ py_decref (void *p)
{
PyObject *py = p;
- /* Note that we need the extra braces in this 'if' to avoid a
- warning from gcc. */
if (py)
- {
- Py_DECREF (py);
- }
+ Py_DECREF (py);
}
/* Return a new cleanup which will decrement the Python object's
@@ -443,9 +439,6 @@ gdb_pymodule_addobject (PyObject *module, const char *name, PyObject *object)
Py_INCREF (object);
result = PyModule_AddObject (module, name, object);
if (result < 0)
- {
- /* Python 2.6 did not wrap Py_DECREF in do { } while (0);. */
- Py_DECREF (object);
- }
+ Py_DECREF (object);
return result;
}
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index b01efa1..b5c34b6 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -169,6 +169,18 @@ typedef unsigned long gdb_py_ulongest;
#endif /* HAVE_LONG_LONG */
+/* Python 2.6 did not wrap Py_DECREF in 'do {...} while (0)', leading
+ to 'suggest explicit braces to avoid ambiguous ‘else’' gcc errors.
+ Wrap it ourselves, so that callers don't need to care. */
+
+static inline void
+gdb_Py_DECREF (void *op)
+{
+ Py_DECREF (op);
+}
+
+#undef Py_DECREF
+#define Py_DECREF(op) gdb_Py_DECREF (op)
/* In order to be able to parse symtab_and_line_to_sal_object function
a real symtab_and_line structure is needed. */
^ permalink raw reply [flat|nested] 66+ messages in thread* Re: [patch] Compilation regression with python-2.6 [Re: [PATCH 24/28] introduce gdb_pymodule_addobject]
2013-05-21 16:05 ` Pedro Alves
@ 2013-05-21 16:14 ` Jan Kratochvil
2013-05-21 16:24 ` Pedro Alves
0 siblings, 1 reply; 66+ messages in thread
From: Jan Kratochvil @ 2013-05-21 16:14 UTC (permalink / raw)
To: Pedro Alves; +Cc: Tom Tromey, gdb-patches
On Tue, 21 May 2013 18:05:40 +0200, Pedro Alves wrote:
> How about we handle this in a central place with something like:
Fine with me although there is also Py_INCREF and not sure if also others.
Jan
^ permalink raw reply [flat|nested] 66+ messages in thread
* Re: [patch] Compilation regression with python-2.6 [Re: [PATCH 24/28] introduce gdb_pymodule_addobject]
2013-05-21 16:14 ` Jan Kratochvil
@ 2013-05-21 16:24 ` Pedro Alves
2013-05-21 16:36 ` Tom Tromey
2013-05-21 20:55 ` [COMMIT] Centralize workaround for Python 2.6's Py_DECREF. (Re: " Pedro Alves
0 siblings, 2 replies; 66+ messages in thread
From: Pedro Alves @ 2013-05-21 16:24 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: Tom Tromey, gdb-patches
On 05/21/2013 05:14 PM, Jan Kratochvil wrote:
> On Tue, 21 May 2013 18:05:40 +0200, Pedro Alves wrote:
>> How about we handle this in a central place with something like:
>
> Fine with me although there is also Py_INCREF and not sure if also others.
Yeah. I guess we can handle those on an as needed basis.
Here's a complete patch, with ChangeLog.
I notice that py_decref could actually be using Py_XDECREF instead
of doing the explicit 'if (py)' check.
----
Subject: Centralize workaround for Python 2.6's Py_DECREF.
Wrap/redefine Py_DECREF ourselves, avoiding the need for uses to care
about extra braces due to the fact that Python only started wrapping Py_DECREF
in 'do {} while (0)' after 2.6.
gdb/
2013-05-21 Pedro Alves <palves@redhat.com>
* python/py-utils.c (py_decref): Remove extra braces.
(gdb_pymodule_addobject): Remove extra braces.
* python-internal.h (gdb_Py_DECREF): New static inline function.
(Py_DECREF): Redefine as calling gdb_Py_DECREF.
---
gdb/python/py-utils.c | 11 ++---------
gdb/python/python-internal.h | 12 ++++++++++++
2 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
index e78dee0..80bacf7 100644
--- a/gdb/python/py-utils.c
+++ b/gdb/python/py-utils.c
@@ -31,12 +31,8 @@ py_decref (void *p)
{
PyObject *py = p;
- /* Note that we need the extra braces in this 'if' to avoid a
- warning from gcc. */
if (py)
- {
- Py_DECREF (py);
- }
+ Py_DECREF (py);
}
/* Return a new cleanup which will decrement the Python object's
@@ -443,9 +439,6 @@ gdb_pymodule_addobject (PyObject *module, const char *name, PyObject *object)
Py_INCREF (object);
result = PyModule_AddObject (module, name, object);
if (result < 0)
- {
- /* Python 2.6 did not wrap Py_DECREF in do { } while (0);. */
- Py_DECREF (object);
- }
+ Py_DECREF (object);
return result;
}
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index b01efa1..b5c34b6 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -169,6 +169,18 @@ typedef unsigned long gdb_py_ulongest;
#endif /* HAVE_LONG_LONG */
+/* Python 2.6 did not wrap Py_DECREF in 'do {...} while (0)', leading
+ to 'suggest explicit braces to avoid ambiguous ‘else’' gcc errors.
+ Wrap it ourselves, so that callers don't need to care. */
+
+static inline void
+gdb_Py_DECREF (void *op)
+{
+ Py_DECREF (op);
+}
+
+#undef Py_DECREF
+#define Py_DECREF(op) gdb_Py_DECREF (op)
/* In order to be able to parse symtab_and_line_to_sal_object function
a real symtab_and_line structure is needed. */
^ permalink raw reply [flat|nested] 66+ messages in thread* Re: [patch] Compilation regression with python-2.6 [Re: [PATCH 24/28] introduce gdb_pymodule_addobject]
2013-05-21 16:24 ` Pedro Alves
@ 2013-05-21 16:36 ` Tom Tromey
2013-05-21 16:48 ` Pedro Alves
2013-05-21 20:55 ` [COMMIT] Centralize workaround for Python 2.6's Py_DECREF. (Re: " Pedro Alves
1 sibling, 1 reply; 66+ messages in thread
From: Tom Tromey @ 2013-05-21 16:36 UTC (permalink / raw)
To: Pedro Alves; +Cc: Jan Kratochvil, gdb-patches
>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
Pedro> I notice that py_decref could actually be using Py_XDECREF instead
Pedro> of doing the explicit 'if (py)' check.
Pedro> - /* Note that we need the extra braces in this 'if' to avoid a
Pedro> - warning from gcc. */
Pedro> if (py)
Pedro> - {
Pedro> - Py_DECREF (py);
Pedro> - }
Pedro> + Py_DECREF (py);
The X is missing.
Also, as discussed on irc, if you do this you might as well zap
make_cleanup_py_xdecref and py_xdecref.
I think having one set of cleanup functions is plenty. The NULL check
can't cost much, either in performance or clarity.
Really I would prefer to get rid of decref cleanups at all, since they
mess with the checker. But this is a pain, and probably not worth the
effort unless we think we could really get to 0 false reports.
Tom
^ permalink raw reply [flat|nested] 66+ messages in thread* Re: [patch] Compilation regression with python-2.6 [Re: [PATCH 24/28] introduce gdb_pymodule_addobject]
2013-05-21 16:36 ` Tom Tromey
@ 2013-05-21 16:48 ` Pedro Alves
2013-05-21 17:32 ` Tom Tromey
0 siblings, 1 reply; 66+ messages in thread
From: Pedro Alves @ 2013-05-21 16:48 UTC (permalink / raw)
To: Tom Tromey; +Cc: Jan Kratochvil, gdb-patches
On 05/21/2013 05:36 PM, Tom Tromey wrote:
>>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
>
> Pedro> I notice that py_decref could actually be using Py_XDECREF instead
> Pedro> of doing the explicit 'if (py)' check.
>
> Pedro> - /* Note that we need the extra braces in this 'if' to avoid a
> Pedro> - warning from gcc. */
> Pedro> if (py)
> Pedro> - {
> Pedro> - Py_DECREF (py);
> Pedro> - }
> Pedro> + Py_DECREF (py);
>
> The X is missing.
Oh, I did not intend to do that change in the 7.6 workaround patch.
I was leaving that patch concerned only with the scoping issue.
>
> Also, as discussed on irc, if you do this you might as well zap
> make_cleanup_py_xdecref and py_xdecref.
Yeah. As discussed on irc, given the existence of py_xdecref, I
think py_decref calling Py_XDECREF would be odd. Given the only difference
between Py_DECREF and Py_XDECREF is that the latter allows passing
in a NULL object, while the former prohibits it, it's natural to expect
the same from py_decref vs py_xdecref.
> I think having one set of cleanup functions is plenty. The NULL check
> can't cost much, either in performance or clarity.
I removed the NULL check from py_decref, and ran the testsuite.
It caused a GDB crash in py-pp-maint.exp. I did that before seeing your
note... See below. The issue is of course that make_cleanup_py_decref
is installed on a NULL object. I could have used make_cleanup_py_xdecref,
but I actually went the other way... I didn't mean to get myself
into Python hacking. :-) If you think this is not good, then I'll
just file a PR.
> Really I would prefer to get rid of decref cleanups at all, since they
> mess with the checker. But this is a pain, and probably not worth the
> effort unless we think we could really get to 0 false reports.
---
gdb/python/py-prettyprint.c | 6 +++++-
gdb/python/py-utils.c | 3 +--
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
index 8c45cd6..8fa2f42 100644
--- a/gdb/python/py-prettyprint.c
+++ b/gdb/python/py-prettyprint.c
@@ -735,8 +735,12 @@ apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
/* Find the constructor. */
printer = find_pretty_printer (val_obj);
Py_DECREF (val_obj);
+
+ if (printer == NULL)
+ goto done;
+
make_cleanup_py_decref (printer);
- if (! printer || printer == Py_None)
+ if (printer == Py_None)
goto done;
/* If we are printing a map, we want some special formatting. */
diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
index 80bacf7..7c7c5ca 100644
--- a/gdb/python/py-utils.c
+++ b/gdb/python/py-utils.c
@@ -31,8 +31,7 @@ py_decref (void *p)
{
PyObject *py = p;
- if (py)
- Py_DECREF (py);
+ Py_DECREF (py);
}
/* Return a new cleanup which will decrement the Python object's
--
Pedro Alves
^ permalink raw reply [flat|nested] 66+ messages in thread* Re: [patch] Compilation regression with python-2.6 [Re: [PATCH 24/28] introduce gdb_pymodule_addobject]
2013-05-21 16:48 ` Pedro Alves
@ 2013-05-21 17:32 ` Tom Tromey
2013-05-21 20:56 ` [COMMIT] py_decref: Don't check for NULL before calling Py_DECREF. (was: Re: [patch] Compilation regression with python-2.6) Pedro Alves
0 siblings, 1 reply; 66+ messages in thread
From: Tom Tromey @ 2013-05-21 17:32 UTC (permalink / raw)
To: Pedro Alves; +Cc: Jan Kratochvil, gdb-patches
>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
Pedro> If you think this is not good, then I'll just file a PR.
It is totally fine. Please check it in.
Tom
^ permalink raw reply [flat|nested] 66+ messages in thread
* [COMMIT] py_decref: Don't check for NULL before calling Py_DECREF. (was: Re: [patch] Compilation regression with python-2.6)
2013-05-21 17:32 ` Tom Tromey
@ 2013-05-21 20:56 ` Pedro Alves
0 siblings, 0 replies; 66+ messages in thread
From: Pedro Alves @ 2013-05-21 20:56 UTC (permalink / raw)
To: Tom Tromey; +Cc: Jan Kratochvil, gdb-patches
On 05/21/2013 06:32 PM, Tom Tromey wrote:
>>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
>
> Pedro> If you think this is not good, then I'll just file a PR.
>
> It is totally fine. Please check it in.
Thanks. Done.
---------
Subject: py_decref: Don't check for NULL before calling Py_DECREF.
The only difference between Py_DECREF and Py_XDECREF is that the latter allows passing
in a NULL object, while the former prohibits it. Given that, it's natural to expect
the same from py_decref vs py_xdecref.
gdb/
2013-05-21 Pedro Alves <palves@redhat.com>
* python/py-prettyprint.c (apply_val_pretty_printer): Check
whether PRINTER is NULL before installing a Py_DECREF cleanup.
* python/py-utils.c (py_decref): Don't check for NULL before
calling Py_DECREF.
---
gdb/python/py-prettyprint.c | 6 +++++-
gdb/python/py-utils.c | 3 +--
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
index 8c45cd6..8fa2f42 100644
--- a/gdb/python/py-prettyprint.c
+++ b/gdb/python/py-prettyprint.c
@@ -735,8 +735,12 @@ apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
/* Find the constructor. */
printer = find_pretty_printer (val_obj);
Py_DECREF (val_obj);
+
+ if (printer == NULL)
+ goto done;
+
make_cleanup_py_decref (printer);
- if (! printer || printer == Py_None)
+ if (printer == Py_None)
goto done;
/* If we are printing a map, we want some special formatting. */
diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
index 80bacf7..7c7c5ca 100644
--- a/gdb/python/py-utils.c
+++ b/gdb/python/py-utils.c
@@ -31,8 +31,7 @@ py_decref (void *p)
{
PyObject *py = p;
- if (py)
- Py_DECREF (py);
+ Py_DECREF (py);
}
/* Return a new cleanup which will decrement the Python object's
^ permalink raw reply [flat|nested] 66+ messages in thread
* [COMMIT] Centralize workaround for Python 2.6's Py_DECREF. (Re: [patch] Compilation regression with python-2.6)
2013-05-21 16:24 ` Pedro Alves
2013-05-21 16:36 ` Tom Tromey
@ 2013-05-21 20:55 ` Pedro Alves
1 sibling, 0 replies; 66+ messages in thread
From: Pedro Alves @ 2013-05-21 20:55 UTC (permalink / raw)
To: gdb-patches; +Cc: Jan Kratochvil, Tom Tromey
On 05/21/2013 05:23 PM, Pedro Alves wrote:
> Subject: Centralize workaround for Python 2.6's Py_DECREF.
>
> Wrap/redefine Py_DECREF ourselves, avoiding the need for uses to care
> about extra braces due to the fact that Python only started wrapping Py_DECREF
> in 'do {} while (0)' after 2.6.
>
> gdb/
> 2013-05-21 Pedro Alves <palves@redhat.com>
>
> * python/py-utils.c (py_decref): Remove extra braces.
> (gdb_pymodule_addobject): Remove extra braces.
> * python-internal.h (gdb_Py_DECREF): New static inline function.
> (Py_DECREF): Redefine as calling gdb_Py_DECREF.
I've applied this one.
--
Pedro Alves
^ permalink raw reply [flat|nested] 66+ messages in thread
* Python 2.4 compile failure (Re: [PATCH 24/28] introduce gdb_pymodule_addobject)
2013-04-19 17:46 ` [PATCH 24/28] introduce gdb_pymodule_addobject Tom Tromey
2013-05-21 7:58 ` [patch] Compilation regression with python-2.6 [Re: [PATCH 24/28] introduce gdb_pymodule_addobject] Jan Kratochvil
@ 2013-06-03 12:50 ` Ulrich Weigand
2013-06-03 16:06 ` Tom Tromey
1 sibling, 1 reply; 66+ messages in thread
From: Ulrich Weigand @ 2013-06-03 12:50 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
Tom Tromey wrote:
> +int
> +gdb_pymodule_addobject (PyObject *module, const char *name, PyObject *object)
> +{
> + int result;
> +
> + Py_INCREF (object);
> + result = PyModule_AddObject (module, name, object);
> + if (result < 0)
> + Py_DECREF (object);
> + return result;
> +}
This causes compile failures on one of our build servers which is
still using RHEL5 (which has Python 2.4 installed by default):
/home/kwerner/dailybuild/spu-tc-2013-06-02/gdb-head/src/gdb/python/py-utils.c: In function 'gdb_pymodule_addobject':
/home/kwerner/dailybuild/spu-tc-2013-06-02/gdb-head/src/gdb/python/py-utils.c:439: warning: passing argument 2 of 'PyModule_AddObject' discards qualifiers from pointer target type
The problem seems to be that in Python 2.4, gdb_pymodule_addobject takes
a "char *" instead of a "const char *":
/usr/include/python2.4/modsupport.h:PyAPI_FUNC(int) PyModule_AddObject(PyObject *, char *, PyObject *);
Now I guess 2.4 is quite old, but it is still supported according to
GDB documentation (and there are some special cases in the sources) ...
Should this be fixed?
Bye,
Ulrich
--
Dr. Ulrich Weigand
GNU Toolchain for Linux on System z and Cell BE
Ulrich.Weigand@de.ibm.com
^ permalink raw reply [flat|nested] 66+ messages in thread* Re: Python 2.4 compile failure (Re: [PATCH 24/28] introduce gdb_pymodule_addobject)
2013-06-03 12:50 ` Python 2.4 compile failure (Re: [PATCH 24/28] introduce gdb_pymodule_addobject) Ulrich Weigand
@ 2013-06-03 16:06 ` Tom Tromey
2013-06-03 16:54 ` Ulrich Weigand
2013-06-05 17:31 ` Tom Tromey
0 siblings, 2 replies; 66+ messages in thread
From: Tom Tromey @ 2013-06-03 16:06 UTC (permalink / raw)
To: Ulrich Weigand; +Cc: gdb-patches
Ulrich> Now I guess 2.4 is quite old, but it is still supported according to
Ulrich> GDB documentation (and there are some special cases in the sources) ...
Ulrich> Should this be fixed?
Yes. Can you please try the appended?
Tom
diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
index 7c7c5ca..bbbdef4 100644
--- a/gdb/python/py-utils.c
+++ b/gdb/python/py-utils.c
@@ -436,7 +436,8 @@ gdb_pymodule_addobject (PyObject *module, const char *name, PyObject *object)
int result;
Py_INCREF (object);
- result = PyModule_AddObject (module, name, object);
+ /* Python 2.4 did not have a 'const' here. */
+ result = PyModule_AddObject (module, (char *) name, object);
if (result < 0)
Py_DECREF (object);
return result;
^ permalink raw reply [flat|nested] 66+ messages in thread* Re: Python 2.4 compile failure (Re: [PATCH 24/28] introduce gdb_pymodule_addobject)
2013-06-03 16:06 ` Tom Tromey
@ 2013-06-03 16:54 ` Ulrich Weigand
2013-06-05 17:31 ` Tom Tromey
1 sibling, 0 replies; 66+ messages in thread
From: Ulrich Weigand @ 2013-06-03 16:54 UTC (permalink / raw)
To: tromey; +Cc: gdb-patches
Tom Tromey wrote:
> Ulrich> Now I guess 2.4 is quite old, but it is still supported according to
> Ulrich> GDB documentation (and there are some special cases in the sources) ...
>
> Ulrich> Should this be fixed?
>
> Yes. Can you please try the appended?
Yes, this works for me.
Thanks,
Ulrich
(PS: Not sure if the mail went through the first time,
sorry if you got it twice ...)
--
Dr. Ulrich Weigand
GNU Toolchain for Linux on System z and Cell BE
Ulrich.Weigand@de.ibm.com
^ permalink raw reply [flat|nested] 66+ messages in thread
* Re: Python 2.4 compile failure (Re: [PATCH 24/28] introduce gdb_pymodule_addobject)
2013-06-03 16:06 ` Tom Tromey
2013-06-03 16:54 ` Ulrich Weigand
@ 2013-06-05 17:31 ` Tom Tromey
1 sibling, 0 replies; 66+ messages in thread
From: Tom Tromey @ 2013-06-05 17:31 UTC (permalink / raw)
To: Ulrich Weigand; +Cc: gdb-patches
Tom> Yes. Can you please try the appended?
I'm checking it in with this ChangeLog entry:
2013-06-05 Tom Tromey <tromey@redhat.com>
* python/py-utils.c (gdb_pymodule_addobject): Cast away const.
Tom
^ permalink raw reply [flat|nested] 66+ messages in thread
* [PATCH 25/28] some py-frame.c changes to make the checker work better
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
` (25 preceding siblings ...)
2013-04-19 17:46 ` [PATCH 24/28] introduce gdb_pymodule_addobject Tom Tromey
@ 2013-04-19 17:49 ` Tom Tromey
2013-04-19 17:50 ` [PATCH 26/28] fix refcount bug in typy_fields Tom Tromey
` (3 subsequent siblings)
30 siblings, 0 replies; 66+ messages in thread
From: Tom Tromey @ 2013-04-19 17:49 UTC (permalink / raw)
To: gdb-patches
The checker complained about some code in py-frame.c that was simple
to refactor into a digestible form.
* python/py-frame.c (frapy_older, frapy_newer, gdbpy_newest_frame)
(gdbpy_selected_frame): Move object-construction code
out of TRY_CATCH.
---
gdb/python/py-frame.c | 46 ++++++++++++++++++++++------------------------
1 file changed, 22 insertions(+), 24 deletions(-)
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index 435eb50..a18ec1f 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -342,7 +342,7 @@ frame_info_to_frame_object (struct frame_info *frame)
static PyObject *
frapy_older (PyObject *self, PyObject *args)
{
- struct frame_info *frame, *prev;
+ struct frame_info *frame, *prev = NULL;
volatile struct gdb_exception except;
PyObject *prev_obj = NULL; /* Initialize to appease gcc warning. */
@@ -351,16 +351,17 @@ frapy_older (PyObject *self, PyObject *args)
FRAPY_REQUIRE_VALID (self, frame);
prev = get_prev_frame (frame);
- if (prev)
- prev_obj = (PyObject *) frame_info_to_frame_object (prev);
- else
- {
- Py_INCREF (Py_None);
- prev_obj = Py_None;
- }
}
GDB_PY_HANDLE_EXCEPTION (except);
+ if (prev)
+ prev_obj = (PyObject *) frame_info_to_frame_object (prev);
+ else
+ {
+ Py_INCREF (Py_None);
+ prev_obj = Py_None;
+ }
+
return prev_obj;
}
@@ -371,7 +372,7 @@ frapy_older (PyObject *self, PyObject *args)
static PyObject *
frapy_newer (PyObject *self, PyObject *args)
{
- struct frame_info *frame, *next;
+ struct frame_info *frame, *next = NULL;
volatile struct gdb_exception except;
PyObject *next_obj = NULL; /* Initialize to appease gcc warning. */
@@ -380,16 +381,17 @@ frapy_newer (PyObject *self, PyObject *args)
FRAPY_REQUIRE_VALID (self, frame);
next = get_next_frame (frame);
- if (next)
- next_obj = (PyObject *) frame_info_to_frame_object (next);
- else
- {
- Py_INCREF (Py_None);
- next_obj = Py_None;
- }
}
GDB_PY_HANDLE_EXCEPTION (except);
+ if (next)
+ next_obj = (PyObject *) frame_info_to_frame_object (next);
+ else
+ {
+ Py_INCREF (Py_None);
+ next_obj = Py_None;
+ }
+
return next_obj;
}
@@ -524,18 +526,16 @@ frapy_select (PyObject *self, PyObject *args)
PyObject *
gdbpy_newest_frame (PyObject *self, PyObject *args)
{
- struct frame_info *frame;
- PyObject *frame_obj = NULL; /* Initialize to appease gcc warning. */
+ struct frame_info *frame = NULL;
volatile struct gdb_exception except;
TRY_CATCH (except, RETURN_MASK_ALL)
{
frame = get_current_frame ();
- frame_obj = frame_info_to_frame_object (frame);
}
GDB_PY_HANDLE_EXCEPTION (except);
- return frame_obj;
+ return frame_info_to_frame_object (frame);
}
/* Implementation of gdb.selected_frame () -> gdb.Frame.
@@ -544,18 +544,16 @@ gdbpy_newest_frame (PyObject *self, PyObject *args)
PyObject *
gdbpy_selected_frame (PyObject *self, PyObject *args)
{
- struct frame_info *frame;
- PyObject *frame_obj = NULL; /* Initialize to appease gcc warning. */
+ struct frame_info *frame = NULL;
volatile struct gdb_exception except;
TRY_CATCH (except, RETURN_MASK_ALL)
{
frame = get_selected_frame ("No frame is currently selected.");
- frame_obj = frame_info_to_frame_object (frame);
}
GDB_PY_HANDLE_EXCEPTION (except);
- return frame_obj;
+ return frame_info_to_frame_object (frame);
}
/* Implementation of gdb.stop_reason_string (Integer) -> String.
--
1.8.1.4
^ permalink raw reply [flat|nested] 66+ messages in thread* [PATCH 26/28] fix refcount bug in typy_fields
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
` (26 preceding siblings ...)
2013-04-19 17:49 ` [PATCH 25/28] some py-frame.c changes to make the checker work better Tom Tromey
@ 2013-04-19 17:50 ` Tom Tromey
2013-04-19 17:52 ` [PATCH 27/28] rearrange for some clarity in valpy_get_dynamic_type Tom Tromey
` (2 subsequent siblings)
30 siblings, 0 replies; 66+ messages in thread
From: Tom Tromey @ 2013-04-19 17:50 UTC (permalink / raw)
To: gdb-patches
The checker found a bug in typy_fields -- we leaked a reference in one
path.
* python/py-type.c (typy_fields): Unconditionally decref 'r'.
---
gdb/python/py-type.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 63629fe..337e307 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -379,10 +379,7 @@ typy_fields (PyObject *self, PyObject *args)
return NULL;
rl = Py_BuildValue ("[O]", r);
- if (rl == NULL)
- {
- Py_DECREF (r);
- }
+ Py_DECREF (r);
return rl;
}
--
1.8.1.4
^ permalink raw reply [flat|nested] 66+ messages in thread* [PATCH 27/28] rearrange for some clarity in valpy_get_dynamic_type
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
` (27 preceding siblings ...)
2013-04-19 17:50 ` [PATCH 26/28] fix refcount bug in typy_fields Tom Tromey
@ 2013-04-19 17:52 ` Tom Tromey
2013-04-19 17:59 ` [PATCH 28/28] fix refcount bug in search_pp_list Tom Tromey
2013-05-20 20:06 ` [0/27] RFC: fix reports from the CPython checker Tom Tromey
30 siblings, 0 replies; 66+ messages in thread
From: Tom Tromey @ 2013-04-19 17:52 UTC (permalink / raw)
To: gdb-patches
The checker noticed some funny code in valpy_get_dynamic_type. This
simplifies the code a little and also changes an incref to an xincref;
the current code could crash if type_to_type_object failed.
* python/py-value.c (valpy_get_dynamic_type): Simplify
dynamic_type assignment. Use Py_XINCREF.
---
gdb/python/py-value.c | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index e4f4263..df4bf77 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -334,18 +334,11 @@ valpy_get_dynamic_type (PyObject *self, void *closure)
GDB_PY_HANDLE_EXCEPTION (except);
if (type == NULL)
- {
- /* Ensure that the TYPE field is ready. */
- if (!valpy_get_type (self, NULL))
- return NULL;
- /* We don't need to incref here, because valpy_get_type already
- did it for us. */
- obj->dynamic_type = obj->type;
- }
+ obj->dynamic_type = valpy_get_type (self, NULL);
else
obj->dynamic_type = type_to_type_object (type);
- Py_INCREF (obj->dynamic_type);
+ Py_XINCREF (obj->dynamic_type);
return obj->dynamic_type;
}
--
1.8.1.4
^ permalink raw reply [flat|nested] 66+ messages in thread* [PATCH 28/28] fix refcount bug in search_pp_list
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
` (28 preceding siblings ...)
2013-04-19 17:52 ` [PATCH 27/28] rearrange for some clarity in valpy_get_dynamic_type Tom Tromey
@ 2013-04-19 17:59 ` Tom Tromey
2013-05-20 20:06 ` [0/27] RFC: fix reports from the CPython checker Tom Tromey
30 siblings, 0 replies; 66+ messages in thread
From: Tom Tromey @ 2013-04-19 17:59 UTC (permalink / raw)
To: gdb-patches
The checker noticed a missing decref in search_pp_list.
* python/py-prettyprint.c (search_pp_list): Decref 'attr'.
---
gdb/python/py-prettyprint.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
index c337334..2d2af59 100644
--- a/gdb/python/py-prettyprint.c
+++ b/gdb/python/py-prettyprint.c
@@ -69,6 +69,7 @@ search_pp_list (PyObject *list, PyObject *value)
if (!attr)
return NULL;
cmp = PyObject_IsTrue (attr);
+ Py_DECREF (attr);
if (cmp == -1)
return NULL;
--
1.8.1.4
^ permalink raw reply [flat|nested] 66+ messages in thread* Re: [0/27] RFC: fix reports from the CPython checker
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
` (29 preceding siblings ...)
2013-04-19 17:59 ` [PATCH 28/28] fix refcount bug in search_pp_list Tom Tromey
@ 2013-05-20 20:06 ` Tom Tromey
30 siblings, 0 replies; 66+ messages in thread
From: Tom Tromey @ 2013-05-20 20:06 UTC (permalink / raw)
To: gdb-patches
>>>>> "Tom" == Tom Tromey <tromey@redhat.com> writes:
Tom> The Python plugin for GCC comes with an analyzer that checks the usage
Tom> of the CPython API:
Tom> https://gcc-python-plugin.readthedocs.org/en/latest/cpychecker.html
Tom> I ran this checker on gdb and fixed a number of bugs that it pointed
Tom> out.
I'm going to check this in now.
Tom
^ permalink raw reply [flat|nested] 66+ messages in thread