]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/python/libstdcxx/v6/xmethods.py
1 # Xmethods for libstc++.
3 # Copyright (C) 2014 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 matcher_name_prefix
= 'libstdc++::'
24 # Xmethods for std::vector
26 class VectorSizeWorker(gdb
.xmethod
.XMethodWorker
):
31 def get_arg_types(self
):
34 def __call__(self
, obj
):
35 return obj
['_M_impl']['_M_finish'] - obj
['_M_impl']['_M_start']
37 class VectorSubscriptWorker(gdb
.xmethod
.XMethodWorker
):
39 self
.name
= 'operator[]'
42 def get_arg_types(self
):
43 return gdb
.lookup_type('std::size_t')
45 def __call__(self
, obj
, subscript
):
46 return obj
['_M_impl']['_M_start'][subscript
]
48 class VectorMethodsMatcher(gdb
.xmethod
.XMethodMatcher
):
50 gdb
.xmethod
.XMethodMatcher
.__init
__(self
,
51 matcher_name_prefix
+ 'vector')
52 self
._subscript
_worker
= VectorSubscriptWorker()
53 self
._size
_worker
= VectorSizeWorker()
54 self
.methods
= [self
._subscript
_worker
, self
._size
_worker
]
56 def match(self
, class_type
, method_name
):
57 if not re
.match('^std::vector<.*>$', class_type
.tag
):
59 if method_name
== 'operator[]' and self
._subscript
_worker
.enabled
:
60 return self
._subscript
_worker
61 elif method_name
== 'size' and self
._size
_worker
.enabled
:
62 return self
._size
_worker
64 # Xmethods for std::unique_ptr
66 class UniquePtrGetWorker(gdb
.xmethod
.XMethodWorker
):
71 def get_arg_types(self
):
74 def __call__(self
, obj
):
75 return obj
['_M_t']['_M_head_impl']
77 class UniquePtrDerefWorker(UniquePtrGetWorker
):
79 UniquePtrGetWorker
.__init
__(self
)
80 self
.name
= 'operator*'
82 def __call__(self
, obj
):
83 return UniquePtrGetWorker
.__call
__(self
, obj
).dereference()
85 class UniquePtrMethodsMatcher(gdb
.xmethod
.XMethodMatcher
):
87 gdb
.xmethod
.XMethodMatcher
.__init
__(self
,
88 matcher_name_prefix
+ 'unique_ptr')
89 self
._get
_worker
= UniquePtrGetWorker()
90 self
._deref
_worker
= UniquePtrDerefWorker()
91 self
.methods
= [self
._get
_worker
, self
._deref
_worker
]
93 def match(self
, class_type
, method_name
):
94 if not re
.match('^std::unique_ptr<.*>$', class_type
.tag
):
96 if method_name
== 'operator*' and self
._deref
_worker
.enabled
:
97 return self
._deref
_worker
98 elif method_name
== 'get' and self
._get
_worker
.enabled
:
99 return self
._get
_worker
101 def register_libstdcxx_xmethods(locus
):
102 gdb
.xmethod
.register_xmethod_matcher(locus
, VectorMethodsMatcher())
103 gdb
.xmethod
.register_xmethod_matcher(locus
, UniquePtrMethodsMatcher())