Newer
Older
Johnny Chen
committed
"""
LLDB modules which contains miscellaneous utilities.
"""
import lldb
import sys
import StringIO
Johnny Chen
committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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()))
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()))
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()))
def PrintStackTrace(thread, string_buffer = False):
Johnny Chen
committed
"""Prints a simple stack trace of this thread."""
Johnny Chen
committed
depth = thread.GetNumFrames()
mods = GetModuleNames(thread)
funcs = GetFunctionNames(thread)
files = GetFilenames(thread)
lines = GetLineNumbers(thread)
output = StringIO.StringIO() if string_buffer else sys.stdout
print >> output, "Stack trace for thread id={0:#x} name={1} queue={2}:".format(
Johnny Chen
committed
thread.GetThreadID(), thread.GetName(), thread.GetQueueName())
for i in range(depth - 1):
print >> output, " frame #{num}: {mod}`{func} at {file}:{line}".format(
Johnny Chen
committed
num=i, mod=mods[i], func=funcs[i], file=files[i], line=lines[i])
print >> output, " frame #{num}: {mod}`start".format(num=depth-1, mod=mods[depth-1])
if string_buffer:
return output.getvalue()