From 757ec09602cc527254ca99a22bf5952c1b21b959 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 16 Feb 2024 14:45:08 -0700 Subject: [PATCH] Document LD_LIBRARY_PATH and catching exceptions with GDB when testing (#4175) * Document LD_LIBRARY_PATH and catching exceptions Signed-off-by: Ryan Friedman * Uniform capitization of gdb Signed-off-by: Ryan Friedman * Remove extra line Signed-off-by: Ryan Friedman --------- Signed-off-by: Ryan Friedman (cherry picked from commit d084dd8ecbe2437da6bd556dc31a65a0ac79b82a) --- source/Tutorials/Intermediate/Testing/CLI.rst | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/source/Tutorials/Intermediate/Testing/CLI.rst b/source/Tutorials/Intermediate/Testing/CLI.rst index 3579c52b2f..cdd8374ef8 100644 --- a/source/Tutorials/Intermediate/Testing/CLI.rst +++ b/source/Tutorials/Intermediate/Testing/CLI.rst @@ -35,7 +35,7 @@ To see the exact test cases which fail, use the ``--verbose`` flag: Debugging tests with GDB ^^^^^^^^^^^^^^^^^^^^^^^^ -If a C++ test is failing, gdb can be used directly on the test executable in the build directory. +If a C++ test is failing, GDB can be used directly on the test executable in the build directory. Ensure to build the code in debug mode. Since the previous build type may be cached by CMake, clean the cache and rebuild. @@ -43,9 +43,25 @@ Since the previous build type may be cached by CMake, clean the cache and rebuil colcon build --cmake-clean-cache --mixin debug -Next, run the test directly through gdb. +In order for GDB to load debug symbols for any shared libraries called, make sure to source your environment. +This configures the value of ``LD_LIBRARY_PATH``. + +.. code-block:: console + + source install/setup.bash + +Finally, run the test directly through GDB. For example: .. code-block:: console gdb -ex run ./build/rcl/test/test_logging + +If the code is throwing an unhandled exception, you can catch it in GDB before gtest handles it. + +.. code-block:: console + + gdb ./build/rcl/test/test_logging + catch throw + run +