This is the mail archive of the archer@sourceware.org mailing list for the Archer project.


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

Re: bokenness of nested pretty printers


On Fri, Oct 17, 2008 at 11:56 AM, Tom Tromey <tromey@redhat.com> wrote:

> Paul> It doesn't fix the array test case (print ssa). Below is proposed
> Paul> patch to fix that.
>
> Thanks, please check this in.

Done and pushed.

Attached is a proposed starting point for pretty-printer tests.
OK?

-- 
Paul Pluzhnikov


2008-10-17  Paul Pluzhnikov  <ppluzhnikov@google.com>
	
	* gdb.python/python-prettyprint.{c,exp,py}: New test for
	pretty printing.

diff --git a/gdb/testsuite/gdb.python/python-prettyprint.c
b/gdb/testsuite/gdb.python/python-prettyprint.c
new file mode 100644
index 0000000..90883cf
--- /dev/null
+++ b/gdb/testsuite/gdb.python/python-prettyprint.c
@@ -0,0 +1,52 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2008 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/>.  */
+
+struct s
+{
+  int a;
+  int *b;
+};
+
+struct ss
+{
+  struct s a;
+  struct s b;
+};
+
+void init_s(struct s *s, int a)
+{
+  s->a = a;
+  s->b = &s->a;
+}
+
+void init_ss(struct ss *s, int a, int b)
+{
+  init_s(&s->a, a);
+  init_s(&s->b, b);
+}
+
+int
+main ()
+{
+  struct ss  ss;
+  struct ss  ssa[2];
+
+  init_ss(&ss, 1, 2);
+  init_ss(ssa+0, 3, 4);
+  init_ss(ssa+1, 5, 6);
+  return 0;      /* break to inspect struct and union */
+}
diff --git a/gdb/testsuite/gdb.python/python-prettyprint.exp
b/gdb/testsuite/gdb.python/python-prettyprint.exp
new file mode 100644
index 0000000..c36289a
--- /dev/null
+++ b/gdb/testsuite/gdb.python/python-prettyprint.exp
@@ -0,0 +1,60 @@
+# Copyright (C) 2008 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 mechanism
+# exposing values to Python.
+
+if $tracelevel then {
+    strace $tracelevel
+}
+
+set testfile "python-prettyprint"
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}"
executable {debug}] != "" } {
+    untested "Couldn't compile ${srcfile}"
+    return -1
+}
+
+
+# Start with a fresh gdb.
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+gdb_test_multiple "python print 'hello, world!'" "verify python support" {
+    -re "not supported.*$gdb_prompt $"	{
+      unsupported "python support is disabled"
+      return -1
+    }
+    -re "$gdb_prompt $"	{}
+}
+
+if ![runto_main ] then {
+    perror "couldn't run to breakpoint"
+    return
+}
+
+gdb_test "b [gdb_get_line_number {break to inspect} ${testfile}.c ]" \
+	 ".*Breakpoint.*"
+gdb_test "continue" ".*Breakpoint.*"
+
+gdb_test "source ${srcdir}/${subdir}/${testfile}.py" ""
+
+gdb_test "print ss" " = a=< a=<1> b=<$hex>> b=< a=<2> b=<$hex>>"
+gdb_test "print ssa\[1\]" " = a=< a=<5> b=<$hex>> b=< a=<6> b=<$hex>>"
+gdb_test "print ssa" " = {a=< a=<3> b=<$hex>> b=< a=<4> b=<$hex>>,
a=< a=<5> b=<$hex>> b=< a=<6> b=<$hex>>}"
diff --git a/gdb/testsuite/gdb.python/python-prettyprint.py
b/gdb/testsuite/gdb.python/python-prettyprint.py
new file mode 100644
index 0000000..42f79f6
--- /dev/null
+++ b/gdb/testsuite/gdb.python/python-prettyprint.py
@@ -0,0 +1,32 @@
+# Copyright (C) 2008 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 python pretty
+# printers.
+
+python
+
+def pp_s(val):
+  a = val["a"]
+  b = val["b"]
+  if a.address() != b:
+    raise Exception("&a(%s) != b(%s)" % (str(a.address()), str(b)))
+  return " a=<" + str(val["a"]) + "> b=<" + str(val["b"]) + ">"
+
+def pp_ss(val):
+  return "a=<" + str(val["a"]) + "> b=<" + str(val["b"]) + ">"
+
+gdb.cli_pretty_printers['^struct s$']   = pp_s
+gdb.cli_pretty_printers['^struct ss$']  = pp_ss


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