25 #include "llvm/Support/ConvertUTF.h"
34 llvm::Triple &triple) {
37 auto imageBinaryP = FileSystem::Instance().Open(
38 executable, File::eOpenOptionReadOnly, lldb::eFilePermissionsUserRead);
40 return llvm::errorToBool(imageBinaryP.takeError());
41 File &imageBinary = *imageBinaryP.get();
46 size_t readSize =
sizeof(peOffset);
47 imageBinary.
Read(&peOffset, readSize);
49 imageBinary.
Read(&peHead, readSize);
50 if (peHead != 0x00004550)
53 imageBinary.
Read(&machineType, readSize);
54 triple.setVendor(llvm::Triple::PC);
55 triple.setOS(llvm::Triple::Win32);
56 triple.setArch(llvm::Triple::UnknownArch);
57 if (machineType == 0x8664)
58 triple.setArch(llvm::Triple::x86_64);
59 else if (machineType == 0x14c)
60 triple.setArch(llvm::Triple::x86);
61 else if (machineType == 0x1c4)
62 triple.setArch(llvm::Triple::arm);
63 else if (machineType == 0xaa64)
64 triple.setArch(llvm::Triple::aarch64);
73 std::vector<wchar_t> buffer(
PATH_MAX);
74 DWORD dwSize = buffer.size();
75 if (!::QueryFullProcessImageNameW(handle.
get(), 0, &buffer[0], &dwSize))
77 return llvm::convertWideToUTF8(buffer.data(), path);
88 triple.setVendor(llvm::Triple::PC);
89 triple.setOS(llvm::Triple::Win32);
90 triple.setArch(llvm::Triple::UnknownArch);
92 FileSpec executableFile(executable.c_str());
106 TerminateProcess((HANDLE)pid, 1);
109 const char *Host::GetSignalAsCString(
int signo) {
return NULL; }
111 FileSpec Host::GetModuleFileSpecForHostAddress(
const void *host_addr) {
114 HMODULE hmodule = NULL;
115 if (!::GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
116 (LPCTSTR)host_addr, &hmodule))
117 return module_filespec;
119 std::vector<wchar_t> buffer(
PATH_MAX);
120 DWORD chars_copied = 0;
122 chars_copied = ::GetModuleFileNameW(hmodule, &buffer[0], buffer.size());
123 if (chars_copied == buffer.size() &&
124 ::GetLastError() == ERROR_INSUFFICIENT_BUFFER)
125 buffer.resize(buffer.size() * 2);
126 }
while (chars_copied >= buffer.size());
128 if (!llvm::convertWideToUTF8(buffer.data(), path))
129 return module_filespec;
130 module_filespec.
SetFile(path, FileSpec::Style::native);
131 return module_filespec;
136 process_infos.clear();
138 AutoHandle snapshot(CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0));
139 if (!snapshot.IsValid())
142 PROCESSENTRY32W pe = {};
143 pe.dwSize =
sizeof(PROCESSENTRY32W);
144 if (Process32FirstW(snapshot.get(), &pe)) {
146 AutoHandle handle(::OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE,
152 llvm::convertWideToUTF8(pe.szExeFile, exeFile);
159 process_infos.push_back(process);
160 }
while (Process32NextW(snapshot.get(), &pe));
162 return process_infos.size();
166 process_info.
Clear();
169 ::OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid),
171 if (!handle.IsValid())
179 AutoHandle snapshot(CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0));
180 if (!snapshot.IsValid())
184 pe.dwSize =
sizeof(PROCESSENTRY32W);
185 if (Process32FirstW(snapshot.get(), &pe)) {
187 if (pe.th32ProcessID == pid) {
191 }
while (Process32NextW(snapshot.get(), &pe));
197 llvm::Expected<HostThread> Host::StartMonitoringChildProcess(
204 if (launch_info.
GetFlags().
Test(eLaunchFlagShellExpandArguments)) {
205 FileSpec expand_tool_spec = HostInfo::GetSupportExeDir();
206 if (!expand_tool_spec) {
207 error.SetErrorString(
"could not find support executable directory for "
208 "the lldb-argdumper tool");
212 if (!FileSystem::Instance().Exists(expand_tool_spec)) {
213 error.SetErrorString(
"could not find the lldb-argdumper tool");
219 std::replace(quoted_cmd_string.begin(), quoted_cmd_string.end(),
'\\',
'/');
222 expand_command.
Printf(
"\"%s\" %s", expand_tool_spec.
GetPath().c_str(),
223 quoted_cmd_string.c_str());
230 &status,
nullptr, &output, std::chrono::seconds(10));
236 error.SetErrorStringWithFormat(
"lldb-argdumper exited with error %d",
241 auto data_sp = StructuredData::ParseJSON(output);
243 error.SetErrorString(
"invalid JSON");
247 auto dict_sp = data_sp->GetAsDictionary();
249 error.SetErrorString(
"invalid JSON");
253 auto args_sp = dict_sp->GetObjectForDotSeparatedPath(
"arguments");
255 error.SetErrorString(
"invalid JSON");
259 auto args_array_sp = args_sp->GetAsArray();
260 if (!args_array_sp) {
261 error.SetErrorString(
"invalid JSON");
267 for (
size_t i = 0; i < args_array_sp->GetSize(); i++) {
268 auto item_sp = args_array_sp->GetItemAtIndex(i);
271 auto str_sp = item_sp->GetAsString();
287 LPWCH environment_block = ::GetEnvironmentStringsW();
288 while (*environment_block != L
'\0') {
290 auto current_var_size = wcslen(environment_block) + 1;
291 if (!llvm::convertWideToUTF8(environment_block, current_var)) {
292 environment_block += current_var_size;
295 if (current_var[0] !=
'=')
298 environment_block += current_var_size;