SBModule.i revision 1dbf2a82654bebe365eb882b2cad9af413418222
1//===-- SWIG Interface for SBModule -----------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10namespace lldb { 11 12%feature("docstring", 13"Represents an executable image and its associated object and symbol files. 14 15The module is designed to be able to select a single slice of an 16executable image as it would appear on disk and during program 17execution. 18 19You can retrieve SBModule from SBSymbolContext, which in turn is available 20from SBFrame. 21 22SBModule supports symbol iteration, for example, 23 24 for symbol in module: 25 name = symbol.GetName() 26 saddr = symbol.GetStartAddress() 27 eaddr = symbol.GetEndAddress() 28 29and rich comparion methods which allow the API program to use, 30 31 if thisModule == thatModule: 32 print 'This module is the same as that module' 33 34to test module equality. A module also contains object file sections, namely 35SBSection. SBModule supports section iteration through section_iter(), for 36example, 37 38 print 'Number of sections: %d' % module.GetNumSections() 39 for sec in module.section_iter(): 40 print sec 41 42And to iterate the symbols within a SBSection, use symbol_in_section_iter(), 43 44 # Iterates the text section and prints each symbols within each sub-section. 45 for subsec in text_sec: 46 print INDENT + repr(subsec) 47 for sym in exe_module.symbol_in_section_iter(subsec): 48 print INDENT2 + repr(sym) 49 print INDENT2 + 'symbol type: %s' % symbol_type_to_str(sym.GetType()) 50 51produces this following output: 52 53 [0x0000000100001780-0x0000000100001d5c) a.out.__TEXT.__text 54 id = {0x00000004}, name = 'mask_access(MaskAction, unsigned int)', range = [0x00000001000017c0-0x0000000100001870) 55 symbol type: code 56 id = {0x00000008}, name = 'thread_func(void*)', range = [0x0000000100001870-0x00000001000019b0) 57 symbol type: code 58 id = {0x0000000c}, name = 'main', range = [0x00000001000019b0-0x0000000100001d5c) 59 symbol type: code 60 id = {0x00000023}, name = 'start', address = 0x0000000100001780 61 symbol type: code 62 [0x0000000100001d5c-0x0000000100001da4) a.out.__TEXT.__stubs 63 id = {0x00000024}, name = '__stack_chk_fail', range = [0x0000000100001d5c-0x0000000100001d62) 64 symbol type: trampoline 65 id = {0x00000028}, name = 'exit', range = [0x0000000100001d62-0x0000000100001d68) 66 symbol type: trampoline 67 id = {0x00000029}, name = 'fflush', range = [0x0000000100001d68-0x0000000100001d6e) 68 symbol type: trampoline 69 id = {0x0000002a}, name = 'fgets', range = [0x0000000100001d6e-0x0000000100001d74) 70 symbol type: trampoline 71 id = {0x0000002b}, name = 'printf', range = [0x0000000100001d74-0x0000000100001d7a) 72 symbol type: trampoline 73 id = {0x0000002c}, name = 'pthread_create', range = [0x0000000100001d7a-0x0000000100001d80) 74 symbol type: trampoline 75 id = {0x0000002d}, name = 'pthread_join', range = [0x0000000100001d80-0x0000000100001d86) 76 symbol type: trampoline 77 id = {0x0000002e}, name = 'pthread_mutex_lock', range = [0x0000000100001d86-0x0000000100001d8c) 78 symbol type: trampoline 79 id = {0x0000002f}, name = 'pthread_mutex_unlock', range = [0x0000000100001d8c-0x0000000100001d92) 80 symbol type: trampoline 81 id = {0x00000030}, name = 'rand', range = [0x0000000100001d92-0x0000000100001d98) 82 symbol type: trampoline 83 id = {0x00000031}, name = 'strtoul', range = [0x0000000100001d98-0x0000000100001d9e) 84 symbol type: trampoline 85 id = {0x00000032}, name = 'usleep', range = [0x0000000100001d9e-0x0000000100001da4) 86 symbol type: trampoline 87 [0x0000000100001da4-0x0000000100001e2c) a.out.__TEXT.__stub_helper 88 [0x0000000100001e2c-0x0000000100001f10) a.out.__TEXT.__cstring 89 [0x0000000100001f10-0x0000000100001f68) a.out.__TEXT.__unwind_info 90 [0x0000000100001f68-0x0000000100001ff8) a.out.__TEXT.__eh_frame 91" 92) SBModule; 93class SBModule 94{ 95public: 96 97 SBModule (); 98 99 SBModule (const SBModule &rhs); 100 101 SBModule (lldb::SBProcess &process, 102 lldb::addr_t header_addr); 103 104 ~SBModule (); 105 106 bool 107 IsValid () const; 108 109 void 110 Clear(); 111 112 %feature("docstring", " 113 //------------------------------------------------------------------ 114 /// Get const accessor for the module file specification. 115 /// 116 /// This function returns the file for the module on the host system 117 /// that is running LLDB. This can differ from the path on the 118 /// platform since we might be doing remote debugging. 119 /// 120 /// @return 121 /// A const reference to the file specification object. 122 //------------------------------------------------------------------ 123 ") GetFileSpec; 124 lldb::SBFileSpec 125 GetFileSpec () const; 126 127 %feature("docstring", " 128 //------------------------------------------------------------------ 129 /// Get accessor for the module platform file specification. 130 /// 131 /// Platform file refers to the path of the module as it is known on 132 /// the remote system on which it is being debugged. For local 133 /// debugging this is always the same as Module::GetFileSpec(). But 134 /// remote debugging might mention a file '/usr/lib/liba.dylib' 135 /// which might be locally downloaded and cached. In this case the 136 /// platform file could be something like: 137 /// '/tmp/lldb/platform-cache/remote.host.computer/usr/lib/liba.dylib' 138 /// The file could also be cached in a local developer kit directory. 139 /// 140 /// @return 141 /// A const reference to the file specification object. 142 //------------------------------------------------------------------ 143 ") GetPlatformFileSpec; 144 lldb::SBFileSpec 145 GetPlatformFileSpec () const; 146 147 bool 148 SetPlatformFileSpec (const lldb::SBFileSpec &platform_file); 149 150 %feature("docstring", "Returns the UUID of the module as a Python string." 151 ) GetUUIDString; 152 const char * 153 GetUUIDString () const; 154 155 lldb::SBSection 156 FindSection (const char *sect_name); 157 158 lldb::SBAddress 159 ResolveFileAddress (lldb::addr_t vm_addr); 160 161 lldb::SBSymbolContext 162 ResolveSymbolContextForAddress (const lldb::SBAddress& addr, 163 uint32_t resolve_scope); 164 165 bool 166 GetDescription (lldb::SBStream &description); 167 168 uint32_t 169 GetNumCompileUnits(); 170 171 lldb::SBCompileUnit 172 GetCompileUnitAtIndex (uint32_t); 173 174 size_t 175 GetNumSymbols (); 176 177 lldb::SBSymbol 178 GetSymbolAtIndex (size_t idx); 179 180 size_t 181 GetNumSections (); 182 183 lldb::SBSection 184 GetSectionAtIndex (size_t idx); 185 186 187 %feature("docstring", " 188 //------------------------------------------------------------------ 189 /// Find functions by name. 190 /// 191 /// @param[in] name 192 /// The name of the function we are looking for. 193 /// 194 /// @param[in] name_type_mask 195 /// A logical OR of one or more FunctionNameType enum bits that 196 /// indicate what kind of names should be used when doing the 197 /// lookup. Bits include fully qualified names, base names, 198 /// C++ methods, or ObjC selectors. 199 /// See FunctionNameType for more details. 200 /// 201 /// @return 202 /// A symbol context list that gets filled in with all of the 203 /// matches. 204 //------------------------------------------------------------------ 205 ") FindFunctions; 206 lldb::SBSymbolContextList 207 FindFunctions (const char *name, 208 uint32_t name_type_mask = lldb::eFunctionNameTypeAny); 209 210 lldb::SBType 211 FindFirstType (const char* name); 212 213 lldb::SBTypeList 214 FindTypes (const char* type); 215 216 217 %feature("docstring", " 218 //------------------------------------------------------------------ 219 /// Find global and static variables by name. 220 /// 221 /// @param[in] target 222 /// A valid SBTarget instance representing the debuggee. 223 /// 224 /// @param[in] name 225 /// The name of the global or static variable we are looking 226 /// for. 227 /// 228 /// @param[in] max_matches 229 /// Allow the number of matches to be limited to \a max_matches. 230 /// 231 /// @return 232 /// A list of matched variables in an SBValueList. 233 //------------------------------------------------------------------ 234 ") FindGlobalVariables; 235 lldb::SBValueList 236 FindGlobalVariables (lldb::SBTarget &target, 237 const char *name, 238 uint32_t max_matches); 239 240 lldb::ByteOrder 241 GetByteOrder (); 242 243 uint32_t 244 GetAddressByteSize(); 245 246 const char * 247 GetTriple (); 248 249 uint32_t 250 GetVersion (uint32_t *versions, 251 uint32_t num_versions); 252 253 %pythoncode %{ 254 class symbols_access(object): 255 re_compile_type = type(re.compile('.')) 256 '''A helper object that will lazily hand out lldb.SBModule objects for a target when supplied an index, or by full or partial path.''' 257 def __init__(self, sbmodule): 258 self.sbmodule = sbmodule 259 260 def __len__(self): 261 if self.sbmodule: 262 return self.sbmodule.GetNumSymbols() 263 return 0 264 265 def __getitem__(self, key): 266 count = len(self) 267 if type(key) is int: 268 if key < count: 269 return self.sbmodule.GetSymbolAtIndex(key) 270 elif type(key) is str: 271 matches = [] 272 for idx in range(count): 273 symbol = self.sbmodule.GetSymbolAtIndex(idx) 274 if symbol.name == key or symbol.mangled == key: 275 matches.append(symbol) 276 return matches 277 elif isinstance(key, self.re_compile_type): 278 matches = [] 279 for idx in range(count): 280 symbol = self.sbmodule.GetSymbolAtIndex(idx) 281 added = False 282 name = symbol.name 283 if name: 284 re_match = key.search(name) 285 if re_match: 286 matches.append(symbol) 287 added = True 288 if not added: 289 mangled = symbol.mangled 290 if mangled: 291 re_match = key.search(mangled) 292 if re_match: 293 matches.append(symbol) 294 return matches 295 else: 296 print "error: unsupported item type: %s" % type(key) 297 return None 298 299 def get_symbols_access_object(self): 300 '''An accessor function that returns a symbols_access() object which allows lazy symbol access from a lldb.SBModule object.''' 301 return self.symbols_access (self) 302 303 def get_symbols_array(self): 304 '''An accessor function that returns a list() that contains all symbols in a lldb.SBModule object.''' 305 symbols = [] 306 for idx in range(self.num_symbols): 307 symbols.append(self.GetSymbolAtIndex(idx)) 308 return symbols 309 310 class sections_access(object): 311 re_compile_type = type(re.compile('.')) 312 '''A helper object that will lazily hand out lldb.SBModule objects for a target when supplied an index, or by full or partial path.''' 313 def __init__(self, sbmodule): 314 self.sbmodule = sbmodule 315 316 def __len__(self): 317 if self.sbmodule: 318 return self.sbmodule.GetNumSections() 319 return 0 320 321 def __getitem__(self, key): 322 count = len(self) 323 if type(key) is int: 324 if key < count: 325 return self.sbmodule.GetSectionAtIndex(key) 326 elif type(key) is str: 327 for idx in range(count): 328 section = self.sbmodule.GetSectionAtIndex(idx) 329 if section.name == key: 330 return section 331 elif isinstance(key, self.re_compile_type): 332 matches = [] 333 for idx in range(count): 334 section = self.sbmodule.GetSectionAtIndex(idx) 335 name = section.name 336 if name: 337 re_match = key.search(name) 338 if re_match: 339 matches.append(section) 340 return matches 341 else: 342 print "error: unsupported item type: %s" % type(key) 343 return None 344 345 def get_sections_access_object(self): 346 '''An accessor function that returns a sections_access() object which allows lazy section array access.''' 347 return self.sections_access (self) 348 349 def get_sections_array(self): 350 '''An accessor function that returns an array object that contains all sections in this module object.''' 351 if not hasattr(self, 'sections'): 352 self.sections = [] 353 for idx in range(self.num_sections): 354 self.sections.append(self.GetSectionAtIndex(idx)) 355 return self.sections 356 357 __swig_getmethods__["symbols"] = get_symbols_array 358 if _newclass: x = property(get_symbols_array, None) 359 360 __swig_getmethods__["symbol"] = get_symbols_access_object 361 if _newclass: x = property(get_symbols_access_object, None) 362 363 __swig_getmethods__["sections"] = get_sections_array 364 if _newclass: x = property(get_sections_array, None) 365 366 __swig_getmethods__["section"] = get_sections_access_object 367 if _newclass: x = property(get_sections_access_object, None) 368 369 def get_uuid(self): 370 return uuid.UUID (self.GetUUIDString()) 371 372 __swig_getmethods__["uuid"] = get_uuid 373 if _newclass: x = property(get_uuid, None) 374 375 __swig_getmethods__["file"] = GetFileSpec 376 if _newclass: x = property(GetFileSpec, None) 377 378 __swig_getmethods__["platform_file"] = GetPlatformFileSpec 379 if _newclass: x = property(GetPlatformFileSpec, None) 380 381 __swig_getmethods__["byte_order"] = GetByteOrder 382 if _newclass: x = property(GetByteOrder, None) 383 384 __swig_getmethods__["addr_size"] = GetAddressByteSize 385 if _newclass: x = property(GetAddressByteSize, None) 386 387 __swig_getmethods__["triple"] = GetTriple 388 if _newclass: x = property(GetTriple, None) 389 390 __swig_getmethods__["num_symbols"] = GetNumSymbols 391 if _newclass: x = property(GetNumSymbols, None) 392 393 __swig_getmethods__["num_sections"] = GetNumSections 394 if _newclass: x = property(GetNumSections, None) 395 396 %} 397 398}; 399 400} // namespace lldb 401