[lldb-vscode] Report an error if an invalid program is specified.

Previously if an invalid program was specified, there was a bug
which, when we attempted to launch the program, would report that
the operation succeeded, causing LLDB to then hang while waiting
indefinitely to receive some events from the process.

After this patch, when an invalid program is specified, we immediately
return to vs code with an error message that indicates that the
program can not be found.

Differential Revision: https://reviews.llvm.org/D59114

llvm-svn: 355656
This commit is contained in:
Zachary Turner 2019-03-08 00:11:27 +00:00
parent 5ed14ef1e4
commit 7e89b3cc17
2 changed files with 95 additions and 88 deletions

View File

@ -2519,7 +2519,11 @@ Status Process::Launch(ProcessLaunchInfo &launch_info) {
m_process_input_reader.reset();
Module *exe_module = GetTarget().GetExecutableModulePointer();
if (exe_module) {
if (!exe_module) {
error.SetErrorString("executable module does not exist");
return error;
}
char local_exec_file_path[PATH_MAX];
char platform_exec_file_path[PATH_MAX];
exe_module->GetFileSpec().GetPath(local_exec_file_path,
@ -2562,8 +2566,8 @@ Status Process::Launch(ProcessLaunchInfo &launch_info) {
} else {
EventSP event_sp;
// Now wait for the process to launch and return control to us, and then call
// DidLaunch:
// Now wait for the process to launch and return control to us, and then
// call DidLaunch:
StateType state = WaitForProcessStopPrivate(event_sp, seconds(10));
if (state == eStateInvalid || !event_sp) {
@ -2620,7 +2624,7 @@ Status Process::Launch(ProcessLaunchInfo &launch_info) {
error.SetErrorStringWithFormat("file doesn't exist: '%s'",
local_exec_file_path);
}
}
return error;
}

View File

@ -1227,20 +1227,23 @@ void request_launch(const llvm::json::Object &request) {
// Grab the name of the program we need to debug and set it as the first
// argument that will be passed to the program we will debug.
const auto program = GetString(arguments, "program");
llvm::StringRef program = GetString(arguments, "program");
if (!program.empty()) {
lldb::SBFileSpec program_fspec(program.data(), true /*resolve_path*/);
g_vsc.launch_info.SetExecutableFile(program_fspec,
true /*add_as_first_arg*/);
const char *target_triple = nullptr;
const char *uuid_cstr = nullptr;
// Stand alone debug info file if different from executable
const char *symfile = nullptr;
g_vsc.target.AddModule(program.data(), target_triple, uuid_cstr, symfile);
if (error.Fail()) {
lldb::SBModule module = g_vsc.target.AddModule(
program.data(), target_triple, uuid_cstr, symfile);
if (!module.IsValid()) {
response["success"] = llvm::json::Value(false);
EmplaceSafeString(response, "message", std::string(error.GetCString()));
EmplaceSafeString(
response, "message",
llvm::formatv("Could not load program '{0}'.", program).str());
g_vsc.SendJSON(llvm::json::Value(std::move(response)));
}
}