55 #include <sys/types.h> 57 #if defined(LIBMESH_HAVE_GLIBC_BACKTRACE) 61 #if defined(LIBMESH_HAVE_GCC_ABI_DEMANGLE) 73 #if defined(LIBMESH_HAVE_GLIBC_BACKTRACE) 74 std::string process_trace(
const char *
name)
76 std::string fullname =
name;
77 std::string saved_begin, saved_end;
78 size_t namestart, nameend;
86 namestart = fullname.find(
"0x");
87 if (namestart != std::string::npos)
89 namestart = fullname.find(
' ', namestart) + 1;
90 saved_begin = fullname.substr(0, namestart);
94 nameend = fullname.find(
'+');
95 if (nameend == std::string::npos ||
97 nameend = fullname.size();
101 saved_end = fullname.substr(nameend, fullname.length());
104 namestart = fullname.find(
'(');
105 if (namestart == std::string::npos)
109 nameend = fullname.find(
'+');
110 if (nameend == std::string::npos ||
111 nameend <= namestart)
115 std::string type_name = fullname.substr(namestart, nameend - namestart);
128 bool gdb_backtrace(std::ostream & out_stream)
130 #ifdef LIBMESH_GDB_COMMAND 137 char temp_file[] =
"temp_print_trace.XXXXXX";
138 int fd = mkstemp(temp_file);
147 pid_t this_pid = getpid();
153 std::string gdb_command =
156 std::ostringstream command;
157 command << gdb_command
160 <<
" -batch -ex bt -ex detach 2>/dev/null 1>" 162 exit_status = std::system(command.str().c_str());
166 std::cerr <<
"Unable to run gdb" << std::endl;
174 std::ifstream fin(temp_file);
175 if (fin && (fin.peek() != std::ifstream::traits_type::eof()) && (exit_status == 0))
176 out_stream << fin.rdbuf();
182 std::remove(temp_file);
203 bool gdb_worked =
false;
207 if (std::string(LIBMESH_GDB_COMMAND) != std::string(
"no") &&
209 gdb_worked = gdb_backtrace(out_stream);
214 #if defined(LIBMESH_HAVE_GLIBC_BACKTRACE) 217 void * addresses[40];
220 int size = backtrace(addresses, 40);
221 strings = backtrace_symbols(addresses, size);
222 out_stream <<
"Stack frames: " << size << std::endl;
223 for (
int i = 0; i < size; i++)
224 out_stream << i <<
": " << process_trace(strings[i]) << std::endl;
235 #ifdef LIBMESH_ENABLE_TRACEFILES 236 std::stringstream outname;
238 std::ofstream traceout(outname.str().c_str(), std::ofstream::app);
249 #if defined(LIBMESH_HAVE_GCC_ABI_DEMANGLE) 253 std::string ret =
name;
256 char * demangled_name = abi::__cxa_demangle(
name, 0, 0, &
status);
260 ret = demangled_name;
264 std::free(demangled_name);
std::string name(const ElemQuality q)
void print_trace(std::ostream &out_stream)
std::string demangle(const char *name)
processor_id_type global_processor_id()
bool on_command_line(std::string arg)
T command_line_value(const std::string &name, T value)