Bug 17379

Summary: PowerPC: internal-error: value_of_register_lazy: Assertion `frame_id_p (get_frame_id (frame))' failed.
Product: gdb Reporter: Edjunior Machado <emachado>
Component: tdepAssignee: Edjunior Machado <emachado>
Severity: normal CC: palves, uweigand, uweigand
Priority: P2    
Version: HEAD   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:

Description Edjunior Machado 2014-09-11 20:55:39 UTC
GDB throws this internal-error when debugging a piece of code in ppc64 (also reproducible in ppc64le):

$ cat bug.S 
#include <ppc-asm.h>
        li      sp,0
        mtlr    sp

$ gcc -g bug.S -o bug

$ ~/gdb/binutils-gdb.git/build.orig/gdb/gdb ./bug 
GNU gdb (GDB)
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "powerpc64-unknown-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
Find the GDB manual and other documentation resources online at:
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./bug...done.
(gdb) run
Starting program: /home/emachado/gdb/bugs/bug 

Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) info registers 
../../gdb/findvar.c:290: internal-error: value_of_register_lazy: Assertion `frame_id_p (get_frame_id (frame))' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) y

This is a bug, please report it.  For instructions, see:

../../gdb/findvar.c:290: internal-error: value_of_register_lazy: Assertion `frame_id_p (get_frame_id (frame))' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Create a core file of GDB? (y or n) n
Comment 1 Pedro Alves 2014-09-12 09:17:24 UTC
A backtrace would be good.  If indeed the frame doesn't have a valid id, then it'd be a bug in the unwinder.
Comment 2 Ulrich Weigand 2014-09-12 09:28:04 UTC
Hi Pedro, the problem was in rs6000_frame_cache, where a read_memory_unsigned_integer would throw an exception if the stack is invalid.  This exception was caught somewhere higher up in the frame unwinding logic, but this lead to a situation where frame 0 was marked invalid, which the rest of GDB doesn't really handle well.

Edjunior has already posted a patch to the list.
Comment 3 Pedro Alves 2014-09-12 10:01:21 UTC
Ah, indeed, hadn't seen it yet:

Comment 4 cvs-commit@gcc.gnu.org 2014-09-12 12:29:20 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gdb and binutils".

The branch, master has been updated
       via  9d9bf2df89db515958b429a1aeb1db38884ba488 (commit)
      from  1cf2f1b045e9e647f6dfd28829ff4592c588dcb7 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------

commit 9d9bf2df89db515958b429a1aeb1db38884ba488
Author: Edjunior Barbosa Machado <emachado@linux.vnet.ibm.com>
Date:   Fri Sep 12 09:20:25 2014 -0300

    PR tdep/17379: Fix internal-error when stack pointer is invalid.
    The problem is that rs6000_frame_cache attempts to read the stack backchain via
    read_memory_unsigned_integer, which throws an exception if the stack pointer is
    invalid.  With this patch, it calls safe_read_memory_integer instead, which
    doesn't throw an exception and allows for safe handling of that situation.
    2014-09-12  Edjunior Barbosa Machado  <emachado@linux.vnet.ibm.com>
    	    Ulrich Weigand´┐Ż <uweigand@de.ibm.com>
    	PR tdep/17379
    	* rs6000-tdep.c (rs6000_frame_cache): Use safe_read_memory_integer
    	instead of read_memory_unsigned_integer.
    2014-09-12  Edjunior Barbosa Machado  <emachado@linux.vnet.ibm.com>
    	PR tdep/17379
    	* gdb.arch/powerpc-stackless.S: New file.
    	* gdb.arch/powerpc-stackless.exp: New file.


Summary of changes:
 gdb/ChangeLog                                |    7 ++++
 gdb/rs6000-tdep.c                            |   11 +++++--
 gdb/testsuite/ChangeLog                      |    6 ++++
 gdb/testsuite/gdb.arch/powerpc-stackless.S   |   24 +++++++++++++++
 gdb/testsuite/gdb.arch/powerpc-stackless.exp |   42 ++++++++++++++++++++++++++
 5 files changed, 87 insertions(+), 3 deletions(-)
 create mode 100644 gdb/testsuite/gdb.arch/powerpc-stackless.S
 create mode 100644 gdb/testsuite/gdb.arch/powerpc-stackless.exp
Comment 5 Edjunior Machado 2014-09-12 13:04:39 UTC
Marking this bugzilla as fixed.