Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any assembly language debugger for OS X?

So i was wondering if there is any? I know afd on windows but not sure anything about mac?

And this his how i am using nasam on the following code: nasm a.asm -o a.com -l a.lst

[org 0x100]
mov ax, 5
mov bx, 10
add ax, bx
mov bx, 15
add ax, bx
mov ax, 0x4c00
int 0x21 

On windows i know a debugger name afd which help me to step through each statement but not sure how i can do this using gdb.

And neither i am able to execute this .com file, am i supposed to make some other file here?

like image 206
itsaboutcode Avatar asked Dec 01 '22 06:12

itsaboutcode


2 Answers

Why are you writing 16-bit code that makes DOS syscalls? If you want to know how to write asm that's applicable to your OS, take a look the code generated by "gcc -S" on some C code... (Note that code generated this way will have operands reversed, and is meant to be assembled with as instead of nasm)

Further, are you aware what this code is doing? It reads to me like this:

ax = 5
bx = 10
ax += bx
bx = 15
ax += bx
ax = 0x4c00
int 21h

Seems like this code is equivalent to:

mov bx, 15
mov ax, 4c00
int 21h

Which according to what I see here, is exit(0). You didn't need to change bx either...

But. This doesn't even apply to what you were trying to do, because Mac OS X is not MS-DOS, does not know about DOS APIs, cannot run .COM files, etc. I wasn't even aware that it can run 16 bit code. You will want to look at nasm's -f elf option, and you will want to use registers like eax rather than ax.

I've not done assembly programming on OS X, but you could theoretically do something like this:

extern exit
global main
main:
    push dword 0
    call exit

    ; This will never get called, but hey...
    add esp, 4
    xor eax, eax
    ret

Then:

nasm -f elf foo.asm -o foo.o
ld -o foo foo.o -lc

Of course this is relying on the C library, which you might not want to do. I've omitted the "full" version because I don't know what the syscall interface looks like on Mac. On many platforms your entry point is the symbol _start and you do syscalls with int 80h or sysenter.

As for debugging... I would also suggest GDB. You can advance by a single instruction with stepi, and the info registers command will dump register state. The disassemble command is also helpful.

Update: Just remembered, I don't think Mac OS X uses ELF... Well.. Much of what I wrote still applies. :-)

like image 142
asveikau Avatar answered Dec 09 '22 12:12

asveikau


Xcode ships with GDB, the GNU Debugger.
Xcode 4 and newer ships with LLDB instead.

like image 43
Tamas Czinege Avatar answered Dec 09 '22 11:12

Tamas Czinege