7
7
from lldbsuite .test .decorators import *
8
8
from lldbsuite .test .lldbtest import *
9
9
from lldbsuite .test import lldbutil
10
+ from dataclass import dataclass
11
+
12
+ class AddressRange :
13
+ begin : int
14
+ end : int
15
+
16
+ def __init__ (self , begin , end ):
17
+ self .begin = begin
18
+ self .end = end
10
19
11
20
12
21
class ProcessSaveCoreMinidumpTestCaseYaml (TestBase ):
@@ -17,12 +26,34 @@ def process_from_yaml(self, yaml_file):
17
26
self .process = self .target .LoadCore (minidump_path )
18
27
return self .process
19
28
29
+ def validate_regions_saved_correctly (self , core_process , expected_region , expected_invalid_region = None ):
30
+ """ Validate that the expected_region is saved in the core_proc, and that the expected invalid region is not saved, if not not none. """
31
+
32
+ # Validate we can read the entire expected_region
33
+ error = lldb .SBError ()
34
+ core_process .ReadMemory (expected_region .begin , expected_region .end - expected_region .begin , error )
35
+ self .assertTrue (error .Success (), error .GetCString ())
36
+
37
+ # Validate we can't read before and after the expected_region
38
+ core_process .ReadMemory (expected_region .begin - 1 , 1 , error )
39
+ self .assertTrue (error .Fail (), error .GetCString ())
40
+
41
+ core_process .ReadMemory (expected_region .end + 1 , 1 , error )
42
+ self .assertTrue (error .Fail (), error .GetCString ())
43
+
44
+ if expected_invalid_region is None :
45
+ return
46
+
47
+ # Validate we can't read the original_region
48
+ core_process .ReadMemory (expected_invalid_region .begin , expected_invalid_region .end - expected_invalid_region .end , error )
49
+ self .assertTrue (error .Success (), error .GetCString ())
50
+
20
51
def test_saving_sub_memory_range (self ):
21
52
"""
22
53
Validate we can save a Minidump for a subsection of a memory range.
23
54
I.E.
24
- If our memory range is 0x1000- 0x2000 nd the user specifies 0x1200-0x1800
25
- we should still capture 0x1200 to 0x1800
55
+ If our memory range is 0x2000-0x2020 and the user specifies 0x2000-0x2008
56
+ we should still capture 0x2000-0x2008
26
57
"""
27
58
yaml = "minidump_mem64.yaml"
28
59
proc = self .process_from_yaml (yaml )
@@ -43,20 +74,16 @@ def test_saving_sub_memory_range(self):
43
74
core_target = self .dbg .CreateTarget (None )
44
75
core_process = core_target .LoadCore (new_minidump_path )
45
76
46
- error = lldb .SBError ()
47
- core_process .ReadMemory (begin , size , error )
48
- self .assertTrue (error .Success (), error .GetCString ())
49
-
50
- # Try to read 1 byte past the end
51
- core_process .ReadMemory (end + 1 , 1 , error )
52
- self .assertTrue (error .Fail (), error .GetCString ())
77
+ expected_address_range = AddressRange (begin , end )
78
+ expected_invalid_range = AddressRange (begin , 0x2020 )
79
+ self .validate_regions_saved_correctly (core_process , expected_address_range , expected_invalid_range )
53
80
54
81
def test_saving_super_memory_range (self ):
55
82
"""
56
83
Validate we can save a Minidump for a subsection of a memory range.
57
84
I.E.
58
- If our memory range is 0x1000-0x2000 nd the user specifies 0x0800-0x2800
59
- we should still capture 0x1000-0x2000
85
+ If our memory range is 0x1000-0x1100 and the user specifies 0x900-x1200
86
+ we should still capture 0x1000-0x1100
60
87
"""
61
88
yaml = "minidump_mem64.yaml"
62
89
proc = self .process_from_yaml (yaml )
@@ -77,9 +104,9 @@ def test_saving_super_memory_range(self):
77
104
core_target = self .dbg .CreateTarget (None )
78
105
core_process = core_target .LoadCore (new_minidump_path )
79
106
80
- error = lldb . SBError ( )
81
- core_process . ReadMemory (begin , size , error )
82
- self .assertTrue ( error . Success (), error . GetCString () )
107
+ expected_address_range = AddressRange ( begin , end )
108
+ expected_invalid_range = AddressRange (begin - 16 , end + 16 )
109
+ self .validate_regions_saved_correctly ( core_process , expected_address_range , expected_invalid_range )
83
110
84
111
def test_region_that_goes_out_of_bounds (self ):
85
112
"""
@@ -105,13 +132,9 @@ def test_region_that_goes_out_of_bounds(self):
105
132
core_target = self .dbg .CreateTarget (None )
106
133
core_process = core_target .LoadCore (new_minidump_path )
107
134
108
- error = lldb .SBError ()
109
- core_process .ReadMemory (begin , 0x00000020 , error )
110
- self .assertTrue (error .Success (), error .GetCString ())
111
-
112
- # Whole region should be unavailable
113
- core_process .ReadMemory (end , 1 , error )
114
- self .assertTrue (error .Fail (), error .GetCString ())
135
+ expected_address_range = AddressRange (begin , end )
136
+ expected_invalid_range = AddressRange (begin - 16 , end + 16 )
137
+ self .validate_regions_saved_correctly (core_process , expected_address_range , expected_invalid_range )
115
138
116
139
def test_region_that_starts_out_of_bounds (self ):
117
140
"""
@@ -137,6 +160,6 @@ def test_region_that_starts_out_of_bounds(self):
137
160
core_target = self .dbg .CreateTarget (None )
138
161
core_process = core_target .LoadCore (new_minidump_path )
139
162
140
- error = lldb . SBError ( )
141
- core_process . ReadMemory (begin , 0x00000020 , error )
142
- self .assertTrue ( error . Success (), error . GetCString () )
163
+ expected_address_range = AddressRange ( begin , end )
164
+ expected_invalid_range = AddressRange (begin - 16 , end )
165
+ self .validate_regions_saved_correctly ( core_process , expected_address_range , expected_invalid_range )
0 commit comments