-
Notifications
You must be signed in to change notification settings - Fork 394
Add C++ debugging example #824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TamseSaso
wants to merge
16
commits into
main
Choose a base branch
from
cpp_debugging
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
88cadf0
Add C++ debugging example
TamseSaso 7c2797e
Added final newline character
TamseSaso 168daa2
Run pre-commit check
TamseSaso 9076cf4
Added launch.json
TamseSaso 47365bc
Updated launch.json and changes in README.md
TamseSaso 89a70eb
Applied comments
TamseSaso 36981f3
Added tasks.json
TamseSaso bf0d811
Simpler debugging_example
TamseSaso a7effb7
Added new line characters
TamseSaso 6abfc93
Ran pre-commit
TamseSaso 8df1009
Added full automation of vscode debugging c++
TamseSaso 5662fdf
optimized behaviour for ubuntu
TamseSaso 1530550
Updated README.md file
TamseSaso a8ffd55
Working debugging_example
TamseSaso 51a5f2c
Hopefully working
TamseSaso 4acddfe
separate folder for .build artifacts, keeping clean
TamseSaso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| build/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # Build artifacts | ||
| build/ | ||
|
|
||
| # Documentation | ||
| README.md | ||
|
|
||
| # VCS | ||
| .git/ | ||
| .github/ | ||
| .gitlab/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| cmake_minimum_required(VERSION 3.20) | ||
|
|
||
| project(camera_stream VERSION 1.0 LANGUAGES CXX) | ||
|
|
||
| # Use C++17 standard | ||
| set(CMAKE_CXX_STANDARD 17) | ||
|
|
||
|
|
||
| # Depthai dependency | ||
| find_package(depthai REQUIRED) | ||
| message(STATUS "Found depthai: ${depthai_DIR}") | ||
|
|
||
| # Add source files | ||
| add_executable(main src/main.cpp) | ||
|
|
||
| # Link with libraries | ||
| target_link_libraries(main PUBLIC depthai::core) | ||
|
|
||
| # Suppress warnings about C++17 ABI in GCC 10.1+ | ||
| target_compile_options(main PRIVATE -Wno-psabi) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # Remote Debugging Setup for OAK C++ Apps | ||
|
|
||
| This example shows the steps to add VS Code remote debugging to any C++ OAK app. | ||
|
|
||
| ## 1. Copy `.vscode/launch.json` | ||
|
|
||
| Copy the `.vscode/launch.json` from this project into your app's `.vscode/` folder. No changes needed — it uses `${workspaceFolder}` throughout so it works in any project location. | ||
|
|
||
| On launch it will prompt for: | ||
|
|
||
| - **GDB path** — your local GDB binary (dropdown with common OS paths) | ||
|
TamseSaso marked this conversation as resolved.
Outdated
|
||
| - **Board IP** — IP address of your OAK device | ||
|
|
||
| ## 2. Update `backend-run.sh` | ||
|
|
||
| Your `backend-run.sh` should start `gdbserver` wrapping your binary instead of running it directly: | ||
|
|
||
| ```sh | ||
| #!/bin/sh | ||
| gdbserver 0.0.0.0:5678 /app/build/main | ||
| ``` | ||
|
|
||
| ## 3. Update `oakapp.toml` | ||
|
|
||
| Add the following to your `build_steps`: | ||
|
|
||
| ```toml | ||
| build_steps = [ | ||
| # Install gdbserver | ||
| "apt-get install -y --no-install-recommends gdb gdbserver", | ||
|
|
||
| # Register backend-run.sh as a runit service so gdbserver starts automatically | ||
| "mkdir -p /etc/service/backend", | ||
| "cp /app/backend-run.sh /etc/service/backend/run", | ||
| "chmod +x /etc/service/backend/run", | ||
|
themarpe marked this conversation as resolved.
Outdated
|
||
|
|
||
| # Build in Debug mode so the binary has symbols | ||
| "cmake -S /app -B /app/build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON", | ||
| "cmake --build /app/build -- -j", | ||
| ] | ||
| ``` | ||
|
|
||
| ## 4. Deploy and Debug | ||
|
|
||
| ```bash | ||
| oakctl app run . | ||
| ``` | ||
|
|
||
| Then set breakpoints and press **F5** in VS Code. GDB connects to `gdbserver` on port 5678, pulls the binary directly from the container, reloads symbols, and starts the debug session. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| #!/bin/sh | ||
| echo "Starting Backend" | ||
| gdbserver 0.0.0.0:5678 /app/build/main |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| identifier = "com.example.cpp.camera_stream" | ||
| entrypoint = ["bash", "-c", "/usr/bin/runsvdir -P /etc/service"] | ||
| app_version = "1.0.0" | ||
|
|
||
| build_steps = [ | ||
| "apt-get install -y --no-install-recommends gdb gdbserver", | ||
| "mkdir -p /etc/service/backend", | ||
| "cp /app/backend-run.sh /etc/service/backend/run", | ||
| "chmod +x /etc/service/backend/run", | ||
| "cmake -S /app -B /app/build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON", | ||
|
TamseSaso marked this conversation as resolved.
Outdated
|
||
| "cmake --build /app/build -- -j", | ||
|
TamseSaso marked this conversation as resolved.
Outdated
|
||
| ] | ||
|
|
||
| assign_frontend_port = true | ||
|
|
||
| [base_image] | ||
| api_url = "https://registry-1.docker.io" | ||
| service = "registry.docker.io" | ||
| oauth_url = "https://auth.docker.io/token" | ||
| auth_type = "repository" | ||
| auth_name = "luxonis/oakapp-base" | ||
| image_name = "luxonis/oakapp-base" | ||
| image_tag = "1.2.6-cpp" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #include <depthai/depthai.hpp> | ||
| #include <depthai/remote_connection/RemoteConnection.hpp> | ||
|
|
||
| int main(int argc, char** argv) { | ||
| dai::RemoteConnection remoteConnector; | ||
|
|
||
| dai::Pipeline pipeline; | ||
|
|
||
| // Create a camera and request a 800p output | ||
| auto cameraNode = pipeline.create<dai::node::Camera>()->build(dai::CameraBoardSocket::CAM_A); | ||
| auto* cameraOutputVisualize = cameraNode->requestOutput(std::make_pair(1280, 800), dai::ImgFrame::Type::NV12); | ||
|
|
||
| // Register the output so it's visualized on the remote connection | ||
| remoteConnector.addTopic("stream", *cameraOutputVisualize); | ||
|
|
||
| // Start the pipeline | ||
| pipeline.start(); | ||
| while(pipeline.isRunning()) { | ||
| int key = remoteConnector.waitKey(1); | ||
| if(key == 'q') { | ||
| std::cout << "Got 'q' key from the remote connection!" << std::endl; | ||
| break; | ||
| } | ||
| } | ||
| return 0; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.