Skip to content

Commit

Permalink
Disassembly unit test: memory error
Browse files Browse the repository at this point in the history
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  <[email protected]>

	* disasm-selftests.c (memory_error_test): New function.
	(_initialize_disasm_selftests): Register memory_error_test.
  • Loading branch information
Yao Qi committed Jan 26, 2017
1 parent 79843d4 commit 658ca58
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
5 changes: 5 additions & 0 deletions gdb/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2017-01-26 Yao Qi <[email protected]>

* disasm-selftests.c (memory_error_test): New function.
(_initialize_disasm_selftests): Register memory_error_test.

2017-01-26 Yao Qi <[email protected]>

* Makefile.in (SFILES): Add disasm-selftests.c and
Expand Down
42 changes: 42 additions & 0 deletions gdb/disasm-selftests.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand All @@ -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
}

0 comments on commit 658ca58

Please sign in to comment.