Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Joel Brobecker <brobecker@adacore.com>
Cc: Simon Marchi <simon.marchi@ericsson.com>,
	gdb-patches@sourceware.org,
	       Keith Seitz <keiths@redhat.com>,
	Xavier Roirand <roirand@adacore.com>
Subject: Re: [RFA/linespec] wrong line number in breakpoint location
Date: Mon, 29 Jan 2018 17:01:00 -0000	[thread overview]
Message-ID: <ee45bc1fd2a4f82cbd517994e16a95a7@polymtl.ca> (raw)
In-Reply-To: <20180129044505.mtvh2ps464imwp2t@adacore.com>

On 2018-01-28 23:45, Joel Brobecker wrote:
> 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 <number>\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)

Hi Joel,

Thanks, this is fine with me.  Just a really small nit, I would suggest 
initializing the line_actual variable to 0 or -1 (an invalid line 
number) prior to calling gdb_test_multiple.  This way, if that test 
fails, line_actual will still be defined, and the expression that refers 
to it will generate a FAIL instead of an unreadable tcl backtrace.

Simon


  reply	other threads:[~2018-01-29 17:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-18  2:44 Joel Brobecker
2017-12-18  4:09 ` Simon Marchi
2017-12-19  9:24   ` Joel Brobecker
2017-12-21  1:31     ` Simon Marchi
2017-12-21 11:31       ` Joel Brobecker
2017-12-21 11:32         ` Joel Brobecker
2018-01-22  4:17           ` pushed: " Joel Brobecker
     [not found]           ` <5bc2ff63-7341-4000-8ec4-d56c87779c3d@ericsson.com>
2018-01-29  4:45             ` Joel Brobecker
2018-01-29 17:01               ` Simon Marchi [this message]
2018-01-30  4:09                 ` Joel Brobecker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ee45bc1fd2a4f82cbd517994e16a95a7@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=keiths@redhat.com \
    --cc=roirand@adacore.com \
    --cc=simon.marchi@ericsson.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox