<div dir="ltr"><div dir="ltr">On Mon, Nov 22, 2021 at 11:02 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">> Hey Paul - you mentioned the SCE debugger always rebuilds names<br>
> from the DWARF tags (after stripping the <...> suffix from the<br>
> DW_AT_name in the DWARF, I guess/assume?) - I was curious if you<br>
> (or others you could cc on this thread) know how that solution<br>
> deals with some of the more difficult issues I've punted on so<br>
> far with the Simplified Template Names work. <br>
><br>
> The specific one that comes to mind is any pointer non-type<br>
> template parameters. (eg: "template<int*> void f1(); int g; ...<br>
> f1<&g>()" - so far as I know there's not enough data in the DWARF<br>
> to reconstruct that name.<br>
<br>
This one I'm pretty sure about: The template_value_parameter has<br>
a DW_AT_location that is the address of the actual parameter, and<br>
that address ought to be resolvable to "g" (at least once you have<br>
the linked image, it should be straightforward, because "g" would<br>
have a DWARF description whose location had that as the address).<br>
We don't have to worry about things like "&array[10]" because <br>
that's not legal for a non-type template parameter (as per<br>
[temp.arg.nontype]p3 in C++11).<br>
<br>
But I've asked anyway, to confirm.<br></blockquote><div><br>Ah, yep. I thought about the possibility of actually doing symbol lookup - but that seemed a bit extreme to me (having to go outside the DWARF to figure out the name). Though that wouldn't work if the variable/function is optimized out (if it's defined in another object file and that isn't referenced/is omitted by the linker, or -Wl,-gc-sections, etc).</div><div><br>There's some quirks here - for some reason these relocations used in the ELF file to write the address of the variables/functions for pointer non-type-template parameters into the DWARF data cause linker errors if those globals aren't defined (which leads to -g/-g0 codegen differences, since the linker is pulling in these symbols, could pull in global ctors in the objects that define those symbols, etc) but the symbols /can/ still be eliminated with -ffunction-sections f-data-sections -Wl,-gc-sections... </div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> The other one I came across was unnamed struct types V lambda<br>
> types - they have distinct manglings & so need different naming<br>
> I think? But the DWARF has no record of that, and probably<br>
> doesn't have enough data to reconstruct the original naming<br>
> (because the naming is based on the number of lambdas seen so<br>
> far - and the DWARF isn't adequately/guaranteed to be ordered<br>
> like the source and also may omit some types if they're unused<br>
> leading to holes in the numbering)<br>
<br>
I was recently unable to figure out how to pass a lambda as a<br>
template parameter, so if you could provide an example that would<br>
be helpful both for this question and the other thing I was doing.<br>
I've passed your description along just in case they know off the<br>
tops of their heads.<br></blockquote><div><br>Oh, sure, consider code something like this:<br><br>





<p 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 style="font-variant-ligatures:no-common-ligatures">template<typename T></span></p>
<p 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 style="font-variant-ligatures:no-common-ligatures">void f1() { }</span></p>
<p 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 style="font-variant-ligatures:no-common-ligatures">class { } x;</span></p>
<p 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 style="font-variant-ligatures:no-common-ligatures">auto y = [] { };</span></p>
<p 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 style="font-variant-ligatures:no-common-ligatures">int main() {</span></p>
<p 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 style="font-variant-ligatures:no-common-ligatures"><span>  </span>f1<decltype(x)>();</span></p>
<p 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 style="font-variant-ligatures:no-common-ligatures"><span>  </span>f1<decltype(y)>();</span></p>
<p 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 style="font-variant-ligatures:no-common-ligatures">}</span></p> <br>





<p 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 style="font-variant-ligatures:no-common-ligatures">$ clang++-tot test.cpp -g -c && llvm-dwarfdump-tot test.o | grep "DW_AT_name\|DW_TAG\|DW_AT_type\|DW_AT_linkage"</span></p>
<p 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 style="font-variant-ligatures:no-common-ligatures">0x0000000b: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(202,51,35)"><b>DW_TAG</b></span><span style="font-variant-ligatures:no-common-ligatures">_compile_unit</span></p>
<p 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 style="font-variant-ligatures:no-common-ligatures"><span>              </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(202,51,35)"><b>DW_AT_name</b></span><span style="font-variant-ligatures:no-common-ligatures"><span>        </span>("test.cpp")</span></p>
<p 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 style="font-variant-ligatures:no-common-ligatures">0x0000002a: <span>  </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(202,51,35)"><b>DW_TAG</b></span><span style="font-variant-ligatures:no-common-ligatures">_subprogram</span></p>
<p 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 style="font-variant-ligatures:no-common-ligatures"><span>                </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(202,51,35)"><b>DW_AT_name</b></span><span style="font-variant-ligatures:no-common-ligatures"><span>      </span>("main")</span></p>
<p 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 style="font-variant-ligatures:no-common-ligatures"><span>                </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(202,51,35)"><b>DW_AT_type</b></span><span style="font-variant-ligatures:no-common-ligatures"><span>      </span>(0x00000089 "int")</span></p>
<p 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 style="font-variant-ligatures:no-common-ligatures">0x00000043: <span>  </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(202,51,35)"><b>DW_TAG</b></span><span style="font-variant-ligatures:no-common-ligatures">_subprogram</span></p>
<p 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 style="font-variant-ligatures:no-common-ligatures"><span>                </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(202,51,35)"><b>DW_AT_linkage</b></span><span style="font-variant-ligatures:no-common-ligatures">_name<span>      </span>("_Z2f1I3$_0Evv")</span></p>
<p 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 style="font-variant-ligatures:no-common-ligatures"><span>                </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(202,51,35)"><b>DW_AT_name</b></span><span style="font-variant-ligatures:no-common-ligatures"><span>      </span>("f1<(unnamed class at test.cpp:3:1)>")</span></p>
<p 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 style="font-variant-ligatures:no-common-ligatures">0x0000005c: <span>    </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(202,51,35)"><b>DW_TAG</b></span><span style="font-variant-ligatures:no-common-ligatures">_template_type_parameter</span></p>
<p 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 style="font-variant-ligatures:no-common-ligatures"><span>                  </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(202,51,35)"><b>DW_AT_type</b></span><span style="font-variant-ligatures:no-common-ligatures"><span>    </span>(0x00000090 "class ")</span></p>
<p 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 style="font-variant-ligatures:no-common-ligatures"><span>                  </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(202,51,35)"><b>DW_AT_name</b></span><span style="font-variant-ligatures:no-common-ligatures"><span>    </span>("T")</span></p>
<p 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 style="font-variant-ligatures:no-common-ligatures">0x00000066: <span>  </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(202,51,35)"><b>DW_TAG</b></span><span style="font-variant-ligatures:no-common-ligatures">_subprogram</span></p>
<p 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 style="font-variant-ligatures:no-common-ligatures"><span>                </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(202,51,35)"><b>DW_AT_linkage</b></span><span style="font-variant-ligatures:no-common-ligatures">_name<span>      </span>("_Z2f1I3$_1Evv")</span></p>
<p 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 style="font-variant-ligatures:no-common-ligatures"><span>                </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(202,51,35)"><b>DW_AT_name</b></span><span style="font-variant-ligatures:no-common-ligatures"><span>      </span>("f1<(lambda at test.cpp:4:10)>")</span></p>
<p 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 style="font-variant-ligatures:no-common-ligatures">0x0000007f: <span>    </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(202,51,35)"><b>DW_TAG</b></span><span style="font-variant-ligatures:no-common-ligatures">_template_type_parameter</span></p>
<p 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 style="font-variant-ligatures:no-common-ligatures"><span>                  </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(202,51,35)"><b>DW_AT_type</b></span><span style="font-variant-ligatures:no-common-ligatures"><span>    </span>(0x00000095 "class ")</span></p>
<p 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 style="font-variant-ligatures:no-common-ligatures"><span>                  </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(202,51,35)"><b>DW_AT_name</b></span><span style="font-variant-ligatures:no-common-ligatures"><span>    </span>("T")</span></p>
<p 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 style="font-variant-ligatures:no-common-ligatures">0x00000089: <span>  </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(202,51,35)"><b>DW_TAG</b></span><span style="font-variant-ligatures:no-common-ligatures">_base_type</span></p>
<p 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 style="font-variant-ligatures:no-common-ligatures"><span>                </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(202,51,35)"><b>DW_AT_name</b></span><span style="font-variant-ligatures:no-common-ligatures"><span>      </span>("int")</span></p>
<p 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 style="font-variant-ligatures:no-common-ligatures">0x00000090: <span>  </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(202,51,35)"><b>DW_TAG</b></span><span style="font-variant-ligatures:no-common-ligatures">_class_type</span></p>
<p 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 style="font-variant-ligatures:no-common-ligatures">0x00000095: <span>  </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(202,51,35)"><b>DW_TAG</b></span><span style="font-variant-ligatures:no-common-ligatures">_class_type<br><br><br style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;font-size:small;font-variant-ligatures:normal"><span style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;font-size:small;font-variant-ligatures:normal">Oh, I had thought these actually mangled differently, but they don't - so if you rendered both as "unnamed class" that'd probably be OK! Clang/LLVM only includes the line, and not the column, so you'd be able to render this as "(unnamed class at test.cpp:3)" rather than "(unnamed class at test.cpp:3:1)".</span><br></span></p></div></div></div>