TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
catch_and_trace.h
1/****************************************************************************
2* Copyright (c) 2026, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16#ifndef catch_and_trace_H
17#define catch_and_trace_H
18
19#ifndef _GNU_SOURCE
20# define _GNU_SOURCE
21#endif
22#ifndef __USE_GNU
23# define __USE_GNU
24#endif
25
26#include <execinfo.h>
27#include <signal.h>
28#include <stdio.h>
29#include <cstring>
30#include <dlfcn.h>
31
32#include <iostream>
33#include <cstdlib>
34
35
36#include <memory>
37
38#include <string>
39#include <array>
40
41#include <Process.h>
42#include <EntreeSortie.h>
43
44// This structure mirrors the one found in /usr/include/asm/ucontext.h
45#ifndef __APPLE__
46typedef struct _sig_ucontext
47{
48 unsigned long uc_flags;
49 struct ucontext *uc_link;
50 stack_t uc_stack;
51 struct sigcontext uc_mcontext;
52 sigset_t uc_sigmask;
53} sig_ucontext_t;
54#endif
55
56/*
57 * Execute a system command and get output.
58 */
59int exec_cmd_and_get_output(const char* cmd, std::string& result);
60
61/*
62 * Custom error handler printing out in the journal the backtrace of the exception.
63 */
64void crit_err_hdlr(int sig_num, siginfo_t * info, void * ucontext);
65
66/*
67 * Install error handlers catching SIGABRT and SIGFPE
68 */
69void install_handlers();
70
71
72#endif /* catch_and_trace_H */
struct sigcontext uc_mcontext
sigset_t uc_sigmask
unsigned long uc_flags
struct ucontext * uc_link