aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectPlatform.cpp
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2012-04-14 01:42:46 +0000
committerGreg Clayton <gclayton@apple.com>2012-04-14 01:42:46 +0000
commitd1cf11a74df14374c8be20dd43e805d2dfb1de07 (patch)
tree8d93d9fd95aa1825bf1ae394233bee05208c16f4 /lldb/source/Commands/CommandObjectPlatform.cpp
parentf5c87882a01b733a98a0138688d2ff0c9e586848 (diff)
downloadllvm-d1cf11a74df14374c8be20dd43e805d2dfb1de07.zip
llvm-d1cf11a74df14374c8be20dd43e805d2dfb1de07.tar.gz
llvm-d1cf11a74df14374c8be20dd43e805d2dfb1de07.tar.bz2
Added a new host function that allows us to run shell command and get the output from them along with the status and signal:
Error Host::RunShellCommand (const char *command, const char *working_dir, int *status_ptr, int *signo_ptr, std::string *command_output_ptr, uint32_t timeout_sec); This will allow us to use this functionality in the host lldb_private::Platform, and also use it in our lldb-platform binary. It leverages the existing code in Host::LaunchProcess and ProcessLaunchInfo. llvm-svn: 154730
Diffstat (limited to 'lldb/source/Commands/CommandObjectPlatform.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectPlatform.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp
index 9618c6c..e4d0273 100644
--- a/lldb/source/Commands/CommandObjectPlatform.cpp
+++ b/lldb/source/Commands/CommandObjectPlatform.cpp
@@ -870,6 +870,75 @@ private:
DISALLOW_COPY_AND_ASSIGN (CommandObjectPlatformProcess);
};
+
+class CommandObjectPlatformShell : public CommandObject
+{
+public:
+ CommandObjectPlatformShell (CommandInterpreter &interpreter) :
+ CommandObject (interpreter,
+ "platform shell",
+ "Run a shell command on a the selected platform.",
+ "platform shell <shell-command>",
+ 0)
+ {
+ }
+
+ virtual
+ ~CommandObjectPlatformShell ()
+ {
+ }
+
+ virtual bool
+ Execute (Args& command,
+ CommandReturnObject &result)
+ {
+ return false;
+ }
+
+ virtual bool
+ WantsRawCommandString() { return true; }
+
+ bool
+ ExecuteRawCommandString (const char *raw_command_line, CommandReturnObject &result)
+ {
+ // TODO: Implement "Platform::RunShellCommand()" and switch over to using
+ // the current platform when it is in the interface.
+ const char *working_dir = NULL;
+ std::string output;
+ int status = -1;
+ int signo = -1;
+ Error error (Host::RunShellCommand (raw_command_line, working_dir, &status, &signo, &output, 10));
+ if (!output.empty())
+ result.GetOutputStream().PutCString(output.c_str());
+ if (status > 0)
+ {
+ if (signo > 0)
+ {
+ const char *signo_cstr = Host::GetSignalAsCString(signo);
+ if (signo_cstr)
+ result.GetOutputStream().Printf("error: command returned with status %i and signal %s\n", status, signo_cstr);
+ else
+ result.GetOutputStream().Printf("error: command returned with status %i and signal %i\n", status, signo);
+ }
+ else
+ result.GetOutputStream().Printf("error: command returned with status %i\n", status);
+ }
+
+ if (error.Fail())
+ {
+ result.AppendError(error.AsCString());
+ result.SetStatus (eReturnStatusFailed);
+ }
+ else
+ {
+ result.SetStatus (eReturnStatusSuccessFinishResult);
+ }
+ return true;
+ }
+
+protected:
+};
+
//----------------------------------------------------------------------
// CommandObjectPlatform constructor
//----------------------------------------------------------------------
@@ -885,6 +954,7 @@ CommandObjectPlatform::CommandObjectPlatform(CommandInterpreter &interpreter) :
LoadSubCommand ("connect", CommandObjectSP (new CommandObjectPlatformConnect (interpreter)));
LoadSubCommand ("disconnect", CommandObjectSP (new CommandObjectPlatformDisconnect (interpreter)));
LoadSubCommand ("process", CommandObjectSP (new CommandObjectPlatformProcess (interpreter)));
+ LoadSubCommand ("shell", CommandObjectSP (new CommandObjectPlatformShell (interpreter)));
}