Open ryan-summers opened 4 years ago
The nicest debug user experience I can imagine is a sort of RawRegisterBlock
struct containing plain u32 in repr(C)
, and a static SPI1: *const RawRegisterBlock = 0x4000abcd;
global export, maybe even no_mangle
, which would allow GDB to very easily p SPI1
.
Unfortunately *const
aren't Sync so there's no way to export such a thing. Exporting just the type alone would at least permit manually printing it from a pointer address, e.g. p *(0x40003800 as *const u32 as *const pac::spi::RawRegisterBlock)
, but it's still pretty wordy. More importantly, if the exported type isn't actually used in the final application, I don't think its layout ends up in the ELF, so gdb can't see it.
(As I'm sure you know,) in C there's often a struct declared and then defined globally in the device header file which permits global access to all registers just through the peripheral name, and makes debug printing (and even setting) from within GDB very easy and ergonomic. I think that's basically the ideal end point, but it might just not be compatible with the type safety we want. It might be that our effect really is better spent on making sure the GDB extensions are as slick as possible: already having it easily print out each field values with the field names and descriptions taken from the SVD is a big win.
Unfortunately arm-none-eabi-gdb
shipped by Arm doesn't support Python, which means you can't even use the Python extensions without swapping to a different gdb build.
Unfortunately
arm-none-eabi-gdb
shipped by Arm doesn't support Python, which means you can't even use the Python extensions without swapping to a different gdb build.
I've been using gdb-multiarch
from Ubuntu 20.04 and have played around with the python-interactive
interface with a Cortex-M7, so there is a python interface we can use to write a pretty-printer.
Unfortunately
*const
aren't Sync so there's no way to export such a thing. Exporting just the type alone would at least permit manually printing it from a pointer address, e.g.p *(0x40003800 as *const u32 as *const pac::spi::RawRegisterBlock)
, but it's still pretty wordy. More importantly, if the exported type isn't actually used in the final application, I don't think its layout ends up in the ELF, so gdb can't see it.
As I noted earlier, RegisterBlock structures aren't always included in the final output ELF. However, if they were, we could generate a GDB pretty-printer to automatically format the structures, which I think is the right approach here. I was playing around with this and discovered that we need the following:
RawRegisterBlock
structures make it into the output ELF file (which would be a C-like definition of the register block)Deref
traitIn regard to (2), I was previously unable to get at these addresses as it looks like the debug info wasn't present in the ELF file (there was no way to call the ptr()
method or get the underlying address through GDB from what I could tell)
I definitely think that a pretty-printer for GDB is the right way to go - we just need to try to provide the necessary debug information in the output ELF for the pretty-printer to do it's job.
This issue is being moved after originally posted in https://github.com/rust-embedded/wg/issues/459
Because of the implementation of
svd2rust
(and some issues with trait implementations in the debug information outlined here), register blocks cannot be printed in a GDB interface. Attempts to do so only result in an output similar to the following:Similarly, if the register block is correctly type-cast in GDB, the output is equally unhelpful:
The simplest way to visualize the registers is to just examine the raw memory, which is not a great alternative:
Is there a way that we can provide an interface co cleanly print out the bits (or just bytes) of the registers along with their names in GDB?
In https://github.com/rust-embedded/wg/issues/459, https://github.com/bnahill/PyCortexMDebug was pointed out as an option, but we would ideally not require an external tool and the chip SVD (which may or may not have bugs that have been patched by the PAC maintainer) to visualize the registers.