Reverts llvm/llvm-project#173261 Some bots were failing with: ``` Step 6 (build-unified-tree) failure: build (failure) ... 2.874 [7103/10/382] Building CXX object utils/TableGen/CMakeFiles/llvm-tblgen.dir/CallingConvEmitter.cpp.o 2.875 [7102/10/383] Building CXX object utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeEmitterGen.cpp.o 2.895 [7101/10/384] Building CXX object utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeGenMapTable.cpp.o 2.896 [7100/10/385] Building CXX object utils/TableGen/CMakeFiles/llvm-tblgen.dir/CompressInstEmitter.cpp.o 2.898 [7099/10/386] Building CXX object utils/TableGen/CMakeFiles/llvm-tblgen.dir/CTagsEmitter.cpp.o 2.901 [7098/10/387] Building CXX object utils/TableGen/CMakeFiles/llvm-tblgen.dir/DAGISelEmitter.cpp.o 2.905 [7097/10/388] Building CXX object utils/TableGen/CMakeFiles/llvm-tblgen.dir/DAGISelMatcherEmitter.cpp.o 2.918 [7096/10/389] Building CXX object utils/TableGen/CMakeFiles/llvm-tblgen.dir/DAGISelMatcherGen.cpp.o 2.920 [7095/10/390] Building CXX object utils/TableGen/CMakeFiles/llvm-tblgen.dir/DecoderTree.cpp.o 2.932 [7094/10/391] Building CXX object projects/cross-project-tests/CMakeFiles/check-lldb-llvm-support-pointer-int-pair.dir/debuginfo-tests/llvm-prettyprinters/lldb/pointer-int-pair.cpp.o FAILED: projects/cross-project-tests/CMakeFiles/check-lldb-llvm-support-pointer-int-pair.dir/debuginfo-tests/llvm-prettyprinters/lldb/pointer-int-pair.cpp.o /opt/ccache/bin/g++ -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GLIBCXX_USE_CXX11_ABI=1 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/buildbot/buildbot-root/abi-test/build/projects/cross-project-tests -I/home/buildbot/buildbot-root/abi-test/llvm/cross-project-tests -I/home/buildbot/buildbot-root/abi-test/build/include -I/home/buildbot/buildbot-root/abi-test/llvm/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-array-bounds -Wno-stringop-overread -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -UNDEBUG -g -O0 -std=c++17 -MD -MT projects/cross-project-tests/CMakeFiles/check-lldb-llvm-support-pointer-int-pair.dir/debuginfo-tests/llvm-prettyprinters/lldb/pointer-int-pair.cpp.o -MF projects/cross-project-tests/CMakeFiles/check-lldb-llvm-support-pointer-int-pair.dir/debuginfo-tests/llvm-prettyprinters/lldb/pointer-int-pair.cpp.o.d -o projects/cross-project-tests/CMakeFiles/check-lldb-llvm-support-pointer-int-pair.dir/debuginfo-tests/llvm-prettyprinters/lldb/pointer-int-pair.cpp.o -c /home/buildbot/buildbot-root/abi-test/llvm/cross-project-tests/debuginfo-tests/llvm-prettyprinters/lldb/pointer-int-pair.cpp /home/buildbot/buildbot-root/abi-test/llvm/cross-project-tests/debuginfo-tests/llvm-prettyprinters/lldb/pointer-int-pair.cpp: In function ‘int main()’: /home/buildbot/buildbot-root/abi-test/llvm/cross-project-tests/debuginfo-tests/llvm-prettyprinters/lldb/pointer-int-pair.cpp:25:3: error: ‘__builtin_debugtrap’ was not declared in this scope; did you mean ‘__builtin_trap’? 25 | __builtin_debugtrap(); | ^~~~~~~~~~~~~~~~~~~ | __builtin_trap 2.932 [7094/9/392] Building CXX object utils/TableGen/CMakeFiles/llvm-tblgen.dir/DAGISelMatcherOpt.cpp.o 2.933 [7094/8/393] Building CXX object utils/TableGen/CMakeFiles/llvm-tblgen.dir/DecoderTableEmitter.cpp.o 2.936 [7094/7/394] Building CXX object utils/TableGen/CMakeFiles/llvm-tblgen.dir/DecoderEmitter.cpp.o 2.937 [7094/6/395] Building CXX object utils/TableGen/CMakeFiles/llvm-tblgen.dir/DFAEmitter.cpp.o 2.944 [7094/5/396] Building CXX object utils/TableGen/CMakeFiles/llvm-tblgen.dir/DFAPacketizerEmitter.cpp.o 3.340 [7094/4/397] Building PPCGenTargetFeatures.inc... 3.450 [7094/3/398] Building ARMTargetParserDef.inc... 3.780 [7094/2/399] Building AArch64TargetParserDef.inc... 5.093 [7094/1/400] Building RISCVTargetParserDef.inc... ninja: build stopped: subcommand failed. ```
476 lines
15 KiB
Python
476 lines
15 KiB
Python
"""
|
|
LLDB Formatters for LLVM data types.
|
|
|
|
Load into LLDB with 'command script import /path/to/lldbDataFormatters.py'
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import collections
|
|
import lldb
|
|
|
|
|
|
def __lldb_init_module(debugger, internal_dict):
|
|
debugger.HandleCommand("type category define -e llvm -l c++")
|
|
debugger.HandleCommand(
|
|
"type synthetic add -w llvm "
|
|
f"-l {__name__}.SmallVectorSynthProvider "
|
|
'-x "^llvm::SmallVectorImpl<.+>$"'
|
|
)
|
|
debugger.HandleCommand(
|
|
"type summary add -w llvm "
|
|
'-e -s "size=${svar%#}" '
|
|
'-x "^llvm::SmallVectorImpl<.+>$"'
|
|
)
|
|
debugger.HandleCommand(
|
|
"type synthetic add -w llvm "
|
|
f"-l {__name__}.SmallVectorSynthProvider "
|
|
'-x "^llvm::SmallVector<.+,.+>$"'
|
|
)
|
|
debugger.HandleCommand(
|
|
"type summary add -w llvm "
|
|
'-e -s "size=${svar%#}" '
|
|
'-x "^llvm::SmallVector<.+,.+>$"'
|
|
)
|
|
debugger.HandleCommand(
|
|
"type synthetic add -w llvm "
|
|
f"-l {__name__}.ArrayRefSynthProvider "
|
|
'-x "^llvm::ArrayRef<.+>$"'
|
|
)
|
|
debugger.HandleCommand(
|
|
"type summary add -w llvm "
|
|
'-e -s "size=${svar%#}" '
|
|
'-x "^llvm::ArrayRef<.+>$"'
|
|
)
|
|
debugger.HandleCommand(
|
|
"type summary add -w llvm "
|
|
f"-F {__name__}.SmallStringSummaryProvider "
|
|
'-x "^llvm::SmallString<.+>$"'
|
|
)
|
|
debugger.HandleCommand(
|
|
"type summary add -w llvm "
|
|
f"-F {__name__}.StringRefSummaryProvider "
|
|
"llvm::StringRef"
|
|
)
|
|
debugger.HandleCommand(
|
|
"type summary add -w llvm "
|
|
f"-F {__name__}.ConstStringSummaryProvider "
|
|
"lldb_private::ConstString"
|
|
)
|
|
|
|
# The synthetic providers for PointerIntPair and PointerUnion are disabled
|
|
# because of a few issues. One example is template arguments that are
|
|
# non-pointer types that instead specialize PointerLikeTypeTraits.
|
|
# debugger.HandleCommand(
|
|
# "type synthetic add -w llvm "
|
|
# f"-l {__name__}.PointerIntPairSynthProvider "
|
|
# '-x "^llvm::PointerIntPair<.+>$"'
|
|
# )
|
|
# debugger.HandleCommand(
|
|
# "type synthetic add -w llvm "
|
|
# f"-l {__name__}.PointerUnionSynthProvider "
|
|
# '-x "^llvm::PointerUnion<.+>$"'
|
|
# )
|
|
|
|
debugger.HandleCommand(
|
|
"type summary add -w llvm "
|
|
f"-e -F {__name__}.DenseMapSummary "
|
|
'-x "^llvm::DenseMap<.+>$"'
|
|
)
|
|
debugger.HandleCommand(
|
|
"type synthetic add -w llvm "
|
|
f"-l {__name__}.DenseMapSynthetic "
|
|
'-x "^llvm::DenseMap<.+>$"'
|
|
)
|
|
debugger.HandleCommand(
|
|
"type synthetic add -w llvm "
|
|
f"-l {__name__}.DenseSetSynthetic "
|
|
'-x "^llvm::DenseSet<.+>$"'
|
|
)
|
|
|
|
debugger.HandleCommand(
|
|
"type synthetic add -w llvm "
|
|
f"-l {__name__}.ExpectedSynthetic "
|
|
'-x "^llvm::Expected<.+>$"'
|
|
)
|
|
debugger.HandleCommand(
|
|
"type summary add -w llvm "
|
|
f"-F {__name__}.SmallBitVectorSummary "
|
|
"llvm::SmallBitVector"
|
|
)
|
|
|
|
|
|
# Pretty printer for llvm::SmallVector/llvm::SmallVectorImpl
|
|
class SmallVectorSynthProvider:
|
|
def __init__(self, valobj, internal_dict):
|
|
self.valobj = valobj
|
|
self.update() # initialize this provider
|
|
|
|
def num_children(self):
|
|
return self.size.GetValueAsUnsigned(0)
|
|
|
|
def get_child_index(self, name):
|
|
try:
|
|
return int(name.lstrip("[").rstrip("]"))
|
|
except:
|
|
return -1
|
|
|
|
def get_child_at_index(self, index):
|
|
# Do bounds checking.
|
|
if index < 0:
|
|
return None
|
|
if index >= self.num_children():
|
|
return None
|
|
|
|
offset = index * self.type_size
|
|
return self.begin.CreateChildAtOffset(
|
|
"[" + str(index) + "]", offset, self.data_type
|
|
)
|
|
|
|
def update(self):
|
|
self.begin = self.valobj.GetChildMemberWithName("BeginX")
|
|
self.size = self.valobj.GetChildMemberWithName("Size")
|
|
the_type = self.valobj.GetType()
|
|
# If this is a reference type we have to dereference it to get to the
|
|
# template parameter.
|
|
if the_type.IsReferenceType():
|
|
the_type = the_type.GetDereferencedType()
|
|
|
|
if the_type.IsPointerType():
|
|
the_type = the_type.GetPointeeType()
|
|
|
|
self.data_type = the_type.GetTemplateArgumentType(0)
|
|
self.type_size = self.data_type.GetByteSize()
|
|
assert self.type_size != 0
|
|
|
|
|
|
class ArrayRefSynthProvider:
|
|
"""Provider for llvm::ArrayRef"""
|
|
|
|
def __init__(self, valobj, internal_dict):
|
|
self.valobj = valobj
|
|
self.update() # initialize this provider
|
|
|
|
def num_children(self):
|
|
return self.length
|
|
|
|
def get_child_index(self, name):
|
|
try:
|
|
return int(name.lstrip("[").rstrip("]"))
|
|
except:
|
|
return -1
|
|
|
|
def get_child_at_index(self, index):
|
|
if index < 0 or index >= self.num_children():
|
|
return None
|
|
offset = index * self.type_size
|
|
return self.data.CreateChildAtOffset(
|
|
"[" + str(index) + "]", offset, self.data_type
|
|
)
|
|
|
|
def update(self):
|
|
self.data = self.valobj.GetChildMemberWithName("Data")
|
|
length_obj = self.valobj.GetChildMemberWithName("Length")
|
|
self.length = length_obj.GetValueAsUnsigned(0)
|
|
self.data_type = self.data.GetType().GetPointeeType()
|
|
self.type_size = self.data_type.GetByteSize()
|
|
assert self.type_size != 0
|
|
|
|
|
|
def SmallStringSummaryProvider(valobj, internal_dict):
|
|
# The underlying SmallVector base class is the first child.
|
|
vector = valobj.GetChildAtIndex(0)
|
|
num_elements = vector.GetNumChildren()
|
|
res = '"'
|
|
for i in range(num_elements):
|
|
c = vector.GetChildAtIndex(i)
|
|
if c:
|
|
res += chr(c.GetValueAsUnsigned())
|
|
res += '"'
|
|
return res
|
|
|
|
|
|
def StringRefSummaryProvider(valobj, internal_dict):
|
|
data_pointer = valobj.GetChildMemberWithName("Data")
|
|
length = valobj.GetChildMemberWithName("Length").unsigned
|
|
if data_pointer.unsigned == 0 or length == 0:
|
|
return '""'
|
|
|
|
data = data_pointer.deref
|
|
# StringRef may be uninitialized with length exceeding available memory,
|
|
# potentially causing bad_alloc exceptions. Limit the length to max string summary setting.
|
|
limit_obj = valobj.target.debugger.GetSetting("target.max-string-summary-length")
|
|
if limit_obj:
|
|
length = min(length, limit_obj.GetUnsignedIntegerValue())
|
|
# Get a char[N] type, from the underlying char type.
|
|
array_type = data.type.GetArrayType(length)
|
|
# Cast the char* string data to a char[N] array.
|
|
char_array = data.Cast(array_type)
|
|
# Use the builtin summary for its support of max-string-summary-length and
|
|
# display of non-printable bytes.
|
|
return char_array.summary
|
|
|
|
|
|
def ConstStringSummaryProvider(valobj, internal_dict):
|
|
if valobj.GetNumChildren() == 1:
|
|
return valobj.GetChildAtIndex(0).GetSummary()
|
|
return ""
|
|
|
|
|
|
def get_expression_path(val):
|
|
stream = lldb.SBStream()
|
|
if not val.GetExpressionPath(stream):
|
|
return None
|
|
return stream.GetData()
|
|
|
|
|
|
class PointerIntPairSynthProvider:
|
|
def __init__(self, valobj, internal_dict):
|
|
self.valobj = valobj
|
|
self.update()
|
|
|
|
def num_children(self):
|
|
return 2
|
|
|
|
def get_child_index(self, name):
|
|
if name == "Pointer":
|
|
return 0
|
|
if name == "Int":
|
|
return 1
|
|
return None
|
|
|
|
def get_child_at_index(self, index):
|
|
expr_path = get_expression_path(self.valobj)
|
|
if index == 0:
|
|
return self.valobj.CreateValueFromExpression(
|
|
"Pointer", f"({self.pointer_ty.name}){expr_path}.getPointer()"
|
|
)
|
|
if index == 1:
|
|
return self.valobj.CreateValueFromExpression(
|
|
"Int", f"({self.int_ty.name}){expr_path}.getInt()"
|
|
)
|
|
return None
|
|
|
|
def update(self):
|
|
self.pointer_ty = self.valobj.GetType().GetTemplateArgumentType(0)
|
|
self.int_ty = self.valobj.GetType().GetTemplateArgumentType(2)
|
|
|
|
|
|
def parse_template_parameters(typename):
|
|
"""
|
|
LLDB doesn't support template parameter packs, so let's parse them manually.
|
|
"""
|
|
result = []
|
|
start = typename.find("<")
|
|
end = typename.rfind(">")
|
|
if start < 1 or end < 2 or end - start < 2:
|
|
return result
|
|
|
|
nesting_level = 0
|
|
current_parameter_start = start + 1
|
|
|
|
for i in range(start + 1, end + 1):
|
|
c = typename[i]
|
|
if c == "<":
|
|
nesting_level += 1
|
|
elif c == ">":
|
|
nesting_level -= 1
|
|
elif c == "," and nesting_level == 0:
|
|
result.append(typename[current_parameter_start:i].strip())
|
|
current_parameter_start = i + 1
|
|
|
|
result.append(typename[current_parameter_start:i].strip())
|
|
|
|
return result
|
|
|
|
|
|
class PointerUnionSynthProvider:
|
|
def __init__(self, valobj, internal_dict):
|
|
self.valobj = valobj
|
|
self.update()
|
|
|
|
def num_children(self):
|
|
return 1
|
|
|
|
def get_child_index(self, name):
|
|
if name == "Ptr":
|
|
return 0
|
|
return None
|
|
|
|
def get_child_at_index(self, index):
|
|
if index != 0:
|
|
return None
|
|
ptr_type_name = self.template_args[self.active_type_tag]
|
|
return self.valobj.CreateValueFromExpression(
|
|
"Ptr", f"({ptr_type_name}){self.val_expr_path}.getPointer()"
|
|
)
|
|
|
|
def update(self):
|
|
self.pointer_int_pair = self.valobj.GetChildMemberWithName("Val")
|
|
self.val_expr_path = get_expression_path(
|
|
self.valobj.GetChildMemberWithName("Val")
|
|
)
|
|
self.active_type_tag = self.valobj.CreateValueFromExpression(
|
|
"", f"(int){self.val_expr_path}.getInt()"
|
|
).GetValueAsSigned()
|
|
self.template_args = parse_template_parameters(self.valobj.GetType().name)
|
|
|
|
|
|
def DenseMapSummary(valobj: lldb.SBValue, _) -> str:
|
|
raw_value = valobj.GetNonSyntheticValue()
|
|
num_entries = raw_value.GetChildMemberWithName("NumEntries").unsigned
|
|
num_tombstones = raw_value.GetChildMemberWithName("NumTombstones").unsigned
|
|
|
|
summary = f"size={num_entries}"
|
|
if num_tombstones == 1:
|
|
# The heuristic to identify valid entries does not handle the case of a
|
|
# single tombstone. The summary calls attention to this.
|
|
summary = f"tombstones=1, {summary}"
|
|
return summary
|
|
|
|
|
|
class DenseMapSynthetic:
|
|
valobj: lldb.SBValue
|
|
|
|
# The indexes into `Buckets` that contain valid map entries.
|
|
child_buckets: list[int]
|
|
|
|
def __init__(self, valobj: lldb.SBValue, _) -> None:
|
|
self.valobj = valobj
|
|
|
|
def num_children(self) -> int:
|
|
return len(self.child_buckets)
|
|
|
|
def get_child_at_index(self, child_index: int) -> lldb.SBValue:
|
|
bucket_index = self.child_buckets[child_index]
|
|
entry = self.valobj.GetValueForExpressionPath(f".Buckets[{bucket_index}]")
|
|
|
|
# By default, DenseMap instances use DenseMapPair to hold key-value
|
|
# entries. When the entry is a DenseMapPair, unwrap it to expose the
|
|
# children as simple std::pair values.
|
|
#
|
|
# This entry type is customizable (a template parameter). For other
|
|
# types, expose the entry type as is.
|
|
if entry.type.name.startswith("llvm::detail::DenseMapPair<"):
|
|
entry = entry.GetChildAtIndex(0)
|
|
|
|
return entry.Clone(f"[{child_index}]")
|
|
|
|
def update(self):
|
|
self.child_buckets = []
|
|
|
|
num_entries = self.valobj.GetChildMemberWithName("NumEntries").unsigned
|
|
if num_entries == 0:
|
|
return
|
|
|
|
buckets = self.valobj.GetChildMemberWithName("Buckets")
|
|
num_buckets = self.valobj.GetChildMemberWithName("NumBuckets").unsigned
|
|
|
|
# Bucket entries contain one of the following:
|
|
# 1. Valid key-value
|
|
# 2. Empty key
|
|
# 3. Tombstone key (a deleted entry)
|
|
#
|
|
# NumBuckets is always greater than NumEntries. The empty key, and
|
|
# potentially the tombstone key, will occur multiple times. A key that
|
|
# is repeated is either the empty key or the tombstone key.
|
|
|
|
# For each key, collect a list of buckets it appears in.
|
|
key_buckets: dict[str, list[int]] = collections.defaultdict(list)
|
|
for index in range(num_buckets):
|
|
bucket = buckets.GetValueForExpressionPath(f"[{index}]")
|
|
key = bucket.GetChildAtIndex(0)
|
|
key_buckets[str(key.data)].append(index)
|
|
|
|
# Heuristic: This is not a multi-map, any repeated (non-unique) keys are
|
|
# either the the empty key or the tombstone key. Populate child_buckets
|
|
# with the indexes of entries containing unique keys.
|
|
for indexes in key_buckets.values():
|
|
if len(indexes) == 1:
|
|
self.child_buckets.append(indexes[0])
|
|
|
|
|
|
class DenseSetSynthetic:
|
|
valobj: lldb.SBValue
|
|
map: lldb.SBValue
|
|
|
|
def __init__(self, valobj: lldb.SBValue, _) -> None:
|
|
self.valobj = valobj
|
|
|
|
def num_children(self) -> int:
|
|
return self.map.num_children
|
|
|
|
def get_child_at_index(self, idx: int) -> lldb.SBValue:
|
|
map_entry = self.map.child[idx]
|
|
set_entry = map_entry.GetChildAtIndex(0)
|
|
return set_entry.Clone(f"[{idx}]")
|
|
|
|
def update(self):
|
|
raw_map = self.valobj.GetChildMemberWithName("TheMap")
|
|
self.map = raw_map.GetSyntheticValue()
|
|
|
|
|
|
class ExpectedSynthetic:
|
|
# The llvm::Expected<T> value.
|
|
expected: lldb.SBValue
|
|
# The stored success value or error value.
|
|
stored_value: lldb.SBValue
|
|
|
|
def __init__(self, valobj: lldb.SBValue, _) -> None:
|
|
self.expected = valobj
|
|
|
|
def update(self) -> None:
|
|
has_error = self.expected.GetChildMemberWithName("HasError").unsigned
|
|
if not has_error:
|
|
name = "value"
|
|
member = "TStorage"
|
|
else:
|
|
name = "error"
|
|
member = "ErrorStorage"
|
|
# Anonymous union.
|
|
union = self.expected.child[0]
|
|
storage = union.GetChildMemberWithName(member)
|
|
stored_type = storage.type.template_args[0]
|
|
self.stored_value = storage.Cast(stored_type).Clone(name)
|
|
|
|
def num_children(self) -> int:
|
|
return 1
|
|
|
|
def get_child_index(self, name: str) -> int:
|
|
if name == self.stored_value.name:
|
|
return 0
|
|
# Allow dereferencing for values, not errors.
|
|
if name == "$$dereference$$" and self.stored_value.name == "value":
|
|
return 0
|
|
return -1
|
|
|
|
def get_child_at_index(self, idx: int) -> lldb.SBValue:
|
|
if idx == 0:
|
|
return self.stored_value
|
|
return lldb.SBValue()
|
|
|
|
|
|
def SmallBitVectorSummary(valobj, _):
|
|
underlyingValue = valobj.GetChildMemberWithName("X").unsigned
|
|
numBaseBits = valobj.target.addr_size * 8
|
|
smallNumRawBits = numBaseBits - 1
|
|
smallNumSizeBits = None
|
|
if numBaseBits == 32:
|
|
smallNumSizeBits = 5
|
|
elif numBaseBits == 64:
|
|
smallNumSizeBits = 6
|
|
else:
|
|
smallNumSizeBits = smallNumRawBits
|
|
smallNumDataBits = smallNumRawBits - smallNumSizeBits
|
|
|
|
# If our underlying value is not small, print we can not dump large values.
|
|
isSmallMask = 1
|
|
if underlyingValue & isSmallMask == 0:
|
|
return "<can not read large SmallBitVector>"
|
|
|
|
smallRawBits = underlyingValue >> 1
|
|
smallSize = smallRawBits >> smallNumDataBits
|
|
bits = smallRawBits & ((1 << (smallSize + 1)) - 1)
|
|
# format `bits` in binary (b), with 0 padding, of width `smallSize`, and left aligned (>)
|
|
return f"[{bits:0>{smallSize}b}]"
|