[v2] gdb: xtensa: fix frame initialization when PC is invalid

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

Commit Message

Max Filippov March 29, 2016, 6:17 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.

Use safe_read_memory_integer instead.

2016-03-29  Max Filippov  <jcmvbkbc@gmail.com>
gdb/
	* xtensa-tdep.c (xtensa_frame_cache): Use
	safe_read_memory_integer instead of read_memory_integer.
---
Changes v1->v2:
- use safe_read_memory_integer instead of TRY/CATCH block.

 gdb/xtensa-tdep.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Pedro Alves March 29, 2016, 7:09 p.m. UTC | #1
On 03/29/2016 07:17 PM, Max Filippov wrote:
> -      op1 = read_memory_integer (pc, 1, byte_order);
> -      if (XTENSA_IS_ENTRY (gdbarch, op1))
> +      if (safe_read_memory_integer (pc, 1, byte_order, &op1)
> +	  && XTENSA_IS_ENTRY (gdbarch, op1))
>   	{

I'm surprised if this compiles without an "incompatible pointer type"
warning/error?  safe_read_memory_integer's last parameter is
'LONGEST *', while op1 is 'char', AFAICS.  So you need to change op1
to be a LONGEST to match.

Thanks,
Pedro Alves
  
Max Filippov March 29, 2016, 7:56 p.m. UTC | #2
On Tue, Mar 29, 2016 at 10:09 PM, Pedro Alves <palves@redhat.com> wrote:
> On 03/29/2016 07:17 PM, Max Filippov wrote:
>> -      op1 = read_memory_integer (pc, 1, byte_order);
>> -      if (XTENSA_IS_ENTRY (gdbarch, op1))
>> +      if (safe_read_memory_integer (pc, 1, byte_order, &op1)
>> +       && XTENSA_IS_ENTRY (gdbarch, op1))
>>       {
>
> I'm surprised if this compiles without an "incompatible pointer type"
> warning/error?  safe_read_memory_integer's last parameter is
> 'LONGEST *', while op1 is 'char', AFAICS.  So you need to change op1
> to be a LONGEST to match.

You're right, sorry. I've checked that it builds and works, but I've missed
that it was configured with --disable-werror.
  

Patch

diff --git a/gdb/xtensa-tdep.c b/gdb/xtensa-tdep.c
index 9e87fa5..9aa6232 100644
--- a/gdb/xtensa-tdep.c
+++ b/gdb/xtensa-tdep.c
@@ -1293,8 +1293,8 @@  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);
-      if (XTENSA_IS_ENTRY (gdbarch, op1))
+      if (safe_read_memory_integer (pc, 1, byte_order, &op1)
+	  && XTENSA_IS_ENTRY (gdbarch, op1))
 	{
 	  int callinc = CALLINC (ps);
 	  ra = get_frame_register_unsigned