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

Severe system-wide lag when breakpoint/exception hit when debugging #197

Open
GeorgeBarlow opened this issue Jul 12, 2024 · 1 comment
Open

Comments

@GeorgeBarlow
Copy link

GeorgeBarlow commented Jul 12, 2024

Description

When using libuiohook and pausing execution with a debugger (on breakpoint or an exception that has been caught), the entire system experiences severe lag. This is mainly due to the low-level hooks continuing to handle system-wide events while the application is paused, causing the event queue to back up.

Desired Behavior

  • The hooks should ideally be unregistered or bypassed when the debugged process is halted, not just when a debugger is attached.
  • System should remain responsive during debugging sessions.

Potential Solutions

At a glance, on Windows, the Win32 API has an IsDebuggerPresent() function that could aid in better understanding the environment the process is being used/ran in. However, this function gets called when the process is initially attached to a debugger rather than when the process is halted on exception or breakpoint. The obvious consequence is that we would lose the ability to observe events when a debugger is attached if we decided to unregister the hooks at this point.

Platform

  • Windows (when tested significant lag was present system-wide)
  • macOS (no significant issues when tested but in theory, the same issue could occur)
  • Linux (untested)

Ideally, as discussed previously with @kwhat, it could be useful to explore a solution for Windows and then expand that to the other supported operating systems. However, this may be subject to change.

@kwhat
Copy link
Owner

kwhat commented Jul 13, 2024

For Windows, I think you can do something like this on line 277.

while (!IsDebuggerPresent() && GetMessage(&message, (HWND) NULL, 0, 0) > 0) {

This will basically just stop the listener when the debugger connects. You won't be able to debug though the hook, but at least it wont prevent the keyboard and mouse from functioning.

Let me know if that works / open a pull-request. I don't have a Windows development environment setup right now so I can't really test.

The more I think about the above, the more I am not convinced it will work. You may need to add something like this around line 65 and 105

if (IsDebuggerPresent()) {
    hook_stop();
}

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

No branches or pull requests

2 participants