掌機 - Game & Watch: Super Mario Bros. - GDB Debug game-and-watch-retro-go



參考資料:
https://github.com/kbeckmann/game-and-watch-retro-go
https://github.com/ghidraninja/game-and-watch-flashloader
https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads

步驟如下:
1. 連接ST-LINK V2燒錄器到SWD腳位
2. 執行如下命令

$ sudo apt-get install gdb-multiarch -y
$ ln -s /usr/bin/gdb-multiarch /usr/bin/arm-none-eabi-gdb

$ cd
$ wget https://developer.arm.com/-/media/Files/downloads/gnu-rm/10-2020q4/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2
$ tar xvf gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2
$ sudo mv gcc-arm-none-eabi-10-2020-q4-major /opt
$ export PATH=/opt/gcc-arm-none-eabi-10-2020-q4-major/bin:$PATH

$ cd
$ git clone --recurse-submodules https://github.com/kbeckmann/game-and-watch-retro-go
$ cd game-and-watch-retro-go
$ make -j8 flash

$ vim main.cfg
    source [find interface/stlink.cfg]
    adapter speed 500
    transport select hla_swd
    source [find target/stm32h7x.cfg]
    reset_config none

$ openocd -f main.cfg -c "init; program build/gw_retro_go.elf; halt;"
    Open On-Chip Debugger 0.11.0-rc1+dev-00010-gc69b4deae-dirty (2020-12-27-01:20)
    Licensed under GNU GPL v2
    For bug reports, read
      http://openocd.org/doc/doxygen/bugs.html
    Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
    none separate

    Info : clock speed 1800 kHz
    Info : STLINK V2J17S4 (API v2) VID:PID 0483:3748
    Info : Target voltage: 3.198428
    Info : stm32h7x.cpu0: hardware has 8 breakpoints, 4 watchpoints
    Info : starting gdb server for stm32h7x.cpu0 on 3333
    Info : Listening on port 3333 for gdb connections
    target halted due to debug-request, current mode: Thread
    xPSR: 0x01000000 pc: 0x0800c180 msp: 0x20020000
    ** Programming Started **
    Info : Device: STM32H7Ax/7Bx
    Info : STM32H7 flash has dual banks
    Info : Bank (0) size is 1024 kb, base address is 0x08000000
    Info : Padding image section 1 at 0x0800faf4 with 12 bytes (bank write end alignment)
    Warn : Adding extra erase range, 0x0800fb00 .. 0x0800ffff
    Warn : no flash bank found for address 0x90000000
    Warn : no flash bank found for address 0x90000278
    Warn : no flash bank found for address 0x9008c000
    ** Programming Finished **
    Info : Listening on port 6666 for tcl connections
    Info : Listening on port 4444 for telnet connections

接著開啟另一個視窗並且輸入如下指令

$ arm-none-eabi-gdb build/gw_retro_go.elf

(gdb) target remote :3333
    Remote debugging using :3333
    Reset_Handler () at startup_stm32h7b0xx.s:62
    62	  ldr   sp, =_estack      /* set stack pointer */

(gdb) b main
    Breakpoint 1 at 0x800156c: file Core/Src/main.c, line 359.

(gdb) c
    Continuing.
    Note: automatically using hardware breakpoints for read-only addresses.

    Breakpoint 1, main () at Core/Src/main.c:359
    359	  for(int i = 0; i < 1000000; i++) {

(gdb) list
    354	int main(void)
    355	{
    356	  /* USER CODE BEGIN 1 */
    357	  uint8_t trigger_wdt_bsod = 0;
    358
    359	  for(int i = 0; i < 1000000; i++) {
    360	    __NOP();
    361	  }
    362
    363	  // Nullpointer redzone