sobota 11. května 2019

Pokračování s GDB


C:\Users\Jenda\Documents\ARM_GCC_Tools\bin>arm-none-eabi-gdb.exe "C:\Users\Jenda\Documents\STM32\STM32L1\Debug test\Debug\Debug test.elf"
C:\Users\Jenda\Documents\ARM_GCC_Tools\bin\arm-none-eabi-gdb.exe: warning: Couldn't determine a path for the index cache directory.
GNU gdb (GNU Tools for Arm Embedded Processors 8-2018-q4-major) 8.2.50.20181213-git
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
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=i686-w64-mingw32 --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from C:\Users\Jenda\Documents\STM32\STM32L1\Debug test\Debug\Debug test.elf...
 (gdb) target remote localhost:3333    # připojení k OpenOCD
Remote debugging using localhost:3333
0x00000000 in ?? ()
(gdb) load                              # nahrání proramu na MCU
Loading section .isr_vector, size 0x13c lma 0x8000000
Loading section .text, size 0x1474 lma 0x800013c
Loading section .rodata, size 0x1c lma 0x80015b0
Loading section .init_array, size 0x4 lma 0x80015cc
Loading section .fini_array, size 0x4 lma 0x80015d0
Loading section .data, size 0xc lma 0x80015d4
Start address 0x80014f4, load size 5600
Transfer rate: 5 KB/sec, 933 bytes/write.
(gdb) monitor reset halt               # zastavení MCU
Unable to match requested speed 300 kHz, using 240 kHz
Unable to match requested speed 300 kHz, using 240 kHz
adapter speed: 240 kHz
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x080014f4 msp: 0x20004000
(gdb) l                                # zobrazení zdrojového kódu
warning: Source file is more recent than executable.
62      /**
63        * @brief  The application entry point.
64        * @retval int
65        */
66      int main(void)
67      {
68        /* USER CODE BEGIN 1 */
69
70        /* USER CODE END 1 */
71
(gdb) l 95                             # zobrazení zdrojového kódu od řádky 85
90        MX_GPIO_Init();
91        /* USER CODE BEGIN 2 */
92        volatile char array[10];
93        array[0] = 'a';
94        array[1] = 'b';
95        //array[25] = 'x';
96        array[2] = 'c';
97        array[3] = 'd';
98
99        for (int i = 8; i<10; i++) array[i] = i;
(gdb) b 97                             # přidání breakpointu na řádek 97
Breakpoint 1 at 0x8001242: file ..\Src\main.c, line 97.
(gdb) c                                # pokračování běhu programu
Continuing.
Note: automatically using hardware breakpoints for read-only addresses.

Breakpoint 1, main () at ..\Src\main.c:97    # běh se zastavil na bteakpointu
97        array[3] = 'd';
(gdb) c
Continuing.

Program received signal SIGINT, Interrupt.
HAL_GPIO_ReadPin (GPIOx=0x40020000, GPIO_Pin=1) at ..\Drivers\STM32L1xx_HAL_Driver\Src\stm32l1xx_hal_gpio.c:401
401     }
(gdb) c
Continuing.

Program received signal SIGINT, Interrupt.
0x0800076e in HAL_GPIO_ReadPin (GPIOx=0x40020000, GPIO_Pin=1) at ..\Drivers\STM32L1xx_HAL_Driver\Src\stm32l1xx_hal_gpio.c:392
392       if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)GPIO_PIN_RESET)
(gdb) c
Continuing.

Program received signal SIGINT, Interrupt.
0x08000764 in HAL_GPIO_ReadPin (GPIOx=0x40020000, GPIO_Pin=1) at ..\Drivers\STM32L1xx_HAL_Driver\Src\stm32l1xx_hal_gpio.c:386
386     {
(gdb) c
Continuing.

Program received signal SIGINT, Interrupt.
0x08000782 in HAL_GPIO_ReadPin (GPIOx=0x40020000, GPIO_Pin=1) at ..\Drivers\STM32L1xx_HAL_Driver\Src\stm32l1xx_hal_gpio.c:401
401     }
(gdb) disas main          # disassemblování funkce main
Dump of assembler code for function main:
   0x08001224 <+0>:     push    {r7, lr}
   0x08001226 <+2>:     sub     sp, #16
   0x08001228 <+4>:     add     r7, sp, #0
   0x0800122a <+6>:     bl      0x800017c <HAL_Init>
   0x0800122e <+10>:    bl      0x80012a0 <SystemClock_Config>
   0x08001232 <+14>:    bl      0x800132c <MX_GPIO_Init>
   0x08001236 <+18>:    movs    r3, #97 ; 0x61
   0x08001238 <+20>:    strb    r3, [r7, #0]
   0x0800123a <+22>:    movs    r3, #98 ; 0x62
   0x0800123c <+24>:    strb    r3, [r7, #1]
   0x0800123e <+26>:    movs    r3, #99 ; 0x63
   0x08001240 <+28>:    strb    r3, [r7, #2]
=> 0x08001242 <+30>:    movs    r3, #100        ; 0x64
   0x08001244 <+32>:    strb    r3, [r7, #3]
   0x08001246 <+34>:    movs    r3, #8
   0x08001248 <+36>:    str     r3, [r7, #12]
   0x0800124a <+38>:    b.n     0x8001260 <main+60>
   0x0800124c <+40>:    ldr     r3, [r7, #12]
   0x0800124e <+42>:    uxtb    r1, r3
   0x08001250 <+44>:    mov     r2, r7
   0x08001252 <+46>:    ldr     r3, [r7, #12]
   0x08001254 <+48>:    add     r3, r2
   0x08001256 <+50>:    mov     r2, r1
   0x08001258 <+52>:    strb    r2, [r3, #0]
   0x0800125a <+54>:    ldr     r3, [r7, #12]
   0x0800125c <+56>:    adds    r3, #1
   0x0800125e <+58>:    str     r3, [r7, #12]
   0x08001260 <+60>:    ldr     r3, [r7, #12]
   0x08001262 <+62>:    cmp     r3, #11
   0x08001264 <+64>:    ble.n   0x800124c <main+40>
   0x08001266 <+66>:    movs    r1, #1
   0x08001268 <+68>:    ldr     r0, [pc, #44]   ; (0x8001298 <main+116>)
   0x0800126a <+70>:    bl      0x800075c <HAL_GPIO_ReadPin>
   0x0800126e <+74>:    mov     r3, r0
   0x08001270 <+76>:    cmp     r3, #1
   0x08001272 <+78>:    bne.n   0x8001266 <main+66>
   0x08001274 <+80>:    movs    r2, #0
   0x08001276 <+82>:    movs    r1, #64 ; 0x40
   0x08001278 <+84>:    ldr     r0, [pc, #32]   ; (0x800129c <main+120>)
   0x0800127a <+86>:    bl      0x800078a <HAL_GPIO_WritePin>
   0x0800127e <+90>:    movs    r0, #200        ; 0xc8
   0x08001280 <+92>:    bl      0x8000258 <HAL_Delay>
   0x08001284 <+96>:    movs    r2, #1
   0x08001286 <+98>:    movs    r1, #64 ; 0x40
   0x08001288 <+100>:   ldr     r0, [pc, #16]   ; (0x800129c <main+120>)
   0x0800128a <+102>:   bl      0x800078a <HAL_GPIO_WritePin>
   0x0800128e <+106>:   movs    r0, #200        ; 0xc8
--Type <RET> for more, q to quit, c to continue without paging--
   0x08001290 <+108>:   bl      0x8000258 <HAL_Delay>
   0x08001294 <+112>:   b.n     0x8001266 <main+66>
   0x08001296 <+114>:   nop
   0x08001298 <+116>:   movs    r0, r0
   0x0800129a <+118>:   ands    r2, r0
   0x0800129c <+120>:   lsls    r0, r0, #16
   0x0800129e <+122>:   ands    r2, r0
End of assembler dump.
(gdb) jump *0x80000  # spuštění kódu od adresy 0x80000

Continuing at 0x80000.
(gdb) i b                        # výpis aktivních breakpointů
Num     Type           Disp Enb Address    What
1       breakpoint     keep y   0x08001236 in main at ..\Src\main.c:93
        breakpoint already hit 1 time
2       breakpoint     keep y   0x08001242 in main at ..\Src\main.c:97
        breakpoint already hit 1 time

(gdb) c
Continuing.

Program received signal SIGINT, Interrupt.
0x08001270 in main () at ..\Src\main.c:110
110         /* USER CODE END WHILE */
(gdb) q
A debugging session is active.

        Inferior 1 [Remote target] will be detached.

Quit anyway? (y or n) y

Další zajímavostí je možnost tvorby vlastního skriptu:
(gdb) define hexdump
Type commands for definition of "hexdump".
End with a line saying just "end".
>dump binary memory dump.bin $arg0 $arg0+$arg1
>shell hexdump dump.bin -C
>end
(gdb) 
(gdb) hexdump 0x80000 0x100
00000000  a1 00 38 d5 21 04 40 92  61 00 00 b4 5f 20 03 d5  |..8.!.@.a..._ ..|
00000010  ff ff ff 17 61 01 00 58  3f 00 00 91 61 01 00 58  |....a..X?...a..X|
00000020  e2 00 00 18 82 00 00 34  3f 84 00 f8 42 04 00 51  |.......4?...B..Q|
00000030  a2 ff ff 35 07 00 00 94  f5 ff ff 17 02 00 00 00  |...5............|
00000040  00 00 08 00 00 00 00 00  60 02 08 00 00 00 00 00  |........`.......|
00000050  fd 7b bf a9 fd 03 00 91  08 00 00 94 00 00 00 90  |.{..............|
00000060  00 a0 08 91 5b 00 00 94  00 00 00 90 00 80 09 91  |....[...........|
00000070  58 00 00 94 00 00 00 14  f3 0f 1f f8 80 00 8a d2  |X...............|
00000080  20 e4 a7 f2 01 00 40 b9  80 00 8a d2 20 e4 a7 f2  | .....@..... ...|
00000090  21 00 00 32 01 00 00 b9  00 0c 8a d2 20 e4 a7 f2  |!..2........ ...|
000000a0  1f 00 00 b9 80 09 8a d2  20 e4 a7 f2 61 00 80 52  |........ ...a..R|
000000b0  01 00 00 b9 00 0a 8a d2  20 e4 a7 f2 1f 00 00 b9  |........ .......|
000000c0  80 08 8a d2 20 e4 a7 f2  1f 00 00 b9 00 09 8a d2  |.... ...........|
000000d0  20 e4 a7 f2 c1 18 80 52  01 00 00 b9 00 0d 8a d2  | ......R........|
000000e0  20 e4 a7 f2 c1 21 80 52  01 00 00 b9 80 00 80 d2  | ....!.R........|
000000f0  00 e4 a7 f2 13 00 40 b9  73 66 0e 12 00 00 84 52  |......@.sf.....R|
00000100


https://stackoverflow.com/questions/9233095/memory-dump-formatted-like-xxd-from-gdb

Žádné komentáře:

Okomentovat