-
Notifications
You must be signed in to change notification settings - Fork 16
Remote SSH Debugging Setup in Visual Studio Code
kxu edited this page Jan 20, 2022
·
1 revision
- Launch a ubuntu vm on AWS (default setting)
- Generate a RSA key pair or reuse the existing key pair
- Download the private key
- Suggest moving the key under
C:\Users\<username>\.ssh\
, otherwise may cause issues when connecting
- Open Visual Studio Code (VSC) locally
- Click 'Extensions' on the left navigation menu
- Search 'Remote Development'
- Click 'Install'
- 'Remote Explorer' icon appears after installation
- Click 'Remote Explorer' icon on the left navigation menu
- Select 'SSH Targets' under the dropdown menu in the side bar window
- Click the gear icon (Configure) next to 'SSH TARGETS'
- In the pop-up bar, select 'C:\Users<username>.ssh\config'
- The config file appears in the right editor area
- Fill in the following information
Host <alias>
HostName <Public IPv4 DNS of the vm on AWS>
User <username>
IdentityFile <full dir of the private key>
- Click 'Connect to host in New Window' in the side bar window
- In the new window, select 'Linux' in the pop-up bar, select 'Continue'
- Click 'New Terminal' under 'Terminal' tab on the menu bar
- Now you have a terminal which ssh into the remote vm
- Run
sudo apt-get -y update; sudo apt-get -y install build-essential
- Run
curl -LO https://go.dev/dl/go1.17.6.linux-amd64.tar.gz
- Run
sudo tar -C /usr/local -xvf go1.17.6.linux-amd64.tar.gz
- Append
export PATH=$PATH:/usr/local/go/bin
to~/.profile
- Run
source ~/.profile
- Click 'Extensions' on the left navigation menu
- Search 'Go'
- Click 'Go' package
- Click 'Install in SSH:<remote_vm_alias>'
- Press F1, search ''Go: Install/Update Tools'
- Select all packages, click 'OK'
- Run
mkdir code
on remote vm - Click 'Open Folder' from 'File' tab in VSC
- Select the dir
/home/ubuntu/code
in the search bar, click 'OK' - A new VSC window pops up.
- Creat a new file and put some test code
- Open a new terminal and run the code
- Press F5, click 'create a launch json file'
- In the 'program' field, change to
"${workspaceFolder}/<filename>.go"
- Set breakpoints in the code, and run.
- Open a terminal
- Run
sudo ln -s /usr/local/go/bin/go /usr/bin/go
- Edit
launch.json
following the below example:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "debug", // builds and launches, or use `exec` to executes precompiled binary
"host": "127.0.0.1",
"port": 2345, //2345 can be any unused port
"program": "${workspaceFolder}/<filename>.go"
}
]
}
- Run
sudo <go/bin directory>/dlv-dap dap -l='127.0.0.1:2345' --only-same-user=false --check-go-version=false
, where2345
can be any unused port. - Set breakpoints in the code, and run.
- Reference