Skip to content

Instantly share code, notes, and snippets.

@jbevain
Created May 8, 2025 20:59
Show Gist options
  • Save jbevain/6a0afe03fa458cda51bc65b8d9b1fda0 to your computer and use it in GitHub Desktop.
Save jbevain/6a0afe03fa458cda51bc65b8d9b1fda0 to your computer and use it in GitHub Desktop.
"""
LLDB pretty printer for NativeAOT
Add to ~/.lldbinit:
command script import {path-to-lldb-nativeaot}/NativeAOT.py
"""
import lldb
def __lldb_init_module(debugger, dict):
debugger.HandleCommand('type summary add -x "^String$" -e -F NativeAOT.String_SummaryProvider')
debugger.HandleCommand('type summary add -x "^__Array<.+>$" -e -F NativeAOT.Array_SummaryProvider')
debugger.HandleCommand('type synthetic add -x "^__Array<.+>$" -l NativeAOT.Array_SyntheticProvider')
debugger.HandleCommand('type synthetic add -x "^Object$" -l NativeAOT.Object_SyntheticProvider')
def String_SummaryProvider(valobj, internal_dict):
valobj = valobj.GetNonSyntheticValue()
strval = '"'
try:
length = valobj.GetChildMemberWithName('_stringLength').GetValueAsUnsigned()
chars = valobj.GetChildMemberWithName('_firstChar').address_of.GetPointeeData(0, length).uint16
for i in range(0, length):
strval += chr(chars[i])
except:
pass
strval = strval + '"'
return strval
def Array_SummaryProvider(valobj, internal_dict):
return 'length=' + str(valobj.GetNonSyntheticValue().GetChildMemberWithName('_numComponents').GetValueAsUnsigned())
class Array_SyntheticProvider:
def __init__(self, valobj, internal_dict):
self.valobj = valobj
def num_children(self):
return self.valobj.GetChildMemberWithName('_numComponents').GetValueAsUnsigned()
def get_child_index(self,name):
try:
return int(name.lstrip('[').rstrip(']'))
except:
return None
def get_child_at_index(self,index):
type = self.valobj.GetChildMemberWithName('m_Data').GetType().GetArrayElementType()
return self.valobj.GetChildMemberWithName('_numComponents').address_of.CreateChildAtOffset('[' + str(index) + ']', self.valobj.target.GetAddressByteSize() + index * type.GetByteSize(), type)
class Object_SyntheticProvider:
def __init__(self, valobj, internal_dict):
self.valobj = valobj
def num_children(self):
return 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment