Skip to content

Commit

Permalink
Add GDB pretty-printers for range and grid types
Browse files Browse the repository at this point in the history
  • Loading branch information
fknorr committed Sep 14, 2023
1 parent c6ce3e6 commit 6fe664c
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gdbinit
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
7 changes: 7 additions & 0 deletions debug/gdb/celerity/gdb/__init__.py
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)
144 changes: 144 additions & 0 deletions debug/gdb/celerity/gdb/prettyprinters.py
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()

0 comments on commit 6fe664c

Please sign in to comment.