Skip to content

Commit efed2cc

Browse files
committed
Move check out of process plugin and into sbprocess
1 parent 829cb99 commit efed2cc

File tree

6 files changed

+27
-28
lines changed

6 files changed

+27
-28
lines changed

lldb/include/lldb/Core/PluginManager.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,7 @@ class PluginManager {
261261
static ObjectFileCreateMemoryInstance
262262
GetObjectFileCreateMemoryCallbackForPluginName(llvm::StringRef name);
263263

264-
static Status SaveCore(const lldb::ProcessSP &process_sp,
265-
lldb_private::SaveCoreOptions &core_options);
264+
static Status SaveCore(lldb_private::SaveCoreOptions &core_options);
266265

267266
static std::vector<llvm::StringRef> GetSaveCorePluginNames();
268267

lldb/include/lldb/Symbol/SaveCoreOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class SaveCoreOptions {
4444
bool ShouldThreadBeSaved(lldb::tid_t tid) const;
4545
bool HasSpecifiedThreads() const;
4646

47-
Status EnsureValidConfiguration(lldb::ProcessSP process_sp) const;
47+
Status EnsureValidConfiguration() const;
4848
const MemoryRanges &GetCoreFileMemoryRanges() const;
4949

5050
void AddMemoryRegionToSave(const lldb_private::MemoryRegionInfo &region);

lldb/source/API/SBProcess.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,15 @@ lldb::SBError SBProcess::SaveCore(SBSaveCoreOptions &options) {
12631263
return error;
12641264
}
12651265

1266+
if (!options.GetProcess())
1267+
options.SetProcess(process_sp);
1268+
1269+
if (options.GetProcess().GetSP() != process_sp) {
1270+
error = Status::FromErrorString(
1271+
"Save Core Options configured for a different process.");
1272+
return error;
1273+
}
1274+
12661275
std::lock_guard<std::recursive_mutex> guard(
12671276
process_sp->GetTarget().GetAPIMutex());
12681277

@@ -1271,7 +1280,7 @@ lldb::SBError SBProcess::SaveCore(SBSaveCoreOptions &options) {
12711280
return error;
12721281
}
12731282

1274-
error.ref() = PluginManager::SaveCore(process_sp, options.ref());
1283+
error.ref() = PluginManager::SaveCore(options.ref());
12751284

12761285
return error;
12771286
}

lldb/source/Commands/CommandObjectProcess.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1354,7 +1354,8 @@ class CommandObjectProcessSaveCore : public CommandObjectParsed {
13541354
FileSystem::Instance().Resolve(output_file);
13551355
auto &core_dump_options = m_options.m_core_dump_options;
13561356
core_dump_options.SetOutputFile(output_file);
1357-
Status error = PluginManager::SaveCore(process_sp, core_dump_options);
1357+
core_dump_options.SetProcess(process_sp);
1358+
Status error = PluginManager::SaveCore(core_dump_options);
13581359
if (error.Success()) {
13591360
if (core_dump_options.GetStyle() ==
13601361
SaveCoreStyle::eSaveCoreDirtyOnly ||

lldb/source/Core/PluginManager.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -952,37 +952,26 @@ PluginManager::GetObjectFileCreateMemoryCallbackForPluginName(
952952
return nullptr;
953953
}
954954

955-
Status PluginManager::SaveCore(const lldb::ProcessSP &process_sp,
956-
lldb_private::SaveCoreOptions &options) {
955+
Status PluginManager::SaveCore(lldb_private::SaveCoreOptions &options) {
957956
Status error;
958957
if (!options.GetOutputFile()) {
959958
error = Status::FromErrorString("No output file specified");
960959
return error;
961960
}
962961

963-
if (!process_sp) {
962+
if (!options.GetProcess()) {
964963
error = Status::FromErrorString("Invalid process");
965964
return error;
966965
}
967966

968-
if (!options.GetProcess())
969-
options.SetProcess(process_sp);
970-
971-
// Make sure the process sp is the same as the one we are using.
972-
if (options.GetProcess() != process_sp) {
973-
error = Status::FromErrorString(
974-
"Save Core Options configured for a different process.");
975-
return error;
976-
}
977-
978-
error = options.EnsureValidConfiguration(process_sp);
967+
error = options.EnsureValidConfiguration();
979968
if (error.Fail())
980969
return error;
981970

982971
if (!options.GetPluginName().has_value()) {
983972
// Try saving core directly from the process plugin first.
984973
llvm::Expected<bool> ret =
985-
process_sp->SaveCore(options.GetOutputFile()->GetPath());
974+
options.GetProcess()->SaveCore(options.GetOutputFile()->GetPath());
986975
if (!ret)
987976
return Status::FromError(ret.takeError());
988977
if (ret.get())
@@ -994,7 +983,10 @@ Status PluginManager::SaveCore(const lldb::ProcessSP &process_sp,
994983
auto instances = GetObjectFileInstances().GetSnapshot();
995984
for (auto &instance : instances) {
996985
if (plugin_name.empty() || instance.name == plugin_name) {
997-
if (instance.save_core && instance.save_core(process_sp, options, error))
986+
// TODO: Refactor the instance.save_core() to not require a process and
987+
// get it from options instead.
988+
if (instance.save_core &&
989+
instance.save_core(options.GetProcess(), options, error))
998990
return error;
999991
}
1000992
}

lldb/source/Symbol/SaveCoreOptions.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,14 @@ void SaveCoreOptions::AddMemoryRegionToSave(
124124
const MemoryRanges &SaveCoreOptions::GetCoreFileMemoryRanges() const {
125125
return m_regions_to_save;
126126
}
127-
Status
128-
SaveCoreOptions::EnsureValidConfiguration(lldb::ProcessSP process_sp) const {
127+
Status SaveCoreOptions::EnsureValidConfiguration() const {
129128
Status error;
130129
std::string error_str;
131130
if (!m_threads_to_save.empty() && GetStyle() == lldb::eSaveCoreFull)
132131
error_str += "Cannot save a full core with a subset of threads\n";
133132

134-
if (m_process_sp && m_process_sp != process_sp)
135-
error_str += "Cannot save core for process using supplied core options. "
136-
"Options were constructed targeting a different process. \n";
133+
if (!m_process_sp)
134+
error_str += "Need to assign a valid process\n";
137135

138136
if (!error_str.empty())
139137
error = Status(error_str);
@@ -161,7 +159,7 @@ SaveCoreOptions::GetMemoryRegionsToSave() {
161159
if (!m_process_sp)
162160
return Status::FromErrorString("Requires a process to be set.").takeError();
163161

164-
error = EnsureValidConfiguration(m_process_sp);
162+
error = EnsureValidConfiguration();
165163
if (error.Fail())
166164
return error.takeError();
167165

@@ -178,7 +176,7 @@ llvm::Expected<uint64_t> SaveCoreOptions::GetCurrentSizeInBytes() {
178176
if (!m_process_sp)
179177
return Status::FromErrorString("Requires a process to be set.").takeError();
180178

181-
error = EnsureValidConfiguration(m_process_sp);
179+
error = EnsureValidConfiguration();
182180
if (error.Fail())
183181
return error.takeError();
184182

0 commit comments

Comments
 (0)