diff options
Diffstat (limited to 'lldb/source/Commands')
-rw-r--r-- | lldb/source/Commands/CommandObjectProcess.cpp | 1 | ||||
-rw-r--r-- | lldb/source/Commands/CommandObjectTarget.cpp | 210 |
2 files changed, 103 insertions, 108 deletions
diff --git a/lldb/source/Commands/CommandObjectProcess.cpp b/lldb/source/Commands/CommandObjectProcess.cpp index 5ef0b87..1eef280 100644 --- a/lldb/source/Commands/CommandObjectProcess.cpp +++ b/lldb/source/Commands/CommandObjectProcess.cpp @@ -364,7 +364,6 @@ protected: result.AppendError(error.AsCString("Error creating target")); return false; } - GetDebugger().GetTargetList().SetSelectedTarget(target); } // Record the old executable module, we want to issue a warning if the diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp index eba129c..c033493 100644 --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/lldb/source/Commands/CommandObjectTarget.cpp @@ -50,6 +50,7 @@ #include "lldb/Utility/State.h" #include "lldb/Utility/Timer.h" +#include "llvm/ADT/ScopeExit.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/FormatAdapters.h" @@ -318,123 +319,124 @@ protected: m_add_dependents.m_load_dependent_files, &m_platform_options, target_sp)); - if (target_sp) { - // Only get the platform after we create the target because we might - // have switched platforms depending on what the arguments were to - // CreateTarget() we can't rely on the selected platform. - - PlatformSP platform_sp = target_sp->GetPlatform(); - - if (remote_file) { - if (platform_sp) { - // I have a remote file.. two possible cases - if (file_spec && FileSystem::Instance().Exists(file_spec)) { - // if the remote file does not exist, push it there - if (!platform_sp->GetFileExists(remote_file)) { - Status err = platform_sp->PutFile(file_spec, remote_file); - if (err.Fail()) { - result.AppendError(err.AsCString()); - result.SetStatus(eReturnStatusFailed); - return false; - } - } - } else { - // there is no local file and we need one - // in order to make the remote ---> local transfer we need a - // platform - // TODO: if the user has passed in a --platform argument, use it - // to fetch the right platform - if (!platform_sp) { - result.AppendError( - "unable to perform remote debugging without a platform"); + if (!target_sp) { + result.AppendError(error.AsCString()); + result.SetStatus(eReturnStatusFailed); + return false; + } + + auto on_error = llvm::make_scope_exit( + [&target_list = debugger.GetTargetList(), &target_sp]() { + target_list.DeleteTarget(target_sp); + }); + + // Only get the platform after we create the target because we might + // have switched platforms depending on what the arguments were to + // CreateTarget() we can't rely on the selected platform. + + PlatformSP platform_sp = target_sp->GetPlatform(); + + if (remote_file) { + if (platform_sp) { + // I have a remote file.. two possible cases + if (file_spec && FileSystem::Instance().Exists(file_spec)) { + // if the remote file does not exist, push it there + if (!platform_sp->GetFileExists(remote_file)) { + Status err = platform_sp->PutFile(file_spec, remote_file); + if (err.Fail()) { + result.AppendError(err.AsCString()); result.SetStatus(eReturnStatusFailed); return false; } - if (file_path) { - // copy the remote file to the local file - Status err = platform_sp->GetFile(remote_file, file_spec); - if (err.Fail()) { - result.AppendError(err.AsCString()); - result.SetStatus(eReturnStatusFailed); - return false; - } - } else { - // make up a local file - result.AppendError("remote --> local transfer without local " - "path is not implemented yet"); + } + } else { + // there is no local file and we need one + // in order to make the remote ---> local transfer we need a + // platform + // TODO: if the user has passed in a --platform argument, use it + // to fetch the right platform + if (file_path) { + // copy the remote file to the local file + Status err = platform_sp->GetFile(remote_file, file_spec); + if (err.Fail()) { + result.AppendError(err.AsCString()); result.SetStatus(eReturnStatusFailed); return false; } + } else { + // make up a local file + result.AppendError("remote --> local transfer without local " + "path is not implemented yet"); + result.SetStatus(eReturnStatusFailed); + return false; } - } else { - result.AppendError("no platform found for target"); - result.SetStatus(eReturnStatusFailed); - return false; } + } else { + result.AppendError("no platform found for target"); + result.SetStatus(eReturnStatusFailed); + return false; } + } - if (symfile || remote_file) { - ModuleSP module_sp(target_sp->GetExecutableModule()); - if (module_sp) { - if (symfile) - module_sp->SetSymbolFileFileSpec(symfile); - if (remote_file) { - std::string remote_path = remote_file.GetPath(); - target_sp->SetArg0(remote_path.c_str()); - module_sp->SetPlatformFileSpec(remote_file); - } + if (symfile || remote_file) { + ModuleSP module_sp(target_sp->GetExecutableModule()); + if (module_sp) { + if (symfile) + module_sp->SetSymbolFileFileSpec(symfile); + if (remote_file) { + std::string remote_path = remote_file.GetPath(); + target_sp->SetArg0(remote_path.c_str()); + module_sp->SetPlatformFileSpec(remote_file); } } + } - debugger.GetTargetList().SetSelectedTarget(target_sp.get()); - if (must_set_platform_path) { - ModuleSpec main_module_spec(file_spec); - ModuleSP module_sp = - target_sp->GetOrCreateModule(main_module_spec, true /* notify */); - if (module_sp) - module_sp->SetPlatformFileSpec(remote_file); - } + if (must_set_platform_path) { + ModuleSpec main_module_spec(file_spec); + ModuleSP module_sp = + target_sp->GetOrCreateModule(main_module_spec, true /* notify */); + if (module_sp) + module_sp->SetPlatformFileSpec(remote_file); + } - if (core_file) { - FileSpec core_file_dir; - core_file_dir.GetDirectory() = core_file.GetDirectory(); - target_sp->AppendExecutableSearchPaths(core_file_dir); + if (core_file) { + FileSpec core_file_dir; + core_file_dir.GetDirectory() = core_file.GetDirectory(); + target_sp->AppendExecutableSearchPaths(core_file_dir); - ProcessSP process_sp(target_sp->CreateProcess( - GetDebugger().GetListener(), llvm::StringRef(), &core_file, - false)); + ProcessSP process_sp(target_sp->CreateProcess( + GetDebugger().GetListener(), llvm::StringRef(), &core_file, false)); - if (process_sp) { - // Seems weird that we Launch a core file, but that is what we - // do! - error = process_sp->LoadCore(); + if (process_sp) { + // Seems weird that we Launch a core file, but that is what we + // do! + error = process_sp->LoadCore(); - if (error.Fail()) { - result.AppendError( - error.AsCString("can't find plug-in for core file")); - result.SetStatus(eReturnStatusFailed); - return false; - } else { - result.AppendMessageWithFormatv("Core file '{0}' ({1}) was loaded.\n", core_file.GetPath(), - target_sp->GetArchitecture().GetArchitectureName()); - result.SetStatus(eReturnStatusSuccessFinishNoResult); - } - } else { - result.AppendErrorWithFormatv( - "Unable to find process plug-in for core file '{0}'\n", - core_file.GetPath()); + if (error.Fail()) { + result.AppendError( + error.AsCString("can't find plug-in for core file")); result.SetStatus(eReturnStatusFailed); + return false; + } else { + result.AppendMessageWithFormatv( + "Core file '{0}' ({1}) was loaded.\n", core_file.GetPath(), + target_sp->GetArchitecture().GetArchitectureName()); + result.SetStatus(eReturnStatusSuccessFinishNoResult); + on_error.release(); } } else { - result.AppendMessageWithFormat( - "Current executable set to '%s' (%s).\n", - file_spec.GetPath().c_str(), - target_sp->GetArchitecture().GetArchitectureName()); - result.SetStatus(eReturnStatusSuccessFinishNoResult); + result.AppendErrorWithFormatv( + "Unable to find process plug-in for core file '{0}'\n", + core_file.GetPath()); + result.SetStatus(eReturnStatusFailed); } } else { - result.AppendError(error.AsCString()); - result.SetStatus(eReturnStatusFailed); + result.AppendMessageWithFormat( + "Current executable set to '%s' (%s).\n", + file_spec.GetPath().c_str(), + target_sp->GetArchitecture().GetArchitectureName()); + result.SetStatus(eReturnStatusSuccessFinishNoResult); + on_error.release(); } } else { result.AppendErrorWithFormat("'%s' takes exactly one executable path " @@ -442,6 +444,7 @@ protected: m_cmd_name.c_str()); result.SetStatus(eReturnStatusFailed); } + return result.Succeeded(); } @@ -507,18 +510,11 @@ protected: TargetList &target_list = GetDebugger().GetTargetList(); const uint32_t num_targets = target_list.GetNumTargets(); if (target_idx < num_targets) { - TargetSP target_sp(target_list.GetTargetAtIndex(target_idx)); - if (target_sp) { - Stream &strm = result.GetOutputStream(); - target_list.SetSelectedTarget(target_sp.get()); - bool show_stopped_process_status = false; - DumpTargetList(target_list, show_stopped_process_status, strm); - result.SetStatus(eReturnStatusSuccessFinishResult); - } else { - result.AppendErrorWithFormat("target #%u is NULL in target list\n", - target_idx); - result.SetStatus(eReturnStatusFailed); - } + target_list.SetSelectedTarget(target_idx); + Stream &strm = result.GetOutputStream(); + bool show_stopped_process_status = false; + DumpTargetList(target_list, show_stopped_process_status, strm); + result.SetStatus(eReturnStatusSuccessFinishResult); } else { if (num_targets > 0) { result.AppendErrorWithFormat( |