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

Target interruption #2

Open
gsmcmullin opened this issue Nov 15, 2016 · 1 comment
Open

Target interruption #2

gsmcmullin opened this issue Nov 15, 2016 · 1 comment

Comments

@gsmcmullin
Copy link
Owner

There are 4 different scenarios requiring different mechanisms for interrupting the target.

On POSIX systems:

  • Local child processes must be sent SIGINT directly to the child
  • For remote targets SIGINT must be sent to GDB

On Windows systems:

  • Local targets must have a debug exception generated by calling DebugBreakProcess with a handle to the child process.
  • For remote targets GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0) can be used to send SIGINT to GDB, but this requires the sender to share a console window with GDB, and ignore the signal.

POSIX signals are easily sent with Node's process.kill(pid, signal). The problem remains of how to tell if the target is remote. These are options:

  • Have a check box in the config dialog
  • Check for magic pid 42000 reported by GDB
  • Try send SIGINT to GDB, and then to reported PID if it hasn't halted after a timeout.

How to even make Windows API calls from JS remains a mystery.

Windows API calls that may be useful to achieve this nonsense:

/* Get the Windows handle from the PID reported by GDB */
HANDLE process = OpenProcess(PROCESS_ALL_ACCESS, FALSE, (DWORD)pid);
/* Attach to another process' console window */
AttachConsole(pid);
/* Make the console Window invisible, so users don't see the ugly DOS box */
SetWindowPos(GetConsoleWindow(), HWND_BOTTOM, 0, 0, 0, 0, SWP_HIDEWINDOW);

GDB async-mi mode may also be used to make MI run command asynchronous. Sending -gdb-set async-mi on puts GDB into async mode. After this the -exec-* commands that resume execution run in the background, and further commands may be sent while the inferior is running. The -exec-interrupt command may be sent to GDB to interrupt the target.

CLI commands that resume the target will still block until the inferior stops. They may be explicitly run in the background by adding an ampersand to the command line.

@gsmcmullin
Copy link
Owner Author

The current implementation uses async mode. -exec-interrupt is sent to interrupt the target. If the target does not stop, a SIGINT is sent to GDB after a timeout. This works for interrupting blocking CLI commands, but is not documented. This strategy appears to work on Windows with remote targets, but on native targets GDB is killed by the signal. I presume this is because there is no way to send SIGINT other than the CTRL_C_EVENT through the console window, as described above.

Interruption of both native and remote targets is tested in the testsuite. Travis only runs the tests on Linux.

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

1 participant