@@ -56,8 +56,6 @@ void sanity_check_fn(const char *assertion, const char *file,
56
56
errorstream << file << " :" << line << " : " << function
57
57
<< " : An engine assumption '" << assertion << " ' failed." << std::endl;
58
58
59
- debug_stacks_print_to (errorstream);
60
-
61
59
abort ();
62
60
}
63
61
@@ -73,140 +71,9 @@ void fatal_error_fn(const char *msg, const char *file,
73
71
errorstream << file << " :" << line << " : " << function
74
72
<< " : A fatal error occured: " << msg << std::endl;
75
73
76
- debug_stacks_print_to (errorstream);
77
-
78
74
abort ();
79
75
}
80
76
81
- /*
82
- DebugStack
83
- */
84
-
85
- struct DebugStack
86
- {
87
- DebugStack (std::thread::id id);
88
- void print (FILE *file, bool everything);
89
- void print (std::ostream &os, bool everything);
90
-
91
- std::thread::id thread_id;
92
- char stack[DEBUG_STACK_SIZE][DEBUG_STACK_TEXT_SIZE];
93
- int stack_i; // Points to the lowest empty position
94
- int stack_max_i; // Highest i that was seen
95
- };
96
-
97
- DebugStack::DebugStack (std::thread::id id)
98
- {
99
- thread_id = id;
100
- stack_i = 0 ;
101
- stack_max_i = 0 ;
102
- memset (stack, 0 , DEBUG_STACK_SIZE*DEBUG_STACK_TEXT_SIZE);
103
- }
104
-
105
- void DebugStack::print (FILE *file, bool everything)
106
- {
107
- std::ostringstream os;
108
- os << thread_id;
109
- fprintf (file, " DEBUG STACK FOR THREAD %s:\n " ,
110
- os.str ().c_str ());
111
-
112
- for (int i = 0 ; i < stack_max_i; i++) {
113
- if (i == stack_i && !everything)
114
- break ;
115
-
116
- if (i < stack_i)
117
- fprintf (file, " #%d %s\n " , i, stack[i]);
118
- else
119
- fprintf (file, " (Leftover data: #%d %s)\n " , i, stack[i]);
120
- }
121
-
122
- if (stack_i == DEBUG_STACK_SIZE)
123
- fprintf (file, " Probably overflown.\n " );
124
- }
125
-
126
- void DebugStack::print (std::ostream &os, bool everything)
127
- {
128
- os<<" DEBUG STACK FOR THREAD " <<thread_id<<" : " <<std::endl;
129
-
130
- for (int i = 0 ; i < stack_max_i; i++) {
131
- if (i == stack_i && !everything)
132
- break ;
133
-
134
- if (i < stack_i)
135
- os<<" #" <<i<<" " <<stack[i]<<std::endl;
136
- else
137
- os<<" (Leftover data: #" <<i<<" " <<stack[i]<<" )" <<std::endl;
138
- }
139
-
140
- if (stack_i == DEBUG_STACK_SIZE)
141
- os<<" Probably overflown." <<std::endl;
142
- }
143
-
144
- std::map<std::thread::id, DebugStack*> g_debug_stacks;
145
- std::mutex g_debug_stacks_mutex;
146
-
147
- void debug_stacks_print_to (std::ostream &os)
148
- {
149
- MutexAutoLock lock (g_debug_stacks_mutex);
150
-
151
- os<<" Debug stacks:" <<std::endl;
152
-
153
- for (auto it : g_debug_stacks) {
154
- it.second ->print (os, false );
155
- }
156
- }
157
-
158
- void debug_stacks_print ()
159
- {
160
- debug_stacks_print_to (errorstream);
161
- }
162
-
163
- DebugStacker::DebugStacker (const char *text)
164
- {
165
- std::thread::id thread_id = std::this_thread::get_id ();
166
-
167
- MutexAutoLock lock (g_debug_stacks_mutex);
168
-
169
- auto n = g_debug_stacks.find (thread_id);
170
- if (n != g_debug_stacks.end ()) {
171
- m_stack = n->second ;
172
- } else {
173
- /* DEBUGPRINT("Creating new debug stack for thread %x\n",
174
- (unsigned int)thread_id);*/
175
- m_stack = new DebugStack (thread_id);
176
- g_debug_stacks[thread_id] = m_stack;
177
- }
178
-
179
- if (m_stack->stack_i >= DEBUG_STACK_SIZE) {
180
- m_overflowed = true ;
181
- } else {
182
- m_overflowed = false ;
183
-
184
- snprintf (m_stack->stack [m_stack->stack_i ],
185
- DEBUG_STACK_TEXT_SIZE, " %s" , text);
186
- m_stack->stack_i ++;
187
- if (m_stack->stack_i > m_stack->stack_max_i )
188
- m_stack->stack_max_i = m_stack->stack_i ;
189
- }
190
- }
191
-
192
- DebugStacker::~DebugStacker ()
193
- {
194
- MutexAutoLock lock (g_debug_stacks_mutex);
195
-
196
- if (m_overflowed)
197
- return ;
198
-
199
- m_stack->stack_i --;
200
-
201
- if (m_stack->stack_i == 0 ) {
202
- std::thread::id thread_id = m_stack->thread_id ;
203
- /* DEBUGPRINT("Deleting debug stack for thread %x\n",
204
- (unsigned int)thread_id);*/
205
- delete m_stack;
206
- g_debug_stacks.erase (thread_id);
207
- }
208
- }
209
-
210
77
#ifdef _MSC_VER
211
78
212
79
const char *Win32ExceptionCodeToString (DWORD exception_code)
0 commit comments