【发布时间】:2014-01-21 09:49:05
【问题描述】:
我想通过更新我的 std::pretty 打印机或 boost::prettyprinters 的现有 printers.py 文件来添加新的漂亮打印机。 使用以下链接适当地设置它们: https://sourceware.org/gdb/wiki/STLSupport https://github.com/ruediger/Boost-Pretty-Printer
我也阅读了他们的教程来添加新的打印机,但不知何故未能很好地理解。也有机会研究类似的线程: pretty printing boost::mpl::string<...> types in gdb 和 Pretty printing boost::unordered_map on gdb
很高兴知道如何添加在我的 printers.py 文件中注册的上述 boost::unorder_map。我对 boost 目录中的 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"
不知何故,它似乎无法识别此类。
提前致谢
【问题讨论】:
-
您需要围绕 boost 库创建一个 python 包装器,可能使用 cython。
-
不,这与在 gdb 中运行的 python 代码有关。为此,您不需要用于 boost 或 cython 的 python 包装器。
标签: python gdb pretty-print