Does anyone know how to effectively debug mediapipe?
So far I'm putting print statements in every second line and keep on compiling + running the code until I find my errors.
Is there any way to debug this using breakpoints and a debugger, say from VS code?
I already saw that vs code features a Bazel extension, however I'm not sure how to configure the extension properly.
This is what I normally run in terminal in the root directory to compile and run
bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 mediapipe/examples/desktop/hand_tracking:hand_tracking_cpu
bazel run --define MEDIAPIPE_DISABLE_GPU=1 mediapipe/examples/desktop/hand_tracking:hand_tracking_cpu --calculator_graph_config_file=mediapipe/graphs/hand_tracking/hand_tracking_desktop_signn.pbtxt
Further info:
There apparantly is already a bazel plugin installed in vs code. This is what the vs code bazel plugin settings look like. While I could find a potential candidate for my executable, I'm not sure about the 'buildifier'. Is this a normal bazel compiler? I'm currently using bazelisk, which is supposed to figure out the required bazel version automatically. Could I just use the bazelisk executable here?
Just a quick answer: Adding this content as into .vscode/launch.json
allows me to debug mediapipe with breakpoints:
{
// 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": [
{
"preLaunchTask": "Bazel Build (Debug)",
"name": "CodeLLDB",
"type": "lldb",
"request": "launch",
"console": "internalConsole",
"program": "${workspaceFolder}/bazel-out/k8-dbg/bin/mediapipe/examples/desktop/hand_tracking/hand_tracking_cpu",
"args": ["--calculator_graph_config_file=mediapipe/graphs/hand_tracking/hand_tracking_desktop_signn.pbtxt"],
"env": {"GLOG_logtostderr":"1"},
"sourceMap": {
"/proc/self/cwd/": "${workspaceFolder}"
},
}
]
}
Notes
-c dbg
as additional argument to compile a binary that is suited for usage with the debugger"env": {"GLOG_logtostderr":"1"}
is a system variable (similar to $PATH in linux), that tells the debugger to write Google logger output to console/bazel-out/k8-dbg/bin/
is the location of the binary file once you compile with bazel using debug flags ( -c dbg )"args"
as you can see by comparing with the original launch command"/proc/self/cwd/": "${workspaceFolder}"
is needed so the debugger breaks in the correct file (by default, the debugger opens different source files than those where you actually put the break pointUpdate
In case you also want the build to be executed by vscode you need to add the following entry to your .vscode/tasks.json
{
"label": "Bazel Build (Debug)",
"type": "shell",
"command": "bazel build -c dbg --define MEDIAPIPE_DISABLE_GPU=1 mediapipe/examples/desktop/hand_tracking:hand_tracking_cpu",
"group": {
"kind": "build",
"isDefault": true
},
}
Note how the label "Bazel Build (Debug)" corresponds to "preLaunchTask" in launch.json