25#include "llvm/ADT/StringExtras.h"
26#include "llvm/Support/ErrorExtras.h"
34#define LLDB_PROPERTIES_platformwasm
35#include "PlatformWasmProperties.inc"
38#define LLDB_PROPERTIES_platformwasm
39#include "PlatformWasmPropertiesEnum.inc"
45 m_collection_sp = std::make_shared<OptionValueProperties>(
47 m_collection_sp->Initialize(g_platformwasm_properties_def);
50 FileSpec GetRuntimePath()
const {
51 return GetPropertyAtIndexAs<FileSpec>(ePropertyRuntimePath, {});
54 Args GetRuntimeArgs()
const {
56 m_collection_sp->GetPropertyAtIndexAsArgs(ePropertyRuntimeArgs, result);
60 llvm::StringRef GetPortArg()
const {
61 return GetPropertyAtIndexAs<llvm::StringRef>(ePropertyPortArg, {});
64 llvm::StringRef GetEnvArg()
const {
65 return GetPropertyAtIndexAs<llvm::StringRef>(ePropertyEnvArg, {});
72 static PluginProperties g_settings;
77 return "Platform for debugging Wasm";
97 "Properties for the wasm platform plugin.",
104 LLDB_LOG(log,
"force = {0}, arch = ({1}, {2})", force,
106 arch ? arch->
GetTriple().getTriple() :
"<null>");
109 if (!create && arch && arch->
IsValid()) {
110 const llvm::Triple &triple = arch->
GetTriple();
111 switch (triple.getArch()) {
112 case llvm::Triple::wasm32:
113 case llvm::Triple::wasm64:
121 LLDB_LOG(log,
"create = {0}", create);
145 "attaching is only supported when connected to a remote Wasm platform");
160 FileSpec runtime = properties.GetRuntimePath();
165 "WebAssembly runtime does not exist: {0}", runtime.
GetPath());
170 if (!expected_port) {
174 uint16_t port = *expected_port;
177 llvm::formatv(
"{0}{1}", properties.GetPortArg(), port).str()});
182 if (llvm::StringRef env_arg = properties.GetEnvArg(); !env_arg.empty())
193 const std::string exe_path = exe_module_sp->GetFileSpec().GetPath();
205 launch_info.
GetFlags().
Clear(eLaunchFlagDebug | eLaunchFlagDisableASLR);
209 auto exit_code = std::make_shared<std::optional<int>>();
214 "WebAssembly runtime exited: pid = {0}, signal = {1}, status = {2}",
215 pid, signal, status);
216 exit_code->emplace(status);
222 LLDB_LOG_ERROR(log, std::move(Err),
"SetUpPtyRedirection failed: {0}");
239 error = process_sp->ConnectRemote(
240 llvm::formatv(
"connect://localhost:{0}", port).str());
246 llvm::createStringErrorV(
247 "WebAssembly runtime exited with exit code {0}", **exit_code),
255 process_sp->SetSTDIOFileDescriptor(
264 "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)
size_t GetArgumentCount() const
Gets the number of arguments left in this command object.
void ReplaceArgumentAtIndex(size_t idx, llvm::StringRef arg_str, char quote_char='\0')
Replaces the argument value at index idx to arg_str if idx is a valid argument index.
void AppendArgument(llvm::StringRef arg_str, char quote_char='\0')
Appends a new argument to the end of the list argument list.
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
lldb::ModuleSP GetExecutableModule()
Gets the module for the main executable.
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
std::shared_ptr< lldb_private::Module > ModuleSP