How to debug Vue 3 Vite while on lan --host - debugging

How can I debug while using --host option on Vue 3 Vite so I can debug my phone instance for example. At the moment Im using visual studio code plugin "Vite"
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "pwa-chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:4000",
"webRoot": "${workspaceFolder}/app",
}
]
}
package.json
"scripts": {
"dev": "vite --host --port 4000",
}
Vite config options
with this I'm being able to run on lan and debug but only on my pc, if I try from my phone or other pc, it connects but it wont stop on any breakpoint.

In order to debug any web app, web browser running on your phone must support a debugging protocol. Chrome for Android for example does support what you need, see Remote debugging article.
As for another PC, you need to launch Chrome there with a remote debugging command line switch as well, and then edit your launch.json to attach your vs code instance to different host (ip and port). That is of course if you want to be able to set breakpoints in vs code on your developer machine and then reflect that on another PC.
Roughly saying, you need to point your vs code to a running target
browser, for example, in your current config vs code launches instance of Chrome with a debugging switch enabled for you, behind the scenes

Related

launchSettings "commandName": "Docker" - what exactly does it do?

Visual studio can create a project from template with "enable Docker support". In which a section in launchSettings.json is created with
"Docker": {
"commandName": "Docker",
"publishAllPorts": true
}
When started with this configuration, what I see is that docker image is built and started in Docker Desktop and debugging is started in a remote debugging fashion (I see no dotnet instance started locally)
My question:
Are my assumptions correct?
Is there any documentation that describe thoese behaviour and where we can tweak these settings, such as targeting a remote docker host?

How can I debug Go file in VS Code with root privileges?

How can I force Delve in VS Code to use root privileges?
I'm trying to debug go file that involves gopacket/pcap:
hndl, err := pcapgo.NewEthernetHandle(ifname)
// err == "couldn't open packet socket: operation not permitted"
Launching same program using sudo doesn't trigger error.
I've tried several methods:
Launch sudo code . It warns that it is not recommended. Plus there are issues to use dlv in this mode as environment variables are messed up.
Using this guide https://fatdragon.me/blog/2020/06/debug-golang-vs-code-linux-root. However "go.alternateTools" seems to know nothing about "dlv": Property dlv is not allowed. Probably something is missing in guide.
Search for .vscode/launch.json config property that allows to sudo. VSC allows to do such for Python, but not for Go.
Is there any trivial way to launch debugger with root privileges?
Environment:
Ubuntu 18.04
VSCode 1.48.0
Go 1.13.4
Delve 1.4.0
Update May 2022
Debugging programs and tests as root in the documentation of the VSCode Go addon has been updated accordingly with task and launch configuration examples to not only debug programs but also tests as root.
Old
Debugging Go programs and tests that require root privileges using VSCode has been sore for a long time. As of VSCode version 1.65.0 I noticed a new experimental launch option "asRoot": "true" 🙌 that needs to be combined with "console": "integratedTerminal".
For instance, in your launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Test/dbg pkg as root",
"type": "go",
"request": "launch",
"mode": "test",
"program": "${fileDirname}",
"console": "integratedTerminal",
"asRoot": true,
},
]
}
When launching this configuration by pressing F5, a new debug terminal session opens (or might get reused) and the following command executed:
/usr/bin/env GOPATH=/home/foobar/go /usr/bin/sudo /home/foobar/go/bin/dlv dap --check-go-version=false --client-addr=:41945
This now automatically inserts the sudo command before dlv itself, so this needs to be launched into an internal or external interactive terminal (and thus does not work in the internal console). After authenticating to sudo, VSCode switches back to the debug console view and you are good to go.
This now avoids having to fiddle around with remapping the dlv command in your workspace to a wrapper shell script.

Cannot hit ASP.NET Core API from remote computer on network

I created the sample dotnet webapi project via dotnet new webapi (v3.1.101) and updated launchSettings.json's applicationUrl to first http:*:5000 then to http:0.0.0.0:5000. When I try to go to http://<MY_COMPUTER_NETWORK_NAME>:5000/WeatherForecast, it times out, yet when I locally try http://localhost:5000/WeatherForecast, it works.
I ran a React App on port 5000 and I could successfully connect to it remotely, so I don't think it is a firewall issue.
I am running on a Mac. I also tried adding .UseUrls(...) without success.
Why can't I connect remotely?
Thanks in advance!
dotnet run will try to automatically load MyApplication\Properties\launchSettings.json.
If file launchSettings.json exists and "all addresses" binding is set:
{
"profiles": {
"Uno": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://0.0.0.0:5001;http://0.0.0.0:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Then running the application should give this result:
> dotnet run
info: Microsoft.Hosting.Lifetime[0]
Now listening on: https://0.0.0.0:5001
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://0.0.0.0:5000
and checking open ports:
> netstat -na | ? { $_ -match "5000|5001" }
TCP 0.0.0.0:5000 0.0.0.0:0 LISTENING
TCP 0.0.0.0:5001 0.0.0.0:0 LISTENING
If launchSettings.json does not exist or exist with different name, default binding will apply:
> mv .\Properties\launchSettings.json .\Properties\launch.json
> dotnet run
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
Now listening on: https://localhost:5001
unless you specify the urls using specific option:
server.urls="http://0.0.0.0:5000;https://0.0.0.0:5001"
Also note that the first time that any application tries to bind to 0.0.0.0:port, a window like this appears:
It is very easy to miss it if you are in multi monitor setup or if you immediately focus on other windows. Also, this dialog will set an application specific firewall rule, so maybe you created the rule for the React application and not the rule for the dotnet app.
I'm using VSCode in Windows and I've noticed I cannot use the dotnet run command from the terminal, I have to hit play from the Debug sidebar window for it to work, and then I can connect from other computers on the same network.
If you would like to launch with the terminal, then I think you have to manually specify your launch.json file in the options. See the --launch-profile option here: https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-run

How to remotely debug Go code with VSCode

I run a process inside a docker container that needs to be debugged. The process is started in the docker's entry point via
dlv debug /go/src/path/to/package --headless --listen=:2345 --log for the purpose of enabling debugging later in VSCode.
The docker container is started via
docker run --rm -it -p 2345:2345 my_image:tag. Note delve's port is exposed.
In VSCode I define launch.json as follows:
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach remote",
"type": "go",
"request": "attach",
"mode": "remote",
"port": 2345,
"host": "127.0.0.1",
"apiVersion": 1
}
]
}
Upon starting the "attach remote" VSCode debugging configuration I get
It isn't crystal clear, but that UI leads me to believe I'm now connected to the remote headless debugger and ready to debug. I have one breakpoint defined which I know would be hit by a request I can send the remote process. I send that request, I get a result, and that breakpoint never hit, indicating that I haven't yet achieved remote debugging.
Is something wrong with my VSCode "attach remote" configuration? I can do command-line debugging with dlv connect :2345 and actually debug the remote process just fine, which indicates the headless server is functional. I would rather debug with source code, in VSCode though.
Try again with the latest beta of vscode-go (April 2020) (for any time after April 2020, the latest official vscode-go release will be enough)
Microsoft/vscode-go issue 2010 includes this confirmation from Ramya Rao:
The fix from #3108 is available in the latest beta version of this extension. Please do try and share feedback
The latest version of the extension now has the fix to this issue
And:
I can confirm that I am able to hit breakpoints now using AWS SAM to launch a linux container with delve and go binaries compiled from Windows.
For anyone still having this problem (like I was before I edited this comment), take care that the "remotePath" element of your launch.json is the absolute path to the source files as compiled on your local system (not the container).
As implied above - it's the absolute local path that is added to the DWARF compilation unit file table when you compile the binary.

How to make Visual Studio starting my ASP.NET application always on the same port when debugging?

I am developing an ASP.NET Core Web API in Visual Studio and using Postman to test it.
To do so, I start the integrated IIS Express Server via clicking on the "Run" Button in Visual Studio. I would expect the server always listening on the same port but on every start it is assigned a different port. How can I change this?
This is my output of the ASP.NET Core Web Server in Visual Studio after I started and stopped the server 3 times:
WebApi> Hosting environment: Development
WebApi> Content root path: C:\Code\Work\webcoreapi\WebApi
WebApi> Now listening on: http://localhost:25626
WebApi> Application started. Press Ctrl+C to shut down.
WebApi> Hosting environment: Development
WebApi> Content root path: C:\Code\Work\webcoreapi\WebApi
WebApi> Now listening on: http://localhost:22130
WebApi> Application started. Press Ctrl+C to shut down.
WebApi> Hosting environment: Development
WebApi> Content root path: C:\Code\Work\webcoreapi\WebApi
WebApi> Now listening on: http://localhost:22405
WebApi> Application started. Press Ctrl+C to shut down.
If I run the same Application in command line via dotnet run it starts the application and listens on localhost:5000 as expected every single time.
So it has to do something with my Visual Studio Configuration but I cannot find it. Here is my launchSettings.jsonfile:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:5000/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchUrl": "http://localhost:5000/",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
So I guess everything is correctly configurated. I know that Visual Studio tries to find an open port if the default one is not availability but I already checked that too. The port 5000 is always free to use when I start the server in VS.
Does anyone have a hint how to make VS always start on 5000?
I am using Visual Studio Community 2017 (Version 15.3.5)
Under properties in the startup project, look for launchSettings.json.
You can set the applicationURL value there.
I.e. http://localhost:5000
The environment variables and launch URL can be set there as well.

Resources