ld -plugin options when plugins are disabled
[deliverable/binutils-gdb.git] / gdb / disasm-selftests.c
index 3d68abd037f1d6e1e743e1e0ed8cca39937d2871..a24db7f224ff983fa3cc0746e547043243e7ee40 100644 (file)
@@ -1,6 +1,6 @@
 /* Self tests for disassembler for GDB, the GNU debugger.
 
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   Copyright (C) 2017-2020 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 
 #include "defs.h"
 #include "disasm.h"
-
-#if GDB_SELF_TEST
-#include "selftest.h"
+#include "gdbsupport/selftest.h"
 #include "selftest-arch.h"
+#include "gdbarch.h"
 
 namespace selftests {
 
@@ -77,12 +76,15 @@ print_one_insn_test (struct gdbarch *gdbarch)
       /* fall through */
     case bfd_arch_nios2:
     case bfd_arch_score:
-      /* nios2 and score need to know the current instruction to select
-        breakpoint instruction.  Give the breakpoint instruction kind
-        explicitly.  */
-      int bplen;
-      insn = gdbarch_sw_breakpoint_from_kind (gdbarch, 4, &bplen);
-      len = bplen;
+    case bfd_arch_riscv:
+      /* nios2, riscv, and score need to know the current instruction
+        to select breakpoint instruction.  Give the breakpoint
+        instruction kind explicitly.  */
+      {
+       int bplen;
+       insn = gdbarch_sw_breakpoint_from_kind (gdbarch, 4, &bplen);
+       len = bplen;
+      }
       break;
     default:
       {
@@ -102,18 +104,17 @@ print_one_insn_test (struct gdbarch *gdbarch)
   /* 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)
     {
@@ -164,16 +165,54 @@ print_one_insn_test (struct gdbarch *gdbarch)
   SELF_CHECK (di.print_insn (0) == len);
 }
 
-} // namespace selftests
-#endif /* GDB_SELF_TEST */
+/* 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)
+    {
+    }
 
-/* Suppress warning from -Wmissing-prototypes.  */
-extern initialize_file_ftype _initialize_disasm_selftests;
+    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);
+}
+
+} // namespace selftests
 
+void _initialize_disasm_selftests ();
 void
-_initialize_disasm_selftests (void)
+_initialize_disasm_selftests ()
 {
-#if GDB_SELF_TEST
-  register_self_test_foreach_arch (selftests::print_one_insn_test);
-#endif
+  selftests::register_test_foreach_arch ("print_one_insn",
+                                        selftests::print_one_insn_test);
+  selftests::register_test_foreach_arch ("memory_error",
+                                        selftests::memory_error_test);
 }
This page took 0.024877 seconds and 4 git commands to generate.