Skip to content

Commit accf5c9

Browse files
authored
Revert "[LLDB][SBSaveCore] Implement a selectable threadlist for Core… (#102018)
… Options. (#100443)" This reverts commit 3e4af61. @adrian-prantl FYI Reverts #100443
1 parent 0319711 commit accf5c9

File tree

18 files changed

+65
-395
lines changed

18 files changed

+65
-395
lines changed

lldb/include/lldb/API/SBProcess.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,6 @@ class LLDB_API SBProcess {
586586
friend class SBBreakpointCallbackBaton;
587587
friend class SBBreakpointLocation;
588588
friend class SBCommandInterpreter;
589-
friend class SBSaveCoreOptions;
590589
friend class SBDebugger;
591590
friend class SBExecutionContext;
592591
friend class SBFunction;

lldb/include/lldb/API/SBSaveCoreOptions.h

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
#define LLDB_API_SBSAVECOREOPTIONS_H
1111

1212
#include "lldb/API/SBDefines.h"
13-
#include "lldb/API/SBError.h"
14-
#include "lldb/API/SBFileSpec.h"
15-
#include "lldb/API/SBProcess.h"
16-
#include "lldb/API/SBThread.h"
1713

1814
namespace lldb {
1915

@@ -57,29 +53,6 @@ class LLDB_API SBSaveCoreOptions {
5753
/// \return The output file spec.
5854
SBFileSpec GetOutputFile() const;
5955

60-
/// Set the process to save, or unset if supplied with a default constructed
61-
/// process.
62-
///
63-
/// \param process The process to save.
64-
/// \return Success if process was set, otherwise an error
65-
/// \note This will clear all process specific options if a different process
66-
/// is specified than the current set process, either explicitly from this
67-
/// api, or implicitly from any function that requires a process.
68-
SBError SetProcess(lldb::SBProcess process);
69-
70-
/// Add a thread to save in the core file.
71-
///
72-
/// \param thread The thread to save.
73-
/// \note This will set the process if it is not already set, or return
74-
/// and error if the SBThread is not from the set process.
75-
SBError AddThread(lldb::SBThread thread);
76-
77-
/// Remove a thread from the list of threads to save.
78-
///
79-
/// \param thread The thread to remove.
80-
/// \return True if the thread was removed, false if it was not in the list.
81-
bool RemoveThread(lldb::SBThread thread);
82-
8356
/// Reset all options.
8457
void Clear();
8558

lldb/include/lldb/API/SBThread.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ class LLDB_API SBThread {
233233
friend class SBBreakpoint;
234234
friend class SBBreakpointLocation;
235235
friend class SBBreakpointCallbackBaton;
236-
friend class SBSaveCoreOptions;
237236
friend class SBExecutionContext;
238237
friend class SBFrame;
239238
friend class SBProcess;
@@ -254,8 +253,6 @@ class LLDB_API SBThread {
254253
SBError ResumeNewPlan(lldb_private::ExecutionContext &exe_ctx,
255254
lldb_private::ThreadPlan *new_plan);
256255

257-
lldb::ThreadSP GetSP() const;
258-
259256
lldb::ExecutionContextRefSP m_opaque_sp;
260257

261258
lldb_private::Thread *operator->();

lldb/include/lldb/Symbol/SaveCoreOptions.h

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
#include <optional>
1717
#include <string>
18-
#include <unordered_set>
1918

2019
namespace lldb_private {
2120

@@ -33,25 +32,13 @@ class SaveCoreOptions {
3332
void SetOutputFile(lldb_private::FileSpec file);
3433
const std::optional<lldb_private::FileSpec> GetOutputFile() const;
3534

36-
Status SetProcess(lldb::ProcessSP process_sp);
37-
38-
Status AddThread(lldb::ThreadSP thread_sp);
39-
bool RemoveThread(lldb::ThreadSP thread_sp);
40-
bool ShouldThreadBeSaved(lldb::tid_t tid) const;
41-
42-
Status EnsureValidConfiguration(lldb::ProcessSP process_sp) const;
43-
4435
void Clear();
4536

4637
private:
47-
void ClearProcessSpecificData();
48-
4938
std::optional<std::string> m_plugin_name;
5039
std::optional<lldb_private::FileSpec> m_file;
5140
std::optional<lldb::SaveCoreStyle> m_style;
52-
lldb::ProcessSP m_process_sp;
53-
std::unordered_set<lldb::tid_t> m_threads_to_save;
5441
};
5542
} // namespace lldb_private
5643

57-
#endif // LLDB_SOURCE_PLUGINS_OBJECTFILE_SAVECOREOPTIONS_H
44+
#endif // LLDB_SOURCE_PLUGINS_OBJECTFILE_SaveCoreOPTIONS_H

lldb/include/lldb/Target/Process.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -738,15 +738,9 @@ class Process : public std::enable_shared_from_this<Process>,
738738
/// Helper function for Process::SaveCore(...) that calculates the address
739739
/// ranges that should be saved. This allows all core file plug-ins to save
740740
/// consistent memory ranges given a \a core_style.
741-
Status CalculateCoreFileSaveRanges(const SaveCoreOptions &core_options,
741+
Status CalculateCoreFileSaveRanges(lldb::SaveCoreStyle core_style,
742742
CoreFileMemoryRanges &ranges);
743743

744-
/// Helper function for Process::SaveCore(...) that calculates the thread list
745-
/// based upon options set within a given \a core_options object.
746-
/// \note If there is no thread list defined, all threads will be saved.
747-
std::vector<lldb::ThreadSP>
748-
CalculateCoreFileThreadList(const SaveCoreOptions &core_options);
749-
750744
protected:
751745
virtual JITLoaderList &GetJITLoaders();
752746

lldb/source/API/SBSaveCoreOptions.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "lldb/API/SBSaveCoreOptions.h"
10+
#include "lldb/API/SBError.h"
11+
#include "lldb/API/SBFileSpec.h"
1012
#include "lldb/Host/FileSystem.h"
1113
#include "lldb/Symbol/SaveCoreOptions.h"
1214
#include "lldb/Utility/Instrumentation.h"
@@ -73,21 +75,6 @@ lldb::SaveCoreStyle SBSaveCoreOptions::GetStyle() const {
7375
return m_opaque_up->GetStyle();
7476
}
7577

76-
SBError SBSaveCoreOptions::SetProcess(lldb::SBProcess process) {
77-
LLDB_INSTRUMENT_VA(this, process);
78-
return m_opaque_up->SetProcess(process.GetSP());
79-
}
80-
81-
SBError SBSaveCoreOptions::AddThread(lldb::SBThread thread) {
82-
LLDB_INSTRUMENT_VA(this, thread);
83-
return m_opaque_up->AddThread(thread.GetSP());
84-
}
85-
86-
bool SBSaveCoreOptions::RemoveThread(lldb::SBThread thread) {
87-
LLDB_INSTRUMENT_VA(this, thread);
88-
return m_opaque_up->RemoveThread(thread.GetSP());
89-
}
90-
9178
void SBSaveCoreOptions::Clear() {
9279
LLDB_INSTRUMENT_VA(this);
9380
m_opaque_up->Clear();

lldb/source/API/SBThread.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,8 +1331,6 @@ bool SBThread::SafeToCallFunctions() {
13311331
return true;
13321332
}
13331333

1334-
lldb::ThreadSP SBThread::GetSP() const { return m_opaque_sp->GetThreadSP(); }
1335-
13361334
lldb_private::Thread *SBThread::operator->() {
13371335
return get();
13381336
}

lldb/source/Core/PluginManager.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -714,10 +714,6 @@ Status PluginManager::SaveCore(const lldb::ProcessSP &process_sp,
714714
return error;
715715
}
716716

717-
error = options.EnsureValidConfiguration(process_sp);
718-
if (error.Fail())
719-
return error;
720-
721717
if (!options.GetPluginName().has_value()) {
722718
// Try saving core directly from the process plugin first.
723719
llvm::Expected<bool> ret =

lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6347,24 +6347,22 @@ struct segment_vmaddr {
63476347
// are some multiple passes over the image list while calculating
63486348
// everything.
63496349

6350-
static offset_t
6351-
CreateAllImageInfosPayload(const lldb::ProcessSP &process_sp,
6352-
offset_t initial_file_offset,
6353-
StreamString &all_image_infos_payload,
6354-
const lldb_private::SaveCoreOptions &options) {
6350+
static offset_t CreateAllImageInfosPayload(
6351+
const lldb::ProcessSP &process_sp, offset_t initial_file_offset,
6352+
StreamString &all_image_infos_payload, SaveCoreStyle core_style) {
63556353
Target &target = process_sp->GetTarget();
63566354
ModuleList modules = target.GetImages();
63576355

63586356
// stack-only corefiles have no reason to include binaries that
63596357
// are not executing; we're trying to make the smallest corefile
63606358
// we can, so leave the rest out.
6361-
if (options.GetStyle() == SaveCoreStyle::eSaveCoreStackOnly)
6359+
if (core_style == SaveCoreStyle::eSaveCoreStackOnly)
63626360
modules.Clear();
63636361

63646362
std::set<std::string> executing_uuids;
6365-
std::vector<ThreadSP> thread_list =
6366-
process_sp->CalculateCoreFileThreadList(options);
6367-
for (const ThreadSP &thread_sp : thread_list) {
6363+
ThreadList &thread_list(process_sp->GetThreadList());
6364+
for (uint32_t i = 0; i < thread_list.GetSize(); i++) {
6365+
ThreadSP thread_sp = thread_list.GetThreadAtIndex(i);
63686366
uint32_t stack_frame_count = thread_sp->GetStackFrameCount();
63696367
for (uint32_t j = 0; j < stack_frame_count; j++) {
63706368
StackFrameSP stack_frame_sp = thread_sp->GetStackFrameAtIndex(j);
@@ -6561,7 +6559,7 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
65616559

65626560
if (make_core) {
65636561
Process::CoreFileMemoryRanges core_ranges;
6564-
error = process_sp->CalculateCoreFileSaveRanges(options, core_ranges);
6562+
error = process_sp->CalculateCoreFileSaveRanges(core_style, core_ranges);
65656563
if (error.Success()) {
65666564
const uint32_t addr_byte_size = target_arch.GetAddressByteSize();
65676565
const ByteOrder byte_order = target_arch.GetByteOrder();
@@ -6732,8 +6730,8 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
67326730
std::make_shared<StructuredData::Dictionary>());
67336731
StructuredData::ArraySP threads(
67346732
std::make_shared<StructuredData::Array>());
6735-
for (const ThreadSP &thread_sp :
6736-
process_sp->CalculateCoreFileThreadList(options)) {
6733+
for (uint32_t thread_idx = 0; thread_idx < num_threads; ++thread_idx) {
6734+
ThreadSP thread_sp(thread_list.GetThreadAtIndex(thread_idx));
67376735
StructuredData::DictionarySP thread(
67386736
std::make_shared<StructuredData::Dictionary>());
67396737
thread->AddIntegerItem("thread_id", thread_sp->GetID());
@@ -6756,7 +6754,7 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
67566754
all_image_infos_lcnote_up->payload_file_offset = file_offset;
67576755
file_offset = CreateAllImageInfosPayload(
67586756
process_sp, file_offset, all_image_infos_lcnote_up->payload,
6759-
options);
6757+
core_style);
67606758
lc_notes.push_back(std::move(all_image_infos_lcnote_up));
67616759

67626760
// Add LC_NOTE load commands

lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ Status MinidumpFileBuilder::AddHeaderAndCalculateDirectories() {
6969
m_expected_directories += 9;
7070

7171
// Go through all of the threads and check for exceptions.
72-
std::vector<lldb::ThreadSP> threads =
73-
m_process_sp->CalculateCoreFileThreadList(m_save_core_options);
74-
for (const ThreadSP &thread_sp : threads) {
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));
7576
StopInfoSP stop_info_sp = thread_sp->GetStopInfo();
7677
if (stop_info_sp) {
7778
const StopReason &stop_reason = stop_info_sp->GetStopReason();
@@ -587,13 +588,12 @@ Status MinidumpFileBuilder::FixThreadStacks() {
587588

588589
Status MinidumpFileBuilder::AddThreadList() {
589590
constexpr size_t minidump_thread_size = sizeof(llvm::minidump::Thread);
590-
std::vector<ThreadSP> thread_list =
591-
m_process_sp->CalculateCoreFileThreadList(m_save_core_options);
591+
lldb_private::ThreadList thread_list = m_process_sp->GetThreadList();
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.size() * minidump_thread_size;
596+
thread_list.GetSize() * minidump_thread_size;
597597
// save for the ability to set up RVA
598598
size_t size_before = GetCurrentDataEndOffset();
599599
Status error;
@@ -602,15 +602,17 @@ Status MinidumpFileBuilder::AddThreadList() {
602602
return error;
603603

604604
llvm::support::ulittle32_t thread_count =
605-
static_cast<llvm::support::ulittle32_t>(thread_list.size());
605+
static_cast<llvm::support::ulittle32_t>(thread_list.GetSize());
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();
612613
Log *log = GetLog(LLDBLog::Object);
613-
for (const ThreadSP &thread_sp : thread_list) {
614+
for (uint32_t thread_idx = 0; thread_idx < num_threads; ++thread_idx) {
615+
ThreadSP thread_sp(thread_list.GetThreadAtIndex(thread_idx));
614616
RegisterContextSP reg_ctx_sp(thread_sp->GetRegisterContext());
615617

616618
if (!reg_ctx_sp) {
@@ -648,7 +650,7 @@ Status MinidumpFileBuilder::AddThreadList() {
648650
m_tid_to_reg_ctx[thread_sp->GetID()] = thread_context_memory_locator;
649651

650652
LLDB_LOGF(log, "AddThreadList for thread %d: thread_context %zu bytes",
651-
thread_sp->GetIndexID(), thread_context.size());
653+
thread_idx, thread_context.size());
652654
helper_data.AppendData(thread_context.data(), thread_context.size());
653655

654656
llvm::minidump::Thread t;
@@ -672,10 +674,11 @@ Status MinidumpFileBuilder::AddThreadList() {
672674
}
673675

674676
Status MinidumpFileBuilder::AddExceptions() {
675-
std::vector<ThreadSP> thread_list =
676-
m_process_sp->CalculateCoreFileThreadList(m_save_core_options);
677+
lldb_private::ThreadList thread_list = m_process_sp->GetThreadList();
677678
Status error;
678-
for (const ThreadSP &thread_sp : thread_list) {
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));
679682
StopInfoSP stop_info_sp = thread_sp->GetStopInfo();
680683
bool add_exception = false;
681684
if (stop_info_sp) {
@@ -816,7 +819,7 @@ Status MinidumpFileBuilder::AddLinuxFileStreams() {
816819
return error;
817820
}
818821

819-
Status MinidumpFileBuilder::AddMemoryList() {
822+
Status MinidumpFileBuilder::AddMemoryList(SaveCoreStyle core_style) {
820823
Status error;
821824

822825
// We first save the thread stacks to ensure they fit in the first UINT32_MAX
@@ -825,26 +828,18 @@ Status MinidumpFileBuilder::AddMemoryList() {
825828
// in accessible with a 32 bit offset.
826829
Process::CoreFileMemoryRanges ranges_32;
827830
Process::CoreFileMemoryRanges ranges_64;
828-
Process::CoreFileMemoryRanges all_core_memory_ranges;
829-
error = m_process_sp->CalculateCoreFileSaveRanges(m_save_core_options,
830-
all_core_memory_ranges);
831+
error = m_process_sp->CalculateCoreFileSaveRanges(
832+
SaveCoreStyle::eSaveCoreStackOnly, ranges_32);
831833
if (error.Fail())
832834
return error;
833835

834-
// Start by saving all of the stacks and ensuring they fit under the 32b
835-
// limit.
836+
// Calculate totalsize including the current offset.
836837
uint64_t total_size = GetCurrentDataEndOffset();
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-
}
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();
848843
}
849844

850845
if (total_size >= UINT32_MAX) {
@@ -854,20 +849,31 @@ Status MinidumpFileBuilder::AddMemoryList() {
854849
return error;
855850
}
856851

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+
857860
// After saving the stacks, we start packing as much as we can into 32b.
858861
// We apply a generous padding here so that the Directory, MemoryList and
859862
// Memory64List sections all begin in 32b addressable space.
860863
// Then anything overflow extends into 64b addressable space.
861864
// All core memeroy ranges will either container nothing on stacks only
862865
// or all the memory ranges including stacks
863866
if (!all_core_memory_ranges.empty())
864-
total_size += 256 + (all_core_memory_ranges.size() *
865-
sizeof(llvm::minidump::MemoryDescriptor_64));
867+
total_size +=
868+
256 + (all_core_memory_ranges.size() - stack_start_addresses.size()) *
869+
sizeof(llvm::minidump::MemoryDescriptor_64);
866870

867871
for (const auto &core_range : all_core_memory_ranges) {
868872
const addr_t range_size = core_range.range.size();
869-
// We don't need to check for stacks here because we already removed them
870-
// from all_core_memory_ranges.
873+
if (stack_start_addresses.count(core_range.range.start()) > 0)
874+
// Don't double save stacks.
875+
continue;
876+
871877
if (total_size + range_size < UINT32_MAX) {
872878
ranges_32.push_back(core_range);
873879
total_size += range_size;

0 commit comments

Comments
 (0)