This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

patch for #14363


Hello,

this patch can be used to achieve a workaround to bug
http://sourceware.org/bugzilla/show_bug.cgi?id=14363
Besides being a workaround, it also is a new feature, enabling a pretty-printer to
control the pretty-printing on deeper recursion levels.


The bug:
Structures/classes which produce cyclic reference lead to an infinite recursion on
iterating children during pretty-pretting - leading to endless print and stack-overflow on gdb print.


What the patch does:
Before calling the pretty-printer, py-prettyprint.c:print_children() informs the pretty-printer about the current recursion level.
This is done by setting a property "level" if this property exists.


Changelog:

2012-08-02 Oliver Buchtala <oliver.buchtala@googlemail.com>

python/py-prettyprint.c: provide current recursion level to pretty printer.

>From 05a921d423793db93dfead59c9fe12d342f55d75 Mon Sep 17 00:00:00 2001
From: Oliver Buchtala <oliver.buchtala@googlemail.com>
Date: Wed, 1 Aug 2012 21:59:43 +0200
Subject: [PATCH] Adapt py-prettyprint to inform pretty-printer about current
 recursion level.

---
 gdb/python/py-prettyprint.c  |    3 +++
 gdb/python/python-internal.h |    1 +
 gdb/python/python.c          |    2 ++
 3 files changed, 6 insertions(+)

diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
index 86d4f2c..d5c6b66 100644
--- a/gdb/python/py-prettyprint.c
+++ b/gdb/python/py-prettyprint.c
@@ -476,6 +476,9 @@ print_children (PyObject *printer, const char *hint,
   if (! PyObject_HasAttr (printer, gdbpy_children_cst))
     return;
 
+  if ( PyObject_HasAttr (printer, gdbpy_level_cst))
+    PyObject_SetAttr(printer, gdbpy_level_cst, PyInt_FromLong((long) recurse));
+
   /* If we are printing a map or an array, we want some special
      formatting.  */
   is_map = hint && ! strcmp (hint, "map");
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index bae61c2..e600632 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -328,6 +328,7 @@ extern PyObject *gdbpy_to_string_cst;
 extern PyObject *gdbpy_display_hint_cst;
 extern PyObject *gdbpy_enabled_cst;
 extern PyObject *gdbpy_value_cst;
+extern PyObject *gdbpy_level_cst;
 
 /* Exception types.  */
 extern PyObject *gdbpy_gdb_error;
diff --git a/gdb/python/python.c b/gdb/python/python.c
index c66efe4..ae9e530 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -82,6 +82,7 @@ PyObject *gdbpy_display_hint_cst;
 PyObject *gdbpy_doc_cst;
 PyObject *gdbpy_enabled_cst;
 PyObject *gdbpy_value_cst;
+PyObject *gdbpy_level_cst;
 
 /* The GdbError exception.  */
 PyObject *gdbpy_gdberror_exc;
@@ -1305,6 +1306,7 @@ message == an error message without a stack will be printed."),
   gdbpy_doc_cst = PyString_FromString ("__doc__");
   gdbpy_enabled_cst = PyString_FromString ("enabled");
   gdbpy_value_cst = PyString_FromString ("value");
+  gdbpy_level_cst = PyString_FromString ("level");
 
   /* Release the GIL while gdb runs.  */
   PyThreadState_Swap (NULL);
-- 
1.7.9.5



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]