Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Bernd Edlinger <bernd.edlinger@hotmail.de>
To: Andrew Burgess <andrew.burgess@embecosm.com>
Cc: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: Re: [PATCH 2/2] gdb: Add support for tracking the DWARF line table is-stmt field
Date: Fri, 14 Feb 2020 20:05:00 -0000	[thread overview]
Message-ID: <AM6PR03MB51704A9FE4E02CA11EF2F8E7E4150@AM6PR03MB5170.eurprd03.prod.outlook.com> (raw)
In-Reply-To: <20200211135710.GR4020@embecosm.com>

On 2/11/20 2:57 PM, Andrew Burgess wrote:
> * Bernd Edlinger <bernd.edlinger@hotmail.de> [2020-02-05 17:55:37 +0000]:
> 
>> On 2/5/20 12:37 PM, Andrew Burgess wrote:
>>
>> did you mean, when we don't land in the middle of a line ?
> 
> No, in this case I did write the correct thing.
> 
> So GDB had/has some code designed to "improve" the handling of looping
> constructs.  I think the idea is to handle cases like this:
> 
>   0x100      LN=5
>   0x104 <-\
>   0x108   |
>   0x10c   |  LN=6
>   0x110   |
>   0x114 --/
> 
> So when line 6 branches back to the middle of line 5, we don't stop
> (because we are in the middle of line 5), but we do want to stop at
> the start of line 6, so we "reset" the starting point back to line 5.
> 
> This is done by calling set_step_info in process_event_stop_test, in
> infrun.c.
> 
> What we actually did though was whenever we were at an address that
> didn't exactly match a SAL (in the example above, marked LN=5, LN=6)
> we called set_step_info.  This worked fine, at address 0x104 we reset
> back to LN=5, same at address 0x108.
> 
> However, in the new world things can look different, for example, like
> this:
> 
>   0x100      LN=5,STMT=1
>   0x104
>   0x108      LN=6,STMT=0
>   0x10c      LN=6,STMT=1
>   0x110
>   0x114
> 
> In this world, when we move forward to 0x100 we don't have a matching
> SAL, so we get the SAL for address 0x100.  We can then safely call
> set_step_info like we did before, that's fine.  But when we step to
> 0x108 we do now have a matching SAL, but we don't want to stop yet as
> this address is 'STMT=0'.  However, if we call set_step_info then GDB
> is going to think we are stepping away from LN=6, and so will refuse
> to stop at address 0x10c.
> 
> The proposal in this commit is that if we land at an address which
> doesn't specifically match a SAL, 0x104, 0x110, 0x114 in the above
> example, then we do call set_step_info, but otherwise we don't.
> 
> There are going to be situations where the behaviour of GDB changes
> after this patch, but I don't think we can avoid that.  What we had
> previously was just a heuristic.  I think enabling this new
> information in GDB will allow us to do better overall, so I think we
> should make this change and fix any issues as they show up.
> 

I agree with that, thanks for this explanation.

However, I think I found a small problem in this patch.
You can see it with the next-inline test case.
When you use just step the execution does not stop
between the inline functions, because not calling 

current behaviour is this:

Breakpoint 1, main () at next-inline.cc:63
63	  get_alias_set (&xx);
(gdb) s
get_alias_set (t=0x404040 <xx>) at next-inline.cc:50
50	  if (t != NULL
(gdb) s
51	      && TREE_TYPE (t).z != 1
(gdb) s
0x0000000000401169 in tree_check (i=0, t=0x404040 <xx>) at next-inline.h:34
34	  if (t->x != i)
(gdb) s
0x000000000040117d in tree_check (i=0, t=0x404040 <xx>) at next-inline.h:34
34	  if (t->x != i)
(gdb) s
0x000000000040118f in tree_check (i=0, t=0x404040 <xx>) at next-inline.h:34
34	  if (t->x != i)
(gdb) s
main () at next-inline.cc:64
64	  return 0;
(gdb) 

I debugged a bit because I was not sure why that happens, and it looks
like set_step_info does also set the current inline frame, but you
only want to suppress the line number not the currently executing
inline function.
With this small patch the step works as expected.

commit 193d81765d88b11e68111a8856a84cdf084d0b22
Author: Bernd Edlinger <bernd.edlinger@hotmail.de>
Date:   Fri Feb 14 20:41:51 2020 +0100

    Fix next-inline test case with step
    
    Should stop between inline function invocations.

diff --git a/gdb/infrun.c b/gdb/infrun.c
index 3919de8..89e6654 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -7190,6 +7190,8 @@ process_event_stop_test (struct execution_control_state *e
   ecs->event_thread->control.step_range_start = stop_pc_sal.pc;
   ecs->event_thread->control.step_range_end = stop_pc_sal.end;
   ecs->event_thread->control.may_range_step = 1;
+  ecs->event_thread->control.step_frame_id = get_frame_id (frame);
+  ecs->event_thread->control.step_stack_frame_id = get_stack_frame_id (frame);
   if (refresh_step_info)
     set_step_info (frame, stop_pc_sal);
 

I'm not sure if that is the cleanest solution, but it works.
With that adjustment, the stepping out of the inline and back into
makes the step call stop, which is the correct behavior:

Breakpoint 1, main () at next-inline.cc:63
63	  get_alias_set (&xx);
(gdb) s
get_alias_set (t=0x404040 <xx>) at next-inline.cc:50
50	  if (t != NULL
(gdb) s
51	      && TREE_TYPE (t).z != 1
(gdb) s
0x0000000000401169 in tree_check (i=0, t=0x404040 <xx>) at next-inline.h:34
34	  if (t->x != i)
(gdb) s
52	      && TREE_TYPE (t).z != 2
(gdb) s
tree_check (i=0, t=0x404040 <xx>) at next-inline.h:34
34	  if (t->x != i)
(gdb) s
53	      && TREE_TYPE (t).z != 3)
(gdb) s
tree_check (i=0, t=0x404040 <xx>) at next-inline.h:34
34	  if (t->x != i)
(gdb) s
main () at next-inline.cc:64
64	  return 0;
(gdb) 

If you like you can integrate that into your patch.
You will probably want to add that to the test case.

>>
>>> --- a/gdb/stack.c
>>> +++ b/gdb/stack.c
>>> @@ -330,7 +330,7 @@ frame_show_address (struct frame_info *frame,
>>>        return false;
>>>      }
>>>  
>>> -  return get_frame_pc (frame) != sal.pc;
>>> +  return get_frame_pc (frame) != sal.pc || !sal.is_stmt;
>>>  }
>>>  
>>>  /* See frame.h.  */
>>> @@ -1036,6 +1036,7 @@ print_frame_info (const frame_print_options &fp_opts,
>>>    int location_print;
>>>    struct ui_out *uiout = current_uiout;
>>>  
>>> +
>>>    if (!current_uiout->is_mi_like_p ()
>>>        && fp_opts.print_frame_info != print_frame_info_auto)
>>>      {
>>
>> Is this white space change intentional?
> 
> Ooops.  Fixed.
> 
> I also fixed the space before tab issue you pointed out in another
> mail.
> 
> I see you have a patch that depends on this one, but I'd like to leave
> this on the mailing list for a little longer before I merge it to give
> others a chance to comment.
> 

Thanks, regarding my other patch...

I used gprof to get performance numbers, because I was not sure if that
simple approach adds too much execution time, and it turns out that it
spent 30% of the complete execution time in the record_inline_range_end
function, when I was debugging GCC's cc1 executable.
So I decided that this needs to be optimized, I will send a new
version that does the line table patching with a binary search,
after the weekend.

Thanks
Bernd.


> I'll probably merge this over the weekend if there's no other
> feedback.
> 
> Thanks,
> Andrew
> 


  reply	other threads:[~2020-02-14 20:05 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-05 11:37 [PATCH 0/2] Line table is_stmt support Andrew Burgess
2020-02-05 11:37 ` [PATCH 1/2] gdb/testsuite: Add is-stmt support to the DWARF compiler Andrew Burgess
2020-02-05 11:37 ` [PATCH 2/2] gdb: Add support for tracking the DWARF line table is-stmt field Andrew Burgess
2020-02-05 17:55   ` Bernd Edlinger
2020-02-10 18:30     ` Bernd Edlinger
2020-02-11 13:57     ` Andrew Burgess
2020-02-14 20:05       ` Bernd Edlinger [this message]
2020-03-05 18:01         ` Bernd Edlinger
2020-03-08 12:50           ` [PATCHv2 0/2] Line table is_stmt support Andrew Burgess
2020-03-08 14:39             ` Bernd Edlinger
2020-03-10 23:01               ` Andrew Burgess
2020-03-11  6:50                 ` Simon Marchi
2020-03-11 11:28                   ` Andrew Burgess
2020-03-11 13:27                     ` Simon Marchi
2020-04-03 22:21             ` [PATCH 0/2] More regression fixing from is-stmt patches Andrew Burgess
2020-04-03 22:21             ` [PATCH 1/2] gdb/testsuite: Move helper function into lib/dwarf.exp Andrew Burgess
2020-04-06 20:18               ` Tom Tromey
2020-04-14 11:18                 ` Andrew Burgess
2020-04-03 22:21             ` [PATCH 2/2] gdb: Preserve is-stmt lines when switch between files Andrew Burgess
2020-04-04 18:07               ` Bernd Edlinger
2020-04-04 19:59                 ` Bernd Edlinger
2020-04-04 22:23                 ` Andrew Burgess
2020-04-05  0:04                   ` Bernd Edlinger
2020-04-05  0:47                   ` Bernd Edlinger
2020-04-05  8:55                   ` Bernd Edlinger
2020-04-11  3:52               ` Bernd Edlinger
2020-04-12 17:13                 ` Bernd Edlinger
2020-04-14 11:28                   ` Andrew Burgess
2020-04-14 11:37                     ` Bernd Edlinger
2020-04-14 11:41                       ` Bernd Edlinger
2020-04-14 13:08                       ` Andrew Burgess
2020-04-16 17:18                     ` Andrew Burgess
2020-04-22 21:13                       ` Tom Tromey
2020-04-25  7:06                         ` Bernd Edlinger
2020-04-27 10:34                           ` Andrew Burgess
2020-05-14 20:18                             ` Tom Tromey
2020-05-14 22:39                               ` Andrew Burgess
2020-05-15  3:35                                 ` Bernd Edlinger
2020-05-15 14:46                                   ` Andrew Burgess
2020-05-16  8:12                                     ` Bernd Edlinger
2020-05-17 17:26                                   ` Bernd Edlinger
2020-05-20 18:26                                   ` Andrew Burgess
2020-05-27 13:10                                     ` Andrew Burgess
2020-06-01  9:05                                       ` Andrew Burgess
2020-03-08 12:50           ` [PATCHv2 1/2] gdb/testsuite: Add is-stmt support to the DWARF compiler Andrew Burgess
2020-03-08 12:50           ` [PATCHv2 2/2] gdb: Add support for tracking the DWARF line table is-stmt field Andrew Burgess
2020-03-16 20:57             ` Tom Tromey
2020-03-16 22:37               ` Bernd Edlinger
2020-03-17 12:47               ` Tom Tromey
2020-03-17 18:23                 ` Tom Tromey
2020-03-17 18:51                   ` Bernd Edlinger
2020-03-17 18:56                   ` Andrew Burgess
2020-03-17 20:18                     ` Tom Tromey
2020-03-17 22:21                       ` Andrew Burgess
2020-03-23 17:30             ` [PATCH 0/3] Keep duplicate line table entries Andrew Burgess
2020-03-23 17:30             ` [PATCH 1/3] gdb/testsuite: Add compiler options parameter to function_range helper Andrew Burgess
2020-04-01 18:31               ` Tom Tromey
2020-03-23 17:30             ` [PATCH 2/3] gdb/testsuite: Add support for DW_LNS_set_file to DWARF compiler Andrew Burgess
2020-04-01 18:32               ` Tom Tromey
2020-03-23 17:30             ` [PATCH 3/3] gdb: Don't remove duplicate entries from the line table Andrew Burgess
2020-04-01 18:34               ` Tom Tromey
2020-06-01 13:26           ` [PATCH 2/2] gdb: Add support for tracking the DWARF line table is-stmt field Pedro Alves
2020-02-06  9:01   ` Luis Machado
2020-02-11 15:39     ` Andrew Burgess
2020-02-09 21:07   ` [PATCH] Fix range end handling of inlined subroutines Bernd Edlinger
2020-02-10 21:48     ` Andrew Burgess
2020-02-22  6:39     ` [PATCHv2] " Bernd Edlinger
2020-03-08 14:57       ` [PATCHv3] " Bernd Edlinger
2020-03-11 22:02         ` Andrew Burgess
2020-03-12 18:21           ` Bernd Edlinger
2020-03-12 18:27             ` Christian Biesinger
2020-03-13  8:03               ` Bernd Edlinger
2020-03-17 22:27                 ` Andrew Burgess
2020-03-19  1:33                   ` Bernd Edlinger
2020-03-21 20:31                     ` Bernd Edlinger
2020-03-23 17:53                       ` Andrew Burgess
2020-03-23 20:58                         ` Bernd Edlinger
2020-06-01 14:28                           ` Pedro Alves
2020-03-13 12:47         ` [PATCHv4] " Bernd Edlinger

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=AM6PR03MB51704A9FE4E02CA11EF2F8E7E4150@AM6PR03MB5170.eurprd03.prod.outlook.com \
    --to=bernd.edlinger@hotmail.de \
    --cc=andrew.burgess@embecosm.com \
    --cc=gdb-patches@sourceware.org \
    /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