yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
9666fbcab
master
1""" 2This python script provides LLDB formatters for Slang core types. 3To use it, see the `docs/debugging.md` file in this repo. 4""" 5 6import lldb 7 8# Set to True to enable the logger 9ENABLE_LOGGING = True 10 11 12# log to the LLDB formatter stream 13def log (msg ): 14if ENABLE_LOGGING : 15lldb .formatters .Logger .Logger ()>> msg 16 17 18def make_string (F :lldb .SBData ,L :int )-> str : 19strval = "" 20G = F .uint8 21for X in range (L ): 22V = G [X ] 23if V == 0 : 24break 25strval = strval + chr (V % 256 ) 26return '"' + strval + '"' 27 28 29# Return the pointer to the data in a Slang::RefPtr 30def get_ref_pointer (valobj :lldb .SBValue )-> lldb .SBValue : 31return valobj .GetNonSyntheticValue ().GetChildMemberWithName ("pointer" ) 32 33 34# Check if a pointer is nullptr 35def is_nullptr (valobj :lldb .SBValue )-> bool : 36return valobj .GetValueAsUnsigned (0 )== 0 37 38 39# Slang::String summary 40def String_summary (valobj :lldb .SBValue ,dict )-> str : 41buffer_ptr = get_ref_pointer (valobj .GetChildMemberWithName ("m_buffer" )) 42if is_nullptr (buffer_ptr ): 43return '""' 44buffer = buffer_ptr .Dereference () 45length = buffer .GetChildMemberWithName ("length" ).GetValueAsUnsigned (0 ) 46data = buffer_ptr .GetPointeeData (1 ,length ) 47return make_string (data ,length ) 48 49 50# Slang::UnownedStringSlice summary 51def UnownedStringSlice_summary (valobj :lldb .SBValue ,dict )-> str : 52begin = valobj .GetChildMemberWithName ("m_begin" ) 53end = valobj .GetChildMemberWithName ("m_end" ) 54length = end .GetValueAsUnsigned (0 )- begin .GetValueAsUnsigned (0 ) 55if length <= 0 : 56return '""' 57data = begin .GetPointeeData (0 ,length ) 58return make_string (data ,length ) 59 60 61# Slang::RefPtr synthetic provider 62class RefPtr_synthetic (lldb .SBSyntheticValueProvider ): 63def __init__ (self ,valobj :lldb .SBValue ,dict ): 64self .valobj = valobj 65 66def has_children (self ): 67return True 68 69def num_children (self ): 70return len (self .children ) 71 72def get_child_index (self ,name ): 73for idx in range (self .num_children ()): 74if self .children [idx ].GetName ()== name : 75return idx 76return - 1 77 78def get_child_at_index (self ,idx ): 79if idx >= 0 and idx < self .num_children (): 80return self .children [idx ] 81else : 82return None 83 84def update (self ): 85self .pointer = self .valobj .GetNonSyntheticValue ().GetChildMemberWithName ( 86"pointer" 87 ) 88self .children = [] 89if not is_nullptr (self .pointer ): 90self .children = self .pointer .Dereference ().children 91 92 93# Slang::RefPtr summary 94def RefPtr_summary (valobj :lldb .SBValue ,dict )-> str : 95pointer = valobj .GetNonSyntheticValue ().GetChildMemberWithName ("pointer" ) 96if is_nullptr (pointer ): 97return "nullptr" 98pointee = pointer .Dereference () 99refcount = pointee .GetChildMemberWithName ("referenceCount" ).GetValueAsUnsigned () 100return str (pointer .GetValue ())+ " refcount=" + str (refcount ) 101 102 103# Slang::ComPtr synthetic provider 104class ComPtr_synthetic (lldb .SBSyntheticValueProvider ): 105def __init__ (self ,valobj :lldb .SBValue ,dict ): 106self .valobj = valobj 107 108def has_children (self ): 109return len (self .children )> 0 110 111def num_children (self ): 112return len (self .children ) 113 114def get_child_index (self ,name ): 115for idx in range (self .num_children ()): 116if self .children [idx ].GetName ()== name : 117return idx 118return - 1 119 120def get_child_at_index (self ,idx ): 121if idx >= 0 and idx < self .num_children (): 122return self .children [idx ] 123else : 124return None 125 126def update (self ): 127self .pointer = self .valobj .GetChildMemberWithName ("m_ptr" ) 128self .children = [] 129if not is_nullptr (self .pointer ): 130self .children = self .pointer .Dereference ().children 131 132 133# Slang::ComPtr summary 134def ComPtr_summary (valobj :lldb .SBValue ,dict )-> str : 135pointer = valobj .GetNonSyntheticValue ().GetChildMemberWithName ("m_ptr" ) 136if is_nullptr (pointer ): 137return "nullptr" 138return str (pointer .GetValue ()) 139 140 141# Slang::Array synthetic provider 142class Array_synthetic (lldb .SBSyntheticValueProvider ): 143def __init__ (self ,valobj :lldb .SBValue ,dict ): 144self .valobj = valobj 145 146def has_children (self ): 147return True 148 149def num_children (self ): 150return self .count .GetValueAsUnsigned (0 ) 151 152def get_child_index (self ,name ): 153return int (name .lstrip ("[" ).rstrip ("]" )) 154 155def get_child_at_index (self ,idx ): 156if idx >= 0 and idx < self .num_children (): 157offset = idx * self .data_size 158return self .buffer .CreateChildAtOffset ( 159"[" + str (idx )+ "]" ,offset ,self .data_type 160 ) 161else : 162return None 163 164def update (self ): 165self .count = self .valobj .GetChildMemberWithName ("m_count" ) 166self .buffer = self .valobj .GetChildMemberWithName ("m_buffer" ) 167self .data_type = self .buffer .GetType ().GetArrayElementType () 168self .data_size = self .data_type .GetByteSize () 169 170 171# Slang::List synthetic provider 172class List_synthetic (lldb .SBSyntheticValueProvider ): 173def __init__ (self ,valobj :lldb .SBValue ,dict ): 174self .valobj = valobj 175 176def has_children (self ): 177return True 178 179def num_children (self ): 180return self .count .GetValueAsUnsigned (0 ) 181 182def get_child_index (self ,name ): 183return int (name .lstrip ("[" ).rstrip ("]" )) 184 185def get_child_at_index (self ,idx ): 186if idx >= 0 and idx < self .num_children (): 187offset = idx * self .data_size 188return self .buffer .CreateChildAtOffset ( 189"[" + str (idx )+ "]" ,offset ,self .data_type 190 ) 191else : 192return None 193 194def update (self ): 195self .count = self .valobj .GetChildMemberWithName ("m_count" ) 196self .buffer = self .valobj .GetChildMemberWithName ("m_buffer" ) 197self .data_type = self .buffer .GetType ().GetPointeeType () 198self .data_size = self .data_type .GetByteSize () 199 200 201# Slang::ShortList synthetic provider 202class ShortList_synthetic (lldb .SBSyntheticValueProvider ): 203def __init__ (self ,valobj :lldb .SBValue ,dict ): 204self .valobj = valobj 205 206def has_children (self ): 207return True 208 209def num_children (self ): 210return self .count .GetValueAsUnsigned (0 ) 211 212def get_child_index (self ,name ): 213return int (name .lstrip ("[" ).rstrip ("]" )) 214 215def get_child_at_index (self ,idx ): 216if idx >= 0 and idx < self .short_count : 217offset = idx * self .data_size 218return self .short_buffer .CreateChildAtOffset ( 219"[" + str (idx )+ "]" ,offset ,self .data_type 220 ) 221elif idx >= self .short_count and idx < self .num_children (): 222offset = (idx - self .short_count )* self .data_size 223return self .buffer .CreateChildAtOffset ( 224"[" + str (idx )+ "]" ,offset ,self .data_type 225 ) 226else : 227return None 228 229def update (self ): 230self .count = self .valobj .GetChildMemberWithName ("m_count" ) 231self .buffer = self .valobj .GetChildMemberWithName ("m_buffer" ) 232self .short_buffer = self .valobj .GetChildMemberWithName ("m_shortBuffer" ) 233self .short_count = self .short_buffer .GetNumChildren () 234self .data_type = self .buffer .GetType ().GetPointeeType () 235self .data_size = self .data_type .GetByteSize () 236 237 238def __lldb_init_module (debugger :lldb .SBDebugger ,internal_dict ): 239if ENABLE_LOGGING : 240lldb .formatters .Logger ._lldb_formatters_debug_level = 2 241 242commands = [ 243# Slang::String 244"type summary add Slang::String -F core_lldb.String_summary -w slang" , 245# Slang::UnownedStringSlice 246"type summary add Slang::UnownedStringSlice -F core_lldb.UnownedStringSlice_summary -w slang" , 247# Slang::RefPtr 248'type synthetic add -x "^Slang::RefPtr<.+>$" -l core_lldb.RefPtr_synthetic -w slang' , 249'type summary add -x "^Slang::RefPtr<.+>$" -F core_lldb.RefPtr_summary -w slang' , 250# Slang::ComPtr 251'type synthetic add -x "^Slang::ComPtr<.+>$" -l core_lldb.ComPtr_synthetic -w slang' , 252'type summary add -x "^Slang::ComPtr<.+>$" -F core_lldb.ComPtr_summary -w slang' , 253# Slang::Array 254'type synthetic add -x "^Slang::Array<.+>$" -l core_lldb.Array_synthetic -w slang' , 255'type summary add --x "^Slang::Array<.+>$" --summary-string "size=${svar%#}" -w slang' , 256# Slang::List 257'type synthetic add -x "^Slang::List<.+>$" -l core_lldb.List_synthetic -w slang' , 258'type summary add --expand -x "^Slang::List<.+>$" --summary-string "size=${var.m_count} capacity=${var.m_capacity}" -w slang' , 259# Slang::ShortList 260'type synthetic add -x "^Slang::ShortList<.+>$" -l core_lldb.ShortList_synthetic -w slang' , 261'type summary add --expand -x "^Slang::ShortList<.+>$" --summary-string "size=${var.m_count} capacity=${var.m_capacity}" -w slang' , 262# Enable slang category 263"type category enable slang" , 264 ] 265 266for c in commands : 267debugger .HandleCommand (c )