diff options
author | Siva Chandra Reddy <sivachandra@google.com> | 2014-09-10 13:18:04 +0000 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2014-09-10 14:18:04 +0100 |
commit | e9e08827bf931aba511a928a0feccbc328f2a927 (patch) | |
tree | 99b6859d870823eec6a19c39fa4d7c997524e91b /libstdc++-v3/python | |
parent | f15b287f2dcdf5284a2abb3e5c727f26c11cc064 (diff) | |
download | gcc-e9e08827bf931aba511a928a0feccbc328f2a927.tar.gz |
hook.in: Load the xmethods.
2014-09-10 Siva Chandra Reddy <sivachandra@google.com>
* python/hook.in: Load the xmethods.
* python/Makefile.am (nobase_python_DATA): Add xmethods.py.
* python/Makefile.in: Regenerated.
* python/libstdcxx/v6/xmethods.py: New file.
* testsuite/lib/gdb-test.exp (gdb_version_check_xmethods): New
function.
(gdb-test): New optional argument LOAD_XMETHODS. Load xmethods
python script if LOAD_XMETHODS is true.
* testsuite/libstdc++-xmethods/unique_ptr.cc: New file.
* testsuite/libstdc++-xmethods/vector.cc: New file.
* testsuite/libstdc++-xmethods/xmethods.exp: New file.
From-SVN: r215128
Diffstat (limited to 'libstdc++-v3/python')
-rw-r--r-- | libstdc++-v3/python/Makefile.am | 1 | ||||
-rw-r--r-- | libstdc++-v3/python/Makefile.in | 1 | ||||
-rw-r--r-- | libstdc++-v3/python/hook.in | 12 | ||||
-rw-r--r-- | libstdc++-v3/python/libstdcxx/v6/xmethods.py | 103 |
4 files changed, 117 insertions, 0 deletions
diff --git a/libstdc++-v3/python/Makefile.am b/libstdc++-v3/python/Makefile.am index ac7341a2806..c34c8609873 100644 --- a/libstdc++-v3/python/Makefile.am +++ b/libstdc++-v3/python/Makefile.am @@ -33,6 +33,7 @@ all-local: gdb.py nobase_python_DATA = \ libstdcxx/v6/printers.py \ + libstdcxx/v6/xmethods.py \ libstdcxx/v6/__init__.py \ libstdcxx/__init__.py diff --git a/libstdc++-v3/python/Makefile.in b/libstdc++-v3/python/Makefile.in index 21d74a90930..7d0c8ac413e 100644 --- a/libstdc++-v3/python/Makefile.in +++ b/libstdc++-v3/python/Makefile.in @@ -316,6 +316,7 @@ AM_CPPFLAGS = $(GLIBCXX_INCLUDES) @ENABLE_PYTHONDIR_TRUE@pythondir = $(prefix)/$(python_mod_dir) nobase_python_DATA = \ libstdcxx/v6/printers.py \ + libstdcxx/v6/xmethods.py \ libstdcxx/v6/__init__.py \ libstdcxx/__init__.py diff --git a/libstdc++-v3/python/hook.in b/libstdc++-v3/python/hook.in index 3620523b595..aeb1cdbc91a 100644 --- a/libstdc++-v3/python/hook.in +++ b/libstdc++-v3/python/hook.in @@ -58,3 +58,15 @@ if gdb.current_objfile () is not None: # Load the pretty-printers. from libstdcxx.v6.printers import register_libstdcxx_printers register_libstdcxx_printers (gdb.current_objfile ()) + +# Load the xmethods if GDB supports them. +def gdb_has_xmethods(): + try: + import gdb.xmethod + return True + except ImportError: + return False + +if gdb_has_xmethods(): + from libstdcxx.v6.xmethods import register_libstdcxx_xmethods + register_libstdcxx_xmethods (gdb.current_objfile ()) diff --git a/libstdc++-v3/python/libstdcxx/v6/xmethods.py b/libstdc++-v3/python/libstdcxx/v6/xmethods.py new file mode 100644 index 00000000000..f20f411affd --- /dev/null +++ b/libstdc++-v3/python/libstdcxx/v6/xmethods.py @@ -0,0 +1,103 @@ +# Xmethods for libstc++. + +# Copyright (C) 2014 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/>. + +import gdb +import gdb.xmethod +import re + +matcher_name_prefix = 'libstdc++::' + +# Xmethods for std::vector + +class VectorSizeWorker(gdb.xmethod.XMethodWorker): + def __init__(self): + self.name = 'size' + self.enabled = True + + def get_arg_types(self): + return None + + def __call__(self, obj): + return obj['_M_impl']['_M_finish'] - obj['_M_impl']['_M_start'] + +class VectorSubscriptWorker(gdb.xmethod.XMethodWorker): + def __init__(self): + self.name = 'operator[]' + self.enabled = True + + def get_arg_types(self): + return gdb.lookup_type('std::size_t') + + def __call__(self, obj, subscript): + return obj['_M_impl']['_M_start'][subscript] + +class VectorMethodsMatcher(gdb.xmethod.XMethodMatcher): + def __init__(self): + gdb.xmethod.XMethodMatcher.__init__(self, + matcher_name_prefix + 'vector') + self._subscript_worker = VectorSubscriptWorker() + self._size_worker = VectorSizeWorker() + self.methods = [self._subscript_worker, self._size_worker] + + def match(self, class_type, method_name): + if not re.match('^std::vector<.*>$', class_type.tag): + return None + if method_name == 'operator[]' and self._subscript_worker.enabled: + return self._subscript_worker + elif method_name == 'size' and self._size_worker.enabled: + return self._size_worker + +# Xmethods for std::unique_ptr + +class UniquePtrGetWorker(gdb.xmethod.XMethodWorker): + def __init__(self): + self.name = 'get' + self.enabled = True + + def get_arg_types(self): + return None + + def __call__(self, obj): + return obj['_M_t']['_M_head_impl'] + +class UniquePtrDerefWorker(UniquePtrGetWorker): + def __init__(self): + UniquePtrGetWorker.__init__(self) + self.name = 'operator*' + + def __call__(self, obj): + return UniquePtrGetWorker.__call__(self, obj).dereference() + +class UniquePtrMethodsMatcher(gdb.xmethod.XMethodMatcher): + def __init__(self): + gdb.xmethod.XMethodMatcher.__init__(self, + matcher_name_prefix + 'unique_ptr') + self._get_worker = UniquePtrGetWorker() + self._deref_worker = UniquePtrDerefWorker() + self.methods = [self._get_worker, self._deref_worker] + + def match(self, class_type, method_name): + if not re.match('^std::unique_ptr<.*>$', class_type.tag): + return None + if method_name == 'operator*' and self._deref_worker.enabled: + return self._deref_worker + elif method_name == 'get' and self._get_worker.enabled: + return self._get_worker + +def register_libstdcxx_xmethods(locus): + gdb.xmethod.register_xmethod_matcher(locus, VectorMethodsMatcher()) + gdb.xmethod.register_xmethod_matcher(locus, UniquePtrMethodsMatcher()) |