This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] GDB: Treat memory exception from tui_disassemble() gracefully
- From: Shahab Vahedi <shahab dot vahedi at gmail dot com>
- To: Andrew Burgess <andrew dot burgess at embecosm dot com>
- Cc: gdb-patches at sourceware dot org, Shahab Vahedi <shahab at synopsys dot com>, Pedro Alves <palves at redhat dot com>, Claudiu Zissulescu <claziss at synopsys dot com>, Francois Bedard <fbedard at synopsys dot com>
- Date: Thu, 9 Jan 2020 12:59:07 +0100
- Subject: Re: [PATCH] GDB: Treat memory exception from tui_disassemble() gracefully
- References: <20200108152550.112120-1-shahab.vahedi@gmail.com> <20200108163139.GY3865@embecosm.com>
Hi Andrew,
After a few iterations, I came up with a solution that is listed at
the end of this mail. In my opinion, it works the best. You can see
it in action here:
https://sourceware.org/bugzilla/attachment.cgi?id=12178
It does not highlight the empty lines anymore or crash when it goes
one window beyond the last instructions. Moreover, going to the top
and right is fine too.
The only downside is that last invalid address (the address just
after the _last valid_ address) is repeated. If I try to remove it,
the highlight issue kicks in.
If you agree this is good enough, I will submit a V2 patch.
diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c
index 98c691f3387..3dfe70bc480 100644
--- a/gdb/tui/tui-disasm.c
+++ b/gdb/tui/tui-disasm.c
@@ -114,7 +114,18 @@ tui_disassemble (struct gdbarch *gdbarch,
asm_lines[pos + i].addr_size = new_size;
}
- pc = pc + gdb_print_insn (gdbarch, pc, &gdb_dis_out, NULL);
+ try
+ {
+ pc = pc + gdb_print_insn (gdbarch, pc, &gdb_dis_out, NULL);
+ }
+ catch (const gdb_exception &except)
+ {
+ /* In cases where max_lines is asking tui_disassemble() to fetch
+ too much, like when PC goes past the valid address range, a
+ MEMORY_ERROR is thrown, but it is alright. */
+ if (except.error != MEMORY_ERROR)
+ throw;
+ }
asm_lines[pos + i].insn = std::move (gdb_dis_out.string ());
--
Shahab