26 #define LLDB_PROPERTIES_platformqemuuser
27 #include "PlatformQemuUserProperties.inc"
30 #define LLDB_PROPERTIES_platformqemuuser
31 #include "PlatformQemuUserPropertiesEnum.inc"
37 m_collection_sp = std::make_shared<OptionValueProperties>(
38 ConstString(PlatformQemuUser::GetPluginNameStatic()));
39 m_collection_sp->Initialize(g_platformqemuuser_properties);
43 return m_collection_sp->GetPropertyAtIndexAsString(
44 nullptr, ePropertyArchitecture,
"");
48 return m_collection_sp->GetPropertyAtIndexAsFileSpec(
nullptr,
49 ePropertyEmulatorPath);
54 m_collection_sp->GetPropertyAtIndexAsArgs(
nullptr, ePropertyEmulatorArgs,
61 m_collection_sp->GetPropertyAtIndexAsArgs(
nullptr, ePropertyEmulatorEnvVars,
68 m_collection_sp->GetPropertyAtIndexAsArgs(
nullptr, ePropertyTargetEnvVars,
75 static PluginProperties g_settings;
79 llvm::StringRef PlatformQemuUser::GetPluginDescriptionStatic() {
80 return "Platform for debugging binaries under user mode qemu";
83 void PlatformQemuUser::Initialize() {
84 PluginManager::RegisterPlugin(
85 GetPluginNameStatic(), GetPluginDescriptionStatic(),
86 PlatformQemuUser::CreateInstance, PlatformQemuUser::DebuggerInitialize);
89 void PlatformQemuUser::Terminate() {
90 PluginManager::UnregisterPlugin(PlatformQemuUser::CreateInstance);
93 void PlatformQemuUser::DebuggerInitialize(
Debugger &debugger) {
94 if (!PluginManager::GetSettingForPlatformPlugin(
96 PluginManager::CreateSettingForPlatformPlugin(
98 ConstString(
"Properties for the qemu-user platform plugin."),
103 PlatformSP PlatformQemuUser::CreateInstance(
bool force,
const ArchSpec *arch) {
109 std::vector<ArchSpec>
110 PlatformQemuUser::GetSupportedArchitectures(
const ArchSpec &process_host_arch) {
111 llvm::Triple triple = HostInfo::GetArchitecture().GetTriple();
112 triple.setEnvironment(llvm::Triple::UnknownEnvironment);
114 if (triple.getArch() != llvm::Triple::UnknownArch)
130 std::vector<std::string> set_env;
131 for (
const auto &KV : target) {
134 auto host_it = host.find(KV.first());
135 if (host_it == host.end() || host_it->second != KV.second)
136 set_env.push_back(Environment::compose(KV));
140 std::vector<llvm::StringRef> unset_env;
141 for (
const auto &KV : host) {
144 if (target.count(KV.first()) == 0)
145 unset_env.push_back(KV.first());
147 llvm::sort(unset_env);
151 if (!set_env.empty()) {
152 host[
"QEMU_SET_ENV"] = llvm::join(set_env,
",");
153 unset_env.push_back(
"QEMU_SET_ENV");
155 if (!unset_env.empty()) {
156 unset_env.push_back(
"QEMU_UNSET_ENV");
157 host[
"QEMU_UNSET_ENV"] = llvm::join(unset_env,
",");
170 FileSystem::Instance().ResolveExecutableLocation(qemu);
172 llvm::SmallString<0> socket_model, socket_path;
173 HostInfo::GetProcessTempDir().GetPath(socket_model);
174 llvm::sys::path::append(socket_model,
"qemu-%%%%%%%%.socket");
176 llvm::sys::fs::createUniquePath(socket_model, socket_path,
false);
177 }
while (FileSystem::Instance().Exists(socket_path));
180 if (!launch_info.
GetArg0().empty()) {
182 args.AppendArgument(launch_info.
GetArg0());
185 args.AppendArgument(
"--");
187 for (
size_t i = 1; i < launch_info.
GetArguments().size(); ++i)
188 args.AppendArgument(launch_info.
GetArguments()[i].ref());
197 emulator_env[
"QEMU_LD_PREFIX"] = sysroot.GetStringRef().str();
199 emulator_env[KV.first()] = KV.second;
201 std::move(launch_info.
GetEnvironment()), std::move(emulator_env));
210 LLDB_LOG_ERROR(log, std::move(Err),
"SetUpPtyRedirection failed: {0}");
212 error = Host::LaunchProcess(launch_info);
218 process_gdb_remote::ProcessGDBRemote::GetPluginNameStatic(),
nullptr,
221 error.SetErrorString(
"Failed to create GDB process");
227 error = process_sp->ConnectRemote((
"unix-connect://" + socket_path).str());
232 PseudoTerminal::invalid_fd)
233 process_sp->SetSTDIOFileDescriptor(
242 env[KV.first()] = KV.second;