Skip to content

Commit

Permalink
sigsegv trace added for better debug
Browse files Browse the repository at this point in the history
  • Loading branch information
sulincix committed May 27, 2024
1 parent 86d05ad commit 28e62a2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/ccode/signal.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
#include <stddef.h>
#include <signal.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <signal.h>
#include <execinfo.h>
#include <unistd.h>
#include <string.h>

typedef void (*sighandler_t)(int);
sighandler_t sigint_signal;

Expand All @@ -12,6 +20,39 @@ void unblock_sigint(){
signal(SIGINT, sigint_signal);
}

static void sigsegv_handler(int sig) {
void *array[10];
size_t size;
char **strings;
size_t i;

/* Get backtrace */
size = backtrace(array, 10);
strings = backtrace_symbols(array, size);

printf("Caught signal %d\n", sig);
printf("Backtrace:\n");
for (i = 0; i < size; i++) {
printf("%s\n", strings[i]);
}

/* Free the memory allocated by backtrace_symbols */
free(strings);
exit(1);
}
static bool sigsegv_trace_enabled = false;
void enable_sigsegv_trace(){
if(sigsegv_trace_enabled){
return;
}
sigsegv_trace_enabled = true;
struct sigaction sigact;
sigact.sa_handler = sigsegv_handler;
sigemptyset(&sigact.sa_mask);
sigact.sa_flags = 0;
sigaction(SIGSEGV, &sigact, NULL);
}

#ifndef kill
int kill(pid_t pid, int sig);
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/ymp.vala
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ private bool ymp_activated = false;

#ifndef no_locale
private extern void locale_init();
private extern void enable_sigsegv_trace();
public const string GETTEXT_PACKAGE="ymp";
#endif
public void ymp_init (string[] args) {
if(ymp_activated){
return;
}
enable_sigsegv_trace();
#ifndef no_locale
locale_init();
#endif
Expand Down

0 comments on commit 28e62a2

Please sign in to comment.