Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* Getting rid of "Cannot access memory at address ..."
@ 2020-01-04 12:07 Shahab Vahedi
  2020-01-08 13:03 ` Shahab Vahedi
  2020-01-08 13:48 ` Shahab Vahedi
  0 siblings, 2 replies; 3+ messages in thread
From: Shahab Vahedi @ 2020-01-04 12:07 UTC (permalink / raw)
  To: gdb

Hello everyone,

I have sumbitted a bug [1]. I am not going to repeat the whole
description here but only the part pertaining to the solution.

To solve the whole bug completely, there are 2 things to tackle:

1. The overflow occuring in "tui_disasm_window::addr_is_displayed".
   A patch has been submitted [2].

2. Calculation of "max_lines" in "tui_disasm_window::set_contents".
   Ideally, "max_lines" should be:
     max_lines = std::min<int>(height-2,
                               number_of_instructions_in_elf);

However, it's not trivial (to me) how to get the number of
instructions that exist there. Any thought on that?

--
Shahab

[1]
https://sourceware.org/bugzilla/show_bug.cgi?id=25345

[2]
with title: [PATCH] GDB: Fix the overflow in addr_is_displayed()


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

* Re: Getting rid of "Cannot access memory at address ..."
  2020-01-04 12:07 Getting rid of "Cannot access memory at address ..." Shahab Vahedi
@ 2020-01-08 13:03 ` Shahab Vahedi
  2020-01-08 13:48 ` Shahab Vahedi
  1 sibling, 0 replies; 3+ messages in thread
From: Shahab Vahedi @ 2020-01-08 13:03 UTC (permalink / raw)
  To: gdb; +Cc: Andrew Burgess, Pedro Alves

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


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

* Re: Getting rid of "Cannot access memory at address ..."
  2020-01-04 12:07 Getting rid of "Cannot access memory at address ..." Shahab Vahedi
  2020-01-08 13:03 ` Shahab Vahedi
@ 2020-01-08 13:48 ` Shahab Vahedi
  1 sibling, 0 replies; 3+ messages in thread
From: Shahab Vahedi @ 2020-01-08 13:48 UTC (permalink / raw)
  To: gdb; +Cc: Andrew Burgess, Pedro Alves

After talking with Andrew, it seems 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


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

end of thread, other threads:[~2020-01-08 13:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-04 12:07 Getting rid of "Cannot access memory at address ..." Shahab Vahedi
2020-01-08 13:03 ` Shahab Vahedi
2020-01-08 13:48 ` Shahab Vahedi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox