<div dir="ltr"><div dir="ltr">On Wed, Jun 16, 2021 at 11:35 AM <<a href="mailto:paul.robinson@sony.com" target="_blank">paul.robinson@sony.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">> (out of curiosity, any idea what the Sony debugger does for<br>
> pointer template parameters? At least GCC doesn't seem to be<br>
> able to reconstruct those back into strings (you'd basically<br>
> have to symbolize the address value of the parameter (GCC<br>
> doesn't even encode this value, so it's not surprising GDB<br>
> doesn't try to do anything when it's present)) - so I'll<br>
> probably implement this under a flag but not include (ie: use<br>
> the current full textual encoding) any template with a pointer<br>
> template parameter)<br>
><br>
> eg: extern int i; template<int *> void f1() { } int main() { f1<&i>(); }<br>
<br>
Nice catch, we don't do anything clever here either. </blockquote><div><br>Do you do equality on the computed DW_AT_location value to test whether one DW_TAG_template_value_parameter is equal to another (& so whether the template instantiation in one CU is the same type as in another CU)? Probably pretty reliable if you do the comparison with the result of DWARF expression evaluation.<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> This would<br>
appear to be a special case of non-type template params that can<br>
be arbitrary compile-time expressions; for non-pointer params we <br>
provide the computed value of the compile-time expression, which <br>
is arguably sufficient for cases like<br>
<br>
  constexpr int a = 1; constexpr int b = 2;<br>
  template <int> void f2() { }<br>
  void int_expr() { f2<a + b>(); }<br>
<br>
but it would be nice to do something useful for<br>
<br>
  extern int j[4];<br>
  void ptr_expr() { f1<&j[a+b]>(); }<br></blockquote><div><br>Conveniently this feature is not quite so general, this code would fail to compile (GCC says, for instance: "'& j[3]' is not a valid template argument of type 'int*' because 'j[3]' is not a variable", Clang just says the parameter is "invalid")<br><br>But passing only 'j' is valid. So in theory we could have some attribute that points to the variable declaration of 'j' in this case, which could allow structural equality testing using this DWARF. I'm not sure what we'd call that attribute - I guess we could repurpose the DW_AT_location attribute - if it's a DW_FORM_ref* encoding, it refers to another DIE whose location is used (this makes me a bit twitchy because it sounds like DW_OP_implicit_pointer which I think is overly narrow (by describing only an implicit pointer to another object, rather than to an arbitrary value) - but in this case at least for now, C++ doesn't support any generalization, it must point to a named variable so far as I understand), and if it's DW_FORM_exprloc it's what we do today already.<br><br>This might help address the difficult issue that GCC and Clang have split on - GCC, by not including the DW_AT_location ensures that enabling debug info doesn't affect codegen/linking. Clang ensures the value is debuggable, but at the cost of causing the value to be linked into the final binary even if the production code doesn't use it (due to the relocation in the DW_AT_location causing the linker to pull in the value). Hmm, actually I don't really know what the issue is there - clearly we use some kind of relocation for functions that doesn't have this problem, so maybe we're just not using the right kind of relocation for variables? Or there's a gap in relocation support/features that we should fill?<br><br>In any case, having DW_AT_location refer to the DW_TAG_variable then the DW_TAG_variable doesn't necessarily need to have a DW_AT_location (to avoid the linking issue) & if it has a linkage name, the consumer can look up the symbol itself to find it without a DW_AT_location.<br><br>(<br>Here's an example of the linkage issue:<br><br>





<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">$ cat > nttp.cpp</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">extern int i;</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">template<int*> void f1() { }</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">int main() { f1<&i>(); } <span class="gmail-Apple-converted-space"> </span></span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">$ clang++-tot nttp.cpp -g</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">/usr/local/google/home/blaikie/install/bin/../lib/gcc/x86_64-pc-linux-gnu/10.0.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/nttp-e4e14a.o:(.debug_info+0x63): undefined reference to `i'</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">clang-13: </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(202,51,35)"><b>error: </b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><b>linker command failed with exit code 1 (use -v to see invocation)</b></span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">$ clang++-tot nttp.cpp<span class="gmail-Apple-converted-space"> </span></span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(57,192,38)"><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">$ g++-tot nttp.cpp</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">$ g++-tot nttp.cpp -g</span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(57,192,38)"><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">$<span class="gmail-Apple-converted-space"> </span></span></p> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">We can't repurpose DW_AT_name for this because that's the <br>
template parameter's formal name; nothing else comes to mind,<br>
maybe we need a new attribute for this.<br>
--paulr<br>
<br>
</blockquote></div></div>