-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GDB pretty-printers for range and grid types
- Loading branch information
Showing
3 changed files
with
156 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,5 @@ | ||
python | ||
import sys | ||
sys.path += ['debug/gdb', 'vendor/small_vector/source/support/python'] | ||
import celerity.gdb, gch.gdb.prettyprinters.small_vector | ||
end |
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,7 @@ | ||
import gdb | ||
|
||
def register_printers(obj): | ||
from .prettyprinters import pretty_printer | ||
gdb.printing.register_pretty_printer(obj, pretty_printer) | ||
|
||
register_printers(None) |
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,144 @@ | ||
import gdb | ||
|
||
|
||
def typeof(val): | ||
ty = val.type | ||
while ty.name is None: | ||
ty = ty.target() | ||
return ty | ||
|
||
|
||
class PhantomTypePrinter: | ||
def __init__(self, val): | ||
self.val = val | ||
|
||
def to_string(self): | ||
return str(self.val['m_value']) | ||
|
||
|
||
class CoordinatePrinter: | ||
def __init__(self, val): | ||
self.val = val | ||
|
||
def to_string(self): | ||
values = self.val['m_values']['values'] | ||
i_min, i_max = values.type.range() | ||
return '[' + ', '.join(str(values[i]) for i in range(i_min, i_max+1)) + ']' | ||
|
||
|
||
class SubrangePrinter: | ||
def __init__(self, val): | ||
self.val = val | ||
|
||
def to_string(self): | ||
return str(self.val['offset']) + ' + ' + str(self.val['range']) | ||
|
||
|
||
class NdRangePrinter: | ||
def __init__(self, val): | ||
self.val = val | ||
|
||
def to_string(self): | ||
return typeof(self.val).name | ||
|
||
def children(self): | ||
return [ | ||
('global_range', self.val['m_global_range']), | ||
('local_range', self.val['m_local_range']), | ||
('offset', self.val['m_offset']), | ||
] | ||
|
||
|
||
class ChunkPrinter: | ||
def __init__(self, val): | ||
self.val = val | ||
|
||
def to_string(self): | ||
return typeof(self.val).name | ||
|
||
def children(self): | ||
return [ | ||
('offset', self.val['offset']), | ||
('range', self.val['range']), | ||
('global_size', self.val['global_size']), | ||
] | ||
|
||
|
||
class BoxPrinter: | ||
def __init__(self, val): | ||
self.val = val | ||
|
||
def to_string(self): | ||
return str(self.val['m_min']) + ' - ' + str(self.val['m_max']) | ||
|
||
|
||
class RegionPrinter: | ||
def __init__(self, val): | ||
self.val = val | ||
|
||
def to_string(self): | ||
return typeof(self.val).name | ||
|
||
def children(self): | ||
for i, b in gdb.default_visualizer(self.val['m_boxes']).children(): | ||
yield i, b | ||
|
||
def display_hint(self): | ||
return 'array' | ||
|
||
|
||
def iter_children(variant): | ||
for _, child in gdb.default_visualizer(variant).children(): | ||
yield child | ||
|
||
|
||
def get_inner(variant): | ||
children = list(iter_children(variant)) | ||
assert len(children) == 1 | ||
return children[0] | ||
|
||
|
||
class RegionMapPrinter: | ||
def __init__(self, val): | ||
self.val = val | ||
|
||
def to_string(self): | ||
return typeof(self.val).name | ||
|
||
def children(self): | ||
impl = get_inner(self.val['m_region_map']) | ||
yield ('extent', impl['m_extent']) | ||
|
||
def recurse_tree(root): | ||
child_boxes = root['m_child_boxes'] | ||
children = root['m_children'] | ||
for box, child in zip(iter_children(child_boxes), iter_children(children)): | ||
child = get_inner(child) | ||
if typeof(child).name.startswith('celerity::detail::region_map_detail::inner_node'): | ||
yield from recurse_tree(child) | ||
else: | ||
yield ('[' + str(box) + ']', child) | ||
|
||
root = get_inner(impl['m_root']) | ||
assert root != 0 | ||
yield from recurse_tree(root.dereference()) | ||
|
||
|
||
def build_pretty_printer(): | ||
pp = gdb.printing.RegexpCollectionPrettyPrinter("Celerity") | ||
pp.add_printer( | ||
'phantom_type', '^celerity::detail::PhantomType<.*>$', PhantomTypePrinter) | ||
pp.add_printer('id', '^celerity::id<.*>$', CoordinatePrinter) | ||
pp.add_printer('range', '^celerity::range<.*>$', CoordinatePrinter) | ||
pp.add_printer('subrange', '^celerity::subrange<.*>$', SubrangePrinter) | ||
pp.add_printer('nd_range', '^celerity::nd_range<.*>$', NdRangePrinter) | ||
pp.add_printer('chunk', '^celerity::chunk<.*>$', ChunkPrinter) | ||
pp.add_printer('box', '^celerity::detail::box<.*>$', BoxPrinter) | ||
pp.add_printer( | ||
'region', '^celerity::detail::region<.*>$', RegionPrinter) | ||
pp.add_printer( | ||
'region_map', '^celerity::detail::region_map<.*>$', RegionMapPrinter) | ||
return pp | ||
|
||
|
||
pretty_printer = build_pretty_printer() |