A professional, automated framework for cross-compiling and remote debugging on Embedded Linux devices using VS Code, CMake, and GDB.
This repository provides a robust "One-Click Debugging" workflow for Embedded Linux development. It solves the inefficiency of manual file transfers and printf debugging by automating the entire pipeline:
- Cross-Compilation (Host side).
- Deployment (SCP to Target).
- Process Management (Safe port handling on Target).
- GDB Attachment (Live debugging via VS Code).
This template is board-agnostic and can be adapted for any platform (Raspberry Pi, BeagleBone, i.MX, STM32MP1, Nuvoton, etc.) running gdbserver.
.
├── CMakeLists.txt # Main build configuration (Platform independent)
├── build/ # Out-of-source build artifacts
├── src/
│ └── main.cpp # Application source code
├── toolchain/
│ └── generic.cmake # Toolchain definition (Compiler paths & flags)
└── .vscode/ # VS Code Automation & Configuration
├── settings.json # Project-wide variables (IPs, Paths, Users)
├── tasks.json # Automation pipeline (Build -> Deploy -> Run)
└── launch.json # GDB Client configuration
Host Machine (Developer PC)
- OS: Linux (Ubuntu/Debian) or Windows (WSL2).
- Software:
- VS Code + C/C++ Extension + CMake Tools.
- gdb-multiarch (Universal GDB Client).
- ssh, scp.
- Target Device (Embedded Board)
- Linux Kernel.
- gdbserver installed. (or download from https://github.com/stayliv3/gdb-static-cross/tree/master/prebuilt)
- SSH Access enabled.
Clone this repository and update the environment variables in .vscode/settings.json to match your hardware:
// .vscode/settings.json
{
// --- Target Board Configuration ---
"embed.targetIP": "192.168.1.100",
"embed.targetUser": "root",
"embed.targetPath": "/usr/local/my_app",
"embed.debugPort": "2345",
// --- Host Configuration ---
"embed.hostBuildPath": "${workspaceFolder}/build/my_app"
}To allow automation, the Host must access the Target without a password prompt.
# On Host Terminal
ssh-copy-id root@192.168.1.100Create this file to define your cross-compiler. Do not hardcode paths in CMakeLists.txt.
# Change your toolchain path
cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=./toolchain/generic.cmake -DCMAKE_BUILD_TYPE=Debug- Open src/main.cpp
- Set a Breakpoint (F9).
- Press F5.