riscvarchive / riscv-qemu

QEMU with RISC-V (RV64G, RV32G) Emulation Support
384 stars 154 forks source link

Add gdb xml register support. #160

Closed jim-wilson closed 5 years ago

jim-wilson commented 5 years ago

This allows gdb to read misa and set breakpoints. This is a work in progress, and has a number of obvious problems, incomplete csr support, wrong int reg size for rv32, etc.

jim-wilson commented 5 years ago

This is a proposed solution for issue #156.

lbmeng commented 5 years ago

This patch solves my problem with https://github.com/riscv/riscv-qemu/issues/101. Thanks!

jim-wilson commented 5 years ago

One odd thing about the patch is that misa is listed as 0x342 when it is actually 0x301. This is because in gdb, CSRs start at 65, and 0x301+65 is 0x342. This is a little confusing. We can avoid the problem if we put all 4096 registers in the riscv-csr.xml file, in which case we don't need to specify register numbers, but then gdb will actually try to read all 4096 of them, so that may not be the right solution. I want to check the gdb XML syntax, to see if maybe there is a better way to handle this.

michaeljclark commented 5 years ago

Can we just put the present subset of the CSRs in the riscv-csr.xml file. We have that information in the csr_ops array in target/riscv/csr.c. Sorry I am not sure how GDB XML works so this might be a dumb idea.

BTW I have backported the CSR_TABLE_SIZE fix to the patch that adds the feature as it is not in upstream QEMU yet. It made sense to collapse the change into the CSR table feature patch in the qemu-for-upstream branch.

Sorry for the rebasing here, but it is a result of us sharing our in-progress patches... the workflow requires us to rebase our pending branch. If you have a patch, then you can just remove the CSR.

The riscv-qemu-3.0 branch is stable and we can backport to it. The riscv-all branch currently just has a merge commit of the qemu-for-upstream branch which gets rebased against upstream.

jim-wilson commented 5 years ago

The rebasing is fine. I can deal with that.

The more CSRs we put into the XML file, the more CSRs gdb will read when connecting to the target. I'm not sure if that is OK; I haven't looked at that yet. I just started with misa as gdb requires that one in order to work properly. I haven't had a chance to expand the list yet. Presumably qemu is OK with reading lots of CSRs and will do something reasonable if we try to read a CSR that doesn't exist on the target. On the gdb side the register displays may get a bit messy, e.g. the user types "info all-registers" and then gdb will display hundreds or maybe thousands of lines of info because we have lots of CSRs. But these are manageable problems, and ideally we should put as many CSRs in the list as reasonable, as gdb can only read/write registers mentioned in the XML files, and there may be people that want to see all of the CSR register values from gdb.

jim-wilson commented 5 years ago

The gdb support is in upstream qemu now.