Showing posts with label ubuntu. Show all posts
Showing posts with label ubuntu. Show all posts

Tuesday, August 2, 2011

Debugging ARM files with DDD (Simulation)

DDD is a graphical front-end to a variety of debuggers, including arm-elf-gdb.


Installation
In Ubuntu, install by running sudo apt-get install ddd 
For OS X, you can try your luck over here.
Usage
With the GNU ARM tools installed, in the terminal run ddd --debugger arm-elf-gdb &
Click File -> Open Program. Select your ELF file (that was assembled with --gdwarf2).
In the GDB console (the bottom pane), type
(gdb) target sim 
(gdb) load
(gdb) start 
You can view the registers by clicking Source -> Registers.
You can now step through the program, set breakpoints, and perform most other functions that GDB is capable of.


Monday, August 1, 2011

Debugging ARM files with arm-elf-gdb (Simulation)

First off, ensure you have downloaded the GNU ARM Toolchain, including the debugger (arm-elf-gdb). The following works beautifully in Ubuntu 10.04 (Lucid), and will work similarly under Cygwin.

We need an ARM assembly file. Here is one right here: flash-v1.s. (Note that the comments are preceded by @ symbols, not semicolons).

Create an executable file by following this post.


Life@Phi:$ make flash-v1.elf

arm-elf-as --gdwarf2 -mcpu=arm7tdmi -o flash-v1.o flash-v1.s
arm-elf-ld -o flash-v1.elf flash-v1.o
rm flash-v1.o


Open the ELF file with the debugger.

Life@Phi:$ arm-elf-gdb flash-v1.elf 
GNU gdb 6.8
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=arm-elf"...
(gdb) 
GDB can be used to step through programs loaded on microcontrollers (via JTAG, etc), but here we will only look at simulating hardware. To do this, we need to initiate the simulator:

(gdb) target sim 
Connected to the simulator.
Now we 'load' our ELF file in to our simulator.
(gdb) load

Loading section .text, size 0x1c vma 0x8000
Start address 0x8000

Notice that the start address corresponds to the _start variable set in flash-v1.s.
There are hundreds of commands available in GDB. This is by no means the only (or best) way to debug programs, but here we go. Right now the code is loaded in our simulator, and we need to start running it. start will run the program until it reaches the beginning of the main function. (Alternatively, run will run to program until it finds a breakpoint).
(gdb) start

Breakpoint 1 at 0x8004: file flash-v1.s, line 62.
Starting program: /your/directory/flash-v1.elf 
main () at flash-v1.s:62
62    mov r4, #LED_port       @ Load the address of the LED port
Current language:  auto; currently asm

All that extra information in there is due to the -gdwarf2 debugging flag used during assembly. Without this information, it can be extremely difficult to debug and follow along.
The instruction 'mov r4, #LED_port' is the next instruction to be executed (i.e. it has not been executed yet).

Now for a little bit of information gathering. Let's inspect the values at the registers:

(gdb) info registers 
r0             0x0 0
r1             0x0 0
r2             0x0 0
r3             0x0 0
r4             0x0 0
r5             0x0 0
r6             0x0 0
r7             0x0 0
r8             0x0 0
r9             0x0 0
r10            0x0 0
r11            0x0 0
r12            0x0 0
sp             0x800 0x800
lr             0x0 0
pc             0x8004 0x8004

fps            0x0 0
cpsr           0x13 19
Let's execute ONE instruction of our program.

(gdb) step
main_loop () at flash-v1.s:70
70    mov r5, #Value1         @ Load the value Value1 into R5

It is important to remember this will execute the previously listed instruction, 'mov r4, #LED_port', not the currently displayed instruction. We verify this by inspecting the registers again.


(gdb) info registers 
r0             0x0 0
r1             0x0 0
r2             0x0 0
r3             0x0 0
r4             0x10000000 268435456
r5             0x0 0
r6             0x0 0
r7             0x0 0
r8             0x0 0
r9             0x0 0
r10            0x0 0
r11            0x0 0
r12            0x0 0
sp             0x800 0x800
lr             0x0 0
pc             0x8008 0x8008
fps            0x0 0
cpsr           0x13 19


We can also examine (x) specific parts of memory.
(gdb) x 0x10000000
0x10000000: 0x00000000
(gdb) step
71    strb    r5, [r4]        @ and store this value (a byte) to
(gdb) step
76    mov r5, #Value2         @ Load the value Value2 into R5
(gdb) x 0x10000000
0x10000000: 0x000000ff

Notice how the value at 0x10000000 changes from 0x00 to 0xFF.

In summary, here are some of the important commands for gdb:
target [object/process, e.g. sim]
load
start
info registers
step
x [addr]
and I didn't mention it, but the invaluable help.

Sunday, July 31, 2011

Installing GNU ARM Toolchain (Ubuntu)

Installing the GNU ARM toolchain is a breeze in Debian/Ubuntu. Just fire up the terminal and enter the following three lines.
sudo add-apt-repository ppa:bdrung/bsprak
sudo apt-get update
sudo apt-get install arm-elf-toolchain
(From Benjamin Drung)

This will install all the tools you will need to assemble and link your ARM-based files. arm-elf-gdb is a GDB-based debugger that will let simulate an ARM microprocessor in which you can step through, and examine registers and memory.

If you want to install the toolchain on Windows or Mac OSX, head on over to http://www.gnuarm.com/files.html

Monday, May 3, 2010

Rhythmbox Notification - Currently Playing Song

I have been using Ubuntu for several years now, and love it. I have come across countless tidbits of useful information online that have saved hours of my life. I intend to use this blog as platform to document little tips and tricks that I have found useful. Today I will start with one of the simplest customisations for Ubuntu, suitable for the most novice of users.

Rhythmbox Notification on Key Press in Ubuntu 10.04 Lucid Lynx



I constantly listen to music while I am at my computer. And I'm lazy. So now, when a song is playing, and I want to know the name, artist, and album, I can click a single button on my keyboard, and I get the notification displayed above for several seconds.

Instructions

1. Select System -> Preferences -> Keyboard Shortcuts


2. Click Add.

3. Give the shortcut a name (e.g. 'Show Current Song').

4. In the Command field, type 'rhythmbox-client --notify' (without the quotation marks).

5. Click Apply.

6. Click the newly created shortcut shortcut (currently 'Disabled'),and click the keyboard combination you want to trigger the notification. I have used the Pause/Break key, simply because it is near my media controls and my keyboard, and I have no other use for it. The final result should appear somewhat like the image below. Play a song in Rhythmbox, and try out your new keyboard shortcut!


[Note: If Rhythmbox is not open when the action is triggered, it will open the media player, and not play a song.]

Hopefully this will give you a simple introduction to the keyboard shortcuts in Ubuntu. Any terminal command can be bound to a key combination. For more Rhythmbox commands, type 'rhythmbox-client --help' in a terminal. For example, you could bind ctrl+shift+5 to 'rhythmbox-client --set-rating 5' to set the current song rating to 5 stars.