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

debugging ppc on i386 w/xcode 3

Discussion in 'Mac Programming' started by Amdahl, Feb 21, 2008.

  1. macrumors 65816

    I've got Xcode 3 on MBP. I was able to compile a ppc-only console app by using vi to edit the project file and specify ppc as the arch. (Instead of the NATIVE_ARCH).

    The app runs correctly, so I believe it is built properly.

    Can gdb be used either in Xcode or terminal to debug a ppc-only app on an i386 platform?

    The gdb takes parameters that would make it appear this is possible (--translate & -arch), but when I try, I get some bizarre errors from gdb as the program starts running, and it then hangs and has to be killed.

    I'm doing: gdb --translate -arch=ppc myprog

    Any comments appreciated.
  2. macrumors 68020


    First off, you don't need to edit the project file by hand like that. There is a build option in XCode (2 & 3) that lets you specify the build architectures.

    Secondly, the easiest way to find out if it works is to setup the arch in XCode, clean the project, and then build it. Set a breakpoint, kick off the app and see if it breaks on the breakpoint.
  3. macrumors 65816

    I guess I should have explained. Xcode 3 GUI appears to be incapable of setting a project to build to only the opposite architecture. Try it yourself. I'm using a command-line project template.

    It doesn't even start running in gdb. It says Bad CPU type in executable. Perhaps I need to edit something else in the project? But in any case, I still can't seem to get it to work in gdb from command line, while the parameters seem to indicate it should work. It actually starts as a PPC app, but it craps out with some bizarre errors.
    warning: error on line 139 of "/SourceCache/gdb/gdb-768/src/gdb/macosx/macosx-nat-infthread.c" in function "modify_trace_bit": (os/kern) invalid argument (0x4x)
    warning: error on line 233 of "/SourceCache/gdb/gdb-768/src/gdb/macosx/macosx-nat-infthread.c" in function "prepare_threads_after_stop": (os/kern) invalid argument (0x4x)
    Error calling thread_get_state for GP registers for thread 0x15635lxerror on line 81 of "/SourceCache/gdb/gdb-768/src/gdb/macosx/ppc-macosx-nat-exec.c" in function "fetch_inferior_registers": (os/kern) invalid argument (0x4)
  4. macrumors 68020


    I just did it with an Obj-C template. You do have to be building and editing the same configuration, however.

    I was unable to debug a PPC-only binary using XCode, so the odds are that any debugger support for it is incomplete.

    My next question is: Why do you need to debug a PPC-only binary on an x86? Are you running into a PPC-only bug?
  5. macrumors 65816

    You got it to show just "ppc" under the "Architectures" setting?

    I'm working on PPC optimization for a program with asm. I usually am working on a G5, but my only laptop is x86. It would be nice to be able to work on it there, even if it is emulation. I'll try Xcode 2.4 on Tiger/x86 in the next couple of days and see if it works.
  6. macrumors 65816

    I just downloaded Xcode 2.5 and installed on Tiger/x86. Xcode 2.5 does not have the bug that prevents building PPC only.

    But the debugger doesn't work on it, either in Xcode or command line. It gives roughly the same error. Oh well. Guess you need a PPC to debug for PPC.
  7. macrumors 68020


    There is the option to do remote debugging (I believe), but that probably won't work in your case.

    In any case, trying to do PPC optimization using an emulator is not going to give you a lot of accurate data. The sort of optimizations that help PPC code run faster on x86 don't always apply for live PPC processors.

Share This Page