Message ID | 20230417162428.48426-1-r@hev.cc |
---|---|
State | New |
Headers |
Return-Path: <gdb-patches-bounces+patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7F3913857BB2 for <patchwork@sourceware.org>; Mon, 17 Apr 2023 16:25:05 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by sourceware.org (Postfix) with ESMTPS id 2E6F83858C53 for <gdb-patches@sourceware.org>; Mon, 17 Apr 2023 16:24:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2E6F83858C53 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=hev.cc Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=hev.cc Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1a66e7a52d3so6364055ad.0 for <gdb-patches@sourceware.org>; Mon, 17 Apr 2023 09:24:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hev-cc.20221208.gappssmtp.com; s=20221208; t=1681748681; x=1684340681; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=2NNPIXokggz/odhUmwbZG4n1vvgVJEh27Qxp9aruszU=; b=iggadqRKb2v3TtAFhNRME+t1s+mEIlR+0RLuEev75BxQpY2gbqid+U/pdKbRnRP2fk KBrYSlXkIRkG7dsFPRW0EEMTBxIo1LNnWSc9dwrMWfsHsAQqpGZgkxzO9R+9O38rrCzB Hl+zVLAfhxM9EQ7vJlt2kAGYjF1aqGC3nyk3UFKjrDMLScuIF4p/wTsQ0IX8LH1PKNQO dY804yJ8pQ4SSLd52auQYLXtByIh+205yTSJ9XUnAfDc2UTZrIBcdGBw8VS7RgELWY82 s/PbiukV9o3eWfLHsd21jEoA7euzezNoiGR60E93oz21sNyD3HkhuQb5qrf26I51uQUI zGww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681748681; x=1684340681; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=2NNPIXokggz/odhUmwbZG4n1vvgVJEh27Qxp9aruszU=; b=JveHnsCRoS8viU2hBjWDobHfFEidBkVkW5GHo6tzW3uKllII5ghtZc9trkCIvJk3K7 7ZM3fh5V/yW4bpsAhFDM1FF/lO/qtZG4+GVgk2ABR2EAx4fE0ckg0QOGJbBDhTX35nq7 2Kh047SmZp3sFLLgyVO11WvWILmR2j2PtBesvRQTUWRPg7YZYDz4Ik50mn5Z/h7y8dGj 4qrVBVvgq6o5IifgKCePH/En6U2TIDrcltt+bxXl4FGz8ZgawIbqrnK8DX58ygMfHvBu xDxuq55EP3JpVO+Rq4w+sjjomzJTAdAjbKe8yixWjrhNbtJngq/LQNLomKEtwOdMtW+2 7NCA== X-Gm-Message-State: AAQBX9dms4/YqdsRIyEG6qeTYNb71h29sWIJ3swKTs/LuU9alv5L5yPa T/mqpwrqTETcxU+bXUX95uTcbhKQ0ctVE48CmISkvdZZ2uo= X-Google-Smtp-Source: AKy350Z/5lILv0XQ/lJHBXeeNPienGApish3oxfE+bJnPB1IZrRfVgGr+pwN5N2xkfB9xQSWx49vXQ== X-Received: by 2002:a05:6a00:a8f:b0:62a:4503:53ba with SMTP id b15-20020a056a000a8f00b0062a450353bamr22360461pfl.26.1681748680724; Mon, 17 Apr 2023 09:24:40 -0700 (PDT) Received: from localhost.localdomain ([2400:8901:e002:5400::]) by smtp.gmail.com with ESMTPSA id i16-20020aa78d90000000b005ae02dc5b94sm7819622pfr.219.2023.04.17.09.24.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 09:24:40 -0700 (PDT) From: WANG Rui <r@hev.cc> To: gdb-patches@sourceware.org Cc: Lancelot SIX <lancelot.six@amd.com>, WANG Rui <r@hev.cc> Subject: [PATCH] gdb: Fix false match issue in skip_prologue_using_linetable Date: Tue, 18 Apr 2023 00:24:28 +0800 Message-Id: <20230417162428.48426-1-r@hev.cc> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list <gdb-patches.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=subscribe> Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" <gdb-patches-bounces+patchwork=sourceware.org@sourceware.org> |
Series |
gdb: Fix false match issue in skip_prologue_using_linetable
|
|
Commit Message
hev
April 17, 2023, 4:24 p.m. UTC
We should exclude matches to the ending PC to prevent false matches with the next function, as prologue_end is located at the end PC. <fun1>: 0x00: ... <-- start_pc 0x04: ... 0x08: ... <-- breakpoint 0x0c: ret <fun2>: 0x10: ret <-- end_pc | prologue_end of fun2 --- gdb/symtab.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On 4/17/23 09:24, WANG Rui wrote: > We should exclude matches to the ending PC to prevent false matches with the > next function, as prologue_end is located at the end PC. > > <fun1>: > 0x00: ... <-- start_pc > 0x04: ... > 0x08: ... <-- breakpoint > 0x0c: ret > <fun2>: > 0x10: ret <-- end_pc | prologue_end of fun2 Thank you for the patch. Indeed, my recollection is that we always record/search for pc's in [start, end). find_pc_partial_function seems to concur. > --- > gdb/symtab.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/gdb/symtab.c b/gdb/symtab.c > index f2b1a14e006..a662d7d1869 100644 > --- a/gdb/symtab.c > +++ b/gdb/symtab.c > @@ -3735,7 +3735,7 @@ skip_prologue_using_linetable (CORE_ADDR func_addr) > }); > > for (; > - it < linetable->item + linetable->nitems && it->pc <= end_pc; > + it < linetable->item + linetable->nitems && it->pc < end_pc; > it++) > if (it->prologue_end) > return {it->pc}; This appears to be against gdb 13 and will need to be rebased. I have regression tested this on x86_64 and found nothing of concern. [The patch which introduced this function contained a test case, gdb.dwarf2/dw2-prologue-end.exp, and that test also shows no regressions.] I have to ask, though, is there a way to write a test case for this? Maybe by using dw2-prologue-end.exp as an example? Keith
> > diff --git a/gdb/symtab.c b/gdb/symtab.c > index f2b1a14e006..a662d7d1869 100644 > --- a/gdb/symtab.c > +++ b/gdb/symtab.c > @@ -3735,7 +3735,7 @@ skip_prologue_using_linetable (CORE_ADDR func_addr) > }); > > for (; > - it < linetable->item + linetable->nitems && it->pc <= end_pc; > + it < linetable->item + linetable->nitems && it->pc < end_pc; > it++) > if (it->prologue_end) > return {it->pc}; Hi Rui, thanks for spotting this. I am not a maintainer, so I can only comment. I do not think this patch applies cleanly to the master branch, but the change should be trivial. That being said, it is true that find_pc_partial_function returns the first address past the end of the function, so the change looks good to me. Thanks for spotting this! Best, Lancelot.
Hello Keith, Thanks for your comments. On Tue, Apr 18, 2023 at 1:38 AM Keith Seitz <keiths@redhat.com> wrote: > > On 4/17/23 09:24, WANG Rui wrote: > > We should exclude matches to the ending PC to prevent false matches with the > > next function, as prologue_end is located at the end PC. > > > > <fun1>: > > 0x00: ... <-- start_pc > > 0x04: ... > > 0x08: ... <-- breakpoint > > 0x0c: ret > > <fun2>: > > 0x10: ret <-- end_pc | prologue_end of fun2 > > Thank you for the patch. Indeed, my recollection is that we always > record/search for pc's in [start, end). find_pc_partial_function seems to > concur. > > > --- > > gdb/symtab.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/gdb/symtab.c b/gdb/symtab.c > > index f2b1a14e006..a662d7d1869 100644 > > --- a/gdb/symtab.c > > +++ b/gdb/symtab.c > > @@ -3735,7 +3735,7 @@ skip_prologue_using_linetable (CORE_ADDR func_addr) > > }); > > > > for (; > > - it < linetable->item + linetable->nitems && it->pc <= end_pc; > > + it < linetable->item + linetable->nitems && it->pc < end_pc; > > it++) > > if (it->prologue_end) > > return {it->pc}; > > This appears to be against gdb 13 and will need to be rebased. > > I have regression tested this on x86_64 and found nothing of concern. > [The patch which introduced this function contained a test case, > gdb.dwarf2/dw2-prologue-end.exp, and that test also shows no regressions.] > > I have to ask, though, is there a way to write a test case for this? Maybe > by using dw2-prologue-end.exp as an example? I attempted to write a test case, but it did not work. I discovered this issue while running the Rust debuginfo test[1] on LoongArch. As the function entry alignment is 4-byte, which is the size of an instruction, there is no padding between the two functions. This creates a possibility of matching the start address of the next function. This is unlike x86, which is why this problem does not occur on x86. I sincerely hope that this information proves to be beneficial to you. [1] https://github.com/rust-lang/rust/blob/7908a1d65496b88626e4b7c193c81d777005d6f3/tests/debuginfo/box.rs -- Rui
Hello Lancelot, Thanks for your comments. On Tue, Apr 18, 2023 at 5:13 AM Lancelot SIX <Lancelot.Six@amd.com> wrote: > > > > > diff --git a/gdb/symtab.c b/gdb/symtab.c > > index f2b1a14e006..a662d7d1869 100644 > > --- a/gdb/symtab.c > > +++ b/gdb/symtab.c > > @@ -3735,7 +3735,7 @@ skip_prologue_using_linetable (CORE_ADDR func_addr) > > }); > > > > for (; > > - it < linetable->item + linetable->nitems && it->pc <= end_pc; > > + it < linetable->item + linetable->nitems && it->pc < end_pc; > > it++) > > if (it->prologue_end) > > return {it->pc}; > > Hi Rui, thanks for spotting this. > > I am not a maintainer, so I can only comment. > > I do not think this patch applies cleanly to the master branch, but the > change should be trivial. That being said, it is true that > find_pc_partial_function returns the first address past the end of the > function, so the change looks good to me. Thanks for spotting this! I realized that I made a mistake. I have been focusing so much on debugging Rust issues that I forgot to work on the 13 branch. I will work on the v2 patch. Thank you! -- Rui
On 4/18/23 04:26, hev wrote: >> I have to ask, though, is there a way to write a test case for this? Maybe >> by using dw2-prologue-end.exp as an example? > I attempted to write a test case, but it did not work. I discovered this > issue while running the Rust debuginfo test[1] on LoongArch. As the > function entry alignment is 4-byte, which is the size of an instruction, > there is no padding between the two functions. This creates a possibility > of matching the start address of the next function. This is unlike x86, > which is why this problem does not occur on x86. I sincerely hope that this > information proves to be beneficial to you. Using this information I managed to write a regression test for this, I've attached it to a PR I opened for this issue ( https://sourceware.org/bugzilla/show_bug.cgi?id=30369 ). Thanks, - Tom
On Tue, Apr 18, 2023 at 4:43 PM Tom de Vries <tdevries@suse.de> wrote: > > On 4/18/23 04:26, hev wrote: > >> I have to ask, though, is there a way to write a test case for this? Maybe > >> by using dw2-prologue-end.exp as an example? > > > I attempted to write a test case, but it did not work. I discovered this > > issue while running the Rust debuginfo test[1] on LoongArch. As the > > function entry alignment is 4-byte, which is the size of an instruction, > > there is no padding between the two functions. This creates a possibility > > of matching the start address of the next function. This is unlike x86, > > which is why this problem does not occur on x86. I sincerely hope that this > > information proves to be beneficial to you. > > Using this information I managed to write a regression test for this, > I've attached it to a PR I opened for this issue ( > https://sourceware.org/bugzilla/show_bug.cgi?id=30369 ). Awesome! Thank you. -- Rui
On 4/17/23 18:24, WANG Rui wrote: > We should exclude matches to the ending PC to prevent false matches with the > next function, as prologue_end is located at the end PC. Hi Rui, thanks for the bug-report-and-fix, much appreciated. If you might make more or larger contributions in the future, please consider filing a copyright assignment ( https://sourceware.org/gdb/wiki/ContributionChecklist#FSF_copyright_Assignment ). Thanks, - Tom
Hi Tom, On Sat, Apr 22, 2023 at 4:36 PM Tom de Vries <tdevries@suse.de> wrote: > > On 4/17/23 18:24, WANG Rui wrote: > > We should exclude matches to the ending PC to prevent false matches with the > > next function, as prologue_end is located at the end PC. > > Hi Rui, > > thanks for the bug-report-and-fix, much appreciated. > > If you might make more or larger contributions in the future, please > consider filing a copyright assignment ( > https://sourceware.org/gdb/wiki/ContributionChecklist#FSF_copyright_Assignment > ). Thank you for suggesting that I consider filing a copyright assignment with the FSF if I plan on making more contributions in the future. I appreciate your guidance and will definitely keep it in mind. :) Thanks Rui
diff --git a/gdb/symtab.c b/gdb/symtab.c index f2b1a14e006..a662d7d1869 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -3735,7 +3735,7 @@ skip_prologue_using_linetable (CORE_ADDR func_addr) }); for (; - it < linetable->item + linetable->nitems && it->pc <= end_pc; + it < linetable->item + linetable->nitems && it->pc < end_pc; it++) if (it->prologue_end) return {it->pc};