[Lldb-commits] [lldb] r113432 - in /lldb/trunk/test: conditional_break/TestConditionalBreak.py lldbutil.py
Johnny Chen
johnny.chen at apple.com
Wed Sep 8 15:54:46 PDT 2010
Author: johnny
Date: Wed Sep 8 17:54:46 2010
New Revision: 113432
URL: http://llvm.org/viewvc/llvm-project?rev=113432&view=rev
Log:
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
Added:
lldb/trunk/test/lldbutil.py
Modified:
lldb/trunk/test/conditional_break/TestConditionalBreak.py
Modified: lldb/trunk/test/conditional_break/TestConditionalBreak.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/conditional_break/TestConditionalBreak.py?rev=113432&r1=113431&r2=113432&view=diff
==============================================================================
--- lldb/trunk/test/conditional_break/TestConditionalBreak.py (original)
+++ lldb/trunk/test/conditional_break/TestConditionalBreak.py Wed Sep 8 17:54:46 2010
@@ -45,6 +45,8 @@
target = self.dbg.GetSelectedTarget()
process = target.GetProcess()
thread = process.GetThreadAtIndex(0)
+ import lldbutil
+ lldbutil.PrintStackTrace(thread)
if thread.GetNumFrames() >= 2:
frame0 = thread.GetFrameAtIndex(0)
Added: lldb/trunk/test/lldbutil.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbutil.py?rev=113432&view=auto
==============================================================================
--- lldb/trunk/test/lldbutil.py (added)
+++ lldb/trunk/test/lldbutil.py Wed Sep 8 17:54:46 2010
@@ -0,0 +1,63 @@
+"""
+LLDB modules which contains miscellaneous utilities.
+"""
+
+import lldb
+
+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 PrintStackTrace(thread):
+ """Prints a simple stack trace of this thread."""
+ depth = thread.GetNumFrames()
+
+ mods = GetModuleNames(thread)
+ funcs = GetFunctionNames(thread)
+ files = GetFilenames(thread)
+ lines = GetLineNumbers(thread)
+
+ print "Stack trace for thread id={0:#x} name={1} queue={2}:".format(
+ thread.GetThreadID(), thread.GetName(), thread.GetQueueName())
+
+ for i in range(depth - 1):
+ print " frame #{num}: {mod}`{func} at {file}:{line}".format(
+ num=i, mod=mods[i], func=funcs[i], file=files[i], line=lines[i])
+
+ print " frame #{num}: {mod}`start".format(num=depth-1, mod=mods[depth-1])
More information about the lldb-commits
mailing list