Learning In Arm assembly language , it is necessary to debug Arm assembly instructions. As a debugger that supports multiple languages,gdb is naturally a better choice. When the debugger works, it usually constructs the trap soft interrupt instruction by modifying the content of the code snippet , realizes the program's pause and the program execution state monitoring. In order to execute arm instructions on the x86 platform, you can use the QEMU emulator to perform arm assembly instructions, specific debugging methods, and take a look at it.
First, prepare ARM Assembler Program
First, we construct a simple The ARM assembler is main.s as a test code .
. globl _start
_start:
mov R0, #0
SWI 0x00900001
The assembly instruction above completes the call to exit 0 for system call . The MOV instruction passes the system call number to the register R0 andthen uses the 0x00900001 soft interrupt to fall into the system call.
in order to run ARM Assembly code requires the use of cross-compiler ARM-LINUX-GCC to compile the arm assembler code. After downloading the cross compiler installation, compile the ARM assembly code.
ARM-LINUX-GCC Main.s-o Main-nostdlib
The compile option "-nostdlib" means that no run-time library files are used, and the generated executables are compiled to run only on the ARM architecture's system.
Ii. Compiling and installing the QEMU simulator
in order to run an executable program of the ARM architecture within a x86 Linux system , you need to install the qemu emulator.
First Download the QEMU source code, and then make sure that the system already has Flex and Bison installed.
Compile and install qemu.
./configure--PREFIX=/USR
sudo make && make install
then use the QEMU arm emulator to execute the arm program.
Qemu./main
third, compile and install arm-gdb
in order to debug The ARM program needs to generate ARM-GDB using GDB 's source code compilation .
First Download the GDB source code, compile the installation.
./configure--target=arm-linux--prefix=/usr/local
sudo make && make install
to avoid conflicts with the system's gdb , we install the GDB installation directory to /usr/local andthen create a soft link.
Ln-s/usr/bin/arm-gdb/usr/local/gdb/gdb
you can then use the arm-gdb command to debug the arm program.
Four, commissioning ARM Program
First Use qemu to Open the remote debugging port.
Qemu-arm-g 1024x768/main.
then export the environment variables Qemu_gdb.
Export QEMU_GDB=/USR/LOCAL/GDB
Finally, go to gdb debugging.
Arm-gdb./main
After entering arm-gdb , connect the remote debugging port first.
(GDB) Target remote localhost:1024
then Debug the code with the debug commands commonly used by GDB.
(GDB) disassemble// View disassembly
(GDB) X/8xw 0x0000808e// View memory
(GDB) Info Register// View Register
(GDB) Continue// Continue execution
(GDB) Stepi// assembly step-by-process
(GDB) Nexti// assembly-level progressive statement
Article Source: Technical bit
How do I debug arm assembly instructions?