Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mechanism to detect new threads #88

Merged
merged 9 commits into from
Sep 13, 2021
Merged

Conversation

aaalexandrov
Copy link
Contributor

Use windows debugger interface to detect the debugee's threads.
Fall back to polling a toolhelp snapshot in case debugger interface can't attach of fails.
Fixes #4

@CyberShadow
Copy link
Member

Amazing. Will look at this soon!

@CyberShadow
Copy link
Member

Thanks! Do you think this should be an option? E.g., if someone starts profiling but later decides to attach a debugger, this will now not be possible AIUI. Though, I guess the old behavior is still possible if you just select all threads and profile with those threads. Maybe we only need to document it.

@rmitton
Copy link
Contributor

rmitton commented Aug 30, 2021

If the debugger interface doesn't work out, I believe another option is to inject a custom mini DLL into the target's address space -- you can get thread creation notifications via its DllMain callback.

@aaalexandrov
Copy link
Contributor Author

Thanks! Do you think this should be an option? E.g., if someone starts profiling but later decides to attach a debugger, this will now not be possible AIUI. Though, I guess the old behavior is still possible if you just select all threads and profile with those threads. Maybe we only need to document it.

Yes, my thinking was that you get the old behavior by selecting all existing threads and profiling them
but if you have an idea how to make this more obvious in the UI, I can implement it

@aaalexandrov
Copy link
Contributor Author

If the debugger interface doesn't work out, I believe another option is to inject a custom mini DLL into the target's address space -- you can get thread creation notifications via its DllMain callback.

It works on my machine!!1
On a more serious note, it seems to work fine, except when there's already a debugger attached to the application. And if it fails for whatever reason, it should fall back to the old behavior.

@CyberShadow
Copy link
Member

Yep, I think a note in the documentation should be enough. We can update the wiki after this is merged.

LGTM, I rebased on master and added a changelog entry. Let me know if that looks OK to you and we can merge.

@aaalexandrov
Copy link
Contributor Author

It looks great, thank you :)

@CyberShadow CyberShadow merged commit dc62b28 into VerySleepy:master Sep 13, 2021
@aaalexandrov
Copy link
Contributor Author

I also looked into how to make this work through dll injection. RenderDoc does this in production code, here's the code https://github.com/baldurk/renderdoc/blob/v1.x/renderdoc/os/win32/win32_process.cpp#L252-L297

@CyberShadow
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New threads created during profiling get ignored
3 participants