tags:

views:

358

answers:

3

This is definitely obsessive, but I am fascinated by how cleverly the compiler translates C code into machine instructions. Since I am a little fuzzy on some instructions, it would be helpful if I could watch the operation of a compiled program at the level of individual machine instructions - "below" the level of a C statement (which might generate several CPU instructions). In other words, can I watch the registers/memory change after a single machine instruction?

I'm sure it's possible with some other debuggers, but I am only using Xcode.

+1  A: 

In the Debugger window, enable assembly: Run/Debugger display/Source and disassembly. Wait till you hit a breakpoint. Then use Run/Step into(over) instruction to step in assembly.

Seva Alekseyev
Thanks - I had the 'Step Into', but overlooked the OPTION key for machine level steps
gary
A: 

Ooops, didn't check closely enough - Step Into w/Option (Cmd-Opt-Shft-I = ⌘⌥⇧I)

gary
+1  A: 

si is "Step Instruction", and ni is "Next Instruction". They have the same semantics as "step" and "next" do for lines of code, just on the instruction level.

Dave DeLong
That sounds like gdb - can I do that from XCode?
gary
shift-cmd-R brings up the console window, where (once you break) you get a standard GDB prompt. Also, it looks like the Run menu has a "Step Into Instruction" item (opt-shift-cmd-I) and a "Step Over Instruction" item (opt-shift-cmd-O).
Dave DeLong
that's a capital "I" (as in "Indigo"), not a lower-case "L".
Dave DeLong