This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] GDB: Treat memory exception from tui_disassemble() gracefully


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]