ARM Assembly command debugging method

Source: Internet
Author: User

ARM Assembly command debugging method
When learning ARM assembly, you must debug ARM Assembly commands. As a multi-language debugger, gdb is naturally a good choice. When the debugger is working, it generally constructs the trap Soft Interrupt command by modifying the content of the Code segment to monitor the program pause and program execution status. To execute ARM commands on the x86 platform, you can use the qemu simulator to execute ARM Assembly commands. I. Prepare the ARM assembler. First, we construct a simple ARM assembler as the test code main. s.. Globl _ start_start: mov R0, # 0swi 0x00900001 and above Assembly commands have completed the call of exit by system call no. 0. The mov command passes the system call number into the registers R0, and then uses 0x00900001 Soft Interrupt into the system call. To run ARM assembly code, you must use the cross compiler arm-linux-gcc to compile ARM assembly code. After installing the cross-compiler, compile the ARM assembly code. Arm-linux-gcc main. the "-nostdlib" Compilation option of s-o main-nostdlib indicates that no Runtime Library file is used. The compiled Executable File main can only run on the System of the ARM architecture. 2. Compile and install the qemu simulator. To run the executable program of the ARM architecture in x86 Linux system, the qemu simulator must be installed. First download the qemu source code, and then ensure that the system has installed flex and bison. Compile and install qemu. ./Configure -- prefix =/usrsudo make & make install and then run the ARM program using the qemu ARM Simulator. Qemu./main 3. Compile and install arm-gdb to debug the ARM program, generate arm-gdb using gdb source code compilation. First download the gdb source code, compile and install it.. /Configure -- target = arm-linux -- prefix =/usr/localsudo make & make install to avoid conflicts with the system's gdb, install the gdb installation directory to/usr/local and then create a soft link. After ln-s/usr/bin/arm-gdb/usr/local/gdb, you can use the arm-gdb command to debug the ARM program. 4. debug the ARM program by using qemu to open the remote debugging port. Qemu-arm-g 1024./main and then export the environment variable QEMU_GDB. Export QEMU_GDB =/usr/local/gdb and start gdb debugging. After entering arm-gdb./main, connect to the remote debugging port. (Gdb) target remote localhost: 1024 and then use the common Debugging commands of gdb to debug the code. (Gdb) disassemble // view disassembly (gdb) x/8xw 0x0000808e // view memory (gdb) info register // view register (gdb) continue // continue execution (gdb) stepi // assembly-level by-process (gdb) nexti // assembly-level by-Statement

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.