[Lldb-commits] [lldb] r141931 - in /lldb/trunk: source/API/SBTarget.cpp test/python_api/default-constructor/sb_target.py test/python_api/watchpoint/watchlocation/TestTargetWatchAddress.py
Johnny Chen
johnny.chen at apple.com
Thu Oct 13 18:16:39 PDT 2011
Author: johnny
Date: Thu Oct 13 20:16:39 2011
New Revision: 141931
URL: http://llvm.org/viewvc/llvm-project?rev=141931&view=rev
Log:
Add a test case to exercise the newly added SB API:
lldb::SBWatchpoint
SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write)
Added:
lldb/trunk/test/python_api/watchpoint/watchlocation/TestTargetWatchAddress.py
Modified:
lldb/trunk/source/API/SBTarget.cpp
lldb/trunk/test/python_api/default-constructor/sb_target.py
Modified: lldb/trunk/source/API/SBTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=141931&r1=141930&r2=141931&view=diff
==============================================================================
--- lldb/trunk/source/API/SBTarget.cpp (original)
+++ lldb/trunk/source/API/SBTarget.cpp Thu Oct 13 20:16:39 2011
@@ -957,7 +957,7 @@
Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
uint32_t watch_type = (read ? LLDB_WATCH_TYPE_READ : 0) |
(write ? LLDB_WATCH_TYPE_WRITE : 0);
- WatchpointSP wp_sp = m_opaque_sp->CreateWatchpoint(addr, size, watch_type);
+ sb_watchpoint = m_opaque_sp->CreateWatchpoint(addr, size, watch_type);
}
if (log)
Modified: lldb/trunk/test/python_api/default-constructor/sb_target.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/default-constructor/sb_target.py?rev=141931&r1=141930&r2=141931&view=diff
==============================================================================
--- lldb/trunk/test/python_api/default-constructor/sb_target.py (original)
+++ lldb/trunk/test/python_api/default-constructor/sb_target.py Thu Oct 13 20:16:39 2011
@@ -47,6 +47,7 @@
obj.EnableAllWatchpoints()
obj.DisableAllWatchpoints()
obj.DeleteAllWatchpoints()
+ obj.WatchAddress(123, 8, True, True)
obj.GetBroadcaster()
obj.GetDescription(lldb.SBStream(), lldb.eDescriptionLevelBrief)
obj.Clear()
@@ -54,5 +55,5 @@
print module
for bp in obj.breakpoint_iter():
print bp
- for wp_loc in obj.watchpoint_iter():
- print wp_loc
+ for wp in obj.watchpoint_iter():
+ print wp
Added: lldb/trunk/test/python_api/watchpoint/watchlocation/TestTargetWatchAddress.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/watchpoint/watchlocation/TestTargetWatchAddress.py?rev=141931&view=auto
==============================================================================
--- lldb/trunk/test/python_api/watchpoint/watchlocation/TestTargetWatchAddress.py (added)
+++ lldb/trunk/test/python_api/watchpoint/watchlocation/TestTargetWatchAddress.py Thu Oct 13 20:16:39 2011
@@ -0,0 +1,102 @@
+"""
+Use lldb Python SBtarget.WatchAddress() API to create a watchpoint for write of '*g_char_ptr'.
+"""
+
+import os, time
+import re
+import unittest2
+import lldb, lldbutil
+from lldbtest import *
+
+class TargetWatchAddressAPITestCase(TestBase):
+
+ mydir = os.path.join("python_api", "watchpoint", "watchlocation")
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ # Our simple source filename.
+ self.source = 'main.cpp'
+ # Find the line number to break inside main().
+ self.line = line_number(self.source, '// Set break point at this line.')
+ # This is for verifying that watch location works.
+ self.violating_func = "do_bad_thing_with_location";
+
+ @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+ @python_api_test
+ def test_watch_address_with_dsym(self):
+ """Exercise SBTarget.WatchAddress() API to set a watchpoint."""
+ self.buildDsym()
+ self.do_set_watchaddress()
+
+ @python_api_test
+ def test_watch_val_with_dwarf(self):
+ """Exercise SBTarget.WatchAddress() API to set a watchpoint."""
+ self.buildDwarf()
+ self.do_set_watchaddress()
+
+ def do_set_watchaddress(self):
+ """Use SBTarget.WatchAddress() to set a watchpoint and verify that the program stops later due to the watchpoint."""
+ exe = os.path.join(os.getcwd(), "a.out")
+
+ # Create a target by the debugger.
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, VALID_TARGET)
+
+ # Now create a breakpoint on main.c.
+ breakpoint = target.BreakpointCreateByLocation(self.source, self.line)
+ self.assertTrue(breakpoint and
+ breakpoint.GetNumLocations() == 1,
+ VALID_BREAKPOINT)
+
+ # Now launch the process, and do not stop at the entry point.
+ process = target.LaunchSimple(None, None, os.getcwd())
+
+ # We should be stopped due to the breakpoint. Get frame #0.
+ process = target.GetProcess()
+ self.assertTrue(process.GetState() == lldb.eStateStopped,
+ PROCESS_STOPPED)
+ thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
+ frame0 = thread.GetFrameAtIndex(0)
+
+ value = frame0.FindValue('g_char_ptr',
+ lldb.eValueTypeVariableGlobal)
+ pointee = value.CreateValueFromAddress("pointee",
+ value.GetValueAsUnsigned(0),
+ value.GetType().GetPointeeType())
+ # Watch for write to *g_char_ptr.
+ watchpoint = target.WatchAddress(value.GetValueAsUnsigned(), 1, False, True)
+ print watchpoint
+ self.assertTrue(value and watchpoint,
+ "Successfully found the pointer and set a watchpoint")
+ self.DebugSBValue(value)
+ self.DebugSBValue(pointee)
+
+ # Hide stdout if not running with '-t' option.
+ if not self.TraceOn():
+ self.HideStdout()
+
+ print watchpoint
+
+ # Continue. Expect the program to stop due to the variable being written to.
+ process.Continue()
+
+ if (self.TraceOn()):
+ lldbutil.print_stacktraces(process)
+
+ thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonWatchpoint)
+ self.assertTrue(thread, "The thread stopped due to watchpoint")
+ self.DebugSBValue(value)
+ self.DebugSBValue(pointee)
+
+ self.expect(lldbutil.print_stacktrace(thread, string_buffer=True), exe=False,
+ substrs = [self.violating_func])
+
+ # This finishes our test.
+
+
+if __name__ == '__main__':
+ import atexit
+ lldb.SBDebugger.Initialize()
+ atexit.register(lambda: lldb.SBDebugger.Terminate())
+ unittest2.main()
More information about the lldb-commits
mailing list