Bug 25911 - Show column when stepping through line
Summary: Show column when stepping through line
Status: NEW
Alias: None
Product: gdb
Classification: Unclassified
Component: cli (show other bugs)
Version: HEAD
: P2 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-05-03 10:32 UTC by Tom de Vries
Modified: 2022-03-01 23:58 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tom de Vries 2020-05-03 10:32:19 UTC
I.

Consider the following test-case:
...
$ cat -n stmts-on-line.c 
     1  int
     2  main (void)
     3  {
     4    int a = 4;
     5
     6    a = 5; a = 6; a = 7;
     7
     8    return 0;
     9  }
...

II.

Compiled with gcc 7.5.0 and debug info:
...
$ gcc -g stmts-on-line.c 
...

We can step through the instructions on line 6 using stepi:
...
$ gdb a.out
Reading symbols from a.out...
(gdb) start
Temporary breakpoint 1 at 0x40049b: file stmts-on-line.c, line 4.
Starting program: a.out 

Temporary breakpoint 1, main () at stmts-on-line.c:4
4         int a = 4;
(gdb) s
6         a = 5; a = 6; a = 7;
(gdb) si
0x00000000004004a9      6         a = 5; a = 6; a = 7;
(gdb) si
0x00000000004004b0      6         a = 5; a = 6; a = 7;
(gdb) si
8         return 0;
...
and can see progress through the line number and instruction addresses.

That works as follows.  The instructions are at addresses:
...
  40049b:       c7 45 fc 04 00 00 00    movl   $0x4,-0x4(%rbp)
  4004a2:       c7 45 fc 05 00 00 00    movl   $0x5,-0x4(%rbp)
  4004a9:       c7 45 fc 06 00 00 00    movl   $0x6,-0x4(%rbp)
  4004b0:       c7 45 fc 07 00 00 00    movl   $0x7,-0x4(%rbp)
  4004b7:       b8 00 00 00 00          mov    $0x0,%eax
...
and the line number info table looks like:
...
  [0x00000125]  Special opcode 62: advance Address by 4 to 0x40049b and Line by 1 to 4
  [0x00000126]  Special opcode 105: advance Address by 7 to 0x4004a2 and Line by 2 to 6
  [0x00000127]  Advance PC by constant 17 to 0x4004b3
  [0x00000128]  Special opcode 63: advance Address by 4 to 0x4004b7 and Line by 2 to 8
...

So, put in DWARF standard terms, there are "recommended breakpoint locations" at 0x40049b, 0x4004a2 and 0x4004b7.  When we're stopped at such a location, the line without address is shown.

When we're stopped at an instruction which is not such a location, the line with address is shown (4004a9, 4004b0).

III.

Now consider the same test-case, compiled with gcc 10.0.1 and debug info:
...
$ gcc-10 -g stmts-on-line.c 
...

Now when stepping through the instructions on line 6 using stepi:
...
$ gdb a.out
Reading symbols from a.out...
(gdb) start
Temporary breakpoint 1 at 0x400496: file stmts-on-line.c, line 4.
Starting program: /data/gdb_versions/devel/a.out 

Temporary breakpoint 1, main () at stmts-on-line.c:4
4         int a = 4;
(gdb) s
6         a = 5; a = 6; a = 7;
(gdb) si
6         a = 5; a = 6; a = 7;
(gdb) si
6         a = 5; a = 6; a = 7;
(gdb) si
8         return 0;
...
we don't see progress, we seem to be stuck at line 6.

In this case, the instructions are at addresses:
...
  400496:       c7 45 fc 04 00 00 00    movl   $0x4,-0x4(%rbp)
  40049d:       c7 45 fc 05 00 00 00    movl   $0x5,-0x4(%rbp)
  4004a4:       c7 45 fc 06 00 00 00    movl   $0x6,-0x4(%rbp)
  4004ab:       c7 45 fc 07 00 00 00    movl   $0x7,-0x4(%rbp)
  4004b2:       b8 00 00 00 00          mov    $0x0,%eax
...
and the line number info table looks like:
...
  [0x00000129]  Special opcode 62: advance Address by 4 to 0x400496 and Line by 1 to 4
  [0x0000012a]  Set column to 5
  [0x0000012c]  Special opcode 105: advance Address by 7 to 0x40049d and Line by 2 to 6
  [0x0000012d]  Set column to 12
  [0x0000012f]  Special opcode 103: advance Address by 7 to 0x4004a4 and Line by 0 to 6
  [0x00000130]  Set column to 19
  [0x00000132]  Special opcode 103: advance Address by 7 to 0x4004ab and Line by 0 to 6
  [0x00000133]  Set column to 10
  [0x00000135]  Special opcode 105: advance Address by 7 to 0x4004b2 and Line by ...

Now all the instructions are also breakpoint locations, which explains why we don't see addresses.

IV.

It would be good if gdb can somehow show progress here, perhaps through something like:
...
(gdb) s
6         a = 5; a = 6; a = 7;
(gdb) si
6         a = 5; a = 6; a = 7;
                 ^
(gdb) si
6         a = 5; a = 6; a = 7;
                        ^
(gdb) si
8         return 0;
...
Comment 1 Tom de Vries 2020-05-04 14:27:13 UTC
Alternatively, as suggested in PR22531 comment 1, we could try to combine entries in the line number table with the same line.

That way, progress would be shown by showing the addresses, as before with gcc-7.
Comment 2 Tom de Vries 2020-05-04 16:26:15 UTC
Hmm, lldb uses an underline to indicate the column.  That's nice, because it can be done in the same line.
Comment 3 Tom Tromey 2022-03-01 23:58:43 UTC
We could display it somehow in the TUI as well.

Column stepping is also useful if we ever want to implement
the Debug Adapter Protocol.  It allows for column stepping.