1 //===-- PlatformPOSIX.cpp ---------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "PlatformPOSIX.h" 11 12 // C Includes 13 // C++ Includes 14 // Other libraries and framework includes 15 // Project includes 16 17 #include "lldb/Core/Debugger.h" 18 #include "lldb/Core/Module.h" 19 #include "lldb/Core/ModuleSpec.h" 20 #include "lldb/Core/ValueObject.h" 21 #include "lldb/Expression/DiagnosticManager.h" 22 #include "lldb/Expression/FunctionCaller.h" 23 #include "lldb/Expression/UserExpression.h" 24 #include "lldb/Expression/UtilityFunction.h" 25 #include "lldb/Host/File.h" 26 #include "lldb/Host/FileCache.h" 27 #include "lldb/Host/FileSystem.h" 28 #include "lldb/Host/Host.h" 29 #include "lldb/Host/HostInfo.h" 30 #include "lldb/Symbol/ClangASTContext.h" 31 #include "lldb/Target/DynamicLoader.h" 32 #include "lldb/Target/ExecutionContext.h" 33 #include "lldb/Target/Process.h" 34 #include "lldb/Target/ProcessLaunchInfo.h" 35 #include "lldb/Target/Thread.h" 36 #include "lldb/Utility/CleanUp.h" 37 #include "lldb/Utility/DataBufferHeap.h" 38 #include "lldb/Utility/FileSpec.h" 39 #include "lldb/Utility/Log.h" 40 #include "lldb/Utility/StreamString.h" 41 42 using namespace lldb; 43 using namespace lldb_private; 44 45 //------------------------------------------------------------------ 46 /// Default Constructor 47 //------------------------------------------------------------------ 48 PlatformPOSIX::PlatformPOSIX(bool is_host) 49 : Platform(is_host), // This is the local host platform 50 m_option_group_platform_rsync(new OptionGroupPlatformRSync()), 51 m_option_group_platform_ssh(new OptionGroupPlatformSSH()), 52 m_option_group_platform_caching(new OptionGroupPlatformCaching()), 53 m_remote_platform_sp() {} 54 55 //------------------------------------------------------------------ 56 /// Destructor. 57 /// 58 /// The destructor is virtual since this class is designed to be 59 /// inherited from by the plug-in instance. 60 //------------------------------------------------------------------ 61 PlatformPOSIX::~PlatformPOSIX() {} 62 63 bool PlatformPOSIX::GetModuleSpec(const FileSpec &module_file_spec, 64 const ArchSpec &arch, 65 ModuleSpec &module_spec) { 66 if (m_remote_platform_sp) 67 return m_remote_platform_sp->GetModuleSpec(module_file_spec, arch, 68 module_spec); 69 70 return Platform::GetModuleSpec(module_file_spec, arch, module_spec); 71 } 72 73 lldb_private::OptionGroupOptions *PlatformPOSIX::GetConnectionOptions( 74 lldb_private::CommandInterpreter &interpreter) { 75 auto iter = m_options.find(&interpreter), end = m_options.end(); 76 if (iter == end) { 77 std::unique_ptr<lldb_private::OptionGroupOptions> options( 78 new OptionGroupOptions()); 79 options->Append(m_option_group_platform_rsync.get()); 80 options->Append(m_option_group_platform_ssh.get()); 81 options->Append(m_option_group_platform_caching.get()); 82 m_options[&interpreter] = std::move(options); 83 } 84 85 return m_options.at(&interpreter).get(); 86 } 87 88 bool PlatformPOSIX::IsConnected() const { 89 if (IsHost()) 90 return true; 91 else if (m_remote_platform_sp) 92 return m_remote_platform_sp->IsConnected(); 93 return false; 94 } 95 96 lldb_private::Status PlatformPOSIX::RunShellCommand( 97 const char *command, // Shouldn't be NULL 98 const FileSpec & 99 working_dir, // Pass empty FileSpec to use the current working directory 100 int *status_ptr, // Pass NULL if you don't want the process exit status 101 int *signo_ptr, // Pass NULL if you don't want the signal that caused the 102 // process to exit 103 std::string 104 *command_output, // Pass NULL if you don't want the command output 105 const Timeout<std::micro> &timeout) { 106 if (IsHost()) 107 return Host::RunShellCommand(command, working_dir, status_ptr, signo_ptr, 108 command_output, timeout); 109 else { 110 if (m_remote_platform_sp) 111 return m_remote_platform_sp->RunShellCommand( 112 command, working_dir, status_ptr, signo_ptr, command_output, timeout); 113 else 114 return Status("unable to run a remote command without a platform"); 115 } 116 } 117 118 Status 119 PlatformPOSIX::ResolveExecutable(const ModuleSpec &module_spec, 120 lldb::ModuleSP &exe_module_sp, 121 const FileSpecList *module_search_paths_ptr) { 122 Status error; 123 // Nothing special to do here, just use the actual file and architecture 124 125 char exe_path[PATH_MAX]; 126 ModuleSpec resolved_module_spec(module_spec); 127 128 if (IsHost()) { 129 // If we have "ls" as the exe_file, resolve the executable location based 130 // on the current path variables 131 if (!resolved_module_spec.GetFileSpec().Exists()) { 132 resolved_module_spec.GetFileSpec().GetPath(exe_path, sizeof(exe_path)); 133 resolved_module_spec.GetFileSpec().SetFile(exe_path, true, 134 FileSpec::Style::native); 135 } 136 137 if (!resolved_module_spec.GetFileSpec().Exists()) 138 resolved_module_spec.GetFileSpec().ResolveExecutableLocation(); 139 140 // Resolve any executable within a bundle on MacOSX 141 Host::ResolveExecutableInBundle(resolved_module_spec.GetFileSpec()); 142 143 if (resolved_module_spec.GetFileSpec().Exists()) 144 error.Clear(); 145 else { 146 const uint32_t permissions = 147 resolved_module_spec.GetFileSpec().GetPermissions(); 148 if (permissions && (permissions & eFilePermissionsEveryoneR) == 0) 149 error.SetErrorStringWithFormat( 150 "executable '%s' is not readable", 151 resolved_module_spec.GetFileSpec().GetPath().c_str()); 152 else 153 error.SetErrorStringWithFormat( 154 "unable to find executable for '%s'", 155 resolved_module_spec.GetFileSpec().GetPath().c_str()); 156 } 157 } else { 158 if (m_remote_platform_sp) { 159 error = 160 GetCachedExecutable(resolved_module_spec, exe_module_sp, 161 module_search_paths_ptr, *m_remote_platform_sp); 162 } else { 163 // We may connect to a process and use the provided executable (Don't use 164 // local $PATH). 165 166 // Resolve any executable within a bundle on MacOSX 167 Host::ResolveExecutableInBundle(resolved_module_spec.GetFileSpec()); 168 169 if (resolved_module_spec.GetFileSpec().Exists()) 170 error.Clear(); 171 else 172 error.SetErrorStringWithFormat("the platform is not currently " 173 "connected, and '%s' doesn't exist in " 174 "the system root.", 175 exe_path); 176 } 177 } 178 179 if (error.Success()) { 180 if (resolved_module_spec.GetArchitecture().IsValid()) { 181 error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp, 182 module_search_paths_ptr, nullptr, nullptr); 183 if (error.Fail()) { 184 // If we failed, it may be because the vendor and os aren't known. If 185 // that is the case, try setting them to the host architecture and give 186 // it another try. 187 llvm::Triple &module_triple = 188 resolved_module_spec.GetArchitecture().GetTriple(); 189 bool is_vendor_specified = 190 (module_triple.getVendor() != llvm::Triple::UnknownVendor); 191 bool is_os_specified = 192 (module_triple.getOS() != llvm::Triple::UnknownOS); 193 if (!is_vendor_specified || !is_os_specified) { 194 const llvm::Triple &host_triple = 195 HostInfo::GetArchitecture(HostInfo::eArchKindDefault).GetTriple(); 196 197 if (!is_vendor_specified) 198 module_triple.setVendorName(host_triple.getVendorName()); 199 if (!is_os_specified) 200 module_triple.setOSName(host_triple.getOSName()); 201 202 error = ModuleList::GetSharedModule(resolved_module_spec, 203 exe_module_sp, module_search_paths_ptr, nullptr, nullptr); 204 } 205 } 206 207 // TODO find out why exe_module_sp might be NULL 208 if (error.Fail() || !exe_module_sp || !exe_module_sp->GetObjectFile()) { 209 exe_module_sp.reset(); 210 error.SetErrorStringWithFormat( 211 "'%s' doesn't contain the architecture %s", 212 resolved_module_spec.GetFileSpec().GetPath().c_str(), 213 resolved_module_spec.GetArchitecture().GetArchitectureName()); 214 } 215 } else { 216 // No valid architecture was specified, ask the platform for the 217 // architectures that we should be using (in the correct order) and see 218 // if we can find a match that way 219 StreamString arch_names; 220 for (uint32_t idx = 0; GetSupportedArchitectureAtIndex( 221 idx, resolved_module_spec.GetArchitecture()); 222 ++idx) { 223 error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp, 224 module_search_paths_ptr, nullptr, nullptr); 225 // Did we find an executable using one of the 226 if (error.Success()) { 227 if (exe_module_sp && exe_module_sp->GetObjectFile()) 228 break; 229 else 230 error.SetErrorToGenericError(); 231 } 232 233 if (idx > 0) 234 arch_names.PutCString(", "); 235 arch_names.PutCString( 236 resolved_module_spec.GetArchitecture().GetArchitectureName()); 237 } 238 239 if (error.Fail() || !exe_module_sp) { 240 if (resolved_module_spec.GetFileSpec().Readable()) { 241 error.SetErrorStringWithFormat( 242 "'%s' doesn't contain any '%s' platform architectures: %s", 243 resolved_module_spec.GetFileSpec().GetPath().c_str(), 244 GetPluginName().GetCString(), arch_names.GetData()); 245 } else { 246 error.SetErrorStringWithFormat( 247 "'%s' is not readable", 248 resolved_module_spec.GetFileSpec().GetPath().c_str()); 249 } 250 } 251 } 252 } 253 254 return error; 255 } 256 257 Status PlatformPOSIX::GetFileWithUUID(const FileSpec &platform_file, 258 const UUID *uuid_ptr, 259 FileSpec &local_file) { 260 if (IsRemote() && m_remote_platform_sp) 261 return m_remote_platform_sp->GetFileWithUUID(platform_file, uuid_ptr, 262 local_file); 263 264 // Default to the local case 265 local_file = platform_file; 266 return Status(); 267 } 268 269 bool PlatformPOSIX::GetProcessInfo(lldb::pid_t pid, 270 ProcessInstanceInfo &process_info) { 271 if (IsHost()) 272 return Platform::GetProcessInfo(pid, process_info); 273 if (m_remote_platform_sp) 274 return m_remote_platform_sp->GetProcessInfo(pid, process_info); 275 return false; 276 } 277 278 uint32_t 279 PlatformPOSIX::FindProcesses(const ProcessInstanceInfoMatch &match_info, 280 ProcessInstanceInfoList &process_infos) { 281 if (IsHost()) 282 return Platform::FindProcesses(match_info, process_infos); 283 if (m_remote_platform_sp) 284 return 285 m_remote_platform_sp->FindProcesses(match_info, process_infos); 286 return 0; 287 } 288 289 Status PlatformPOSIX::MakeDirectory(const FileSpec &file_spec, 290 uint32_t file_permissions) { 291 if (m_remote_platform_sp) 292 return m_remote_platform_sp->MakeDirectory(file_spec, file_permissions); 293 else 294 return Platform::MakeDirectory(file_spec, file_permissions); 295 } 296 297 Status PlatformPOSIX::GetFilePermissions(const FileSpec &file_spec, 298 uint32_t &file_permissions) { 299 if (m_remote_platform_sp) 300 return m_remote_platform_sp->GetFilePermissions(file_spec, 301 file_permissions); 302 else 303 return Platform::GetFilePermissions(file_spec, file_permissions); 304 } 305 306 Status PlatformPOSIX::SetFilePermissions(const FileSpec &file_spec, 307 uint32_t file_permissions) { 308 if (m_remote_platform_sp) 309 return m_remote_platform_sp->SetFilePermissions(file_spec, 310 file_permissions); 311 else 312 return Platform::SetFilePermissions(file_spec, file_permissions); 313 } 314 315 lldb::user_id_t PlatformPOSIX::OpenFile(const FileSpec &file_spec, 316 uint32_t flags, uint32_t mode, 317 Status &error) { 318 if (IsHost()) 319 return FileCache::GetInstance().OpenFile(file_spec, flags, mode, error); 320 else if (m_remote_platform_sp) 321 return m_remote_platform_sp->OpenFile(file_spec, flags, mode, error); 322 else 323 return Platform::OpenFile(file_spec, flags, mode, error); 324 } 325 326 bool PlatformPOSIX::CloseFile(lldb::user_id_t fd, Status &error) { 327 if (IsHost()) 328 return FileCache::GetInstance().CloseFile(fd, error); 329 else if (m_remote_platform_sp) 330 return m_remote_platform_sp->CloseFile(fd, error); 331 else 332 return Platform::CloseFile(fd, error); 333 } 334 335 uint64_t PlatformPOSIX::ReadFile(lldb::user_id_t fd, uint64_t offset, void *dst, 336 uint64_t dst_len, Status &error) { 337 if (IsHost()) 338 return FileCache::GetInstance().ReadFile(fd, offset, dst, dst_len, error); 339 else if (m_remote_platform_sp) 340 return m_remote_platform_sp->ReadFile(fd, offset, dst, dst_len, error); 341 else 342 return Platform::ReadFile(fd, offset, dst, dst_len, error); 343 } 344 345 uint64_t PlatformPOSIX::WriteFile(lldb::user_id_t fd, uint64_t offset, 346 const void *src, uint64_t src_len, 347 Status &error) { 348 if (IsHost()) 349 return FileCache::GetInstance().WriteFile(fd, offset, src, src_len, error); 350 else if (m_remote_platform_sp) 351 return m_remote_platform_sp->WriteFile(fd, offset, src, src_len, error); 352 else 353 return Platform::WriteFile(fd, offset, src, src_len, error); 354 } 355 356 static uint32_t chown_file(Platform *platform, const char *path, 357 uint32_t uid = UINT32_MAX, 358 uint32_t gid = UINT32_MAX) { 359 if (!platform || !path || *path == 0) 360 return UINT32_MAX; 361 362 if (uid == UINT32_MAX && gid == UINT32_MAX) 363 return 0; // pretend I did chown correctly - actually I just didn't care 364 365 StreamString command; 366 command.PutCString("chown "); 367 if (uid != UINT32_MAX) 368 command.Printf("%d", uid); 369 if (gid != UINT32_MAX) 370 command.Printf(":%d", gid); 371 command.Printf("%s", path); 372 int status; 373 platform->RunShellCommand(command.GetData(), NULL, &status, NULL, NULL, 374 std::chrono::seconds(10)); 375 return status; 376 } 377 378 lldb_private::Status 379 PlatformPOSIX::PutFile(const lldb_private::FileSpec &source, 380 const lldb_private::FileSpec &destination, uint32_t uid, 381 uint32_t gid) { 382 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM)); 383 384 if (IsHost()) { 385 if (FileSpec::Equal(source, destination, true)) 386 return Status(); 387 // cp src dst 388 // chown uid:gid dst 389 std::string src_path(source.GetPath()); 390 if (src_path.empty()) 391 return Status("unable to get file path for source"); 392 std::string dst_path(destination.GetPath()); 393 if (dst_path.empty()) 394 return Status("unable to get file path for destination"); 395 StreamString command; 396 command.Printf("cp %s %s", src_path.c_str(), dst_path.c_str()); 397 int status; 398 RunShellCommand(command.GetData(), NULL, &status, NULL, NULL, 399 std::chrono::seconds(10)); 400 if (status != 0) 401 return Status("unable to perform copy"); 402 if (uid == UINT32_MAX && gid == UINT32_MAX) 403 return Status(); 404 if (chown_file(this, dst_path.c_str(), uid, gid) != 0) 405 return Status("unable to perform chown"); 406 return Status(); 407 } else if (m_remote_platform_sp) { 408 if (GetSupportsRSync()) { 409 std::string src_path(source.GetPath()); 410 if (src_path.empty()) 411 return Status("unable to get file path for source"); 412 std::string dst_path(destination.GetPath()); 413 if (dst_path.empty()) 414 return Status("unable to get file path for destination"); 415 StreamString command; 416 if (GetIgnoresRemoteHostname()) { 417 if (!GetRSyncPrefix()) 418 command.Printf("rsync %s %s %s", GetRSyncOpts(), src_path.c_str(), 419 dst_path.c_str()); 420 else 421 command.Printf("rsync %s %s %s%s", GetRSyncOpts(), src_path.c_str(), 422 GetRSyncPrefix(), dst_path.c_str()); 423 } else 424 command.Printf("rsync %s %s %s:%s", GetRSyncOpts(), src_path.c_str(), 425 GetHostname(), dst_path.c_str()); 426 if (log) 427 log->Printf("[PutFile] Running command: %s\n", command.GetData()); 428 int retcode; 429 Host::RunShellCommand(command.GetData(), NULL, &retcode, NULL, NULL, 430 std::chrono::minutes(1)); 431 if (retcode == 0) { 432 // Don't chown a local file for a remote system 433 // if (chown_file(this,dst_path.c_str(),uid,gid) != 0) 434 // return Status("unable to perform chown"); 435 return Status(); 436 } 437 // if we are still here rsync has failed - let's try the slow way before 438 // giving up 439 } 440 } 441 return Platform::PutFile(source, destination, uid, gid); 442 } 443 444 lldb::user_id_t PlatformPOSIX::GetFileSize(const FileSpec &file_spec) { 445 if (IsHost()) { 446 uint64_t Size; 447 if (llvm::sys::fs::file_size(file_spec.GetPath(), Size)) 448 return 0; 449 return Size; 450 } else if (m_remote_platform_sp) 451 return m_remote_platform_sp->GetFileSize(file_spec); 452 else 453 return Platform::GetFileSize(file_spec); 454 } 455 456 Status PlatformPOSIX::CreateSymlink(const FileSpec &src, const FileSpec &dst) { 457 if (IsHost()) 458 return FileSystem::Symlink(src, dst); 459 else if (m_remote_platform_sp) 460 return m_remote_platform_sp->CreateSymlink(src, dst); 461 else 462 return Platform::CreateSymlink(src, dst); 463 } 464 465 bool PlatformPOSIX::GetFileExists(const FileSpec &file_spec) { 466 if (IsHost()) 467 return file_spec.Exists(); 468 else if (m_remote_platform_sp) 469 return m_remote_platform_sp->GetFileExists(file_spec); 470 else 471 return Platform::GetFileExists(file_spec); 472 } 473 474 Status PlatformPOSIX::Unlink(const FileSpec &file_spec) { 475 if (IsHost()) 476 return llvm::sys::fs::remove(file_spec.GetPath()); 477 else if (m_remote_platform_sp) 478 return m_remote_platform_sp->Unlink(file_spec); 479 else 480 return Platform::Unlink(file_spec); 481 } 482 483 lldb_private::Status PlatformPOSIX::GetFile( 484 const lldb_private::FileSpec &source, // remote file path 485 const lldb_private::FileSpec &destination) // local file path 486 { 487 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM)); 488 489 // Check the args, first. 490 std::string src_path(source.GetPath()); 491 if (src_path.empty()) 492 return Status("unable to get file path for source"); 493 std::string dst_path(destination.GetPath()); 494 if (dst_path.empty()) 495 return Status("unable to get file path for destination"); 496 if (IsHost()) { 497 if (FileSpec::Equal(source, destination, true)) 498 return Status("local scenario->source and destination are the same file " 499 "path: no operation performed"); 500 // cp src dst 501 StreamString cp_command; 502 cp_command.Printf("cp %s %s", src_path.c_str(), dst_path.c_str()); 503 int status; 504 RunShellCommand(cp_command.GetData(), NULL, &status, NULL, NULL, 505 std::chrono::seconds(10)); 506 if (status != 0) 507 return Status("unable to perform copy"); 508 return Status(); 509 } else if (m_remote_platform_sp) { 510 if (GetSupportsRSync()) { 511 StreamString command; 512 if (GetIgnoresRemoteHostname()) { 513 if (!GetRSyncPrefix()) 514 command.Printf("rsync %s %s %s", GetRSyncOpts(), src_path.c_str(), 515 dst_path.c_str()); 516 else 517 command.Printf("rsync %s %s%s %s", GetRSyncOpts(), GetRSyncPrefix(), 518 src_path.c_str(), dst_path.c_str()); 519 } else 520 command.Printf("rsync %s %s:%s %s", GetRSyncOpts(), 521 m_remote_platform_sp->GetHostname(), src_path.c_str(), 522 dst_path.c_str()); 523 if (log) 524 log->Printf("[GetFile] Running command: %s\n", command.GetData()); 525 int retcode; 526 Host::RunShellCommand(command.GetData(), NULL, &retcode, NULL, NULL, 527 std::chrono::minutes(1)); 528 if (retcode == 0) 529 return Status(); 530 // If we are here, rsync has failed - let's try the slow way before 531 // giving up 532 } 533 // open src and dst 534 // read/write, read/write, read/write, ... 535 // close src 536 // close dst 537 if (log) 538 log->Printf("[GetFile] Using block by block transfer....\n"); 539 Status error; 540 user_id_t fd_src = OpenFile(source, File::eOpenOptionRead, 541 lldb::eFilePermissionsFileDefault, error); 542 543 if (fd_src == UINT64_MAX) 544 return Status("unable to open source file"); 545 546 uint32_t permissions = 0; 547 error = GetFilePermissions(source, permissions); 548 549 if (permissions == 0) 550 permissions = lldb::eFilePermissionsFileDefault; 551 552 user_id_t fd_dst = FileCache::GetInstance().OpenFile( 553 destination, File::eOpenOptionCanCreate | File::eOpenOptionWrite | 554 File::eOpenOptionTruncate, 555 permissions, error); 556 557 if (fd_dst == UINT64_MAX) { 558 if (error.Success()) 559 error.SetErrorString("unable to open destination file"); 560 } 561 562 if (error.Success()) { 563 lldb::DataBufferSP buffer_sp(new DataBufferHeap(1024, 0)); 564 uint64_t offset = 0; 565 error.Clear(); 566 while (error.Success()) { 567 const uint64_t n_read = ReadFile(fd_src, offset, buffer_sp->GetBytes(), 568 buffer_sp->GetByteSize(), error); 569 if (error.Fail()) 570 break; 571 if (n_read == 0) 572 break; 573 if (FileCache::GetInstance().WriteFile(fd_dst, offset, 574 buffer_sp->GetBytes(), n_read, 575 error) != n_read) { 576 if (!error.Fail()) 577 error.SetErrorString("unable to write to destination file"); 578 break; 579 } 580 offset += n_read; 581 } 582 } 583 // Ignore the close error of src. 584 if (fd_src != UINT64_MAX) 585 CloseFile(fd_src, error); 586 // And close the dst file descriptot. 587 if (fd_dst != UINT64_MAX && 588 !FileCache::GetInstance().CloseFile(fd_dst, error)) { 589 if (!error.Fail()) 590 error.SetErrorString("unable to close destination file"); 591 } 592 return error; 593 } 594 return Platform::GetFile(source, destination); 595 } 596 597 std::string PlatformPOSIX::GetPlatformSpecificConnectionInformation() { 598 StreamString stream; 599 if (GetSupportsRSync()) { 600 stream.PutCString("rsync"); 601 if ((GetRSyncOpts() && *GetRSyncOpts()) || 602 (GetRSyncPrefix() && *GetRSyncPrefix()) || GetIgnoresRemoteHostname()) { 603 stream.Printf(", options: "); 604 if (GetRSyncOpts() && *GetRSyncOpts()) 605 stream.Printf("'%s' ", GetRSyncOpts()); 606 stream.Printf(", prefix: "); 607 if (GetRSyncPrefix() && *GetRSyncPrefix()) 608 stream.Printf("'%s' ", GetRSyncPrefix()); 609 if (GetIgnoresRemoteHostname()) 610 stream.Printf("ignore remote-hostname "); 611 } 612 } 613 if (GetSupportsSSH()) { 614 stream.PutCString("ssh"); 615 if (GetSSHOpts() && *GetSSHOpts()) 616 stream.Printf(", options: '%s' ", GetSSHOpts()); 617 } 618 if (GetLocalCacheDirectory() && *GetLocalCacheDirectory()) 619 stream.Printf("cache dir: %s", GetLocalCacheDirectory()); 620 if (stream.GetSize()) 621 return stream.GetString(); 622 else 623 return ""; 624 } 625 626 bool PlatformPOSIX::CalculateMD5(const FileSpec &file_spec, uint64_t &low, 627 uint64_t &high) { 628 if (IsHost()) 629 return Platform::CalculateMD5(file_spec, low, high); 630 if (m_remote_platform_sp) 631 return m_remote_platform_sp->CalculateMD5(file_spec, low, high); 632 return false; 633 } 634 635 const lldb::UnixSignalsSP &PlatformPOSIX::GetRemoteUnixSignals() { 636 if (IsRemote() && m_remote_platform_sp) 637 return m_remote_platform_sp->GetRemoteUnixSignals(); 638 return Platform::GetRemoteUnixSignals(); 639 } 640 641 FileSpec PlatformPOSIX::GetRemoteWorkingDirectory() { 642 if (IsRemote() && m_remote_platform_sp) 643 return m_remote_platform_sp->GetRemoteWorkingDirectory(); 644 else 645 return Platform::GetRemoteWorkingDirectory(); 646 } 647 648 bool PlatformPOSIX::SetRemoteWorkingDirectory(const FileSpec &working_dir) { 649 if (IsRemote() && m_remote_platform_sp) 650 return m_remote_platform_sp->SetRemoteWorkingDirectory(working_dir); 651 else 652 return Platform::SetRemoteWorkingDirectory(working_dir); 653 } 654 655 bool PlatformPOSIX::GetRemoteOSVersion() { 656 if (m_remote_platform_sp) { 657 m_os_version = m_remote_platform_sp->GetOSVersion(); 658 return !m_os_version.empty(); 659 } 660 return false; 661 } 662 663 bool PlatformPOSIX::GetRemoteOSBuildString(std::string &s) { 664 if (m_remote_platform_sp) 665 return m_remote_platform_sp->GetRemoteOSBuildString(s); 666 s.clear(); 667 return false; 668 } 669 670 Environment PlatformPOSIX::GetEnvironment() { 671 if (IsRemote()) { 672 if (m_remote_platform_sp) 673 return m_remote_platform_sp->GetEnvironment(); 674 return Environment(); 675 } 676 return Host::GetEnvironment(); 677 } 678 679 bool PlatformPOSIX::GetRemoteOSKernelDescription(std::string &s) { 680 if (m_remote_platform_sp) 681 return m_remote_platform_sp->GetRemoteOSKernelDescription(s); 682 s.clear(); 683 return false; 684 } 685 686 // Remote Platform subclasses need to override this function 687 ArchSpec PlatformPOSIX::GetRemoteSystemArchitecture() { 688 if (m_remote_platform_sp) 689 return m_remote_platform_sp->GetRemoteSystemArchitecture(); 690 return ArchSpec(); 691 } 692 693 const char *PlatformPOSIX::GetHostname() { 694 if (IsHost()) 695 return Platform::GetHostname(); 696 697 if (m_remote_platform_sp) 698 return m_remote_platform_sp->GetHostname(); 699 return NULL; 700 } 701 702 const char *PlatformPOSIX::GetUserName(uint32_t uid) { 703 // Check the cache in Platform in case we have already looked this uid up 704 const char *user_name = Platform::GetUserName(uid); 705 if (user_name) 706 return user_name; 707 708 if (IsRemote() && m_remote_platform_sp) 709 return m_remote_platform_sp->GetUserName(uid); 710 return NULL; 711 } 712 713 const char *PlatformPOSIX::GetGroupName(uint32_t gid) { 714 const char *group_name = Platform::GetGroupName(gid); 715 if (group_name) 716 return group_name; 717 718 if (IsRemote() && m_remote_platform_sp) 719 return m_remote_platform_sp->GetGroupName(gid); 720 return NULL; 721 } 722 723 Status PlatformPOSIX::ConnectRemote(Args &args) { 724 Status error; 725 if (IsHost()) { 726 error.SetErrorStringWithFormat( 727 "can't connect to the host platform '%s', always connected", 728 GetPluginName().GetCString()); 729 } else { 730 if (!m_remote_platform_sp) 731 m_remote_platform_sp = 732 Platform::Create(ConstString("remote-gdb-server"), error); 733 734 if (m_remote_platform_sp && error.Success()) 735 error = m_remote_platform_sp->ConnectRemote(args); 736 else 737 error.SetErrorString("failed to create a 'remote-gdb-server' platform"); 738 739 if (error.Fail()) 740 m_remote_platform_sp.reset(); 741 } 742 743 if (error.Success() && m_remote_platform_sp) { 744 if (m_option_group_platform_rsync.get() && 745 m_option_group_platform_ssh.get() && 746 m_option_group_platform_caching.get()) { 747 if (m_option_group_platform_rsync->m_rsync) { 748 SetSupportsRSync(true); 749 SetRSyncOpts(m_option_group_platform_rsync->m_rsync_opts.c_str()); 750 SetRSyncPrefix(m_option_group_platform_rsync->m_rsync_prefix.c_str()); 751 SetIgnoresRemoteHostname( 752 m_option_group_platform_rsync->m_ignores_remote_hostname); 753 } 754 if (m_option_group_platform_ssh->m_ssh) { 755 SetSupportsSSH(true); 756 SetSSHOpts(m_option_group_platform_ssh->m_ssh_opts.c_str()); 757 } 758 SetLocalCacheDirectory( 759 m_option_group_platform_caching->m_cache_dir.c_str()); 760 } 761 } 762 763 return error; 764 } 765 766 Status PlatformPOSIX::DisconnectRemote() { 767 Status error; 768 769 if (IsHost()) { 770 error.SetErrorStringWithFormat( 771 "can't disconnect from the host platform '%s', always connected", 772 GetPluginName().GetCString()); 773 } else { 774 if (m_remote_platform_sp) 775 error = m_remote_platform_sp->DisconnectRemote(); 776 else 777 error.SetErrorString("the platform is not currently connected"); 778 } 779 return error; 780 } 781 782 Status PlatformPOSIX::LaunchProcess(ProcessLaunchInfo &launch_info) { 783 Status error; 784 785 if (IsHost()) { 786 error = Platform::LaunchProcess(launch_info); 787 } else { 788 if (m_remote_platform_sp) 789 error = m_remote_platform_sp->LaunchProcess(launch_info); 790 else 791 error.SetErrorString("the platform is not currently connected"); 792 } 793 return error; 794 } 795 796 lldb_private::Status PlatformPOSIX::KillProcess(const lldb::pid_t pid) { 797 if (IsHost()) 798 return Platform::KillProcess(pid); 799 800 if (m_remote_platform_sp) 801 return m_remote_platform_sp->KillProcess(pid); 802 803 return Status("the platform is not currently connected"); 804 } 805 806 lldb::ProcessSP PlatformPOSIX::Attach(ProcessAttachInfo &attach_info, 807 Debugger &debugger, Target *target, 808 Status &error) { 809 lldb::ProcessSP process_sp; 810 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM)); 811 812 if (IsHost()) { 813 if (target == NULL) { 814 TargetSP new_target_sp; 815 816 error = debugger.GetTargetList().CreateTarget(debugger, "", "", false, 817 NULL, new_target_sp); 818 target = new_target_sp.get(); 819 if (log) 820 log->Printf("PlatformPOSIX::%s created new target", __FUNCTION__); 821 } else { 822 error.Clear(); 823 if (log) 824 log->Printf("PlatformPOSIX::%s target already existed, setting target", 825 __FUNCTION__); 826 } 827 828 if (target && error.Success()) { 829 debugger.GetTargetList().SetSelectedTarget(target); 830 if (log) { 831 ModuleSP exe_module_sp = target->GetExecutableModule(); 832 log->Printf("PlatformPOSIX::%s set selected target to %p %s", 833 __FUNCTION__, (void *)target, 834 exe_module_sp 835 ? exe_module_sp->GetFileSpec().GetPath().c_str() 836 : "<null>"); 837 } 838 839 process_sp = 840 target->CreateProcess(attach_info.GetListenerForProcess(debugger), 841 attach_info.GetProcessPluginName(), NULL); 842 843 if (process_sp) { 844 ListenerSP listener_sp = attach_info.GetHijackListener(); 845 if (listener_sp == nullptr) { 846 listener_sp = 847 Listener::MakeListener("lldb.PlatformPOSIX.attach.hijack"); 848 attach_info.SetHijackListener(listener_sp); 849 } 850 process_sp->HijackProcessEvents(listener_sp); 851 error = process_sp->Attach(attach_info); 852 } 853 } 854 } else { 855 if (m_remote_platform_sp) 856 process_sp = 857 m_remote_platform_sp->Attach(attach_info, debugger, target, error); 858 else 859 error.SetErrorString("the platform is not currently connected"); 860 } 861 return process_sp; 862 } 863 864 lldb::ProcessSP 865 PlatformPOSIX::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger, 866 Target *target, // Can be NULL, if NULL create a new 867 // target, else use existing one 868 Status &error) { 869 ProcessSP process_sp; 870 871 if (IsHost()) { 872 // We are going to hand this process off to debugserver which will be in 873 // charge of setting the exit status. However, we still need to reap it 874 // from lldb. So, make sure we use a exit callback which does not set exit 875 // status. 876 const bool monitor_signals = false; 877 launch_info.SetMonitorProcessCallback( 878 &ProcessLaunchInfo::NoOpMonitorCallback, monitor_signals); 879 process_sp = Platform::DebugProcess(launch_info, debugger, target, error); 880 } else { 881 if (m_remote_platform_sp) 882 process_sp = m_remote_platform_sp->DebugProcess(launch_info, debugger, 883 target, error); 884 else 885 error.SetErrorString("the platform is not currently connected"); 886 } 887 return process_sp; 888 } 889 890 void PlatformPOSIX::CalculateTrapHandlerSymbolNames() { 891 m_trap_handlers.push_back(ConstString("_sigtramp")); 892 } 893 894 Status PlatformPOSIX::EvaluateLibdlExpression( 895 lldb_private::Process *process, const char *expr_cstr, 896 llvm::StringRef expr_prefix, lldb::ValueObjectSP &result_valobj_sp) { 897 DynamicLoader *loader = process->GetDynamicLoader(); 898 if (loader) { 899 Status error = loader->CanLoadImage(); 900 if (error.Fail()) 901 return error; 902 } 903 904 ThreadSP thread_sp(process->GetThreadList().GetExpressionExecutionThread()); 905 if (!thread_sp) 906 return Status("Selected thread isn't valid"); 907 908 StackFrameSP frame_sp(thread_sp->GetStackFrameAtIndex(0)); 909 if (!frame_sp) 910 return Status("Frame 0 isn't valid"); 911 912 ExecutionContext exe_ctx; 913 frame_sp->CalculateExecutionContext(exe_ctx); 914 EvaluateExpressionOptions expr_options; 915 expr_options.SetUnwindOnError(true); 916 expr_options.SetIgnoreBreakpoints(true); 917 expr_options.SetExecutionPolicy(eExecutionPolicyAlways); 918 expr_options.SetLanguage(eLanguageTypeC_plus_plus); 919 expr_options.SetTrapExceptions(false); // dlopen can't throw exceptions, so 920 // don't do the work to trap them. 921 expr_options.SetTimeout(std::chrono::seconds(2)); 922 923 Status expr_error; 924 ExpressionResults result = 925 UserExpression::Evaluate(exe_ctx, expr_options, expr_cstr, expr_prefix, 926 result_valobj_sp, expr_error); 927 if (result != eExpressionCompleted) 928 return expr_error; 929 930 if (result_valobj_sp->GetError().Fail()) 931 return result_valobj_sp->GetError(); 932 return Status(); 933 } 934 935 std::unique_ptr<UtilityFunction> 936 PlatformPOSIX::MakeLoadImageUtilityFunction(ExecutionContext &exe_ctx, 937 Status &error) { 938 // Remember to prepend this with the prefix from 939 // GetLibdlFunctionDeclarations. The returned values are all in 940 // __lldb_dlopen_result for consistency. The wrapper returns a void * but 941 // doesn't use it because UtilityFunctions don't work with void returns at 942 // present. 943 static const char *dlopen_wrapper_code = R"( 944 struct __lldb_dlopen_result { 945 void *image_ptr; 946 const char *error_str; 947 }; 948 949 void * __lldb_dlopen_wrapper (const char *path, 950 __lldb_dlopen_result *result_ptr) 951 { 952 result_ptr->image_ptr = dlopen(path, 2); 953 if (result_ptr->image_ptr == (void *) 0x0) 954 result_ptr->error_str = dlerror(); 955 return nullptr; 956 } 957 )"; 958 959 static const char *dlopen_wrapper_name = "__lldb_dlopen_wrapper"; 960 Process *process = exe_ctx.GetProcessSP().get(); 961 // Insert the dlopen shim defines into our generic expression: 962 std::string expr(GetLibdlFunctionDeclarations(process)); 963 expr.append(dlopen_wrapper_code); 964 Status utility_error; 965 DiagnosticManager diagnostics; 966 967 std::unique_ptr<UtilityFunction> dlopen_utility_func_up(process 968 ->GetTarget().GetUtilityFunctionForLanguage(expr.c_str(), 969 eLanguageTypeObjC, 970 dlopen_wrapper_name, 971 utility_error)); 972 if (utility_error.Fail()) { 973 error.SetErrorStringWithFormat("dlopen error: could not make utility" 974 "function: %s", utility_error.AsCString()); 975 return nullptr; 976 } 977 if (!dlopen_utility_func_up->Install(diagnostics, exe_ctx)) { 978 error.SetErrorStringWithFormat("dlopen error: could not install utility" 979 "function: %s", 980 diagnostics.GetString().c_str()); 981 return nullptr; 982 } 983 984 Value value; 985 ValueList arguments; 986 FunctionCaller *do_dlopen_function = nullptr; 987 988 // Fetch the clang types we will need: 989 ClangASTContext *ast = process->GetTarget().GetScratchClangASTContext(); 990 991 CompilerType clang_void_pointer_type 992 = ast->GetBasicType(eBasicTypeVoid).GetPointerType(); 993 CompilerType clang_char_pointer_type 994 = ast->GetBasicType(eBasicTypeChar).GetPointerType(); 995 996 // We are passing two arguments, the path to dlopen, and a pointer to the 997 // storage we've made for the result: 998 value.SetValueType(Value::eValueTypeScalar); 999 value.SetCompilerType(clang_void_pointer_type); 1000 arguments.PushValue(value); 1001 value.SetCompilerType(clang_char_pointer_type); 1002 arguments.PushValue(value); 1003 1004 do_dlopen_function = dlopen_utility_func_up->MakeFunctionCaller( 1005 clang_void_pointer_type, arguments, exe_ctx.GetThreadSP(), utility_error); 1006 if (utility_error.Fail()) { 1007 error.SetErrorStringWithFormat("dlopen error: could not make function" 1008 "caller: %s", utility_error.AsCString()); 1009 return nullptr; 1010 } 1011 1012 do_dlopen_function = dlopen_utility_func_up->GetFunctionCaller(); 1013 if (!do_dlopen_function) { 1014 error.SetErrorString("dlopen error: could not get function caller."); 1015 return nullptr; 1016 } 1017 1018 // We made a good utility function, so cache it in the process: 1019 return dlopen_utility_func_up; 1020 } 1021 1022 uint32_t PlatformPOSIX::DoLoadImage(lldb_private::Process *process, 1023 const lldb_private::FileSpec &remote_file, 1024 lldb_private::Status &error) { 1025 std::string path; 1026 path = remote_file.GetPath(); 1027 1028 ThreadSP thread_sp = process->GetThreadList().GetExpressionExecutionThread(); 1029 if (!thread_sp) { 1030 error.SetErrorString("dlopen error: no thread available to call dlopen."); 1031 return LLDB_INVALID_IMAGE_TOKEN; 1032 } 1033 1034 DiagnosticManager diagnostics; 1035 1036 ExecutionContext exe_ctx; 1037 thread_sp->CalculateExecutionContext(exe_ctx); 1038 1039 Status utility_error; 1040 UtilityFunction *dlopen_utility_func; 1041 ValueList arguments; 1042 FunctionCaller *do_dlopen_function = nullptr; 1043 1044 // The UtilityFunction is held in the Process. Platforms don't track the 1045 // lifespan of the Targets that use them, we can't put this in the Platform. 1046 dlopen_utility_func = process->GetLoadImageUtilityFunction( 1047 this, [&]() -> std::unique_ptr<UtilityFunction> { 1048 return MakeLoadImageUtilityFunction(exe_ctx, error); 1049 }); 1050 // If we couldn't make it, the error will be in error, so we can exit here. 1051 if (!dlopen_utility_func) 1052 return LLDB_INVALID_IMAGE_TOKEN; 1053 1054 do_dlopen_function = dlopen_utility_func->GetFunctionCaller(); 1055 if (!do_dlopen_function) { 1056 error.SetErrorString("dlopen error: could not get function caller."); 1057 return LLDB_INVALID_IMAGE_TOKEN; 1058 } 1059 arguments = do_dlopen_function->GetArgumentValues(); 1060 1061 // Now insert the path we are searching for and the result structure into the 1062 // target. 1063 uint32_t permissions = ePermissionsReadable|ePermissionsWritable; 1064 size_t path_len = path.size() + 1; 1065 lldb::addr_t path_addr = process->AllocateMemory(path_len, 1066 permissions, 1067 utility_error); 1068 if (path_addr == LLDB_INVALID_ADDRESS) { 1069 error.SetErrorStringWithFormat("dlopen error: could not allocate memory" 1070 "for path: %s", utility_error.AsCString()); 1071 return LLDB_INVALID_IMAGE_TOKEN; 1072 } 1073 1074 // Make sure we deallocate the input string memory: 1075 CleanUp path_cleanup([process, path_addr] { 1076 process->DeallocateMemory(path_addr); 1077 }); 1078 1079 process->WriteMemory(path_addr, path.c_str(), path_len, utility_error); 1080 if (utility_error.Fail()) { 1081 error.SetErrorStringWithFormat("dlopen error: could not write path string:" 1082 " %s", utility_error.AsCString()); 1083 return LLDB_INVALID_IMAGE_TOKEN; 1084 } 1085 1086 // Make space for our return structure. It is two pointers big: the token 1087 // and the error string. 1088 const uint32_t addr_size = process->GetAddressByteSize(); 1089 lldb::addr_t return_addr = process->CallocateMemory(2*addr_size, 1090 permissions, 1091 utility_error); 1092 if (utility_error.Fail()) { 1093 error.SetErrorStringWithFormat("dlopen error: could not allocate memory" 1094 "for path: %s", utility_error.AsCString()); 1095 return LLDB_INVALID_IMAGE_TOKEN; 1096 } 1097 1098 // Make sure we deallocate the result structure memory 1099 CleanUp return_cleanup([process, return_addr] { 1100 process->DeallocateMemory(return_addr); 1101 }); 1102 1103 // Set the values into our args and write them to the target: 1104 arguments.GetValueAtIndex(0)->GetScalar() = path_addr; 1105 arguments.GetValueAtIndex(1)->GetScalar() = return_addr; 1106 1107 lldb::addr_t func_args_addr = LLDB_INVALID_ADDRESS; 1108 1109 diagnostics.Clear(); 1110 if (!do_dlopen_function->WriteFunctionArguments(exe_ctx, 1111 func_args_addr, 1112 arguments, 1113 diagnostics)) { 1114 error.SetErrorStringWithFormat("dlopen error: could not write function " 1115 "arguments: %s", 1116 diagnostics.GetString().c_str()); 1117 return LLDB_INVALID_IMAGE_TOKEN; 1118 } 1119 1120 // Make sure we clean up the args structure. We can't reuse it because the 1121 // Platform lives longer than the process and the Platforms don't get a 1122 // signal to clean up cached data when a process goes away. 1123 CleanUp args_cleanup([do_dlopen_function, &exe_ctx, func_args_addr] { 1124 do_dlopen_function->DeallocateFunctionResults(exe_ctx, func_args_addr); 1125 }); 1126 1127 // Now run the caller: 1128 EvaluateExpressionOptions options; 1129 options.SetExecutionPolicy(eExecutionPolicyAlways); 1130 options.SetLanguage(eLanguageTypeC_plus_plus); 1131 options.SetIgnoreBreakpoints(true); 1132 options.SetUnwindOnError(true); 1133 options.SetTrapExceptions(false); // dlopen can't throw exceptions, so 1134 // don't do the work to trap them. 1135 options.SetTimeout(std::chrono::seconds(2)); 1136 1137 Value return_value; 1138 // Fetch the clang types we will need: 1139 ClangASTContext *ast = process->GetTarget().GetScratchClangASTContext(); 1140 1141 CompilerType clang_void_pointer_type 1142 = ast->GetBasicType(eBasicTypeVoid).GetPointerType(); 1143 1144 return_value.SetCompilerType(clang_void_pointer_type); 1145 1146 ExpressionResults results = do_dlopen_function->ExecuteFunction( 1147 exe_ctx, &func_args_addr, options, diagnostics, return_value); 1148 if (results != eExpressionCompleted) { 1149 error.SetErrorStringWithFormat("dlopen error: could write execute " 1150 "dlopen wrapper function: %s", 1151 diagnostics.GetString().c_str()); 1152 return LLDB_INVALID_IMAGE_TOKEN; 1153 } 1154 1155 // Read the dlopen token from the return area: 1156 lldb::addr_t token = process->ReadPointerFromMemory(return_addr, 1157 utility_error); 1158 if (utility_error.Fail()) { 1159 error.SetErrorStringWithFormat("dlopen error: could not read the return " 1160 "struct: %s", utility_error.AsCString()); 1161 return LLDB_INVALID_IMAGE_TOKEN; 1162 } 1163 1164 // The dlopen succeeded! 1165 if (token != 0x0) 1166 return process->AddImageToken(token); 1167 1168 // We got an error, lets read in the error string: 1169 std::string dlopen_error_str; 1170 lldb::addr_t error_addr 1171 = process->ReadPointerFromMemory(return_addr + addr_size, utility_error); 1172 if (utility_error.Fail()) { 1173 error.SetErrorStringWithFormat("dlopen error: could not read error string: " 1174 "%s", utility_error.AsCString()); 1175 return LLDB_INVALID_IMAGE_TOKEN; 1176 } 1177 1178 size_t num_chars = process->ReadCStringFromMemory(error_addr + addr_size, 1179 dlopen_error_str, 1180 utility_error); 1181 if (utility_error.Success() && num_chars > 0) 1182 error.SetErrorStringWithFormat("dlopen error: %s", 1183 dlopen_error_str.c_str()); 1184 else 1185 error.SetErrorStringWithFormat("dlopen failed for unknown reasons."); 1186 1187 return LLDB_INVALID_IMAGE_TOKEN; 1188 } 1189 1190 Status PlatformPOSIX::UnloadImage(lldb_private::Process *process, 1191 uint32_t image_token) { 1192 const addr_t image_addr = process->GetImagePtrFromToken(image_token); 1193 if (image_addr == LLDB_INVALID_ADDRESS) 1194 return Status("Invalid image token"); 1195 1196 StreamString expr; 1197 expr.Printf("dlclose((void *)0x%" PRIx64 ")", image_addr); 1198 llvm::StringRef prefix = GetLibdlFunctionDeclarations(process); 1199 lldb::ValueObjectSP result_valobj_sp; 1200 Status error = EvaluateLibdlExpression(process, expr.GetData(), prefix, 1201 result_valobj_sp); 1202 if (error.Fail()) 1203 return error; 1204 1205 if (result_valobj_sp->GetError().Fail()) 1206 return result_valobj_sp->GetError(); 1207 1208 Scalar scalar; 1209 if (result_valobj_sp->ResolveValue(scalar)) { 1210 if (scalar.UInt(1)) 1211 return Status("expression failed: \"%s\"", expr.GetData()); 1212 process->ResetImageToken(image_token); 1213 } 1214 return Status(); 1215 } 1216 1217 lldb::ProcessSP PlatformPOSIX::ConnectProcess(llvm::StringRef connect_url, 1218 llvm::StringRef plugin_name, 1219 lldb_private::Debugger &debugger, 1220 lldb_private::Target *target, 1221 lldb_private::Status &error) { 1222 if (m_remote_platform_sp) 1223 return m_remote_platform_sp->ConnectProcess(connect_url, plugin_name, 1224 debugger, target, error); 1225 1226 return Platform::ConnectProcess(connect_url, plugin_name, debugger, target, 1227 error); 1228 } 1229 1230 llvm::StringRef 1231 PlatformPOSIX::GetLibdlFunctionDeclarations(lldb_private::Process *process) { 1232 return R"( 1233 extern "C" void* dlopen(const char*, int); 1234 extern "C" void* dlsym(void*, const char*); 1235 extern "C" int dlclose(void*); 1236 extern "C" char* dlerror(void); 1237 )"; 1238 } 1239 1240 size_t PlatformPOSIX::ConnectToWaitingProcesses(Debugger &debugger, 1241 Status &error) { 1242 if (m_remote_platform_sp) 1243 return m_remote_platform_sp->ConnectToWaitingProcesses(debugger, error); 1244 return Platform::ConnectToWaitingProcesses(debugger, error); 1245 } 1246 1247 ConstString PlatformPOSIX::GetFullNameForDylib(ConstString basename) { 1248 if (basename.IsEmpty()) 1249 return basename; 1250 1251 StreamString stream; 1252 stream.Printf("lib%s.so", basename.GetCString()); 1253 return ConstString(stream.GetString()); 1254 } 1255