skip_prologue_using_sal: early exit if assembler

Message ID yjt2vbp5pnje.fsf@ruffy.mtv.corp.google.com
State New, archived
Headers

Commit Message

Doug Evans Sept. 3, 2014, 12:15 a.m. UTC
  Hi.

This patch is part of the discussion I started here:
https://sourceware.org/ml/gdb-patches/2014-08/msg00539.html

The prologue parsing aspect of that discussion is submitted
as a patch here:
https://sourceware.org/ml/gdb-patches/2014-09/msg00079.html

This patch fixes a few failures when tested with clang,
e.g. amd64-disp-step.exp.  There's no point in trying to
use source line info to parse prologues in assembler code.

Regression tested on amd64, i386, aarch64, ppc64 [all linux].

Note: Most of the patch is due to re-indentation.

2014-09-02  Doug Evans  <dje@google.com>

	* symtab.c (skip_prologue_using_sal): Return zero if called for
	assembler code.
  

Comments

Doug Evans Sept. 3, 2014, 4:55 p.m. UTC | #1
On Tue, Sep 2, 2014 at 5:15 PM, Doug Evans <dje@google.com> wrote:
> Hi.
>
> This patch is part of the discussion I started here:
> https://sourceware.org/ml/gdb-patches/2014-08/msg00539.html
>
> The prologue parsing aspect of that discussion is submitted
> as a patch here:
> https://sourceware.org/ml/gdb-patches/2014-09/msg00079.html
>
> This patch fixes a few failures when tested with clang,
> e.g. amd64-disp-step.exp.  There's no point in trying to
> use source line info to parse prologues in assembler code.
>
> Regression tested on amd64, i386, aarch64, ppc64 [all linux].
>
> Note: Most of the patch is due to re-indentation.
>
> 2014-09-02  Doug Evans  <dje@google.com>
>
>         * symtab.c (skip_prologue_using_sal): Return zero if called for
>         assembler code.

btw, I think a case can be made to return func_addr here instead of zero.
IOW define things such that if we know we're in assembler there
is never any prologue (for symtab-and-line based prologue skipping).
If the caller wants to be "clever" for assembler they can do so.

And if ever someone wants symtab-and-line based prologue skipping
for assembler to detect and skip a prologue then
implement support for DW_LNS_set_prologue_end.
[And if a non-DWARF debug format doesn't support its equivalent, punt.]
  

Patch

diff --git a/gdb/symtab.c b/gdb/symtab.c
index c530d50..a2b051b 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -3139,27 +3139,33 @@  skip_prologue_using_sal (struct gdbarch *gdbarch, CORE_ADDR func_addr)
   prologue_sal = find_pc_line (start_pc, 0);
   if (prologue_sal.line != 0)
     {
+      struct linetable *linetable = LINETABLE (prologue_sal.symtab);
+      int idx = 0;
+
+      /* If this is assembler just punt.
+	 While the assembler code could be implementing a higher level
+	 language and thus could have a logical prologue, we can't really
+	 know what is prologue and what is not using sals (short of using
+	 something like DWARF's DW_LNS_set_prologue_end).  */
+      if (prologue_sal.symtab->language == language_asm)
+	return 0;
+
       /* For languages other than assembly, treat two consecutive line
 	 entries at the same address as a zero-instruction prologue.
 	 The GNU assembler emits separate line notes for each instruction
 	 in a multi-instruction macro, but compilers generally will not
 	 do this.  */
-      if (prologue_sal.symtab->language != language_asm)
-	{
-	  struct linetable *linetable = LINETABLE (prologue_sal.symtab);
-	  int idx = 0;
-
-	  /* Skip any earlier lines, and any end-of-sequence marker
-	     from a previous function.  */
-	  while (linetable->item[idx].pc != prologue_sal.pc
-		 || linetable->item[idx].line == 0)
-	    idx++;
-
-	  if (idx+1 < linetable->nitems
-	      && linetable->item[idx+1].line != 0
-	      && linetable->item[idx+1].pc == start_pc)
-	    return start_pc;
-	}
+
+      /* Skip any earlier lines, and any end-of-sequence marker
+	 from a previous function.  */
+      while (linetable->item[idx].pc != prologue_sal.pc
+	     || linetable->item[idx].line == 0)
+	idx++;
+
+      if (idx+1 < linetable->nitems
+	  && linetable->item[idx+1].line != 0
+	  && linetable->item[idx+1].pc == start_pc)
+	return start_pc;
 
       /* If there is only one sal that covers the entire function,
 	 then it is probably a single line function, like