aboutsummaryrefslogtreecommitdiff
path: root/tools/lldb-mi/MICmdCmdTarget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/lldb-mi/MICmdCmdTarget.cpp')
-rw-r--r--tools/lldb-mi/MICmdCmdTarget.cpp59
1 files changed, 18 insertions, 41 deletions
diff --git a/tools/lldb-mi/MICmdCmdTarget.cpp b/tools/lldb-mi/MICmdCmdTarget.cpp
index a82bd682de81..0666fc4c60ec 100644
--- a/tools/lldb-mi/MICmdCmdTarget.cpp
+++ b/tools/lldb-mi/MICmdCmdTarget.cpp
@@ -10,9 +10,8 @@
// Overview: CMICmdCmdTargetSelect implementation.
// Third Party Headers:
-#include "lldb/API/SBCommandInterpreter.h"
-#include "lldb/API/SBCommandReturnObject.h"
#include "lldb/API/SBStream.h"
+#include "lldb/API/SBError.h"
// In-house headers:
#include "MICmdArgValNumber.h"
@@ -52,7 +51,7 @@ CMICmdCmdTargetSelect::CMICmdCmdTargetSelect()
// Return: None.
// Throws: None.
//--
-CMICmdCmdTargetSelect::~CMICmdCmdTargetSelect() {}
+CMICmdCmdTargetSelect::~CMICmdCmdTargetSelect() = default;
//++
//------------------------------------------------------------------------------------
@@ -93,16 +92,17 @@ bool CMICmdCmdTargetSelect::Execute() {
CMICmnLLDBDebugSessionInfo &rSessionInfo(
CMICmnLLDBDebugSessionInfo::Instance());
+ lldb::SBTarget target = rSessionInfo.GetTarget();
- // Check we have a valid target
- // Note: target created via 'file-exec-and-symbols' command
- if (!rSessionInfo.GetTarget().IsValid()) {
+ // Check we have a valid target.
+ // Note: target created via 'file-exec-and-symbols' command.
+ if (!target.IsValid()) {
SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_INVALID_TARGET_CURRENT),
m_cmdData.strMiCmd.c_str()));
return MIstatus::failure;
}
- // Verify that we are executing remotely
+ // Verify that we are executing remotely.
const CMIUtilString &rRemoteType(pArgType->GetValue());
if (rRemoteType != "remote") {
SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_INVALID_TARGET_TYPE),
@@ -111,33 +111,25 @@ bool CMICmdCmdTargetSelect::Execute() {
return MIstatus::failure;
}
- // Create a URL pointing to the remote gdb stub
+ // Create a URL pointing to the remote gdb stub.
const CMIUtilString strUrl =
CMIUtilString::Format("connect://%s", pArgParameters->GetValue().c_str());
- // Ask LLDB to connect to the target port
- const char *pPlugin("gdb-remote");
lldb::SBError error;
- lldb::SBProcess process = rSessionInfo.GetTarget().ConnectRemote(
+ // Ask LLDB to connect to the target port.
+ const char *pPlugin("gdb-remote");
+ lldb::SBProcess process = target.ConnectRemote(
rSessionInfo.GetListener(), strUrl.c_str(), pPlugin, error);
- // Verify that we have managed to connect successfully
- lldb::SBStream errMsg;
- error.GetDescription(errMsg);
+ // Verify that we have managed to connect successfully.
if (!process.IsValid()) {
SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_INVALID_TARGET_PLUGIN),
m_cmdData.strMiCmd.c_str(),
- errMsg.GetData()));
- return MIstatus::failure;
- }
- if (error.Fail()) {
- SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_CONNECT_TO_TARGET),
- m_cmdData.strMiCmd.c_str(),
- errMsg.GetData()));
+ error.GetCString()));
return MIstatus::failure;
}
- // Set the environment path if we were given one
+ // Set the environment path if we were given one.
CMIUtilString strWkDir;
if (rSessionInfo.SharedDataRetrieve<CMIUtilString>(
rSessionInfo.m_constStrSharedDataKeyWkDir, strWkDir)) {
@@ -150,28 +142,13 @@ bool CMICmdCmdTargetSelect::Execute() {
}
}
- // Set the shared object path if we were given one
+ // Set the shared object path if we were given one.
CMIUtilString strSolibPath;
if (rSessionInfo.SharedDataRetrieve<CMIUtilString>(
- rSessionInfo.m_constStrSharedDataSolibPath, strSolibPath)) {
- lldb::SBDebugger &rDbgr = rSessionInfo.GetDebugger();
- lldb::SBCommandInterpreter cmdIterpreter = rDbgr.GetCommandInterpreter();
-
- CMIUtilString strCmdString = CMIUtilString::Format(
- "target modules search-paths add . %s", strSolibPath.c_str());
-
- lldb::SBCommandReturnObject retObj;
- cmdIterpreter.HandleCommand(strCmdString.c_str(), retObj, false);
+ rSessionInfo.m_constStrSharedDataSolibPath, strSolibPath))
+ target.AppendImageSearchPath(".", strSolibPath.c_str(), error);
- if (!retObj.Succeeded()) {
- SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_FNFAILED),
- m_cmdData.strMiCmd.c_str(),
- "target-select"));
- return MIstatus::failure;
- }
- }
-
- return MIstatus::success;
+ return HandleSBError(error);
}
//++