Skip to content

Commit 5953f54

Browse files
committed
Compare saved stack pointer and the cached thread stack pointer from the process to ensure the addresses are saved correctly.
1 parent aa6d0a2 commit 5953f54

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class ProcessSaveCoreMinidumpTestCase(TestBase):
1313
def verify_core_file(
14-
self, core_path, expected_pid, expected_modules, expected_threads
14+
self, core_path, expected_pid, expected_modules, expected_threads, stacks_to_sps_map
1515
):
1616
# To verify, we'll launch with the mini dump
1717
target = self.dbg.CreateTarget(None)
@@ -41,15 +41,22 @@ def verify_core_file(
4141
self.assertTrue(thread.IsValid())
4242
thread_id = thread.GetThreadID()
4343
self.assertIn(thread_id, expected_threads)
44-
oldest_frame = thread.GetFrameAtIndex(thread.GetNumFrames() - 1)
45-
stack_start = oldest_frame.GetSP()
4644
frame = thread.GetFrameAtIndex(0)
45+
sp_region = lldb.SBMemoryRegionInfo()
4746
sp = frame.GetSP()
47+
err = process.GetMemoryRegionInfo(sp, sp_region)
48+
self.assertTrue(err.Success(), err.GetCString())
4849
error = lldb.SBError()
49-
process.ReadMemory(sp - red_zone + 1, 1, error)
50-
self.assertTrue(error.Success(), error.GetCString())
51-
process.ReadMemory(stack_start - 1, 1, error)
50+
# Try to read at the end of the stack red zone and succeed
51+
process.ReadMemory(sp_region.GetRegionEnd() - 1, 1, error)
5252
self.assertTrue(error.Success(), error.GetCString())
53+
# Try to read just past the red zone and fail
54+
process.ReadMemory(sp_region.GetRegionEnd() + 1, 1, error)
55+
# Try to read from the base of the stack
56+
self.assertTrue(error.Fail(), error.GetCString())
57+
self.assertTrue(stacks_to_sps_map.__contains__(thread_id), "stacks_to_sps_map does not contain thread_idx: %d" % thread_idx)
58+
# Ensure the SP is correct
59+
self.assertEqual(stacks_to_sps_map[thread_id], sp)
5360

5461

5562
self.dbg.DeleteTarget(target)
@@ -81,45 +88,47 @@ def test_save_linux_mini_dump(self):
8188
expected_modules = target.modules
8289
expected_number_of_threads = process.GetNumThreads()
8390
expected_threads = []
91+
stacks_to_sp_map = {}
8492

8593
for thread_idx in range(process.GetNumThreads()):
8694
thread = process.GetThreadAtIndex(thread_idx)
8795
thread_id = thread.GetThreadID()
8896
expected_threads.append(thread_id)
97+
stacks_to_sp_map[thread_id] = thread.GetFrameAtIndex(0).GetSP()
8998

9099
# save core and, kill process and verify corefile existence
91100
base_command = "process save-core --plugin-name=minidump "
92101
self.runCmd(base_command + " --style=stack '%s'" % (core_stack))
93102
self.assertTrue(os.path.isfile(core_stack))
94103
self.verify_core_file(
95-
core_stack, expected_pid, expected_modules, expected_threads
104+
core_stack, expected_pid, expected_modules, expected_threads, stacks_to_sp_map
96105
)
97106

98107
self.runCmd(base_command + " --style=modified-memory '%s'" % (core_dirty))
99108
self.assertTrue(os.path.isfile(core_dirty))
100109
self.verify_core_file(
101-
core_dirty, expected_pid, expected_modules, expected_threads
110+
core_dirty, expected_pid, expected_modules, expected_threads, stacks_to_sp_map
102111
)
103112

104113
self.runCmd(base_command + " --style=full '%s'" % (core_full))
105114
self.assertTrue(os.path.isfile(core_full))
106115
self.verify_core_file(
107-
core_full, expected_pid, expected_modules, expected_threads
116+
core_full, expected_pid, expected_modules, expected_threads, stacks_to_sp_map
108117
)
109118

110119
# validate saving via SBProcess
111120
error = process.SaveCore(core_sb_stack, "minidump", lldb.eSaveCoreStackOnly)
112121
self.assertTrue(error.Success())
113122
self.assertTrue(os.path.isfile(core_sb_stack))
114123
self.verify_core_file(
115-
core_sb_stack, expected_pid, expected_modules, expected_threads
124+
core_sb_stack, expected_pid, expected_modules, expected_threads, stacks_to_sp_map
116125
)
117126

118127
error = process.SaveCore(core_sb_dirty, "minidump", lldb.eSaveCoreDirtyOnly)
119128
self.assertTrue(error.Success())
120129
self.assertTrue(os.path.isfile(core_sb_dirty))
121130
self.verify_core_file(
122-
core_sb_dirty, expected_pid, expected_modules, expected_threads
131+
core_sb_dirty, expected_pid, expected_modules, expected_threads, stacks_to_sp_map
123132
)
124133

125134
# Minidump can now save full core files, but they will be huge and
@@ -128,7 +137,7 @@ def test_save_linux_mini_dump(self):
128137
self.assertTrue(error.Success())
129138
self.assertTrue(os.path.isfile(core_sb_full))
130139
self.verify_core_file(
131-
core_sb_full, expected_pid, expected_modules, expected_threads
140+
core_sb_full, expected_pid, expected_modules, expected_threads, stacks_to_sp_map
132141
)
133142

134143
self.assertSuccess(process.Kill())

0 commit comments

Comments
 (0)