aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectPlatform.cpp
diff options
context:
space:
mode:
authorMed Ismail Bennani <medismail.bennani@gmail.com>2020-08-28 15:38:39 +0200
committerMed Ismail Bennani <medismail.bennani@gmail.com>2020-09-02 16:36:10 +0200
commitaddb5148f58d710fcaba04bb2afec8006ae8ac15 (patch)
treeaee143185e2be542401ab16d75675572a735eaea /lldb/source/Commands/CommandObjectPlatform.cpp
parent425573a2fa2dc5666273944a584acdb286447b66 (diff)
downloadllvm-addb5148f58d710fcaba04bb2afec8006ae8ac15.zip
llvm-addb5148f58d710fcaba04bb2afec8006ae8ac15.tar.gz
llvm-addb5148f58d710fcaba04bb2afec8006ae8ac15.tar.bz2
[lldb/Target] Add custom interpreter option to `platform shell`
This patch adds the ability to use a custom interpreter with the `platform shell` command. If the user set the `-s|--shell` option with the path to a binary, lldb passes it down to the platform's `RunShellProcess` method and set it as the shell to use in `ProcessLaunchInfo to run commands. Note that not all the Platforms support running shell commands with custom interpreters (i.e. RemoteGDBServer is only expected to use the default shell). This patch also makes some refactoring and cleanups, like swapping CString for StringRef when possible and updating `SBPlatformShellCommand` with new methods and a new constructor. rdar://67759256 Differential Revision: https://reviews.llvm.org/D86667 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
Diffstat (limited to 'lldb/source/Commands/CommandObjectPlatform.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectPlatform.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp
index b5409e6..3a5af9f 100644
--- a/lldb/source/Commands/CommandObjectPlatform.cpp
+++ b/lldb/source/Commands/CommandObjectPlatform.cpp
@@ -1611,6 +1611,16 @@ public:
else
m_timeout = std::chrono::seconds(timeout_sec);
break;
+ case 's': {
+ if (option_arg.empty()) {
+ error.SetErrorStringWithFormat(
+ "missing shell interpreter path for option -i|--interpreter.");
+ return error;
+ }
+
+ m_shell_interpreter = option_arg.str();
+ break;
+ }
default:
llvm_unreachable("Unimplemented option");
}
@@ -1621,10 +1631,12 @@ public:
void OptionParsingStarting(ExecutionContext *execution_context) override {
m_timeout.reset();
m_use_host_platform = false;
+ m_shell_interpreter.clear();
}
Timeout<std::micro> m_timeout = std::chrono::seconds(10);
bool m_use_host_platform;
+ std::string m_shell_interpreter;
};
CommandObjectPlatformShell(CommandInterpreter &interpreter)
@@ -1650,7 +1662,6 @@ public:
const bool is_alias = !raw_command_line.contains("platform");
OptionsWithRaw args(raw_command_line);
- const char *expr = args.GetRawPart().c_str();
if (args.HasArgs())
if (!ParseOptions(args.GetArgs(), result))
@@ -1662,6 +1673,8 @@ public:
return false;
}
+ llvm::StringRef cmd = args.GetRawPart();
+
PlatformSP platform_sp(
m_options.m_use_host_platform
? Platform::GetHostPlatform()
@@ -1672,7 +1685,8 @@ public:
std::string output;
int status = -1;
int signo = -1;
- error = (platform_sp->RunShellCommand(expr, working_dir, &status, &signo,
+ error = (platform_sp->RunShellCommand(m_options.m_shell_interpreter, cmd,
+ working_dir, &status, &signo,
&output, m_options.m_timeout));
if (!output.empty())
result.GetOutputStream().PutCString(output);