1e0f8f574SDaniel Malea //===-- PlatformPOSIX.cpp ---------------------------------------*- C++ -*-===// 2e0f8f574SDaniel Malea // 3e0f8f574SDaniel Malea // The LLVM Compiler Infrastructure 4e0f8f574SDaniel Malea // 5e0f8f574SDaniel Malea // This file is distributed under the University of Illinois Open Source 6e0f8f574SDaniel Malea // License. See LICENSE.TXT for details. 7e0f8f574SDaniel Malea // 8e0f8f574SDaniel Malea //===----------------------------------------------------------------------===// 9e0f8f574SDaniel Malea 10e0f8f574SDaniel Malea #include "PlatformPOSIX.h" 11e0f8f574SDaniel Malea 12e0f8f574SDaniel Malea // C Includes 13e0f8f574SDaniel Malea // C++ Includes 14e0f8f574SDaniel Malea // Other libraries and framework includes 15e0f8f574SDaniel Malea // Project includes 16e0f8f574SDaniel Malea 17e0f8f574SDaniel Malea #include "lldb/Core/DataBufferHeap.h" 18348fb385STodd Fiala #include "lldb/Core/Debugger.h" 19e0f8f574SDaniel Malea #include "lldb/Core/Log.h" 20348fb385STodd Fiala #include "lldb/Core/Module.h" 21e0f8f574SDaniel Malea #include "lldb/Core/StreamString.h" 22e0f8f574SDaniel Malea #include "lldb/Host/File.h" 23c00cf4a0SZachary Turner #include "lldb/Host/FileCache.h" 24e0f8f574SDaniel Malea #include "lldb/Host/FileSpec.h" 25c00cf4a0SZachary Turner #include "lldb/Host/FileSystem.h" 26e0f8f574SDaniel Malea #include "lldb/Host/Host.h" 27a78bd7ffSZachary Turner #include "lldb/Target/Process.h" 28015d818bSTodd Fiala #include "lldb/Target/ProcessLaunchInfo.h" 29e0f8f574SDaniel Malea 30e0f8f574SDaniel Malea using namespace lldb; 31e0f8f574SDaniel Malea using namespace lldb_private; 32e0f8f574SDaniel Malea 33e0f8f574SDaniel Malea 34e0f8f574SDaniel Malea //------------------------------------------------------------------ 35e0f8f574SDaniel Malea /// Default Constructor 36e0f8f574SDaniel Malea //------------------------------------------------------------------ 37e0f8f574SDaniel Malea PlatformPOSIX::PlatformPOSIX (bool is_host) : 38e0f8f574SDaniel Malea Platform(is_host), // This is the local host platform 39e0f8f574SDaniel Malea m_remote_platform_sp () 40e0f8f574SDaniel Malea { 41e0f8f574SDaniel Malea } 42e0f8f574SDaniel Malea 43e0f8f574SDaniel Malea //------------------------------------------------------------------ 44e0f8f574SDaniel Malea /// Destructor. 45e0f8f574SDaniel Malea /// 46e0f8f574SDaniel Malea /// The destructor is virtual since this class is designed to be 47e0f8f574SDaniel Malea /// inherited from by the plug-in instance. 48e0f8f574SDaniel Malea //------------------------------------------------------------------ 49e0f8f574SDaniel Malea PlatformPOSIX::~PlatformPOSIX() 50e0f8f574SDaniel Malea { 51e0f8f574SDaniel Malea } 52e0f8f574SDaniel Malea 5363acdfdeSOleksiy Vyalov bool 5463acdfdeSOleksiy Vyalov PlatformPOSIX::GetModuleSpec (const FileSpec& module_file_spec, 5563acdfdeSOleksiy Vyalov const ArchSpec& arch, 5663acdfdeSOleksiy Vyalov ModuleSpec &module_spec) 5763acdfdeSOleksiy Vyalov { 5863acdfdeSOleksiy Vyalov if (m_remote_platform_sp) 5963acdfdeSOleksiy Vyalov return m_remote_platform_sp->GetModuleSpec (module_file_spec, arch, module_spec); 6063acdfdeSOleksiy Vyalov 6163acdfdeSOleksiy Vyalov return Platform::GetModuleSpec (module_file_spec, arch, module_spec); 6263acdfdeSOleksiy Vyalov } 6363acdfdeSOleksiy Vyalov 64e0f8f574SDaniel Malea lldb_private::OptionGroupOptions* 65e0f8f574SDaniel Malea PlatformPOSIX::GetConnectionOptions (lldb_private::CommandInterpreter& interpreter) 66e0f8f574SDaniel Malea { 67e0f8f574SDaniel Malea if (m_options.get() == NULL) 68e0f8f574SDaniel Malea { 69e0f8f574SDaniel Malea m_options.reset(new OptionGroupOptions(interpreter)); 70e0f8f574SDaniel Malea m_options->Append(new OptionGroupPlatformRSync()); 71e0f8f574SDaniel Malea m_options->Append(new OptionGroupPlatformSSH()); 72e0f8f574SDaniel Malea m_options->Append(new OptionGroupPlatformCaching()); 73e0f8f574SDaniel Malea } 74e0f8f574SDaniel Malea return m_options.get(); 75e0f8f574SDaniel Malea } 76e0f8f574SDaniel Malea 77015d818bSTodd Fiala bool 78015d818bSTodd Fiala PlatformPOSIX::IsConnected () const 79015d818bSTodd Fiala { 80015d818bSTodd Fiala if (IsHost()) 81015d818bSTodd Fiala return true; 82015d818bSTodd Fiala else if (m_remote_platform_sp) 83015d818bSTodd Fiala return m_remote_platform_sp->IsConnected(); 84015d818bSTodd Fiala return false; 85015d818bSTodd Fiala } 86015d818bSTodd Fiala 87e0f8f574SDaniel Malea lldb_private::Error 88e0f8f574SDaniel Malea PlatformPOSIX::RunShellCommand(const char *command, // Shouldn't be NULL 89d3173f34SChaoren Lin const FileSpec &working_dir, // Pass empty FileSpec to use the current working directory 90e0f8f574SDaniel Malea int *status_ptr, // Pass NULL if you don't want the process exit status 91e0f8f574SDaniel Malea int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit 92e0f8f574SDaniel Malea std::string *command_output, // Pass NULL if you don't want the command output 93e0f8f574SDaniel Malea uint32_t timeout_sec) // Timeout in seconds to wait for shell program to finish 94e0f8f574SDaniel Malea { 95e0f8f574SDaniel Malea if (IsHost()) 96e0f8f574SDaniel Malea return Host::RunShellCommand(command, working_dir, status_ptr, signo_ptr, command_output, timeout_sec); 97e0f8f574SDaniel Malea else 98e0f8f574SDaniel Malea { 99e0f8f574SDaniel Malea if (m_remote_platform_sp) 100e0f8f574SDaniel Malea return m_remote_platform_sp->RunShellCommand(command, working_dir, status_ptr, signo_ptr, command_output, timeout_sec); 101e0f8f574SDaniel Malea else 102e0f8f574SDaniel Malea return Error("unable to run a remote command without a platform"); 103e0f8f574SDaniel Malea } 104e0f8f574SDaniel Malea } 105e0f8f574SDaniel Malea 106fbb76349SGreg Clayton Error 107d3173f34SChaoren Lin PlatformPOSIX::MakeDirectory(const FileSpec &file_spec, uint32_t file_permissions) 108e0f8f574SDaniel Malea { 109fbb76349SGreg Clayton if (m_remote_platform_sp) 110d3173f34SChaoren Lin return m_remote_platform_sp->MakeDirectory(file_spec, file_permissions); 111fbb76349SGreg Clayton else 112d3173f34SChaoren Lin return Platform::MakeDirectory(file_spec ,file_permissions); 113e0f8f574SDaniel Malea } 114fbb76349SGreg Clayton 115fbb76349SGreg Clayton Error 116d3173f34SChaoren Lin PlatformPOSIX::GetFilePermissions(const FileSpec &file_spec, uint32_t &file_permissions) 117fbb76349SGreg Clayton { 118fbb76349SGreg Clayton if (m_remote_platform_sp) 119d3173f34SChaoren Lin return m_remote_platform_sp->GetFilePermissions(file_spec, file_permissions); 120fbb76349SGreg Clayton else 121d3173f34SChaoren Lin return Platform::GetFilePermissions(file_spec ,file_permissions); 122fbb76349SGreg Clayton } 123fbb76349SGreg Clayton 124fbb76349SGreg Clayton Error 125d3173f34SChaoren Lin PlatformPOSIX::SetFilePermissions(const FileSpec &file_spec, uint32_t file_permissions) 126fbb76349SGreg Clayton { 127fbb76349SGreg Clayton if (m_remote_platform_sp) 128d3173f34SChaoren Lin return m_remote_platform_sp->SetFilePermissions(file_spec, file_permissions); 129fbb76349SGreg Clayton else 130d3173f34SChaoren Lin return Platform::SetFilePermissions(file_spec, file_permissions); 131e0f8f574SDaniel Malea } 132e0f8f574SDaniel Malea 133e0f8f574SDaniel Malea lldb::user_id_t 134e0f8f574SDaniel Malea PlatformPOSIX::OpenFile (const FileSpec& file_spec, 135e0f8f574SDaniel Malea uint32_t flags, 136fbb76349SGreg Clayton uint32_t mode, 137e0f8f574SDaniel Malea Error &error) 138e0f8f574SDaniel Malea { 139e0f8f574SDaniel Malea if (IsHost()) 140c00cf4a0SZachary Turner return FileCache::GetInstance().OpenFile(file_spec, flags, mode, error); 141fbb76349SGreg Clayton else if (m_remote_platform_sp) 142e0f8f574SDaniel Malea return m_remote_platform_sp->OpenFile(file_spec, flags, mode, error); 143fbb76349SGreg Clayton else 144e0f8f574SDaniel Malea return Platform::OpenFile(file_spec, flags, mode, error); 145e0f8f574SDaniel Malea } 146e0f8f574SDaniel Malea 147e0f8f574SDaniel Malea bool 148e0f8f574SDaniel Malea PlatformPOSIX::CloseFile (lldb::user_id_t fd, Error &error) 149e0f8f574SDaniel Malea { 150e0f8f574SDaniel Malea if (IsHost()) 151c00cf4a0SZachary Turner return FileCache::GetInstance().CloseFile(fd, error); 152fbb76349SGreg Clayton else if (m_remote_platform_sp) 153e0f8f574SDaniel Malea return m_remote_platform_sp->CloseFile(fd, error); 154fbb76349SGreg Clayton else 155e0f8f574SDaniel Malea return Platform::CloseFile(fd, error); 156e0f8f574SDaniel Malea } 157e0f8f574SDaniel Malea 158e0f8f574SDaniel Malea uint64_t 159e0f8f574SDaniel Malea PlatformPOSIX::ReadFile (lldb::user_id_t fd, 160e0f8f574SDaniel Malea uint64_t offset, 161e0f8f574SDaniel Malea void *dst, 162e0f8f574SDaniel Malea uint64_t dst_len, 163e0f8f574SDaniel Malea Error &error) 164e0f8f574SDaniel Malea { 165e0f8f574SDaniel Malea if (IsHost()) 166c00cf4a0SZachary Turner return FileCache::GetInstance().ReadFile(fd, offset, dst, dst_len, error); 167fbb76349SGreg Clayton else if (m_remote_platform_sp) 168e0f8f574SDaniel Malea return m_remote_platform_sp->ReadFile(fd, offset, dst, dst_len, error); 169fbb76349SGreg Clayton else 170e0f8f574SDaniel Malea return Platform::ReadFile(fd, offset, dst, dst_len, error); 171e0f8f574SDaniel Malea } 172e0f8f574SDaniel Malea 173e0f8f574SDaniel Malea uint64_t 174e0f8f574SDaniel Malea PlatformPOSIX::WriteFile (lldb::user_id_t fd, 175e0f8f574SDaniel Malea uint64_t offset, 176e0f8f574SDaniel Malea const void* src, 177e0f8f574SDaniel Malea uint64_t src_len, 178e0f8f574SDaniel Malea Error &error) 179e0f8f574SDaniel Malea { 180e0f8f574SDaniel Malea if (IsHost()) 181c00cf4a0SZachary Turner return FileCache::GetInstance().WriteFile(fd, offset, src, src_len, error); 182fbb76349SGreg Clayton else if (m_remote_platform_sp) 183e0f8f574SDaniel Malea return m_remote_platform_sp->WriteFile(fd, offset, src, src_len, error); 184fbb76349SGreg Clayton else 185e0f8f574SDaniel Malea return Platform::WriteFile(fd, offset, src, src_len, error); 186e0f8f574SDaniel Malea } 187e0f8f574SDaniel Malea 188e0f8f574SDaniel Malea static uint32_t 189e0f8f574SDaniel Malea chown_file(Platform *platform, 190e0f8f574SDaniel Malea const char* path, 191e0f8f574SDaniel Malea uint32_t uid = UINT32_MAX, 192e0f8f574SDaniel Malea uint32_t gid = UINT32_MAX) 193e0f8f574SDaniel Malea { 194e0f8f574SDaniel Malea if (!platform || !path || *path == 0) 195e0f8f574SDaniel Malea return UINT32_MAX; 196e0f8f574SDaniel Malea 197e0f8f574SDaniel Malea if (uid == UINT32_MAX && gid == UINT32_MAX) 198e0f8f574SDaniel Malea return 0; // pretend I did chown correctly - actually I just didn't care 199e0f8f574SDaniel Malea 200e0f8f574SDaniel Malea StreamString command; 201e0f8f574SDaniel Malea command.PutCString("chown "); 202e0f8f574SDaniel Malea if (uid != UINT32_MAX) 203e0f8f574SDaniel Malea command.Printf("%d",uid); 204e0f8f574SDaniel Malea if (gid != UINT32_MAX) 205e0f8f574SDaniel Malea command.Printf(":%d",gid); 206e0f8f574SDaniel Malea command.Printf("%s",path); 207e0f8f574SDaniel Malea int status; 208e0f8f574SDaniel Malea platform->RunShellCommand(command.GetData(), 209e0f8f574SDaniel Malea NULL, 210e0f8f574SDaniel Malea &status, 211e0f8f574SDaniel Malea NULL, 212e0f8f574SDaniel Malea NULL, 213e0f8f574SDaniel Malea 10); 214e0f8f574SDaniel Malea return status; 215e0f8f574SDaniel Malea } 216e0f8f574SDaniel Malea 217e0f8f574SDaniel Malea lldb_private::Error 218e0f8f574SDaniel Malea PlatformPOSIX::PutFile (const lldb_private::FileSpec& source, 219e0f8f574SDaniel Malea const lldb_private::FileSpec& destination, 220e0f8f574SDaniel Malea uint32_t uid, 221e0f8f574SDaniel Malea uint32_t gid) 222e0f8f574SDaniel Malea { 223fbb76349SGreg Clayton Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM)); 224fbb76349SGreg Clayton 225e0f8f574SDaniel Malea if (IsHost()) 226e0f8f574SDaniel Malea { 227e0f8f574SDaniel Malea if (FileSpec::Equal(source, destination, true)) 228e0f8f574SDaniel Malea return Error(); 229e0f8f574SDaniel Malea // cp src dst 230e0f8f574SDaniel Malea // chown uid:gid dst 231e0f8f574SDaniel Malea std::string src_path (source.GetPath()); 232e0f8f574SDaniel Malea if (src_path.empty()) 233e0f8f574SDaniel Malea return Error("unable to get file path for source"); 234e0f8f574SDaniel Malea std::string dst_path (destination.GetPath()); 235e0f8f574SDaniel Malea if (dst_path.empty()) 236e0f8f574SDaniel Malea return Error("unable to get file path for destination"); 237e0f8f574SDaniel Malea StreamString command; 238e0f8f574SDaniel Malea command.Printf("cp %s %s", src_path.c_str(), dst_path.c_str()); 239e0f8f574SDaniel Malea int status; 240e0f8f574SDaniel Malea RunShellCommand(command.GetData(), 241e0f8f574SDaniel Malea NULL, 242e0f8f574SDaniel Malea &status, 243e0f8f574SDaniel Malea NULL, 244e0f8f574SDaniel Malea NULL, 245e0f8f574SDaniel Malea 10); 246e0f8f574SDaniel Malea if (status != 0) 247e0f8f574SDaniel Malea return Error("unable to perform copy"); 248e0f8f574SDaniel Malea if (uid == UINT32_MAX && gid == UINT32_MAX) 249e0f8f574SDaniel Malea return Error(); 250e0f8f574SDaniel Malea if (chown_file(this,dst_path.c_str(),uid,gid) != 0) 251e0f8f574SDaniel Malea return Error("unable to perform chown"); 252e0f8f574SDaniel Malea return Error(); 253e0f8f574SDaniel Malea } 254fbb76349SGreg Clayton else if (m_remote_platform_sp) 255e0f8f574SDaniel Malea { 256e0f8f574SDaniel Malea if (GetSupportsRSync()) 257e0f8f574SDaniel Malea { 258e0f8f574SDaniel Malea std::string src_path (source.GetPath()); 259e0f8f574SDaniel Malea if (src_path.empty()) 260e0f8f574SDaniel Malea return Error("unable to get file path for source"); 261e0f8f574SDaniel Malea std::string dst_path (destination.GetPath()); 262e0f8f574SDaniel Malea if (dst_path.empty()) 263e0f8f574SDaniel Malea return Error("unable to get file path for destination"); 264e0f8f574SDaniel Malea StreamString command; 265e0f8f574SDaniel Malea if (GetIgnoresRemoteHostname()) 266e0f8f574SDaniel Malea { 267e0f8f574SDaniel Malea if (!GetRSyncPrefix()) 268e0f8f574SDaniel Malea command.Printf("rsync %s %s %s", 269e0f8f574SDaniel Malea GetRSyncOpts(), 270e0f8f574SDaniel Malea src_path.c_str(), 271e0f8f574SDaniel Malea dst_path.c_str()); 272e0f8f574SDaniel Malea else 273e0f8f574SDaniel Malea command.Printf("rsync %s %s %s%s", 274e0f8f574SDaniel Malea GetRSyncOpts(), 275e0f8f574SDaniel Malea src_path.c_str(), 276e0f8f574SDaniel Malea GetRSyncPrefix(), 277e0f8f574SDaniel Malea dst_path.c_str()); 278e0f8f574SDaniel Malea } 279e0f8f574SDaniel Malea else 280e0f8f574SDaniel Malea command.Printf("rsync %s %s %s:%s", 281e0f8f574SDaniel Malea GetRSyncOpts(), 282e0f8f574SDaniel Malea src_path.c_str(), 283e0f8f574SDaniel Malea GetHostname(), 284e0f8f574SDaniel Malea dst_path.c_str()); 285e0f8f574SDaniel Malea if (log) 286e0f8f574SDaniel Malea log->Printf("[PutFile] Running command: %s\n", command.GetData()); 287e0f8f574SDaniel Malea int retcode; 288e0f8f574SDaniel Malea Host::RunShellCommand(command.GetData(), 289e0f8f574SDaniel Malea NULL, 290e0f8f574SDaniel Malea &retcode, 291e0f8f574SDaniel Malea NULL, 292e0f8f574SDaniel Malea NULL, 293e0f8f574SDaniel Malea 60); 294e0f8f574SDaniel Malea if (retcode == 0) 295e0f8f574SDaniel Malea { 296e0f8f574SDaniel Malea // Don't chown a local file for a remote system 297e0f8f574SDaniel Malea // if (chown_file(this,dst_path.c_str(),uid,gid) != 0) 298e0f8f574SDaniel Malea // return Error("unable to perform chown"); 299e0f8f574SDaniel Malea return Error(); 300e0f8f574SDaniel Malea } 301e0f8f574SDaniel Malea // if we are still here rsync has failed - let's try the slow way before giving up 302e0f8f574SDaniel Malea } 303e0f8f574SDaniel Malea } 304e0f8f574SDaniel Malea return Platform::PutFile(source,destination,uid,gid); 305e0f8f574SDaniel Malea } 306e0f8f574SDaniel Malea 307e0f8f574SDaniel Malea lldb::user_id_t 308e0f8f574SDaniel Malea PlatformPOSIX::GetFileSize (const FileSpec& file_spec) 309e0f8f574SDaniel Malea { 310e0f8f574SDaniel Malea if (IsHost()) 311c00cf4a0SZachary Turner return FileSystem::GetFileSize(file_spec); 312fbb76349SGreg Clayton else if (m_remote_platform_sp) 313e0f8f574SDaniel Malea return m_remote_platform_sp->GetFileSize(file_spec); 314fbb76349SGreg Clayton else 315e0f8f574SDaniel Malea return Platform::GetFileSize(file_spec); 316e0f8f574SDaniel Malea } 317e0f8f574SDaniel Malea 318fbb76349SGreg Clayton Error 319d3173f34SChaoren Lin PlatformPOSIX::CreateSymlink(const FileSpec &src, const FileSpec &dst) 320fbb76349SGreg Clayton { 321fbb76349SGreg Clayton if (IsHost()) 322c00cf4a0SZachary Turner return FileSystem::Symlink(src, dst); 323fbb76349SGreg Clayton else if (m_remote_platform_sp) 324fbb76349SGreg Clayton return m_remote_platform_sp->CreateSymlink(src, dst); 325fbb76349SGreg Clayton else 326fbb76349SGreg Clayton return Platform::CreateSymlink(src, dst); 327fbb76349SGreg Clayton } 328fbb76349SGreg Clayton 329e0f8f574SDaniel Malea bool 330e0f8f574SDaniel Malea PlatformPOSIX::GetFileExists (const FileSpec& file_spec) 331e0f8f574SDaniel Malea { 332e0f8f574SDaniel Malea if (IsHost()) 333e0f8f574SDaniel Malea return file_spec.Exists(); 334fbb76349SGreg Clayton else if (m_remote_platform_sp) 335e0f8f574SDaniel Malea return m_remote_platform_sp->GetFileExists(file_spec); 336fbb76349SGreg Clayton else 337e0f8f574SDaniel Malea return Platform::GetFileExists(file_spec); 338e0f8f574SDaniel Malea } 339e0f8f574SDaniel Malea 340fbb76349SGreg Clayton Error 341d3173f34SChaoren Lin PlatformPOSIX::Unlink(const FileSpec &file_spec) 342e0f8f574SDaniel Malea { 343e0f8f574SDaniel Malea if (IsHost()) 344d3173f34SChaoren Lin return FileSystem::Unlink(file_spec); 345fbb76349SGreg Clayton else if (m_remote_platform_sp) 346d3173f34SChaoren Lin return m_remote_platform_sp->Unlink(file_spec); 347fbb76349SGreg Clayton else 348d3173f34SChaoren Lin return Platform::Unlink(file_spec); 349e0f8f574SDaniel Malea } 350e0f8f574SDaniel Malea 351e0f8f574SDaniel Malea lldb_private::Error 352d3173f34SChaoren Lin PlatformPOSIX::GetFile(const lldb_private::FileSpec &source, // remote file path 353d3173f34SChaoren Lin const lldb_private::FileSpec &destination) // local file path 354e0f8f574SDaniel Malea { 355fbb76349SGreg Clayton Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM)); 356fbb76349SGreg Clayton 357e0f8f574SDaniel Malea // Check the args, first. 358e0f8f574SDaniel Malea std::string src_path (source.GetPath()); 359e0f8f574SDaniel Malea if (src_path.empty()) 360e0f8f574SDaniel Malea return Error("unable to get file path for source"); 361e0f8f574SDaniel Malea std::string dst_path (destination.GetPath()); 362e0f8f574SDaniel Malea if (dst_path.empty()) 363e0f8f574SDaniel Malea return Error("unable to get file path for destination"); 364e0f8f574SDaniel Malea if (IsHost()) 365e0f8f574SDaniel Malea { 366e0f8f574SDaniel Malea if (FileSpec::Equal(source, destination, true)) 367e0f8f574SDaniel Malea return Error("local scenario->source and destination are the same file path: no operation performed"); 368e0f8f574SDaniel Malea // cp src dst 369e0f8f574SDaniel Malea StreamString cp_command; 370e0f8f574SDaniel Malea cp_command.Printf("cp %s %s", src_path.c_str(), dst_path.c_str()); 371e0f8f574SDaniel Malea int status; 372e0f8f574SDaniel Malea RunShellCommand(cp_command.GetData(), 373e0f8f574SDaniel Malea NULL, 374e0f8f574SDaniel Malea &status, 375e0f8f574SDaniel Malea NULL, 376e0f8f574SDaniel Malea NULL, 377e0f8f574SDaniel Malea 10); 378e0f8f574SDaniel Malea if (status != 0) 379e0f8f574SDaniel Malea return Error("unable to perform copy"); 380e0f8f574SDaniel Malea return Error(); 381e0f8f574SDaniel Malea } 382fbb76349SGreg Clayton else if (m_remote_platform_sp) 383e0f8f574SDaniel Malea { 384e0f8f574SDaniel Malea if (GetSupportsRSync()) 385e0f8f574SDaniel Malea { 386e0f8f574SDaniel Malea StreamString command; 387e0f8f574SDaniel Malea if (GetIgnoresRemoteHostname()) 388e0f8f574SDaniel Malea { 389e0f8f574SDaniel Malea if (!GetRSyncPrefix()) 390e0f8f574SDaniel Malea command.Printf("rsync %s %s %s", 391e0f8f574SDaniel Malea GetRSyncOpts(), 392e0f8f574SDaniel Malea src_path.c_str(), 393e0f8f574SDaniel Malea dst_path.c_str()); 394e0f8f574SDaniel Malea else 395e0f8f574SDaniel Malea command.Printf("rsync %s %s%s %s", 396e0f8f574SDaniel Malea GetRSyncOpts(), 397e0f8f574SDaniel Malea GetRSyncPrefix(), 398e0f8f574SDaniel Malea src_path.c_str(), 399e0f8f574SDaniel Malea dst_path.c_str()); 400e0f8f574SDaniel Malea } 401e0f8f574SDaniel Malea else 402e0f8f574SDaniel Malea command.Printf("rsync %s %s:%s %s", 403e0f8f574SDaniel Malea GetRSyncOpts(), 404e0f8f574SDaniel Malea m_remote_platform_sp->GetHostname(), 405e0f8f574SDaniel Malea src_path.c_str(), 406e0f8f574SDaniel Malea dst_path.c_str()); 407e0f8f574SDaniel Malea if (log) 408e0f8f574SDaniel Malea log->Printf("[GetFile] Running command: %s\n", command.GetData()); 409e0f8f574SDaniel Malea int retcode; 410e0f8f574SDaniel Malea Host::RunShellCommand(command.GetData(), 411e0f8f574SDaniel Malea NULL, 412e0f8f574SDaniel Malea &retcode, 413e0f8f574SDaniel Malea NULL, 414e0f8f574SDaniel Malea NULL, 415e0f8f574SDaniel Malea 60); 416e0f8f574SDaniel Malea if (retcode == 0) 417e0f8f574SDaniel Malea return Error(); 418e0f8f574SDaniel Malea // If we are here, rsync has failed - let's try the slow way before giving up 419e0f8f574SDaniel Malea } 420e0f8f574SDaniel Malea // open src and dst 421e0f8f574SDaniel Malea // read/write, read/write, read/write, ... 422e0f8f574SDaniel Malea // close src 423e0f8f574SDaniel Malea // close dst 424e0f8f574SDaniel Malea if (log) 425e0f8f574SDaniel Malea log->Printf("[GetFile] Using block by block transfer....\n"); 426e0f8f574SDaniel Malea Error error; 427e0f8f574SDaniel Malea user_id_t fd_src = OpenFile (source, 428e0f8f574SDaniel Malea File::eOpenOptionRead, 429fbb76349SGreg Clayton lldb::eFilePermissionsFileDefault, 430e0f8f574SDaniel Malea error); 431e0f8f574SDaniel Malea 432e0f8f574SDaniel Malea if (fd_src == UINT64_MAX) 433e0f8f574SDaniel Malea return Error("unable to open source file"); 434e0f8f574SDaniel Malea 435fbb76349SGreg Clayton uint32_t permissions = 0; 436d3173f34SChaoren Lin error = GetFilePermissions(source, permissions); 437e0f8f574SDaniel Malea 438e0f8f574SDaniel Malea if (permissions == 0) 439fbb76349SGreg Clayton permissions = lldb::eFilePermissionsFileDefault; 440e0f8f574SDaniel Malea 441c00cf4a0SZachary Turner user_id_t fd_dst = FileCache::GetInstance().OpenFile( 442c00cf4a0SZachary Turner destination, File::eOpenOptionCanCreate | File::eOpenOptionWrite | File::eOpenOptionTruncate, permissions, 443e0f8f574SDaniel Malea error); 444e0f8f574SDaniel Malea 445e0f8f574SDaniel Malea if (fd_dst == UINT64_MAX) 446e0f8f574SDaniel Malea { 447e0f8f574SDaniel Malea if (error.Success()) 448e0f8f574SDaniel Malea error.SetErrorString("unable to open destination file"); 449e0f8f574SDaniel Malea } 450e0f8f574SDaniel Malea 451e0f8f574SDaniel Malea if (error.Success()) 452e0f8f574SDaniel Malea { 453e0f8f574SDaniel Malea lldb::DataBufferSP buffer_sp(new DataBufferHeap(1024, 0)); 454e0f8f574SDaniel Malea uint64_t offset = 0; 455e0f8f574SDaniel Malea error.Clear(); 456e0f8f574SDaniel Malea while (error.Success()) 457e0f8f574SDaniel Malea { 458e0f8f574SDaniel Malea const uint64_t n_read = ReadFile (fd_src, 459e0f8f574SDaniel Malea offset, 460e0f8f574SDaniel Malea buffer_sp->GetBytes(), 461e0f8f574SDaniel Malea buffer_sp->GetByteSize(), 462e0f8f574SDaniel Malea error); 463e0f8f574SDaniel Malea if (error.Fail()) 464e0f8f574SDaniel Malea break; 465e0f8f574SDaniel Malea if (n_read == 0) 466e0f8f574SDaniel Malea break; 467c00cf4a0SZachary Turner if (FileCache::GetInstance().WriteFile(fd_dst, offset, buffer_sp->GetBytes(), n_read, error) != n_read) 468e0f8f574SDaniel Malea { 469e0f8f574SDaniel Malea if (!error.Fail()) 470e0f8f574SDaniel Malea error.SetErrorString("unable to write to destination file"); 471e0f8f574SDaniel Malea break; 472e0f8f574SDaniel Malea } 473e0f8f574SDaniel Malea offset += n_read; 474e0f8f574SDaniel Malea } 475e0f8f574SDaniel Malea } 476e0f8f574SDaniel Malea // Ignore the close error of src. 477e0f8f574SDaniel Malea if (fd_src != UINT64_MAX) 478e0f8f574SDaniel Malea CloseFile(fd_src, error); 479e0f8f574SDaniel Malea // And close the dst file descriptot. 480c00cf4a0SZachary Turner if (fd_dst != UINT64_MAX && !FileCache::GetInstance().CloseFile(fd_dst, error)) 481e0f8f574SDaniel Malea { 482e0f8f574SDaniel Malea if (!error.Fail()) 483e0f8f574SDaniel Malea error.SetErrorString("unable to close destination file"); 484e0f8f574SDaniel Malea 485e0f8f574SDaniel Malea } 486e0f8f574SDaniel Malea return error; 487e0f8f574SDaniel Malea } 488e0f8f574SDaniel Malea return Platform::GetFile(source,destination); 489e0f8f574SDaniel Malea } 490e0f8f574SDaniel Malea 491e0f8f574SDaniel Malea std::string 492e0f8f574SDaniel Malea PlatformPOSIX::GetPlatformSpecificConnectionInformation() 493e0f8f574SDaniel Malea { 494e0f8f574SDaniel Malea StreamString stream; 495e0f8f574SDaniel Malea if (GetSupportsRSync()) 496e0f8f574SDaniel Malea { 497e0f8f574SDaniel Malea stream.PutCString("rsync"); 498e0f8f574SDaniel Malea if ( (GetRSyncOpts() && *GetRSyncOpts()) || 499e0f8f574SDaniel Malea (GetRSyncPrefix() && *GetRSyncPrefix()) || 500e0f8f574SDaniel Malea GetIgnoresRemoteHostname()) 501e0f8f574SDaniel Malea { 502e0f8f574SDaniel Malea stream.Printf(", options: "); 503e0f8f574SDaniel Malea if (GetRSyncOpts() && *GetRSyncOpts()) 504e0f8f574SDaniel Malea stream.Printf("'%s' ",GetRSyncOpts()); 505e0f8f574SDaniel Malea stream.Printf(", prefix: "); 506e0f8f574SDaniel Malea if (GetRSyncPrefix() && *GetRSyncPrefix()) 507e0f8f574SDaniel Malea stream.Printf("'%s' ",GetRSyncPrefix()); 508e0f8f574SDaniel Malea if (GetIgnoresRemoteHostname()) 509e0f8f574SDaniel Malea stream.Printf("ignore remote-hostname "); 510e0f8f574SDaniel Malea } 511e0f8f574SDaniel Malea } 512e0f8f574SDaniel Malea if (GetSupportsSSH()) 513e0f8f574SDaniel Malea { 514e0f8f574SDaniel Malea stream.PutCString("ssh"); 515e0f8f574SDaniel Malea if (GetSSHOpts() && *GetSSHOpts()) 516e0f8f574SDaniel Malea stream.Printf(", options: '%s' ",GetSSHOpts()); 517e0f8f574SDaniel Malea } 518e0f8f574SDaniel Malea if (GetLocalCacheDirectory() && *GetLocalCacheDirectory()) 519e0f8f574SDaniel Malea stream.Printf("cache dir: %s",GetLocalCacheDirectory()); 520e0f8f574SDaniel Malea if (stream.GetSize()) 521e0f8f574SDaniel Malea return stream.GetData(); 522e0f8f574SDaniel Malea else 523e0f8f574SDaniel Malea return ""; 524e0f8f574SDaniel Malea } 525e0f8f574SDaniel Malea 526e0f8f574SDaniel Malea bool 527e0f8f574SDaniel Malea PlatformPOSIX::CalculateMD5 (const FileSpec& file_spec, 528e0f8f574SDaniel Malea uint64_t &low, 529e0f8f574SDaniel Malea uint64_t &high) 530e0f8f574SDaniel Malea { 531e0f8f574SDaniel Malea if (IsHost()) 532e0f8f574SDaniel Malea return Platform::CalculateMD5 (file_spec, low, high); 533e0f8f574SDaniel Malea if (m_remote_platform_sp) 534e0f8f574SDaniel Malea return m_remote_platform_sp->CalculateMD5(file_spec, low, high); 535e0f8f574SDaniel Malea return false; 536e0f8f574SDaniel Malea } 537fbb76349SGreg Clayton 53898d0a4b3SChaoren Lin const lldb::UnixSignalsSP & 53998d0a4b3SChaoren Lin PlatformPOSIX::GetRemoteUnixSignals() { 54098d0a4b3SChaoren Lin if (IsRemote() && m_remote_platform_sp) 54198d0a4b3SChaoren Lin return m_remote_platform_sp->GetRemoteUnixSignals(); 54298d0a4b3SChaoren Lin return Platform::GetRemoteUnixSignals(); 54398d0a4b3SChaoren Lin } 54498d0a4b3SChaoren Lin 54598d0a4b3SChaoren Lin 546d3173f34SChaoren Lin FileSpec 547fbb76349SGreg Clayton PlatformPOSIX::GetRemoteWorkingDirectory() 548fbb76349SGreg Clayton { 549fbb76349SGreg Clayton if (IsRemote() && m_remote_platform_sp) 550fbb76349SGreg Clayton return m_remote_platform_sp->GetRemoteWorkingDirectory(); 551fbb76349SGreg Clayton else 552fbb76349SGreg Clayton return Platform::GetRemoteWorkingDirectory(); 553fbb76349SGreg Clayton } 554fbb76349SGreg Clayton 555fbb76349SGreg Clayton bool 556d3173f34SChaoren Lin PlatformPOSIX::SetRemoteWorkingDirectory(const FileSpec &working_dir) 557fbb76349SGreg Clayton { 558fbb76349SGreg Clayton if (IsRemote() && m_remote_platform_sp) 559d3173f34SChaoren Lin return m_remote_platform_sp->SetRemoteWorkingDirectory(working_dir); 560fbb76349SGreg Clayton else 561d3173f34SChaoren Lin return Platform::SetRemoteWorkingDirectory(working_dir); 562fbb76349SGreg Clayton } 563fbb76349SGreg Clayton 564015d818bSTodd Fiala bool 565015d818bSTodd Fiala PlatformPOSIX::GetRemoteOSVersion () 566015d818bSTodd Fiala { 567015d818bSTodd Fiala if (m_remote_platform_sp) 568015d818bSTodd Fiala return m_remote_platform_sp->GetOSVersion (m_major_os_version, 569015d818bSTodd Fiala m_minor_os_version, 570015d818bSTodd Fiala m_update_os_version); 571015d818bSTodd Fiala return false; 572015d818bSTodd Fiala } 573015d818bSTodd Fiala 574015d818bSTodd Fiala bool 575015d818bSTodd Fiala PlatformPOSIX::GetRemoteOSBuildString (std::string &s) 576015d818bSTodd Fiala { 577015d818bSTodd Fiala if (m_remote_platform_sp) 578015d818bSTodd Fiala return m_remote_platform_sp->GetRemoteOSBuildString (s); 579015d818bSTodd Fiala s.clear(); 580015d818bSTodd Fiala return false; 581015d818bSTodd Fiala } 582015d818bSTodd Fiala 583e15fcaa2STodd Fiala size_t 584e15fcaa2STodd Fiala PlatformPOSIX::GetEnvironment (StringList &env) 585e15fcaa2STodd Fiala { 586e15fcaa2STodd Fiala if (IsRemote()) 587e15fcaa2STodd Fiala { 588e15fcaa2STodd Fiala if (m_remote_platform_sp) 589e15fcaa2STodd Fiala return m_remote_platform_sp->GetEnvironment(env); 590e15fcaa2STodd Fiala return 0; 591e15fcaa2STodd Fiala } 592e15fcaa2STodd Fiala return Host::GetEnvironment(env); 593e15fcaa2STodd Fiala } 594e15fcaa2STodd Fiala 595015d818bSTodd Fiala bool 596015d818bSTodd Fiala PlatformPOSIX::GetRemoteOSKernelDescription (std::string &s) 597015d818bSTodd Fiala { 598015d818bSTodd Fiala if (m_remote_platform_sp) 599015d818bSTodd Fiala return m_remote_platform_sp->GetRemoteOSKernelDescription (s); 600015d818bSTodd Fiala s.clear(); 601015d818bSTodd Fiala return false; 602015d818bSTodd Fiala } 603015d818bSTodd Fiala 604015d818bSTodd Fiala // Remote Platform subclasses need to override this function 605015d818bSTodd Fiala ArchSpec 606015d818bSTodd Fiala PlatformPOSIX::GetRemoteSystemArchitecture () 607015d818bSTodd Fiala { 608015d818bSTodd Fiala if (m_remote_platform_sp) 609015d818bSTodd Fiala return m_remote_platform_sp->GetRemoteSystemArchitecture (); 610015d818bSTodd Fiala return ArchSpec(); 611015d818bSTodd Fiala } 612015d818bSTodd Fiala 613015d818bSTodd Fiala const char * 614015d818bSTodd Fiala PlatformPOSIX::GetHostname () 615015d818bSTodd Fiala { 616015d818bSTodd Fiala if (IsHost()) 617015d818bSTodd Fiala return Platform::GetHostname(); 618015d818bSTodd Fiala 619015d818bSTodd Fiala if (m_remote_platform_sp) 620015d818bSTodd Fiala return m_remote_platform_sp->GetHostname (); 621015d818bSTodd Fiala return NULL; 622015d818bSTodd Fiala } 623015d818bSTodd Fiala 624015d818bSTodd Fiala const char * 625015d818bSTodd Fiala PlatformPOSIX::GetUserName (uint32_t uid) 626015d818bSTodd Fiala { 627015d818bSTodd Fiala // Check the cache in Platform in case we have already looked this uid up 628015d818bSTodd Fiala const char *user_name = Platform::GetUserName(uid); 629015d818bSTodd Fiala if (user_name) 630015d818bSTodd Fiala return user_name; 631015d818bSTodd Fiala 632015d818bSTodd Fiala if (IsRemote() && m_remote_platform_sp) 633015d818bSTodd Fiala return m_remote_platform_sp->GetUserName(uid); 634015d818bSTodd Fiala return NULL; 635015d818bSTodd Fiala } 636015d818bSTodd Fiala 637015d818bSTodd Fiala const char * 638015d818bSTodd Fiala PlatformPOSIX::GetGroupName (uint32_t gid) 639015d818bSTodd Fiala { 640015d818bSTodd Fiala const char *group_name = Platform::GetGroupName(gid); 641015d818bSTodd Fiala if (group_name) 642015d818bSTodd Fiala return group_name; 643015d818bSTodd Fiala 644015d818bSTodd Fiala if (IsRemote() && m_remote_platform_sp) 645015d818bSTodd Fiala return m_remote_platform_sp->GetGroupName(gid); 646015d818bSTodd Fiala return NULL; 647015d818bSTodd Fiala } 648015d818bSTodd Fiala 649015d818bSTodd Fiala Error 650015d818bSTodd Fiala PlatformPOSIX::ConnectRemote (Args& args) 651015d818bSTodd Fiala { 652015d818bSTodd Fiala Error error; 653015d818bSTodd Fiala if (IsHost()) 654015d818bSTodd Fiala { 655015d818bSTodd Fiala error.SetErrorStringWithFormat ("can't connect to the host platform '%s', always connected", GetPluginName().GetCString()); 656015d818bSTodd Fiala } 657015d818bSTodd Fiala else 658015d818bSTodd Fiala { 659015d818bSTodd Fiala if (!m_remote_platform_sp) 660615eb7e6SGreg Clayton m_remote_platform_sp = Platform::Create (ConstString("remote-gdb-server"), error); 661015d818bSTodd Fiala 662015d818bSTodd Fiala if (m_remote_platform_sp && error.Success()) 663015d818bSTodd Fiala error = m_remote_platform_sp->ConnectRemote (args); 664015d818bSTodd Fiala else 665015d818bSTodd Fiala error.SetErrorString ("failed to create a 'remote-gdb-server' platform"); 666015d818bSTodd Fiala 667015d818bSTodd Fiala if (error.Fail()) 668015d818bSTodd Fiala m_remote_platform_sp.reset(); 669015d818bSTodd Fiala } 670015d818bSTodd Fiala 671015d818bSTodd Fiala if (error.Success() && m_remote_platform_sp) 672015d818bSTodd Fiala { 673015d818bSTodd Fiala if (m_options.get()) 674015d818bSTodd Fiala { 675015d818bSTodd Fiala OptionGroupOptions* options = m_options.get(); 676*ba507b04SSaleem Abdulrasool const OptionGroupPlatformRSync *m_rsync_options = 677*ba507b04SSaleem Abdulrasool static_cast<const OptionGroupPlatformRSync *>(options->GetGroupWithOption('r')); 678*ba507b04SSaleem Abdulrasool const OptionGroupPlatformSSH *m_ssh_options = 679*ba507b04SSaleem Abdulrasool static_cast<const OptionGroupPlatformSSH *>(options->GetGroupWithOption('s')); 680*ba507b04SSaleem Abdulrasool const OptionGroupPlatformCaching *m_cache_options = 681*ba507b04SSaleem Abdulrasool static_cast<const OptionGroupPlatformCaching *>(options->GetGroupWithOption('c')); 682015d818bSTodd Fiala 683015d818bSTodd Fiala if (m_rsync_options->m_rsync) 684015d818bSTodd Fiala { 685015d818bSTodd Fiala SetSupportsRSync(true); 686015d818bSTodd Fiala SetRSyncOpts(m_rsync_options->m_rsync_opts.c_str()); 687015d818bSTodd Fiala SetRSyncPrefix(m_rsync_options->m_rsync_prefix.c_str()); 688015d818bSTodd Fiala SetIgnoresRemoteHostname(m_rsync_options->m_ignores_remote_hostname); 689015d818bSTodd Fiala } 690015d818bSTodd Fiala if (m_ssh_options->m_ssh) 691015d818bSTodd Fiala { 692015d818bSTodd Fiala SetSupportsSSH(true); 693015d818bSTodd Fiala SetSSHOpts(m_ssh_options->m_ssh_opts.c_str()); 694015d818bSTodd Fiala } 695015d818bSTodd Fiala SetLocalCacheDirectory(m_cache_options->m_cache_dir.c_str()); 696015d818bSTodd Fiala } 697015d818bSTodd Fiala } 698015d818bSTodd Fiala 699015d818bSTodd Fiala return error; 700015d818bSTodd Fiala } 701015d818bSTodd Fiala 702015d818bSTodd Fiala Error 703015d818bSTodd Fiala PlatformPOSIX::DisconnectRemote () 704015d818bSTodd Fiala { 705015d818bSTodd Fiala Error error; 706015d818bSTodd Fiala 707015d818bSTodd Fiala if (IsHost()) 708015d818bSTodd Fiala { 709015d818bSTodd Fiala error.SetErrorStringWithFormat ("can't disconnect from the host platform '%s', always connected", GetPluginName().GetCString()); 710015d818bSTodd Fiala } 711015d818bSTodd Fiala else 712015d818bSTodd Fiala { 713015d818bSTodd Fiala if (m_remote_platform_sp) 714015d818bSTodd Fiala error = m_remote_platform_sp->DisconnectRemote (); 715015d818bSTodd Fiala else 716015d818bSTodd Fiala error.SetErrorString ("the platform is not currently connected"); 717015d818bSTodd Fiala } 718015d818bSTodd Fiala return error; 719015d818bSTodd Fiala } 720015d818bSTodd Fiala 721348fb385STodd Fiala Error 722348fb385STodd Fiala PlatformPOSIX::LaunchProcess (ProcessLaunchInfo &launch_info) 723348fb385STodd Fiala { 724348fb385STodd Fiala Error error; 725348fb385STodd Fiala 726348fb385STodd Fiala if (IsHost()) 727348fb385STodd Fiala { 728348fb385STodd Fiala error = Platform::LaunchProcess (launch_info); 729348fb385STodd Fiala } 730348fb385STodd Fiala else 731348fb385STodd Fiala { 732348fb385STodd Fiala if (m_remote_platform_sp) 733348fb385STodd Fiala error = m_remote_platform_sp->LaunchProcess (launch_info); 734348fb385STodd Fiala else 735348fb385STodd Fiala error.SetErrorString ("the platform is not currently connected"); 736348fb385STodd Fiala } 737348fb385STodd Fiala return error; 738348fb385STodd Fiala } 739348fb385STodd Fiala 74009daa881SOleksiy Vyalov lldb_private::Error 74109daa881SOleksiy Vyalov PlatformPOSIX::KillProcess (const lldb::pid_t pid) 74209daa881SOleksiy Vyalov { 74309daa881SOleksiy Vyalov if (IsHost()) 74409daa881SOleksiy Vyalov return Platform::KillProcess (pid); 74509daa881SOleksiy Vyalov 74609daa881SOleksiy Vyalov if (m_remote_platform_sp) 74709daa881SOleksiy Vyalov return m_remote_platform_sp->KillProcess (pid); 74809daa881SOleksiy Vyalov 74909daa881SOleksiy Vyalov return Error ("the platform is not currently connected"); 75009daa881SOleksiy Vyalov } 75109daa881SOleksiy Vyalov 752348fb385STodd Fiala lldb::ProcessSP 753348fb385STodd Fiala PlatformPOSIX::Attach (ProcessAttachInfo &attach_info, 754348fb385STodd Fiala Debugger &debugger, 755348fb385STodd Fiala Target *target, 756348fb385STodd Fiala Error &error) 757348fb385STodd Fiala { 758348fb385STodd Fiala lldb::ProcessSP process_sp; 759348fb385STodd Fiala Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM)); 760348fb385STodd Fiala 761348fb385STodd Fiala if (IsHost()) 762348fb385STodd Fiala { 763348fb385STodd Fiala if (target == NULL) 764348fb385STodd Fiala { 765348fb385STodd Fiala TargetSP new_target_sp; 766348fb385STodd Fiala 767348fb385STodd Fiala error = debugger.GetTargetList().CreateTarget (debugger, 768348fb385STodd Fiala NULL, 769348fb385STodd Fiala NULL, 770348fb385STodd Fiala false, 771348fb385STodd Fiala NULL, 772348fb385STodd Fiala new_target_sp); 773348fb385STodd Fiala target = new_target_sp.get(); 774348fb385STodd Fiala if (log) 775348fb385STodd Fiala log->Printf ("PlatformPOSIX::%s created new target", __FUNCTION__); 776348fb385STodd Fiala } 777348fb385STodd Fiala else 778348fb385STodd Fiala { 779348fb385STodd Fiala error.Clear(); 780348fb385STodd Fiala if (log) 781348fb385STodd Fiala log->Printf ("PlatformPOSIX::%s target already existed, setting target", __FUNCTION__); 782348fb385STodd Fiala } 783348fb385STodd Fiala 784348fb385STodd Fiala if (target && error.Success()) 785348fb385STodd Fiala { 786348fb385STodd Fiala debugger.GetTargetList().SetSelectedTarget(target); 787348fb385STodd Fiala if (log) 788348fb385STodd Fiala { 789348fb385STodd Fiala ModuleSP exe_module_sp = target->GetExecutableModule (); 790129b839dSDavid Blaikie log->Printf("PlatformPOSIX::%s set selected target to %p %s", __FUNCTION__, (void *)target, 791348fb385STodd Fiala exe_module_sp ? exe_module_sp->GetFileSpec().GetPath().c_str() : "<null>"); 792348fb385STodd Fiala } 793348fb385STodd Fiala 794348fb385STodd Fiala 7958012cadbSGreg Clayton process_sp = target->CreateProcess (attach_info.GetListenerForProcess(debugger), attach_info.GetProcessPluginName(), NULL); 796348fb385STodd Fiala 797348fb385STodd Fiala if (process_sp) 798348fb385STodd Fiala { 799926af0cdSOleksiy Vyalov auto listener_sp = attach_info.GetHijackListener(); 800926af0cdSOleksiy Vyalov if (listener_sp == nullptr) 801926af0cdSOleksiy Vyalov { 802926af0cdSOleksiy Vyalov listener_sp.reset(new Listener("lldb.PlatformPOSIX.attach.hijack")); 803348fb385STodd Fiala attach_info.SetHijackListener(listener_sp); 804926af0cdSOleksiy Vyalov } 805348fb385STodd Fiala process_sp->HijackProcessEvents(listener_sp.get()); 806348fb385STodd Fiala error = process_sp->Attach (attach_info); 807348fb385STodd Fiala } 808348fb385STodd Fiala } 809348fb385STodd Fiala } 810348fb385STodd Fiala else 811348fb385STodd Fiala { 812348fb385STodd Fiala if (m_remote_platform_sp) 8138012cadbSGreg Clayton process_sp = m_remote_platform_sp->Attach (attach_info, debugger, target, error); 814348fb385STodd Fiala else 815348fb385STodd Fiala error.SetErrorString ("the platform is not currently connected"); 816348fb385STodd Fiala } 817348fb385STodd Fiala return process_sp; 818348fb385STodd Fiala } 819348fb385STodd Fiala 820015d818bSTodd Fiala lldb::ProcessSP 821015d818bSTodd Fiala PlatformPOSIX::DebugProcess (ProcessLaunchInfo &launch_info, 822015d818bSTodd Fiala Debugger &debugger, 823015d818bSTodd Fiala Target *target, // Can be NULL, if NULL create a new target, else use existing one 824015d818bSTodd Fiala Error &error) 825015d818bSTodd Fiala { 826015d818bSTodd Fiala ProcessSP process_sp; 827015d818bSTodd Fiala 828015d818bSTodd Fiala if (IsHost()) 829015d818bSTodd Fiala { 830015d818bSTodd Fiala // We are going to hand this process off to debugserver which will be in charge of setting the exit status. 831015d818bSTodd Fiala // We still need to reap it from lldb but if we let the monitor thread also set the exit status, we set up a 832015d818bSTodd Fiala // race between debugserver & us for who will find out about the debugged process's death. 833015d818bSTodd Fiala launch_info.GetFlags().Set(eLaunchFlagDontSetExitStatus); 8348012cadbSGreg Clayton process_sp = Platform::DebugProcess (launch_info, debugger, target, error); 835015d818bSTodd Fiala } 836015d818bSTodd Fiala else 837015d818bSTodd Fiala { 838015d818bSTodd Fiala if (m_remote_platform_sp) 8398012cadbSGreg Clayton process_sp = m_remote_platform_sp->DebugProcess (launch_info, debugger, target, error); 840015d818bSTodd Fiala else 841015d818bSTodd Fiala error.SetErrorString ("the platform is not currently connected"); 842015d818bSTodd Fiala } 843015d818bSTodd Fiala return process_sp; 844015d818bSTodd Fiala 845015d818bSTodd Fiala } 846015d818bSTodd Fiala 8472094dbf4SJason Molenda void 8482094dbf4SJason Molenda PlatformPOSIX::CalculateTrapHandlerSymbolNames () 8492094dbf4SJason Molenda { 8502094dbf4SJason Molenda m_trap_handlers.push_back (ConstString ("_sigtramp")); 8512094dbf4SJason Molenda } 852