LvArray
system.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021, Lawrence Livermore National Security, LLC and LvArray contributors.
3  * All rights reserved.
4  * See the LICENSE file for details.
5  * SPDX-License-Identifier: (BSD-3-Clause)
6  */
7 
13 #pragma once
14 
15 // System includes
16 #include <string>
17 #include <typeinfo>
18 #include <functional>
19 #include <dlfcn.h>
20 
21 namespace LvArray
22 {
23 
27 namespace system
28 {
29 
37 std::string stackTrace( bool const lineInfo );
38 
44 std::string demangle( char const * const name );
45 
50 template< class T >
51 inline std::string demangleType()
52 { return demangle( typeid( T ).name() ); }
53 
59 template< class T >
60 inline std::string demangleType( T const & var )
61 { return demangle( typeid( var ).name() ); }
62 
68 void setErrorHandler( std::function< void() > const & handler );
69 
73 void callErrorHandler();
74 
80 void stackTraceHandler( int const sig, bool const exit );
81 
86 void setSignalHandling( void (* handler)( int ) );
87 
91 void resetSignalHandling();
92 
98 
105 
112 
118 void setFPE();
119 
125 {
126 public:
132  m_previousExceptions( disableFloatingPointExceptions( exceptions ) )
133  {}
134 
140 
141 private:
144 };
145 
151 std::string calculateSize( size_t const bytes );
152 
153 } // namespace system
154 } // namespace LvArray
std::string demangleType()
Definition: system.hpp:51
void resetSignalHandling()
Rest the signal handling back to the original state.
Definition: system.cpp:522
std::string stackTrace(bool const location)
Return a demangled stack trace of the last 25 frames.
Definition: system.cpp:361
void setErrorHandler(std::function< void() > const &handler)
Set the error handler called by LVARRAY_ERROR and others.
Definition: system.cpp:445
Changes the floating point environment and reverts it when destoyed.
Definition: system.hpp:124
int getDefaultFloatingPointExceptions()
Get the default set of exceptions to check.
Definition: system.cpp:531
void stackTraceHandler(int const sig, bool const exit)
Print signal information and a stack trace to standard out, optionally aborting.
Definition: system.cpp:468
int enableFloatingPointExceptions(int const exceptions)
A wrapper around feenableexcept that work on OSX.
Definition: system.cpp:557
void setSignalHandling(void(*handler)(int))
Set the signal handler for common signals.
Definition: system.cpp:496
The top level namespace.
Definition: Array.hpp:24
void setFPE()
Sets the floating point environment.
Definition: system.cpp:636
int disableFloatingPointExceptions(int const exceptions)
A wrapper around fedisableexcept that work on OSX.
Definition: system.cpp:603
std::string demangle(char const *const name)
Definition: system.cpp:388
int const m_previousExceptions
The floating point exceptions that were active on construction.
Definition: system.hpp:143
void callErrorHandler()
Call the error handler, by default this is std::abort.
Definition: system.cpp:457
~FloatingPointExceptionGuard()
Re-enable the floating point exceptions that were active on construction.
Definition: system.hpp:138
FloatingPointExceptionGuard(int const exceptions=getDefaultFloatingPointExceptions())
Disable the floating point exceptions given by exceptions.
Definition: system.hpp:131
std::string calculateSize(size_t const bytes)
Definition: system.cpp:406