How do I debug arm assembly instructions?

Source: Internet
Author: User

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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.