Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(569)

Side by Side Diff: chrome/common/mac/objc_zombie.mm

Issue 7849011: Refactor Mac crash key reporting - move to base/mac/crash_logging.{h,mm} (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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>
11 11
12 #import <objc/objc-class.h> 12 #import <objc/objc-class.h>
13 13
14 #include <algorithm> 14 #include <algorithm>
15 #include <iostream> 15 #include <iostream>
16 16
17 #include "base/debug/stack_trace.h" 17 #include "base/debug/stack_trace.h"
18 #include "base/logging.h" 18 #include "base/logging.h"
19 #include "base/mac/crash_logging.h"
19 #include "base/mac/mac_util.h" 20 #include "base/mac/mac_util.h"
20 #include "base/metrics/histogram.h" 21 #include "base/metrics/histogram.h"
21 #include "base/synchronization/lock.h" 22 #include "base/synchronization/lock.h"
22 #import "chrome/app/breakpad_mac.h"
23 #import "chrome/common/mac/objc_method_swizzle.h" 23 #import "chrome/common/mac/objc_method_swizzle.h"
24 24
25 // Deallocated objects are re-classed as |CrZombie|. No superclass 25 // Deallocated objects are re-classed as |CrZombie|. No superclass
26 // because then the class would have to override many/most of the 26 // because then the class would have to override many/most of the
27 // inherited methods (|NSObject| is like a category magnet!). 27 // inherited methods (|NSObject| is like a category magnet!).
28 @interface CrZombie { 28 @interface CrZombie {
29 Class isa; 29 Class isa;
30 } 30 }
31 @end 31 @end
32 32
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 277
278 NSString* aString = 278 NSString* aString =
279 [NSString stringWithFormat:@"Zombie <%s: %p> received -%s", 279 [NSString stringWithFormat:@"Zombie <%s: %p> received -%s",
280 wasaName, object, sel_getName(aSelector)]; 280 wasaName, object, sel_getName(aSelector)];
281 if (viaSelector != NULL) { 281 if (viaSelector != NULL) {
282 const char* viaName = sel_getName(viaSelector); 282 const char* viaName = sel_getName(viaSelector);
283 aString = [aString stringByAppendingFormat:@" (via -%s)", viaName]; 283 aString = [aString stringByAppendingFormat:@" (via -%s)", viaName];
284 } 284 }
285 285
286 // Set a value for breakpad to report. 286 // Set a value for breakpad to report.
287 SetCrashKeyValue(@"zombie", aString); 287 base::mac::SetCrashKeyValue(@"zombie", aString);
288 288
289 // Hex-encode the backtrace and tuck it into a breakpad key. 289 // Hex-encode the backtrace and tuck it into a breakpad key.
290 NSString* deallocTrace = @"<unknown>"; 290 NSString* deallocTrace = @"<unknown>";
291 if (found && record.traceDepth) { 291 if (found && record.traceDepth) {
292 NSMutableArray* hexBacktrace = 292 NSMutableArray* hexBacktrace =
293 [NSMutableArray arrayWithCapacity:record.traceDepth]; 293 [NSMutableArray arrayWithCapacity:record.traceDepth];
294 for (size_t i = 0; i < record.traceDepth; ++i) { 294 for (size_t i = 0; i < record.traceDepth; ++i) {
295 NSString* s = [NSString stringWithFormat:@"%p", record.trace[i]]; 295 NSString* s = [NSString stringWithFormat:@"%p", record.trace[i]];
296 [hexBacktrace addObject:s]; 296 [hexBacktrace addObject:s];
297 } 297 }
298 deallocTrace = [hexBacktrace componentsJoinedByString:@" "]; 298 deallocTrace = [hexBacktrace componentsJoinedByString:@" "];
299 299
300 // Warn someone if this exceeds the breakpad limits. 300 // Warn someone if this exceeds the breakpad limits.
301 DCHECK_LE(strlen([deallocTrace UTF8String]), 255U); 301 DCHECK_LE(strlen([deallocTrace UTF8String]), 255U);
302 } 302 }
303 SetCrashKeyValue(@"zombie_dealloc_bt", deallocTrace); 303 base::mac::SetCrashKeyValue(@"zombie_dealloc_bt", deallocTrace);
304 304
305 // Log -dealloc backtrace in debug builds then crash with a useful 305 // Log -dealloc backtrace in debug builds then crash with a useful
306 // stack trace. 306 // stack trace.
307 if (found && record.traceDepth) { 307 if (found && record.traceDepth) {
308 DCHECK(DumpDeallocTrace(record.trace, record.traceDepth)); 308 DCHECK(DumpDeallocTrace(record.trace, record.traceDepth));
309 } else { 309 } else {
310 DLOG(INFO) << "Unable to generate backtrace from -dealloc."; 310 DLOG(INFO) << "Unable to generate backtrace from -dealloc.";
311 } 311 }
312 DLOG(FATAL) << [aString UTF8String]; 312 DLOG(FATAL) << [aString UTF8String];
313 313
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 if (oldZombies) { 552 if (oldZombies) {
553 for (size_t i = 0; i < oldCount; ++i) { 553 for (size_t i = 0; i < oldCount; ++i) {
554 if (oldZombies[i].object) 554 if (oldZombies[i].object)
555 object_dispose(oldZombies[i].object); 555 object_dispose(oldZombies[i].object);
556 } 556 }
557 free(oldZombies); 557 free(oldZombies);
558 } 558 }
559 } 559 }
560 560
561 } // namespace ObjcEvilDoers 561 } // namespace ObjcEvilDoers
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698