Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

st-util: wrong register values passed to gdb (st-link v2) #1026

Closed
arsv opened this issue Sep 9, 2020 · 0 comments · Fixed by #1027
Closed

st-util: wrong register values passed to gdb (st-link v2) #1026

arsv opened this issue Sep 9, 2020 · 0 comments · Fixed by #1027

Comments

@arsv
Copy link
Contributor

arsv commented Sep 9, 2020

  • Programmer/board type: Stlink v2 clone
  • Operating system and version: Linux
  • Stlink tools git commit hash: 5c03678
  • Stlink commandline tool name: st-util
  • Target chip: STM32F103CBT6 (Maple Mini clone)

Test code on the target device:

initial_stack_ptr:
        .word 0x20005000
interrupt_vectors:
        .word reset_handler + 1
        ...
reset_handler:
        mov r0, #0
        mov r1, #1
        mov r2, #2
        mov r3, #3
        mov r4, #4
        mov r5, #5
        mov r6, #6
        mov r7, #7
        mov r8, #8
        mov r9, #9
        mov r10, #10
        mov r11, #11
        mov r12, #12
        mov r14, #14
1:      b.n 1b

Actual GDB output with the target stopped on the final line of the test code:

(gdb) info reg
r0             0x30                48
r1             0x30                48
r2             0xbbc56fb8          3150278584
r3             0x7ffe              32766
r4             0x3                 3
r5             0x4                 4
r6             0x5                 5
r7             0x6                 6
r8             0x7                 7
r9             0x8                 8
r10            0x9                 9
r11            0xa                 10
r12            0xb                 11
sp             0xc                 0xc
lr             0x20005000          536891392
pc             0xe                 0xe
cpsr           0x1000000           16777216

Expected GDB output in the same scenario:

(gdb) info reg
r0             0x0                 0
r1             0x1                 1
r2             0x2                 2
r3             0x3                 3
r4             0x4                 4
r5             0x5                 5
r6             0x6                 6
r7             0x7                 7
r8             0x8                 8
r9             0x9                 9
r10            0xa                 10
r11            0xb                 11
r12            0xc                 12
sp             0x20005000          ...
lr             0xe                 14
pc             ....                ...
cpsr           ....                ...

Adding debug output to stlink_read_all_regs() confirms that the culprit is in fact st-util, not gdb:

int reg_offset = sl->version.jtag_api == STLINK_JTAG_API_V1 ? 0 : 4;
sl->q_len = (int)size;
stlink_print_data(sl);

for (i = reg_offset; i < 16; i++) regp->r[i] = read_uint32(sl->q_buf, i * 4);

DLOG("reg_offset=%i\n", reg_offset);
DLOG("r0 %08X r4 %08X   r8 %08X r12 %08X\n", regp->r[0], regp->r[4], regp->r[8],  regp->r[12]);
DLOG("r1 %08X r5 %08X   r9 %08X r13 %08X\n", regp->r[1], regp->r[5], regp->r[9],  regp->r[13]);
DLOG("r2 %08X r6 %08X  r10 %08X r14 %08X\n", regp->r[2], regp->r[6], regp->r[10], regp->r[14]);
DLOG("r3 %08X r7 %08X  r11 %08X r15 %08X\n", regp->r[3], regp->r[7], regp->r[11], regp->r[15]);

Output of the code above:

2020-09-09T23:31:58 DEBUG usb.c: reg_offset=4
2020-09-09T23:31:58 DEBUG usb.c: r0 00000030 r4 00000003   r8 00000007 r12 0000000B
2020-09-09T23:31:58 DEBUG usb.c: r1 00000030 r5 00000004   r9 00000008 r13 0000000C
2020-09-09T23:31:58 DEBUG usb.c: r2 D81F1598 r6 00000005  r10 00000009 r14 20005000
2020-09-09T23:31:58 DEBUG usb.c: r3 00007FFE r7 00000006  r11 0000000A r15 0000000E
2020-09-09T23:31:58 DEBUG gdb-server.c: send: 300000003000000098151fd8fe7f0000030000000400000005000000060000000700000008000000090000000a0000000b0000000c000000005000200e000000

I'm going to send a PR for this but that patch will probably require some context.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants