Use machine hostname inside VSCode launch.json file - visual-studio-code

I'd like to know if it's possible to have the launch.json file of VSCode using the hostname of my machine. To be more precisely, I'd like to use the hostname in the configurations.url properties, something like this:
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch",
"url": "https://<<hostname>>/",
"webRoot": "${workspaceFolder}"
}
]
}
As you can see, the url properties has <<hostname>>; though, I'd like that, when pressing F5, that <<hostname>> is automatically replaced with the machine hostname (e.g. DESKTOP-JUWKA3).
I've tried to look for answer on stackOverflow, as well as VSCode official site:
https://code.visualstudio.com/docs/nodejs/browser-debugging
https://code.visualstudio.com/docs/editor/variables-reference
I thought something was possible with the information in the second link, but unfortunately I haven't been able to do that (maybe I'm not capable of doing it >_>)

Related

VS Code launch.json, debug with input user

Suppose I have in working directory hundreds exe file, I would like to debug one of them.
I do not want that launch.json will have hundreds objects for each exe file.
Is there a way, to have one object, and when start debug, I will choose which file I would like to debug?
I have tried extension "VSCode Prompt Debug" but it seems it does not work
In VSCode there is inputs, how can I use regex
for example:
{
"version": "0.2.0",
"configurations": [{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/${input:pickProgram}"
}],
"inputs": [{
"id": "pickProgram",
"description": "Select client or server",
"type": "pickString",
"options": ["*.exe"]
}]}
Thanks

Run HTML page in Chrome

In Visual Studio Code running on Windows 10, I am trying to run a plain HTML page in Chrome using a startup script in my workspace definition. When I run the site, chrome opens to the correct URL but I get the error below stating the connection was refused. The chrome browser that opens is not the same chrome browser I use when I just browse the internet on my own. My preferences are not set and there are not any user profiles. Has anyone else experienced this behavior?
{
"folders": [
{
"path": "."
}
],
"settings": {},
"launch": {
"version": "0.2.0",
"configurations": [
{
"name": "mypage",
"request": "launch",
"type": "chrome",
"url": "http://localhost:8080/index.html",
"webRoot": "${workspaceFolder}"
}
]
}
}
I was able to run the files by changing the URL to point to the file directly. It seems even if you leave out the protocol, VS Code defaults it to HTTP. Even though my description had the HTTP URL defined, I also tried removing it. #ScottMildenburger comment got me to reevaluate that logic and find the answer. Thank you Scott!
"launch": {
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against Samples Index",
"url": "file:///${workspaceFolder}/index.html"
}
]

Why does R Debugger fail to verify all breakpoints (Vscode)

I am using R Debugger in Vscode to develop an RShiny app while using SSH to connect to the remote.
My launch.json file looks like this:
{
"version": "0.2.0",
"configurations": [
{
"type": "R-Debugger",
"name": "Launch R-Workspace",
"request": "launch",
"debugMode": "workspace",
"workingDirectory": "", // If I put my actual path here, it changes nothing
"allowGlobalDebugging":true
}
]
}
For the purposes of this topic, I have these folders/files:
src/www/uis
src/server.R
I set breakpoints in files within src/www/uis as well as within src/server.R.
When I use Launch R-Workspace, the breakpoints at src/www/uis will trigger but within src/server.r they turn into "unverified breakpoints".
What I've tried:
Reading through similar questions and findings answers that did not seem relevant. Reading through the documentation where I did not see anything useful to me.
Any insight?
Thanks

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

VS Code debug in Chrome - This site can’t be reached error

I know this question has been asked before, but after reading a lot of the threads, I still haven't found my answer...
I am trying to debug a very simple html app with Chrome, but when I get to my localhost I get an error that says "This site can’t be reached". My launch.json code looks like this:
"version": "0.2.0",
"configurations": [
{
"name": "Launch Chrome against localhost, with sourcemaps",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000",
"sourceMaps": true,
"webRoot": "${workspaceRoot}"
},
{
"name": "Attach to Chrome, with sourcemaps",
"type": "chrome",
"request": "attach",
"port": 9222,
"sourceMaps": true,
"webRoot": "${workspaceRoot}"
}
]
}
Any help would really be appreciated as I have been struggling for quite a while with this now.
As #Rob-Lourens has mentioned you need to start your own local server to host your HTML/Javascript/CSS and images.
You can use a VS code plugin Live Server to create a local development server for you. Please make sure your URL("url": "http://localhost:3000") in your configuration file matches the URL of Live Server.
If you are on Windows and want to use IIS or IIS Express you can read up on IIS and IISExpress
Just change the value in launch.Json and remove unwanted and paste the html file location in the file attribute.
{
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Open index.html",
"file": "C:\\Users\\xyz\\projects\\PracticeProjects\\jsbasics\\index.html"
}
]
}