From patchwork Mon Jan 29 04:45:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Brobecker X-Patchwork-Id: 25657 Received: (qmail 116331 invoked by alias); 29 Jan 2018 04:45:27 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk 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 116097 invoked by uid 89); 29 Jan 2018 04:45:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=7.3.1, lands, 1604 X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 29 Jan 2018 04:45:11 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 45E58562E3; Sun, 28 Jan 2018 23:45:10 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 0SLs6ivtATgO; Sun, 28 Jan 2018 23:45:10 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id B7088562E0; Sun, 28 Jan 2018 23:45:09 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id 832DA83307; Mon, 29 Jan 2018 08:45:05 +0400 (+04) Date: Mon, 29 Jan 2018 08:45:05 +0400 From: Joel Brobecker To: Simon Marchi Cc: Simon Marchi , gdb-patches@sourceware.org, Keith Seitz , Xavier Roirand Subject: Re: [RFA/linespec] wrong line number in breakpoint location Message-ID: <20180129044505.mtvh2ps464imwp2t@adacore.com> References: <1513565091-118926-1-git-send-email-brobecker@adacore.com> <20171219092405.n2dql5ji52qhjilj@adacore.com> <206d75d6b1f14e55b6a0dff523d8c722@polymtl.ca> <20171221113127.ijqv6dnzjfifwfnb@adacore.com> <20171221113214.hezwvaatnbd4yzfq@adacore.com> <5bc2ff63-7341-4000-8ec4-d56c87779c3d@ericsson.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <5bc2ff63-7341-4000-8ec4-d56c87779c3d@ericsson.com> User-Agent: NeoMutt/20170113 (1.7.2) Hi Simon, > I started seeing a failure with this patch: > > FAIL: gdb.base/break.exp: verify that they were cleared > > Here is the test code: > > 40 int > 41 main (int argc, char **argv, char **envp) > 42 { > 43 if (argc == 12345) { /* an unlikely value < 2^16, in case uninited */ /* set breakpoint 6 here */ > 44 fprintf (stderr, "usage: factorial \n"); > 45 return 1; > 46 } > 47 printf ("%d\n", factorial (atoi ("6"))); /* set breakpoint 1 here */ > 48 /* set breakpoint 12 here */ > 49 marker1 (); /* set breakpoint 11 here */ > 50 marker2 (43); /* set breakpoint 20 here */ > > What happens is that we build a binary with optimization, set a > breakpoint on line 47, and expect "info break" to show it at line 47. > In reality, everything about line 47 has been inlined and there's no > address associated to line 47. The following location in that file > that has generated code associated to it is line 49, so that's where > the breakpoint is placed in reality. With this patch, "info break" > therefore now shows line 49. Looking at the assembly code between the two versions, the difference is that in the GCC 5.x case, the printf called gets inlined (!), whereas it does not when usin GCC 7.x, even on the same system. So, in the first case, the code generated for line 47 gets line numbers referencing either another file, or another function, which explains why we end up breaking on the next line of code, which is line 49. With the more recent version of GCC, the call to printf is no longer inlined, and so we have some instructions "attached" to line 47, thanks to the call to "printf". > This particular test isn't really about testing with optimized code, > it's about checking if we can clear breakpoint commands. So we should > probably test that against a non-optimized binary. That's true that it doesn't seem necessary to perform that check against the optimized version. On the other hand, we could keep the testcase as is, by simply extracting from the output of the "break" command which line we actually broke on, and then use that in the expected output. WDYT? gdb/testsuite/ChangeLog: * gdb.base/break.exp: Save the location where the breakpoint on break.c:47 was actually inserted when debugging the version compiled at -O2 and use it in the expected output of the "info break" test performed soon after. tested on x86_64-linux, with two configurations: - Ubuntu 16.04 with the system compiler (breakpoint lands on line 49) - Ubuntu 16.04 with GCC 7.3.1 (breakpoint lands on line 47) From d9207d517fc2e9b6460ac769553f7c0841ac9d91 Mon Sep 17 00:00:00 2001 From: Joel Brobecker Date: Sun, 28 Jan 2018 23:20:42 -0500 Subject: [PATCH] gdb.base/break.exp: fix last "info break" test failure on Ubuntu 16.04 The last test of this testcase fails when run on Ubuntu 16.04 using the system compiler (16.04): FAIL: gdb.base/break.exp: verify that they were cleared This is because the testcase expected that a breakpoint on line 47 of break.c... printf ("%d\n", factorial (atoi ("6"))); /* set breakpoint 1 here */ ... would actually be inserted on an instruction belonging to that line. However, what actually happens is that system GCC on that version of Ubuntu ends up inlining everything, including the call to printf, thus reporting every instruction of generated for this line of code as belonging to a different function. As a result, GDB ends up insering the breakpoint on the next line of code, which is line 49: (gdb) break break.c:$l Breakpoint 3 at 0x4005c1: file /[...]/gdb.base/break.c, line 49. This causes a spurious failure in the "info break" test later on, as it assumed that the breakpoint above is inserted on line 47: gdb_test "info break" "$srcfile:$line" "verify that they were cleared" This patch fixes the issue by saving the actual source location where the breakpoint was inserted. gdb/testsuite/ChangeLog: * gdb.base/break.exp: Save the location where the breakpoint on break.c:47 was actually inserted when debugging the version compiled at -O2 and use it in the expected output of the "info break" test performed soon after. tested on x86_64-linux, with two configurations: - Ubuntu 16.04 with the system compiler (breakpoint lands on line 49) - Ubuntu 16.04 with GCC 7.3.1 (breakpoint lands on line 47) --- gdb/testsuite/gdb.base/break.exp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/gdb/testsuite/gdb.base/break.exp b/gdb/testsuite/gdb.base/break.exp index 8a21222..2bd0eb1 100644 --- a/gdb/testsuite/gdb.base/break.exp +++ b/gdb/testsuite/gdb.base/break.exp @@ -847,7 +847,18 @@ gdb_test_multiple "" $test { # set line [gdb_get_line_number "set breakpoint 1 here"] gdb_test_no_output "set \$l = $line" -gdb_breakpoint ${srcfile}:\$l +set test "break ${srcfile}:\$l" +gdb_test_multiple "$test" $test { + -re "Breakpoint $decimal at $hex: file .*break\\.c, line ($decimal)\\.\r\n$gdb_prompt $" { + # Save the actual line number on which the breakpoint was + # actually set. On some systems (Eg: Ubuntu 16.04 with GCC + # version 5.4.0), that line gets completely inlined, including + # the call to printf, and so we end up inserting the breakpoint + # on one of the following lines instead. + set line_actual $expect_out(1,string) + pass $test + } +} gdb_test_no_output "set \$foo=81.5" \ "set convenience variable \$foo to 81.5" @@ -865,4 +876,4 @@ gdb_test "commands\nend" ">end" "clear breakpoint commands" # We verify that the commands were cleared by ensuring that the last # breakpoint's location ends the output -- if there were commands, # they would have been printed after the location. -gdb_test "info break" "$srcfile:$line" "verify that they were cleared" +gdb_test "info break" "$srcfile:$line_actual" "verify that they were cleared" -- 2.1.4