aboutsummaryrefslogtreecommitdiff
path: root/gdb/disasm.c
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2021-10-05 15:10:12 +0100
committerAndrew Burgess <andrew.burgess@embecosm.com>2021-10-13 11:43:28 +0100
commit76b43c9b5c2b275cbf4f927bfc25984410cb5dd5 (patch)
tree7cbf8a1b1201aaa1d4bab7c001a9d12b409d756c /gdb/disasm.c
parent38b03d23c7c7e6a9f8f27a9899fd0a84587c379e (diff)
downloadgdb-76b43c9b5c2b275cbf4f927bfc25984410cb5dd5.zip
gdb-76b43c9b5c2b275cbf4f927bfc25984410cb5dd5.tar.gz
gdb-76b43c9b5c2b275cbf4f927bfc25984410cb5dd5.tar.bz2
gdb: improve error reporting from the disassembler
If the libopcodes disassembler returns a negative value then this indicates that the disassembly failed for some reason. In disas.c, in the function gdb_disassembler::print_insn we can see how this is handled; when we get a negative value back, we call the memory_error function, which throws an exception. The problem here is that the address used in the memory_error call is gdb_disassembler::m_err_memaddr, which is set in gdb_disassembler::dis_asm_memory_error, which is called from within the libopcodes disassembler through the disassembler_info::memory_error_func callback. However, for this to work correctly, every time the libopcodes disassembler returns a negative value, the libopcodes disassembler must have first called the memory_error_func callback. My first plan was to make m_err_memaddr a gdb::optional, and assert that it always had a value prior to calling memory_error, however, a quick look in opcodes/*-dis.c shows that there _are_ cases where a negative value is returned without first calling the memory_error_func callback, for example in arc-dis.c and cris-dis.c. Now, I think that a good argument can be made that these disassemblers must therefore be broken, except for the case where we can't read memory, we should always be able to disassemble the memory contents to _something_, even if it's just '.word 0x....'. However, I certainly don't plan to go and fix all of the disassemblers. What I do propose to do then, is make m_err_memaddr a gdb::optional, but now, instead of always calling memory_error, I add a new path which just calls error complaining about an unknown error. This new path is only used if m_err_memaddr doesn't have a value (indicating that the memory_error_func callback was not called). To test this I just augmented one of the disassemblers to always return -1, before this patch I see this: Dump of assembler code for function main: 0x000101aa <+0>: Cannot access memory at address 0x0 And after this commit I now see: Dump of assembler code for function main: 0x000101aa <+0>: unknown disassembler error (error = -1) This doesn't really help much, but that's because there's no way to report non memory errors out of the disasembler, because, it was not expected that the disassembler would ever report non memory errors.
Diffstat (limited to 'gdb/disasm.c')
-rw-r--r--gdb/disasm.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/gdb/disasm.c b/gdb/disasm.c
index c788f5b..dc64267 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -148,7 +148,7 @@ gdb_disassembler::dis_asm_memory_error (int err, bfd_vma memaddr,
gdb_disassembler *self
= static_cast<gdb_disassembler *>(info->application_data);
- self->m_err_memaddr = memaddr;
+ self->m_err_memaddr.emplace (memaddr);
}
/* Wrapper of print_address. */
@@ -754,8 +754,7 @@ get_all_disassembler_options (struct gdbarch *gdbarch)
gdb_disassembler::gdb_disassembler (struct gdbarch *gdbarch,
struct ui_file *file,
di_read_memory_ftype read_memory_func)
- : m_gdbarch (gdbarch),
- m_err_memaddr (0)
+ : m_gdbarch (gdbarch)
{
init_disassemble_info (&m_di, file, fprintf_disasm);
m_di.flavour = bfd_target_unknown_flavour;
@@ -790,12 +789,17 @@ int
gdb_disassembler::print_insn (CORE_ADDR memaddr,
int *branch_delay_insns)
{
- m_err_memaddr = 0;
+ m_err_memaddr.reset ();
int length = gdbarch_print_insn (arch (), memaddr, &m_di);
if (length < 0)
- memory_error (TARGET_XFER_E_IO, m_err_memaddr);
+ {
+ if (m_err_memaddr.has_value ())
+ memory_error (TARGET_XFER_E_IO, *m_err_memaddr);
+ else
+ error (_("unknown disassembler error (error = %d)"), length);
+ }
if (branch_delay_insns != NULL)
{