microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.53k stars 1.56k forks source link

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

Open simon-p-r opened 6 years ago

simon-p-r commented 6 years ago

Type: Debugger

pieandcakes commented 6 years ago

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.

simon-p-r commented 6 years ago

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 commented 6 years ago

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

parkovski commented 6 years ago

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.

pieandcakes commented 6 years ago

@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.

simon-p-r commented 6 years ago

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

andig commented 5 years ago

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.

drew-512 commented 5 years ago

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!

pieandcakes commented 5 years ago

@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.

janpauldahlke commented 4 years ago

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

smdmori commented 4 years ago

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

github-actions[bot] commented 3 years ago

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] commented 3 years ago

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

dreua commented 3 years ago

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.

sean-mcmanus commented 3 years ago

Thanks for letting us know.

mdegans commented 3 years ago

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.

kmansoft commented 2 years ago

Still in an issue in 1.71.0

Code team, please fix!

astralmaster commented 2 years ago

Still an issue to this day.

dreua commented 2 years ago

@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.

ktemelkov commented 1 year ago

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.

Spongman commented 1 year ago

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.

metalim commented 1 year ago

"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