public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [patch] Do not skip prologue for asm (.S) files
@ 2015-06-20 15:44 Jan Kratochvil
  2015-06-21 22:52 ` Doug Evans
  0 siblings, 1 reply; 9+ messages in thread
From: Jan Kratochvil @ 2015-06-20 15:44 UTC (permalink / raw)
  To: gdb-patches; +Cc: Sergio Durigan Junior

[-- Attachment #1: Type: text/plain, Size: 2080 bytes --]

Hi,

https://bugzilla.redhat.com/show_bug.cgi?id=1084404

GDB tries to skip prologue for .S files according to .debug_line but it then
places the breakpoint to a location where it is never hit.

This is because #defines in .S files cause prologue skipping which is
completely inappropriate, for s390x:

glibc/sysdeps/unix/syscall-template.S
78:/* This is a "normal" system call stub: if there is an error,
79:   it returns -1 and sets errno.  */
80:
81:T_PSEUDO (SYSCALL_SYMBOL, SYSCALL_NAME, SYSCALL_NARGS)
82:     ret

00000000000f4210 T __select
 Line Number Statements:
  Extended opcode 2: set Address to 0xf41c8
  Advance Line by 80 to 81
  Copy
  Advance PC by 102 to 0xf422e
  Special opcode 6: advance Address by 0 to 0xf422e and Line by 1 to 82
  Special opcode 34: advance Address by 2 to 0xf4230 and Line by 1 to 83
  Advance PC by 38 to 0xf4256
  Extended opcode 1: End of Sequence
  Compilation Unit @ offset 0x28b3e0:
 <0><28b3eb>: Abbrev Number: 1 (DW_TAG_compile_unit)
    <28b3ec>   DW_AT_stmt_list   : 0x7b439
    <28b3f0>   DW_AT_low_pc      : 0xf41c8
    <28b3f8>   DW_AT_high_pc     : 0xf4256
    <28b400>   DW_AT_name        : ../sysdeps/unix/syscall-template.S
    <28b423>   DW_AT_comp_dir    : /usr/src/debug////////glibc-2.17-c758a686/misc
    <28b452>   DW_AT_producer    : GNU AS 2.23.52.0.1
    <28b465>   DW_AT_language    : 32769        (MIPS assembler)

without debuginfo - correct address:
(gdb) b select
Breakpoint 1 at 0xf4210

with debuginfo, either with or without the fix:
(gdb) b select
Breakpoint 1 at 0xf41c8: file ../sysdeps/unix/syscall-template.S, line 81.


One part is to make 'locations_valid' true even for asm files.
  /* Symtab has been compiled with both optimizations and debug info so that
     GDB may stop skipping prologues as variables locations are valid already
     at function entry points.  */
  unsigned int locations_valid : 1;

The other part is to extend the 'locations_valid' functionality more - I have
chosen mostly randomly this place.

No regressions on {x86_64,x86_64-m32,i686}-fedora23pre-linux-gnu.


Jan

[-- Attachment #2: locvalid3.patch --]
[-- Type: text/plain, Size: 4359 bytes --]

gdb/ChangeLog
2015-06-20  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* dwarf2read.c (process_full_comp_unit): Set LOCATIONS_VALID also for
	language_asm.
	* linespec.c (minsym_found): Reset sal.PC forCOMPUNIT_LOCATIONS_VALID.

gdb/testsuite/ChangeLog
2015-06-20  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.arch/amd64-prologue-skip.S: New file.
	* gdb.arch/amd64-prologue-skip.exp: New file.

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index d79b2e3..76ff66d 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -8096,7 +8096,7 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
 	 Still one can confuse GDB by using non-standard GCC compilation
 	 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
 	 */ 
-      if (cu->has_loclist && gcc_4_minor >= 5)
+      if ((cu->has_loclist && gcc_4_minor >= 5) || cu->language == language_asm)
 	cust->locations_valid = 1;
 
       if (gcc_4_minor >= 5)
diff --git a/gdb/linespec.c b/gdb/linespec.c
index d2089b5..a7ea41b 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -3454,7 +3454,17 @@ minsym_found (struct linespec_state *self, struct objfile *objfile,
     sal = find_pc_sect_line (pc, NULL, 0);
 
   if (self->funfirstline)
-    skip_prologue_sal (&sal);
+    {
+      if (sal.symtab != NULL
+	  && COMPUNIT_LOCATIONS_VALID (SYMTAB_COMPUNIT (sal.symtab)))
+	{
+	  sal.pc = MSYMBOL_VALUE_ADDRESS (objfile, msymbol);
+	  sal.pc = gdbarch_convert_from_func_ptr_addr (gdbarch, sal.pc,
+						       &current_target);
+	}
+      else
+	skip_prologue_sal (&sal);
+    }
 
   if (maybe_add_address (self->addr_set, objfile->pspace, sal.pc))
     add_sal_to_sals (self, result, &sal, MSYMBOL_NATURAL_NAME (msymbol), 0);
diff --git a/gdb/testsuite/gdb.arch/amd64-prologue-skip.S b/gdb/testsuite/gdb.arch/amd64-prologue-skip.S
new file mode 100644
index 0000000..66b806a
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/amd64-prologue-skip.S
@@ -0,0 +1,28 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2015 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+	.text
+/*0*/	hlt
+pushrbp: .globl pushrbp
+#define PUSHRBP push %rbp; mov %rsp, %rbp; nop
+/*1*/	PUSHRBP
+/*6*/	hlt
+
+/*7*/	hlt
+#define MINSYM nop; .globl minsym; minsym: nop
+/*8*/	MINSYM
+/*a*/	hlt
diff --git a/gdb/testsuite/gdb.arch/amd64-prologue-skip.exp b/gdb/testsuite/gdb.arch/amd64-prologue-skip.exp
new file mode 100644
index 0000000..015cd69
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/amd64-prologue-skip.exp
@@ -0,0 +1,35 @@
+# Copyright 2010-2015 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+standard_testfile .S
+set binfile ${binfile}.o
+
+if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
+    verbose "Skipping ${testfile}."
+    return
+}
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {debug}] != "" } {
+    untested ${testfile}
+    return
+}
+
+clean_restart ${binfile}
+
+gdb_test "break *pushrbp" " at 0x1: file .*"
+gdb_test "break pushrbp" " at 0x1: file .*"
+
+gdb_test "break *minsym" " at 0x9: file .*"
+gdb_test "break minsym" " at 0x9: file .*"

^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: [patch] Do not skip prologue for asm (.S) files
@ 2015-06-25 20:30 Doug Evans
  2015-06-25 20:37 ` Jan Kratochvil
  0 siblings, 1 reply; 9+ messages in thread
From: Doug Evans @ 2015-06-25 20:30 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches, Sergio Durigan Junior

Jan Kratochvil writes:
  > On Tue, 23 Jun 2015 22:35:01 +0200, Jan Kratochvil wrote:
  > > On Tue, 23 Jun 2015 01:46:08 +0200, Doug Evans wrote:
  > > > static void
  > > > minsym_found (struct linespec_state *self, struct objfile *objfile,
  > > >               struct minimal_symbol *msymbol,
  > > >               struct symtabs_and_lines *result)
  > > > {
  > > >   struct gdbarch *gdbarch = get_objfile_arch (objfile);
  > > >   CORE_ADDR pc;
  > > >   struct symtab_and_line sal;
  > > >
  > > >   sal = find_pc_sect_line (MSYMBOL_VALUE_ADDRESS (objfile, msymbol),
  > > >                            (struct obj_section *) 0, 0);
  > > >   sal.section = MSYMBOL_OBJ_SECTION (objfile, msymbol);
  > > >
  > > >   /* The minimal symbol might point to a function descriptor;
  > > >      resolve it to the actual code address instead.  */
  > > >   pc = gdbarch_convert_from_func_ptr_addr (gdbarch, sal.pc,  
&current_target);
  > > >   if (pc != sal.pc)
  > > >     sal = find_pc_sect_line (pc, NULL, 0);
  > > >
  > > >   if (self->funfirstline)
  > > >     skip_prologue_sal (&sal);
  > > >
  > > >   if (maybe_add_address (self->addr_set, objfile->pspace, sal.pc))
  > > >     add_sal_to_sals (self, result, &sal, MSYMBOL_NATURAL_NAME  
(msymbol), 0);
  > > > }
  > > >
  > > > With the patch added, we're using the value of
  > > > MSYMBOL_VALUE_ADDRESS twice
  > > > and calling gdbarch_convert_from_func_ptr_addr twice.
  > > > [I'm not micro-optimizing here, my goal is code readability.]
  > > >
  > > > Plus the patch does:
  > > >
  > > >       sal.pc = MSYMBOL_VALUE_ADDRESS (objfile, msymbol);
  > > >       sal.pc = gdbarch_convert_from_func_ptr_addr (gdbarch, sal.pc,
  > > >                                                   &current_target);
  > > >
  > > > but it doesn't update sal.section nor sal.line.
  > >
  > > OK, I agree that seems wrong.
  >
  > I do not agree, it seems correct to me.

I was wondering if things were correct, not stating they weren't.

  > I have only added a comment to the code.  Is it enough this way?

The comment helps, thanks.
I'm still uncomfortable with setting locations_valid for assembler.
The flag may get used for more things in the future, and this feels
like asking for trouble.
Fortunately, I think there's a better way: instead of setting  
locations_valid
check the language at the place where we care.

diff --git a/gdb/linespec.c b/gdb/linespec.c
index d2089b5..71bab61 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -3454,7 +3454,23 @@ minsym_found (struct linespec_state *self, struct  
objfile *objfile,
      sal = find_pc_sect_line (pc, NULL, 0);

    if (self->funfirstline)
-    skip_prologue_sal (&sal);
+    {
+      if (sal.symtab != NULL
+	  && (COMPUNIT_LOCATIONS_VALID (SYMTAB_COMPUNIT (sal.symtab))
+	      || SYMTAB_LANGUAGE (sal.symtab) == language_asm))
+	{
+	  /* If gdbarch_convert_from_func_ptr_addr does not apply then
+	     sal.SECTION, sal.LINE&co. will stay correct from above.
+	     If gdbarch_convert_from_func_ptr_addr applies then
+	     sal.SECTION is cleared from above and sal.LINE&co. will
+	     stay correct from the last find_pc_sect_line above.  */
+	  sal.pc = MSYMBOL_VALUE_ADDRESS (objfile, msymbol);
+	  sal.pc = gdbarch_convert_from_func_ptr_addr (gdbarch, sal.pc,
+						       &current_target);
+	}
+      else
+	skip_prologue_sal (&sal);
+    }

    if (maybe_add_address (self->addr_set, objfile->pspace, sal.pc))
      add_sal_to_sals (self, result, &sal, MSYMBOL_NATURAL_NAME (msymbol),  
0);


[and leave dwarf2read.c as is]

Ok with this change.
Thanks!

  > I am sorry I cannot write it much cleanly as the data structures and  
functions
  > involved are not much clean.
  >
  >
  > Jan
  > gdb/ChangeLog
  > 2015-06-20  Jan Kratochvil  <jan.kratochvil@redhat.com>
  >
  > 	* dwarf2read.c (process_full_comp_unit): Set LOCATIONS_VALID also for
  > 	language_asm.
  > 	* linespec.c (minsym_found): Reset sal.PC forCOMPUNIT_LOCATIONS_VALID.
  >
  > gdb/testsuite/ChangeLog
  > 2015-06-20  Jan Kratochvil  <jan.kratochvil@redhat.com>
  >
  > 	* gdb.arch/amd64-prologue-skip.S: New file.
  > 	* gdb.arch/amd64-prologue-skip.exp: New file.
  >

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-06-25 20:37 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-20 15:44 [patch] Do not skip prologue for asm (.S) files Jan Kratochvil
2015-06-21 22:52 ` Doug Evans
2015-06-22 21:16   ` Jan Kratochvil
2015-06-22 23:46     ` Doug Evans
2015-06-23 20:35       ` Jan Kratochvil
2015-06-24 20:20         ` Jan Kratochvil
2015-06-25 15:47           ` [patchv2] " Jan Kratochvil
2015-06-25 20:30 [patch] " Doug Evans
2015-06-25 20:37 ` Jan Kratochvil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).