我想通过更新我的std :: Pretty Printers或Boost :: PrettyPrinters的现有打印机来添加新的漂亮打印机。他们使用以下链接进行了适当的设置:https://sourceware.org/gdb/wiki/stlsupporthttps://github.com/ruediger/boost-pretty-printer
我也经过了他们的教程来添加新打印机,但某种程度上未能获得良好的理解。也有机会研究类似的线程:漂亮的打印boost :: mpl :: string< ...>GDB中的类型和漂亮的打印boost :: gdb上的unordered_map
知道如何在我的Printers.py文件中添加上述boost :: unorder_map。我在Boost Directory中对Printers.py文件进行了以下修改
@_register_printer
class BoostUnorderedMapPrinter:
"Pretty printer for a boost::unordered_map"
printer_name = 'boost::unordered_map'
version = '1.40'
type_name_re = '^boost::unordered_map$'
class _iterator:
def __init__ (self, fields):
type_1 = fields.val.type.template_argument(0)
type_2 = fields.val.type.template_argument(1)
self.buckets = fields.val['table_']['buckets_']
self.bucket_count = fields.val['table_']['bucket_count_']
self.current_bucket = 0
pair = "std::pair<%s const, %s>" % (type_1, type_2)
self.pair_pointer = gdb.lookup_type(pair).pointer()
self.base_pointer = gdb.lookup_type("boost::unordered_detail::value_base< %s >" % pair).pointer()
self.node_pointer = gdb.lookup_type("boost::unordered_detail::hash_node<std::allocator< %s >, boost::unordered_detail::ungrouped>" % pair).pointer()
self.node = self.buckets[self.current_bucket]['next_']
def __iter__(self):
return self
def next(self):
while not self.node:
self.current_bucket = self.current_bucket + 1
if self.current_bucket >= self.bucket_count:
raise StopIteration
self.node = self.buckets[self.current_bucket]['next_']
iterator = self.node.cast(self.node_pointer).cast(self.base_pointer).cast(self.pair_pointer).dereference()
self.node = self.node['next_']
return ('%s' % iterator['first'], iterator['second'])
def __init__(self, val):
self.val = val
def children(self):
return self._iterator(self)
def to_string(self):
return "boost::unordered_map"
某种程度上,它似乎无法识别此类。
预先感谢
github上的升压打印代码使用装饰器注意,应注册给定的打印机,然后在类中进行一些字段以控制注册:
@_register_printer
class BoostIteratorRange:
...
printer_name = 'boost::iterator_range'
version = '1.40'
type_name_re = '^boost::iterator_range<.*>$'
所以我想您可以将它们添加到另一个给出的示例代码中,以便张贴以设置内容。
另外,您可以自己手动编写注册代码。
可能不是最好的方法,但它适用于我的快速调试会话:
import gdb
import re
def lookup_type(val)
resolved_type = str(val.type.unqualified().strip_typedefs())
if (re.search("^boost::unordered_map>.*>$", resolved_type):
return BoostUnorderedMapPrinter()
gdb.pretty_printers.append (lookup_type)