Skip to content

Commit b19c3da

Browse files
author
Miro Bucko
committed
[lldb] Fix tests for FindInMemory SB API introduced in llvm#95007.
1 parent 33a9c57 commit b19c3da

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed

lldb/test/API/python_api/find_in_memory/TestFindInMemory.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,33 @@ def setUp(self):
2121
self.thread,
2222
self.bp,
2323
) = lldbutil.run_to_source_breakpoint(
24-
self, "break here", lldb.SBFileSpec("main.cpp")
24+
self,
25+
"break here",
26+
lldb.SBFileSpec("main.cpp"),
2527
)
2628
self.assertTrue(self.bp.IsValid())
2729

30+
def test_check_stack_pointer(self):
31+
"""Make sure the 'stack_pointer' variable lives on the stack"""
32+
self.assertTrue(self.process, PROCESS_IS_VALID)
33+
self.assertState(self.process.GetState(), lldb.eStateStopped, PROCESS_STOPPED)
34+
35+
frame = self.thread.GetSelectedFrame()
36+
ex = frame.EvaluateExpression("&stack_pointer")
37+
variable_region = lldb.SBMemoryRegionInfo()
38+
self.assertTrue(
39+
self.process.GetMemoryRegionInfo(
40+
ex.GetValueAsUnsigned(), variable_region
41+
).Success(),
42+
)
43+
44+
stack_region = lldb.SBMemoryRegionInfo()
45+
self.assertTrue(
46+
self.process.GetMemoryRegionInfo(frame.GetSP(), stack_region).Success(),
47+
)
48+
49+
self.assertEqual(variable_region, stack_region)
50+
2851
def test_find_in_memory_ok(self):
2952
"""Make sure a match exists in the heap memory and the right address ranges are provided"""
3053
self.assertTrue(self.process, PROCESS_IS_VALID)

lldb/test/API/python_api/find_in_memory/address_ranges_helper.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def GetAlignedRange(test_base):
1515

1616
def GetStackRange(test_base):
1717
frame = test_base.thread.GetSelectedFrame()
18-
ex = frame.EvaluateExpression("stack_pointer")
18+
ex = frame.EvaluateExpression("&stack_pointer")
1919
test_base.assertTrue(ex.IsValid())
2020
return GetRangeFromAddrValue(test_base, ex)
2121

@@ -35,6 +35,7 @@ def GetRangeFromAddrValue(test_base, addr):
3535
)
3636

3737
test_base.assertTrue(region.IsReadable())
38+
test_base.assertFalse(region.IsExecutable())
3839

3940
address_start = lldb.SBAddress(region.GetRegionBase(), test_base.target)
4041
stack_size = region.GetRegionEnd() - region.GetRegionBase()
Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#include <cstdlib>
21
#include <cstring>
2+
#include <memory>
33
#include <string>
44

55
int main() {
66
// Stack
7-
const char *stack_pointer = "stack_there_is_only_one_of_me";
7+
const char stack_pointer[] = "stack_there_is_only_one_of_me";
88

99
// Heap
1010
const std::string heap_string1("heap_there_is_exactly_two_of_me");
@@ -14,14 +14,25 @@ int main() {
1414

1515
// Aligned Heap
1616
constexpr char aligned_string[] = "i_am_unaligned_string_on_the_heap";
17+
constexpr size_t buffer_size = 100;
1718
constexpr size_t len = sizeof(aligned_string) + 1;
1819
// Allocate memory aligned to 8-byte boundary
19-
void *aligned_string_ptr = aligned_alloc(8, len);
20+
void *aligned_string_ptr = new size_t[buffer_size];
21+
if (aligned_string_ptr == nullptr) {
22+
return -1;
23+
}
24+
// Zero out the memory
25+
memset(aligned_string_ptr, 0, buffer_size);
26+
27+
// Align the pointer to a multiple of 8 bytes
28+
size_t size = buffer_size;
29+
aligned_string_ptr = std::align(8, len, aligned_string_ptr, size);
30+
31+
// Copy the string to aligned memory
2032
memcpy(aligned_string_ptr, aligned_string, len);
2133

2234
(void)stack_pointer;
2335
(void)heap_pointer1;
24-
(void)heap_pointer2;
25-
(void)aligned_string_ptr; // break here
36+
(void)heap_pointer2; // break here
2637
return 0;
2738
}

0 commit comments

Comments
 (0)