Skip to content
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

How to disable C4_DEBUG_BREAK #326

Closed
captain-yoshi opened this issue Nov 16, 2022 · 10 comments
Closed

How to disable C4_DEBUG_BREAK #326

captain-yoshi opened this issue Nov 16, 2022 · 10 comments

Comments

@captain-yoshi
Copy link
Contributor

captain-yoshi commented Nov 16, 2022

I have a cmake project which includes the rapidyaml library. When building my library in Debug mode, ryml also switches to Debug and thus triggers C4_DEBUG_BREAK in the code, especially in the _RYML_CB_ERR. I have a custom try catch mechanism, which will trigger and then resume. This makes it hard when debugging my library because it triggers a lot of false positive signal traps.

Is there a way to not switch rapidyaml to a Debug build when building my library in Debug? Or a way to disable C4_DEBUG_BREAK.

@biojppm
Copy link
Owner

biojppm commented Nov 16, 2022

It can be disabled both runtime and compile-time.

For runtime, here's the relevant line:

#   define C4_ERROR(msg, ...)                               \
    do {                                                    \
        if(c4::get_error_flags() & c4::ON_ERROR_DEBUGBREAK) \
        {                                                   \
            C4_DEBUG_BREAK()                                \
        }                                                   \
        c4::handle_error(C4_SRCLOC(), msg, ## __VA_ARGS__); \
    } while(0)

So all you need to do is to use this somewhere in your code:

ryml::set_error_flags(ryml::get_error_flags() & ~ryml::ON_ERROR_DEBUGBREAK);

For compile time, use the NDEBUG macro. Here's the relevant line:

#ifdef NDEBUG
#   define C4_DEBUG_BREAK()
#else
//... enable C4_DEBUG_BREAK
#endif

I recognize the NDEBUG way may be a bit heavy-handed. Maybe adding an auxiliary C4_NO_DEBUG_BREAK macro would be a better approach than the current one:

#if defined(NDEBUG) || defined(C4_NO_DEBUG_BREAK)
#   define C4_DEBUG_BREAK()
#else
//... enable C4_DEBUG_BREAK
#endif

@biojppm
Copy link
Owner

biojppm commented Nov 16, 2022

Actually, I just noticed the C4_DEBUG_BREAK() call in _RYML_CB_ERR() is not honoring the error flags. Sorry for that.

I will work on a PR to address both this problem and to add the C4_NO_DEBUG_BREAK disabler.

@captain-yoshi
Copy link
Contributor Author

captain-yoshi commented Nov 18, 2022

@biojppm Tried to set C4CORE_NO_DEBUG_BREAK at compile time in my project with 59ea113 like so :

cmake_minimum_required(VERSION 3.1.3)
project(moveit_serialization)

...
# also tried with option
# option(C4_NO_DEBUG_BREAK "disable use of debug break even in debug builds" ON)
SET(C4_NO_DEBUG_BREAK ON CACHE BOOL "disable use of debug break even in debug builds")
add_subdirectory(ext/ryml ryml)

Followed this option from stackoverflow.

When building in Debug mode, GDB still receives a trap signal :

Thread 1 "plot_dataset" received signal SIGTRAP, Trace/breakpoint trap.
trap_instruction () at /home/captain-yoshi/ws/ros/mimic_ws/src/moveit_serialization/ext/ryml/ext/c4core/src/c4/ext/debugbreak/debugbreak.h:48
48	}
(gdb) bt
#0  trap_instruction () at /home/captain-yoshi/ws/ros/mimic_ws/src/moveit_serialization/ext/ryml/ext/c4core/src/c4/ext/debugbreak/debugbreak.h:48
#1  0x00007ffff7dd7a84 in debug_break () at /home/captain-yoshi/ws/ros/mimic_ws/src/moveit_serialization/ext/ryml/ext/c4core/src/c4/ext/debugbreak/debugbreak.h:143
#2  c4::yml::detail::RoNodeMethods<c4::yml::ConstNodeRef, c4::yml::ConstNodeRef>::operator>><bool> (this=0x7fffffffb000, v=@0x7fffffffaf18: false)
    at /home/captain-yoshi/ws/ros/mimic_ws/src/moveit_serialization/ext/ryml/src/c4/yml/node.hpp:366
#3  0x00007ffff79d5aed in computePredicate(c4::yml::ConstNodeRef const&, c4::yml::ConstNodeRef const&, moveit_benchmark_suite::Predicate) ()
   from /home/captain-yoshi/ws/ros/mimic_ws/devel/lib/libmoveit_benchmark_suite_core.so
#4  0x00007ffff79d790d in moveit_benchmark_suite::DatasetFilter::filterMetadata(c4::yml::ConstNodeRef const&, moveit_benchmark_suite::Token const&, moveit_benchmark_suite::Predicate) ()
   from /home/captain-yoshi/ws/ros/mimic_ws/devel/lib/libmoveit_benchmark_suite_core.so
#5  0x00007ffff79d88ba in moveit_benchmark_suite::DatasetFilter::filter[abi:cxx11](unsigned long, c4::yml::Tree&, std::vector<moveit_benchmark_suite::Filter, std::allocator<moveit_benchmark_suite::Filter> > const&) () from /home/captain-yoshi/ws/ros/mimic_ws/devel/lib/libmoveit_benchmark_suite_core.so
#6  0x00007ffff7e25ff0 in moveit_benchmark_suite::tools::GNUPlotDataset::plot (this=0x7fffffffb9a0, layout=..., id=0)
    at /home/captain-yoshi/ws/ros/mimic_ws/src/moveit_benchmark_suite/tools/src/gnuplot.cpp:870
#7  0x00007ffff7e25e06 in moveit_benchmark_suite::tools::GNUPlotDataset::plot (this=0x7fffffffb9a0, dataset_files=std::vector of length 1, capacity 1 = {...})
    at /home/captain-yoshi/ws/ros/mimic_ws/src/moveit_benchmark_suite/tools/src/gnuplot.cpp:843
#8  0x0000555555567d51 in main (argc=1, argv=0x7fffffffbba8) at /home/captain-yoshi/ws/ros/mimic_ws/src/moveit_benchmark_suite/tools/src/plot_dataset.cpp:35

Not sure if it's me or something missing in the callback error trigger.

@biojppm
Copy link
Owner

biojppm commented Nov 18, 2022

The define is C4_NO_DEBUG_BREAK but the cmake option is C4CORE_NO_DEBUG_BREAK.

@captain-yoshi
Copy link
Contributor Author

captain-yoshi commented Nov 18, 2022

That's what I initially tested, but gives the same backtrace.

I think there may be missing a branch point here depending on the macro ?

@biojppm
Copy link
Owner

biojppm commented Nov 18, 2022

At the moment it's hard for me to investigate. Can you look into what's happening with the defines? Adding a judicious #error here or there will immediately reveal the source of the problem.

But make sure to use the current master tip. I think when the issue was closed something was still missing.

@captain-yoshi
Copy link
Contributor Author

It's working now.

We use Catkin a meta-buildsystem to build cmake projects. There is a problem with the override, but the fault is not on ryml side.

@captain-yoshi
Copy link
Contributor Author

Working when changing directly from the c4core CMakeLists. Not working from my project.

I will investigate why it does not propagate from my top level project.

@captain-yoshi
Copy link
Contributor Author

Disabling at runtime works perfectly! Disabling at compile time seems to not work, but my project may be to blame. Il leave this as is.

@biojppm
Copy link
Owner

biojppm commented Nov 29, 2022

How are you setting up your project to use the compile-time macro?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants