Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

blueshogun96

macrumors regular
Original poster
Nov 24, 2012
112
2
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.
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,565
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.
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,560
6,059
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.
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,565
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.
 

blueshogun96

macrumors regular
Original poster
Nov 24, 2012
112
2
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.
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,565
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.
 

lloyddean

macrumors 65816
May 10, 2009
1,047
19
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?
 

blueshogun96

macrumors regular
Original poster
Nov 24, 2012
112
2
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.

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.

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.