diff options
| author | Dan Liew <dan@su-root.co.uk> | 2023-02-27 17:05:19 -0800 |
|---|---|---|
| committer | Dan Liew <dan@su-root.co.uk> | 2023-03-01 11:15:05 -0800 |
| commit | 55a363fea18b20a81e8ebb9518997a3bda602f32 (patch) | |
| tree | 3cb8df7c95e068f452b851ec6c05bd2cba528033 /lldb/test/API/python_api | |
| parent | c574e93afd2e5f7986abeece88449c84ebd2e76d (diff) | |
| download | llvm-55a363fea18b20a81e8ebb9518997a3bda602f32.zip llvm-55a363fea18b20a81e8ebb9518997a3bda602f32.tar.gz llvm-55a363fea18b20a81e8ebb9518997a3bda602f32.tar.bz2 | |
[LLDB] Expose several methods in SBWatchpoint
This patch adds the following methods:
* `GetType()`
* `GetWatchValueKind()`
* `GetWatchSpec()`
* `IsWatchingReads()`
* `IsWatchingWrites()`
These mostly expose methods that `lldb_private::Watchpoint` already
had. Tests are included that exercise these new methods.
The motivation for exposing these are as follows:
* `GetType()` - With this information and the address from a watchpoint
it is now possible to construct an SBValue from an SBWatchpoint.
Previously this wasn't possible. The included test case illustrates
doing this.
* `GetWatchValueKind()` - This allows the caller to determine whether the
watchpoint is a variable watchpoint or an expression watchpoint. A new
enum (`WatchpointValueKind`) has been introduced to represent the
return values. Unfortunately the name `WatchpointKind` was already
taken.
* `GetWatchSpec()` - This allows (at least for variable watchpoints)
to use a sensible name for SBValues created from an SBWatchpoint.
* `IsWatchingReads()` - This allow checking if a watchpoint is
monitoring read accesses.
* `IsWatchingWRites()` - This allow checking if a watchpoint is
monitoring write accesses.
rdar://105606978
Reviewers: jingham, mib, bulbazord, jasonmolenda, JDevlieghere
Differential Revision: https://reviews.llvm.org/D144937
Diffstat (limited to 'lldb/test/API/python_api')
| -rw-r--r-- | lldb/test/API/python_api/watchpoint/TestSetWatchpoint.py | 52 | ||||
| -rw-r--r-- | lldb/test/API/python_api/watchpoint/watchlocation/TestSetWatchlocation.py | 9 |
2 files changed, 55 insertions, 6 deletions
diff --git a/lldb/test/API/python_api/watchpoint/TestSetWatchpoint.py b/lldb/test/API/python_api/watchpoint/TestSetWatchpoint.py index 1a6f18e..b6ffec3 100644 --- a/lldb/test/API/python_api/watchpoint/TestSetWatchpoint.py +++ b/lldb/test/API/python_api/watchpoint/TestSetWatchpoint.py @@ -19,12 +19,24 @@ class SetWatchpointAPITestCase(TestBase): # Find the line number to break inside main(). self.line = line_number( self.source, '// Set break point at this line.') + self.build() # Read-write watchpoints not supported on SystemZ @expectedFailureAll(archs=['s390x']) def test_watch_val(self): """Exercise SBValue.Watch() API to set a watchpoint.""" - self.build() + self._test_watch_val(variable_watchpoint=False) + pass + + @expectedFailureAll(archs=['s390x']) + def test_watch_variable(self): + """ + Exercise some watchpoint APIs when the watchpoint + is created as a variable watchpoint. + """ + self._test_watch_val(variable_watchpoint=True) + + def _test_watch_val(self, variable_watchpoint): exe = self.getBuildArtifact("a.out") # Create a target by the debugger. @@ -50,12 +62,40 @@ class SetWatchpointAPITestCase(TestBase): frame0 = thread.GetFrameAtIndex(0) # Watch 'global' for read and write. - value = frame0.FindValue('global', lldb.eValueTypeVariableGlobal) - error = lldb.SBError() - watchpoint = value.Watch(True, True, True, error) - self.assertTrue(value and watchpoint, + if variable_watchpoint: + # FIXME: There should probably be an API to create a + # variable watchpoint. + self.runCmd('watchpoint set variable -w read_write -- global') + watchpoint = target.GetWatchpointAtIndex(0) + self.assertEqual(watchpoint.GetWatchValueKind(), + lldb.eWatchPointValueKindVariable) + self.assertEqual(watchpoint.GetWatchSpec(), 'global') + # Synthesize an SBValue from the watchpoint + watchpoint_addr = lldb.SBAddress(watchpoint.GetWatchAddress(), + target) + value = target.CreateValueFromAddress( + watchpoint.GetWatchSpec(), + watchpoint_addr, watchpoint.GetType()) + else: + value = frame0.FindValue('global', lldb.eValueTypeVariableGlobal) + error = lldb.SBError() + watchpoint = value.Watch(True, True, True, error) + self.assertTrue(value and watchpoint, "Successfully found the variable and set a watchpoint") - self.DebugSBValue(value) + self.DebugSBValue(value) + self.assertEqual(watchpoint.GetWatchValueKind(), + lldb.eWatchPointValueKindExpression) + # FIXME: The spec should probably be '&global' given that the kind + # is reported as eWatchPointValueKindExpression. If the kind is + # actually supposed to be eWatchPointValueKindVariable then the spec + # should probably be 'global'. + self.assertEqual(watchpoint.GetWatchSpec(), None) + + self.assertEqual(watchpoint.GetType().GetDisplayTypeName(), 'int32_t') + self.assertEqual(value.GetName(), 'global') + self.assertEqual(value.GetType(), watchpoint.GetType()) + self.assertTrue(watchpoint.IsWatchingReads()) + self.assertTrue(watchpoint.IsWatchingWrites()) # Hide stdout if not running with '-t' option. if not self.TraceOn(): diff --git a/lldb/test/API/python_api/watchpoint/watchlocation/TestSetWatchlocation.py b/lldb/test/API/python_api/watchpoint/watchlocation/TestSetWatchlocation.py index bd4d309..ccf9bf8 100644 --- a/lldb/test/API/python_api/watchpoint/watchlocation/TestSetWatchlocation.py +++ b/lldb/test/API/python_api/watchpoint/watchlocation/TestSetWatchlocation.py @@ -64,6 +64,15 @@ class SetWatchlocationAPITestCase(TestBase): self.DebugSBValue(value) self.DebugSBValue(pointee) + # Check some API calls return expected values + self.assertEqual(watchpoint.GetWatchValueKind(), + lldb.eWatchPointValueKindExpression) + # FIXME: The spec should probably be 'g_char_ptr' + self.assertEqual(watchpoint.GetWatchSpec(), None) + self.assertEqual(watchpoint.GetType().GetDisplayTypeName(), 'char') + self.assertFalse(watchpoint.IsWatchingReads()) + self.assertTrue(watchpoint.IsWatchingWrites()) + # Hide stdout if not running with '-t' option. if not self.TraceOn(): self.HideStdout() |
