Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Shahab Vahedi <shahab.vahedi@gmail.com>, gdb-patches@sourceware.org
Cc: Shahab Vahedi <shahab@synopsys.com>,
	Andrew Burgess <andrew.burgess@embecosm.com>,
	Tom Tromey <tom@tromey.com>,
	Claudiu Zissulescu <claziss@synopsys.com>,
	Francois Bedard <fbedard@synopsys.com>
Subject: Re: [PATCH v2][PR tui/9765] Fix segfault in asm TUI when reaching end of file
Date: Fri, 10 Jan 2020 12:53:00 -0000	[thread overview]
Message-ID: <8f3c2363-6ab8-ce73-0f4b-b0b9efca6815@redhat.com> (raw)
In-Reply-To: <20200110115728.13940-1-shahab.vahedi@gmail.com>

On 1/10/20 11:57 AM, Shahab Vahedi wrote:
> 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.  */
> +	}
>  

I didn't delve deep into the patch, but, I should point out one
thing -- as described in the PR, it's a problem to let exceptions
cross ncurses.  Any kind of C++ exception.  So which ncurses callback/entry
point in gdb were we at?  We need to look into it and make sure that
no exceptions are thrown from it back into ncurses.  Above, you're rethrowing
non-memory exceptions, which is what made me wonder, since it sounds like
for  example a Ctrl-C at some "wrong" time may bring down GDB.
For readline, we ended up with TRY_SJLJ/CATCH_SJLJ.

>        asm_lines[pos + i].insn = std::move (gdb_dis_out.string ());
>  
> 

Thanks,
Pedro Alves


       reply	other threads:[~2020-01-10 12:53 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200110115728.13940-1-shahab.vahedi@gmail.com>
2020-01-10 12:53 ` Pedro Alves [this message]
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 22:04       ` [PATCH 1/2] gdb/tui: Prevent exceptions from trying to cross readline Andrew Burgess
2020-01-15  0:56         ` Tom Tromey
     [not found]       ` <cover.1578948166.git.andrew.burgess@embecosm.com>
2020-01-14 14:19         ` [PATCH 0/2] gdb/tui: Assembler window scrolling fixes 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 1/2] gdb/tui: Update help text for scroll commands Andrew Burgess
2020-01-26 16:07               ` Tom Tromey
2020-01-24 21:22             ` [PATCH 0/2] Further Assembler Scrolling Fixes Andrew Burgess
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-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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8f3c2363-6ab8-ce73-0f4b-b0b9efca6815@redhat.com \
    --to=palves@redhat.com \
    --cc=andrew.burgess@embecosm.com \
    --cc=claziss@synopsys.com \
    --cc=fbedard@synopsys.com \
    --cc=gdb-patches@sourceware.org \
    --cc=shahab.vahedi@gmail.com \
    --cc=shahab@synopsys.com \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox