KiCad PCB EDA Suite
Loading...
Searching...
No Matches
error_handlers.cpp
Go to the documentation of this file.
1
/*
2
* This program source code file is part of KiCad, a free EDA CAD application.
3
*
4
* Copyright The KiCad Developers, see AUTHORS.TXT for contributors.
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18
*/
19
20
#include <csignal>
21
#include <string>
22
#include <iostream>
23
#include <
qa_utils/error_handlers.h
>
24
#if defined(__APPLE__) || defined(__FreeBSD__)
25
#define BOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED
26
#endif
27
#ifdef __linux__
28
#define BOOST_STACKTRACE_USE_ADDR2LINE
29
#endif
30
#include <boost/stacktrace.hpp>
31
#include <boost/test/unit_test_monitor.hpp>
32
33
34
static
std::string
get_signal_string
(
int
signum )
35
{
36
#ifdef _WIN32
37
switch
( signum )
38
{
39
case
SIGABRT:
return
"SIGABRT (Abnormal termination)"
;
40
case
SIGFPE:
return
"SIGFPE (Floating-point exception)"
;
41
case
SIGILL:
return
"SIGILL (Illegal instruction)"
;
42
case
SIGINT:
return
"SIGINT (Interrupt)"
;
43
case
SIGSEGV:
return
"SIGSEGV (Segmentation fault)"
;
44
case
SIGTERM:
return
"SIGTERM (Termination request)"
;
45
default
:
return
"Unknown signal"
;
46
}
47
#else
48
return
strsignal( signum );
49
#endif
50
}
51
52
53
static
void
signal_handler
(
int
signum )
54
{
55
// Associate the signal number with a name
56
::signal( signum, SIG_DFL );
// Re-register the default handler
57
58
std::cerr << std::endl <<
"Signal caught: "
<<
get_signal_string
( signum ) <<
" ("
<< signum <<
")"
<< std::endl;
59
std::cerr <<
"Stack trace:"
<< std::endl;
60
61
// Print the stack trace to standard error
62
std::cerr << boost::stacktrace::stacktrace() << std::endl;
63
64
// Let the default handler terminate the program
65
::raise( signum );
66
}
67
68
69
KI_SIGNAL_HANDLER_FIXTURE::KI_SIGNAL_HANDLER_FIXTURE
()
70
{
71
::signal( SIGSEGV, &
signal_handler
);
72
::signal( SIGABRT, &
signal_handler
);
73
::signal( SIGFPE, &
signal_handler
);
74
};
75
76
77
static
void
translate_std_exception
(
const
std::exception& e )
78
{
79
std::cerr << std::endl <<
"Caught exception: "
<< e.what() << std::endl << std::endl;
80
81
// Print the stack trace
82
std::cerr <<
"Stack trace:"
<< std::endl;
83
std::cerr << boost::stacktrace::stacktrace() << std::endl << std::endl;
84
85
// Re-throw the exception to let Boost.Test handle it and fail the test
86
throw
;
87
}
88
89
90
KI_STACK_TRACE_FIXTURE::KI_STACK_TRACE_FIXTURE
()
91
{
92
boost::unit_test::unit_test_monitor.register_exception_translator<std::exception>( &
translate_std_exception
);
93
}
get_signal_string
static std::string get_signal_string(int signum)
Definition
error_handlers.cpp:34
signal_handler
static void signal_handler(int signum)
Definition
error_handlers.cpp:53
translate_std_exception
static void translate_std_exception(const std::exception &e)
Definition
error_handlers.cpp:77
error_handlers.h
KI_SIGNAL_HANDLER_FIXTURE::KI_SIGNAL_HANDLER_FIXTURE
KI_SIGNAL_HANDLER_FIXTURE()
Definition
error_handlers.cpp:69
KI_STACK_TRACE_FIXTURE::KI_STACK_TRACE_FIXTURE
KI_STACK_TRACE_FIXTURE()
Definition
error_handlers.cpp:90
src
qa
qa_utils
error_handlers.cpp
Generated on Fri Jun 26 2026 00:05:42 for KiCad PCB EDA Suite by
1.13.2