11
11
12
12
class ProcessSaveCoreMinidumpTestCase (TestBase ):
13
13
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
15
15
):
16
16
# To verify, we'll launch with the mini dump
17
17
target = self .dbg .CreateTarget (None )
@@ -41,15 +41,22 @@ def verify_core_file(
41
41
self .assertTrue (thread .IsValid ())
42
42
thread_id = thread .GetThreadID ()
43
43
self .assertIn (thread_id , expected_threads )
44
- oldest_frame = thread .GetFrameAtIndex (thread .GetNumFrames () - 1 )
45
- stack_start = oldest_frame .GetSP ()
46
44
frame = thread .GetFrameAtIndex (0 )
45
+ sp_region = lldb .SBMemoryRegionInfo ()
47
46
sp = frame .GetSP ()
47
+ err = process .GetMemoryRegionInfo (sp , sp_region )
48
+ self .assertTrue (err .Success (), err .GetCString ())
48
49
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 )
52
52
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 )
53
60
54
61
55
62
self .dbg .DeleteTarget (target )
@@ -81,45 +88,47 @@ def test_save_linux_mini_dump(self):
81
88
expected_modules = target .modules
82
89
expected_number_of_threads = process .GetNumThreads ()
83
90
expected_threads = []
91
+ stacks_to_sp_map = {}
84
92
85
93
for thread_idx in range (process .GetNumThreads ()):
86
94
thread = process .GetThreadAtIndex (thread_idx )
87
95
thread_id = thread .GetThreadID ()
88
96
expected_threads .append (thread_id )
97
+ stacks_to_sp_map [thread_id ] = thread .GetFrameAtIndex (0 ).GetSP ()
89
98
90
99
# save core and, kill process and verify corefile existence
91
100
base_command = "process save-core --plugin-name=minidump "
92
101
self .runCmd (base_command + " --style=stack '%s'" % (core_stack ))
93
102
self .assertTrue (os .path .isfile (core_stack ))
94
103
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
96
105
)
97
106
98
107
self .runCmd (base_command + " --style=modified-memory '%s'" % (core_dirty ))
99
108
self .assertTrue (os .path .isfile (core_dirty ))
100
109
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
102
111
)
103
112
104
113
self .runCmd (base_command + " --style=full '%s'" % (core_full ))
105
114
self .assertTrue (os .path .isfile (core_full ))
106
115
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
108
117
)
109
118
110
119
# validate saving via SBProcess
111
120
error = process .SaveCore (core_sb_stack , "minidump" , lldb .eSaveCoreStackOnly )
112
121
self .assertTrue (error .Success ())
113
122
self .assertTrue (os .path .isfile (core_sb_stack ))
114
123
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
116
125
)
117
126
118
127
error = process .SaveCore (core_sb_dirty , "minidump" , lldb .eSaveCoreDirtyOnly )
119
128
self .assertTrue (error .Success ())
120
129
self .assertTrue (os .path .isfile (core_sb_dirty ))
121
130
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
123
132
)
124
133
125
134
# Minidump can now save full core files, but they will be huge and
@@ -128,7 +137,7 @@ def test_save_linux_mini_dump(self):
128
137
self .assertTrue (error .Success ())
129
138
self .assertTrue (os .path .isfile (core_sb_full ))
130
139
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
132
141
)
133
142
134
143
self .assertSuccess (process .Kill ())
0 commit comments