@@ -94,6 +94,11 @@ def __lldb_init_module(debugger, internal_dict):
9494 f"-l { __name__ } .ExpectedSynthetic "
9595 '-x "^llvm::Expected<.+>$"'
9696 )
97+ debugger .HandleCommand (
98+ "type summary add -w llvm "
99+ f"-F { __name__ } .SmallBitVectorSummary "
100+ "llvm::SmallBitVector"
101+ )
97102
98103
99104# Pretty printer for llvm::SmallVector/llvm::SmallVectorImpl
@@ -448,3 +453,28 @@ def get_child_at_index(self, idx: int) -> lldb.SBValue:
448453 if idx == 0 :
449454 return self .stored_value
450455 return lldb .SBValue ()
456+
457+
458+ def SmallBitVectorSummary (valobj , _ ):
459+ underlyingValue = valobj .GetChildMemberWithName ("X" ).unsigned
460+ numBaseBits = valobj .target .addr_size * 8
461+ smallNumRawBits = numBaseBits - 1
462+ smallNumSizeBits = None
463+ if numBaseBits == 32 :
464+ smallNumSizeBits = 5
465+ elif numBaseBits == 64 :
466+ smallNumSizeBits = 6
467+ else :
468+ smallNumSizeBits = smallNumRawBits
469+ smallNumDataBits = smallNumRawBits - smallNumSizeBits
470+
471+ # If our underlying value is not small, print we can not dump large values.
472+ isSmallMask = 1
473+ if underlyingValue & isSmallMask == 0 :
474+ return "<can not read large SmallBitVector>"
475+
476+ smallRawBits = underlyingValue >> 1
477+ smallSize = smallRawBits >> smallNumDataBits
478+ bits = smallRawBits & ((1 << (smallSize + 1 )) - 1 )
479+ # format `bits` in binary (b), with 0 padding, of width `smallSize`, and left aligned (>)
480+ return f"[{ bits :0>{smallSize }b} ]"
0 commit comments