diff -Nru libexcept-1.1.14.0~focal/debian/changelog libexcept-1.1.15.0~focal/debian/changelog --- libexcept-1.1.14.0~focal/debian/changelog 2022-07-01 03:27:17.000000000 +0000 +++ libexcept-1.1.15.0~focal/debian/changelog 2022-07-14 04:54:40.000000000 +0000 @@ -1,4 +1,11 @@ -libexcept (1.1.14.0~focal) focal; urgency=high +libexcept (1.1.15.0~focal) focal; urgency=high + + * Added the report_signal functions. + * Cleaned up the #include's. + + -- Alexis Wilke Wed, 13 Jul 2022 21:54:40 -0700 + +libexcept (1.1.14.0~bionic) bionic; urgency=high * Added support for any number of parameters. * Updated the tests to include parameters. diff -Nru libexcept-1.1.14.0~focal/libexcept/CMakeLists.txt libexcept-1.1.15.0~focal/libexcept/CMakeLists.txt --- libexcept-1.1.14.0~focal/libexcept/CMakeLists.txt 2022-07-01 03:27:17.000000000 +0000 +++ libexcept-1.1.15.0~focal/libexcept/CMakeLists.txt 2022-07-14 03:49:06.000000000 +0000 @@ -28,6 +28,7 @@ demangle.cpp exception.cpp file_inheritance.cpp + report_signal.cpp stack_trace.cpp version.cpp ) @@ -54,6 +55,7 @@ demangle.h exception.h file_inheritance.h + report_signal.h stack_trace.h ${PROJECT_BINARY_DIR}/version.h diff -Nru libexcept-1.1.14.0~focal/libexcept/demangle.cpp libexcept-1.1.15.0~focal/libexcept/demangle.cpp --- libexcept-1.1.14.0~focal/libexcept/demangle.cpp 2022-06-05 23:06:39.000000000 +0000 +++ libexcept-1.1.15.0~focal/libexcept/demangle.cpp 2022-07-14 03:50:04.000000000 +0000 @@ -17,12 +17,15 @@ // with this program; if not, write to the Free Software Foundation, Inc., // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -#include "./demangle.h" +// self +// +#include "libexcept/demangle.h" + -// C++ includes +// C++ // -#include -#include +#include +#include /** \file diff -Nru libexcept-1.1.14.0~focal/libexcept/exception.cpp libexcept-1.1.15.0~focal/libexcept/exception.cpp --- libexcept-1.1.14.0~focal/libexcept/exception.cpp 2022-06-30 15:32:56.000000000 +0000 +++ libexcept-1.1.15.0~focal/libexcept/exception.cpp 2022-07-14 04:29:06.000000000 +0000 @@ -19,25 +19,26 @@ // self // -#include "./exception.h" +#include "libexcept/exception.h" -#include "./demangle.h" +#include "libexcept/demangle.h" -// C++ includes +// C++ // #include #include #include -// C lib includes +// C // #include #include #include + /** \file * \brief Implementation of the libexcept classes. * diff -Nru libexcept-1.1.14.0~focal/libexcept/file_inheritance.cpp libexcept-1.1.15.0~focal/libexcept/file_inheritance.cpp --- libexcept-1.1.14.0~focal/libexcept/file_inheritance.cpp 2022-06-08 16:27:10.000000000 +0000 +++ libexcept-1.1.15.0~focal/libexcept/file_inheritance.cpp 2022-07-14 04:30:26.000000000 +0000 @@ -19,10 +19,10 @@ // self // -#include "./file_inheritance.h" +#include "libexcept/file_inheritance.h" -// C++ includes +// C++ // #include #include @@ -30,7 +30,7 @@ #include -// C lib includes +// C // #include #include diff -Nru libexcept-1.1.14.0~focal/libexcept/report_signal.cpp libexcept-1.1.15.0~focal/libexcept/report_signal.cpp --- libexcept-1.1.14.0~focal/libexcept/report_signal.cpp 1970-01-01 00:00:00.000000000 +0000 +++ libexcept-1.1.15.0~focal/libexcept/report_signal.cpp 2022-07-14 04:52:32.000000000 +0000 @@ -0,0 +1,141 @@ +// Copyright (c) 2019-2022 Made to Order Software Corp. All Rights Reserved +// +// https://snapwebsites.org/project/libexcept +// contact@m2osw.com +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +// self +// +#include "libexcept/report_signal.h" + +#include "libexcept/stack_trace.h" + + +// C++ +// +#include +#include + + +// C +// +#include + + +/** \file + * \brief Implementation of the init_report_signal() function. + * + * This file includes a function to setup a report handler on all the crashing + * signals such as SEGV. This allows your software to report the stacktrace + * even in a release version. + * + * \note + * If you can link against the eventdispatcher library, you should instead + * consider using that library signal handlers. + */ + + + +namespace libexcept +{ + + + +namespace +{ + +typedef struct sigaction sigaction_t; +typedef std::shared_ptr sigaction_ptr_t; + +sigaction_ptr_t g_signal_actions[64] = {}; + +void report_signal( + int sig + , siginfo_t * info + , void * context) +{ + // unused parameters + static_cast(info); + static_cast(context); + + auto const trace(collect_stack_trace()); + for(auto const & stack_line : trace) + { + std::cerr + << "report_signal():" + << sig + << ": backtrace=" + << stack_line + << "\n"; + } + + // Abort + // + abort(); +} + + +} // no name namespace + + + +/** \brief Setup the callbacks. + * + * This function sets up the callbacks of all the signals representing a + * crash. The callback will print the stack to stderr. + * + * If you are a project over eventdispatcher, you have several options at + * your disposal which are much better than this simplistic function: + * + * \li signal -- a connection that can catch any signal using the signalfd() + * function (i.e. the eventdispatcher can poll on it) + * \li signal_handler -- similar to this function, it capture signals and + * reports them in the logger including a stack trace + * \li signal_child -- an extension of the signal connection which provides + * additional data about the child that died + * + * \warning + * This code is not thread safe. + */ +void init_report_signal() +{ + constexpr std::int64_t sigs( + (1 << SIGHUP) + | (1 << SIGILL) + | (1 << SIGTRAP) + | (1 << SIGBUS) + | (1 << SIGFPE) + | (1 << SIGSEGV) + ); + for(size_t i(0); i < std::size(g_signal_actions); ++i) + { + if((sigs & (1L << i)) != 0) + { + sigaction_t action = sigaction_t(); + action.sa_sigaction = report_signal; + action.sa_flags = SA_SIGINFO | SA_RESETHAND; + + g_signal_actions[i] = std::make_shared(); + sigaction(i, &action, g_signal_actions[i].get()); + } + } +} + + + +} +// namespace libexcept +// vim: ts=4 sw=4 et Binary files /tmp/tmpgs1rolz8/ZrqdPUzPE8/libexcept-1.1.14.0~focal/libexcept/.report_signal.cpp.swp and /tmp/tmpgs1rolz8/Q7H3bUe6kA/libexcept-1.1.15.0~focal/libexcept/.report_signal.cpp.swp differ diff -Nru libexcept-1.1.14.0~focal/libexcept/report_signal.h libexcept-1.1.15.0~focal/libexcept/report_signal.h --- libexcept-1.1.14.0~focal/libexcept/report_signal.h 1970-01-01 00:00:00.000000000 +0000 +++ libexcept-1.1.15.0~focal/libexcept/report_signal.h 2022-07-14 04:37:43.000000000 +0000 @@ -0,0 +1,46 @@ +// Copyright (c) 2019-2022 Made to Order Software Corp. All Rights Reserved +// +// https://snapwebsites.org/ +// contact@m2osw.com +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +#pragma once + +/** \file + * \brief Report crashing signals if they are emitted. + * + * By default a crashing signal kills your application quietly, making it + * very difficult to know what happened. + * + * The report signal implementation sets up signal handlers to capture those + * signals and report the stack trace which will include the point where the + * crash occurred. + */ + +namespace libexcept +{ + + +void init_report_signal(); + + +} +// namespace libexcept +// vim: ts=4 sw=4 et diff -Nru libexcept-1.1.14.0~focal/libexcept/stack_trace.cpp libexcept-1.1.15.0~focal/libexcept/stack_trace.cpp --- libexcept-1.1.14.0~focal/libexcept/stack_trace.cpp 2022-06-05 23:06:39.000000000 +0000 +++ libexcept-1.1.15.0~focal/libexcept/stack_trace.cpp 2022-07-14 04:30:59.000000000 +0000 @@ -19,19 +19,19 @@ // self // -#include "./exception.h" +#include "libexcept/exception.h" -#include "./demangle.h" +#include "libexcept/demangle.h" -// C++ includes +// C++ // #include #include #include -// C lib includes +// C // #include #include diff -Nru libexcept-1.1.14.0~focal/libexcept/version.cpp libexcept-1.1.15.0~focal/libexcept/version.cpp --- libexcept-1.1.14.0~focal/libexcept/version.cpp 2022-06-05 23:06:39.000000000 +0000 +++ libexcept-1.1.15.0~focal/libexcept/version.cpp 2022-07-14 04:31:43.000000000 +0000 @@ -3,26 +3,24 @@ // https://snapwebsites.org/ // contact@m2osw.com // -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. // -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -#include "libexcept/version.h" + +// self +// +#include "libexcept/version.h" namespace libexcept