summaryrefslogtreecommitdiffstats
path: root/gdb/testsuite/gdb.python/py-prettyprint.py
diff options
context:
space:
mode:
authorJoel Brobecker <brobecker@gnat.com>2009-09-09 17:45:42 +0000
committerJoel Brobecker <brobecker@gnat.com>2009-09-09 17:45:42 +0000
commit5172aecbd2b65e71aedbd21c46253ca6a20227aa (patch)
tree879124432741656573e3a6f6a4c7b3a9dfb2ca8a /gdb/testsuite/gdb.python/py-prettyprint.py
parentb83e9eb71cb4a21b31f8f47782da821a5a0ddb32 (diff)
downloadppe42-binutils-5172aecbd2b65e71aedbd21c46253ca6a20227aa.tar.gz
ppe42-binutils-5172aecbd2b65e71aedbd21c46253ca6a20227aa.zip
Checking in this patch for Thiago: Rename python-* files into py-*,
more 8+3 friendly. gdb/ * Makefile.in (py-cmd.o): Renamed from python-cmd.o. Updated references. (py-frame.o): Renamed from python-frame.o. Updated references. (py-function.o): Renamed from python-function.o. Updated references. (py-objfile.o): Renamed from python-objfile.o. Updated references. (py-prettyprint.o): Renamed from python-prettyprint.o. Updated +references. (py-type.o): Renamed from python-type.o. Updated references. (py-utils.o): Renamed from python-utils.o. Updated references. (py-value.o): Renamed from python-value.o. Updated references. * py-cmd.o: Renamed from python-cmd.o. * py-frame.o: Renamed from python-frame.o. * py-function.o: Renamed from python-function.o. * py-objfile.o: Renamed from python-objfile.o. * py-prettyprint.o: Renamed from python-prettyprint.o. * py-type.o: Renamed from python-type.o. * py-utils.o: Renamed from python-utils.o. * py-value.o: Renamed from python-value.o. gdb/testsuite/ * gdb.python/Makefile.in (EXECUTABLES): Adjust to new executable names, add missing ones. * gdb.python/py-cmd.exp: Rename from python-cmd.exp. * gdb.python/py-frame.c: Rename from python-frame.c. * gdb.python/py-frame.exp: Rename from python-frame.exp. Adjust testfile name. * gdb.python/py-function.exp: Rename from python-function.exp. * gdb.python/py-mi.exp: Rename from python-mi.exp. Adjust testfile name. * gdb.python/py-prettyprint.c: Rename from python-prettyprint.c. * gdb.python/py-prettyprint.exp: Rename from python-prettyprint.exp. Adjust testfile name. * gdb.python/py-prettyprint.py: Rename from python-prettyprint.py. * gdb.python/py-template.cc: Rename from python-template.cc. * gdb.python/py-template.exp: Rename from python-template.exp. Adjust testfile name. * gdb.python/py-value.c: Rename from python-value.c. * gdb.python/py-value.exp: Rename from python-value.exp. Adjust testfile name.
Diffstat (limited to 'gdb/testsuite/gdb.python/py-prettyprint.py')
-rw-r--r--gdb/testsuite/gdb.python/py-prettyprint.py166
1 files changed, 166 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.python/py-prettyprint.py b/gdb/testsuite/gdb.python/py-prettyprint.py
new file mode 100644
index 0000000000..bf009a1e6c
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-prettyprint.py
@@ -0,0 +1,166 @@
+# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# 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.
+
+import re
+
+# Test returning a Value from a printer.
+class string_print:
+ def __init__(self, val):
+ self.val = val
+
+ def to_string(self):
+ return self.val['whybother']['contents']
+
+# Test a class-based printer.
+class ContainerPrinter:
+ class _iterator:
+ def __init__ (self, pointer, len):
+ self.start = pointer
+ self.pointer = pointer
+ self.end = pointer + len
+
+ def __iter__(self):
+ return self
+
+ def next(self):
+ if self.pointer == self.end:
+ raise StopIteration
+ result = self.pointer
+ self.pointer = self.pointer + 1
+ return ('[%d]' % int (result - self.start), result.dereference())
+
+ def __init__(self, val):
+ self.val = val
+
+ def to_string(self):
+ return 'container %s with %d elements' % (self.val['name'], self.val['len'])
+
+ def children(self):
+ return self._iterator(self.val['elements'], self.val['len'])
+
+class pp_s:
+ def __init__(self, val):
+ self.val = val
+
+ def to_string(self):
+ a = self.val["a"]
+ b = self.val["b"]
+ if a.address != b:
+ raise Exception("&a(%s) != b(%s)" % (str(a.address), str(b)))
+ return " a=<" + str(self.val["a"]) + "> b=<" + str(self.val["b"]) + ">"
+
+class pp_ss:
+ def __init__(self, val):
+ self.val = val
+
+ def to_string(self):
+ return "a=<" + str(self.val["a"]) + "> b=<" + str(self.val["b"]) + ">"
+
+class pp_sss:
+ def __init__(self, val):
+ self.val = val
+
+ def to_string(self):
+ return "a=<" + str(self.val['a']) + "> b=<" + str(self.val["b"]) + ">"
+
+class pp_multiple_virtual:
+ def __init__ (self, val):
+ self.val = val
+
+ def to_string (self):
+ return "pp value variable is: " + str (self.val['value'])
+
+class pp_vbase1:
+ def __init__ (self, val):
+ self.val = val
+
+ def to_string (self):
+ return "pp class name: " + self.val.type.tag
+
+class pp_ns:
+ "Print a std::basic_string of some kind"
+
+ def __init__(self, val):
+ self.val = val
+
+ def to_string(self):
+ len = self.val['length']
+ return self.val['null_str'].string (gdb.parameter ('target-charset'), length = len)
+
+ def display_hint (self):
+ return 'string'
+
+def lookup_function (val):
+ "Look-up and return a pretty-printer that can print val."
+
+ # Get the type.
+ type = val.type;
+
+ # If it points to a reference, get the reference.
+ if type.code == gdb.TYPE_CODE_REF:
+ type = type.target ()
+
+ # Get the unqualified type, stripped of typedefs.
+ type = type.unqualified ().strip_typedefs ()
+
+ # Get the type name.
+ typename = type.tag
+
+ if typename == None:
+ return None
+
+ # Iterate over local dictionary of types to determine
+ # if a printer is registered for that type. Return an
+ # instantiation of the printer if found.
+ for function in pretty_printers_dict:
+ if function.match (typename):
+ return pretty_printers_dict[function] (val)
+
+ # Cannot find a pretty printer. Return None.
+
+ return None
+
+
+def register_pretty_printers ():
+ pretty_printers_dict[re.compile ('^struct s$')] = pp_s
+ pretty_printers_dict[re.compile ('^s$')] = pp_s
+ pretty_printers_dict[re.compile ('^S$')] = pp_s
+
+ pretty_printers_dict[re.compile ('^struct ss$')] = pp_ss
+ pretty_printers_dict[re.compile ('^ss$')] = pp_ss
+ pretty_printers_dict[re.compile ('^const S &$')] = pp_s
+ pretty_printers_dict[re.compile ('^SSS$')] = pp_sss
+
+ pretty_printers_dict[re.compile ('^VirtualTest$')] = pp_multiple_virtual
+ pretty_printers_dict[re.compile ('^Vbase1$')] = pp_vbase1
+
+ # Note that we purposely omit the typedef names here.
+ # Printer lookup is based on canonical name.
+ # However, we do need both tagged and untagged variants, to handle
+ # both the C and C++ cases.
+ pretty_printers_dict[re.compile ('^struct string_repr$')] = string_print
+ pretty_printers_dict[re.compile ('^struct container$')] = ContainerPrinter
+ pretty_printers_dict[re.compile ('^string_repr$')] = string_print
+ pretty_printers_dict[re.compile ('^container$')] = ContainerPrinter
+
+ pretty_printers_dict[re.compile ('^struct ns$')] = pp_ns
+ pretty_printers_dict[re.compile ('^ns$')] = pp_ns
+pretty_printers_dict = {}
+
+register_pretty_printers ()
+gdb.pretty_printers.append (lookup_function)
OpenPOWER on IntegriCloud