gdb: xtensa: fix frame initialization when PC is invalid

Message ID 1459121556-4907-1-git-send-email-jcmvbkbc@gmail.com
State New, archived
Headers

Commit Message

Max Filippov March 27, 2016, 11:32 p.m. UTC
  When gdb is used on core dump and PC is not pointing to a readable
memory read_memory_integer call in the xtensa_frame_cache throws an
error, making register inspection/backtracing impossible in that thread.

Put read_memory_integer into TRY/CATCH block and in case an error is
caught initialize result to something different than ENTRY opcode.

2016-03-27  Max Filippov  <jcmvbkbc@gmail.com>
gdb/
	* xtensa-tdep.c (xtensa_frame_cache): Put read_memory_integer
	into TRY/CATCH block.
---
 gdb/xtensa-tdep.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
  

Comments

Pedro Alves March 29, 2016, 4:52 p.m. UTC | #1
On 03/28/2016 12:32 AM, Max Filippov wrote:
> When gdb is used on core dump and PC is not pointing to a readable
> memory read_memory_integer call in the xtensa_frame_cache throws an
> error, making register inspection/backtracing impossible in that thread.
>
> Put read_memory_integer into TRY/CATCH block and in case an error is
> caught initialize result to something different than ENTRY opcode.
>
> 2016-03-27  Max Filippov  <jcmvbkbc@gmail.com>
> gdb/
> 	* xtensa-tdep.c (xtensa_frame_cache): Put read_memory_integer
> 	into TRY/CATCH block.
> ---
>   gdb/xtensa-tdep.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/gdb/xtensa-tdep.c b/gdb/xtensa-tdep.c
> index 9e87fa5..f37476e 100644
> --- a/gdb/xtensa-tdep.c
> +++ b/gdb/xtensa-tdep.c
> @@ -1293,7 +1293,12 @@ xtensa_frame_cache (struct frame_info *this_frame, void **this_cache)
>         ws = get_frame_register_unsigned (this_frame,
>   					gdbarch_tdep (gdbarch)->ws_regnum);
>
> -      op1 = read_memory_integer (pc, 1, byte_order);
> +      TRY
> +	op1 = read_memory_integer (pc, 1, byte_order);
> +      CATCH (e, RETURN_MASK_ERROR)
> +	op1 = 0;
> +      END_CATCH

This is an odd pattern: use safe_read_memory_integer instead?

You could then write:

       if (safe_read_memory_integer (pc, 1, byte_order, &op1)
           && XTENSA_IS_ENTRY (gdbarch, op1))

avoiding the magic "0".

Thanks,
Pedro Alves
  
Max Filippov March 29, 2016, 6 p.m. UTC | #2
On Tue, Mar 29, 2016 at 7:52 PM, Pedro Alves <palves@redhat.com> wrote:
> On 03/28/2016 12:32 AM, Max Filippov wrote:
>> -      op1 = read_memory_integer (pc, 1, byte_order);
>> +      TRY
>> +       op1 = read_memory_integer (pc, 1, byte_order);
>> +      CATCH (e, RETURN_MASK_ERROR)
>> +       op1 = 0;
>> +      END_CATCH
>
> This is an odd pattern: use safe_read_memory_integer instead?
>
> You could then write:
>
>       if (safe_read_memory_integer (pc, 1, byte_order, &op1)
>           && XTENSA_IS_ENTRY (gdbarch, op1))
>
> avoiding the magic "0".

Thanks, will do.

-- Max
  

Patch

diff --git a/gdb/xtensa-tdep.c b/gdb/xtensa-tdep.c
index 9e87fa5..f37476e 100644
--- a/gdb/xtensa-tdep.c
+++ b/gdb/xtensa-tdep.c
@@ -1293,7 +1293,12 @@  xtensa_frame_cache (struct frame_info *this_frame, void **this_cache)
       ws = get_frame_register_unsigned (this_frame,
 					gdbarch_tdep (gdbarch)->ws_regnum);
 
-      op1 = read_memory_integer (pc, 1, byte_order);
+      TRY
+	op1 = read_memory_integer (pc, 1, byte_order);
+      CATCH (e, RETURN_MASK_ERROR)
+	op1 = 0;
+      END_CATCH
+
       if (XTENSA_IS_ENTRY (gdbarch, op1))
 	{
 	  int callinc = CALLINC (ps);