Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_signals.c File Reference

Signals general handling with stack printing. More...

#include <signal.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
#include "nilorea/n_log.h"
#include "nilorea/n_signals.h"
#include "nilorea/n_str.h"
#include <err.h>
#include <execinfo.h>
Include dependency graph for n_signals.c:

Go to the source code of this file.

Macros

#define LOGFPRT(...)
 internal: output to stderr
#define LOGNLOG(...)
 internal: output to syslog
#define LOGSIG   LOGNLOG
 internal: output to syslog

Functions

int addr2line (char const *const program_name, void const *const addr)
 Resolve symbol name and source location given the path to the executable and an address.
void posix_print_stack_trace ()
 print current stack
void posix_signal_handler (int sig, siginfo_t *siginfo, void *context)
 decode a signal and call stack print
void set_signal_handler (const char *progname)
 Install a signal handler for progname.

Variables

static const char * __n_stack_traced_progam_name
 name of program to debug (addr2line & co)
static void * stack_traces [32]
 static frame list

Detailed Description

Signals general handling with stack printing.

Author
Castagnier Mickael, adapted from https://gist.github.com/jvranish/4441299
Version
1.0
Date
08/11/2018

Definition in file n_signals.c.

Macro Definition Documentation

◆ LOGFPRT

#define LOGFPRT ( ...)
Value:
fprintf(stderr, "Error: " __VA_ARGS__)

internal: output to stderr

Definition at line 42 of file n_signals.c.

◆ LOGNLOG

#define LOGNLOG ( ...)
Value:
n_log(LOG_ERR, __VA_ARGS__)
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
Definition n_log.h:113
#define LOG_ERR
error conditions
Definition n_log.h:100

internal: output to syslog

Definition at line 45 of file n_signals.c.

◆ LOGSIG

#define LOGSIG   LOGNLOG

internal: output to syslog

Definition at line 48 of file n_signals.c.

Referenced by addr2line(), posix_print_stack_trace(), and posix_signal_handler().

Function Documentation

◆ addr2line()

int addr2line ( char const *const program_name,
void const *const addr )

Resolve symbol name and source location given the path to the executable and an address.

Parameters
program_nametarget filename
addraddress to peek
Returns
addr2line command return code

Definition at line 104 of file n_signals.c.

References addr, N_STR::data, free_nstr, LOGSIG, and n_popen().

Referenced by posix_print_stack_trace().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ posix_print_stack_trace()

void posix_print_stack_trace ( )

print current stack

Definition at line 273 of file n_signals.c.

References __n_stack_traced_progam_name, addr2line(), LOGSIG, MAX_STACK_FRAMES, and stack_traces.

Referenced by posix_signal_handler().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ posix_signal_handler()

void posix_signal_handler ( int sig,
siginfo_t * siginfo,
void * context )

decode a signal and call stack print

Parameters
sigsignal to decode
siginfodetails of the signal
contextthe context to unroll

Definition at line 304 of file n_signals.c.

References LOGSIG, and posix_print_stack_trace().

Referenced by set_signal_handler().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ __n_stack_traced_progam_name

const char* __n_stack_traced_progam_name
static

name of program to debug (addr2line & co)

Definition at line 51 of file n_signals.c.

Referenced by posix_print_stack_trace(), and set_signal_handler().

◆ stack_traces

void* stack_traces[32]
static

static frame list

Definition at line 268 of file n_signals.c.

Referenced by posix_print_stack_trace().