Skip to content

[lldb] Turn lldb_private::Status into a value type. #106163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions lldb/bindings/python/python-wrapper.swig
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,11 @@ PythonObject lldb_private::python::SWIGBridge::LLDBSwigPythonCreateScriptedStopH
const char *session_dictionary_name, const StructuredDataImpl &args_impl,
Status &error) {
if (python_class_name == NULL || python_class_name[0] == '\0') {
error.SetErrorString("Empty class name.");
error = Status::FromErrorString("Empty class name.");
return PythonObject();
}
if (!session_dictionary_name) {
error.SetErrorString("No session dictionary");
error = Status::FromErrorString("No session dictionary");
return PythonObject();
}

Expand All @@ -322,7 +322,7 @@ PythonObject lldb_private::python::SWIGBridge::LLDBSwigPythonCreateScriptedStopH
python_class_name, dict);

if (!pfunc.IsAllocated()) {
error.SetErrorStringWithFormat("Could not find class: %s.",
error = Status::FromErrorStringWithFormat("Could not find class: %s.",
python_class_name);
return PythonObject();
}
Expand All @@ -337,23 +337,25 @@ PythonObject lldb_private::python::SWIGBridge::LLDBSwigPythonCreateScriptedStopH
if (auto args_info = callback_func.GetArgInfo()) {
size_t num_args = (*args_info).max_positional_args;
if (num_args != 2) {
error.SetErrorStringWithFormat(
error = Status::FromErrorStringWithFormat(
"Wrong number of args for "
"handle_stop callback, should be 2 (excluding self), got: %zu",
num_args);
return PythonObject();
} else
return result;
} else {
error.SetErrorString("Couldn't get num arguments for handle_stop "
"callback.");
error = Status::FromErrorString(
"Couldn't get num arguments for handle_stop "
"callback.");
return PythonObject();
}
return result;
} else {
error.SetErrorStringWithFormat("Class \"%s\" is missing the required "
"handle_stop callback.",
python_class_name);
error = Status::FromErrorStringWithFormat(
"Class \"%s\" is missing the required "
"handle_stop callback.",
python_class_name);
}
}
return PythonObject();
Expand Down
28 changes: 9 additions & 19 deletions lldb/include/lldb/Core/StructuredDataImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,38 +50,28 @@ class StructuredDataImpl {
}

Status GetAsJSON(Stream &stream) const {
Status error;

if (!m_data_sp) {
error.SetErrorString("No structured data.");
return error;
}
if (!m_data_sp)
return Status::FromErrorString("No structured data.");

llvm::json::OStream s(stream.AsRawOstream());
m_data_sp->Serialize(s);
return error;
return Status();
}

Status GetDescription(Stream &stream) const {
Status error;

if (!m_data_sp) {
error.SetErrorString("Cannot pretty print structured data: "
"no data to print.");
return error;
}
if (!m_data_sp)
return Status::FromErrorString("Cannot pretty print structured data: "
"no data to print.");

// Grab the plugin
lldb::StructuredDataPluginSP plugin_sp = m_plugin_wp.lock();

// If there's no plugin, call underlying data's dump method:
if (!plugin_sp) {
if (!m_data_sp) {
error.SetErrorString("No data to describe.");
return error;
}
if (!m_data_sp)
return Status::FromErrorString("No data to describe.");
m_data_sp->GetDescription(stream);
return error;
return Status();
}
// Get the data's description.
return plugin_sp->GetDescription(m_data_sp, stream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ScriptedInterface {
llvm::Twine(llvm::Twine(" (") + llvm::Twine(detailed_error) +
llvm::Twine(")"))
.str();
error.SetErrorString(full_error_message);
error = Status(std::move(full_error_message));
return {};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,18 @@ class ScriptedPlatformInterface : virtual public ScriptedInterface {
}

virtual Status AttachToProcess(lldb::ProcessAttachInfoSP attach_info) {
return Status("ScriptedPlatformInterface cannot attach to a process");
return Status::FromErrorString(
"ScriptedPlatformInterface cannot attach to a process");
}

virtual Status LaunchProcess(lldb::ProcessLaunchInfoSP launch_info) {
return Status("ScriptedPlatformInterface cannot launch process");
return Status::FromErrorString(
"ScriptedPlatformInterface cannot launch process");
}

virtual Status KillProcess(lldb::pid_t pid) {
return Status("ScriptedPlatformInterface cannot kill process");
return Status::FromErrorString(
"ScriptedPlatformInterface cannot kill process");
}
};
} // namespace lldb_private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,28 @@ class ScriptedProcessInterface : virtual public ScriptedInterface {
virtual StructuredData::DictionarySP GetCapabilities() { return {}; }

virtual Status Attach(const ProcessAttachInfo &attach_info) {
return Status("ScriptedProcess did not attach");
return Status::FromErrorString("ScriptedProcess did not attach");
}

virtual Status Launch() { return Status("ScriptedProcess did not launch"); }
virtual Status Launch() {
return Status::FromErrorString("ScriptedProcess did not launch");
}

virtual Status Resume() { return Status("ScriptedProcess did not resume"); }
virtual Status Resume() {
return Status::FromErrorString("ScriptedProcess did not resume");
}

virtual std::optional<MemoryRegionInfo>
GetMemoryRegionContainingAddress(lldb::addr_t address, Status &error) {
error.SetErrorString("ScriptedProcess have no memory region.");
error = Status::FromErrorString("ScriptedProcess have no memory region.");
return {};
}

virtual StructuredData::DictionarySP GetThreadsInfo() { return {}; }

virtual bool CreateBreakpoint(lldb::addr_t addr, Status &error) {
error.SetErrorString("ScriptedProcess don't support creating breakpoints.");
error = Status::FromErrorString(
"ScriptedProcess don't support creating breakpoints.");
return {};
}

Expand Down
3 changes: 2 additions & 1 deletion lldb/include/lldb/Interpreter/OptionValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ class OptionValue {
virtual lldb::OptionValueSP GetSubValue(const ExecutionContext *exe_ctx,
llvm::StringRef name,
Status &error) const {
error.SetErrorStringWithFormatv("'{0}' is not a valid subvalue", name);
error = Status::FromErrorStringWithFormatv("'{0}' is not a valid subvalue",
name);
return lldb::OptionValueSP();
}

Expand Down
43 changes: 15 additions & 28 deletions lldb/include/lldb/Interpreter/ScriptInterpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,25 +176,19 @@ class ScriptInterpreter : public PluginInterface {
virtual Status ExecuteMultipleLines(
const char *in_string,
const ExecuteScriptOptions &options = ExecuteScriptOptions()) {
Status error;
error.SetErrorString("not implemented");
return error;
return Status::FromErrorString("not implemented");
}

virtual Status
ExportFunctionDefinitionToInterpreter(StringList &function_def) {
Status error;
error.SetErrorString("not implemented");
return error;
return Status::FromErrorString("not implemented");
}

virtual Status GenerateBreakpointCommandCallbackData(StringList &input,
std::string &output,
bool has_extra_args,
bool is_callback) {
Status error;
error.SetErrorString("not implemented");
return error;
return Status::FromErrorString("not implemented");
}

virtual bool GenerateWatchpointCommandCallbackData(StringList &input,
Expand Down Expand Up @@ -280,8 +274,9 @@ class ScriptInterpreter : public PluginInterface {
virtual StructuredData::GenericSP
CreateScriptedStopHook(lldb::TargetSP target_sp, const char *class_name,
const StructuredDataImpl &args_data, Status &error) {
error.SetErrorString("Creating scripted stop-hooks with the current "
"script interpreter is not supported.");
error =
Status::FromErrorString("Creating scripted stop-hooks with the current "
"script interpreter is not supported.");
return StructuredData::GenericSP();
}

Expand All @@ -308,9 +303,7 @@ class ScriptInterpreter : public PluginInterface {
virtual Status GenerateFunction(const char *signature,
const StringList &input,
bool is_callback) {
Status error;
error.SetErrorString("unimplemented");
return error;
return Status::FromErrorString("not implemented");
}

virtual void CollectDataForBreakpointCommandCallback(
Expand All @@ -329,18 +322,14 @@ class ScriptInterpreter : public PluginInterface {
virtual Status SetBreakpointCommandCallback(BreakpointOptions &bp_options,
const char *callback_text,
bool is_callback) {
Status error;
error.SetErrorString("unimplemented");
return error;
return Status::FromErrorString("not implemented");
}

/// This one is for deserialization:
virtual Status SetBreakpointCommandCallback(
BreakpointOptions &bp_options,
std::unique_ptr<BreakpointOptions::CommandData> &data_up) {
Status error;
error.SetErrorString("unimplemented");
return error;
return Status::FromErrorString("not implemented");
}

Status SetBreakpointCommandCallbackFunction(
Expand All @@ -352,9 +341,7 @@ class ScriptInterpreter : public PluginInterface {
SetBreakpointCommandCallbackFunction(BreakpointOptions &bp_options,
const char *function_name,
StructuredData::ObjectSP extra_args_sp) {
Status error;
error.SetErrorString("unimplemented");
return error;
return Status::FromErrorString("not implemented");
}

/// Set a one-liner as the callback for the watchpoint.
Expand Down Expand Up @@ -453,33 +440,33 @@ class ScriptInterpreter : public PluginInterface {
virtual bool RunScriptFormatKeyword(const char *impl_function,
Process *process, std::string &output,
Status &error) {
error.SetErrorString("unimplemented");
error = Status::FromErrorString("unimplemented");
return false;
}

virtual bool RunScriptFormatKeyword(const char *impl_function, Thread *thread,
std::string &output, Status &error) {
error.SetErrorString("unimplemented");
error = Status::FromErrorString("unimplemented");
return false;
}

virtual bool RunScriptFormatKeyword(const char *impl_function, Target *target,
std::string &output, Status &error) {
error.SetErrorString("unimplemented");
error = Status::FromErrorString("unimplemented");
return false;
}

virtual bool RunScriptFormatKeyword(const char *impl_function,
StackFrame *frame, std::string &output,
Status &error) {
error.SetErrorString("unimplemented");
error = Status::FromErrorString("unimplemented");
return false;
}

virtual bool RunScriptFormatKeyword(const char *impl_function,
ValueObject *value, std::string &output,
Status &error) {
error.SetErrorString("unimplemented");
error = Status::FromErrorString("unimplemented");
return false;
}

Expand Down
Loading
Loading