forked from efficient/libcuckoo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Manu Goyal
authored and
Manu Goyal
committed
Dec 31, 2017
1 parent
11080cc
commit 682118b
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# GDB Printers | ||
|
||
This directory contains a python module that allows pretty-printing a | ||
cuckoohash map. | ||
|
||
## Usage | ||
|
||
In order to use the libcuckoo pretty printers, add the following to your | ||
`~/.gdbinit`: | ||
|
||
``` | ||
python | ||
import sys | ||
sys.path.insert(0, '/path/to/libcuckoo/libcuckoo-gdb-printers') | ||
from libcuckoo.printers import register_libcuckoo_printers | ||
register_libcuckoo_printers (None) | ||
end | ||
``` |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import gdb | ||
import gdb.printing | ||
|
||
class CuckoohashMapPrinter: | ||
"""Print a cuckoohash_map object""" | ||
|
||
def __init__(self, val): | ||
self.val = val | ||
self.slot_per_bucket = int(self.val.type.template_argument(5)) | ||
|
||
def _iterator(self): | ||
buckets_obj = self.val['buckets_'] | ||
hashpower = buckets_obj['hashpower_']['_M_i'] | ||
buckets_ptr = buckets_obj['buckets_'] | ||
if not buckets_ptr: | ||
return | ||
num_buckets = int(2**hashpower) | ||
for i in range(num_buckets): | ||
bucket = (buckets_ptr + i).dereference() | ||
storage_value_type = gdb.lookup_type(str(bucket.type) + '::storage_value_type') | ||
for j in range(self.slot_per_bucket): | ||
if bucket['occupied_']['_M_elems'][j]: | ||
value_blob = bucket['values_']['_M_elems'][j] | ||
storage_value = value_blob.cast(storage_value_type) | ||
yield ('key', storage_value['first']) | ||
yield ('value', storage_value['second']) | ||
|
||
def children(self): | ||
return self._iterator() | ||
|
||
def to_string(self): | ||
return 'cuckoohash_map' | ||
|
||
def display_hint(self): | ||
return 'map' | ||
|
||
def build_pretty_printer(): | ||
pp = gdb.printing.RegexpCollectionPrettyPrinter("libcuckoo") | ||
pp.add_printer('cuckoohash_map', '^cuckoohash_map<.*>$', CuckoohashMapPrinter) | ||
return pp | ||
|
||
def register_libcuckoo_printers(objfile): | ||
gdb.printing.register_pretty_printer(objfile, build_pretty_printer()) |