Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess <andrew.burgess@embecosm.com>
To: Luis Machado <luis.machado@linaro.org>
Cc: gdb-patches@sourceware.org, Bernd Edlinger <bernd.edlinger@hotmail.de>
Subject: Re: [PATCH 2/2] gdb: Add support for tracking the DWARF line table is-stmt field
Date: Tue, 11 Feb 2020 15:39:00 -0000	[thread overview]
Message-ID: <20200211153923.GS4020@embecosm.com> (raw)
In-Reply-To: <fee4d657-af43-dcc4-fe3d-85945e793221@linaro.org>

* Luis Machado <luis.machado@linaro.org> [2020-02-06 06:00:29 -0300]:

> Hi,
> 
> I still need to check the patch itself, but i had a question about one
> particular paragraph...
> 
> On 2/5/20 8:37 AM, Andrew Burgess wrote:
> > This commit brings support for the DWARF line table is_stmt field to
> > GDB.  The is_stmt field is used by the compiler when a single source
> > line is split into multiple assembler instructions, especially if the
> > assembler instructions are interleaved with instruction from other
> > source lines.
> > 
> > The compiler will set the is_stmt flag false from some instructions
> > from the source lines, these instructions are not a good place to
> > insert a breakpoint in order to stop at the source line.
> > Instructions which are marked with the is_stmt flag true are a good
> > place to insert a breakpoint for that source line.
> > 
> > Currently GDB ignores all instructions for which is_stmt is false.
> > This is fine in a lot of cases, however, there are some cases where
> > this means the debug experience is not as good as it could be.
> > 
> > Consider stopping at a random instruction, currently this instruction
> > will be attributed to the last line table entry before this point for
> > which is_stmt was true - as these are the only line table entries that
> > GDB tracks.  This can easily be incorrect in code with even a low
> > level of optimisation.
> > 
> > With is_stmt tracking in place, when stopping at a random instruction
> > we now attribute the instruction back to the real source line, even
> > when is_stmt is false for that instruction in the line table.
> > 
> > When inserting breakpoints we still select line table entries for
> > which is_stmt is true, so the breakpoint placing behaviour should not
> > change.
> > 
> > When stepping though code (at the line level, not the instruction
> > level) we will still stop at instruction where is_stmt is true, I
> > think this is more likely to be the desired behaviour.
> 
> Considering a block of continuous instructions that map to the same source
> line, will line-stepping stop at each one of these instructions if is_stmt
> is true? As opposed to stepping over the the whole block until we see a line
> change?

No, a continuous block will be skipped as it is at the moment, even if
is_stmt is true for all entries.

>
> I'm wondering if this would help this bug
> (https://sourceware.org/bugzilla/show_bug.cgi?id=21221) in any way.

I took a look at this bug and even had a few ideas on how we might
improve GDB.  Below is one patch that I put together, though this only
fixes one of the example cases from that bug.  The problem this patch
runs into is that it regresses a few GDB tests
(gdb.base/gdb-sigterm.exp and
gdb.thread/step-bg-decr-pc-switch-thread.exp) in at least one of these
tests GDB makes the following assumption:  Single stepping on a one
line loop (e.g. 'for (;;);') will block forever.  The question then
is:  Does single step move us to the next source line to be executed
that is not the current line, or does single step move us to the next
source line to be executed, even if it is the same as the current
line?

I'm not sure what the answer is to this question...

Thanks,
Andrew

---

commit 35a72ddacf86c7e7f899c869558d1af3cfadb549
Author: Andrew Burgess <andrew.burgess@embecosm.com>
Date:   Tue Feb 11 15:08:10 2020 +0000

    WIP: Try to better handle small loops
    
    This handles this case:
    
      int main(void)
      {
        int var = 0;
    
        for (;;)
          {
            var++;
          }
    
        return 0;
      }
    
    Compiled as 'gcc -g -o test.x test.c'.
    
    Change-Id: I6f499181eca5fb51b6edb050cbce0bda15665d38

diff --git a/gdb/infrun.c b/gdb/infrun.c
index 3919de81f90..03878025959 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -6674,11 +6674,14 @@ process_event_stop_test (struct execution_control_state *ecs)
 
       /* When stepping backward, stop at beginning of line range
 	 (unless it's the function entry point, in which case
-	 keep going back to the call point).  */
+	 keep going back to the call point).  When stepping forward we
+	 stop at the beginning of the range as this indicates we must be
+	 looping.  */
       CORE_ADDR stop_pc = ecs->event_thread->suspend.stop_pc;
       if (stop_pc == ecs->event_thread->control.step_range_start
-	  && stop_pc != ecs->stop_func_start
-	  && execution_direction == EXEC_REVERSE)
+	  && (execution_direction != EXEC_REVERSE
+	      || (stop_pc != ecs->stop_func_start
+		  && execution_direction == EXEC_REVERSE)))
 	end_stepping_range (ecs);
       else
 	keep_going (ecs);
@@ -7173,6 +7176,16 @@ process_event_stop_test (struct execution_control_state *ecs)
 	}
     }
 
+  if (ecs->event_thread->suspend.stop_pc
+      == ecs->event_thread->control.step_range_start)
+    {
+      /* Very small loops might only contain a single line information
+	 entry.  If this is the case then spot when we return to the start
+	 of the line range and stop again.  */
+      end_stepping_range (ecs);
+      return;
+    }
+
   /* We aren't done stepping.
 
      Optimize by setting the stepping range to the line.


  reply	other threads:[~2020-02-11 15:39 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
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 [this message]
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=20200211153923.GS4020@embecosm.com \
    --to=andrew.burgess@embecosm.com \
    --cc=bernd.edlinger@hotmail.de \
    --cc=gdb-patches@sourceware.org \
    --cc=luis.machado@linaro.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