Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Shahab Vahedi <shahab.vahedi@gmail.com>
To: gdb@sourceware.org
Cc: Andrew Burgess <andrew.burgess@embecosm.com>,
	Pedro Alves <palves@redhat.com>
Subject: Re: Getting rid of "Cannot access memory at address ..."
Date: Wed, 08 Jan 2020 13:03:00 -0000	[thread overview]
Message-ID: <20200108130316.GB3752@gmail.com> (raw)
In-Reply-To: <20200104120749.GA166189@gmail.com>

After talking with Andrew, it seemes a possible solution could be using
try/catch to catch the usual suspect (a.k.a. MEMORY_ERROR):

Please let me know what you think of this change?

 diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c
 index 98c691f3387..7faaa45f039 100644
 --- a/gdb/tui/tui-disasm.c
 +++ b/gdb/tui/tui-disasm.c
 @@ -226,7 +226,18 @@ tui_disasm_window::set_contents (struct gdbarch *arch,
    /* Get temporary table that will hold all strings (addr & insn).  */
    std::vector<tui_asm_line> asm_lines (max_lines);
    size_t addr_size = 0;
 -  tui_disassemble (gdbarch, asm_lines, pc, 0, max_lines, &addr_size);
 +  try
 +    {
 +      tui_disassemble (gdbarch, asm_lines, pc, 0, max_lines, &addr_size);
 +    }
 +  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;
 +    }
  
    /* Align instructions to the same column.  */
    insn_pos = (1 + (addr_size / tab_len)) * tab_len;

My only concern is what if we have MEMORY_ERROR exception for reasons other
than disassembling PC addresses that just went beyond the valid range. Do
such reasons exist in this scenario?

--
Shahab


  reply	other threads:[~2020-01-08 13:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-04 12:07 Shahab Vahedi
2020-01-08 13:03 ` Shahab Vahedi [this message]
2020-01-08 13:48 ` Shahab Vahedi

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=20200108130316.GB3752@gmail.com \
    --to=shahab.vahedi@gmail.com \
    --cc=andrew.burgess@embecosm.com \
    --cc=gdb@sourceware.org \
    --cc=palves@redhat.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