-# Copyright (C) 2008-2012 Free Software Foundation, Inc.
+# Copyright (C) 2008-2015 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
import re
import gdb
+def _iterator (pointer, len):
+ start = pointer
+ end = pointer + len
+ while pointer != end:
+ yield ('[%d]' % int (pointer - start), pointer.dereference())
+ pointer += 1
+
+# Same as _iterator but can be told to raise an exception.
+def _iterator_except (pointer, len):
+ start = pointer
+ end = pointer + len
+ while pointer != end:
+ if exception_flag:
+ raise gdb.MemoryError ('hi bob')
+ yield ('[%d]' % int (pointer - start), pointer.dereference())
+ pointer += 1
+
# Test returning a Value from a printer.
-class string_print:
+class string_print (object):
def __init__(self, val):
self.val = val
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())
+class ContainerPrinter (object):
def __init__(self, val):
self.val = val
return 'container %s with %d elements' % (self.val['name'], self.val['len'])
def children(self):
- return self._iterator(self.val['elements'], self.val['len'])
+ return _iterator(self.val['elements'], self.val['len'])
+
+# Treats a container as array.
+class ArrayPrinter (object):
+ def __init__(self, val):
+ self.val = val
+
+ def to_string(self):
+ return 'array %s with %d elements' % (self.val['name'], self.val['len'])
+
+ def children(self):
+ return _iterator(self.val['elements'], self.val['len'])
+
+ def display_hint (self):
+ return 'array'
# Flag to make NoStringContainerPrinter throw an exception.
exception_flag = False
# Test a printer where to_string is None
-class NoStringContainerPrinter:
- 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
- if exception_flag:
- raise gdb.MemoryError, 'hi bob'
- result = self.pointer
- self.pointer = self.pointer + 1
- return ('[%d]' % int (result - self.start), result.dereference())
-
+class NoStringContainerPrinter (object):
def __init__(self, val):
self.val = val
return None
def children(self):
- return self._iterator(self.val['elements'], self.val['len'])
+ return _iterator_except (self.val['elements'], self.val['len'])
-class pp_s:
+class pp_s (object):
def __init__(self, val):
self.val = val
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:
+class pp_ss (object):
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:
+class pp_sss (object):
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:
+class pp_multiple_virtual (object):
def __init__ (self, val):
self.val = val
def to_string (self):
return "pp value variable is: " + str (self.val['value'])
-class pp_vbase1:
+class pp_vbase1 (object):
def __init__ (self, val):
self.val = val
def to_string (self):
return "pp class name: " + self.val.type.tag
-class pp_nullstr:
+class pp_nullstr (object):
def __init__(self, val):
self.val = val
def to_string(self):
return self.val['s'].string(gdb.target_charset())
-class pp_ns:
+class pp_ns (object):
"Print a std::basic_string of some kind"
def __init__(self, val):
pp_ls_encoding = None
-class pp_ls:
+class pp_ls (object):
"Print a std::basic_string of some kind"
def __init__(self, val):
def display_hint (self):
return 'string'
-class pp_hint_error:
+class pp_hint_error (object):
"Throw error from display_hint"
def __init__(self, val):
def display_hint (self):
raise Exception("hint failed")
-class pp_children_as_list:
+class pp_children_as_list (object):
"Throw error from display_hint"
def __init__(self, val):
def children (self):
return [('one', 1)]
-class pp_outer:
+class pp_outer (object):
"Print struct outer"
def __init__ (self, val):
yield 's', self.val['s']
yield 'x', self.val['x']
-class MemoryErrorString:
+class MemoryErrorString (object):
"Raise an error"
def __init__(self, val):
self.val = val
def to_string(self):
- raise gdb.MemoryError ("Cannot access memory.");
+ raise gdb.MemoryError ("Cannot access memory.")
def display_hint (self):
return 'string'
-class pp_eval_type:
+class pp_eval_type (object):
def __init__(self, val):
self.val = val
def to_string(self):
- gdb.execute("bt", to_string=True)
+ gdb.execute("bt", to_string=True)
return "eval=<" + str(gdb.parse_and_eval("eval_func (123456789, 2, 3, 4, 5, 6, 7, 8)")) + ">"
def lookup_function (val):