[Bug c++/25329] New: incorrect evaluated address for struct fields

sgdxbc at gmail dot com sourceware-bugzilla@sourceware.org
Tue Dec 31 10:24:00 GMT 2019


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

            Bug ID: 25329
           Summary: incorrect evaluated address for struct fields
           Product: gdb
           Version: 8.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
          Assignee: unassigned at sourceware dot org
          Reporter: sgdxbc at gmail dot com
  Target Milestone: ---

Created attachment 12158
  --> https://sourceware.org/bugzilla/attachment.cgi?id=12158&action=edit
Demo code file.

Reproducing demo

#include <stdio.h>
#include <stdlib.h>

#define S(n) \
        struct { \
                int a[n]; \
                int x; \
        }

int main(int argc, char *argv[]) {
    S(argc) *s = malloc(sizeof(S(argc)));
    printf("%p %p %p\n", s, &s->a[1], &s->x);
    return 0;
}       

GDB log

$ gdb test
GNU gdb (Debian 8.2.1-2+b3) 8.2.1
Copyright (C) 2018 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.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from test...done.
(gdb) break main
Breakpoint 1 at 0x115d: file test.c, line 11.
(gdb) r a a a
Starting program: /mnt/c/Users/corre/Projects/weaver/test a a a

Breakpoint 1, main (argc=4, argv=0x7ffffffee218) at test.c:11
warning: Source file is more recent than executable.
11              S(argc) *s = malloc(sizeof(S(argc)));
(gdb) n
12          printf("%p %p %p\n", s, &s->a[1], &s->x);
(gdb) p s
$1 = (struct {...} *) 0x8005260
(gdb) p &s->a
$2 = (int (*)[variable length]) 0x8005260
(gdb) p &s->x
$3 = (int *) 0x8005260
(gdb) n
0x8005260 0x8005264 0x8005270
13              return 0;
(gdb)

Which is clear that GDB report wrong address 0x8005260 for &s->x, which is
actually should be 0x8005270.

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


More information about the Gdb-prs mailing list