LCOV - code coverage report
Current view: top level - src - assert.c (source / functions) Hit Total Coverage
Test: passgen-test.info Lines: 0 9 0.0 %
Date: 2024-11-15 06:04:45 Functions: 0 1 0.0 %

          Line data    Source code
       1             : #include "passgen/assert.h"
       2             : 
       3             : #include <stdlib.h>
       4             : 
       5             : #ifdef PASSGEN_DEBUG
       6             : 
       7             : #ifdef PASSGEN_BACKTRACE
       8             : #include <execinfo.h>
       9             : #endif
      10             : 
      11             : #include <stdio.h>
      12             : 
      13             : #define CALLSTACK_MAX 128
      14             : 
      15           0 : void passgen_assert_fail(
      16             :     const char *cond,
      17             :     const char *file,
      18             :     const char *func,
      19             :     size_t line) {
      20             :     // print warning
      21           0 :     fprintf(
      22             :         stderr,
      23             :         "Assertion failed in file %s at %s:%zu\n  \033[31m%s\033[0m\n",
      24             :         file,
      25             :         func,
      26             :         line,
      27             :         cond);
      28             : 
      29             : #ifdef PASSGEN_BACKTRACE
      30             :     // print backtrace
      31           0 :     fprintf(stderr, "\nBacktrace:\n");
      32             : 
      33             :     void *callstack[CALLSTACK_MAX];
      34           0 :     int frames = backtrace(callstack, sizeof(callstack));
      35           0 :     char **strs = backtrace_symbols(callstack, frames);
      36             : 
      37           0 :     for(int i = 0; i < frames; ++i) {
      38           0 :         printf("%s\n", strs[i]);
      39             :     }
      40             : 
      41           0 :     free(strs);
      42             : #endif
      43             : 
      44           0 :     exit(EXIT_FAILURE);
      45             : }
      46             : #endif

Generated by: LCOV version 1.14