summaryrefslogtreecommitdiffstats
path: root/lldb/test/python_api/target
diff options
context:
space:
mode:
authorJohnny Chen <johnny.chen@apple.com>2011-03-03 01:41:57 +0000
committerJohnny Chen <johnny.chen@apple.com>2011-03-03 01:41:57 +0000
commitd61816b5b8c5e0f5d5c9e6c5e6811bee59c98140 (patch)
treef51b3a5b57c08b2c2c7957f9803f66402c6b2d95 /lldb/test/python_api/target
parentec845689049c89ffb7d021cc245774f0f21e6796 (diff)
downloadbcm5719-llvm-d61816b5b8c5e0f5d5c9e6c5e6811bee59c98140.tar.gz
bcm5719-llvm-d61816b5b8c5e0f5d5c9e6c5e6811bee59c98140.zip
Add TestTargetAPI.py:
// When stopped on breakppint 1, and then 2, we can get the line entries using // SBFrame API SBFrame.GetLineEntry(). We'll get the start addresses for the // two line entries; with the start address (of SBAddress type), we can then // resolve the symbol context using the SBTarget API // SBTarget.ResolveSymbolContextForAddress(). // // The two symbol context should point to the same symbol, i.e., 'a' function. Add two utility functions to lldbutil.py: o get_stopped_threads(process, reason): return the list of threads with the specified stop reason or an empty list if not found o get_stopped_thread(process, reason): return the first thread with the given stop reason or None if not found llvm-svn: 126916
Diffstat (limited to 'lldb/test/python_api/target')
-rw-r--r--lldb/test/python_api/target/Makefile5
-rw-r--r--lldb/test/python_api/target/TestTargetAPI.py114
-rw-r--r--lldb/test/python_api/target/main.c57
3 files changed, 176 insertions, 0 deletions
diff --git a/lldb/test/python_api/target/Makefile b/lldb/test/python_api/target/Makefile
new file mode 100644
index 00000000000..0d70f259501
--- /dev/null
+++ b/lldb/test/python_api/target/Makefile
@@ -0,0 +1,5 @@
+LEVEL = ../../make
+
+C_SOURCES := main.c
+
+include $(LEVEL)/Makefile.rules
diff --git a/lldb/test/python_api/target/TestTargetAPI.py b/lldb/test/python_api/target/TestTargetAPI.py
new file mode 100644
index 00000000000..0c5f806bc72
--- /dev/null
+++ b/lldb/test/python_api/target/TestTargetAPI.py
@@ -0,0 +1,114 @@
+"""
+Test SBTarget APIs.
+"""
+
+import os, time
+import re
+import unittest2
+import lldb, lldbutil
+from lldbtest import *
+
+class TargetAPITestCase(TestBase):
+
+ mydir = os.path.join("python_api", "target")
+
+ @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+ @python_api_test
+ def test_with_dsym(self):
+ """Exercise SBTaget APIs."""
+ self.buildDsym()
+ self.target_api()
+
+ @python_api_test
+ def test_with_dwarf(self):
+ """Exercise SBTarget APIs."""
+ self.buildDwarf()
+ self.target_api()
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ # Find the line number to of function 'c'.
+ self.line1 = line_number('main.c', '// Find the line number for breakpoint 1 here.')
+ self.line2 = line_number('main.c', '// Find the line number for breakpoint 2 here.')
+
+ def target_api(self):
+ """Exercise SBTarget APIs."""
+ exe = os.path.join(os.getcwd(), "a.out")
+
+ # Create a target by the debugger.
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target.IsValid(), VALID_TARGET)
+
+ # Now create the two breakpoints inside function 'a'.
+ breakpoint1 = target.BreakpointCreateByLocation('main.c', self.line1)
+ breakpoint2 = target.BreakpointCreateByLocation('main.c', self.line2)
+ print "breakpoint1:", breakpoint1
+ print "breakpoint2:", breakpoint2
+ self.assertTrue(breakpoint1.IsValid() and
+ breakpoint1.GetNumLocations() == 1,
+ VALID_BREAKPOINT)
+ self.assertTrue(breakpoint2.IsValid() and
+ breakpoint2.GetNumLocations() == 1,
+ VALID_BREAKPOINT)
+
+ # Now launch the process, and do not stop at entry point.
+ error = lldb.SBError()
+ self.process = target.Launch (self.dbg.GetListener(), None, None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, error)
+
+ self.process = target.GetProcess()
+ self.assertTrue(self.process.IsValid(), PROCESS_IS_VALID)
+
+ # Frame #0 should be on self.line1.
+ self.assertTrue(self.process.GetState() == lldb.eStateStopped)
+ thread = lldbutil.get_stopped_thread(self.process, lldb.eStopReasonBreakpoint)
+ self.runCmd("process status")
+ frame0 = thread.GetFrameAtIndex(0)
+ lineEntry = frame0.GetLineEntry()
+ self.assertTrue(lineEntry.GetLine() == self.line1)
+
+ address1 = lineEntry.GetStartAddress()
+
+ # Continue the inferior, the breakpoint 2 should be hit.
+ self.process.Continue()
+ self.assertTrue(self.process.GetState() == lldb.eStateStopped)
+ thread = lldbutil.get_stopped_thread(self.process, lldb.eStopReasonBreakpoint)
+ self.runCmd("process status")
+ frame0 = thread.GetFrameAtIndex(0)
+ lineEntry = frame0.GetLineEntry()
+ self.assertTrue(lineEntry.GetLine() == self.line2)
+
+ address2 = lineEntry.GetStartAddress()
+
+ print "address1:", address1
+ print "address2:", address2
+
+ # Now call SBTarget.ResolveSymbolContextForAddress() with the addresses from our line entry.
+ context1 = target.ResolveSymbolContextForAddress(address1, lldb.eSymbolContextEverything)
+ context2 = target.ResolveSymbolContextForAddress(address2, lldb.eSymbolContextEverything)
+
+ self.assertTrue(context1.IsValid() and context2.IsValid())
+ print "context1:", context1
+ print "context2:", context2
+
+ # Verify that the context point to the same function 'a'.
+ symbol1 = context1.GetSymbol()
+ symbol2 = context2.GetSymbol()
+ self.assertTrue(symbol1.IsValid() and symbol2.IsValid())
+ print "symbol1:", symbol1
+ print "symbol2:", symbol2
+
+ stream1 = lldb.SBStream()
+ symbol1.GetDescription(stream1)
+ stream2 = lldb.SBStream()
+ symbol2.GetDescription(stream2)
+
+ self.expect(stream1.GetData(), "The two addresses should resolve to the same symbol", exe=False,
+ startstr = stream2.GetData())
+
+
+if __name__ == '__main__':
+ import atexit
+ lldb.SBDebugger.Initialize()
+ atexit.register(lambda: lldb.SBDebugger.Terminate())
+ unittest2.main()
diff --git a/lldb/test/python_api/target/main.c b/lldb/test/python_api/target/main.c
new file mode 100644
index 00000000000..aa9fc092627
--- /dev/null
+++ b/lldb/test/python_api/target/main.c
@@ -0,0 +1,57 @@
+//===-- 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>
+
+// This simple program is to test the lldb Python API SBTarget.
+//
+// When stopped on breakppint 1, and then 2, we can get the line entries using
+// SBFrame API SBFrame.GetLineEntry(). We'll get the start addresses for the
+// two line entries; with the start address (of SBAddress type), we can then
+// resolve the symbol context using the SBTarget API
+// SBTarget.ResolveSymbolContextForAddress().
+//
+// The two symbol context should point to the same symbol, i.e., 'a' function.
+
+int a(int);
+int b(int);
+int c(int);
+
+int a(int val)
+{
+ if (val <= 1) // Find the line number for breakpoint 1 here.
+ val = b(val);
+ else if (val >= 3)
+ val = c(val);
+
+ return val; // Find the line number for breakpoint 2 here.
+}
+
+int b(int val)
+{
+ return c(val);
+}
+
+int c(int val)
+{
+ return val + 3;
+}
+
+int main (int argc, char const *argv[])
+{
+ int A1 = a(1); // a(1) -> b(1) -> c(1)
+ printf("a(1) returns %d\n", A1);
+
+ int B2 = b(2); // b(2) -> c(2)
+ printf("b(2) returns %d\n", B2);
+
+ int A3 = a(3); // a(3) -> c(3)
+ printf("a(3) returns %d\n", A3);
+
+ return 0;
+}
OpenPOWER on IntegriCloud