ExceptionUtils.m
changeset 14 1af6415650bf
parent 10 82a37ccf6b8c
child 16 ce9c83f7ec14
     1.1 --- a/ExceptionUtils.m	Tue May 20 17:40:28 2008 -0700
     1.2 +++ b/ExceptionUtils.m	Tue Jun 17 14:57:48 2008 -0700
     1.3 @@ -8,7 +8,12 @@
     1.4  //
     1.5  
     1.6  #import "ExceptionUtils.h"
     1.7 -#import <unistd.h>
     1.8 +
     1.9 +#import "Logging.h"
    1.10 +#import "Test.h"
    1.11 +
    1.12 +#include <sys/sysctl.h>
    1.13 +#include <unistd.h>
    1.14  
    1.15  
    1.16  #ifndef Warn
    1.17 @@ -111,6 +116,8 @@
    1.18  
    1.19  
    1.20  
    1.21 +#ifdef NSAppKitVersionNumber10_4 // only enable this in a project that uses AppKit
    1.22 +
    1.23  @implementation MYExceptionReportingApplication
    1.24  
    1.25  
    1.26 @@ -138,11 +145,11 @@
    1.27  - (void) _showExceptionAlert: (NSException*)x
    1.28  {
    1.29      NSString *stack = [x my_callStack] ?:@"";
    1.30 -    int r = NSRunCriticalAlertPanel( @"Cloudy Internal Error!",
    1.31 +    int r = NSRunCriticalAlertPanel( @"Internal Error!",
    1.32                              [NSString stringWithFormat: @"Uncaught exception: %@\n%@\n\n%@\n\n"
    1.33 -                             "Please report this bug to jens@mooseyard.com (you can copy & paste the text).",
    1.34 +                             "Please report this bug (you can copy & paste the text).",
    1.35                               [x name], [x reason], stack],
    1.36 -                            @"Sorry",@"Quit",nil);
    1.37 +                            @"Continue",@"Quit",nil);
    1.38      if( r == NSAlertAlternateReturn )
    1.39          exit(1);
    1.40      MYSetExceptionReporter(&report);
    1.41 @@ -150,9 +157,35 @@
    1.42  
    1.43  @end
    1.44  
    1.45 +#endif
    1.46 +
    1.47 +
    1.48 +
    1.49 +BOOL IsGDBAttached( void )
    1.50 +{
    1.51 +    // From: <http://lists.apple.com/archives/Xcode-users/2004/Feb/msg00241.html>
    1.52 +    int mib[4];
    1.53 +    size_t bufSize = 0;
    1.54 +    int local_error = 0;
    1.55 +    struct kinfo_proc kp;
    1.56 +    
    1.57 +    mib[0] = CTL_KERN;
    1.58 +    mib[1] = KERN_PROC;
    1.59 +    mib[2] = KERN_PROC_PID;
    1.60 +    mib[3] = getpid();
    1.61 +    
    1.62 +    bufSize = sizeof (kp);
    1.63 +    if ((local_error = sysctl(mib, 4, &kp, &bufSize, NULL, 0)) < 0) {
    1.64 +        Warn(@"Failure calling sysctl");
    1.65 +        return NO;
    1.66 +    }
    1.67 +    return (kp.kp_proc.p_flag & P_TRACED) != 0;
    1.68 +}
    1.69 +
    1.70 +
    1.71  
    1.72  /*
    1.73 - Copyright (c) 2008, Jens Alfke. All rights reserved.
    1.74 + Copyright (c) 2008, Jens Alfke <jens@mooseyard.com>. All rights reserved.
    1.75   
    1.76   Redistribution and use in source and binary forms, with or without modification, are permitted
    1.77   provided that the following conditions are met: