This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 7/8] Disassembly unit test: memory error
- From: Yao Qi <qiyaoltc at gmail dot com>
- To: binutils at sourceware dot org, gdb-patches at sourceware dot org
- Date: Tue, 10 Jan 2017 12:26:17 +0000
- Subject: [PATCH 7/8] Disassembly unit test: memory error
- Authentication-results: sourceware.org; auth=none
- References: <1484051178-16013-1-git-send-email-yao.qi@linaro.org>
This patch adds a unit test about memory error occurs on reading
memory, and check MEMORY_ERROR exception is always thrown.
gdb:
2017-01-10 Yao Qi <yao.qi@linaro.org>
* disasm.c (gdb_disassembler_print_one_insn_test):
(gdb_disassembler_memory_error_test): New function.
(_initialize_disasm): Register
gdb_disassembler_memory_error_test.
---
gdb/disasm.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/gdb/disasm.c b/gdb/disasm.c
index 6e403da..e908199 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -424,6 +424,53 @@ gdb_disassembler_print_one_insn_test (struct gdbarch *gdbarch)
SELF_CHECK (di.print_insn (0) == len);
}
+/* Test disassembly on memory error. */
+
+static void
+gdb_disassembler_memory_error_test (struct gdbarch *gdbarch)
+{
+ class gdb_disassembler_test : public gdb_disassembler
+ {
+ public:
+ gdb_disassembler_test (struct gdbarch *gdbarch)
+ : gdb_disassembler (gdbarch, ui_file_new (),
+ gdb_disassembler_test::read_memory)
+ {
+ }
+
+ ~gdb_disassembler_test ()
+ {
+ ui_file_delete ((struct ui_file *) m_di.stream);
+ }
+
+ static int read_memory (bfd_vma memaddr, gdb_byte *myaddr,
+ unsigned int len,
+ struct disassemble_info *info)
+ {
+ /* Always get an error. */
+ return -1;
+ }
+ };
+
+ gdb_disassembler_test di (gdbarch);
+ bool see_memory_error = false;
+
+ TRY
+ {
+ di.print_insn (0);
+ }
+ CATCH (ex, RETURN_MASK_ERROR)
+ {
+ if (ex.error == MEMORY_ERROR)
+ see_memory_error = true;
+ }
+ END_CATCH
+
+ /* Expect MEMORY_ERROR. */
+ SELF_CHECK (see_memory_error);
+
+}
+
} // namespace selftests
#endif /* GDB_SELF_TEST */
@@ -1083,5 +1130,6 @@ _initialize_disasm (void)
{
#if GDB_SELF_TEST
register_self_test (selftests::gdb_disassembler_print_one_insn_test);
+ register_self_test (selftests::gdb_disassembler_memory_error_test);
#endif
}
--
1.9.1