DWARF question about size of a variable

Carl Love cel@us.ibm.com
Wed Jun 8 19:58:57 GMT 2022


GCC developers:

Is there dwarf information that gives the size of a variable?  I have a
test case which when run on Intel gdb can print the size of an
optimized out variable.  However on PowerPC, gdb says the size
information for the variable is optimized out.  Is there some DWARF
information that I can print on the Intel binary that shows the size
information for the variable even though the variable is optimized out?
Then by comparison on PowerPC I would expect the DWARF information
would either say the size of the variable is optimized out or there is
no information available.

Here is the test program for the test.

#include "../lib/attributes.h"

int
#ifdef NOCLONE
__attribute__((noinline,weak)) ATTRIBUTE_NOCLONE
#else
__attribute__((noinline,weak))
#endif
f1 (int i)
{
  char a[i + 1];
  a[0] = 5;
  return a[0];
}

int
main (void)
{
  volatile int j;
  int i = 5;
  asm volatile ("" : "=r" (i) : "0" (i));
  j = f1 (i);
  return 0;
}

So when the above test program is compiled with -03 and run on Intel we
have the following:

(gdb) break f1
Breakpoint 1 at 0x1150: file /.../gdb/testsuite/gdb.base/vla-optimized-out.c, line 30.
(gdb) r
Starting program: /.../gdb/testsuite/outputs/gdb.base/vla-optimized-out/vla-optimized-out-o3 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, f1 (i=5)
    at /.../gdb/testsuite/gdb.base/vla-optimized-out.c:30
30	{
(gdb) p a
$1 = <optimized out>
(gdb) p sizeof( a)
$2 = 6                              <- the variable is optimized out but apparently 
                                       the size info is still accessible


When I compile and run the same program on PowerPC:

(gdb) break f1
Breakpoint 1 at 0x100006e0: file /.../gdb/testsuite/gdb.base/vla-optimized-out.c, line 33.
(gdb) r
Starting program: /home/carll/GDB/build-current/.../vla-optimized-out-3 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Breakpoint 1, f1 (i=5)
    at /.../gdb/testsuite/gdb.base/vla-optimized-out.c:33
33	  return a[0];
(gdb) p a
$1 = <optimized out>
(gdb) p sizeof (a)
$2 = <optimized out>                  <- the variable is optimized out and the size
                                         is not available.

Anyway, I am looking for some DWARF info on Intel and PowerPC which
will show why Intel can display the size of the variable but PowerPC
can not.  Thanks for you help.

                    Carl Love



More information about the Gcc mailing list