1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
# Load this module into LLDB by running:
# command script import /path/to/Halide/tools/lldbhalide.py
import functools
import lldb
def normalize(raw):
return raw.lstrip('"').rstrip('"').replace(r"\n", " ").replace(" ", " ")
def summary_string(summary_fn):
@functools.wraps(summary_fn)
def wrapper(value, _):
if value is None or not value.IsValid():
return "<invalid>"
try:
return normalize(summary_fn(value).GetSummary())
except Exception as e:
return f"<error:{e},{value}>"
return wrapper
@summary_string
def call_name(value):
return value.EvaluateExpression("this->name()", lldb.SBExpressionOptions())
@summary_string
def call_lldb_string(value):
return value.EvaluateExpression(
"Halide::Internal::lldb_string(*this)", lldb.SBExpressionOptions()
)
class ProxyChildrenProvider:
def __init__(self, valobj, _):
self.inner = valobj
self.update()
def update(self):
pass
def num_children(self):
return self.inner.GetNumChildren()
def get_child_index(self, name):
return self.inner.GetIndexOfChildWithName(name)
def get_child_at_index(self, index):
return self.inner.GetChildAtIndex(index)
class IRChildrenProvider(ProxyChildrenProvider):
def __init__(self, valobj, _):
super().__init__(valobj.GetChildMemberWithName("ptr"), None)
class BoxChildrenProvider(IRChildrenProvider):
def __init__(self, valobj, _):
super().__init__(valobj.GetChildMemberWithName("contents"), None)
class FunctionChildrenProvider(ProxyChildrenProvider):
def __init__(self, valobj, _):
contents = valobj.EvaluateExpression(
"*this->contents.get()", lldb.SBExpressionOptions()
)
print(contents)
super().__init__(contents, None)
def __lldb_init_module(debugger, _):
base_exprs = [
"Add",
"And",
"Broadcast",
"Call",
"Cast",
"Div",
"EQ",
"GE",
"GT",
"LE",
"LT",
"Let",
"Load",
"Max",
"Min",
"Mod",
"Mul",
"NE",
"Not",
"Or",
"Ramp",
"Reinterpret",
"Select",
"Shuffle",
"Sub",
"Variable",
"VectorReduce",
]
for ty in base_exprs:
debugger.HandleCommand(
f"type summary add Halide::Internal::{ty} --python-function lldbhalide.call_lldb_string"
)
for ty in ("Expr", "Internal::Stmt"):
debugger.HandleCommand(
f"type summary add Halide::{ty} --python-function lldbhalide.call_lldb_string"
)
debugger.HandleCommand(
f"type synthetic add Halide::{ty} -l lldbhalide.IRChildrenProvider"
)
for ty in ("Definition", "FuncSchedule", "ReductionDomain", "StageSchedule"):
debugger.HandleCommand(
f"type synthetic add Halide::Internal::{ty} -l lldbhalide.BoxChildrenProvider"
)
debugger.HandleCommand(
"type synthetic add Halide::Internal::Function -l lldbhalide.FunctionChildrenProvider"
)
debugger.HandleCommand("type summary add Halide::Internal::Dim -s '${var.var%S}'")
debugger.HandleCommand(
"type summary add Halide::RVar --python-function lldbhalide.call_name"
)
debugger.HandleCommand(
"type summary add Halide::Var --python-function lldbhalide.call_name"
)
debugger.HandleCommand(
"type summary add halide_type_t -s '${var.code%S} bits=${var.bits%u} lanes=${var.lanes%u}'"
)
debugger.HandleCommand(
"type summary add Halide::Internal::RefCount -s ${var.count.Value%S}"
)
|