From 6b2bd93918bceac12b0aea61fd13a65676cd4577 Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Wed, 1 Feb 2012 08:09:32 +0000 Subject: Added many more python convenience accessors: You can now access a frame in a thread using: lldb.SBThread.frame[int] -> lldb.SBFrame object for a frame in a thread Where "int" is an integer index. You can also access a list object with all of the frames using: lldb.SBThread.frames => list() of lldb.SBFrame objects All SB objects that give out SBAddress objects have properties named "addr" lldb.SBInstructionList now has the following convenience accessors for len() and instruction access using an index: insts = lldb.frame.function.instructions for idx in range(len(insts)): print insts[idx] Instruction lists can also lookup an isntruction using a lldb.SBAddress as the key: pc_inst = lldb.frame.function.instructions[lldb.frame.addr] lldb.SBProcess now exposes: lldb.SBProcess.is_alive => BOOL Check if a process is exists and is alive lldb.SBProcess.is_running => BOOL check if a process is running (or stepping): lldb.SBProcess.is_running => BOOL check if a process is currently stopped or crashed: lldb.SBProcess.thread[int] => lldb.SBThreads for a given "int" zero based index lldb.SBProcess.threads => list() containing all lldb.SBThread objects in a process SBInstruction now exposes: lldb.SBInstruction.mnemonic => python string for instruction mnemonic lldb.SBInstruction.operands => python string for instruction operands lldb.SBInstruction.command => python string for instruction comment SBModule now exposes: lldb.SBModule.uuid => uuid.UUID(), an UUID object from the "uuid" python module lldb.SBModule.symbol[int] => lldb.Symbol, lookup symbol by zero based index lldb.SBModule.symbol[str] => list() of lldb.Symbol objects that match "str" lldb.SBModule.symbol[re] => list() of lldb.Symbol objecxts that match the regex lldb.SBModule.symbols => list() of all symbols in a module SBAddress objects can now access the current load address with the "lldb.SBAddress.load_addr" property. The current "lldb.target" will be used to try and resolve the load address. Load addresses can also be set using this accessor: addr = lldb.SBAddress() addd.load_addr = 0x123023 Then you can check the section and offset to see if the address got resolved. SBTarget now exposes: lldb.SBTarget.module[int] => lldb.SBModule from zero based module index lldb.SBTarget.module[str] => lldb.SBModule by basename or fullpath or uuid string lldb.SBTarget.module[uuid.UUID()] => lldb.SBModule whose UUID matches lldb.SBTarget.module[re] => list() of lldb.SBModule objects that match the regex lldb.SBTarget.modules => list() of all lldb.SBModule objects in the target SBSymbol now exposes: lldb.SBSymbol.name => python string for demangled symbol name lldb.SBSymbol.mangled => python string for mangled symbol name or None if there is none lldb.SBSymbol.type => lldb.eSymbolType enum value lldb.SBSymbol.addr => SBAddress object that represents the start address for this symbol (if there is one) lldb.SBSymbol.end_addr => SBAddress for the end address of the symbol (if there is one) lldb.SBSymbol.prologue_size => pythin int containing The size of the prologue in bytes lldb.SBSymbol.instructions => SBInstructionList containing all instructions for this symbol SBFunction now also has these new properties in addition to what is already has: lldb.SBFunction.addr => SBAddress object that represents the start address for this function lldb.SBFunction.end_addr => SBAddress for the end address of the function lldb.SBFunction.instructions => SBInstructionList containing all instructions for this function SBFrame now exposes the SBAddress for the frame: lldb.SBFrame.addr => SBAddress which is the section offset address for the current frame PC These are all in addition to what was already added. Documentation and website updates coming soon. llvm-svn: 149489 --- lldb/scripts/Python/interface/SBModule.i | 73 ++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 3 deletions(-) (limited to 'lldb/scripts/Python/interface/SBModule.i') diff --git a/lldb/scripts/Python/interface/SBModule.i b/lldb/scripts/Python/interface/SBModule.i index 547b4a2..d3c4352 100644 --- a/lldb/scripts/Python/interface/SBModule.i +++ b/lldb/scripts/Python/interface/SBModule.i @@ -247,15 +247,82 @@ public: GetTriple (); %pythoncode %{ + class symbols_access(object): + re_type = type(re.compile('.')) + '''A helper object that will lazily hand out lldb.SBModule objects for a target when supplied an index, or by full or partial path.''' + def __init__(self, sbmodule): + self.sbmodule = sbmodule + + def __len__(self): + if self.sbmodule: + return self.sbmodule.GetNumSymbols() + return 0 + + def __getitem__(self, key): + count = self.sbmodule.GetNumSymbols() + if type(key) is int: + if key < count: + return self.sbmodule.GetSymbolAtIndex(key) + elif type(key) is str: + matches = [] + for idx in range(count): + symbol = self.sbmodule.GetSymbolAtIndex(idx) + if symbol.name == key or symbol.mangled == key: + matches.append(symbol) + if len(matches): + return matches + elif isinstance(key, self.re_type): + matches = [] + for idx in range(count): + symbol = self.sbmodule.GetSymbolAtIndex(idx) + added = False + name = symbol.name + if name: + re_match = key.search(name) + if re_match: + matches.append(symbol) + added = True + if not added: + mangled = symbol.mangled + if mangled: + re_match = key.search(mangled) + if re_match: + matches.append(symbol) + if len(matches): + return matches + else: + print "error: unsupported item type: %s" % type(key) + return None + + def get_symbols_access_object(self): + '''An accessor function that retuns a symbols_access() object which allows lazy module array access.''' + return self.symbols_access (self) + + def get_symbols_array(self): + '''An accessor function that retuns an array object that contains all modules in this target object.''' + symbols = [] + for idx in range(self.GetNumSymbols()): + symbols.append(self.GetSymbolAtIndex(idx)) + return symbols + + __swig_getmethods__["symbols"] = get_symbols_array + if _newclass: x = property(get_symbols_array, None) + + __swig_getmethods__["symbol"] = get_symbols_access_object + if _newclass: x = property(get_symbols_access_object, None) + + def get_uuid(self): + return uuid.UUID (self.GetUUIDString()) + + __swig_getmethods__["uuid"] = get_uuid + if _newclass: x = property(get_uuid, None) + __swig_getmethods__["file"] = GetFileSpec if _newclass: x = property(GetFileSpec, None) __swig_getmethods__["platform_file"] = GetPlatformFileSpec if _newclass: x = property(GetPlatformFileSpec, None) - __swig_getmethods__["uuid"] = GetUUIDString - if _newclass: x = property(GetUUIDString, None) - __swig_getmethods__["byte_order"] = GetByteOrder if _newclass: x = property(GetByteOrder, None) -- cgit v1.1