24#include "llvm/ADT/StringExtras.h"
25#include "llvm/Support/ErrorExtras.h"
33#define LLDB_PROPERTIES_platformwasm
34#include "PlatformWasmProperties.inc"
37#define LLDB_PROPERTIES_platformwasm
38#include "PlatformWasmPropertiesEnum.inc"
44 m_collection_sp = std::make_shared<OptionValueProperties>(
46 m_collection_sp->Initialize(g_platformwasm_properties_def);
49 FileSpec GetRuntimePath()
const {
50 return GetPropertyAtIndexAs<FileSpec>(ePropertyRuntimePath, {});
53 Args GetRuntimeArgs()
const {
55 m_collection_sp->GetPropertyAtIndexAsArgs(ePropertyRuntimeArgs, result);
59 llvm::StringRef GetPortArg()
const {
60 return GetPropertyAtIndexAs<llvm::StringRef>(ePropertyPortArg, {});
63 llvm::StringRef GetEnvArg()
const {
64 return GetPropertyAtIndexAs<llvm::StringRef>(ePropertyEnvArg, {});
71 static PluginProperties g_settings;
76 return "Platform for debugging Wasm";
96 "Properties for the wasm platform plugin.",
103 LLDB_LOG(log,
"force = {0}, arch = ({1}, {2})", force,
105 arch ? arch->
GetTriple().getTriple() :
"<null>");
108 if (!create && arch && arch->
IsValid()) {
109 const llvm::Triple &triple = arch->
GetTriple();
110 switch (triple.getArch()) {
111 case llvm::Triple::wasm32:
112 case llvm::Triple::wasm64:
120 LLDB_LOG(log,
"create = {0}", create);
144 "attaching is only supported when connected to a remote Wasm platform");
159 FileSpec runtime = properties.GetRuntimePath();
164 "WebAssembly runtime does not exist: {0}", runtime.
GetPath());
169 if (!expected_port) {
173 uint16_t port = *expected_port;
176 llvm::formatv(
"{0}{1}", properties.GetPortArg(), port).str()});
181 if (llvm::StringRef env_arg = properties.GetEnvArg(); !env_arg.empty())
192 launch_info.
GetFlags().
Clear(eLaunchFlagDebug | eLaunchFlagDisableASLR);
196 auto exit_code = std::make_shared<std::optional<int>>();
201 "WebAssembly runtime exited: pid = {0}, signal = {1}, status = {2}",
202 pid, signal, status);
203 exit_code->emplace(status);
209 LLDB_LOG_ERROR(log, std::move(Err),
"SetUpPtyRedirection failed: {0}");
226 error = process_sp->ConnectRemote(
227 llvm::formatv(
"connect://localhost:{0}", port).str());
233 llvm::createStringErrorV(
234 "WebAssembly runtime exited with exit code {0}", **exit_code),
242 process_sp->SetSTDIOFileDescriptor(
251 "can't connect to the host platform, always connected");
static llvm::raw_ostream & error(Stream &strm)
static DynamicLoaderDarwinKernelProperties & GetGlobalProperties()
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
#define LLDB_LOG_ERROR(log, error,...)
#define LLDB_PLUGIN_DEFINE(PluginName)
An architecture specification class.
bool IsValid() const
Tests if this ArchSpec is valid.
llvm::Triple & GetTriple()
Architecture triple accessor.
const char * GetArchitectureName() const
Returns a static string representing the current architecture.
A command line argument class.
void AppendArguments(const Args &rhs)
A class to manage flag bits.
static std::string compose(const value_type &KeyValue)
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
bool ResolveExecutableLocation(FileSpec &file_spec)
Call into the Host to see if it can help find the file.
static FileSystem & Instance()
ValueType Clear(ValueType mask=~static_cast< ValueType >(0))
Clear one or more flags.
static Status LaunchProcess(ProcessLaunchInfo &launch_info)
Launch the process specified in launch_info.
static Environment GetEnvironment()
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static lldb::OptionValuePropertiesSP GetSettingForPlatformPlugin(Debugger &debugger, llvm::StringRef setting_name)
static bool CreateSettingForPlatformPlugin(Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp, llvm::StringRef description, bool is_global_property)
static bool UnregisterPlugin(ABICreateInstance create_callback)
lldb::ListenerSP GetHijackListener() const
void SetArguments(const Args &args, bool first_arg_is_executable)
lldb::ListenerSP GetListener() const
Environment & GetEnvironment()
llvm::Error SetUpPtyRedirection()
void SetMonitorProcessCallback(Host::MonitorChildProcessCallback callback)
void SetLaunchInSeparateProcessGroup(bool separate)
@ invalid_fd
Invalid file descriptor value.
int GetPrimaryFileDescriptor() const
The primary file descriptor accessor.
int ReleasePrimaryFileDescriptor()
Release the primary file descriptor.
static Status FromErrorString(const char *str)
bool Fail() const
Test for error condition.
static Status static Status FromErrorStringWithFormatv(const char *format, Args &&...args)
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
Status Listen(llvm::StringRef name, int backlog) override
uint16_t GetLocalPortNumber() const
const lldb::ProcessSP & CreateProcess(lldb::ListenerSP listener_sp, llvm::StringRef plugin_name, const FileSpec *crash_file, bool can_connect)
static llvm::StringRef GetPluginNameStatic()
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
std::shared_ptr< lldb_private::Platform > PlatformSP
std::shared_ptr< lldb_private::Process > ProcessSP