This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [patch] Workaround gcc bug 49906
- From: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- To: Aleksandar Ristovski <aristovski at qnx dot com>
- Cc: gdb-patches at sources dot redhat dot com
- Date: Fri, 28 Oct 2011 22:51:58 +0200
- Subject: Re: [patch] Workaround gcc bug 49906
- References: <j86sfj$j96$1@dough.gmane.org>
Hello Aleksandar,
the problem is that for this testcase:
/*1*/ static int i;
/*2*/ static void
/*3*/ f (int q)
/*4*/ {
/*5*/ for (;; i--)
/*6*/ if (i++)
/*7*/ break;
/*8*/ }
/*9*/ int main (void) { f (5); return 0; }
Built with:
gcc -o f2 f2.c -Wall -g -Werror
gcc (GCC) 4.6.3 20111028 (prerelease) -- the version should not matter
x86_64
it has a regression
gdb ./f2 -ex 'b f' -ex r
FSF GDB HEAD:
Breakpoint 1, f (q=5) at f2.c:6
^
6 if (i++)
with your patch:
Breakpoint 1, f (q=0) at f2.c:4
^
4 {
For reader's convenience attaching objdump at the bottom of this mail.
After GCC PR/49906 gets fixed the regression would stay there I think as this
testcase has already fully correct .debug_line now; unless this work around
gets protected by some DW_AT_producer based GCC version check.
I do not say how to fix it but I do not find the regression acceptable as is.
On Tue, 25 Oct 2011 19:43:14 +0200, Aleksandar Ristovski wrote:
> In addition to the patch, I'm attaching new test.
As discussed on IRC to make such testcase useful with future fixed GCCs (and
to make it meaningful for future GCC debug changes in general) it should be
placed into gdb.dwarf2/ and either prepared by gcc -S -dA (FSF GCC preferred)
while making it unfortunatelt arch-dependent or best (but not required and
very time consuming to prepare) building it by hand such as:
gdb.dwarf2/dw2-unresolved-main.c
gdb.dwarf2/dw2-unresolved.S
> 2011-10-25 Aleksandar Ristovski <aristovski@qnx.com>
>
> * symtab.c (skip_prologue_sal): Introduced start_sal_orig to keep
> entry value. Added check for line after the prologue. If line
> information for the next line exists but appears to be before in
> the code, discard skip over prologue work and revert original sal.
The modified skip_prologue_using_sal function should be in ChangeLog.
> gdb/testsuite/ChangeLog:
>
> 2011-10-25 Aleksandar Ristovski <aristovski@qnx.com>
>
> * prologue-gccbug49906.exp: New test.
> * prologue.c (f_gccbuf49906): New function, call new function.
Here should be gdb.base/ prefix. Please give the testfile any name you find
but not just the 49906 number.
> --- gdb/symtab.c 21 Jul 2011 15:13:29 -0000 1.283
> +++ gdb/symtab.c 25 Oct 2011 17:28:46 -0000
> @@ -2474,6 +2474,7 @@ skip_prologue_sal (struct symtab_and_lin
> struct gdbarch *gdbarch;
> struct block *b, *function_block;
> int force_skip, skip;
> + const struct symtab_and_line start_sal_orig = *sal;
>
> /* Do not change the SAL is PC was specified explicitly. */
> if (sal->explicit_pc)
> @@ -2627,6 +2628,29 @@ skip_prologue_sal (struct symtab_and_lin
> sal->line = SYMBOL_LINE (BLOCK_FUNCTION (function_block));
> sal->symtab = SYMBOL_SYMTAB (BLOCK_FUNCTION (function_block));
> }
> + else
> + {
> + /* Check if line number of apparent prologue end comes after
> + the next line information. If so, do not skip prologue
> + as something odd has happened. Probably gcc bug 49906.
> + Instead of giving awkward location for the function start,
> + give the previous good line (fuction start). */
> + const struct symtab_and_line prologue_sal_next
> + = find_pc_line (sal->end, 0);
> +
> + if ((sym? (BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) <= prologue_sal_next.end
Code formatting: sym ? (...
(I understand it is copy paste.)
> + && prologue_sal_next.end < BLOCK_END (SYMBOL_BLOCK_VALUE (sym)))
here was incorrect indentation.
> + : (lookup_minimal_symbol_by_pc_section (prologue_sal_next.end,
> + section)
> + == lookup_minimal_symbol_by_pc_section (sal->pc, section)))
> + && prologue_sal_next.line != 0
> + && prologue_sal_next.symtab == sal->symtab
> + && prologue_sal_next.line >= start_sal_orig.line
> + && prologue_sal_next.line < sal->line)
Thanks,
Jan
0000000000400474 <f>:
f():
f2.c:4
400474: 55 push %rbp
400475: 48 89 e5 mov %rsp,%rbp
400478: 89 7d fc mov %edi,-0x4(%rbp)
f2.c:6
40047b: 8b 05 2f 04 20 00 mov 0x20042f(%rip),%eax # 6008b0 <i>
400481: 85 c0 test %eax,%eax
400483: 0f 95 c2 setne %dl
400486: 83 c0 01 add $0x1,%eax
400489: 89 05 21 04 20 00 mov %eax,0x200421(%rip) # 6008b0 <i>
40048f: 84 d2 test %dl,%dl
400491: 75 11 jne 4004a4 <f+0x30>
f2.c:5
400493: 8b 05 17 04 20 00 mov 0x200417(%rip),%eax # 6008b0 <i>
400499: 83 e8 01 sub $0x1,%eax
40049c: 89 05 0e 04 20 00 mov %eax,0x20040e(%rip) # 6008b0 <i>
f2.c:8
4004a2: eb d7 jmp 40047b <f+0x7>
f2.c:7
4004a4: 90 nop
f2.c:8
4004a5: 5d pop %rbp
4004a6: c3 retq