diff --git a/docker/debug/.vscode/launch.json b/docker/debug/.vscode/launch.json new file mode 100644 index 000000000..7d37af129 --- /dev/null +++ b/docker/debug/.vscode/launch.json @@ -0,0 +1,56 @@ +{ + "version": "0.2.0", + "configurations": + [ + { + "name": "Docker Remote Debug (start & attach)", + "type": "lldb", + "request": "launch", + + "initCommands": [ + "platform select remote-linux", + "platform connect connect://localhost:10586" + ], + + "targetCreateCommands": [ + "target create /usr/src/tuliprox/target/x86_64-unknown-linux-musl/debug/tuliprox" + ], + + "processCreateCommands": [ + // Attache to the process and continue after attaching + "attach -n tuliprox", + "continue" + ], + + "sourceMap": { + "/usr/src/tuliprox": "${workspaceFolder}" + }, + + "preLaunchTask": "docker-compose-up-debug" + }, + { + "name": "Docker Remote Debug (attach only)", + "type": "lldb", + "request": "launch", + + "initCommands": [ + "platform select remote-linux", + "platform connect connect://localhost:10586" + ], + + "targetCreateCommands": [ + "target create /usr/src/tuliprox/target/x86_64-unknown-linux-musl/debug/tuliprox" + ], + + "processCreateCommands": [ + // Attache to the process and continue after attaching + "attach -n tuliprox", + "continue" + ], + + "sourceMap": { + "/usr/src/tuliprox": "${workspaceFolder}" + } + } + ] +} \ No newline at end of file diff --git a/docker/debug/.vscode/tasks.json b/docker/debug/.vscode/tasks.json new file mode 100644 index 000000000..41d920797 --- /dev/null +++ b/docker/debug/.vscode/tasks.json @@ -0,0 +1,27 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "docker-compose-up-debug", + "type": "shell", + "command": "docker compose -f docker-compose.yml -f docker-compose.debug-override.yml up --build --force-recreate -d --wait", + "problemMatcher": [], + "presentation": { + "reveal": "always", + "clear": true + }, + "detail": "Builds and starts the Docker Compose stack for debugging." + }, + { + "label": "docker-compose-down", + "type": "shell", + "command": "docker compose -f docker-compose.yml -f docker-compose.debug-override.yml down", + "problemMatcher": [], + "presentation": { + "reveal": "silent", + "clear": true + }, + "detail": "Stops and removes all containers defined in the Docker Compose files." + } + ] +} diff --git a/docker/debug/HOWTO.md b/docker/debug/HOWTO.md new file mode 100644 index 000000000..5127b8ca2 --- /dev/null +++ b/docker/debug/HOWTO.md @@ -0,0 +1,73 @@ +# Remote Debugging tuliprox in VSCode with Docker + +This guide explains how to set up remote debugging for the tuliprox project in VSCode using a Docker container. + +## Prerequisites + +- VSCode with the following extensions: + - [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb) + - [Docker](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-docker) +- Docker and Docker Compose installed +- Rust toolchain (if building locally) + +## Setup + +1. Copy the debug configuration files to your project root: + ```bash + cp -r docker/debug/.vscode . + cp docker/debug/docker-compose.debug-override.yml . + ``` + +## Configuration + +### Docker Compose +The `docker-compose.debug-override.yml` file: +- Configures LLDB debug ports (10586 for control, 10600-10700 for sessions) +- Sets up privileged mode for debugging +- Mounts cargo cache volumes for faster builds +- Uses the debug build target + +### VSCode Tasks +The `.vscode/tasks.json` defines: +- `docker-compose-up-debug`: Builds and starts containers with debug config +- `docker-compose-down`: Stops and removes containers + +### VSCode Launch Configurations +The `.vscode/launch.json` provides two debug configurations: +1. **Docker Remote Debug (start & attach)**: + - Automatically starts containers and attaches debugger + - Uses the `docker-compose-up-debug` pre-launch task +2. **Docker Remote Debug (attach only)**: + - Only attaches debugger to running container + +## Debugging Workflow + +1. Open the project in VSCode +2. Set breakpoints in your Rust code +3. Select the debug configuration from the Run and Debug panel: + - Use "Docker Remote Debug (start & attach)" for a complete start-to-debug workflow + - Use "Docker Remote Debug (attach only)" if containers are already running +4. Press F5 to start debugging + +## Troubleshooting + +### Common Issues + +1. **Debugger fails to connect**: + - Verify ports 10586 and 10600-10700 are available + - Check Docker container logs for errors + - Ensure the container is running in privileged mode + +2. **Breakpoints not hitting**: + - Verify source mapping is correct in launch.json + - Ensure you're using the debug build (`target/debug/tuliprox`) + +3. **Performance issues**: + - The debug build is slower than release + - Consider adding more RAM to Docker if needed + +### Debugging Tips + +- Use the VSCode debug console for LLDB commands +- The debugger supports all standard LLDB features (watch, call stack, etc.) +- Breakpoints can be set while the program is running \ No newline at end of file