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

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