forked from OSchip/llvm-project
[lldb-mi] Re-implement target-select command
Now target-select uses SB API instead of HandleCommand. This patch has been reviewed along with the r339175. Differential Revision: https://reviews.llvm.org/D49739 llvm-svn: 339178
This commit is contained in:
parent
e7ce247dd7
commit
65bd2f6c85
|
@ -56,7 +56,10 @@ config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable', '
|
|||
# Register substitutions
|
||||
config.substitutions.append(('%python', "'%s'" % (config.python_executable)))
|
||||
|
||||
debugserver = lit.util.which('debugserver', lldb_tools_dir)
|
||||
if platform.system() in ['Darwin']:
|
||||
debugserver = lit.util.which('debugserver', lldb_tools_dir)
|
||||
else:
|
||||
debugserver = lit.util.which('lldb-server', lldb_tools_dir)
|
||||
lldb = "%s -S %s/lit-lldb-init" % (lit.util.which('lldb', lldb_tools_dir),
|
||||
config.test_source_root)
|
||||
|
||||
|
@ -91,7 +94,10 @@ config.substitutions.append(('%lldbmi', lldbmi + " --synchronous"))
|
|||
config.substitutions.append(('%lldb', lldb))
|
||||
|
||||
if debugserver is not None:
|
||||
config.substitutions.append(('%debugserver', debugserver))
|
||||
if platform.system() in ['Darwin']:
|
||||
config.substitutions.append(('%debugserver', debugserver))
|
||||
else:
|
||||
config.substitutions.append(('%debugserver', debugserver + ' gdbserver'))
|
||||
|
||||
for pattern in [r"\bFileCheck\b",
|
||||
r"\blldb-test\b",
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
int main(void) {
|
||||
int x = 0;
|
||||
return x;
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
#!/usr/bin/env python2
|
||||
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
|
||||
hostname = 'localhost'
|
||||
|
||||
(r, w) = os.pipe()
|
||||
args = sys.argv
|
||||
# Get debugserver, lldb-mi and FileCheck executables' paths with arguments.
|
||||
debugserver = ' '.join([args[1], '--pipe', str(w), hostname + ':0'])
|
||||
lldbmi = args[2]
|
||||
test_file = args[3]
|
||||
filecheck = 'FileCheck ' + test_file
|
||||
|
||||
# Run debugserver, lldb-mi and FileCheck.
|
||||
debugserver_proc = subprocess.Popen(debugserver.split())
|
||||
lldbmi_proc = subprocess.Popen(lldbmi, stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE, shell=True)
|
||||
filecheck_proc = subprocess.Popen(filecheck, stdin=lldbmi_proc.stdout,
|
||||
shell=True)
|
||||
|
||||
# Get a tcp port chosen by debugserver.
|
||||
# The number quite big to get lldb-server's output and to not hang.
|
||||
bytes_to_read = 10
|
||||
port_bytes = os.read(r, bytes_to_read)
|
||||
port = str(port_bytes.decode('utf-8').strip('\x00'))
|
||||
|
||||
with open(test_file, 'r') as f:
|
||||
# Replace '$PORT' with a free port number and pass
|
||||
# test's content to lldb-mi.
|
||||
lldbmi_proc.stdin.write(f.read().replace('$PORT', port))
|
||||
lldbmi_proc.wait()
|
||||
filecheck_proc.wait()
|
||||
|
||||
debugserver_proc.kill()
|
||||
exit(filecheck_proc.returncode)
|
|
@ -0,0 +1 @@
|
|||
config.suffixes = ['.test']
|
|
@ -0,0 +1,25 @@
|
|||
# UNSUPPORTED: windows
|
||||
#
|
||||
# RUN: %cc -o %t %p/inputs/main.c -g
|
||||
# RUN: python %p/inputs/target-select-so-path.py "%debugserver" "%lldbmi %t" %s
|
||||
|
||||
# Test that -target-select command can hook up a path
|
||||
# added by gdb-set solib-search-path.
|
||||
|
||||
# Check that we have a valid target created via file-exec-and-symbols.
|
||||
# CHECK: ^done
|
||||
|
||||
-interpreter-exec console "target modules search-paths list"
|
||||
# CHECK ^done
|
||||
|
||||
-gdb-set solib-search-path /example/dir
|
||||
# CHECK: ^done
|
||||
|
||||
-target-select remote localhost:$PORT
|
||||
# CHECK: ^connected
|
||||
|
||||
-interpreter-exec console "target modules search-paths list"
|
||||
# CHECK: ~"[0] \".\" -> \"/example/dir\"\n"
|
||||
# CHECK-NEXT: ^done
|
||||
|
||||
-gdb-exit
|
|
@ -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();
|
||||
rSessionInfo.m_constStrSharedDataSolibPath, strSolibPath))
|
||||
target.AppendImageSearchPath(".", strSolibPath.c_str(), error);
|
||||
|
||||
CMIUtilString strCmdString = CMIUtilString::Format(
|
||||
"target modules search-paths add . %s", strSolibPath.c_str());
|
||||
|
||||
lldb::SBCommandReturnObject retObj;
|
||||
cmdIterpreter.HandleCommand(strCmdString.c_str(), retObj, false);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
//++
|
||||
|
|
Loading…
Reference in New Issue