This is the mail archive of the archer@sourceware.org mailing list for the Archer 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]

[python] implement -enable-pretty-printing


This implements the MI command -enable-pretty-printing.

This is needed because we eventually realized that we can't
unconditionally enable pretty-printing in MI without either breaking
compatibility or making it appear that gdb is broken.

Unlike what was discussed on the gdb list, I made the new command take
no arguments.  I will follow up on the list at some point to explain
why; but I want to implement the whole proposal first so I can batch
all the issues that arise (if any more do arise).

Tom

b/gdb/ChangeLog:
2009-07-13  Tom Tromey  <tromey@redhat.com>

	* mi/mi-cmds.c (mi_cmds): Add enable-pretty-printing.
	* mi/mi-cmd-var.c (mi_cmd_enable_pretty_printing): New function.
	* varobj.c (pretty_printing): New global.
	(varobj_enable_pretty_printing): New function.
	(install_default_visualizer): Use new global.

b/gdb/doc/ChangeLog:
2009-07-13  Tom Tromey  <tromey@redhat.com>

	* gdb.texinfo (GDB/MI Variable Objects): Document
	-enable-pretty-printing.

b/gdb/testsuite/ChangeLog:
2009-07-13  Tom Tromey  <tromey@redhat.com>

	* gdb.python/python-mi.exp: Send -enable-pretty-printing.

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index b93bd75..d137e11 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -23587,6 +23587,8 @@ access this functionality:
 @item @strong{Operation}
 @tab @strong{Description}
 
+@item @code{-enable-pretty-printing}
+@tab enable Python-based pretty-printing
 @item @code{-var-create}
 @tab create a variable object
 @item @code{-var-delete}
@@ -23622,6 +23624,23 @@ how it can be used.
 
 @subheading Description And Use of Operations on Variable Objects
 
+@subheading The @code{-enable-pretty-printing} Command
+@findex -enable-pretty-printing
+
+@smallexample
+-enable-pretty-printing
+@end smallexample
+
+@var{GDBN} allows Python-based visualizers to affect the output of the
+MI variable object commands.  However, because there was no way to
+implement this in a fully backward-compatible way, a front end must
+request that this functionality be enabled.
+
+Once sent, this command cannot be undone.
+
+Note that if Python support has not been compiled into @var{GDBN},
+this command will still succeed.
+
 @subheading The @code{-var-create} Command
 @findex -var-create
 
diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
index 61e7ee5..5ee1586 100644
--- a/gdb/mi/mi-cmd-var.c
+++ b/gdb/mi/mi-cmd-var.c
@@ -751,3 +751,11 @@ varobj_update_one (struct varobj *var, enum print_values print_values,
     }
   VEC_free (varobj_update_result, changes);
 }
+
+void
+mi_cmd_enable_pretty_printing (char *command, char **argv, int argc)
+{
+  if (argc != 0)
+    error (_("mi_cmd_enable_pretty_printing: no arguments allowed"));
+  varobj_enable_pretty_printing ();
+}
diff --git a/gdb/mi/mi-cmds.c b/gdb/mi/mi-cmds.c
index 4911146..772566e 100644
--- a/gdb/mi/mi-cmds.c
+++ b/gdb/mi/mi-cmds.c
@@ -51,6 +51,7 @@ struct mi_cmd mi_cmds[] =
   { "data-write-memory", { NULL, 0 }, mi_cmd_data_write_memory},
   { "data-write-register-values", { NULL, 0 }, mi_cmd_data_write_register_values},
   { "enable-timings", { NULL, 0 }, mi_cmd_enable_timings},
+  { "enable-pretty-printing", { NULL, 0 }, mi_cmd_enable_pretty_printing},
   { "environment-cd", { NULL, 0 }, mi_cmd_env_cd},
   { "environment-directory", { NULL, 0 }, mi_cmd_env_dir},
   { "environment-path", { NULL, 0 }, mi_cmd_env_path},
diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
index afcba1e..79798ef 100644
--- a/gdb/mi/mi-cmds.h
+++ b/gdb/mi/mi-cmds.h
@@ -98,6 +98,7 @@ extern mi_cmd_argv_ftype mi_cmd_var_set_visualizer;
 extern mi_cmd_argv_ftype mi_cmd_var_show_attributes;
 extern mi_cmd_argv_ftype mi_cmd_var_show_format;
 extern mi_cmd_argv_ftype mi_cmd_var_update;
+extern mi_cmd_argv_ftype mi_cmd_enable_pretty_printing;
 
 /* Description of a single command. */
 
diff --git a/gdb/testsuite/gdb.python/python-mi.exp b/gdb/testsuite/gdb.python/python-mi.exp
index 8153f84..e7bfe54 100644
--- a/gdb/testsuite/gdb.python/python-mi.exp
+++ b/gdb/testsuite/gdb.python/python-mi.exp
@@ -48,7 +48,21 @@ mi_gdb_test "python execfile ('${srcdir}/${subdir}/${testfile}.py')" ""
 mi_continue_to_line [gdb_get_line_number {MI breakpoint here} ${testfile}.c] \
   "step to breakpoint"
 
-mi_create_floating_varobj container c "create container varobj"
+mi_create_floating_varobj container c \
+  "create container varobj, no pretty-printing"
+
+mi_list_varobj_children container {
+  { container.name name 1 string }
+  { container.len len 0 int }
+  { container.elements elements 1 "int ." }
+} "examine container children=0, no pretty-printing"
+
+mi_delete_varobj container "delete varobj"
+
+mi_gdb_test "-enable-pretty-printing" ""
+
+mi_create_floating_varobj container c \
+  "create container varobj"
 
 mi_list_varobj_children container {
 } "examine container children=0"
diff --git a/gdb/varobj.c b/gdb/varobj.c
index a774cdf..6c6b056 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -62,6 +62,15 @@ char *varobj_format_string[] =
 /* String representations of gdb's known languages */
 char *varobj_language_string[] = { "unknown", "C", "C++", "Java" };
 
+/* True if we want to allow Python-based pretty-printing.  */
+static int pretty_printing = 0;
+
+void
+varobj_enable_pretty_printing (void)
+{
+  pretty_printing = 1;
+}
+
 /* Data structures */
 
 /* Every root variable has one of these structures saved in its
@@ -1206,31 +1215,34 @@ install_visualizer (struct varobj *var, PyObject *constructor,
 static void
 install_default_visualizer (struct varobj *var)
 {
-  struct cleanup *cleanup;
-  PyGILState_STATE state;
-  PyObject *pretty_printer = NULL;
+  if (pretty_printing)
+    {
+      struct cleanup *cleanup;
+      PyGILState_STATE state;
+      PyObject *pretty_printer = NULL;
 
-  state = PyGILState_Ensure ();
-  cleanup = make_cleanup_py_restore_gil (&state);
+      state = PyGILState_Ensure ();
+      cleanup = make_cleanup_py_restore_gil (&state);
 
-  if (var->value)
-    {
-      pretty_printer = gdbpy_get_varobj_pretty_printer (var->value);
-      if (! pretty_printer)
+      if (var->value)
 	{
-	  gdbpy_print_stack ();
-	  error (_("Cannot instantiate printer for default visualizer"));
+	  pretty_printer = gdbpy_get_varobj_pretty_printer (var->value);
+	  if (! pretty_printer)
+	    {
+	      gdbpy_print_stack ();
+	      error (_("Cannot instantiate printer for default visualizer"));
+	    }
 	}
-    }
       
-  if (pretty_printer == Py_None)
-    {
-      Py_DECREF (pretty_printer);
-      pretty_printer = NULL;
-    }
+      if (pretty_printer == Py_None)
+	{
+	  Py_DECREF (pretty_printer);
+	  pretty_printer = NULL;
+	}
   
-  install_visualizer (var, NULL, pretty_printer);
-  do_cleanups (cleanup);
+      install_visualizer (var, NULL, pretty_printer);
+      do_cleanups (cleanup);
+    }
 }
 
 /* Instantiate and install a visualizer for VAR using CONSTRUCTOR to
diff --git a/gdb/varobj.h b/gdb/varobj.h
index bd2df2c..35053f8 100644
--- a/gdb/varobj.h
+++ b/gdb/varobj.h
@@ -157,4 +157,6 @@ extern int varobj_floating_p (struct varobj *var);
 extern void 
 varobj_set_visualizer (struct varobj *var, const char *visualizer);
 
+extern void varobj_enable_pretty_printing (void);
+
 #endif /* VAROBJ_H */


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