OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "chrome/common/mac/objc_zombie.h" | 5 #import "chrome/common/mac/objc_zombie.h" |
6 | 6 |
7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
8 #include <execinfo.h> | 8 #include <execinfo.h> |
9 #include <mach-o/dyld.h> | 9 #include <mach-o/dyld.h> |
10 #include <mach-o/nlist.h> | 10 #include <mach-o/nlist.h> |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 [NSString stringWithFormat:@"Zombie <%s: %p> received -%s", | 283 [NSString stringWithFormat:@"Zombie <%s: %p> received -%s", |
284 wasaName, object, sel_getName(aSelector)]; | 284 wasaName, object, sel_getName(aSelector)]; |
285 if (viaSelector != NULL) { | 285 if (viaSelector != NULL) { |
286 const char* viaName = sel_getName(viaSelector); | 286 const char* viaName = sel_getName(viaSelector); |
287 aString = [aString stringByAppendingFormat:@" (via -%s)", viaName]; | 287 aString = [aString stringByAppendingFormat:@" (via -%s)", viaName]; |
288 } | 288 } |
289 | 289 |
290 // Set a value for breakpad to report. | 290 // Set a value for breakpad to report. |
291 base::mac::SetCrashKeyValue(@"zombie", aString); | 291 base::mac::SetCrashKeyValue(@"zombie", aString); |
292 | 292 |
293 // Hex-encode the backtrace and tuck it into a breakpad key. | 293 // Encode trace into a breakpad key. |
294 NSString* deallocTrace = @"<unknown>"; | 294 if (found) { |
295 if (found && record.traceDepth) { | 295 base::mac::SetCrashKeyFromAddresses( |
296 NSMutableArray* hexBacktrace = | 296 @"zombie_dealloc_bt", record.trace, record.traceDepth); |
297 [NSMutableArray arrayWithCapacity:record.traceDepth]; | |
298 for (size_t i = 0; i < record.traceDepth; ++i) { | |
299 NSString* s = [NSString stringWithFormat:@"%p", record.trace[i]]; | |
300 [hexBacktrace addObject:s]; | |
301 } | |
302 deallocTrace = [hexBacktrace componentsJoinedByString:@" "]; | |
303 | |
304 // Warn someone if this exceeds the breakpad limits. | |
305 DCHECK_LE(strlen([deallocTrace UTF8String]), 255U); | |
306 } | 297 } |
307 base::mac::SetCrashKeyValue(@"zombie_dealloc_bt", deallocTrace); | |
308 | 298 |
309 // Log -dealloc backtrace in debug builds then crash with a useful | 299 // Log -dealloc backtrace in debug builds then crash with a useful |
310 // stack trace. | 300 // stack trace. |
311 if (found && record.traceDepth) { | 301 if (found && record.traceDepth) { |
312 DCHECK(DumpDeallocTrace(record.trace, record.traceDepth)); | 302 DCHECK(DumpDeallocTrace(record.trace, record.traceDepth)); |
313 } else { | 303 } else { |
314 DLOG(INFO) << "Unable to generate backtrace from -dealloc."; | 304 DLOG(INFO) << "Unable to generate backtrace from -dealloc."; |
315 } | 305 } |
316 DLOG(FATAL) << [aString UTF8String]; | 306 DLOG(FATAL) << [aString UTF8String]; |
317 | 307 |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 if (oldZombies) { | 546 if (oldZombies) { |
557 for (size_t i = 0; i < oldCount; ++i) { | 547 for (size_t i = 0; i < oldCount; ++i) { |
558 if (oldZombies[i].object) | 548 if (oldZombies[i].object) |
559 object_dispose(oldZombies[i].object); | 549 object_dispose(oldZombies[i].object); |
560 } | 550 } |
561 free(oldZombies); | 551 free(oldZombies); |
562 } | 552 } |
563 } | 553 } |
564 | 554 |
565 } // namespace ObjcEvilDoers | 555 } // namespace ObjcEvilDoers |
OLD | NEW |