From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20466 invoked by alias); 17 Oct 2014 09:56:29 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 20395 invoked by uid 48); 17 Oct 2014 09:56:25 -0000 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug debug/63572] [5 Regression] ICF breaks user debugging experience Date: Fri, 17 Oct 2014 09:56:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: debug X-Bugzilla-Version: 5.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 5.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-10/txt/msg01352.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63572 --- Comment #4 from Jakub Jelinek --- Better testcase, where ICF actually happens. struct S { int a; int b; int c; }; __attribute__((noinline)) static int f1 (struct S *x) { static int u = 1; int g = x->a * 7; { static int v = 2; int h = x->b * 11; int i = x->c; return g + h + i; } } __attribute__((noinline)) static int f2 (struct S *x) { static int w = 3; int j = x->a * 7; int k = x->b * 11; { static int y = 4; int l = x->c; return j + k + l; } } __attribute__((noinline)) int f3 (struct S *x) { return f1 (x); } __attribute__((noinline)) int f4 (struct S *x) { return f2 (x) + 1; } __attribute__((noinline)) int f5 (struct S *x) { return f1 (x) + 2; } __attribute__((noinline)) int f6 (struct S *x) { return f2 (x) + 3; } int main () { struct S s = { 1, 2, 3 }; asm volatile ("" : : "r" (&s) : "memory"); int a[4]; a[0] = f3 (&s); a[1] = f4 (&s); a[2] = f5 (&s); a[3] = f6 (&s); asm volatile ("" : : "r" (a) : "memory"); return 0; } As for .debug_line, the only solution which doesn't require any extensions would be IMHO to put the icf_merged clone's DW_TAG_subprogram into its own DW_TAG_partial_unit, import it into the DW_TAG_compile_unit where it is needed, and use a different DW_AT_stmt_list offset in there, and emit part of .debug_line (the one for the icf_merged aliases) manually into .debug_line by the compiler and see whether the assembler will deal with it properly. Anyway, the ideal user debugging experience IMHO with the above testcase is: b f1 - debugger finds out that f1 and f2 subprograms have overlapping ranges, puts a breakpoint into f1==f2 prologue, and when the breakpoint is hit, unwinds, checks if from the backtrace it is possible using DW_TAG_GNU_call_site figure out which of the functions has been called; if it is, depending on if it is f1 or f2 either honors or ignores the breakpoint; if it isn't possible to uniquely identify what the caller meant to call, honor the breakpoint. To map instructions back to line info, blocks etc., again, check unwind info/backtrace which function it is, if it is known which one it is, go into .debug_line table corresponding to the CU/PU of the subprogram, otherwise pick one. Ditto for the DW_TAG_subprogram/DW_TAG_lexical_block/DW_TAG_inlined_subroutine trees. Does that sound like a plan?