Learning ARM assembly time, and ultimately, for debugging ARM assembly instructions. As a multi-language debugger, gdb nature is a better choice. The debugger work, generally by modifying the contents of the code segment structure trap soft interrupt instruction, and implement procedures to suspend the monitor program execution state. To execute ARM instruction on the x86 platform, you can use qemu emulator executing ARM assembly instructions.
First, prepare ARM assembler
First, we construct a simple piece of ARM assembler program as a test code main.s.
mov R0, # 0
Above assembly instructions to complete the exit system call 0 calls. mov instruction system calls incoming register R0, then use 0x00900001 into soft interrupt system calls.
To run the ARM assembly code, you need to use a cross compiler arm-linux-gcc compiler for ARM assembly code. After downloading cross compiler installed on ARM assembly code to compile.
arm-linux-gcc main.s -o main -nostdlib
Compile option "-nostdlib" said they did not use any run-time library files, compiled executable file can only be run on the main system ARM architecture.
Second, compile and install qemu emulator
To run the ARM architecture executable within an x86 Linux system, you need to install qemu emulator.
First, download the source code qemu, and then ensure that the system has been installed flex and bison.
Compile and install qemu.
./configure --prefix = / usr
sudo make && make install
Then use the qemu emulator for ARM ARM program execution.
Third, compile and install arm-gdb
To debug ARM program, you need to use the source code to compile gdb generation arm-gdb.
First, download the gdb source code, compile and install.
./configure --target = arm-linux --prefix = / usr / local
sudo make && make install
In order to avoid conflicts and gdb system, we will install gdb installation directory to / usr / local, and then create a soft link.
ln -s / usr / bin / arm-gdb / usr / local / gdb / gdb
Then you can use arm-gdb debugger command ARM program.
Fourth, the program debugging ARM
The first to use qemu turn on remote debugging port.
qemu-arm -g 1024 ./main
And then export the environment variable QEMU_GDB.
export QEMU_GDB = / usr / local / gdb
Finally, enter the gdb debugger.
After entering arm-gdb, first connect remote debugging port.
(Gdb) target remote localhost: 1024
Then use the usual gdb debugging commands to debug code.
(Gdb) disassemble // View Disassembly
(Gdb) x / 8xw 0x0000808e // Check memory
(Gdb) info register // View register
(Gdb) continue // continue
(Gdb) stepi // assembly-level process by
(Gdb) nexti // assembly-level statements by