1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

How do I interpret error code from gdb?

Discussion in 'Mac Programming' started by dancks, Dec 10, 2011.

  1. macrumors member

    dancks

    #1
    So I'm debugging a C++ program I wrote using game library allegro. I fixed a problem with returning a pointer from a function, recompiled, retested, and I got the following from GDB:
    Code:
    ****** malloc error repeated 1000 times ******
    p9rev6(6901,0xb00a1000) malloc: *** error for object 0xfa910b88: Non-aligned pointer being freed
    *** set a breakpoint in malloc_error_break to debug
    p9rev6(6901,0xb00a1000) malloc: *** error for object 0x3376a0: double free
    *** set a breakpoint in malloc_error_break to debug
    
    Program received signal EXC_BAD_ACCESS, Could not access memory.
    Reason: KERN_INVALID_ADDRESS at address: 0xc0000023
    0x91c79688 in objc_msgSend ()
    (gdb) backtrace
    #0  0x91c79688 in objc_msgSend ()
    #1  0x96f5b38a in CFRelease ()
    #2  0x90b8d866 in ReleaseEvent ()
    #3  0x910d280c in -[NSEvent dealloc] ()
    #4  0x95ff444f in NSPopAutoreleasePool ()
    #5  0x0020e929 in osx_event_handler ()
    Cannot access memory at address 0x2ff
    (gdb) x/i $pc
    0x91c79688 <objc_msgSend+24>:	mov    0x20(%edx),%edi
    (gdb) p/x $edx
    $1 = 0xc0000003
    (gdb) p/x $edi
    $2 = 0x3473f0
    (gdb) 
    
    ok so its a segmentation fault, so I should be looking for an out of bounds array call or write-to?
     
  2. macrumors 68040

    lee1210

    #2
    I'd guess you returned the value 35 cast to some sort of pointer, then tried to dereference. Never cast another primitive to a pointer. You can get a pointer with & or get a pointer to some new memory with malloc.

    -Lee
     
  3. macrumors 68030

    jared_kipe

    #3
    I would have guessed that that the NSAutoReleasePool tried to release an object that has already been dealloc'd.

    Hence the stack trace, and double free.

    I see the 35 (0x23) but there is also a 0xc0 in the highest order byte of that address. So I'm not so sure about dereferencing an ints value...
     
  4. macrumors 68040

    lee1210

    #4
    Oops. The tiny text on my phone (with no retina display) made it look like all 0s then 23.

    -Lee
     

Share This Page