public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 2/2] test: ensure certain types exposed to python are not instancable
  2013-08-30 14:40 [PATCH 0/2] prevent gdb.Frame/Objfile and other types to be instanciated Sanimir Agovic
@ 2013-08-30 14:40 ` Sanimir Agovic
  2013-10-10 19:14   ` Tom Tromey
  2013-08-30 14:40 ` [PATCH 1/2] python: disallow python code to instanciate certain types Sanimir Agovic
  2013-10-10 19:10 ` [PATCH 0/2] prevent gdb.Frame/Objfile and other types to be instanciated Tom Tromey
  2 siblings, 1 reply; 9+ messages in thread
From: Sanimir Agovic @ 2013-08-30 14:40 UTC (permalink / raw)
  To: gdb-patches; +Cc: pmuldoon

The proc gdb_py_test_exception executes a piece of python code and
expects an exception of type EXCEPTION to be raised by the code with
an optional MESSAGE for fine grained filtering.

  # Example ...
  gdb_py_test_exception "gdb.Frame()" "TypeError" "cannot create 'gdb.Frame' instances"

  # ... w/o exception message
  gdb_py_test_exception "gdb.Frame()" "TypeError"

  # ... any exception
  gdb_py_test_exception "gdb.Frame()"

2013-08-30  Sanimir Agovic  <sanimir.agovic@intel.com>

testsuite/
	* lib/gdb-python.exp: Add proc gdb_py_test_exception.
	* gdb.python/py-arch.exp: Call gdb_py_test_exception gdb.Arhitecture.
	* gdb.python/py-block.exp: Call gdb_py_test_exception gdb.Block.
	* gdb.python/py-frame.exp: Call gdb_py_test_exception gdb.Frame.
	* gdb.python/py-inferior.exp: Call gdb_py_test_exception gdb.Inferior.
	* gdb.python/py-infthread.exp: Call gdb_py_test_exception gdb.Infthread.
	* gdb.python/py-progspace.exp: Use proc gdb_py_test_exception gdb.Progspace.
	* gdb.python/py-symtab.exp: Call gdb_py_test_exception gdb.Symtab and
        gdb_py_test_exception gdb.Symtab_and_line
	* gdb.python/py-type.exp: Call gdb_py_test_exception gdb.Type.

Change-Id: I8dfb4b42b43dbc1e3bdcb85b56bb202c84eec608
---
 gdb/testsuite/gdb.python/py-arch.exp      |    2 ++
 gdb/testsuite/gdb.python/py-block.exp     |    2 ++
 gdb/testsuite/gdb.python/py-frame.exp     |    2 ++
 gdb/testsuite/gdb.python/py-inferior.exp  |    2 ++
 gdb/testsuite/gdb.python/py-infthread.exp |    2 ++
 gdb/testsuite/gdb.python/py-progspace.exp |    4 ++++
 gdb/testsuite/gdb.python/py-symtab.exp    |    3 +++
 gdb/testsuite/gdb.python/py-type.exp      |    2 ++
 gdb/testsuite/lib/gdb-python.exp          |   14 ++++++++++++++
 9 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/gdb/testsuite/gdb.python/py-arch.exp b/gdb/testsuite/gdb.python/py-arch.exp
index 7413b44..9d4c2da 100644
--- a/gdb/testsuite/gdb.python/py-arch.exp
+++ b/gdb/testsuite/gdb.python/py-arch.exp
@@ -52,3 +52,5 @@ gdb_test "python print (\"length\" in insn)" "True" "test key length"
 # Negative test
 gdb_test "python arch.disassemble(0, 0)" ".*gdb\.MemoryError.*" \
   "test exception"
+
+gdb_py_test_exception "gdb.Architecture()" "TypeError"
diff --git a/gdb/testsuite/gdb.python/py-block.exp b/gdb/testsuite/gdb.python/py-block.exp
index 138ca3d..d6923ca 100644
--- a/gdb/testsuite/gdb.python/py-block.exp
+++ b/gdb/testsuite/gdb.python/py-block.exp
@@ -85,3 +85,5 @@ gdb_test "python print (block.is_valid())" "False" \
          "Check block validity"
 gdb_test "python print (block_iter.is_valid())" "False" \
          "Check block validity"
+
+gdb_py_test_exception "gdb.Block()" "TypeError"
diff --git a/gdb/testsuite/gdb.python/py-frame.exp b/gdb/testsuite/gdb.python/py-frame.exp
index 63e4afb..8136b18 100644
--- a/gdb/testsuite/gdb.python/py-frame.exp
+++ b/gdb/testsuite/gdb.python/py-frame.exp
@@ -94,3 +94,5 @@ gdb_test "python print ('result = %s' % f0.read_var ('variable_which_surely_does
 gdb_test "python print ('result = %s' % f0.read_var ('a'))" " = 1" "test Frame.read_var - success"
 
 gdb_test "python print ('result = %s' % (gdb.selected_frame () == f1))" " = True" "test gdb.selected_frame"
+
+gdb_py_test_exception "gdb.Frame()" "TypeError"
diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp
index 4c1dba7..b86115b 100644
--- a/gdb/testsuite/gdb.python/py-inferior.exp
+++ b/gdb/testsuite/gdb.python/py-inferior.exp
@@ -231,3 +231,5 @@ gdb_test "inferior 3" ".*" "Switch to third inferior"
 gdb_test "py print (gdb.selected_inferior().num)" "3" "Third inferior selected"
 gdb_test "inferior 1" ".*" "Switch to first inferior"
 gdb_test_no_output "remove-inferiors 3" "Remove second inferior"
+
+gdb_py_test_exception "gdb.Inferior()" "TypeError"
diff --git a/gdb/testsuite/gdb.python/py-infthread.exp b/gdb/testsuite/gdb.python/py-infthread.exp
index a26cdc1..0240a41 100644
--- a/gdb/testsuite/gdb.python/py-infthread.exp
+++ b/gdb/testsuite/gdb.python/py-infthread.exp
@@ -65,3 +65,5 @@ gdb_test "python print ('result = %s' % t0.is_exited ())" " = False" "test Infer
 gdb_test "python print ('result = %s' % t0.is_valid ())" " = True" "test InferiorThread.is_valid"
 gdb_test_no_output "kill inferior 1" "kill inferior 1"
 gdb_test "python print ('result = %s' % t0.is_valid ())" " = False" "test InferiorThread.is_valid"
+
+gdb_py_test_exception "gdb.InferiorThread()" "TypeError"
diff --git a/gdb/testsuite/gdb.python/py-progspace.exp b/gdb/testsuite/gdb.python/py-progspace.exp
index d101680..6e28adc 100644
--- a/gdb/testsuite/gdb.python/py-progspace.exp
+++ b/gdb/testsuite/gdb.python/py-progspace.exp
@@ -16,6 +16,8 @@
 # This file is part of the GDB testsuite.  It tests the program space
 # support in Python.
 
+load_lib gdb-python.exp
+
 standard_testfile
 
 if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} {
@@ -39,3 +41,5 @@ gdb_load ${binfile}
 
 gdb_test "python print (gdb.current_progspace().filename)" "py-progspace" \
   "current progspace filename (py-progspace)"
+
+gdb_py_test_exception "gdb.Progspace()" "TypeError"
diff --git a/gdb/testsuite/gdb.python/py-symtab.exp b/gdb/testsuite/gdb.python/py-symtab.exp
index f5279b1..b60eecc 100644
--- a/gdb/testsuite/gdb.python/py-symtab.exp
+++ b/gdb/testsuite/gdb.python/py-symtab.exp
@@ -76,3 +76,6 @@ gdb_test "python print (symtab.is_valid())" "False" "Test symtab.is_valid()"
 
 gdb_test_no_output "python sal = None" "Test sal destructor"
 gdb_test_no_output "python symtab = None" "Test symtab destructor"
+
+gdb_py_test_exception "gdb.Symtab()" "TypeError"
+gdb_py_test_exception "gdb.Symtab_and_line()" "TypeError"
diff --git a/gdb/testsuite/gdb.python/py-type.exp b/gdb/testsuite/gdb.python/py-type.exp
index f6b1d96..0da0940 100644
--- a/gdb/testsuite/gdb.python/py-type.exp
+++ b/gdb/testsuite/gdb.python/py-type.exp
@@ -254,3 +254,5 @@ with_test_prefix "lang_cpp" {
     test_template
     test_enums
 }
+
+gdb_py_test_exception "gdb.InferiorThread()" "TypeError"
diff --git a/gdb/testsuite/lib/gdb-python.exp b/gdb/testsuite/lib/gdb-python.exp
index 26ebf8f..1d6f229 100644
--- a/gdb/testsuite/lib/gdb-python.exp
+++ b/gdb/testsuite/lib/gdb-python.exp
@@ -45,3 +45,17 @@ proc gdb_py_test_multiple { name args } {
     }
     return 0
 }
+
+# Usage: gdb_py_test_exception STMT {EXCEPTION} {MESSAGE}
+# Executes python code named STMT which is expected to throw EXCEPTION
+# with MESSAGE.
+
+proc gdb_py_test_exception { stmt {exception "Exception"} {message .*} } {
+    gdb_py_test_multiple "$stmt throws $exception" \
+      "python" "" \
+      "try:" "" \
+      "   $stmt" "" \
+      "except $exception as e:" "" \
+      "   print \"$exception\",e.message" "" \
+      "end" "$exception $message"
+}
-- 
1.7.1.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/2] python: disallow python code to instanciate certain types
  2013-08-30 14:40 [PATCH 0/2] prevent gdb.Frame/Objfile and other types to be instanciated Sanimir Agovic
  2013-08-30 14:40 ` [PATCH 2/2] test: ensure certain types exposed to python are not instancable Sanimir Agovic
@ 2013-08-30 14:40 ` Sanimir Agovic
  2013-08-30 15:08   ` Phil Muldoon
  2013-10-10 19:06   ` Tom Tromey
  2013-10-10 19:10 ` [PATCH 0/2] prevent gdb.Frame/Objfile and other types to be instanciated Tom Tromey
  2 siblings, 2 replies; 9+ messages in thread
From: Sanimir Agovic @ 2013-08-30 14:40 UTC (permalink / raw)
  To: gdb-patches; +Cc: pmuldoon

I simply followed the pattern used for gdb.Type and assign NULL to tp_new
thus the type cannot be created from python code.

before>
(gdb) python gdb.Frame()
(gdb)

after>
(gdb) python gdb.Frame()
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: cannot create 'gdb.Frame' instances
Error while executing Python code.

2013-08-30  Sanimir Agovic  <sanimir.agovic@intel.com>

python/

	* py-arch.c (gdbpy_initialize_arch): Set tp_new implicitly to NULL.
	* py-block.c (gdbpy_initialize_blocks): Set tp_new implicitly to NULL.
	* py-frame.c (gdbpy_initialize_frames): Set tp_new implicitly to NULL.
	* py-objfile.c (objfpy_new): Remove function.
	(objfile_object_type): Set tp_new to NULL.
	* py-progspace.c (pspy_new): Remove function.
	(pspace_object_type): Set tp_new to NULL
	* py-symtab.c (gdbpy_initialize_symtabs): Set tp_new implicitly to NULL.

Change-Id: Ie9ced3d27f4a0660d160f651391a97ed7af4d1ce
---
 gdb/python/py-arch.c      |    1 -
 gdb/python/py-block.c     |    1 -
 gdb/python/py-frame.c     |    1 -
 gdb/python/py-objfile.c   |   35 +----------------------------------
 gdb/python/py-progspace.c |   35 +----------------------------------
 gdb/python/py-symtab.c    |    2 --
 6 files changed, 2 insertions(+), 73 deletions(-)

diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c
index 7098a8a..464ffb3 100644
--- a/gdb/python/py-arch.c
+++ b/gdb/python/py-arch.c
@@ -235,7 +235,6 @@ 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 -1;
 
diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c
index c74ac2c..b7a7264 100644
--- a/gdb/python/py-block.c
+++ b/gdb/python/py-block.c
@@ -428,7 +428,6 @@ del_objfile_blocks (struct objfile *objfile, void *datum)
 int
 gdbpy_initialize_blocks (void)
 {
-  block_object_type.tp_new = PyType_GenericNew;
   if (PyType_Ready (&block_object_type) < 0)
     return -1;
 
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index f960b08..5fd099e 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -620,7 +620,6 @@ frapy_richcompare (PyObject *self, PyObject *other, int op)
 int
 gdbpy_initialize_frames (void)
 {
-  frame_object_type.tp_new = PyType_GenericNew;
   if (PyType_Ready (&frame_object_type) < 0)
     return -1;
 
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index a954c9d..ddd6b79 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -69,39 +69,6 @@ objfpy_dealloc (PyObject *o)
   Py_TYPE (self)->tp_free (self);
 }
 
-static PyObject *
-objfpy_new (PyTypeObject *type, PyObject *args, PyObject *keywords)
-{
-  objfile_object *self = (objfile_object *) type->tp_alloc (type, 0);
-
-  if (self)
-    {
-      self->objfile = NULL;
-
-      self->printers = PyList_New (0);
-      if (!self->printers)
-	{
-	  Py_DECREF (self);
-	  return NULL;
-	}
-
-      self->frame_filters = PyDict_New ();
-      if (!self->frame_filters)
-	{
-	  Py_DECREF (self);
-	  return NULL;
-	}
-
-      self->type_printers = PyList_New (0);
-      if (!self->type_printers)
-	{
-	  Py_DECREF (self);
-	  return NULL;
-	}
-    }
-  return (PyObject *) self;
-}
-
 PyObject *
 objfpy_get_printers (PyObject *o, void *ignore)
 {
@@ -374,5 +341,5 @@ static PyTypeObject objfile_object_type =
   0,				  /* tp_dictoffset */
   0,				  /* tp_init */
   0,				  /* tp_alloc */
-  objfpy_new,			  /* tp_new */
+  0,				  /* tp_new */
 };
diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c
index 98eeecc..6634aae 100644
--- a/gdb/python/py-progspace.c
+++ b/gdb/python/py-progspace.c
@@ -77,39 +77,6 @@ pspy_dealloc (PyObject *self)
   Py_TYPE (self)->tp_free (self);
 }
 
-static PyObject *
-pspy_new (PyTypeObject *type, PyObject *args, PyObject *keywords)
-{
-  pspace_object *self = (pspace_object *) type->tp_alloc (type, 0);
-
-  if (self)
-    {
-      self->pspace = NULL;
-
-      self->printers = PyList_New (0);
-      if (!self->printers)
-	{
-	  Py_DECREF (self);
-	  return NULL;
-	}
-
-      self->frame_filters = PyDict_New ();
-      if (!self->frame_filters)
-	{
-	  Py_DECREF (self);
-	  return NULL;
-	}
-
-      self->type_printers = PyList_New (0);
-      if (!self->type_printers)
-	{
-	  Py_DECREF (self);
-	  return NULL;
-	}
-    }
-  return (PyObject *) self;
-}
-
 PyObject *
 pspy_get_printers (PyObject *o, void *ignore)
 {
@@ -361,5 +328,5 @@ static PyTypeObject pspace_object_type =
   0,				  /* tp_dictoffset */
   0,				  /* tp_init */
   0,				  /* tp_alloc */
-  pspy_new,			  /* tp_new */
+  0,				  /* tp_new */
 };
diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c
index 006946c..269feb8 100644
--- a/gdb/python/py-symtab.c
+++ b/gdb/python/py-symtab.c
@@ -484,11 +484,9 @@ del_objfile_sal (struct objfile *objfile, void *datum)
 int
 gdbpy_initialize_symtabs (void)
 {
-  symtab_object_type.tp_new = PyType_GenericNew;
   if (PyType_Ready (&symtab_object_type) < 0)
     return -1;
 
-  sal_object_type.tp_new = PyType_GenericNew;
   if (PyType_Ready (&sal_object_type) < 0)
     return -1;
 
-- 
1.7.1.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 0/2] prevent gdb.Frame/Objfile and other types to be instanciated
@ 2013-08-30 14:40 Sanimir Agovic
  2013-08-30 14:40 ` [PATCH 2/2] test: ensure certain types exposed to python are not instancable Sanimir Agovic
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Sanimir Agovic @ 2013-08-30 14:40 UTC (permalink / raw)
  To: gdb-patches; +Cc: pmuldoon

Hello,

as discussed in http://sourceware.org/ml/gdb-patches/2013-08/msg00848.html
the gdb/python interface exposes types which should not be instanciated
directly by python code. This patch now raising a TypeError if one instanciate
such type.

Test results:

$ make check RUNTESTFLAGS="--directory=gdb.python"

                === gdb tests ===

Schedule of variations:
    unix

Running target unix
Using /usr/share/dejagnu/baseboards/unix.exp as board description file for target.
Using /usr/share/dejagnu/config/unix.exp as generic interface file for target.
Using ../../../../gdb/gdb/testsuite/config/unix.exp as tool-and-target-specific interface file.
[...]
                === gdb Summary ===

# of expected passes            1705

 -Sanimir


Sanimir Agovic (2):
  python: disallow python code to instanciate certain types
  test: ensure certain types exposed to python are not instancable

 gdb/python/py-arch.c                      |    1 -
 gdb/python/py-block.c                     |    1 -
 gdb/python/py-frame.c                     |    1 -
 gdb/python/py-objfile.c                   |   35 +----------------------------
 gdb/python/py-progspace.c                 |   35 +----------------------------
 gdb/python/py-symtab.c                    |    2 -
 gdb/testsuite/gdb.python/py-arch.exp      |    2 +
 gdb/testsuite/gdb.python/py-block.exp     |    2 +
 gdb/testsuite/gdb.python/py-frame.exp     |    2 +
 gdb/testsuite/gdb.python/py-inferior.exp  |    2 +
 gdb/testsuite/gdb.python/py-infthread.exp |    2 +
 gdb/testsuite/gdb.python/py-progspace.exp |    4 +++
 gdb/testsuite/gdb.python/py-symtab.exp    |    3 ++
 gdb/testsuite/gdb.python/py-type.exp      |    2 +
 gdb/testsuite/lib/gdb-python.exp          |   14 +++++++++++
 15 files changed, 35 insertions(+), 73 deletions(-)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] python: disallow python code to instanciate certain types
  2013-08-30 14:40 ` [PATCH 1/2] python: disallow python code to instanciate certain types Sanimir Agovic
@ 2013-08-30 15:08   ` Phil Muldoon
  2013-10-10 19:08     ` Tom Tromey
  2013-10-10 19:06   ` Tom Tromey
  1 sibling, 1 reply; 9+ messages in thread
From: Phil Muldoon @ 2013-08-30 15:08 UTC (permalink / raw)
  To: Sanimir Agovic; +Cc: gdb-patches

On 30/08/13 15:40, Sanimir Agovic wrote:
> I simply followed the pattern used for gdb.Type and assign NULL to tp_new
> thus the type cannot be created from python code.
> 
> before>
> (gdb) python gdb.Frame()
> (gdb)
> 
> after>
> (gdb) python gdb.Frame()
> Traceback (most recent call last):
>   File "<string>", line 1, in <module>
> TypeError: cannot create 'gdb.Frame' instances
> Error while executing Python code.
> 
> 2013-08-30  Sanimir Agovic  <sanimir.agovic@intel.com>

Thanks.


> -static PyObject *
> -objfpy_new (PyTypeObject *type, PyObject *args, PyObject *keywords)
> -{
> -  objfile_object *self = (objfile_object *) type->tp_alloc (type, 0);
> -
> -  if (self)
> -    {
> -      self->objfile = NULL;
> -
> -      self->printers = PyList_New (0);
> -      if (!self->printers)
> -	{
> -	  Py_DECREF (self);
> -	  return NULL;
> -	}
> -
> -      self->frame_filters = PyDict_New ();
> -      if (!self->frame_filters)
> -	{
> -	  Py_DECREF (self);
> -	  return NULL;
> -	}
> -
> -      self->type_printers = PyList_New (0);
> -      if (!self->type_printers)
> -	{
> -	  Py_DECREF (self);
> -	  return NULL;
> -	}
> -    }
> -  return (PyObject *) self;
> -}

In removing this function, you are removing the instantiation of
self->printers (Which is needed for pretty-printers),
self->frame-filters (for frame filters) and self->type_printers (for
type printers).  If this is the case, and I have not missed an
equivalent instantiation somewhere else, you will have an
uninitialized PyObject for each of the above and likely will result in
a crash?  I'm surprised this did not crash GDB.  Each object file
keeps a separate list or dictionary of frame filters, pretty printers
and type printers that may be populated for object file specific
scenarios (like auto-loading). Also, I suspect the corresponding
clean-up function for these objects will crash when they are freed.


> -static PyObject *
> -pspy_new (PyTypeObject *type, PyObject *args, PyObject *keywords)
> -{
> -  pspace_object *self = (pspace_object *) type->tp_alloc (type, 0);
> -
> -  if (self)
> -    {
> -      self->pspace = NULL;
> -
> -      self->printers = PyList_New (0);
> -      if (!self->printers)
> -	{
> -	  Py_DECREF (self);
> -	  return NULL;
> -	}
> -
> -      self->frame_filters = PyDict_New ();
> -      if (!self->frame_filters)
> -	{
> -	  Py_DECREF (self);
> -	  return NULL;
> -	}
> -
> -      self->type_printers = PyList_New (0);
> -      if (!self->type_printers)
> -	{
> -	  Py_DECREF (self);
> -	  return NULL;
> -	}
> -    }
> -  return (PyObject *) self;
> -}
> -

Ditto, same with object files above.

Cheers,

Phil

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] python: disallow python code to instanciate certain types
  2013-08-30 14:40 ` [PATCH 1/2] python: disallow python code to instanciate certain types Sanimir Agovic
  2013-08-30 15:08   ` Phil Muldoon
@ 2013-10-10 19:06   ` Tom Tromey
  1 sibling, 0 replies; 9+ messages in thread
From: Tom Tromey @ 2013-10-10 19:06 UTC (permalink / raw)
  To: Sanimir Agovic; +Cc: gdb-patches, pmuldoon

>>>>> "Sanimir" == Sanimir Agovic <sanimir.agovic@intel.com> writes:

Sanimir> 2013-08-30  Sanimir Agovic  <sanimir.agovic@intel.com>
Sanimir> 	* py-arch.c (gdbpy_initialize_arch): Set tp_new implicitly to NULL.
Sanimir> 	* py-block.c (gdbpy_initialize_blocks): Set tp_new implicitly to NULL.
Sanimir> 	* py-frame.c (gdbpy_initialize_frames): Set tp_new implicitly to NULL.
Sanimir> 	* py-objfile.c (objfpy_new): Remove function.
Sanimir> 	(objfile_object_type): Set tp_new to NULL.
Sanimir> 	* py-progspace.c (pspy_new): Remove function.
Sanimir> 	(pspace_object_type): Set tp_new to NULL
Sanimir> 	* py-symtab.c (gdbpy_initialize_symtabs): Set tp_new implicitly to NULL.

This is ok.

Tom

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] python: disallow python code to instanciate certain types
  2013-08-30 15:08   ` Phil Muldoon
@ 2013-10-10 19:08     ` Tom Tromey
  0 siblings, 0 replies; 9+ messages in thread
From: Tom Tromey @ 2013-10-10 19:08 UTC (permalink / raw)
  To: Phil Muldoon; +Cc: Sanimir Agovic, gdb-patches

>> -static PyObject *
>> -objfpy_new (PyTypeObject *type, PyObject *args, PyObject *keywords)
[...]

Phil> In removing this function, you are removing the instantiation of
Phil> self-> printers (Which is needed for pretty-printers),
Phil> self-> frame-filters (for frame filters) and self->type_printers (for
Phil> type printers).  If this is the case, and I have not missed an
Phil> equivalent instantiation somewhere else, you will have an
Phil> uninitialized PyObject for each of the above and likely will result in
Phil> a crash?

Internal instantiations don't go through tp_new.  instead they use
PyObject_New.

In the case of objfile these fields are initialized in
objfile_to_objfile_object.

>> -static PyObject *
>> -pspy_new (PyTypeObject *type, PyObject *args, PyObject *keywords)

Phil> Ditto, same with object files above.

This is handled in pspace_to_pspace_object.

Tom

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/2] prevent gdb.Frame/Objfile and other types to be instanciated
  2013-08-30 14:40 [PATCH 0/2] prevent gdb.Frame/Objfile and other types to be instanciated Sanimir Agovic
  2013-08-30 14:40 ` [PATCH 2/2] test: ensure certain types exposed to python are not instancable Sanimir Agovic
  2013-08-30 14:40 ` [PATCH 1/2] python: disallow python code to instanciate certain types Sanimir Agovic
@ 2013-10-10 19:10 ` Tom Tromey
  2 siblings, 0 replies; 9+ messages in thread
From: Tom Tromey @ 2013-10-10 19:10 UTC (permalink / raw)
  To: Sanimir Agovic; +Cc: gdb-patches, pmuldoon

>>>>> "Sanimir" == Sanimir Agovic <sanimir.agovic@intel.com> writes:

Sanimir> as discussed in
Sanimir> http://sourceware.org/ml/gdb-patches/2013-08/msg00848.html the
Sanimir> gdb/python interface exposes types which should not be
Sanimir> instanciated directly by python code. This patch now raising a
Sanimir> TypeError if one instanciate such type.

It seems like a reasonable plan to me.
We never intended to allow instantiation of these objects; and most of
them are actually useless if instantiated.

Tom

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] test: ensure certain types exposed to python are not instancable
  2013-08-30 14:40 ` [PATCH 2/2] test: ensure certain types exposed to python are not instancable Sanimir Agovic
@ 2013-10-10 19:14   ` Tom Tromey
  2013-10-10 19:59     ` Paul_Koning
  0 siblings, 1 reply; 9+ messages in thread
From: Tom Tromey @ 2013-10-10 19:14 UTC (permalink / raw)
  To: Sanimir Agovic; +Cc: gdb-patches, pmuldoon

>>>>> "Sanimir" == Sanimir Agovic <sanimir.agovic@intel.com> writes:

Sanimir> The proc gdb_py_test_exception executes a piece of python code and
Sanimir> expects an exception of type EXCEPTION to be raised by the code with
Sanimir> an optional MESSAGE for fine grained filtering.

FWIW I generally put the test cases in the same patch as the
modification; same with the docs.  That's because they are a conceptual
unit.

It looks good, however --

Sanimir> +    gdb_py_test_multiple "$stmt throws $exception" \
Sanimir> +      "python" "" \
Sanimir> +      "try:" "" \
Sanimir> +      "   $stmt" "" \
Sanimir> +      "except $exception as e:" "" \

... there's one version of Python we support that doesn't have this
syntax.  I forget which one, I know Phil remembers though.

Tom

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] test: ensure certain types exposed to python are not instancable
  2013-10-10 19:14   ` Tom Tromey
@ 2013-10-10 19:59     ` Paul_Koning
  0 siblings, 0 replies; 9+ messages in thread
From: Paul_Koning @ 2013-10-10 19:59 UTC (permalink / raw)
  To: tromey; +Cc: sanimir.agovic, gdb-patches, pmuldoon

That syntax was added in Python 2.6.  If you want to handle older Pythons, you need to use plain "except $exception" and extract the value ("e") via "e = sys.exc_info ()[1]".  That workaround shows up in a number of other spots in the testsuite.

	paul

On Oct 10, 2013, at 3:14 PM, Tom Tromey <tromey@redhat.com> wrote:

>>>>>> "Sanimir" == Sanimir Agovic <sanimir.agovic@intel.com> writes:
> 
> Sanimir> The proc gdb_py_test_exception executes a piece of python code and
> Sanimir> expects an exception of type EXCEPTION to be raised by the code with
> Sanimir> an optional MESSAGE for fine grained filtering.
> 
> FWIW I generally put the test cases in the same patch as the
> modification; same with the docs.  That's because they are a conceptual
> unit.
> 
> It looks good, however --
> 
> Sanimir> +    gdb_py_test_multiple "$stmt throws $exception" \
> Sanimir> +      "python" "" \
> Sanimir> +      "try:" "" \
> Sanimir> +      "   $stmt" "" \
> Sanimir> +      "except $exception as e:" "" \
> 
> ... there's one version of Python we support that doesn't have this
> syntax.  I forget which one, I know Phil remembers though.
> 
> Tom

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-10-10 19:59 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-30 14:40 [PATCH 0/2] prevent gdb.Frame/Objfile and other types to be instanciated Sanimir Agovic
2013-08-30 14:40 ` [PATCH 2/2] test: ensure certain types exposed to python are not instancable Sanimir Agovic
2013-10-10 19:14   ` Tom Tromey
2013-10-10 19:59     ` Paul_Koning
2013-08-30 14:40 ` [PATCH 1/2] python: disallow python code to instanciate certain types Sanimir Agovic
2013-08-30 15:08   ` Phil Muldoon
2013-10-10 19:08     ` Tom Tromey
2013-10-10 19:06   ` Tom Tromey
2013-10-10 19:10 ` [PATCH 0/2] prevent gdb.Frame/Objfile and other types to be instanciated Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).