File tree Expand file tree Collapse file tree 6 files changed +64
-0
lines changed
test/API/python_api/sbsavecoreoptions Expand file tree Collapse file tree 6 files changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -119,6 +119,19 @@ class LLDB_API SBSaveCoreOptions {
119
119
// / an empty collection will be returned.
120
120
SBThreadCollection GetThreadsToSave () const ;
121
121
122
+ // / Get the current total number of bytes the core is expected to be but not
123
+ // / including the overhead of the core file format. Requires a Process and
124
+ // / Style to be specified.
125
+ // /
126
+ // / \note
127
+ // / This can cause some modification of the underlying data store
128
+ // / as regions with no permissions, or invalid permissions will be removed
129
+ // / and stacks will be minified up to their stack pointer + the redzone.
130
+ // /
131
+ // / \returns
132
+ // / The expected size of the data contained in the core in bytes.
133
+ uint64_t GetCurrentSizeInBytes (SBError &error);
134
+
122
135
// / Reset all options.
123
136
void Clear ();
124
137
Original file line number Diff line number Diff line change @@ -49,6 +49,8 @@ class SaveCoreOptions {
49
49
50
50
lldb_private::ThreadCollection::collection GetThreadsToSave () const ;
51
51
52
+ uint64_t GetCurrentSizeInBytes (Status &error);
53
+
52
54
void Clear ();
53
55
54
56
private:
Original file line number Diff line number Diff line change @@ -114,6 +114,11 @@ void SBSaveCoreOptions::Clear() {
114
114
m_opaque_up->Clear ();
115
115
}
116
116
117
+ uint64_t SBSaveCoreOptions::GetCurrentSizeInBytes (SBError &error) {
118
+ LLDB_INSTRUMENT_VA (this , error);
119
+ return m_opaque_up->GetCurrentSizeInBytes (error.ref ());
120
+ }
121
+
117
122
lldb_private::SaveCoreOptions &SBSaveCoreOptions::ref () const {
118
123
return *m_opaque_up.get ();
119
124
}
Original file line number Diff line number Diff line change @@ -145,6 +145,24 @@ SaveCoreOptions::GetThreadsToSave() const {
145
145
return thread_collection;
146
146
}
147
147
148
+ uint64_t SaveCoreOptions::GetCurrentSizeInBytes (Status &error) {
149
+ if (!m_process_sp) {
150
+ error = Status::FromErrorString (" Requires a process to be set." );
151
+ return 0 ;
152
+ }
153
+
154
+ CoreFileMemoryRanges ranges;
155
+ error = m_process_sp->CalculateCoreFileSaveRanges (*this , ranges);
156
+ if (error.Fail ())
157
+ return 0 ;
158
+
159
+ uint64_t total_in_bytes = 0 ;
160
+ for (auto & core_range : ranges)
161
+ total_in_bytes += core_range.data .range .size ();
162
+
163
+ return total_in_bytes;
164
+ }
165
+
148
166
void SaveCoreOptions::ClearProcessSpecificData () {
149
167
// Deliberately not following the formatter style here to indicate that
150
168
// this method will be expanded in the future.
Original file line number Diff line number Diff line change @@ -104,3 +104,24 @@ def test_removing_and_adding_insertion_order(self):
104
104
thread_collection = options .GetThreadsToSave ()
105
105
self .assertEqual (thread_collection .GetSize (), 3 )
106
106
self .assertIn (middle_thread , thread_collection )
107
+
108
+ def test_get_total_in_bytes (self ):
109
+ """
110
+ Tests that get total in bytes properly returns an error without a process,
111
+ and the readable regions with a process.
112
+ """
113
+
114
+ options = lldb .SBSaveCoreOptions ()
115
+ options .SetStyle (lldb .eSaveCoreCustomOnly )
116
+ process = self .get_basic_process ()
117
+ memory_range = lldb .SBMemoryRegionInfo ()
118
+ process .GetMemoryRegionInfo (0x7FFF12A84030 , memory_range )
119
+ options .AddMemoryRegionToSave (memory_range )
120
+ error = lldb .SBError ()
121
+ total = options .GetCurrentSizeInBytes (error )
122
+ self .assertTrue (error .Fail (), error .GetCString ())
123
+ options .SetProcess (process )
124
+ total = options .GetCurrentSizeInBytes (error )
125
+ self .assertTrue (error .Success (), error .GetCString ())
126
+ expected_size = memory_range .GetRegionEnd () - memory_range .GetRegionBase ()
127
+ self .assertEqual (total , expected_size )
Original file line number Diff line number Diff line change @@ -34,3 +34,8 @@ Streams:
34
34
Stack :
35
35
Start of Memory Range : 0x00007FFFC8DFF000
36
36
Content : ' BAADBEEF'
37
+ - Type : Memory64List
38
+ Memory Ranges :
39
+ - Start of Memory Range : 0x7FFF12A84030
40
+ Data Size : 0x2FD0
41
+ Content : ' '
You can’t perform that action at this time.
0 commit comments