public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug debug/112582] New: Inconsistent Variable Values: Discrepancy between Source-Level and Instruction-Level Debugging
@ 2023-11-17  6:35 iamanonymous.cs at gmail dot com
  2023-11-17  6:45 ` [Bug debug/112582] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: iamanonymous.cs at gmail dot com @ 2023-11-17  6:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112582

            Bug ID: 112582
           Summary: Inconsistent Variable Values: Discrepancy between
                    Source-Level and Instruction-Level Debugging
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: iamanonymous.cs at gmail dot com
  Target Milestone: ---

########################
As shows in the following, we can observed that the values of variables x and y
exhibit inconsistencies between source-level debugging and instruction-level
debugging prior to entering the function foo. I'm not sure whether the
inconsistency is a result of code optimization.
########################


###### source-level debugging ######
$ gcc -O2 -g small.c
root@ubuntu:~# gdb -q a.out
Reading symbols from a.out...
(gdb) b main
Breakpoint 1 at 0x401060: file small.c, line 30.
(gdb) r
Starting program: /root/a.out 

Breakpoint 1, main () at small.c:30
30        x = -5;
(gdb) s
31        y = -10;
(gdb) s
32        foo (&x, &y);
(gdb) info locals
x = 65531
y = 65526
(gdb) 


###### instruction-level debugging ######
$ gcc -O2 -g small.c; gdb -q a.out
Reading symbols from a.out...
(gdb) b main
Breakpoint 1 at 0x401060: file small.c, line 27.
(gdb) r
Starting program: /root/a.out 

Breakpoint 1, main () at small.c:27
27        x = -5;
(gdb) si
0x0000000000401064      27        x = -5;
(gdb) info locals
x = 0
y = 0
(gdb) si
0x0000000000401069      28        y = -10;
(gdb) info locals
x = 0
y = 0
(gdb) si
0x000000000040106e      29        foo (&x, &y);
(gdb) info locals
x = 0
y = 0
(gdb) 




###### bug-triggering code ######

$ cat small.c
extern void abort (void);
extern void exit (int);

__attribute__ ((noinline)) void
foo(short unsigned int *p1, short unsigned int *p2)
{
  short unsigned int x1, x4;
  int x2, x3, x5, x6;
  unsigned int x7;

  x1 = *p1;
  x2 = (int) x1;
  x3 = x2 * 65536;
  x4 = *p2;
  x5 = (int) x4;
  x6 = x3 + x4;
  x7 = (unsigned int) x6;
  if (x7 <= 268435455U)
    abort ();
  exit (0);
}

int
main()
{
  short unsigned int x, y;
  x = -5;
  y = -10;
  foo (&x, &y);
}



###### gcc and gdb version ######
$ gcc --version
gcc (GCC) 14.0.0 20231116 (experimental)
Copyright (C) 2023 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.

$ gdb --version
GNU gdb (GDB) 15.0.50.20231116-git
Copyright (C) 2023 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.

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

* [Bug debug/112582] Inconsistent Variable Values: Discrepancy between Source-Level and Instruction-Level Debugging
  2023-11-17  6:35 [Bug debug/112582] New: Inconsistent Variable Values: Discrepancy between Source-Level and Instruction-Level Debugging iamanonymous.cs at gmail dot com
@ 2023-11-17  6:45 ` pinskia at gcc dot gnu.org
  2023-11-20  8:28 ` iamanonymous.cs at gmail dot com
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-17  6:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112582

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
        .cfi_def_cfa_offset 32
        .loc 1 27 5 view .LVU27
        movl    $-5, %eax
        .loc 1 28 5 view .LVU28
        movl    $-10, %edx
        .loc 1 29 3 view .LVU29 // point where after `si`'s is located
        leaq    14(%rsp), %rsi
        leaq    12(%rsp), %rdi
        .loc 1 27 5 view .LVU30
        movw    %ax, 12(%rsp)
        .loc 1 28 3 is_stmt 1 view .LVU31
        .loc 1 28 5 is_stmt 0 view .LVU32
        movw    %dx, 14(%rsp)
        .loc 1 29 3 is_stmt 1 view .LVU33 // point where step is 
        call    foo
...
       .ascii "x\0"    # DW_AT_name
                        # DW_AT_decl_file (1, /app/example.c)
                        # DW_AT_decl_line (0x1a)
        .byte   0x16  # DW_AT_decl_column
        .long   0x9e  # DW_AT_type
        .uleb128 0x2    # DW_AT_location
        .byte   0x91  # DW_OP_fbreg
        .sleb128 -20
        .uleb128 0x3    # (DIE (0x78) DW_TAG_variable)
        .ascii "y\0"    # DW_AT_name
                        # DW_AT_decl_file (1, /app/example.c)
                        # DW_AT_decl_line (0x1a)
        .byte   0x19  # DW_AT_decl_column
        .long   0x9e  # DW_AT_type
        .uleb128 0x2    # DW_AT_location
        .byte   0x91  # DW_OP_fbreg
        .sleb128 -18

Not a bug.

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

* [Bug debug/112582] Inconsistent Variable Values: Discrepancy between Source-Level and Instruction-Level Debugging
  2023-11-17  6:35 [Bug debug/112582] New: Inconsistent Variable Values: Discrepancy between Source-Level and Instruction-Level Debugging iamanonymous.cs at gmail dot com
  2023-11-17  6:45 ` [Bug debug/112582] " pinskia at gcc dot gnu.org
@ 2023-11-20  8:28 ` iamanonymous.cs at gmail dot com
  2023-11-20  8:40 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: iamanonymous.cs at gmail dot com @ 2023-11-20  8:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112582

--- Comment #2 from Anonymous <iamanonymous.cs at gmail dot com> ---
(In reply to Andrew Pinski from comment #1)
>         .cfi_def_cfa_offset 32
>         .loc 1 27 5 view .LVU27
>         movl    $-5, %eax
>         .loc 1 28 5 view .LVU28
>         movl    $-10, %edx
>         .loc 1 29 3 view .LVU29 // point where after `si`'s is located
>         leaq    14(%rsp), %rsi
>         leaq    12(%rsp), %rdi
>         .loc 1 27 5 view .LVU30
>         movw    %ax, 12(%rsp)
>         .loc 1 28 3 is_stmt 1 view .LVU31
>         .loc 1 28 5 is_stmt 0 view .LVU32
>         movw    %dx, 14(%rsp)
>         .loc 1 29 3 is_stmt 1 view .LVU33 // point where step is 
>         call    foo
> ...
>        .ascii "x\0"    # DW_AT_name
>                         # DW_AT_decl_file (1, /app/example.c)
>                         # DW_AT_decl_line (0x1a)
>         .byte   0x16  # DW_AT_decl_column
>         .long   0x9e  # DW_AT_type
>         .uleb128 0x2    # DW_AT_location
>         .byte   0x91  # DW_OP_fbreg
>         .sleb128 -20
>         .uleb128 0x3    # (DIE (0x78) DW_TAG_variable)
>         .ascii "y\0"    # DW_AT_name
>                         # DW_AT_decl_file (1, /app/example.c)
>                         # DW_AT_decl_line (0x1a)
>         .byte   0x19  # DW_AT_decl_column
>         .long   0x9e  # DW_AT_type
>         .uleb128 0x2    # DW_AT_location
>         .byte   0x91  # DW_OP_fbreg
>         .sleb128 -18
> 
> Not a bug.

Thank you, Andrew, for your response. I have concerns regarding the information
provided by the debugger, as it may be somewhat misleading. Although the
debugger indicates that lines 27 and 28 have been executed, a closer
examination reveals that the assigned values of the x and y variables do not
align with expected results. From the user's perspective, it appears that lines
27 and 28 have indeed been executed, yet the variable values remain unchanged.
Therefore, I was wondering whether there are any guarantees from the compiler
or debugger.

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

* [Bug debug/112582] Inconsistent Variable Values: Discrepancy between Source-Level and Instruction-Level Debugging
  2023-11-17  6:35 [Bug debug/112582] New: Inconsistent Variable Values: Discrepancy between Source-Level and Instruction-Level Debugging iamanonymous.cs at gmail dot com
  2023-11-17  6:45 ` [Bug debug/112582] " pinskia at gcc dot gnu.org
  2023-11-20  8:28 ` iamanonymous.cs at gmail dot com
@ 2023-11-20  8:40 ` rguenth at gcc dot gnu.org
  2023-11-20  9:20 ` iamanonymous.cs at gmail dot com
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-11-20  8:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112582

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
I think that's deficiencies in the debugger, IIRC GCC is providing some extra
info here that it doesn't (yet) evaluate.

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

* [Bug debug/112582] Inconsistent Variable Values: Discrepancy between Source-Level and Instruction-Level Debugging
  2023-11-17  6:35 [Bug debug/112582] New: Inconsistent Variable Values: Discrepancy between Source-Level and Instruction-Level Debugging iamanonymous.cs at gmail dot com
                   ` (2 preceding siblings ...)
  2023-11-20  8:40 ` rguenth at gcc dot gnu.org
@ 2023-11-20  9:20 ` iamanonymous.cs at gmail dot com
  2023-11-20  9:21 ` sjames at gcc dot gnu.org
  2023-11-20  9:25 ` iamanonymous.cs at gmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: iamanonymous.cs at gmail dot com @ 2023-11-20  9:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112582

--- Comment #4 from Anonymous <iamanonymous.cs at gmail dot com> ---
(In reply to Richard Biener from comment #3)
> I think that's deficiencies in the debugger, IIRC GCC is providing some
> extra info here that it doesn't (yet) evaluate.

Thanks, Richard. I will take a look on the IIRC GCC.

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

* [Bug debug/112582] Inconsistent Variable Values: Discrepancy between Source-Level and Instruction-Level Debugging
  2023-11-17  6:35 [Bug debug/112582] New: Inconsistent Variable Values: Discrepancy between Source-Level and Instruction-Level Debugging iamanonymous.cs at gmail dot com
                   ` (3 preceding siblings ...)
  2023-11-20  9:20 ` iamanonymous.cs at gmail dot com
@ 2023-11-20  9:21 ` sjames at gcc dot gnu.org
  2023-11-20  9:25 ` iamanonymous.cs at gmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: sjames at gcc dot gnu.org @ 2023-11-20  9:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112582

Sam James <sjames at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sjames at gcc dot gnu.org

--- Comment #5 from Sam James <sjames at gcc dot gnu.org> ---
(IIRC = if I recall correctly)

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

* [Bug debug/112582] Inconsistent Variable Values: Discrepancy between Source-Level and Instruction-Level Debugging
  2023-11-17  6:35 [Bug debug/112582] New: Inconsistent Variable Values: Discrepancy between Source-Level and Instruction-Level Debugging iamanonymous.cs at gmail dot com
                   ` (4 preceding siblings ...)
  2023-11-20  9:21 ` sjames at gcc dot gnu.org
@ 2023-11-20  9:25 ` iamanonymous.cs at gmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: iamanonymous.cs at gmail dot com @ 2023-11-20  9:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112582

--- Comment #6 from Anonymous <iamanonymous.cs at gmail dot com> ---
(In reply to Sam James from comment #5)
> (IIRC = if I recall correctly)

Ah, that explains why my search for "IIRC GCC" on Google didn't yield any
relevant results. Thank you for pointing that out. 😄

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

end of thread, other threads:[~2023-11-20  9:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-17  6:35 [Bug debug/112582] New: Inconsistent Variable Values: Discrepancy between Source-Level and Instruction-Level Debugging iamanonymous.cs at gmail dot com
2023-11-17  6:45 ` [Bug debug/112582] " pinskia at gcc dot gnu.org
2023-11-20  8:28 ` iamanonymous.cs at gmail dot com
2023-11-20  8:40 ` rguenth at gcc dot gnu.org
2023-11-20  9:20 ` iamanonymous.cs at gmail dot com
2023-11-20  9:21 ` sjames at gcc dot gnu.org
2023-11-20  9:25 ` iamanonymous.cs at gmail dot com

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