[Lldb-commits] [lldb] [lldb][windows] add attach by name with --waitfor (PR #173015)
Charles Zablit via lldb-commits
lldb-commits at lists.llvm.org
Mon Jan 5 10:52:04 PST 2026
================
@@ -227,6 +230,58 @@ 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;
+ }
+
+ ProcessInstanceInfoMatch match_info;
+ match_info.SetNameMatchType(NameMatch::Equals);
+ match_info.GetProcessInfo().GetExecutableFile().SetFile(
+ process_name, FileSpec::Style::native);
+
+ Log *log = GetLog(LLDBLog::Process);
+ LLDB_LOGF(log, "ProcessWindows::%s waiting for process '%s' to launch",
+ __FUNCTION__, process_name);
+
+ lldb::pid_t pid = LLDB_INVALID_PROCESS_ID;
+ while (pid == LLDB_INVALID_PROCESS_ID) {
+ ProcessInstanceInfoList process_infos;
+ uint32_t num_matches = Host::FindProcesses(match_info, process_infos);
+
+ if (num_matches == 1) {
+ pid = process_infos[0].GetProcessID();
+ break;
+ }
+ if (num_matches > 1) {
+ StreamString s;
+ ProcessInstanceInfo::DumpTableHeader(s, true, false);
+ for (size_t i = 0; i < num_matches; i++) {
+ process_infos[i].DumpAsTableRow(
+ s, lldb_private::HostInfoWindows::GetUserIDResolver(), true, false);
+ }
+ error = Status::FromErrorStringWithFormat(
+ "more than one process named %s:\n%s", process_name, s.GetData());
+ break;
+ }
+
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
----------------
charles-zablit wrote:
I am not sure. I don't see anything that prevents us from doing it: a lot of the logic is implemented through Windows API calls in `windows/common/DebuggerThread.cpp`.
It is certainly a lot of work, which I think would be worth doing simply for the sake of matching the POSIX implementations (async mechanisms, etc). In the Swift fork, `print` does not work in the REPL on Windows because we are not using `ProcessGDBRemote`.
I will start by creating a thread on the forums to see if anyone has attempted that before.
https://github.com/llvm/llvm-project/pull/173015
More information about the lldb-commits
mailing list