/* Test gdb_disassembler for a given gdbarch by reading data from a
pre-allocated buffer. If you want to see the disassembled
instruction printed to gdb_stdout, set verbose to true. */
+ static const bool verbose = false;
class gdb_disassembler_test : public gdb_disassembler
{
public:
- const bool verbose = false;
-
explicit gdb_disassembler_test (struct gdbarch *gdbarch,
const gdb_byte *insn,
size_t len)
: gdb_disassembler (gdbarch,
- (verbose ? gdb_stdout : null_stream ()),
+ (verbose ? gdb_stdout : &null_stream),
gdb_disassembler_test::read_memory),
m_insn (insn), m_len (len)
{
SELF_CHECK (di.print_insn (0) == len);
}
+/* Test disassembly on memory error. */
+
+static void
+memory_error_test (struct gdbarch *gdbarch)
+{
+ class gdb_disassembler_test : public gdb_disassembler
+ {
+ public:
+ gdb_disassembler_test (struct gdbarch *gdbarch)
+ : gdb_disassembler (gdbarch, &null_stream,
+ gdb_disassembler_test::read_memory)
+ {
+ }
+
+ static int read_memory (bfd_vma memaddr, gdb_byte *myaddr,
+ unsigned int len,
+ struct disassemble_info *info)
+ {
+ /* Always return an error. */
+ return -1;
+ }
+ };
+
+ gdb_disassembler_test di (gdbarch);
+ bool saw_memory_error = false;
+
+ TRY
+ {
+ di.print_insn (0);
+ }
+ CATCH (ex, RETURN_MASK_ERROR)
+ {
+ if (ex.error == MEMORY_ERROR)
+ saw_memory_error = true;
+ }
+ END_CATCH
+
+ /* Expect MEMORY_ERROR. */
+ SELF_CHECK (saw_memory_error);
+}
+
} // namespace selftests
#endif /* GDB_SELF_TEST */
{
#if GDB_SELF_TEST
register_self_test_foreach_arch (selftests::print_one_insn_test);
+ register_self_test_foreach_arch (selftests::memory_error_test);
#endif
}