2 Use lldb Python SBValue.WatchPointee() API to create a watchpoint for write of '*g_char_ptr'.
5 from __future__ import print_function
10 from lldbsuite.test.decorators import *
11 from lldbsuite.test.lldbtest import *
12 from lldbsuite.test import lldbutil
15 class SetWatchlocationAPITestCase(TestBase):
17 mydir = TestBase.compute_mydir(__file__)
18 NO_DEBUG_INFO_TESTCASE = True
21 # Call super's setUp().
23 # Our simple source filename.
24 self.source = 'main.cpp'
25 # Find the line number to break inside main().
26 self.line = line_number(
27 self.source, '// Set break point at this line.')
28 # This is for verifying that watch location works.
29 self.violating_func = "do_bad_thing_with_location"
31 @add_test_categories(['pyapi'])
32 def test_watch_location(self):
33 """Exercise SBValue.WatchPointee() API to set a watchpoint."""
35 exe = self.getBuildArtifact("a.out")
37 # Create a target by the debugger.
38 target = self.dbg.CreateTarget(exe)
39 self.assertTrue(target, VALID_TARGET)
41 # Now create a breakpoint on main.c.
42 breakpoint = target.BreakpointCreateByLocation(self.source, self.line)
43 self.assertTrue(breakpoint and
44 breakpoint.GetNumLocations() == 1,
47 # Now launch the process, and do not stop at the entry point.
48 process = target.LaunchSimple(
49 None, None, self.get_process_working_directory())
51 # We should be stopped due to the breakpoint. Get frame #0.
52 process = target.GetProcess()
53 self.assertTrue(process.GetState() == lldb.eStateStopped,
55 thread = lldbutil.get_stopped_thread(
56 process, lldb.eStopReasonBreakpoint)
57 frame0 = thread.GetFrameAtIndex(0)
59 value = frame0.FindValue('g_char_ptr',
60 lldb.eValueTypeVariableGlobal)
61 pointee = value.CreateValueFromAddress(
63 value.GetValueAsUnsigned(0),
64 value.GetType().GetPointeeType())
65 # Watch for write to *g_char_ptr.
66 error = lldb.SBError()
67 watchpoint = value.WatchPointee(True, False, True, error)
68 self.assertTrue(value and watchpoint,
69 "Successfully found the pointer and set a watchpoint")
70 self.DebugSBValue(value)
71 self.DebugSBValue(pointee)
73 # Hide stdout if not running with '-t' option.
74 if not self.TraceOn():
79 # Continue. Expect the program to stop due to the variable being
84 lldbutil.print_stacktraces(process)
86 thread = lldbutil.get_stopped_thread(
87 process, lldb.eStopReasonWatchpoint)
88 self.assertTrue(thread, "The thread stopped due to watchpoint")
89 self.DebugSBValue(value)
90 self.DebugSBValue(pointee)
93 lldbutil.print_stacktrace(
100 # This finishes our test.