This guide provides an introduction on how to debug the barton reference app, unit tests, and any integration tests in the BartonCore project. This guide will show what you can do in VSCode as well as via command-line. It assumes you are working in the docker environment provided; any other environment is not supported for development.
The Barton Reference App provides a CLI for interactively interfacing with Barton Device Service.
One can debug the Barton Reference App with the (gdb) Reference App debug configuration. A terminal will automatically open ready to accept input from the user.
Refer to the (gdb) Reference App debug configuration in launch.json to determine what command to run in your terminal.
Barton unit tests are all known to CMake.
There are two ways to run CMake test targets.
The first way is to:
- Navigate to the CMake panel.
- Ensure configuration is done in IDE (as opposed to via CLI) by pressing
Delete Cache and Reconfigue. This is only necessary if there is a cache divergence from running CMake in a terminal (unlikely). - Select either the test target or
allin theBuildsection. - Select the desired test in the
Debugsection. - Press the debug button in the bottom ribbon (this will build your
Buildtarget first if necessary).
The second way is to:
- Complete steps 1-3 of the previous method.
- Navigate to the
Testingpanel. - Under
BartonCore, hover over the test you want to debug and press the Debug button.
Our Python integration tests have some divergence in debuggability.
As a prerequisite, ensure you have run the CMake install task. In VSCode, this can be done in the Command Pallette. This will install the barton shared library, generated gir/typelib files, and generated python stubs (.pyi file) for development code-completion.
If Barton is compiled with Address Sanitizer enabled, libasan.so must be preloaded before any pytest invocations. This can either be done manually with:
# if using gcc
LD_PRELOAD=$(gcc -print-file-name=libasan.so) pytest #pytest args
# if using clang
LD_PRELOAD=$(clang -print-file-name=libasan.so) pytest #pytest argsOr you can execute the testing/py_test.sh script to handle setting up the environment for you. Simply pass
the desired pytest args to the py_test.sh script and they will be forwarded to pytest.
If this is a fresh devcontainer and the first time you have tried running the python tests,
you may not see the tests show up in the Testing panel (beaker icon) automatically. If you do not,
execute the Python: Configure Tests command in the Command Pallette. VSC will handle test discovery
from there and you should see a suite of Python Tests within the Testing panel.
Once the tests have been discovered, you can execute tests by either:
- From within the Testing panel by clicking the
Run Test,Debug TestorRun Test with Coveragebuttons next to the desired test - From the test file itself by clicking the icon in the gutter next to the test name.
View the VSC docs on running python tests in VSC for more information.
It is recommended to use the above steps for debugging pytests. However, if you are working on a pure Python file that does not use pytest and want to debug its interactions with Barton, you can use pdb for this. In VSCode, this can be accomplished via:
- Navigating to the python test/file in question.
- Locating the Play button in the top right actions ribbon.
- Click the carrot button and select
Python Debugger: Debug using launch.json - Select
Python Debugger: Current Filedebug configuration.
Again, this will not allow you do place breakpoints or step through Barton api/core code; only the python code.
To debug Barton api/core code in a python program:
- From a terminal, run
gdb python3 - Answer yes to any prompts about downloading debug information.
- Set any breakpoints in C code. This includes Barton api/core, or any libraries it depends on. These will not be loaded yet so gdb will not autocomplete these. You can, instead, run the program (step 4), set breakpoints with auto-complete after running the program, then re-run the program to hit those breakpoints.
- Run your program via one of the following: NOTE - certain custom PATHs must be defined for these to function.
These are handled automatically in the docker container, but if you need to set them yourself, see
docker/setupDockerEnv.shfor more information on these PATHs and how to set them.- For debugging pure python:
run <path-to-python-file> - For debugging a pytest
run -m pytest <path-to-python-file>. NOTE: If Barton has been compiled with Address Sanitizer, you must set the LD_PRELOAD variable first withset env LD_PRELOAD=<path-to-libasan.so>.
- For debugging pure python:
For debugging the Matter stack, Barton can log every inbound and outbound Matter message as a JSON record (hex payload plus fully-decoded TLV) through the normal ChipLog output. This is a developer-only feature: it is off by default, very high volume, and will noticeably slow the stack. Do not enable it in production.
Enabling it is a single build option:
./build.sh -DBCORE_MATTER_MESSAGE_TRACING=ON
When this option is ON, CMake automatically builds the Matter library with tracing support
(passing -t to build-matter.sh) and compiles the trace backend into the core. If a Matter build
already exists under build/matter (built without tracing), delete it first so it is rebuilt:
rm -rf build/matter build/matter-install
./build.sh -DBCORE_MATTER_MESSAGE_TRACING=ON
When enabled, Barton logs a warning at startup and the per-message JSON trace records appear inline
with the rest of the logs. Turn the feature off again with ./build.sh -d -DBCORE_MATTER_MESSAGE_TRACING=OFF
(and delete build/matter to drop tracing support from the library).