================
@@ -227,6 +229,56 @@ ProcessWindows::DoAttachToProcessWithID(lldb::pid_t pid,
return error;
}
+Status ProcessWindows::DoAttachToProcessWithName(
+ const char *process_name, const ProcessAttachInfo &attach_info) {
+ Status error;
+ Clear();
+
+ if (!process_name || process_name[0] == '\0') {
+ error = Status::FromErrorString("Invalid process name");
+ return error;
+ }
+
+ lldb::pid_t pid = FindProcessByName(process_name, error);
+
+ if (pid == LLDB_INVALID_PROCESS_ID) {
+ error = Status::FromErrorStringWithFormatv("Unable to find process '%s'",
+ process_name);
+ return error;
+ }
+
+ return DoAttachToProcessWithID(pid, attach_info);
+}
+
+lldb::pid_t ProcessWindows::FindProcessByName(const char *process_name,
+ Status &error) {
+ HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
+ if (hProcessSnap == INVALID_HANDLE_VALUE) {
+ error = Status(GetLastError(), eErrorTypeWin32);
+ return LLDB_INVALID_PROCESS_ID;
+ }
+ auto cleanup = llvm::make_scope_exit([&] { CloseHandle(hProcessSnap); });
+
+ llvm::StringRef process_filename = llvm::sys::path::filename(process_name);
----------------
DavidSpickett wrote:
What happens here if process_name is null?
https://github.com/llvm/llvm-project/pull/173015
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits