The following example produced an inlined block with local variables that
contain correct location expressions (-g -O2):

#include <stdio.h>
#include <stdint.h>

static inline void
m(char *name, int i, int j)
{
// Random syntactical block to be inlined.
do {
  volatile int p_i = i;
  volatile int p_j = j;
  // Change this to void * or char * and var debugloc disappears!?!
  volatile uintptr_t p_name = (uintptr_t) name;
  // empty asm to force locals into regs.
  inlined_label: asm volatile ("" :: "g"(p_name), "g"(p_i), "g"(p_j));
  printf("%s: (%d,%d)\n", p_name, p_i, p_j);
} while (0);
}

int
main (int argc, char **argv)
{
  m("call", 40, 23);
  return 0;
}

$ gcc -g -O2 i.c
$ readelf -w a.out
[...]
 <5><3d4>: Abbrev Number: 28 (DW_TAG_variable)
    <3d5>   DW_AT_abstract_origin: <0x30f>      
    <3d9>   DW_AT_location    : 2 byte block: 91 6c     (DW_OP_fbreg: -20)
 <5><3dc>: Abbrev Number: 28 (DW_TAG_variable)
    <3dd>   DW_AT_abstract_origin: <0x31a>      
    <3e1>   DW_AT_location    : 2 byte block: 91 68     (DW_OP_fbreg: -24)
 <5><3e4>: Abbrev Number: 28 (DW_TAG_variable)
    <3e5>   DW_AT_abstract_origin: <0x325>      
    <3e9>   DW_AT_location    : 2 byte block: 91 60     (DW_OP_fbreg: -32)
[...]

But if you change the type of p_name to char * (which would be more natural and
was what the original code did), the DW_AT_location of p_name disappears:

[... as above ...]
volatile char *p_name = name;
[...]
$ gcc -g -O2 i.c
$ readelf -w a.out
[...]
 <5><3cf>: Abbrev Number: 28 (DW_TAG_variable)
    <3d0>   DW_AT_abstract_origin: <0x304>      
    <3d4>   DW_AT_location    : 2 byte block: 91 6c     (DW_OP_fbreg: -20)
 <5><3d7>: Abbrev Number: 28 (DW_TAG_variable)
    <3d8>   DW_AT_abstract_origin: <0x30f>      
    <3dc>   DW_AT_location    : 2 byte block: 91 68     (DW_OP_fbreg: -24)
 <5><3df>: Abbrev Number: 29 (DW_TAG_variable)
    <3e0>   DW_AT_abstract_origin: <0x31a>      
[...]

Note, no DW_AT_location for the last variable (p_name), just a
DW_AT_abstract_origin. The other vars (p_i and p_j) still do have both
abstract_origin and location).


-- 
           Summary: Inlined variable debug location disappears when ptr type
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mark at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41097

Reply via email to