Blame SOURCES/gdb-rhbz1084404-ppc64-s390x-wrong-prologue-skip-O2-g-1of3.patch

7b26da
commit 6e22494e5076e4d3c0b2c2785883162f83db499e
7b26da
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
7b26da
Date:   Fri Jun 26 15:11:14 2015 +0200
7b26da
7b26da
    Do not skip prologue for asm (.S) files
7b26da
    
7b26da
    GDB tries to skip prologue for .S files according to .debug_line but it then
7b26da
    places the breakpoint to a location where it is never hit.
7b26da
    
7b26da
    This is because #defines in .S files cause prologue skipping which is
7b26da
    completely inappropriate, for s390x:
7b26da
    
7b26da
    glibc/sysdeps/unix/syscall-template.S
7b26da
    78:/* This is a "normal" system call stub: if there is an error,
7b26da
    79:   it returns -1 and sets errno.  */
7b26da
    80:
7b26da
    81:T_PSEUDO (SYSCALL_SYMBOL, SYSCALL_NAME, SYSCALL_NARGS)
7b26da
    82:     ret
7b26da
    
7b26da
    00000000000f4210 T __select
7b26da
     Line Number Statements:
7b26da
      Extended opcode 2: set Address to 0xf41c8
7b26da
      Advance Line by 80 to 81
7b26da
      Copy
7b26da
      Advance PC by 102 to 0xf422e
7b26da
      Special opcode 6: advance Address by 0 to 0xf422e and Line by 1 to 82
7b26da
      Special opcode 34: advance Address by 2 to 0xf4230 and Line by 1 to 83
7b26da
      Advance PC by 38 to 0xf4256
7b26da
      Extended opcode 1: End of Sequence
7b26da
      Compilation Unit @ offset 0x28b3e0:
7b26da
     <0><28b3eb>: Abbrev Number: 1 (DW_TAG_compile_unit)
7b26da
        <28b3ec>   DW_AT_stmt_list   : 0x7b439
7b26da
        <28b3f0>   DW_AT_low_pc	 : 0xf41c8
7b26da
        <28b3f8>   DW_AT_high_pc     : 0xf4256
7b26da
        <28b400>   DW_AT_name        : ../sysdeps/unix/syscall-template.S
7b26da
        <28b423>   DW_AT_comp_dir    : /usr/src/debug////////glibc-2.17-c758a686/misc
7b26da
        <28b452>   DW_AT_producer    : GNU AS 2.23.52.0.1
7b26da
        <28b465>   DW_AT_language    : 32769        (MIPS assembler)
7b26da
    
7b26da
    without debuginfo or with debuginfo and the fix - correct address:
7b26da
    (gdb) b select
7b26da
    Breakpoint 1 at 0xf4210
7b26da
    
7b26da
    It is also where .dynsym+.symtab point to:
7b26da
    00000000000f4210 T __select
7b26da
    00000000000f4210 W select
7b26da
    
7b26da
    with debuginfo, without the fix:
7b26da
    (gdb) b select
7b26da
    Breakpoint 1 at 0xf41c8: file ../sysdeps/unix/syscall-template.S, line 81.
7b26da
    
7b26da
    One part is to behave for asm files similar way like for 'locations_valid':
7b26da
      /* Symtab has been compiled with both optimizations and debug info so that
7b26da
         GDB may stop skipping prologues as variables locations are valid already
7b26da
         at function entry points.  */
7b26da
      unsigned int locations_valid : 1;
7b26da
    
7b26da
    The other part is to extend the 'locations_valid'-like functionality more.
7b26da
    
7b26da
    Both minsym_found and find_function_start_sal need to be patched, otherwise
7b26da
    their addresses do not match and GDB regresses on ppc64:
7b26da
    
7b26da
    gdb/ChangeLog
7b26da
    2015-06-26  Jan Kratochvil  <jan.kratochvil@redhat.com>
7b26da
    
7b26da
    	* linespec.c (minsym_found): Reset sal.PC for COMPUNIT_LOCATIONS_VALID
7b26da
    	and language_asm..
7b26da
    	* symtab.c (find_function_start_sal): Likewise.
7b26da
    
7b26da
    gdb/testsuite/ChangeLog
7b26da
    2015-06-26  Jan Kratochvil  <jan.kratochvil@redhat.com>
7b26da
    
7b26da
    	* gdb.arch/amd64-prologue-skip.S: New file.
7b26da
    	* gdb.arch/amd64-prologue-skip.exp: New file.
7b26da
7b26da
Index: gdb-7.6.1/gdb/linespec.c
7b26da
===================================================================
7b26da
--- gdb-7.6.1.orig/gdb/linespec.c
7b26da
+++ gdb-7.6.1/gdb/linespec.c
7b26da
@@ -3386,7 +3386,9 @@ collect_symbols (struct symbol *sym, voi
7b26da
 }
7b26da
 
7b26da
 /* We've found a minimal symbol MSYMBOL in OBJFILE to associate with our
7b26da
-   linespec; return the SAL in RESULT.  */
7b26da
+   linespec; return the SAL in RESULT.  This function should return SALs
7b26da
+   matching those from find_function_start_sal, otherwise false
7b26da
+   multiple-locations breakpoints could be placed.  */
7b26da
 
7b26da
 static void
7b26da
 minsym_found (struct linespec_state *self, struct objfile *objfile,
7b26da
@@ -3408,7 +3410,23 @@ minsym_found (struct linespec_state *sel
7b26da
     sal = find_pc_sect_line (pc, NULL, 0);
7b26da
 
7b26da
   if (self->funfirstline)
7b26da
-    skip_prologue_sal (&sal;;
7b26da
+    {
7b26da
+      if (sal.symtab != NULL
7b26da
+	  && (sal.symtab->locations_valid
7b26da
+	      || sal.symtab->language == language_asm))
7b26da
+	{
7b26da
+	  /* If gdbarch_convert_from_func_ptr_addr does not apply then
7b26da
+	     sal.SECTION, sal.LINE&co. will stay correct from above.
7b26da
+	     If gdbarch_convert_from_func_ptr_addr applies then
7b26da
+	     sal.SECTION is cleared from above and sal.LINE&co. will
7b26da
+	     stay correct from the last find_pc_sect_line above.  */
7b26da
+	  sal.pc = SYMBOL_VALUE_ADDRESS (msymbol);
7b26da
+	  sal.pc = gdbarch_convert_from_func_ptr_addr (gdbarch, sal.pc,
7b26da
+						       &current_target);
7b26da
+	}
7b26da
+      else
7b26da
+	skip_prologue_sal (&sal;;
7b26da
+    }
7b26da
 
7b26da
   if (maybe_add_address (self->addr_set, objfile->pspace, sal.pc))
7b26da
     add_sal_to_sals (self, result, &sal, SYMBOL_NATURAL_NAME (msymbol), 0);
7b26da
Index: gdb-7.6.1/gdb/symtab.c
7b26da
===================================================================
7b26da
--- gdb-7.6.1.orig/gdb/symtab.c
7b26da
+++ gdb-7.6.1/gdb/symtab.c
7b26da
@@ -2762,7 +2762,9 @@ skip_prologue_using_lineinfo (CORE_ADDR
7b26da
 /* Given a function symbol SYM, find the symtab and line for the start
7b26da
    of the function.
7b26da
    If the argument FUNFIRSTLINE is nonzero, we want the first line
7b26da
-   of real code inside the function.  */
7b26da
+   of real code inside the function.
7b26da
+   This function should return SALs matching those from minsym_found,
7b26da
+   otherwise false multiple-locations breakpoints could be placed.  */
7b26da
 
7b26da
 struct symtab_and_line
7b26da
 find_function_start_sal (struct symbol *sym, int funfirstline)
7b26da
@@ -2773,6 +2775,14 @@ find_function_start_sal (struct symbol *
7b26da
   sal = find_pc_sect_line (BLOCK_START (SYMBOL_BLOCK_VALUE (sym)),
7b26da
 			   SYMBOL_OBJ_SECTION (sym), 0);
7b26da
 
7b26da
+  if (funfirstline && sal.symtab != NULL
7b26da
+      && (sal.symtab->locations_valid
7b26da
+	  || sal.symtab->language == language_asm))
7b26da
+    {
7b26da
+      sal.pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
7b26da
+      return sal;
7b26da
+    }
7b26da
+
7b26da
   /* We always should have a line for the function start address.
7b26da
      If we don't, something is odd.  Create a plain SAL refering
7b26da
      just the PC and hope that skip_prologue_sal (if requested)
7b26da
Index: gdb-7.6.1/gdb/testsuite/gdb.arch/amd64-prologue-skip.S
7b26da
===================================================================
7b26da
--- /dev/null
7b26da
+++ gdb-7.6.1/gdb/testsuite/gdb.arch/amd64-prologue-skip.S
7b26da
@@ -0,0 +1,28 @@
7b26da
+/* This testcase is part of GDB, the GNU debugger.
7b26da
+
7b26da
+   Copyright 2015 Free Software Foundation, Inc.
7b26da
+
7b26da
+   This program is free software; you can redistribute it and/or modify
7b26da
+   it under the terms of the GNU General Public License as published by
7b26da
+   the Free Software Foundation; either version 3 of the License, or
7b26da
+   (at your option) any later version.
7b26da
+
7b26da
+   This program is distributed in the hope that it will be useful,
7b26da
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
7b26da
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7b26da
+   GNU General Public License for more details.
7b26da
+
7b26da
+   You should have received a copy of the GNU General Public License
7b26da
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
7b26da
+
7b26da
+	.text
7b26da
+/*0*/	hlt
7b26da
+pushrbp: .globl pushrbp
7b26da
+#define PUSHRBP push %rbp; mov %rsp, %rbp; nop
7b26da
+/*1*/	PUSHRBP
7b26da
+/*6*/	hlt
7b26da
+
7b26da
+/*7*/	hlt
7b26da
+#define MINSYM nop; .globl minsym; minsym: nop
7b26da
+/*8*/	MINSYM
7b26da
+/*a*/	hlt
7b26da
Index: gdb-7.6.1/gdb/testsuite/gdb.arch/amd64-prologue-skip.exp
7b26da
===================================================================
7b26da
--- /dev/null
7b26da
+++ gdb-7.6.1/gdb/testsuite/gdb.arch/amd64-prologue-skip.exp
7b26da
@@ -0,0 +1,35 @@
7b26da
+# Copyright 2010-2015 Free Software Foundation, Inc.
7b26da
+
7b26da
+# This program is free software; you can redistribute it and/or modify
7b26da
+# it under the terms of the GNU General Public License as published by
7b26da
+# the Free Software Foundation; either version 3 of the License, or
7b26da
+# (at your option) any later version.
7b26da
+#
7b26da
+# This program is distributed in the hope that it will be useful,
7b26da
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
7b26da
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7b26da
+# GNU General Public License for more details.
7b26da
+#
7b26da
+# You should have received a copy of the GNU General Public License
7b26da
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
7b26da
+
7b26da
+standard_testfile .S
7b26da
+set binfile ${binfile}.o
7b26da
+
7b26da
+if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
7b26da
+    verbose "Skipping ${testfile}."
7b26da
+    return
7b26da
+}
7b26da
+
7b26da
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {debug}] != "" } {
7b26da
+    untested ${testfile}
7b26da
+    return
7b26da
+}
7b26da
+
7b26da
+clean_restart ${binfile}
7b26da
+
7b26da
+gdb_test "break *pushrbp" " at 0x1: file .*"
7b26da
+gdb_test "break pushrbp" " at 0x1: file .*"
7b26da
+
7b26da
+gdb_test "break *minsym" " at 0x9: file .*"
7b26da
+gdb_test "break minsym" " at 0x9: file .*"