2010-09-09 06:54:46 +08:00
|
|
|
"""
|
2010-10-08 05:38:28 +08:00
|
|
|
This LLDB module contains miscellaneous utilities.
|
2010-09-09 06:54:46 +08:00
|
|
|
"""
|
|
|
|
|
|
|
|
import lldb
|
Turns out that the test failure wrt:
rdar://problem/9173060 lldb hangs while running unique-types
disappears if running with clang version >= 3. Modify the TestUniqueTypes.py
to detect if we are running with clang version < 3 and, if true, skip the test.
Update the lldbtest.system() function to return a tuple of (stdoutdata, stderrdata)
since we need the stderr data from "clang -v" command. Modify existing clients of
lldbtest.system() to now use, for example:
# First, capture the golden output emitted by the oracle, i.e., the
# series of printf statements.
- go = system("./a.out", sender=self)
+ go = system("./a.out", sender=self)[0]
# This golden list contains a list of (variable, value) pairs extracted
# from the golden output.
gl = []
And add two utility functions to lldbutil.py.
llvm-svn: 128162
2011-03-24 04:28:59 +08:00
|
|
|
import os, sys
|
2010-10-16 07:33:18 +08:00
|
|
|
import StringIO
|
2010-09-09 06:54:46 +08:00
|
|
|
|
Turns out that the test failure wrt:
rdar://problem/9173060 lldb hangs while running unique-types
disappears if running with clang version >= 3. Modify the TestUniqueTypes.py
to detect if we are running with clang version < 3 and, if true, skip the test.
Update the lldbtest.system() function to return a tuple of (stdoutdata, stderrdata)
since we need the stderr data from "clang -v" command. Modify existing clients of
lldbtest.system() to now use, for example:
# First, capture the golden output emitted by the oracle, i.e., the
# series of printf statements.
- go = system("./a.out", sender=self)
+ go = system("./a.out", sender=self)[0]
# This golden list contains a list of (variable, value) pairs extracted
# from the golden output.
gl = []
And add two utility functions to lldbutil.py.
llvm-svn: 128162
2011-03-24 04:28:59 +08:00
|
|
|
def is_exe(fpath):
|
|
|
|
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
|
|
|
|
|
|
|
|
def which(program):
|
2011-04-19 02:34:09 +08:00
|
|
|
"""Find the full path to a program, or return None."""
|
Turns out that the test failure wrt:
rdar://problem/9173060 lldb hangs while running unique-types
disappears if running with clang version >= 3. Modify the TestUniqueTypes.py
to detect if we are running with clang version < 3 and, if true, skip the test.
Update the lldbtest.system() function to return a tuple of (stdoutdata, stderrdata)
since we need the stderr data from "clang -v" command. Modify existing clients of
lldbtest.system() to now use, for example:
# First, capture the golden output emitted by the oracle, i.e., the
# series of printf statements.
- go = system("./a.out", sender=self)
+ go = system("./a.out", sender=self)[0]
# This golden list contains a list of (variable, value) pairs extracted
# from the golden output.
gl = []
And add two utility functions to lldbutil.py.
llvm-svn: 128162
2011-03-24 04:28:59 +08:00
|
|
|
fpath, fname = os.path.split(program)
|
|
|
|
if fpath:
|
|
|
|
if is_exe(program):
|
|
|
|
return program
|
|
|
|
else:
|
|
|
|
for path in os.environ["PATH"].split(os.pathsep):
|
|
|
|
exe_file = os.path.join(path, program)
|
|
|
|
if is_exe(exe_file):
|
|
|
|
return exe_file
|
|
|
|
return None
|
|
|
|
|
2011-03-03 09:41:57 +08:00
|
|
|
# ===========================================
|
|
|
|
# Iterator for lldb aggregate data structures
|
|
|
|
# ===========================================
|
|
|
|
|
|
|
|
def lldb_iter(obj, getsize, getelem):
|
|
|
|
"""A generator adaptor for lldb aggregate data structures.
|
|
|
|
|
|
|
|
API clients pass in an aggregate object or a container of it, the name of
|
|
|
|
the method to get the size of the aggregate, and the name of the method to
|
|
|
|
get the element by index.
|
|
|
|
|
|
|
|
Example usages:
|
|
|
|
|
|
|
|
1. Pass an aggregate as the first argument:
|
|
|
|
|
|
|
|
def disassemble_instructions (insts):
|
|
|
|
from lldbutil import lldb_iter
|
|
|
|
for i in lldb_iter(insts, 'GetSize', 'GetInstructionAtIndex'):
|
|
|
|
print i
|
|
|
|
|
|
|
|
2. Pass a container of aggregate which provides APIs to get to the size and
|
|
|
|
the element of the aggregate:
|
|
|
|
|
|
|
|
# Module is a container of symbol table
|
|
|
|
module = target.FindModule(filespec)
|
|
|
|
for symbol in lldb_iter(module, 'GetNumSymbols', 'GetSymbolAtIndex'):
|
|
|
|
name = symbol.GetName()
|
|
|
|
...
|
|
|
|
"""
|
|
|
|
size = getattr(obj, getsize)
|
|
|
|
elem = getattr(obj, getelem)
|
|
|
|
for i in range(size()):
|
|
|
|
yield elem(i)
|
|
|
|
|
|
|
|
|
2011-03-04 03:14:00 +08:00
|
|
|
# ===================================================
|
|
|
|
# Disassembly for an SBFunction or an SBSymbol object
|
|
|
|
# ===================================================
|
|
|
|
|
|
|
|
def disassemble(target, function_or_symbol):
|
|
|
|
"""Disassemble the function or symbol given a target.
|
|
|
|
|
|
|
|
It returns the disassembly content in a string object.
|
|
|
|
"""
|
|
|
|
buf = StringIO.StringIO()
|
|
|
|
insts = function_or_symbol.GetInstructions(target)
|
|
|
|
for i in lldb_iter(insts, 'GetSize', 'GetInstructionAtIndex'):
|
|
|
|
print >> buf, i
|
|
|
|
return buf.getvalue()
|
|
|
|
|
|
|
|
|
2011-03-02 09:36:45 +08:00
|
|
|
# ==========================================================
|
|
|
|
# Integer (byte size 1, 2, 4, and 8) to bytearray conversion
|
|
|
|
# ==========================================================
|
|
|
|
|
|
|
|
def int_to_bytearray(val, bytesize):
|
|
|
|
"""Utility function to convert an integer into a bytearray.
|
|
|
|
|
2011-03-03 04:54:22 +08:00
|
|
|
It returns the bytearray in the little endian format. It is easy to get the
|
|
|
|
big endian format, just do ba.reverse() on the returned object.
|
2011-03-02 09:36:45 +08:00
|
|
|
"""
|
2011-03-31 01:54:35 +08:00
|
|
|
import struct
|
2011-03-02 09:36:45 +08:00
|
|
|
|
|
|
|
if bytesize == 1:
|
|
|
|
return bytearray([val])
|
|
|
|
|
|
|
|
# Little endian followed by a format character.
|
|
|
|
template = "<%c"
|
|
|
|
if bytesize == 2:
|
|
|
|
fmt = template % 'h'
|
|
|
|
elif bytesize == 4:
|
|
|
|
fmt = template % 'i'
|
|
|
|
elif bytesize == 4:
|
|
|
|
fmt = template % 'q'
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2011-03-31 01:54:35 +08:00
|
|
|
packed = struct.pack(fmt, val)
|
2011-03-02 09:36:45 +08:00
|
|
|
return bytearray(map(ord, packed))
|
|
|
|
|
|
|
|
def bytearray_to_int(bytes, bytesize):
|
|
|
|
"""Utility function to convert a bytearray into an integer.
|
|
|
|
|
2011-03-03 04:54:22 +08:00
|
|
|
It interprets the bytearray in the little endian format. For a big endian
|
|
|
|
bytearray, just do ba.reverse() on the object before passing it in.
|
2011-03-02 09:36:45 +08:00
|
|
|
"""
|
2011-03-31 01:54:35 +08:00
|
|
|
import struct
|
2011-03-02 09:36:45 +08:00
|
|
|
|
|
|
|
if bytesize == 1:
|
|
|
|
return ba[0]
|
|
|
|
|
|
|
|
# Little endian followed by a format character.
|
|
|
|
template = "<%c"
|
|
|
|
if bytesize == 2:
|
|
|
|
fmt = template % 'h'
|
|
|
|
elif bytesize == 4:
|
|
|
|
fmt = template % 'i'
|
|
|
|
elif bytesize == 4:
|
|
|
|
fmt = template % 'q'
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2011-03-31 01:54:35 +08:00
|
|
|
unpacked = struct.unpack(fmt, str(bytes))
|
2011-03-02 09:36:45 +08:00
|
|
|
return unpacked[0]
|
|
|
|
|
|
|
|
|
2011-03-03 09:41:57 +08:00
|
|
|
# ===========================================================
|
|
|
|
# Returns the list of stopped thread(s) given an lldb process
|
|
|
|
# ===========================================================
|
2010-10-15 09:18:29 +08:00
|
|
|
|
2011-03-03 09:41:57 +08:00
|
|
|
def get_stopped_threads(process, reason):
|
|
|
|
"""Returns the thread(s) with the specified stop reason in a list."""
|
|
|
|
threads = []
|
|
|
|
for t in lldb_iter(process, 'GetNumThreads', 'GetThreadAtIndex'):
|
|
|
|
if t.GetStopReason() == reason:
|
|
|
|
threads.append(t)
|
|
|
|
return threads
|
2010-12-09 03:19:08 +08:00
|
|
|
|
2011-03-03 09:41:57 +08:00
|
|
|
def get_stopped_thread(process, reason):
|
|
|
|
"""A convenience function which returns the first thread with the given stop
|
|
|
|
reason or None.
|
2010-10-09 09:31:09 +08:00
|
|
|
|
2010-12-09 03:19:08 +08:00
|
|
|
Example usages:
|
2010-10-09 09:31:09 +08:00
|
|
|
|
2011-03-03 09:41:57 +08:00
|
|
|
1. Get the stopped thread due to a breakpoint condition
|
2010-10-09 09:31:09 +08:00
|
|
|
|
2011-03-03 09:41:57 +08:00
|
|
|
...
|
|
|
|
from lldbutil import get_stopped_thread
|
|
|
|
thread = get_stopped_thread(self.process, lldb.eStopReasonPlanComplete)
|
|
|
|
self.assertTrue(thread != None, "There should be a thread stopped due to breakpoint condition")
|
|
|
|
...
|
2010-12-09 03:19:08 +08:00
|
|
|
|
2011-03-03 09:41:57 +08:00
|
|
|
2. Get the thread stopped due to a breakpoint
|
2010-12-09 03:19:08 +08:00
|
|
|
|
2011-03-03 09:41:57 +08:00
|
|
|
...
|
|
|
|
from lldbutil import get_stopped_thread
|
|
|
|
thread = get_stopped_thread(self.process, lldb.eStopReasonBreakpoint)
|
|
|
|
self.assertTrue(thread != None, "There should be a thread stopped due to breakpoint")
|
|
|
|
...
|
2010-10-09 09:31:09 +08:00
|
|
|
|
2011-03-03 09:41:57 +08:00
|
|
|
"""
|
|
|
|
threads = get_stopped_threads(process, reason)
|
|
|
|
if len(threads) == 0:
|
|
|
|
return None
|
|
|
|
return threads[0]
|
2010-10-09 09:31:09 +08:00
|
|
|
|
2011-04-23 08:13:34 +08:00
|
|
|
# ==============================================================
|
|
|
|
# Get the description of an lldb object or None if not available
|
|
|
|
# ==============================================================
|
|
|
|
def get_description(lldb_obj, option=None):
|
|
|
|
"""Calls lldb_obj.GetDescription() and returns a string, or None."""
|
|
|
|
method = getattr(lldb_obj, 'GetDescription')
|
|
|
|
if not method:
|
|
|
|
return None
|
|
|
|
stream = lldb.SBStream()
|
|
|
|
if option is None:
|
|
|
|
success = method(stream)
|
|
|
|
else:
|
|
|
|
success = method(stream, option)
|
|
|
|
if not success:
|
|
|
|
return None
|
|
|
|
return stream.GetData()
|
|
|
|
|
|
|
|
|
2010-10-23 05:31:03 +08:00
|
|
|
# =================================================
|
|
|
|
# Convert some enum value to its string counterpart
|
|
|
|
# =================================================
|
2010-10-08 06:15:58 +08:00
|
|
|
|
|
|
|
def StateTypeString(enum):
|
|
|
|
"""Returns the stateType string given an enum."""
|
|
|
|
if enum == lldb.eStateInvalid:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "invalid"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStateUnloaded:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "unloaded"
|
2011-03-05 09:20:11 +08:00
|
|
|
elif enum == lldb.eStateConnected:
|
|
|
|
return "connected"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStateAttaching:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "attaching"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStateLaunching:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "launching"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStateStopped:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "stopped"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStateRunning:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "running"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStateStepping:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "stepping"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStateCrashed:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "crashed"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStateDetached:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "detached"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStateExited:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "exited"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStateSuspended:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "suspended"
|
2010-10-08 06:15:58 +08:00
|
|
|
else:
|
2011-03-05 09:20:11 +08:00
|
|
|
raise Exception("Unknown StateType enum")
|
2010-10-08 06:15:58 +08:00
|
|
|
|
|
|
|
def StopReasonString(enum):
|
|
|
|
"""Returns the stopReason string given an enum."""
|
|
|
|
if enum == lldb.eStopReasonInvalid:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "invalid"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStopReasonNone:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "none"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStopReasonTrace:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "trace"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStopReasonBreakpoint:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "breakpoint"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStopReasonWatchpoint:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "watchpoint"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStopReasonSignal:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "signal"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStopReasonException:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "exception"
|
2010-10-08 06:15:58 +08:00
|
|
|
elif enum == lldb.eStopReasonPlanComplete:
|
2010-10-18 23:46:54 +08:00
|
|
|
return "plancomplete"
|
2010-10-08 06:15:58 +08:00
|
|
|
else:
|
2011-03-05 09:20:11 +08:00
|
|
|
raise Exception("Unknown StopReason enum")
|
2010-10-08 06:15:58 +08:00
|
|
|
|
2010-11-04 05:37:58 +08:00
|
|
|
def ValueTypeString(enum):
|
|
|
|
"""Returns the valueType string given an enum."""
|
|
|
|
if enum == lldb.eValueTypeInvalid:
|
|
|
|
return "invalid"
|
|
|
|
elif enum == lldb.eValueTypeVariableGlobal:
|
|
|
|
return "global_variable"
|
|
|
|
elif enum == lldb.eValueTypeVariableStatic:
|
|
|
|
return "static_variable"
|
|
|
|
elif enum == lldb.eValueTypeVariableArgument:
|
|
|
|
return "argument_variable"
|
|
|
|
elif enum == lldb.eValueTypeVariableLocal:
|
|
|
|
return "local_variable"
|
|
|
|
elif enum == lldb.eValueTypeRegister:
|
|
|
|
return "register"
|
|
|
|
elif enum == lldb.eValueTypeRegisterSet:
|
|
|
|
return "register_set"
|
|
|
|
elif enum == lldb.eValueTypeConstResult:
|
|
|
|
return "constant_result"
|
|
|
|
else:
|
2011-03-05 09:20:11 +08:00
|
|
|
raise Exception("Unknown ValueType enum")
|
2010-11-04 05:37:58 +08:00
|
|
|
|
2010-10-08 06:15:58 +08:00
|
|
|
|
2010-10-23 05:31:03 +08:00
|
|
|
# ==================================================
|
|
|
|
# Utility functions related to Threads and Processes
|
|
|
|
# ==================================================
|
2010-10-08 06:15:58 +08:00
|
|
|
|
2011-03-10 07:45:56 +08:00
|
|
|
def get_caller_symbol(thread):
|
|
|
|
"""
|
|
|
|
Returns the symbol name for the call site of the leaf function.
|
|
|
|
"""
|
|
|
|
depth = thread.GetNumFrames()
|
|
|
|
if depth <= 1:
|
|
|
|
return None
|
|
|
|
caller = thread.GetFrameAtIndex(1).GetSymbol()
|
|
|
|
if caller:
|
|
|
|
return caller.GetName()
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
2010-09-09 06:54:46 +08:00
|
|
|
def GetFunctionNames(thread):
|
|
|
|
"""
|
|
|
|
Returns a sequence of function names from the stack frames of this thread.
|
|
|
|
"""
|
|
|
|
def GetFuncName(i):
|
|
|
|
return thread.GetFrameAtIndex(i).GetFunction().GetName()
|
|
|
|
|
|
|
|
return map(GetFuncName, range(thread.GetNumFrames()))
|
|
|
|
|
|
|
|
|
2010-10-08 05:38:28 +08:00
|
|
|
def GetSymbolNames(thread):
|
|
|
|
"""
|
|
|
|
Returns a sequence of symbols for this thread.
|
|
|
|
"""
|
|
|
|
def GetSymbol(i):
|
|
|
|
return thread.GetFrameAtIndex(i).GetSymbol().GetName()
|
|
|
|
|
|
|
|
return map(GetSymbol, range(thread.GetNumFrames()))
|
|
|
|
|
|
|
|
|
|
|
|
def GetPCAddresses(thread):
|
|
|
|
"""
|
|
|
|
Returns a sequence of pc addresses for this thread.
|
|
|
|
"""
|
|
|
|
def GetPCAddress(i):
|
|
|
|
return thread.GetFrameAtIndex(i).GetPCAddress()
|
|
|
|
|
|
|
|
return map(GetPCAddress, range(thread.GetNumFrames()))
|
|
|
|
|
|
|
|
|
2010-09-09 06:54:46 +08:00
|
|
|
def GetFilenames(thread):
|
|
|
|
"""
|
|
|
|
Returns a sequence of file names from the stack frames of this thread.
|
|
|
|
"""
|
|
|
|
def GetFilename(i):
|
|
|
|
return thread.GetFrameAtIndex(i).GetLineEntry().GetFileSpec().GetFilename()
|
|
|
|
|
|
|
|
return map(GetFilename, range(thread.GetNumFrames()))
|
|
|
|
|
|
|
|
|
|
|
|
def GetLineNumbers(thread):
|
|
|
|
"""
|
|
|
|
Returns a sequence of line numbers from the stack frames of this thread.
|
|
|
|
"""
|
|
|
|
def GetLineNumber(i):
|
|
|
|
return thread.GetFrameAtIndex(i).GetLineEntry().GetLine()
|
|
|
|
|
|
|
|
return map(GetLineNumber, range(thread.GetNumFrames()))
|
|
|
|
|
|
|
|
|
|
|
|
def GetModuleNames(thread):
|
|
|
|
"""
|
|
|
|
Returns a sequence of module names from the stack frames of this thread.
|
|
|
|
"""
|
|
|
|
def GetModuleName(i):
|
|
|
|
return thread.GetFrameAtIndex(i).GetModule().GetFileSpec().GetFilename()
|
|
|
|
|
|
|
|
return map(GetModuleName, range(thread.GetNumFrames()))
|
|
|
|
|
|
|
|
|
2010-09-09 08:55:07 +08:00
|
|
|
def GetStackFrames(thread):
|
|
|
|
"""
|
|
|
|
Returns a sequence of stack frames for this thread.
|
|
|
|
"""
|
|
|
|
def GetStackFrame(i):
|
|
|
|
return thread.GetFrameAtIndex(i)
|
|
|
|
|
|
|
|
return map(GetStackFrame, range(thread.GetNumFrames()))
|
|
|
|
|
|
|
|
|
2010-10-08 02:52:48 +08:00
|
|
|
def PrintStackTrace(thread, string_buffer = False):
|
2010-09-09 06:54:46 +08:00
|
|
|
"""Prints a simple stack trace of this thread."""
|
2010-10-08 02:52:48 +08:00
|
|
|
|
2010-10-16 07:33:18 +08:00
|
|
|
output = StringIO.StringIO() if string_buffer else sys.stdout
|
2010-10-08 05:38:28 +08:00
|
|
|
target = thread.GetProcess().GetTarget()
|
|
|
|
|
2010-09-09 06:54:46 +08:00
|
|
|
depth = thread.GetNumFrames()
|
|
|
|
|
|
|
|
mods = GetModuleNames(thread)
|
|
|
|
funcs = GetFunctionNames(thread)
|
2010-10-08 05:38:28 +08:00
|
|
|
symbols = GetSymbolNames(thread)
|
2010-09-09 06:54:46 +08:00
|
|
|
files = GetFilenames(thread)
|
|
|
|
lines = GetLineNumbers(thread)
|
2010-10-08 05:38:28 +08:00
|
|
|
addrs = GetPCAddresses(thread)
|
2010-10-08 02:52:48 +08:00
|
|
|
|
2010-10-26 03:13:52 +08:00
|
|
|
if thread.GetStopReason() != lldb.eStopReasonInvalid:
|
|
|
|
desc = "stop reason=" + StopReasonString(thread.GetStopReason())
|
|
|
|
else:
|
|
|
|
desc = ""
|
|
|
|
print >> output, "Stack trace for thread id={0:#x} name={1} queue={2} ".format(
|
|
|
|
thread.GetThreadID(), thread.GetName(), thread.GetQueueName()) + desc
|
2010-09-09 06:54:46 +08:00
|
|
|
|
2010-10-08 05:38:28 +08:00
|
|
|
for i in range(depth):
|
|
|
|
frame = thread.GetFrameAtIndex(i)
|
|
|
|
function = frame.GetFunction()
|
|
|
|
|
|
|
|
load_addr = addrs[i].GetLoadAddress(target)
|
|
|
|
if not function.IsValid():
|
|
|
|
file_addr = addrs[i].GetFileAddress()
|
|
|
|
print >> output, " frame #{num}: {addr:#016x} {mod}`{symbol} + ????".format(
|
|
|
|
num=i, addr=load_addr, mod=mods[i], symbol=symbols[i])
|
|
|
|
else:
|
|
|
|
print >> output, " frame #{num}: {addr:#016x} {mod}`{func} at {file}:{line}".format(
|
|
|
|
num=i, addr=load_addr, mod=mods[i], func=funcs[i], file=files[i], line=lines[i])
|
|
|
|
|
|
|
|
if string_buffer:
|
2010-10-16 07:33:18 +08:00
|
|
|
return output.getvalue()
|
2010-10-08 05:38:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
def PrintStackTraces(process, string_buffer = False):
|
|
|
|
"""Prints the stack traces of all the threads."""
|
|
|
|
|
2010-10-16 07:33:18 +08:00
|
|
|
output = StringIO.StringIO() if string_buffer else sys.stdout
|
2010-10-08 05:38:28 +08:00
|
|
|
|
|
|
|
print >> output, "Stack traces for " + repr(process)
|
2010-09-09 06:54:46 +08:00
|
|
|
|
2010-10-08 05:38:28 +08:00
|
|
|
for i in range(process.GetNumThreads()):
|
|
|
|
print >> output, PrintStackTrace(process.GetThreadAtIndex(i), string_buffer=True)
|
2010-10-08 02:52:48 +08:00
|
|
|
|
|
|
|
if string_buffer:
|
2010-10-16 07:33:18 +08:00
|
|
|
return output.getvalue()
|
2011-04-16 08:01:13 +08:00
|
|
|
|
|
|
|
def GetThreadsStoppedAtBreakpoint (process, bkpt):
|
2011-04-19 02:32:09 +08:00
|
|
|
""" For a stopped process returns the thread stopped at the breakpoint passed in bkpt"""
|
2011-04-16 08:01:13 +08:00
|
|
|
stopped_threads = []
|
|
|
|
threads = []
|
|
|
|
|
|
|
|
stopped_threads = get_stopped_threads (process, lldb.eStopReasonBreakpoint)
|
|
|
|
|
|
|
|
if len(stopped_threads) == 0:
|
|
|
|
return threads
|
|
|
|
|
|
|
|
for thread in stopped_threads:
|
|
|
|
# Make sure we've hit our breakpoint...
|
|
|
|
break_id = thread.GetStopReasonDataAtIndex (0)
|
|
|
|
if break_id == bkpt.GetID():
|
|
|
|
threads.append(thread)
|
|
|
|
|
|
|
|
return threads
|
|
|
|
|
|
|
|
def ContinueToBreakpoint (process, bkpt):
|
2011-04-19 02:32:09 +08:00
|
|
|
""" Continues the process, if it stops, returns the threads stopped at bkpt; otherwise, returns None"""
|
2011-04-16 08:01:13 +08:00
|
|
|
process.Continue()
|
|
|
|
if process.GetState() != lldb.eStateStopped:
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
return GetThreadsStoppedAtBreakpoint (process, bkpt)
|
|
|
|
|