ARM simulation using GDB

arm-elf-GDB is the debugger that helps to simulate ARM processor.

Prerequisites:
-install arm-elf-gcc toolchain
-compile your source code with -g option turned on.

Lets us assume your output elf file is main.elf. Type the following command in the terminal to open GDB.

arm-elf-gdb main.elf

It brings up the gdb prompt. These commands initialises the gdb environment.

target sim
load

The first statement tells gdb that we are going to simulate ARM processor. Second line tells it to load the current ELF(main.elf) file into memory. Next step is to create some breakpoints and run the code.

From Wikipedia:-
(Note:- A breakpoint, in software development, is an intentional stopping or pausing place in a program, put in place for debugging purposes.)

You can set breakpoint at a particular function, line number, address or offset.
Syntax:

break *address

  • sets breakpoint at particular address

break function

  • sets breakpoint at function

break filename:line_number

  • sets breakpoint at line number of a specified file

break +offset
break -offset

  • Set breakpoint some number of lines forward or back from the position at which execution stopped in the currently selected stack frame.

After you have set the breakpoints. Run the debugger using

run

Notice that debugger stops at the places you have set breakpoints. Now you can inspect the registers and memory using these commands.

info reg

  • displays register information

x /5xw 0x00000800

  • this displays memory starting at address(0x00000800). The /5xw instructs gdb to show 5 memory locations, each of length words and represented in hexadecimal. Use d instead of x to display in decimal. h or b instead of w to display in half-word or byte length.

After you have finished inspecting, you can either continue execution or step through each instruction or statement.

si

  • steps through each instruction.

next

  • steps through each statement. if it finds a function call, it will step over the function to the next line of code

step

  • steps thought each statement. if it find a function call, it will go into the function call.

continue

  • continues debugging until next breakpoint is reached.

tejainece

Ravi Teja is a technology entrepreneur with interest in Embedded Systems, Software engineering, Operating Systems, Web development, Cloud computing, Machine learning, etc.

More Posts - Website

Follow Me:
LinkedInGoogle Plus