Where is stdout for VS Code? - visual-studio-code

I am running Node.js in VS Code. I see output of console.log in the Debug Window.
Where does process.stdout.write go to? I can't find it in the Debug Console or any of the Output windows.
My launch.json is simply this:
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/job.js"
}
]
}

Looking at issues with process.stdout.write the suggested fixes are adding these to your launch config:
"console": "internalConsole",
"outputCapture": "std",
Especially the outputCapture entry is important.

Make sure the Debug Console is visible:
Ctrl + Shift + Y

Can you try to add "console": "internalConsole" to your config and see if it works?
As per the docs these are the available options for the console:
console - what kind of console to use, for example, internalConsole,
integratedTerminal, externalTerminal

Related

Piping VSCode output to another program

Frustratingly there is an old issue that has been closed in relation to this. The linked issues seem to resolve this for python extensions, but I am using Typescript. No comments on it being resolved in general when it was closed so I assume that there must be a way to achieve this.
I wish to use VSCode debugging with individual test files, but also pipe the final output to a different program. VSCode escapes the pipe operator...
launch.json
{
"type": "node",
"request": "launch",
"name": "tap-single",
"skipFiles": [
"<node_internals>/**",
"${workspaceFolder}/node_modules/**"
],
"program": "${file}",
"runtimeExecutable": "/home/user/.npm-global/bin/ts-node",
"runtimeArgs": [
"--transpileOnly",
],
"args": [
"|", // This is output as `\|` in the console...
"tap-arc"
],
"console": "integratedTerminal",
}
Partial output is below;
... /home/user/.npm-global/bin/ts-node --transpileOnly ./test/example.test.ts \| tap-arc
Debugger attached.

Remote debugging C++ with VsCode

I have gdbserver attached to a process and working fine on a remote machine, port 9999. On my local machine, from command line:
$ gdb
(gdb) target remote localhost:9999
works just fine. I am trying to configure Vs Code debugger so that I can have a GDB frontend for this case. Here is my launch JSON.
"version": "0.2.0",
"configurations": [
{
"name": "GDB",
"type": "cppdbg",
"request": "attach",
"miDebuggerServerAddress": "localhost:9999",
"program": "path-to-cross-compiled-binary-with-same-debug-symbols",
"linux": {
"MIMode": "gdb",
},
}
]
There are couple of issues here. First of all, why "program"? In this case, gdb doesn't need any program name to start. Program is already running on remote, gdbserver is already attached to it. I just want gdb client to connect to port 9999. But anyways, moving on.
It wants me to give a processId. This also does not make sense, I am already attached on remote. The fun part is:
If you leave out processId, Vs Code says "unable to parse the process id"
If you specify a processId, Vs Code says "processId cannot be used with miDebuggerServerAddress"
Of course, if I am using a debugger server address, server is already attached to PID and it makes sense that processId can't be used in this case. But if I leave it out, VS Code gives the 1. error. This is cyclic in a way.
Anyone is able to attach to a remote process in VS Code C++ debugger with gdbserver address, that is my question. What is wrong with my launch file?
You need to use the "launch" request instead of "attach". I also needed to add the default "cwd" option.
"request": "launch",
"cwd": "${workspaceFolder}",
You may also need to define "additionalSOLibSearchPath".
My launch config now looks like this:
{
// 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": [
{
// "processId": "${command:pickProcess}",
"name": "(gdb) Remote Attach",
"type": "cppdbg",
"request": "launch",
"program": ".\\src\\binaryfolder\\app.nostrip",
"additionalSOLibSearchPath": "arm-none-linux-gnueabi/libc/lib;./lib;C:\\DeviceSDK\\win-2.8.15\\sdk\\toolchains\\arm-4.4.1\\arm-none-linux-gnueabi\\libc\\lib;C:\\DeviceSDK\\win-2.8.15\\sdk\\platforms\\201205\\lib",
// "processId": "${command:pickProcess}",
"MIMode": "gdb",
"cwd": "${workspaceFolder}",
"miDebuggerPath": "C:\\DeviceSDK\\win-2.8.15\\sdk\\toolchains\\arm-4.4.1\\bin\\arm-none-linux-gnueabi-gdb.exe",
"miDebuggerServerAddress": "192.168.205.88:51000",
"miDebuggerArgs": " -ex 'handle all print nostop noignore'",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true,
}
]
},
]
}
See CppTools issue 321

unable to start debugging unexpected gdb output from command environment cd

I want to lauch gdb in vscode. I want to debug my c code using gdb in vscode , but i m getting following error :
unable to start debugging unexpected gdb output from command environment cd
I have my gdb installed on wsl.
here is my lauch.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": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\\bin\\main",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"pipeTransport": {
"pipeCwd": "",
"pipeProgram": "c:\\windows\\sysnative\\bash.exe",
"pipeArgs": ["-c"],
"debuggerPath": "/usr/bin/gdb"
},
"sourceFileMap": {
"/mnt/z": "z:\\"
}
}
]
}
I am unable to debug my program
Well, two years too late, but here we go.
From what I saw, you are using windows. I had the same problem and quickly resolved it. Apparently it's some system bug. To resolve, follow these steps:
(Tested on Windows 10)
Go to Windows Control Panel (You can do this by opening File Explorer and in the path type 'Control Panel' (without quotes) and hit Enter);
From the Control Panel, click on 'Clock and Region'.
Click Region. A new screen will open.
In the screen that opened, click on Administrative and search for the button "Change system location".
Check the option: "Beta: Use Unicode UTF-8 for world language support"
Restart the computer.
By doing this procedure, the problem will be solved.
I hope it has helped you and others who are experiencing this problem.

Visual Studio Code Task is Prepending the working directory to the command

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.

VSCode Debug console customization

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"
}
]
}