diff options
| author | Dave Lee <davelee.com@gmail.com> | 2023-02-03 08:45:44 -0800 |
|---|---|---|
| committer | Dave Lee <davelee.com@gmail.com> | 2023-02-08 10:46:26 -0800 |
| commit | 3ff636729d067801039b3a37618f6ce0dd1c3d24 (patch) | |
| tree | 22a48d087319e4571c4bfa4594d0b3600619c46c /lldb/test/API/python_api | |
| parent | 5d07e0448e38d4be0cc7b1079d72b5e3644e941c (diff) | |
| download | llvm-3ff636729d067801039b3a37618f6ce0dd1c3d24.zip llvm-3ff636729d067801039b3a37618f6ce0dd1c3d24.tar.gz llvm-3ff636729d067801039b3a37618f6ce0dd1c3d24.tar.bz2 | |
[lldb] Accept negative indexes in __getitem__
To the Python bindings, add support for Python-like negative indexes.
While was using `script`, I tried to access a thread's bottom frame with
`thread.frame[-1]`, but that failed. This change updates the `__getitem__`
implementations to support negative indexes as one would expect in Python.
Differential Revision: https://reviews.llvm.org/D143282
Diffstat (limited to 'lldb/test/API/python_api')
| -rw-r--r-- | lldb/test/API/python_api/breakpoint/TestBreakpointAPI.py | 3 | ||||
| -rw-r--r-- | lldb/test/API/python_api/thread/TestThreadAPI.py | 31 |
2 files changed, 34 insertions, 0 deletions
diff --git a/lldb/test/API/python_api/breakpoint/TestBreakpointAPI.py b/lldb/test/API/python_api/breakpoint/TestBreakpointAPI.py index 014065e..da6c895 100644 --- a/lldb/test/API/python_api/breakpoint/TestBreakpointAPI.py +++ b/lldb/test/API/python_api/breakpoint/TestBreakpointAPI.py @@ -62,6 +62,9 @@ class BreakpointAPITestCase(TestBase): location = breakpoint.GetLocationAtIndex(0) self.assertTrue(location.IsValid()) + # Test negative index access. + self.assertTrue(breakpoint.location[-1].IsValid()) + # Make sure the breakpoint's target is right: self.assertEqual(target, breakpoint.GetTarget(), "Breakpoint reports its target correctly") diff --git a/lldb/test/API/python_api/thread/TestThreadAPI.py b/lldb/test/API/python_api/thread/TestThreadAPI.py index 7bdcf36..b26d168 100644 --- a/lldb/test/API/python_api/thread/TestThreadAPI.py +++ b/lldb/test/API/python_api/thread/TestThreadAPI.py @@ -48,6 +48,11 @@ class ThreadAPITestCase(TestBase): self.setTearDownCleanup(dictionary=d) self.step_over_3_times(self.exe_name) + def test_negative_indexing(self): + """Test SBThread.frame with negative indexes.""" + self.build() + self.validate_negative_indexing() + def setUp(self): # Call super's setUp(). TestBase.setUp(self) @@ -269,3 +274,29 @@ class ThreadAPITestCase(TestBase): thread.RunToAddress(start_addr) self.runCmd("process status") #self.runCmd("thread backtrace") + + def validate_negative_indexing(self): + exe = self.getBuildArtifact("a.out") + + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + breakpoint = target.BreakpointCreateByLocation( + "main.cpp", self.break_line) + self.assertTrue(breakpoint, VALID_BREAKPOINT) + self.runCmd("breakpoint list") + + # Launch the process, and do not stop at the entry point. + process = target.LaunchSimple( + None, None, self.get_process_working_directory()) + + thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertTrue( + thread.IsValid(), + "There should be a thread stopped due to breakpoint") + self.runCmd("process status") + + pos_range = range(thread.num_frames) + neg_range = range(thread.num_frames, 0, -1) + for pos, neg in zip(pos_range, neg_range): + self.assertEqual(thread.frame[pos].idx, thread.frame[-neg].idx) |
