[LLDB][SBSaveCore] Implement a selectable threadlist for Core Options… · llvm/llvm-project@3e4af61 (original) (raw)

`@@ -69,10 +69,9 @@ Status MinidumpFileBuilder::AddHeaderAndCalculateDirectories() {

`

69

69

` m_expected_directories += 9;

`

70

70

``

71

71

`// Go through all of the threads and check for exceptions.

`

72

``

`-

lldb_private::ThreadList thread_list = m_process_sp->GetThreadList();

`

73

``

`-

const uint32_t num_threads = thread_list.GetSize();

`

74

``

`-

for (uint32_t thread_idx = 0; thread_idx < num_threads; ++thread_idx) {

`

75

``

`-

ThreadSP thread_sp(thread_list.GetThreadAtIndex(thread_idx));

`

``

72

`+

std::vectorlldb::ThreadSP threads =

`

``

73

`+

m_process_sp->CalculateCoreFileThreadList(m_save_core_options);

`

``

74

`+

for (const ThreadSP &thread_sp : threads) {

`

76

75

` StopInfoSP stop_info_sp = thread_sp->GetStopInfo();

`

77

76

`if (stop_info_sp) {

`

78

77

`const StopReason &stop_reason = stop_info_sp->GetStopReason();

`

`@@ -588,12 +587,13 @@ Status MinidumpFileBuilder::FixThreadStacks() {

`

588

587

``

589

588

`Status MinidumpFileBuilder::AddThreadList() {

`

590

589

`constexpr size_t minidump_thread_size = sizeof(llvm::minidump::Thread);

`

591

``

`-

lldb_private::ThreadList thread_list = m_process_sp->GetThreadList();

`

``

590

`+

std::vector thread_list =

`

``

591

`+

m_process_sp->CalculateCoreFileThreadList(m_save_core_options);

`

592

592

``

593

593

`// size of the entire thread stream consists of:

`

594

594

`// number of threads and threads array

`

595

595

`size_t thread_stream_size = sizeof(llvm::support::ulittle32_t) +

`

596

``

`-

thread_list.GetSize() * minidump_thread_size;

`

``

596

`+

thread_list.size() * minidump_thread_size;

`

597

597

`// save for the ability to set up RVA

`

598

598

`size_t size_before = GetCurrentDataEndOffset();

`

599

599

` Status error;

`

`@@ -602,17 +602,15 @@ Status MinidumpFileBuilder::AddThreadList() {

`

602

602

`return error;

`

603

603

``

604

604

` llvm::support::ulittle32_t thread_count =

`

605

``

`-

static_castllvm::support::ulittle32_t(thread_list.GetSize());

`

``

605

`+

static_castllvm::support::ulittle32_t(thread_list.size());

`

606

606

` m_data.AppendData(&thread_count, sizeof(llvm::support::ulittle32_t));

`

607

607

``

608

608

`// Take the offset after the thread count.

`

609

609

` m_thread_list_start = GetCurrentDataEndOffset();

`

610

610

` DataBufferHeap helper_data;

`

611

611

``

612

``

`-

const uint32_t num_threads = thread_list.GetSize();

`

613

612

` Log *log = GetLog(LLDBLog::Object);

`

614

``

`-

for (uint32_t thread_idx = 0; thread_idx < num_threads; ++thread_idx) {

`

615

``

`-

ThreadSP thread_sp(thread_list.GetThreadAtIndex(thread_idx));

`

``

613

`+

for (const ThreadSP &thread_sp : thread_list) {

`

616

614

` RegisterContextSP reg_ctx_sp(thread_sp->GetRegisterContext());

`

617

615

``

618

616

`if (!reg_ctx_sp) {

`

`@@ -650,7 +648,7 @@ Status MinidumpFileBuilder::AddThreadList() {

`

650

648

` m_tid_to_reg_ctx[thread_sp->GetID()] = thread_context_memory_locator;

`

651

649

``

652

650

`LLDB_LOGF(log, "AddThreadList for thread %d: thread_context %zu bytes",

`

653

``

`-

thread_idx, thread_context.size());

`

``

651

`+

thread_sp->GetIndexID(), thread_context.size());

`

654

652

` helper_data.AppendData(thread_context.data(), thread_context.size());

`

655

653

``

656

654

` llvm::minidump::Thread t;

`

`@@ -674,11 +672,10 @@ Status MinidumpFileBuilder::AddThreadList() {

`

674

672

`}

`

675

673

``

676

674

`Status MinidumpFileBuilder::AddExceptions() {

`

677

``

`-

lldb_private::ThreadList thread_list = m_process_sp->GetThreadList();

`

``

675

`+

std::vector thread_list =

`

``

676

`+

m_process_sp->CalculateCoreFileThreadList(m_save_core_options);

`

678

677

` Status error;

`

679

``

`-

const uint32_t num_threads = thread_list.GetSize();

`

680

``

`-

for (uint32_t thread_idx = 0; thread_idx < num_threads; ++thread_idx) {

`

681

``

`-

ThreadSP thread_sp(thread_list.GetThreadAtIndex(thread_idx));

`

``

678

`+

for (const ThreadSP &thread_sp : thread_list) {

`

682

679

` StopInfoSP stop_info_sp = thread_sp->GetStopInfo();

`

683

680

`bool add_exception = false;

`

684

681

`if (stop_info_sp) {

`

`@@ -819,7 +816,7 @@ Status MinidumpFileBuilder::AddLinuxFileStreams() {

`

819

816

`return error;

`

820

817

`}

`

821

818

``

822

``

`-

Status MinidumpFileBuilder::AddMemoryList(SaveCoreStyle core_style) {

`

``

819

`+

Status MinidumpFileBuilder::AddMemoryList() {

`

823

820

` Status error;

`

824

821

``

825

822

`// We first save the thread stacks to ensure they fit in the first UINT32_MAX

`

`@@ -828,18 +825,26 @@ Status MinidumpFileBuilder::AddMemoryList(SaveCoreStyle core_style) {

`

828

825

`// in accessible with a 32 bit offset.

`

829

826

` Process::CoreFileMemoryRanges ranges_32;

`

830

827

` Process::CoreFileMemoryRanges ranges_64;

`

831

``

`-

error = m_process_sp->CalculateCoreFileSaveRanges(

`

832

``

`-

SaveCoreStyle::eSaveCoreStackOnly, ranges_32);

`

``

828

`+

Process::CoreFileMemoryRanges all_core_memory_ranges;

`

``

829

`+

error = m_process_sp->CalculateCoreFileSaveRanges(m_save_core_options,

`

``

830

`+

all_core_memory_ranges);

`

833

831

`if (error.Fail())

`

834

832

`return error;

`

835

833

``

836

``

`-

// Calculate totalsize including the current offset.

`

``

834

`+

// Start by saving all of the stacks and ensuring they fit under the 32b

`

``

835

`+

// limit.

`

837

836

`uint64_t total_size = GetCurrentDataEndOffset();

`

838

``

`-

total_size += ranges_32.size() * sizeof(llvm::minidump::MemoryDescriptor);

`

839

``

`-

std::unordered_set stack_start_addresses;

`

840

``

`-

for (const auto &core_range : ranges_32) {

`

841

``

`-

stack_start_addresses.insert(core_range.range.start());

`

842

``

`-

total_size += core_range.range.size();

`

``

837

`+

auto iterator = all_core_memory_ranges.begin();

`

``

838

`+

while (iterator != all_core_memory_ranges.end()) {

`

``

839

`+

if (m_saved_stack_ranges.count(iterator->range.start()) > 0) {

`

``

840

`+

// We don't save stacks twice.

`

``

841

`+

ranges_32.push_back(*iterator);

`

``

842

`+

total_size +=

`

``

843

`+

iterator->range.size() + sizeof(llvm::minidump::MemoryDescriptor);

`

``

844

`+

iterator = all_core_memory_ranges.erase(iterator);

`

``

845

`+

} else {

`

``

846

`+

iterator++;

`

``

847

`+

}

`

843

848

` }

`

844

849

``

845

850

`if (total_size >= UINT32_MAX) {

`

`@@ -849,31 +854,20 @@ Status MinidumpFileBuilder::AddMemoryList(SaveCoreStyle core_style) {

`

849

854

`return error;

`

850

855

` }

`

851

856

``

852

``

`-

Process::CoreFileMemoryRanges all_core_memory_ranges;

`

853

``

`-

if (core_style != SaveCoreStyle::eSaveCoreStackOnly) {

`

854

``

`-

error = m_process_sp->CalculateCoreFileSaveRanges(core_style,

`

855

``

`-

all_core_memory_ranges);

`

856

``

`-

if (error.Fail())

`

857

``

`-

return error;

`

858

``

`-

}

`

859

``

-

860

857

`// After saving the stacks, we start packing as much as we can into 32b.

`

861

858

`// We apply a generous padding here so that the Directory, MemoryList and

`

862

859

`// Memory64List sections all begin in 32b addressable space.

`

863

860

`// Then anything overflow extends into 64b addressable space.

`

864

861

`// All core memeroy ranges will either container nothing on stacks only

`

865

862

`// or all the memory ranges including stacks

`

866

863

`if (!all_core_memory_ranges.empty())

`

867

``

`-

total_size +=

`

868

``

`-

256 + (all_core_memory_ranges.size() - stack_start_addresses.size()) *

`

869

``

`-

sizeof(llvm::minidump::MemoryDescriptor_64);

`

``

864

`+

total_size += 256 + (all_core_memory_ranges.size() *

`

``

865

`+

sizeof(llvm::minidump::MemoryDescriptor_64));

`

870

866

``

871

867

`for (const auto &core_range : all_core_memory_ranges) {

`

872

868

`const addr_t range_size = core_range.range.size();

`

873

``

`-

if (stack_start_addresses.count(core_range.range.start()) > 0)

`

874

``

`-

// Don't double save stacks.

`

875

``

`-

continue;

`

876

``

-

``

869

`+

// We don't need to check for stacks here because we already removed them

`

``

870

`+

// from all_core_memory_ranges.

`

877

871

`if (total_size + range_size < UINT32_MAX) {

`

878

872

` ranges_32.push_back(core_range);

`

879

873

` total_size += range_size;

`