Gdb: target remote connects at the wrong place?

1

I'm learning how to use OpenOCD and GDB according to the Rust Embedded Book.

There is a moment when you connect to the running OpenOCD:

(gdb) target remote :3333
Remote debugging using :3333
0x00000000 in ?? ()

Something broke without any changes I am aware of, and now I see something like this:

(gdb) target remote :3333
Remote debugging using :3333
0x08000bbe in __c_m_sh_syscall ()

It won't work properly since then. What does the 0x00000000 in ?? () line mean, and how to set things back to rights?

rust
gdb
embedded
openocd
asked on Stack Overflow Jan 15, 2021 by Alexey Orlov

1 Answer

1

When you connect to the target with target remote GDB asks the target for its current register state, including the $pc value. GDB does NOT (at that point) modify the remote state in any way.

When you first connected the remote reported a $pc value of 0x0. If the remote changed state for some reason, lets say, you ran something on the remote, then the $pc value might change, say to 0x08000bbe.

If you then disconnect and reconnect the remote target might still have a $pc value of 0x08000bbe which is what GDB will see.

As was mentioned in the comments, GDB is just trying to map the $pc value onto the debug information in your program. The ?? shows that GDB can't find any symbols at address 0x0. While GDB did find the symbol __c_m_sh_syscall near to address 0x08000bbe. However, this is information doesn't mean much at this point, you've not yet loaded anything onto the target, so you're not really in the function __c_m_sh_syscall, it's just the current address of the remote.

When you do the load command this is when GDB loads the executable onto the target, and writes to the $pc.

TL;DR; If your work flow is target remote then load, don't worry about the state of the target immediately after the target remote, this is just whatever random state happens to be in the target when you connect.

answered on Stack Overflow Jan 15, 2021 by Andrew

User contributions licensed under CC BY-SA 3.0