From patchwork Thu Mar 19 17:13:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 46053 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 498D721515 for ; Thu, 19 Mar 2015 17:14:12 +0000 (UTC) Received: by wghb13 with SMTP id b13sf4962914wgh.3 for ; Thu, 19 Mar 2015 10:14:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:mailing-list :precedence:list-id:list-unsubscribe:list-subscribe:list-archive :list-post:list-help:sender:delivered-to:from:to:subject:date :message-id:in-reply-to:references:x-original-sender :x-original-authentication-results; bh=ChAWx9uCfiuaK0lJkr4oXXFvmfN/DmjH4C83V7o0VfY=; b=FtXrMD5yC1ffqNzzpSUnrms9dPXxaPOeCmfqcrkv52jP0Li6HTwoNTgY9rQ2HtdQVy 9UjF7BTCXjjfeG2R5PLW7D23Ty3zrwK+4ifwqR0hrM8/3OyKGpIp2SLsl5mEWYQqMbfN 6PkeHHjq+dTraH1QXpWGD/ct8h8+fItlyhqA6VJ0XkHCFzth/SKw2b6G2WKEYVKcTbyY 7vhtylsqdv+qcNw2580t7Fz+SvD6otdb9NTBtzPw3dzqsRoA4+wtsioDrXyZigHCh6Bh ujdtSdr1V3nLa3fC1M60zhbY3HUARe/2pYj2syBlVJ/1n5TQqSB2arDHwA0FPRncILHe qUfA== X-Gm-Message-State: ALoCoQmTDzJDg5DDiwxxWvf0WMP6IEKglGdUg+6LovSnIRrMExwDgWI/IZSvnfzbBfOlBG49SbNQ X-Received: by 10.112.98.38 with SMTP id ef6mr11387540lbb.3.1426785251412; Thu, 19 Mar 2015 10:14:11 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.45.6 with SMTP id i6ls331610lam.10.gmail; Thu, 19 Mar 2015 10:14:10 -0700 (PDT) X-Received: by 10.152.5.170 with SMTP id t10mr69309495lat.43.1426785250536; Thu, 19 Mar 2015 10:14:10 -0700 (PDT) Received: from mail-la0-x22f.google.com (mail-la0-x22f.google.com. [2a00:1450:4010:c03::22f]) by mx.google.com with ESMTPS id qg6si1421045lbb.79.2015.03.19.10.14.10 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Mar 2015 10:14:10 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::22f as permitted sender) client-ip=2a00:1450:4010:c03::22f; Received: by lagg8 with SMTP id g8so67687585lag.1 for ; Thu, 19 Mar 2015 10:14:10 -0700 (PDT) X-Received: by 10.112.212.106 with SMTP id nj10mr50777680lbc.36.1426785250310; Thu, 19 Mar 2015 10:14:10 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp526557lbj; Thu, 19 Mar 2015 10:14:09 -0700 (PDT) X-Received: by 10.107.7.18 with SMTP id 18mr116635056ioh.69.1426785248840; Thu, 19 Mar 2015 10:14:08 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id ny12si3897726pab.202.2015.03.19.10.14.07 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Mar 2015 10:14:08 -0700 (PDT) Received-SPF: pass (google.com: domain of gdb-patches-return-120932-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 91544 invoked by alias); 19 Mar 2015 17:13:45 -0000 Mailing-List: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org Precedence: list List-Id: List-Unsubscribe: , List-Subscribe: List-Archive: List-Post: , List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 91497 invoked by uid 89); 19 Mar 2015 17:13:44 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=2.3 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, KAM_FROM_URIBL_PCCC, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-pa0-f51.google.com Received: from mail-pa0-f51.google.com (HELO mail-pa0-f51.google.com) (209.85.220.51) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 19 Mar 2015 17:13:39 +0000 Received: by padcy3 with SMTP id cy3so81156715pad.3 for ; Thu, 19 Mar 2015 10:13:37 -0700 (PDT) X-Received: by 10.70.124.138 with SMTP id mi10mr118358426pdb.39.1426785217170; Thu, 19 Mar 2015 10:13:37 -0700 (PDT) Received: from E107787-LIN.cambridge.arm.com (gcc1-power7.osuosl.org. [140.211.15.137]) by mx.google.com with ESMTPSA id ey10sm3943535pab.47.2015.03.19.10.13.35 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Mar 2015 10:13:36 -0700 (PDT) From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH 3/3] Handle the effect of skipping prologue Date: Thu, 19 Mar 2015 17:13:28 +0000 Message-Id: <1426785208-18301-4-git-send-email-qiyaoltc@gmail.com> In-Reply-To: <1426785208-18301-1-git-send-email-qiyaoltc@gmail.com> References: <1426785208-18301-1-git-send-email-qiyaoltc@gmail.com> X-IsSubscribed: yes X-Original-Sender: qiyaoltc@gmail.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::22f as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@sourceware.org; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com X-Google-Group-Id: 836684582541 From: Yao Qi break-asm-file.exp has some manually written dwarf to create some line number entries like this, [0x0000013d] Extended opcode 2: set Address to 0x40053f [0x00000144] Advance Line by 4 to 7 [0x00000146] Copy [0x00000147] Extended opcode 2: set Address to 0x400541 [0x0000014e] Advance Line by 1 to 8 [0x00000150] Copy [0x00000151] Extended opcode 2: set Address to 0x400547 [0x00000158] Extended opcode 1: End of Sequence 0x40053f is the start address of function func, and is mapped to line 7. 0x400541 is within function func, and is mapped to line 8. (gdb) disassemble /r 0x40053f,+8 Dump of assembler code from 0x40053f to 0x400547: 0x000000000040053f : 00 00 add %al,(%rax) 0x0000000000400541 : 00 00 add %al,(%rax) 0x0000000000400543 : 00 00 add %al,(%rax) 0x0000000000400545 : 00 00 add %al,(%rax) in the following test, (gdb) break a/break-asm-file0.s:func Breakpoint 1 at 0x40053f: file a/break-asm-file0.s, line 7. As we can see, breakpoint is set at the start address of function func on x86, which means no prologue is skipped. On other targets, such as arm and aarch64, breakpoint is set at the address *after* the start address, which is mapped to line 8. Then test fails. In fact, it is lucky this test doesn't fail on x86 and x86_64, whose gdbarch method skip_prologue doesn't reply on skip_prologue_using_sal if producer isn't clang. if (find_pc_partial_function (start_pc, NULL, &func_addr, NULL)) { CORE_ADDR post_prologue_pc = skip_prologue_using_sal (gdbarch, func_addr); struct compunit_symtab *cust = find_pc_compunit_symtab (func_addr); /* Clang always emits a line note before the prologue and another one after. We trust clang to emit usable line notes. */ if (post_prologue_pc && (cust != NULL && COMPUNIT_PRODUCER (cust) != NULL && startswith (COMPUNIT_PRODUCER (cust), "clang "))) return max (start_pc, post_prologue_pc); } so it doesn't return and go further to prologue analyser. Since ".int 0" isn't an instruction of prologue, nothing is skipped, starting address is used, and test passes. however, on targets which don't have such producer checking, the first line number entry is skipped, and skip_prologue_using_sal returns sal represents the second line number entry. The idea of this patch is to force GDB stop at somewhere which is stilled mapped to line 7 after skipping prologue. I choose to add a new line number entry for the following instruction but mapped to the same line (7), because I see the comments in dwarf2read.c, ... fact that two consecutive line number entries for the same line is a heuristic used by gcc to denote the end of the prologue. then the line table becomes: [0x000000d4] Extended opcode 2: set Address to 0x400529 [0x000000db] Advance Line by 4 to 7 [0x000000dd] Copy [0x000000de] Extended opcode 2: set Address to 0x40052a [0x000000e5] Advance Line by 0 to 7 [0x000000e7] Copy [0x000000e8] Extended opcode 2: set Address to 0x40052b [0x000000ef] Advance Line by 1 to 8 [0x000000f1] Copy [0x000000f2] Extended opcode 2: set Address to 0x40052c [0x000000f9] Extended opcode 1: End of Sequence gdb/testsuite: 2015-03-19 Yao Qi PR testsuite/18139 * gdb.linespec/break-asm-file0.s (func): New label .Lfunc_2. Add a line number entry for the same line. * gdb.linespec/break-asm-file1.s (func): New label .Lfunc_2. Add a line number entry for the same line. --- gdb/testsuite/gdb.linespec/break-asm-file0.s | 14 ++++++++++++++ gdb/testsuite/gdb.linespec/break-asm-file1.s | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/gdb/testsuite/gdb.linespec/break-asm-file0.s b/gdb/testsuite/gdb.linespec/break-asm-file0.s index 42c4213..dbc4398 100644 --- a/gdb/testsuite/gdb.linespec/break-asm-file0.s +++ b/gdb/testsuite/gdb.linespec/break-asm-file0.s @@ -38,6 +38,8 @@ func: nop .Lfunc_1: nop +.Lfunc_2: + nop .Lend_func: .size func, .-func .Lend_text1: @@ -202,6 +204,18 @@ func: .byte 2 .4byte .Lfunc_1 + /* A line number entry for the same line (7) denotes the end */ + /* of prologue. */ + .byte 3 /* DW_LNS_advance_line */ + .sleb128 0 /* ... to 7 */ + + .byte 1 /* DW_LNS_copy */ + + .byte 0 /* DW_LNE_set_address */ + .uleb128 5 + .byte 2 + .4byte .Lfunc_2 + .byte 3 /* DW_LNS_advance_line */ .sleb128 1 /* ... to 8 */ diff --git a/gdb/testsuite/gdb.linespec/break-asm-file1.s b/gdb/testsuite/gdb.linespec/break-asm-file1.s index a1e7a42..4372626 100644 --- a/gdb/testsuite/gdb.linespec/break-asm-file1.s +++ b/gdb/testsuite/gdb.linespec/break-asm-file1.s @@ -34,6 +34,8 @@ func: nop .Lfunc_1: nop +.Lfunc_2: + nop .Lend_func: .size func, .-func .Lend_text1: @@ -228,6 +230,18 @@ func: .byte 2 .4byte .Lfunc_1 + /* A line number entry for the same line (7) denotes the end */ + /* of prologue. */ + .byte 3 /* DW_LNS_advance_line */ + .sleb128 0 /* ... to 7 */ + + .byte 1 /* DW_LNS_copy */ + + .byte 0 /* DW_LNE_set_address */ + .uleb128 5 + .byte 2 + .4byte .Lfunc_2 + .byte 3 /* DW_LNS_advance_line */ .sleb128 1 /* ... to 8 */