summaryrefslogtreecommitdiff
path: root/libstdc++-v3/python
diff options
context:
space:
mode:
authortromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2012-11-16 18:17:25 +0000
committertromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2012-11-16 18:17:25 +0000
commit0ed3336a547e85306b4424b97b9762dbe15db061 (patch)
treec77f1eede46fec5a355a7b3f04cf72736bb46a4c /libstdc++-v3/python
parentebf12ee0d18cf247956fa3f1e8a31de900ae55ee (diff)
downloadgcc-0ed3336a547e85306b4424b97b9762dbe15db061.tar.gz
* testsuite/libstdc++-prettyprinters/whatis.cc: New file.
* testsuite/lib/gdb-test.exp (whatis-test): New proc. (gdb-test): Handle 'whatis' tests. (gdb_batch_check): New proc. (gdb_version_check): Rewrite to use gdb_batch_check. * python/libstdcxx/v6/printers.py: Import gdb.types. (FilteringTypePrinter): New class. (add_one_type_printer, register_type_printers): New functions. (register_libstdcxx_printers): Call register_type_printers. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@193573 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/python')
-rw-r--r--libstdc++-v3/python/libstdcxx/v6/printers.py102
1 files changed, 102 insertions, 0 deletions
diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
index 5197284b017..294ec4cf3c9 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -26,6 +26,15 @@ try:
except ImportError:
_use_gdb_pp = False
+# Try to install type-printers.
+_use_type_printing = False
+try:
+ import gdb.types
+ if hasattr(gdb.types, 'TypePrinter'):
+ _use_type_printing = True
+except ImportError:
+ pass
+
# Starting with the type ORIG, search for the member type NAME. This
# handles searching upward through superclasses. This is needed to
# work around http://sourceware.org/bugzilla/show_bug.cgi?id=13615.
@@ -801,6 +810,97 @@ class Printer(object):
libstdcxx_printer = None
+class FilteringTypePrinter(object):
+ def __init__(self, match, name):
+ self.match = match
+ self.name = name
+ self.enabled = True
+
+ class _recognizer(object):
+ def __init__(self, match, name):
+ self.match = match
+ self.name = name
+ self.type_obj = None
+
+ def recognize(self, type_obj):
+ if type_obj.tag is None:
+ return None
+
+ if self.type_obj is None:
+ if not self.match in type_obj.tag:
+ # Filter didn't match.
+ return None
+ try:
+ self.type_obj = gdb.lookup_type(self.name).strip_typedefs()
+ except:
+ pass
+ if self.type_obj == type_obj:
+ return self.name
+ return None
+
+ def instantiate(self):
+ return self._recognizer(self.match, self.name)
+
+def add_one_type_printer(obj, match, name):
+ printer = FilteringTypePrinter(match, 'std::' + name)
+ gdb.types.register_type_printer(obj, printer)
+
+def register_type_printers(obj):
+ global _use_type_printing
+
+ if not _use_type_printing:
+ return
+
+ for pfx in ('', 'w'):
+ add_one_type_printer(obj, 'basic_string', pfx + 'string')
+ add_one_type_printer(obj, 'basic_ios', pfx + 'ios')
+ add_one_type_printer(obj, 'basic_streambuf', pfx + 'streambuf')
+ add_one_type_printer(obj, 'basic_istream', pfx + 'istream')
+ add_one_type_printer(obj, 'basic_ostream', pfx + 'ostream')
+ add_one_type_printer(obj, 'basic_iostream', pfx + 'iostream')
+ add_one_type_printer(obj, 'basic_stringbuf', pfx + 'stringbuf')
+ add_one_type_printer(obj, 'basic_istringstream',
+ pfx + 'istringstream')
+ add_one_type_printer(obj, 'basic_ostringstream',
+ pfx + 'ostringstream')
+ add_one_type_printer(obj, 'basic_stringstream',
+ pfx + 'stringstream')
+ add_one_type_printer(obj, 'basic_filebuf', pfx + 'filebuf')
+ add_one_type_printer(obj, 'basic_ifstream', pfx + 'ifstream')
+ add_one_type_printer(obj, 'basic_ofstream', pfx + 'ofstream')
+ add_one_type_printer(obj, 'basic_fstream', pfx + 'fstream')
+ add_one_type_printer(obj, 'basic_regex', pfx + 'regex')
+ add_one_type_printer(obj, 'sub_match', pfx + 'csub_match')
+ add_one_type_printer(obj, 'sub_match', pfx + 'ssub_match')
+ add_one_type_printer(obj, 'match_results', pfx + 'cmatch')
+ add_one_type_printer(obj, 'match_results', pfx + 'smatch')
+ add_one_type_printer(obj, 'regex_iterator', pfx + 'cregex_iterator')
+ add_one_type_printer(obj, 'regex_iterator', pfx + 'sregex_iterator')
+ add_one_type_printer(obj, 'regex_token_iterator',
+ pfx + 'cregex_token_iterator')
+ add_one_type_printer(obj, 'regex_token_iterator',
+ pfx + 'sregex_token_iterator')
+
+ # Note that we can't have a printer for std::wstreampos, because
+ # it shares the same underlying type as std::streampos.
+ add_one_type_printer(obj, 'fpos', 'streampos')
+ add_one_type_printer(obj, 'basic_string', 'u16string')
+ add_one_type_printer(obj, 'basic_string', 'u32string')
+
+ for dur in ('nanoseconds', 'microseconds', 'milliseconds',
+ 'seconds', 'minutes', 'hours'):
+ add_one_type_printer(obj, 'duration', dur)
+
+ add_one_type_printer(obj, 'linear_congruential_engine', 'minstd_rand0')
+ add_one_type_printer(obj, 'linear_congruential_engine', 'minstd_rand')
+ add_one_type_printer(obj, 'mersenne_twister_engine', 'mt19937')
+ add_one_type_printer(obj, 'mersenne_twister_engine', 'mt19937_64')
+ add_one_type_printer(obj, 'subtract_with_carry_engine', 'ranlux24_base')
+ add_one_type_printer(obj, 'subtract_with_carry_engine', 'ranlux48_base')
+ add_one_type_printer(obj, 'discard_block_engine', 'ranlux24')
+ add_one_type_printer(obj, 'discard_block_engine', 'ranlux48')
+ add_one_type_printer(obj, 'shuffle_order_engine', 'knuth_b')
+
def register_libstdcxx_printers (obj):
"Register libstdc++ pretty-printers with objfile Obj."
@@ -814,6 +914,8 @@ def register_libstdcxx_printers (obj):
obj = gdb
obj.pretty_printers.append(libstdcxx_printer)
+ register_type_printers(obj)
+
def build_libstdcxx_dictionary ():
global libstdcxx_printer