1cfca06d7SDimitry Andric //===-- SBPlatform.cpp ----------------------------------------------------===//
286758c71SEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
686758c71SEd Maste //
786758c71SEd Maste //===----------------------------------------------------------------------===//
886758c71SEd Maste
986758c71SEd Maste #include "lldb/API/SBPlatform.h"
10b1c73532SDimitry Andric #include "lldb/API/SBDebugger.h"
11cfca06d7SDimitry Andric #include "lldb/API/SBEnvironment.h"
1286758c71SEd Maste #include "lldb/API/SBError.h"
1386758c71SEd Maste #include "lldb/API/SBFileSpec.h"
1412bd4897SEd Maste #include "lldb/API/SBLaunchInfo.h"
157fa27ce4SDimitry Andric #include "lldb/API/SBModuleSpec.h"
16cfca06d7SDimitry Andric #include "lldb/API/SBPlatform.h"
17b1c73532SDimitry Andric #include "lldb/API/SBProcessInfoList.h"
18b1c73532SDimitry Andric #include "lldb/API/SBTarget.h"
19027f1c96SDimitry Andric #include "lldb/API/SBUnixSignals.h"
2086758c71SEd Maste #include "lldb/Host/File.h"
2186758c71SEd Maste #include "lldb/Target/Platform.h"
2214f1b3e8SDimitry Andric #include "lldb/Target/Target.h"
23ef5d0b5eSDimitry Andric #include "lldb/Utility/ArchSpec.h"
24f73363f1SDimitry Andric #include "lldb/Utility/Args.h"
256f8fc217SDimitry Andric #include "lldb/Utility/Instrumentation.h"
26b76161e4SDimitry Andric #include "lldb/Utility/Status.h"
2774a628f7SDimitry Andric
2874a628f7SDimitry Andric #include "llvm/Support/FileSystem.h"
2986758c71SEd Maste
3012bd4897SEd Maste #include <functional>
3112bd4897SEd Maste
3286758c71SEd Maste using namespace lldb;
3386758c71SEd Maste using namespace lldb_private;
3486758c71SEd Maste
3586758c71SEd Maste // PlatformConnectOptions
3686758c71SEd Maste struct PlatformConnectOptions {
PlatformConnectOptionsPlatformConnectOptions376f8fc217SDimitry Andric PlatformConnectOptions(const char *url = nullptr) {
3886758c71SEd Maste if (url && url[0])
3986758c71SEd Maste m_url = url;
4086758c71SEd Maste }
4186758c71SEd Maste
42cfca06d7SDimitry Andric ~PlatformConnectOptions() = default;
4386758c71SEd Maste
4486758c71SEd Maste std::string m_url;
4586758c71SEd Maste std::string m_rsync_options;
4686758c71SEd Maste std::string m_rsync_remote_path_prefix;
47344a3780SDimitry Andric bool m_rsync_enabled = false;
48344a3780SDimitry Andric bool m_rsync_omit_hostname_from_remote_path = false;
4986758c71SEd Maste ConstString m_local_cache_directory;
5086758c71SEd Maste };
5186758c71SEd Maste
5286758c71SEd Maste // PlatformShellCommand
5386758c71SEd Maste struct PlatformShellCommand {
PlatformShellCommandPlatformShellCommand54b60736ecSDimitry Andric PlatformShellCommand(llvm::StringRef shell_interpreter,
55145449b1SDimitry Andric llvm::StringRef shell_command) {
56b60736ecSDimitry Andric if (!shell_interpreter.empty())
57b60736ecSDimitry Andric m_shell = shell_interpreter.str();
58b60736ecSDimitry Andric
59b60736ecSDimitry Andric if (!m_shell.empty() && !shell_command.empty())
60b60736ecSDimitry Andric m_command = shell_command.str();
61b60736ecSDimitry Andric }
62b60736ecSDimitry Andric
PlatformShellCommandPlatformShellCommand636f8fc217SDimitry Andric PlatformShellCommand(llvm::StringRef shell_command = llvm::StringRef()) {
64b60736ecSDimitry Andric if (!shell_command.empty())
65b60736ecSDimitry Andric m_command = shell_command.str();
6686758c71SEd Maste }
6786758c71SEd Maste
68cfca06d7SDimitry Andric ~PlatformShellCommand() = default;
6986758c71SEd Maste
70b60736ecSDimitry Andric std::string m_shell;
7186758c71SEd Maste std::string m_command;
7286758c71SEd Maste std::string m_working_dir;
7386758c71SEd Maste std::string m_output;
74344a3780SDimitry Andric int m_status = 0;
75344a3780SDimitry Andric int m_signo = 0;
76e3b55780SDimitry Andric Timeout<std::ratio<1>> m_timeout = std::nullopt;
7786758c71SEd Maste };
7886758c71SEd Maste // SBPlatformConnectOptions
SBPlatformConnectOptions(const char * url)7914f1b3e8SDimitry Andric SBPlatformConnectOptions::SBPlatformConnectOptions(const char *url)
805f29bb8aSDimitry Andric : m_opaque_ptr(new PlatformConnectOptions(url)) {
816f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, url);
825f29bb8aSDimitry Andric }
8386758c71SEd Maste
SBPlatformConnectOptions(const SBPlatformConnectOptions & rhs)8414f1b3e8SDimitry Andric SBPlatformConnectOptions::SBPlatformConnectOptions(
8514f1b3e8SDimitry Andric const SBPlatformConnectOptions &rhs)
8614f1b3e8SDimitry Andric : m_opaque_ptr(new PlatformConnectOptions()) {
876f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, rhs);
885f29bb8aSDimitry Andric
8986758c71SEd Maste *m_opaque_ptr = *rhs.m_opaque_ptr;
9086758c71SEd Maste }
9186758c71SEd Maste
~SBPlatformConnectOptions()9214f1b3e8SDimitry Andric SBPlatformConnectOptions::~SBPlatformConnectOptions() { delete m_opaque_ptr; }
9386758c71SEd Maste
94b60736ecSDimitry Andric SBPlatformConnectOptions &
operator =(const SBPlatformConnectOptions & rhs)95b60736ecSDimitry Andric SBPlatformConnectOptions::operator=(const SBPlatformConnectOptions &rhs) {
966f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, rhs);
975f29bb8aSDimitry Andric
9886758c71SEd Maste *m_opaque_ptr = *rhs.m_opaque_ptr;
996f8fc217SDimitry Andric return *this;
10086758c71SEd Maste }
10186758c71SEd Maste
GetURL()10214f1b3e8SDimitry Andric const char *SBPlatformConnectOptions::GetURL() {
1036f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
1045f29bb8aSDimitry Andric
10586758c71SEd Maste if (m_opaque_ptr->m_url.empty())
1065f29bb8aSDimitry Andric return nullptr;
1077fa27ce4SDimitry Andric return ConstString(m_opaque_ptr->m_url.c_str()).GetCString();
10886758c71SEd Maste }
10986758c71SEd Maste
SetURL(const char * url)11014f1b3e8SDimitry Andric void SBPlatformConnectOptions::SetURL(const char *url) {
1116f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, url);
1125f29bb8aSDimitry Andric
11386758c71SEd Maste if (url && url[0])
11486758c71SEd Maste m_opaque_ptr->m_url = url;
11586758c71SEd Maste else
11686758c71SEd Maste m_opaque_ptr->m_url.clear();
11786758c71SEd Maste }
11886758c71SEd Maste
GetRsyncEnabled()11914f1b3e8SDimitry Andric bool SBPlatformConnectOptions::GetRsyncEnabled() {
1206f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
1215f29bb8aSDimitry Andric
12286758c71SEd Maste return m_opaque_ptr->m_rsync_enabled;
12386758c71SEd Maste }
12486758c71SEd Maste
EnableRsync(const char * options,const char * remote_path_prefix,bool omit_hostname_from_remote_path)12514f1b3e8SDimitry Andric void SBPlatformConnectOptions::EnableRsync(
12614f1b3e8SDimitry Andric const char *options, const char *remote_path_prefix,
12714f1b3e8SDimitry Andric bool omit_hostname_from_remote_path) {
1286f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, options, remote_path_prefix,
1296f8fc217SDimitry Andric omit_hostname_from_remote_path);
1305f29bb8aSDimitry Andric
13186758c71SEd Maste m_opaque_ptr->m_rsync_enabled = true;
13214f1b3e8SDimitry Andric m_opaque_ptr->m_rsync_omit_hostname_from_remote_path =
13314f1b3e8SDimitry Andric omit_hostname_from_remote_path;
13486758c71SEd Maste if (remote_path_prefix && remote_path_prefix[0])
13586758c71SEd Maste m_opaque_ptr->m_rsync_remote_path_prefix = remote_path_prefix;
13686758c71SEd Maste else
13786758c71SEd Maste m_opaque_ptr->m_rsync_remote_path_prefix.clear();
13886758c71SEd Maste
13986758c71SEd Maste if (options && options[0])
14086758c71SEd Maste m_opaque_ptr->m_rsync_options = options;
14186758c71SEd Maste else
14286758c71SEd Maste m_opaque_ptr->m_rsync_options.clear();
14386758c71SEd Maste }
14486758c71SEd Maste
DisableRsync()14514f1b3e8SDimitry Andric void SBPlatformConnectOptions::DisableRsync() {
1466f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
1475f29bb8aSDimitry Andric
14886758c71SEd Maste m_opaque_ptr->m_rsync_enabled = false;
14986758c71SEd Maste }
15086758c71SEd Maste
GetLocalCacheDirectory()15114f1b3e8SDimitry Andric const char *SBPlatformConnectOptions::GetLocalCacheDirectory() {
1526f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
1535f29bb8aSDimitry Andric
15486758c71SEd Maste return m_opaque_ptr->m_local_cache_directory.GetCString();
15586758c71SEd Maste }
15686758c71SEd Maste
SetLocalCacheDirectory(const char * path)15714f1b3e8SDimitry Andric void SBPlatformConnectOptions::SetLocalCacheDirectory(const char *path) {
1586f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, path);
1595f29bb8aSDimitry Andric
16086758c71SEd Maste if (path && path[0])
16186758c71SEd Maste m_opaque_ptr->m_local_cache_directory.SetCString(path);
16286758c71SEd Maste else
16386758c71SEd Maste m_opaque_ptr->m_local_cache_directory = ConstString();
16486758c71SEd Maste }
16586758c71SEd Maste
16686758c71SEd Maste // SBPlatformShellCommand
SBPlatformShellCommand(const char * shell_interpreter,const char * shell_command)167b60736ecSDimitry Andric SBPlatformShellCommand::SBPlatformShellCommand(const char *shell_interpreter,
168b60736ecSDimitry Andric const char *shell_command)
169b60736ecSDimitry Andric : m_opaque_ptr(new PlatformShellCommand(shell_interpreter, shell_command)) {
1706f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, shell_interpreter, shell_command);
171b60736ecSDimitry Andric }
172b60736ecSDimitry Andric
SBPlatformShellCommand(const char * shell_command)17314f1b3e8SDimitry Andric SBPlatformShellCommand::SBPlatformShellCommand(const char *shell_command)
1745f29bb8aSDimitry Andric : m_opaque_ptr(new PlatformShellCommand(shell_command)) {
1756f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, shell_command);
1765f29bb8aSDimitry Andric }
17786758c71SEd Maste
SBPlatformShellCommand(const SBPlatformShellCommand & rhs)17814f1b3e8SDimitry Andric SBPlatformShellCommand::SBPlatformShellCommand(
17914f1b3e8SDimitry Andric const SBPlatformShellCommand &rhs)
18014f1b3e8SDimitry Andric : m_opaque_ptr(new PlatformShellCommand()) {
1816f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, rhs);
1825f29bb8aSDimitry Andric
18386758c71SEd Maste *m_opaque_ptr = *rhs.m_opaque_ptr;
18486758c71SEd Maste }
18586758c71SEd Maste
186b60736ecSDimitry Andric SBPlatformShellCommand &
operator =(const SBPlatformShellCommand & rhs)187b60736ecSDimitry Andric SBPlatformShellCommand::operator=(const SBPlatformShellCommand &rhs) {
188cfca06d7SDimitry Andric
1896f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, rhs);
190cfca06d7SDimitry Andric
191cfca06d7SDimitry Andric *m_opaque_ptr = *rhs.m_opaque_ptr;
1926f8fc217SDimitry Andric return *this;
193cfca06d7SDimitry Andric }
194cfca06d7SDimitry Andric
~SBPlatformShellCommand()19514f1b3e8SDimitry Andric SBPlatformShellCommand::~SBPlatformShellCommand() { delete m_opaque_ptr; }
19686758c71SEd Maste
Clear()19714f1b3e8SDimitry Andric void SBPlatformShellCommand::Clear() {
1986f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
1995f29bb8aSDimitry Andric
200e81d9d49SDimitry Andric m_opaque_ptr->m_output = std::string();
20186758c71SEd Maste m_opaque_ptr->m_status = 0;
20286758c71SEd Maste m_opaque_ptr->m_signo = 0;
20386758c71SEd Maste }
20486758c71SEd Maste
GetShell()205b60736ecSDimitry Andric const char *SBPlatformShellCommand::GetShell() {
2066f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
207b60736ecSDimitry Andric
208b60736ecSDimitry Andric if (m_opaque_ptr->m_shell.empty())
209b60736ecSDimitry Andric return nullptr;
2107fa27ce4SDimitry Andric return ConstString(m_opaque_ptr->m_shell.c_str()).GetCString();
211b60736ecSDimitry Andric }
212b60736ecSDimitry Andric
SetShell(const char * shell_interpreter)213b60736ecSDimitry Andric void SBPlatformShellCommand::SetShell(const char *shell_interpreter) {
2146f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, shell_interpreter);
215b60736ecSDimitry Andric
216b60736ecSDimitry Andric if (shell_interpreter && shell_interpreter[0])
217b60736ecSDimitry Andric m_opaque_ptr->m_shell = shell_interpreter;
218b60736ecSDimitry Andric else
219b60736ecSDimitry Andric m_opaque_ptr->m_shell.clear();
220b60736ecSDimitry Andric }
221b60736ecSDimitry Andric
GetCommand()22214f1b3e8SDimitry Andric const char *SBPlatformShellCommand::GetCommand() {
2236f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
2245f29bb8aSDimitry Andric
22586758c71SEd Maste if (m_opaque_ptr->m_command.empty())
2265f29bb8aSDimitry Andric return nullptr;
2277fa27ce4SDimitry Andric return ConstString(m_opaque_ptr->m_command.c_str()).GetCString();
22886758c71SEd Maste }
22986758c71SEd Maste
SetCommand(const char * shell_command)23014f1b3e8SDimitry Andric void SBPlatformShellCommand::SetCommand(const char *shell_command) {
2316f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, shell_command);
2325f29bb8aSDimitry Andric
23386758c71SEd Maste if (shell_command && shell_command[0])
23486758c71SEd Maste m_opaque_ptr->m_command = shell_command;
23586758c71SEd Maste else
23686758c71SEd Maste m_opaque_ptr->m_command.clear();
23786758c71SEd Maste }
23886758c71SEd Maste
GetWorkingDirectory()23914f1b3e8SDimitry Andric const char *SBPlatformShellCommand::GetWorkingDirectory() {
2406f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
2415f29bb8aSDimitry Andric
24286758c71SEd Maste if (m_opaque_ptr->m_working_dir.empty())
2435f29bb8aSDimitry Andric return nullptr;
2447fa27ce4SDimitry Andric return ConstString(m_opaque_ptr->m_working_dir.c_str()).GetCString();
24586758c71SEd Maste }
24686758c71SEd Maste
SetWorkingDirectory(const char * path)24714f1b3e8SDimitry Andric void SBPlatformShellCommand::SetWorkingDirectory(const char *path) {
2486f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, path);
2495f29bb8aSDimitry Andric
25086758c71SEd Maste if (path && path[0])
25186758c71SEd Maste m_opaque_ptr->m_working_dir = path;
25286758c71SEd Maste else
25386758c71SEd Maste m_opaque_ptr->m_working_dir.clear();
25486758c71SEd Maste }
25586758c71SEd Maste
GetTimeoutSeconds()25614f1b3e8SDimitry Andric uint32_t SBPlatformShellCommand::GetTimeoutSeconds() {
2576f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
2585f29bb8aSDimitry Andric
259f73363f1SDimitry Andric if (m_opaque_ptr->m_timeout)
260f73363f1SDimitry Andric return m_opaque_ptr->m_timeout->count();
261f73363f1SDimitry Andric return UINT32_MAX;
26286758c71SEd Maste }
26386758c71SEd Maste
SetTimeoutSeconds(uint32_t sec)26414f1b3e8SDimitry Andric void SBPlatformShellCommand::SetTimeoutSeconds(uint32_t sec) {
2656f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, sec);
2665f29bb8aSDimitry Andric
267f73363f1SDimitry Andric if (sec == UINT32_MAX)
268e3b55780SDimitry Andric m_opaque_ptr->m_timeout = std::nullopt;
269f73363f1SDimitry Andric else
270f73363f1SDimitry Andric m_opaque_ptr->m_timeout = std::chrono::seconds(sec);
27186758c71SEd Maste }
27286758c71SEd Maste
GetSignal()2735f29bb8aSDimitry Andric int SBPlatformShellCommand::GetSignal() {
2746f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
27586758c71SEd Maste
2765f29bb8aSDimitry Andric return m_opaque_ptr->m_signo;
2775f29bb8aSDimitry Andric }
2785f29bb8aSDimitry Andric
GetStatus()2795f29bb8aSDimitry Andric int SBPlatformShellCommand::GetStatus() {
2806f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
2815f29bb8aSDimitry Andric
2825f29bb8aSDimitry Andric return m_opaque_ptr->m_status;
2835f29bb8aSDimitry Andric }
28486758c71SEd Maste
GetOutput()28514f1b3e8SDimitry Andric const char *SBPlatformShellCommand::GetOutput() {
2866f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
2875f29bb8aSDimitry Andric
28886758c71SEd Maste if (m_opaque_ptr->m_output.empty())
2895f29bb8aSDimitry Andric return nullptr;
2907fa27ce4SDimitry Andric return ConstString(m_opaque_ptr->m_output.c_str()).GetCString();
29186758c71SEd Maste }
29286758c71SEd Maste
29386758c71SEd Maste // SBPlatform
SBPlatform()2946f8fc217SDimitry Andric SBPlatform::SBPlatform() { LLDB_INSTRUMENT_VA(this); }
29586758c71SEd Maste
SBPlatform(const char * platform_name)2966f8fc217SDimitry Andric SBPlatform::SBPlatform(const char *platform_name) {
2976f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, platform_name);
2985f29bb8aSDimitry Andric
299145449b1SDimitry Andric m_opaque_sp = Platform::Create(platform_name);
30086758c71SEd Maste }
30186758c71SEd Maste
SBPlatform(const SBPlatform & rhs)302cfca06d7SDimitry Andric SBPlatform::SBPlatform(const SBPlatform &rhs) {
3036f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, rhs);
304cfca06d7SDimitry Andric
305cfca06d7SDimitry Andric m_opaque_sp = rhs.m_opaque_sp;
306cfca06d7SDimitry Andric }
307cfca06d7SDimitry Andric
operator =(const SBPlatform & rhs)308cfca06d7SDimitry Andric SBPlatform &SBPlatform::operator=(const SBPlatform &rhs) {
3096f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, rhs);
310cfca06d7SDimitry Andric
311cfca06d7SDimitry Andric m_opaque_sp = rhs.m_opaque_sp;
3126f8fc217SDimitry Andric return *this;
313cfca06d7SDimitry Andric }
314cfca06d7SDimitry Andric
315cfca06d7SDimitry Andric SBPlatform::~SBPlatform() = default;
316cfca06d7SDimitry Andric
GetHostPlatform()317cfca06d7SDimitry Andric SBPlatform SBPlatform::GetHostPlatform() {
3186f8fc217SDimitry Andric LLDB_INSTRUMENT();
319cfca06d7SDimitry Andric
320cfca06d7SDimitry Andric SBPlatform host_platform;
321cfca06d7SDimitry Andric host_platform.m_opaque_sp = Platform::GetHostPlatform();
3226f8fc217SDimitry Andric return host_platform;
323cfca06d7SDimitry Andric }
32486758c71SEd Maste
IsValid() const3255f29bb8aSDimitry Andric bool SBPlatform::IsValid() const {
3266f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
3275f29bb8aSDimitry Andric return this->operator bool();
3285f29bb8aSDimitry Andric }
operator bool() const3295f29bb8aSDimitry Andric SBPlatform::operator bool() const {
3306f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
33186758c71SEd Maste
3325f29bb8aSDimitry Andric return m_opaque_sp.get() != nullptr;
3335f29bb8aSDimitry Andric }
3345f29bb8aSDimitry Andric
Clear()3355f29bb8aSDimitry Andric void SBPlatform::Clear() {
3366f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
3375f29bb8aSDimitry Andric
3385f29bb8aSDimitry Andric m_opaque_sp.reset();
3395f29bb8aSDimitry Andric }
34086758c71SEd Maste
GetName()34114f1b3e8SDimitry Andric const char *SBPlatform::GetName() {
3426f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
3435f29bb8aSDimitry Andric
34486758c71SEd Maste PlatformSP platform_sp(GetSP());
34586758c71SEd Maste if (platform_sp)
346145449b1SDimitry Andric return ConstString(platform_sp->GetName()).AsCString();
3475f29bb8aSDimitry Andric return nullptr;
34886758c71SEd Maste }
34986758c71SEd Maste
GetSP() const35014f1b3e8SDimitry Andric lldb::PlatformSP SBPlatform::GetSP() const { return m_opaque_sp; }
35186758c71SEd Maste
SetSP(const lldb::PlatformSP & platform_sp)35214f1b3e8SDimitry Andric void SBPlatform::SetSP(const lldb::PlatformSP &platform_sp) {
35386758c71SEd Maste m_opaque_sp = platform_sp;
35486758c71SEd Maste }
35586758c71SEd Maste
GetWorkingDirectory()35614f1b3e8SDimitry Andric const char *SBPlatform::GetWorkingDirectory() {
3576f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
3585f29bb8aSDimitry Andric
35986758c71SEd Maste PlatformSP platform_sp(GetSP());
36086758c71SEd Maste if (platform_sp)
361e3b55780SDimitry Andric return platform_sp->GetWorkingDirectory().GetPathAsConstString().AsCString();
3625f29bb8aSDimitry Andric return nullptr;
36386758c71SEd Maste }
36486758c71SEd Maste
SetWorkingDirectory(const char * path)36514f1b3e8SDimitry Andric bool SBPlatform::SetWorkingDirectory(const char *path) {
3666f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, path);
3675f29bb8aSDimitry Andric
36886758c71SEd Maste PlatformSP platform_sp(GetSP());
36914f1b3e8SDimitry Andric if (platform_sp) {
37086758c71SEd Maste if (path)
37194994d37SDimitry Andric platform_sp->SetWorkingDirectory(FileSpec(path));
37286758c71SEd Maste else
37394994d37SDimitry Andric platform_sp->SetWorkingDirectory(FileSpec());
37486758c71SEd Maste return true;
37586758c71SEd Maste }
37686758c71SEd Maste return false;
37786758c71SEd Maste }
37886758c71SEd Maste
ConnectRemote(SBPlatformConnectOptions & connect_options)37914f1b3e8SDimitry Andric SBError SBPlatform::ConnectRemote(SBPlatformConnectOptions &connect_options) {
3806f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, connect_options);
3815f29bb8aSDimitry Andric
38286758c71SEd Maste SBError sb_error;
38386758c71SEd Maste PlatformSP platform_sp(GetSP());
38414f1b3e8SDimitry Andric if (platform_sp && connect_options.GetURL()) {
38586758c71SEd Maste Args args;
386344a3780SDimitry Andric args.AppendArgument(connect_options.GetURL());
38786758c71SEd Maste sb_error.ref() = platform_sp->ConnectRemote(args);
38814f1b3e8SDimitry Andric } else {
38986758c71SEd Maste sb_error.SetErrorString("invalid platform");
39086758c71SEd Maste }
3916f8fc217SDimitry Andric return sb_error;
39286758c71SEd Maste }
39386758c71SEd Maste
DisconnectRemote()39414f1b3e8SDimitry Andric void SBPlatform::DisconnectRemote() {
3956f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
3965f29bb8aSDimitry Andric
39786758c71SEd Maste PlatformSP platform_sp(GetSP());
39886758c71SEd Maste if (platform_sp)
39986758c71SEd Maste platform_sp->DisconnectRemote();
40086758c71SEd Maste }
40186758c71SEd Maste
IsConnected()40214f1b3e8SDimitry Andric bool SBPlatform::IsConnected() {
4036f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
4045f29bb8aSDimitry Andric
40586758c71SEd Maste PlatformSP platform_sp(GetSP());
40686758c71SEd Maste if (platform_sp)
407f73363f1SDimitry Andric return platform_sp->IsConnected();
40886758c71SEd Maste return false;
40986758c71SEd Maste }
41086758c71SEd Maste
GetTriple()41114f1b3e8SDimitry Andric const char *SBPlatform::GetTriple() {
4126f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
4135f29bb8aSDimitry Andric
41486758c71SEd Maste PlatformSP platform_sp(GetSP());
41514f1b3e8SDimitry Andric if (platform_sp) {
4165e95aa85SEd Maste ArchSpec arch(platform_sp->GetSystemArchitecture());
41714f1b3e8SDimitry Andric if (arch.IsValid()) {
41814f1b3e8SDimitry Andric // Const-ify the string so we don't need to worry about the lifetime of
41914f1b3e8SDimitry Andric // the string
42086758c71SEd Maste return ConstString(arch.GetTriple().getTriple().c_str()).GetCString();
42186758c71SEd Maste }
42286758c71SEd Maste }
4235f29bb8aSDimitry Andric return nullptr;
42486758c71SEd Maste }
42586758c71SEd Maste
GetOSBuild()42614f1b3e8SDimitry Andric const char *SBPlatform::GetOSBuild() {
4276f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
4285f29bb8aSDimitry Andric
42986758c71SEd Maste PlatformSP platform_sp(GetSP());
43014f1b3e8SDimitry Andric if (platform_sp) {
431145449b1SDimitry Andric std::string s = platform_sp->GetOSBuildString().value_or("");
43214f1b3e8SDimitry Andric if (!s.empty()) {
43314f1b3e8SDimitry Andric // Const-ify the string so we don't need to worry about the lifetime of
43414f1b3e8SDimitry Andric // the string
435c0981da4SDimitry Andric return ConstString(s).GetCString();
43686758c71SEd Maste }
43786758c71SEd Maste }
4385f29bb8aSDimitry Andric return nullptr;
43986758c71SEd Maste }
44086758c71SEd Maste
GetOSDescription()44114f1b3e8SDimitry Andric const char *SBPlatform::GetOSDescription() {
4426f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
4435f29bb8aSDimitry Andric
44486758c71SEd Maste PlatformSP platform_sp(GetSP());
44514f1b3e8SDimitry Andric if (platform_sp) {
446145449b1SDimitry Andric std::string s = platform_sp->GetOSKernelDescription().value_or("");
44714f1b3e8SDimitry Andric if (!s.empty()) {
44814f1b3e8SDimitry Andric // Const-ify the string so we don't need to worry about the lifetime of
44914f1b3e8SDimitry Andric // the string
45086758c71SEd Maste return ConstString(s.c_str()).GetCString();
45186758c71SEd Maste }
45286758c71SEd Maste }
4535f29bb8aSDimitry Andric return nullptr;
45486758c71SEd Maste }
45586758c71SEd Maste
GetHostname()45614f1b3e8SDimitry Andric const char *SBPlatform::GetHostname() {
4576f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
4585f29bb8aSDimitry Andric
45986758c71SEd Maste PlatformSP platform_sp(GetSP());
46086758c71SEd Maste if (platform_sp)
4617fa27ce4SDimitry Andric return ConstString(platform_sp->GetHostname()).GetCString();
4625f29bb8aSDimitry Andric return nullptr;
46386758c71SEd Maste }
46486758c71SEd Maste
GetOSMajorVersion()46514f1b3e8SDimitry Andric uint32_t SBPlatform::GetOSMajorVersion() {
4666f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
4675f29bb8aSDimitry Andric
468f73363f1SDimitry Andric llvm::VersionTuple version;
469f73363f1SDimitry Andric if (PlatformSP platform_sp = GetSP())
470f73363f1SDimitry Andric version = platform_sp->GetOSVersion();
471f73363f1SDimitry Andric return version.empty() ? UINT32_MAX : version.getMajor();
47286758c71SEd Maste }
47386758c71SEd Maste
GetOSMinorVersion()47414f1b3e8SDimitry Andric uint32_t SBPlatform::GetOSMinorVersion() {
4756f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
4765f29bb8aSDimitry Andric
477f73363f1SDimitry Andric llvm::VersionTuple version;
478f73363f1SDimitry Andric if (PlatformSP platform_sp = GetSP())
479f73363f1SDimitry Andric version = platform_sp->GetOSVersion();
480145449b1SDimitry Andric return version.getMinor().value_or(UINT32_MAX);
48186758c71SEd Maste }
48286758c71SEd Maste
GetOSUpdateVersion()48314f1b3e8SDimitry Andric uint32_t SBPlatform::GetOSUpdateVersion() {
4846f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
4855f29bb8aSDimitry Andric
486f73363f1SDimitry Andric llvm::VersionTuple version;
487f73363f1SDimitry Andric if (PlatformSP platform_sp = GetSP())
488f73363f1SDimitry Andric version = platform_sp->GetOSVersion();
489145449b1SDimitry Andric return version.getSubminor().value_or(UINT32_MAX);
49086758c71SEd Maste }
49186758c71SEd Maste
SetSDKRoot(const char * sysroot)4926f8fc217SDimitry Andric void SBPlatform::SetSDKRoot(const char *sysroot) {
4936f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, sysroot);
4946f8fc217SDimitry Andric if (PlatformSP platform_sp = GetSP())
4957fa27ce4SDimitry Andric platform_sp->SetSDKRootDirectory(llvm::StringRef(sysroot).str());
4966f8fc217SDimitry Andric }
4976f8fc217SDimitry Andric
Get(SBFileSpec & src,SBFileSpec & dst)49814f1b3e8SDimitry Andric SBError SBPlatform::Get(SBFileSpec &src, SBFileSpec &dst) {
4996f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, src, dst);
5005f29bb8aSDimitry Andric
50186758c71SEd Maste SBError sb_error;
50286758c71SEd Maste PlatformSP platform_sp(GetSP());
50314f1b3e8SDimitry Andric if (platform_sp) {
50486758c71SEd Maste sb_error.ref() = platform_sp->GetFile(src.ref(), dst.ref());
50514f1b3e8SDimitry Andric } else {
50686758c71SEd Maste sb_error.SetErrorString("invalid platform");
50786758c71SEd Maste }
5086f8fc217SDimitry Andric return sb_error;
50986758c71SEd Maste }
51086758c71SEd Maste
Put(SBFileSpec & src,SBFileSpec & dst)51114f1b3e8SDimitry Andric SBError SBPlatform::Put(SBFileSpec &src, SBFileSpec &dst) {
5126f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, src, dst);
5136f8fc217SDimitry Andric return ExecuteConnected([&](const lldb::PlatformSP &platform_sp) {
51414f1b3e8SDimitry Andric if (src.Exists()) {
5156f8fc217SDimitry Andric uint32_t permissions = FileSystem::Instance().GetPermissions(src.ref());
51614f1b3e8SDimitry Andric if (permissions == 0) {
51794994d37SDimitry Andric if (FileSystem::Instance().IsDirectory(src.ref()))
51886758c71SEd Maste permissions = eFilePermissionsDirectoryDefault;
51986758c71SEd Maste else
52086758c71SEd Maste permissions = eFilePermissionsFileDefault;
52186758c71SEd Maste }
52286758c71SEd Maste
52312bd4897SEd Maste return platform_sp->PutFile(src.ref(), dst.ref(), permissions);
52486758c71SEd Maste }
52512bd4897SEd Maste
526b76161e4SDimitry Andric Status error;
52714f1b3e8SDimitry Andric error.SetErrorStringWithFormat("'src' argument doesn't exist: '%s'",
52814f1b3e8SDimitry Andric src.ref().GetPath().c_str());
52912bd4897SEd Maste return error;
5306f8fc217SDimitry Andric });
53186758c71SEd Maste }
53286758c71SEd Maste
Install(SBFileSpec & src,SBFileSpec & dst)53314f1b3e8SDimitry Andric SBError SBPlatform::Install(SBFileSpec &src, SBFileSpec &dst) {
5346f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, src, dst);
5356f8fc217SDimitry Andric return ExecuteConnected([&](const lldb::PlatformSP &platform_sp) {
53686758c71SEd Maste if (src.Exists())
53712bd4897SEd Maste return platform_sp->Install(src.ref(), dst.ref());
53812bd4897SEd Maste
539b76161e4SDimitry Andric Status error;
54014f1b3e8SDimitry Andric error.SetErrorStringWithFormat("'src' argument doesn't exist: '%s'",
54114f1b3e8SDimitry Andric src.ref().GetPath().c_str());
54212bd4897SEd Maste return error;
5436f8fc217SDimitry Andric });
54486758c71SEd Maste }
54586758c71SEd Maste
Run(SBPlatformShellCommand & shell_command)54614f1b3e8SDimitry Andric SBError SBPlatform::Run(SBPlatformShellCommand &shell_command) {
5476f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, shell_command);
5486f8fc217SDimitry Andric return ExecuteConnected(
5496f8fc217SDimitry Andric [&](const lldb::PlatformSP &platform_sp) {
55086758c71SEd Maste const char *command = shell_command.GetCommand();
55112bd4897SEd Maste if (!command)
552b76161e4SDimitry Andric return Status("invalid shell command (empty)");
55312bd4897SEd Maste
554e3b55780SDimitry Andric if (shell_command.GetWorkingDirectory() == nullptr) {
555e3b55780SDimitry Andric std::string platform_working_dir =
556e3b55780SDimitry Andric platform_sp->GetWorkingDirectory().GetPath();
557e3b55780SDimitry Andric if (!platform_working_dir.empty())
558e3b55780SDimitry Andric shell_command.SetWorkingDirectory(platform_working_dir.c_str());
55986758c71SEd Maste }
560b60736ecSDimitry Andric return platform_sp->RunShellCommand(
561e3b55780SDimitry Andric shell_command.m_opaque_ptr->m_shell, command,
562e3b55780SDimitry Andric FileSpec(shell_command.GetWorkingDirectory()),
56386758c71SEd Maste &shell_command.m_opaque_ptr->m_status,
56486758c71SEd Maste &shell_command.m_opaque_ptr->m_signo,
56586758c71SEd Maste &shell_command.m_opaque_ptr->m_output,
566f73363f1SDimitry Andric shell_command.m_opaque_ptr->m_timeout);
5676f8fc217SDimitry Andric });
56886758c71SEd Maste }
56912bd4897SEd Maste
Launch(SBLaunchInfo & launch_info)57014f1b3e8SDimitry Andric SBError SBPlatform::Launch(SBLaunchInfo &launch_info) {
5716f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, launch_info);
5726f8fc217SDimitry Andric return ExecuteConnected([&](const lldb::PlatformSP &platform_sp) {
573f73363f1SDimitry Andric ProcessLaunchInfo info = launch_info.ref();
574f73363f1SDimitry Andric Status error = platform_sp->LaunchProcess(info);
575f73363f1SDimitry Andric launch_info.set_ref(info);
576f73363f1SDimitry Andric return error;
5776f8fc217SDimitry Andric });
57812bd4897SEd Maste }
57912bd4897SEd Maste
Attach(SBAttachInfo & attach_info,const SBDebugger & debugger,SBTarget & target,SBError & error)580b1c73532SDimitry Andric SBProcess SBPlatform::Attach(SBAttachInfo &attach_info,
581b1c73532SDimitry Andric const SBDebugger &debugger, SBTarget &target,
582b1c73532SDimitry Andric SBError &error) {
583b1c73532SDimitry Andric LLDB_INSTRUMENT_VA(this, attach_info, debugger, target, error);
584b1c73532SDimitry Andric
585b1c73532SDimitry Andric if (PlatformSP platform_sp = GetSP()) {
586b1c73532SDimitry Andric if (platform_sp->IsConnected()) {
587b1c73532SDimitry Andric ProcessAttachInfo &info = attach_info.ref();
588b1c73532SDimitry Andric Status status;
589b1c73532SDimitry Andric ProcessSP process_sp = platform_sp->Attach(info, debugger.ref(),
590b1c73532SDimitry Andric target.GetSP().get(), status);
591b1c73532SDimitry Andric error.SetError(status);
592b1c73532SDimitry Andric return SBProcess(process_sp);
593b1c73532SDimitry Andric }
594b1c73532SDimitry Andric
595b1c73532SDimitry Andric error.SetErrorString("not connected");
596b1c73532SDimitry Andric return {};
597b1c73532SDimitry Andric }
598b1c73532SDimitry Andric
599b1c73532SDimitry Andric error.SetErrorString("invalid platform");
600b1c73532SDimitry Andric return {};
601b1c73532SDimitry Andric }
602b1c73532SDimitry Andric
GetAllProcesses(SBError & error)603b1c73532SDimitry Andric SBProcessInfoList SBPlatform::GetAllProcesses(SBError &error) {
604b1c73532SDimitry Andric if (PlatformSP platform_sp = GetSP()) {
605b1c73532SDimitry Andric if (platform_sp->IsConnected()) {
606b1c73532SDimitry Andric ProcessInstanceInfoList list = platform_sp->GetAllProcesses();
607b1c73532SDimitry Andric return SBProcessInfoList(list);
608b1c73532SDimitry Andric }
609b1c73532SDimitry Andric error.SetErrorString("not connected");
610b1c73532SDimitry Andric return {};
611b1c73532SDimitry Andric }
612b1c73532SDimitry Andric
613b1c73532SDimitry Andric error.SetErrorString("invalid platform");
614b1c73532SDimitry Andric return {};
615b1c73532SDimitry Andric }
616b1c73532SDimitry Andric
Kill(const lldb::pid_t pid)61714f1b3e8SDimitry Andric SBError SBPlatform::Kill(const lldb::pid_t pid) {
6186f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, pid);
6196f8fc217SDimitry Andric return ExecuteConnected([&](const lldb::PlatformSP &platform_sp) {
62012bd4897SEd Maste return platform_sp->KillProcess(pid);
6216f8fc217SDimitry Andric });
62212bd4897SEd Maste }
62312bd4897SEd Maste
ExecuteConnected(const std::function<Status (const lldb::PlatformSP &)> & func)62414f1b3e8SDimitry Andric SBError SBPlatform::ExecuteConnected(
625b76161e4SDimitry Andric const std::function<Status(const lldb::PlatformSP &)> &func) {
62612bd4897SEd Maste SBError sb_error;
62712bd4897SEd Maste const auto platform_sp(GetSP());
62814f1b3e8SDimitry Andric if (platform_sp) {
62912bd4897SEd Maste if (platform_sp->IsConnected())
63012bd4897SEd Maste sb_error.ref() = func(platform_sp);
63112bd4897SEd Maste else
63286758c71SEd Maste sb_error.SetErrorString("not connected");
63314f1b3e8SDimitry Andric } else
63486758c71SEd Maste sb_error.SetErrorString("invalid platform");
63512bd4897SEd Maste
63686758c71SEd Maste return sb_error;
63786758c71SEd Maste }
63886758c71SEd Maste
MakeDirectory(const char * path,uint32_t file_permissions)63914f1b3e8SDimitry Andric SBError SBPlatform::MakeDirectory(const char *path, uint32_t file_permissions) {
6406f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, path, file_permissions);
6415f29bb8aSDimitry Andric
64286758c71SEd Maste SBError sb_error;
64386758c71SEd Maste PlatformSP platform_sp(GetSP());
64414f1b3e8SDimitry Andric if (platform_sp) {
64514f1b3e8SDimitry Andric sb_error.ref() =
64694994d37SDimitry Andric platform_sp->MakeDirectory(FileSpec(path), file_permissions);
64714f1b3e8SDimitry Andric } else {
64886758c71SEd Maste sb_error.SetErrorString("invalid platform");
64986758c71SEd Maste }
6506f8fc217SDimitry Andric return sb_error;
65186758c71SEd Maste }
65286758c71SEd Maste
GetFilePermissions(const char * path)65314f1b3e8SDimitry Andric uint32_t SBPlatform::GetFilePermissions(const char *path) {
6546f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, path);
6555f29bb8aSDimitry Andric
65686758c71SEd Maste PlatformSP platform_sp(GetSP());
65714f1b3e8SDimitry Andric if (platform_sp) {
65886758c71SEd Maste uint32_t file_permissions = 0;
65994994d37SDimitry Andric platform_sp->GetFilePermissions(FileSpec(path), file_permissions);
66086758c71SEd Maste return file_permissions;
66186758c71SEd Maste }
66286758c71SEd Maste return 0;
66386758c71SEd Maste }
66486758c71SEd Maste
SetFilePermissions(const char * path,uint32_t file_permissions)66514f1b3e8SDimitry Andric SBError SBPlatform::SetFilePermissions(const char *path,
66614f1b3e8SDimitry Andric uint32_t file_permissions) {
6676f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, path, file_permissions);
6685f29bb8aSDimitry Andric
66986758c71SEd Maste SBError sb_error;
67086758c71SEd Maste PlatformSP platform_sp(GetSP());
67114f1b3e8SDimitry Andric if (platform_sp) {
67294994d37SDimitry Andric sb_error.ref() =
67394994d37SDimitry Andric platform_sp->SetFilePermissions(FileSpec(path), file_permissions);
67414f1b3e8SDimitry Andric } else {
67586758c71SEd Maste sb_error.SetErrorString("invalid platform");
67686758c71SEd Maste }
6776f8fc217SDimitry Andric return sb_error;
67886758c71SEd Maste }
67986758c71SEd Maste
GetUnixSignals() const68014f1b3e8SDimitry Andric SBUnixSignals SBPlatform::GetUnixSignals() const {
6816f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
682027f1c96SDimitry Andric
6835f29bb8aSDimitry Andric if (auto platform_sp = GetSP())
6846f8fc217SDimitry Andric return SBUnixSignals{platform_sp};
6855f29bb8aSDimitry Andric
6866f8fc217SDimitry Andric return SBUnixSignals();
6875f29bb8aSDimitry Andric }
6885f29bb8aSDimitry Andric
GetEnvironment()689cfca06d7SDimitry Andric SBEnvironment SBPlatform::GetEnvironment() {
6906f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
691cfca06d7SDimitry Andric PlatformSP platform_sp(GetSP());
692cfca06d7SDimitry Andric
693cfca06d7SDimitry Andric if (platform_sp) {
6946f8fc217SDimitry Andric return SBEnvironment(platform_sp->GetEnvironment());
695cfca06d7SDimitry Andric }
696cfca06d7SDimitry Andric
6976f8fc217SDimitry Andric return SBEnvironment();
698cfca06d7SDimitry Andric }
6997fa27ce4SDimitry Andric
SetLocateModuleCallback(lldb::SBPlatformLocateModuleCallback callback,void * callback_baton)7007fa27ce4SDimitry Andric SBError SBPlatform::SetLocateModuleCallback(
7017fa27ce4SDimitry Andric lldb::SBPlatformLocateModuleCallback callback, void *callback_baton) {
7027fa27ce4SDimitry Andric LLDB_INSTRUMENT_VA(this, callback, callback_baton);
7037fa27ce4SDimitry Andric PlatformSP platform_sp(GetSP());
7047fa27ce4SDimitry Andric if (!platform_sp)
7057fa27ce4SDimitry Andric return SBError("invalid platform");
7067fa27ce4SDimitry Andric
7077fa27ce4SDimitry Andric if (!callback) {
7087fa27ce4SDimitry Andric // Clear the callback.
7097fa27ce4SDimitry Andric platform_sp->SetLocateModuleCallback(nullptr);
7107fa27ce4SDimitry Andric return SBError();
7117fa27ce4SDimitry Andric }
7127fa27ce4SDimitry Andric
7137fa27ce4SDimitry Andric // Platform.h does not accept lldb::SBPlatformLocateModuleCallback directly
7147fa27ce4SDimitry Andric // because of the SBModuleSpec and SBFileSpec dependencies. Use a lambda to
7157fa27ce4SDimitry Andric // convert ModuleSpec/FileSpec <--> SBModuleSpec/SBFileSpec for the callback
7167fa27ce4SDimitry Andric // arguments.
7177fa27ce4SDimitry Andric platform_sp->SetLocateModuleCallback(
7187fa27ce4SDimitry Andric [callback, callback_baton](const ModuleSpec &module_spec,
7197fa27ce4SDimitry Andric FileSpec &module_file_spec,
7207fa27ce4SDimitry Andric FileSpec &symbol_file_spec) {
7217fa27ce4SDimitry Andric SBModuleSpec module_spec_sb(module_spec);
7227fa27ce4SDimitry Andric SBFileSpec module_file_spec_sb;
7237fa27ce4SDimitry Andric SBFileSpec symbol_file_spec_sb;
7247fa27ce4SDimitry Andric
7257fa27ce4SDimitry Andric SBError error = callback(callback_baton, module_spec_sb,
7267fa27ce4SDimitry Andric module_file_spec_sb, symbol_file_spec_sb);
7277fa27ce4SDimitry Andric
7287fa27ce4SDimitry Andric if (error.Success()) {
7297fa27ce4SDimitry Andric module_file_spec = module_file_spec_sb.ref();
7307fa27ce4SDimitry Andric symbol_file_spec = symbol_file_spec_sb.ref();
7317fa27ce4SDimitry Andric }
7327fa27ce4SDimitry Andric
7337fa27ce4SDimitry Andric return error.ref();
7347fa27ce4SDimitry Andric });
7357fa27ce4SDimitry Andric return SBError();
7367fa27ce4SDimitry Andric }
737