+/* 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 (const gdb_exception_error &ex)
+ {
+ if (ex.error == MEMORY_ERROR)
+ saw_memory_error = true;
+ }
+
+ /* Expect MEMORY_ERROR. */
+ SELF_CHECK (saw_memory_error);
+}
+