[Lldb-commits] [lldb] r127374 - in /lldb/trunk/test: lldbutil.py python_api/thread/Makefile python_api/thread/TestThreadAPI.py python_api/thread/main2.cpp
Johnny Chen
johnny.chen at apple.com
Wed Mar 9 15:45:56 PST 2011
Author: johnny
Date: Wed Mar 9 17:45:56 2011
New Revision: 127374
URL: http://llvm.org/viewvc/llvm-project?rev=127374&view=rev
Log:
Add test cases for Python SBThread.StepOut() API by stepping out of a malloc call where the call site is at function b().
Verifies that after the thread.StepOut(), we are at the correct line within function b.
Added:
lldb/trunk/test/python_api/thread/main2.cpp
Modified:
lldb/trunk/test/lldbutil.py
lldb/trunk/test/python_api/thread/Makefile
lldb/trunk/test/python_api/thread/TestThreadAPI.py
Modified: lldb/trunk/test/lldbutil.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbutil.py?rev=127374&r1=127373&r2=127374&view=diff
==============================================================================
--- lldb/trunk/test/lldbutil.py (original)
+++ lldb/trunk/test/lldbutil.py Wed Mar 9 17:45:56 2011
@@ -232,6 +232,20 @@
# Utility functions related to Threads and Processes
# ==================================================
+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
+
+
def GetFunctionNames(thread):
"""
Returns a sequence of function names from the stack frames of this thread.
Modified: lldb/trunk/test/python_api/thread/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/thread/Makefile?rev=127374&r1=127373&r2=127374&view=diff
==============================================================================
--- lldb/trunk/test/python_api/thread/Makefile (original)
+++ lldb/trunk/test/python_api/thread/Makefile Wed Mar 9 17:45:56 2011
@@ -1,5 +1,5 @@
LEVEL = ../../make
-CXX_SOURCES := main.cpp
+CXX_SOURCES ?= main.cpp
include $(LEVEL)/Makefile.rules
Modified: lldb/trunk/test/python_api/thread/TestThreadAPI.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/thread/TestThreadAPI.py?rev=127374&r1=127373&r2=127374&view=diff
==============================================================================
--- lldb/trunk/test/python_api/thread/TestThreadAPI.py (original)
+++ lldb/trunk/test/python_api/thread/TestThreadAPI.py Wed Mar 9 17:45:56 2011
@@ -5,7 +5,7 @@
import os, time
import unittest2
import lldb
-from lldbutil import get_stopped_thread
+from lldbutil import get_stopped_thread, get_caller_symbol
from lldbtest import *
class ThreadAPITestCase(TestBase):
@@ -25,11 +25,32 @@
self.buildDwarf()
self.get_stop_description()
+ @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+ @python_api_test
+ def test_step_out_of_malloc_into_function_b_with_dsym(self):
+ """Test Python SBThread.StepOut() API to step out of a malloc call where the call site is at function b()."""
+ # We build a different executable than the default buildDsym() does.
+ d = {'CXX_SOURCES': 'main2.cpp'}
+ self.buildDsym(dictionary=d)
+ self.setTearDownCleanup(dictionary=d)
+ self.step_out_of_malloc_into_function_b()
+
+ @python_api_test
+ def test_step_out_of_malloc_into_function_b_with_dwarf(self):
+ """Test Python SBThread.StepOut() API to step out of a malloc call where the call site is at function b()."""
+ # We build a different executable than the default buildDwarf() does.
+ d = {'CXX_SOURCES': 'main2.cpp'}
+ self.buildDwarf(dictionary=d)
+ self.setTearDownCleanup(dictionary=d)
+ self.step_out_of_malloc_into_function_b()
+
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
# Find the line number to break inside main().
self.line = line_number("main.cpp", "// Set break point at this line and check variable 'my_char'.")
+ # Find the line number within main2.cpp for step_out_of_malloc_into_function_b().
+ self.line2 = line_number("main2.cpp", "// thread step-out of malloc into function b.")
def get_stop_description(self):
"""Test Python SBProcess.ReadMemory() API."""
@@ -58,6 +79,40 @@
self.expect(stop_description, exe=False,
startstr = 'breakpoint')
+ def step_out_of_malloc_into_function_b(self):
+ """Test Python SBThread.StepOut() API to step out of a malloc call where the call site is at function b()."""
+ exe = os.path.join(os.getcwd(), "a.out")
+ self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target.IsValid(), VALID_TARGET)
+
+ breakpoint = target.BreakpointCreateByName('malloc')
+ self.assertTrue(breakpoint.IsValid(), VALID_BREAKPOINT)
+ self.runCmd("breakpoint list")
+
+ # Launch the process, and do not stop at the entry point.
+ error = lldb.SBError()
+ self.process = target.Launch (self.dbg.GetListener(), None, None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, error)
+
+ thread = get_stopped_thread(self.process, lldb.eStopReasonBreakpoint)
+ self.assertTrue(thread != None, "There should be a thread stopped due to breakpoint")
+ self.runCmd("process status")
+ symbol = get_caller_symbol(thread)
+ caller = symbol.split('(')[0]
+
+ while caller != "b":
+ #self.runCmd("thread backtrace")
+ #self.runCmd("process status")
+ self.process.Continue()
+ thread = get_stopped_thread(self.process, lldb.eStopReasonBreakpoint)
+ symbol = get_caller_symbol(thread)
+ caller = symbol.split('(')[0]
+ self.assertTrue(thread != None, "There should be a thread stopped due to breakpoint")
+
+ thread.StepOut()
+ self.assertTrue(thread.GetFrameAtIndex(0).GetLineEntry().GetLine() == self.line2,
+ "step out of malloc into function b is successful")
if __name__ == '__main__':
import atexit
Added: lldb/trunk/test/python_api/thread/main2.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/thread/main2.cpp?rev=127374&view=auto
==============================================================================
--- lldb/trunk/test/python_api/thread/main2.cpp (added)
+++ lldb/trunk/test/python_api/thread/main2.cpp Wed Mar 9 17:45:56 2011
@@ -0,0 +1,54 @@
+//===-- main.c --------------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#include <stdio.h>
+#include <stdlib.h>
+
+int a(int);
+int b(int);
+int c(int);
+
+int a(int val)
+{
+ if (val <= 1)
+ return b(val);
+ else if (val >= 3)
+ return c(val);
+
+ return val;
+}
+
+int b(int val)
+{
+ int rc = c(val);
+ void *ptr = malloc(1024); // thread step-out of malloc into function b.
+ if (!ptr)
+ return -1;
+ else
+ printf("ptr=%p\n", ptr);
+ return rc;
+}
+
+int c(int val)
+{
+ return val + 3;
+}
+
+int main (int argc, char const *argv[])
+{
+ int A1 = a(1);
+ printf("a(1) returns %d\n", A1);
+
+ int B2 = b(2);
+ printf("b(2) returns %d\n", B2);
+
+ int A3 = a(3);
+ printf("a(3) returns %d\n", A3);
+
+ return 0;
+}
More information about the lldb-commits
mailing list