19
19
20
20
// https://gist.github.com/jvranish/4441299
21
21
22
- static constexpr size_t FRAME_SIZE = 64 ;
22
+ static constexpr size_t FRAME_SIZE = 128 ;
23
23
static int s_signal = 0 ;
24
24
static siginfo_t * s_siginfo = nullptr ;
25
25
static ucontext_t * s_context = nullptr ;
70
70
if (imageName.empty ()) {
71
71
imageName = " <Unknown>" ;
72
72
}
73
+
74
+ // don't print those really long paths
75
+ if (
76
+ imageName.ends_with (" Geode.ios.dylib" )
77
+ || imageName.ends_with (" GeometryJump" )
78
+ || imageName.find (" game/geode/unzipped" ) != std::string::npos
79
+ ) {
80
+ imageName = imageName.substr (imageName.find_last_of (' /' ) + 1 );
81
+ }
82
+
73
83
return imageName;
74
84
}
75
85
@@ -178,20 +188,20 @@ size_t getImageSize(struct mach_header_64 const* header) {
178
188
}
179
189
180
190
extern " C" void signalHandler (int signal, siginfo_t * signalInfo, void * vcontext) {
181
- /* auto context = reinterpret_cast<ucontext_t*>(vcontext);
182
- s_backtraceSize = backtrace(s_backtrace.data(), FRAME_SIZE);
191
+ /* auto context = reinterpret_cast<ucontext_t*>(vcontext);
192
+ s_backtraceSize = backtrace(s_backtrace.data(), FRAME_SIZE);
183
193
184
194
// for some reason this is needed, dont ask me why
185
- s_backtrace[2] = reinterpret_cast<void*>(context->uc_mcontext->__ss.__pc);
186
- if (s_backtraceSize < FRAME_SIZE) {
187
- s_backtrace[s_backtraceSize] = nullptr;
188
- }*/
189
-
190
- s_signal = signal;
191
- s_siginfo = signalInfo;
192
- s_context = reinterpret_cast <ucontext_t *>(vcontext);
193
- char buf = ' 1' ;
194
- write (s_pipe[1 ], &buf, 1 );
195
+ s_backtrace[2] = reinterpret_cast<void*>(context->uc_mcontext->__ss.__pc);
196
+ if (s_backtraceSize < FRAME_SIZE) {
197
+ s_backtrace[s_backtraceSize] = nullptr;
198
+ }*/
199
+
200
+ s_signal = signal;
201
+ s_siginfo = signalInfo;
202
+ s_context = reinterpret_cast <ucontext_t *>(vcontext);
203
+ char buf = ' 1' ;
204
+ write (s_pipe[1 ], &buf, 1 );
195
205
}
196
206
197
207
// https://stackoverflow.com/questions/8278691/how-to-fix-backtrace-line-number-error-in-c
@@ -223,9 +233,9 @@ size_t getImageSize(struct mach_header_64 const* header) {
223
233
std::stringstream stacktrace;
224
234
225
235
auto messages = backtrace_symbols (s_backtrace.data (), s_backtraceSize);
226
- if (s_backtraceSize < FRAME_SIZE) {
227
- messages[s_backtraceSize] = nullptr ;
228
- }
236
+ if (s_backtraceSize < FRAME_SIZE) {
237
+ messages[s_backtraceSize] = nullptr ;
238
+ }
229
239
230
240
std::stringstream lines (addr2Line ());
231
241
@@ -272,7 +282,7 @@ size_t getImageSize(struct mach_header_64 const* header) {
272
282
std::getline (stream, function);
273
283
274
284
cutoff = function.find (" +" );
275
- stream = std::stringstream (function.substr (cutoff));
285
+ stream = std::stringstream (function.substr (cutoff + 1 ));
276
286
stream >> offset;
277
287
function = geode::utils::string::trim (function.substr (0 , cutoff));
278
288
@@ -285,13 +295,25 @@ size_t getImageSize(struct mach_header_64 const* header) {
285
295
free (demangle);
286
296
}
287
297
298
+ // don't display the (function + offset) part if it will be bogus.
299
+ // the first case (0x0) happens with hook handlers, while the second happens because
300
+ // GD exports a few fmt symbols, so backtrace_symbols thinks every function in GD is the last fmt symbol in the binary
301
+ if (function == " 0x0" || (binary == " GeometryJump" && offset > 0x1000 )) {
302
+ function = " " ;
303
+ }
304
+
288
305
if (auto image = imageFromAddress (reinterpret_cast <void *>(address))) {
289
306
stacktrace << " - " << getImageName (image) << " + " << std::showbase << std::hex << (address - (uintptr_t )image->imageLoadAddress ) << std::dec;
290
307
}
291
308
else {
292
- stacktrace << " - " << binary << " @ " << std::showbase << std::hex << address << std::dec ;
309
+ stacktrace << " - " << binary;
293
310
}
294
- stacktrace << " (" << function << " + " << offset << " ) @ " << std::showbase << std::hex << address << std::dec << " \n " ;
311
+
312
+ if (!function.empty ()) {
313
+ stacktrace << " (" << function << " + " << offset << " )" ;
314
+ }
315
+
316
+ stacktrace << " @ " << std::showbase << std::hex << address << std::dec << " \n " ;
295
317
}
296
318
}
297
319
@@ -352,7 +374,7 @@ static void handlerThread() {
352
374
while (read (s_pipe[0 ], &buf, 1 ) != 0 ) {
353
375
auto signalAddress = reinterpret_cast <void *>(s_context->uc_mcontext ->__ss .__pc );
354
376
// as you can tell, i moved code from signalHandler to here
355
- if (s_context) {
377
+ if (s_context) {
356
378
// s_backtraceSize = backtrace(s_backtrace.data(), FRAME_SIZE);
357
379
// i can't use 2 because then it'll show the actual stacktrace to be lower than what it actually is
358
380
s_backtrace[s_backtraceSize++] = signalAddress;
@@ -366,15 +388,15 @@ static void handlerThread() {
366
388
void ** frame = reinterpret_cast <void **>(current_fp);
367
389
void * next_fp = frame[0 ];
368
390
void * lr = frame[1 ];
369
-
391
+
370
392
if (next_fp == current_fp || lr == nullptr ) break ;
371
-
393
+
372
394
s_backtrace[s_backtraceSize++] = lr;
373
395
current_fp = next_fp;
374
396
}
375
397
}
376
- Mod* faultyMod = modFromAddress (signalAddress);
377
-
398
+ Mod* faultyMod = modFromAddress (signalAddress);
399
+
378
400
// Mod* faultyMod = nullptr;
379
401
// for (int i = 1; i < s_backtraceSize; ++i) {
380
402
// auto mod = modFromAddress(s_backtrace[i]);
@@ -387,7 +409,7 @@ static void handlerThread() {
387
409
388
410
log::error (" Geode crashed!\n {}" , text);
389
411
std::_Exit (EXIT_FAILURE);
390
- // s_signal = 0;
412
+ // s_signal = 0;
391
413
}
392
414
}
393
415
0 commit comments