public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug gdb/30344] New: inconsistent variable values for source-level and instruction-level stepping
@ 2023-04-13  8:30 yangyibiao at nju dot edu.cn
  2023-04-13  8:31 ` [Bug gdb/30344] " yangyibiao at nju dot edu.cn
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: yangyibiao at nju dot edu.cn @ 2023-04-13  8:30 UTC (permalink / raw)
  To: gdb-prs

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

            Bug ID: 30344
           Summary: inconsistent variable values for source-level and
                    instruction-level stepping
           Product: gdb
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: gdb
          Assignee: unassigned at sourceware dot org
          Reporter: yangyibiao at nju dot edu.cn
  Target Milestone: ---

Created attachment 14820
  --> https://sourceware.org/bugzilla/attachment.cgi?id=14820&action=edit
triggering source code of small.c

$ gdb --version
GNU gdb (GDB) 13.0.50.20221107-git
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$ gcc --version
gcc (GCC) 13.0.0 20221107 (experimental)
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.



$ cat small.c -n
     1  
     2  int main (int argc, char **argv)
     3  {
     4    char buf[10];
     5  
     6    char c[] = "%i";
     7    unsigned char uc[] = "%i";
     8    const char cc[] = "%i";
     9    const unsigned char cuc[] = "%i";
    10  
    11    __builtin_sprintf(buf, (char *)c, 1);
    12    __builtin_sprintf(buf, (char *)uc, 1);
    13    __builtin_sprintf(buf, (char *)cc, 1);
    14    __builtin_sprintf(buf, (char *)cuc, 1); 
    15    __builtin_sprintf(buf, (const char *)L"foo"); 
    16  
    17    return 0;
    18  }


$ gcc -O2 -g small.c


$ gdb -q a.out
Reading symbols from a.out...
(gdb) start
Temporary breakpoint 1 at 0x401040: file small.c, line 6.
Starting program: /root/devil/batch/a.out 

Temporary breakpoint 1, main (argc=1, argv=0x7fffffffe478) at small.c:6
6         char c[] = "%i";
(gdb) s
7         unsigned char uc[] = "%i";
(gdb) s
8         const char cc[] = "%i";
(gdb) info locals
buf = "\000\000\000\000\000\000\000\000\000"
c = "%i"
uc = "%i"
cc = "%i\377"
cuc = "%i\177"
(gdb) 


$ gdb -q a.out
Reading symbols from a.out...
(gdb) start
Temporary breakpoint 1 at 0x401040: file small.c, line 6.
Starting program: /root/devil/batch/a.out 

Temporary breakpoint 1, main (argc=1, argv=0x7fffffffe478) at small.c:6
6         char c[] = "%i";
(gdb) si
0x0000000000401044      6         char c[] = "%i";
(gdb) 
0x0000000000401049      7         unsigned char uc[] = "%i";
(gdb) 
0x000000000040104e      9         const unsigned char cuc[] = "%i";
(gdb) 
0x0000000000401053      8         const char cc[] = "%i";
(gdb) info locals
buf = "\000\000\000\000\000\000\000\000\000"
c = "@\000"
uc = "\000\000"
cc = "p\344\377"
cuc = "\377\377\177"
(gdb) 



/**********************************
We can found that, when stepping to source code of line 8, these local
variables has different values. 
**********************************/

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

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

* [Bug gdb/30344] inconsistent variable values for source-level and instruction-level stepping
  2023-04-13  8:30 [Bug gdb/30344] New: inconsistent variable values for source-level and instruction-level stepping yangyibiao at nju dot edu.cn
@ 2023-04-13  8:31 ` yangyibiao at nju dot edu.cn
  2023-04-13 12:38 ` yangyibiao at nju dot edu.cn
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: yangyibiao at nju dot edu.cn @ 2023-04-13  8:31 UTC (permalink / raw)
  To: gdb-prs

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

Yibiao Yang <yangyibiao at nju dot edu.cn> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|unknown                     |13.1

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

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

* [Bug gdb/30344] inconsistent variable values for source-level and instruction-level stepping
  2023-04-13  8:30 [Bug gdb/30344] New: inconsistent variable values for source-level and instruction-level stepping yangyibiao at nju dot edu.cn
  2023-04-13  8:31 ` [Bug gdb/30344] " yangyibiao at nju dot edu.cn
@ 2023-04-13 12:38 ` yangyibiao at nju dot edu.cn
  2023-04-14  3:00 ` yangyibiao at nju dot edu.cn
  2023-04-17  9:09 ` vries at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: yangyibiao at nju dot edu.cn @ 2023-04-13 12:38 UTC (permalink / raw)
  To: gdb-prs

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

Yibiao Yang <yangyibiao at nju dot edu.cn> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |vries at gcc dot gnu.org,
                   |                            |yangyibiao at nju dot edu.cn

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

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

* [Bug gdb/30344] inconsistent variable values for source-level and instruction-level stepping
  2023-04-13  8:30 [Bug gdb/30344] New: inconsistent variable values for source-level and instruction-level stepping yangyibiao at nju dot edu.cn
  2023-04-13  8:31 ` [Bug gdb/30344] " yangyibiao at nju dot edu.cn
  2023-04-13 12:38 ` yangyibiao at nju dot edu.cn
@ 2023-04-14  3:00 ` yangyibiao at nju dot edu.cn
  2023-04-17  9:09 ` vries at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: yangyibiao at nju dot edu.cn @ 2023-04-14  3:00 UTC (permalink / raw)
  To: gdb-prs

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

Yibiao Yang <yangyibiao at nju dot edu.cn> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tromey at sourceware dot org

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

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

* [Bug gdb/30344] inconsistent variable values for source-level and instruction-level stepping
  2023-04-13  8:30 [Bug gdb/30344] New: inconsistent variable values for source-level and instruction-level stepping yangyibiao at nju dot edu.cn
                   ` (2 preceding siblings ...)
  2023-04-14  3:00 ` yangyibiao at nju dot edu.cn
@ 2023-04-17  9:09 ` vries at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: vries at gcc dot gnu.org @ 2023-04-17  9:09 UTC (permalink / raw)
  To: gdb-prs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |NOTABUG
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Yibiao Yang from comment #0)
> /**********************************
> We can found that, when stepping to source code of line 8, these local
> variables has different values. 
> **********************************/

But you haven't stepped to the same location (to be precise, the same pc) in
both cases.

In one case, using step, you've stepped to the start of line 8.

In the other case using stepi, you've stepped until hitting the first insn that
is part of line 8.

You should continue stepi-ing until you hit the same location, at which point
you'll see the same values:
...
$ gdb -q a.out
Reading symbols from a.out...
(gdb) start
Temporary breakpoint 1 at 0x400430: file small.c, line 6.
Starting program: /data/vries/gdb/a.out 

Temporary breakpoint 1, main (argc=1, argv=0x7fffffffdce8) at small.c:6
6         char c[] = "%i";
(gdb) si
0x0000000000400434      6         char c[] = "%i";
(gdb) 
0x0000000000400439      7         unsigned char uc[] = "%i";
(gdb) 
0x000000000040043e      9         const unsigned char cuc[] = "%i";
(gdb) 
0x0000000000400443      8         const char cc[] = "%i";
(gdb) 
0x0000000000400448      6         char c[] = "%i";
(gdb) 
0x000000000040044d      11        __builtin_sprintf(buf, (char *)c, 1);
(gdb) 
0x0000000000400452      11        __builtin_sprintf(buf, (char *)c, 1);
(gdb) 
0x0000000000400454      7         unsigned char uc[] = "%i";
(gdb) 
0x0000000000400459      11        __builtin_sprintf(buf, (char *)c, 1);
(gdb) 
0x000000000040045e      9         const unsigned char cuc[] = "%i";
(gdb) 
0x0000000000400463      11        __builtin_sprintf(buf, (char *)c, 1);
(gdb) 
0x0000000000400468      8         const char cc[] = "%i";
(gdb) si
0x000000000040046d      6         char c[] = "%i";
(gdb) 
7         unsigned char uc[] = "%i";
(gdb) 
8         const char cc[] = "%i";
(gdb) info locals
buf = "\000\000\000\000\000\000\000\000\000"
c = "%i"
uc = "%i"
cc = "%i\377"
cuc = "%i\177"
(gdb) print /x $pc
$1 = 0x400477
...

Using print /x $pc, we can verify that it is indeed the same location:
...
$ gdb -q a.out
Reading symbols from a.out...
(gdb) start
Temporary breakpoint 1 at 0x400430: file small.c, line 6.
Starting program: /data/vries/gdb/a.out 

Temporary breakpoint 1, main (argc=1, argv=0x7fffffffdce8) at small.c:6
6         char c[] = "%i";
(gdb) s
7         unsigned char uc[] = "%i";
(gdb) 
8         const char cc[] = "%i";
(gdb) p /x $pc
$1 = 0x400477
...

AFAICT, there's no bug in gcc and no bug in gdb.

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

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

end of thread, other threads:[~2023-04-17  9:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-13  8:30 [Bug gdb/30344] New: inconsistent variable values for source-level and instruction-level stepping yangyibiao at nju dot edu.cn
2023-04-13  8:31 ` [Bug gdb/30344] " yangyibiao at nju dot edu.cn
2023-04-13 12:38 ` yangyibiao at nju dot edu.cn
2023-04-14  3:00 ` yangyibiao at nju dot edu.cn
2023-04-17  9:09 ` 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).