public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Re: gdb displaying only one line of instructions when stepping
@ 2021-12-21 22:14 Andrea Monaco
  2021-12-21 22:54 ` David Blaikie
  0 siblings, 1 reply; 4+ messages in thread
From: Andrea Monaco @ 2021-12-21 22:14 UTC (permalink / raw)
  To: dblaikie; +Cc: gdb


  > Though ultimately the DWARF format itself would probably need to be
  > improved to describe source ranges (maybe even non-contiguous ones)
  > and a preferred location - then then + operation could be described
  > as the whole range of "x + y" with a specific location of '+', and
  > the assignment could be the whole range of "a = x + y" with a
  > specific location of '='.


I looked up DWARF format a bit using the dwarfdump utility.  I see that
DWARF records the line number of each new instruction.  Changing the
format would be a lot of work; but maybe some kind of heuristics might
do the job.


When single stepping, gdb could display all lines until the following
instruction, excluding it, and also excluding blank lines and (perhaps)
comments immediately before it.

As another rule, it might stop immediately (like it does now) when the
current line is, or includes, the closing bracket of a function.  (I saw
that gcc records the closing bracket as a separate instruction, even
when it is on the same line as the last instruction of the function.)


This heuristics may give reasonable results in many cases, or be a
starting point.  What do you think?



Andrea Monaco

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: gdb displaying only one line of instructions when stepping
  2021-12-21 22:14 gdb displaying only one line of instructions when stepping Andrea Monaco
@ 2021-12-21 22:54 ` David Blaikie
  0 siblings, 0 replies; 4+ messages in thread
From: David Blaikie @ 2021-12-21 22:54 UTC (permalink / raw)
  To: Andrea Monaco; +Cc: gdb

On Tue, Dec 21, 2021 at 5:14 PM Andrea Monaco <andrea.monaco@autistici.org>
wrote:

>
>   > Though ultimately the DWARF format itself would probably need to be
>   > improved to describe source ranges (maybe even non-contiguous ones)
>   > and a preferred location - then then + operation could be described
>   > as the whole range of "x + y" with a specific location of '+', and
>   > the assignment could be the whole range of "a = x + y" with a
>   > specific location of '='.
>
>
> I looked up DWARF format a bit using the dwarfdump utility.  I see that
> DWARF records the line number of each new instruction.  Changing the
> format would be a lot of work;


^ Yeah, for sure. Would be quite a bit of work.


> but maybe some kind of heuristics might
> do the job.
>

Possibly - that gets into the realm of design judgments that I'm not
qualified to make much of an assessment of, as I don't work on gdb
generally (I mostly work on clang's debug info emission)

When single stepping, gdb could display all lines until the following
> instruction, excluding it, and also excluding blank lines and (perhaps)
> comments immediately before it.
>

Hmm, maybe? Not sure how that'll compare between Clang and GCC's (or other
compiler's) choice of source location for expressions, or how it might
break when macros or other things are involved (where the line may not move
forward in a regular way)..

At least with Clang's debug info, if you did this - it might not ever
trigger, because the next instruction will often be at a previous line (as
in the `a = b + c` example - the next line location after the '+' would be
earlier, at the '=' - I guess a direction agnostic definition could be used
and so in:
1: a
2: =
3: b
4: +
5: c

gdb could show lines 3 and 4 when stopped at '+' and, could show lines 2,
3, 4, and 5 when stopped at '='? That might be a bit
uncomfortable/haphazard to the user.

Not sure what GCC's line table looks like/how it'd appear - I /guess/ if it
always use the start of the subexpression, then it'd show line 2 and 3 for
the '+' (which might be pretty confusing, since that'd include the '='
line, but not include the '+' line) and then include lines 1-5 for the '='.


> As another rule, it might stop immediately (like it does now) when the
> current line is, or includes, the closing bracket of a function.  (I saw
> that gcc records the closing bracket as a separate instruction, even
> when it is on the same line as the last instruction of the function.)
>
>
> This heuristics may give reasonable results in many cases, or be a
> starting point.  What do you think?
>

Might be something that could be done - but I worry it'd be more confusing
than helpful. Maybe changing the default number of lines of source the
debugger shows from 1 to 3 or something, to provide a bit of context rather
than just a single line, would be sufficient?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: gdb displaying only one line of instructions when stepping
  2021-12-21 14:15 Andrea Monaco
@ 2021-12-21 14:21 ` David Blaikie
  0 siblings, 0 replies; 4+ messages in thread
From: David Blaikie @ 2021-12-21 14:21 UTC (permalink / raw)
  To: Andrea Monaco; +Cc: gdb

The actual underlying DWARF information that gdb is using to render source
only describes a single line of source - and gdb probably doesn't try to
parse or interpret the source code at all.

I'm not sure about GCC's generated DWARF, but Clang's generated DWARF will
use its AST's "preferred location" as the location of a given instruction.
This is the same location as would be highlighted with a "^" in a Clang
warning or other diagnostic.

eg:

a =
  x +
  y;

The store to 'a' should be attributed to '=' and the add instruction should
be attributed to '+'.

If GCC rendered the column info from the line table, it might make it more
clear? (maybe there's an option to make it do that)

Though ultimately the DWARF format itself would probably need to be
improved to describe source ranges (maybe even non-contiguous ones) and a
preferred location - then then + operation could be described as the whole
range of "x + y" with a specific location of '+', and the assignment could
be the whole range of "a = x + y" with a specific location of '='.

On Tue, Dec 21, 2021 at 9:16 AM Andrea Monaco via Gdb <gdb@sourceware.org>
wrote:

>
> Hello.
>
>
> I noticed that, when single stepping through a program, gdb shows only
> one line of instructions that take more than one.
>
> For example, a simple
>
>   a =
>     5;
>
>
> is showed as
>
>   (gdb) next
>   24        a =
>   (gdb)
>
> As a user, I'd definitely prefer gdb to show me the full instruction I'm
> about to run.
>
>
> Maybe there's some way to do that, and I missed it?  Otherwise I can
> work on it.
>
>
>
> Let me know,
>
> Andrea Monaco
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* gdb displaying only one line of instructions when stepping
@ 2021-12-21 14:15 Andrea Monaco
  2021-12-21 14:21 ` David Blaikie
  0 siblings, 1 reply; 4+ messages in thread
From: Andrea Monaco @ 2021-12-21 14:15 UTC (permalink / raw)
  To: gdb


Hello.


I noticed that, when single stepping through a program, gdb shows only
one line of instructions that take more than one.

For example, a simple

  a =
    5;


is showed as

  (gdb) next
  24        a =
  (gdb)         

As a user, I'd definitely prefer gdb to show me the full instruction I'm
about to run.


Maybe there's some way to do that, and I missed it?  Otherwise I can
work on it.



Let me know,

Andrea Monaco

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-12-21 22:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-21 22:14 gdb displaying only one line of instructions when stepping Andrea Monaco
2021-12-21 22:54 ` David Blaikie
  -- strict thread matches above, loose matches on Subject: below --
2021-12-21 14:15 Andrea Monaco
2021-12-21 14:21 ` David Blaikie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).