Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA, doc RFA] Implement $_memeq, $_streq, $_strlen
@ 2012-08-07 21:37 dje
  2012-08-08  7:11 ` Jan Kratochvil
  2012-08-08 16:44 ` Eli Zaretskii
  0 siblings, 2 replies; 14+ messages in thread
From: dje @ 2012-08-07 21:37 UTC (permalink / raw)
  To: gdb-patches

Hi.
I've had several requests for these and I'd like to finally get
these implemented.  And I've long wanted them myself.

Ok to check in?

2012-08-07  Doug Evans  <dje@google.com>

	Add $_memeq, $_streq, $_strlen convenience functions.
	* NEWS: Document them.
	* data-directory/Makefile.in (PYTHON_FILES): Add function/__init__.py,
	function/strfns.py.
	* python/py-type.c (typy_array_1): New function.
	(typy_array): Call it.
	(typy_vector): New function.
	(type_object_methods): Add "vector".
	* python/lib/gdb/function/__init__.py: New file.
	* python/lib/gdb/function/strfns.py: New file.

	doc/
	* gdb.texinfo (Convenience Funs): New node.
	(Types In Python): Document Type.vector.

	testsuite/
	* gdb.python/py-strfns.c: New file.
	* gdb.python/py-strfns.exp: New file.
	* gdb.python/py-type.exp (test_fields): Add vector tests.

Index: NEWS
===================================================================
RCS file: /cvs/src/src/gdb/NEWS,v
retrieving revision 1.538
diff -u -p -r1.538 NEWS
--- NEWS	6 Aug 2012 17:13:26 -0000	1.538
+++ NEWS	7 Aug 2012 21:32:53 -0000
@@ -3,6 +3,16 @@
 
 *** Changes since GDB 7.5
 
+* Python scripting
+
+  ** Vectors can be created with gdb.Type.vector.
+
+* New convenience functions:
+
+  ** $_memeq(buf1, buf2, length)
+  ** $_streq(str1, str2, length)
+  ** $_strlen(str)
+
 * The 'cd' command now defaults to using '~' (the home directory) if not
   given an argument.
 
Index: data-directory/Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/data-directory/Makefile.in,v
retrieving revision 1.11
diff -u -p -r1.11 Makefile.in
--- data-directory/Makefile.in	11 Apr 2012 05:50:44 -0000	1.11
+++ data-directory/Makefile.in	7 Aug 2012 21:20:29 -0000
@@ -59,7 +59,9 @@ PYTHON_FILES = \
 	gdb/command/__init__.py \
 	gdb/command/pretty_printers.py \
 	gdb/command/prompt.py \
-	gdb/command/explore.py
+	gdb/command/explore.py \
+	gdb/function/__init__.py \
+	gdb/function/strfns.py
 
 FLAGS_TO_PASS = \
 	"prefix=$(prefix)" \
Index: doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.998
diff -u -p -r1.998 gdb.texinfo
--- doc/gdb.texinfo	7 Aug 2012 01:11:02 -0000	1.998
+++ doc/gdb.texinfo	7 Aug 2012 21:20:30 -0000
@@ -7558,6 +7558,7 @@ being passed the type of @var{arg} as th
 * Pretty Printing::             Python pretty printing
 * Value History::               Value history
 * Convenience Vars::            Convenience variables
+* Convenience Funs::            Convenience functions
 * Registers::                   Registers
 * Floating Point Hardware::     Floating point hardware
 * Vector Unit::                 Vector Unit
@@ -9311,6 +9312,9 @@ On HP-UX systems, if you refer to a func
 begins with a dollar sign, @value{GDBN} searches for a user or system
 name first, before it searches for a convenience variable.
 
+@node Convenience Funs
+@section Convenience Functions
+
 @cindex convenience functions
 @value{GDBN} also supplies some @dfn{convenience functions}.  These
 have a syntax similar to convenience variables.  A convenience
@@ -9319,6 +9323,28 @@ however, a convenience function is imple
 @value{GDBN}.
 
 @table @code
+
+@item $_memeq(@var{buf1}, @var{buf2}, @var{length})
+@vindex $_memeq@r{, convenience function}
+Returns one if the @var{length} bytes at the addresses given by
+@var{buf1} and @var{buf2} are equal.
+Otherwise it returns zero.
+
+@item $_streq(@var{str1}, @var{str2})
+@vindex $_streq@r{, convenience function}
+Returns one if the @code{C} strings @var{str1} and @var{str2} are equal.
+Otherwise it returns zero.
+
+@item $_strlen(@var{str})
+@vindex $_strlen@r{, convenience function}
+Returns the length of @code{C} string @var{str}.
+
+@end table
+
+@value{GDBN} provides the ability to list and get help on
+convenience functions.
+
+@table @code
 @item help function
 @kindex help function
 @cindex show all convenience functions
@@ -23361,6 +23387,19 @@ second argument is the upper bound of th
 must not be negative, but the bounds can be.
 @end defun
 
+@defun Type.vector (@var{n1} @r{[}, @var{n2}@r{]})
+Return a new @code{gdb.Type} object which represents a vector of this
+type.  If one argument is given, it is the inclusive upper bound of
+the vector; in this case the lower bound is zero.  If two arguments are
+given, the first argument is the lower bound of the vector, and the
+second argument is the upper bound of the vector.  A vector's length
+must not be negative, but the bounds can be.
+
+The difference between an @code{array} and a @code{vector} is that
+arrays behave like in C: when used in expressions they decay to a pointer
+to the first element whereas vectors are treated as first class values.
+@end defun
+
 @defun Type.const ()
 Return a new @code{gdb.Type} object which represents a
 @code{const}-qualified variant of this type.
Index: python/py-type.c
===================================================================
RCS file: /cvs/src/src/gdb/python/py-type.c,v
retrieving revision 1.39
diff -u -p -r1.39 py-type.c
--- python/py-type.c	18 May 2012 21:02:52 -0000	1.39
+++ python/py-type.c	7 Aug 2012 21:20:31 -0000
@@ -461,10 +461,10 @@ typy_get_composite (struct type *type)
   return type;
 }
 
-/* Return an array type.  */
+/* Helper for typy_array and typy_vector.  */
 
 static PyObject *
-typy_array (PyObject *self, PyObject *args)
+typy_array_1 (PyObject *self, PyObject *args, int is_vector)
 {
   long n1, n2;
   PyObject *n2_obj = NULL;
@@ -503,12 +503,30 @@ typy_array (PyObject *self, PyObject *ar
   TRY_CATCH (except, RETURN_MASK_ALL)
     {
       array = lookup_array_range_type (type, n1, n2);
+      if (is_vector)
+	make_vector_type (array);
     }
   GDB_PY_HANDLE_EXCEPTION (except);
 
   return type_to_type_object (array);
 }
 
+/* Return an array type.  */
+
+static PyObject *
+typy_array (PyObject *self, PyObject *args)
+{
+  return typy_array_1 (self, args, 0);
+}
+
+/* Return a vector type.  */
+
+static PyObject *
+typy_vector (PyObject *self, PyObject *args)
+{
+  return typy_array_1 (self, args, 1);
+}
+
 /* Return a Type object which represents a pointer to SELF.  */
 static PyObject *
 typy_pointer (PyObject *self, PyObject *args)
@@ -1559,6 +1577,14 @@ static PyMethodDef type_object_methods[]
 Return a type which represents an array of objects of this type.\n\
 The bounds of the array are [LOW_BOUND, HIGH_BOUND] inclusive.\n\
 If LOW_BOUND is omitted, a value of zero is used." },
+  { "vector", typy_vector, METH_VARARGS,
+    "vector ([LOW_BOUND,] HIGH_BOUND) -> Type\n\
+Return a type which represents a vector of objects of this type.\n\
+The bounds of the array are [LOW_BOUND, HIGH_BOUND] inclusive.\n\
+If LOW_BOUND is omitted, a value of zero is used.\n\
+Vectors differ from arrays in that if the current language has C-style\n\
+arrays, vectors don't decay to a pointer to the first element.\n\
+They are first class values." },
    { "__contains__", typy_has_key, METH_VARARGS,
      "T.__contains__(k) -> True if T has a field named k, else False" },
   { "const", typy_const, METH_NOARGS,
Index: python/lib/gdb/function/__init__.py
===================================================================
RCS file: python/lib/gdb/function/__init__.py
diff -N python/lib/gdb/function/__init__.py
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ python/lib/gdb/function/__init__.py	7 Aug 2012 21:20:31 -0000
@@ -0,0 +1,14 @@
+# Copyright (C) 2012 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
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
Index: python/lib/gdb/function/strfns.py
===================================================================
RCS file: python/lib/gdb/function/strfns.py
diff -N python/lib/gdb/function/strfns.py
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ python/lib/gdb/function/strfns.py	7 Aug 2012 21:20:31 -0000
@@ -0,0 +1,91 @@
+# Useful gdb string convenience functions.
+# Copyright (C) 2012 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
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+"""$_memeq, $_strlen, $_streq"""
+
+import gdb
+
+
+class _MemEq(gdb.Function):
+  """$_memeq - compare bytes of memory
+
+Usage:
+  $_memeq(a, b, len)
+
+Returns:
+  True if len bytes at a and b compare equally.
+"""
+  def __init__(self):
+    super(_MemEq, self).__init__("_memeq")
+
+  def invoke(self, a, b, length):
+    if length < 0:
+      raise ValueError("length must be non-negative")
+    if length == 0:
+      return True
+    # The argument(s) to vector are [low_bound,]high_bound.
+    byte_vector = gdb.lookup_type("char").vector(length - 1)
+    ptr_byte_vector = byte_vector.pointer()
+    a_ptr = a.reinterpret_cast(ptr_byte_vector)
+    b_ptr = b.reinterpret_cast(ptr_byte_vector)
+    return a_ptr.dereference() == b_ptr.dereference()
+
+
+class _StrLen(gdb.Function):
+  """$_strlen - compute string length
+
+Usage:
+  $_strlen(a)
+
+Returns:
+  Length of string a, assumed to be a Nul-terminated C string.
+"""
+  def __init__(self):
+    super(_StrLen, self).__init__("_strlen")
+
+  def invoke(self, a):
+    # We don't care about the encoding here, per se.
+    # We just want a nul-terminated string where each byte is a character.
+    s = a.string("iso-8859-1")
+    return len(s)
+
+
+class _StrEq(gdb.Function):
+  """$_streq - check string equality
+
+Usage:
+  $_streq(a, b)
+
+Returns:
+  True if a and b are strings with the same length and the same characters.
+
+Example (amd64-linux):
+  catch syscall open
+  cond 1 $_streq((char*) $rdi, "foo")
+"""
+  def __init__(self):
+    super(_StrEq, self).__init__("_streq")
+
+  def invoke(self, a, b):
+    # We don't care about the encoding here, per se.
+    # We just want a nul-terminated string where each byte is a character.
+    return a.string("iso-8859-1") == b.string("iso-8859-1")
+
+
+# GDB will import us automagically via gdb/__init__.py.
+_MemEq()
+_StrLen()
+_StrEq()
Index: testsuite/gdb.python/py-strfns.c
===================================================================
RCS file: testsuite/gdb.python/py-strfns.c
diff -N testsuite/gdb.python/py-strfns.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gdb.python/py-strfns.c	7 Aug 2012 21:20:31 -0000
@@ -0,0 +1,50 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2012 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
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+const char str1[] = "Hello.";
+const char str2[] = "Hello.";
+const char str3[] = "Goodbye.";
+
+const char buf1[] = { 0, 1, 2, 3 };
+const char buf2[] = { 0, 1, 2, 3 };
+const char buf3[] = { 0, 1, 2, 4 };
+
+static void
+func (const char *arg)
+{
+  return; /* Break func here.  */
+}
+
+static void
+bfunc (const char *arg)
+{
+  return; /* Break bfunc here.  */
+}
+
+int
+main ()
+{
+  func (str1);
+  func (str2);
+  func (str3);
+
+  bfunc (buf1);
+  bfunc (buf2);
+  bfunc (buf3);
+
+  return 0;
+}
Index: testsuite/gdb.python/py-strfns.exp
===================================================================
RCS file: testsuite/gdb.python/py-strfns.exp
diff -N testsuite/gdb.python/py-strfns.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gdb.python/py-strfns.exp	7 Aug 2012 21:20:31 -0000
@@ -0,0 +1,53 @@
+# Copyright (C) 2012 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
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# This file is part of the GDB testsuite.  It tests the convenience
+# functions in strfns.py.
+
+load_lib gdb-python.exp
+
+standard_testfile
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
+    return -1
+}
+
+if ![runto_main] {
+    return 0
+}
+
+# Skip all tests if Python scripting is not enabled.
+if { [skip_python_tests] } { continue }
+
+gdb_test "p \$_streq (str1, str2)" " = 1"
+gdb_test "p \$_streq (str1, str3)" " = 0"
+
+gdb_test "p \$_strlen (str1)" " = 6"
+gdb_test "p \$_strlen (buf1)" " = 0"
+
+gdb_test "p \$_memeq (buf1, buf2, 4)" " = 1"
+gdb_test "p \$_memeq (buf1, buf3, 4)" " = 0"
+
+# Verify use in a conditional breakpoint.
+
+gdb_breakpoint [gdb_get_line_number "Break func here."]
+gdb_test_no_output "condition \$bpnum \$_streq (arg, \"Goodbye.\")"
+gdb_continue_to_breakpoint "Break func here."
+gdb_test "p arg" "= $hex <str3> \"Goodbye.\""
+
+gdb_breakpoint [gdb_get_line_number "Break bfunc here."]
+gdb_test_no_output "condition \$bpnum \$_memeq (arg, buf3, 4)"
+gdb_continue_to_breakpoint "Break bfunc here."
+gdb_test "p /d {char\[4\]} arg" "= \\{0, 1, 2, 4\\}"
Index: testsuite/gdb.python/py-type.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.python/py-type.exp,v
retrieving revision 1.24
diff -u -p -r1.24 py-type.exp
--- testsuite/gdb.python/py-type.exp	22 Jun 2012 17:59:33 -0000	1.24
+++ testsuite/gdb.python/py-type.exp	7 Aug 2012 21:20:31 -0000
@@ -114,12 +114,27 @@ proc test_fields {lang} {
   gdb_test "python print len(fields)" "1" "Check the number of fields"
   gdb_test "python print fields\[0\].type" "<range type>" "Check array field type"
 
+  # Test gdb.Type.array.
   gdb_test "python print ar\[0\].cast(ar\[0\].type.array(1))" \
       ".1, 2." "cast to array with one argument"
   gdb_test "python print ar\[0\].cast(ar\[0\].type.array(0, 1))" \
       ".1, 2." "cast to array with two arguments"
 
   gdb_test "python print ar\[0\].type == ar\[0\].type" "True"
+
+  # Test gdb.Type.vector.
+  # Note: vectors cast differently than arrays.  Here ar[0] is replicated
+  # for the size of the vector.
+  gdb_py_test_silent_cmd \
+      "python vec1 = ar\[0\].cast(ar\[0\].type.vector(1))" "set vec1" 1
+  gdb_test "python print vec1" ".1, 1." "cast to vector with one argument"
+  gdb_py_test_silent_cmd \
+      "python vec2 = ar\[0\].cast(ar\[0\].type.vector(0, 1))" "set vec2" 1
+  gdb_test "python print vec2" ".1, 1." "cast to vector with two arguments"
+  gdb_test "python print vec1 == vec2" "True"
+  gdb_py_test_silent_cmd \
+      "python vec3 = ar\[1\].cast(ar\[1\].type.vector(1))" "set vec3" 1
+  gdb_test "python print vec1 == vec3" "False"
 }
 
 proc test_enums {} {


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

* Re: [RFA, doc RFA] Implement $_memeq, $_streq, $_strlen
  2012-08-07 21:37 [RFA, doc RFA] Implement $_memeq, $_streq, $_strlen dje
@ 2012-08-08  7:11 ` Jan Kratochvil
  2012-08-08 16:44 ` Eli Zaretskii
  1 sibling, 0 replies; 14+ messages in thread
From: Jan Kratochvil @ 2012-08-08  7:11 UTC (permalink / raw)
  To: dje; +Cc: gdb-patches

Hello Doug,

On Tue, 07 Aug 2012 23:37:03 +0200, dje@google.com wrote:
> I've had several requests for these and I'd like to finally get
> these implemented.  And I've long wanted them myself.

FYI I commonly use also strstr.  (For example for long pathnames in function
parameters one can type just short substring.)

Unrelated is a problem that real (gnu-ifunc) strstr does not work in FSF GDB,
it is a glibc Bug currently only workarounded in Fedora GDB:
	http://pkgs.fedoraproject.org/cgit/gdb.git/tree/gdb-glibc-strstr-workaround.patch
	http://sourceware.org/bugzilla/show_bug.cgi?id=14166


Regards,
Jan


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

* Re: [RFA, doc RFA] Implement $_memeq, $_streq, $_strlen
  2012-08-07 21:37 [RFA, doc RFA] Implement $_memeq, $_streq, $_strlen dje
  2012-08-08  7:11 ` Jan Kratochvil
@ 2012-08-08 16:44 ` Eli Zaretskii
  2012-08-08 16:52   ` dje
  1 sibling, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2012-08-08 16:44 UTC (permalink / raw)
  To: dje; +Cc: gdb-patches

> Date: Tue, 07 Aug 2012 14:37:03 -0700
> From: dje@google.com
> 
> I've had several requests for these and I'd like to finally get
> these implemented.  And I've long wanted them myself.
> 
> Ok to check in?

The documentation parts are approved.  Thanks.


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

* Re: [RFA, doc RFA] Implement $_memeq, $_streq, $_strlen
  2012-08-08 16:44 ` Eli Zaretskii
@ 2012-08-08 16:52   ` dje
  2012-08-08 17:15     ` Jan Kratochvil
                       ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: dje @ 2012-08-08 16:52 UTC (permalink / raw)
  To: Eli Zaretskii, jan.kratochvil; +Cc: gdb-patches

Eli Zaretskii writes:
 > > Date: Tue, 07 Aug 2012 14:37:03 -0700
 > > From: dje@google.com
 > > 
 > > I've had several requests for these and I'd like to finally get
 > > these implemented.  And I've long wanted them myself.
 > > 
 > > Ok to check in?
 > 
 > The documentation parts are approved.  Thanks.

Thanks.
In response to Jan's strstr comment, I added $_regex.

2012-08-08  Doug Evans  <dje@google.com>

	Add $_memeq, $_regex, $_streq, $_strlen convenience functions.
	* NEWS: Document them.
	* data-directory/Makefile.in (PYTHON_FILES): Add function/__init__.py,
	function/strfns.py.
	* python/py-type.c (typy_array_1): New function.
	(typy_array): Call it.
	(typy_vector): New function.
	(type_object_methods): Add "vector".
	* python/lib/gdb/function/__init__.py: New file.
	* python/lib/gdb/function/strfns.py: New file.

	doc/
	* gdb.texinfo (Convenience Funs): New node.
	(Types In Python): Document Type.vector.

	testsuite/
	* gdb.python/py-strfns.c: New file.
	* gdb.python/py-strfns.exp: New file.
	* gdb.python/py-type.exp (test_fields): Add vector tests.

Index: NEWS
===================================================================
RCS file: /cvs/src/src/gdb/NEWS,v
retrieving revision 1.538
diff -u -p -r1.538 NEWS
--- NEWS	6 Aug 2012 17:13:26 -0000	1.538
+++ NEWS	8 Aug 2012 16:42:35 -0000
@@ -3,6 +3,17 @@
 
 *** Changes since GDB 7.5
 
+* Python scripting
+
+  ** Vectors can be created with gdb.Type.vector.
+
+* New Python-based convenience functions:
+
+  ** $_memeq(buf1, buf2, length)
+  ** $_streq(str1, str2)
+  ** $_strlen(str)
+  ** $_regex(str, regex)
+
 * The 'cd' command now defaults to using '~' (the home directory) if not
   given an argument.
 
Index: data-directory/Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/data-directory/Makefile.in,v
retrieving revision 1.11
diff -u -p -r1.11 Makefile.in
--- data-directory/Makefile.in	11 Apr 2012 05:50:44 -0000	1.11
+++ data-directory/Makefile.in	8 Aug 2012 16:42:35 -0000
@@ -59,7 +59,9 @@ PYTHON_FILES = \
 	gdb/command/__init__.py \
 	gdb/command/pretty_printers.py \
 	gdb/command/prompt.py \
-	gdb/command/explore.py
+	gdb/command/explore.py \
+	gdb/function/__init__.py \
+	gdb/function/strfns.py
 
 FLAGS_TO_PASS = \
 	"prefix=$(prefix)" \
Index: doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.998
diff -u -p -r1.998 gdb.texinfo
--- doc/gdb.texinfo	7 Aug 2012 01:11:02 -0000	1.998
+++ doc/gdb.texinfo	8 Aug 2012 16:42:36 -0000
@@ -7558,6 +7558,7 @@ being passed the type of @var{arg} as th
 * Pretty Printing::             Python pretty printing
 * Value History::               Value history
 * Convenience Vars::            Convenience variables
+* Convenience Funs::            Convenience functions
 * Registers::                   Registers
 * Floating Point Hardware::     Floating point hardware
 * Vector Unit::                 Vector Unit
@@ -9311,6 +9312,9 @@ On HP-UX systems, if you refer to a func
 begins with a dollar sign, @value{GDBN} searches for a user or system
 name first, before it searches for a convenience variable.
 
+@node Convenience Funs
+@section Convenience Functions
+
 @cindex convenience functions
 @value{GDBN} also supplies some @dfn{convenience functions}.  These
 have a syntax similar to convenience variables.  A convenience
@@ -9318,6 +9322,37 @@ function can be used in an expression ju
 however, a convenience function is implemented internally to
 @value{GDBN}.
 
+These functions require GDB to be configured with @code{Python} support.
+
+@table @code
+
+@item $_memeq(@var{buf1}, @var{buf2}, @var{length})
+@vindex $_memeq@r{, convenience function}
+Returns one if the @var{length} bytes at the addresses given by
+@var{buf1} and @var{buf2} are equal.
+Otherwise it returns zero.
+
+@item $_regex(@var{str}, @var{regex})
+@vindex $_regex@r{, convenience function}
+Returns one if the string @var{str} matches the regular expression
+@var{regex}.  Otherwise it returns zero.
+The syntax of the regular expression is that specified by @code{Python}'s
+regular expression support.
+
+@item $_streq(@var{str1}, @var{str2})
+@vindex $_streq@r{, convenience function}
+Returns one if the @code{C} strings @var{str1} and @var{str2} are equal.
+Otherwise it returns zero.
+
+@item $_strlen(@var{str})
+@vindex $_strlen@r{, convenience function}
+Returns the length of @code{C} string @var{str}.
+
+@end table
+
+@value{GDBN} provides the ability to list and get help on
+convenience functions.
+
 @table @code
 @item help function
 @kindex help function
@@ -23361,6 +23396,19 @@ second argument is the upper bound of th
 must not be negative, but the bounds can be.
 @end defun
 
+@defun Type.vector (@var{n1} @r{[}, @var{n2}@r{]})
+Return a new @code{gdb.Type} object which represents a vector of this
+type.  If one argument is given, it is the inclusive upper bound of
+the vector; in this case the lower bound is zero.  If two arguments are
+given, the first argument is the lower bound of the vector, and the
+second argument is the upper bound of the vector.  A vector's length
+must not be negative, but the bounds can be.
+
+The difference between an @code{array} and a @code{vector} is that
+arrays behave like in C: when used in expressions they decay to a pointer
+to the first element whereas vectors are treated as first class values.
+@end defun
+
 @defun Type.const ()
 Return a new @code{gdb.Type} object which represents a
 @code{const}-qualified variant of this type.
Index: python/py-type.c
===================================================================
RCS file: /cvs/src/src/gdb/python/py-type.c,v
retrieving revision 1.39
diff -u -p -r1.39 py-type.c
--- python/py-type.c	18 May 2012 21:02:52 -0000	1.39
+++ python/py-type.c	8 Aug 2012 16:42:36 -0000
@@ -461,10 +461,10 @@ typy_get_composite (struct type *type)
   return type;
 }
 
-/* Return an array type.  */
+/* Helper for typy_array and typy_vector.  */
 
 static PyObject *
-typy_array (PyObject *self, PyObject *args)
+typy_array_1 (PyObject *self, PyObject *args, int is_vector)
 {
   long n1, n2;
   PyObject *n2_obj = NULL;
@@ -503,12 +503,30 @@ typy_array (PyObject *self, PyObject *ar
   TRY_CATCH (except, RETURN_MASK_ALL)
     {
       array = lookup_array_range_type (type, n1, n2);
+      if (is_vector)
+	make_vector_type (array);
     }
   GDB_PY_HANDLE_EXCEPTION (except);
 
   return type_to_type_object (array);
 }
 
+/* Return an array type.  */
+
+static PyObject *
+typy_array (PyObject *self, PyObject *args)
+{
+  return typy_array_1 (self, args, 0);
+}
+
+/* Return a vector type.  */
+
+static PyObject *
+typy_vector (PyObject *self, PyObject *args)
+{
+  return typy_array_1 (self, args, 1);
+}
+
 /* Return a Type object which represents a pointer to SELF.  */
 static PyObject *
 typy_pointer (PyObject *self, PyObject *args)
@@ -1559,6 +1577,14 @@ static PyMethodDef type_object_methods[]
 Return a type which represents an array of objects of this type.\n\
 The bounds of the array are [LOW_BOUND, HIGH_BOUND] inclusive.\n\
 If LOW_BOUND is omitted, a value of zero is used." },
+  { "vector", typy_vector, METH_VARARGS,
+    "vector ([LOW_BOUND,] HIGH_BOUND) -> Type\n\
+Return a type which represents a vector of objects of this type.\n\
+The bounds of the array are [LOW_BOUND, HIGH_BOUND] inclusive.\n\
+If LOW_BOUND is omitted, a value of zero is used.\n\
+Vectors differ from arrays in that if the current language has C-style\n\
+arrays, vectors don't decay to a pointer to the first element.\n\
+They are first class values." },
    { "__contains__", typy_has_key, METH_VARARGS,
      "T.__contains__(k) -> True if T has a field named k, else False" },
   { "const", typy_const, METH_NOARGS,
Index: python/lib/gdb/function/__init__.py
===================================================================
RCS file: python/lib/gdb/function/__init__.py
diff -N python/lib/gdb/function/__init__.py
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ python/lib/gdb/function/__init__.py	8 Aug 2012 16:42:36 -0000
@@ -0,0 +1,14 @@
+# Copyright (C) 2012 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
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
Index: python/lib/gdb/function/strfns.py
===================================================================
RCS file: python/lib/gdb/function/strfns.py
diff -N python/lib/gdb/function/strfns.py
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ python/lib/gdb/function/strfns.py	8 Aug 2012 16:42:36 -0000
@@ -0,0 +1,111 @@
+# Useful gdb string convenience functions.
+# Copyright (C) 2012 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
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+"""$_memeq, $_strlen, $_streq, $_regex"""
+
+import gdb
+import re
+
+
+class _MemEq(gdb.Function):
+  """$_memeq - compare bytes of memory
+
+Usage:
+  $_memeq(a, b, len)
+
+Returns:
+  True if len bytes at a and b compare equally.
+"""
+  def __init__(self):
+    super(_MemEq, self).__init__("_memeq")
+
+  def invoke(self, a, b, length):
+    if length < 0:
+      raise ValueError("length must be non-negative")
+    if length == 0:
+      return True
+    # The argument(s) to vector are [low_bound,]high_bound.
+    byte_vector = gdb.lookup_type("char").vector(length - 1)
+    ptr_byte_vector = byte_vector.pointer()
+    a_ptr = a.reinterpret_cast(ptr_byte_vector)
+    b_ptr = b.reinterpret_cast(ptr_byte_vector)
+    return a_ptr.dereference() == b_ptr.dereference()
+
+
+class _StrLen(gdb.Function):
+  """$_strlen - compute string length
+
+Usage:
+  $_strlen(a)
+
+Returns:
+  Length of string a, assumed to be a Nul-terminated C string.
+"""
+  def __init__(self):
+    super(_StrLen, self).__init__("_strlen")
+
+  def invoke(self, a):
+    # We don't care about the encoding here, per se.
+    # We just want a nul-terminated string where each byte is a character.
+    s = a.string("iso-8859-1")
+    return len(s)
+
+
+class _StrEq(gdb.Function):
+  """$_streq - check string equality
+
+Usage:
+  $_streq(a, b)
+
+Returns:
+  True if a and b are strings with the same length and the same characters.
+
+Example (amd64-linux):
+  catch syscall open
+  cond 1 $_streq((char*) $rdi, "foo")
+"""
+  def __init__(self):
+    super(_StrEq, self).__init__("_streq")
+
+  def invoke(self, a, b):
+    # We don't care about the encoding here, per se.
+    # We just want a nul-terminated string where each byte is a character.
+    return a.string("iso-8859-1") == b.string("iso-8859-1")
+
+
+class _RegEx(gdb.Function):
+  """$_regex - check if a string matches a regular expression
+
+Usage:
+  $_regex(string, regex)
+
+Returns:
+  True if str matches the regular expression regex.
+"""
+  def __init__(self):
+    super(_RegEx, self).__init__("_regex")
+
+  def invoke(self, string, regex):
+    s = string.string()
+    r = re.compile(regex.string())
+    return bool(r.match(s))
+
+
+# GDB will import us automagically via gdb/__init__.py.
+_MemEq()
+_StrLen()
+_StrEq()
+_RegEx()
Index: testsuite/gdb.python/py-strfns.c
===================================================================
RCS file: testsuite/gdb.python/py-strfns.c
diff -N testsuite/gdb.python/py-strfns.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gdb.python/py-strfns.c	8 Aug 2012 16:42:36 -0000
@@ -0,0 +1,50 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2012 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
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+const char str1[] = "Hello.";
+const char str2[] = "Hello.";
+const char str3[] = "Goodbye.";
+
+const char buf1[] = { 0, 1, 2, 3 };
+const char buf2[] = { 0, 1, 2, 3 };
+const char buf3[] = { 0, 1, 2, 4 };
+
+static void
+func (const char *arg)
+{
+  return; /* Break func here.  */
+}
+
+static void
+bfunc (const char *arg)
+{
+  return; /* Break bfunc here.  */
+}
+
+int
+main ()
+{
+  func (str1);
+  func (str2);
+  func (str3);
+
+  bfunc (buf1);
+  bfunc (buf2);
+  bfunc (buf3);
+
+  return 0;
+}
Index: testsuite/gdb.python/py-strfns.exp
===================================================================
RCS file: testsuite/gdb.python/py-strfns.exp
diff -N testsuite/gdb.python/py-strfns.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gdb.python/py-strfns.exp	8 Aug 2012 16:42:36 -0000
@@ -0,0 +1,58 @@
+# Copyright (C) 2012 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
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# This file is part of the GDB testsuite.  It tests the convenience
+# functions in strfns.py.
+
+load_lib gdb-python.exp
+
+standard_testfile
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
+    return -1
+}
+
+if ![runto_main] {
+    return 0
+}
+
+# Skip all tests if Python scripting is not enabled.
+if { [skip_python_tests] } { continue }
+
+gdb_test "p \$_streq (str1, str2)" " = 1"
+gdb_test "p \$_streq (str1, str3)" " = 0"
+
+gdb_test "p \$_strlen (str1)" " = 6"
+gdb_test "p \$_strlen (buf1)" " = 0"
+
+gdb_test "p \$_memeq (buf1, buf2, 4)" " = 1"
+gdb_test "p \$_memeq (buf1, buf3, 4)" " = 0"
+
+gdb_test {p $_regex (str1, "Hello")} " = 1"
+gdb_test {p $_regex (str1, "Help")} " = 0"
+gdb_test {p $_regex (str1, "^Hello")} " = 1"
+gdb_test {p $_regex (str1, "^Hello.$")} " = 1"
+
+# Verify use in a conditional breakpoint.
+
+gdb_breakpoint [gdb_get_line_number "Break func here."]
+gdb_test_no_output "condition \$bpnum \$_streq (arg, \"Goodbye.\")"
+gdb_continue_to_breakpoint "Break func here."
+gdb_test "p arg" "= $hex <str3> \"Goodbye.\""
+
+gdb_breakpoint [gdb_get_line_number "Break bfunc here."]
+gdb_test_no_output "condition \$bpnum \$_memeq (arg, buf3, 4)"
+gdb_continue_to_breakpoint "Break bfunc here."
+gdb_test "p /d {char\[4\]} arg" "= \\{0, 1, 2, 4\\}"
Index: testsuite/gdb.python/py-type.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.python/py-type.exp,v
retrieving revision 1.24
diff -u -p -r1.24 py-type.exp
--- testsuite/gdb.python/py-type.exp	22 Jun 2012 17:59:33 -0000	1.24
+++ testsuite/gdb.python/py-type.exp	8 Aug 2012 16:42:36 -0000
@@ -114,12 +114,27 @@ proc test_fields {lang} {
   gdb_test "python print len(fields)" "1" "Check the number of fields"
   gdb_test "python print fields\[0\].type" "<range type>" "Check array field type"
 
+  # Test gdb.Type.array.
   gdb_test "python print ar\[0\].cast(ar\[0\].type.array(1))" \
       ".1, 2." "cast to array with one argument"
   gdb_test "python print ar\[0\].cast(ar\[0\].type.array(0, 1))" \
       ".1, 2." "cast to array with two arguments"
 
   gdb_test "python print ar\[0\].type == ar\[0\].type" "True"
+
+  # Test gdb.Type.vector.
+  # Note: vectors cast differently than arrays.  Here ar[0] is replicated
+  # for the size of the vector.
+  gdb_py_test_silent_cmd \
+      "python vec1 = ar\[0\].cast(ar\[0\].type.vector(1))" "set vec1" 1
+  gdb_test "python print vec1" ".1, 1." "cast to vector with one argument"
+  gdb_py_test_silent_cmd \
+      "python vec2 = ar\[0\].cast(ar\[0\].type.vector(0, 1))" "set vec2" 1
+  gdb_test "python print vec2" ".1, 1." "cast to vector with two arguments"
+  gdb_test "python print vec1 == vec2" "True"
+  gdb_py_test_silent_cmd \
+      "python vec3 = ar\[1\].cast(ar\[1\].type.vector(1))" "set vec3" 1
+  gdb_test "python print vec1 == vec3" "False"
 }
 
 proc test_enums {} {


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

* Re: [RFA, doc RFA] Implement $_memeq, $_streq, $_strlen
  2012-08-08 16:52   ` dje
@ 2012-08-08 17:15     ` Jan Kratochvil
  2012-08-08 17:36     ` Eli Zaretskii
  2012-08-08 18:00     ` Tom Tromey
  2 siblings, 0 replies; 14+ messages in thread
From: Jan Kratochvil @ 2012-08-08 17:15 UTC (permalink / raw)
  To: dje; +Cc: Eli Zaretskii, gdb-patches

On Wed, 08 Aug 2012 18:52:04 +0200, dje@google.com wrote:
> In response to Jan's strstr comment, I added $_regex.

A good idea, thanks.


Jan


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

* Re: [RFA, doc RFA] Implement $_memeq, $_streq, $_strlen
  2012-08-08 16:52   ` dje
  2012-08-08 17:15     ` Jan Kratochvil
@ 2012-08-08 17:36     ` Eli Zaretskii
       [not found]       ` <CADPb22Q7_232vwcQxjDVrYA1ngWZ1DbChb6oSGArz7RzmHMVgw@mail.gmail.com>
  2012-08-08 18:00     ` Tom Tromey
  2 siblings, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2012-08-08 17:36 UTC (permalink / raw)
  To: dje; +Cc: jan.kratochvil, gdb-patches

> Date: Wed, 8 Aug 2012 09:52:04 -0700
> Cc: gdb-patches@sourceware.org
> From: dje@google.com
> 
> In response to Jan's strstr comment, I added $_regex.

Here I have a couple of comments:

> +@item $_regex(@var{str}, @var{regex})
> +@vindex $_regex@r{, convenience function}
> +Returns one if the string @var{str} matches the regular expression
> +@var{regex}.  Otherwise it returns zero.
> +The syntax of the regular expression is that specified by @code{Python}'s
> +regular expression support.

I would suggest to say here that 'str' and 'regex' are both C strings,
as you say for $_strlen etc.  Otherwise, the reference to Python could
fool the reader into thinking they should be Python strings.

Btw, what is the technical reason we require Python for these
functions?

Finally, I think it's better to use @findex instead of @vindex
(since these are functions).  Sorry I missed that earlier.

Thanks.


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

* Re: [RFA, doc RFA] Implement $_memeq, $_streq, $_strlen
  2012-08-08 16:52   ` dje
  2012-08-08 17:15     ` Jan Kratochvil
  2012-08-08 17:36     ` Eli Zaretskii
@ 2012-08-08 18:00     ` Tom Tromey
       [not found]       ` <CADPb22SSM83g2tbBq2jpRj4SySwPS2Vqn-_5VxKYbvApV+VSMw@mail.gmail.com>
  2 siblings, 1 reply; 14+ messages in thread
From: Tom Tromey @ 2012-08-08 18:00 UTC (permalink / raw)
  To: dje; +Cc: Eli Zaretskii, jan.kratochvil, gdb-patches

>>>>> "Doug" == Douglas Evans <dje@google.com> writes:

Doug> +  ** $_memeq(buf1, buf2, length)
Doug> +  ** $_streq(str1, str2)

I don't really care, but I'm curious why you chose the eq forms instead
of the cmp forms.

[streq]
Doug> +    return a.string("iso-8859-1") == b.string("iso-8859-1")

I wonder whether this forces a constant string to inferior memory.
It would be nice to avoid that if possible.

The patch looks good, I think it is ok as-is.

Tom


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

* Re: [RFA, doc RFA] Implement $_memeq, $_streq, $_strlen
       [not found]       ` <CADPb22Q7_232vwcQxjDVrYA1ngWZ1DbChb6oSGArz7RzmHMVgw@mail.gmail.com>
@ 2012-08-08 18:14         ` Eli Zaretskii
  0 siblings, 0 replies; 14+ messages in thread
From: Eli Zaretskii @ 2012-08-08 18:14 UTC (permalink / raw)
  To: Doug Evans; +Cc: jan.kratochvil, gdb-patches

> Date: Wed, 8 Aug 2012 10:48:52 -0700
> From: Doug Evans <dje@google.com>
> Cc: jan.kratochvil@redhat.com, gdb-patches@sourceware.org
> 
> Hmm, maybe it would be better to remove the "C" reference (e.g., the
> current language could be something else).

If that works for strings in any language, then yes.  But please
mention that they are strings in the current language then.

> Btw, what is the technical reason we require Python for these
> > functions?
> >
> 
> There is none (beyond they're implemented in Python).

Sorry, I'm not following: we have strlen, regex, memcmp etc. in C as
well, don't we?

> If the v in vindex is for variables and f in findex is for functions,

They are.

> should these be using vindex?
> 
> @table @code
> @findex STDOUT
> @findex gdb.STDOUT
> @item gdb.STDOUT
> @value{GDBN}'s standard output stream.
> 
> @findex STDERR
> @findex gdb.STDERR
> @item gdb.STDERR
> @value{GDBN}'s standard error stream.
> 
> @findex STDLOG
> @findex gdb.STDLOG
> @item gdb.STDLOG
> @value{GDBN}'s log stream (@pxref{Logging Output}).
> @end table

Yes, they should be.


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

* Re: [RFA, doc RFA] Implement $_memeq, $_streq, $_strlen
       [not found]       ` <CADPb22SSM83g2tbBq2jpRj4SySwPS2Vqn-_5VxKYbvApV+VSMw@mail.gmail.com>
@ 2012-08-10  4:14         ` dje
  2012-08-10  6:39           ` Eli Zaretskii
  2012-08-11  8:08           ` Regression for gdb.base/default.exp: show convenience [Re: [RFA, doc RFA] Implement $_memeq, $_streq, $_strlen] Jan Kratochvil
  0 siblings, 2 replies; 14+ messages in thread
From: dje @ 2012-08-10  4:14 UTC (permalink / raw)
  To: Tom Tromey, Eli Zaretskii, jan.kratochvil; +Cc: gdb-patches

Here's, hopefully, my final revision.

Ok to check in?

2012-08-09  Doug Evans  <dje@google.com>

	Add $_memeq, $_regex, $_streq, $_strlen convenience functions.
	* NEWS: Document them.
	* data-directory/Makefile.in (PYTHON_FILES): Add function/__init__.py,
	function/strfns.py.
	* python/py-type.c (typy_array_1): New function.
	(typy_array): Call it.
	(typy_vector): New function.
	(type_object_methods): Add "vector".
	* python/lib/gdb/function/__init__.py: New file.
	* python/lib/gdb/function/strfns.py: New file.

	doc/
	* gdb.texinfo (Convenience Funs): New node.
	(Types In Python): Document Type.vector.

	testsuite/
	* gdb.python/py-strfns.c: New file.
	* gdb.python/py-strfns.exp: New file.
	* gdb.python/py-type.exp (test_fields): Add vector tests.

Index: NEWS
===================================================================
RCS file: /cvs/src/src/gdb/NEWS,v
retrieving revision 1.539
diff -u -p -r1.539 NEWS
--- NEWS	9 Aug 2012 12:53:43 -0000	1.539
+++ NEWS	10 Aug 2012 03:59:28 -0000
@@ -3,6 +3,17 @@
 
 *** Changes since GDB 7.5
 
+* Python scripting
+
+  ** Vectors can be created with gdb.Type.vector.
+
+* New Python-based convenience functions:
+
+  ** $_memeq(buf1, buf2, length)
+  ** $_streq(str1, str2)
+  ** $_strlen(str)
+  ** $_regex(str, regex)
+
 * The 'cd' command now defaults to using '~' (the home directory) if not
   given an argument.
 
Index: data-directory/Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/data-directory/Makefile.in,v
retrieving revision 1.11
diff -u -p -r1.11 Makefile.in
--- data-directory/Makefile.in	11 Apr 2012 05:50:44 -0000	1.11
+++ data-directory/Makefile.in	10 Aug 2012 03:59:28 -0000
@@ -59,7 +59,9 @@ PYTHON_FILES = \
 	gdb/command/__init__.py \
 	gdb/command/pretty_printers.py \
 	gdb/command/prompt.py \
-	gdb/command/explore.py
+	gdb/command/explore.py \
+	gdb/function/__init__.py \
+	gdb/function/strfns.py
 
 FLAGS_TO_PASS = \
 	"prefix=$(prefix)" \
Index: doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.999
diff -u -p -r1.999 gdb.texinfo
--- doc/gdb.texinfo	9 Aug 2012 12:53:44 -0000	1.999
+++ doc/gdb.texinfo	10 Aug 2012 03:59:30 -0000
@@ -7558,6 +7558,7 @@ being passed the type of @var{arg} as th
 * Pretty Printing::             Python pretty printing
 * Value History::               Value history
 * Convenience Vars::            Convenience variables
+* Convenience Funs::            Convenience functions
 * Registers::                   Registers
 * Floating Point Hardware::     Floating point hardware
 * Vector Unit::                 Vector Unit
@@ -9311,6 +9312,9 @@ On HP-UX systems, if you refer to a func
 begins with a dollar sign, @value{GDBN} searches for a user or system
 name first, before it searches for a convenience variable.
 
+@node Convenience Funs
+@section Convenience Functions
+
 @cindex convenience functions
 @value{GDBN} also supplies some @dfn{convenience functions}.  These
 have a syntax similar to convenience variables.  A convenience
@@ -9318,6 +9322,37 @@ function can be used in an expression ju
 however, a convenience function is implemented internally to
 @value{GDBN}.
 
+These functions require GDB to be configured with @code{Python} support.
+
+@table @code
+
+@item $_memeq(@var{buf1}, @var{buf2}, @var{length})
+@findex $_memeq@r{, convenience function}
+Returns one if the @var{length} bytes at the addresses given by
+@var{buf1} and @var{buf2} are equal.
+Otherwise it returns zero.
+
+@item $_regex(@var{str}, @var{regex})
+@findex $_regex@r{, convenience function}
+Returns one if the string @var{str} matches the regular expression
+@var{regex}.  Otherwise it returns zero.
+The syntax of the regular expression is that specified by @code{Python}'s
+regular expression support.
+
+@item $_streq(@var{str1}, @var{str2})
+@findex $_streq@r{, convenience function}
+Returns one if the strings @var{str1} and @var{str2} are equal.
+Otherwise it returns zero.
+
+@item $_strlen(@var{str})
+@findex $_strlen@r{, convenience function}
+Returns the length of string @var{str}.
+
+@end table
+
+@value{GDBN} provides the ability to list and get help on
+convenience functions.
+
 @table @code
 @item help function
 @kindex help function
@@ -23361,6 +23396,19 @@ second argument is the upper bound of th
 must not be negative, but the bounds can be.
 @end defun
 
+@defun Type.vector (@var{n1} @r{[}, @var{n2}@r{]})
+Return a new @code{gdb.Type} object which represents a vector of this
+type.  If one argument is given, it is the inclusive upper bound of
+the vector; in this case the lower bound is zero.  If two arguments are
+given, the first argument is the lower bound of the vector, and the
+second argument is the upper bound of the vector.  A vector's length
+must not be negative, but the bounds can be.
+
+The difference between an @code{array} and a @code{vector} is that
+arrays behave like in C: when used in expressions they decay to a pointer
+to the first element whereas vectors are treated as first class values.
+@end defun
+
 @defun Type.const ()
 Return a new @code{gdb.Type} object which represents a
 @code{const}-qualified variant of this type.
Index: python/py-type.c
===================================================================
RCS file: /cvs/src/src/gdb/python/py-type.c,v
retrieving revision 1.39
diff -u -p -r1.39 py-type.c
--- python/py-type.c	18 May 2012 21:02:52 -0000	1.39
+++ python/py-type.c	10 Aug 2012 03:59:30 -0000
@@ -461,10 +461,10 @@ typy_get_composite (struct type *type)
   return type;
 }
 
-/* Return an array type.  */
+/* Helper for typy_array and typy_vector.  */
 
 static PyObject *
-typy_array (PyObject *self, PyObject *args)
+typy_array_1 (PyObject *self, PyObject *args, int is_vector)
 {
   long n1, n2;
   PyObject *n2_obj = NULL;
@@ -503,12 +503,30 @@ typy_array (PyObject *self, PyObject *ar
   TRY_CATCH (except, RETURN_MASK_ALL)
     {
       array = lookup_array_range_type (type, n1, n2);
+      if (is_vector)
+	make_vector_type (array);
     }
   GDB_PY_HANDLE_EXCEPTION (except);
 
   return type_to_type_object (array);
 }
 
+/* Return an array type.  */
+
+static PyObject *
+typy_array (PyObject *self, PyObject *args)
+{
+  return typy_array_1 (self, args, 0);
+}
+
+/* Return a vector type.  */
+
+static PyObject *
+typy_vector (PyObject *self, PyObject *args)
+{
+  return typy_array_1 (self, args, 1);
+}
+
 /* Return a Type object which represents a pointer to SELF.  */
 static PyObject *
 typy_pointer (PyObject *self, PyObject *args)
@@ -1559,6 +1577,14 @@ static PyMethodDef type_object_methods[]
 Return a type which represents an array of objects of this type.\n\
 The bounds of the array are [LOW_BOUND, HIGH_BOUND] inclusive.\n\
 If LOW_BOUND is omitted, a value of zero is used." },
+  { "vector", typy_vector, METH_VARARGS,
+    "vector ([LOW_BOUND,] HIGH_BOUND) -> Type\n\
+Return a type which represents a vector of objects of this type.\n\
+The bounds of the array are [LOW_BOUND, HIGH_BOUND] inclusive.\n\
+If LOW_BOUND is omitted, a value of zero is used.\n\
+Vectors differ from arrays in that if the current language has C-style\n\
+arrays, vectors don't decay to a pointer to the first element.\n\
+They are first class values." },
    { "__contains__", typy_has_key, METH_VARARGS,
      "T.__contains__(k) -> True if T has a field named k, else False" },
   { "const", typy_const, METH_NOARGS,
Index: python/lib/gdb/function/__init__.py
===================================================================
RCS file: python/lib/gdb/function/__init__.py
diff -N python/lib/gdb/function/__init__.py
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ python/lib/gdb/function/__init__.py	10 Aug 2012 03:59:30 -0000
@@ -0,0 +1,14 @@
+# Copyright (C) 2012 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
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
Index: python/lib/gdb/function/strfns.py
===================================================================
RCS file: python/lib/gdb/function/strfns.py
diff -N python/lib/gdb/function/strfns.py
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ python/lib/gdb/function/strfns.py	10 Aug 2012 03:59:30 -0000
@@ -0,0 +1,108 @@
+# Useful gdb string convenience functions.
+# Copyright (C) 2012 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
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+"""$_memeq, $_strlen, $_streq, $_regex"""
+
+import gdb
+import re
+
+
+class _MemEq(gdb.Function):
+  """$_memeq - compare bytes of memory
+
+Usage:
+  $_memeq(a, b, len)
+
+Returns:
+  True if len bytes at a and b compare equally.
+"""
+  def __init__(self):
+    super(_MemEq, self).__init__("_memeq")
+
+  def invoke(self, a, b, length):
+    if length < 0:
+      raise ValueError("length must be non-negative")
+    if length == 0:
+      return True
+    # The argument(s) to vector are [low_bound,]high_bound.
+    byte_vector = gdb.lookup_type("char").vector(length - 1)
+    ptr_byte_vector = byte_vector.pointer()
+    a_ptr = a.reinterpret_cast(ptr_byte_vector)
+    b_ptr = b.reinterpret_cast(ptr_byte_vector)
+    return a_ptr.dereference() == b_ptr.dereference()
+
+
+class _StrLen(gdb.Function):
+  """$_strlen - compute string length
+
+Usage:
+  $_strlen(a)
+
+Returns:
+  Length of string a, assumed to be a string in the current language.
+"""
+  def __init__(self):
+    super(_StrLen, self).__init__("_strlen")
+
+  def invoke(self, a):
+    s = a.string()
+    return len(s)
+
+
+class _StrEq(gdb.Function):
+  """$_streq - check string equality
+
+Usage:
+  $_streq(a, b)
+
+Returns:
+  True if a and b are identical strings in the current language.
+
+Example (amd64-linux):
+  catch syscall open
+  cond $bpnum $_streq((char*) $rdi, "foo")
+"""
+  def __init__(self):
+    super(_StrEq, self).__init__("_streq")
+
+  def invoke(self, a, b):
+    return a.string() == b.string()
+
+
+class _RegEx(gdb.Function):
+  """$_regex - check if a string matches a regular expression
+
+Usage:
+  $_regex(string, regex)
+
+Returns:
+  True if string str (in the current language) matches the
+  regular expression regex.
+"""
+  def __init__(self):
+    super(_RegEx, self).__init__("_regex")
+
+  def invoke(self, string, regex):
+    s = string.string()
+    r = re.compile(regex.string())
+    return bool(r.match(s))
+
+
+# GDB will import us automagically via gdb/__init__.py.
+_MemEq()
+_StrLen()
+_StrEq()
+_RegEx()
Index: testsuite/gdb.python/py-strfns.c
===================================================================
RCS file: testsuite/gdb.python/py-strfns.c
diff -N testsuite/gdb.python/py-strfns.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gdb.python/py-strfns.c	10 Aug 2012 03:59:30 -0000
@@ -0,0 +1,50 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2012 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
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+const char str1[] = "Hello.";
+const char str2[] = "Hello.";
+const char str3[] = "Goodbye.";
+
+const char buf1[] = { 0, 1, 2, 3 };
+const char buf2[] = { 0, 1, 2, 3 };
+const char buf3[] = { 0, 1, 2, 4 };
+
+static void
+func (const char *arg)
+{
+  return; /* Break func here.  */
+}
+
+static void
+bfunc (const char *arg)
+{
+  return; /* Break bfunc here.  */
+}
+
+int
+main ()
+{
+  func (str1);
+  func (str2);
+  func (str3);
+
+  bfunc (buf1);
+  bfunc (buf2);
+  bfunc (buf3);
+
+  return 0;
+}
Index: testsuite/gdb.python/py-strfns.exp
===================================================================
RCS file: testsuite/gdb.python/py-strfns.exp
diff -N testsuite/gdb.python/py-strfns.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gdb.python/py-strfns.exp	10 Aug 2012 03:59:30 -0000
@@ -0,0 +1,103 @@
+# Copyright (C) 2012 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
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# This file is part of the GDB testsuite.  It tests the convenience
+# functions in strfns.py.
+
+load_lib gdb-python.exp
+
+standard_testfile
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
+    return -1
+}
+
+if ![runto_main] {
+    return 0
+}
+
+# Skip all tests if Python scripting is not enabled.
+if { [skip_python_tests] } { continue }
+
+proc test_all_strfns { } {
+    gdb_test "p \$_streq (str1, str2)" " = 1"
+    gdb_test "p \$_streq (str1, str3)" " = 0"
+
+    gdb_test "p \$_strlen (str1)" " = 6"
+    gdb_test "p \$_strlen (buf1)" " = 0"
+
+    gdb_test "p \$_memeq (buf1, buf2, 4)" " = 1"
+    gdb_test "p \$_memeq (buf1, buf3, 4)" " = 0"
+
+    gdb_test {p $_regex (str1, "Hello")} " = 1"
+    gdb_test {p $_regex (str1, "Help")} " = 0"
+    gdb_test {p $_regex (str1, "^Hello")} " = 1"
+    gdb_test {p $_regex (str1, "^Hello.$")} " = 1"
+}
+
+test_all_strfns
+
+# Verify use in a conditional breakpoint.
+
+gdb_breakpoint [gdb_get_line_number "Break func here."]
+gdb_test_no_output "condition \$bpnum \$_streq (arg, \"Goodbye.\")"
+gdb_continue_to_breakpoint "Break func here."
+gdb_test "p arg" "= $hex <str3> \"Goodbye.\""
+
+gdb_breakpoint [gdb_get_line_number "Break bfunc here."]
+gdb_test_no_output "condition \$bpnum \$_memeq (arg, buf3, 4)"
+gdb_continue_to_breakpoint "Break bfunc here."
+gdb_test "p /d {char\[4\]} arg" "= \\{0, 1, 2, 4\\}"
+
+# Verify use on a core file.
+
+proc test_strfns_core_file { } {
+    global objdir subdir gdb_prompt testfile
+
+    set filename "${objdir}/${subdir}/py-strfns.core"
+    set escapedfilename [string_to_regexp $filename]
+
+    gdb_test_multiple "gcore $filename" \
+	"save a corefile" \
+	{
+	    -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
+		pass "save a corefile"
+	    }
+	    -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
+		unsupported "save a corefile"
+		# No use proceeding from here.
+		return
+	    }
+	}
+
+    clean_restart $testfile
+
+    gdb_test_multiple "core $filename" \
+	"re-load generated corefile" \
+	{
+	    -re "Core was generated by .*$gdb_prompt $" {
+		pass "re-load generated corefile"
+	    }
+	    -re ".*$gdb_prompt $" {
+		fail "re-load generated corefile"
+		# No use proceeding from here.
+		return
+	    }
+	}
+
+    test_all_strfns
+}
+
+test_strfns_core_file
Index: testsuite/gdb.python/py-type.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.python/py-type.exp,v
retrieving revision 1.24
diff -u -p -r1.24 py-type.exp
--- testsuite/gdb.python/py-type.exp	22 Jun 2012 17:59:33 -0000	1.24
+++ testsuite/gdb.python/py-type.exp	10 Aug 2012 03:59:30 -0000
@@ -114,12 +114,27 @@ proc test_fields {lang} {
   gdb_test "python print len(fields)" "1" "Check the number of fields"
   gdb_test "python print fields\[0\].type" "<range type>" "Check array field type"
 
+  # Test gdb.Type.array.
   gdb_test "python print ar\[0\].cast(ar\[0\].type.array(1))" \
       ".1, 2." "cast to array with one argument"
   gdb_test "python print ar\[0\].cast(ar\[0\].type.array(0, 1))" \
       ".1, 2." "cast to array with two arguments"
 
   gdb_test "python print ar\[0\].type == ar\[0\].type" "True"
+
+  # Test gdb.Type.vector.
+  # Note: vectors cast differently than arrays.  Here ar[0] is replicated
+  # for the size of the vector.
+  gdb_py_test_silent_cmd \
+      "python vec1 = ar\[0\].cast(ar\[0\].type.vector(1))" "set vec1" 1
+  gdb_test "python print vec1" ".1, 1." "cast to vector with one argument"
+  gdb_py_test_silent_cmd \
+      "python vec2 = ar\[0\].cast(ar\[0\].type.vector(0, 1))" "set vec2" 1
+  gdb_test "python print vec2" ".1, 1." "cast to vector with two arguments"
+  gdb_test "python print vec1 == vec2" "True"
+  gdb_py_test_silent_cmd \
+      "python vec3 = ar\[1\].cast(ar\[1\].type.vector(1))" "set vec3" 1
+  gdb_test "python print vec1 == vec3" "False"
 }
 
 proc test_enums {} {


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

* Re: [RFA, doc RFA] Implement $_memeq, $_streq, $_strlen
  2012-08-10  4:14         ` dje
@ 2012-08-10  6:39           ` Eli Zaretskii
  2012-08-11  8:08           ` Regression for gdb.base/default.exp: show convenience [Re: [RFA, doc RFA] Implement $_memeq, $_streq, $_strlen] Jan Kratochvil
  1 sibling, 0 replies; 14+ messages in thread
From: Eli Zaretskii @ 2012-08-10  6:39 UTC (permalink / raw)
  To: dje; +Cc: tromey, jan.kratochvil, gdb-patches

> Date: Thu, 9 Aug 2012 21:14:24 -0700
> Cc: gdb-patches@sourceware.org
> From: dje@google.com
> 
> Here's, hopefully, my final revision.
> 
> Ok to check in?

Yes, with this final nit:

> +These functions require GDB to be configured with @code{Python} support.
                           ^^^
@value{GDBN}

Thanks.


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

* Regression for gdb.base/default.exp: show convenience  [Re: [RFA, doc RFA] Implement $_memeq, $_streq, $_strlen]
  2012-08-10  4:14         ` dje
  2012-08-10  6:39           ` Eli Zaretskii
@ 2012-08-11  8:08           ` Jan Kratochvil
  2012-08-11 17:46             ` dje
  1 sibling, 1 reply; 14+ messages in thread
From: Jan Kratochvil @ 2012-08-11  8:08 UTC (permalink / raw)
  To: dje; +Cc: Tom Tromey, Eli Zaretskii, gdb-patches

On Fri, 10 Aug 2012 06:14:24 +0200, dje@google.com wrote:
> Ok to check in?

96e5de1146522ad853b4cb51ff58fdad6ad79f7d is the first bad commit
commit 96e5de1146522ad853b4cb51ff58fdad6ad79f7d
Author: Doug Evans <dje@google.com>
Date:   Fri Aug 10 20:25:50 2012 +0000

    	Add $_memeq, $_regex, $_streq, $_strlen convenience functions.

-PASS: gdb.base/default.exp: show convenience
+FAIL: gdb.base/default.exp: show convenience ($_probe_arg0 = <error: No frame selected> not found)

It happens on all OSes/archs but only without --without-python.


Regards,
Jan


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

* Re: Regression for gdb.base/default.exp: show convenience  [Re: [RFA, doc RFA] Implement $_memeq, $_streq, $_strlen]
  2012-08-11  8:08           ` Regression for gdb.base/default.exp: show convenience [Re: [RFA, doc RFA] Implement $_memeq, $_streq, $_strlen] Jan Kratochvil
@ 2012-08-11 17:46             ` dje
  2012-08-11 17:54               ` Eli Zaretskii
  2012-08-11 19:24               ` Jan Kratochvil
  0 siblings, 2 replies; 14+ messages in thread
From: dje @ 2012-08-11 17:46 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: Tom Tromey, Eli Zaretskii, gdb-patches

Jan Kratochvil writes:
 > On Fri, 10 Aug 2012 06:14:24 +0200, dje@google.com wrote:
 > > Ok to check in?
 > 
 > 96e5de1146522ad853b4cb51ff58fdad6ad79f7d is the first bad commit
 > commit 96e5de1146522ad853b4cb51ff58fdad6ad79f7d
 > Author: Doug Evans <dje@google.com>
 > Date:   Fri Aug 10 20:25:50 2012 +0000
 > 
 >     	Add $_memeq, $_regex, $_streq, $_strlen convenience functions.
 > 
 > -PASS: gdb.base/default.exp: show convenience
 > +FAIL: gdb.base/default.exp: show convenience ($_probe_arg0 = <error: No frame selected> not found)
 > 
 > It happens on all OSes/archs but only without --without-python.

Blech.  I'm used to skimming over a (small) list of failures and this one got lost.
[Note to self: Finish installation of validate_failures.py.]

There are two ways to proceed here, based on the answer to this question: Does "show conv" include convenience functions?  I can argue either way, but I prefer it including functions, so I've updated the respective text.

Tested on amd64-linux with/without Python.
I will check this in in a few days if there are no objections.
[modulo doc RFA: Eli?]

btw, I changed "print $foo=1" to "set $foo=1" in the output of
"help show conv".  I think it's cleaner.

2012-08-11  Doug Evans  <dje@google.com>

	* value.c (show_convenience): Tweak comment.
	(_initialize_values): Mention convenience functions in the help text
	for "show convenience".

	doc/
	* gdb.texinfo (Convenience Vars): Update text for "show convenience"
	to include functions.

	testsuite/
	* gdb.base/default.exp: Update expected output of "show convenience".

Index: value.c
===================================================================
RCS file: /cvs/src/src/gdb/value.c,v
retrieving revision 1.160
diff -u -p -r1.160 value.c
--- value.c	13 Jun 2012 15:50:19 -0000	1.160
+++ value.c	11 Aug 2012 17:36:59 -0000
@@ -2255,11 +2255,17 @@ show_convenience (char *ignore, int from
       printf_filtered (("\n"));
     }
   if (!varseen)
-    printf_unfiltered (_("No debugger convenience variables now defined.\n"
-			 "Convenience variables have "
-			 "names starting with \"$\";\n"
-			 "use \"set\" as in \"set "
-			 "$foo = 5\" to define them.\n"));
+    {
+      /* This text does not mention convenience functions on purpose.
+	 The user can't create them except via Python, and if Python support
+	 is installed this message will never be printed ($_streq will
+	 exist).  */
+      printf_unfiltered (_("No debugger convenience variables now defined.\n"
+			   "Convenience variables have "
+			   "names starting with \"$\";\n"
+			   "use \"set\" as in \"set "
+			   "$foo = 5\" to define them.\n"));
+    }
 }
 \f
 /* Extract a value as a C number (either long or double).
@@ -3363,14 +3369,18 @@ void
 _initialize_values (void)
 {
   add_cmd ("convenience", no_class, show_convenience, _("\
-Debugger convenience (\"$foo\") variables.\n\
-These variables are created when you assign them values;\n\
-thus, \"print $foo=1\" gives \"$foo\" the value 1.  Values may be any type.\n\
+Debugger convenience (\"$foo\") variables and functions.\n\
+Convenience variables are created when you assign them values;\n\
+thus, \"set $foo=1\" gives \"$foo\" the value 1.  Values may be any type.\n\
 \n\
 A few convenience variables are given values automatically:\n\
 \"$_\"holds the last address examined with \"x\" or \"info lines\",\n\
-\"$__\" holds the contents of the last address examined with \"x\"."),
-	   &showlist);
+\"$__\" holds the contents of the last address examined with \"x\"."
+#ifdef HAVE_PYTHON
+"\n\n\
+Convenience functions are defined via the Python API."
+#endif
+	   ), &showlist);
 
   add_cmd ("values", no_set_class, show_values, _("\
 Elements of value history around item number IDX (or last ten)."),
Index: doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.1000
diff -u -p -r1.1000 gdb.texinfo
--- doc/gdb.texinfo	10 Aug 2012 20:25:56 -0000	1.1000
+++ doc/gdb.texinfo	11 Aug 2012 17:37:00 -0000
@@ -9225,9 +9225,10 @@ variable, when used as an expression, ha
 
 @table @code
 @kindex show convenience
-@cindex show all user variables
+@cindex show all user variables and functions
 @item show convenience
-Print a list of convenience variables used so far, and their values.
+Print a list of convenience variables used so far, and their values,
+as well as a list of the convenience functions.
 Abbreviated @code{show conv}.
 
 @kindex init-if-undefined
Index: testsuite/gdb.base/default.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/default.exp,v
retrieving revision 1.60
diff -u -p -r1.60 default.exp
--- testsuite/gdb.base/default.exp	7 Aug 2012 05:49:02 -0000	1.60
+++ testsuite/gdb.base/default.exp	11 Aug 2012 17:37:00 -0000
@@ -595,11 +595,10 @@ gdb_test "show complaints" "Max number o
 gdb_test "show confirm" "Whether to confirm potentially dangerous operations is o\[a-z\]*." "show confirm"
 
 #test show convenience
-# This is tricker as there are multiple internal convenience vars and we
-# can't assume any particular order.
-gdb_test_list_exact "show convenience" "show convenience" \
-    "\[^\r\n\]+\[\r\n\]+" \
-    "\[^\r\n\]+" \
+# This is trickier as there are multiple internal convenience vars and
+# functions and we can't assume any particular order.
+# And we have to handle the extra convenience funs provided by Python.
+set show_conv_list \
     { \
 	{$_sdata = void} \
 	{$_siginfo = void} \
@@ -618,6 +617,19 @@ gdb_test_list_exact "show convenience" "
 	{$_probe_arg10 = <error: No frame selected>} \
 	{$_probe_arg11 = <error: No frame selected>} \
     }
+if ![skip_python_tests] {
+    append show_conv_list \
+	{
+	    {$_memeq = <internal function _memeq>} \
+	    {$_regex = <internal function _regex>} \
+	    {$_streq = <internal function _streq>} \
+	    {$_strlen = <internal function _strlen>} \
+	}
+}
+gdb_test_list_exact "show convenience" "show convenience" \
+    "\[^\r\n\]+\[\r\n\]+" \
+    "\[^\r\n\]+" \
+    $show_conv_list
 
 #test show directories
 gdb_test "show directories" "Source directories searched: .cdir\[:;\].cwd" "show directories"


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

* Re: Regression for gdb.base/default.exp: show convenience  [Re: [RFA, doc RFA] Implement $_memeq, $_streq, $_strlen]
  2012-08-11 17:46             ` dje
@ 2012-08-11 17:54               ` Eli Zaretskii
  2012-08-11 19:24               ` Jan Kratochvil
  1 sibling, 0 replies; 14+ messages in thread
From: Eli Zaretskii @ 2012-08-11 17:54 UTC (permalink / raw)
  To: dje; +Cc: jan.kratochvil, tromey, gdb-patches

> Date: Sat, 11 Aug 2012 10:46:01 -0700
> Cc: Tom Tromey <tromey@redhat.com>,
>     Eli Zaretskii <eliz@gnu.org>,
>     gdb-patches@sourceware.org
> From: dje@google.com
> 
> I will check this in in a few days if there are no objections.
> [modulo doc RFA: Eli?]

No objections, thanks.


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

* Re: Regression for gdb.base/default.exp: show convenience  [Re: [RFA, doc RFA] Implement $_memeq, $_streq, $_strlen]
  2012-08-11 17:46             ` dje
  2012-08-11 17:54               ` Eli Zaretskii
@ 2012-08-11 19:24               ` Jan Kratochvil
  1 sibling, 0 replies; 14+ messages in thread
From: Jan Kratochvil @ 2012-08-11 19:24 UTC (permalink / raw)
  To: dje; +Cc: Tom Tromey, Eli Zaretskii, gdb-patches

On Sat, 11 Aug 2012 19:46:01 +0200, dje@google.com wrote:
> Tested on amd64-linux with/without Python.

Confirming it also works for me now.


Thanks,
Jan


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

end of thread, other threads:[~2012-08-11 19:24 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-07 21:37 [RFA, doc RFA] Implement $_memeq, $_streq, $_strlen dje
2012-08-08  7:11 ` Jan Kratochvil
2012-08-08 16:44 ` Eli Zaretskii
2012-08-08 16:52   ` dje
2012-08-08 17:15     ` Jan Kratochvil
2012-08-08 17:36     ` Eli Zaretskii
     [not found]       ` <CADPb22Q7_232vwcQxjDVrYA1ngWZ1DbChb6oSGArz7RzmHMVgw@mail.gmail.com>
2012-08-08 18:14         ` Eli Zaretskii
2012-08-08 18:00     ` Tom Tromey
     [not found]       ` <CADPb22SSM83g2tbBq2jpRj4SySwPS2Vqn-_5VxKYbvApV+VSMw@mail.gmail.com>
2012-08-10  4:14         ` dje
2012-08-10  6:39           ` Eli Zaretskii
2012-08-11  8:08           ` Regression for gdb.base/default.exp: show convenience [Re: [RFA, doc RFA] Implement $_memeq, $_streq, $_strlen] Jan Kratochvil
2012-08-11 17:46             ` dje
2012-08-11 17:54               ` Eli Zaretskii
2012-08-11 19:24               ` Jan Kratochvil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox