It's possible, but Windows gives us a handle to the thread which has all privileges associated with it (in other words we can use it for just about anything), so it's considered better to use the handle windows gives us. At the very least we'd want to queue up all the incoming event notifications that we get from this loop, and then use it to update the state when someone stops.
Just to be certain, when you and Greg refer to "when someone has stopped", I assume you are referring to a public stop, i.e. someone has to enter a command to resume the debugger?
No just a private stop. You should _not_ be changing the process state to stopped and running again (via Process::SetPrivateState()) for thread creation or thread death, only for stops where an existing thread stops for some reason (trace (single step), breakpoint, exception, etc). The private state thread will move the thread plans along for private stops, which agains are only actual stops where the process stops due to a existing thread (not a new or dying thread) stopping for a reason. These thread creation events should be suppressed from the private state thread and only handled for your own purposed. You also do not want to be updating the thread list as you are running (the one in Process::GetThreadList()), so you should keep your own ThreadList object within the windows event loop that only your windows event will update. Later when a stop gets propagated to the private state of the process, it will call:
UpdateThreadList (ThreadList &old_thread_list, ThreadList &new_thread_list) = 0;
And you can merge your private copy of your ThreadList into new_thread_list as needed. You should be doing something like:
while (WaitForDebugEvent(&event)) // Block until something happens in the process
if (event is thread creation)
else if (event is thread death)
// Windows stopped the process for us automatically. Do something with the event
ContinueDebugEvent(&event); // Resume the process
Then in your
ProcessWindows::UpdateThreadList (ThreadList &old_thread_list, ThreadList &new_thread_list)
// Append any threads from old_thread_list into new_thread_list if they are still alive by checking if any of them are in deadWindowsThreads and only adding them if they aren't in the list
// Append all threads from newWindowsThreads into new_thread_list
I was wondering why my RefreshStateAfterStop override was never being called, I'm guessing now that it's because I was only updating the private state, and this only gets called on a public stop.
Yes this seems to be for public stops only. ProcessWindows::UpdateThreadList() isn't only for public stops, it is used in private stops as well.