How can I run my debugger commands while the program is running? - c

I've configured my launch.json & tasks.json then return to my file.c and click the green arrow.
I see 'attached image'. Click OK to allow access then I am left with my Debugger but no variables exist and my options like step_into, step_over disappear then I find myself in the same loop.
Below is the JSON for launch and tasks.
launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "clang - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"preLaunchTask": "clang build active file"
}
]
}
tasks.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "msbuild",
"args": [
"/property:GenerateFullPaths=true",
"/t:build",
"/consoleloggerparameters:NoSummary"
],
"group": "build",
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
},
{
"type": "shell",
"label": "clang build active file",
"command": "/usr/bin/clang",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
}
]
}

It looks like the code is not "paused", so the debugger will not activate while the code is actively running. Try to set a breakpoint and see if that fixes the issue.

Related

Passing arguments to the C debugger in Visual Studio Code

As the title says, I'm not able to pass arguments to the Visual Studio Code debugger.
I'm in MacOS, and I'm using gcc.
When I use the auto-generated launch.json and tasks.json everything's fine, but when I add the arguments everything crashes.
auto-generated launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "gcc - Compilar y depurar el archivo activo",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"preLaunchTask": "C/C++: gcc build active file"
}
]
}
auto-generated tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
When I first execute it, I can debug freely, but as I'm adding (to launch.json):
"args": [
"-c",
"1",
"file1"
],
everything's crashes with the message:
The preLaunchTask 'C/C++: gcc build active file' terminated with exit code -1.
and if I click Debug Anyway the message becomes:
launch: program '/Users/.../.vscode/launch' does not exist*
At that point I can't do anything else but click on Open launch.json
Could you help me?
Thanks

MinGW Debugger in VS Code is Stuck at Building tasks. What can I do to get it back to normal? I

Earlier it used to create the .exe files whenever I hit the F5 button to debug the code. But now for some reason I am unable to get it right and I messed up with the .json files, and it keeps throwing errors.
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe build active file",
"command": "C:\\MinGW\\bin\\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-Wall",
"-Wextra",
"-Wpedantic"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "compiler: C:\\MinGW\\bin\\gcc.exe"
}
]
}
This is the tasks.json file.
{
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": true,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true,
"internalConsoleOptions": "openOnSessionStart",
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
This is the launch .json file.

exe. file not running in vs code

when I try to run c-code in "VS Code", it not showing output.
but exe. file is made by compiler as shown in image.
I cross checked that I add GCC,G++ in environment variable so,
mostly there is problem in config
''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''
launch.json-->
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "gcc.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc.exe build active file"
}
]
}
task.json -->
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe build active file",
"command": "C:\\MinGW\\bin\\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
Go to settings -> Search for channel -> In C/C++ setting will be INSIDER -> Update to DEFAULT

I get an error saying " Could not find the task 'C/C++: g++.exe build active file'

I've tried most things on Stack Overflow including messing around with external console values, using a previous version of C/C++ extensions, changing cppbuild to shell, etc. Nothing seems to make it work. If I press debug anyway, I get an error saying the launch program '....launch.exe' does not exist.
Here is my launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "C:\\msys64\\mingw64\\bin",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file",
"miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe"
}
]
}
Here is my task.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: gcc.exe build active file",
"command": "C:\\msys64\\mingw64\\bin\\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: C:\\msys64\\mingw64\\bin\\gcc.exe"
},
{
"label": "run make",
"type": "shell",
"command": "make"
},
{
"label": "run make test",
"type": "shell",
"command": "make test"
}
]
}
"preLaunchTask": "C/C++: g++.exe build active file" in launch.json, should be consistent with "label": "C/C++: gcc.exe build active file" in tasks.json.

VScode's debugger not working [MacOS - Clang - C]

My problem is generated when trying to debug C (the programming language) in vscode using the latest MacOS version with command line tools installed.
The error appears when the external terminal is launched in order to debug. I'm using the clang compiler with the following configuration files for the debugger in vscode:
launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "clang - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true,
"MIMode": "lldb",
"preLaunchTask": "C/C++: clang build active file"
}
]
}
tasks.json:
{
"tasks": [
{
"label": "Open Terminal",
"type": "shell",
"command": "osascript -e 'tell application \"Terminal\"\ndo script \"echo hello\"\nend tell'",
"problemMatcher": []
},
{
"type": "cppbuild",
"label": "C/C++: clang build active file",
"command": "/usr/bin/clang",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
The error that appears in the terminal:
username#Martins-MBP ~ % cd ''; env 'USER=Martin' '__CFBundleIdentifier=com.microsoft.VSCode' 'COMMAND_MODE=unix2003' 'LOGNAME=Martin' 'PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin' 'SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.ABVM6fu0pS/Listeners' 'SHELL=/bin/zsh' 'HOME=/Users/Martin' '__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x2' 'TMPDIR=/var/folders/zb/b62pl9hd43n4chv3k7jg5cxr0000gn/T/' 'XPC_SERVICE_NAME=application.com.microsoft.VSCode.142509.142515' 'XPC_FLAGS=0x0' 'ORIGINAL_XDG_CURRENT_DESKTOP=undefined' 'SHLVL=0' 'PWD=/' 'OLDPWD=/' '_=/Applications/Visual Studio Code.app/Contents/MacOS/Electron' 'APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL=true' '/bin/sh' '/var/folders/zb/b62pl9hd43n4chv3k7jg5cxr0000gn/T/Microsoft-MIEngine-Cmd-ukaihz0n.2gz'

Resources