diff options
author | Marek PikuĊa <m.pikula@partner.samsung.com> | 2025-05-28 13:54:47 +0200 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2025-07-17 18:11:47 +0100 |
commit | 1324b95f574f86018e947e1c5255a26266e0eefc (patch) | |
tree | f46b175eb588a9dd6187fe26b8fbe3814db42b9f /gdb | |
parent | 596ba5e9fb2bb03d866bc8cfacc0b24c2619d723 (diff) | |
download | binutils-1324b95f574f86018e947e1c5255a26266e0eefc.zip binutils-1324b95f574f86018e947e1c5255a26266e0eefc.tar.gz binutils-1324b95f574f86018e947e1c5255a26266e0eefc.tar.bz2 |
gdb/risc-v: fix ISA string detection for disassembly
Commit 3f61a38 introduced a regression where the ISA string was no
longer detected based on the ELF header. The mechanism was changed from
directly referencing `abfd` to using `disassembler_info->section`, which
was not properly initialized for RISC-V.
The previous implementation ignored the object in scope, leading to
issues such as failing to decode RVV instructions when a library was
compiled as `rv64gcv` and the main application as `rv64gc`.
This patch resolves both problems by initializing
`disassembler_info->section` with the object currently in scope,
ensuring correct ISA string detection during disassembly.
Approved-By: Andrew Burgess <aburgess@redhat.com>
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/riscv-tdep.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c index 6d439b0..f5b8523 100644 --- a/gdb/riscv-tdep.c +++ b/gdb/riscv-tdep.c @@ -4163,6 +4163,20 @@ riscv_gnu_triplet_regexp (struct gdbarch *gdbarch) return "riscv(32|64)?"; } +/* Implement the "print_insn" gdbarch method. */ + +static int +riscv_print_insn (bfd_vma addr, struct disassemble_info *info) +{ + /* Initialize the BFD section to enable ISA string detection depending on the + object in scope. */ + struct obj_section *s = find_pc_section (addr); + if (s != nullptr) + info->section = s->the_bfd_section; + + return default_print_insn (addr, info); +} + /* Implementation of `gdbarch_stap_is_single_operand', as defined in gdbarch.h. */ @@ -4429,6 +4443,9 @@ riscv_gdbarch_init (struct gdbarch_info info, disassembler_options_riscv ()); set_gdbarch_disassembler_options (gdbarch, &riscv_disassembler_options); + /* Disassembler print_insn. */ + set_gdbarch_print_insn (gdbarch, riscv_print_insn); + /* SystemTap Support. */ set_gdbarch_stap_is_single_operand (gdbarch, riscv_stap_is_single_operand); set_gdbarch_stap_register_indirection_prefixes |