Try   HackMD

gdb Introduction and openocd

tags: 2022/12 gdb

(2022/12/29) Following QEMU simulation for hardware boards, created another article to collect everything related to gdb. Can refer to another article, QEMU simulation with hardware boards, which provides examples related to qemu, gdb, and openocd.
latest update on 2022/12/29


Table of Contents


gdb Introduction

gdb related documents

  • gdb official documents
  • gdb popluar commands and usages
    • (gdb) target extended-remote localhost:3333 : connect to gdbserver. From previous example, when we launch openocd, the system output Info : starting gdb server for stm32f1x.cpu on 3333 Info : Listening on port 3333 for gdb connections, showing it starts a gdb server on port 3333. (since we use the same PC, so localhost is used, instead of specific ip address. And localhost can be omitted.)
    • (gdb) disconnect : to disconntect from gdb server.
    • (gdb) monitor reset init : Reset and intialize the target hardware.
    • (gdb) run or r : Run the program continueously from the beginning. To stop, press CTRL-c.
    • (gdb) Continue or c : Continue the program continueously from where it stopped. To stop, press CTRL-c.
    • (gdb) Next or n: Next step by sept to execute the program per line instruction. Complete the subroutine if next instruction is a subroutine.
    • (gdb) Step or s: Step by step to execute the program per line instruction. Step into the subroutine if if next instruction is a subroutine.
    • monitor command in gdb is a magic command. You can use the monitor command to send special requests to gdbserver.
      • (gdb) monitor help : This is a gdb command to list the openocd commands supported. More details in next section of openocd.
  • gdb examples

openocd Related Documents

  • openocd official documents
  • openocd popular commands and usage
    • monitor command in gdb is a magic command, which was introduced at previous gdb section. Can use monitor + openocd commands to control openocd and target hardware in gdb.
      • (gdb) monitor help : This is a gdb command to list the openocd commands supported.
      • (gdb) monitor reset {run, halt, init} : Reset the hardware target, then take next action of run (run the program), halt (halt the CPU), init (Initialize the target hardware system).
      • (gdb) monitor soft_reset_halt: Requesting target halt and executing a soft reset. This is often used when a target cannot be reset and halted. The target, after reset is released begins to execute code. OpenOCD attempts to stop the CPU and then sets the program counter back to the reset vector. Unfortunately the code that was executed may have left the hardware in an unknown state.
      • (gdb) monitor flash help to know more flash command provided by target hardware about OpenOCD flash commands.
        • OpenOCD has different commands for NOR and NAND flash; the “flash” command works with NOR flash, while the “nand” command works with NAND flash. This partially reflects different hardware technologies: NOR flash usually supports direct CPU instruction and data bus access, while data from a NAND flash must be copied to memory before it can be used. (SPI flash must also be copied to memory before use.) However, the documentation also uses “flash” as a generic term; for example, “Put flash configuration in board-specific files”.
  • openocd + gdb examples

gdb - One Page gdb commands

A : Debugging with GDB - the GNU debugger GDB Tenth Edition: the GNU Source-Level Debugger for GDB Version 14.0.50.20230124-git.


gdb - Debugging multithreaded programs in GDB

A : Debugging multithreaded programs in GDB


References


Previous article - QEMU simulation with hardware boards
Next article - back to marconi's blog
back to marconi's blog