- Either download the .deb and install as in this link https://code.visualstudio.com/docs/setup/linux
- Or add microsoft repo and run apt install as here https://linuxize.com/post/how-to-install-visual-studio-code-on-ubuntu-18-04/
- Add C/C++ Intellisense extension
- Git extension for easy commits
- Doxygen commenting extension is also pretty cool.
- There is VIM key support extensions
- In VScode menu bar, Go to Terminal > Configure Tasks and click on the create tasks.json file > and select external command
- This will add a default tasks.json file in the .vscode directory in your project folder.
Modify the tasks.json to something similar to, most of it is already populated you just have to change the commands for build with your makefile
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "HOST BUILD",
"type": "shell",
"command": "make all"
},
{
"label": "BBB BUILD",
"type": "shell",
"command": "make all PLATFORM=BBB",
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "Clean",
"type": "shell",
"command": "make clean"
}
]
}
-
This gives you 3 tasks HOST_BUILD, BBB_BUILD and Clean. Ctrl+Shift+B to run default build task.
-
Run the tasks from Terminal Run task and select task to run.
-
Can also set up shortcut keys for the tasks.
Go to Debug, Open Configurations, Choose C++.
Change file to something like this for native debugging.
{
// 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}/target",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
For remote debugging we need 2 additional parameters
- The gdb we are using has to be gdb multi-arch “miDebuggerPath”
- And also the server address “miDebuggerServerAddress” set this to gdb server address:port.
- The resulting config.js file is something similar
{
// 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-HOST",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/target",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
{
"name": "GDB-REMOTE-BBB",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/target",
"miDebuggerServerAddress": "192.168.7.2:4000",
"miDebuggerPath": "/usr/bin/gdb-multiarch",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
Add this command at the end of your build (Makefile) or as a prebuild task in vscode to remotely start gdb server on target device
ssh -t root@BBB_ip_address "cd /target_location/ && gdbserver localhost:port target_name"
https://code.visualstudio.com/docs/languages/cpp#_debugging-your-code
Hello, I am trying to remote debug the same way with gdb multiarch but it stops at listening on port and it does not start the remote debug session. the one you wrote includes two different configs. does that mean you should run the host and then the remote client?
`