public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2][PR tui/9765] Fix segfault in asm TUI when reaching end of file
@ 2020-01-10 11:57 Shahab Vahedi
  2020-01-10 12:53 ` Pedro Alves
  2020-01-11  2:00 ` Andrew Burgess
  0 siblings, 2 replies; 27+ messages in thread
From: Shahab Vahedi @ 2020-01-10 11:57 UTC (permalink / raw)
  To: gdb-patches
  Cc: Shahab Vahedi, Pedro Alves, Andrew Burgess, Tom Tromey,
	Claudiu Zissulescu, Francois Bedard

From: Shahab Vahedi <shahab@synopsys.com>

In TUI mode, when the assembly layout reaches the end of a binary,
GDB wants to disassemle the addresses beyond the last valid ones.
This results in a "MEMORY_ERROR" exception to be thrown when
tui_disasm_window::set_contents() invokes tui_disassemble(). When
that happens set_contents() bails out prematurely without filling
the "content" for the valid addresses. This eventually leads to
no assembly lines or termination of GDB when you scroll down to
the last lines of the program.

With this change, tui_disassemble() catches MEMORY_ERROR exceptions
and ignores them, while filling the rest of "asm_lines" with the
same address (the one just beyond the last PC address).

The issue has been discussed at length in bug 25345 (and 9765).

gdb/ChangeLog:
2020-01-10  Shahab Vahedi  <shahab@synopsys.com>

	PR tui/25345
	* tui/tui-disasm.c (tui_disasm_window::tui_disassemble):
	Handle MEMORY_ERROR exceptions gracefully.
---
The behavior of GDB after this fix is illustrated here:
https://sourceware.org/bugzilla/attachment.cgi?id=12178

 gdb/tui/tui-disasm.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c
index 98c691f3387..dffcd257a0d 100644
--- a/gdb/tui/tui-disasm.c
+++ b/gdb/tui/tui-disasm.c
@@ -114,7 +114,19 @@ 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;
+	  /* fall through: let asm_lines still to be filled.  */
+	}
 
       asm_lines[pos + i].insn = std::move (gdb_dis_out.string ());
 
-- 
2.24.1

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2020-01-31 10:09 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-10 11:57 [PATCH v2][PR tui/9765] Fix segfault in asm TUI when reaching end of file Shahab Vahedi
2020-01-10 12:53 ` Pedro Alves
2020-01-10 13:37   ` [PATCH] Don't let TUI exceptions escape to readline (PR tui/9765) Pedro Alves
2020-01-10 14:31     ` Shahab Vahedi
2020-01-13 20:46       ` [PATCH 2/2] gdb/tui: asm window handles invalid memory and scrolls better Andrew Burgess
2020-01-15  0:57         ` Tom Tromey
2020-01-13 20:46       ` [PATCH 0/2] gdb/tui: Assembler window scrolling fixes Andrew Burgess
2020-01-14 14:19         ` Shahab Vahedi
2020-01-16  0:48         ` [PATCHv2 2/2] gdb/tui: asm window handles invalid memory and scrolls better Andrew Burgess
2020-01-21 16:27           ` Shahab Vahedi
2020-01-22 13:30             ` Shahab Vahedi
2020-01-22 16:32               ` Andrew Burgess
2020-01-22 19:26           ` Pedro Alves
2020-01-16  0:48         ` [PATCHv2 0/2] gdb/tui: Assembler window scrolling fixes Andrew Burgess
2020-01-24 11:22           ` Shahab Vahedi
2020-01-24 21:22             ` [PATCH 0/2] Further Assembler Scrolling Fixes Andrew Burgess
2020-01-24 21:22             ` [PATCH 1/2] gdb/tui: Update help text for scroll commands Andrew Burgess
2020-01-26 16:07               ` Tom Tromey
2020-01-24 21:29             ` [PATCH 2/2] gdb/tui: Disassembler scrolling of very small programs Andrew Burgess
2020-01-26 16:10               ` Tom Tromey
2020-01-31 10:10               ` Shahab Vahedi
2020-01-16  2:55         ` [PATCHv2 1/2] gdb/tui: Prevent exceptions from trying to cross readline Andrew Burgess
2020-01-13 22:04       ` [PATCH " Andrew Burgess
2020-01-15  0:56         ` Tom Tromey
2020-01-10 14:42     ` [PATCH] Don't let TUI exceptions escape to readline (PR tui/9765) Tom Tromey
2020-01-10 13:47   ` [PATCH v2][PR tui/9765] Fix segfault in asm TUI when reaching end of file Shahab Vahedi
2020-01-11  2:00 ` Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).