Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lldb/include/lldb/API/SBSaveCoreOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ class LLDB_API SBSaveCoreOptions {
/// an empty collection will be returned.
SBThreadCollection GetThreadsToSave() const;

/// Get the current total number of bytes the core is expected to be but not
/// including the overhead of the core file format. Requires a Process and
/// Style to be specified.
///
/// \note
/// This can cause some modification of the underlying data store
/// as regions with no permissions, or invalid permissions will be removed
/// and stacks will be minified up to their stack pointer + the redzone.
///
/// \returns
/// The expected size of the data contained in the core in bytes.
uint64_t GetCurrentSizeInBytes(SBError &error);

/// Reset all options.
void Clear();

Expand Down
2 changes: 2 additions & 0 deletions lldb/include/lldb/Symbol/SaveCoreOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class SaveCoreOptions {

lldb_private::ThreadCollection::collection GetThreadsToSave() const;

uint64_t GetCurrentSizeInBytes(Status &error);

void Clear();

private:
Expand Down
5 changes: 5 additions & 0 deletions lldb/source/API/SBSaveCoreOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ void SBSaveCoreOptions::Clear() {
m_opaque_up->Clear();
}

uint64_t SBSaveCoreOptions::GetCurrentSizeInBytes(SBError &error) {
LLDB_INSTRUMENT_VA(this, error);
return m_opaque_up->GetCurrentSizeInBytes(error.ref());
}

lldb_private::SaveCoreOptions &SBSaveCoreOptions::ref() const {
return *m_opaque_up.get();
}
22 changes: 22 additions & 0 deletions lldb/source/Symbol/SaveCoreOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,28 @@ SaveCoreOptions::GetThreadsToSave() const {
return thread_collection;
}

uint64_t SaveCoreOptions::GetCurrentSizeInBytes(Status &error) {
if (!m_process_sp) {
error = Status::FromErrorString("Requires a process to be set.");
return 0;
}

error = EnsureValidConfiguration(m_process_sp);
if (error.Fail())
return 0;

CoreFileMemoryRanges ranges;
error = m_process_sp->CalculateCoreFileSaveRanges(*this, ranges);
if (error.Fail())
return 0;

uint64_t total_in_bytes = 0;
for (auto &core_range : ranges)
total_in_bytes += core_range.data.range.size();

return total_in_bytes;
}

void SaveCoreOptions::ClearProcessSpecificData() {
// Deliberately not following the formatter style here to indicate that
// this method will be expanded in the future.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,24 @@ def test_removing_and_adding_insertion_order(self):
thread_collection = options.GetThreadsToSave()
self.assertEqual(thread_collection.GetSize(), 3)
self.assertIn(middle_thread, thread_collection)

def test_get_total_in_bytes(self):
"""
Tests that get total in bytes properly returns an error without a process,
and the readable regions with a process.
"""

options = lldb.SBSaveCoreOptions()
options.SetStyle(lldb.eSaveCoreCustomOnly)
process = self.get_basic_process()
memory_range = lldb.SBMemoryRegionInfo()
process.GetMemoryRegionInfo(0x7FFF12A84030, memory_range)
options.AddMemoryRegionToSave(memory_range)
error = lldb.SBError()
total = options.GetCurrentSizeInBytes(error)
self.assertTrue(error.Fail(), error.GetCString())
options.SetProcess(process)
total = options.GetCurrentSizeInBytes(error)
self.assertTrue(error.Success(), error.GetCString())
expected_size = memory_range.GetRegionEnd() - memory_range.GetRegionBase()
self.assertEqual(total, expected_size)
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@ Streams:
Stack:
Start of Memory Range: 0x00007FFFC8DFF000
Content: 'BAADBEEF'
- Type: Memory64List
Memory Ranges:
- Start of Memory Range: 0x7FFF12A84030
Data Size: 0x2FD0
Content : ''
Loading