Debugging code written in assembly with Xcode

Discussion in 'Mac Programming' started by noexcuse4you, Feb 25, 2010.

  1. noexcuse4you macrumors newbie

    Joined:
    Feb 25, 2010
    #1
    I have a program written in C calling a function written in assembly. When I run the debugger, I can step through the C code just fine, but then when it reaches the function, it won't step through the assembly code. It'll just go on to the next statement. In the assembly viewer I see:

    call 0x1eda <isgreater>

    and then the rest of the main function after that. How do I view the function isgreater?

    My professor uses the Eclipse IDE and it can do it just fine. I'd rather use the Xcode IDE as Eclipse is very buggy.

    Thanks!
    Kyle.
     
  2. noexcuse4you thread starter macrumors newbie

    Joined:
    Feb 25, 2010
    #2
    I thought I would update this in case anyone else runs into this problem. If you go to Run > Debugger Display > Disassembly Only, it'll step into the function. It won't work in the Source and Disassembly view.

    Kyle.
     
  3. mike619 macrumors newbie

    Joined:
    Jan 28, 2010
    #3
    Would you mind putting up your code?
    I'm running into the same problem right now.
     
  4. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #4
    You just need to press "Step Into" rather than "Step Over" and it will enter the function. You can do this for any function as well, not just ones written in assembly.
     
  5. noexcuse4you thread starter macrumors newbie

    Joined:
    Feb 25, 2010
    #5
    Step Into won't enter the function written in assembly in the Source and Assembly View. It'll only work in Assembly Only.
     
  6. noexcuse4you thread starter macrumors newbie

    Joined:
    Feb 25, 2010
    #6
    #include <stdio.h>
    #include <stdlib.h>

    /*void endianSwap(unsigned int *x)
    {
    *x = (*x>>24) |
    ((*x<<8) & 0x00FF0000) |
    ((*x>>8) & 0x0000FF00) |
    (*x<<24);
    }*/


    int main(void)
    {
    unsigned int x = 0x01020304;
    printf("%x",x);
    endianSwap(&x);
    printf("%x",x);

    return EXIT_SUCCESS;
    }

    -------------------
    In a separate file
    -------------------

    .globl _endianSwap
    _endianSwap:
    pushl %ebp
    movl %esp, %ebp

    movl 8(%ebp), %eax //copies x to eax
    movl (%eax), %eax //copies address of x to eax
    movl %eax, %ecx //copies address of x to ecx
    movl %eax, %edx //copies address of x to edx

    shrl $24, %edx //shifts address of x 24 bits right stores in edx

    shll $8, %ecx //shifts address of x 8 bits left stores in ecx
    andl $0x00FF0000, %ecx // ands it with 0x00FF0000
    orl %ecx, %edx //ecx or edx - stores in edx

    movl %eax, %ecx //recopies address of x to ecx
    shrl $8, %ecx //shifts address of x 8 bits right stores in ecx
    andl $0x0000FF00, %ecx //ands it with 0x0000FF00
    orl %ecx, %edx //ecx or edx - stores in edx

    movl %eax, %ecx //recopies address of x to ecx
    shll $24, %ecx //shifts address of x 24 bits left stores in ecx
    orl %ecx, %edx //ecx or edx - stores in edx

    movl 8(%ebp), %eax //recopies x to eax
    movl %edx, (%eax) //moves new address of x to old address of x

    popl %ebp
    ret
     
  7. mike619 macrumors newbie

    Joined:
    Jan 28, 2010
    #7
    How exactly does one go about actually running the above code in Xcode?
     

Share This Page