hanchenye-llvm-project/lldb/test/lldbutil.py

214 lines
6.4 KiB
Python
Raw Normal View History

Added a lldbutil.py module, which contains utility functions which can be used from scripting applications. An example usage from TestConditionalBreak.py is: import lldbutil lldbutil.PrintStackTrace(thread) ./dotest.py -v conditional_break ---------------------------------------------------------------------- Collected 2 tests test_with_dsym (TestConditionalBreak.ConditionalBreakTestCase) Exercise some thread and frame APIs to break if c() is called by a(). ... Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`a at main.c:25 frame #3: a.out`main at main.c:44 frame #4: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`main at main.c:47 frame #3: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`a at main.c:27 frame #2: a.out`main at main.c:50 frame #3: a.out`start ok test_with_dwarf (TestConditionalBreak.ConditionalBreakTestCase) Exercise some thread and frame APIs to break if c() is called by a(). ... Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`a at main.c:25 frame #3: a.out`main at main.c:44 frame #4: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`main at main.c:47 frame #3: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`a at main.c:27 frame #2: a.out`main at main.c:50 frame #3: a.out`start ok ---------------------------------------------------------------------- Ran 2 tests in 7.803s OK llvm-svn: 113432
2010-09-09 06:54:46 +08:00
"""
This LLDB module contains miscellaneous utilities.
Added a lldbutil.py module, which contains utility functions which can be used from scripting applications. An example usage from TestConditionalBreak.py is: import lldbutil lldbutil.PrintStackTrace(thread) ./dotest.py -v conditional_break ---------------------------------------------------------------------- Collected 2 tests test_with_dsym (TestConditionalBreak.ConditionalBreakTestCase) Exercise some thread and frame APIs to break if c() is called by a(). ... Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`a at main.c:25 frame #3: a.out`main at main.c:44 frame #4: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`main at main.c:47 frame #3: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`a at main.c:27 frame #2: a.out`main at main.c:50 frame #3: a.out`start ok test_with_dwarf (TestConditionalBreak.ConditionalBreakTestCase) Exercise some thread and frame APIs to break if c() is called by a(). ... Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`a at main.c:25 frame #3: a.out`main at main.c:44 frame #4: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`main at main.c:47 frame #3: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`a at main.c:27 frame #2: a.out`main at main.c:50 frame #3: a.out`start ok ---------------------------------------------------------------------- Ran 2 tests in 7.803s OK llvm-svn: 113432
2010-09-09 06:54:46 +08:00
"""
import lldb
import sys
import StringIO
Added a lldbutil.py module, which contains utility functions which can be used from scripting applications. An example usage from TestConditionalBreak.py is: import lldbutil lldbutil.PrintStackTrace(thread) ./dotest.py -v conditional_break ---------------------------------------------------------------------- Collected 2 tests test_with_dsym (TestConditionalBreak.ConditionalBreakTestCase) Exercise some thread and frame APIs to break if c() is called by a(). ... Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`a at main.c:25 frame #3: a.out`main at main.c:44 frame #4: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`main at main.c:47 frame #3: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`a at main.c:27 frame #2: a.out`main at main.c:50 frame #3: a.out`start ok test_with_dwarf (TestConditionalBreak.ConditionalBreakTestCase) Exercise some thread and frame APIs to break if c() is called by a(). ... Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`a at main.c:25 frame #3: a.out`main at main.c:44 frame #4: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`main at main.c:47 frame #3: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`a at main.c:27 frame #2: a.out`main at main.c:50 frame #3: a.out`start ok ---------------------------------------------------------------------- Ran 2 tests in 7.803s OK llvm-svn: 113432
2010-09-09 06:54:46 +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 the aggregate object, the name of the method to get the
size of the object, and the name of the method to get the element given an
index.
Example usage:
def disassemble_instructions (insts):
from lldbutil import lldb_iter
for i in lldb_iter(insts, 'GetSize', 'GetInstructionAtIndex'):
print i
"""
size = getattr(obj, getsize)
elem = getattr(obj, getelem)
for i in range(size()):
yield elem(i)
########################################################
# #
# Convert some enum value to its string's counterpart. #
# #
########################################################
def StateTypeString(enum):
"""Returns the stateType string given an enum."""
if enum == lldb.eStateInvalid:
return "Invalid"
elif enum == lldb.eStateUnloaded:
return "Unloaded"
elif enum == lldb.eStateAttaching:
return "Attaching"
elif enum == lldb.eStateLaunching:
return "Launching"
elif enum == lldb.eStateStopped:
return "Stopped"
elif enum == lldb.eStateRunning:
return "Running"
elif enum == lldb.eStateStepping:
return "Stepping"
elif enum == lldb.eStateCrashed:
return "Crashed"
elif enum == lldb.eStateDetached:
return "Detached"
elif enum == lldb.eStateExited:
return "Exited"
elif enum == lldb.eStateSuspended:
return "Suspended"
else:
raise Exception("Unknown stopReason enum")
def StopReasonString(enum):
"""Returns the stopReason string given an enum."""
if enum == lldb.eStopReasonInvalid:
return "Invalid"
elif enum == lldb.eStopReasonNone:
return "None"
elif enum == lldb.eStopReasonTrace:
return "Trace"
elif enum == lldb.eStopReasonBreakpoint:
return "Breakpoint"
elif enum == lldb.eStopReasonWatchpoint:
return "Watchpoint"
elif enum == lldb.eStopReasonSignal:
return "Signal"
elif enum == lldb.eStopReasonException:
return "Exception"
elif enum == lldb.eStopReasonPlanComplete:
return "PlanComplete"
else:
raise Exception("Unknown stopReason enum")
#######################################################
# #
# Utility functions related to Threads and Processes. #
# #
#######################################################
Added a lldbutil.py module, which contains utility functions which can be used from scripting applications. An example usage from TestConditionalBreak.py is: import lldbutil lldbutil.PrintStackTrace(thread) ./dotest.py -v conditional_break ---------------------------------------------------------------------- Collected 2 tests test_with_dsym (TestConditionalBreak.ConditionalBreakTestCase) Exercise some thread and frame APIs to break if c() is called by a(). ... Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`a at main.c:25 frame #3: a.out`main at main.c:44 frame #4: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`main at main.c:47 frame #3: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`a at main.c:27 frame #2: a.out`main at main.c:50 frame #3: a.out`start ok test_with_dwarf (TestConditionalBreak.ConditionalBreakTestCase) Exercise some thread and frame APIs to break if c() is called by a(). ... Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`a at main.c:25 frame #3: a.out`main at main.c:44 frame #4: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`main at main.c:47 frame #3: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`a at main.c:27 frame #2: a.out`main at main.c:50 frame #3: a.out`start ok ---------------------------------------------------------------------- Ran 2 tests in 7.803s OK llvm-svn: 113432
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()))
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()))
Added a lldbutil.py module, which contains utility functions which can be used from scripting applications. An example usage from TestConditionalBreak.py is: import lldbutil lldbutil.PrintStackTrace(thread) ./dotest.py -v conditional_break ---------------------------------------------------------------------- Collected 2 tests test_with_dsym (TestConditionalBreak.ConditionalBreakTestCase) Exercise some thread and frame APIs to break if c() is called by a(). ... Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`a at main.c:25 frame #3: a.out`main at main.c:44 frame #4: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`main at main.c:47 frame #3: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`a at main.c:27 frame #2: a.out`main at main.c:50 frame #3: a.out`start ok test_with_dwarf (TestConditionalBreak.ConditionalBreakTestCase) Exercise some thread and frame APIs to break if c() is called by a(). ... Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`a at main.c:25 frame #3: a.out`main at main.c:44 frame #4: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`main at main.c:47 frame #3: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`a at main.c:27 frame #2: a.out`main at main.c:50 frame #3: a.out`start ok ---------------------------------------------------------------------- Ran 2 tests in 7.803s OK llvm-svn: 113432
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()))
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):
Added a lldbutil.py module, which contains utility functions which can be used from scripting applications. An example usage from TestConditionalBreak.py is: import lldbutil lldbutil.PrintStackTrace(thread) ./dotest.py -v conditional_break ---------------------------------------------------------------------- Collected 2 tests test_with_dsym (TestConditionalBreak.ConditionalBreakTestCase) Exercise some thread and frame APIs to break if c() is called by a(). ... Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`a at main.c:25 frame #3: a.out`main at main.c:44 frame #4: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`main at main.c:47 frame #3: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`a at main.c:27 frame #2: a.out`main at main.c:50 frame #3: a.out`start ok test_with_dwarf (TestConditionalBreak.ConditionalBreakTestCase) Exercise some thread and frame APIs to break if c() is called by a(). ... Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`a at main.c:25 frame #3: a.out`main at main.c:44 frame #4: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`main at main.c:47 frame #3: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`a at main.c:27 frame #2: a.out`main at main.c:50 frame #3: a.out`start ok ---------------------------------------------------------------------- Ran 2 tests in 7.803s OK llvm-svn: 113432
2010-09-09 06:54:46 +08:00
"""Prints a simple stack trace of this thread."""
output = StringIO.StringIO() if string_buffer else sys.stdout
target = thread.GetProcess().GetTarget()
Added a lldbutil.py module, which contains utility functions which can be used from scripting applications. An example usage from TestConditionalBreak.py is: import lldbutil lldbutil.PrintStackTrace(thread) ./dotest.py -v conditional_break ---------------------------------------------------------------------- Collected 2 tests test_with_dsym (TestConditionalBreak.ConditionalBreakTestCase) Exercise some thread and frame APIs to break if c() is called by a(). ... Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`a at main.c:25 frame #3: a.out`main at main.c:44 frame #4: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`main at main.c:47 frame #3: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`a at main.c:27 frame #2: a.out`main at main.c:50 frame #3: a.out`start ok test_with_dwarf (TestConditionalBreak.ConditionalBreakTestCase) Exercise some thread and frame APIs to break if c() is called by a(). ... Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`a at main.c:25 frame #3: a.out`main at main.c:44 frame #4: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`main at main.c:47 frame #3: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`a at main.c:27 frame #2: a.out`main at main.c:50 frame #3: a.out`start ok ---------------------------------------------------------------------- Ran 2 tests in 7.803s OK llvm-svn: 113432
2010-09-09 06:54:46 +08:00
depth = thread.GetNumFrames()
mods = GetModuleNames(thread)
funcs = GetFunctionNames(thread)
symbols = GetSymbolNames(thread)
Added a lldbutil.py module, which contains utility functions which can be used from scripting applications. An example usage from TestConditionalBreak.py is: import lldbutil lldbutil.PrintStackTrace(thread) ./dotest.py -v conditional_break ---------------------------------------------------------------------- Collected 2 tests test_with_dsym (TestConditionalBreak.ConditionalBreakTestCase) Exercise some thread and frame APIs to break if c() is called by a(). ... Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`a at main.c:25 frame #3: a.out`main at main.c:44 frame #4: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`main at main.c:47 frame #3: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`a at main.c:27 frame #2: a.out`main at main.c:50 frame #3: a.out`start ok test_with_dwarf (TestConditionalBreak.ConditionalBreakTestCase) Exercise some thread and frame APIs to break if c() is called by a(). ... Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`a at main.c:25 frame #3: a.out`main at main.c:44 frame #4: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`main at main.c:47 frame #3: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`a at main.c:27 frame #2: a.out`main at main.c:50 frame #3: a.out`start ok ---------------------------------------------------------------------- Ran 2 tests in 7.803s OK llvm-svn: 113432
2010-09-09 06:54:46 +08:00
files = GetFilenames(thread)
lines = GetLineNumbers(thread)
addrs = GetPCAddresses(thread)
print >> output, "Stack trace for thread id={0:#x} name={1} queue={2}:".format(
Added a lldbutil.py module, which contains utility functions which can be used from scripting applications. An example usage from TestConditionalBreak.py is: import lldbutil lldbutil.PrintStackTrace(thread) ./dotest.py -v conditional_break ---------------------------------------------------------------------- Collected 2 tests test_with_dsym (TestConditionalBreak.ConditionalBreakTestCase) Exercise some thread and frame APIs to break if c() is called by a(). ... Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`a at main.c:25 frame #3: a.out`main at main.c:44 frame #4: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`main at main.c:47 frame #3: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`a at main.c:27 frame #2: a.out`main at main.c:50 frame #3: a.out`start ok test_with_dwarf (TestConditionalBreak.ConditionalBreakTestCase) Exercise some thread and frame APIs to break if c() is called by a(). ... Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`a at main.c:25 frame #3: a.out`main at main.c:44 frame #4: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`main at main.c:47 frame #3: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`a at main.c:27 frame #2: a.out`main at main.c:50 frame #3: a.out`start ok ---------------------------------------------------------------------- Ran 2 tests in 7.803s OK llvm-svn: 113432
2010-09-09 06:54:46 +08:00
thread.GetThreadID(), thread.GetName(), thread.GetQueueName())
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:
return output.getvalue()
def PrintStackTraces(process, string_buffer = False):
"""Prints the stack traces of all the threads."""
output = StringIO.StringIO() if string_buffer else sys.stdout
print >> output, "Stack traces for " + repr(process)
Added a lldbutil.py module, which contains utility functions which can be used from scripting applications. An example usage from TestConditionalBreak.py is: import lldbutil lldbutil.PrintStackTrace(thread) ./dotest.py -v conditional_break ---------------------------------------------------------------------- Collected 2 tests test_with_dsym (TestConditionalBreak.ConditionalBreakTestCase) Exercise some thread and frame APIs to break if c() is called by a(). ... Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`a at main.c:25 frame #3: a.out`main at main.c:44 frame #4: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`main at main.c:47 frame #3: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`a at main.c:27 frame #2: a.out`main at main.c:50 frame #3: a.out`start ok test_with_dwarf (TestConditionalBreak.ConditionalBreakTestCase) Exercise some thread and frame APIs to break if c() is called by a(). ... Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`a at main.c:25 frame #3: a.out`main at main.c:44 frame #4: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`b at main.c:34 frame #2: a.out`main at main.c:47 frame #3: a.out`start Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread: frame #0: a.out`c at main.c:39 frame #1: a.out`a at main.c:27 frame #2: a.out`main at main.c:50 frame #3: a.out`start ok ---------------------------------------------------------------------- Ran 2 tests in 7.803s OK llvm-svn: 113432
2010-09-09 06:54:46 +08:00
for i in range(process.GetNumThreads()):
print >> output, PrintStackTrace(process.GetThreadAtIndex(i), string_buffer=True)
if string_buffer:
return output.getvalue()