public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM]  archer-pmuldoon-pretty-printers-lookup: Merge commit 'origin/archer-tromey-python' into archer-pmuldoon-pretty-printers-lookup
@ 2009-02-24  9:27 pmuldoon
  0 siblings, 0 replies; 2+ messages in thread
From: pmuldoon @ 2009-02-24  9:27 UTC (permalink / raw)
  To: archer-commits

The branch, archer-pmuldoon-pretty-printers-lookup has been updated
       via  219a4656534db9037967f36e4fd3c2eebed502b7 (commit)
       via  6b43f0eaec652104bcbf802d7a86869d956ce4e4 (commit)
       via  f17c887e8b4aa77c8a49885a0f8bf2dab0dba228 (commit)
       via  20340ed988af98c24acd5efac0f36b015d3caf6a (commit)
       via  02bcb2e138d6dc35eebb59cebd43803325cc01fb (commit)
       via  6cf7323f651c1f26407543741907ddd08ba3339e (commit)
       via  c64ee73557889fc3d244615aeb10940a9aab2a08 (commit)
      from  ad2304013aa16e1bfa13ad7be293932d400cc8db (commit)

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

- Log -----------------------------------------------------------------
commit 219a4656534db9037967f36e4fd3c2eebed502b7
Merge: ad2304013aa16e1bfa13ad7be293932d400cc8db 6b43f0eaec652104bcbf802d7a86869d956ce4e4
Author: Phil Muldoon <pmuldoon@redhat.com>
Date:   Tue Feb 24 09:06:39 2009 +0000

    Merge commit 'origin/archer-tromey-python' into archer-pmuldoon-pretty-printers-lookup

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

Summary of changes:
 gdb/doc/gdb.texinfo                         |   17 ++
 gdb/findcmd.c                               |  111 +++++++++----
 gdb/python/lib/gdb/libstdcxx/v6/printers.py |   23 ++-
 gdb/python/python-internal.h                |    4 +
 gdb/python/python-membuf.c                  |    8 +-
 gdb/python/python-utils.c                   |   46 +++++
 gdb/python/python-value.c                   |   41 +++++-
 gdb/python/python.c                         |  238 +++++++++++++++++++++++++++
 gdb/target.h                                |   14 ++
 gdb/testsuite/gdb.python/find.c             |   64 +++++++
 gdb/testsuite/gdb.python/find.exp           |  186 +++++++++++++++++++++
 gdb/value.c                                 |   48 ++++++
 gdb/value.h                                 |    1 +
 13 files changed, 764 insertions(+), 37 deletions(-)
 create mode 100644 gdb/testsuite/gdb.python/find.c
 create mode 100644 gdb/testsuite/gdb.python/find.exp

First 500 lines of diff:
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 4371672..d607daa 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -18280,6 +18280,23 @@ protocol, i.e., a string, an array or the object returned from
 @var{length} determines the number of bytes from @var{buffer} to be written.
 @end defun
 
+@findex gdb.search_memory
+@defun search_memory @var{address} @var{length} @var{pattern} @r{[}@var{size}@r{]} @r{[}@var{max_count}@r{]}
+Search a region of the inferior memory starting at @var{address} with the given
+@var{length}.  @var{pattern} can be a string, a byte array, a buffer object,
+a number, a @code{gdb.Value} object (@pxref{Values From Inferior}) or a list
+or tuple with elements in any combination of those types.  If @var{size} is
+given and is non-zero, it specifies the size in bytes of a Python scalar or
+@code{gdb.Value} in the search pattern.  If @var{size} is zero or not specified,
+ it is taken from the value's type in the current language.
+This is useful when one wants to specify the search
+pattern as a mixture of types.
+Note that this means, for example, that in the case of C-like languages
+a search for an untyped 0x42 will search for @samp{(int) 0x42}
+which is typically four bytes.  @var{max_count} is the highest number of matches
+to search for.
+@end defun
+
 @node Exception Handling
 @subsubsection Exception Handling
 @cindex python exceptions
diff --git a/gdb/findcmd.c b/gdb/findcmd.c
index 4e7fa09..f912dcf 100644
--- a/gdb/findcmd.c
+++ b/gdb/findcmd.c
@@ -26,7 +26,7 @@
 
 /* Copied from bfd_put_bits.  */
 
-static void
+void
 put_bits (bfd_uint64_t data, char *buf, int bits, bfd_boolean big_p)
 {
   int i;
@@ -44,6 +44,41 @@ put_bits (bfd_uint64_t data, char *buf, int bits, bfd_boolean big_p)
     }
 }
 
+/* Allocates a buffer in *PATTERN_BUF, with a hard-coded initial size which
+   will be returned in *PATTERN_BUF_SIZE. *PATTERN_BUF_END points to the same
+   place as *PATTERN_BUF, indicating that the buffer is initially empty.  */
+
+void
+allocate_pattern_buffer (char **pattern_buf, char **pattern_buf_end,
+			 ULONGEST *pattern_buf_size)
+{
+#define INITIAL_PATTERN_BUF_SIZE 100
+  *pattern_buf_size = INITIAL_PATTERN_BUF_SIZE;
+  *pattern_buf = xmalloc (*pattern_buf_size);
+  *pattern_buf_end = *pattern_buf;
+}
+
+/* Grows *PATTERN_BUF by a factor of two if it's not large enough to hold
+   VAL_BYTES more bytes  or a 64-bit value, whichever is larger.
+   *PATTERN_BUF_END is updated as necessary.  */
+
+void
+increase_pattern_buffer (char **pattern_buf, char **pattern_buf_end,
+			 ULONGEST *pattern_buf_size, int val_bytes)
+{
+    /* Keep it simple and assume size == 'g' when watching for when we
+       need to grow the pattern buf.  */
+    if ((*pattern_buf_end - *pattern_buf + max (val_bytes, sizeof (int64_t)))
+	> *pattern_buf_size)
+      {
+	size_t current_offset = *pattern_buf_end - *pattern_buf;
+
+	*pattern_buf_size *= 2;
+	*pattern_buf = xrealloc (*pattern_buf, *pattern_buf_size);
+	*pattern_buf_end = *pattern_buf + current_offset;
+      }
+}
+
 /* Subroutine of find_command to simplify it.
    Parse the arguments of the "find" command.  */
 
@@ -59,8 +94,7 @@ parse_find_args (char *args, ULONGEST *max_countp,
   char *pattern_buf;
   /* Current size of search pattern buffer.
      We realloc space as needed.  */
-#define INITIAL_PATTERN_BUF_SIZE 100
-  ULONGEST pattern_buf_size = INITIAL_PATTERN_BUF_SIZE;
+  ULONGEST pattern_buf_size;
   /* Pointer to one past the last in-use part of pattern_buf.  */
   char *pattern_buf_end;
   ULONGEST pattern_len;
@@ -74,8 +108,7 @@ parse_find_args (char *args, ULONGEST *max_countp,
   if (args == NULL)
     error (_("Missing search parameters."));
 
-  pattern_buf = xmalloc (pattern_buf_size);
-  pattern_buf_end = pattern_buf;
+  allocate_pattern_buffer (&pattern_buf, &pattern_buf_end, &pattern_buf_size);
   old_cleanups = make_cleanup (free_current_contents, &pattern_buf);
 
   /* Get search granularity and/or max count if specified.
@@ -172,16 +205,8 @@ parse_find_args (char *args, ULONGEST *max_countp,
       v = parse_to_comma_and_eval (&s);
       val_bytes = TYPE_LENGTH (value_type (v));
 
-      /* Keep it simple and assume size == 'g' when watching for when we
-	 need to grow the pattern buf.  */
-      if ((pattern_buf_end - pattern_buf + max (val_bytes, sizeof (int64_t)))
-	  > pattern_buf_size)
-	{
-	  size_t current_offset = pattern_buf_end - pattern_buf;
-	  pattern_buf_size *= 2;
-	  pattern_buf = xrealloc (pattern_buf, pattern_buf_size);
-	  pattern_buf_end = pattern_buf + current_offset;
-	}
+      increase_pattern_buffer (&pattern_buf, &pattern_buf_end,
+			       &pattern_buf_size, val_bytes);
 
       if (size != '\0')
 	{
@@ -236,6 +261,45 @@ parse_find_args (char *args, ULONGEST *max_countp,
   discard_cleanups (old_cleanups);
 }
 
+/* Drives target_search_memory to sweep through the specified search space,
+   possibly in several iterations (with one call to this function for each
+   iteration).  *START_ADDR is the address where the search starts, and is
+   updated to the next starting address to continue the search.
+   *SEARCH_SPACE_LEN is the amount of bytes which will be searched, and is
+   updated for the next iteration. PATTERN_BUF holds the pattern to be searched
+   for, PATTERN_LEN is the size of the pattern in bytes.  If a match is found,
+   it's address is put in *FOUND_ADDR.
+
+   Returns 1 if found, 0 if not found, and -1 if there was an error requiring
+   halting of the search (e.g. memory read error).  */
+
+int
+search_memory (CORE_ADDR *start_addr, ULONGEST *search_space_len,
+	       const char *pattern_buf, ULONGEST pattern_len,
+	       CORE_ADDR *found_addr)
+{
+  /* Offset from start of this iteration to the next iteration.  */
+  ULONGEST next_iter_incr;
+  int found;
+    
+  found = target_search_memory (*start_addr, *search_space_len,
+				pattern_buf, pattern_len, found_addr);
+  if (found <= 0)
+    return found;
+
+  /* Begin next iteration at one byte past this match.  */
+  next_iter_incr = (*found_addr - *start_addr) + 1;
+
+  /* For robustness, we don't let search_space_len go -ve here.  */
+  if (*search_space_len >= next_iter_incr)
+    *search_space_len -= next_iter_incr;
+  else
+    *search_space_len = 0;
+  *start_addr += next_iter_incr;
+
+  return found;
+}
+
 static void
 find_command (char *args, int from_tty)
 {
@@ -264,12 +328,11 @@ find_command (char *args, int from_tty)
   while (search_space_len >= pattern_len
 	 && found_count < max_count)
     {
-      /* Offset from start of this iteration to the next iteration.  */
-      ULONGEST next_iter_incr;
       CORE_ADDR found_addr;
-      int found = target_search_memory (start_addr, search_space_len,
-					pattern_buf, pattern_len, &found_addr);
+      int found;
 
+      found = search_memory (&start_addr, &search_space_len, pattern_buf,
+			     pattern_len, &found_addr);
       if (found <= 0)
 	break;
 
@@ -277,16 +340,6 @@ find_command (char *args, int from_tty)
       printf_filtered ("\n");
       ++found_count;
       last_found_addr = found_addr;
-
-      /* Begin next iteration at one byte past this match.  */
-      next_iter_incr = (found_addr - start_addr) + 1;
-
-      /* For robustness, we don't let search_space_len go -ve here.  */
-      if (search_space_len >= next_iter_incr)
-	search_space_len -= next_iter_incr;
-      else
-	search_space_len = 0;
-      start_addr += next_iter_incr;
     }
 
   /* Record and print the results.  */
diff --git a/gdb/python/lib/gdb/libstdcxx/v6/printers.py b/gdb/python/lib/gdb/libstdcxx/v6/printers.py
index b8c6d6f..7a77ad4 100644
--- a/gdb/python/lib/gdb/libstdcxx/v6/printers.py
+++ b/gdb/python/lib/gdb/libstdcxx/v6/printers.py
@@ -338,7 +338,16 @@ class StdBitsetPrinter:
     def children (self):
         words = self.val['_M_w']
         wtype = words.type()
-        tsize = wtype.target().sizeof()
+
+        # 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 ()
+        else:
+            words = [words]
+            tsize = wtype.sizeof () 
+
         nwords = wtype.sizeof() / tsize
         result = []
         byte = 0
@@ -464,7 +473,7 @@ class StdStringPrinter:
 class Tr1HashtableIterator:
     def __init__ (self, hash):
         self.count = 0
-        self.n_buckets = hash['_M_bucket_count']
+        self.n_buckets = hash['_M_element_count']
         if self.n_buckets == 0:
             self.node = False
         else:
@@ -481,11 +490,13 @@ class Tr1HashtableIterator:
         while self.node == 0:
             self.bucket = self.bucket + 1
             self.node = self.bucket[0]
+
+       # If we advanced off the end of the bucket array, then
+       # we're done.
+        if self.count == self.n_buckets:
+            self.node = False
+        else:
             self.count = self.count + 1
-            # If we advanced off the end of the bucket array, then
-            # we're done.
-            if self.count == self.n_buckets:
-                self.node = False
 
     def next (self):
         if not self.node:
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index e2fc9f1..c370af1 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -157,6 +157,8 @@ char *python_string_to_host_string (PyObject *obj);
 PyObject *target_string_to_unicode (const gdb_byte *str, int length);
 int gdbpy_is_string (PyObject *obj);
 
+int gdbpy_is_value_object (PyObject *obj);
+
 /* Note that these are declared here, and not in python.h with the
    other pretty-printer functions, because they refer to PyObject.  */
 char *apply_varobj_pretty_printer (PyObject *print_obj, struct value *value,
@@ -170,4 +172,6 @@ extern PyObject *gdbpy_to_string_cst;
 extern PyObject *gdbpy_display_hint_cst;
 extern PyObject *gdbpy_doc_cst;
 
+int get_addr_from_python (PyObject *obj, CORE_ADDR *addr);
+
 #endif /* GDB_PYTHON_INTERNAL_H */
diff --git a/gdb/python/python-membuf.c b/gdb/python/python-membuf.c
index df8849d..04bf3b4 100644
--- a/gdb/python/python-membuf.c
+++ b/gdb/python/python-membuf.c
@@ -165,7 +165,13 @@ get_seg_count (PyObject *self, Py_ssize_t *lenp)
 Py_ssize_t
 get_char_buffer (PyObject *self, Py_ssize_t segment, char **ptrptr)
 {
-  return get_char_buffer (self, segment, ptrptr);
+  void *ptr = NULL;
+  Py_ssize_t ret;
+
+  ret = get_read_buffer (self, segment, &ptr);
+  *ptrptr = (char *) ptr;
+
+  return ret;
 }
 
 /* Python doesn't provide a decent way to get compatibility here.  */
diff --git a/gdb/python/python-utils.c b/gdb/python/python-utils.c
index 1e6d952..c6c305f 100644
--- a/gdb/python/python-utils.c
+++ b/gdb/python/python-utils.c
@@ -19,6 +19,7 @@
 
 #include "defs.h"
 #include "charset.h"
+#include "value.h"
 #include "python-internal.h"
 
 
@@ -181,3 +182,48 @@ gdbpy_is_string (PyObject *obj)
 {
   return PyString_Check (obj) || PyUnicode_Check (obj);
 }
+
+/* Converts OBJ to a CORE_ADDR value.
+
+   Returns 1 on success or 0 on failure, with a Python exception set.  This
+   function can also throw GDB exceptions.  */
+
+int
+get_addr_from_python (PyObject *obj, CORE_ADDR *addr)
+{
+  if (gdbpy_is_value_object (obj))
+    *addr = value_as_address (value_object_to_value (obj));
+  else if (PyLong_Check (obj))
+    {
+      /* Assume CORE_ADDR corresponds to unsigned long.  */
+      *addr = PyLong_AsUnsignedLong (obj);
+      if (PyErr_Occurred () != NULL)
+	return 0;
+    }
+  else if (PyInt_Check (obj))
+    {
+      long val;
+
+      /* Assume CORE_ADDR corresponds to unsigned long.  */
+      val = PyInt_AsLong (obj);
+
+      if (val >= 0)
+	*addr = val;
+      else
+      {
+	/* If no error ocurred, VAL is indeed negative.  */
+	if (PyErr_Occurred () != NULL)
+	  return 0;
+
+	PyErr_SetString (PyExc_ValueError, "negative address");
+	return 0;
+      }
+    }
+  else
+    {
+      PyErr_SetString (PyExc_TypeError, "invalid type for address");
+      return 0;
+    }
+
+  return 1;
+}
diff --git a/gdb/python/python-value.c b/gdb/python/python-value.c
index 55361d6..ca29f46 100644
--- a/gdb/python/python-value.c
+++ b/gdb/python/python-value.c
@@ -52,6 +52,10 @@ struct value *values_in_python = NULL;
 /* Python's long type corresponds to C's long long type.  */
 #define builtin_type_pylong builtin_type (current_gdbarch)->builtin_long_long
 
+/* Python's long type corresponds to C's long long type.  Unsigned version.  */
+#define builtin_type_upylong builtin_type \
+  (current_gdbarch)->builtin_unsigned_long_long
+
 #define builtin_type_pybool \
   language_bool_type (current_language, current_gdbarch)
 
@@ -798,7 +802,34 @@ convert_value_from_python (PyObject *obj)
 	{
 	  LONGEST l = PyLong_AsLongLong (obj);
 
-	  if (! PyErr_Occurred ())
+	  if (PyErr_Occurred ())
+	    {
+	      /* If the error was an overflow, we can try converting to
+	         ULONGEST instead.  */
+	      if (PyErr_ExceptionMatches (PyExc_OverflowError))
+		{
+		  PyObject *etype, *evalue, *etraceback, *zero;
+
+		  PyErr_Fetch (&etype, &evalue, &etraceback);
+		  zero = PyInt_FromLong (0);
+
+		  /* Check whether obj is positive.  */
+		  if (PyObject_RichCompareBool (obj, zero, Py_GT) > 0)
+		    {
+		      ULONGEST ul;
+
+		      ul = PyLong_AsUnsignedLongLong (obj);
+		      if (! PyErr_Occurred ())
+			value = value_from_ulongest (builtin_type_upylong, ul);
+		    }
+		  else
+		    /* There's nothing we can do.  */
+		    PyErr_Restore (etype, evalue, etraceback);
+
+		  Py_DECREF (zero);
+		}
+	    }
+	  else
 	    value = value_from_longest (builtin_type_pylong, l);
 	}
       else if (PyFloat_Check (obj))
@@ -857,6 +888,14 @@ gdbpy_history (PyObject *self, PyObject *args)
   return value_to_value_object (res_val);
 }
 
+/* Returns 1 in OBJ is a gdb.Value object, 0 otherwise.  */
+
+int
+gdbpy_is_value_object (PyObject *obj)
+{
+  return PyObject_TypeCheck (obj, &value_object_type);
+}
+
 void
 gdbpy_initialize_values (void)
 {
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 590ac88..20b09ec 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -326,6 +326,241 @@ gdbpy_find_pc_function (PyObject *self, PyObject *args)
   Py_RETURN_NONE;
 }
 
+/* Adds GDB value V to the pattern buffer in *PATTERN_BUF.  If SIZE is not zero,
+   it specifies the number of bytes from V to copy to *PATTERN_BUF.  The
+   function increases the size of *PATTERN_BUF as necessary, adjusting
+   *PATTERN_BUF_END and *PATTERN_BUF_SIZE in the process.  */
+
+static void
+add_value_pattern (struct value *v, int size, char **pattern_buf,
+		   char **pattern_buf_end, ULONGEST *pattern_buf_size)
+{
+  int val_bytes;
+
+  if (size)
+    {
+      LONGEST x = value_as_long (v);
+
+      if (size == 1)
+	*(*pattern_buf_end)++ = x;
+      else
+	{
+	  put_bits (x, *pattern_buf_end, size * 8,
+		    gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_BIG);
+	  *pattern_buf_end += size;
+	}
+    }
+  else
+   {
+     val_bytes = TYPE_LENGTH (value_type (v));
+
+     increase_pattern_buffer (pattern_buf, pattern_buf_end,
+			      pattern_buf_size, val_bytes);
+
+     memcpy (*pattern_buf_end, value_contents_raw (v), val_bytes);
+     *pattern_buf_end += val_bytes;
+   }
+}
+
+/* This function does the actual work of constructing the pattern buffer from
+   OBJ.  If OBJ is an object which implements the read buffer protocol (such
+   as a string, a byte array or gdb.Membuf), then its contents are directly
+   copied to *PATTERN_BUF.  If it is a list, then this function is recursively
+   called for each of its elements.  If OBJ is an object which can be converted
+   to a GDB value, then the contents of the value are copied to PATTERN_BUF.
+   If SIZE is different than zero, then it limits the number of bytes which
+   are copied to the buffer in case OBJ is converted to a GDB value.  That
+   means that SIZE influences only Python scalars and gdb.Value objects.
+   The function increases the size of *PATTERN_BUF as necessary, adjusting
+   *PATTERN_BUF_END and *PATTERN_BUF_SIZE in the process.
+
+   Returns 1 on success or 0 on failure, with a Python exception set.  This
+   function can also throw GDB exceptions.  */
+
+static int
+add_pattern_element (PyObject *obj, int size, char **pattern_buf,
+		     char **pattern_buf_end, ULONGEST *pattern_buf_size)
+{
+  if (PyObject_CheckReadBuffer (obj))
+    {
+      /* Handle string, Unicode string, byte array, gdb.Membuf and any other
+         object implementing the buffer protocol.  The SIZE parameter is
+	 ignored in this case.  */
+
+      Py_ssize_t val_bytes;
+      const void *buffer;
+
+      if (PyObject_AsReadBuffer (obj, &buffer, &val_bytes) == -1)
+	return 0;
+
+      increase_pattern_buffer (pattern_buf, pattern_buf_end,
+			       pattern_buf_size, val_bytes);
+
+      memcpy (*pattern_buf_end, buffer, val_bytes);
+      *pattern_buf_end += val_bytes;
+    }
+  else if (gdbpy_is_value_object (obj))
+    add_value_pattern (value_object_to_value (obj), size, pattern_buf,
+		       pattern_buf_end, pattern_buf_size);


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


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

* [SCM]  archer-pmuldoon-pretty-printers-lookup: Merge commit 'origin/archer-tromey-python' into archer-pmuldoon-pretty-printers-lookup
@ 2009-02-16 14:40 pmuldoon
  0 siblings, 0 replies; 2+ messages in thread
From: pmuldoon @ 2009-02-16 14:40 UTC (permalink / raw)
  To: archer-commits

The branch, archer-pmuldoon-pretty-printers-lookup has been updated
       via  3820f99bc89734019da28d74dc52b76d717ecdb4 (commit)
       via  0d552e47e6b7b0f2b9f497064b80e978905b45c9 (commit)
       via  6d9b63ffb28e9810f374939ce9f3fc8611803719 (commit)
       via  85aee1e19b8da584293b25be3f093b8c0d4b0d76 (commit)
       via  56ce8a9af0d917bb7717e64ed9f5386ec64f9f22 (commit)
       via  c5d0304916ac571e2132b58d26aa11a330885a61 (commit)
       via  945aa667ba5a3418910aff5c5f5a50a0eb686510 (commit)
       via  fa51997c482ef5fb4176fa354883c9ddc27ec300 (commit)
       via  c2b0d851b102ddd8a49b43b35a43360642465d0a (commit)
       via  2036b77f54725a3ba90b7a6aee3fdccbb88ffb7c (commit)
       via  a069920b792fe697379cfd707316466e6765b552 (commit)
      from  04fb491450e24fba046c54a40169d82a37c980ed (commit)

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

- Log -----------------------------------------------------------------
commit 3820f99bc89734019da28d74dc52b76d717ecdb4
Merge: 04fb491450e24fba046c54a40169d82a37c980ed 0d552e47e6b7b0f2b9f497064b80e978905b45c9
Author: Phil Muldoon <pmuldoon@redhat.com>
Date:   Mon Feb 16 14:23:13 2009 +0000

    Merge commit 'origin/archer-tromey-python' into archer-pmuldoon-pretty-printers-lookup

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

Summary of changes:
 gdb/ChangeLog                                  |   70 +++++++++++++
 gdb/NEWS                                       |    2 +
 gdb/ada-lang.c                                 |    2 +-
 gdb/c-lang.c                                   |   45 +++++----
 gdb/doc/ChangeLog                              |   21 ++++
 gdb/doc/gdb.texinfo                            |  129 +++++++++++++++---------
 gdb/language.c                                 |    2 +-
 gdb/language.h                                 |    9 +-
 gdb/python/lib/gdb/command/alias.py            |    5 +-
 gdb/python/lib/gdb/command/backtrace.py        |    2 -
 gdb/python/lib/gdb/command/pahole.py           |    2 +-
 gdb/python/lib/gdb/command/save_breakpoints.py |    2 -
 gdb/python/python-cmd.c                        |   39 ++++----
 gdb/python/python-function.c                   |   12 +--
 gdb/python/python-value.c                      |  126 ++++++++++++-----------
 gdb/python/python.c                            |   15 ++-
 gdb/testsuite/ChangeLog                        |    5 +
 gdb/testsuite/gdb.python/python-function.exp   |   14 +++
 gdb/value.h                                    |    2 +-
 19 files changed, 330 insertions(+), 174 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 640998b..517b4f2 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,73 @@
+2009-02-08  Jim Blandy  <jimb@red-bean.com>
+
+	* python/python-value.c (convert_value_from_python):
+	Properly hand off GDB values returned by convenience
+	functions.
+
+2009-02-08  Thiago Jung Bauermann  <bauerman@br.ibm.com>
+
+	* python/python-value.c (convert_value_from_python): Change to throw
+	a Python exception instead of a GDB exception on error.
+	(valpy_new, valpy_getitem, valpy_binop, valpy_richcompare): Adapt to
+	new behaviour of convert_value_from_python.
+	* python/python-function.c (fnpy_call): Likewise.
+	* python/python.c (pretty_print_one_value, print_children): Likewise.
+	(apply_varobj_pretty_printer): Call gdbpy_print_stack if
+	pretty_print_one_value fails.
+
+2009-02-06  Thiago Jung Bauermann  <bauerman@br.ibm.com>
+
+	* python/python-cmd.c (gdbpy_initialize_commands): Rename COMMAND_
+	constants to match the actual help category to which they correspond.
+
+2009-02-05  Thiago Jung Bauermann  <bauerman@br.ibm.com>
+
+	* python/python-cmd.c (cmdpy_function): Convert command arguments to a
+	Unicode string.
+	(cmdpy_completer): Convert text and word arguments to a Unicode
+	string.
+	* python/lib/gdb/command/pahole.py (invoke): Raise a TypeError
+	exception instead of a (deprecated) string.
+
+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
+	type of the value.  Use the type variable instead of calling
+	value_type again.  Fix formatting issues.  Verify if *length > 0
+	before checking whether the last character is null.
+	* value.h (type_to_string): Remove extra space.
+
+2009-02-04  Thiago Jung Bauermann  <bauerman@br.ibm.com>
+
+	* ada-lang.c (ada_language_defn): Use c_get_string.
+	* c-lang.c (c_get_string): Remove static attribute.
+	(minimal_language_defn): Use c_get_string.
+	* language.h (c_get_string): Add prototype.
+
+2009-02-04  Thiago Jung Bauermann  <bauerman@br.ibm.com>
+
+	* c-lang.c (c_get_string): Change to return void.
+	* language.c (default_get_string): Likewise.
+	* language.h (language_defn): Change la_get_string member to return
+	void.
+	(default_get_string): Change prototype to return void.
+	* python/python-value.c (valpy_string): Adapt to new return type of
+	la_get_string.
+
 2009-02-03  Thiago Jung Bauermann  <bauerman@br.ibm.com>
 
 	* gdb/c-lang.c (c_get_string): Remove superfluous parenthesis from
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/ada-lang.c b/gdb/ada-lang.c
index dd40181..a44f0e3 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -11058,7 +11058,7 @@ const struct language_defn ada_language_defn = {
   ada_language_arch_info,
   ada_print_array_index,
   default_pass_by_reference,
-  default_get_string,
+  c_get_string,
   LANG_MAGIC
 };
 
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 7abd695..8b5410f 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -194,21 +194,15 @@ c_printstr (struct ui_file *stream, const gdb_byte *string,
    This means that a null byte present in a multi-byte character will not
    terminate the string unless the whole character is null.
 
-   Unless an exception is thrown, BUFFER will always be allocated, even on
-   failure.  In this case, some characters might have been read before the
-   failure happened.  Check LENGTH to recognize this situation.
+   CHARSET is always set to the target charset.  */
 
-   CHARSET is always set to the target charset.
-
-   Return 0 on success, errno on failure.  */
-
-static int
+void
 c_get_string (struct value *value, gdb_byte **buffer, int *length,
 	      const char **charset)
 {
   int err, width;
   unsigned int fetchlimit;
-  struct type *type = value_type (value);
+  struct type *type = check_typedef (value_type (value));
   struct type *element_type = TYPE_TARGET_TYPE (type);
 
   if (element_type == NULL)
@@ -230,7 +224,7 @@ c_get_string (struct value *value, gdb_byte **buffer, int *length,
       else
 	fetchlimit = UINT_MAX;
     }
-  else if (TYPE_CODE (value_type (value)) == TYPE_CODE_PTR)
+  else if (TYPE_CODE (type) == TYPE_CODE_PTR)
     fetchlimit = UINT_MAX;
   else
     /* We work only with arrays and pointers.  */
@@ -257,28 +251,37 @@ c_get_string (struct value *value, gdb_byte **buffer, int *length,
 
       /* Look for a null character.  */
       for (i = 0; i < fetchlimit; i++)
-	if (extract_unsigned_integer (contents + i*width, width) == 0)
+	if (extract_unsigned_integer (contents + i * width, width) == 0)
 	  break;
 
-      /* i is now either the number of non-null characters, or fetchlimit.  */
-      *length = i*width;
+      /* I is now either the number of non-null characters, or FETCHLIMIT.  */
+      *length = i * width;
       *buffer = xmalloc (*length);
       memcpy (*buffer, contents, *length);
       err = 0;
     }
   else
-    err = read_string (value_as_address (value), -1, width, fetchlimit,
-		       buffer, length);
+    {
+      err = read_string (value_as_address (value), -1, width, fetchlimit,
+			 buffer, length);
+      if (err)
+	{
+	  xfree (buffer);
+	  error (_("Error reading string from inferior: %s"),
+		 safe_strerror (err));
+	}
+    }
 
-  /* If the last character is null, subtract it from length.  */
-  if (extract_unsigned_integer (*buffer + *length - width, width) == 0)
-      *length -= width;
+  /* If the last character is null, subtract it from LENGTH.  */
+  if (*length > 0
+      && extract_unsigned_integer (*buffer + *length - width, width) == 0)
+    *length -= width;
 
   *charset = target_charset ();
 
-  return err;
+  return;
 
-error:
+ error:
   {
     char *type_str;
 
@@ -627,7 +630,7 @@ const struct language_defn minimal_language_defn =
   c_language_arch_info,
   default_print_array_index,
   default_pass_by_reference,
-  default_get_string,
+  c_get_string,
   LANG_MAGIC
 };
 
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index d807c50..b42d473 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,24 @@
+2009-02-06  Thiago Jung Bauermann  <bauerman@br.ibm.com>
+
+	* gdb.texinfo (Commands In Python):  Update names of COMMAND_
+	constants.
+
+2009-02-05  Thiago Jung Bauermann  <bauerman@br.ibm.com>
+
+	* gdb.texinfo (Values From Inferior): Better explain
+	Value.string's encoding argument.
+
+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
+	Eli Zaretskii.
+
 2009-01-29  Phil Muldoon  <pmuldoon@redhat.com>
 
 	* gdb.texinfo (Types From Inferior): Remove
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 144cd26..8d662b9 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -18428,12 +18428,14 @@ 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, 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.
+naming the encoding of the string in the @code{gdb.Value}, such as
+@code{"ascii"}, @code{"iso-8859-6"} or @code{"utf-8"}.  It accepts
+the same encodings as the corresponding argument to Python's
+@code{string.decode} method, and the Python codec machinery will be used
+to convert the string.  If @var{encoding} 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.
@@ -18921,8 +18923,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
@@ -18935,9 +18938,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
@@ -18948,19 +18950,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
@@ -18979,76 +18983,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
+@findex COMMAND_RUNNING
+@findex gdb.COMMAND_RUNNING
 @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
+@findex COMMAND_DATA
+@findex gdb.COMMAND_DATA
 @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
+@findex COMMAND_STATUS
+@findex gdb.COMMAND_STATUS
 @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
+@findex COMMAND_BREAKPOINTS
+@findex gdb.COMMAND_BREAKPOINTS
 @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
+@findex COMMAND_TRACEPOINTS
+@findex gdb.COMMAND_TRACEPOINTS
 @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
@@ -19065,6 +19101,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
@@ -19244,10 +19281,10 @@ class @code{gdb.Function}.
 
 @defmethod Function __init__ name
 The initializer for @code{Function} registers the new function with
-@value{GDBN}.  The @var{name} argument is the name of the function.
-This must be a string.  The function is made visible to the user as a
-convenience variable, of ``internal function'' type, whose name is the
-same as @var{name}.
+@value{GDBN}.  The argument @var{name} is the name of the function,
+a string.  The function will be visible to the user as a convenience
+variable of type @code{internal function}, whose name is the same as
+the given @var{name}.
 
 The documentation for the new function is taken from the documentation
 string for the new class.
diff --git a/gdb/language.c b/gdb/language.c
index 36198c3..3c37a64 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -1043,7 +1043,7 @@ default_print_array_index (struct value *index_value, struct ui_file *stream,
   fprintf_filtered (stream, "] = ");
 }
 
-int
+void
 default_get_string (struct value *value, gdb_byte **buffer, int *length,
 		    const char **charset)
 {
diff --git a/gdb/language.h b/gdb/language.h
index 46f8f34..85826fd 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -287,7 +287,7 @@ struct language_defn
        hold the size in bytes of the string (only actual characters, excluding
        an eventual terminating null character).  CHARSET will hold the encoding
        used in the string.  */
-    int (*la_get_string) (struct value *value, gdb_byte **buffer, int *length,
+    void (*la_get_string) (struct value *value, gdb_byte **buffer, int *length,
 			  const char **charset);
 
     /* Add fields above this point, so the magic number is always last. */
@@ -499,7 +499,10 @@ int default_pass_by_reference (struct type *type);
 void default_print_typedef (struct type *type, struct symbol *new_symbol,
 			    struct ui_file *stream);
 
-int default_get_string (struct value *value, gdb_byte **buffer, int *length,
-			const char **charset);
+void default_get_string (struct value *value, gdb_byte **buffer, int *length,
+			 const char **charset);
+
+void c_get_string (struct value *value, gdb_byte **buffer, int *length,
+		   const char **charset);
 


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


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

end of thread, other threads:[~2009-02-24  9:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-24  9:27 [SCM] archer-pmuldoon-pretty-printers-lookup: Merge commit 'origin/archer-tromey-python' into archer-pmuldoon-pretty-printers-lookup pmuldoon
  -- strict thread matches above, loose matches on Subject: below --
2009-02-16 14:40 pmuldoon

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).