MVE - Multi-View Environment mve-devel
Loading...
Searching...
No Matches
system.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015, Simon Fuhrmann
3 * TU Darmstadt - Graphics, Capture and Massively Parallel Computing
4 * All rights reserved.
5 *
6 * This software may be modified and distributed under the terms
7 * of the BSD 3-Clause license. See the LICENSE.txt file for details.
8 */
9
10#include <iostream>
11#include <cstdlib>
12#include <csignal>
13#if defined(__GLIBC__) && !defined(_WIN32) && !defined(__CYGWIN__)
14# include <execinfo.h> // ::backtrace
15#endif
16
17#include "util/system.h"
18
21
22void
23print_build_timestamp (char const* application_name,
24 char const* date, char const* time)
25{
26 std::cout << application_name << " (built on "
27 << date << ", " << time << ")" << std::endl;
28}
29
30/* ---------------------------------------------------------------- */
31
32void
37
38/* ---------------------------------------------------------------- */
39
40void
42{
43 if (code != SIGSEGV)
44 return;
45 std::cerr << "Received signal SIGSEGV (segmentation fault)" << std::endl;
47}
48
49/* ---------------------------------------------------------------- */
50
51void
53{
54#if defined(__GLIBC__) && !defined(_WIN32) && !defined(__CYGWIN__)
55 /* Get stack pointers for all frames on the stack. */
56 void *array[32];
57 int const size = ::backtrace(array, 32);
58
59 /* Print out all the addresses to stderr. */
60 std::cerr << "Obtained " << size << " stack frames:";
61 for (int i = 0; i < size; ++i)
62 std::cerr << " " << array[i];
63 std::cerr << std::endl;
64
65 /* Print out human readable representation to stderr. */
66 ::backtrace_symbols_fd(array, size, 2); // 2 = stderr
67#endif
68 std::cerr << "Segmentation fault" << std::endl;
69 ::exit(1);
70}
71
void print_stack_trace(void)
Prints a stack trace.
Definition system.cc:52
void signal_segfault_handler(int code)
Handles signal SIGSEGV (segmentation fault) printing a stack trace.
Definition system.cc:41
void print_build_timestamp(char const *application_name, char const *date, char const *time)
Prints the application name and the given date and time strings.
Definition system.cc:23
void register_segfault_handler(void)
Registers signal SIGSEGV (segmentation fault) handler.
Definition system.cc:33
#define UTIL_NAMESPACE_BEGIN
Definition defines.h:13
#define UTIL_NAMESPACE_END
Definition defines.h:14
#define UTIL_SYSTEM_NAMESPACE_BEGIN
Definition defines.h:22
#define UTIL_SYSTEM_NAMESPACE_END
Definition defines.h:23