public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug gdb/25528] step will stopped at any "asm volatile" statement
       [not found] <bug-25528-4717@http.sourceware.org/bugzilla/>
@ 2020-12-29  3:33 ` yangyibiao at outlook dot com
  2020-12-30 17:02 ` vries at gcc dot gnu.org
  2020-12-30 17:16 ` vries at gcc dot gnu.org
  2 siblings, 0 replies; 3+ messages in thread
From: yangyibiao at outlook dot com @ 2020-12-29  3:33 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=25528

Yibiao Yang <yangyibiao at outlook dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |vries at gcc dot gnu.org,
                   |                            |yangyibiao at outlook dot com
            Summary|incorrect trace for "asm    |step will stopped at any
                   |volatile" statement         |"asm volatile" statement
         Resolution|---                         |FIXED
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Yibiao Yang <yangyibiao at outlook dot com> ---
In current version of GDB, statement with asm volatile will be skipped.

I was wondering that this is the default behavior of GDB.

Therefore, I think this bug in previous version is a bug of GDB.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug gdb/25528] step will stopped at any "asm volatile" statement
       [not found] <bug-25528-4717@http.sourceware.org/bugzilla/>
  2020-12-29  3:33 ` [Bug gdb/25528] step will stopped at any "asm volatile" statement yangyibiao at outlook dot com
@ 2020-12-30 17:02 ` vries at gcc dot gnu.org
  2020-12-30 17:16 ` vries at gcc dot gnu.org
  2 siblings, 0 replies; 3+ messages in thread
From: vries at gcc dot gnu.org @ 2020-12-30 17:02 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=25528

--- Comment #2 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Yibiao Yang from comment #1)
> In current version of GDB, statement with asm volatile will be skipped.
> 
> I was wondering that this is the default behavior of GDB.
> 

Compiling with gcc 9.3.1, and looking at the line info using readline -wL, I
get:
...
CU: small.c:

Line number    Starting address    View    Stmt
4            0x400492               x
5            0x40049c               x
6            0x4004a2               x
6            0x4004a8               x
8            0x4004aa               x
9            0x4004b8               x
9            0x4004c5               x
10           0x4004c9               x
6            0x4004c9       1       x
6            0x4004d4               x
12           0x4004db               x
14           0x4004df               x
14           0x4004e3               x
14           0x4004ed               x
14           0x4004f0               x
...

while we have:
...
$ cat -n small.c
     1  const signed char NM[] = {-1, 0, 1};
     2
     3  __attribute__((noinline)) void f(short delta)
     4  {
     5    short p = 2, s;
     6    for (s = 0; s < 2; s++)
     7    {
     8      p += delta;
     9      if (NM[p] == 0)
    10        asm volatile("");
    11    }
    12  }
    13
    14  void main(void) { f(-1); }
    15
...

So, the line with the asm stmt does have line info, but shares the address with
another entry with another line number.

Using this debugging session, we can see that we do visit the address, but show
line 6 instead of line 10:
...
(gdb) 
9           if (NM[p] == 0)
(gdb) p /x $pc
$1 = 0x4004b8
(gdb) s
6         for (s = 0; s < 2; s++)
(gdb) p /x $pc
$2 = 0x4004c9
(gdb) 
...
which I'd say is a valid interpretation of the line number info.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug gdb/25528] step will stopped at any "asm volatile" statement
       [not found] <bug-25528-4717@http.sourceware.org/bugzilla/>
  2020-12-29  3:33 ` [Bug gdb/25528] step will stopped at any "asm volatile" statement yangyibiao at outlook dot com
  2020-12-30 17:02 ` vries at gcc dot gnu.org
@ 2020-12-30 17:16 ` vries at gcc dot gnu.org
  2 siblings, 0 replies; 3+ messages in thread
From: vries at gcc dot gnu.org @ 2020-12-30 17:16 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=25528

Tom de Vries <vries at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|FIXED                       |NOTABUG

--- Comment #3 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Yibiao Yang from comment #0)
> $ gdb -q ./a.out
> Reading symbols from ./a.out...
> (gdb) break small.c:9
> Breakpoint 1 at 0x113f: file small.c, line 9.
> (gdb) run
> Starting program: /home/yibiao/cv-gcov/a.out 
> 
> Breakpoint 1, f (delta=-1) at small.c:9
> 9	    if (NM[p] == 0)
> (gdb) step
> 10	      asm volatile("");
> (gdb) c
> Continuing.
> 
> Breakpoint 1, f (delta=-1) at small.c:9
> 9	    if (NM[p] == 0)
> (gdb) step
> 10	      asm volatile("");
> (gdb) q
> A debugging session is active.
> 
> 	Inferior 1 [process 4947] will be killed.
> 
> Quit anyway? (y or n) y
> 
> 
> 
> #############################################################################
> ##
> ### We can find that Line #10 @asm volatile("");@ is executed twice. 
> ### However, it is obvious that Line #9 "if (NM[p] == 0)" is True in the
> second for loop. 
> #############################################################################
> ##

I think this is a different variant of the same problem: the target of the true
_and_ false path end up at the same insn, which has two entries in the line
table.  So either we show the "true" line twice, or the "false" line twice.

Confusing, but not a gdb bug.

On the gcc side, it could be argued that this is exactly what you asked for by
providing an _empty_ asm stmt.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

end of thread, other threads:[~2020-12-30 17:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-25528-4717@http.sourceware.org/bugzilla/>
2020-12-29  3:33 ` [Bug gdb/25528] step will stopped at any "asm volatile" statement yangyibiao at outlook dot com
2020-12-30 17:02 ` vries at gcc dot gnu.org
2020-12-30 17:16 ` vries at gcc dot gnu.org

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).