• Stars
    star
    4,166
  • Rank 9,898 (Top 0.3 %)
  • Language
    Objective-C
  • License
    Other
  • Created almost 12 years ago
  • Updated 17 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The Ultimate iOS Crash Reporter

KSCrash

The Ultimate Crash Reporter

Another crash reporter? Why?

Because while the existing crash reporters do report crashes, there's a heck of a lot more that they COULD do. Here are some key features of KSCrash:

  • On-device symbolication in a way that supports re-symbolication offline (necessary for iOS versions where many functions have been redacted).
  • Generates full Apple reports, with every field filled in.
  • 32-bit and 64-bit mode.
  • Supports all Apple devices, including Apple Watch.
  • Handles errors that can only be caught at the mach level, such as stack overflow.
  • Tracks the REAL cause of an uncaught C++ exception.
  • Handles a crash in the crash handler itself (or in the user crash handler callback).
  • Detects zombie (deallocated) object access attempts.
  • Recovers lost NSException messages in cases of zombies or memory corruption.
  • Introspects objects in registers and on the stack (C strings and Objective-C objects, including ivars).
  • Extracts information about objects referenced by an exception (such as "unrecognized selector sent to instance 0xa26d9a0")
  • Its pluggable server reporting architecture makes it easy to adapt to any API service.
  • Dumps the stack contents.
  • Diagnoses crash causes (Crash Doctor).
  • Records lots of information beyond what the Apple crash report can, in a JSON format.
  • Supports including extra data that the programmer supplies (before and during a crash).

KSCrash handles the following kinds of crashes:

  • Mach kernel exceptions
  • Fatal signals
  • C++ exceptions
  • Objective-C exceptions
  • Main thread deadlock (experimental)
  • Custom crashes (e.g. from scripting languages)

KSCrash can report to the following servers:

Here are some examples of the reports it can generate.

What's New?

Call for help!

My life has changed enough over the past few years that I can't keep up with giving KSCrash the love it needs.

I want you

I'm looking for someone to help me maintain this package, make sure issues get handled, merges are properly vetted, and code quality remains high. Please contact me personally (kstenerud at my gmail address) or comment in #313

VERY VERY VERY preliminary Android support.

And I do mean PRELIMINARY. Most stuff doesn't work, but it does compile. Look in the Android subdir if you want to play around with it.

C++ Exception Handling

That's right! Normally if your app terminates due to an uncaught C++ exception, all you get is this:

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libsystem_kernel.dylib          0x9750ea6a 0x974fa000 + 84586 (__pthread_kill + 10)
1   libsystem_sim_c.dylib           0x04d56578 0x4d0f000 + 292216 (abort + 137)
2   libc++abi.dylib                 0x04ed6f78 0x4ed4000 + 12152 (abort_message + 102)
3   libc++abi.dylib                 0x04ed4a20 0x4ed4000 + 2592 (_ZL17default_terminatev + 29)
4   libobjc.A.dylib                 0x013110d0 0x130b000 + 24784 (_ZL15_objc_terminatev + 109)
5   libc++abi.dylib                 0x04ed4a60 0x4ed4000 + 2656 (_ZL19safe_handler_callerPFvvE + 8)
6   libc++abi.dylib                 0x04ed4ac8 0x4ed4000 + 2760 (_ZSt9terminatev + 18)
7   libc++abi.dylib                 0x04ed5c48 0x4ed4000 + 7240 (__cxa_rethrow + 77)
8   libobjc.A.dylib                 0x01310fb8 0x130b000 + 24504 (objc_exception_rethrow + 42)
9   CoreFoundation                  0x01f2af98 0x1ef9000 + 204696 (CFRunLoopRunSpecific + 360)
...

No way to track what the exception was or where it was thrown from!

Now with KSCrash, you get the uncaught exception type, description, and where it was thrown from:

Application Specific Information:
*** Terminating app due to uncaught exception 'MyException', reason: 'Something bad happened...'

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   Crash-Tester                    0x0000ad80 0x1000 + 40320 (-[Crasher throwUncaughtCPPException] + 0)
1   Crash-Tester                    0x0000842e 0x1000 + 29742 (__32-[AppDelegate(UI) crashCommands]_block_invoke343 + 78)
2   Crash-Tester                    0x00009523 0x1000 + 34083 (-[CommandEntry executeWithViewController:] + 67)
3   Crash-Tester                    0x00009c0a 0x1000 + 35850 (-[CommandTVC tableView:didSelectRowAtIndexPath:] + 154)
4   UIKit                           0x0016f285 0xb4000 + 766597 (-[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1194)
5   UIKit                           0x0016f4ed 0xb4000 + 767213 (-[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 201)
6   Foundation                      0x00b795b3 0xb6e000 + 46515 (__NSFireDelayedPerform + 380)
7   CoreFoundation                  0x01f45376 0x1efa000 + 308086 (__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 22)
8   CoreFoundation                  0x01f44e06 0x1efa000 + 306694 (__CFRunLoopDoTimer + 534)
9   CoreFoundation                  0x01f2ca82 0x1efa000 + 207490 (__CFRunLoopRun + 1810)
10  CoreFoundation                  0x01f2bf44 0x1efa000 + 204612 (CFRunLoopRunSpecific + 276)
...

Custom Crashes & Stack Traces

You can now report your own custom crashes and stack traces (think scripting languages):

- (void) reportUserException:(NSString*) name
                  reason:(NSString*) reason
              lineOfCode:(NSString*) lineOfCode
              stackTrace:(NSArray*) stackTrace
        terminateProgram:(BOOL) terminateProgram;

See KSCrash.h for details.

Unstable Features

The following features should be considered "unstable" and are disabled by default:

  • Deadlock detection

How to Build KSCrash

  1. Select the KSCrash scheme.
  2. Choose iOS Device.
  3. Select Archive from the Products menu.

When it has finished building, it will show you the framework in Finder. You can use it like you would any other framework.

How to Use KSCrash

  1. Add the framework to your project (or add the KSCrash project as a dependency)

  2. Add the following system frameworks & libraries to your project:

    • libc++.dylib (libc++.tbd in newer versions)
    • libz.dylib (libz.tbd in newer versions)
    • MessageUI.framework (iOS only)
    • SystemConfiguration.framework
  3. Add the flag "-ObjC" to Other Linker Flags in your Build Settings

  4. Add the following to your [application: didFinishLaunchingWithOptions:] method in your app delegate:

#import <KSCrash/KSCrash.h>
// Include to use the standard reporter.
#import <KSCrash/KSCrashInstallationStandard.h>
// Include to use Quincy or Hockey.
#import <KSCrash/KSCrashInstallationQuincyHockey.h>
// Include to use the email reporter.
#import <KSCrash/KSCrashInstallationEmail.h>
// Include to use Victory.
#import <KSCrash/KSCrashInstallationVictory.h>

- (BOOL)application:(UIApplication*) application didFinishLaunchingWithOptions:(NSDictionary*) launchOptions
{
KSCrashInstallationStandard* installation = [KSCrashInstallationStandard sharedInstance];
installation.url = [NSURL URLWithString:@"http://put.your.url.here"];

// OR:

KSCrashInstallationQuincy* installation = [KSCrashInstallationQuincy sharedInstance];
installation.url = [NSURL URLWithString:@"http://put.your.url.here"];

// OR:

KSCrashInstallationHockey* installation = [KSCrashInstallationHockey sharedInstance];
installation.appIdentifier = @"PUT_YOUR_HOCKEY_APP_ID_HERE";

// OR:

KSCrashInstallationEmail* installation = [KSCrashInstallationEmail sharedInstance];
installation.recipients = @[@"[email protected]"];

// Optional (Email): Send Apple-style reports instead of JSON
[installation setReportStyle:KSCrashEmailReportStyleApple useDefaultFilenameFormat:YES]; 

// Optional: Add an alert confirmation (recommended for email installation)
[installation addConditionalAlertWithTitle:@"Crash Detected"
                                 message:@"The app crashed last time it was launched. Send a crash report?"
                               yesAnswer:@"Sure!"
                                noAnswer:@"No thanks"];

// OR:

KSCrashInstallationVictory* installation = [KSCrashInstallationVictory sharedInstance];
installation.url = [NSURL URLWithString:@"https://put.your.url.here/api/v1/crash/<application key>"];

[installation install];
    …
}

This will install the crash monitor system (which intercepts crashes and stores reports to disk). Note that there are other properties you can and probably will want to set for the various installations.

Once you're ready to send any outstanding crash reports, call the following:

[installation sendAllReportsWithCompletion:^(NSArray *filteredReports, BOOL completed, NSError *error)
{
 // Stuff to do when report sending is complete
}];

Recommended Reading

If possible, you should read the following header files to fully understand what features KSCrash has, and how to use them:

  • KSCrash.h
  • KSCrashInstallation.h
  • KSCrashInstallation(SPECIFIC TYPE).h
  • Architecture.md

Understanding the KSCrash Codebase

I've written a quick code tour here

Advanced Usage

Enabling on-device symbolication

On-device symbolication requires basic symbols to be present in the final build. To enable this, go to your app's build settings and set Strip Style to Debugging Symbols. Doing so increases your final binary size by about 5%, but you get on-device symbolication.

Enabling advanced functionality:

KSCrash has advanced functionality that can be very useful when examining crash reports in the wild. Some involve minor trade-offs, so most of them are disabled by default.

Custom User Data (userInfo in KSCrash.h)

You can store custom user data to the next crash report by setting the userInfo property in KSCrash.h.

Zombie Tracking (KSCrashMonitorTypeZombie in KSCrashMonitorType.h)

KSCrash has the ability to detect zombie instances (dangling pointers to deallocated objects). It does this by recording the address and class of any object that gets deallocated. It stores these values in a cache, keyed off the deallocated object's address. This means that the smaller you set the cache size, the greater the chance that a hash collision occurs and you lose information about a previously deallocated object.

With zombie tracking enabled, KSCrash will also detect a lost NSException and print its contents. Certain kinds of memory corruption or stack corruption crashes can cause the exception to deallocate early, further twarting efforts to debug your app, so this feature can be quite handy at times.

Trade off: Zombie tracking at the cost of adding very slight overhead to object deallocation, and having some memory reserved.

Deadlock Detection (KSCrashMonitorTypeMainThreadDeadlock in KSCrashMonitorType.h)

WARNING WARNING WARNING WARNING WARNING WARNING WARNING

This feature is UNSTABLE! It can false-positive and crash your app!

If your main thread deadlocks, your user interface will become unresponsive, and the user will have to manually shut down the app (for which there will be no crash report). With deadlock detection enabled, a watchdog timer is set up. If anything holds the main thread for longer than the watchdog timer duration, KSCrash will shut down the app and give you a stack trace showing what the main thread was doing at the time.

This is wonderful, but you must be careful: App initialization generally occurs on the main thread. If your initialization code takes longer than the watchdog timer, your app will be forcibly shut down during start up! If you enable this feature, you MUST ensure that NONE of your normally running code holds the main thread for longer than the watchdog value! At the same time, you'll want to set the timer to a low enough value that the user doesn't become impatient and shut down the app manually before the watchdog triggers!

Trade off: Deadlock detection, but you must be a lot more careful about what runs on the main thread!

Memory Introspection (introspectMemory in KSCrash.h)

When an app crashes, there are usually objects and strings in memory that are being referenced by the stack, registers, or even exception messages. When enabled, KSCrash will introspect these memory regions and store their contents in the crash report.

You can also specify a list of classes that should not be introspected by setting the doNotIntrospectClasses property in KSCrash.

Custom crash handling code (onCrash in KSCrash.h)

If you want to do some extra processing after a crash occurs (perhaps to add more contextual data to the report), you can do so.

However, you must ensure that you only use async-safe code, and above all else never call Objective-C code from that method! There are many cases where you can get away with doing so anyway, but there are certain classes of crashes where handler code that disregards this warning will cause the crash handler to crash! Note that if this happens, KSCrash will detect it and write a full report anyway, though your custom handler code may not fully run.

Trade off: Custom crash handling code, but you must be careful what you put in it!

KSCrash log redirection

This takes whatever KSCrash would have printed to the console, and writes it to a file instead. I mostly use this for debugging KSCrash itself, but it could be useful for other purposes, so I've exposed an API for it.

Examples

The workspace includes some example apps, which demonstrate common KSCrash usage. Please look at the top of AppDelegate.m in each app for a description of what it does.

License

Copyright (c) 2012 Karl Stenerud

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in the documentation of any redistributions of the template files themselves (but not in projects built using the templates).

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

iOS-Universal-Framework

An XCode project template to build universal frameworks (arm7, arm7s, and simulator) for iOS / iPhone.
Python
2,957
star
2

ObjectAL-for-iPhone

Mac and iOS Audio development, minus the headache. ObjectAL is the easy Objective-C interface to OpenAL, AVAudioPlayer, and audio session management.
Objective-C
886
star
3

Musashi

Motorola 680x0 emulator written in C
C
361
star
4

bo

The Swiss army knife of data examination and manipulation
C
330
star
5

KSReachability

A better iOS & Mac reachability for a modern age.
Objective-C
258
star
6

concise-encoding

The secure data format for a modern world
ANTLR
243
star
7

Crash-Manager

An iOS library for recording crash events.
Objective-C
71
star
8

KSJSON

The fastest JSON parser and serializer for Objective-C.
Objective-C
63
star
9

virtual-builders

Builds various virtual environments
Shell
60
star
10

meson-examples

Example C/C++ projects using Meson
Meson
57
star
11

nixos-beginners-handbook

The missing handbook for NixOS beginners
57
star
12

Objective-Gems

Useful little gems to use when programming in Objective C
Objective-C
47
star
13

openwrt-relayd-wireless-bridge

Instructions for setting up a wireless bridge in OpenWRT using relayd
44
star
14

docker-desktops

Desktops inside of Docker images
Shell
43
star
15

Aural

iOS (and later OSX) audio library based on Audio Units (work-in-progress)
C
37
star
16

dogma

Dogma: A modernized metalanguage with better expressiveness and binary grammar support
36
star
17

go-concise-encoding

Golang implementation of Concise Binary and Text Encoding
Go
30
star
18

smalltime

A simple and convenient binary date & time format in 64 bits.
C
23
star
19

safe-encoding

Binary-to-text encoding that is safe to pass through modern text processors
C
22
star
20

bit-tricks

Various tricks for dealing with bits
C
21
star
21

modern-cmake-templates

Templates to get a CMake project started quickly
CMake
20
star
22

KSVarArgs

Taking the pain out of variable argument lists in Objective-C.
Objective-C
19
star
23

SynthesizeSingleton

Note: The latest version is at http://github.com/cjhanson/Objective-C-Optimized-Singleton
C
18
star
24

DOS-Serial-Library

A serial port / UART library for DOS
C
16
star
25

ubuntu-dev-installer

Scripts to install an ubuntu dev environment
Shell
15
star
26

go-subvert

Subvert go's runtime system
Go
14
star
27

ARCSafe-MemManagement

Makes your code both ARC and non-ARC compatible
Objective-C
13
star
28

compact-time

Encoding schemes to store a complete time, date, or timestamp in as few bytes as possible for data transmission.
12
star
29

depixelate

Implementation of various scaling/depixelating techbologies
C
10
star
30

specifications

Specifications for better computing
9
star
31

ubuntu-server-zfs

Install Ubuntu server with ZFS root
Shell
9
star
32

Universal-Framework-Examples

Examples for more complex usage of universal iOS frameworks
Objective-C
9
star
33

KSLogging

Basic, lightweight preprocessor-controlled logging for C and Objective-C.
C
9
star
34

CocosEnhanced

Some useful classes for cocos2d
Objective-C
8
star
35

JSONCompare

A program to compare the speeds of various Objective-C JSON libraries.
Objective-C
8
star
36

mac-kvm

Scripts to launch mac os under kvm
Shell
6
star
37

streamux

A minimalist, asynchronous, multiplexing, request-response protocol.
C
4
star
38

go-describe

Rich object descriptions in go
Go
4
star
39

vlq

An encoding scheme to compress unsigned integers
C
4
star
40

lxc-desktop

Script to create complete desktop environments inside LXC containers
Shell
4
star
41

KSRetainTracker

A tool for debugging retain/release issues in Objective-C
Objective-C
4
star
42

enctool

A tool for manipulating data in various encoding formats.
Go
3
star
43

darip

Bulk downloads images from Deviant Art using Mechanicalsoup's simulated browser
Python
3
star
44

go-gotchas

Common gotchas with golang and how to work around them
3
star
45

Throwaway-IntroMusic

A throwaway repo for demonstrating intro music in ObjectAL
Objective-C
3
star
46

c-smalltime

C implementation of smalltime and nanotime
C
3
star
47

showcase

Showcase of my best work
3
star
48

go-uleb128

Go implementation of unsigned little endian base-128
Go
2
star
49

work-installer

Installer for my work environment
Shell
2
star
50

ubuntu-maintainers-handbook

Ubuntu Maintainer's Handbook
2
star
51

go-smalltime

Go implementation of Smalltime and Nanotime
Go
2
star
52

marwaita

Marwaita Theme (Modified)
CSS
2
star
53

compact-float

An encoding scheme to store a floating point value in as few bytes as possible.
2
star
54

open-in-lxc

Start an LXC container wrapping a directory in the host
Shell
2
star
55

fix-crd

Fixes chrome remote desktop
Shell
1
star
56

ubuntu-package-fixing

Instructions for fixing an Ubuntu package
1
star
57

go-loggedio

Logged I/O for Go
Go
1
star
58

hyver

Hybrid Versioning: Versioning with better U/X
1
star
59

bash-installer-common

Functions to help install things on an Ubuntu system.
Shell
1
star
60

KSLog

A simple, header-only, async-safe logger for C and C++
C
1
star
61

navigation

Idiomic navigation through DOM graphs
Java
1
star
62

xor

XORs each octet of the input file with 0xff
C
1
star
63

c-compact-time

C implementation of compact time
C
1
star
64

ubuntu-env-installer

Installer scripts to set up my dev and desktop environments.
Shell
1
star
65

bin

my bin dir
Shell
1
star
66

docker-commafeed

Dockerfile for the Commafeed RSS reader
1
star
67

unicode_range_finder

A quick utility to find and print ranges of unicode codepoints for BNF
Go
1
star
68

bonjson

A binary serialization format for JSON
1
star
69

lxc-services

Various services running under LXC
Shell
1
star
70

go-equivalence

A go library for comparing objects
Go
1
star
71

KSDelegateForwarding

Multiplex delegates for any object implementing the delegate pattern.
Objective-C
1
star
72

go-cte

Go implementation of Concise Text Encoding
Go
1
star
73

endianness

Endianness macros and functions for C and C++
C
1
star
74

c-compact-float

C implementation of compact float
C
1
star
75

kstenerud

Go
1
star
76

varpad

Unlimited padding with an embedded length field
1
star
77

linux-fixes

Fixes for various Linux issues
1
star
78

go-compact-time

golang implementation of compact time
Go
1
star