aboutsummaryrefslogtreecommitdiff
path: root/gdb/s12z-tdep.c
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2022-04-04 15:48:19 +0100
committerAndrew Burgess <aburgess@redhat.com>2022-06-15 09:44:55 +0100
commit8b39b1e7ab20609ced6a224cae440f19e6ae02c1 (patch)
tree015e347bb39704d9424f3068c1ea372146d90b48 /gdb/s12z-tdep.c
parent15e15b2d9cd3b1db68f99cd3b047352142ddfd1c (diff)
downloadgdb-8b39b1e7ab20609ced6a224cae440f19e6ae02c1.zip
gdb-8b39b1e7ab20609ced6a224cae440f19e6ae02c1.tar.gz
gdb-8b39b1e7ab20609ced6a224cae440f19e6ae02c1.tar.bz2
gdb: refactor the non-printing disassemblers
This commit started from an observation I made while working on some other disassembler patches, that is, that the function gdb_buffered_insn_length, is broken ... sort of. I noticed that the gdb_buffered_insn_length function doesn't set up the application data field if the disassemble_info structure. Further, I noticed that some architectures, for example, ARM, require that the application_data field be set, see gdb_print_insn_arm in arm-tdep.c. And so, if we ever use gdb_buffered_insn_length for ARM, then GDB will likely crash. Which is why I said only "sort of" broken. Right now we don't use gdb_buffered_insn_length with ARM, so maybe it isn't broken yet? Anyway to prove to myself that there was a problem here I extended the disassembler self tests in disasm-selftests.c to include a test of gdb_buffered_insn_length. As I run the test for all architectures, I do indeed see GDB crash for ARM. To fix this we need gdb_buffered_insn_length to create a disassembler that inherits from gdb_disassemble_info, but we also need this new disassembler to not print anything. And so, I introduce a new gdb_non_printing_disassembler class, this is a disassembler that doesn't print anything to the output stream. I then observed that both ARC and S12Z also create non-printing disassemblers, but these are slightly different. While the disassembler in gdb_non_printing_disassembler reads the instruction from a buffer, the ARC and S12Z disassemblers read from target memory using target_read_code. And so, I further split gdb_non_printing_disassembler into two sub-classes, gdb_non_printing_memory_disassembler and gdb_non_printing_buffer_disassembler. The new selftests now pass, but otherwise, there should be no user visible changes after this commit.
Diffstat (limited to 'gdb/s12z-tdep.c')
-rw-r--r--gdb/s12z-tdep.c26
1 files changed, 2 insertions, 24 deletions
diff --git a/gdb/s12z-tdep.c b/gdb/s12z-tdep.c
index 5394c1b..4e33faa 100644
--- a/gdb/s12z-tdep.c
+++ b/gdb/s12z-tdep.c
@@ -141,27 +141,6 @@ s12z_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int num)
/* Support functions for frame handling. */
-
-/* Return a disassemble_info initialized for s12z disassembly, however,
- the disassembler will not actually print anything. */
-
-static struct disassemble_info
-s12z_disassemble_info (struct gdbarch *gdbarch)
-{
- struct disassemble_info di;
- init_disassemble_info_for_no_printing (&di);
- di.arch = gdbarch_bfd_arch_info (gdbarch)->arch;
- di.mach = gdbarch_bfd_arch_info (gdbarch)->mach;
- di.endian = gdbarch_byte_order (gdbarch);
- di.read_memory_func = [](bfd_vma memaddr, gdb_byte *myaddr,
- unsigned int len, struct disassemble_info *info)
- {
- return target_read_code (memaddr, myaddr, len);
- };
- return di;
-}
-
-
/* A struct (based on mem_read_abstraction_base) to read memory
through the disassemble_info API. */
struct mem_read_abstraction
@@ -332,15 +311,14 @@ s12z_frame_cache (struct frame_info *this_frame, void **prologue_cache)
int frame_size = 0;
int saved_frame_size = 0;
- struct disassemble_info di = s12z_disassemble_info (gdbarch);
-
+ struct gdb_non_printing_memory_disassembler dis (gdbarch);
struct mem_read_abstraction mra;
mra.base.read = (int (*)(mem_read_abstraction_base*,
int, size_t, bfd_byte*)) abstract_read_memory;
mra.base.advance = advance ;
mra.base.posn = posn;
- mra.info = &di;
+ mra.info = dis.disasm_info ();
while (this_pc > addr)
{