-
Notifications
You must be signed in to change notification settings - Fork 305
Expand file tree
/
Copy pathlibmesh_common.C
More file actions
134 lines (107 loc) · 3.99 KB
/
Copy pathlibmesh_common.C
File metadata and controls
134 lines (107 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// The libMesh Finite Element Library.
// Copyright (C) 2002-2026 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// This library 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
// Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// libmesh includes
#include "libmesh/libmesh.h"
#include "libmesh/libmesh_common.h"
#include "libmesh/print_trace.h"
#include "libmesh/threads.h"
// C/C++ includes
#ifdef LIBMESH_HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef LIBMESH_HAVE_UNISTD_H
#include <unistd.h> // needed for getpid()
#endif
#ifdef LIBMESH_HAVE_CSIGNAL
#include <csignal>
#endif
#if defined(LIBMESH_HAVE_GCC_ABI_DEMANGLE)
#include <cxxabi.h>
#include <cstdlib>
#endif
namespace libMesh
{
namespace MacroFunctions
{
void here(const char * file, int line, const char * date, const char * time, std::ostream & os)
{
os << "[" << static_cast<std::size_t>(libMesh::global_processor_id()) << "] "
<< file
<< ", line " << line
<< ", compiled " << date
<< " at " << time
<< std::endl;
}
void stop(const char * file, int line, const char * date, const char * time)
{
if (libMesh::global_n_processors() == 1)
{
libMesh::MacroFunctions::here(file, line, date, time);
#if defined(LIBMESH_HAVE_CSIGNAL) && defined(SIGSTOP)
libMesh::out << "Stopping process " << getpid() << "..." << std::endl;
std::raise(SIGSTOP);
libMesh::out << "Continuing process " << getpid() << "..." << std::endl;
#else
libMesh::out << "WARNING: libmesh_stop() does not work; no operating system support." << std::endl;
#endif
}
}
Threads::spin_mutex report_error_spin_mtx;
void report_error(const char * file, int line, const char * date, const char * time, std::ostream & os)
{
// Avoid a race condition on that static bool
Threads::spin_mutex::scoped_lock lock(report_error_spin_mtx);
// It is possible to have an error *inside* report_error; e.g. from
// print_trace. We don't want to infinitely recurse.
static bool reporting_error = false;
if (reporting_error)
{
// I heard you like error reporting, so we put an error report
// in report_error() so you can report errors from the report.
os << "libMesh encountered an error while attempting to report_error." << std::endl;
return;
}
reporting_error = true;
libMesh::MacroFunctions::here(file, line, date, time, os);
if (libMesh::global_n_processors() == 1 ||
libMesh::on_command_line("--print-trace"))
libMesh::print_trace(os);
else
libMesh::write_traceout();
reporting_error = false;
}
} // namespace MacroFunctions
// demangle() is used by the process_trace() helper function. It is
// also used by the Parameters class and cast_xxx functions for demangling typeid's. If
// configure determined that your compiler does not support
// demangling, it simply returns the input string.
#if defined(LIBMESH_HAVE_GCC_ABI_DEMANGLE)
std::string demangle(const char * name)
{
int status = 0;
std::string ret = name;
// Actually do the demangling
char * demangled_name = abi::__cxa_demangle(name, 0, 0, &status);
// If demangling returns non-nullptr, save the result in a string.
if (demangled_name)
ret = demangled_name;
// According to cxxabi.h docs, the caller is responsible for
// deallocating memory.
std::free(demangled_name);
return ret;
}
#else
std::string demangle(const char * name) { return std::string(name); }
#endif
} // namespace libMesh