[Lldb-commits] [lldb] r155266 - in /lldb/branches/lldb-platform-work: include/lldb/Target/Platform.h source/Commands/CommandObjectPlatform.cpp source/Plugins/Platform/POSIX/PlatformPOSIX.cpp source/Plugins/Platform/POSIX/PlatformPOSIX.h source/Target/Platform.cpp
Enrico Granata
egranata at apple.com
Fri Apr 20 18:08:05 PDT 2012
Author: enrico
Date: Fri Apr 20 20:08:05 2012
New Revision: 155266
URL: http://llvm.org/viewvc/llvm-project?rev=155266&view=rev
Log:
Enabling a --timeout (-t) option for 'platform shell' that allows the user to specify how many seconds they want to wait for the remote command to execute
Modified:
lldb/branches/lldb-platform-work/include/lldb/Target/Platform.h
lldb/branches/lldb-platform-work/source/Commands/CommandObjectPlatform.cpp
lldb/branches/lldb-platform-work/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
lldb/branches/lldb-platform-work/source/Plugins/Platform/POSIX/PlatformPOSIX.h
lldb/branches/lldb-platform-work/source/Target/Platform.cpp
Modified: lldb/branches/lldb-platform-work/include/lldb/Target/Platform.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/include/lldb/Target/Platform.h?rev=155266&r1=155265&r2=155266&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/include/lldb/Target/Platform.h (original)
+++ lldb/branches/lldb-platform-work/include/lldb/Target/Platform.h Fri Apr 20 20:08:05 2012
@@ -452,9 +452,6 @@
}
virtual uint32_t
- RunShellCommand (const std::string &command_line);
-
- virtual uint32_t
MakeDirectory (const std::string &path,
mode_t mode)
{
Modified: lldb/branches/lldb-platform-work/source/Commands/CommandObjectPlatform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Commands/CommandObjectPlatform.cpp?rev=155266&r1=155265&r2=155266&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Commands/CommandObjectPlatform.cpp (original)
+++ lldb/branches/lldb-platform-work/source/Commands/CommandObjectPlatform.cpp Fri Apr 20 20:08:05 2012
@@ -1877,12 +1877,78 @@
class CommandObjectPlatformShell : public CommandObject
{
public:
+
+ class CommandOptions : public Options
+ {
+ public:
+
+ CommandOptions (CommandInterpreter &interpreter) :
+ Options(interpreter)
+ {
+ }
+
+ virtual
+ ~CommandOptions ()
+ {
+ }
+
+ virtual uint32_t
+ GetNumDefinitions ()
+ {
+ return 1;
+ }
+
+ virtual const OptionDefinition*
+ GetDefinitions ()
+ {
+ return g_option_table;
+ }
+
+ virtual Error
+ SetOptionValue (uint32_t option_idx,
+ const char *option_value)
+ {
+ Error error;
+
+ const char short_option = (char) g_option_table[option_idx].short_option;
+
+ switch (short_option)
+ {
+ case 't':
+ {
+ bool success;
+ timeout = Args::StringToUInt32(option_value, 10, 10, &success);
+ if (!success)
+ error.SetErrorStringWithFormat("could not convert \"%s\" to a numeric value.", option_value);
+ break;
+ }
+ default:
+ error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
+ break;
+ }
+
+ return error;
+ }
+
+ virtual void
+ OptionParsingStarting ()
+ {
+ timeout = 10;
+ }
+
+ // Options table: Required for subclasses of Options.
+
+ static OptionDefinition g_option_table[];
+ uint32_t timeout;
+ };
+
CommandObjectPlatformShell (CommandInterpreter &interpreter) :
CommandObject (interpreter,
"platform shell",
"Run a shell command on a the selected platform.",
"platform shell <shell-command>",
- 0)
+ 0),
+ m_options(interpreter)
{
}
@@ -1891,6 +1957,13 @@
{
}
+ virtual
+ Options *
+ GetOptions ()
+ {
+ return &m_options;
+ }
+
virtual bool
Execute (Args& command,
CommandReturnObject &result)
@@ -1904,6 +1977,40 @@
bool
ExecuteRawCommandString (const char *raw_command_line, CommandReturnObject &result)
{
+ const char* expr = NULL;
+ if (raw_command_line[0] == '-')
+ {
+ // We have some options and these options MUST end with --.
+ const char *end_options = NULL;
+ const char *s = raw_command_line;
+ while (s && s[0])
+ {
+ end_options = ::strstr (s, "--");
+ if (end_options)
+ {
+ end_options += 2; // Get past the "--"
+ if (::isspace (end_options[0]))
+ {
+ expr = end_options;
+ while (::isspace (*expr))
+ ++expr;
+ break;
+ }
+ }
+ s = end_options;
+ }
+
+ if (end_options)
+ {
+ Args args (raw_command_line, end_options - raw_command_line);
+ if (!ParseOptions (args, result))
+ return false;
+ }
+ }
+
+ if (expr == NULL)
+ expr = raw_command_line;
+
PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
Error error;
if (platform_sp)
@@ -1912,7 +2019,7 @@
std::string output;
int status = -1;
int signo = -1;
- error = (platform_sp->RunShellCommand (raw_command_line, working_dir, &status, &signo, &output, 10));
+ error = (platform_sp->RunShellCommand (expr, working_dir, &status, &signo, &output, m_options.timeout));
if (!output.empty())
result.GetOutputStream().PutCString(output.c_str());
if (status > 0)
@@ -1948,6 +2055,13 @@
}
protected:
+ CommandOptions m_options;
+};
+
+OptionDefinition
+CommandObjectPlatformShell::CommandOptions::g_option_table[] =
+{
+ { LLDB_OPT_SET_ALL, false, "timeout", 't', required_argument, NULL, 0, eArgTypeValue, "Seconds to wait for the remote host to finish running the command."},
};
struct RecurseCopyBaton
Modified: lldb/branches/lldb-platform-work/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp?rev=155266&r1=155265&r2=155266&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp (original)
+++ lldb/branches/lldb-platform-work/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp Fri Apr 20 20:08:05 2012
@@ -75,41 +75,6 @@
}
uint32_t
-PlatformPOSIX::RunShellCommand (const std::string &command_line)
-{
- if (IsHost())
- {
- int retcode;
- Host::RunShellCommand(command_line.c_str(),
- NULL,
- &retcode,
- NULL,
- NULL,
- 60);
- return retcode;
- }
- if (IsRemote())
- {
- if (GetSupportsSSH())
- {
- // run the command over SSH
- StreamString command;
- command.Printf("ssh %s %s %s",
- GetSSHOpts(),
- GetHostname(),
- command_line.c_str());
- return m_remote_platform_sp->RunShellCommand(command.GetData());
- }
- else if (m_remote_platform_sp)
- {
- // plain run the command
- return m_remote_platform_sp->RunShellCommand(command_line);
- }
- }
- return Platform::RunShellCommand(command_line);
-}
-
-uint32_t
PlatformPOSIX::MakeDirectory (const std::string &path,
mode_t mode)
{
@@ -193,7 +158,14 @@
if (gid != UINT32_MAX)
command.Printf(":%d",gid);
command.Printf("%s",path);
- return platform->RunShellCommand(command.GetData());
+ int status;
+ platform->RunShellCommand(command.GetData(),
+ NULL,
+ &status,
+ NULL,
+ NULL,
+ 10);
+ return status;
}
lldb_private::Error
@@ -217,7 +189,14 @@
return Error("unable to get file path for destination");
StreamString command;
command.Printf("cp %s %s", src_path.c_str(), dst_path.c_str());
- if (RunShellCommand(command.GetData()) != 0)
+ int status;
+ RunShellCommand(command.GetData(),
+ NULL,
+ &status,
+ NULL,
+ NULL,
+ 10);
+ if (status != 0)
return Error("unable to perform copy");
if (uid == UINT32_MAX && gid == UINT32_MAX)
return Error();
@@ -343,7 +322,14 @@
// cp src dst
StreamString cp_command;
cp_command.Printf("cp %s %s", src_path.c_str(), dst_path.c_str());
- if (RunShellCommand(cp_command.GetData()) != 0)
+ int status;
+ RunShellCommand(cp_command.GetData(),
+ NULL,
+ &status,
+ NULL,
+ NULL,
+ 10);
+ if (status != 0)
return Error("unable to perform copy");
return Error();
}
Modified: lldb/branches/lldb-platform-work/source/Plugins/Platform/POSIX/PlatformPOSIX.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Plugins/Platform/POSIX/PlatformPOSIX.h?rev=155266&r1=155265&r2=155266&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Platform/POSIX/PlatformPOSIX.h (original)
+++ lldb/branches/lldb-platform-work/source/Plugins/Platform/POSIX/PlatformPOSIX.h Fri Apr 20 20:08:05 2012
@@ -63,9 +63,6 @@
GetFile (const lldb_private::FileSpec& source,
const lldb_private::FileSpec& destination);
- virtual uint32_t
- RunShellCommand (const std::string &command_line);
-
virtual lldb_private::Error
RunShellCommand (const char *command, // Shouldn't be NULL
const char *working_dir, // Pass NULL to use the current working directory
Modified: lldb/branches/lldb-platform-work/source/Target/Platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Target/Platform.cpp?rev=155266&r1=155265&r2=155266&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Target/Platform.cpp (original)
+++ lldb/branches/lldb-platform-work/source/Target/Platform.cpp Fri Apr 20 20:08:05 2012
@@ -709,16 +709,6 @@
return false;
}
-uint32_t
-Platform::RunShellCommand (const std::string &command_line)
-{
- int status;
- Error err = RunShellCommand(command_line.c_str(), NULL, &status, NULL, NULL, 10);
- if (err.Fail())
- return UINT32_MAX;
- return status;
-}
-
lldb_private::Error
Platform::RunShellCommand (const char *command, // Shouldn't be NULL
const char *working_dir, // Pass NULL to use the current working directory
More information about the lldb-commits
mailing list