# Python 2 does not provide the datetime.UTC singleton.
class UTC(datetime.tzinfo):
- """Concrete tzinfo class representing the UTC time zone"""
+ """Concrete tzinfo class representing the UTC time zone."""
def utcoffset(self, dt):
return datetime.timedelta(0)
def lookup_templ_spec(templ, *args):
"""
- Lookup template specialization templ<args...>
+ Lookup template specialization templ<args...>.
"""
t = '{}<{}>'.format(templ, ', '.join([str(a) for a in args]))
try:
# Use this to find container node types instead of find_type,
# see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91997 for details.
-
def lookup_node_type(nodename, containertype):
"""
- Lookup specialization of template NODENAME corresponding to CONTAINERTYPE.
- e.g. if NODENAME is '_List_node' and CONTAINERTYPE is std::list<int>
- then return the type std::_List_node<int>.
- Returns None if not found.
+ Lookup specialization of template nodename corresponding to containertype.
+
+ nodename - The name of a class template, as a String
+ containertype - The container, as a gdb.Type
+
+ Return a gdb.Type for the corresponding specialization of nodename,
+ or None if the type cannot be found.
+
+ e.g. lookup_node_type('_List_node', gdb.lookup_type('std::list<int>'))
+ will return a gdb.Type for the type std::_List_node<int>.
"""
# If nodename is unqualified, assume it's in namespace std.
if '::' not in nodename:
nodename = 'std::' + nodename
+ # Use either containertype's value_type or its first template argument.
try:
valtype = find_type(containertype, 'value_type')
except:
def strip_inline_namespaces(type_str):
- "Remove known inline namespaces from the canonical name of a type."
+ """Remove known inline namespaces from the canonical name of a type."""
type_str = strip_versioned_namespace(type_str)
type_str = type_str.replace('std::__cxx11::', 'std::')
expt_ns = 'std::experimental::'
def get_template_arg_list(type_obj):
- "Return a type's template arguments as a list"
+ """Return a type's template arguments as a list."""
n = 0
template_args = []
while True:
class SmartPtrIterator(Iterator):
- "An iterator for smart pointer types with a single 'child' value"
+ """An iterator for smart pointer types with a single 'child' value."""
def __init__(self, val):
self.val = val
class SharedPointerPrinter:
- "Print a shared_ptr, weak_ptr, atomic<shared_ptr>, or atomic<weak_ptr>"
+ """
+ Print a shared_ptr, weak_ptr, atomic<shared_ptr>, or atomic<weak_ptr>.
+ """
def __init__(self, typename, val):
self.typename = strip_versioned_namespace(typename)
def _tuple_impl_get(val):
- "Return the tuple element stored in a _Tuple_impl<N, T> base class."
+ """Return the tuple element stored in a _Tuple_impl<N, T> base class."""
bases = val.type.fields()
if not bases[-1].is_base_class:
raise ValueError(
def tuple_get(n, val):
- "Return the result of std::get<n>(val) on a std::tuple"
+ """Return the result of std::get<n>(val) on a std::tuple."""
tuple_size = len(get_template_arg_list(val.type))
if n > tuple_size:
raise ValueError("Out of range index for std::get<N> on std::tuple")
def unique_ptr_get(val):
- "Return the result of val.get() on a std::unique_ptr"
+ """Return the result of val.get() on a std::unique_ptr."""
# std::unique_ptr<T, D> contains a std::tuple<D::pointer, D>,
# either as a direct data member _M_t (the old implementation)
# or within a data member of type __uniq_ptr_data.
class UniquePointerPrinter:
- "Print a unique_ptr"
+ """Print a unique_ptr."""
def __init__(self, typename, val):
self.val = val
def get_value_from_aligned_membuf(buf, valtype):
- """Returns the value held in a __gnu_cxx::__aligned_membuf."""
+ """Return the value held in a __gnu_cxx::__aligned_membuf."""
return buf['_M_storage'].address.cast(valtype.pointer()).dereference()
def get_value_from_list_node(node):
- """Returns the value held in an _List_node<_Val>"""
+ """Return the value held in an _List_node<_Val>."""
try:
member = node.type.fields()[1].name
if member == '_M_data':
class StdListPrinter:
- "Print a std::list"
+ """Print a std::list."""
class _iterator(Iterator):
def __init__(self, nodetype, head):
class StdListIteratorPrinter(NodeIteratorPrinter):
- "Print std::list::iterator"
+ """Print std::list::iterator."""
def __init__(self, typename, val):
NodeIteratorPrinter.__init__(self, typename, val, 'list', '_List_node')
class StdFwdListIteratorPrinter(NodeIteratorPrinter):
- "Print std::forward_list::iterator"
+ """Print std::forward_list::iterator."""
def __init__(self, typename, val):
NodeIteratorPrinter.__init__(self, typename, val, 'forward_list',
class StdSlistPrinter:
- "Print a __gnu_cxx::slist"
+ """Print a __gnu_cxx::slist."""
class _iterator(Iterator):
def __init__(self, nodetype, head):
class StdSlistIteratorPrinter:
- "Print __gnu_cxx::slist::iterator"
+ """Print __gnu_cxx::slist::iterator."""
def __init__(self, typename, val):
self.val = val
class StdVectorPrinter:
- "Print a std::vector"
+ """Print a std::vector."""
class _iterator(Iterator):
def __init__(self, start, finish, bitvec):
class StdVectorIteratorPrinter:
- "Print std::vector::iterator"
+ """Print std::vector::iterator."""
def __init__(self, typename, val):
self.val = val
class StdBitIteratorPrinter:
- "Print std::vector<bool>'s _Bit_iterator and _Bit_const_iterator"
+ """Print std::vector<bool>'s _Bit_iterator and _Bit_const_iterator."""
def __init__(self, typename, val):
self.val = val
class StdBitReferencePrinter:
- "Print std::vector<bool>::reference"
+ """Print std::vector<bool>::reference."""
def __init__(self, typename, val):
self.val = val
class StdTuplePrinter:
- "Print a std::tuple"
+ """Print a std::tuple."""
class _iterator(Iterator):
@staticmethod
class StdStackOrQueuePrinter:
- "Print a std::stack or std::queue"
+ """Print a std::stack or std::queue."""
def __init__(self, typename, val):
self.typename = strip_versioned_namespace(typename)
def get_value_from_Rb_tree_node(node):
- """Returns the value held in an _Rb_tree_node<_Val>"""
+ """Return the value held in an _Rb_tree_node<_Val>."""
try:
member = node.type.fields()[1].name
if member == '_M_value_field':
class StdRbtreeIteratorPrinter:
- "Print std::map::iterator, std::set::iterator, etc."
+ """Print std::map::iterator, std::set::iterator, etc."""
def __init__(self, typename, val):
self.val = val
class StdDebugIteratorPrinter:
- "Print a debug enabled version of an iterator"
+ """Print a debug enabled version of an iterator."""
def __init__(self, typename, val):
self.val = val
class StdMapPrinter:
- "Print a std::map or std::multimap"
+ """Print a std::map or std::multimap."""
# Turn an RbtreeIterator into a pretty-print iterator.
class _iter(Iterator):
class StdSetPrinter:
- "Print a std::set or std::multiset"
+ """Print a std::set or std::multiset."""
# Turn an RbtreeIterator into a pretty-print iterator.
class _iter(Iterator):
class StdBitsetPrinter:
- "Print a std::bitset"
+ """Print a std::bitset."""
def __init__(self, typename, val):
self.typename = strip_versioned_namespace(typename)
class StdDequePrinter:
- "Print a std::deque"
+ """Print a std::deque."""
class _iter(Iterator):
def __init__(self, node, start, end, last, buffer_size):
class StdDequeIteratorPrinter:
- "Print std::deque::iterator"
+ """Print std::deque::iterator."""
def __init__(self, typename, val):
self.val = val
class StdStringPrinter:
- "Print a std::basic_string of some kind"
+ """Print a std::basic_string of some kind."""
def __init__(self, typename, val):
self.val = val
def access_streambuf_ptrs(streambuf):
- "Access the streambuf put area pointers"
+ """Access the streambuf put area pointers."""
pbase = streambuf['_M_out_beg']
pptr = streambuf['_M_out_cur']
egptr = streambuf['_M_in_end']
class StdStringBufPrinter:
- "Print a std::basic_stringbuf"
+ """Print a std::basic_stringbuf."""
def __init__(self, _, val):
self.val = val
class StdStringStreamPrinter:
- "Print a std::basic_stringstream"
+ """Print a std::basic_stringstream."""
def __init__(self, typename, val):
self.val = val
class Tr1UnorderedSetPrinter:
- "Print a std::unordered_set or tr1::unordered_set"
+ """Print a std::unordered_set or tr1::unordered_set."""
def __init__(self, typename, val):
self.typename = strip_versioned_namespace(typename)
class Tr1UnorderedMapPrinter:
- "Print a std::unordered_map or tr1::unordered_map"
+ """Print a std::unordered_map or tr1::unordered_map."""
def __init__(self, typename, val):
self.typename = strip_versioned_namespace(typename)
class StdForwardListPrinter:
- "Print a std::forward_list"
+ """Print a std::forward_list."""
class _iterator(Iterator):
def __init__(self, nodetype, head):
class SingleObjContainerPrinter(object):
- "Base class for printers of containers of single objects"
+ """Base class for printers of containers of single objects."""
def __init__(self, val, viz, hint=None):
self.contained_value = val
self.hint = hint
def _recognize(self, type):
- """Return TYPE as a string after applying type printers"""
+ """Return type as a string after applying type printers."""
global _use_type_printing
if not _use_type_printing:
return str(type)
def function_pointer_to_name(f):
- "Find the name of the function referred to by the gdb.Value f, "
- " which should contain a function pointer from the program."
+ """Find the name of the function referred to by the gdb.Value f,
+ which should contain a function pointer from the program."""
# Turn the function pointer into an actual address.
# This is needed to unpack ppc64 function descriptors.
class StdExpAnyPrinter(SingleObjContainerPrinter):
- "Print a std::any or std::experimental::any"
+ """Print a std::any or std::experimental::any."""
def __init__(self, typename, val):
self.typename = strip_versioned_namespace(typename)
class StdExpOptionalPrinter(SingleObjContainerPrinter):
- "Print a std::optional or std::experimental::optional"
+ """Print a std::optional or std::experimental::optional."""
def __init__(self, typename, val):
valtype = self._recognize(val.type.template_argument(0))
class StdVariantPrinter(SingleObjContainerPrinter):
- "Print a std::variant"
+ """Print a std::variant."""
def __init__(self, typename, val):
alternatives = get_template_arg_list(val.type)
class StdNodeHandlePrinter(SingleObjContainerPrinter):
- "Print a container node handle"
+ """Print a container node handle."""
def __init__(self, typename, val):
self.value_type = val.type.template_argument(1)
class StdExpStringViewPrinter:
- "Print a std::basic_string_view or std::experimental::basic_string_view"
+ """
+ Print a std::basic_string_view or std::experimental::basic_string_view
+ """
def __init__(self, typename, val):
self.val = val
class StdExpPathPrinter:
- "Print a std::experimental::filesystem::path"
+ """Print a std::experimental::filesystem::path."""
def __init__(self, typename, val):
self.val = val
class StdPathPrinter:
- "Print a std::filesystem::path"
+ """Print a std::filesystem::path."""
def __init__(self, typename, val):
self.val = val
class StdPairPrinter:
- "Print a std::pair object, with 'first' and 'second' as children"
+ """Print a std::pair object, with 'first' and 'second' as children."""
def __init__(self, typename, val):
self.val = val
class _iter(Iterator):
- "An iterator for std::pair types. Returns 'first' then 'second'."
+ """An iterator for std::pair types. Returns 'first' then 'second'."""
def __init__(self, val):
self.val = val
class StdCmpCatPrinter:
- "Print a comparison category object"
+ """Print a comparison category object."""
def __init__(self, typename, val):
self.typename = typename[typename.rfind(':')+1:]
class StdErrorCodePrinter:
- "Print a std::error_code or std::error_condition"
+ """Print a std::error_code or std::error_condition."""
_system_is_posix = None # Whether std::system_category() use errno values.
@staticmethod
def _unqualified_name(name):
- "Strip any nested-name-specifier from NAME to give an unqualified name"
+ """
+ Strip any nested-name-specifier from name to give an unqualified name.
+ """
return name.split('::')[-1]
def to_string(self):
class StdRegexStatePrinter:
- "Print a state node in the NFA for a std::regex"
+ """Print a state node in the NFA for a std::regex."""
def __init__(self, typename, val):
self.val = val
class StdSpanPrinter:
- "Print a std::span"
+ """Print a std::span."""
class iterator(Iterator):
def __init__(self, begin, size):
class StdInitializerListPrinter:
- "Print a std::initializer_list"
+ """Print a std::initializer_list."""
def __init__(self, typename, val):
self.typename = typename
class StdAtomicPrinter:
- "Print a std:atomic"
+ """Print a std:atomic."""
def __init__(self, typename, val):
self.typename = strip_versioned_namespace(typename)
class StdFormatArgsPrinter:
- "Print a std::basic_format_args"
+ """Print a std::basic_format_args."""
# TODO: add printer for basic_format_arg<Context> and print out children.
# TODO: add printer for __format::_ArgStore<Context, Args...>.
class StdChronoDurationPrinter:
- "Print a std::chrono::duration"
+ """Print a std::chrono::duration."""
def __init__(self, typename, val):
self.typename = strip_versioned_namespace(typename)
class StdChronoTimePointPrinter:
- "Print a std::chrono::time_point"
+ """Print a std::chrono::time_point."""
def __init__(self, typename, val):
self.typename = strip_versioned_namespace(typename)
class StdChronoZonedTimePrinter:
- "Print a std::chrono::zoned_time"
+ """Print a std::chrono::zoned_time."""
def __init__(self, typename, val):
self.typename = strip_versioned_namespace(typename)
class StdChronoCalendarPrinter:
- "Print a std::chrono::day, std::chrono::month, std::chrono::year etc."
+ """Print a std::chrono::day, std::chrono::month, std::chrono::year etc."""
def __init__(self, typename, val):
self.typename = strip_versioned_namespace(typename)
class StdChronoTimeZonePrinter:
- "Print a chrono::time_zone or chrono::time_zone_link"
+ """Print a chrono::time_zone or chrono::time_zone_link."""
def __init__(self, typename, val):
self.typename = strip_versioned_namespace(typename)
class StdChronoLeapSecondPrinter:
- "Print a chrono::leap_second"
+ """Print a chrono::leap_second."""
def __init__(self, typename, val):
self.typename = strip_versioned_namespace(typename)
class StdChronoTzdbPrinter:
- "Print a chrono::tzdb"
+ """Print a chrono::tzdb."""
def __init__(self, typename, val):
self.typename = strip_versioned_namespace(typename)
class StdChronoTimeZoneRulePrinter:
- "Print a chrono::time_zone rule"
+ """Print a chrono::time_zone rule."""
def __init__(self, typename, val):
self.typename = strip_versioned_namespace(typename)
class StdLocalePrinter:
- "Print a std::locale"
+ """Print a std::locale."""
def __init__(self, typename, val):
self.val = val
class TemplateTypePrinter(object):
- r"""
+ """
A type printer for class templates with default template arguments.
Recognizes specializations of class templates and prints them without
any template arguments that use a default template argument.
Type printers are recursively applied to the template arguments.
- e.g. replace "std::vector<T, std::allocator<T> >" with "std::vector<T>".
+ e.g. replace 'std::vector<T, std::allocator<T> >' with 'std::vector<T>'.
"""
def __init__(self, name, defargs):
self.enabled = True
class _recognizer(object):
- "The recognizer class for TemplateTypePrinter."
+ """The recognizer class for TemplateTypePrinter."""
def __init__(self, name, defargs):
self.name = name
return str(type_obj)
def instantiate(self):
- "Return a recognizer object for this type printer."
+ """Return a recognizer object for this type printer."""
return self._recognizer(self.name, self.defargs)
def add_one_template_type_printer(obj, name, defargs):
- r"""
+ """
Add a type printer for a class template with default template arguments.
Args:
{ 2: 'std::hash<{0}>',
3: 'std::equal_to<{0}>',
4: 'std::allocator<std::pair<const {0}, {1}> >' }
-
"""
printer = TemplateTypePrinter('std::'+name, defargs)
gdb.types.register_type_printer(obj, printer)
class FilteringTypePrinter(object):
- r"""
+ """
A type printer that uses typedef names for common template specializations.
Args:
self.enabled = True
class _recognizer(object):
- "The recognizer class for FilteringTypePrinter."
+ """The recognizer class for FilteringTypePrinter."""
def __init__(self, template, name, targ1):
self.template = template
return None
def instantiate(self):
- "Return a recognizer object for this type printer."
+ """Return a recognizer object for this type printer."""
return self._recognizer(self.template, self.name, self.targ1)
def register_libstdcxx_printers(obj):
- "Register libstdc++ pretty-printers with objfile Obj."
+ """Register libstdc++ pretty-printers with objfile Obj."""
global _use_gdb_pp
global libstdcxx_printer