aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorYao Qi <yao.qi@linaro.org>2017-01-26 14:29:19 +0000
committerYao Qi <yao.qi@linaro.org>2017-01-26 14:29:19 +0000
commit658ca58c4d41c7512dcabcbc4a5ea2109045c363 (patch)
treea58a313f3b65f5b9cba4cbf2aec516a1ba00af63 /gdb
parent79843d45f7633f33dca8b0a9999a1b0795b6b459 (diff)
downloadgdb-658ca58c4d41c7512dcabcbc4a5ea2109045c363.zip
gdb-658ca58c4d41c7512dcabcbc4a5ea2109045c363.tar.gz
gdb-658ca58c4d41c7512dcabcbc4a5ea2109045c363.tar.bz2
Disassembly unit test: memory error
This patch adds a unit test about memory error occurs on reading memory, and check MEMORY_ERROR exception is always thrown. gdb: 2017-01-26 Yao Qi <yao.qi@linaro.org> * disasm-selftests.c (memory_error_test): New function. (_initialize_disasm_selftests): Register memory_error_test.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/disasm-selftests.c42
2 files changed, 47 insertions, 0 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 422697d..2e8a96f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2017-01-26 Yao Qi <yao.qi@linaro.org>
+ * disasm-selftests.c (memory_error_test): New function.
+ (_initialize_disasm_selftests): Register memory_error_test.
+
+2017-01-26 Yao Qi <yao.qi@linaro.org>
+
* Makefile.in (SFILES): Add disasm-selftests.c and
selftest-arch.c.
(COMMON_OBS): Add disasm-selftests.o and selftest-arch.o.
diff --git a/gdb/disasm-selftests.c b/gdb/disasm-selftests.c
index 3d68abd..c89c5ed 100644
--- a/gdb/disasm-selftests.c
+++ b/gdb/disasm-selftests.c
@@ -164,6 +164,47 @@ print_one_insn_test (struct gdbarch *gdbarch)
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 */
@@ -175,5 +216,6 @@ _initialize_disasm_selftests (void)
{
#if GDB_SELF_TEST
register_self_test_foreach_arch (selftests::print_one_insn_test);
+ register_self_test_foreach_arch (selftests::memory_error_test);
#endif
}