According to documentation, I should be able to get my program output to display in the Integrated debug console instead of in the Integrated terminal with:
"programOutput": true in launch.json
In the simplest hello world C program on linux with vscode version 1.75.1, this just doesn't work. Both stderr, and stdout go to the integrated terminal.
By the way, the reason I want this to work is because I want to use the filter line to specify which output lines to show and which to hide.
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
...
...
"externalConsole": false,
"logging": {
"programOutput": true
},
Related
I'm using GDB to debug a QEMU program using vscode. The GDB server is started by a make command, via a task in tasks.json:
"tasks": [
{
"label": "ARMCM33_GDBServer",
"type": "shell",
"command": "make gdbserver",
"isBackground": true
}
]
Where my makefile looks a bit like this:
gdbserver: $(BINARY)
#$(QEMU_PATH) \
-machine $(MACHINE_NAME) \
-kernel $(BUILD_DIR)/kernel.elf \
-S -gdb tcp::4321
gdb: $(BINARY)
$(GDB) $(BINARY) -ex "target remote:4321"
My launch.json looks a bit like this:
"configurations": [
{
"type": "cppdbg",
"request": "launch",
"name": "Debug",
"miDebuggerPath": "/bin/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi-gdb",
"program": "build/ARMCM33/kernel.elf",
"args": ["ex"],
"miDebuggerServerAddress": "localhost:4321",
"preLaunchTask": "ARMCM33_GDBServer",
],
},
This all works well in vscode. However, the problem is I want vscode to use my Makefile gdb call, rather than having to duplicate parameters in the launch.json (e.g. like the TCP address, GDB path). Having browsed the launch.json docs, I can't immediately see a solution.
So, how do I use my gdb command line command to use GDB in vscode?
I want to run bash script when I hit F5 and see the results in the terminal like I can do with python scripts or whatever. I tried to do that with Bash Debug however it automatically goes to the debug mode and stops at the first step even if I do not put breakpoint. This is the launch configuration I use.
{
"type": "bashdb",
"request": "launch",
"name": "Run mysql test",
"cwd": "${workspaceFolder}",
"program": "/srv/gpf/dba/mysqlslap/run.sh",
"args": []
}
I don't know about running bash in a debug mode (doesn't seem like you need those features based on your example) but you can easily get your script to run as a Task or Build option.
Place this at .vscode/tasks.json of your project dir
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Run as Bash Script",
"type": "shell",
"command": "/bin/bash ${file}",
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
You can place whatever you want in the "command" parameter.
As you can see, it's of type "kind": "build" so I can hit ctrl+shift+B and this will execute in a terminal.
Note, you can also use the command palette (F1 or ctrl+shift+P) and use Task: Run as Task too.
Source: https://code.visualstudio.com/Docs/editor/tasks
I am trying to step through Postgresql code using Visual Studio Code as my IDE on Linux. I am using attach to a process config in launch.json to achieve the same. Following is the launch.json config:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "attach",
"program": "/usr/local/pgsql/bin/postgres",
"processId": 4165,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true,
}
]
}
]
}
When I start Debugging via the GUI, it attaches to the process. But whenever I add a breakpoint, I get the following message printed on the debug console:
Program received signal SIGINT, Interrupt.
0x00007ff5d084e31b in epoll_wait () from /lib64/libc.so.6
And fails to add the breakpoint. From the Postgres developer documentation (link) it is clear that we need to bypass the interrupts arriving at gdb by issuing the following command to gdb:
handle SIGUSR1 noprint pass
I think this command in gdb can be executed only before attaching the process for debugging. Hence when I run this command via the debug console on Visual Studio Code, I get the following error:
Unable to perform this action because the process is running.
Is there a way to instruct the Visual Studio Code debugging, to issue the "handle SIGUSR1 noprint pass" into gdb before it attaches the target process via gdb?
After more research, I found a way to achieve this using ~/.gdbinit file. This file can have commands that will be run each time gdb is run. I have the following content in it:
handle SIGUSR1 nostop noprint pass
handle SIGINT nostop noprint pass
Now what happens is since SIGINT is being overriden, every time the IDE is disconnected from the process, it has be restarted because it cannot disconnect gracefully anymore.
Consider to define these commands in section setupCommands of launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "debugging of local server",
"type": "cppdbg",
"request": "attach",
"program": "/usr/local/pgsql/bin/postgres",
"processId": "${command:pickProcess}",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "ignore SIGUSR1 signal",
"text": "handle SIGUSR1 nostop noprint pass"
}
]
}
]
}
In addition to Keshav's answer.
You may also add another command to the ~/.gdbinit file :
set auto-load safe-path /
This will tell the compiler that it can use the local .gdbinit file in your working directory.
Now you can make a separate .gdbinit for each project / directory and have them configured independently and not clutter up the global .gdbinit.
I'm trying to setup visual studio code for rust to do debugging. In my launch.json file I have
{
"version": "0.2.0",
"configurations": [
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceRoot}/target/debug/vscode-rust-debug-example.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"preLaunchTask": "localcargobuildtask"
}
]
}
and in my tasks.json I have
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "localcargobuildtask",
"command": "echo hi",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Where "echo hi" is in my tasks I eventually want to have something like "cargo build" or "cargo test" or whatever. But this is just a starting step.
But when I press F5 the output I get is
> Executing task: C:\programs\VSCodeWorkspaces\RustProjects\vscode-rust-debug-example-debug-config-included\echo hi <
The terminal process terminated with exit code: 2
Terminal will be reused by tasks, press any key to close it.
Rather than running "echo" from where ever the terminal finds it (working directory first, then check global path variable like you would expect) it is actually looking for a program named "echo" in my root folder of the workspace.
How do I tell visual studio code "No I don't want you to run workspace/echo, I want you to run echo in workspace" ? Or is there another more direct way to tell visual studio code "compile this before you debug it" ?
The answer to this question How to debug Rust unit tests on Windows?
suggests that changing
"command": "cargo build",
into
"command": "cargo",
"args": [
"build"
],
in the tasks.json file works and somehow it does. Maybe the editor is configured to search the %path% for single word commands, or maybe some plugin I installed overwrote the "cargo" command. Maybe the reason echo wasn't found is because it is a terminal command, not a program. Maybe the error message was a lie and it was only reporting that it couldn't find workspacefolder\command despite checking %path%? Or maybe none of that. I have no idea. It is some pretty idiosyncratic behavior.
I've a project that i'm using Bunyan logger as logger agent. But the Bunyan logs with the json format the debug texts, and this make difficult to read the output:
But Bunyan provides a CLI tool to humanize the log that converts the JSON to a readable text:
What I want's is create an extension to enable Bunyan console format to the Debug output text, automatic transforming the json output to debug text. But in VSCode extension development API I couldn't find any reference to manipulate debug console.
I if can manipulate de Debug console message, I could return te messages well formatted as Bunyan format.
So my question is if have some documentation to manipulate debug console messages or how i can work with debug console messages in my vscode extension.
I have found the answer by myself. I can do this simply changing my Debugger configurations, setting args and console type as the follow:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceRoot}/app.js",
"cwd": "${workspaceRoot}",
"args": [
"|",
"bunyan"
],
"console": "integratedTerminal"
}
]
}