@@ -69,10 +69,9 @@ Status MinidumpFileBuilder::AddHeaderAndCalculateDirectories() {
6969 m_expected_directories += 9 ;
7070
7171 // 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::vector<lldb::ThreadSP> threads =
73+ m_process_sp->CalculateCoreFileThreadList (m_save_core_options);
74+ for (const ThreadSP &thread_sp : threads) {
7675 StopInfoSP stop_info_sp = thread_sp->GetStopInfo ();
7776 if (stop_info_sp) {
7877 const StopReason &stop_reason = stop_info_sp->GetStopReason ();
@@ -588,12 +587,13 @@ Status MinidumpFileBuilder::FixThreadStacks() {
588587
589588Status MinidumpFileBuilder::AddThreadList () {
590589 constexpr size_t minidump_thread_size = sizeof (llvm::minidump::Thread);
591- lldb_private::ThreadList thread_list = m_process_sp->GetThreadList ();
590+ std::vector<ThreadSP> thread_list =
591+ m_process_sp->CalculateCoreFileThreadList (m_save_core_options);
592592
593593 // size of the entire thread stream consists of:
594594 // number of threads and threads array
595595 size_t thread_stream_size = sizeof (llvm::support::ulittle32_t ) +
596- thread_list.GetSize () * minidump_thread_size;
596+ thread_list.size () * minidump_thread_size;
597597 // save for the ability to set up RVA
598598 size_t size_before = GetCurrentDataEndOffset ();
599599 Status error;
@@ -602,17 +602,15 @@ Status MinidumpFileBuilder::AddThreadList() {
602602 return error;
603603
604604 llvm::support::ulittle32_t thread_count =
605- static_cast <llvm::support::ulittle32_t >(thread_list.GetSize ());
605+ static_cast <llvm::support::ulittle32_t >(thread_list.size ());
606606 m_data.AppendData (&thread_count, sizeof (llvm::support::ulittle32_t ));
607607
608608 // Take the offset after the thread count.
609609 m_thread_list_start = GetCurrentDataEndOffset ();
610610 DataBufferHeap helper_data;
611611
612- const uint32_t num_threads = thread_list.GetSize ();
613612 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) {
616614 RegisterContextSP reg_ctx_sp (thread_sp->GetRegisterContext ());
617615
618616 if (!reg_ctx_sp) {
@@ -650,7 +648,7 @@ Status MinidumpFileBuilder::AddThreadList() {
650648 m_tid_to_reg_ctx[thread_sp->GetID ()] = thread_context_memory_locator;
651649
652650 LLDB_LOGF (log, " AddThreadList for thread %d: thread_context %zu bytes" ,
653- thread_idx , thread_context.size ());
651+ thread_sp-> GetIndexID () , thread_context.size ());
654652 helper_data.AppendData (thread_context.data (), thread_context.size ());
655653
656654 llvm::minidump::Thread t;
@@ -674,11 +672,10 @@ Status MinidumpFileBuilder::AddThreadList() {
674672}
675673
676674Status MinidumpFileBuilder::AddExceptions () {
677- lldb_private::ThreadList thread_list = m_process_sp->GetThreadList ();
675+ std::vector<ThreadSP> thread_list =
676+ m_process_sp->CalculateCoreFileThreadList (m_save_core_options);
678677 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) {
682679 StopInfoSP stop_info_sp = thread_sp->GetStopInfo ();
683680 bool add_exception = false ;
684681 if (stop_info_sp) {
@@ -819,7 +816,7 @@ Status MinidumpFileBuilder::AddLinuxFileStreams() {
819816 return error;
820817}
821818
822- Status MinidumpFileBuilder::AddMemoryList (SaveCoreStyle core_style ) {
819+ Status MinidumpFileBuilder::AddMemoryList () {
823820 Status error;
824821
825822 // 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) {
828825 // in accessible with a 32 bit offset.
829826 Process::CoreFileMemoryRanges ranges_32;
830827 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);
833831 if (error.Fail ())
834832 return error;
835833
836- // Calculate totalsize including the current offset.
834+ // Start by saving all of the stacks and ensuring they fit under the 32b
835+ // limit.
837836 uint64_t total_size = GetCurrentDataEndOffset ();
838- total_size += ranges_32.size () * sizeof (llvm::minidump::MemoryDescriptor);
839- std::unordered_set<addr_t > 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+ }
843848 }
844849
845850 if (total_size >= UINT32_MAX) {
@@ -849,31 +854,20 @@ Status MinidumpFileBuilder::AddMemoryList(SaveCoreStyle core_style) {
849854 return error;
850855 }
851856
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-
860857 // After saving the stacks, we start packing as much as we can into 32b.
861858 // We apply a generous padding here so that the Directory, MemoryList and
862859 // Memory64List sections all begin in 32b addressable space.
863860 // Then anything overflow extends into 64b addressable space.
864861 // All core memeroy ranges will either container nothing on stacks only
865862 // or all the memory ranges including stacks
866863 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));
870866
871867 for (const auto &core_range : all_core_memory_ranges) {
872868 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.
877871 if (total_size + range_size < UINT32_MAX) {
878872 ranges_32.push_back (core_range);
879873 total_size += range_size;
0 commit comments