25#include "llvm/Support/ConvertUTF.h"
34 llvm::Triple &triple) {
40 return llvm::errorToBool(imageBinaryP.takeError());
41 File &imageBinary = *imageBinaryP.get();
45 uint16_t machineType = 0;
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);
86 std::string executable;
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 AutoHandle handle(::OpenProcess(PROCESS_TERMINATE, FALSE, pid),
nullptr);
107 if (handle.IsValid())
108 ::TerminateProcess(handle.get(), 1);
116 HMODULE hmodule = NULL;
117 if (!::GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
118 (LPCTSTR)host_addr, &hmodule))
119 return module_filespec;
121 std::vector<wchar_t> buffer(
PATH_MAX);
122 DWORD chars_copied = 0;
124 chars_copied = ::GetModuleFileNameW(hmodule, &buffer[0], buffer.size());
125 if (chars_copied == buffer.size() &&
126 ::GetLastError() == ERROR_INSUFFICIENT_BUFFER)
127 buffer.resize(buffer.size() * 2);
128 }
while (chars_copied >= buffer.size());
130 if (!llvm::convertWideToUTF8(buffer.data(), path))
131 return module_filespec;
132 module_filespec.
SetFile(path, FileSpec::Style::native);
133 return module_filespec;
138 process_infos.clear();
140 AutoHandle snapshot(CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0));
141 if (!snapshot.IsValid())
144 PROCESSENTRY32W pe = {};
145 pe.dwSize =
sizeof(PROCESSENTRY32W);
146 if (Process32FirstW(snapshot.get(), &pe)) {
148 AutoHandle handle(::OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE,
154 llvm::convertWideToUTF8(pe.szExeFile, exeFile);
161 process_infos.push_back(process);
162 }
while (Process32NextW(snapshot.get(), &pe));
164 return process_infos.size();
168 process_info.
Clear();
171 ::OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid),
173 if (!handle.IsValid())
181 AutoHandle snapshot(CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0));
182 if (!snapshot.IsValid())
186 pe.dwSize =
sizeof(PROCESSENTRY32W);
187 if (Process32FirstW(snapshot.get(), &pe)) {
189 if (pe.th32ProcessID == pid) {
193 }
while (Process32NextW(snapshot.get(), &pe));
206 if (launch_info.
GetFlags().
Test(eLaunchFlagShellExpandArguments)) {
207 FileSpec expand_tool_spec = HostInfo::GetSupportExeDir();
208 if (!expand_tool_spec) {
210 "could not find support executable directory for "
211 "the lldb-argdumper tool");
220 std::string quoted_cmd_string;
222 std::replace(quoted_cmd_string.begin(), quoted_cmd_string.end(),
'\\',
'/');
225 expand_command.
Printf(
"\"%s\" %s", expand_tool_spec.
GetPath().c_str(),
226 quoted_cmd_string.c_str());
230 std::string command = expand_command.
GetString().str();
233 &status,
nullptr, &output, std::chrono::seconds(10));
240 "lldb-argdumper exited with error %d", status);
250 auto dict_sp = data_sp->GetAsDictionary();
256 auto args_sp = dict_sp->GetObjectForDotSeparatedPath(
"arguments");
262 auto args_array_sp = args_sp->GetAsArray();
263 if (!args_array_sp) {
270 for (
size_t i = 0; i < args_array_sp->GetSize(); i++) {
271 auto item_sp = args_array_sp->GetItemAtIndex(i);
274 auto str_sp = item_sp->GetAsString();
290 LPWCH environment_block = ::GetEnvironmentStringsW();
291 while (*environment_block != L
'\0') {
292 std::string current_var;
293 auto current_var_size = wcslen(environment_block) + 1;
294 if (!llvm::convertWideToUTF8(environment_block, current_var)) {
295 environment_block += current_var_size;
298 if (current_var[0] !=
'=')
301 environment_block += current_var_size;
static llvm::raw_ostream & error(Stream &strm)
An architecture specification class.
void AppendArgument(llvm::StringRef arg_str, char quote_char='\0')
Appends a new argument to the end of the list argument list.
bool GetQuotedCommandString(std::string &command) const
void Clear()
Clear the arguments.
std::pair< iterator, bool > insert(llvm::StringRef KeyEqValue)
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
void AppendPathComponent(llvm::StringRef component)
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
int Open(const char *path, int flags, int mode=0600)
Wraps ::open in a platform-independent way.
static FileSystem & Instance()
An abstract base class for files.
Status Read(void *buf, size_t &num_bytes) override
Read bytes from a file from the current file position into buf.
virtual off_t SeekFromStart(off_t offset, Status *error_ptr=nullptr)
Seek to an offset relative to the beginning of the file.
bool Test(ValueType bit) const
Test a single flag bit.
static Status ShellExpandArguments(ProcessLaunchInfo &launch_info)
Perform expansion of the command-line for this launch info This can potentially involve wildcard expa...
static Status RunShellCommand(llvm::StringRef command, const FileSpec &working_dir, int *status_ptr, int *signo_ptr, std::string *command_output, const Timeout< std::micro > &timeout, bool run_in_shell=true, bool hide_stderr=false)
Run a shell command.
static lldb::thread_t GetCurrentThread()
Get the thread token (the one returned by ThreadCreate when the thread was created) for the calling t...
static Environment GetEnvironment()
static uint32_t FindProcessesImpl(const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &proc_infos)
static bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info)
static FileSpec GetModuleFileSpecForHostAddress(const void *host_addr)
Given an address in the current process (the process that is running the LLDB code),...
std::function< void(lldb::pid_t pid, int signal, int status)> MonitorChildProcessCallback
static llvm::Expected< HostThread > StartMonitoringChildProcess(const MonitorChildProcessCallback &callback, lldb::pid_t pid)
Start monitoring a child process.
static void Kill(lldb::pid_t pid, int signo)
static const char * GetSignalAsCString(int signo)
void SetExecutableFile(const FileSpec &exe_file, bool add_exe_file_as_first_arg)
void SetArchitecture(const ArchSpec &arch)
void SetProcessID(lldb::pid_t pid)
bool MatchAllProcesses() const
bool Matches(const ProcessInstanceInfo &proc_info) const
void SetParentProcessID(lldb::pid_t pid)
const FileSpec & GetWorkingDirectory() const
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
static Status FromErrorString(const char *str)
bool Fail() const
Test for error condition.
llvm::StringRef GetString() const
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
static ObjectSP ParseJSON(llvm::StringRef json_text)
A class that represents a running process on the host machine.
std::vector< ProcessInstanceInfo > ProcessInstanceInfoList
static void GetProcessExecutableAndTriple(const AutoHandle &handle, ProcessInstanceInfo &process)
static bool GetTripleForProcess(const FileSpec &executable, llvm::Triple &triple)
static bool GetExecutableForProcess(const AutoHandle &handle, std::string &path)