vscode-cpptools icon indicating copy to clipboard operation
vscode-cpptools copied to clipboard

Cannot send ctrl-c or ctrl-break to spawned debug console

Open simon-p-r opened this issue 6 years ago • 17 comments

Type: Debugger

  • OS and Version:

    Microsoft Windows [Version 10.0.17134.112]

  • VS Code Version:

    Version 1.24.1 Commit 24f62626b222e9a8313213fb64b10d741a326288 Date 2018-06-13T17:51:32.889Z Shell 1.7.12 Renderer 58.0.3029.110 Node 7.9.0 Architecture x64

  • C/C++ Extension Version:

    Version 0.17.4

  • Other extensions you installed (and if the issue persists after disabling them):

    None

  • A clear and concise description of what the bug is.

    Trying to send ctrl-c to debug console but not triggering console interrupt handler in source code

  • Additional context

    Tried adding logging to debugger but no events are being captured for this

simon-p-r avatar Jun 19 '18 11:06 simon-p-r

Tried adding logging to debugger but no events are being captured for this

What did you try?

Can you please post your launch.json and which type of application you are debugging?

If you want to send Ctrl+c you probably need to use the terminal that appears and not the debuggerTerminal in VS Code since we aren't hooked up to that yet.

pieandcakes avatar Jun 19 '18 20:06 pieandcakes

I am using libuv to trap signals, the debugger spawns a separate console but it is not trapping the key signals. I expect it to handle ctrl-c and ctrl-break signals when pressed. I have created a repo with a demo of bug.

simon-p-r avatar Jun 20 '18 12:06 simon-p-r

Repo is here https://github.com/simon-p-r/vscode-debugger-signal

simon-p-r avatar Jun 22 '18 13:06 simon-p-r

There's probably an issue relating to this in just about every Windows terminal project. They've been impossible to make work consistently, and I think most people have given up on them until the PTY API is made stable. The only thing that consistently works is finding the hidden console window and sending it WM_KEYDOWN/WM_KEYUP messages.

parkovski avatar Jun 23 '18 21:06 parkovski

@simon-p-r I have your repo but I can't figure out how to build. I installed your tool set items below and then ran vcpkg install libuv, I set the libuv Library path environment variable. and then tried both cmake and cmake-js's builds.

pieandcakes avatar Jun 26 '18 00:06 pieandcakes

Sorry that was not clear, you need to run build.js script with node. It needs to find version of libuv installed by vcpkg

simon-p-r avatar Jun 26 '18 13:06 simon-p-r

I've just noticed the same trying to debug a golang issue where the application would hang on signal. Doesn't seem possible to Ctrl-C in the debug console. This is on OSX.

andig avatar Jan 01 '19 16:01 andig

Bump!

First off, shoutout to the VS Code dev team for making such a badass piece of software! It just keeps getting better and the Go support is so lovely. Thanks so much and and sending y'all good vibes! <3

Anyway, yes, I get the complexity around Ctrl+C mysteriously not arriving to a given debug process. However, maybe it's easy/doable to have SIGINT or SIGTERM make it when coming from the OS? Justing being able to execute kill -s SIGTERM 12345 for a daemon running under the VS Code debugger would be awesome. Otherwise, to simulate a SIGINT (ctrl+c), we have to have painful hack in place (and make sure that code never gets committed, etc). As is, sending a SIGTERM, SIGINT, and SIGHUP never show up (via package signal.Notifiy() handler) when the process is running in the VS Code debugger.

Heeeelp! Kindly get this to this lil but helpful thing!

drew-512 avatar May 30 '19 18:05 drew-512

@drew-512 this is the C++ extension. If you are asking for VS Code to support it for Go, you will need to ask either VS Code or the Go extension you are using.

For C++ this is currently on the list of items to tackle.

pieandcakes avatar May 30 '19 23:05 pieandcakes

Bump. Still happens in 1.44.1 on Windows 10 in nodejs environment

janpauldahlke avatar Apr 23 '20 10:04 janpauldahlke

Tried this in 1.47.2 on Ubuntu in python environment, and it's still happening.

smdmori avatar Jul 29 '20 08:07 smdmori

Hey @pieandcakes, this issue might need further attention.

@simon-p-r, you can help us out by closing this issue if the problem no longer exists, or adding more information.

github-actions[bot] avatar Dec 09 '20 00:12 github-actions[bot]

This issue has been closed automatically because it needs more information and has not had recent activity.

github-actions[bot] avatar Dec 23 '20 11:12 github-actions[bot]

I think this issue should not have been closed, what information is missing?

I believe that vs code or gdb catch the Ctrl+C and instantly kill the application without sending a signal or giving it time to exit gracefully. That is very annoying if you are debugging an app that needs a signal to gracefully shutdown and clean up.

dreua avatar Dec 23 '20 13:12 dreua

Thanks for letting us know.

sean-mcmanus avatar Dec 23 '20 17:12 sean-mcmanus

I can repro on an aarch64 Ubuntu 18.04 remote. Local client is Ubuntu 20.04 amd64. Vscode version 1.56.2 (snap)

launch.json configuration is:

        {
            "name": "(gdb) test sigint",
            "type": "cppdbg",
            "request": "launch",
            "program": "/usr/bin/python3",
            "args": [
                "${workspaceFolder}/test_sigint.py"
            ],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": []
        },

test_sigint.py is

import time

try:
  while(True):
    time.sleep(1)
except KeyboardInterrupt:
  print("success")

When run directly, with gdb --args python3 ... and i hit ctrl+c, "success" is printed. When I run the configuration in vscode, the script immediately quits.

~/.gdbinit is:

handle SIGINT nostop print pass

What's frustrating is this was working last week on the same configuration. It appears this may be a recent regression.

mdegans avatar Jun 02 '21 21:06 mdegans

Still in an issue in 1.71.0

Code team, please fix!

kmansoft avatar Sep 11 '22 15:09 kmansoft

Still an issue to this day.

astralmaster avatar Oct 06 '22 11:10 astralmaster

@kmansoft @astralmaster please give :+1: to the top post to support this issue. You can also hit the "Subscribe" button in order to get notifications when someone adds a comment. With those two steps done, I'm not sure there is need to leave a comment and notify everyone that this issue is still present. I believe everyone here is quite aware of that.

dreua avatar Oct 06 '22 13:10 dreua

I am using this configuration to debug my NodeJS AddOn:

{
  "type": "cppvsdbg",
  "request": "launch",  
  "name": "Launch test application",
  "cwd": "${workspaceFolder}",
  "console": "integratedTerminal",
  "program": "node",
  "args": ["test-out/main.js"]
}

Note the "console": "integratedTerminal" line. Pressing Ctrl-C inside the "Debug Console" does not do anything, but as the application is run inside the integrated terminal Ctrl-C works correctly there. I suspect that this might be the intended behavior and the debug console is not same as a terminal. I am working on MS Windows at the moment and have not verified this behavior with gdb, yet.

ktemelkov avatar Nov 29 '22 00:11 ktemelkov

I'm seeing the same issue. ctrl-c always kills the debuggee:

my launch..json contains:

"setupCommands": [
    { "text": "-interpreter-exec exec handle SIGINT nostop print pass", "ignoreFailures": true }
]

the debuggee handles SIGINT and normally shuts down gracefully, but when being debugged in vscode it's impossible to debug this shutdown code as it never gets run.

Spongman avatar Dec 14 '22 07:12 Spongman

"console": "integratedTerminal", allows to send Ctrl+C to the app, but debugger terminates the app before it runs all cleanup code.

ChatGPT to the rescue.

image

Results:

image

metalim avatar Aug 17 '23 09:08 metalim