SBModule.i revision 39f54ea7c3e0f9fb3bdc0d17a8def6781159d24f
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 (); 102 103 bool 104 IsValid () const; 105 106 void 107 Clear(); 108 109 %feature("docstring", " 110 //------------------------------------------------------------------ 111 /// Get const accessor for the module file specification. 112 /// 113 /// This function returns the file for the module on the host system 114 /// that is running LLDB. This can differ from the path on the 115 /// platform since we might be doing remote debugging. 116 /// 117 /// @return 118 /// A const reference to the file specification object. 119 //------------------------------------------------------------------ 120 ") GetFileSpec; 121 lldb::SBFileSpec 122 GetFileSpec () const; 123 124 %feature("docstring", " 125 //------------------------------------------------------------------ 126 /// Get accessor for the module platform file specification. 127 /// 128 /// Platform file refers to the path of the module as it is known on 129 /// the remote system on which it is being debugged. For local 130 /// debugging this is always the same as Module::GetFileSpec(). But 131 /// remote debugging might mention a file '/usr/lib/liba.dylib' 132 /// which might be locally downloaded and cached. In this case the 133 /// platform file could be something like: 134 /// '/tmp/lldb/platform-cache/remote.host.computer/usr/lib/liba.dylib' 135 /// The file could also be cached in a local developer kit directory. 136 /// 137 /// @return 138 /// A const reference to the file specification object. 139 //------------------------------------------------------------------ 140 ") GetPlatformFileSpec; 141 lldb::SBFileSpec 142 GetPlatformFileSpec () const; 143 144 bool 145 SetPlatformFileSpec (const lldb::SBFileSpec &platform_file); 146 147 %feature("docstring", "Returns the UUID of the module as a Python string." 148 ) GetUUIDString; 149 const char * 150 GetUUIDString () const; 151 152 lldb::SBSection 153 FindSection (const char *sect_name); 154 155 lldb::SBAddress 156 ResolveFileAddress (lldb::addr_t vm_addr); 157 158 lldb::SBSymbolContext 159 ResolveSymbolContextForAddress (const lldb::SBAddress& addr, 160 uint32_t resolve_scope); 161 162 bool 163 GetDescription (lldb::SBStream &description); 164 165 size_t 166 GetNumSymbols (); 167 168 lldb::SBSymbol 169 GetSymbolAtIndex (size_t idx); 170 171 size_t 172 GetNumSections (); 173 174 lldb::SBSection 175 GetSectionAtIndex (size_t idx); 176 177 178 %feature("docstring", " 179 //------------------------------------------------------------------ 180 /// Find functions by name. 181 /// 182 /// @param[in] name 183 /// The name of the function we are looking for. 184 /// 185 /// @param[in] name_type_mask 186 /// A logical OR of one or more FunctionNameType enum bits that 187 /// indicate what kind of names should be used when doing the 188 /// lookup. Bits include fully qualified names, base names, 189 /// C++ methods, or ObjC selectors. 190 /// See FunctionNameType for more details. 191 /// 192 /// @param[in] append 193 /// If true, any matches will be appended to \a sc_list, else 194 /// matches replace the contents of \a sc_list. 195 /// 196 /// @param[out] sc_list 197 /// A symbol context list that gets filled in with all of the 198 /// matches. 199 /// 200 /// @return 201 /// The number of matches added to \a sc_list. 202 //------------------------------------------------------------------ 203 ") FindFunctions; 204 uint32_t 205 FindFunctions (const char *name, 206 uint32_t name_type_mask, // Logical OR one or more FunctionNameType enum bits 207 bool append, 208 lldb::SBSymbolContextList& sc_list); 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 %pythoncode %{ 250 class symbols_access(object): 251 re_compile_type = type(re.compile('.')) 252 '''A helper object that will lazily hand out lldb.SBModule objects for a target when supplied an index, or by full or partial path.''' 253 def __init__(self, sbmodule): 254 self.sbmodule = sbmodule 255 256 def __len__(self): 257 if self.sbmodule: 258 return self.sbmodule.GetNumSymbols() 259 return 0 260 261 def __getitem__(self, key): 262 count = len(self) 263 if type(key) is int: 264 if key < count: 265 return self.sbmodule.GetSymbolAtIndex(key) 266 elif type(key) is str: 267 matches = [] 268 for idx in range(count): 269 symbol = self.sbmodule.GetSymbolAtIndex(idx) 270 if symbol.name == key or symbol.mangled == key: 271 matches.append(symbol) 272 return matches 273 elif isinstance(key, self.re_compile_type): 274 matches = [] 275 for idx in range(count): 276 symbol = self.sbmodule.GetSymbolAtIndex(idx) 277 added = False 278 name = symbol.name 279 if name: 280 re_match = key.search(name) 281 if re_match: 282 matches.append(symbol) 283 added = True 284 if not added: 285 mangled = symbol.mangled 286 if mangled: 287 re_match = key.search(mangled) 288 if re_match: 289 matches.append(symbol) 290 return matches 291 else: 292 print "error: unsupported item type: %s" % type(key) 293 return None 294 295 def get_symbols_access_object(self): 296 '''An accessor function that returns a symbols_access() object which allows lazy symbol access from a lldb.SBModule object.''' 297 return self.symbols_access (self) 298 299 def get_symbols_array(self): 300 '''An accessor function that returns a list() that contains all symbols in a lldb.SBModule object.''' 301 symbols = [] 302 for idx in range(self.num_symbols): 303 symbols.append(self.GetSymbolAtIndex(idx)) 304 return symbols 305 306 class sections_access(object): 307 re_compile_type = type(re.compile('.')) 308 '''A helper object that will lazily hand out lldb.SBModule objects for a target when supplied an index, or by full or partial path.''' 309 def __init__(self, sbmodule): 310 self.sbmodule = sbmodule 311 312 def __len__(self): 313 if self.sbmodule: 314 return self.sbmodule.GetNumSections() 315 return 0 316 317 def __getitem__(self, key): 318 count = len(self) 319 if type(key) is int: 320 if key < count: 321 return self.sbmodule.GetSectionAtIndex(key) 322 elif type(key) is str: 323 for idx in range(count): 324 section = self.sbmodule.GetSectionAtIndex(idx) 325 if section.name == key: 326 return section 327 elif isinstance(key, self.re_compile_type): 328 matches = [] 329 for idx in range(count): 330 section = self.sbmodule.GetSectionAtIndex(idx) 331 name = section.name 332 if name: 333 re_match = key.search(name) 334 if re_match: 335 matches.append(section) 336 return matches 337 else: 338 print "error: unsupported item type: %s" % type(key) 339 return None 340 341 def get_sections_access_object(self): 342 '''An accessor function that returns a sections_access() object which allows lazy section array access.''' 343 return self.sections_access (self) 344 345 def get_sections_array(self): 346 '''An accessor function that returns an array object that contains all sections in this module object.''' 347 if not hasattr(self, 'sections'): 348 self.sections = [] 349 for idx in range(self.num_sections): 350 self.sections.append(self.GetSectionAtIndex(idx)) 351 return self.sections 352 353 __swig_getmethods__["symbols"] = get_symbols_array 354 if _newclass: x = property(get_symbols_array, None) 355 356 __swig_getmethods__["symbol"] = get_symbols_access_object 357 if _newclass: x = property(get_symbols_access_object, None) 358 359 __swig_getmethods__["sections"] = get_sections_array 360 if _newclass: x = property(get_sections_array, None) 361 362 __swig_getmethods__["section"] = get_sections_access_object 363 if _newclass: x = property(get_sections_access_object, None) 364 365 def get_uuid(self): 366 return uuid.UUID (self.GetUUIDString()) 367 368 __swig_getmethods__["uuid"] = get_uuid 369 if _newclass: x = property(get_uuid, None) 370 371 __swig_getmethods__["file"] = GetFileSpec 372 if _newclass: x = property(GetFileSpec, None) 373 374 __swig_getmethods__["platform_file"] = GetPlatformFileSpec 375 if _newclass: x = property(GetPlatformFileSpec, None) 376 377 __swig_getmethods__["byte_order"] = GetByteOrder 378 if _newclass: x = property(GetByteOrder, None) 379 380 __swig_getmethods__["addr_size"] = GetAddressByteSize 381 if _newclass: x = property(GetAddressByteSize, None) 382 383 __swig_getmethods__["triple"] = GetTriple 384 if _newclass: x = property(GetTriple, None) 385 386 __swig_getmethods__["num_symbols"] = GetNumSymbols 387 if _newclass: x = property(GetNumSymbols, None) 388 389 __swig_getmethods__["num_sections"] = GetNumSections 390 if _newclass: x = property(GetNumSections, None) 391 392 %} 393 394}; 395 396} // namespace lldb 397