Line data Source code
1 : /*
2 : * Copyright (c) 2012-2015: G-CSC, Goethe University Frankfurt
3 : * Author: Martin Rupp
4 : *
5 : * This file is part of UG4.
6 : *
7 : * UG4 is free software: you can redistribute it and/or modify it under the
8 : * terms of the GNU Lesser General Public License version 3 (as published by the
9 : * Free Software Foundation) with the following additional attribution
10 : * requirements (according to LGPL/GPL v3 §7):
11 : *
12 : * (1) The following notice must be displayed in the Appropriate Legal Notices
13 : * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14 : *
15 : * (2) The following notice must be displayed at a prominent place in the
16 : * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17 : *
18 : * (3) The following bibliography is recommended for citation and must be
19 : * preserved in all covered files:
20 : * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21 : * parallel geometric multigrid solver on hierarchically distributed grids.
22 : * Computing and visualization in science 16, 4 (2013), 151-164"
23 : * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24 : * flexible software system for simulating pde based models on high performance
25 : * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26 : *
27 : * This program is distributed in the hope that it will be useful,
28 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 : * GNU Lesser General Public License for more details.
31 : */
32 :
33 : #include "common/log.h"
34 : #include "common/profiler/profiler.h"
35 : #include "assert.h"
36 : #include <stdlib.h>
37 :
38 : #ifdef UG_POSIX
39 : #include "util/demangle.h"
40 : #if !defined ANDROID && !defined UG_CYGWIN
41 : #include <execinfo.h>
42 : #endif // ANDROID
43 : #endif // UG_POSIX
44 :
45 : #include <string>
46 : #include <sstream>
47 :
48 : #ifdef UG_FOR_LUA
49 : #include "bindings/lua/info_commands.h"
50 : #include <map>
51 : namespace ug{namespace script{bool IsLUADebug();}}
52 : #endif
53 :
54 : #ifdef UG_PARALLEL
55 : #include "pcl/pcl_base.h"
56 : #endif
57 :
58 : using namespace std;
59 :
60 0 : void lua_backtrace()
61 : {
62 : #ifdef UG_FOR_LUA
63 : bool bDoLUAStackTrace=true;
64 : #ifdef UG_POSIX
65 : #ifdef UG_PROFILER_SHINY
66 : if(ug::script::IsLUADebug()) bDoLUAStackTrace = false;
67 : #endif
68 : #endif
69 : if(bDoLUAStackTrace)
70 : {
71 : UG_LOG("--------------- LUA Stack Trace: --------------\n");
72 0 : UG_LOG(ug::bridge::LuaStackTraceString());
73 : UG_LOG("\n");
74 : }
75 : #endif
76 0 : }
77 :
78 0 : void shiny_backtrace()
79 : {
80 : #ifdef UG_POSIX
81 : #ifdef UG_PROFILER_SHINY
82 : UG_LOG("---------- Shiny Profiler Backtrace: ----------\n");
83 : Shiny::ProfileNode *p = Shiny::ProfileManager::instance._curNode;
84 : size_t i=0;
85 :
86 : while(p != &Shiny::ProfileManager::instance.rootNode)
87 : {
88 : const char *name = p->zone->name;
89 : if(name[0] == '@') name = "LUA Script";
90 : UG_LOG(std::setw(3) << i++ << std::setw(50) << name << "\t" << p->zone->file << " :" << p->zone->line << "\n");
91 : p = p->parent;
92 : }
93 : UG_LOG("\n");
94 : #endif
95 : #endif
96 0 : }
97 :
98 :
99 :
100 0 : string get_gcc_backtrace()
101 : {
102 : #if defined UG_POSIX && !defined ANDROID && !defined UG_CYGWIN
103 0 : stringstream ss;
104 : void *array[100];
105 : size_t size;
106 : char **strings;
107 :
108 0 : size = backtrace (array, 100);
109 0 : strings = backtrace_symbols (array, size);
110 :
111 0 : for (size_t i = 0; i < size; i++)
112 0 : ss << i << ":\n" << ug::demangle_block(strings[i]);
113 0 : free (strings);
114 0 : ss << "\n";
115 0 : return ss.str();
116 : #else
117 : return "";
118 : #endif // UG_POSIX
119 0 : }
120 :
121 0 : void gcc_backtrace()
122 : {
123 : #if defined UG_POSIX && !defined UG_CYGWIN
124 : UG_LOG("--------------- GCC Backtrace: ----------------\n");
125 0 : UG_LOG(get_gcc_backtrace());
126 : #endif // UG_POSIX
127 0 : }
128 :
129 :
130 :
131 : /*
132 : * This function is meant to put out some more meaningful debug data.
133 : * It prints the call backtrace and Profiler backtrace if available.
134 : * It also demangles the C++ function names so you get more a clue
135 : * what's going on.
136 : */
137 0 : void ug_backtrace()
138 : {
139 0 : lua_backtrace();
140 0 : shiny_backtrace();
141 0 : gcc_backtrace();
142 :
143 0 : }
144 :
145 : /// put a breakpoint here to break on UG_ASSERT or UG_THROW
146 : /// b ug_assert_or_error
147 1 : void ug_assert_or_error()
148 : {
149 : // intentionally left empty
150 1 : }
151 :
152 :
153 : /// called whenever UG_ASSERT is called.
154 0 : void ug_assert_failed()
155 : {
156 0 : ug_backtrace();
157 0 : ug_assert_or_error();
158 : #ifdef UG_PARALLEL
159 : pcl::Abort();
160 : #endif
161 0 : }
162 :
163 : /// called whenever UG_THROW or UG_THROW_REGISTRY_ERROR is called.
164 1 : void ug_throw_error()
165 : {
166 : //ug_backtrace();
167 1 : ug_assert_or_error();
168 1 : }
|