OpenOCD

September 20, 2016

Amazingly, this is available as a fedora package, so I just do:

dnf install openocd
Installing:
 hidapi                                     x86_64                     0.8.0-0.2.d17db57.fc24
 libftdi                                    x86_64                     1.2-8.fc24
 openocd                                    x86_64                     0.9.0-4.fc24
After doing this, I set up an "ocd" script with the following:
openocd -f /usr/share/openocd/scripts/interface/stlink-v2.cfg -f /usr/share/openocd/scripts/target/stm32f1x.cfg
I put this script into /home/tom/bin so I can start openOCD without having to remember impossible long things. There is a nice 172 page PDF user manual for OpenOCD.

What about gdb for ARM on Fedora?

We used to have a package for this (see below), but not for a long time. When it vanished, I looked into it, and apparently the guy who maintained the package for Fedora just no longer wanted to do it, so the package got dropped and that was that.

See my notes on this circa Fedora 37

Gdb for ARM on Fedora back in 2013 or so

On my fedora system, the available gcc and gdb packages look like so:
arm-none-eabi-gdb.x86_64                 7.6.2-4.fc24                   fedora  
arm-none-eabi-gcc-cs.x86_64              1:5.2.0-4.fc24                 fedora  
gcc-arm-linux-gnu.x86_64                 6.1.1-2.fc24                   updates 
So, I have two gcc choices and only one gdb choice. I wonder if that gdb will work with the gcc-arm-linux compiler I am using? Nothing like just diving in, so I install it and:
dnf install arm-none-eabi-gdb

ocd &
make gdb
arm-none-eabi-gdb --eval-command="target remote localhost:3333" blink.elf
GNU gdb (GDB) 7.6.2
Copyright (C) 2013 Free Software Foundation, Inc.
This GDB was configured as "--host=x86_64-unknown-linux-gnu --target=arm-none-eabi".
Reading symbols from /u1/Projects/STM32/Archive/blink1/blink.elf...(no debugging symbols found)...done.
Remote debugging using localhost:3333
0x00000000 in ?? ()
Note that I put the jive to start gdb into my makefile.

I find it useful to keep at least 3 windows open. One running OpenOCD, the other with a telnet to port 4444 to send commands directly to openocd, and another running gdb via port 3333. Maybe a fourth with vim showing the source code.

Also if you want to enjoy debuggine with gdb, compile with the -g flag.
And, if you forget the elf file at the end of the gdb line use "file blink.elf" to get the debug information.

gdbtui

Something called "gdbtui" is "text user interface", which is a text user interface on top of gdb. I was going to give up because there is no gdbtui package as such available on Fedora. But, it turns out you can get this via "gdb -tui" if you want to play with it. Alternately you can press C-x C-a after starting gdb. So it is a standard part of gdb, and pretty doggone nice.

Enter "layout asm" to make the upper window display assembly -- this will automatically follow your instruction pointer, although you can also change frames or scroll around while debugging. Press C-x s to enter SingleKey mode, where "run continue up down finish" etc. are abbreviated to a single key. This allows you to move quicky through your program.

s = step
n = next
c = continue
r = run
f = finish
d = down
u = up
w = where
v = info locals

Useful gdb commands

It isn't a gdb command, but just for the record, the openocd command to place an image in flash is:
flash write_image erase blink.bin 0x08000000
Note that for this to work, openocd itself must have been started in the same directory that contains the image.
i r -- shows the registers
stepi -- execute one assembly instruction
nexti -- as above, but a function call is executed until it returns
disas 0x50, 0x60 - disassemble from start to end
x/nfu 0x40 - examines memory
    n = how many
    f = format (usually x for hex), maybe x, i, s
    u = how big b, h, w, g are 1,2,4,8 byte objects
continue -- run to breakpoint (or forever)
    note that "reset halt" in openocd window will get control

Random stuff and possibly useful links


Feedback? Questions? Drop me a line!

Tom's Computer Info / tom@mmto.org