[英]Pretty printing boost::unordered_map on gdb
recently I've started to use the excellent boost::unordered_map on my system, but got one drawback: I couldn't figure how to inspect its contents. 最近我开始在我的系统上使用优秀的boost :: unordered_map,但有一个缺点:我无法弄清楚如何检查其内容。 Printing it on gdb gives me a table_ and a buckets_, but haven't found where are the items.
在gdb上打印它会给我一个table_和一个buckets_,但是没有找到它们的位置。 Anyone has a clue about this?
任何人都有这方面的线索?
For the ones that wanted a printer, I've managed to create one. 对于那些想要打印机的人,我设法创建了一台打印机。 Here is Code:
这是代码:
class BoostUnorderedMapPrinter:
"prints a 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"
In a typical hash table implementation, the buckets contain the head of a linked list which actually contains the values corresponding to this particular hash. 在典型的散列表实现中,桶包含链表的头部,该链表实际上包含与该特定散列相对应的值。 Thus I would bet on
buckets_
. 因此,我打赌
buckets_
。
Another option: there are various python pretty printer libraries for gdb now, and I think that you could find one that works with C++0x and inspect where it looks for the values. 另一种选择:gdb现在有各种各样的python漂亮的打印机库,我认为你可以找到一个适用于C ++ 0x并检查它在哪里寻找值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.