public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM]  archer-tromey-python: gdb
@ 2008-11-06 21:11 tromey
  0 siblings, 0 replies; 26+ messages in thread
From: tromey @ 2008-11-06 21:11 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-python has been updated
       via  6f0db4dff8d078bd334fc4f364adf0f792687dc1 (commit)
       via  f331e1ef50d42a6919c7c10f2983354b138b3cf0 (commit)
      from  95bc4ef80d85b793a2cc50d39db64f2e7abd8551 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 6f0db4dff8d078bd334fc4f364adf0f792687dc1
Author: Tom Tromey <tromey@redhat.com>
Date:   Thu Nov 6 14:09:53 2008 -0700

    gdb
    	* python/python.c (source_python_script): New function.
    	* python/python.h (source_python_script): Declare.
    	* cli/cli-cmds.c (find_argument): New function.
    	(source_command): Always run cleanup.  Use find_argument.  Handle
    	-p argument.  Use make_cleanup_restore_integer.
    	(source_verbose_cleanup): Remove.
    	(source_python): New global.
    	Include python.h.
    	(init_cli_cmds): Update.
    gdb/doc
    	* gdb.texinfo (File Options): Document -x on .py files.
    	(Command Files): Document source -p.

commit f331e1ef50d42a6919c7c10f2983354b138b3cf0
Author: Tom Tromey <tromey@redhat.com>
Date:   Thu Nov 6 13:23:31 2008 -0700

    	* python/python.c (GdbMethods): Make conditional.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog       |   16 +++++++++++
 gdb/cli/cli-cmds.c  |   70 +++++++++++++++++++++++++++++++++++++-------------
 gdb/doc/ChangeLog   |    5 +++
 gdb/doc/gdb.texinfo |   13 +++++++--
 gdb/python/python.c |   18 +++++++++++++
 gdb/python/python.h |    2 +
 6 files changed, 103 insertions(+), 21 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 9333dcf..210f2af 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,21 @@
 2008-11-06  Tom Tromey  <tromey@redhat.com>
 
+	* python/python.c (source_python_script): New function.
+	* python/python.h (source_python_script): Declare.
+	* cli/cli-cmds.c (find_argument): New function.
+	(source_command): Always run cleanup.  Use find_argument.  Handle
+	-p argument.  Use make_cleanup_restore_integer.
+	(source_verbose_cleanup): Remove.
+	(source_python): New global.
+	Include python.h.
+	(init_cli_cmds): Update.
+
+2008-11-06  Tom Tromey  <tromey@redhat.com>
+
+	* python/python.c (GdbMethods): Make conditional.
+
+2008-11-06  Tom Tromey  <tromey@redhat.com>
+
 	* varobj.c (struct varobj) <constructor>: New field.
 	(varobj_set_display_format): Update.
 	(varobj_get_display_hint): Likewise.
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index d9d2c56..92a59a3 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -45,6 +45,8 @@
 #include "cli/cli-setshow.h"
 #include "cli/cli-cmds.h"
 
+#include "python/python.h"
+
 #ifdef TUI
 #include "tui/tui.h"		/* For tui_active et.al.   */
 #endif
@@ -178,6 +180,7 @@ struct cmd_list_element *showchecklist;
 
 /* Command tracing state.  */
 
+static int source_python = 0;
 int source_verbose = 0;
 int trace_commands = 0;
 \f
@@ -437,6 +440,7 @@ source_script (char *file, int from_tty)
   struct cleanup *old_cleanups;
   char *full_pathname = NULL;
   int fd;
+  int is_python;
 
   if (file == NULL || *file == 0)
     {
@@ -465,8 +469,16 @@ source_script (char *file, int from_tty)
 	return;
     }
 
+  is_python = source_python;
+  if (strlen (file) > 3 && !strcmp (&file[strlen (file) - 3], ".py"))
+    is_python = 1;
+
   stream = fdopen (fd, FOPEN_RT);
-  script_from_file (stream, file);
+
+  if (is_python)
+    source_python_script (stream, file);
+  else
+    script_from_file (stream, file);
 
   do_cleanups (old_cleanups);
 }
@@ -480,15 +492,30 @@ source_verbose_cleanup (void *old_value)
   xfree (old_value);
 }
 
+/* A helper for source_command.  Look for an argument in *ARGS.
+   Update *ARGS by stripping leading whitespace.  If an argument is
+   found, return it (a character).  Otherwise, return 0.  */
+static int
+find_argument (char **args)
+{
+  int result = 0;
+  while (isspace ((*args)[0]))
+    ++*args;
+  if ((*args)[0] == '-' && isalpha ((*args)[1]))
+    {
+      result = (*args)[1];
+      *args += 3;
+    }
+  return result;
+}
+
 static void
 source_command (char *args, int from_tty)
 {
   struct cleanup *old_cleanups;
-  char *file = args;
-  int *old_source_verbose = xmalloc (sizeof(int));
 
-  *old_source_verbose = source_verbose;
-  old_cleanups = make_cleanup (source_verbose_cleanup, old_source_verbose);
+  old_cleanups = make_cleanup_restore_integer (&source_verbose);
+  make_cleanup_restore_integer (&source_python);
 
   /* -v causes the source command to run in verbose mode.
      We still have to be able to handle filenames with spaces in a
@@ -496,23 +523,28 @@ source_command (char *args, int from_tty)
 
   if (args)
     {
-      /* Make sure leading white space does not break the comparisons.  */
-      while (isspace(args[0]))
-	args++;
-
-      /* Is -v the first thing in the string?  */
-      if (args[0] == '-' && args[1] == 'v' && isspace (args[2]))
+      while (1)
 	{
-	  source_verbose = 1;
-
-	  /* Trim -v and whitespace from the filename.  */
-	  file = &args[3];
-	  while (isspace (file[0]))
-	    file++;
+	  int arg = find_argument (&args);
+	  if (!arg)
+	    break;
+	  switch (arg)
+	    {
+	    case 'v':
+	      source_verbose = 1;
+	      break;
+	    case 'p':
+	      source_python = 1;
+	      break;
+	    default:
+	      error (_("unrecognized option -%c"), arg);
+	    }
 	}
     }
 
-  source_script (file, from_tty);
+  source_script (args, from_tty);
+
+  do_cleanups (old_cleanups);
 }
 
 
@@ -1274,6 +1306,8 @@ Commands defined in this way may have up to ten arguments."));
 Read commands from a file named FILE.\n\
 Optional -v switch (before the filename) causes each command in\n\
 FILE to be echoed as it is executed.\n\
+Optional -p switch (before the filename) causes FILE to be evaluated\n\
+as Python code.\n\
 Note that the file \"%s\" is read automatically in this way\n\
 when GDB is started."), gdbinit);
   c = add_cmd ("source", class_support, source_command,
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 9d45150..a25df37 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,5 +1,10 @@
 2008-11-06  Tom Tromey  <tromey@redhat.com>
 
+	* gdb.texinfo (File Options): Document -x on .py files.
+	(Command Files): Document source -p.
+
+2008-11-06  Tom Tromey  <tromey@redhat.com>
+
 	* gdb.texinfo (Pretty Printing): Update.
 	(GDB/MI Variable Objects): Likewise.
 
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 071c912..a7038b5 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -962,8 +962,10 @@ Connect to process ID @var{number}, as with the @code{attach} command.
 @itemx -x @var{file}
 @cindex @code{--command}
 @cindex @code{-x}
-Execute @value{GDBN} commands from file @var{file}.  @xref{Command
-Files,, Command files}.
+Execute commands from file @var{file}.  If @var{file} ends in
+@samp{.py}, then the file is evaluated as Python code.  If Python
+support is not enabled in this @value{GDBN}, then an error occurs.
+@xref{Command Files,, Command files}.
 
 @item -eval-command @var{command}
 @itemx -ex @var{command}
@@ -17380,7 +17382,7 @@ command:
 @table @code
 @kindex source
 @cindex execute commands from a file
-@item source [@code{-v}] @var{filename}
+@item source [@code{-v}] [@code{-p}] @var{filename}
 Execute the command file @var{filename}.
 @end table
 
@@ -17397,6 +17399,11 @@ If @code{-v}, for verbose mode, is given then @value{GDBN} displays
 each command as it is executed.  The option must be given before
 @var{filename}, and is interpreted as part of the filename anywhere else.
 
+If @var{filename} ends in @samp{.py}, or if @code{-p}, for Python, is
+given then @value{GDBN} evaluates the contents of the file as Python
+code.  If Python support is not compiled in to @value{GDBN}, then an
+error occurs.
+
 Commands that would ask for confirmation if used interactively proceed
 without asking when used in a command file.  Many @value{GDBN} commands that
 normally print messages to say what they are doing omit the messages
diff --git a/gdb/python/python.c b/gdb/python/python.c
index d6cea7e..9f4448b 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -543,6 +543,13 @@ run_python_script (int argc, char **argv)
   exit (0);
 }
 
+void
+source_python_script (FILE *stream, char *file)
+{
+  PyRun_SimpleFile (stream, file);
+  fclose (stream);
+}
+
 \f
 
 /* The "current" objfile.  This is set when gdb detects that a new
@@ -1006,6 +1013,13 @@ apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
   return NULL;
 }
 
+void
+source_python_script (FILE *stream)
+{
+  fclose (stream);
+  error (_("Python scripting is not supported in this copy of GDB."));
+}
+
 #endif /* HAVE_PYTHON */
 
 \f
@@ -1175,6 +1189,8 @@ gdb._format_children = _format_children\n\
 
 \f
 
+#if HAVE_PYTHON
+
 static PyMethodDef GdbMethods[] =
 {
   { "get_value_from_history", gdbpy_get_value_from_history, METH_VARARGS,
@@ -1233,3 +1249,5 @@ Note: may later change to return an object." },
 
   {NULL, NULL, 0, NULL}
 };
+
+#endif /* HAVE_PYTHON */
diff --git a/gdb/python/python.h b/gdb/python/python.h
index bcba616..ef0560c 100644
--- a/gdb/python/python.h
+++ b/gdb/python/python.h
@@ -26,6 +26,8 @@ extern struct value *values_in_python;
 
 void eval_python_from_control_command (struct command_line *);
 
+void source_python_script (FILE *stream, char *file);
+
 void run_python_script (int argc, char **argv);
 
 char *apply_pretty_printer (struct value *, struct value **);


hooks/post-receive
--
Repository for Project Archer.


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

* [SCM]  archer-tromey-python: gdb
@ 2009-04-07 20:28 tromey
  0 siblings, 0 replies; 26+ messages in thread
From: tromey @ 2009-04-07 20:28 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-python has been updated
       via  1f080e897996d60ab7fde20423e2947512115667 (commit)
      from  27864e441f63a596e0c6896bf26e5594949332a3 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 1f080e897996d60ab7fde20423e2947512115667
Author: Tom Tromey <tromey@redhat.com>
Date:   Tue Apr 7 14:26:53 2009 -0600

    gdb
    	* python/python.c (GdbMethods): Add "lookup_type".
    	* python/python-internal.h (gdbpy_lookup_type): Declare.
    	* python/lib/gdb/libstdcxx/v6/printers.py: Update.
    	* python/lib/gdb/command/pahole.py: Update.
    	* python/python-value.c (value_object) <type>: New field.
    	(valpy_dealloc): Destroy type.
    	(valpy_new): Initialize new field.
    	(valpy_get_type): Rename.  Now a getter.
    	(value_to_value_object): Initialize new field.
    	(value_object_getset): Add "type".
    	(value_object_methods): Remove "type".
    	* python/python-type.c (field_dealloc): Call tp_free.
    	(typy_lookup_typename): Use GDB_PY_HANDLE_EXCEPTION.
    	(typy_new): Make name argument mandatory.
    	(typy_get_code): Rename.  Now a getter.
    	(typy_get_tag): Likewise.
    	(typy_get_sizeof): Likewise.  Don't throw an exception.
    	(type_object_getset): New global.
    	(type_object_type): Use it.
    	(type_object_methods): Remove getters.
    	(gdbpy_lookup_type): Move.  Rename from typy_new.
    gdb/doc
    	* gdb.texinfo (Types In Python): Rename and update.
    	(Values From Inferior): "type" is now an attribute.
    gdb/testsuite
    	* gdb.python/python-value.exp: Update.
    	* gdb.python/python-template.exp: Update.
    	* gdb.python/python-prettyprint.py: Update.
    	* gdb.python/find.exp: Update.

-----------------------------------------------------------------------

Summary of changes:
 gdb/doc/gdb.texinfo                            |  105 +++++++++----------
 gdb/python/lib/gdb/command/pahole.py           |   22 ++---
 gdb/python/lib/gdb/libstdcxx/v6/printers.py    |   50 +++++-----
 gdb/python/python-internal.h                   |    1 +
 gdb/python/python-type.c                       |  134 +++++++++++++-----------
 gdb/python/python-value.c                      |   26 ++++-
 gdb/python/python.c                            |    5 +
 gdb/testsuite/gdb.python/find.exp              |    8 +-
 gdb/testsuite/gdb.python/python-prettyprint.py |    8 +-
 gdb/testsuite/gdb.python/python-template.exp   |    4 +-
 gdb/testsuite/gdb.python/python-value.exp      |    4 +-
 11 files changed, 196 insertions(+), 171 deletions(-)

First 500 lines of diff:
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 4c92495..8b1b944 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -18135,7 +18135,7 @@ situation, a Python @code{KeyboardInterrupt} exception is thrown.
 * Exception Handling::
 * Auto-loading::                Automatically loading Python code.
 * Values From Inferior::	Python representation of values.
-* Types From Inferior::		Python representation of types.
+* Types In Python::		Python representation of types.
 * Pretty Printing::		Pretty-printing values.
 * Threads In Python::           Accessing inferior threads from Python.
 * Commands In Python::          Implementing new commands in Python.
@@ -18393,17 +18393,22 @@ Again, @code{bar} will also be a @code{gdb.Value} object.
 The following attributes are provided:
 
 @table @code
-@defmethod Value address
+@defivar Value address
 If this object is addressable, this read-only attribute holds a
 @code{gdb.Value} object representing the address.  Otherwise,
 this attribute holds @code{None}.
-@end defmethod
+@end defivar
 
 @cindex optimized out value in Python
-@defmethod Value is_optimized_out
+@defivar Value is_optimized_out
 This read-only boolean attribute is true if the compiler optimized out
 this value, thus it is not available for fetching from the inferior.
-@end defmethod
+@end defivar
+
+@defivar Value type
+The type of this @code{gdb.Value}.  The result is a @code{gdb.Type}
+object.
+@end defivar
 @end table
 
 The following methods are provided:
@@ -18463,43 +18468,62 @@ will be used, if the current language is able to supply one.
 The optional @var{errors} argument is the same as the corresponding
 argument to Python's @code{string.decode} method.
 @end defmethod
-
-@defmethod Value type
-Return the type of this @code{gdb.Value}.  The result is a
-@code{gdb.Type} object.
-@end defmethod
 @end table
 
-@node Types From Inferior
-@subsubsection Types From Inferior
+@node Types In Python
+@subsubsection Types In Python
+@cindex types in Python
+@cindex Python, working with types
 
-@cindex gdb.Type
+@tindex gdb.Type
 @value{GDBN} represents types from the inferior using the class
 @code{gdb.Type}.
 
-The following methods are provided:
-
-@table @code
-@defmethod Type Type [name [block]]
-Construct a new instance of @code{gdb.Type}.
+The following type-related functions are available in the @code{gdb}
+module:
 
-If @var{name} is given, it specifies the name of a type to look up in
-the inferior.
+@findex gdb.lookup_type
+@defun lookup_type name [block]
+This function looks up a type by name.  @var{name} is the name of the
+type to look up.  It must be a string.
 
 If @var{block} is given, then @var{name} is looked up in that scope.
 Otherwise, it is searched for globally.
-@end defmethod
 
-@defmethod Type code
-Return the type code for this type.  The type code will be one of the
+Ordinarily, this function will return an instance of @code{gdb.Type}.
+If the named type cannot be found, it will throw an exception.
+@end defun
+
+An instance of @code{Type} has the following attributes:
+
+@table @code
+@defivar Type code
+The type code for this type.  The type code will be one of the
 @code{TYPE_CODE_} constants defined below.
-@end defmethod
+@end defivar
 
+@defivar Type sizeof
+The size of this type, in target @code{char} units.  Usually, a
+target's @code{char} type will be an 8-bit byte.  However, on some
+unusual platforms, this type may have a different size.
+@end defivar
+
+@defivar Type tag
+The tag name for this type.  The tag name is the name after
+@code{struct}, @code{union}, or @code{enum} in C; not all languages
+have this concept.  If this type has no tag name, then @code{None} is
+returned.
+@end defivar
+@end table
+
+The following methods are provided:
+
+@table @code
 @defmethod Type fields
 For structure and union types, this method returns the fields.  Range
 types have two fields, the minimum and maximum values.  Enum types
 have one field per enum constant.  Function and method types have one
-field per parameter.  The base types of C++ classes are also
+field per parameter.  The base types of C@t{++} classes are also
 represented as fields.  If the type has no fields, or does not fit
 into one of these categories, an empty sequence will be returned.
 
@@ -18549,24 +18573,11 @@ Return a new @code{gdb.Type} object which represents a reference to this
 type.
 @end defmethod
 
-@defmethod Type sizeof
-Return the size of this type, in target @code{char} units.  Usually, a
-target's @code{char} type will be an 8-bit byte.  However, on some
-unusual platforms, this type may have a different size.
-@end defmethod
-
 @defmethod Type strip_typedefs
 Return a new @code{gdb.Type} that represents the real type,
 after removing all layers of typedefs.
 @end defmethod
 
-@defmethod Type tag
-Return the tag name for this type.  The tag name is the name after
-@code{struct}, @code{union}, or @code{enum} in C; not all languages
-have this concept.  If this type has no tag name, then @code{None} is
-returned.
-@end defmethod
-
 @defmethod Type target
 Return a new @code{gdb.Type} object which represents the target type
 of this type.
@@ -18626,8 +18637,7 @@ The type is an enum.
 @findex TYPE_CODE_FLAGS
 @findex gdb.TYPE_CODE_FLAGS
 @item TYPE_CODE_FLAGS
-A bit flags type.
-@c FIXME: what is this?
+A bit flags type, used for things such as status registers.
 
 @findex TYPE_CODE_FUNC
 @findex gdb.TYPE_CODE_FUNC
@@ -18678,7 +18688,7 @@ An unknown or erroneous type.
 @findex TYPE_CODE_METHOD
 @findex gdb.TYPE_CODE_METHOD
 @item TYPE_CODE_METHOD
-A C++ method type.
+A method type, as found in C++ or Java.
 
 @findex TYPE_CODE_METHODPTR
 @findex gdb.TYPE_CODE_METHODPTR
@@ -18715,19 +18725,6 @@ A complex float type.
 @item TYPE_CODE_TYPEDEF
 A typedef to some other type.
 
-@findex TYPE_CODE_TEMPLATE
-@findex gdb.TYPE_CODE_TEMPLATE
-@item TYPE_CODE_TEMPLATE
-A C++ template type.  Note that this is not used for a template
-instantiation; those appear as ordinary struct types.
-@c FIXME I hope that is true
-
-@findex TYPE_CODE_TEMPLATE_ARG
-@findex gdb.TYPE_CODE_TEMPLATE_ARG
-@item TYPE_CODE_TEMPLATE_ARG
-A C++ template argument.
-@c FIXME: is this ever used?
-
 @findex TYPE_CODE_NAMESPACE
 @findex gdb.TYPE_CODE_NAMESPACE
 @item TYPE_CODE_NAMESPACE
diff --git a/gdb/python/lib/gdb/command/pahole.py b/gdb/python/lib/gdb/command/pahole.py
index 569b816..21a0bf0 100644
--- a/gdb/python/lib/gdb/command/pahole.py
+++ b/gdb/python/lib/gdb/command/pahole.py
@@ -1,6 +1,6 @@
 # pahole command for gdb
 
-# Copyright (C) 2008 Free Software Foundation, Inc.
+# Copyright (C) 2008, 2009 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
@@ -26,16 +26,10 @@ It prints the type and displays comments showing where holes are."""
         super (Pahole, self).__init__ ("pahole", gdb.COMMAND_NONE,
                                        gdb.COMPLETE_SYMBOL)
 
-    @staticmethod
-    def strip (type):
-        while type.code () == gdb.TYPE_CODE_TYPEDEF:
-            type = type.target ()
-        return type
-
     def pahole (self, type, level, name):
         if name is None:
             name = ''
-        tag = type.tag ()
+        tag = type.tag
         if tag is None:
             tag = ''
         print '%sstruct %s {' % (' ' * (2 * level), tag)
@@ -45,7 +39,7 @@ It prints the type and displays comments showing where holes are."""
             if not hasattr (field, ('bitpos')):
                 continue
 
-            ftype = self.strip (field.type)
+            ftype = field.type.strip_typedefs()
 
             if bitpos != field.bitpos:
                 hole = field.bitpos - bitpos
@@ -55,13 +49,13 @@ It prints the type and displays comments showing where holes are."""
                 fieldsize = field.bitsize
             else:
                 # TARGET_CHAR_BIT here...
-                fieldsize = 8 * ftype.sizeof ()
+                fieldsize = 8 * ftype.sizeof
 
             # TARGET_CHAR_BIT
             print ' /* %3d %3d */' % (int (bitpos / 8), int (fieldsize / 8)),
             bitpos = bitpos + fieldsize
 
-            if ftype.code () == gdb.TYPE_CODE_STRUCT:
+            if ftype.code == gdb.TYPE_CODE_STRUCT:
                 self.pahole (ftype, level + 1, field.name)
             else:
                 print ' ' * (2 + 2 * level),
@@ -71,9 +65,9 @@ It prints the type and displays comments showing where holes are."""
         print '} %s' % name
 
     def invoke (self, arg, from_tty):
-        type = gdb.Type (arg)
-        type = self.strip (type)
-        if type.code () != gdb.TYPE_CODE_STRUCT:
+        type = gdb.lookup_type (arg)
+        type = type.strip_typedefs ()
+        if type.code != gdb.TYPE_CODE_STRUCT:
             raise TypeError, '%s is not a struct type' % arg
         print ' ' * 14,
         self.pahole (type, 0, '')
diff --git a/gdb/python/lib/gdb/libstdcxx/v6/printers.py b/gdb/python/lib/gdb/libstdcxx/v6/printers.py
index 149f1dd..2bd2593 100644
--- a/gdb/python/lib/gdb/libstdcxx/v6/printers.py
+++ b/gdb/python/lib/gdb/libstdcxx/v6/printers.py
@@ -68,8 +68,8 @@ class StdListPrinter:
         self.val = val
 
     def children(self):
-        itype = self.val.type().template_argument(0)
-        nodetype = gdb.Type('std::_List_node<%s>' % itype).pointer()
+        itype = self.val.type.template_argument(0)
+        nodetype = gdb.lookup_type('std::_List_node<%s>' % itype).pointer()
         return self._iterator(nodetype, self.val['_M_impl']['_M_node'])
 
     def to_string(self):
@@ -84,8 +84,8 @@ class StdListIteratorPrinter:
         self.val = val
 
     def to_string(self):
-        itype = self.val.type().template_argument(0)
-        nodetype = gdb.Type('std::_List_node<%s>' % itype).pointer()
+        itype = self.val.type.template_argument(0)
+        nodetype = gdb.lookup_type('std::_List_node<%s>' % itype).pointer()
         return self.val['_M_node'].cast(nodetype).dereference()['_M_data']
 
 class StdSlistPrinter:
@@ -113,8 +113,8 @@ class StdSlistPrinter:
         self.val = val
 
     def children(self):
-        itype = self.val.type().template_argument(0)
-        nodetype = gdb.Type('__gnu_cxx::_Slist_node<%s>' % itype).pointer()
+        itype = self.val.type.template_argument(0)
+        nodetype = gdb.lookup_type('__gnu_cxx::_Slist_node<%s>' % itype).pointer()
         return self._iterator(nodetype, self.val)
 
     def to_string(self):
@@ -129,8 +129,8 @@ class StdSlistIteratorPrinter:
         self.val = val
 
     def to_string(self):
-        itype = self.val.type().template_argument(0)
-        nodetype = gdb.Type('__gnu_cxx::_Slist_node<%s>' % itype).pointer()
+        itype = self.val.type.template_argument(0)
+        nodetype = gdb.lookup_type('__gnu_cxx::_Slist_node<%s>' % itype).pointer()
         return self.val['_M_node'].cast(nodetype).dereference()['_M_data']
 
 class StdVectorPrinter:
@@ -243,8 +243,8 @@ class StdRbtreeIteratorPrinter:
         self.val = val
 
     def to_string (self):
-        valuetype = self.val.type().template_argument(0)
-        nodetype = gdb.Type('std::_Rb_tree_node < %s >' % valuetype)
+        valuetype = self.val.type.template_argument(0)
+        nodetype = gdb.lookup_type('std::_Rb_tree_node < %s >' % valuetype)
         nodetype = nodetype.pointer()
         return self.val.cast(nodetype).dereference()['_M_value_field']
 
@@ -283,9 +283,9 @@ class StdMapPrinter:
         return '%s with %d elements' % (self.typename, len (self.iter))
 
     def children (self):
-        keytype = self.val.type().template_argument(0).const()
-        valuetype = self.val.type().template_argument(1)
-        nodetype = gdb.Type('std::_Rb_tree_node< std::pair< %s, %s > >' % (keytype, valuetype))
+        keytype = self.val.type.template_argument(0).const()
+        valuetype = self.val.type.template_argument(1)
+        nodetype = gdb.lookup_type('std::_Rb_tree_node< std::pair< %s, %s > >' % (keytype, valuetype))
         nodetype = nodetype.pointer()
         return self._iter (self.iter, nodetype)
 
@@ -323,8 +323,8 @@ class StdSetPrinter:
         return '%s with %d elements' % (self.typename, len (self.iter))
 
     def children (self):
-        keytype = self.val.type().template_argument(0)
-        nodetype = gdb.Type('std::_Rb_tree_node< %s >' % keytype).pointer()
+        keytype = self.val.type.template_argument(0)
+        nodetype = gdb.lookup_type('std::_Rb_tree_node< %s >' % keytype).pointer()
         return self._iter (self.iter, nodetype)
 
 class StdBitsetPrinter:
@@ -340,18 +340,18 @@ class StdBitsetPrinter:
 
     def children (self):
         words = self.val['_M_w']
-        wtype = words.type()
+        wtype = words.type
 
         # The _M_w member can be either an unsigned long, or an
         # array.  This depends on the template specialization used.
         # If it is a single long, convert to a single element list.
-        if wtype.code () == gdb.TYPE_CODE_ARRAY:
-            tsize = wtype.target ().sizeof ()
+        if wtype.code == gdb.TYPE_CODE_ARRAY:
+            tsize = wtype.target ().sizeof
         else:
             words = [words]
-            tsize = wtype.sizeof () 
+            tsize = wtype.sizeof 
 
-        nwords = wtype.sizeof() / tsize
+        nwords = wtype.sizeof / tsize
         result = []
         byte = 0
         while byte < nwords:
@@ -401,8 +401,8 @@ class StdDequePrinter:
 
     def __init__(self, val):
         self.val = val
-        self.elttype = val.type().template_argument(0)
-        size = self.elttype.sizeof ()
+        self.elttype = val.type.template_argument(0)
+        size = self.elttype.sizeof
         if size < 512:
             self.buffer_size = int (512 / size)
         else:
@@ -573,17 +573,17 @@ def lookup_function (val):
     "Look-up and return a pretty-printer that can print val."
 
     # Get the type.
-    type = val.type ();
+    type = val.type;
 
     # If it points to a reference, get the reference.
-    if type.code () == gdb.TYPE_CODE_REF:
+    if type.code == gdb.TYPE_CODE_REF:
         type = type.target ()
 
     # Get the unqualified type, stripped of typedefs.
     type = type.unqualified ().strip_typedefs ()
 
     # Get the type name.    
-    typename = type.tag ()
+    typename = type.tag
     if typename == None:
         return None
 
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 4aae0aa..5e43267 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -83,6 +83,7 @@ PyObject *gdbpy_selected_frame (PyObject *self, PyObject *args);
 PyObject *gdbpy_block_for_pc (PyObject *self, PyObject *args);
 PyObject *gdbpy_read_memory (PyObject *self, PyObject *args);
 PyObject *gdbpy_write_memory (PyObject *self, PyObject *args);
+PyObject *gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw);
 
 PyObject *symtab_and_line_to_sal_object (struct symtab_and_line sal);
 PyObject *symtab_to_symtab_object (struct symtab *symtab);
diff --git a/gdb/python/python-type.c b/gdb/python/python-type.c
index 2a54556..ec9ec46 100644
--- a/gdb/python/python-type.c
+++ b/gdb/python/python-type.c
@@ -103,6 +103,7 @@ field_dealloc (PyObject *obj)
 {
   field_object *f = (field_object *) obj;
   Py_XDECREF (f->dict);
+  f->ob_type->tp_free (obj);
 }
 
 static PyObject *
@@ -125,7 +126,7 @@ field_new (void)
 
 /* Return the code for this type.  */
 static PyObject *
-typy_code (PyObject *self, PyObject *args)
+typy_get_code (PyObject *self, void *closure)
 {
   struct type *type = ((type_object *) self)->type;
   return PyInt_FromLong (TYPE_CODE (type));
@@ -232,7 +233,7 @@ typy_fields (PyObject *self, PyObject *args)
 
 /* Return the type's tag, or None.  */
 static PyObject *
-typy_tag (PyObject *self, PyObject *args)
+typy_get_tag (PyObject *self, void *closure)
 {
   struct type *type = ((type_object *) self)->type;
   if (!TYPE_TAG_NAME (type))
@@ -346,16 +347,16 @@ typy_unqualified (PyObject *self, PyObject *args)
 
 /* Return the size of the type represented by SELF, in bytes.  */
 static PyObject *
-typy_sizeof (PyObject *self, PyObject *args)
+typy_get_sizeof (PyObject *self, void *closure)
 {
   struct type *type = ((type_object *) self)->type;
   volatile struct gdb_exception except;
 
   TRY_CATCH (except, RETURN_MASK_ALL)
     {
-      CHECK_TYPEDEF (type);
+      check_typedef (type);
     }
-  GDB_PY_HANDLE_EXCEPTION (except);
+  /* Ignore exceptions.  */
 
   return PyLong_FromLong (TYPE_LENGTH (type));
 }
@@ -595,47 +596,6 @@ set_type (type_object *obj, struct type *type)
     obj->next = NULL;
 }
 
-static PyObject *
-typy_new (PyTypeObject *subtype, PyObject *args, PyObject *kwargs)
-{
-  char *type_name = NULL;
-  struct type *type = NULL;
-  type_object *result;
-  PyObject *block_obj = NULL;
-  struct block *block = NULL;
-
-  /* FIXME: it is strange to allow a Type with no name, but we need
-     this for type_to_type_object.  */
-  if (! PyArg_ParseTuple (args, "|sO", &type_name, &block_obj))
-    return NULL;
-
-  if (block_obj)
-    {
-      block = block_object_to_block (block_obj);
-      if (! block)
-	{
-	  PyErr_SetString (PyExc_RuntimeError,
-			   "second argument must be block");
-	  return NULL;
-	}
-    }
-
-  if (type_name)
-    {
-      type = typy_lookup_typename (type_name, block);
-      if (! type)
-	return NULL;
-    }
-
-  result = (type_object *) subtype->tp_alloc (subtype, 1);
-  if (! result)
-    return NULL;
-
-  set_type (result, type);
-
-  return (PyObject *) result;
-}


hooks/post-receive
--
Repository for Project Archer.


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

* [SCM]  archer-tromey-python: gdb
@ 2009-03-24 17:27 tromey
  0 siblings, 0 replies; 26+ messages in thread
From: tromey @ 2009-03-24 17:27 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-python has been updated
       via  cb7eaa7343fa9fa04f8deee2471b85be2b44fe13 (commit)
      from  cb27ee6e1ada4fd6992dd51da402baef10ad88e3 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit cb7eaa7343fa9fa04f8deee2471b85be2b44fe13
Author: Tom Tromey <tromey@redhat.com>
Date:   Tue Mar 24 11:26:59 2009 -0600

    gdb
    	* python/python-type.c (convert_field): Handle a NULL type.
    gdb/doc
    	* gdb.texinfo (Types From Inferior): Update.

-----------------------------------------------------------------------

Summary of changes:
 gdb/doc/gdb.texinfo      |    3 ++-
 gdb/python/python-type.c |    9 ++++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

First 500 lines of diff:
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 7c01732..af3d12b 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -18522,7 +18522,8 @@ non-zero value, which is the size of the field in bits.  Otherwise,
 this will be zero; in this case the field's size is given by its type.
 
 @item type
-The type of the field.
+The type of the field.  This is usually an instance of @code{Type},
+but it can be @code{None} in some situations.
 @end table
 @end defmethod
 
diff --git a/gdb/python/python-type.c b/gdb/python/python-type.c
index d336456..2a54556 100644
--- a/gdb/python/python-type.c
+++ b/gdb/python/python-type.c
@@ -175,7 +175,14 @@ convert_field (struct type *type, int field)
   if (PyObject_SetAttrString (result, "bitsize", arg) < 0)
     goto failarg;
 
-  arg = type_to_type_object (TYPE_FIELD_TYPE (type, field));
+  /* A field can have a NULL type in some situations.  */
+  if (TYPE_FIELD_TYPE (type, field) == NULL)
+    {
+      arg = Py_None;
+      Py_INCREF (arg);
+    }
+  else
+    arg = type_to_type_object (TYPE_FIELD_TYPE (type, field));
   if (!arg)
     goto fail;
   if (PyObject_SetAttrString (result, "type", arg) < 0)


hooks/post-receive
--
Repository for Project Archer.


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

* [SCM]  archer-tromey-python: gdb
@ 2009-02-05 19:56 tromey
  0 siblings, 0 replies; 26+ messages in thread
From: tromey @ 2009-02-05 19:56 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-python has been updated
       via  945aa667ba5a3418910aff5c5f5a50a0eb686510 (commit)
      from  fa51997c482ef5fb4176fa354883c9ddc27ec300 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 945aa667ba5a3418910aff5c5f5a50a0eb686510
Author: Tom Tromey <tromey@redhat.com>
Date:   Thu Feb 5 12:55:54 2009 -0700

    gdb
    	* python/lib/gdb/command/save_breakpoints.py
    	(SaveBreakpointsCommand.invoke): Don't check for 'None'.
    	* python/lib/gdb/command/backtrace.py (FilteringBacktrace.invoke):
    	Don't check for 'None'.
    	* python/lib/gdb/command/alias.py (AliasImplementation.invoke):
    	Don't check for 'None'.
    	* NEWS: Mention commands feature.
    	* python/python-cmd.c (struct cmdpy_object) <sub_list>: Rewrite
    	comment.
    	(cmdpy_function): Always pass a string argument to 'invoke'.
    	(gdbpy_initialize_commands): Update comment.
    gdb/doc
    	* gdb.texinfo (Commands In Python): Update for change to 'invoke'
    	argument.  Fix a couple typos.  Update documentation for COMMAND_
    	constants.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog                                  |   14 ++++
 gdb/NEWS                                       |    2 +
 gdb/doc/ChangeLog                              |    6 ++
 gdb/doc/gdb.texinfo                            |   87 +++++++++++++++++-------
 gdb/python/lib/gdb/command/alias.py            |    5 +-
 gdb/python/lib/gdb/command/backtrace.py        |    2 -
 gdb/python/lib/gdb/command/save_breakpoints.py |    2 -
 gdb/python/python-cmd.c                        |   24 +++----
 8 files changed, 95 insertions(+), 47 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 9a95c2e..9164bfa 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,17 @@
+2009-02-05  Tom Tromey  <tromey@redhat.com>
+
+	* python/lib/gdb/command/save_breakpoints.py
+	(SaveBreakpointsCommand.invoke): Don't check for 'None'.
+	* python/lib/gdb/command/backtrace.py (FilteringBacktrace.invoke):
+	Don't check for 'None'.
+	* python/lib/gdb/command/alias.py (AliasImplementation.invoke):
+	Don't check for 'None'.
+	* NEWS: Mention commands feature.
+	* python/python-cmd.c (struct cmdpy_object) <sub_list>: Rewrite
+	comment.
+	(cmdpy_function): Always pass a string argument to 'invoke'.
+	(gdbpy_initialize_commands): Update comment.
+
 2009-02-05  Thiago Jung Bauermann  <bauerman@br.ibm.com>
 
 	* c-lang.c (c_get_string): Call check_typedef before examining the
diff --git a/gdb/NEWS b/gdb/NEWS
index 4532f9e..33f1029 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -96,6 +96,8 @@ are treated as the standard definitions, regardless of context.
   GDB now has support for scripting using Python.  Whether this is
   available is determined at configure time.
 
+  New GDB commands can now be written in Python.
+
 * Ada tasking support
 
   Ada tasks can now be inspected in GDB. The following commands have
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index c91b73f..628b681 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,9 @@
+2009-02-05  Tom Tromey  <tromey@redhat.com>
+
+	* gdb.texinfo (Commands In Python): Update for change to 'invoke'
+	argument.  Fix a couple typos.  Update documentation for COMMAND_
+	constants.
+
 2009-02-03  Thiago Jung Bauermann  <bauerman@br.ibm.com>
 
 	* gdb.texinfo (Functions in Python): Rephrasing as suggested by
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 9981607..9392168 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -18917,8 +18917,9 @@ command is a prefix command; sub-commands of this command may be
 registered.
 
 The help text for the new command is taken from the Python
-documentation string for the command's class, if there is one.  If
-there is no documentation string, a default value is used.
+documentation string for the command's class, if there is one.  If no
+documentation string is provided, the default value ``This command is
+not documented.'' is used.
 @end defmethod
 
 @defmethod Command dont_repeat
@@ -18931,9 +18932,8 @@ to the user command @code{dont-repeat}, see @ref{Define, dont-repeat}.
 @defmethod Command invoke argument from_tty
 This method is called by @value{GDBN} when this command is invoked.
 
-@var{argument} is the argument to the command.  The argument
-ordinarily is a string, but may be @code{None}, meaning that there was
-no argument.
+@var{argument} is a string.  It is the argument to the command, after
+leading and trailing whitespace has been stripped.
 
 @var{from_tty} is a boolean argument.  When true, this means that the
 command was entered by the user at the terminal; when false it means
@@ -18944,19 +18944,21 @@ If this method throws an exception, it is turned into a @value{GDBN}
 @end defmethod
 
 @defmethod Command complete text word
-This method is called by @value{GDBN} when the user attempts @key{TAB}
-completion on this command.
+This method is called by @value{GDBN} when the user attempts
+completion on this command.  All forms of completion are handled by
+this method, that is, the @key{TAB} and @key{M-?} key bindings, and
+the @code{complete} command.
 
 The arguments @var{text} and @var{word} are both strings.  @var{text}
 holds the complete command line up to the cursor's location.
 @var{word} holds the last word of the command line; this is computed
 using a word-breaking heuristic.
 
-The @code{invoke} method can return several values:
+The @code{complete} method can return several values:
 @itemize @bullet
 @item
 If the return value is a sequence, the contents of the sequence are
-used as the completions.  It is up to @code{invoke} to ensure that the
+used as the completions.  It is up to @code{complete} to ensure that the
 contents actually do complete the word.  A zero-length sequence is
 allowed, it means that there were no completions available.  Only
 string elements of the sequence are used; other elements in the
@@ -18975,76 +18977,108 @@ completions.
 
 
 When a new command is registered, it must be declared as a member of
-some general class of commands.  This is used to classify the command
-in the on-line help system.  The available classifications are
-represented by constants defined in the @code{gdb} module:
+some general class of commands.  This is used to classify top-level
+commands in the on-line help system; note that prefix commands are not
+listed under their own category but rather that of their top-level
+command.  The available classifications are represented by constants
+defined in the @code{gdb} module:
 
 @table @code
 @findex COMMAND_NONE
 @findex gdb.COMMAND_NONE
 @item COMMAND_NONE
-The command does not belong to any particular class.
+The command does not belong to any particular class.  A command in
+this category will not be displayed in any of the help categories.
 
 @findex COMMAND_RUN
 @findex gdb.COMMAND_RUN
 @item COMMAND_RUN
-The command is related to running the inferior.
+The command is related to running the inferior.  For example,
+@code{start}, @code{step}, and @code{continue} are in this category.
+Type @code{help running} at the @value{GDBN} prompt to see a list of
+commands in this category.
 
 @findex COMMAND_VARS
 @findex gdb.COMMAND_VARS
 @item COMMAND_VARS
-The command is related to variables.
+The command is related to data or variables.  For example,
+@code{call}, @code{find}, and @code{print} are in this category.  Type
+@code{help data} at the @value{GDBN} prompt to see a list of commands
+in this category.
 
 @findex COMMAND_STACK
 @findex gdb.COMMAND_STACK
 @item COMMAND_STACK
-The command has to do with manipulation of the stack.
+The command has to do with manipulation of the stack.  For example,
+@code{backtrace}, @code{frame}, and @code{return} are in this
+category.  Type @code{help stack} at the @value{GDBN} prompt to see a
+list of commands in this category.
 
 @findex COMMAND_FILES
 @findex gdb.COMMAND_FILES
 @item COMMAND_FILES
-This class is used for file-related commands.
+This class is used for file-related commands.  For example,
+@code{file}, @code{list} and @code{section} are in this category.
+Type @code{help files} at the @value{GDBN} prompt to see a list of
+commands in this category.
 
 @findex COMMAND_SUPPORT
 @findex gdb.COMMAND_SUPPORT
 @item COMMAND_SUPPORT
 This should be used for ``support facilities'', generally meaning
 things that are useful to the user when interacting with @value{GDBN},
-but not related to the state of the inferior.
+but not related to the state of the inferior.  For example,
+@code{help}, @code{make}, and @code{shell} are in this category.  Type
+@code{help support} at the @value{GDBN} prompt to see a list of
+commands in this category.
 
 @findex COMMAND_INFO
 @findex gdb.COMMAND_INFO
 @item COMMAND_INFO
 The command is an @samp{info}-related command, that is, related to the
-state of @value{GDBN} itself.
+state of @value{GDBN} itself.  For example, @code{info}, @code{macro},
+and @code{show} are in this category.  Type @code{help status} at the
+@value{GDBN} prompt to see a list of commands in this category.
 
 @findex COMMAND_BREAKPOINT
 @findex gdb.COMMAND_BREAKPOINT
 @item COMMAND_BREAKPOINT
-The command has to do with breakpoints.
+The command has to do with breakpoints.  For example, @code{break},
+@code{clear}, and @code{delete} are in this category.  Type @code{help
+breakpoints} at the @value{GDBN} prompt to see a list of commands in
+this category.
 
 @findex COMMAND_TRACE
 @findex gdb.COMMAND_TRACE
 @item COMMAND_TRACE
-The command has to do with tracepoints.
+The command has to do with tracepoints.  For example, @code{trace},
+@code{actions}, and @code{tfind} are in this category.  Type
+@code{help tracepoints} at the @value{GDBN} prompt to see a list of
+commands in this category.
 
 @findex COMMAND_OBSCURE
 @findex gdb.COMMAND_OBSCURE
 @item COMMAND_OBSCURE
 The command is only used in unusual circumstances, or is not of
-general interest to users.
+general interest to users.  For example, @code{checkpoint},
+@code{fork}, and @code{stop} are in this category.  Type @code{help
+obscure} at the @value{GDBN} prompt to see a list of commands in this
+category.
 
 @findex COMMAND_MAINTENANCE
 @findex gdb.COMMAND_MAINTENANCE
 @item COMMAND_MAINTENANCE
-The command is only useful to @value{GDBN} maintainers.
+The command is only useful to @value{GDBN} maintainers.  The
+@code{maintenance} and @code{flushregs} commands are in this category.
+Type @code{help internals} at the @value{GDBN} prompt to see a list of
+commands in this category.
 @end table
 
 
 A new command can use a predefined completion function, either by
-specifying it via an argument at initialization, or by return it from
-the @code{complete} method.  These predefined completion constants are
-all defined in the @code{gdb} module:
+specifying it via an argument at initialization, or by returning it
+from the @code{complete} method.  These predefined completion
+constants are all defined in the @code{gdb} module:
 
 @table @code
 @findex COMPLETE_NONE
@@ -19061,6 +19095,7 @@ This constant means that filename completion should be performed.
 @findex gdb.COMPLETE_LOCATION
 @item COMPLETE_LOCATION
 This constant means that location completion should be done.
+@xref{Specify Location}.
 
 @findex COMPLETE_COMMAND
 @findex gdb.COMPLETE_COMMAND
diff --git a/gdb/python/lib/gdb/command/alias.py b/gdb/python/lib/gdb/command/alias.py
index 53f52e5..96b6618 100644
--- a/gdb/python/lib/gdb/command/alias.py
+++ b/gdb/python/lib/gdb/command/alias.py
@@ -27,10 +27,7 @@ class AliasImplementation (gdb.Command):
         self.real = real
 
     def invoke(self, arg, from_tty):
-        if arg == None:
-            gdb.execute (self.real, from_tty)
-        else:
-            gdb.execute (self.real + ' ' + arg, from_tty)
+        gdb.execute (self.real + ' ' + arg, from_tty)
 
 class AliasCommand (gdb.Command):
     """Alias one command to another.
diff --git a/gdb/python/lib/gdb/command/backtrace.py b/gdb/python/lib/gdb/command/backtrace.py
index e01e2b6..008e5dd 100644
--- a/gdb/python/lib/gdb/command/backtrace.py
+++ b/gdb/python/lib/gdb/command/backtrace.py
@@ -160,8 +160,6 @@ Use of the 'raw' qualifier avoids any filtering by loadable modules.
         filter = True
         full = False
 
-        if arg == None:
-            arg = ''
         for word in arg.split (" "):
             if word == '':
                 continue
diff --git a/gdb/python/lib/gdb/command/save_breakpoints.py b/gdb/python/lib/gdb/command/save_breakpoints.py
index 14a27f7..90e07db 100644
--- a/gdb/python/lib/gdb/command/save_breakpoints.py
+++ b/gdb/python/lib/gdb/command/save_breakpoints.py
@@ -41,8 +41,6 @@ The breakpoints can be restored using the 'source' command."""
         bps = gdb.breakpoints ()
         if bps is None:
             raise RuntimeError, 'No breakpoints to save'
-        if arg is None:
-            raise RuntimeError, 'No filename specified'
         with open (arg.strip (), 'w') as f:
             for bp in bps:
                 print >> f, "break", bp.location,
diff --git a/gdb/python/python-cmd.c b/gdb/python/python-cmd.c
index 61d5e5d..50f1141 100644
--- a/gdb/python/python-cmd.c
+++ b/gdb/python/python-cmd.c
@@ -56,7 +56,10 @@ struct cmdpy_object
      no longer installed.  */
   struct cmd_list_element *command;
 
-  /* For a prefix command, this is the list of sub-commands.  */
+  /* A prefix command requires storage for a list of its sub-commands.
+     A pointer to this is passed to add_prefix_command, and to add_cmd
+     for sub-commands of that prefix.  If this Command is not a prefix
+     command, then this field is unused.  */
   struct cmd_list_element *sub_list;
 };
 
@@ -129,16 +132,11 @@ cmdpy_function (struct cmd_list_element *command, char *args, int from_tty)
     }
 
   if (! args)
-    {
-      argobj = Py_None;
-      Py_INCREF (argobj);
-    }
-  else
-    {
-      argobj = PyString_FromString (args);
-      if (! argobj)
-	error (_("Could not convert arguments to Python string."));
-    }
+    args = "";
+  argobj = PyString_FromString (args);
+  if (! argobj)
+    error (_("Could not convert arguments to Python string."));
+
   ttyobj = from_tty ? Py_True : Py_False;
   Py_INCREF (ttyobj);
   result = PyObject_CallMethodObjArgs ((PyObject *) obj, invoke_cst, argobj,
@@ -500,8 +498,8 @@ gdbpy_initialize_commands (void)
   if (PyType_Ready (&cmdpy_object_type) < 0)
     return;
 
-  /* Note: alias and user seem to be special; pseudo appears to be
-     unused, and there is no reason to expose tui or xdb, I think.  */
+  /* Note: alias and user are special; pseudo appears to be unused,
+     and there is no reason to expose tui or xdb, I think.  */
   if (PyModule_AddIntConstant (gdb_module, "COMMAND_NONE", no_class) < 0
       || PyModule_AddIntConstant (gdb_module, "COMMAND_RUN", class_run) < 0
       || PyModule_AddIntConstant (gdb_module, "COMMAND_VARS", class_vars) < 0


hooks/post-receive
--
Repository for Project Archer.


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

* [SCM]  archer-tromey-python: gdb
@ 2008-12-17 23:10 tromey
  0 siblings, 0 replies; 26+ messages in thread
From: tromey @ 2008-12-17 23:10 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-python has been updated
       via  dd619449eafdf274e2ec10002e15c0bcf912e16c (commit)
      from  61d61d47d50decc0d8193195026415a9e246777f (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit dd619449eafdf274e2ec10002e15c0bcf912e16c
Author: Tom Tromey <tromey@redhat.com>
Date:   Wed Dec 17 16:09:51 2008 -0700

    gdb
    	* python/lib/gdb/libstdcxx/v6/printers.py
    	(StdMapPrinter.children): Use type's const method.
    	* python/python-type.c (typy_const): New function.
    	(typy_volatile): Likewise.
    	(typy_unqualified): Likewise.
    	(type_object_methods): Add const, volatile, unqualified.
    gdb/doc
    	* gdb.texinfo (Types From Inferior): Document const, volatile,
    	and unqualified methods.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog                               |    9 +++++
 gdb/doc/ChangeLog                           |    5 +++
 gdb/doc/gdb.texinfo                         |   22 ++++++++++--
 gdb/python/lib/gdb/libstdcxx/v6/printers.py |    4 +-
 gdb/python/python-type.c                    |   53 +++++++++++++++++++++++++++
 5 files changed, 88 insertions(+), 5 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 7b48435..63ac2b4 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,12 @@
+2008-12-17  Tom Tromey  <tromey@redhat.com>
+
+	* python/lib/gdb/libstdcxx/v6/printers.py
+	(StdMapPrinter.children): Use type's const method.
+	* python/python-type.c (typy_const): New function.
+	(typy_volatile): Likewise.
+	(typy_unqualified): Likewise.
+	(type_object_methods): Add const, volatile, unqualified.
+
 2008-12-16  Tom Tromey  <tromey@redhat.com>
 
 	* python/python-frame.c (FRAPY_REQUIRE_VALID): Use error, not
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 5a29986..56cf330 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,8 @@
+2008-12-17  Tom Tromey  <tromey@redhat.com>
+
+	* gdb.texinfo (Types From Inferior): Document const, volatile,
+	and unqualified methods.
+
 2008-12-16  Thiago Jung Bauermann  <bauerman@br.ibm.com>
 
 	* gdb.texinfo (Commands in Python): Mention need of importing the gdb
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 6257660..13137ab 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -18377,9 +18377,25 @@ The type of the field.
 @end table
 @end defmethod
 
-@defmethod Type pointer
-Return a new @code{gdb.Type} object which represents a pointer to this
-type.
+@defmethod Type const
+Return a new @code{gdb.Type} object which represents a @code{const}
+qualified variant of this type.
+@end defmethod
+
+@defmethod Type const
+Return a new @code{gdb.Type} object which represents a
+@code{const}-qualified variant of this type.
+@end defmethod
+
+@defmethod Type volatile
+Return a new @code{gdb.Type} object which represents a
+@code{volatile}-qualified variant of this type.
+@end defmethod
+
+@defmethod Type unqualified
+Return a new @code{gdb.Type} object which represents an unqualified
+variant of this type.  That is, the result is neither @code{const} nor
+@code{volatile}.
 @end defmethod
 
 @defmethod Type reference
diff --git a/gdb/python/lib/gdb/libstdcxx/v6/printers.py b/gdb/python/lib/gdb/libstdcxx/v6/printers.py
index c03c682..4390553 100644
--- a/gdb/python/lib/gdb/libstdcxx/v6/printers.py
+++ b/gdb/python/lib/gdb/libstdcxx/v6/printers.py
@@ -232,9 +232,9 @@ class StdMapPrinter:
         return '%s with %d elements' % (self.typename, len (self.iter))
 
     def children (self):
-        keytype = self.val.type().template_argument(0)
+        keytype = self.val.type().template_argument(0).const()
         valuetype = self.val.type().template_argument(1)
-        nodetype = gdb.Type('std::_Rb_tree_node< std::pair< const %s, %s > >' % (keytype, valuetype))
+        nodetype = gdb.Type('std::_Rb_tree_node< std::pair< %s, %s > >' % (keytype, valuetype))
         nodetype = nodetype.pointer()
         return self._iter (self.iter, nodetype)
 
diff --git a/gdb/python/python-type.c b/gdb/python/python-type.c
index b2d3654..5aa82f6 100644
--- a/gdb/python/python-type.c
+++ b/gdb/python/python-type.c
@@ -280,6 +280,54 @@ typy_target (PyObject *self, PyObject *args)
   return type_to_type_object (TYPE_TARGET_TYPE (type));
 }
 
+/* Return a const-qualified type variant.  */
+static PyObject *
+typy_const (PyObject *self, PyObject *args)
+{
+  struct type *type = ((type_object *) self)->type;
+  volatile struct gdb_exception except;
+
+  TRY_CATCH (except, RETURN_MASK_ALL)
+    {
+      type = make_cv_type (1, 0, type, NULL);
+    }
+  GDB_PY_HANDLE_EXCEPTION (except);
+
+  return type_to_type_object (type);
+}
+
+/* Return a volatile-qualified type variant.  */
+static PyObject *
+typy_volatile (PyObject *self, PyObject *args)
+{
+  struct type *type = ((type_object *) self)->type;
+  volatile struct gdb_exception except;
+
+  TRY_CATCH (except, RETURN_MASK_ALL)
+    {
+      type = make_cv_type (0, 1, type, NULL);
+    }
+  GDB_PY_HANDLE_EXCEPTION (except);
+
+  return type_to_type_object (type);
+}
+
+/* Return an unqualified type variant.  */
+static PyObject *
+typy_unqualified (PyObject *self, PyObject *args)
+{
+  struct type *type = ((type_object *) self)->type;
+  volatile struct gdb_exception except;
+
+  TRY_CATCH (except, RETURN_MASK_ALL)
+    {
+      type = make_cv_type (0, 0, type, NULL);
+    }
+  GDB_PY_HANDLE_EXCEPTION (except);
+
+  return type_to_type_object (type);
+}
+
 /* Return the size of the type represented by SELF, in bytes.  */
 static PyObject *
 typy_sizeof (PyObject *self, PyObject *args)
@@ -652,6 +700,7 @@ gdbpy_initialize_types (void)
 static PyMethodDef type_object_methods[] =
 {
   { "code", typy_code, METH_NOARGS, "Return the code for this type" },
+  { "const", typy_const, METH_NOARGS, "Return a const variant of this type" },
   { "fields", typy_fields, METH_NOARGS,
     "Return a sequence holding all the fields of this type.\n\
 Each field is a dictionary." },
@@ -665,6 +714,10 @@ Each field is a dictionary." },
     "Return the target type of this type" },
   { "template_argument", typy_template_argument, METH_VARARGS,
     "Return a single template argument type" },
+  { "unqualified", typy_unqualified, METH_NOARGS,
+    "Return a variant of this type without const or volatile attributes" },
+  { "volatile", typy_volatile, METH_NOARGS,
+    "Return a volatile variant of this type" },
   { NULL }
 };
 


hooks/post-receive
--
Repository for Project Archer.


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

* [SCM]  archer-tromey-python: gdb
@ 2008-12-15 22:38 tromey
  0 siblings, 0 replies; 26+ messages in thread
From: tromey @ 2008-12-15 22:38 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-python has been updated
       via  3af011f203616a293e1d709fe074e5eb8e62660d (commit)
      from  7a5b414ecee8a41ec23abf555747f521e7e82c05 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 3af011f203616a293e1d709fe074e5eb8e62660d
Author: Tom Tromey <tromey@redhat.com>
Date:   Mon Dec 15 15:38:17 2008 -0700

    gdb
    	* python/python.c (gdbpy_new_objfile): Look in
    	debug_file_directory as well.
    gdb/doc
    	* gdb.texinfo (Auto-loading): Document debug-file-directory
    	search.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog       |    5 +++++
 gdb/doc/ChangeLog   |    5 +++++
 gdb/doc/gdb.texinfo |   15 +++++++++++----
 gdb/python/python.c |   17 +++++++++++++++++
 4 files changed, 38 insertions(+), 4 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index d147835..6828a6a 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
 2008-12-15  Tom Tromey  <tromey@redhat.com>
 
+	* python/python.c (gdbpy_new_objfile): Look in
+	debug_file_directory as well.
+
+2008-12-15  Tom Tromey  <tromey@redhat.com>
+
 	* python/python.c (print_children): Wrap after ",".
 
 2008-12-15  Tom Tromey  <tromey@redhat.com>
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 2f87e4c..bac5d78 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,5 +1,10 @@
 2008-12-15  Tom Tromey  <tromey@redhat.com>
 
+	* gdb.texinfo (Auto-loading): Document debug-file-directory
+	search.
+
+2008-12-15  Tom Tromey  <tromey@redhat.com>
+
 	* gdb.texinfo (Basic Python): Document gdb.breakpoints.
 	(Breakpoints in Python): New node.
 
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index dedf24b..1ada58b 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -18192,10 +18192,17 @@ traceback.
 When a new object file (@pxref{Objfiles in Python}) is read (for
 example, due to the @code{file} command, or because the inferior has
 loaded a shared library), @value{GDBN} will look for a file named by
-adding @samp{-gdb.py} to the object file's name.  If this file exists
-and is readable, @value{GDBN} will evaluate it as a Python script.
-Note that, if a separate debug file is used, @value{GDBN} will look
-for the @samp{-gdb.py} file both in the directory associated with the
+adding @samp{-gdb.py} to the object file's real name (the name formed
+after following all symlinks and resolving @code{.} and @code{..}
+components).  If this file exists and is readable, @value{GDBN} will
+evaluate it as a Python script.
+
+If this file does not exist, and if the parameter
+@code{debug-file-directory} is set, then @value{GDBN} will append the
+object file's real name to the value of this parameter, and try again.
+
+Also, if a separate debug file is used, @value{GDBN} will look for the
+@samp{-gdb.py} file both in the directory associated with the
 application and the directory associated with the separate debug file.
 
 When reading a @samp{-gdb.py} file, @var{GDBN} sets the ``current
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 9a1d321..fd84f60 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -741,6 +741,23 @@ gdbpy_new_objfile (struct objfile *objfile)
 
   input = fopen (filename, "r");
 
+  if (!input && debug_file_directory)
+    {
+      /* Also try the same file in the separate debug info directory.  */
+      char *debugfile;
+
+      debugfile = xmalloc (strlen (filename)
+			   + strlen (debug_file_directory) + 1);
+      strcpy (debugfile, debug_file_directory);
+      /* FILENAME is absolute, so we don't need a "/" here.  */
+      strcat (debugfile, filename);
+
+      xfree (filename);
+      filename = debugfile;
+
+      input = fopen (filename, "r");
+    }
+
   if (input)
     {
       /* We don't want to throw an exception here -- but the user


hooks/post-receive
--
Repository for Project Archer.


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

* [SCM]  archer-tromey-python: gdb
@ 2008-12-13  0:37 tromey
  0 siblings, 0 replies; 26+ messages in thread
From: tromey @ 2008-12-13  0:37 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-python has been updated
       via  d14f9aff2d79fcf0a60528377c57a33ce6c966e9 (commit)
      from  c02fba96626764b3be627d97f1697e85e76ff6a3 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit d14f9aff2d79fcf0a60528377c57a33ce6c966e9
Author: Tom Tromey <tromey@redhat.com>
Date:   Fri Dec 12 17:37:30 2008 -0700

    gdb
    	* python/lib/gdb/libstdcxx/v6/printers.py
    	(StdVectorPrinter.display_hint): Return 'array'.
    	(StdDequePrinter.display_hint): New method.
    	(StdStackOrQueuePrinter.display_hint): Likewise.
    	* python/python.c (print_children): Handle "array" hint.  Respect
    	"print elements".
    gdb/doc
    	* gdb.texinfo (Pretty Printing): Document 'array' hint.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog                               |    9 ++++++
 gdb/doc/ChangeLog                           |    4 +++
 gdb/doc/gdb.texinfo                         |    5 +++
 gdb/python/lib/gdb/libstdcxx/v6/printers.py |   10 ++++++-
 gdb/python/python.c                         |   38 ++++++++++++++++++++++++---
 5 files changed, 61 insertions(+), 5 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 6b857e5..1e6ddb5 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,6 +1,15 @@
 2008-12-12  Tom Tromey  <tromey@redhat.com>
 
 	* python/lib/gdb/libstdcxx/v6/printers.py
+	(StdVectorPrinter.display_hint): Return 'array'.
+	(StdDequePrinter.display_hint): New method.
+	(StdStackOrQueuePrinter.display_hint): Likewise.
+	* python/python.c (print_children): Handle "array" hint.  Respect
+	"print elements".
+
+2008-12-12  Tom Tromey  <tromey@redhat.com>
+
+	* python/lib/gdb/libstdcxx/v6/printers.py
 	(StdStringPrinter.display_hint): New method.
 	* python/python.c (apply_val_pretty_printer): Compute printer's
 	hint.
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index e194765..651b91d 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,5 +1,9 @@
 2008-12-12  Tom Tromey  <tromey@redhat.com>
 
+	* gdb.texinfo (Pretty Printing): Document 'array' hint.
+
+2008-12-12  Tom Tromey  <tromey@redhat.com>
+
 	* gdb.texinfo (Pretty Printing): Document 'string' hint.
 
 2008-12-10  Tom Tromey  <tromey@redhat.com>
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index fd17158..eeaaf61 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -18602,6 +18602,11 @@ being printed.
 Some display hints are predefined by @value{GDBN}:
 
 @table @samp
+@item array
+Indicate that the object being printed is ``array-like''.  The CLI
+uses this to respect parameters such as @code{set print elements} and
+@code{set print array}.
+
 @item map
 Indicate that the object being printed is ``map-like'', and that the
 children of this value can be assumed to alternate between keys and
diff --git a/gdb/python/lib/gdb/libstdcxx/v6/printers.py b/gdb/python/lib/gdb/libstdcxx/v6/printers.py
index 1ea4dd2..c03c682 100644
--- a/gdb/python/lib/gdb/libstdcxx/v6/printers.py
+++ b/gdb/python/lib/gdb/libstdcxx/v6/printers.py
@@ -143,7 +143,7 @@ class StdVectorPrinter:
                 % (int (finish - start), int (end - start)))
 
     def display_hint(self):
-        return 'whatever'
+        return 'array'
 
 class StdStackOrQueuePrinter:
     "Print a std::stack or std::queue"
@@ -159,6 +159,11 @@ class StdStackOrQueuePrinter:
         return '%s wrapping: %s' % (self.typename,
                                     self.visualizer.to_string())
 
+    def display_hint (self):
+        if hasattr (self.visualizer, 'display_hint'):
+            return self.visualizer.display_hint ()
+        return None
+
 class RbtreeIterator:
     def __init__(self, rbtree):
         self.size = rbtree['_M_t']['_M_impl']['_M_node_count']
@@ -361,6 +366,9 @@ class StdDequePrinter:
         return self._iter(start['_M_node'], start['_M_cur'], start['_M_last'],
                           end['_M_cur'], self.buffer_size)
 
+    def display_hint (self):
+        return 'array'
+
 class WideEncoding (gdb.Parameter):
     """The target wide character set is the encoding used for wchar_t."""
 
diff --git a/gdb/python/python.c b/gdb/python/python.c
index c2d4897..36e8356 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1023,15 +1023,18 @@ print_children (PyObject *printer, const char *hint,
 		const struct value_print_options *options,
 		const struct language_defn *language)
 {
-  int is_map, i;
+  int is_map, is_array, done_flag;
+  unsigned int i;
   PyObject *children, *iter;
   struct cleanup *cleanups;
 
   if (! PyObject_HasAttr (printer, gdbpy_children_cst))
     return;
 
-  /* If we are printing a map, we want some special formatting.  */
+  /* If we are printing a map or an array, we want some special
+     formatting.  */
   is_map = hint && ! strcmp (hint, "map");
+  is_array = hint && ! strcmp (hint, "array");
 
   children = PyObject_CallMethodObjArgs (printer, gdbpy_children_cst,
 					 NULL);
@@ -1051,14 +1054,20 @@ print_children (PyObject *printer, const char *hint,
     }
   make_cleanup_py_decref (iter);
 
-  for (i = 0; ; ++i)
+  done_flag = 0;
+  for (i = 0; i < options->print_max; ++i)
     {
       PyObject *py_v, *item = PyIter_Next (iter);
       char *name;
       struct cleanup *inner_cleanup;
 
       if (! item)
-	break;
+	{
+	  /* Set a flag so we can know whether we printed all the
+	     available elements.  */
+	  done_flag = 1;
+	  break;
+	}
 
       if (! PyArg_ParseTuple (item, "sO", &name, &py_v))
 	{
@@ -1068,6 +1077,11 @@ print_children (PyObject *printer, const char *hint,
 	}
       inner_cleanup = make_cleanup_py_decref (item);
 
+      /* Print initial "{".  For other elements, there are three
+	 cases:
+	 1. Maps.  Print a "," after each value element.
+	 2. Arrays.  Always print a ",".
+	 3. Other.  Always print a ",".  */
       if (i == 0)
 	fputs_filtered (" = {", stream);
       else if (! is_map || i % 2 == 0)
@@ -1081,6 +1095,13 @@ print_children (PyObject *printer, const char *hint,
 
       if (is_map && i % 2 == 0)
 	fputs_filtered ("[", stream);
+      else if (is_array)
+	{
+	  /* We print the index, not whatever the child method
+	     returned as the name.  */
+	  if (options->print_array_indexes)
+	    fprintf_filtered (stream, "[%d] = ", i);
+	}
       else if (! is_map)
 	{
 	  fputs_filtered (name, stream);
@@ -1114,6 +1135,15 @@ print_children (PyObject *printer, const char *hint,
 
   if (i)
     {
+      if (!done_flag)
+	{
+	  if (options->pretty)
+	    {
+	      fputs_filtered ("\n", stream);
+	      print_spaces_filtered (2 + 2 * recurse, stream);
+	    }
+	  fputs_filtered ("...", stream);
+	}
       if (options->pretty)
 	{
 	  fputs_filtered ("\n", stream);


hooks/post-receive
--
Repository for Project Archer.


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

* [SCM]  archer-tromey-python: gdb
@ 2008-12-12 23:54 tromey
  0 siblings, 0 replies; 26+ messages in thread
From: tromey @ 2008-12-12 23:54 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-python has been updated
       via  c02fba96626764b3be627d97f1697e85e76ff6a3 (commit)
      from  ab8c44cb00aed42589972ef0e0cea4cb9d644fba (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit c02fba96626764b3be627d97f1697e85e76ff6a3
Author: Tom Tromey <tromey@redhat.com>
Date:   Fri Dec 12 16:53:57 2008 -0700

    gdb
    	* python/lib/gdb/libstdcxx/v6/printers.py
    	(StdStringPrinter.display_hint): New method.
    	* python/python.c (apply_val_pretty_printer): Compute printer's
    	hint.
    	(print_string_repr): Add "hint" argument.  Recognize "string"
    	hint.
    	(print_children): Add "hint" argument.
    gdb/doc
    	* gdb.texinfo (Pretty Printing): Document 'string' hint.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog                               |   10 ++++++++
 gdb/doc/ChangeLog                           |    4 +++
 gdb/doc/gdb.texinfo                         |   14 +++++++++--
 gdb/python/lib/gdb/libstdcxx/v6/printers.py |    3 ++
 gdb/python/python.c                         |   32 +++++++++++++++-----------
 5 files changed, 46 insertions(+), 17 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index ef0bf91..6b857e5 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,13 @@
+2008-12-12  Tom Tromey  <tromey@redhat.com>
+
+	* python/lib/gdb/libstdcxx/v6/printers.py
+	(StdStringPrinter.display_hint): New method.
+	* python/python.c (apply_val_pretty_printer): Compute printer's
+	hint.
+	(print_string_repr): Add "hint" argument.  Recognize "string"
+	hint.
+	(print_children): Add "hint" argument.
+
 2008-12-10  Tom Tromey  <tromey@redhat.com>
 
 	* python/python.c: Include event-loop.h.
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index d35643c..e194765 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,7 @@
+2008-12-12  Tom Tromey  <tromey@redhat.com>
+
+	* gdb.texinfo (Pretty Printing): Document 'string' hint.
+
 2008-12-10  Tom Tromey  <tromey@redhat.com>
 
 	* gdb.texinfo (Basic Python): Document post_event.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index ea6698c..fd17158 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -18603,9 +18603,17 @@ Some display hints are predefined by @value{GDBN}:
 
 @table @samp
 @item map
-Indicate to the MI consumer that the object being printed is
-``map-like'', and that the children of this value can be assumed to
-alternate between keys and values.
+Indicate that the object being printed is ``map-like'', and that the
+children of this value can be assumed to alternate between keys and
+values.
+
+@item string
+Indicate that the object being printed is ``string-like''.  If the
+printer's @code{to_string} method returns a Python string of some
+kind, then @value{GDBN} will call its internal language-specific
+string-printing function to format the string.  For the CLI this means
+adding quotation marks, possibly escaping some characters, respecting
+@code{set print elements}, and the like.
 @end table
 @end defop
 
diff --git a/gdb/python/lib/gdb/libstdcxx/v6/printers.py b/gdb/python/lib/gdb/libstdcxx/v6/printers.py
index a7964c5..1ea4dd2 100644
--- a/gdb/python/lib/gdb/libstdcxx/v6/printers.py
+++ b/gdb/python/lib/gdb/libstdcxx/v6/printers.py
@@ -393,6 +393,9 @@ class StdStringPrinter:
             encoding = encoding.value
         return self.val['_M_dataplus']['_M_p'].string(encoding)
 
+    def display_hint (self):
+        return 'string'
+
 class Tr1HashtableIterator:
     def __init__ (self, hash):
         self.count = 0
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 1432e5e..c2d4897 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -991,7 +991,8 @@ gdbpy_get_display_hint (PyObject *printer)
 /* Helper for apply_val_pretty_printer which calls to_string and
    formats the result.  */
 static void
-print_string_repr (PyObject *printer, struct ui_file *stream, int recurse,
+print_string_repr (PyObject *printer, const char *hint,
+		   struct ui_file *stream, int recurse,
 		   const struct value_print_options *options,
 		   const struct language_defn *language)
 {
@@ -1001,7 +1002,11 @@ print_string_repr (PyObject *printer, struct ui_file *stream, int recurse,
   output = pretty_print_one_value (printer, &replacement);
   if (output)
     {
-      fputs_filtered (output, stream);
+      if (hint && !strcmp (hint, "string"))
+	LA_PRINT_STRING (stream, (gdb_byte *) output, strlen (output),
+			 1, 0, options);
+      else
+	fputs_filtered (output, stream);
       xfree (output);
     }
   else if (replacement)
@@ -1013,12 +1018,12 @@ print_string_repr (PyObject *printer, struct ui_file *stream, int recurse,
 /* Helper for apply_val_pretty_printer that formats children of the
    printer, if any exist.  */
 static void
-print_children (PyObject *printer, struct ui_file *stream, int recurse,
+print_children (PyObject *printer, const char *hint,
+		struct ui_file *stream, int recurse,
 		const struct value_print_options *options,
 		const struct language_defn *language)
 {
-  char *hint;
-  int is_map = 0, i;
+  int is_map, i;
   PyObject *children, *iter;
   struct cleanup *cleanups;
 
@@ -1026,12 +1031,7 @@ print_children (PyObject *printer, struct ui_file *stream, int recurse,
     return;
 
   /* If we are printing a map, we want some special formatting.  */
-  hint = gdbpy_get_display_hint (printer);
-  if (hint)
-    {
-      is_map = ! strcmp (hint, "map");
-      xfree (hint);
-    }
+  is_map = hint && ! strcmp (hint, "map");
 
   children = PyObject_CallMethodObjArgs (printer, gdbpy_children_cst,
 					 NULL);
@@ -1135,7 +1135,7 @@ apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
 {
   PyObject *func, *printer;
   struct value *value;
-  char *hint;
+  char *hint = NULL;
   struct cleanup *cleanups;
   int result = 0;
   PyGILState_STATE state;
@@ -1160,11 +1160,15 @@ apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
       goto done;
     }
 
+  /* If we are printing a map, we want some special formatting.  */
+  hint = gdbpy_get_display_hint (printer);
+  make_cleanup (free_current_contents, &hint);
+
   make_cleanup_py_decref (printer);
   if (printer != Py_None)
     {
-      print_string_repr (printer, stream, recurse, options, language);
-      print_children (printer, stream, recurse, options, language);
+      print_string_repr (printer, hint, stream, recurse, options, language);
+      print_children (printer, hint, stream, recurse, options, language);
 
       result = 1;
     }


hooks/post-receive
--
Repository for Project Archer.


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

* [SCM]  archer-tromey-python: gdb
@ 2008-12-10 15:28 tromey
  0 siblings, 0 replies; 26+ messages in thread
From: tromey @ 2008-12-10 15:28 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-python has been updated
       via  ab8c44cb00aed42589972ef0e0cea4cb9d644fba (commit)
      from  170f3087305a4fbf35d06d344639534c06672965 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit ab8c44cb00aed42589972ef0e0cea4cb9d644fba
Author: Tom Tromey <tromey@redhat.com>
Date:   Wed Dec 10 08:27:54 2008 -0700

    gdb
    	* python/python.c: Include event-loop.h.
    	(struct gdbpy_event): New type.
    	(gdbpy_event_list, gdbpy_event_list_end): New globals.
    	(gdbpy_event_fd): Likewise.
    	(gdbpy_run_events): New function.
    	(gdbpy_post_event): Likewise.
    	(gdbpy_initialize_events): Likewise.
    	(_initialize_python): Call it.
    	(GdbMethods) <post_event>: New method.
    gdb/doc
    	* gdb.texinfo (Basic Python): Document post_event.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog       |   12 +++++
 gdb/doc/ChangeLog   |    4 ++
 gdb/doc/gdb.texinfo |   15 +++++++
 gdb/python/python.c |  113 +++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 144 insertions(+), 0 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 86cc9ed..ef0bf91 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,15 @@
+2008-12-10  Tom Tromey  <tromey@redhat.com>
+
+	* python/python.c: Include event-loop.h.
+	(struct gdbpy_event): New type.
+	(gdbpy_event_list, gdbpy_event_list_end): New globals.
+	(gdbpy_event_fd): Likewise.
+	(gdbpy_run_events): New function.
+	(gdbpy_post_event): Likewise.
+	(gdbpy_initialize_events): Likewise.
+	(_initialize_python): Call it.
+	(GdbMethods) <post_event>: New method.
+
 2008-12-09  Thiago Jung Bauermann  <bauerman@br.ibm.com>
 
 	* python/python.c (gdbpy_get_threads): Rename to ...
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index b57f111..d35643c 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,7 @@
+2008-12-10  Tom Tromey  <tromey@redhat.com>
+
+	* gdb.texinfo (Basic Python): Document post_event.
+
 2008-12-05  Thiago Jung Bauermann  <bauerman@br.ibm.com>
 
 	* gdb.texinfo: Fix references to renamed gdb module functions.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 8057812..ea6698c 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -18119,6 +18119,21 @@ evaluate it, and return the result as a @code{gdb.Value}.
 @var{expression} must be a string.
 @end defun
 
+@findex gdb.post_event
+@defun post_event event
+Put @var{event}, a callable object taking no arguments, into
+@value{GDBN}'s internal event queue.  This callable will be invoked at
+some later point, during @value{GDBN}'s event processing.  Events
+posted using @code{post_event} will be run in the order in which they
+were posted; however, there is no way to know when they will be
+processed relative to other events inside @value{GDBN}.
+
+@value{GDBN} is not thread-safe.  If your Python program uses multiple
+threads, you must be careful to only call @value{GDBN}-specific
+functions in the main @value{GDBN} thread.  @code{post_event} ensures
+this.
+@end defun
+
 @findex gdb.write
 @defun write string
 Print a string to @value{GDBN}'s paginated standard output stream.
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 3bf3d54..1432e5e 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -27,6 +27,7 @@
 #include "gdb_regex.h"
 #include "language.h"
 #include "valprint.h"
+#include "event-loop.h"
 
 #include <ctype.h>
 
@@ -416,6 +417,113 @@ gdbpy_parse_and_eval (PyObject *self, PyObject *args)
 
 \f
 
+/* Posting and handling events.  */
+
+/* A single event.  */
+struct gdbpy_event
+{
+  /* The Python event.  This is just a callable object.  */
+  PyObject *event;
+  /* The next event.  */
+  struct gdbpy_event *next;
+};
+
+/* All pending events.  */
+static struct gdbpy_event *gdbpy_event_list;
+/* The final link of the event list.  */
+static struct gdbpy_event **gdbpy_event_list_end;
+
+/* We use a file handler, and not an async handler, so that we can
+   wake up the main thread even when it is blocked in poll().  */
+static int gdbpy_event_fds[2];
+
+/* The file handler callback.  This reads from the internal pipe, and
+   then processes the Python event queue.  This will always be run in
+   the main gdb thread.  */
+static void
+gdbpy_run_events (int err, gdb_client_data ignore)
+{
+  PyGILState_STATE state;
+  char buffer[100];
+  int r;
+
+  state = PyGILState_Ensure ();
+
+  /* Just read whatever is available on the fd.  It is relatively
+     harmless if there are any bytes left over.  */
+  r = read (gdbpy_event_fds[0], buffer, sizeof (buffer));
+
+  while (gdbpy_event_list)
+    {
+      /* 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;
+      gdbpy_event_list = gdbpy_event_list->next;
+      if (gdbpy_event_list == NULL)
+	gdbpy_event_list_end = &gdbpy_event_list;
+
+      /* Ignore errors.  */
+      PyObject_CallObject (item->event, NULL);
+
+      Py_DECREF (item->event);
+      xfree (item);
+    }
+
+  PyGILState_Release (state);
+}
+
+/* Submit an event to the gdb thread.  */
+static PyObject *
+gdbpy_post_event (PyObject *self, PyObject *args)
+{
+  struct gdbpy_event *event;
+  PyObject *func;
+  int wakeup;
+
+  if (!PyArg_ParseTuple (args, "O", &func))
+    return NULL;
+
+  if (!PyCallable_Check (func))
+    {
+      PyErr_SetString (PyExc_RuntimeError, "Posted event is not callable");
+      return NULL;
+    }
+
+  Py_INCREF (func);
+
+  /* From here until the end of the function, we have the GIL, so we
+     can operate on our global data structures without worrying.  */
+  wakeup = gdbpy_event_list == NULL;
+
+  event = XNEW (struct gdbpy_event);
+  event->event = func;
+  event->next = NULL;
+  *gdbpy_event_list_end = event;
+  gdbpy_event_list_end = &event->next;
+
+  /* Wake up gdb when needed.  */
+  if (wakeup)
+    {
+      char c = 'q';		/* Anything. */
+      write (gdbpy_event_fds[1], &c, 1);
+    }
+
+  Py_RETURN_NONE;
+}
+
+/* Initialize the Python event handler.  */
+static void
+gdbpy_initialize_events (void)
+{
+  if (!pipe (gdbpy_event_fds))
+    {
+      gdbpy_event_list_end = &gdbpy_event_list;
+      add_file_handler (gdbpy_event_fds[0], gdbpy_run_events, NULL);
+    }
+}
+
+\f
+
 /* Threads.  */
 
 /* Callback function for use with iterate_over_threads.  This function
@@ -1285,6 +1393,8 @@ Enables or disables auto-loading of Python code when an object is opened."),
   gdbpy_initialize_parameters ();
   gdbpy_initialize_objfile ();
 
+  gdbpy_initialize_events ();
+
   PyRun_SimpleString ("import gdb");
   PyRun_SimpleString ("gdb.pretty_printers = {}");
 
@@ -1397,6 +1507,9 @@ Note: may later change to return an object." },
   { "parse_and_eval", gdbpy_parse_and_eval, METH_VARARGS,
     "Parse a string as an expression, evaluate it, and return the result." },
 
+  { "post_event", gdbpy_post_event, METH_VARARGS,
+    "Post an event into gdb's event loop." },
+
   { "write", gdbpy_write, METH_VARARGS,
     "Write a string using gdb's filtered stream." },
   { "flush", gdbpy_flush, METH_NOARGS,


hooks/post-receive
--
Repository for Project Archer.


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

* [SCM]  archer-tromey-python: gdb
@ 2008-12-09  0:33 tromey
  0 siblings, 0 replies; 26+ messages in thread
From: tromey @ 2008-12-09  0:33 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-python has been updated
       via  cc40738cd87a1a27c9843fc1e53c7b69ff98b72b (commit)
      from  66e2f97a188e1dd6d34e0c912323cad35f47f593 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit cc40738cd87a1a27c9843fc1e53c7b69ff98b72b
Author: Tom Tromey <tromey@redhat.com>
Date:   Mon Dec 8 17:32:38 2008 -0700

    gdb
    	* value.c (value_free): Handle value==0.
    
    	* gdbtypes.c (create_array_type): Use range_type as parent.
    
    	* cli/cli-cmds.c (init_cli_cmds): Disambiguate help text.
    gdb/doc
    	* gdb.base/help.exp: Update.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog                   |    8 ++++++++
 gdb/cli/cli-cmds.c              |    6 +++---
 gdb/gdbtypes.c                  |    2 +-
 gdb/testsuite/ChangeLog         |    4 ++++
 gdb/testsuite/gdb.base/help.exp |    2 +-
 gdb/value.c                     |    9 ++++++---
 6 files changed, 23 insertions(+), 8 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 097c121..7aa60c9 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,11 @@
+2008-12-08  Tom Tromey  <tromey@redhat.com>
+
+	* value.c (value_free): Handle value==0.
+
+	* gdbtypes.c (create_array_type): Use range_type as parent.
+
+	* cli/cli-cmds.c (init_cli_cmds): Disambiguate help text.
+
 2008-12-05  Tom Tromey  <tromey@redhat.com>
 
 	* python/python-symbol.c (symbol_object_methods) <get_symtab>: Fix
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index e1dc88a..806a68a 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -1310,10 +1310,10 @@ Commands defined in this way may have up to ten arguments."));
 Read commands from a file named FILE.\n\
 Optional -v switch (before the filename) causes each command in\n\
 FILE to be echoed as it is executed.\n\
-Optional -p switch (before the filename) causes FILE to be evaluated\n\
-as Python code.\n\
 Note that the file \"%s\" is read automatically in this way\n\
-when GDB is started."), gdbinit);
+when GDB is started.\n\
+Optional -p switch (before the filename) causes FILE to be evaluated\n\
+as Python code."), gdbinit);
   c = add_cmd ("source", class_support, source_command,
 	       source_help_text, &cmdlist);
   set_cmd_completer (c, filename_completer);
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 96a15f5..1d9bc2d 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -844,7 +844,7 @@ create_array_type (struct type *result_type,
 
   if (result_type == NULL)
     {
-      result_type = alloc_type (TYPE_OBJFILE (range_type), element_type);
+      result_type = alloc_type (TYPE_OBJFILE (range_type), range_type);
     }
   else
     {
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index b23947a..e491bc6 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2008-12-08  Tom Tromey  <tromey@redhat.com>
+
+	* gdb.base/help.exp: Update.
+
 2008-12-03  Thiago Jung Bauermann  <bauerman@br.ibm.com>
 
 	* gdb.python/python-template.exp: Use `gdb.history' instead of
diff --git a/gdb/testsuite/gdb.base/help.exp b/gdb/testsuite/gdb.base/help.exp
index 65cb546..ca59ac9 100644
--- a/gdb/testsuite/gdb.base/help.exp
+++ b/gdb/testsuite/gdb.base/help.exp
@@ -602,7 +602,7 @@ gdb_test "help stepi" "Step one instruction exactly\.\[\r\n\]+Argument N means d
 gdb_test "help signal" "Continue program giving it signal.*" "help signal"
 # test help source
 # vxgdb reads .vxgdbinit
-gdb_test "help source" "Read commands from a file named FILE\.\[\r\n\]+Optional -v switch \\(before the filename\\) causes each command in\[\r\n\]+FILE to be echoed as it is executed\.\[\r\n\]+Note that the file \"\[^\"\]*\" is read automatically in this way\[\r\n\]+when GDB is started\." "help source"
+gdb_test "help source" "Read commands from a file named FILE\.\[\r\n\]+Optional -v switch \\(before the filename\\) causes each command in\[\r\n\]+FILE to be echoed as it is executed\.\[\r\n\]+Note that the file \"\[^\"\]*\" is read automatically in this way\[\r\n\]+when GDB is started\.\[\r\n\]+Optional -p switch \\(before the filename\\) causes FILE to be evaluated\[\r\n\]+as Python code\." "help source"
 # test help stack
 test_class_help "stack" {
     "Examining the stack\..*\[\r\n\]+"
diff --git a/gdb/value.c b/gdb/value.c
index d5b047f..9642878 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -275,9 +275,12 @@ allocate_value (struct type *type)
 void
 value_free (struct value *value)
 {
-  type_decref (value->type);
-  type_decref (value->enclosing_type);
-  xfree (value);
+  if (value)
+    {
+      type_decref (value->type);
+      type_decref (value->enclosing_type);
+      xfree (value);
+    }
 }
 
 /* Allocate a  value  that has the correct length


hooks/post-receive
--
Repository for Project Archer.


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

* [SCM]  archer-tromey-python: gdb
@ 2008-12-02 21:29 tromey
  0 siblings, 0 replies; 26+ messages in thread
From: tromey @ 2008-12-02 21:29 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-python has been updated
       via  34a2d37155617498485e65ba9d1964785274e7f1 (commit)
      from  949f9573fce69b4516501c9b9c67cc189ce82b09 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 34a2d37155617498485e65ba9d1964785274e7f1
Author: Tom Tromey <tromey@redhat.com>
Date:   Tue Dec 2 14:28:58 2008 -0700

    gdb
    	* python/python-value.c (valpy_string): Add "errors" argument.
    gdb/doc
    	* gdb.texinfo (Values From Inferior): Document new string
    	argument.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog             |    4 ++++
 gdb/doc/ChangeLog         |    5 +++++
 gdb/doc/gdb.texinfo       |   11 ++++++++---
 gdb/python/python-value.c |    7 ++++---
 4 files changed, 21 insertions(+), 6 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index daa5586..f8287c0 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,9 @@
 2008-12-02  Tom Tromey  <tromey@redhat.com>
 
+	* python/python-value.c (valpy_string): Add "errors" argument.
+
+2008-12-02  Tom Tromey  <tromey@redhat.com>
+
 	* python/lib/gdb/command/backtrace.py (FrameWrapper.__getattr__):
 	Rename from __getattribute__.
 	* python/lib/gdb/backtrace.py (push_frame_filter): Add missing
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 703543b..a786ea1 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,8 @@
+2008-12-02  Tom Tromey  <tromey@redhat.com>
+
+	* gdb.texinfo (Values From Inferior): Document new string
+	argument.
+
 2008-12-01  Tom Tromey  <tromey@redhat.com>
 
 	* gdb.texinfo (Basic Python): Document parse_and_eval.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index dfc19aa..1e7a22d 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -18247,7 +18247,7 @@ The result @code{bar} will be a @code{gdb.Value} object holding the
 value pointed to by @code{foo}.
 @end defmethod
 
-@defmethod Value string @r{[}encoding@r{]}
+@defmethod Value string @r{[}encoding @r{[}errors@r{]}@r{]}
 If this @code{gdb.Value} represents a string, then this method
 converts the contents to a Python string.  Otherwise, this method will
 throw an exception.
@@ -18263,8 +18263,13 @@ by a zero of the appropriate width.
 If the optional @var{encoding} argument is given, it must be a string
 naming the encoding of the string in the @code{gdb.Value}.  The Python
 codec machinery will be used to convert the string.  If @var{encoding}
-is not given, then the @code{target-charset} (@pxref{Character Sets})
-will be used.
+is not given, or if @var{encoding} is the empty string, then either
+the @code{target-charset} (@pxref{Character Sets}) will be used, or a
+language-specific encoding will be used, if the current language is
+able to supply one.
+
+The optional @var{errors} argument is the same as the corresponding
+argument to Python's @code{string.decode} method.
 @end defmethod
 
 @defmethod Value type
diff --git a/gdb/python/python-value.c b/gdb/python/python-value.c
index 5a7fae0..342cf28 100644
--- a/gdb/python/python-value.c
+++ b/gdb/python/python-value.c
@@ -165,10 +165,11 @@ valpy_string (PyObject *self, PyObject *args)
   volatile struct gdb_exception except;
   PyObject *unicode;
   const char *encoding = NULL;
+  const char *errors = NULL;
   const char *user_encoding = NULL;
   const char *la_encoding = NULL;
 
-  if (!PyArg_ParseTuple (args, "|s", &user_encoding))
+  if (!PyArg_ParseTuple (args, "|ss", &user_encoding, &errors))
     return NULL;
 
   TRY_CATCH (except, RETURN_MASK_ALL)
@@ -187,8 +188,8 @@ valpy_string (PyObject *self, PyObject *args)
       return NULL;
     }
 
-  encoding = user_encoding? user_encoding : la_encoding;
-  unicode = PyUnicode_Decode (buffer, length, encoding, NULL);
+  encoding = (user_encoding && *user_encoding) ? user_encoding : la_encoding;
+  unicode = PyUnicode_Decode (buffer, length, encoding, errors);
   xfree (buffer);
 
   return unicode;


hooks/post-receive
--
Repository for Project Archer.


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

* [SCM]  archer-tromey-python: gdb
@ 2008-12-01 19:10 tromey
  0 siblings, 0 replies; 26+ messages in thread
From: tromey @ 2008-12-01 19:10 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-python has been updated
       via  a3c509dff50be9deb8f84f30123cd0458120874a (commit)
      from  57ef2e848acae84dcb8497a7a126210bc4de74ff (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit a3c509dff50be9deb8f84f30123cd0458120874a
Author: Tom Tromey <tromey@redhat.com>
Date:   Mon Dec 1 12:09:55 2008 -0700

    gdb
    	* python/python.c (GdbMethods) <parse_and_eval>: New.
    	(gdbpy_parse_and_eval): New function.
    gdb/doc
    	* gdb.texinfo (Basic Python): Document parse_and_eval.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog       |    5 +++++
 gdb/doc/ChangeLog   |    4 ++++
 gdb/doc/gdb.texinfo |    7 +++++++
 gdb/python/python.c |   23 +++++++++++++++++++++++
 4 files changed, 39 insertions(+), 0 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 97a4223..9d51f22 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
 2008-12-01  Tom Tromey  <tromey@redhat.com>
 
+	* python/python.c (GdbMethods) <parse_and_eval>: New.
+	(gdbpy_parse_and_eval): New function.
+
+2008-12-01  Tom Tromey  <tromey@redhat.com>
+
 	* python/python-value.c (is_intlike): New function.
 	(valpy_int): Use it.
 	(valpy_long): Likewise.
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 90a769b..703543b 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,5 +1,9 @@
 2008-12-01  Tom Tromey  <tromey@redhat.com>
 
+	* gdb.texinfo (Basic Python): Document parse_and_eval.
+
+2008-12-01  Tom Tromey  <tromey@redhat.com>
+
 	* gdb.texinfo (Convenience Vars): Document convenience functions.
 	(Functions In Python): New node.
 	(Python API): Update.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 38d3f1e..dfc19aa 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -18099,6 +18099,13 @@ If the named parameter does not exist, this function throws a
 a Python value of the appropriate type, and returned.
 @end defun
 
+@findex gdb.parse_and_eval
+@defun parse_and_eval expression
+Parse @var{expression} as an expression in the current language,
+evaluate it, and return the result as a @code{gdb.Value}.
+@var{expression} must be a string.
+@end defun
+
 @findex gdb.write
 @defun write string
 Print a string to @value{GDBN}'s paginated standard output stream.
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 7b46f0d..bb0b428 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -394,6 +394,26 @@ gdbpy_decode_line (PyObject *self, PyObject *args)
   Py_RETURN_NONE;
 }
 
+/* Parse a string and evaluate it as an expression.  */
+static PyObject *
+gdbpy_parse_and_eval (PyObject *self, PyObject *args)
+{
+  char *expr_str;
+  struct value *result = NULL;
+  volatile struct gdb_exception except;
+
+  if (!PyArg_ParseTuple (args, "s", &expr_str))
+    return NULL;
+
+  TRY_CATCH (except, RETURN_MASK_ALL)
+    {
+      result = parse_and_eval (expr_str);
+    }
+  GDB_PY_HANDLE_EXCEPTION (except);
+
+  return value_to_value_object (result);
+}
+
 \f
 
 /* Threads.  */
@@ -1374,6 +1394,9 @@ Note: may later change to return an object." },
   { "switch_to_thread", gdbpy_switch_to_thread, METH_VARARGS,
     "Switch to a thread, given the thread ID." },
 
+  { "parse_and_eval", gdbpy_parse_and_eval, METH_VARARGS,
+    "Parse a string as an expression, evaluate it, and return the result." },
+
   { "write", gdbpy_write, METH_VARARGS,
     "Write a string using gdb's filtered stream." },
   { "flush", gdbpy_flush, METH_NOARGS,


hooks/post-receive
--
Repository for Project Archer.


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

* [SCM]  archer-tromey-python: gdb
@ 2008-11-25 21:17 tromey
  0 siblings, 0 replies; 26+ messages in thread
From: tromey @ 2008-11-25 21:17 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-python has been updated
       via  3337ab228957a71fa00ca0ba9824b1acc57298a6 (commit)
      from  0823707d573b2ad740132a2b8d5c7c241c814ff1 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 3337ab228957a71fa00ca0ba9824b1acc57298a6
Author: Tom Tromey <tromey@redhat.com>
Date:   Tue Nov 25 14:16:41 2008 -0700

    gdb
    	* python/python-value.c (valpy_type): Update.
    	* python/python-internal.h (type_to_type_object): Update.
    	* python/python-type.c (pyty_type_object) <owned, originator>:
    	Remove.
    	(clean_up_objfile_types): Update.
    	(typy_dealloc): Update.
    	(set_type): Update.  Remove "parent" argument.
    	(type_to_type_object): Likewise.
    	(convert_field): Update.  Remove "self" argument.
    	(typy_fields): Update.
    	(typy_pointer): Update.
    	(typy_reference): Update.
    	(typy_target): Update.
    	(typy_template_argument): Update.
    	(typy_new): Update.
    gdb/testsuite
    	* gdb.python/python-value.c (PTR): New typedef.
    	* gdb.python/python-value.exp (test_value_after_death): New proc.
    	Call it.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog                             |   18 ++++++
 gdb/python/python-internal.h              |    2 +-
 gdb/python/python-type.c                  |   93 ++++++++---------------------
 gdb/python/python-value.c                 |    2 +-
 gdb/testsuite/ChangeLog                   |    6 ++
 gdb/testsuite/gdb.python/python-value.c   |    3 +
 gdb/testsuite/gdb.python/python-value.exp |   28 +++++++++
 7 files changed, 81 insertions(+), 71 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 979ca40..7a2d930 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,21 @@
+2008-11-25  Tom Tromey  <tromey@redhat.com>
+
+	* python/python-value.c (valpy_type): Update.
+	* python/python-internal.h (type_to_type_object): Update.
+	* python/python-type.c (pyty_type_object) <owned, originator>:
+	Remove.
+	(clean_up_objfile_types): Update.
+	(typy_dealloc): Update.
+	(set_type): Update.  Remove "parent" argument.
+	(type_to_type_object): Likewise.
+	(convert_field): Update.  Remove "self" argument.
+	(typy_fields): Update.
+	(typy_pointer): Update.
+	(typy_reference): Update.
+	(typy_target): Update.
+	(typy_template_argument): Update.
+	(typy_new): Update.
+
 2008-11-24  Thiago Jung Bauermann  <bauerman@br.ibm.com>
 
 	More changes from review.
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 4603b18..83fc1e2 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -84,7 +84,7 @@ PyObject *symbol_to_symbol_object (struct symbol *sym);
 PyObject *block_to_block_object (struct block *block);
 PyObject *value_to_value_object (struct value *v);
 PyObject *gdb_owned_value_to_value_object (struct value *v);
-PyObject *type_to_type_object (PyObject *, struct type *);
+PyObject *type_to_type_object (struct type *);
 PyObject *objfile_to_objfile_object (struct objfile *);
 
 PyObject *objfpy_get_printers (PyObject *, void *);
diff --git a/gdb/python/python-type.c b/gdb/python/python-type.c
index cf24a75..0df5252 100644
--- a/gdb/python/python-type.c
+++ b/gdb/python/python-type.c
@@ -37,15 +37,6 @@ typedef struct pyty_type_object
      underlying struct type when the objfile is deleted.  */
   struct pyty_type_object *prev;
   struct pyty_type_object *next;
-
-  /* This is nonzero if the type is owned by this object and should be
-     freed when the object is deleted.  */
-  int owned;
-
-  /* A Type derived from an 'owned' type will refer to its originator.
-     This prevents us from freeing the underlying 'type' too
-     early.  In other cases, this is NULL.  */
-  PyObject *originator;
 } type_object;
 
 static PyTypeObject type_object_type;
@@ -143,7 +134,7 @@ typy_code (PyObject *self, PyObject *args)
 /* Helper function for typy_fields which converts a single field to a
    dictionary.  Returns NULL on error.  */
 static PyObject *
-convert_field (PyObject *self, struct type *type, int field)
+convert_field (struct type *type, int field)
 {
   PyObject *result = field_new ();
   PyObject *arg;
@@ -184,7 +175,7 @@ convert_field (PyObject *self, struct type *type, int field)
   if (PyObject_SetAttrString (result, "bitsize", arg) < 0)
     goto failarg;
 
-  arg = type_to_type_object (self, TYPE_FIELD_TYPE (type, field));
+  arg = type_to_type_object (TYPE_FIELD_TYPE (type, field));
   if (!arg)
     goto fail;
   if (PyObject_SetAttrString (result, "type", arg) < 0)
@@ -215,7 +206,7 @@ typy_fields (PyObject *self, PyObject *args)
 
   for (i = 0; i < TYPE_NFIELDS (type); ++i)
     {
-      PyObject *dict = convert_field (self, type, i);
+      PyObject *dict = convert_field (type, i);
       if (!dict)
 	{
 	  Py_DECREF (result);
@@ -255,7 +246,7 @@ typy_pointer (PyObject *self, PyObject *args)
     }
   GDB_PY_HANDLE_EXCEPTION (except);
 
-  return type_to_type_object (self, type);
+  return type_to_type_object (type);
 }
 
 /* Return a Type object which represents a reference to SELF.  */
@@ -271,7 +262,7 @@ typy_reference (PyObject *self, PyObject *args)
     }
   GDB_PY_HANDLE_EXCEPTION (except);
 
-  return type_to_type_object (self, type);
+  return type_to_type_object (type);
 }
 
 /* Return a Type object which represents the target type of SELF.  */
@@ -286,7 +277,7 @@ typy_target (PyObject *self, PyObject *args)
       return NULL;
     }
 
-  return type_to_type_object (self, TYPE_TARGET_TYPE (type));
+  return type_to_type_object (TYPE_TARGET_TYPE (type));
 }
 
 /* Return the size of the type represented by SELF, in bytes.  */
@@ -444,7 +435,7 @@ typy_template_argument (PyObject *self, PyObject *args)
   if (! argtype)
     return NULL;
 
-  return type_to_type_object (self, argtype);
+  return type_to_type_object (argtype);
 }
 
 static PyObject *
@@ -504,11 +495,13 @@ clean_up_objfile_types (struct objfile *objfile, void *datum)
       type_object *next = obj->next;
 
       htab_empty (copied_types);
+      /* Note that we leak this memory.  There is no good way to
+	 handle freeing this, given things like Value.cast and other
+	 unconstrained operations on values.  */
       obj->type = copy_type_recursive (objfile, obj->type, copied_types);
 
       obj->next = NULL;
       obj->prev = NULL;
-      obj->owned = 1;
 
       obj = next;
     }
@@ -519,10 +512,9 @@ clean_up_objfile_types (struct objfile *objfile, void *datum)
 }
 
 static void
-set_type (type_object *obj, struct type *type, type_object *parent)
+set_type (type_object *obj, struct type *type)
 {
   obj->type = type;
-  obj->owned = 0;
   obj->prev = NULL;
   if (type && TYPE_OBJFILE (type))
     {
@@ -535,21 +527,6 @@ set_type (type_object *obj, struct type *type, type_object *parent)
     }
   else
     obj->next = NULL;
-
-  obj->originator = NULL;
-  if (type && parent)
-    {
-      if (parent->owned)
-	{
-	  Py_INCREF (parent);
-	  obj->originator = (PyObject *) parent;
-	}
-      else if (parent->originator)
-	{
-	  Py_INCREF (parent->originator);
-	  obj->originator = parent->originator;
-	}
-    }
 }
 
 static PyObject *
@@ -588,7 +565,7 @@ typy_new (PyTypeObject *subtype, PyObject *args, PyObject *kwargs)
   if (! result)
     return NULL;
 
-  set_type (result, type, NULL);
+  set_type (result, type);
 
   return (PyObject *) result;
 }
@@ -598,52 +575,30 @@ typy_dealloc (PyObject *obj)
 {
   type_object *type = (type_object *) obj;
 
-  if (type->type)
+  if (type->prev)
+    type->prev->next = type->next;
+  else if (type->type && TYPE_OBJFILE (type->type))
     {
-      if (type->owned)
-	{
-	  /* We own the type, so delete it.  */
-	  htab_t deleted_types;
-
-	  deleted_types = create_deleted_types_hash ();
-	  delete_type_recursive (type->type, deleted_types);
-	  htab_delete (deleted_types);
-	}
-      else if (type->originator)
-	{
-	  Py_DECREF (type->originator);
-	}
-      else
-	{
-	  if (type->prev)
-	    type->prev->next = type->next;
-	  else
-	    {
-	      /* Must reset head of list.  */
-	      struct objfile *objfile = TYPE_OBJFILE (type->type);
-	      if (objfile)
-		set_objfile_data (objfile, typy_objfile_data_key, type->next);
-	    }
-	  if (type->next)
-	    type->next->prev = type->prev;
-	}
+      /* Must reset head of list.  */
+      struct objfile *objfile = TYPE_OBJFILE (type->type);
+      if (objfile)
+	set_objfile_data (objfile, typy_objfile_data_key, type->next);
     }
+  if (type->next)
+    type->next->prev = type->prev;
 
   type->ob_type->tp_free (type);
 }
 
-/* Create a new Type referring to TYPE.  PARENT is the Type from which
-   TYPE is derived; this is needed to handle reference counting for
-   derived 'owned' types.  PARENT can be NULL if you know that this is
-   not a problem; otherwise it must be a Type object.  */
+/* Create a new Type referring to TYPE.  */
 PyObject *
-type_to_type_object (PyObject *parent, struct type *type)
+type_to_type_object (struct type *type)
 {
   type_object *type_obj;
 
   type_obj = PyObject_New (type_object, &type_object_type);
   if (type_obj)
-    set_type (type_obj, type, (type_object *) parent);
+    set_type (type_obj, type);
 
   return (PyObject *) type_obj;
 }
diff --git a/gdb/python/python-value.c b/gdb/python/python-value.c
index 807f914..2a6af14 100644
--- a/gdb/python/python-value.c
+++ b/gdb/python/python-value.c
@@ -151,7 +151,7 @@ static PyObject *
 valpy_type (PyObject *self, PyObject *args)
 {
   struct value *value = ((value_object *) self)->value;
-  return type_to_type_object (NULL, value_type (value));
+  return type_to_type_object (value_type (value));
 }
 
 /* Return Unicode string with value contents (assumed to be encoded in the
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 4805635..688d656 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2008-11-25  Tom Tromey  <tromey@redhat.com>
+
+	* gdb.python/python-value.c (PTR): New typedef.
+	* gdb.python/python-value.exp (test_value_after_death): New proc.
+	Call it.
+
 2008-11-17  Tom Tromey  <tromey@redhat.com>
 
 	* gdb.python/python-prettyprint.c (do_nothing): New function.
diff --git a/gdb/testsuite/gdb.python/python-value.c b/gdb/testsuite/gdb.python/python-value.c
index 0180ed5..95d9e03 100644
--- a/gdb/testsuite/gdb.python/python-value.c
+++ b/gdb/testsuite/gdb.python/python-value.c
@@ -27,12 +27,15 @@ union u
   float b;
 };
 
+typedef struct s *PTR;
+
 int
 main (int argc, char *argv[])
 {
   char *cp = argv[0]; /* Prevent gcc from optimizing argv[] out.  */
   struct s s;
   union u u;
+  PTR x = &s;
 
   s.a = 3;
   s.b = 5;
diff --git a/gdb/testsuite/gdb.python/python-value.exp b/gdb/testsuite/gdb.python/python-value.exp
index 99b576a..a34af9b 100644
--- a/gdb/testsuite/gdb.python/python-value.exp
+++ b/gdb/testsuite/gdb.python/python-value.exp
@@ -222,6 +222,33 @@ proc test_value_in_inferior {} {
   gdb_test "python print arg0" "0x.*$testfile\"" "verify dereferenced value"
 }
 
+proc test_value_after_death {} {
+  # Construct a type while the inferior is still running.
+  gdb_py_test_silent_cmd "python ptrtype = gdb.Type('PTR')" \
+    "create PTR type" 1
+
+  # Kill the inferior and remove the symbols.
+  gdb_test "kill" "" "kill the inferior" \
+    "Kill the program being debugged. .y or n. $" \
+    "y"
+  gdb_test "file" "" "Discard the symbols" \
+    "Discard symbol table from.*y or n. $" \
+    "y"
+
+  # Now create a value using that type.  Relies on arg0, created by
+  # test_value_in_inferior.
+  gdb_py_test_silent_cmd "python castval = arg0.cast(ptrtype.pointer())" \
+    "cast arg0 to PTR" 1
+
+  # Make sure the type is deleted.
+  gdb_py_test_silent_cmd "python ptrtype = None" \
+    "delete PTR type" 1
+
+  # Now see if the value's type is still valid.
+  gdb_test "python print castval.type()" "struct s .." \
+    "print value's type"
+}
+
 
 # Start with a fresh gdb.
 
@@ -251,3 +278,4 @@ if ![runto_main] then {
 }
 
 test_value_in_inferior
+test_value_after_death


hooks/post-receive
--
Repository for Project Archer.


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

* [SCM]  archer-tromey-python: gdb
@ 2008-11-21 18:25 tromey
  0 siblings, 0 replies; 26+ messages in thread
From: tromey @ 2008-11-21 18:25 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-python has been updated
       via  0fdf3e3468cebce67721a34c04adf813d7dc48eb (commit)
      from  d622890c0091978356760aafbb8bc7adfec3724e (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 0fdf3e3468cebce67721a34c04adf813d7dc48eb
Author: Tom Tromey <tromey@redhat.com>
Date:   Fri Nov 21 11:24:44 2008 -0700

    gdb
    	* python/python-value.c (value_object_methods) <string>: Accept
    	varargs.
    	(valpy_string): Accept optional encoding argument.
    gdb/doc
    	* gdb.texinfo (Values From Inferior): Document Value.string.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog             |    6 ++++++
 gdb/doc/ChangeLog         |    4 ++++
 gdb/doc/gdb.texinfo       |   20 ++++++++++++++++++++
 gdb/python/python-value.c |   11 +++++++++--
 4 files changed, 39 insertions(+), 2 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index ca4807f..549ca85 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2008-11-21  Tom Tromey  <tromey@redhat.com>
+
+	* python/python-value.c (value_object_methods) <string>: Accept
+	varargs.
+	(valpy_string): Accept optional encoding argument.
+
 2008-11-20  Tom Tromey  <tromey@redhat.com>
 
 	* gdbtypes.c (delete_main_type): Use TYPE_FIELD_LOC_KIND.
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index e6b9a7b..4a557f9 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,7 @@
+2008-11-21  Tom Tromey  <tromey@redhat.com>
+
+	* gdb.texinfo (Values From Inferior): Document Value.string.
+
 2008-11-18  Tom Tromey  <tromey@redhat.com>
 
 	* gdb.texinfo (Commands In Python): Document prefix commands.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index fad65e2..18fe77f 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -18225,6 +18225,26 @@ The result @code{bar} will be a @code{gdb.Value} object holding the
 value pointed to by @code{foo}.
 @end defmethod
 
+@defmethod Value string @r{[}encoding@r{]}
+If this @code{gdb.Value} represents a string, then this method
+converts the contents to a Python string.  Otherwise, this method will
+throw an exception.
+
+Strings are recognized in a language-specific way; whether a given
+@code{gdb.Value} represents a string is determined by the current
+language.
+
+For C-like languages, a value is a string if it is a pointer to or an
+array of characters or ints.  The string is assumed to be terminated
+by a zero of the appropriate width.
+
+If the optional @var{encoding} argument is given, it must be a string
+naming the encoding of the string in the @code{gdb.Value}.  The Python
+codec machinery will be used to convert the string.  If @var{encoding}
+is not given, then the @code{target-charset} (@pxref{Character Sets})
+will be used.
+@end defmethod
+
 @defmethod Value type
 Return the type of this @code{gdb.Value}.  The result is a
 @code{gdb.Type} object.
diff --git a/gdb/python/python-value.c b/gdb/python/python-value.c
index 0712408..e8196ed 100644
--- a/gdb/python/python-value.c
+++ b/gdb/python/python-value.c
@@ -164,6 +164,13 @@ valpy_string (PyObject *self, PyObject *args)
   struct value *value = ((value_object *) self)->value;
   volatile struct gdb_exception except;
   PyObject *unicode;
+  const char *encoding = NULL;
+
+  if (!PyArg_ParseTuple (args, "|s", &encoding))
+    return NULL;
+
+  if (!encoding)
+    encoding = target_charset ();
 
   TRY_CATCH (except, RETURN_MASK_ALL)
     {
@@ -181,7 +188,7 @@ valpy_string (PyObject *self, PyObject *args)
       return NULL;
     }
 
-  unicode = target_string_to_unicode (buffer, length);
+  unicode = PyUnicode_Decode (buffer, length, encoding, NULL);
   xfree (buffer);
 
   return unicode;
@@ -905,7 +912,7 @@ static PyMethodDef value_object_methods[] = {
   { "cast", valpy_cast, METH_VARARGS, "Cast the value to the supplied type." },
   { "dereference", valpy_dereference, METH_NOARGS, "Dereferences the value." },
   { "type", valpy_type, METH_NOARGS, "Return type of the value." },
-  { "string", valpy_string, METH_NOARGS,
+  { "string", valpy_string, METH_VARARGS,
     "Return Unicode string representation of the value." },
   {NULL}  /* Sentinel */
 };


hooks/post-receive
--
Repository for Project Archer.


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

* [SCM]  archer-tromey-python: gdb
@ 2008-11-18 18:52 tromey
  0 siblings, 0 replies; 26+ messages in thread
From: tromey @ 2008-11-18 18:52 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-python has been updated
       via  4b2ca6c6e0e86a0a2ad45b873a3c1b75993a2f08 (commit)
      from  01af16dc305d029f7bc580ec848b60b7f2b2a880 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 4b2ca6c6e0e86a0a2ad45b873a3c1b75993a2f08
Author: Tom Tromey <tromey@redhat.com>
Date:   Tue Nov 18 11:51:36 2008 -0700

    gdb
    	* python/python-cmd.c (struct cmdpy_object) <sub_list>: New field.
    	(cmdpy_init): Allow prefix commands.
    	(cmdpy_destroyer): Free the prefix name.
    	(cmdpy_function): Handle prefix commands.
    gdb/doc
    	* gdb.texinfo (Commands In Python): Document prefix commands.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog           |    7 ++++
 gdb/doc/ChangeLog       |    4 ++
 gdb/doc/gdb.texinfo     |    9 ++++--
 gdb/python/python-cmd.c |   76 ++++++++++++++++++++++++++++++++++++++++-------
 4 files changed, 82 insertions(+), 14 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index c5fa878..7fb7b12 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,12 @@
 2008-11-18  Tom Tromey  <tromey@redhat.com>
 
+	* python/python-cmd.c (struct cmdpy_object) <sub_list>: New field.
+	(cmdpy_init): Allow prefix commands.
+	(cmdpy_destroyer): Free the prefix name.
+	(cmdpy_function): Handle prefix commands.
+
+2008-11-18  Tom Tromey  <tromey@redhat.com>
+
 	* python/python-internal.h (gdbpy_doc_cst): Declare.
 	* python/python-cmd.c (cmdpy_init): Use gdbpy_doc_cst.  Don't set
 	tp_new or tp_init.
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 385bbca..b0a8038 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,5 +1,9 @@
 2008-11-18  Tom Tromey  <tromey@redhat.com>
 
+	* gdb.texinfo (Commands In Python): Document prefix commands.
+
+2008-11-18  Tom Tromey  <tromey@redhat.com>
+
 	* gdb.texinfo (Parameters In Python): Document set_doc, show_doc.
 
 2008-11-16  Tom Tromey  <tromey@redhat.com>
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 9446ce4..1231ab3 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -18308,7 +18308,7 @@ You can implement new @value{GDBN} CLI commands in Python.  A CLI
 command is implemented using an instance of the @code{gdb.Command}
 class, most commonly using a subclass.
 
-@defmethod Command __init__ name @var{command-class} @r{[}@var{completer-class}@r{]}
+@defmethod Command __init__ name @var{command-class} @r{[}@var{completer-class} @var{prefix}@r{]}
 The object initializer for @code{Command} registers the new command
 with @value{GDBN}.  This initializer is normally invoked from the
 subclass' own @code{__init__} method.
@@ -18318,8 +18318,7 @@ multiple words, then the initial words are looked for as prefix
 commands.  In this case, if one of the prefix commands does not exist,
 an exception is raised.
 
-There is no support for multi-line commands.  Currently, there is also
-no way to define new prefix commands.
+There is no support for multi-line commands.
 
 @var{command-class} should be one of the @samp{COMMAND_} constants
 defined below.  This argument tells @value{GDBN} how to categorize the
@@ -18332,6 +18331,10 @@ given, @value{GDBN} will attempt to complete using the object's
 @code{complete} method (see below); if no such method is found, an
 error will occur when completion is attempted.
 
+@var{prefix} is an optional argument.  If @code{True}, then the new
+command is a prefix command; sub-commands of this command may be
+registered.
+
 The help text for the new command is taken from the Python
 documentation string for the command's class, if there is one.  If
 there is no documentation string, a default value is used.
diff --git a/gdb/python/python-cmd.c b/gdb/python/python-cmd.c
index 91cdc7f..014274b 100644
--- a/gdb/python/python-cmd.c
+++ b/gdb/python/python-cmd.c
@@ -54,8 +54,10 @@ struct cmdpy_object
 
   /* The corresponding gdb command object, or NULL if the command is
      no longer installed.  */
-  /* It isn't clear if we will ever care about this.  */
   struct cmd_list_element *command;
+
+  /* For a prefix command, this is the list of sub-commands.  */
+  struct cmd_list_element *sub_list;
 };
 
 typedef struct cmdpy_object cmdpy_object;
@@ -92,9 +94,11 @@ cmdpy_destroyer (struct cmd_list_element *self, void *context)
   cmd->command = NULL;
   Py_DECREF (cmd);
 
-  /* We allocated the name and doc string.  */
+  /* We allocated the name, doc string, and perhaps the prefix
+     name.  */
   xfree (self->name);
   xfree (self->doc);
+  xfree (self->prefixname);
 
   PyGILState_Release (state);
 }
@@ -114,7 +118,15 @@ cmdpy_function (struct cmd_list_element *command, char *args, int from_tty)
   if (! obj)
     error (_("Invalid invocation of Python command object."));
   if (! PyObject_HasAttr ((PyObject *) obj, invoke_cst))
-    error (_("Python command object missing 'invoke' method."));
+    {
+      if (obj->command->prefixname)
+	{
+	  /* A prefix command does not need an invoke method.  */
+	  do_cleanups (cleanup);
+	  return;
+	}
+      error (_("Python command object missing 'invoke' method."));
+    }
 
   if (! args)
     {
@@ -327,7 +339,7 @@ gdbpy_parse_command_name (char *text, struct cmd_list_element ***base_list,
 
 /* Object initializer; sets up gdb-side structures for command.
 
-   Use: __init__(NAME, CMDCLASS, [COMPLETERCLASS]).
+   Use: __init__(NAME, CMDCLASS, [COMPLETERCLASS, [PREFIX]]).
 
    NAME is the name of the command.  It may consist of multiple words,
    in which case the final word is the name of the new command, and
@@ -340,6 +352,8 @@ gdbpy_parse_command_name (char *text, struct cmd_list_element ***base_list,
    "complete" method will be used.  Otherwise, it should be one of the
    COMPLETE_* constants defined in the gdb module.
 
+   If PREFIX is True, then this command is a prefix command.
+
    The documentation for the command is taken from the doc string for
    the python class.
    
@@ -354,7 +368,8 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kwds)
   char *docstring = NULL;
   volatile struct gdb_exception except;
   struct cmd_list_element **cmd_list;
-  char *cmd_name;
+  char *cmd_name, *pfx_name;
+  PyObject *is_prefix = NULL;
 
   if (obj->command)
     {
@@ -365,7 +380,8 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kwds)
       return -1;
     }
 
-  if (! PyArg_ParseTuple (args, "si|i", &name, &cmdtype, &completetype))
+  if (! PyArg_ParseTuple (args, "si|iO", &name, &cmdtype,
+			  &completetype, &is_prefix))
     return -1;
 
   if (cmdtype != no_class && cmdtype != class_run
@@ -389,6 +405,31 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kwds)
   if (! cmd_name)
     return -1;
 
+  pfx_name = NULL;
+  if (is_prefix == Py_True)
+    {
+      int i, out;
+
+      /* Make a normalized form of the command name.  */
+      pfx_name = xmalloc (strlen (name) + 2);
+
+      i = 0;
+      out = 0;
+      while (name[i])
+	{
+	  /* Skip whitespace.  */
+	  while (name[i] == ' ' || name[i] == '\t')
+	    ++i;
+	  /* Copy non-whitespace characters.  */
+	  while (name[i] && name[i] != ' ' && name[i] != '\t')
+	    pfx_name[out++] = name[i++];
+	  /* Add a single space after each word -- including the final
+	     word.  */
+	  pfx_name[out++] = ' ';
+	}
+      pfx_name[out] = '\0';
+    }
+
   if (PyObject_HasAttr (self, gdbpy_doc_cst))
     {
       PyObject *ds_obj = PyObject_GetAttr (self, gdbpy_doc_cst);
@@ -402,11 +443,23 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kwds)
 
   TRY_CATCH (except, RETURN_MASK_ALL)
     {
-      struct cmd_list_element *cmd = add_cmd (cmd_name,
-					      (enum command_class) cmdtype,
-					      NULL,
-					      docstring,
-					      cmd_list);
+      struct cmd_list_element *cmd;
+
+      if (pfx_name)
+	{
+	  int allow_unknown;
+
+	  /* If we have our own "invoke" method, then allow unknown
+	     sub-commands.  */
+	  allow_unknown = PyObject_HasAttr (self, invoke_cst);
+	  cmd = add_prefix_cmd (cmd_name, (enum command_class) cmdtype,
+				NULL, docstring, &obj->sub_list,
+				pfx_name, allow_unknown, cmd_list);
+	}
+      else
+	cmd = add_cmd (cmd_name, (enum command_class) cmdtype, NULL,
+		       docstring, cmd_list);
+
       /* There appears to be no API to set this.  */
       cmd->func = cmdpy_function;
       cmd->destroyer = cmdpy_destroyer;
@@ -420,6 +473,7 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kwds)
     {
       xfree (cmd_name);
       xfree (docstring);
+      xfree (pfx_name);
       Py_DECREF (self);
       PyErr_Format (except.reason == RETURN_QUIT
 		    ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,


hooks/post-receive
--
Repository for Project Archer.


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

* [SCM]  archer-tromey-python: gdb
@ 2008-11-18 15:54 tromey
  0 siblings, 0 replies; 26+ messages in thread
From: tromey @ 2008-11-18 15:54 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-python has been updated
       via  01af16dc305d029f7bc580ec848b60b7f2b2a880 (commit)
      from  98011209ea5a2fc236cce680946b1097caa80df7 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 01af16dc305d029f7bc580ec848b60b7f2b2a880
Author: Tom Tromey <tromey@redhat.com>
Date:   Tue Nov 18 08:54:03 2008 -0700

    gdb
    	* python/python-internal.h (gdbpy_doc_cst): Declare.
    	* python/python-cmd.c (cmdpy_init): Use gdbpy_doc_cst.  Don't set
    	tp_new or tp_init.
    	(cmdpy_object_type): Add extra entries.  Set tp_init and tp_new.
    	* python/python.c (gdbpy_doc_cst): New global.
    	(_initialize_python): Initialize it.
    	* python/python-param.c (set_doc_cst, show_doc_cst): New globals.
    	(gdbpy_initialize_parameters): Initialize them.  Don't set
    	tp_new or tp_init.
    	(parmpy_init): Use gdbpy_doc_cst.  Get set and show help.  Don't
    	examine __doc__.
    	(get_doc_string): New function.
    	(parmpy_object_type): Add extra entries.  Set tp_init and tp_new.
    gdb/doc
    	* gdb.texinfo (Parameters In Python): Document set_doc, show_doc.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog                |   16 ++++++++++
 gdb/doc/ChangeLog            |    4 ++
 gdb/doc/gdb.texinfo          |   14 +++++++++
 gdb/python/python-cmd.c      |   18 ++++++++---
 gdb/python/python-internal.h |    1 +
 gdb/python/python-param.c    |   64 +++++++++++++++++++++++++++++++----------
 gdb/python/python.c          |    2 +
 7 files changed, 98 insertions(+), 21 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index c51b9b1..c5fa878 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,19 @@
+2008-11-18  Tom Tromey  <tromey@redhat.com>
+
+	* python/python-internal.h (gdbpy_doc_cst): Declare.
+	* python/python-cmd.c (cmdpy_init): Use gdbpy_doc_cst.  Don't set
+	tp_new or tp_init.
+	(cmdpy_object_type): Add extra entries.  Set tp_init and tp_new.
+	* python/python.c (gdbpy_doc_cst): New global.
+	(_initialize_python): Initialize it.
+	* python/python-param.c (set_doc_cst, show_doc_cst): New globals.
+	(gdbpy_initialize_parameters): Initialize them.  Don't set
+	tp_new or tp_init.
+	(parmpy_init): Use gdbpy_doc_cst.  Get set and show help.  Don't
+	examine __doc__.
+	(get_doc_string): New function.
+	(parmpy_object_type): Add extra entries.  Set tp_init and tp_new.
+
 2008-11-17  Tom Tromey  <tromey@redhat.com>
 
 	* varobj.c (install_default_visualizer): Remove 'type' argument.
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index e205dea..385bbca 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,7 @@
+2008-11-18  Tom Tromey  <tromey@redhat.com>
+
+	* gdb.texinfo (Parameters In Python): Document set_doc, show_doc.
+
 2008-11-16  Tom Tromey  <tromey@redhat.com>
 
 	* gdb.texinfo (Types From Inferior): Update.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index eb24ece..9446ce4 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -18553,6 +18553,20 @@ documentation string for the parameter's class, if there is one.  If
 there is no documentation string, a default value is used.
 @end defmethod
 
+@defivar Parameter set_doc
+If this attribute exists, and is a string, then its value is used as
+the help text for this parameter's @code{set} command.  The value is
+examined when @code{Parameter.__init__} is invoked; subsequent changes
+have no effect.
+@end defivar
+
+@defivar Parameter show_doc
+If this attribute exists, and is a string, then its value is used as
+the help text for this parameter's @code{show} command.  The value is
+examined when @code{Parameter.__init__} is invoked; subsequent changes
+have no effect.
+@end defivar
+
 @defivar Parameter value
 The @code{value} attribute holds the underlying value of the
 parameter.  It can be read and assigned to just as any other
diff --git a/gdb/python/python-cmd.c b/gdb/python/python-cmd.c
index 63b5432..91cdc7f 100644
--- a/gdb/python/python-cmd.c
+++ b/gdb/python/python-cmd.c
@@ -389,9 +389,9 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kwds)
   if (! cmd_name)
     return -1;
 
-  if (PyObject_HasAttrString (self, "__doc__"))
+  if (PyObject_HasAttr (self, gdbpy_doc_cst))
     {
-      PyObject *ds_obj = PyObject_GetAttrString (self, "__doc__");
+      PyObject *ds_obj = PyObject_GetAttr (self, gdbpy_doc_cst);
       if (ds_obj && gdbpy_is_string (ds_obj))
 	docstring = python_string_to_host_string (ds_obj);
     }
@@ -437,8 +437,6 @@ gdbpy_initialize_commands (void)
 {
   int i;
 
-  cmdpy_object_type.tp_new = PyType_GenericNew;
-  cmdpy_object_type.tp_init = cmdpy_init;
   if (PyType_Ready (&cmdpy_object_type) < 0)
     return;
 
@@ -515,5 +513,15 @@ static PyTypeObject cmdpy_object_type =
   0,				  /* tp_weaklistoffset */
   0,				  /* tp_iter */
   0,				  /* tp_iternext */
-  cmdpy_object_methods		  /* tp_methods */
+  cmdpy_object_methods,		  /* tp_methods */
+  0,				  /* tp_members */
+  0,				  /* tp_getset */
+  0,				  /* tp_base */
+  0,				  /* tp_dict */
+  0,				  /* tp_descr_get */
+  0,				  /* tp_descr_set */
+  0,				  /* tp_dictoffset */
+  cmdpy_init,			  /* tp_init */
+  0,				  /* tp_alloc */
+  PyType_GenericNew		  /* tp_new */
 };
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 19f39cb..a03d889 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -136,5 +136,6 @@ char *gdbpy_get_display_hint (PyObject *printer);
 extern PyObject *gdbpy_children_cst;
 extern PyObject *gdbpy_to_string_cst;
 extern PyObject *gdbpy_display_hint_cst;
+extern PyObject *gdbpy_doc_cst;
 
 #endif /* GDB_PYTHON_INTERNAL_H */
diff --git a/gdb/python/python-param.c b/gdb/python/python-param.c
index cf1ceaa..96c92c8 100644
--- a/gdb/python/python-param.c
+++ b/gdb/python/python-param.c
@@ -89,6 +89,10 @@ typedef struct parmpy_object parmpy_object;
 
 static PyTypeObject parmpy_object_type;
 
+/* Some handy string constants.  */
+static PyObject *set_doc_cst;
+static PyObject *show_doc_cst;
+
 \f
 
 /* Get an attribute.  */
@@ -374,6 +378,23 @@ compute_enum_values (parmpy_object *self, PyObject *enum_values)
   return 1;
 }
 
+/* A helper function which returns a documentation string for an
+   object.  */
+static char *
+get_doc_string (PyObject *object, PyObject *attr)
+{
+  char *result = NULL;
+  if (PyObject_HasAttr (object, attr))
+    {
+      PyObject *ds_obj = PyObject_GetAttr (object, attr);
+      if (ds_obj && gdbpy_is_string (ds_obj))
+	result = python_string_to_host_string (ds_obj);
+    }
+  if (! result)
+    result = xstrdup ("This command is not documented.");
+  return result;
+}
+
 /* Object initializer; sets up gdb-side structures for command.
 
    Use: __init__(NAME, CMDCLASS, PARMCLASS, [ENUM])
@@ -401,7 +422,7 @@ parmpy_init (PyObject *self, PyObject *args, PyObject *kwds)
 {
   parmpy_object *obj = (parmpy_object *) self;
   char *name;
-  char *docstring = NULL;
+  char *set_doc, *show_doc;
   char *cmd_name;
   int parmclass, cmdtype;
   PyObject *enum_values = NULL;
@@ -458,15 +479,10 @@ parmpy_init (PyObject *self, PyObject *args, PyObject *kwds)
   if (! cmd_name)
     return -1;
 
-  /* FIXME: need set and show docs.  */
-  if (PyObject_HasAttrString (self, "__doc__"))
-    {
-      PyObject *ds_obj = PyObject_GetAttrString (self, "__doc__");
-      if (ds_obj && gdbpy_is_string (ds_obj))
-	docstring = python_string_to_host_string (ds_obj);
-    }
-  if (! docstring)
-    docstring = xstrdup ("This command is not documented.");
+  /* FIXME: there is no way to register a destructor function for
+     set/show commands.  So, these are leaked.  */
+  set_doc = get_doc_string (self, set_doc_cst);
+  show_doc = get_doc_string (self, show_doc_cst);
 
   Py_INCREF (self);
 
@@ -474,13 +490,14 @@ parmpy_init (PyObject *self, PyObject *args, PyObject *kwds)
     {
       add_setshow_generic (parmclass, (enum command_class) cmdtype,
 			   cmd_name, obj,
-			   "FIXME: set doc", "FIXME: show doc",
-			   docstring, set_list, show_list);
+			   set_doc, show_doc,
+			   NULL, set_list, show_list);
     }
   if (except.reason < 0)
     {
       xfree (cmd_name);
-      xfree (docstring);
+      xfree (set_doc);
+      xfree (show_doc);
       Py_DECREF (self);
       PyErr_Format (except.reason == RETURN_QUIT
 		    ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
@@ -498,11 +515,16 @@ gdbpy_initialize_parameters (void)
 {
   int i;
 
-  parmpy_object_type.tp_new = PyType_GenericNew;
-  parmpy_object_type.tp_init = parmpy_init;
   if (PyType_Ready (&parmpy_object_type) < 0)
     return;
 
+  set_doc_cst = PyString_FromString ("set_doc");
+  if (! set_doc_cst)
+    return;
+  show_doc_cst = PyString_FromString ("show_doc");
+  if (! show_doc_cst)
+    return;
+
   for (i = 0; parm_constants[i].name; ++i)
     {
       if (PyModule_AddIntConstant (gdb_module,
@@ -548,5 +570,15 @@ static PyTypeObject parmpy_object_type =
   0,				  /* tp_weaklistoffset */
   0,				  /* tp_iter */
   0,				  /* tp_iternext */
-  0				  /* tp_methods */
+  0,				  /* tp_methods */
+  0,				  /* tp_members */
+  0,				  /* tp_getset */
+  0,				  /* tp_base */
+  0,				  /* tp_dict */
+  0,				  /* tp_descr_get */
+  0,				  /* tp_descr_set */
+  0,				  /* tp_dictoffset */
+  parmpy_init,			  /* tp_init */
+  0,				  /* tp_alloc */
+  PyType_GenericNew		  /* tp_new */
 };
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 1ff3c25..340213f 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -66,6 +66,7 @@ PyObject *gdb_module;
 PyObject *gdbpy_to_string_cst;
 PyObject *gdbpy_children_cst;
 PyObject *gdbpy_display_hint_cst;
+PyObject *gdbpy_doc_cst;
 
 /* Given a command_line, return a command string suitable for passing
    to Python.  Lines in the string are separated by newlines.  The
@@ -1276,6 +1277,7 @@ Enables or disables auto-loading of Python code when an object is opened."),
   gdbpy_to_string_cst = PyString_FromString ("to_string");
   gdbpy_children_cst = PyString_FromString ("children");
   gdbpy_display_hint_cst = PyString_FromString ("display_hint");
+  gdbpy_doc_cst = PyString_FromString ("__doc__");
 
   /* Create a couple objects which are used for Python's stdout and
      stderr.  */


hooks/post-receive
--
Repository for Project Archer.


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

* [SCM]  archer-tromey-python: gdb
@ 2008-11-17 15:45 tromey
  0 siblings, 0 replies; 26+ messages in thread
From: tromey @ 2008-11-17 15:45 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-python has been updated
       via  98011209ea5a2fc236cce680946b1097caa80df7 (commit)
      from  cf82162b0524be8d185e05f561bc177275bb7ecc (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 98011209ea5a2fc236cce680946b1097caa80df7
Author: Tom Tromey <tromey@redhat.com>
Date:   Mon Nov 17 08:45:25 2008 -0700

    gdb
    	* varobj.c (install_default_visualizer): Remove 'type' argument.
    	(varobj_create): Update.
    	(varobj_list_children): Likewise
    	(varobj_add_child): Likewise.
    	(varobj_update): Don't reinstall visualizer when type has
    	changed.
    gdb/testsuite
    	* gdb.python/python-prettyprint.c (do_nothing): New function.
    	(main): Call it.
    	* gdb.python/python-prettyprint.exp (run_lang_tests): Update for
    	reference-printing change.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog                                 |    9 +++++++++
 gdb/testsuite/ChangeLog                       |    2 ++
 gdb/testsuite/gdb.python/python-mi.exp        |   10 ++++++++--
 gdb/testsuite/gdb.python/python-prettyprint.c |   11 +++++++++++
 gdb/varobj.c                                  |   20 +++++++-------------
 5 files changed, 37 insertions(+), 15 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 7c4bf4e..c51b9b1 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,12 @@
+2008-11-17  Tom Tromey  <tromey@redhat.com>
+
+	* varobj.c (install_default_visualizer): Remove 'type' argument.
+	(varobj_create): Update.
+	(varobj_list_children): Likewise
+	(varobj_add_child): Likewise.
+	(varobj_update): Don't reinstall visualizer when type has
+	changed.
+
 2008-11-16  Tom Tromey  <tromey@redhat.com>
 
 	* python/python-type.c (type_object_type): Add extra fields.
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 90079f7..ec897a2 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,7 @@
 2008-11-17  Tom Tromey  <tromey@redhat.com>
 
+	* gdb.python/python-prettyprint.c (do_nothing): New function.
+	(main): Call it.
 	* gdb.python/python-prettyprint.exp (run_lang_tests): Update for
 	reference-printing change.
 
diff --git a/gdb/testsuite/gdb.python/python-mi.exp b/gdb/testsuite/gdb.python/python-mi.exp
index 4d411b3..7cc15c3 100644
--- a/gdb/testsuite/gdb.python/python-mi.exp
+++ b/gdb/testsuite/gdb.python/python-mi.exp
@@ -27,7 +27,7 @@ if [mi_gdb_start] {
 set testfile "python-prettyprint"
 set srcfile ${testfile}.c
 set binfile ${objdir}/${subdir}/${testfile}
-if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DMI}] != "" } {
     untested mi2-var-child.exp
     return -1
 }
@@ -48,7 +48,7 @@ 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_varobj container c "create container varobj"
+mi_create_floating_varobj container c "create container varobj"
 
 mi_list_varobj_children container {
 } "examine container children=0"
@@ -116,3 +116,9 @@ mi_list_varobj_children container {
     { {container.\[0\]} {\[0\]} 0 int }
     { {container.\[1\]} {\[1\]} 0 int }
 } "list varobj children after resetting child range"
+
+mi_continue_to_line \
+    [gdb_get_line_number {Another MI breakpoint} ${testfile}.c] \
+    "step to second breakpoint"
+
+mi_varobj_update_with_type_change container int 0 "update after type change"
diff --git a/gdb/testsuite/gdb.python/python-prettyprint.c b/gdb/testsuite/gdb.python/python-prettyprint.c
index f99e6f9..f8c2435 100644
--- a/gdb/testsuite/gdb.python/python-prettyprint.c
+++ b/gdb/testsuite/gdb.python/python-prettyprint.c
@@ -107,6 +107,13 @@ void init_ss(struct ss *s, int a, int b)
   init_s(&s->b, b);
 }
 
+void do_nothing(void)
+{
+  int c;
+
+  c = 23;			/* Another MI breakpoint */
+}
+
 int
 main ()
 {
@@ -144,5 +151,9 @@ main ()
   add_item (&c, 23);		/* MI breakpoint here */
   add_item (&c, 72);
 
+#ifdef MI
+  do_nothing ();
+#endif
+
   return 0;      /* break to inspect struct and union */
 }
diff --git a/gdb/varobj.c b/gdb/varobj.c
index 0c5bf6f..eed4036 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -247,7 +247,7 @@ static char *cppop (struct cpstack **pstack);
 static int install_new_value (struct varobj *var, struct value *value, 
 			      int initial);
 
-static void install_default_visualizer (struct varobj *var, struct type *type);
+static void install_default_visualizer (struct varobj *var);
 
 /* Language-specific routines. */
 
@@ -603,7 +603,7 @@ varobj_create (char *objname,
 	}
     }
 
-  install_default_visualizer (var, var->type);
+  install_default_visualizer (var);
   discard_cleanups (old_chain);
   return var;
 }
@@ -995,7 +995,7 @@ varobj_list_children (struct varobj *var)
 	  name = name_of_child (var, i);
 	  existing = create_child (var, i, name);
 	  VEC_replace (varobj_p, var->children, i, existing);
-	  install_default_visualizer (existing, existing->type);
+	  install_default_visualizer (existing);
 	}
     }
 
@@ -1009,7 +1009,7 @@ varobj_add_child (struct varobj *var, const char *name, struct value *value)
 					VEC_length (varobj_p, var->children), 
 					name, value);
   VEC_safe_push (varobj_p, var->children, v);
-  install_default_visualizer (v, v->type);
+  install_default_visualizer (v);
   return v;
 }
 
@@ -1427,7 +1427,7 @@ install_visualizer (struct varobj *var, PyObject *visualizer)
 }
 
 static void
-install_default_visualizer (struct varobj *var, struct type *type)
+install_default_visualizer (struct varobj *var)
 {
 #if HAVE_PYTHON
   struct cleanup *cleanup;
@@ -1437,8 +1437,8 @@ install_default_visualizer (struct varobj *var, struct type *type)
   state = PyGILState_Ensure ();
   cleanup = make_cleanup_py_restore_gil (&state);
 
-  if (type)
-    constructor = gdbpy_get_varobj_pretty_printer (type);
+  if (var->type)
+    constructor = gdbpy_get_varobj_pretty_printer (var->type);
   install_visualizer (var, constructor);
 
   do_cleanups (cleanup);
@@ -1543,12 +1543,6 @@ VEC(varobj_update_result) *varobj_update (struct varobj **varp, int explicit)
       new = value_of_root (varp, &type_changed);
       r.varobj = *varp;
 
-      /* Change the default visualizer, if needed, before installing
-	 the new value.  This ensures that we instantiate the correct
-	 class.  */
-      if (type_changed)
-	install_default_visualizer (*varp, value_type (new));
-
       r.type_changed = type_changed;
       if (install_new_value ((*varp), new, type_changed))
 	r.changed = 1;


hooks/post-receive
--
Repository for Project Archer.


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

* [SCM]  archer-tromey-python: gdb
@ 2008-11-16 22:18 tromey
  0 siblings, 0 replies; 26+ messages in thread
From: tromey @ 2008-11-16 22:18 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-python has been updated
       via  5cdfaa4b6fea4493eb6dda47d27807a12beef384 (commit)
      from  e97eeebcadd8e1ced9e9e428c6809e01a94dbfac (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 5cdfaa4b6fea4493eb6dda47d27807a12beef384
Author: Tom Tromey <tromey@redhat.com>
Date:   Sun Nov 16 15:18:27 2008 -0700

    gdb
    	* python/python-type.c (type_object_type): Add extra fields.
    	(gdbpy_initialize_types): Don't set tp_new.  Ready new type.
    	(pyty_field_object): New type.
    	(field_object_type): New global.
    	(field_dealloc): New function.
    	(field_new): Likewise.
    	(convert_field): Create field objects.
    gdb/doc
    	* gdb.texinfo (Types From Inferior): Update.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog            |   10 ++++
 gdb/doc/ChangeLog        |    4 ++
 gdb/doc/gdb.texinfo      |   15 ++---
 gdb/python/python-type.c |  126 ++++++++++++++++++++++++++++++++++++++++------
 4 files changed, 131 insertions(+), 24 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 9de4746..7c4bf4e 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,15 @@
 2008-11-16  Tom Tromey  <tromey@redhat.com>
 
+	* python/python-type.c (type_object_type): Add extra fields.
+	(gdbpy_initialize_types): Don't set tp_new.  Ready new type.
+	(pyty_field_object): New type.
+	(field_object_type): New global.
+	(field_dealloc): New function.
+	(field_new): Likewise.
+	(convert_field): Create field objects.
+
+2008-11-16  Tom Tromey  <tromey@redhat.com>
+
 	* python/python-type.c (typy_code): New function.
 	(struct pyty_code): New type.
 	(ENTRY): New define.
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 0b85f5c..e205dea 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -2,6 +2,10 @@
 
 	* gdb.texinfo (Types From Inferior): Update.
 
+2008-11-16  Tom Tromey  <tromey@redhat.com>
+
+	* gdb.texinfo (Types From Inferior): Update.
+
 2008-11-13  Tom Tromey  <tromey@redhat.com>
 
 	* gdb.texinfo (Basic Python): Document gdb.get_objfiles and
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 6a38009..eb24ece 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -17937,28 +17937,25 @@ Return the type code for this type.  The type code will be one of the
 @end defmethod
 
 @defmethod Type fields
-Return a sequence of all fields of this type.  If this type has no
-fields, the sequence will be empty.
-
 For structure and union types, this method returns the fields.  Range
 types have two fields, the minimum and maximum values.  Enum types
 have one field per enum constant.  Function and method types have one
 field per parameter.  The base types of C++ classes are also
-represented as fields.
+represented as fields.  If the type has no fields, or does not fit
+into one of these categories, an empty sequence will be returned.
 
-Each field is a dictionary, with some pre-defined elements:
+Each field is an object, with some pre-defined attributes:
 @table @code
 @item bitpos
-This element is not available for @code{static} fields.  For
+This attribute is not available for @code{static} fields.  For
 non-@code{static} fields, the value is the bit position of the field.
 
 @item name
-The name of the field.  This element is not available for anonymous
-fields.
+The name of the field, or @code{None} for anonymous fields.
 
 @item artificial
 This is @code{True} if the field is artificial, usually meaning that
-it was provided by the compiler and not the user.  This value is
+it was provided by the compiler and not the user.  This attribute is
 always provided, and is @code{False} if the field is not artificial.
 
 @item bitsize
diff --git a/gdb/python/python-type.c b/gdb/python/python-type.c
index f24a023..31af1ed 100644
--- a/gdb/python/python-type.c
+++ b/gdb/python/python-type.c
@@ -50,6 +50,17 @@ typedef struct pyty_type_object
 
 static PyTypeObject type_object_type;
 
+/* A Field object.  */
+typedef struct pyty_field_object
+{
+  PyObject_HEAD
+
+  /* Dictionary holding our attributes.  */
+  PyObject *dict;
+} field_object;
+
+static PyTypeObject field_object_type;
+
 /* This is used to initialize various gdb.TYPE_ constants.  */
 struct pyty_code
 {
@@ -96,6 +107,31 @@ static struct pyty_code pyty_codes[] =
 
 \f
 
+static void
+field_dealloc (PyObject *obj)
+{
+  field_object *f = (field_object *) obj;
+  Py_XDECREF (f->dict);
+}
+
+static PyObject *
+field_new (void)
+{
+  field_object *result = PyObject_New (field_object, &field_object_type);
+  if (result)
+    {
+      result->dict = PyDict_New ();
+      if (!result->dict)
+	{
+	  Py_DECREF (result);
+	  result = NULL;
+	}
+    }
+  return (PyObject *) result;
+}
+
+\f
+
 /* Return the code for this type.  */
 static PyObject *
 typy_code (PyObject *self, PyObject *args)
@@ -109,10 +145,10 @@ typy_code (PyObject *self, PyObject *args)
 static PyObject *
 convert_field (PyObject *self, struct type *type, int field)
 {
-  PyObject *dict = PyDict_New ();
+  PyObject *result = field_new ();
   PyObject *arg;
 
-  if (!dict)
+  if (!result)
     return NULL;
 
   if (!TYPE_FIELD_STATIC (type, field))
@@ -121,42 +157,45 @@ convert_field (PyObject *self, struct type *type, int field)
       if (!arg)
 	goto fail;
 
-      if (PyDict_SetItemString (dict, "bitpos", arg) < 0)
+      if (PyObject_SetAttrString (result, "bitpos", arg) < 0)
 	goto failarg;
     }
 
   if (TYPE_FIELD_NAME (type, field))
+    arg = PyString_FromString (TYPE_FIELD_NAME (type, field));
+  else
     {
-      arg = PyString_FromString (TYPE_FIELD_NAME (type, field));
-      if (!arg)
-	goto fail;
-      if (PyDict_SetItemString (dict, "name", arg) < 0)
-	goto failarg;
+      arg = Py_None;
+      Py_INCREF (arg);
     }
+  if (!arg)
+    goto fail;
+  if (PyObject_SetAttrString (result, "name", arg) < 0)
+    goto failarg;
 
   arg = TYPE_FIELD_ARTIFICIAL (type, field) ? Py_True : Py_False;
   Py_INCREF (arg);
-  if (PyDict_SetItemString (dict, "artificial", arg) < 0)
+  if (PyObject_SetAttrString (result, "artificial", arg) < 0)
     goto failarg;
 
   arg = PyLong_FromLong (TYPE_FIELD_BITSIZE (type, field));
   if (!arg)
     goto fail;
-  if (PyDict_SetItemString (dict, "bitsize", arg) < 0)
+  if (PyObject_SetAttrString (result, "bitsize", arg) < 0)
     goto failarg;
 
   arg = type_to_type_object (self, TYPE_FIELD_TYPE (type, field));
   if (!arg)
     goto fail;
-  if (PyDict_SetItemString (dict, "type", arg) < 0)
+  if (PyObject_SetAttrString (result, "type", arg) < 0)
     goto failarg;
 
-  return dict;
+  return result;
 
  failarg:
   Py_DECREF (arg);
  fail:
-  Py_DECREF (dict);
+  Py_DECREF (result);
   return NULL;
 }
 
@@ -169,6 +208,9 @@ typy_fields (PyObject *self, PyObject *args)
   int i;
   struct type *type = ((type_object *) self)->type;
 
+  /* We would like to make a tuple here, make fields immutable, and
+     then memoize the result (and perhaps make Field.type() lazy).
+     However, that can lead to cycles.  */
   result = PyList_New (0);
 
   for (i = 0; i < TYPE_NFIELDS (type); ++i)
@@ -624,9 +666,10 @@ gdbpy_initialize_types (void)
   typy_objfile_data_key
     = register_objfile_data_with_cleanup (clean_up_objfile_types);
 
-  type_object_type.tp_new = typy_new;
   if (PyType_Ready (&type_object_type) < 0)
     return;
+  if (PyType_Ready (&field_object_type) < 0)
+    return;
 
   for (i = 0; pyty_codes[i].name; ++i)
     {
@@ -691,5 +734,58 @@ static PyTypeObject type_object_type =
   0,				  /* tp_weaklistoffset */
   0,				  /* tp_iter */
   0,				  /* tp_iternext */
-  type_object_methods		  /* tp_methods */
+  type_object_methods,		  /* tp_methods */
+  0,				  /* tp_members */
+  0,				  /* tp_getset */
+  0,				  /* tp_base */
+  0,				  /* tp_dict */
+  0,				  /* tp_descr_get */
+  0,				  /* tp_descr_set */
+  0,				  /* tp_dictoffset */
+  0,				  /* tp_init */
+  0,				  /* tp_alloc */
+  typy_new,			  /* tp_new */
+};
+
+static PyTypeObject field_object_type =
+{
+  PyObject_HEAD_INIT (NULL)
+  0,				  /*ob_size*/
+  "gdb.Field",			  /*tp_name*/
+  sizeof (field_object),	  /*tp_basicsize*/
+  0,				  /*tp_itemsize*/
+  field_dealloc,		  /*tp_dealloc*/
+  0,				  /*tp_print*/
+  0,				  /*tp_getattr*/
+  0,				  /*tp_setattr*/
+  0,				  /*tp_compare*/
+  0,				  /*tp_repr*/
+  0,				  /*tp_as_number*/
+  0,				  /*tp_as_sequence*/
+  0,				  /*tp_as_mapping*/
+  0,				  /*tp_hash */
+  0,				  /*tp_call*/
+  0,				  /*tp_str*/
+  0,				  /*tp_getattro*/
+  0,				  /*tp_setattro*/
+  0,				  /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,  /*tp_flags*/
+  "GDB field object",		  /* tp_doc */
+  0,				  /* tp_traverse */
+  0,				  /* tp_clear */
+  0,				  /* tp_richcompare */
+  0,				  /* tp_weaklistoffset */
+  0,				  /* tp_iter */
+  0,				  /* tp_iternext */
+  0,				  /* tp_methods */
+  0,				  /* tp_members */
+  0,				  /* tp_getset */
+  0,				  /* tp_base */
+  0,				  /* tp_dict */
+  0,				  /* tp_descr_get */
+  0,				  /* tp_descr_set */
+  offsetof (field_object, dict),  /* tp_dictoffset */
+  0,				  /* tp_init */
+  0,				  /* tp_alloc */
+  0,				  /* tp_new */
 };


hooks/post-receive
--
Repository for Project Archer.


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

* [SCM]  archer-tromey-python: gdb
@ 2008-11-16 16:56 tromey
  0 siblings, 0 replies; 26+ messages in thread
From: tromey @ 2008-11-16 16:56 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-python has been updated
       via  e97eeebcadd8e1ced9e9e428c6809e01a94dbfac (commit)
      from  80512129f1fb5c58348113fcc93ff854b1f7d6f3 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit e97eeebcadd8e1ced9e9e428c6809e01a94dbfac
Author: Tom Tromey <tromey@redhat.com>
Date:   Sun Nov 16 09:56:30 2008 -0700

    gdb
    	* python/python-type.c (typy_code): New function.
    	(struct pyty_code): New type.
    	(ENTRY): New define.
    	(pyty_codes): New array.
    	(clean_up_objfile_types): Acquire GIL.
    	(gdbpy_initialize_types): Register new constants.
    	(type_object_methods): Add "code", "fields", "tag" methods.
    	(convert_field): New functionn.
    	(typy_fields): Likewise.
    	(typy_tag): Likewise.
    	(typy_lookup_typename): Allow struct/union/enum.  Change error
    	handling.
    	(typy_lookup_type): Update.
    	(typy_new): Likewise.
    gdb/doc
    	* gdb.texinfo (Types From Inferior): Update.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog            |   17 ++++
 gdb/doc/ChangeLog        |    4 +
 gdb/doc/gdb.texinfo      |  207 +++++++++++++++++++++++++++++++++++++++++++++-
 gdb/python/python-type.c |  197 ++++++++++++++++++++++++++++++++++++++++---
 4 files changed, 410 insertions(+), 15 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 94b6427..9de4746 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,20 @@
+2008-11-16  Tom Tromey  <tromey@redhat.com>
+
+	* python/python-type.c (typy_code): New function.
+	(struct pyty_code): New type.
+	(ENTRY): New define.
+	(pyty_codes): New array.
+	(clean_up_objfile_types): Acquire GIL.
+	(gdbpy_initialize_types): Register new constants.
+	(type_object_methods): Add "code", "fields", "tag" methods.
+	(convert_field): New functionn.
+	(typy_fields): Likewise.
+	(typy_tag): Likewise.
+	(typy_lookup_typename): Allow struct/union/enum.  Change error
+	handling.
+	(typy_lookup_type): Update.
+	(typy_new): Likewise.
+
 2008-11-15  Tom Tromey  <tromey@redhat.com>
 
 	* varobj.c (varobj_get_display_hint): Acquire GIL.
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 6dad6d3..0b85f5c 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,7 @@
+2008-11-16  Tom Tromey  <tromey@redhat.com>
+
+	* gdb.texinfo (Types From Inferior): Update.
+
 2008-11-13  Tom Tromey  <tromey@redhat.com>
 
 	* gdb.texinfo (Basic Python): Document gdb.get_objfiles and
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 42ed962..6a38009 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -17931,6 +17931,46 @@ If @var{block} is given, then @var{name} is looked up in that scope.
 Otherwise, it is searched for globally.
 @end defmethod
 
+@defmethod Type code
+Return the type code for this type.  The type code will be one of the
+@code{TYPE_CODE_} constants defined below.
+@end defmethod
+
+@defmethod Type fields
+Return a sequence of all fields of this type.  If this type has no
+fields, the sequence will be empty.
+
+For structure and union types, this method returns the fields.  Range
+types have two fields, the minimum and maximum values.  Enum types
+have one field per enum constant.  Function and method types have one
+field per parameter.  The base types of C++ classes are also
+represented as fields.
+
+Each field is a dictionary, with some pre-defined elements:
+@table @code
+@item bitpos
+This element is not available for @code{static} fields.  For
+non-@code{static} fields, the value is the bit position of the field.
+
+@item name
+The name of the field.  This element is not available for anonymous
+fields.
+
+@item artificial
+This is @code{True} if the field is artificial, usually meaning that
+it was provided by the compiler and not the user.  This value is
+always provided, and is @code{False} if the field is not artificial.
+
+@item bitsize
+If the field is packed, or is a bitfield, then this will have a
+nonzero value, which is the size of the field in bits.  Otherwise,
+this will be zero; in this case the field's size is given by its type.
+
+@item type
+The type of the field.
+@end table
+@end defmethod
+
 @defmethod Type pointer
 Return a new @code{gdb.Type} object which represents a pointer to this
 type.
@@ -17942,7 +17982,16 @@ type.
 @end defmethod
 
 @defmethod Type sizeof
-Return the size of this type, in bytes.
+Return the size of this type, in target @code{char} units.  Usually, a
+target's @code{char} type will be an 8-bit byte.  However, on some
+unusual platforms, this type may have a different size.
+@end defmethod
+
+@defmethod Type tag
+Return the tag name for this type.  The tag name is the name after
+@code{struct}, @code{union}, or @code{enum} in C; not all languages
+have this concept.  If this type has no tag name, then @code{None} is
+returned.
 @end defmethod
 
 @defmethod Type target
@@ -17953,7 +18002,8 @@ For a pointer type, the target type is the type of the pointed-to
 object.  For an array type, the target type is the type of the
 elements of the array.  For a function type, the target type is the
 type of the return value.  For a complex type, the target type is the
-type of the elements.
+type of the elements.  For a typedef, the target type is the aliased
+type.
 @end defmethod
 
 @defmethod Type template_argument n [block]
@@ -17969,6 +18019,159 @@ Otherwise, it is searched for globally.
 @end defmethod
 @end table
 
+
+Each type has a code, which indicates what category this type falls
+into.  The available type categories are represented by constants
+defined in the @code{gdb} module:
+
+@table @code
+@findex TYPE_CODE_PTR
+@findex gdb.TYPE_CODE_PTR
+@item TYPE_CODE_PTR
+The type is a pointer.
+
+@findex TYPE_CODE_ARRAY
+@findex gdb.TYPE_CODE_ARRAY
+@item TYPE_CODE_ARRAY
+The type is an array.
+
+@findex TYPE_CODE_STRUCT
+@findex gdb.TYPE_CODE_STRUCT
+@item TYPE_CODE_STRUCT
+The type is a structure.
+
+@findex TYPE_CODE_UNION
+@findex gdb.TYPE_CODE_UNION
+@item TYPE_CODE_UNION
+The type is a union.
+
+@findex TYPE_CODE_ENUM
+@findex gdb.TYPE_CODE_ENUM
+@item TYPE_CODE_ENUM
+The type is an enum.
+
+@findex TYPE_CODE_FLAGS
+@findex gdb.TYPE_CODE_FLAGS
+@item TYPE_CODE_FLAGS
+A bit flags type.
+@c FIXME: what is this?
+
+@findex TYPE_CODE_FUNC
+@findex gdb.TYPE_CODE_FUNC
+@item TYPE_CODE_FUNC
+The type is a function.
+
+@findex TYPE_CODE_INT
+@findex gdb.TYPE_CODE_INT
+@item TYPE_CODE_INT
+The type is an integer type.
+
+@findex TYPE_CODE_FLT
+@findex gdb.TYPE_CODE_FLT
+@item TYPE_CODE_FLT
+A floating point type.
+
+@findex TYPE_CODE_VOID
+@findex gdb.TYPE_CODE_VOID
+@item TYPE_CODE_VOID
+The special type @code{void}.
+
+@findex TYPE_CODE_SET
+@findex gdb.TYPE_CODE_SET
+@item TYPE_CODE_SET
+A Pascal set type.
+
+@findex TYPE_CODE_RANGE
+@findex gdb.TYPE_CODE_RANGE
+@item TYPE_CODE_RANGE
+A range type, that is, an integer type with bounds.
+
+@findex TYPE_CODE_STRING
+@findex gdb.TYPE_CODE_STRING
+@item TYPE_CODE_STRING
+A string type.  Note that this is only used for certain languages with
+language-defined string types; C strings are not represented this way.
+
+@findex TYPE_CODE_BITSTRING
+@findex gdb.TYPE_CODE_BITSTRING
+@item TYPE_CODE_BITSTRING
+A string of bits.
+
+@findex TYPE_CODE_ERROR
+@findex gdb.TYPE_CODE_ERROR
+@item TYPE_CODE_ERROR
+An unknown or erroneous type.
+
+@findex TYPE_CODE_METHOD
+@findex gdb.TYPE_CODE_METHOD
+@item TYPE_CODE_METHOD
+A C++ method type.
+
+@findex TYPE_CODE_METHODPTR
+@findex gdb.TYPE_CODE_METHODPTR
+@item TYPE_CODE_METHODPTR
+A pointer-to-member-function.
+
+@findex TYPE_CODE_MEMBERPTR
+@findex gdb.TYPE_CODE_MEMBERPTR
+@item TYPE_CODE_MEMBERPTR
+A pointer-to-member.
+
+@findex TYPE_CODE_REF
+@findex gdb.TYPE_CODE_REF
+@item TYPE_CODE_REF
+A reference type.
+
+@findex TYPE_CODE_CHAR
+@findex gdb.TYPE_CODE_CHAR
+@item TYPE_CODE_CHAR
+A character type.
+
+@findex TYPE_CODE_BOOL
+@findex gdb.TYPE_CODE_BOOL
+@item TYPE_CODE_BOOL
+A boolean type.
+
+@findex TYPE_CODE_COMPLEX
+@findex gdb.TYPE_CODE_COMPLEX
+@item TYPE_CODE_COMPLEX
+A complex float type.
+
+@findex TYPE_CODE_TYPEDEF
+@findex gdb.TYPE_CODE_TYPEDEF
+@item TYPE_CODE_TYPEDEF
+A typedef to some other type.
+
+@findex TYPE_CODE_TEMPLATE
+@findex gdb.TYPE_CODE_TEMPLATE
+@item TYPE_CODE_TEMPLATE
+A C++ template type.  Note that this is not used for a template
+instantiation; those appear as ordinary struct types.
+@c FIXME I hope that is true
+
+@findex TYPE_CODE_TEMPLATE_ARG
+@findex gdb.TYPE_CODE_TEMPLATE_ARG
+@item TYPE_CODE_TEMPLATE_ARG
+A C++ template argument.
+@c FIXME: is this ever used?
+
+@findex TYPE_CODE_NAMESPACE
+@findex gdb.TYPE_CODE_NAMESPACE
+@item TYPE_CODE_NAMESPACE
+A C++ namespace.
+
+@findex TYPE_CODE_DECFLOAT
+@findex gdb.TYPE_CODE_DECFLOAT
+@item TYPE_CODE_DECFLOAT
+A decimal floating point type.
+
+@findex TYPE_CODE_INTERNAL_FUNCTION
+@findex gdb.TYPE_CODE_INTERNAL_FUNCTION
+@item TYPE_CODE_INTERNAL_FUNCTION
+A function internal to @var{GDBN}.  This is the type used to represent
+convenience functions.
+@end table
+
 @node Pretty Printing
 @subsubsection Pretty Printing
 
diff --git a/gdb/python/python-type.c b/gdb/python/python-type.c
index e0821d7..f24a023 100644
--- a/gdb/python/python-type.c
+++ b/gdb/python/python-type.c
@@ -50,6 +50,156 @@ typedef struct pyty_type_object
 
 static PyTypeObject type_object_type;
 
+/* This is used to initialize various gdb.TYPE_ constants.  */
+struct pyty_code
+{
+  /* The code.  */
+  enum type_code code;
+  /* The name.  */
+  const char *name;
+};
+
+#define ENTRY(X) { X, #X }
+
+static struct pyty_code pyty_codes[] =
+{
+  ENTRY (TYPE_CODE_PTR),
+  ENTRY (TYPE_CODE_ARRAY),
+  ENTRY (TYPE_CODE_STRUCT),
+  ENTRY (TYPE_CODE_UNION),
+  ENTRY (TYPE_CODE_ENUM),
+  ENTRY (TYPE_CODE_FLAGS),
+  ENTRY (TYPE_CODE_FUNC),
+  ENTRY (TYPE_CODE_INT),
+  ENTRY (TYPE_CODE_FLT),
+  ENTRY (TYPE_CODE_VOID),
+  ENTRY (TYPE_CODE_SET),
+  ENTRY (TYPE_CODE_RANGE),
+  ENTRY (TYPE_CODE_STRING),
+  ENTRY (TYPE_CODE_BITSTRING),
+  ENTRY (TYPE_CODE_ERROR),
+  ENTRY (TYPE_CODE_METHOD),
+  ENTRY (TYPE_CODE_METHODPTR),
+  ENTRY (TYPE_CODE_MEMBERPTR),
+  ENTRY (TYPE_CODE_REF),
+  ENTRY (TYPE_CODE_CHAR),
+  ENTRY (TYPE_CODE_BOOL),
+  ENTRY (TYPE_CODE_COMPLEX),
+  ENTRY (TYPE_CODE_TYPEDEF),
+  ENTRY (TYPE_CODE_TEMPLATE),
+  ENTRY (TYPE_CODE_TEMPLATE_ARG),
+  ENTRY (TYPE_CODE_NAMESPACE),
+  ENTRY (TYPE_CODE_DECFLOAT),
+  ENTRY (TYPE_CODE_INTERNAL_FUNCTION),
+  { TYPE_CODE_UNDEF, NULL }
+};
+
+\f
+
+/* Return the code for this type.  */
+static PyObject *
+typy_code (PyObject *self, PyObject *args)
+{
+  struct type *type = ((type_object *) self)->type;
+  return PyInt_FromLong (TYPE_CODE (type));
+}
+
+/* Helper function for typy_fields which converts a single field to a
+   dictionary.  Returns NULL on error.  */
+static PyObject *
+convert_field (PyObject *self, struct type *type, int field)
+{
+  PyObject *dict = PyDict_New ();
+  PyObject *arg;
+
+  if (!dict)
+    return NULL;
+
+  if (!TYPE_FIELD_STATIC (type, field))
+    {
+      arg = PyLong_FromLong (TYPE_FIELD_BITPOS (type, field));
+      if (!arg)
+	goto fail;
+
+      if (PyDict_SetItemString (dict, "bitpos", arg) < 0)
+	goto failarg;
+    }
+
+  if (TYPE_FIELD_NAME (type, field))
+    {
+      arg = PyString_FromString (TYPE_FIELD_NAME (type, field));
+      if (!arg)
+	goto fail;
+      if (PyDict_SetItemString (dict, "name", arg) < 0)
+	goto failarg;
+    }
+
+  arg = TYPE_FIELD_ARTIFICIAL (type, field) ? Py_True : Py_False;
+  Py_INCREF (arg);
+  if (PyDict_SetItemString (dict, "artificial", arg) < 0)
+    goto failarg;
+
+  arg = PyLong_FromLong (TYPE_FIELD_BITSIZE (type, field));
+  if (!arg)
+    goto fail;
+  if (PyDict_SetItemString (dict, "bitsize", arg) < 0)
+    goto failarg;
+
+  arg = type_to_type_object (self, TYPE_FIELD_TYPE (type, field));
+  if (!arg)
+    goto fail;
+  if (PyDict_SetItemString (dict, "type", arg) < 0)
+    goto failarg;
+
+  return dict;
+
+ failarg:
+  Py_DECREF (arg);
+ fail:
+  Py_DECREF (dict);
+  return NULL;
+}
+
+/* Return a sequence of all fields.  Each field is a dictionary with
+   some pre-defined keys.  */
+static PyObject *
+typy_fields (PyObject *self, PyObject *args)
+{
+  PyObject *result;
+  int i;
+  struct type *type = ((type_object *) self)->type;
+
+  result = PyList_New (0);
+
+  for (i = 0; i < TYPE_NFIELDS (type); ++i)
+    {
+      PyObject *dict = convert_field (self, type, i);
+      if (!dict)
+	{
+	  Py_DECREF (result);
+	  return NULL;
+	}
+      if (PyList_Append (result, dict))
+	{
+	  Py_DECREF (dict);
+	  Py_DECREF (result);
+	  return NULL;
+	}
+    }
+
+  return result;
+}
+
+/* Return the type's tag, or None.  */
+static PyObject *
+typy_tag (PyObject *self, PyObject *args)
+{
+  struct type *type = ((type_object *) self)->type;
+  if (!TYPE_TAG_NAME (type))
+    Py_RETURN_NONE;
+  return PyString_FromString (TYPE_TAG_NAME (type));
+}
+
 /* Return a Type object which represents a pointer to SELF.  */
 static PyObject *
 typy_pointer (PyObject *self, PyObject *args)
@@ -120,7 +270,14 @@ typy_lookup_typename (char *type_name, struct block *block)
   volatile struct gdb_exception except;
   TRY_CATCH (except, RETURN_MASK_ALL)
     {
-      type = lookup_typename (type_name, block, 1);
+      if (!strncmp (type_name, "struct ", 7))
+	type = lookup_struct (type_name + 7, block);
+      else if (!strncmp (type_name, "union ", 6))
+	type = lookup_union (type_name + 6, block);
+      else if (!strncmp (type_name, "enum ", 5))
+	type = lookup_enum (type_name + 5, block);
+      else
+	type = lookup_typename (type_name, block, 0);
     }
   if (except.reason < 0)
     {
@@ -169,13 +326,6 @@ typy_lookup_type (struct demangle_component *demangled,
 
   type_name = cp_comp_to_string (demangled, 10);
   type = typy_lookup_typename (type_name, block);
-  if (! type)
-    {
-      PyErr_Format (PyExc_RuntimeError, "no such type named %s",
-		    type_name);
-      xfree (type_name);
-      return NULL;
-    }
   xfree (type_name);
 
   return type;
@@ -297,6 +447,13 @@ clean_up_objfile_types (struct objfile *objfile, void *datum)
 {
   type_object *obj = datum;
   htab_t copied_types;
+  struct cleanup *cleanup;
+  PyGILState_STATE state;
+
+  /* This prevents another thread from freeing the objects we're
+     operating on.  */
+  state = PyGILState_Ensure ();
+  cleanup = make_cleanup_py_restore_gil (&state);
 
   copied_types = create_copied_types_hash (objfile);
 
@@ -315,6 +472,8 @@ clean_up_objfile_types (struct objfile *objfile, void *datum)
     }
 
   htab_delete (copied_types);
+
+  do_cleanups (cleanup);
 }
 
 static void
@@ -380,11 +539,7 @@ typy_new (PyTypeObject *subtype, PyObject *args, PyObject *kwargs)
     {
       type = typy_lookup_typename (type_name, block);
       if (! type)
-	{
-	  PyErr_Format (PyExc_RuntimeError, "no such type named %s",
-			type_name);
-	  return NULL;
-	}
+	return NULL;


hooks/post-receive
--
Repository for Project Archer.


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

* [SCM]  archer-tromey-python: gdb
@ 2008-11-12  1:54 tromey
  0 siblings, 0 replies; 26+ messages in thread
From: tromey @ 2008-11-12  1:54 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-python has been updated
       via  4d3313b792a9e87b61a11f42b08e7ec29414c15d (commit)
       via  1a936d11fbb67589fbf52540a7121614469da8aa (commit)
       via  fa91a4ceeeced81d5bd9c4708503a2ba7ff4d693 (commit)
      from  97c867eb4023181294200de2f15111dc425ed93b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 4d3313b792a9e87b61a11f42b08e7ec29414c15d
Author: Tom Tromey <tromey@redhat.com>
Date:   Tue Nov 11 18:52:27 2008 -0700

    gdb
    	* varobj.c (varobj_get_display_hint): Use gdbpy_get_display_hint.
    	* python/python.c (apply_pretty_printer): Remove.
    	(gdbpy_get_display_hint): New function.
    	(print_string_repr): New function.
    	(print_children): Likewise.
    	(apply_val_pretty_printer): Rewrite.  Change return type.
    	(_initialize_python) <_format_children>: Remove.
    	(pretty_print_one_value): Remove 'children' argument.
    	(apply_varobj_pretty_printer): Update.
    	* python/python.h (apply_pretty_printer): Remove.
    	(apply_val_pretty_printer): Update.
    	* utils.c (fputs_indented): Remove.
    	* defs.h (fputs_indented): Remove.
    	* valprint.c (value_print): Don't pretty-print.
    	(val_print): Update.
    	* python/python-internal.h (gdbpy_get_display_hint): Declare.
    gdb/testsuite
    	* gdb.python/python-prettyprint.exp (run_lang_tests): Ensure "set
    	print pretty" is on.  Update for recent changes.

commit 1a936d11fbb67589fbf52540a7121614469da8aa
Author: Tom Tromey <tromey@redhat.com>
Date:   Tue Nov 11 18:43:13 2008 -0700

    	* Makefile.in (HFILES_NO_SRCDIR): Add python headers.  Remove
    	obsolete headers.

commit fa91a4ceeeced81d5bd9c4708503a2ba7ff4d693
Author: Tom Tromey <tromey@redhat.com>
Date:   Mon Nov 10 14:26:08 2008 -0700

    	* python/python-objfile.c (gdbpy_initialize_objfile): Don't set
    	tp_new.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog                                   |   29 +++
 gdb/Makefile.in                                 |    7 +-
 gdb/defs.h                                      |    2 -
 gdb/python/python-internal.h                    |    1 +
 gdb/python/python-objfile.c                     |    1 -
 gdb/python/python.c                             |  285 ++++++++++++++--------
 gdb/python/python.h                             |   14 +-
 gdb/testsuite/ChangeLog                         |    5 +
 gdb/testsuite/gdb.python/python-prettyprint.exp |   17 +-
 gdb/utils.c                                     |   31 ---
 gdb/valprint.c                                  |   33 +---
 gdb/varobj.c                                    |   16 +--
 12 files changed, 244 insertions(+), 197 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index ceaa078..d1b0bbd 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,32 @@
+2008-11-11  Tom Tromey  <tromey@redhat.com>
+
+	* varobj.c (varobj_get_display_hint): Use gdbpy_get_display_hint.
+	* python/python.c (apply_pretty_printer): Remove.
+	(gdbpy_get_display_hint): New function.
+	(print_string_repr): New function.
+	(print_children): Likewise.
+	(apply_val_pretty_printer): Rewrite.  Change return type.
+	(_initialize_python) <_format_children>: Remove.
+	(pretty_print_one_value): Remove 'children' argument.
+	(apply_varobj_pretty_printer): Update.
+	* python/python.h (apply_pretty_printer): Remove.
+	(apply_val_pretty_printer): Update.
+	* utils.c (fputs_indented): Remove.
+	* defs.h (fputs_indented): Remove.
+	* valprint.c (value_print): Don't pretty-print.
+	(val_print): Update.
+	* python/python-internal.h (gdbpy_get_display_hint): Declare.
+
+2008-11-11  Tom Tromey  <tromey@redhat.com>
+
+	* Makefile.in (HFILES_NO_SRCDIR): Add python headers.  Remove
+	obsolete headers.
+
+2008-11-10  Tom Tromey  <tromey@redhat.com>
+
+	* python/python-objfile.c (gdbpy_initialize_objfile): Don't set
+	tp_new.
+
 2008-11-10  Tom Tromey  <tromey@redhat.com>
 
 	* python/python-type.c (set_type): Use parent's originator, if it
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index a0716af..9329892 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -700,7 +700,7 @@ osf-share/cma_stack_int.h osf-share/cma_init.h \
 osf-share/cma_deb_core.h osf-share/AT386/cma_thread_io.h \
 osf-share/cma_sched.h proc-utils.h arm-tdep.h ax-gdb.h ppcnbsd-tdep.h \
 cli-out.h gdb_expat.h breakpoint.h infcall.h obsd-tdep.h gnu-v2-abi.h \
-exec.h m32r-tdep.h osabi.h gdb-events.h gdbcore.h solib-som.h \
+exec.h m32r-tdep.h osabi.h gdbcore.h solib-som.h \
 i386bsd-nat.h xml-support.h xml-tdesc.h alphabsd-tdep.h gdb_obstack.h \
 ia64-tdep.h ada-lang.h varobj.h frv-tdep.h nto-tdep.h serial.h \
 c-lang.h frame.h event-loop.h block.h cli/cli-setshow.h	\
@@ -717,7 +717,7 @@ gdbarch.h bsd-uthread.h gdb_thread_db.h gdb_stat.h memory-map.h	\
 mdebugread.h m88k-tdep.h stabsread.h hppa-linux-offsets.h linux-fork.h \
 ser-unix.h scm-lang.h inf-ptrace.h terminal.h ui-out.h frame-base.h \
 f-lang.h dwarf2loc.h value.h sparc-tdep.h defs.h target-descriptions.h \
-objfiles.h vec.h disasm.h mips-tdep.h gstdint.h ser-base.h \
+objfiles.h vec.h disasm.h mips-tdep.h ser-base.h \
 gdb_curses.h bfd-target.h memattr.h inferior.h ax.h dummy-frame.h \
 inflow.h fbsd-nat.h libunwind-frame.h completer.h inf-ttrace.h \
 solib-target.h shnbsd-tdep.h gdb_vfork.h alpha-tdep.h dwarf2expr.h \
@@ -750,7 +750,8 @@ config/sparc/nm-sol2.h config/nm-linux.h config/mips/nm-irix5.h	\
 config/rs6000/nm-rs6000.h top.h bsd-kvm.h gdb-stabs.h reggroups.h \
 annotate.h sim-regno.h dictionary.h dfp.h main.h frame-unwind.h	\
 remote-fileio.h i386-linux-tdep.h vax-tdep.h objc-lang.h \
-sentinel-frame.h bcache.h symfile.h
+sentinel-frame.h bcache.h symfile.h \
+python/python.h python/python-internal.h
 
 # Header files that already have srcdir in them, or which are in objdir.
 
diff --git a/gdb/defs.h b/gdb/defs.h
index 21f1daa..23a6599 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -446,8 +446,6 @@ extern struct ui_file *gdb_stdtargin;
 
 extern void fputs_filtered (const char *, struct ui_file *);
 
-extern void fputs_indented (const char *, struct ui_file *);
-
 extern void fputs_unfiltered (const char *, struct ui_file *);
 
 extern int fputc_filtered (int c, struct ui_file *);
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 71c2297..8f756c8 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -130,6 +130,7 @@ char *apply_varobj_pretty_printer (PyObject *print_obj, struct value *value,
 				   struct value **replacement);
 PyObject *gdbpy_get_varobj_pretty_printer (struct type *type);
 PyObject *gdbpy_instantiate_printer (PyObject *cons, struct value *value);
+char *gdbpy_get_display_hint (PyObject *printer);
 
 extern PyObject *gdbpy_children_cst;
 extern PyObject *gdbpy_to_string_cst;
diff --git a/gdb/python/python-objfile.c b/gdb/python/python-objfile.c
index 0a942c8..335e05b 100644
--- a/gdb/python/python-objfile.c
+++ b/gdb/python/python-objfile.c
@@ -159,7 +159,6 @@ gdbpy_initialize_objfile (void)
   objfpy_objfile_data_key
     = register_objfile_data_with_cleanup (clean_up_objfile);
 
-  objfile_object_type.tp_new = PyType_GenericNew;
   if (PyType_Ready (&objfile_object_type) < 0)
     return;
 
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 9f4448b..206b4aa 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -748,12 +748,9 @@ find_pretty_printer (struct type *type)
    the function returns a string, an xmalloc()d copy is returned.
    Otherwise, if the function returns a value, a *OUT_VALUE is set to
    the value, and NULL is returned.  On error, *OUT_VALUE is set to
-   NULL and NULL is returned.  If CHILDREN is true, we may also try to
-   call an object's "children" method and format the output
-   accordingly.  */
+   NULL and NULL is returned.  */
 static char *
-pretty_print_one_value (PyObject *printer, struct value **out_value,
-			int children)
+pretty_print_one_value (PyObject *printer, struct value **out_value)
 {
   char *output = NULL;
   volatile struct gdb_exception except;
@@ -762,20 +759,7 @@ pretty_print_one_value (PyObject *printer, struct value **out_value,
     {
       PyObject *result;
 
-      /* If CHILDREN is true, call _format_children.  Otherwise, just
-	 try to call the object's to_string method.  */
-      if (children
-	  && PyObject_HasAttrString (gdb_module, "_format_children"))
-	{
-	  PyObject *fmt = PyObject_GetAttrString (gdb_module,
-						  "_format_children");
-	  result = PyObject_CallFunctionObjArgs (fmt, printer, NULL);
-	  Py_DECREF (fmt);
-	}
-      else
-	result = PyObject_CallMethodObjArgs (printer, gdbpy_to_string_cst,
-					     NULL);
-
+      result = PyObject_CallMethodObjArgs (printer, gdbpy_to_string_cst, NULL);
       if (result)
 	{
 	  if (gdbpy_is_string (result))
@@ -821,44 +805,172 @@ gdbpy_instantiate_printer (PyObject *cons, struct value *value)
   return result;
 }
 
-/* Try to pretty-print VALUE.  Return an xmalloc()d string
-   representation of the value.  If the result is NULL, and *OUT_VALUE
-   is set, then *OUT_VALUE is a value which should be printed in place
-   of VALUE.  *OUT_VALUE is not passed back to the pretty-printer.
-   Returns NULL and sets *OUT_VALUE to NULL on error or if no
-   pretty-printer was available.  */
+/* Return the display hint for the object printer, PRINTER.  Return
+   NULL if there is no display_hint method, or if the method did not
+   return a string.  On error, print stack trace and return NULL.  On
+   success, return an xmalloc()d string.  */
 char *
-apply_pretty_printer (struct value *value, struct value **out_value)
+gdbpy_get_display_hint (PyObject *printer)
 {
-  PyObject *func, *printer;
-  char *output = NULL;
+  PyObject *hint;
+  char *result = NULL;
 
-  *out_value = NULL;
-
-  /* Find the constructor.  */
-  func = find_pretty_printer (value_type (value));
-  if (! func)
+  if (! PyObject_HasAttr (printer, gdbpy_display_hint_cst))
     return NULL;
 
-  /* Instantiate it to get a printer object.  */
-  printer = gdbpy_instantiate_printer (func, value);
-  if (printer)
+  hint = PyObject_CallMethodObjArgs (printer, gdbpy_display_hint_cst, NULL);
+  if (gdbpy_is_string (hint))
+    result = python_string_to_host_string (hint);
+  if (hint)
+    Py_DECREF (hint);
+  else
+    gdbpy_print_stack ();
+
+  return result;
+}
+
+/* Helper for apply_val_pretty_printer which calls to_string and
+   formats the result.  */
+static void
+print_string_repr (PyObject *printer, struct ui_file *stream, int format,
+		   int deref_ref, int recurse,
+		   enum val_prettyprint pretty,
+		   const struct language_defn *language)
+{
+  char *output;
+  struct value *replacement = NULL;
+
+  output = pretty_print_one_value (printer, &replacement);
+  if (output)
     {
-      /* If instantiation returns None, then don't try to print.  */
-      if (printer != Py_None)
-	output = pretty_print_one_value (printer, out_value, 1);
-      Py_DECREF (printer);
+      fputs_filtered (output, stream);
+      xfree (output);
     }
-  Py_DECREF (func);
+  else if (replacement)
+    common_val_print (replacement, stream, format, deref_ref,
+		      recurse, pretty, language);
+  else
+    gdbpy_print_stack ();
+}
 
-  return output;
+/* Helper for apply_val_pretty_printer that formats children of the
+   printer, if any exist.  */
+static void
+print_children (PyObject *printer, struct ui_file *stream, int format,
+		int deref_ref, int recurse,
+		enum val_prettyprint pretty,
+		const struct language_defn *language)
+{
+  char *hint;
+  int is_map = 0, i;
+  PyObject *children, *iter;
+  struct cleanup *cleanups;
+
+  if (! PyObject_HasAttr (printer, gdbpy_children_cst))
+    return;
+
+  /* If we are printing a map, we want some special formatting.  */
+  hint = gdbpy_get_display_hint (printer);
+  if (hint)
+    {
+      is_map = ! strcmp (hint, "map");
+      xfree (hint);
+    }
+
+  children = PyObject_CallMethodObjArgs (printer, gdbpy_children_cst,
+					 NULL);
+  if (! children)
+    {
+      gdbpy_print_stack ();
+      return;
+    }
+
+  cleanups = make_cleanup_py_decref (children);
+
+  iter = PyObject_GetIter (children);
+  if (!iter)
+    {
+      gdbpy_print_stack ();
+      goto done;
+    }
+  make_cleanup_py_decref (iter);
+
+  for (i = 0; ; ++i)
+    {
+      PyObject *py_v, *item = PyIter_Next (iter);
+      char *name;
+      struct cleanup *inner_cleanup;
+
+      if (! item)
+	break;
+      inner_cleanup = make_cleanup_py_decref (item);
+
+      if (! PyArg_ParseTuple (item, "sO", &name, &py_v))
+	{
+	  gdbpy_print_stack ();
+	  continue;
+	}
+
+      if (i == 0)
+	fputs_filtered (" = {", stream);
+      else if (! is_map || i % 2 == 0)
+	fputs_filtered (pretty ? "," : ", ", stream);
+
+      if (pretty && (! is_map || i % 2 == 0))
+	{
+	  fputs_filtered ("\n", stream);
+	  print_spaces_filtered (2 + 2 * recurse, stream);
+	}
+
+      if (is_map && i % 2 == 0)
+	fputs_filtered ("[", stream);
+      else if (! is_map)
+	{
+	  fputs_filtered (name, stream);
+	  fputs_filtered (" = ", stream);
+	}
+
+      if (gdbpy_is_string (py_v))
+	{
+	  char *text = python_string_to_host_string (py_v);
+	  if (! text)
+	    gdbpy_print_stack ();
+	  else
+	    {
+	      fputs_filtered (text, stream);
+	      xfree (text);
+	    }
+	}
+      else
+	{
+	  struct value *value = convert_value_from_python (py_v);
+	  common_val_print (value, stream, format, deref_ref,
+			    recurse + 1, pretty, language);
+	}
+
+      if (is_map && i % 2 == 0)
+	fputs_filtered ("] = ", stream);
+      else if (! pretty)
+	wrap_here (n_spaces (2 + 2 * recurse));
+
+      do_cleanups (inner_cleanup);
+    }
+
+  if (i)
+    {
+      if (pretty)
+	{
+	  fputs_filtered ("\n", stream);
+	  print_spaces_filtered (2 * recurse, stream);
+	}
+      fputs_filtered ("}", stream);
+    }
+
+ done:
+  do_cleanups (cleanups);
 }
 
-/* Like apply_pretty_printer, but called from the 'val' (and not
-   'value') printing code.  Arguments are as for val_print.  Returns
-   an xmalloc()d pretty-printed string if a pretty-printer was found
-   and was successful.  */
-char *
+int
 apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
 			  int embedded_offset, CORE_ADDR address,
 			  struct ui_file *stream, int format,
@@ -867,13 +979,15 @@ apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
 			  const struct language_defn *language)
 {
   PyObject *func, *printer;
-  struct value *value, *replacement = NULL;
-  char *output = NULL;
+  struct value *value;
+  char *hint;
+  struct cleanup *cleanups;
+  int result = 0;
 
   /* Find the constructor.  */
   func = find_pretty_printer (type);
   if (! func)
-    return NULL;
+    return 0;
 
   /* Instantiate the printer.  */
   value = value_from_contents_and_address (type, valaddr, embedded_offset,
@@ -882,25 +996,24 @@ apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
   Py_DECREF (func);
 
   if (!printer)
-    return NULL;
+    {
+      gdbpy_print_stack ();
+      return 0;
+    }
 
+  cleanups = make_cleanup_py_decref (printer);
   if (printer != Py_None)
-    output = pretty_print_one_value (printer, &replacement, 1);
-  Py_DECREF (printer);
-  if (output)
-    return output;
-
-  if (! replacement)
-    return NULL;
+    {
+      print_string_repr (printer, stream, format, deref_ref,
+			 recurse, pretty, language);
+      print_children (printer, stream, format, deref_ref,
+		      recurse, pretty, language);
 
-  language->la_val_print (value_type (replacement),
-			  value_contents_all (replacement),
-			  value_embedded_offset (replacement),
-			  value_address (replacement),
-			  stream, format, deref_ref, recurse,
-			  pretty);
+      result = 1;
+    }
 
-  return xstrdup ("");
+  do_cleanups (cleanups);
+  return result;
 }
 
 /* Apply a pretty-printer for the varobj code.  PRINTER_OBJ is the
@@ -916,7 +1029,7 @@ apply_varobj_pretty_printer (PyObject *printer_obj, struct value *value,
 			     struct value **replacement)
 {
   *replacement = NULL;
-  return pretty_print_one_value (printer_obj, replacement, 0);
+  return pretty_print_one_value (printer_obj, replacement);
 }
 
 /* Find a pretty-printer object for the varobj module.  Returns a new
@@ -995,14 +1108,7 @@ eval_python_from_control_command (struct command_line *cmd)
   error (_("Python scripting is not supported in this copy of GDB."));
 }
 
-char *
-apply_pretty_printer (struct value *ignore, struct value **out)
-{
-  *out = NULL;
-  return NULL;
-}
-
-char *
+int
 apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
 			  int embedded_offset, CORE_ADDR address,
 			  struct ui_ifle *stream, int format,
@@ -1010,7 +1116,7 @@ apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
 			  enum val_prettyprint pretty,
 			  const language_defn *language)
 {
-  return NULL;
+  return 0;
 }
 
 void
@@ -1155,35 +1261,6 @@ sys.stderr = GdbOutputFile()\n\
 sys.stdout = GdbOutputFile()\n\
 ");
 
-  PyRun_SimpleString ("\
-def _format_children(obj):\n\
-  result = []\n\
-  if hasattr(obj, 'to_string'):\n\
-    result.append(str(obj.to_string()))\n\
-  if hasattr(obj, 'display_hint'):\n\
-    is_map = 'map' == obj.display_hint()\n\
-  else:\n\
-    is_map = False\n\
-  max = gdb.get_parameter('print elements')\n\
-  i = 0\n\
-  previous = None\n\
-  if hasattr(obj, 'children'):\n\
-    for elt in obj.children():\n\
-      (name, val) = elt\n\
-      if is_map:\n\
-	if i % 2 == 0:\n\
-	  previous = val\n\
-	else:\n\
-	  result.append('[%s] = %s' % (str (previous), str (val)))\n\
-      else:\n\
-	result.append('%s = %s' % (name, str(val)))\n\
-      i = i + 1\n\
-      if max != None and i == max:\n\
-	break\n\
-  return '\\n'.join(result)\n\
-\n\
-gdb._format_children = _format_children\n\
-");
 #endif /* HAVE_PYTHON */
 }
 
diff --git a/gdb/python/python.h b/gdb/python/python.h
index ef0560c..a2aec3f 100644
--- a/gdb/python/python.h
+++ b/gdb/python/python.h
@@ -30,13 +30,11 @@ void source_python_script (FILE *stream, char *file);
 
 void run_python_script (int argc, char **argv);
 
-char *apply_pretty_printer (struct value *, struct value **);
-
-char *apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
-				int embedded_offset, CORE_ADDR address,
-				struct ui_file *stream, int format,
-				int deref_ref, int recurse,
-				enum val_prettyprint pretty,
-				const struct language_defn *language);
+int apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
+			      int embedded_offset, CORE_ADDR address,
+			      struct ui_file *stream, int format,
+			      int deref_ref, int recurse,
+			      enum val_prettyprint pretty,
+			      const struct language_defn *language);
 


hooks/post-receive
--
Repository for Project Archer.


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

* [SCM]  archer-tromey-python: gdb
@ 2008-11-10 14:15 tromey
  0 siblings, 0 replies; 26+ messages in thread
From: tromey @ 2008-11-10 14:15 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-python has been updated
       via  259f4ed6acc1cc400d4deb3ab755ac3f5ed95dc3 (commit)
      from  18e9a3e91b4b4529404512c6ed87d7158d1cbbed (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 259f4ed6acc1cc400d4deb3ab755ac3f5ed95dc3
Author: Tom Tromey <tromey@redhat.com>
Date:   Mon Nov 10 07:15:00 2008 -0700

    gdb
    	PR gdb/1815:
    	* cli/cli-decode.c (delete_cmd): Forward declare.
    	(delete_cmd): Now static.  Change return type.  Remove command
    	from alias chain.
    	(add_cmd): Initialize new fields.  Update cmd_pointer on all
    	aliases.
    	(add_alias_cmd): Put command on alias chain.
    	* command.h (delete_cmd): Don't declare.
    	* cli/cli-decode.h (delete_cmd): Don't declare.
    	(struct cmd_list_element) <aliases, alias_chain>: New fields.
    gdb/testsuite
    	* gdb.base/commands.exp (redefine_backtrace_test): New proc.
    	Call it.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog                       |   13 ++++++++++
 gdb/cli/cli-decode.c                |   43 ++++++++++++++++++++++++++++++-----
 gdb/cli/cli-decode.h                |    9 +++++-
 gdb/command.h                       |    2 -
 gdb/testsuite/ChangeLog             |    5 ++++
 gdb/testsuite/gdb.base/commands.exp |   30 ++++++++++++++++++++++++
 6 files changed, 92 insertions(+), 10 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 487e321..2e74818 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,16 @@
+2008-11-10  Tom Tromey  <tromey@redhat.com>
+
+	PR gdb/1815:
+	* cli/cli-decode.c (delete_cmd): Forward declare.
+	(delete_cmd): Now static.  Change return type.  Remove command
+	from alias chain.
+	(add_cmd): Initialize new fields.  Update cmd_pointer on all
+	aliases.
+	(add_alias_cmd): Put command on alias chain.
+	* command.h (delete_cmd): Don't declare.
+	* cli/cli-decode.h (delete_cmd): Don't declare.
+	(struct cmd_list_element) <aliases, alias_chain>: New fields.
+
 2008-11-07  Paul Pluzhnikov  <ppluzhnikov@google.com>
 
 	* python/python-type.c (typy_lookup_type): Fix "dangling" access.
diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index b897124..56964e4 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -37,6 +37,9 @@
 
 static void undef_cmd_error (char *, char *);
 
+static struct cmd_list_element *delete_cmd (char *name,
+					    struct cmd_list_element **list);
+
 static struct cmd_list_element *find_cmd (char *command,
 					  int len,
 					  struct cmd_list_element *clist,
@@ -155,9 +158,13 @@ add_cmd (char *name, enum command_class class, void (*fun) (char *, int),
 {
   struct cmd_list_element *c
   = (struct cmd_list_element *) xmalloc (sizeof (struct cmd_list_element));
-  struct cmd_list_element *p;
+  struct cmd_list_element *p, *iter;
 
-  delete_cmd (name, list);
+  /* Turn each alias of the old command into an alias of the new
+     command.  */
+  c->aliases = delete_cmd (name, list);
+  for (iter = c->aliases; iter; iter = iter->alias_chain)
+    iter->cmd_pointer = c;
 
   if (*list == NULL || strcmp ((*list)->name, name) >= 0)
     {
@@ -200,6 +207,7 @@ add_cmd (char *name, enum command_class class, void (*fun) (char *, int),
   c->hookee_pre = NULL;
   c->hookee_post = NULL;
   c->cmd_pointer = NULL;
+  c->alias_chain = NULL;
 
   return c;
 }
@@ -254,6 +262,8 @@ add_alias_cmd (char *name, char *oldname, enum command_class class,
   c->allow_unknown = old->allow_unknown;
   c->abbrev_flag = abbrev_flag;
   c->cmd_pointer = old;
+  c->alias_chain = old->aliases;
+  old->aliases = c;
   return c;
 }
 
@@ -618,11 +628,12 @@ add_setshow_zinteger_cmd (char *name, enum command_class class,
 
 /* Remove the command named NAME from the command list.  */
 
-void
+static struct cmd_list_element *
 delete_cmd (char *name, struct cmd_list_element **list)
 {
   struct cmd_list_element *iter;
   struct cmd_list_element **previous_chain_ptr;
+  struct cmd_list_element *aliases = NULL;
 
   previous_chain_ptr = list;
 
@@ -637,16 +648,36 @@ delete_cmd (char *name, struct cmd_list_element **list)
 	  if (iter->hookee_post)
 	    iter->hookee_post->hook_post = 0;
 
-	  /* Update the link.  Note that we don't change
-	     previous_chain_ptr; next time through the loop this must
-	     stay the same.  */
+	  /* Update the link.  */
 	  *previous_chain_ptr = iter->next;
 
+	  aliases = iter->aliases;
+
+	  /* If this command was an alias, remove it from the list of
+	     aliases.  */
+	  if (iter->cmd_pointer)
+	    {
+	      struct cmd_list_element **prevp = &iter->cmd_pointer->aliases;
+	      struct cmd_list_element *a = *prevp;
+
+	      while (a != iter)
+		{
+		  prevp = &a->alias_chain;
+		  a = *prevp;
+		}
+	      *prevp = iter->alias_chain;
+	    }
+
 	  xfree (iter);
+
+	  /* We won't see another command with the same name.  */
+	  break;
 	}
       else
 	previous_chain_ptr = &iter->next;
     }
+
+  return aliases;
 }
 \f
 /* Shorthands to the commands above. */
diff --git a/gdb/cli/cli-decode.h b/gdb/cli/cli-decode.h
index 2888398..c9da41c 100644
--- a/gdb/cli/cli-decode.h
+++ b/gdb/cli/cli-decode.h
@@ -202,6 +202,13 @@ struct cmd_list_element
     /* Pointer to command that is aliased by this one, so the
        aliased command can be located in case it has been hooked.  */
     struct cmd_list_element *cmd_pointer;
+
+    /* Start of a linked list of all aliases of this command.  */
+    struct cmd_list_element *aliases;
+
+    /* Link pointer for aliases on an alias list.  */
+    struct cmd_list_element *alias_chain;
+
   };
 
 /* API to the manipulation of command lists.  */
@@ -296,8 +303,6 @@ extern char **complete_on_cmdlist (struct cmd_list_element *, char *, char *);
 
 extern char **complete_on_enum (const char *enumlist[], char *, char *);
 
-extern void delete_cmd (char *, struct cmd_list_element **);
-
 extern void help_cmd_list (struct cmd_list_element *, enum command_class,
 			   char *, int, struct ui_file *);
 
diff --git a/gdb/command.h b/gdb/command.h
index a82ce3a..add3a52 100644
--- a/gdb/command.h
+++ b/gdb/command.h
@@ -194,8 +194,6 @@ extern char **complete_on_cmdlist (struct cmd_list_element *, char *, char *);
 
 extern char **complete_on_enum (const char *enumlist[], char *, char *);
 
-extern void delete_cmd (char *, struct cmd_list_element **);
-
 extern void help_cmd (char *, struct ui_file *);
 
 extern void help_list (struct cmd_list_element *, char *,
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 4678c3d..2ee4513 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2008-11-10  Tom Tromey  <tromey@redhat.com>
+
+	* gdb.base/commands.exp (redefine_backtrace_test): New proc.
+	Call it.
+
 2008-11-07  Paul Pluzhnikov  <ppluzhnikov@google.com>
 
 	* gdb.python/python-template.exp: Make failures clearer.
diff --git a/gdb/testsuite/gdb.base/commands.exp b/gdb/testsuite/gdb.base/commands.exp
index 301b995..41d5bec 100644
--- a/gdb/testsuite/gdb.base/commands.exp
+++ b/gdb/testsuite/gdb.base/commands.exp
@@ -692,6 +692,34 @@ proc if_commands_test {} {
     }
 }
 
+proc redefine_backtrace_test {} {
+    global gdb_prompt
+
+    send_gdb "define backtrace\n"
+    gdb_expect {
+	-re "Really redefine built-in.*$" {
+	    send_gdb "y\n"
+	}
+
+	-re "End with"  {
+	    pass "define backtrace in redefine_backtrace_test"
+	}
+        default {
+	    fail "(timeout or eof) define backtrace in redefine_backtrace_test"
+	}
+    }
+    gdb_test "echo hibob\\n\nend" \
+	    "" \
+	    "enter commands in redefine_backtrace_test"
+
+    gdb_test "backtrace" \
+	    "hibob" \
+	    "execute backtrace command in redefine_backtrace_test"
+    gdb_test "bt" \
+	    "hibob" \
+	    "execute bt command in redefine_backtrace_test"
+}
+
 gdbvar_simple_if_test
 gdbvar_simple_while_test
 gdbvar_complex_if_while_test
@@ -710,3 +738,5 @@ temporary_breakpoint_commands
 stray_arg0_test
 recursive_source_test
 if_commands_test
+# This one should come last, as it redefines "backtrace".
+redefine_backtrace_test


hooks/post-receive
--
Repository for Project Archer.


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

* [SCM]  archer-tromey-python: gdb
@ 2008-11-06 19:58 tromey
  0 siblings, 0 replies; 26+ messages in thread
From: tromey @ 2008-11-06 19:58 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-python has been updated
       via  95bc4ef80d85b793a2cc50d39db64f2e7abd8551 (commit)
      from  e066d5afc0238f478df70c2b2f0c52d58959eb4d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 95bc4ef80d85b793a2cc50d39db64f2e7abd8551
Author: Tom Tromey <tromey@redhat.com>
Date:   Thu Nov 6 12:57:17 2008 -0700

    gdb
    	* varobj.c (struct varobj) <constructor>: New field.
    	(varobj_set_display_format): Update.
    	(varobj_get_display_hint): Likewise.
    	(varobj_get_num_children): Likewise.
    	(varobj_list_children): Likewise.
    	(install_new_value): Destroy old pretty-printer.
    	(install_visualizer): Update.  Recompute children when visualizer
    	is removed.
    	(install_default_visualizer): Don't instantiate printer.  Add
    	'type' argument.
    	(new_variable): Initialize new field.
    	(free_variable): Destroy new field.
    	(instantiate_pretty_printer): New function.
    	(varobj_set_visualizer): Don't instantiate printer.
    	* python/python-internal.h (objfpy_get_mi_printers,
    	objfpy_get_cli_printers): Remove.
    	(objfpy_get_printers): Declare.
    	(gdbpy_instantiate_printer): Declare.
    	* python/python.c (find_pretty_printer): Remove is_mi and dictp
    	arguments.
    	(_initialize_python): Initialize pretty_printers, not
    	cli_pretty_printers and mi_pretty_printers.
    	<_format_children>: Update.  Conditionally call 'children'.
    	(apply_pretty_printer): Update.  Instantiate printer.
    	(apply_val_pretty_printer): Update.  Instantiate printer.
    	(pretty_print_one_value): Rename func argument to printer.  Remove
    	value argument.  Update.
    	(gdbpy_instantiate_printer): New function.
    	(apply_varobj_pretty_printer): Update.
    	(gdbpy_get_varobj_pretty_printer): Update.
    	* python/python-objfile.c (objfile_object): Remove mi_printers,
    	cli_printers; add printers.
    	(objfpy_dealloc): Update.
    	(objfpy_new): Update.
    	(objfpy_get_printers): Rename from objfpy_get_mi_printers.
    	Update.
    	(objfpy_set_printers): Rename from objfpy_set_mi_printers.
    	Update.
    	(objfpy_get_cli_printers): Remove.
    	(objfpy_set_cli_printers): Remove.
    	(objfile_to_objfile_object): Update.
    	(objfile_getset): Update.
    gdb/doc
    	* gdb.texinfo (Pretty Printing): Update.
    	(GDB/MI Variable Objects): Likewise.
    gdb/testsuite
    	* gdb.python/python-mi.exp: Update.
    	* gdb.python/python-prettyprint.py: Move to purely class-based
    	printers.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog                                  |   45 +++++
 gdb/doc/ChangeLog                              |    5 +
 gdb/doc/gdb.texinfo                            |   92 ++++------
 gdb/python/python-internal.h                   |    4 +-
 gdb/python/python-objfile.c                    |   88 ++--------
 gdb/python/python.c                            |  221 +++++++++++++-----------
 gdb/testsuite/ChangeLog                        |    6 +
 gdb/testsuite/gdb.python/python-mi.exp         |    4 +-
 gdb/testsuite/gdb.python/python-prettyprint.py |   76 +++++----
 gdb/varobj.c                                   |  150 +++++++++-------
 10 files changed, 360 insertions(+), 331 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 5533820..9333dcf 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,48 @@
+2008-11-06  Tom Tromey  <tromey@redhat.com>
+
+	* varobj.c (struct varobj) <constructor>: New field.
+	(varobj_set_display_format): Update.
+	(varobj_get_display_hint): Likewise.
+	(varobj_get_num_children): Likewise.
+	(varobj_list_children): Likewise.
+	(install_new_value): Destroy old pretty-printer.
+	(install_visualizer): Update.  Recompute children when visualizer
+	is removed.
+	(install_default_visualizer): Don't instantiate printer.  Add
+	'type' argument.
+	(new_variable): Initialize new field.
+	(free_variable): Destroy new field.
+	(instantiate_pretty_printer): New function.
+	(varobj_set_visualizer): Don't instantiate printer.
+	* python/python-internal.h (objfpy_get_mi_printers,
+	objfpy_get_cli_printers): Remove.
+	(objfpy_get_printers): Declare.
+	(gdbpy_instantiate_printer): Declare.
+	* python/python.c (find_pretty_printer): Remove is_mi and dictp
+	arguments.
+	(_initialize_python): Initialize pretty_printers, not
+	cli_pretty_printers and mi_pretty_printers.
+	<_format_children>: Update.  Conditionally call 'children'.
+	(apply_pretty_printer): Update.  Instantiate printer.
+	(apply_val_pretty_printer): Update.  Instantiate printer.
+	(pretty_print_one_value): Rename func argument to printer.  Remove
+	value argument.  Update.
+	(gdbpy_instantiate_printer): New function.
+	(apply_varobj_pretty_printer): Update.
+	(gdbpy_get_varobj_pretty_printer): Update.
+	* python/python-objfile.c (objfile_object): Remove mi_printers,
+	cli_printers; add printers.
+	(objfpy_dealloc): Update.
+	(objfpy_new): Update.
+	(objfpy_get_printers): Rename from objfpy_get_mi_printers.
+	Update.
+	(objfpy_set_printers): Rename from objfpy_set_mi_printers.
+	Update.
+	(objfpy_get_cli_printers): Remove.
+	(objfpy_set_cli_printers): Remove.
+	(objfile_to_objfile_object): Update.
+	(objfile_getset): Update.
+
 2008-11-03  Paul Pluzhnikov  <ppluzhnikov@google.com>
 
 	* python/python.c (find_pretty_printer): Fix gcc-4.3.1 warnings.
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 26c9ed2..9d45150 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,8 @@
+2008-11-06  Tom Tromey  <tromey@redhat.com>
+
+	* gdb.texinfo (Pretty Printing): Update.
+	(GDB/MI Variable Objects): Likewise.
+
 2008-10-27  Tom Tromey  <tromey@redhat.com>
 
 	* gdb.texinfo (Pretty Printing): Reword list of predefined display
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 787a438..071c912 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -17951,24 +17951,31 @@ using Python code.  This mechanism works for both MI and the CLI.
 A pretty-printer is an object that implements a specific interface.
 There is no predefined base class for pretty-printers.
 
-@defop Operation {pretty printer} children (self, val)
-This method is used by both the MI and CLI code.  When printing a
-value, @value{GDBN} will call this method to display the children of
-@var{val}, an instance of @code{gdb.Value}.
+@defop Operation {pretty printer} __init__ (self, val)
+When printing a value, @value{GDBN} constructs an instance of the
+pretty-printer.  @var{val} is the value to be printed, an instance of
+@code{gdb.Value}.
+@end defop
+
+@defop Operation {pretty printer} children (self)
+When printing a value, @value{GDBN} will call this method to compute
+the children of the value passed to the object's constructor.
 
 This method must return an object conforming to the Python iterator
 protocol.  Each element returned by the iterator must be a tuple
 holding two elements.  The first element is the ``name'' of the child;
 the second element is the child's value.  The value can be any Python
 object which is convertible to a @value{GDBN} value.
-@end defop
 
-@defop Operation {pretty printer} display_hint (self, val)
-This method is only used by the MI printer.
+This method is optional.  If it does not exist, @value{GDBN} will act
+as though the value has no children.
+@end defop
 
-This method must return a string.  It will be supplied to the MI
-consumer as a @samp{displayhint} attribute of the variable being
-printed.
+@defop Operation {pretty printer} display_hint (self)
+This method must return a string.  The CLI may use this to change the
+formatting of children of a value.  The result will also be supplied
+to an MI consumer as a @samp{displayhint} attribute of the variable
+being printed.
 
 Some display hints are predefined by @value{GDBN}:
 
@@ -17980,10 +17987,9 @@ alternate between keys and values.
 @end table
 @end defop
 
-@defop Operation {pretty printer} to_string (self, val)
-This method is used by both the MI and CLI code.  When printing a
-value, @value{GDBN} will call this method to display the string
-representation of @var{val}, an instance of @code{gdb.Value}.
+@defop Operation {pretty printer} to_string (self)
+@value{GDBN} will call this method to display the string
+representation of the value passed to the object's constructor.
 
 When printing from the CLI, if the @code{to_string} method exists,
 then @value{GDBN} will prepend its result to the values returned by
@@ -17992,13 +17998,15 @@ then @value{GDBN} will prepend its result to the values returned by
 This method must return a string.
 @end defop
 
-@subsubsection Selecting CLI Pretty-Printers
+@subsubsection Selecting Pretty-Printers
 
-The Python dictionary @code{gdb.cli_pretty_printers} maps regular
-expressions (strings) onto pretty-printers.  A pretty-printer is
-either a function or an object.
+The Python dictionary @code{gdb.pretty_printers} maps regular
+expressions (strings) onto constructors.  A constructor, in this
+context, is a function which takes a single @code{gdb.Value} argument
+and returns a a pretty-printer conforming to the interface definition
+above.
 
-When printing a value, @value{GDBN} first computes the values'
+When printing a value, @value{GDBN} first computes the value's
 canonical type by following typedefs, following a reference type to
 its referenced type, and removing qualifiers, such as @code{const} or
 @code{volatile}.  The name of this type is then compared to each
@@ -18006,46 +18014,23 @@ regular expression.  If a regular expression matches, then the
 corresponding pretty-printer is invoked with a @code{gdb.Value}
 representing the value to be printed.
 
-If the pretty-printer is a function, the function is called directly.
-
-If the pretty-printer is an object, the object's methods are called as
-described above.
-
-If the pretty-printer returns a string, it is printed.  If it returns any
-Python value that is convertible to a @code{gdb.Value}, then that
-value is passed to the regular @value{GDBN} type-printing code.
-
 The order in which the regular expressions are tried is not specified.
 
-Here is an example showing how a @code{std::string} might be printed:
-
-@smallexample
-def printstdstring(val):
-    return val['_M_dataplus']['_M_p']
-
-gdb.cli_pretty_printers['^std::basic_string<char.*>$'] = printstdstring
-@end smallexample
-
-Here is an example of the same printer, using a class:
+Here is an example showing how a @code{std::string} printer might be
+written:
 
 @smallexample
 class StdStringPrinter:
-    def to_string(self, val):
-        return val['_M_dataplus']['_M_p']
-
-gdb.cli_pretty_printers['^std::basic_string<char.*>$'] = StdStringPrinter()
-@end smallexample
+    "Print a std::string"
 
-@subsubsection Selecting MI Pretty-Printers
+    def __init__(self, val):
+        self.val = val
 
-MI pretty-printers are selected using a dictionary named
-@code{gdb.mi_pretty_printers}.  A key in this dictionary should be a
-regular expression in string form.  A value in this dictionary should
-be a constructor which takes no arguments and which returns a new
-object of the form described above.
+    def to_string(self):
+        return self.val['_M_dataplus']['_M_p']
 
-@value{GDBN} will consult @code{gdb.mi_pretty_printers} whenever a new
-MI variable object is created.
+gdb.pretty_printers['^std::basic_string<char.*>$'] = StdStringPrinter
+@end smallexample
 
 @node Threads In Python
 @subsubsection Threads In Python
@@ -21821,9 +21806,8 @@ The pre-defined function @code{gdb.get_default_visualizer} may be used
 to select a visualizer according to the type of the varobj.  This is
 called when a varobj is created, and so ordinarily is not needed.
 
-@code{gdb.get_default_visualizer} looks in a global dictionary named
-@code{gdb.mi_pretty_printers}.  This works analogously to
-@code{gdb.cli_pretty_printers}.
+@code{gdb.get_default_visualizer} looks in the global dictionary named
+@code{gdb.pretty_printers}.
 
 This feature is only available if Python support is enabled.
 
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 6dff805..672a2fe 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -75,8 +75,7 @@ PyObject *gdb_owned_value_to_value_object (struct value *v);
 PyObject *type_to_type_object (struct type *);
 PyObject *objfile_to_objfile_object (struct objfile *);
 
-PyObject *objfpy_get_mi_printers (PyObject *, void *);
-PyObject *objfpy_get_cli_printers (PyObject *, void *);
+PyObject *objfpy_get_printers (PyObject *, void *);
 
 struct block *block_object_to_block (PyObject *obj);
 struct symbol *symbol_object_to_symbol (PyObject *obj);
@@ -130,6 +129,7 @@ int gdbpy_is_string (PyObject *obj);
 char *apply_varobj_pretty_printer (PyObject *print_obj, struct value *value,
 				   struct value **replacement);
 PyObject *gdbpy_get_varobj_pretty_printer (struct type *type);
+PyObject *gdbpy_instantiate_printer (PyObject *cons, struct value *value);
 
 extern PyObject *gdbpy_children_cst;
 extern PyObject *gdbpy_to_string_cst;
diff --git a/gdb/python/python-objfile.c b/gdb/python/python-objfile.c
index 6b5a7c3..0a942c8 100644
--- a/gdb/python/python-objfile.c
+++ b/gdb/python/python-objfile.c
@@ -29,9 +29,8 @@ typedef struct
   /* The corresponding objfile.  */
   struct objfile *objfile;
 
-  /* The pretty-printer dictionaries.  */
-  PyObject *mi_printers;
-  PyObject *cli_printers;
+  /* The pretty-printer dictionary.  */
+  PyObject *printers;
 } objfile_object;
 
 static PyTypeObject objfile_object_type;
@@ -55,8 +54,7 @@ static void
 objfpy_dealloc (PyObject *o)
 {
   objfile_object *self = (objfile_object *) o;
-  Py_XDECREF (self->mi_printers);
-  Py_XDECREF (self->cli_printers);
+  Py_XDECREF (self->printers);
   self->ob_type->tp_free ((PyObject *) self);
 }
 
@@ -67,17 +65,9 @@ objfpy_new (PyTypeObject *type, PyObject *args, PyObject *keywords)
   if (self)
     {
       self->objfile = NULL;
-      /* Initialize in case of early return.  */
-      self->cli_printers = NULL;
 
-      self->mi_printers = PyDict_New ();
-      if (!self->mi_printers)
-	{
-	  Py_DECREF (self);
-	  return NULL;
-	}
-      self->cli_printers = PyDict_New ();
-      if (!self->cli_printers)
+      self->printers = PyDict_New ();
+      if (!self->printers)
 	{
 	  Py_DECREF (self);
 	  return NULL;
@@ -87,67 +77,34 @@ objfpy_new (PyTypeObject *type, PyObject *args, PyObject *keywords)
 }
 
 PyObject *
-objfpy_get_mi_printers (PyObject *o, void *ignore)
-{
-  objfile_object *self = (objfile_object *) o;
-  Py_INCREF (self->mi_printers);
-  return self->mi_printers;
-}
-
-static int
-objfpy_set_mi_printers (PyObject *o, PyObject *value, void *ignore)
-{
-  objfile_object *self = (objfile_object *) o;
-  if (! value)
-    {
-      PyErr_SetString (PyExc_TypeError,
-		       "cannot delete the mi_pretty_printers attribute");
-      return -1;
-    }
-
-  if (! PyDict_Check (value))
-    {
-      PyErr_SetString (PyExc_TypeError,
-		       "the mi_pretty_printers attribute must be a dictionary");
-      return -1;
-    }
-
-  Py_XDECREF (self->mi_printers);
-  Py_INCREF (value);
-  self->mi_printers = value;
-
-  return 0;
-}
-
-PyObject *
-objfpy_get_cli_printers (PyObject *o, void *ignore)
+objfpy_get_printers (PyObject *o, void *ignore)
 {
   objfile_object *self = (objfile_object *) o;
-  Py_INCREF (self->cli_printers);
-  return self->cli_printers;
+  Py_INCREF (self->printers);
+  return self->printers;
 }
 
 static int
-objfpy_set_cli_printers (PyObject *o, PyObject *value, void *ignore)
+objfpy_set_printers (PyObject *o, PyObject *value, void *ignore)
 {
   objfile_object *self = (objfile_object *) o;
   if (! value)
     {
       PyErr_SetString (PyExc_TypeError,
-		       "cannot delete the cli_pretty_printers attribute");
+		       "cannot delete the pretty_printers attribute");
       return -1;
     }
 
   if (! PyDict_Check (value))
     {
       PyErr_SetString (PyExc_TypeError,
-		       "the cli_pretty_printers attribute must be a dictionary");
+		       "the pretty_printers attribute must be a dictionary");
       return -1;
     }
 
-  Py_XDECREF (self->cli_printers);
+  Py_XDECREF (self->printers);
   Py_INCREF (value);
-  self->cli_printers = value;
+  self->printers = value;
 
   return 0;
 }
@@ -181,18 +138,9 @@ objfile_to_objfile_object (struct objfile *objfile)
 	  PyObject *dict;
 
 	  object->objfile = objfile;
-	  /* Initialize in case of early return.  */
-	  object->cli_printers = NULL;
-
-	  object->mi_printers = PyDict_New ();
-	  if (!object->mi_printers)
-	    {
-	      Py_DECREF (object);
-	      return NULL;
-	    }
 
-	  object->cli_printers = PyDict_New ();
-	  if (!object->cli_printers)
+	  object->printers = PyDict_New ();
+	  if (!object->printers)
 	    {
 	      Py_DECREF (object);
 	      return NULL;
@@ -223,10 +171,8 @@ gdbpy_initialize_objfile (void)
 
 static PyGetSetDef objfile_getset[] =
 {
-  { "mi_pretty_printers", objfpy_get_mi_printers, objfpy_set_mi_printers,
-    "MI pretty printers", NULL },
-  { "cli_pretty_printers", objfpy_get_cli_printers, objfpy_set_cli_printers,
-    "CLI pretty printers", NULL },
+  { "pretty_printers", objfpy_get_printers, objfpy_set_printers,
+    "Pretty printers", NULL },
   { NULL }
 };
 
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 5f6a269..d6cea7e 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -676,17 +676,14 @@ search_pp_dictionary (PyObject *dict, char *type_name)
   return found;
 }
 
-/* Find the pretty-printing function for TYPE.  If no pretty-printer
-   exists, return NULL.  If one exists, return a borrowed reference.
-   If a printer is found, *DICTP is set to a reference to the
-   dictionary object; it must be derefed by the caller.  DICT_NAME is
-   the name of the dictionary to search for types.  */
+/* Find the pretty-printing constructor function for TYPE.  If no
+   pretty-printer exists, return NULL.  If one exists, return a new
+   reference.  */
 static PyObject *
-find_pretty_printer (struct type *type, PyObject **dictp, int is_mi)
+find_pretty_printer (struct type *type)
 {
   PyObject *dict, *found = NULL;
   char *type_name = NULL;
-  char *dict_name;
   struct objfile *obj;
   volatile struct gdb_exception except;
 
@@ -710,11 +707,7 @@ find_pretty_printer (struct type *type, PyObject **dictp, int is_mi)
     if (!objf)
       continue;
 
-    if (is_mi)
-      dict = objfpy_get_mi_printers (objf, NULL);
-    else
-      dict = objfpy_get_cli_printers (objf, NULL);
-
+    dict = objfpy_get_printers (objf, NULL);
     found = search_pp_dictionary (dict, type_name);
     if (found)
       goto done;
@@ -723,11 +716,10 @@ find_pretty_printer (struct type *type, PyObject **dictp, int is_mi)
   }
 
   /* Fetch the global pretty printer dictionary.  */
-  dict_name = is_mi ? "mi_pretty_printers" : "cli_pretty_printers";
   dict = NULL;
-  if (! PyObject_HasAttrString (gdb_module, dict_name))
+  if (! PyObject_HasAttrString (gdb_module, "pretty_printers"))
     goto done;
-  dict = PyObject_GetAttrString (gdb_module, dict_name);
+  dict = PyObject_GetAttrString (gdb_module, "pretty_printers");
   if (! dict)
     goto done;
   if (! PyDict_Check (dict) || ! PyDict_Size (dict))
@@ -739,57 +731,44 @@ find_pretty_printer (struct type *type, PyObject **dictp, int is_mi)
   xfree (type_name);
 
   if (found)
-    *dictp = dict;
-  else
-    Py_XDECREF (dict);
+    Py_INCREF (found);
+  Py_XDECREF (dict);
 
   return found;
 }
 
-/* Pretty-print a single value, VALUE, using the printer function
-   FUNC.  If the function returns a string, an xmalloc()d copy is
-   returned.  Otherwise, if the function returns a value, a *OUT_VALUE
-   is set to the value, and NULL is returned.  On error, *OUT_VALUE is
-   set to NULL and NULL is returned.  If CHILDREN is true, we may also
-   try to call an object's "children" method and format the output
+/* Pretty-print a single value, via the printer object PRINTER.  If
+   the function returns a string, an xmalloc()d copy is returned.
+   Otherwise, if the function returns a value, a *OUT_VALUE is set to
+   the value, and NULL is returned.  On error, *OUT_VALUE is set to
+   NULL and NULL is returned.  If CHILDREN is true, we may also try to
+   call an object's "children" method and format the output
    accordingly.  */
 static char *
-pretty_print_one_value (PyObject *func, struct value *value,
-			struct value **out_value, int children)
+pretty_print_one_value (PyObject *printer, struct value **out_value,
+			int children)
 {
   char *output = NULL;
   volatile struct gdb_exception except;
 
   TRY_CATCH (except, RETURN_MASK_ALL)
     {
-      PyObject *val_obj, *result;
-
-      /* FIXME: memory management here.  Why are values so
-	 funny?  */
-      value = value_copy (value);
-
-      val_obj = value_to_value_object (value);
+      PyObject *result;
 
-      /* The function might be an MI-style class, or it might be an
-	 ordinary function.  If CHILDREN is true, the existence of
-	 either the to_string or children methods means to call
-	 _format_children.  Otherwise, if we have to_string, call it.
-	 As a last resort, call the object as a function.  */
+      /* If CHILDREN is true, call _format_children.  Otherwise, just
+	 try to call the object's to_string method.  */
       if (children


hooks/post-receive
--
Repository for Project Archer.


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

* [SCM]  archer-tromey-python: gdb
@ 2008-10-23 22:27 tromey
  0 siblings, 0 replies; 26+ messages in thread
From: tromey @ 2008-10-23 22:27 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-python has been updated
       via  f413e75bd1cbd52ad756f9d3bfb4863714dca5f9 (commit)
      from  830c5c95aa64f4918c81388f19e080063ea24649 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit f413e75bd1cbd52ad756f9d3bfb4863714dca5f9
Author: Tom Tromey <tromey@redhat.com>
Date:   Thu Oct 23 16:27:05 2008 -0600

    gdb
    	* python/python.c (find_pretty_printer): Strip reference types.
    gdb/doc
    	* gdb.texinfo (Pretty Printing): Update.
    gdb/testsuite
    	* gdb.python/python-prettyprint.exp (run_lang_tests): Test
    	printing a reference.
    	* gdb.python/python-prettyprint.c (main): Add reference.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog                                   |    4 ++++
 gdb/doc/ChangeLog                               |    4 ++++
 gdb/doc/gdb.texinfo                             |    6 ++++--
 gdb/python/python.c                             |    3 +++
 gdb/testsuite/ChangeLog                         |    6 ++++++
 gdb/testsuite/gdb.python/python-prettyprint.c   |    2 ++
 gdb/testsuite/gdb.python/python-prettyprint.exp |    1 +
 7 files changed, 24 insertions(+), 2 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 7eaf2f5..3eddb7c 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,9 @@
 2008-10-23  Tom Tromey  <tromey@redhat.com>
 
+	* python/python.c (find_pretty_printer): Strip reference types.
+
+2008-10-23  Tom Tromey  <tromey@redhat.com>
+
 	* python/python.c (find_pretty_printer): Strip type qualifiers.
 
 2008-10-22  Tom Tromey  <tromey@redhat.com>
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 2d5b8f7..60a9c94 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,7 @@
+2008-10-23  Tom Tromey  <tromey@redhat.com>
+
+	* gdb.texinfo (Pretty Printing): Update.
+
 2008-10-22  Tom Tromey  <tromey@redhat.com>
 
 	* gdb.texinfo (Pretty Printing): Remove comments.  Add missing
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index b41175f..ea1020e 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -17994,8 +17994,10 @@ The Python dictionary @code{gdb.cli_pretty_printers} maps regular
 expressions (strings) onto pretty-printers.  A pretty-printer is
 either a function or an object.
 
-When printing a value, @value{GDBN} first compares the name of the
-value's canonical type (the type after following all typedefs) to each
+When printing a value, @value{GDBN} first computes the values'
+canonical type by following typedefs, following a reference type to
+its referenced type, and removing qualifiers, such as @code{const} or
+@code{volatile}.  The name of this type is then compared to each
 regular expression.  If a regular expression matches, then the
 corresponding pretty-printer is invoked with a @code{gdb.Value}
 representing the value to be printed.
diff --git a/gdb/python/python.c b/gdb/python/python.c
index c6395fb..6d280d9 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -632,6 +632,9 @@ find_pretty_printer (struct type *type, PyObject **dictp, char *dict_name)
   /* Get the name of the type.  */
   TRY_CATCH (except, RETURN_MASK_ALL)
     {
+      /* If we have a reference, use the referenced type.  */
+      if (TYPE_CODE (type) == TYPE_CODE_REF)
+	type = TYPE_TARGET_TYPE (type);
       /* Strip off any qualifiers from the type.  */
       type = make_cv_type (0, 0, type, NULL);
       type_name = get_type (type);
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 1047286..911275c 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,6 +1,12 @@
 2008-10-23  Tom Tromey  <tromey@redhat.com>
 
 	* gdb.python/python-prettyprint.exp (run_lang_tests): Test
+	printing a reference.
+	* gdb.python/python-prettyprint.c (main): Add reference.
+
+2008-10-23  Tom Tromey  <tromey@redhat.com>
+
+	* gdb.python/python-prettyprint.exp (run_lang_tests): Test
 	printing 'cstring'.
 	* gdb.python/python-prettyprint.c (main): New local 'cstring'.
 
diff --git a/gdb/testsuite/gdb.python/python-prettyprint.c b/gdb/testsuite/gdb.python/python-prettyprint.c
index 1336d91..f99e6f9 100644
--- a/gdb/testsuite/gdb.python/python-prettyprint.c
+++ b/gdb/testsuite/gdb.python/python-prettyprint.c
@@ -137,6 +137,8 @@ main ()
   init_s(&cpssa[1].s, 14);
 
   SSS sss(15, cps);
+
+  SSS& ref (sss);
 #endif
 
   add_item (&c, 23);		/* MI breakpoint here */
diff --git a/gdb/testsuite/gdb.python/python-prettyprint.exp b/gdb/testsuite/gdb.python/python-prettyprint.exp
index 7c654a4..d07d195 100644
--- a/gdb/testsuite/gdb.python/python-prettyprint.exp
+++ b/gdb/testsuite/gdb.python/python-prettyprint.exp
@@ -71,6 +71,7 @@ proc run_lang_tests {lang} {
 	gdb_test "print cpssa\[1\]" " = {zss = 13, s =  a=<14> b=<$hex>}"
 	gdb_test "print cpssa" " = {{zss = 11, s =  a=<12> b=<$hex>}, {zss = 13, s =  a=<14> b=<$hex>}}"
 	gdb_test "print sss" "= a=<15> b=< a=<8> b=<$hex>>"
+	gdb_test "print ref" "= a=<15> b=< a=<8> b=<$hex>>"
     }
 
     gdb_test "print x" " = $hex \"this is x\""


hooks/post-receive
--
Repository for Project Archer.


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

* [SCM]  archer-tromey-python: gdb
@ 2008-10-23 21:28 tromey
  0 siblings, 0 replies; 26+ messages in thread
From: tromey @ 2008-10-23 21:28 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-python has been updated
       via  830c5c95aa64f4918c81388f19e080063ea24649 (commit)
      from  cf3e56721383f4e8480f049a20eaa25b7e76d753 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 830c5c95aa64f4918c81388f19e080063ea24649
Author: Tom Tromey <tromey@redhat.com>
Date:   Thu Oct 23 15:27:47 2008 -0600

    gdb
    	* python/python.c (find_pretty_printer): Strip type qualifiers.
    gdb/testsuite
    	* gdb.python/python-prettyprint.exp (run_lang_tests): Test
    	printing 'cstring'.
    	* gdb.python/python-prettyprint.c (main): New local 'cstring'.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog                                   |    4 ++++
 gdb/python/python.c                             |    2 ++
 gdb/testsuite/ChangeLog                         |    6 ++++++
 gdb/testsuite/gdb.python/python-prettyprint.c   |    1 +
 gdb/testsuite/gdb.python/python-prettyprint.exp |    1 +
 5 files changed, 14 insertions(+), 0 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 3a112c4..7eaf2f5 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,7 @@
+2008-10-23  Tom Tromey  <tromey@redhat.com>
+
+	* python/python.c (find_pretty_printer): Strip type qualifiers.
+
 2008-10-22  Tom Tromey  <tromey@redhat.com>
 
 	* python/python.c (_initialize_python) <_format_children>: Handle
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 83bce4d..c6395fb 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -632,6 +632,8 @@ find_pretty_printer (struct type *type, PyObject **dictp, char *dict_name)
   /* Get the name of the type.  */
   TRY_CATCH (except, RETURN_MASK_ALL)
     {
+      /* Strip off any qualifiers from the type.  */
+      type = make_cv_type (0, 0, type, NULL);
       type_name = get_type (type);
     }
   if (except.reason < 0)
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index cb86eca..1047286 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2008-10-23  Tom Tromey  <tromey@redhat.com>
+
+	* gdb.python/python-prettyprint.exp (run_lang_tests): Test
+	printing 'cstring'.
+	* gdb.python/python-prettyprint.c (main): New local 'cstring'.
+
 2008-10-22  Tom Tromey  <tromey@redhat.com>
 
 	* lib/mi-support.exp (mi_list_varobj_children_range): New proc.
diff --git a/gdb/testsuite/gdb.python/python-prettyprint.c b/gdb/testsuite/gdb.python/python-prettyprint.c
index 8e7473a..1336d91 100644
--- a/gdb/testsuite/gdb.python/python-prettyprint.c
+++ b/gdb/testsuite/gdb.python/python-prettyprint.c
@@ -114,6 +114,7 @@ main ()
   struct ss  ssa[2];
   string x = make_string ("this is x");
   zzz_type c = make_container ("container");
+  const struct string_repr cstring = { { "const string" } };
 
   init_ss(&ss, 1, 2);
   init_ss(ssa+0, 3, 4);
diff --git a/gdb/testsuite/gdb.python/python-prettyprint.exp b/gdb/testsuite/gdb.python/python-prettyprint.exp
index 1deac49..7c654a4 100644
--- a/gdb/testsuite/gdb.python/python-prettyprint.exp
+++ b/gdb/testsuite/gdb.python/python-prettyprint.exp
@@ -74,6 +74,7 @@ proc run_lang_tests {lang} {
     }
 
     gdb_test "print x" " = $hex \"this is x\""
+    gdb_test "print cstring" " = $hex \"const string\""
 
     set nl "\[\r\n\]+"
     gdb_test "print c" " = container $hex \"container\" with 2 elements$nl *.0. = 23$nl *.1. = 72"


hooks/post-receive
--
Repository for Project Archer.


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

* [SCM]  archer-tromey-python: gdb
@ 2008-10-22 18:18 tromey
  0 siblings, 0 replies; 26+ messages in thread
From: tromey @ 2008-10-22 18:18 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-python has been updated
       via  be28390bda0775ce506162b7adacf2a4f6fb0c41 (commit)
      from  ec3d8bea908d94df0b4222d876ff779add5494af (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit be28390bda0775ce506162b7adacf2a4f6fb0c41
Author: Tom Tromey <tromey@redhat.com>
Date:   Wed Oct 22 12:17:56 2008 -0600

    gdb
    	* python/python.c (_initialize_python) <_format_children>: Call
    	to_string, not header.
    	(pretty_print_one_value): Call _format_children if either
    	'children' to 'to_string' exists.
    gdb/doc
    	* gdb.texinfo (Pretty Printing): Remove 'header'.
    gdb/testsuite
    	* gdb.python/python-prettyprint.py (ContainerPrinter.to_string):
    	Rename from 'header'.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog                                  |    7 ++++++
 gdb/doc/ChangeLog                              |    4 +++
 gdb/doc/gdb.texinfo                            |   21 +++----------------
 gdb/python/python.c                            |   25 +++++++++++++----------
 gdb/testsuite/ChangeLog                        |    5 ++++
 gdb/testsuite/gdb.python/python-prettyprint.py |    2 +-
 6 files changed, 35 insertions(+), 29 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 8c5474a..a8cfa41 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2008-10-22  Tom Tromey  <tromey@redhat.com>
+
+	* python/python.c (_initialize_python) <_format_children>: Call
+	to_string, not header.
+	(pretty_print_one_value): Call _format_children if either
+	'children' to 'to_string' exists.
+
 2008-10-21  Tom Tromey  <tromey@redhat.com>
 
 	* varobj.c (update_dynamic_varobj_children): Copy value when
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 8831116..ab28b52 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,7 @@
+2008-10-22  Tom Tromey  <tromey@redhat.com>
+
+	* gdb.texinfo (Pretty Printing): Remove 'header'.
+
 2008-10-20  Tom Tromey  <tromey@redhat.com>
 
 	* gdb.texinfo (GDB/MI Miscellaneous Commands): Mention 'python'
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index edbf51e..83c6280 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -17951,17 +17951,6 @@ using Python code.  This mechanism works for both MI and the CLI.
 A pretty-printer is an object that implements a specific interface.
 There is no predefined base class for pretty-printers.
 
-@c FIXME I think perhaps we should nuke header and just use to_string
-@c Investigate.
-
-@defop Operation {pretty printer} header (self, val)
-If this method exists, @value{GDBN} may call it when printing a value
-from the CLI.  In particular, it will be called if the pretty-printer
-does not define the @code{to_string} method.  The method must return a
-string.  This string will be displayed before any children of the
-value being printed.
-@end defop
-
 @defop Operation {pretty printer} children (self, val)
 This method is used by both the MI and CLI code.  When printing a
 value, @value{GDBN} will call this method to display the children of
@@ -17992,13 +17981,11 @@ This method is used by both the MI and CLI code.  When printing a
 value, @value{GDBN} will call this method to display the string
 representation of @var{val}, an instance of @code{gdb.Value}.
 
-This method must return a string.
-
-@c FIXME -- this is where the oddity arises.  Don't we do something
-@c different for MI?
 When printing from the CLI, if the @code{to_string} method exists,
-then @value{GDBN} will print its result, and will not call
-@code{header} and @code{children}.
+then @value{GDBN} will prepend its result to the values returned by
+@code{children}.
+
+This method must return a string.
 @end defop
 
 @subsubsection Selecting CLI Pretty-Printers
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 55de351..3541712 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -687,21 +687,24 @@ pretty_print_one_value (PyObject *func, struct value *value,
 
       val_obj = value_to_value_object (value);
 
-      /* The function might be an MI-style class with a to_string
-	 method, or it might be an ordinary function.  FIXME: should
-	 also check for the 'children' method here.  */
-      if (PyObject_HasAttr (func, gdbpy_to_string_cst))
-	result = PyObject_CallMethodObjArgs (func, gdbpy_to_string_cst,
-					     val_obj, NULL);
-      else if (children
-	       && PyObject_HasAttr (func, gdbpy_children_cst)
-	       && PyObject_HasAttrString (gdb_module, "_format_children"))
+      /* The function might be an MI-style class, or it might be an
+	 ordinary function.  If CHILDREN is true, the existence of
+	 either the to_string or children methods means to call
+	 _format_children.  Otherwise, if we have to_string, call it.
+	 As a last resort, call the object as a function.  */
+      if (children
+	  && (PyObject_HasAttr (func, gdbpy_children_cst)
+	      || PyObject_HasAttr (func, gdbpy_to_string_cst))
+	  && PyObject_HasAttrString (gdb_module, "_format_children"))
 	{
 	  PyObject *fmt = PyObject_GetAttrString (gdb_module,
 						  "_format_children");
 	  result = PyObject_CallFunctionObjArgs (fmt, func, val_obj, NULL);
 	  Py_DECREF (fmt);
 	}
+      else if (PyObject_HasAttr (func, gdbpy_to_string_cst))
+	result = PyObject_CallMethodObjArgs (func, gdbpy_to_string_cst,
+					     val_obj, NULL);
       else
 	result = PyObject_CallFunctionObjArgs (func, val_obj, NULL);
       if (result)
@@ -1047,8 +1050,8 @@ sys.stdout = GdbOutputFile()\n\
   PyRun_SimpleString ("\
 def _format_children(obj, val):\n\
   result = []\n\
-  if hasattr(obj, 'header'):\n\
-    result.append(obj.header(val))\n\
+  if hasattr(obj, 'to_string'):\n\
+    result.append(obj.to_string(val))\n\
   max = gdb.get_parameter('print elements')\n\
   i = 0\n\
   for elt in obj.children(val):\n\
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 5d03fb5..66ba18d 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,10 @@
 2008-10-22  Tom Tromey  <tromey@redhat.com>
 
+	* gdb.python/python-prettyprint.py (ContainerPrinter.to_string):
+	Rename from 'header'.
+
+2008-10-22  Tom Tromey  <tromey@redhat.com>
+
 	* gdb.python/python-prettyprint.py: Add MI pretty printer.
 	* gdb.python/python-mi.exp: New file.
 	* lib/mi-support.exp (mi_child_regexp): New proc.
diff --git a/gdb/testsuite/gdb.python/python-prettyprint.py b/gdb/testsuite/gdb.python/python-prettyprint.py
index 2c30ef3..abb46d7 100644
--- a/gdb/testsuite/gdb.python/python-prettyprint.py
+++ b/gdb/testsuite/gdb.python/python-prettyprint.py
@@ -38,7 +38,7 @@ class ContainerPrinter:
             self.pointer = self.pointer + 1
             return ('[%d]' % int (result - self.start), result.dereference())
 
-    def header(self, val):
+    def to_string(self, val):
         return 'container %s with %d elements' % (val['name'], val['len'])
 
     def children(self, val):


hooks/post-receive
--
Repository for Project Archer.


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

* [SCM]  archer-tromey-python: gdb
@ 2008-10-21 18:32 tromey
  0 siblings, 0 replies; 26+ messages in thread
From: tromey @ 2008-10-21 18:32 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-python has been updated
       via  86eacf053f8a111cdddb8410aa9b9b7b0527fa75 (commit)
      from  e726423960c41516007f440ed0173b1acf3ba4d9 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 86eacf053f8a111cdddb8410aa9b9b7b0527fa75
Author: Tom Tromey <tromey@redhat.com>
Date:   Tue Oct 21 12:30:30 2008 -0600

    gdb
    	* python/python.c (pretty_print_one_value): Use gdbpy_is_string
    	and python_string_to_host_string.
    	* python/python-value.c (valpy_richcompare): Use gdbpy_is_string.
    	(convert_value_from_python): Likewise.
    	* python/python-param.c (set_parameter_value): Use gdbpy_is_string
    	and python_string_to_host_string.
    	(compute_enum_values): Likewise.
    	(parmpy_init): Likewise.
    	* python/python-function.c (fnpy_init): Use gdbpy_is_string and
    	python_string_to_host_string.
    	* python/python-cmd.c (cmdpy_completer): Use gdbpy_is_string and
    	python_string_to_host_string.
    	(cmdpy_init): Likewise.
    	* varobj.c (varobj_get_display_hint): Use gdbpy_is_string.
    	* python/python-internal.h (gdbpy_is_string): Declare.
    	(python_string_to_host_string): Declare.
    	* python/python-utils.c (gdbpy_is_string): New function.
    	(unicode_to_encoded_string): New function.
    	(unicode_to_target_string): Use it.
    	(python_string_to_host_string): New function.
    gdb/testsuite
    	* gdb.python/python-prettyprint.exp (run_lang_tests): Don't expect
    	quotes.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog                                   |   23 ++++++++++
 gdb/python/python-cmd.c                         |   10 ++---
 gdb/python/python-function.c                    |    5 +-
 gdb/python/python-internal.h                    |    2 +
 gdb/python/python-param.c                       |   19 ++++----
 gdb/python/python-utils.c                       |   52 +++++++++++++++++++----
 gdb/python/python-value.c                       |    4 +-
 gdb/python/python.c                             |    4 +-
 gdb/testsuite/ChangeLog                         |    5 ++
 gdb/testsuite/gdb.python/python-prettyprint.exp |    6 ++-
 gdb/varobj.c                                    |    4 +-
 11 files changed, 100 insertions(+), 34 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 582cc95..0ee50c8 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,26 @@
+2008-10-21  Tom Tromey  <tromey@redhat.com>
+
+	* python/python.c (pretty_print_one_value): Use gdbpy_is_string
+	and python_string_to_host_string.
+	* python/python-value.c (valpy_richcompare): Use gdbpy_is_string.
+	(convert_value_from_python): Likewise.
+	* python/python-param.c (set_parameter_value): Use gdbpy_is_string
+	and python_string_to_host_string.
+	(compute_enum_values): Likewise.
+	(parmpy_init): Likewise.
+	* python/python-function.c (fnpy_init): Use gdbpy_is_string and
+	python_string_to_host_string.
+	* python/python-cmd.c (cmdpy_completer): Use gdbpy_is_string and
+	python_string_to_host_string.
+	(cmdpy_init): Likewise.
+	* varobj.c (varobj_get_display_hint): Use gdbpy_is_string.
+	* python/python-internal.h (gdbpy_is_string): Declare.
+	(python_string_to_host_string): Declare.
+	* python/python-utils.c (gdbpy_is_string): New function.
+	(unicode_to_encoded_string): New function.
+	(unicode_to_target_string): Use it.
+	(python_string_to_host_string): New function.
+
 2008-10-20  Tom Tromey  <tromey@redhat.com>
 
 	* mi/mi-main.c (mi_cmd_list_features): Add "python" feature.
diff --git a/gdb/python/python-cmd.c b/gdb/python/python-cmd.c
index c628623..58e79da 100644
--- a/gdb/python/python-cmd.c
+++ b/gdb/python/python-cmd.c
@@ -196,17 +196,15 @@ cmdpy_completer (struct cmd_list_element *command, char *text, char *word)
       result = (char **) xmalloc ((len + 1) * sizeof (char *));
       for (i = out = 0; i < len; ++i)
 	{
-	  char *s;
 	  int l;
 	  PyObject *elt = PySequence_GetItem (resultobj, i);
-	  if (elt == NULL || ! PyString_Check (elt))
+	  if (elt == NULL || ! gdbpy_is_string (elt))
 	    {
 	      /* Skip problem elements.  */
 	      PyErr_Clear ();
 	      continue;
 	    }
-	  s = PyString_AsString (elt);
-	  result[out] = xstrdup (s);
+	  result[out] = python_string_to_host_string (elt);
 	  ++out;
 	}
       result[out] = NULL;
@@ -374,8 +372,8 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kwds)
   if (PyObject_HasAttrString (self, "__doc__"))
     {
       PyObject *ds_obj = PyObject_GetAttrString (self, "__doc__");
-      if (ds_obj && PyString_Check (ds_obj))
-	docstring = xstrdup (PyString_AsString (ds_obj));
+      if (ds_obj && gdbpy_is_string (ds_obj))
+	docstring = python_string_to_host_string (ds_obj);
     }
   if (! docstring)
     docstring = xstrdup ("This command is not documented.");
diff --git a/gdb/python/python-function.c b/gdb/python/python-function.c
index 9f31557..c82a13b 100644
--- a/gdb/python/python-function.c
+++ b/gdb/python/python-function.c
@@ -114,8 +114,9 @@ fnpy_init (PyObject *self, PyObject *args, PyObject *kwds)
   if (PyObject_HasAttrString (self, "__doc__"))
     {
       PyObject *ds_obj = PyObject_GetAttrString (self, "__doc__");
-      if (ds_obj && PyString_Check (ds_obj))
-	docstring = PyString_AsString (ds_obj);
+      if (ds_obj && gdbpy_is_string (ds_obj))
+	/* Nothing ever frees this.  */
+	docstring = python_string_to_host_string (ds_obj);
     }
   if (! docstring)
     docstring = "This command is not documented.";
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index ef4e8f8..12b9917 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -117,6 +117,8 @@ void gdbpy_print_stack (void);
 PyObject *python_string_to_unicode (PyObject *obj);
 char *unicode_to_target_string (PyObject *unicode_str);
 char *python_string_to_target_string (PyObject *obj);
+char *python_string_to_host_string (PyObject *obj);
+int gdbpy_is_string (PyObject *obj);
 
 /* Note that these are declared here, and not in python.h with the
    other pretty-printer functions, because they refer to PyObject.  */
diff --git a/gdb/python/python-param.c b/gdb/python/python-param.c
index a9b8c4d..cf1ceaa 100644
--- a/gdb/python/python-param.c
+++ b/gdb/python/python-param.c
@@ -116,7 +116,7 @@ set_parameter_value (parmpy_object *self, PyObject *value)
     case var_string_noescape:
     case var_optional_filename:
     case var_filename:
-      if (! PyString_Check (value)
+      if (! gdbpy_is_string (value)
 	  && (self->type == var_filename
 	      || value != Py_None))
 	{
@@ -133,7 +133,7 @@ set_parameter_value (parmpy_object *self, PyObject *value)
 	    self->value.stringval = NULL;
 	}
       else
-	self->value.stringval = xstrdup (PyString_AsString (value));
+	self->value.stringval = python_string_to_host_string (value);
       break;
 
     case var_enum:
@@ -141,16 +141,17 @@ set_parameter_value (parmpy_object *self, PyObject *value)
 	int i;
 	char *str;
 
-	if (! PyString_Check (value))
+	if (! gdbpy_is_string (value))
 	  {
 	    PyErr_SetString (PyExc_RuntimeError, "string required");
 	    return -1;
 	  }
 
-	str = PyString_AsString (value);
+	str = python_string_to_host_string (value);
 	for (i = 0; self->enumeration[i]; ++i)
 	  if (! strcmp (self->enumeration[i], str))
 	    break;
+	xfree (str);
 	if (! self->enumeration[i])
 	  {
 	    PyErr_SetString (PyExc_RuntimeError,
@@ -359,17 +360,15 @@ compute_enum_values (parmpy_object *self, PyObject *enum_values)
 
   for (i = 0; i < size; ++i)
     {
-      char *value;
       PyObject *item = PySequence_GetItem (enum_values, i);
       if (! item)
 	return 0;
-      if (! PyString_Check (item))
+      if (! gdbpy_is_string (item))
 	{
 	  PyErr_SetString (PyExc_RuntimeError, "enumeration item not a string");
 	  return 0;
 	}
-      value = PyString_AsString (item);
-      self->enumeration[i] = xstrdup (value);
+      self->enumeration[i] = python_string_to_host_string (item);
     }
 
   return 1;
@@ -463,8 +462,8 @@ parmpy_init (PyObject *self, PyObject *args, PyObject *kwds)
   if (PyObject_HasAttrString (self, "__doc__"))
     {
       PyObject *ds_obj = PyObject_GetAttrString (self, "__doc__");
-      if (ds_obj && PyString_Check (ds_obj))
-	docstring = xstrdup (PyString_AsString (ds_obj));
+      if (ds_obj && gdbpy_is_string (ds_obj))
+	docstring = python_string_to_host_string (ds_obj);
     }
   if (! docstring)
     docstring = xstrdup ("This command is not documented.");
diff --git a/gdb/python/python-utils.c b/gdb/python/python-utils.c
index 912845f..2fdd2b7 100644
--- a/gdb/python/python-utils.c
+++ b/gdb/python/python-utils.c
@@ -78,26 +78,37 @@ python_string_to_unicode (PyObject *obj)
 }
 
 /* Returns a newly allocated string with the contents of the given unicode
-   string object converted to the target's charset.  If an error occurs during
+   string object converted to a named charset.  If an error occurs during
    the conversion, NULL will be returned and a python exception will be set.
 
    The caller is responsible for xfree'ing the string.  */
-char *
-unicode_to_target_string (PyObject *unicode_str)
+static char *
+unicode_to_encoded_string (PyObject *unicode_str, const char *charset)
 {
-  char *target_string;
+  char *result;
   PyObject *string;
 
-  /* Translate string to target's charset.  */
-  string = PyUnicode_AsEncodedString (unicode_str, target_charset (), NULL);
+  /* Translate string to named charset.  */
+  string = PyUnicode_AsEncodedString (unicode_str, charset, NULL);
   if (string == NULL)
     return NULL;
 
-  target_string = xstrdup (PyString_AsString (string));
+  result = xstrdup (PyString_AsString (string));
 
   Py_DECREF (string);
 
-  return target_string;
+  return result;
+}
+
+/* Returns a newly allocated string with the contents of the given unicode
+   string object converted to the target's charset.  If an error occurs during
+   the conversion, NULL will be returned and a python exception will be set.
+
+   The caller is responsible for xfree'ing the string.  */
+char *
+unicode_to_target_string (PyObject *unicode_str)
+{
+  return unicode_to_encoded_string (unicode_str, target_charset ());
 }
 
 /* Converts a python string (8-bit or unicode) to a target string in
@@ -115,3 +126,28 @@ python_string_to_target_string (PyObject *obj)
 
   return unicode_to_target_string (str);
 }
+
+/* Converts a python string (8-bit or unicode) to a target string in
+   the host's charset.  Returns NULL on error, with a python exception set.
+
+   The caller is responsible for xfree'ing the string.  */
+char *
+python_string_to_host_string (PyObject *obj)
+{
+  PyObject *str;
+
+  str = python_string_to_unicode (obj);
+  if (str == NULL)
+    return NULL;
+
+  return unicode_to_encoded_string (str, host_charset ());
+}
+
+/* Return true if OBJ is a Python string or unicode object, false
+   otherwise.  */
+
+int
+gdbpy_is_string (PyObject *obj)
+{
+  return PyString_Check (obj) || PyUnicode_Check (obj);
+}
diff --git a/gdb/python/python-value.c b/gdb/python/python-value.c
index 7d677dd..93af465 100644
--- a/gdb/python/python-value.c
+++ b/gdb/python/python-value.c
@@ -495,7 +495,7 @@ valpy_richcompare (PyObject *self, PyObject *other, int op)
 
       value_other = value_from_double (builtin_type_pyfloat, d);
     }
-  else if (PyString_Check (other) || PyUnicode_Check (other))
+  else if (gdbpy_is_string (other))
     {
       char *str;
 
@@ -720,7 +720,7 @@ convert_value_from_python (PyObject *obj)
       if (! PyErr_Occurred ())
 	value = value_from_double (builtin_type_pyfloat, d);
     }
-  else if (PyString_Check (obj) || PyUnicode_Check (obj))
+  else if (gdbpy_is_string (obj))
     {
       char *s;
 
diff --git a/gdb/python/python.c b/gdb/python/python.c
index c4e0fbd..55de351 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -706,8 +706,8 @@ pretty_print_one_value (PyObject *func, struct value *value,
 	result = PyObject_CallFunctionObjArgs (func, val_obj, NULL);
       if (result)
 	{
-	  if (PyString_Check (result))
-	    output = xstrdup (PyString_AsString (result));
+	  if (gdbpy_is_string (result))
+	    output = python_string_to_host_string (result);
 	  else if (PyObject_TypeCheck (result, &value_object_type))
 	    {
 	      /* If we just call convert_value_from_python for this
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index a41bbb0..e6c51bc 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2008-10-21  Tom Tromey  <tromey@redhat.com>
+
+	* gdb.python/python-prettyprint.exp (run_lang_tests): Don't expect
+	quotes.
+
 2008-10-20  Tom Tromey  <tromey@redhat.com>
 
 	* gdb.python/python-prettyprint.exp: Fixed comment.
diff --git a/gdb/testsuite/gdb.python/python-prettyprint.exp b/gdb/testsuite/gdb.python/python-prettyprint.exp
index d6aa537..2a69572 100644
--- a/gdb/testsuite/gdb.python/python-prettyprint.exp
+++ b/gdb/testsuite/gdb.python/python-prettyprint.exp
@@ -72,8 +72,10 @@ proc run_lang_tests {lang} {
 	gdb_test "print cpssa" " = {{zss = 11, s =  a=<12> b=<$hex>}, {zss = 13, s =  a=<14> b=<$hex>}}"
     }
 
-  gdb_test "print x" " = $hex \"this is x\""
-  gdb_test "print c" " = \"container $hex .\"container.\" with 2 elements..?.0. = 23..?.1. = 72\""
+    gdb_test "print x" " = $hex \"this is x\""
+
+    set nl "\[\r\n\]+"
+    gdb_test "print c" " = container $hex \"container\" with 2 elements$nl *.0. = 23$nl *.1. = 72"
 }
 
 run_lang_tests "c"
diff --git a/gdb/varobj.c b/gdb/varobj.c
index e6890e4..c668c7e 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -755,8 +755,8 @@ varobj_get_display_hint (struct varobj *var)
       PyObject *hint = PyObject_CallMethodObjArgs (var->pretty_printer,
 						   gdbpy_display_hint_cst,
 						   NULL);
-      if (PyString_Check (hint))
-	result = xstrdup (PyString_AsString (hint));
+      if (gdbpy_is_string (hint))
+	result = python_string_to_host_string (hint);
       if (hint)
 	Py_DECREF (hint);
       else


hooks/post-receive
--
Repository for Project Archer.


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

end of thread, other threads:[~2009-04-07 20:28 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-06 21:11 [SCM] archer-tromey-python: gdb tromey
  -- strict thread matches above, loose matches on Subject: below --
2009-04-07 20:28 tromey
2009-03-24 17:27 tromey
2009-02-05 19:56 tromey
2008-12-17 23:10 tromey
2008-12-15 22:38 tromey
2008-12-13  0:37 tromey
2008-12-12 23:54 tromey
2008-12-10 15:28 tromey
2008-12-09  0:33 tromey
2008-12-02 21:29 tromey
2008-12-01 19:10 tromey
2008-11-25 21:17 tromey
2008-11-21 18:25 tromey
2008-11-18 18:52 tromey
2008-11-18 15:54 tromey
2008-11-17 15:45 tromey
2008-11-16 22:18 tromey
2008-11-16 16:56 tromey
2008-11-12  1:54 tromey
2008-11-10 14:15 tromey
2008-11-06 19:58 tromey
2008-10-23 22:27 tromey
2008-10-23 21:28 tromey
2008-10-22 18:18 tromey
2008-10-21 18:32 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).