https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70536

Michał Staromiejski <michal.staromiejski+gnu at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |michal.staromiejski+gnu@gma
                   |                            |il.com

--- Comment #7 from Michał Staromiejski <michal.staromiejski+gnu at gmail dot 
com> ---
I am not an expert on DWARF but I work with heavily templated code and I was
really surprised that the basic feature of having parameters from pack
instantiation is not available.

As per my investigation, the following code snippet is partially supported by
the official GCC release (tested on 14.1 only):


template <typename ... Us>
struct A {
  static int f(Us ... us) {
    return 0; // breakpoint
  }
};

template <typename ... Ts>
int g(Ts ... ts) {
  return A<Ts ...>::f(ts ...);
}

int main() {
  return g(1, 2.5);
}


with (unpatched) GDB stacktrace for the breakpoint at line 4:


#0  A<int, double>::f (us#0=1, us#1=2.5) at vt.cpp:4
#1  0x0000555555555171 in g<int, double> () at vt.cpp:10
#2  0x0000555555555147 in main () at vt.cpp:14


It seems that the issue with variadic parameters is only for function templates
(`f` is not one). After examining GIMPLE output, we can see that the names for
parameters are already there, they are just not exported in respective DIEs:


main ()
{
  int D.2099;

  D.2099 = g<int, double> (1, 2.5e+0);
  return D.2099;
  D.2099 = 0;
  return D.2099;
}

g<int, double> (int ts#0, double ts#1)
{
  int D.2102;

  D.2102 = A<int, double>::f (ts#0, ts#1);
  return D.2102;
}

A<int, double>::f (int us#0, double us#1)
{
  int D.2104;

  D.2104 = 0;
  return D.2104;
}


I tried to just change `false` to `true` just below your change (to emit names)
but the problem is that GDB does not support it (`DW_TAG_formal_parameter` DIEs
should appear directly under the respective `DW_TAG_subprogram` DIE).
So instead, I suggest to modify `while (generic_decl_parm || parm)` loop at
gcc/dwarf2out.cc:24103 (line numbers wrt 14.1 tag) to just export all the
`DW_TAG_formal_parameter` DIEs and separately all the
`DW_TAG_GNU_formal_parameter_pack` DIEs (separate loop) without exporting
formal parameters again:


      // emit all formal parameter packs
      while (generic_decl_parm)
        {
          if (lang_hooks.function_parameter_pack_p (generic_decl_parm))
            gen_formal_parameter_pack_die (generic_decl_parm, NULL, subr_die,
                                           NULL);
          generic_decl_parm = DECL_CHAIN (generic_decl_parm);
        }

      // emit all formal parameters
      while (parm)
        {
          dw_die_ref parm_die = gen_decl_die (parm, NULL, NULL, subr_die);

          if (early_dwarf
              && parm == DECL_ARGUMENTS (decl)
              && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
              && parm_die
              && (dwarf_version >= 3 || !dwarf_strict))
            add_AT_die_ref (subr_die, DW_AT_object_pointer, parm_die);

          parm = DECL_CHAIN (parm);
        }


This seems to work as expected (also with mixed normal + variadic parameters)
with official GDB.

Any thoughts?

Reply via email to