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 return m_remote_platform_sp->GetOSVersion( 658 m_major_os_version, m_minor_os_version, m_update_os_version); 659 return false; 660 } 661 662 bool PlatformPOSIX::GetRemoteOSBuildString(std::string &s) { 663 if (m_remote_platform_sp) 664 return m_remote_platform_sp->GetRemoteOSBuildString(s); 665 s.clear(); 666 return false; 667 } 668 669 Environment PlatformPOSIX::GetEnvironment() { 670 if (IsRemote()) { 671 if (m_remote_platform_sp) 672 return m_remote_platform_sp->GetEnvironment(); 673 return Environment(); 674 } 675 return Host::GetEnvironment(); 676 } 677 678 bool PlatformPOSIX::GetRemoteOSKernelDescription(std::string &s) { 679 if (m_remote_platform_sp) 680 return m_remote_platform_sp->GetRemoteOSKernelDescription(s); 681 s.clear(); 682 return false; 683 } 684 685 // Remote Platform subclasses need to override this function 686 ArchSpec PlatformPOSIX::GetRemoteSystemArchitecture() { 687 if (m_remote_platform_sp) 688 return m_remote_platform_sp->GetRemoteSystemArchitecture(); 689 return ArchSpec(); 690 } 691 692 const char *PlatformPOSIX::GetHostname() { 693 if (IsHost()) 694 return Platform::GetHostname(); 695 696 if (m_remote_platform_sp) 697 return m_remote_platform_sp->GetHostname(); 698 return NULL; 699 } 700 701 const char *PlatformPOSIX::GetUserName(uint32_t uid) { 702 // Check the cache in Platform in case we have already looked this uid up 703 const char *user_name = Platform::GetUserName(uid); 704 if (user_name) 705 return user_name; 706 707 if (IsRemote() && m_remote_platform_sp) 708 return m_remote_platform_sp->GetUserName(uid); 709 return NULL; 710 } 711 712 const char *PlatformPOSIX::GetGroupName(uint32_t gid) { 713 const char *group_name = Platform::GetGroupName(gid); 714 if (group_name) 715 return group_name; 716 717 if (IsRemote() && m_remote_platform_sp) 718 return m_remote_platform_sp->GetGroupName(gid); 719 return NULL; 720 } 721 722 Status PlatformPOSIX::ConnectRemote(Args &args) { 723 Status error; 724 if (IsHost()) { 725 error.SetErrorStringWithFormat( 726 "can't connect to the host platform '%s', always connected", 727 GetPluginName().GetCString()); 728 } else { 729 if (!m_remote_platform_sp) 730 m_remote_platform_sp = 731 Platform::Create(ConstString("remote-gdb-server"), error); 732 733 if (m_remote_platform_sp && error.Success()) 734 error = m_remote_platform_sp->ConnectRemote(args); 735 else 736 error.SetErrorString("failed to create a 'remote-gdb-server' platform"); 737 738 if (error.Fail()) 739 m_remote_platform_sp.reset(); 740 } 741 742 if (error.Success() && m_remote_platform_sp) { 743 if (m_option_group_platform_rsync.get() && 744 m_option_group_platform_ssh.get() && 745 m_option_group_platform_caching.get()) { 746 if (m_option_group_platform_rsync->m_rsync) { 747 SetSupportsRSync(true); 748 SetRSyncOpts(m_option_group_platform_rsync->m_rsync_opts.c_str()); 749 SetRSyncPrefix(m_option_group_platform_rsync->m_rsync_prefix.c_str()); 750 SetIgnoresRemoteHostname( 751 m_option_group_platform_rsync->m_ignores_remote_hostname); 752 } 753 if (m_option_group_platform_ssh->m_ssh) { 754 SetSupportsSSH(true); 755 SetSSHOpts(m_option_group_platform_ssh->m_ssh_opts.c_str()); 756 } 757 SetLocalCacheDirectory( 758 m_option_group_platform_caching->m_cache_dir.c_str()); 759 } 760 } 761 762 return error; 763 } 764 765 Status PlatformPOSIX::DisconnectRemote() { 766 Status error; 767 768 if (IsHost()) { 769 error.SetErrorStringWithFormat( 770 "can't disconnect from the host platform '%s', always connected", 771 GetPluginName().GetCString()); 772 } else { 773 if (m_remote_platform_sp) 774 error = m_remote_platform_sp->DisconnectRemote(); 775 else 776 error.SetErrorString("the platform is not currently connected"); 777 } 778 return error; 779 } 780 781 Status PlatformPOSIX::LaunchProcess(ProcessLaunchInfo &launch_info) { 782 Status error; 783 784 if (IsHost()) { 785 error = Platform::LaunchProcess(launch_info); 786 } else { 787 if (m_remote_platform_sp) 788 error = m_remote_platform_sp->LaunchProcess(launch_info); 789 else 790 error.SetErrorString("the platform is not currently connected"); 791 } 792 return error; 793 } 794 795 lldb_private::Status PlatformPOSIX::KillProcess(const lldb::pid_t pid) { 796 if (IsHost()) 797 return Platform::KillProcess(pid); 798 799 if (m_remote_platform_sp) 800 return m_remote_platform_sp->KillProcess(pid); 801 802 return Status("the platform is not currently connected"); 803 } 804 805 lldb::ProcessSP PlatformPOSIX::Attach(ProcessAttachInfo &attach_info, 806 Debugger &debugger, Target *target, 807 Status &error) { 808 lldb::ProcessSP process_sp; 809 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM)); 810 811 if (IsHost()) { 812 if (target == NULL) { 813 TargetSP new_target_sp; 814 815 error = debugger.GetTargetList().CreateTarget(debugger, "", "", false, 816 NULL, new_target_sp); 817 target = new_target_sp.get(); 818 if (log) 819 log->Printf("PlatformPOSIX::%s created new target", __FUNCTION__); 820 } else { 821 error.Clear(); 822 if (log) 823 log->Printf("PlatformPOSIX::%s target already existed, setting target", 824 __FUNCTION__); 825 } 826 827 if (target && error.Success()) { 828 debugger.GetTargetList().SetSelectedTarget(target); 829 if (log) { 830 ModuleSP exe_module_sp = target->GetExecutableModule(); 831 log->Printf("PlatformPOSIX::%s set selected target to %p %s", 832 __FUNCTION__, (void *)target, 833 exe_module_sp 834 ? exe_module_sp->GetFileSpec().GetPath().c_str() 835 : "<null>"); 836 } 837 838 process_sp = 839 target->CreateProcess(attach_info.GetListenerForProcess(debugger), 840 attach_info.GetProcessPluginName(), NULL); 841 842 if (process_sp) { 843 ListenerSP listener_sp = attach_info.GetHijackListener(); 844 if (listener_sp == nullptr) { 845 listener_sp = 846 Listener::MakeListener("lldb.PlatformPOSIX.attach.hijack"); 847 attach_info.SetHijackListener(listener_sp); 848 } 849 process_sp->HijackProcessEvents(listener_sp); 850 error = process_sp->Attach(attach_info); 851 } 852 } 853 } else { 854 if (m_remote_platform_sp) 855 process_sp = 856 m_remote_platform_sp->Attach(attach_info, debugger, target, error); 857 else 858 error.SetErrorString("the platform is not currently connected"); 859 } 860 return process_sp; 861 } 862 863 lldb::ProcessSP 864 PlatformPOSIX::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger, 865 Target *target, // Can be NULL, if NULL create a new 866 // target, else use existing one 867 Status &error) { 868 ProcessSP process_sp; 869 870 if (IsHost()) { 871 // We are going to hand this process off to debugserver which will be in 872 // charge of setting the exit status. However, we still need to reap it 873 // from lldb. So, make sure we use a exit callback which does not set exit 874 // status. 875 const bool monitor_signals = false; 876 launch_info.SetMonitorProcessCallback( 877 &ProcessLaunchInfo::NoOpMonitorCallback, monitor_signals); 878 process_sp = Platform::DebugProcess(launch_info, debugger, target, error); 879 } else { 880 if (m_remote_platform_sp) 881 process_sp = m_remote_platform_sp->DebugProcess(launch_info, debugger, 882 target, error); 883 else 884 error.SetErrorString("the platform is not currently connected"); 885 } 886 return process_sp; 887 } 888 889 void PlatformPOSIX::CalculateTrapHandlerSymbolNames() { 890 m_trap_handlers.push_back(ConstString("_sigtramp")); 891 } 892 893 Status PlatformPOSIX::EvaluateLibdlExpression( 894 lldb_private::Process *process, const char *expr_cstr, 895 llvm::StringRef expr_prefix, lldb::ValueObjectSP &result_valobj_sp) { 896 DynamicLoader *loader = process->GetDynamicLoader(); 897 if (loader) { 898 Status error = loader->CanLoadImage(); 899 if (error.Fail()) 900 return error; 901 } 902 903 ThreadSP thread_sp(process->GetThreadList().GetExpressionExecutionThread()); 904 if (!thread_sp) 905 return Status("Selected thread isn't valid"); 906 907 StackFrameSP frame_sp(thread_sp->GetStackFrameAtIndex(0)); 908 if (!frame_sp) 909 return Status("Frame 0 isn't valid"); 910 911 ExecutionContext exe_ctx; 912 frame_sp->CalculateExecutionContext(exe_ctx); 913 EvaluateExpressionOptions expr_options; 914 expr_options.SetUnwindOnError(true); 915 expr_options.SetIgnoreBreakpoints(true); 916 expr_options.SetExecutionPolicy(eExecutionPolicyAlways); 917 expr_options.SetLanguage(eLanguageTypeC_plus_plus); 918 expr_options.SetTrapExceptions(false); // dlopen can't throw exceptions, so 919 // don't do the work to trap them. 920 expr_options.SetTimeout(std::chrono::seconds(2)); 921 922 Status expr_error; 923 ExpressionResults result = 924 UserExpression::Evaluate(exe_ctx, expr_options, expr_cstr, expr_prefix, 925 result_valobj_sp, expr_error); 926 if (result != eExpressionCompleted) 927 return expr_error; 928 929 if (result_valobj_sp->GetError().Fail()) 930 return result_valobj_sp->GetError(); 931 return Status(); 932 } 933 934 std::unique_ptr<UtilityFunction> 935 PlatformPOSIX::MakeLoadImageUtilityFunction(ExecutionContext &exe_ctx, 936 Status &error) { 937 // Remember to prepend this with the prefix from 938 // GetLibdlFunctionDeclarations. The returned values are all in 939 // __lldb_dlopen_result for consistency. The wrapper returns a void * but 940 // doesn't use it because UtilityFunctions don't work with void returns at 941 // present. 942 static const char *dlopen_wrapper_code = R"( 943 struct __lldb_dlopen_result { 944 void *image_ptr; 945 const char *error_str; 946 }; 947 948 void * __lldb_dlopen_wrapper (const char *path, 949 __lldb_dlopen_result *result_ptr) 950 { 951 result_ptr->image_ptr = dlopen(path, 2); 952 if (result_ptr->image_ptr == (void *) 0x0) 953 result_ptr->error_str = dlerror(); 954 return nullptr; 955 } 956 )"; 957 958 static const char *dlopen_wrapper_name = "__lldb_dlopen_wrapper"; 959 Process *process = exe_ctx.GetProcessSP().get(); 960 // Insert the dlopen shim defines into our generic expression: 961 std::string expr(GetLibdlFunctionDeclarations(process)); 962 expr.append(dlopen_wrapper_code); 963 Status utility_error; 964 DiagnosticManager diagnostics; 965 966 std::unique_ptr<UtilityFunction> dlopen_utility_func_up(process 967 ->GetTarget().GetUtilityFunctionForLanguage(expr.c_str(), 968 eLanguageTypeObjC, 969 dlopen_wrapper_name, 970 utility_error)); 971 if (utility_error.Fail()) { 972 error.SetErrorStringWithFormat("dlopen error: could not make utility" 973 "function: %s", utility_error.AsCString()); 974 return nullptr; 975 } 976 if (!dlopen_utility_func_up->Install(diagnostics, exe_ctx)) { 977 error.SetErrorStringWithFormat("dlopen error: could not install utility" 978 "function: %s", 979 diagnostics.GetString().c_str()); 980 return nullptr; 981 } 982 983 Value value; 984 ValueList arguments; 985 FunctionCaller *do_dlopen_function = nullptr; 986 987 // Fetch the clang types we will need: 988 ClangASTContext *ast = process->GetTarget().GetScratchClangASTContext(); 989 990 CompilerType clang_void_pointer_type 991 = ast->GetBasicType(eBasicTypeVoid).GetPointerType(); 992 CompilerType clang_char_pointer_type 993 = ast->GetBasicType(eBasicTypeChar).GetPointerType(); 994 995 // We are passing two arguments, the path to dlopen, and a pointer to the 996 // storage we've made for the result: 997 value.SetValueType(Value::eValueTypeScalar); 998 value.SetCompilerType(clang_void_pointer_type); 999 arguments.PushValue(value); 1000 value.SetCompilerType(clang_char_pointer_type); 1001 arguments.PushValue(value); 1002 1003 do_dlopen_function = dlopen_utility_func_up->MakeFunctionCaller( 1004 clang_void_pointer_type, arguments, exe_ctx.GetThreadSP(), utility_error); 1005 if (utility_error.Fail()) { 1006 error.SetErrorStringWithFormat("dlopen error: could not make function" 1007 "caller: %s", utility_error.AsCString()); 1008 return nullptr; 1009 } 1010 1011 do_dlopen_function = dlopen_utility_func_up->GetFunctionCaller(); 1012 if (!do_dlopen_function) { 1013 error.SetErrorString("dlopen error: could not get function caller."); 1014 return nullptr; 1015 } 1016 1017 // We made a good utility function, so cache it in the process: 1018 return dlopen_utility_func_up; 1019 } 1020 1021 uint32_t PlatformPOSIX::DoLoadImage(lldb_private::Process *process, 1022 const lldb_private::FileSpec &remote_file, 1023 lldb_private::Status &error) { 1024 std::string path; 1025 path = remote_file.GetPath(); 1026 1027 ThreadSP thread_sp = process->GetThreadList().GetExpressionExecutionThread(); 1028 if (!thread_sp) { 1029 error.SetErrorString("dlopen error: no thread available to call dlopen."); 1030 return LLDB_INVALID_IMAGE_TOKEN; 1031 } 1032 1033 DiagnosticManager diagnostics; 1034 1035 ExecutionContext exe_ctx; 1036 thread_sp->CalculateExecutionContext(exe_ctx); 1037 1038 Status utility_error; 1039 UtilityFunction *dlopen_utility_func; 1040 ValueList arguments; 1041 FunctionCaller *do_dlopen_function = nullptr; 1042 1043 // The UtilityFunction is held in the Process. Platforms don't track the 1044 // lifespan of the Targets that use them, we can't put this in the Platform. 1045 dlopen_utility_func = process->GetLoadImageUtilityFunction( 1046 this, [&]() -> std::unique_ptr<UtilityFunction> { 1047 return MakeLoadImageUtilityFunction(exe_ctx, error); 1048 }); 1049 // If we couldn't make it, the error will be in error, so we can exit here. 1050 if (!dlopen_utility_func) 1051 return LLDB_INVALID_IMAGE_TOKEN; 1052 1053 do_dlopen_function = dlopen_utility_func->GetFunctionCaller(); 1054 if (!do_dlopen_function) { 1055 error.SetErrorString("dlopen error: could not get function caller."); 1056 return LLDB_INVALID_IMAGE_TOKEN; 1057 } 1058 arguments = do_dlopen_function->GetArgumentValues(); 1059 1060 // Now insert the path we are searching for and the result structure into the 1061 // target. 1062 uint32_t permissions = ePermissionsReadable|ePermissionsWritable; 1063 size_t path_len = path.size() + 1; 1064 lldb::addr_t path_addr = process->AllocateMemory(path_len, 1065 permissions, 1066 utility_error); 1067 if (path_addr == LLDB_INVALID_ADDRESS) { 1068 error.SetErrorStringWithFormat("dlopen error: could not allocate memory" 1069 "for path: %s", utility_error.AsCString()); 1070 return LLDB_INVALID_IMAGE_TOKEN; 1071 } 1072 1073 // Make sure we deallocate the input string memory: 1074 CleanUp path_cleanup([process, path_addr] { 1075 process->DeallocateMemory(path_addr); 1076 }); 1077 1078 process->WriteMemory(path_addr, path.c_str(), path_len, utility_error); 1079 if (utility_error.Fail()) { 1080 error.SetErrorStringWithFormat("dlopen error: could not write path string:" 1081 " %s", utility_error.AsCString()); 1082 return LLDB_INVALID_IMAGE_TOKEN; 1083 } 1084 1085 // Make space for our return structure. It is two pointers big: the token 1086 // and the error string. 1087 const uint32_t addr_size = process->GetAddressByteSize(); 1088 lldb::addr_t return_addr = process->CallocateMemory(2*addr_size, 1089 permissions, 1090 utility_error); 1091 if (utility_error.Fail()) { 1092 error.SetErrorStringWithFormat("dlopen error: could not allocate memory" 1093 "for path: %s", utility_error.AsCString()); 1094 return LLDB_INVALID_IMAGE_TOKEN; 1095 } 1096 1097 // Make sure we deallocate the result structure memory 1098 CleanUp return_cleanup([process, return_addr] { 1099 process->DeallocateMemory(return_addr); 1100 }); 1101 1102 // Set the values into our args and write them to the target: 1103 arguments.GetValueAtIndex(0)->GetScalar() = path_addr; 1104 arguments.GetValueAtIndex(1)->GetScalar() = return_addr; 1105 1106 lldb::addr_t func_args_addr = LLDB_INVALID_ADDRESS; 1107 1108 diagnostics.Clear(); 1109 if (!do_dlopen_function->WriteFunctionArguments(exe_ctx, 1110 func_args_addr, 1111 arguments, 1112 diagnostics)) { 1113 error.SetErrorStringWithFormat("dlopen error: could not write function " 1114 "arguments: %s", 1115 diagnostics.GetString().c_str()); 1116 return LLDB_INVALID_IMAGE_TOKEN; 1117 } 1118 1119 // Make sure we clean up the args structure. We can't reuse it because the 1120 // Platform lives longer than the process and the Platforms don't get a 1121 // signal to clean up cached data when a process goes away. 1122 CleanUp args_cleanup([do_dlopen_function, &exe_ctx, func_args_addr] { 1123 do_dlopen_function->DeallocateFunctionResults(exe_ctx, func_args_addr); 1124 }); 1125 1126 // Now run the caller: 1127 EvaluateExpressionOptions options; 1128 options.SetExecutionPolicy(eExecutionPolicyAlways); 1129 options.SetLanguage(eLanguageTypeC_plus_plus); 1130 options.SetIgnoreBreakpoints(true); 1131 options.SetUnwindOnError(true); 1132 options.SetTrapExceptions(false); // dlopen can't throw exceptions, so 1133 // don't do the work to trap them. 1134 options.SetTimeout(std::chrono::seconds(2)); 1135 1136 Value return_value; 1137 // Fetch the clang types we will need: 1138 ClangASTContext *ast = process->GetTarget().GetScratchClangASTContext(); 1139 1140 CompilerType clang_void_pointer_type 1141 = ast->GetBasicType(eBasicTypeVoid).GetPointerType(); 1142 1143 return_value.SetCompilerType(clang_void_pointer_type); 1144 1145 ExpressionResults results = do_dlopen_function->ExecuteFunction( 1146 exe_ctx, &func_args_addr, options, diagnostics, return_value); 1147 if (results != eExpressionCompleted) { 1148 error.SetErrorStringWithFormat("dlopen error: could write execute " 1149 "dlopen wrapper function: %s", 1150 diagnostics.GetString().c_str()); 1151 return LLDB_INVALID_IMAGE_TOKEN; 1152 } 1153 1154 // Read the dlopen token from the return area: 1155 lldb::addr_t token = process->ReadPointerFromMemory(return_addr, 1156 utility_error); 1157 if (utility_error.Fail()) { 1158 error.SetErrorStringWithFormat("dlopen error: could not read the return " 1159 "struct: %s", utility_error.AsCString()); 1160 return LLDB_INVALID_IMAGE_TOKEN; 1161 } 1162 1163 // The dlopen succeeded! 1164 if (token != 0x0) 1165 return process->AddImageToken(token); 1166 1167 // We got an error, lets read in the error string: 1168 std::string dlopen_error_str; 1169 lldb::addr_t error_addr 1170 = process->ReadPointerFromMemory(return_addr + addr_size, utility_error); 1171 if (utility_error.Fail()) { 1172 error.SetErrorStringWithFormat("dlopen error: could not read error string: " 1173 "%s", utility_error.AsCString()); 1174 return LLDB_INVALID_IMAGE_TOKEN; 1175 } 1176 1177 size_t num_chars = process->ReadCStringFromMemory(error_addr + addr_size, 1178 dlopen_error_str, 1179 utility_error); 1180 if (utility_error.Success() && num_chars > 0) 1181 error.SetErrorStringWithFormat("dlopen error: %s", 1182 dlopen_error_str.c_str()); 1183 else 1184 error.SetErrorStringWithFormat("dlopen failed for unknown reasons."); 1185 1186 return LLDB_INVALID_IMAGE_TOKEN; 1187 } 1188 1189 Status PlatformPOSIX::UnloadImage(lldb_private::Process *process, 1190 uint32_t image_token) { 1191 const addr_t image_addr = process->GetImagePtrFromToken(image_token); 1192 if (image_addr == LLDB_INVALID_ADDRESS) 1193 return Status("Invalid image token"); 1194 1195 StreamString expr; 1196 expr.Printf("dlclose((void *)0x%" PRIx64 ")", image_addr); 1197 llvm::StringRef prefix = GetLibdlFunctionDeclarations(process); 1198 lldb::ValueObjectSP result_valobj_sp; 1199 Status error = EvaluateLibdlExpression(process, expr.GetData(), prefix, 1200 result_valobj_sp); 1201 if (error.Fail()) 1202 return error; 1203 1204 if (result_valobj_sp->GetError().Fail()) 1205 return result_valobj_sp->GetError(); 1206 1207 Scalar scalar; 1208 if (result_valobj_sp->ResolveValue(scalar)) { 1209 if (scalar.UInt(1)) 1210 return Status("expression failed: \"%s\"", expr.GetData()); 1211 process->ResetImageToken(image_token); 1212 } 1213 return Status(); 1214 } 1215 1216 lldb::ProcessSP PlatformPOSIX::ConnectProcess(llvm::StringRef connect_url, 1217 llvm::StringRef plugin_name, 1218 lldb_private::Debugger &debugger, 1219 lldb_private::Target *target, 1220 lldb_private::Status &error) { 1221 if (m_remote_platform_sp) 1222 return m_remote_platform_sp->ConnectProcess(connect_url, plugin_name, 1223 debugger, target, error); 1224 1225 return Platform::ConnectProcess(connect_url, plugin_name, debugger, target, 1226 error); 1227 } 1228 1229 llvm::StringRef 1230 PlatformPOSIX::GetLibdlFunctionDeclarations(lldb_private::Process *process) { 1231 return R"( 1232 extern "C" void* dlopen(const char*, int); 1233 extern "C" void* dlsym(void*, const char*); 1234 extern "C" int dlclose(void*); 1235 extern "C" char* dlerror(void); 1236 )"; 1237 } 1238 1239 size_t PlatformPOSIX::ConnectToWaitingProcesses(Debugger &debugger, 1240 Status &error) { 1241 if (m_remote_platform_sp) 1242 return m_remote_platform_sp->ConnectToWaitingProcesses(debugger, error); 1243 return Platform::ConnectToWaitingProcesses(debugger, error); 1244 } 1245 1246 ConstString PlatformPOSIX::GetFullNameForDylib(ConstString basename) { 1247 if (basename.IsEmpty()) 1248 return basename; 1249 1250 StreamString stream; 1251 stream.Printf("lib%s.so", basename.GetCString()); 1252 return ConstString(stream.GetString()); 1253 } 1254