[RFA] When getting the locno of a bpstat, handle the case of bp with null locations.
Message ID | 20221120173024.3647464-1-philippe.waroquiers@skynet.be |
---|---|
State | Committed |
Commit | 28a072f4af84ad295d37f8aa70c5fec9d36a274c |
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 653EE3858409 for <patchwork@sourceware.org>; Sun, 20 Nov 2022 17:31:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 653EE3858409 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1668965461; bh=IUC+ZEB7LoemUTK8Hp20msAbZqkIlF/prFuojdfLXGg=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=y3bdY0JP2eo6ciDm88sNMgg0Z6GApcp2HU6pccsloZyfyYFKqIsVI72CVN9xw8D69 j4CQVOOXLxrApN7ksebSgDz1iJ2SDK1woJ8Gbq+BkdsYmZnSXBfk/610Vo3dkAyges N6XtmKf6ORwt/jfSutJAuJAjNNDixvl0HHO2M1is= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mailsec113.isp.belgacom.be (mailsec113.isp.belgacom.be [195.238.20.109]) by sourceware.org (Postfix) with ESMTPS id 9E6C33858D20 for <gdb-patches@sourceware.org>; Sun, 20 Nov 2022 17:30:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9E6C33858D20 X-ExtLoop: 1 X-IPAS-Result: A2DWBAC6Ynpj/1uGgG1agRKcN58yDwEBAQEBAQEBAQlEBAEBhQWFBCY4EwECBAEBAQEDAgMBAQEBAQEDAQEGAQEBAQEBBgQBgRuFL0aCNSKDfysLAUaEToMjsz4zgQGEcJpmgWeBQItOhXmBVU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V6RCXoFNp3VnVI1THYCfc+WZ2FXKzQ4sZF3ToqnehVHufYa tZfYzcHgBHoOkcWagZLVcJi9AuurkDUVXpKqnbJn7MMyXT4xxMywpHuFvOAL7RmQu0QxC50v Fnu8GjzRwkTKNefxCGt6XWxnOTCgirhVcQVDrLQ3uZqgVmS3nQeTgIfT1yivPi0kFWWQNFOL UEIvCAjxZXe72T6F5+kBEH9+STU+0dECpxZH/Y+rQ2czOzV+B7fDGUAQTdKb9lgvsJeqSEW6 2JlVujBXVRH2IB5g1rEnltIhVte8hT54YPPieHogOfFDxTeTFkPsy/y IronPort-HdrOrdr: A9a23:Vupy3Khl2Ug3+omb2GbXcCEqlHBQXi0ji2hC6mlwRA09TyX4rb HMoB1/73TJYVkqN03I9ergBED4ewK7yXct2/h3AV7AZmnbUQmTQL2KhLGKq1eMJ8SUzIBgPM lbAtNDIey1IV9mjdvrpCmUeuxQuuWvweSNrcf65VFEZyACUdAE0y5JTj++Vml7WQFKDYcwUI CR4ccCuyahdB0sH6aG76A+LpH+Tgvw5erbSBoPBxss7gGFjHez5Ln2VwSF3hp2aUIq/Ysf X-IronPort-Anti-Spam-Filtered: true X-ProximusIPWarmup: true Received: from 91.134-128-109.adsl-dyn.isp.belgacom.be (HELO md.home) ([109.128.134.91]) by relay.proximus.be with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2022 18:30:34 +0100 To: gdb-patches@sourceware.org Cc: Philippe Waroquiers <philippe.waroquiers@skynet.be> Subject: [RFA] When getting the locno of a bpstat, handle the case of bp with null locations. Date: Sun, 20 Nov 2022 18:30:24 +0100 Message-Id: <20221120173024.3647464-1-philippe.waroquiers@skynet.be> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP 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> From: Philippe Waroquiers via Gdb-patches <gdb-patches@sourceware.org> Reply-To: Philippe Waroquiers <philippe.waroquiers@skynet.be> Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" <gdb-patches-bounces+patchwork=sourceware.org@sourceware.org> |
Series |
[RFA] When getting the locno of a bpstat, handle the case of bp with null locations.
|
|
Commit Message
Philippe Waroquiers
Nov. 20, 2022, 5:30 p.m. UTC
The test py-objfile.exp unloads the current file while debugging the process. This results in bpstat bs->b->loc to become nullptr. Handle this case in breakpoint.c:bpstat_locno. Note: GDB crashes on this problem with an internal error, but the end of gdb summary shows: ... === gdb Summary === # of expected passes 36 The output also does not contain a 'FAIL:'. After the dix, the nr of expeted passes increased. In the gdb.log output, one can see: ... Fatal signal: Segmentation fault ----- Backtrace ----- 0x55698905c5b9 gdb_internal_backtrace_1 ../../binutils-gdb/gdb/bt-utils.c:122 0x55698905c5b9 _Z22gdb_internal_backtracev ... ERROR: Couldn't send python print(objfile.filename) to GDB. ERROR: : spawn id exp9 not open while executing "expect { -i exp9 -timeout 10 -re ".*A problem internal to GDB has been detected" { fail "$message (GDB internal error)" gdb_internal_error..." ("uplevel" body line 1) invoked from within .... Wondering if it might be possible to improve gdb_test to have gdb_test "python print(objfile.filename)" "None" \ "objfile.filename after objfile is unloaded" reporting a failed result instead of just producing the internal error. --- gdb/breakpoint.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On 11/20/22 12:30, Philippe Waroquiers via Gdb-patches wrote: > The test py-objfile.exp unloads the current file while debugging the process. > This results in bpstat bs->b->loc to become nullptr. > Handle this case in breakpoint.c:bpstat_locno. > > Note: GDB crashes on this problem with an internal error, > but the end of gdb summary shows: > ... > === gdb Summary === > > # of expected passes 36 > > The output also does not contain a 'FAIL:'. > After the dix, the nr of expeted passes increased. > > In the gdb.log output, one can see: > ... > Fatal signal: Segmentation fault > ----- Backtrace ----- > 0x55698905c5b9 gdb_internal_backtrace_1 > ../../binutils-gdb/gdb/bt-utils.c:122 > 0x55698905c5b9 _Z22gdb_internal_backtracev > ... > > ERROR: Couldn't send python print(objfile.filename) to GDB. > ERROR: : spawn id exp9 not open > while executing > "expect { > -i exp9 -timeout 10 > -re ".*A problem internal to GDB has been detected" { > fail "$message (GDB internal error)" > gdb_internal_error..." > ("uplevel" body line 1) > invoked from within > .... > > Wondering if it might be possible to improve gdb_test to have > gdb_test "python print(objfile.filename)" "None" \ > "objfile.filename after objfile is unloaded" > reporting a failed result instead of just producing the internal error. I ran the testsuite with the patch applied, I saw these unexpected failures when running with native-gdbserver or native-extended-gdbserver: FAIL: gdb.base/step-over-syscall.exp: detach-on-fork=off: follow-fork=parent: break cond on target : fork: continue to marker FAIL: gdb.base/step-over-syscall.exp: detach-on-fork=off: follow-fork=child: break cond on target : fork: continue to marker I bisected, and it pointed to the locno patch again. Probably the expected patterns that need to be updated? continue^M Continuing.^M [New inferior 2 (process 1262224)]^M ^M Thread 1.1 "step-over-fork" hit Breakpoint 4.1, marker () at /home/simark/src/binutils-gdb/gdb/testsuite/gdb.base/step-over-fork.c:22^M 22 marker () {}^M (gdb) FAIL: gdb.base/step-over-syscall.exp: detach-on-fork=off: follow-fork=parent: break cond on target : fork: continue to marker However, I confirm it gets rid of the UNRESOLVEDs due to the ASan complaints. But I don't have time to look at the code right now, sorry. Simon
On Sun, 2022-11-20 at 14:34 -0500, Simon Marchi wrote: > I ran the testsuite with the patch applied, I saw these unexpected > failures when running with native-gdbserver or > native-extended-gdbserver: > > FAIL: gdb.base/step-over-syscall.exp: detach-on-fork=off: follow-fork=parent: break cond on target : fork: continue to marker > FAIL: gdb.base/step-over-syscall.exp: detach-on-fork=off: follow-fork=child: break cond on target : fork: continue to marker > > I bisected, and it pointed to the locno patch again. Probably the > expected patterns that need to be updated? Effectively, this test contains some parts running only with gdbserver, and I missed the needed update of the pattern. I have posted an RFA with a fix: [RFA] Fix step-over-syscall.exp matching regexp for $bpnum.$locno matching https://sourceware.org/pipermail/gdb-patches/2022-November/194020.html > > continue^M > Continuing.^M > [New inferior 2 (process 1262224)]^M > ^M > Thread 1.1 "step-over-fork" hit Breakpoint 4.1, marker () at /home/simark/src/binutils-gdb/gdb/testsuite/gdb.base/step-over-fork.c:22^M > 22 marker () {}^M > (gdb) FAIL: gdb.base/step-over-syscall.exp: detach-on-fork=off: follow-fork=parent: break cond on target : fork: continue to marker > > However, I confirm it gets rid of the UNRESOLVEDs due to the ASan > complaints. But I don't have time to look at the code right now, sorry. Thanks for testing and pointing at these regressions (and sorry about these). There are now 3 RFA fixing some regressions [RFA] Fix use after free introduced by $_hit_bpnum/$_hit_locno variables. [RFA] When getting the locno of a bpstat, handle the case of bp with null locations. [RFA] Fix step-over-syscall.exp matching regexp for $bpnum.$locno matching and a fix for an unrelated problem but discovered when validating the above: [RFA] Fix jump on uninit producer_is_clang of cu.h, rm declared/undefined find_partial_die The week-end was too busy with the above to search for the dwarf2 leaks also found while validating the fixes. I might have time next week-end. Thanks Philippe
On 11/20/22 12:30, Philippe Waroquiers via Gdb-patches wrote: > The test py-objfile.exp unloads the current file while debugging the process. > This results in bpstat bs->b->loc to become nullptr. > Handle this case in breakpoint.c:bpstat_locno. > > Note: GDB crashes on this problem with an internal error, > but the end of gdb summary shows: > ... > === gdb Summary === > > # of expected passes 36 > > The output also does not contain a 'FAIL:'. > After the dix, the nr of expeted passes increased. dix->fix expeted -> expected > > In the gdb.log output, one can see: > ... > Fatal signal: Segmentation fault > ----- Backtrace ----- > 0x55698905c5b9 gdb_internal_backtrace_1 > ../../binutils-gdb/gdb/bt-utils.c:122 > 0x55698905c5b9 _Z22gdb_internal_backtracev > ... > > ERROR: Couldn't send python print(objfile.filename) to GDB. > ERROR: : spawn id exp9 not open > while executing > "expect { > -i exp9 -timeout 10 > -re ".*A problem internal to GDB has been detected" { > fail "$message (GDB internal error)" > gdb_internal_error..." > ("uplevel" body line 1) > invoked from within > .... > > Wondering if it might be possible to improve gdb_test to have > gdb_test "python print(objfile.filename)" "None" \ > "objfile.filename after objfile is unloaded" > reporting a failed result instead of just producing the internal error. I think an UNRESOLVED would be appropriate here. Normally, it should do that automatically. The perror here: https://gitlab.com/gnutools/binutils-gdb/-/blob/84f9fbe90e5429adb9dee68f04f44c92fa9e2345/gdb/testsuite/lib/gdb.exp#L1183 ... should make it so the next pass/fail becomes an UNRESOLVED. However, we don't even reach a pass / fail, as the expect call throws the error you pasted above, about the spawn id not being open. This mechanism works if GDB hasn't crashed yet when entering gdb_test_multiple, and it's the command gdb_test_multiple sends that crashes GDB. But here, what crashed GDB is the previous gdb_unload call, which uses bare expect, leaving no trace of the crash (in terms of test result). I propose the following changes to handle this situation better: - make gdb_unload use gdb_test_multiple, to make it record a test result and handle the different failure modes - instead of calling perror, manually call unresolved as soone as send_gdb returns an error, and return -1 immediately, to handle more gracefully the case where GDB is already crashed on entry But this is orthogonal with your patch, I will send a separate series. Your patch LGTM: Approved-By: Simon Marchi <simon.marchi@efficios.com> Simon
On Mon, 2022-11-21 at 10:04 -0500, Simon Marchi wrote: > > On 11/20/22 12:30, Philippe Waroquiers via Gdb-patches wrote: > > The test py-objfile.exp unloads the current file while debugging the process. > > This results in bpstat bs->b->loc to become nullptr. > > Handle this case in breakpoint.c:bpstat_locno. > > > > Note: GDB crashes on this problem with an internal error, > > but the end of gdb summary shows: > > ... > > === gdb Summary === > > > > # of expected passes 36 > > > > The output also does not contain a 'FAIL:'. > > After the dix, the nr of expeted passes increased. > > dix->fix > expeted -> expected > > > > > In the gdb.log output, one can see: > > ... > > Fatal signal: Segmentation fault > > ----- Backtrace ----- > > 0x55698905c5b9 gdb_internal_backtrace_1 > > ../../binutils-gdb/gdb/bt-utils.c:122 > > 0x55698905c5b9 _Z22gdb_internal_backtracev > > ... > > > > ERROR: Couldn't send python print(objfile.filename) to GDB. > > ERROR: : spawn id exp9 not open > > while executing > > "expect { > > -i exp9 -timeout 10 > > -re ".*A problem internal to GDB has been detected" { > > fail "$message (GDB internal error)" > > gdb_internal_error..." > > ("uplevel" body line 1) > > invoked from within > > .... > > > > Wondering if it might be possible to improve gdb_test to have > > gdb_test "python print(objfile.filename)" "None" \ > > "objfile.filename after objfile is unloaded" > > reporting a failed result instead of just producing the internal error. > > I think an UNRESOLVED would be appropriate here. Normally, it should do > that automatically. The perror here: > > https://gitlab.com/gnutools/binutils-gdb/-/blob/84f9fbe90e5429adb9dee68f04f44c92fa9e2345/gdb/testsuite/lib/gdb.exp#L1183 > > ... should make it so the next pass/fail becomes an UNRESOLVED. > However, we don't even reach a pass / fail, as the expect call throws > the error you pasted above, about the spawn id not being open. This > mechanism works if GDB hasn't crashed yet when entering > gdb_test_multiple, and it's the command gdb_test_multiple sends that > crashes GDB. But here, what crashed GDB is the previous gdb_unload > call, which uses bare expect, leaving no trace of the crash (in terms of > test result). > > I propose the following changes to handle this situation better: > > - make gdb_unload use gdb_test_multiple, to make it record a test > result and handle the different failure modes > - instead of calling perror, manually call unresolved as soone as > send_gdb returns an error, and return -1 immediately, to handle > more gracefully the case where GDB is already crashed on entry Note that in the meantime, when comparing gdb.log results, I will now also look for the string ERROR: while up to now I was just searching for FAIL: assuming any new error due to a patch I am testing would be shown as a FAIL:. > > But this is orthogonal with your patch, I will send a separate series. > > Your patch LGTM: > > Approved-By: Simon Marchi <simon.marchi@efficios.com> > > Simon Thanks for the review, pushed. Philippe
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 5b691673a0e..a161b78a8aa 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -4486,7 +4486,7 @@ bpstat_locno (const bpstat *bs) int locno = 0; - if (b != nullptr && b->loc->next != nullptr) + if (b != nullptr && b->loc != nullptr && b->loc->next != nullptr) { const bp_location *bl_i;