Skip to content

Target interruption #2

@gsmcmullin

Description

@gsmcmullin

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions