1 //===-- SBPlatform.cpp ----------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "lldb/API/SBPlatform.h" 10 #include "SBReproducerPrivate.h" 11 #include "lldb/API/SBEnvironment.h" 12 #include "lldb/API/SBError.h" 13 #include "lldb/API/SBFileSpec.h" 14 #include "lldb/API/SBLaunchInfo.h" 15 #include "lldb/API/SBPlatform.h" 16 #include "lldb/API/SBUnixSignals.h" 17 #include "lldb/Host/File.h" 18 #include "lldb/Target/Platform.h" 19 #include "lldb/Target/Target.h" 20 #include "lldb/Utility/ArchSpec.h" 21 #include "lldb/Utility/Args.h" 22 #include "lldb/Utility/Status.h" 23 24 #include "llvm/Support/FileSystem.h" 25 26 #include <functional> 27 28 using namespace lldb; 29 using namespace lldb_private; 30 31 // PlatformConnectOptions 32 struct PlatformConnectOptions { 33 PlatformConnectOptions(const char *url = nullptr) 34 : m_url(), m_rsync_options(), m_rsync_remote_path_prefix(), 35 36 m_local_cache_directory() { 37 if (url && url[0]) 38 m_url = url; 39 } 40 41 ~PlatformConnectOptions() = default; 42 43 std::string m_url; 44 std::string m_rsync_options; 45 std::string m_rsync_remote_path_prefix; 46 bool m_rsync_enabled = false; 47 bool m_rsync_omit_hostname_from_remote_path = false; 48 ConstString m_local_cache_directory; 49 }; 50 51 // PlatformShellCommand 52 struct PlatformShellCommand { 53 PlatformShellCommand(llvm::StringRef shell_interpreter, 54 llvm::StringRef shell_command) 55 : m_command(), m_working_dir(), m_status(0), m_signo(0) { 56 if (!shell_interpreter.empty()) 57 m_shell = shell_interpreter.str(); 58 59 if (!m_shell.empty() && !shell_command.empty()) 60 m_command = shell_command.str(); 61 } 62 63 PlatformShellCommand(llvm::StringRef shell_command = llvm::StringRef()) 64 : m_shell(), m_command(), m_working_dir() { 65 if (!shell_command.empty()) 66 m_command = shell_command.str(); 67 } 68 69 ~PlatformShellCommand() = default; 70 71 std::string m_shell; 72 std::string m_command; 73 std::string m_working_dir; 74 std::string m_output; 75 int m_status = 0; 76 int m_signo = 0; 77 Timeout<std::ratio<1>> m_timeout = llvm::None; 78 }; 79 // SBPlatformConnectOptions 80 SBPlatformConnectOptions::SBPlatformConnectOptions(const char *url) 81 : m_opaque_ptr(new PlatformConnectOptions(url)) { 82 LLDB_RECORD_CONSTRUCTOR(SBPlatformConnectOptions, (const char *), url); 83 } 84 85 SBPlatformConnectOptions::SBPlatformConnectOptions( 86 const SBPlatformConnectOptions &rhs) 87 : m_opaque_ptr(new PlatformConnectOptions()) { 88 LLDB_RECORD_CONSTRUCTOR(SBPlatformConnectOptions, 89 (const lldb::SBPlatformConnectOptions &), rhs); 90 91 *m_opaque_ptr = *rhs.m_opaque_ptr; 92 } 93 94 SBPlatformConnectOptions::~SBPlatformConnectOptions() { delete m_opaque_ptr; } 95 96 SBPlatformConnectOptions & 97 SBPlatformConnectOptions::operator=(const SBPlatformConnectOptions &rhs) { 98 LLDB_RECORD_METHOD( 99 SBPlatformConnectOptions &, 100 SBPlatformConnectOptions, operator=,( 101 const lldb::SBPlatformConnectOptions &), 102 rhs); 103 104 *m_opaque_ptr = *rhs.m_opaque_ptr; 105 return LLDB_RECORD_RESULT(*this); 106 } 107 108 const char *SBPlatformConnectOptions::GetURL() { 109 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatformConnectOptions, GetURL); 110 111 if (m_opaque_ptr->m_url.empty()) 112 return nullptr; 113 return m_opaque_ptr->m_url.c_str(); 114 } 115 116 void SBPlatformConnectOptions::SetURL(const char *url) { 117 LLDB_RECORD_METHOD(void, SBPlatformConnectOptions, SetURL, (const char *), 118 url); 119 120 if (url && url[0]) 121 m_opaque_ptr->m_url = url; 122 else 123 m_opaque_ptr->m_url.clear(); 124 } 125 126 bool SBPlatformConnectOptions::GetRsyncEnabled() { 127 LLDB_RECORD_METHOD_NO_ARGS(bool, SBPlatformConnectOptions, GetRsyncEnabled); 128 129 return m_opaque_ptr->m_rsync_enabled; 130 } 131 132 void SBPlatformConnectOptions::EnableRsync( 133 const char *options, const char *remote_path_prefix, 134 bool omit_hostname_from_remote_path) { 135 LLDB_RECORD_METHOD(void, SBPlatformConnectOptions, EnableRsync, 136 (const char *, const char *, bool), options, 137 remote_path_prefix, omit_hostname_from_remote_path); 138 139 m_opaque_ptr->m_rsync_enabled = true; 140 m_opaque_ptr->m_rsync_omit_hostname_from_remote_path = 141 omit_hostname_from_remote_path; 142 if (remote_path_prefix && remote_path_prefix[0]) 143 m_opaque_ptr->m_rsync_remote_path_prefix = remote_path_prefix; 144 else 145 m_opaque_ptr->m_rsync_remote_path_prefix.clear(); 146 147 if (options && options[0]) 148 m_opaque_ptr->m_rsync_options = options; 149 else 150 m_opaque_ptr->m_rsync_options.clear(); 151 } 152 153 void SBPlatformConnectOptions::DisableRsync() { 154 LLDB_RECORD_METHOD_NO_ARGS(void, SBPlatformConnectOptions, DisableRsync); 155 156 m_opaque_ptr->m_rsync_enabled = false; 157 } 158 159 const char *SBPlatformConnectOptions::GetLocalCacheDirectory() { 160 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatformConnectOptions, 161 GetLocalCacheDirectory); 162 163 return m_opaque_ptr->m_local_cache_directory.GetCString(); 164 } 165 166 void SBPlatformConnectOptions::SetLocalCacheDirectory(const char *path) { 167 LLDB_RECORD_METHOD(void, SBPlatformConnectOptions, SetLocalCacheDirectory, 168 (const char *), path); 169 170 if (path && path[0]) 171 m_opaque_ptr->m_local_cache_directory.SetCString(path); 172 else 173 m_opaque_ptr->m_local_cache_directory = ConstString(); 174 } 175 176 // SBPlatformShellCommand 177 SBPlatformShellCommand::SBPlatformShellCommand(const char *shell_interpreter, 178 const char *shell_command) 179 : m_opaque_ptr(new PlatformShellCommand(shell_interpreter, shell_command)) { 180 LLDB_RECORD_CONSTRUCTOR(SBPlatformShellCommand, (const char *, const char *), 181 shell_interpreter, shell_command); 182 } 183 184 SBPlatformShellCommand::SBPlatformShellCommand(const char *shell_command) 185 : m_opaque_ptr(new PlatformShellCommand(shell_command)) { 186 LLDB_RECORD_CONSTRUCTOR(SBPlatformShellCommand, (const char *), 187 shell_command); 188 } 189 190 SBPlatformShellCommand::SBPlatformShellCommand( 191 const SBPlatformShellCommand &rhs) 192 : m_opaque_ptr(new PlatformShellCommand()) { 193 LLDB_RECORD_CONSTRUCTOR(SBPlatformShellCommand, 194 (const lldb::SBPlatformShellCommand &), rhs); 195 196 *m_opaque_ptr = *rhs.m_opaque_ptr; 197 } 198 199 SBPlatformShellCommand & 200 SBPlatformShellCommand::operator=(const SBPlatformShellCommand &rhs) { 201 202 LLDB_RECORD_METHOD( 203 SBPlatformShellCommand &, 204 SBPlatformShellCommand, operator=,(const lldb::SBPlatformShellCommand &), 205 rhs); 206 207 *m_opaque_ptr = *rhs.m_opaque_ptr; 208 return LLDB_RECORD_RESULT(*this); 209 } 210 211 SBPlatformShellCommand::~SBPlatformShellCommand() { delete m_opaque_ptr; } 212 213 void SBPlatformShellCommand::Clear() { 214 LLDB_RECORD_METHOD_NO_ARGS(void, SBPlatformShellCommand, Clear); 215 216 m_opaque_ptr->m_output = std::string(); 217 m_opaque_ptr->m_status = 0; 218 m_opaque_ptr->m_signo = 0; 219 } 220 221 const char *SBPlatformShellCommand::GetShell() { 222 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatformShellCommand, GetShell); 223 224 if (m_opaque_ptr->m_shell.empty()) 225 return nullptr; 226 return m_opaque_ptr->m_shell.c_str(); 227 } 228 229 void SBPlatformShellCommand::SetShell(const char *shell_interpreter) { 230 LLDB_RECORD_METHOD(void, SBPlatformShellCommand, SetShell, (const char *), 231 shell_interpreter); 232 233 if (shell_interpreter && shell_interpreter[0]) 234 m_opaque_ptr->m_shell = shell_interpreter; 235 else 236 m_opaque_ptr->m_shell.clear(); 237 } 238 239 const char *SBPlatformShellCommand::GetCommand() { 240 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatformShellCommand, GetCommand); 241 242 if (m_opaque_ptr->m_command.empty()) 243 return nullptr; 244 return m_opaque_ptr->m_command.c_str(); 245 } 246 247 void SBPlatformShellCommand::SetCommand(const char *shell_command) { 248 LLDB_RECORD_METHOD(void, SBPlatformShellCommand, SetCommand, (const char *), 249 shell_command); 250 251 if (shell_command && shell_command[0]) 252 m_opaque_ptr->m_command = shell_command; 253 else 254 m_opaque_ptr->m_command.clear(); 255 } 256 257 const char *SBPlatformShellCommand::GetWorkingDirectory() { 258 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatformShellCommand, 259 GetWorkingDirectory); 260 261 if (m_opaque_ptr->m_working_dir.empty()) 262 return nullptr; 263 return m_opaque_ptr->m_working_dir.c_str(); 264 } 265 266 void SBPlatformShellCommand::SetWorkingDirectory(const char *path) { 267 LLDB_RECORD_METHOD(void, SBPlatformShellCommand, SetWorkingDirectory, 268 (const char *), path); 269 270 if (path && path[0]) 271 m_opaque_ptr->m_working_dir = path; 272 else 273 m_opaque_ptr->m_working_dir.clear(); 274 } 275 276 uint32_t SBPlatformShellCommand::GetTimeoutSeconds() { 277 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBPlatformShellCommand, 278 GetTimeoutSeconds); 279 280 if (m_opaque_ptr->m_timeout) 281 return m_opaque_ptr->m_timeout->count(); 282 return UINT32_MAX; 283 } 284 285 void SBPlatformShellCommand::SetTimeoutSeconds(uint32_t sec) { 286 LLDB_RECORD_METHOD(void, SBPlatformShellCommand, SetTimeoutSeconds, 287 (uint32_t), sec); 288 289 if (sec == UINT32_MAX) 290 m_opaque_ptr->m_timeout = llvm::None; 291 else 292 m_opaque_ptr->m_timeout = std::chrono::seconds(sec); 293 } 294 295 int SBPlatformShellCommand::GetSignal() { 296 LLDB_RECORD_METHOD_NO_ARGS(int, SBPlatformShellCommand, GetSignal); 297 298 return m_opaque_ptr->m_signo; 299 } 300 301 int SBPlatformShellCommand::GetStatus() { 302 LLDB_RECORD_METHOD_NO_ARGS(int, SBPlatformShellCommand, GetStatus); 303 304 return m_opaque_ptr->m_status; 305 } 306 307 const char *SBPlatformShellCommand::GetOutput() { 308 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatformShellCommand, GetOutput); 309 310 if (m_opaque_ptr->m_output.empty()) 311 return nullptr; 312 return m_opaque_ptr->m_output.c_str(); 313 } 314 315 // SBPlatform 316 SBPlatform::SBPlatform() : m_opaque_sp() { 317 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBPlatform); 318 } 319 320 SBPlatform::SBPlatform(const char *platform_name) : m_opaque_sp() { 321 LLDB_RECORD_CONSTRUCTOR(SBPlatform, (const char *), platform_name); 322 323 Status error; 324 if (platform_name && platform_name[0]) 325 m_opaque_sp = Platform::Create(ConstString(platform_name), error); 326 } 327 328 SBPlatform::SBPlatform(const SBPlatform &rhs) { 329 LLDB_RECORD_CONSTRUCTOR(SBPlatform, (const lldb::SBPlatform &), rhs); 330 331 m_opaque_sp = rhs.m_opaque_sp; 332 } 333 334 SBPlatform &SBPlatform::operator=(const SBPlatform &rhs) { 335 LLDB_RECORD_METHOD(SBPlatform &, 336 SBPlatform, operator=,(const lldb::SBPlatform &), rhs); 337 338 m_opaque_sp = rhs.m_opaque_sp; 339 return LLDB_RECORD_RESULT(*this); 340 } 341 342 SBPlatform::~SBPlatform() = default; 343 344 SBPlatform SBPlatform::GetHostPlatform() { 345 LLDB_RECORD_STATIC_METHOD_NO_ARGS(lldb::SBPlatform, SBPlatform, 346 GetHostPlatform); 347 348 SBPlatform host_platform; 349 host_platform.m_opaque_sp = Platform::GetHostPlatform(); 350 return LLDB_RECORD_RESULT(host_platform); 351 } 352 353 bool SBPlatform::IsValid() const { 354 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBPlatform, IsValid); 355 return this->operator bool(); 356 } 357 SBPlatform::operator bool() const { 358 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBPlatform, operator bool); 359 360 return m_opaque_sp.get() != nullptr; 361 } 362 363 void SBPlatform::Clear() { 364 LLDB_RECORD_METHOD_NO_ARGS(void, SBPlatform, Clear); 365 366 m_opaque_sp.reset(); 367 } 368 369 const char *SBPlatform::GetName() { 370 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatform, GetName); 371 372 PlatformSP platform_sp(GetSP()); 373 if (platform_sp) 374 return platform_sp->GetName().GetCString(); 375 return nullptr; 376 } 377 378 lldb::PlatformSP SBPlatform::GetSP() const { return m_opaque_sp; } 379 380 void SBPlatform::SetSP(const lldb::PlatformSP &platform_sp) { 381 m_opaque_sp = platform_sp; 382 } 383 384 const char *SBPlatform::GetWorkingDirectory() { 385 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatform, GetWorkingDirectory); 386 387 PlatformSP platform_sp(GetSP()); 388 if (platform_sp) 389 return platform_sp->GetWorkingDirectory().GetCString(); 390 return nullptr; 391 } 392 393 bool SBPlatform::SetWorkingDirectory(const char *path) { 394 LLDB_RECORD_METHOD(bool, SBPlatform, SetWorkingDirectory, (const char *), 395 path); 396 397 PlatformSP platform_sp(GetSP()); 398 if (platform_sp) { 399 if (path) 400 platform_sp->SetWorkingDirectory(FileSpec(path)); 401 else 402 platform_sp->SetWorkingDirectory(FileSpec()); 403 return true; 404 } 405 return false; 406 } 407 408 SBError SBPlatform::ConnectRemote(SBPlatformConnectOptions &connect_options) { 409 LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, ConnectRemote, 410 (lldb::SBPlatformConnectOptions &), connect_options); 411 412 SBError sb_error; 413 PlatformSP platform_sp(GetSP()); 414 if (platform_sp && connect_options.GetURL()) { 415 Args args; 416 args.AppendArgument(connect_options.GetURL()); 417 sb_error.ref() = platform_sp->ConnectRemote(args); 418 } else { 419 sb_error.SetErrorString("invalid platform"); 420 } 421 return LLDB_RECORD_RESULT(sb_error); 422 } 423 424 void SBPlatform::DisconnectRemote() { 425 LLDB_RECORD_METHOD_NO_ARGS(void, SBPlatform, DisconnectRemote); 426 427 PlatformSP platform_sp(GetSP()); 428 if (platform_sp) 429 platform_sp->DisconnectRemote(); 430 } 431 432 bool SBPlatform::IsConnected() { 433 LLDB_RECORD_METHOD_NO_ARGS(bool, SBPlatform, IsConnected); 434 435 PlatformSP platform_sp(GetSP()); 436 if (platform_sp) 437 return platform_sp->IsConnected(); 438 return false; 439 } 440 441 const char *SBPlatform::GetTriple() { 442 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatform, GetTriple); 443 444 PlatformSP platform_sp(GetSP()); 445 if (platform_sp) { 446 ArchSpec arch(platform_sp->GetSystemArchitecture()); 447 if (arch.IsValid()) { 448 // Const-ify the string so we don't need to worry about the lifetime of 449 // the string 450 return ConstString(arch.GetTriple().getTriple().c_str()).GetCString(); 451 } 452 } 453 return nullptr; 454 } 455 456 const char *SBPlatform::GetOSBuild() { 457 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatform, GetOSBuild); 458 459 PlatformSP platform_sp(GetSP()); 460 if (platform_sp) { 461 std::string s = platform_sp->GetOSBuildString().getValueOr(""); 462 if (!s.empty()) { 463 // Const-ify the string so we don't need to worry about the lifetime of 464 // the string 465 return ConstString(s).GetCString(); 466 } 467 } 468 return nullptr; 469 } 470 471 const char *SBPlatform::GetOSDescription() { 472 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatform, GetOSDescription); 473 474 PlatformSP platform_sp(GetSP()); 475 if (platform_sp) { 476 std::string s; 477 if (platform_sp->GetOSKernelDescription(s)) { 478 if (!s.empty()) { 479 // Const-ify the string so we don't need to worry about the lifetime of 480 // the string 481 return ConstString(s.c_str()).GetCString(); 482 } 483 } 484 } 485 return nullptr; 486 } 487 488 const char *SBPlatform::GetHostname() { 489 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatform, GetHostname); 490 491 PlatformSP platform_sp(GetSP()); 492 if (platform_sp) 493 return platform_sp->GetHostname(); 494 return nullptr; 495 } 496 497 uint32_t SBPlatform::GetOSMajorVersion() { 498 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBPlatform, GetOSMajorVersion); 499 500 llvm::VersionTuple version; 501 if (PlatformSP platform_sp = GetSP()) 502 version = platform_sp->GetOSVersion(); 503 return version.empty() ? UINT32_MAX : version.getMajor(); 504 } 505 506 uint32_t SBPlatform::GetOSMinorVersion() { 507 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBPlatform, GetOSMinorVersion); 508 509 llvm::VersionTuple version; 510 if (PlatformSP platform_sp = GetSP()) 511 version = platform_sp->GetOSVersion(); 512 return version.getMinor().getValueOr(UINT32_MAX); 513 } 514 515 uint32_t SBPlatform::GetOSUpdateVersion() { 516 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBPlatform, GetOSUpdateVersion); 517 518 llvm::VersionTuple version; 519 if (PlatformSP platform_sp = GetSP()) 520 version = platform_sp->GetOSVersion(); 521 return version.getSubminor().getValueOr(UINT32_MAX); 522 } 523 524 SBError SBPlatform::Get(SBFileSpec &src, SBFileSpec &dst) { 525 LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, Get, 526 (lldb::SBFileSpec &, lldb::SBFileSpec &), src, dst); 527 528 SBError sb_error; 529 PlatformSP platform_sp(GetSP()); 530 if (platform_sp) { 531 sb_error.ref() = platform_sp->GetFile(src.ref(), dst.ref()); 532 } else { 533 sb_error.SetErrorString("invalid platform"); 534 } 535 return LLDB_RECORD_RESULT(sb_error); 536 } 537 538 SBError SBPlatform::Put(SBFileSpec &src, SBFileSpec &dst) { 539 LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, Put, 540 (lldb::SBFileSpec &, lldb::SBFileSpec &), src, dst); 541 return LLDB_RECORD_RESULT( 542 ExecuteConnected([&](const lldb::PlatformSP &platform_sp) { 543 if (src.Exists()) { 544 uint32_t permissions = 545 FileSystem::Instance().GetPermissions(src.ref()); 546 if (permissions == 0) { 547 if (FileSystem::Instance().IsDirectory(src.ref())) 548 permissions = eFilePermissionsDirectoryDefault; 549 else 550 permissions = eFilePermissionsFileDefault; 551 } 552 553 return platform_sp->PutFile(src.ref(), dst.ref(), permissions); 554 } 555 556 Status error; 557 error.SetErrorStringWithFormat("'src' argument doesn't exist: '%s'", 558 src.ref().GetPath().c_str()); 559 return error; 560 })); 561 } 562 563 SBError SBPlatform::Install(SBFileSpec &src, SBFileSpec &dst) { 564 LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, Install, 565 (lldb::SBFileSpec &, lldb::SBFileSpec &), src, dst); 566 return LLDB_RECORD_RESULT( 567 ExecuteConnected([&](const lldb::PlatformSP &platform_sp) { 568 if (src.Exists()) 569 return platform_sp->Install(src.ref(), dst.ref()); 570 571 Status error; 572 error.SetErrorStringWithFormat("'src' argument doesn't exist: '%s'", 573 src.ref().GetPath().c_str()); 574 return error; 575 })); 576 } 577 578 SBError SBPlatform::Run(SBPlatformShellCommand &shell_command) { 579 LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, Run, 580 (lldb::SBPlatformShellCommand &), shell_command); 581 return LLDB_RECORD_RESULT( 582 ExecuteConnected([&](const lldb::PlatformSP &platform_sp) { 583 const char *command = shell_command.GetCommand(); 584 if (!command) 585 return Status("invalid shell command (empty)"); 586 587 const char *working_dir = shell_command.GetWorkingDirectory(); 588 if (working_dir == nullptr) { 589 working_dir = platform_sp->GetWorkingDirectory().GetCString(); 590 if (working_dir) 591 shell_command.SetWorkingDirectory(working_dir); 592 } 593 return platform_sp->RunShellCommand( 594 shell_command.m_opaque_ptr->m_shell, command, FileSpec(working_dir), 595 &shell_command.m_opaque_ptr->m_status, 596 &shell_command.m_opaque_ptr->m_signo, 597 &shell_command.m_opaque_ptr->m_output, 598 shell_command.m_opaque_ptr->m_timeout); 599 })); 600 } 601 602 SBError SBPlatform::Launch(SBLaunchInfo &launch_info) { 603 LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, Launch, (lldb::SBLaunchInfo &), 604 launch_info); 605 return LLDB_RECORD_RESULT( 606 ExecuteConnected([&](const lldb::PlatformSP &platform_sp) { 607 ProcessLaunchInfo info = launch_info.ref(); 608 Status error = platform_sp->LaunchProcess(info); 609 launch_info.set_ref(info); 610 return error; 611 })); 612 } 613 614 SBError SBPlatform::Kill(const lldb::pid_t pid) { 615 LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, Kill, (const lldb::pid_t), pid); 616 return LLDB_RECORD_RESULT( 617 ExecuteConnected([&](const lldb::PlatformSP &platform_sp) { 618 return platform_sp->KillProcess(pid); 619 })); 620 } 621 622 SBError SBPlatform::ExecuteConnected( 623 const std::function<Status(const lldb::PlatformSP &)> &func) { 624 SBError sb_error; 625 const auto platform_sp(GetSP()); 626 if (platform_sp) { 627 if (platform_sp->IsConnected()) 628 sb_error.ref() = func(platform_sp); 629 else 630 sb_error.SetErrorString("not connected"); 631 } else 632 sb_error.SetErrorString("invalid platform"); 633 634 return sb_error; 635 } 636 637 SBError SBPlatform::MakeDirectory(const char *path, uint32_t file_permissions) { 638 LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, MakeDirectory, 639 (const char *, uint32_t), path, file_permissions); 640 641 SBError sb_error; 642 PlatformSP platform_sp(GetSP()); 643 if (platform_sp) { 644 sb_error.ref() = 645 platform_sp->MakeDirectory(FileSpec(path), file_permissions); 646 } else { 647 sb_error.SetErrorString("invalid platform"); 648 } 649 return LLDB_RECORD_RESULT(sb_error); 650 } 651 652 uint32_t SBPlatform::GetFilePermissions(const char *path) { 653 LLDB_RECORD_METHOD(uint32_t, SBPlatform, GetFilePermissions, (const char *), 654 path); 655 656 PlatformSP platform_sp(GetSP()); 657 if (platform_sp) { 658 uint32_t file_permissions = 0; 659 platform_sp->GetFilePermissions(FileSpec(path), file_permissions); 660 return file_permissions; 661 } 662 return 0; 663 } 664 665 SBError SBPlatform::SetFilePermissions(const char *path, 666 uint32_t file_permissions) { 667 LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, SetFilePermissions, 668 (const char *, uint32_t), path, file_permissions); 669 670 SBError sb_error; 671 PlatformSP platform_sp(GetSP()); 672 if (platform_sp) { 673 sb_error.ref() = 674 platform_sp->SetFilePermissions(FileSpec(path), file_permissions); 675 } else { 676 sb_error.SetErrorString("invalid platform"); 677 } 678 return LLDB_RECORD_RESULT(sb_error); 679 } 680 681 SBUnixSignals SBPlatform::GetUnixSignals() const { 682 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBUnixSignals, SBPlatform, 683 GetUnixSignals); 684 685 if (auto platform_sp = GetSP()) 686 return LLDB_RECORD_RESULT(SBUnixSignals{platform_sp}); 687 688 return LLDB_RECORD_RESULT(SBUnixSignals()); 689 } 690 691 SBEnvironment SBPlatform::GetEnvironment() { 692 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBEnvironment, SBPlatform, GetEnvironment); 693 PlatformSP platform_sp(GetSP()); 694 695 if (platform_sp) { 696 return LLDB_RECORD_RESULT(SBEnvironment(platform_sp->GetEnvironment())); 697 } 698 699 return LLDB_RECORD_RESULT(SBEnvironment()); 700 } 701 702 namespace lldb_private { 703 namespace repro { 704 705 template <> void RegisterMethods<SBPlatformConnectOptions>(Registry &R) { 706 LLDB_REGISTER_CONSTRUCTOR(SBPlatformConnectOptions, (const char *)); 707 LLDB_REGISTER_CONSTRUCTOR(SBPlatformConnectOptions, 708 (const lldb::SBPlatformConnectOptions &)); 709 LLDB_REGISTER_METHOD( 710 SBPlatformConnectOptions &, 711 SBPlatformConnectOptions, operator=,( 712 const lldb::SBPlatformConnectOptions &)); 713 LLDB_REGISTER_METHOD(const char *, SBPlatformConnectOptions, GetURL, ()); 714 LLDB_REGISTER_METHOD(void, SBPlatformConnectOptions, SetURL, (const char *)); 715 LLDB_REGISTER_METHOD(bool, SBPlatformConnectOptions, GetRsyncEnabled, ()); 716 LLDB_REGISTER_METHOD(void, SBPlatformConnectOptions, EnableRsync, 717 (const char *, const char *, bool)); 718 LLDB_REGISTER_METHOD(void, SBPlatformConnectOptions, DisableRsync, ()); 719 LLDB_REGISTER_METHOD(const char *, SBPlatformConnectOptions, 720 GetLocalCacheDirectory, ()); 721 LLDB_REGISTER_METHOD(void, SBPlatformConnectOptions, SetLocalCacheDirectory, 722 (const char *)); 723 } 724 725 template <> void RegisterMethods<SBPlatformShellCommand>(Registry &R) { 726 LLDB_REGISTER_CONSTRUCTOR(SBPlatformShellCommand, (const char *)); 727 LLDB_REGISTER_CONSTRUCTOR(SBPlatformShellCommand, 728 (const lldb::SBPlatformShellCommand &)); 729 LLDB_REGISTER_METHOD( 730 SBPlatformShellCommand &, 731 SBPlatformShellCommand, operator=,(const lldb::SBPlatformShellCommand &)); 732 LLDB_REGISTER_METHOD(void, SBPlatformShellCommand, Clear, ()); 733 LLDB_REGISTER_METHOD(const char *, SBPlatformShellCommand, GetShell, ()); 734 LLDB_REGISTER_METHOD(void, SBPlatformShellCommand, SetShell, (const char *)); 735 LLDB_REGISTER_METHOD(const char *, SBPlatformShellCommand, GetCommand, ()); 736 LLDB_REGISTER_METHOD(void, SBPlatformShellCommand, SetCommand, 737 (const char *)); 738 LLDB_REGISTER_METHOD(const char *, SBPlatformShellCommand, 739 GetWorkingDirectory, ()); 740 LLDB_REGISTER_METHOD(void, SBPlatformShellCommand, SetWorkingDirectory, 741 (const char *)); 742 LLDB_REGISTER_METHOD(uint32_t, SBPlatformShellCommand, GetTimeoutSeconds, ()); 743 LLDB_REGISTER_METHOD(void, SBPlatformShellCommand, SetTimeoutSeconds, 744 (uint32_t)); 745 LLDB_REGISTER_METHOD(int, SBPlatformShellCommand, GetSignal, ()); 746 LLDB_REGISTER_METHOD(int, SBPlatformShellCommand, GetStatus, ()); 747 LLDB_REGISTER_METHOD(const char *, SBPlatformShellCommand, GetOutput, ()); 748 } 749 750 template <> void RegisterMethods<SBPlatform>(Registry &R) { 751 LLDB_REGISTER_CONSTRUCTOR(SBPlatform, ()); 752 LLDB_REGISTER_CONSTRUCTOR(SBPlatform, (const char *)); 753 LLDB_REGISTER_CONSTRUCTOR(SBPlatform, (const lldb::SBPlatform &)); 754 LLDB_REGISTER_CONSTRUCTOR(SBPlatformShellCommand, 755 (const char *, const char *)); 756 LLDB_REGISTER_METHOD(SBPlatform &, 757 SBPlatform, operator=,(const lldb::SBPlatform &)); 758 LLDB_REGISTER_METHOD_CONST(bool, SBPlatform, IsValid, ()); 759 LLDB_REGISTER_METHOD_CONST(bool, SBPlatform, operator bool,()); 760 LLDB_REGISTER_METHOD(void, SBPlatform, Clear, ()); 761 LLDB_REGISTER_METHOD(const char *, SBPlatform, GetName, ()); 762 LLDB_REGISTER_METHOD(const char *, SBPlatform, GetWorkingDirectory, ()); 763 LLDB_REGISTER_METHOD(bool, SBPlatform, SetWorkingDirectory, (const char *)); 764 LLDB_REGISTER_METHOD(lldb::SBError, SBPlatform, ConnectRemote, 765 (lldb::SBPlatformConnectOptions &)); 766 LLDB_REGISTER_METHOD(void, SBPlatform, DisconnectRemote, ()); 767 LLDB_REGISTER_METHOD(bool, SBPlatform, IsConnected, ()); 768 LLDB_REGISTER_METHOD(const char *, SBPlatform, GetTriple, ()); 769 LLDB_REGISTER_METHOD(const char *, SBPlatform, GetOSBuild, ()); 770 LLDB_REGISTER_METHOD(const char *, SBPlatform, GetOSDescription, ()); 771 LLDB_REGISTER_METHOD(const char *, SBPlatform, GetHostname, ()); 772 LLDB_REGISTER_METHOD(uint32_t, SBPlatform, GetOSMajorVersion, ()); 773 LLDB_REGISTER_METHOD(uint32_t, SBPlatform, GetOSMinorVersion, ()); 774 LLDB_REGISTER_METHOD(uint32_t, SBPlatform, GetOSUpdateVersion, ()); 775 LLDB_REGISTER_METHOD(lldb::SBError, SBPlatform, Get, 776 (lldb::SBFileSpec &, lldb::SBFileSpec &)); 777 LLDB_REGISTER_METHOD(lldb::SBError, SBPlatform, Put, 778 (lldb::SBFileSpec &, lldb::SBFileSpec &)); 779 LLDB_REGISTER_METHOD(lldb::SBError, SBPlatform, Install, 780 (lldb::SBFileSpec &, lldb::SBFileSpec &)); 781 LLDB_REGISTER_METHOD(lldb::SBError, SBPlatform, Run, 782 (lldb::SBPlatformShellCommand &)); 783 LLDB_REGISTER_METHOD(lldb::SBError, SBPlatform, Launch, 784 (lldb::SBLaunchInfo &)); 785 LLDB_REGISTER_METHOD(lldb::SBError, SBPlatform, Kill, (const lldb::pid_t)); 786 LLDB_REGISTER_METHOD(lldb::SBError, SBPlatform, MakeDirectory, 787 (const char *, uint32_t)); 788 LLDB_REGISTER_METHOD(uint32_t, SBPlatform, GetFilePermissions, 789 (const char *)); 790 LLDB_REGISTER_METHOD(lldb::SBError, SBPlatform, SetFilePermissions, 791 (const char *, uint32_t)); 792 LLDB_REGISTER_METHOD(lldb::SBEnvironment, SBPlatform, GetEnvironment, ()); 793 LLDB_REGISTER_METHOD_CONST(lldb::SBUnixSignals, SBPlatform, GetUnixSignals, 794 ()); 795 LLDB_REGISTER_STATIC_METHOD(lldb::SBPlatform, SBPlatform, GetHostPlatform, 796 ()); 797 } 798 799 } // namespace repro 800 } // namespace lldb_private 801