public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug gdb/30315] New: GDB not showing variable that is supposed to be there
@ 2023-04-05 13:39 hluaw at connect dot ust.hk
  2023-04-05 14:36 ` [Bug gdb/30315] " tromey at sourceware dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: hluaw at connect dot ust.hk @ 2023-04-05 13:39 UTC (permalink / raw)
  To: gdb-prs

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

            Bug ID: 30315
           Summary: GDB not showing variable that is supposed to be there
           Product: gdb
           Version: 13.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: gdb
          Assignee: unassigned at sourceware dot org
          Reporter: hluaw at connect dot ust.hk
  Target Milestone: ---

Given the following code:

#include "stdint.h"
#include "string.h"
#include <stdio.h>
int a, b;
char* c;
static int func_1() {
  int i = 0;
  for (; i < 4; i++)
    ;
  for (; a <= 4;) {
    uint16_t d;
    b = 0;
    return b;
    { int i; }
  }
  return b;
}
int main() {
  func_1();
  printf(c);
}

Compiled with gcc 12.2.0 and -O1 -g

The DWARF says that i persists until func_1 exits

Breakpoint 1, func_1 () at r.c:10
10        for (; a <= 4;) {
(gdb) info addr i
Symbol "i" is multi-location:
  Range 0x40112a-0x40112a: the constant 0
  Range 0x40112a-0x40112a: the constant 1
  Range 0x40112a-0x40112a: the constant 2
  Range 0x40112a-0x40112a: the constant 3
  Range 0x40112a-0x40113d: the constant 4
.
(gdb) p i
$1 = 4

But GDB says i is <optimized out> prematurely at line 12 with $pc = 0x401133
still in the range of func_1

(gdb) p i
$2 = <optimized out>
(gdb) p $pc
$3 = (void (*)()) 0x401133 <main+13>
(gdb)

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

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

* [Bug gdb/30315] GDB not showing variable that is supposed to be there
  2023-04-05 13:39 [Bug gdb/30315] New: GDB not showing variable that is supposed to be there hluaw at connect dot ust.hk
@ 2023-04-05 14:36 ` tromey at sourceware dot org
  2024-01-20 16:19 ` ssbssa at sourceware dot org
  2024-01-20 16:34 ` ssbssa at sourceware dot org
  2 siblings, 0 replies; 4+ messages in thread
From: tromey at sourceware dot org @ 2023-04-05 14:36 UTC (permalink / raw)
  To: gdb-prs

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

Tom Tromey <tromey at sourceware dot org> changed:

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

--- Comment #1 from Tom Tromey <tromey at sourceware dot org> ---
It's picking up that second 'i' somehow here.
It isn't obvious why, though, as that variable and
its block don't seem to be referenced at all.

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

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

* [Bug gdb/30315] GDB not showing variable that is supposed to be there
  2023-04-05 13:39 [Bug gdb/30315] New: GDB not showing variable that is supposed to be there hluaw at connect dot ust.hk
  2023-04-05 14:36 ` [Bug gdb/30315] " tromey at sourceware dot org
@ 2024-01-20 16:19 ` ssbssa at sourceware dot org
  2024-01-20 16:34 ` ssbssa at sourceware dot org
  2 siblings, 0 replies; 4+ messages in thread
From: ssbssa at sourceware dot org @ 2024-01-20 16:19 UTC (permalink / raw)
  To: gdb-prs

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

Hannes Domani <ssbssa at sourceware dot org> changed:

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

--- Comment #2 from Hannes Domani <ssbssa at sourceware dot org> ---
I've debugged it to this location of read_lexical_block_scope in dwarf2/read.c:
```
    case PC_BOUNDS_NOT_PRESENT:
      /* DW_TAG_lexical_block has no attributes, process its children as if
         there was no wrapping by that DW_TAG_lexical_block.
         GCC does no longer produces such DWARF since GCC r224161.  */
```
The inner { int i; } block is optimized away, and apparently gcc produces
this kind of block here in this case.
Which means gdb moves up the i variable to the for{} block, and that's why
it's found by print.
As a test I've just put a return in this case block, then gdb found the
correct i also in this location:
```
(gdb) n
12          b = 0;
(gdb) p i
$2 = 4
(gdb) info addr i
Symbol "i" is multi-location:
  Base address 0x140001609  Range 0x13f2e1609-0x13f2e1609: the constant 0
  Range 0x13f2e1609-0x13f2e1609: the constant 1
  Range 0x13f2e1609-0x13f2e1609: the constant 2
  Range 0x13f2e1609-0x13f2e1609: the constant 3
  Range 0x13f2e1609-0x13f2e161c: the constant 4
```

I'm not sure what the correct solution here is.

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

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

* [Bug gdb/30315] GDB not showing variable that is supposed to be there
  2023-04-05 13:39 [Bug gdb/30315] New: GDB not showing variable that is supposed to be there hluaw at connect dot ust.hk
  2023-04-05 14:36 ` [Bug gdb/30315] " tromey at sourceware dot org
  2024-01-20 16:19 ` ssbssa at sourceware dot org
@ 2024-01-20 16:34 ` ssbssa at sourceware dot org
  2 siblings, 0 replies; 4+ messages in thread
From: ssbssa at sourceware dot org @ 2024-01-20 16:34 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #3 from Hannes Domani <ssbssa at sourceware dot org> ---
(In reply to Hannes Domani from comment #2)
> I've debugged it to this location of read_lexical_block_scope in
> dwarf2/read.c:
> ```
>     case PC_BOUNDS_NOT_PRESENT:
>       /* DW_TAG_lexical_block has no attributes, process its children as if
> 	 there was no wrapping by that DW_TAG_lexical_block.
> 	 GCC does no longer produces such DWARF since GCC r224161.  */
> ```

This was added for PR15231.

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

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

end of thread, other threads:[~2024-01-20 16:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-05 13:39 [Bug gdb/30315] New: GDB not showing variable that is supposed to be there hluaw at connect dot ust.hk
2023-04-05 14:36 ` [Bug gdb/30315] " tromey at sourceware dot org
2024-01-20 16:19 ` ssbssa at sourceware dot org
2024-01-20 16:34 ` ssbssa 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).