public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug gdb/30278] New: gdb gives wrong value at -O1
@ 2023-03-27 13:34 hluaw at connect dot ust.hk
  2023-03-27 14:50 ` [Bug gdb/30278] " tromey at sourceware dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: hluaw at connect dot ust.hk @ 2023-03-27 13:34 UTC (permalink / raw)
  To: gdb-prs

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

            Bug ID: 30278
           Summary: gdb gives wrong value at -O1
           Product: gdb
           Version: HEAD
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: gdb
          Assignee: unassigned at sourceware dot org
          Reporter: hluaw at connect dot ust.hk
  Target Milestone: ---

Environment:
$ gcc --version
gcc (Gentoo 11.3.1_p20221209 p3) 11.3.1 20221209
Copyright (C) 2021 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) 14.0.50.20230327-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.

Code:
int c ;
int func_8() {
  int i = 0;
  for (; i < 8; i++)
    ;
  if ((c = 0))
    ;
  return c;
}
int main() { func_8(); }

Command to reproduce:
b func_8
r
p i

gdb Output:
func_8 () at r.c:6
6         if ((c = 0))
(gdb) p i
$1 = 0

Expected result is `i = 8`, which happens right after line 6.
I tend to think gdb should report `i = 8` at line 6 instead of line 8.
In fact, when the for-loop is followed by other statement rather than the if
here, gdb can correctly report `i = 8` on line 6.

-- 
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/30278] gdb gives wrong value at -O1
  2023-03-27 13:34 [Bug gdb/30278] New: gdb gives wrong value at -O1 hluaw at connect dot ust.hk
@ 2023-03-27 14:50 ` tromey at sourceware dot org
  2023-03-27 14:59 ` tromey at sourceware dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: tromey at sourceware dot org @ 2023-03-27 14:50 UTC (permalink / raw)
  To: gdb-prs

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

Tom Tromey <tromey at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-03-27
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
                 CC|                            |tromey at sourceware dot org

--- Comment #1 from Tom Tromey <tromey at sourceware dot org> ---
I wrote a long thing here about how this is the compiler's fault,
but now I see there really is a gdb bug.

"i" has a location list:

(gdb) info addr i
Symbol "i" is multi-location:
  Base address 0x401106  Range 0x401106-0x401106: a complex DWARF expression:
     0: DW_OP_lit0
     1: DW_OP_stack_value

  Range 0x401106-0x401106: a complex DWARF expression:
     0: DW_OP_lit1
     1: DW_OP_stack_value

  Range 0x401106-0x401106: a complex DWARF expression:
     0: DW_OP_lit2
     1: DW_OP_stack_value

  Range 0x401106-0x401106: a complex DWARF expression:
     0: DW_OP_lit3
     1: DW_OP_stack_value

  Range 0x401106-0x401106: a complex DWARF expression:
     0: DW_OP_lit4
     1: DW_OP_stack_value

  Range 0x401106-0x401106: a complex DWARF expression:
     0: DW_OP_lit5
     1: DW_OP_stack_value

  Range 0x401106-0x401106: a complex DWARF expression:
     0: DW_OP_lit6
     1: DW_OP_stack_value

  Range 0x401106-0x401106: a complex DWARF expression:
     0: DW_OP_lit7
     1: DW_OP_stack_value

  Range 0x401106-0x401116: a complex DWARF expression:
     0: DW_OP_lit8
     1: DW_OP_stack_value


And the PC is:

(gdb) p $pc
$2 = (void (*)()) 0x401106 <func_8>

gdb should be picking the last location in that list, because the 
upper bound is exclusive, not inclusive.  All those other entries
are dead.

-- 
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/30278] gdb gives wrong value at -O1
  2023-03-27 13:34 [Bug gdb/30278] New: gdb gives wrong value at -O1 hluaw at connect dot ust.hk
  2023-03-27 14:50 ` [Bug gdb/30278] " tromey at sourceware dot org
@ 2023-03-27 14:59 ` tromey at sourceware dot org
  2023-03-27 15:42 ` ssbssa at sourceware dot org
  2023-03-27 20:48 ` tromey at sourceware dot org
  3 siblings, 0 replies; 5+ messages in thread
From: tromey at sourceware dot org @ 2023-03-27 14:59 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #2 from Tom Tromey <tromey at sourceware dot org> ---
gdb runs into this code:

      if (low == high && pc == low)
        {
          /* This is entry PC record present only at entry point
             of a function.  Verify it is really the function entry point.  */

in dwarf2_find_location_expression.

In other code paths it does properly check the condition:

      if (pc >= low && pc < high)

It's hard to be sure but maybe this code is some workaround for
a bad compiler case involving entry values, that's then hit by
this particular test case as well.

So right now I'm inclined to say that, while this is a bug, it's
probably better to leave it in place than to try harder to fix it.
The kind of code in the example here isn't really normal or useful.

Maybe one option would be to see if the symbol ("i" in this case)
really could possibly have an entry value.  That would exclude "i"
here since it is not a parameter.

-- 
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/30278] gdb gives wrong value at -O1
  2023-03-27 13:34 [Bug gdb/30278] New: gdb gives wrong value at -O1 hluaw at connect dot ust.hk
  2023-03-27 14:50 ` [Bug gdb/30278] " tromey at sourceware dot org
  2023-03-27 14:59 ` tromey at sourceware dot org
@ 2023-03-27 15:42 ` ssbssa at sourceware dot org
  2023-03-27 20:48 ` tromey at sourceware dot org
  3 siblings, 0 replies; 5+ messages in thread
From: ssbssa at sourceware dot org @ 2023-03-27 15:42 UTC (permalink / raw)
  To: gdb-prs

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

Hannes Domani <ssbssa at sourceware dot org> changed:

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

--- Comment #3 from Hannes Domani <ssbssa at sourceware dot org> ---
Looks like a duplicate of PR28987.

-- 
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/30278] gdb gives wrong value at -O1
  2023-03-27 13:34 [Bug gdb/30278] New: gdb gives wrong value at -O1 hluaw at connect dot ust.hk
                   ` (2 preceding siblings ...)
  2023-03-27 15:42 ` ssbssa at sourceware dot org
@ 2023-03-27 20:48 ` tromey at sourceware dot org
  3 siblings, 0 replies; 5+ messages in thread
From: tromey at sourceware dot org @ 2023-03-27 20:48 UTC (permalink / raw)
  To: gdb-prs

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

Tom Tromey <tromey at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
             Status|NEW                         |RESOLVED

--- Comment #4 from Tom Tromey <tromey at sourceware dot org> ---
LOL, I debugged that one too and came to the same conclusion,
but I have absolutely no recollection of it.

*** This bug has been marked as a duplicate of bug 28987 ***

-- 
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-03-27 20:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-27 13:34 [Bug gdb/30278] New: gdb gives wrong value at -O1 hluaw at connect dot ust.hk
2023-03-27 14:50 ` [Bug gdb/30278] " tromey at sourceware dot org
2023-03-27 14:59 ` tromey at sourceware dot org
2023-03-27 15:42 ` ssbssa at sourceware dot org
2023-03-27 20:48 ` tromey at sourceware dot 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).