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.
Motivation
This PR allows triggering a debugger on the C++ land from the target language (C/Python/Java/...). This can be very helpful during development and debugging of the core C/C++ codebase. For instance, it's possible to debug Java and C++ at the same time.
Changes
Two macros are provided:
GDB()
GDB_ON_TRIGGER()
The first triggers gdb/ddd. The second is the same but only triggers in case the method
trigger_gdb()
inutils/gdb.h
was called before.These macros only generate code when LGBM is compiled with
-DUSE_DEBUG=ON
, otherwise they add up no overhead.Every method in the C API now starts with a
GDB_ON_TRIGGER()
, meaning all methods in the C API can be debugged promptly.The debugger will kick in and the program will wait until
signal_gdb_attached()
is called by the user.This will then unlock and resume the program execution.
In case the debugger fails to kick in, it's easy to attach with
gdb --pid=<target_pid>
, and the program will periodically print the target pid untilsignal_gdb_attached()
is called.