Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 4, 2013, 07:16 PM   #1
blueshogun96
macrumors member
 
Join Date: Nov 2012
Exception Handling

I've done lots of searching on this, but haven't found what I needed. I'm trying to write an exception handler for MacOSX, but all I've found information on is std::exception and some really obscure examples on NSException.

What I need is have the exact memory location (or should I say, the value of the EIP or RIP register) and the value of the x86 registers when the exception occurs as well as the exception code. Maybe this functionality isn't available on MacOSX, but this is what I've gotten used to using on Windows (yeah, I'm spoiled). Am I missing something? Thanks.

Shogun.
blueshogun96 is offline   0 Reply With Quote
Old Jan 5, 2013, 06:53 AM   #2
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
Quote:
Originally Posted by blueshogun96 View Post
I've done lots of searching on this, but haven't found what I needed. I'm trying to write an exception handler for MacOSX, but all I've found information on is std::exception and some really obscure examples on NSException.

What I need is have the exact memory location (or should I say, the value of the EIP or RIP register) and the value of the x86 registers when the exception occurs as well as the exception code. Maybe this functionality isn't available on MacOSX, but this is what I've gotten used to using on Windows (yeah, I'm spoiled). Am I missing something? Thanks.
It looks like you are talking about hardware interrupts, not exceptions.

If you are talking about exceptions, you'll never see and you'll never need to see any processor registers. Read up about try / catch / throw in C++ and @trye etc. in Objective-C.
gnasher729 is offline   0 Reply With Quote
Old Jan 5, 2013, 09:07 AM   #3
ArtOfWarfare
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
My understanding is that exception handling is rarely done in Obj-C, because far fewer things throw exceptions (instead they do things like return null. 0, -1, or an enum value labeled exception.)
Exception handling leads to messy, hard to follow code that runs (relatively) slow.
ArtOfWarfare is offline   0 Reply With Quote
Old Jan 5, 2013, 03:35 PM   #4
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
Quote:
Originally Posted by ArtOfWarfare View Post
My understanding is that exception handling is rarely done in Obj-C, because far fewer things throw exceptions (instead they do things like return null. 0, -1, or an enum value labeled exception.)
Exception handling leads to messy, hard to follow code that runs (relatively) slow.
In Objective-C, any exception that is thrown should be considered a bug in your code. The only exception (sorry) to that rule is remote objects, where any call can potentially throw an exception.
gnasher729 is offline   0 Reply With Quote
Old Jan 6, 2013, 04:11 AM   #5
blueshogun96
Thread Starter
macrumors member
 
Join Date: Nov 2012
Quote:
Originally Posted by gnasher729 View Post
It looks like you are talking about hardware interrupts, not exceptions.

If you are talking about exceptions, you'll never see and you'll never need to see any processor registers. Read up about try / catch / throw in C++ and @trye etc. in Objective-C.
I understand how try, catch and throw work, but now that I look a bit deeper into the issue, Microsoft just has a special feature that allows the user to retain the values of the entire register set as well as the complete call stack, which is not part of standard exception handling.
blueshogun96 is offline   0 Reply With Quote
Old Jan 6, 2013, 08:59 AM   #6
xStep
macrumors 68000
 
Join Date: Jan 2003
Location: Lost in Minneapolis
Quote:
Originally Posted by blueshogun96 View Post
Am I missing something?
Yes. Your goal.

Explain the purpose so that others can understand why you think you need such low level information. Perhaps that will bring someone into the conversation with a great result.
xStep is offline   0 Reply With Quote
Old Jan 6, 2013, 12:47 PM   #7
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
Quote:
Originally Posted by blueshogun96 View Post
I understand how try, catch and throw work, but now that I look a bit deeper into the issue, Microsoft just has a special feature that allows the user to retain the values of the entire register set as well as the complete call stack, which is not part of standard exception handling.
backtrace and backtrace_symbols are standard BSD functions and work just fine on MacOS X. If you want the contents of all registers, you can just write an inline assembler function, but I can't quite see what that would be good for.
gnasher729 is offline   0 Reply With Quote
Old Jan 6, 2013, 02:27 PM   #8
lloyddean
macrumors 6502a
 
Join Date: May 2009
Location: Des Moines, WA
Perhaps a better explanation as to your goals are.

My question is why you think you need this information?
What do you "think" you need it?

Are you doing user space programming or system (kernel) level programming?
lloyddean is offline   0 Reply With Quote
Old Jan 10, 2013, 07:54 PM   #9
blueshogun96
Thread Starter
macrumors member
 
Join Date: Nov 2012
Quote:
Originally Posted by xStep View Post
Yes. Your goal.

Explain the purpose so that others can understand why you think you need such low level information. Perhaps that will bring someone into the conversation with a great result.
Okay, sorry for being so vague. I mentioned this in another thread, and I'm writing a cross platform Xbox emulator. So far, my approach works in Windows and Linux (as multiple people have confirmed), but so far, not on MacOSX.

Since my goal is to use static-rec (or a variant of it at least), I'm required to use the host machine's CPU to a certain degree, and when debugging, obtaining the value of the CPU registers upon an exception occurrence is absolutely necessary.

Quote:
Originally Posted by lloyddean View Post
Perhaps a better explanation as to your goals are.

My question is why you think you need this information?
What do you "think" you need it?

Are you doing user space programming or system (kernel) level programming?
See above, but so far, it looks like a mix of user level and kernel level programming.

Quote:
Originally Posted by gnasher729 View Post
backtrace and backtrace_symbols are standard BSD functions and work just fine on MacOS X. If you want the contents of all registers, you can just write an inline assembler function, but I can't quite see what that would be good for.
See above, please.
blueshogun96 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Exception breakpoint where no exception is caused moonman239 iPhone/iPad Programming 1 Apr 30, 2014 07:03 AM
Do Not Disturb Exception PreferSilence iOS 7 6 Dec 28, 2013 08:35 AM
iPhone: exception code 8badf00d mellywb Jailbreaks and iOS Hacks 1 Dec 27, 2013 11:29 PM
GlimmerBlocker ******* Exception? SawyerTHEBEST Mac Applications and Mac App Store 1 Feb 25, 2013 08:25 PM
Throwing an exception in my app *Need Help* iJustinCabral iPhone/iPad Programming 3 Jul 17, 2012 02:03 AM

Forum Jump

All times are GMT -5. The time now is 05:22 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC