If cocoa app crashes where is stacktrace /crash log stored? - macos

I am new to mac and cocoa development. When a cocoa app crashes there is a windows that asks the user to report crash log to apple. I want to write a customized reporting component. So I want to know if crash reports /log are automatically stored somewhere are these simple text files or core dumps ?
I am looking to support 10.5 to 10.8

Crash logs can be found in a number of places.
In MacOS 10.8 (and I believe also 10.7) crash logs would be "~/Library/Logs/DiagnosticReports" or "/Library/Logs/DiagnosticReports" (the first is for crashes for user apps and the second is for system-wide apps).
Now instead of "reinventing the wheel", you may want to consider third party alternatives that can generate and return crash reports to you. Wikipedia lists these:
Unsanity developed an Input Manager called Smart Crash Reports, that
patches Apple software to include a "submit to developer" button
within Crash Reporter. Smart Crash Reports only works with Mac OS
X 10.4 and 10.5.
Uli Kusterer wrote UKCrashReporter, which can send the output of Apple's Crash Reporter to a developer the next time the
application is started.
CMCrashReporter is a small opensource framework, which can send the crashlog to the developer (via HTTP POST) and let the user
enter optional details.
ILCrashReporter-NG, a fork of Infinite Loop's ILCrashReporter (which was for Mac OS X 10.2-10.5); current OS support unknown
plcrashreporter Plausible CrashReporter provides an in-process crash reporting
framework for use on both the iPhone and Mac OS X
Google Breakpad, an open-source multi-platform crash reporting system

Related

OSX Sandbox: Launch a different executable based on OS version

I have an application in the Mac App Store. I'm trying to support users going back to Snow Leopard but this is becoming increasingly difficult.
Recently I've hit a roadblock due to the iTunesLibrary.framework, this framework must be linked to the main executable and yet doing so will always trigger a crash on load when running in Snow Leopard.
To workaround this problem, I want to compile a version of my app that doesn't use features and frameworks from newer versions of OSX. The problem is, how can I launch the compatibility build automatically?
I'm considering trying to make the main executable point to a shell script, but I don't really like that idea. I've also thought of the main executable being a helper that simply launches the full app and then exits. I expect this would work, but I worry about it getting approved by Apple. Finally, I'm wondering if the app bundle format itself can support this kind of setup, maybe via an advanced used of CFBundleExecutable that I'm unaware of.
Has anyone been down this road, what would you suggest?
Try weak linking the frameworks, more information about Weak Linking and Apple Frameworks here. Then also check in your code for the OS version or - (BOOL)respondsToSelector:(SEL)aSelector of any NSObject to determine what you can call and what not.
To have Snow Leopard as Base SDK you'll need an old Xcode and will have troubles submitting to Mac App Store.

How do you debug an app for an older version of Mac OS X?

I am developing an app using Xcode 4.6 on an OS X 10.8 machine. The app deployment target is set to 10.6, which is what we need to support. But when I archive the app (compile, link and embed resources+frameworks) and deploy (aka copy) it to the 10.6 test machine, it crashes with a generic Segmentation fault. It works fine on 10.7.
I can't compile the project in Xcode on the older Mac because the app is built using the newer compiler (it uses ARC, implicit property synthesis, the new objective-c literal syntax, etc.). It also wouldn't type check because the base SDK is 10.8 and it references some 10.8 tokens which the compiler on the 10.6 machine doesn't know about.
Any suggestions on how to go about debugging the app?
I'm not affiliated with this company/software in any way, but Deploymate is a paid app which can scan your app for SDK usage and tell you when you are calling selectors and APIs that are unavailable on older OS versions. This can help you track down exceptions and crashes relating to API usage.
You are very likely using one or more 10.7+ APIs that crash on 10.6. With a 10.8 target SDK you allow all the calls to function that are available in that SDK. However apps are bound late so this doesn't crash when you do not actually call those functions. You need an explicit check similar to this (here for the full screen feature):
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_6
if (runningOnLionOrLater) {
[mainWindow setCollectionBehavior: NSWindowCollectionBehaviorFullScreenPrimary];
[toggleFullscreenItem setHidden: NO];
}
#endif
One way to determine the current version is:
int macVersion;
if (Gestalt(gestaltSystemVersion, &macVersion) == noErr) {
runningOnLionOrLater = macVersion > MAC_OS_X_VERSION_10_6;
}
For debugging the problematic calls simply set the base SDK to 10.6 and XCode should mark those functions that are not available there.
While there is no real good solution to this (I've seen simply different behaviors on different macOS versions) and no way to simply simulate an older macOS version, if you have a machine to spare:
It is possible to use an external HD, partition it and install different macOS versions. They all can be bootable and it's a matter (pain) of restarting the machine for every OS version.

Getting console output of mac os app without using xcode

I am able to debug iOS apps on other machine without using xcode (even on windows) by using the iPhone Configuration Utility tool from Apple. More info here:
http://developer.apple.com/library/ios/#qa/qa1747/_index.html
But for macos apps, I cannot find a similar tool for debugging apps on a non-developer mac. I am new to this and would appreciate some help from experienced developers how is this typically done on real world.
You can get console output and crashlogs for os x applications from the console app.
You'll find it inside the Utility folder of your Applications folder. Or simply open spotlight and type "console"

How to generate a core file for a crashed app in XCode + gdb?

Having reproduced an elusive bug that crashes my app (running inside the iOS simulator, to be precise), I want to generate a core file for inspection later. On Linux I would run generate-core-file from within gdb, but that command isn't available in the Mac OS X version of gdb.
So, how can I generate a core file from within gdb? There are ways to ask the OS for a core dump of a crashed app, but I fear the app will change some of its state by then. What's the best way to do this?
Thanks!
Unfortunate there is no gcore command in mac osx gdb, but there is a good article about how to generate core dump on osx
Link
In this article there is a downloadable source code to generate core dump, which I have used many times.

Is there any library does minidump on Mac?

MiniDump is a great feature for debugging crashes on Windows, especially because it is small, so it can be sent via crash reports. (Window Error Reporting).
But it seems Mac OS X and other BSD system only supports full core dump.
Is there any mini-dump implementation on Mac or BSD system? Or how does Mac software developer analyze customer's crash reports?
Thanks!
-Jonny
Yes, you can use Google breakpad, which works on Windows, Mac, and Linux. As an added bonus, the file format it creates is the same as the windows minidump format, no matter what platform it's using - so you can apply your current analysis tools to dumps from windows clients.

Resources