68.5 Logging a Backtrace for Failures
In some scenarios, it might be desirable to log the backtrace from the code. A backtrace is a list of the function calls that are currently active in a thread. You can usually inspect a backtrace by using debugging utilities like gdb, but sometimes these are not available.
For macOS, Windows, and Linux systems, Connext logs a backtrace when a precondition fails in debug mode and, if dds.participant.enable_backtrace_upon_sigsegv is set to true or auto, when a segmentation fault occurs. Setting dds.participant.enable_backtrace_upon_sigsegv to true enables backtrace logging when there is a segmentation fault in debug and release libraries; setting it to auto (the default) only enables backtrace logging for segmentation faults in debug libraries. See Chapter 84 Connext Usage of Signal Handlers.
The backtrace feature is automatically enabled upon creation of the first DomainParticipant. (That is, you will not see the backtrace log in a failure until the first DomainParticipant is created.)
- Normally when a precondition fails, the execution continues and there is no information about the problem, but Connext provides a backtrace with context about where the issue was.
- When a segmentation fault occurs, the processor or operating system does not always provide a core dump, but Connext provides a backtrace with context about where the issue was.
For Linux systems, the output of the backtrace will look like this:
#1 RTIOsapiProcessTester_testPrintBacktrace /connextdds/osapi.1.0/srcC/process/test/processTester.c:638 [0x417371]
#2 RTITestSetting_runTestsExt /connextdds/test.1.0/srcC/setting/Setting.c:719 [0x4623B8]
#3 RTITestSetting_runTests /connextdds/test.1.0/srcC/setting/Setting.c:905 [0x462B85]
#4 RTIOsapiProcessTester_run /connextdds/osapi.1.0/srcC/process/test/processTester.c:683 [0x41750C]
#5 RTITestSetting_runTestsExt /connextdds/test.1.0/srcC/setting/Setting.c:719 [0x4623B8]
#6 RTITestSetting_runTests /connextdds/test.1.0/srcC/setting/Setting.c:905 [0x462B85]
#7 RTIOsapiTester_run /connextdds/osapi.1.0/srcC/test/Tester.c:128 [0x4039CB]
#8 main /connextdds/osapi.1.0/srcC/test/Tester.c:213 [0x403A65] #9 ?? ??:0 [0xE8434830] #10 _start ??:? [0x403759]
See the RTI Connext Core Libraries Platform Notes for further details on enabling this feature on macOS, Windows, and Linux systems.
The backtrace feature is smart enough to log the backtrace only once for a given error and not for the following errors in the same code path of the caller's functions. For example, in the failure of the creation of the DDSDomainParticipant, Connext logs the backtrace for just one error instead of logging it for all of the error messages in the same code path:
U00007f86a87df700 Mx08:Udpv4SocketFactory.c:685:RTI0x2080010:invalid port 5562900
Backtrace:
#3 NDDS_Transport_UDPv4_Socket_bind_with_ip ??:? [0xCB235C]
#4 NDDS_Transport_UDPv4_SocketFactory_create_receive_socket ??:? [0xCB2619]
#5 NDDS_Transport_UDP_create_recvresource_rrEA Udp.c:? [0xCAB170]
#6 RTINetioReceiver_addEntryport ??:? [0xCA33F3]
#7 COMMENDActiveFacade_addEntryport ActiveFacade.c:? [0xC12B56]
#8 DDS_DomainParticipantPresentation_reserve_entryportI DomainParticipantPresentation.c:? [0x7E4F11]
#9 DDS_DomainParticipantPresentation_reserve_participant_index_entryports ??:? [0x7E8015]
#10 DDS_DomainParticipant_reserve_participant_index_entryports DomainParticipant.c:? [0x7B0B7E]
#11 DDS_DomainParticipant_enableI DomainParticipant.c:? [0x7CC15E]
#12 DDS_Entity_enable ??:? [0x72EC92]
#13 DDS_DomainParticipantFactory_create_participant ??:? [0x7DACF1]
#14 main ??:? [0x40675F]
#15 ?? ??:0 [0xA76F4830]
#16 _start ??:? [0x405EC9]
U00007f86a87df700 Mx0F:DomainParticipant.c:13313:RTI0x20f0c02:Automatic participant index failed to initialize. PLEASE VERIFY CONSISTENT TRANSPORT / DISCOVERY CONFIGURATION.
U00007f86a87df700 Mx0F:DomainParticipantFactory.c:1314:RTI0x20f000e:ERROR: Failed to auto-enable entity
U00007f86a87df700 Mx01:DomainParticipantTester.c:9325:RTI0x2000007:![DomainParticipantTester.c:9325] pointer is null: participant
By default, the print_format NDDS_CONFIG_LOG_PRINT_FORMAT_DEBUG is set for the log level NDDS_CONFIG_LOG_LEVEL_FATAL_ERROR. This means that by default the backtrace is logged for precondition and segmentation faults; however, you can disable the backtrace for NDDS_CONFIG_LOG_LEVEL_FATAL_ERROR. In the following code, the log level NDDS_CONFIG_LOG_LEVEL_FATAL_ERROR uses the print_format NDDS_CONFIG_LOG_PRINT_FORMAT_DEFAULT, which does not contain the backtrace information:
NDDS_Config_Logger *logger = NDDS_Config_Logger_get_instance();
NDDS_Config_Logger_set_print_format_by_log_level(
logger,
NDDS_CONFIG_LOG_PRINT_FORMAT_DEFAULT,
NDDS_CONFIG_LOG_LEVEL_FATAL_ERROR));
See 68.2.3 Format of Logged Messages and 68.2 Configuring Connext Logging.