iDevGames Forums
Last assembly function - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Tools & Technology (/forum-10.html)
+--- Thread: Last assembly function (/thread-8339.html)



Last assembly function - Miglu - Nov 21, 2010 05:23 AM

What is the best way to find out EXC_BAD_ACCESS's origin using the debugger? I mean the problem that is in the last assembly language function. http://developer.apple.com/library/mac/#documentation/DeveloperTools/gdb/gdb/gdb_toc.html is a massive document so it is difficult to find relevant information from it. I tried using po $eax but I always get "Value can't be converted to integer".


RE: Last assembly function - zenkimoto - Nov 21, 2010 08:13 AM

@Mingu

The EXC_BAD_ACCESS error occurs when you try to access memory with no reference. What was your latest change? Did you forget to retain a pointer? If you have no idea, you may have to step through your code with the debugger. Are you writing an iPhone app? If not, you could turn on garbage collection as you learn the ins and outs of objective-c.

Check out this link:
http://developer.apple.com/library/mac/#DOCUMENTATION/DeveloperTools/Conceptual/XcodeDebugging/100-Debugging_in_the_Debugger/debugging_in_debugger.html%23//apple_ref/doc/uid/TP40007057-CH6-SW1

Hope this helps!


RE: Last assembly function - Miglu - Nov 21, 2010 08:37 AM

Thanks. I actually have a decent understanding of how to use the debugger. However, I do not know how to get relevant information from the registers.
This particular problem is about Cocos2D's setOpenGLView method:
Quote:#0 0x7fff816202e5 in glEnable
#1 0x100020e18 in -[CCDirector setAlphaBlending:] at CCDirector.m:290
#2 0x1000205c5 in -[CCDirector setGLDefaultValues] at CCDirector.m:177
#3 0x100021175 in -[CCDirector setOpenGLView:] at CCDirector.m:326
#4 0x10005ca1d in -[CCDirectorDisplayLink setOpenGLView:] at CCDirectorMac.m:226
#5 0x100001e48 in -[Cocos2D_testAppDelegate applicationDidFinishLaunching:] at Cocos2D_testAppDelegate.m:51
#6 0x7fff81b1084e in _nsnote_callback
#7 0x7fff84cbfa90 in __CFXNotificationPost
#8 0x7fff84cac008 in _CFXNotificationPostNotification
#9 0x7fff81b077b8 in -[NSNotificationCenter postNotificationName:object:userInfo:]
#10 0x7fff8036e832 in -[NSApplication _postDidFinishNotification]
#11 0x7fff8036e767 in -[NSApplication _sendFinishLaunchingNotification]
#12 0x7fff80439719 in -[NSApplication(NSAppleEventHandling) _handleAEOpen:]
#13 0x7fff80439395 in -[NSApplication(NSAppleEventHandling) _handleCoreEvent:withReplyEvent:]
#14 0x7fff81b3f14a in -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:]
#15 0x7fff81b3ef7a in _NSAppleEventManagerGenericHandler
#16 0x7fff828ac323 in aeDispatchAppleEvent
#17 0x7fff828ac21c in dispatchEventAndSendReply
#18 0x7fff828ac123 in aeProcessAppleEvent
#19 0x7fff80f0e741 in AEProcessAppleEvent
#20 0x7fff8033e481 in _DPSNextEvent
#21 0x7fff8033dbed in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]
#22 0x7fff803038d3 in -[NSApplication run]
#23 0x7fff802fc5f8 in NSApplicationMain
#24 0x100001f7c in main at main.m:13



RE: Last assembly function - Miglu - Nov 21, 2010 12:20 PM

I tried using the applicationDidFinishLaunching method from one of Cocos2D's tests, ActionsTest. EXC_BAD_ACCESS occurs in the setOpenGLView method.
Code:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    
    
    CCDirector *director = [CCDirector sharedDirector];
    
    [director setDisplayFPS:YES];
    
    [director setOpenGLView:glView];
    
    [window setAcceptsMouseMovedEvents:NO];
    
    
    CCScene *scene = [CCScene node];
    [scene addChild: [nextAction() node]];
    
    [director runWithScene:scene];
}
I have not included [scene addChild: [nextAction() node]] for now, but that is not relevant as the problem occurs before it.
I defined glView as a MacGLView, like in ActionsTest.h.
What is the problem?
Even if someone helps me to solve this problem, could I also have an answer to the general question in the first post


RE: Last assembly function - szymczyk - Nov 21, 2010 12:57 PM

Miglu ' Wrote:  EXC_BAD_ACCESS occurs in the setOpenGLView method.
Code:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    
    
    CCDirector *director = [CCDirector sharedDirector];
    
    [director setDisplayFPS:YES];
    
    [director setOpenGLView:glView];
    
    [window setAcceptsMouseMovedEvents:NO];
    
    
    CCScene *scene = [CCScene node];
    [scene addChild: [nextAction() node]];
    
    [director runWithScene:scene];
}

What is the problem?
Even if someone helps me to solve this problem, could I also have an answer to the general question in the first post

The most likely cause of your crash is the variable glView is NULL. Set a breakpoint at the line where you call setOpenGLView and see what the value of glView is.

Accessing null pointers is a common cause of EXC_BAD_ACCESS errors along with accessing released Objective-C objects that zenkimoto mentioned. Use the call stack viewer in the debugger to find the method you called that caused the bad access. I hope that answers the general question in your first post.


RE: Last assembly function - arekkusu - Nov 21, 2010 01:00 PM

A crash in glEnable is probably because you have no current GL context.
For this particular crash, go to CCDirector.m:290 and before the GL call at that line, add:
printf("About to make an OpenGL call on ctx %p\n", CGLGetCurrentContext());


For the general case:
* "info registers" will show all registers.

* "disassemble" will show the asm of the entire current function, so you can see the instructions leading to the bad access.

* "po $eax" doesn't work because "po" prints Obj-C objects. You want "p $eax", or p $rax" for a 64-bit app. Really, "p/x" to print in hex and correlate to the disassembly.

* "help" for more commands in gdb.


RE: Last assembly function - zenkimoto - Nov 22, 2010 02:13 PM

@miglu

Are you trying to setup a Mac osx project with cocos2d? If so, there is a set of instructions on the cocos2d forum on how to set that up. Check out this link: http://chris-fletcher.com/2010/10/24/howto-create-a-cocos2d-mac-project/

Hope this helps.