diff options
Diffstat (limited to 'contrib/llvm-project/lldb/source/API/SBPlatform.cpp')
-rw-r--r-- | contrib/llvm-project/lldb/source/API/SBPlatform.cpp | 112 |
1 files changed, 74 insertions, 38 deletions
diff --git a/contrib/llvm-project/lldb/source/API/SBPlatform.cpp b/contrib/llvm-project/lldb/source/API/SBPlatform.cpp index 7ac852488ffb..f118048156b9 100644 --- a/contrib/llvm-project/lldb/source/API/SBPlatform.cpp +++ b/contrib/llvm-project/lldb/source/API/SBPlatform.cpp @@ -50,14 +50,25 @@ struct PlatformConnectOptions { // PlatformShellCommand struct PlatformShellCommand { - PlatformShellCommand(const char *shell_command = nullptr) + PlatformShellCommand(llvm::StringRef shell_interpreter, + llvm::StringRef shell_command) : m_command(), m_working_dir(), m_status(0), m_signo(0) { - if (shell_command && shell_command[0]) - m_command = shell_command; + if (!shell_interpreter.empty()) + m_shell = shell_interpreter.str(); + + if (!m_shell.empty() && !shell_command.empty()) + m_command = shell_command.str(); + } + + PlatformShellCommand(llvm::StringRef shell_command = llvm::StringRef()) + : m_shell(), m_command(), m_working_dir(), m_status(0), m_signo(0) { + if (!shell_command.empty()) + m_command = shell_command.str(); } ~PlatformShellCommand() = default; + std::string m_shell; std::string m_command; std::string m_working_dir; std::string m_output; @@ -82,8 +93,8 @@ SBPlatformConnectOptions::SBPlatformConnectOptions( SBPlatformConnectOptions::~SBPlatformConnectOptions() { delete m_opaque_ptr; } -SBPlatformConnectOptions &SBPlatformConnectOptions:: -operator=(const SBPlatformConnectOptions &rhs) { +SBPlatformConnectOptions & +SBPlatformConnectOptions::operator=(const SBPlatformConnectOptions &rhs) { LLDB_RECORD_METHOD( SBPlatformConnectOptions &, SBPlatformConnectOptions, operator=,( @@ -163,6 +174,13 @@ void SBPlatformConnectOptions::SetLocalCacheDirectory(const char *path) { } // SBPlatformShellCommand +SBPlatformShellCommand::SBPlatformShellCommand(const char *shell_interpreter, + const char *shell_command) + : m_opaque_ptr(new PlatformShellCommand(shell_interpreter, shell_command)) { + LLDB_RECORD_CONSTRUCTOR(SBPlatformShellCommand, (const char *, const char *), + shell_interpreter, shell_command); +} + SBPlatformShellCommand::SBPlatformShellCommand(const char *shell_command) : m_opaque_ptr(new PlatformShellCommand(shell_command)) { LLDB_RECORD_CONSTRUCTOR(SBPlatformShellCommand, (const char *), @@ -178,8 +196,8 @@ SBPlatformShellCommand::SBPlatformShellCommand( *m_opaque_ptr = *rhs.m_opaque_ptr; } -SBPlatformShellCommand &SBPlatformShellCommand:: -operator=(const SBPlatformShellCommand &rhs) { +SBPlatformShellCommand & +SBPlatformShellCommand::operator=(const SBPlatformShellCommand &rhs) { LLDB_RECORD_METHOD( SBPlatformShellCommand &, @@ -200,6 +218,24 @@ void SBPlatformShellCommand::Clear() { m_opaque_ptr->m_signo = 0; } +const char *SBPlatformShellCommand::GetShell() { + LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatformShellCommand, GetShell); + + if (m_opaque_ptr->m_shell.empty()) + return nullptr; + return m_opaque_ptr->m_shell.c_str(); +} + +void SBPlatformShellCommand::SetShell(const char *shell_interpreter) { + LLDB_RECORD_METHOD(void, SBPlatformShellCommand, SetShell, (const char *), + shell_interpreter); + + if (shell_interpreter && shell_interpreter[0]) + m_opaque_ptr->m_shell = shell_interpreter; + else + m_opaque_ptr->m_shell.clear(); +} + const char *SBPlatformShellCommand::GetCommand() { LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatformShellCommand, GetCommand); @@ -545,24 +581,25 @@ SBError SBPlatform::Install(SBFileSpec &src, SBFileSpec &dst) { SBError SBPlatform::Run(SBPlatformShellCommand &shell_command) { LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, Run, (lldb::SBPlatformShellCommand &), shell_command); - return LLDB_RECORD_RESULT(ExecuteConnected([&](const lldb::PlatformSP - &platform_sp) { - const char *command = shell_command.GetCommand(); - if (!command) - return Status("invalid shell command (empty)"); - - const char *working_dir = shell_command.GetWorkingDirectory(); - if (working_dir == nullptr) { - working_dir = platform_sp->GetWorkingDirectory().GetCString(); - if (working_dir) - shell_command.SetWorkingDirectory(working_dir); - } - return platform_sp->RunShellCommand(command, FileSpec(working_dir), - &shell_command.m_opaque_ptr->m_status, - &shell_command.m_opaque_ptr->m_signo, - &shell_command.m_opaque_ptr->m_output, - shell_command.m_opaque_ptr->m_timeout); - })); + return LLDB_RECORD_RESULT( + ExecuteConnected([&](const lldb::PlatformSP &platform_sp) { + const char *command = shell_command.GetCommand(); + if (!command) + return Status("invalid shell command (empty)"); + + const char *working_dir = shell_command.GetWorkingDirectory(); + if (working_dir == nullptr) { + working_dir = platform_sp->GetWorkingDirectory().GetCString(); + if (working_dir) + shell_command.SetWorkingDirectory(working_dir); + } + return platform_sp->RunShellCommand( + shell_command.m_opaque_ptr->m_shell, command, FileSpec(working_dir), + &shell_command.m_opaque_ptr->m_status, + &shell_command.m_opaque_ptr->m_signo, + &shell_command.m_opaque_ptr->m_output, + shell_command.m_opaque_ptr->m_timeout); + })); } SBError SBPlatform::Launch(SBLaunchInfo &launch_info) { @@ -668,8 +705,7 @@ SBEnvironment SBPlatform::GetEnvironment() { namespace lldb_private { namespace repro { -template <> -void RegisterMethods<SBPlatformConnectOptions>(Registry &R) { +template <> void RegisterMethods<SBPlatformConnectOptions>(Registry &R) { LLDB_REGISTER_CONSTRUCTOR(SBPlatformConnectOptions, (const char *)); LLDB_REGISTER_CONSTRUCTOR(SBPlatformConnectOptions, (const lldb::SBPlatformConnectOptions &)); @@ -678,8 +714,7 @@ void RegisterMethods<SBPlatformConnectOptions>(Registry &R) { SBPlatformConnectOptions, operator=,( const lldb::SBPlatformConnectOptions &)); LLDB_REGISTER_METHOD(const char *, SBPlatformConnectOptions, GetURL, ()); - LLDB_REGISTER_METHOD(void, SBPlatformConnectOptions, SetURL, - (const char *)); + LLDB_REGISTER_METHOD(void, SBPlatformConnectOptions, SetURL, (const char *)); LLDB_REGISTER_METHOD(bool, SBPlatformConnectOptions, GetRsyncEnabled, ()); LLDB_REGISTER_METHOD(void, SBPlatformConnectOptions, EnableRsync, (const char *, const char *, bool)); @@ -690,8 +725,7 @@ void RegisterMethods<SBPlatformConnectOptions>(Registry &R) { (const char *)); } -template <> -void RegisterMethods<SBPlatformShellCommand>(Registry &R) { +template <> void RegisterMethods<SBPlatformShellCommand>(Registry &R) { LLDB_REGISTER_CONSTRUCTOR(SBPlatformShellCommand, (const char *)); LLDB_REGISTER_CONSTRUCTOR(SBPlatformShellCommand, (const lldb::SBPlatformShellCommand &)); @@ -699,6 +733,8 @@ void RegisterMethods<SBPlatformShellCommand>(Registry &R) { SBPlatformShellCommand &, SBPlatformShellCommand, operator=,(const lldb::SBPlatformShellCommand &)); LLDB_REGISTER_METHOD(void, SBPlatformShellCommand, Clear, ()); + LLDB_REGISTER_METHOD(const char *, SBPlatformShellCommand, GetShell, ()); + LLDB_REGISTER_METHOD(void, SBPlatformShellCommand, SetShell, (const char *)); LLDB_REGISTER_METHOD(const char *, SBPlatformShellCommand, GetCommand, ()); LLDB_REGISTER_METHOD(void, SBPlatformShellCommand, SetCommand, (const char *)); @@ -706,8 +742,7 @@ void RegisterMethods<SBPlatformShellCommand>(Registry &R) { GetWorkingDirectory, ()); LLDB_REGISTER_METHOD(void, SBPlatformShellCommand, SetWorkingDirectory, (const char *)); - LLDB_REGISTER_METHOD(uint32_t, SBPlatformShellCommand, GetTimeoutSeconds, - ()); + LLDB_REGISTER_METHOD(uint32_t, SBPlatformShellCommand, GetTimeoutSeconds, ()); LLDB_REGISTER_METHOD(void, SBPlatformShellCommand, SetTimeoutSeconds, (uint32_t)); LLDB_REGISTER_METHOD(int, SBPlatformShellCommand, GetSignal, ()); @@ -715,15 +750,16 @@ void RegisterMethods<SBPlatformShellCommand>(Registry &R) { LLDB_REGISTER_METHOD(const char *, SBPlatformShellCommand, GetOutput, ()); } -template <> -void RegisterMethods<SBPlatform>(Registry &R) { +template <> void RegisterMethods<SBPlatform>(Registry &R) { LLDB_REGISTER_CONSTRUCTOR(SBPlatform, ()); LLDB_REGISTER_CONSTRUCTOR(SBPlatform, (const char *)); LLDB_REGISTER_CONSTRUCTOR(SBPlatform, (const lldb::SBPlatform &)); + LLDB_REGISTER_CONSTRUCTOR(SBPlatformShellCommand, + (const char *, const char *)); LLDB_REGISTER_METHOD(SBPlatform &, SBPlatform, operator=,(const lldb::SBPlatform &)); LLDB_REGISTER_METHOD_CONST(bool, SBPlatform, IsValid, ()); - LLDB_REGISTER_METHOD_CONST(bool, SBPlatform, operator bool, ()); + LLDB_REGISTER_METHOD_CONST(bool, SBPlatform, operator bool,()); LLDB_REGISTER_METHOD(void, SBPlatform, Clear, ()); LLDB_REGISTER_METHOD(const char *, SBPlatform, GetName, ()); LLDB_REGISTER_METHOD(const char *, SBPlatform, GetWorkingDirectory, ()); @@ -763,5 +799,5 @@ void RegisterMethods<SBPlatform>(Registry &R) { ()); } -} -} +} // namespace repro +} // namespace lldb_private |