Skip to content

Commit c55cc1e

Browse files
committed
[lldb] add review changes
1 parent de106f4 commit c55cc1e

File tree

6 files changed

+37
-34
lines changed

6 files changed

+37
-34
lines changed

lldb/include/lldb/Interpreter/CommandOptionArgumentTable.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ static constexpr OptionEnumValueElement g_completion_type[] = {
199199
{lldb::eCustomCompletion, "custom", "Custom completion."},
200200
{lldb::eThreadIDCompletion, "thread-id", "Completes to a thread ID."},
201201
{lldb::eProcessSaveCorePluginCompletion, "plugin-name",
202-
"Completes to a process save-core plugin"},
202+
"Completes to an ObjectFile plugin that can save core files."},
203203
};
204204

205205
llvm::StringRef RegisterNameHelpTextCallback();
@@ -316,7 +316,7 @@ static constexpr CommandObject::ArgumentTableEntry g_argument_table[] = {
316316
{ lldb::eArgTypeModule, "module", lldb::CompletionType::eModuleCompletion, {}, { nullptr, false }, "The name of a module loaded into the current target." },
317317
{ lldb::eArgTypeCPUName, "cpu-name", lldb::CompletionType::eNoCompletion, {}, { nullptr, false }, "The name of a CPU." },
318318
{ lldb::eArgTypeCPUFeatures, "cpu-features", lldb::CompletionType::eNoCompletion, {}, { nullptr, false }, "The CPU feature string." },
319-
{ lldb::eArgTypeSaveCorePlugin, "plugin-name", lldb::CompletionType::eProcessSaveCorePluginCompletion, {}, { nullptr, false }, nullptr },
319+
{ lldb::eArgTypeSaveCorePlugin, "save-core-plugin-name", lldb::CompletionType::eProcessSaveCorePluginCompletion, {}, { nullptr, false }, nullptr },
320320
// clang-format on
321321
};
322322

lldb/source/Commands/CommandCompletions.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,7 @@ void CommandCompletions::ProcessNames(CommandInterpreter &interpreter,
738738
for (const ProcessInstanceInfo &info : process_infos)
739739
request.TryCompleteCurrentArg(info.GetNameAsStringRef());
740740
}
741+
741742
void CommandCompletions::ProcessSaveCorePluginNames(
742743
CommandInterpreter &interpreter, CompletionRequest &request,
743744
SearchFilter *searcher) {

lldb/source/Commands/CommandObjectProcess.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,24 +1281,25 @@ class CommandObjectProcessSaveCore : public CommandObjectParsed {
12811281
~CommandOptions() override = default;
12821282

12831283
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
1284-
if (m_opt_def.empty()) {
1285-
auto orig = llvm::ArrayRef(g_process_save_core_options);
1286-
m_opt_def.resize(orig.size());
1287-
llvm::copy(g_process_save_core_options, m_opt_def.data());
1288-
for (OptionDefinition &value : m_opt_def) {
1289-
llvm::StringRef opt_name = value.long_option;
1290-
if (opt_name != "plugin-name")
1291-
continue;
1292-
1293-
llvm::SmallVector<llvm::StringRef> plugin_names =
1294-
PluginManager::GetSaveCorePluginNames();
1295-
m_plugin_enums.resize(plugin_names.size());
1296-
for (auto [num, val] : llvm::zip(plugin_names, m_plugin_enums)) {
1297-
val.string_value = num.data();
1298-
}
1299-
value.enum_values = llvm::ArrayRef(m_plugin_enums);
1300-
break;
1284+
if (!m_opt_def.empty())
1285+
return llvm::ArrayRef(m_opt_def);
1286+
1287+
auto orig = llvm::ArrayRef(g_process_save_core_options);
1288+
m_opt_def.resize(orig.size());
1289+
llvm::copy(g_process_save_core_options, m_opt_def.data());
1290+
for (OptionDefinition &value : m_opt_def) {
1291+
llvm::StringRef opt_name = value.long_option;
1292+
if (opt_name != "plugin-name")
1293+
continue;
1294+
1295+
llvm::SmallVector<llvm::StringRef> plugin_names =
1296+
PluginManager::GetSaveCorePluginNames();
1297+
m_plugin_enums.resize(plugin_names.size());
1298+
for (auto [num, val] : llvm::zip(plugin_names, m_plugin_enums)) {
1299+
val.string_value = num.data();
13011300
}
1301+
value.enum_values = llvm::ArrayRef(m_plugin_enums);
1302+
break;
13021303
}
13031304
return llvm::ArrayRef(m_opt_def);
13041305
}

lldb/source/Commands/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ let Command = "process save_core" in {
797797
EnumArg<"SaveCoreStyle">, Desc<"Request a specific style "
798798
"of corefile to be saved.">;
799799
def process_save_core_plugin_name : Option<"plugin-name", "p">,
800-
Arg<"Plugin">, Completion<"ProcessSaveCorePlugin">,
800+
OptionalArg<"Plugin">, Completion<"ProcessSaveCorePlugin">,
801801
Desc<"Specify a plugin name to create the core file. "
802802
"This allows core files to be saved in different formats.">;
803803
}

lldb/source/Core/PluginManager.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -792,18 +792,19 @@ Status PluginManager::SaveCore(const lldb::ProcessSP &process_sp,
792792
}
793793
}
794794

795-
// report for one plugin if a name is specified.
796-
if (error.Success() && !plugin_name.empty())
797-
error = Status::FromErrorStringWithFormatv(
798-
"\"{}\" plugin is not able to save a core for this process.",
795+
// Check to see if any of the object file plugins tried and failed to save.
796+
// if any failed resturn the error message.
797+
if (error.Fail())
798+
return error;
799+
800+
// Report only for the plugin that was specified.
801+
if (!plugin_name.empty())
802+
return Status::FromErrorStringWithFormatv(
803+
"The \"{}\" plugin is not able to save a core for this process.",
799804
plugin_name);
800805

801-
// Check to see if any of the object file plugins tried and failed to save.
802-
// If none ran, set the error message.
803-
if (error.Success())
804-
error = Status::FromErrorString(
805-
"no ObjectFile plugins were able to save a core for this process");
806-
return error;
806+
return Status::FromErrorString(
807+
"no ObjectFile plugins were able to save a core for this process");
807808
}
808809

809810
llvm::SmallVector<llvm::StringRef> PluginManager::GetSaveCorePluginNames() {

lldb/source/Symbol/SaveCoreOptions.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ Status SaveCoreOptions::SetPluginName(const char *name) {
2121
return error;
2222
}
2323

24-
if (!PluginManager::IsRegisteredObjectFilePluginName(name)) {
24+
llvm::SmallVector<llvm::StringRef> plugin_names =
25+
PluginManager::GetSaveCorePluginNames();
26+
if (llvm::find(plugin_names, name) == plugin_names.end()) {
2527
StreamString stream;
2628
stream.Printf("plugin name '%s' is not a valid ObjectFile plugin name.",
2729
name);
2830

29-
llvm::SmallVector<llvm::StringRef> plugin_names =
30-
PluginManager::GetSaveCorePluginNames();
3131
if (!plugin_names.empty()) {
32-
stream.PutCString(" Valid values are: ");
32+
stream.PutCString(" Valid names are: ");
3333
std::string plugin_names_str = llvm::join(plugin_names, ", ");
3434
stream.PutCString(plugin_names_str);
3535
stream.PutChar('.');

0 commit comments

Comments
 (0)