<div dir="ltr">I built with both clang and gcc, the behavior is the same (lldb fails to evaluate the expression, gdb succeeds).<div><br></div><div>Trying to evaluate a template type that hasn't been instantiated fails in both lldb and gdb.</div><div>ie.</div><div>(gdb) p sizeof(foo<double>)<br>No symbol "foo<double>" in current context.</div><div>(lldb) p sizeof(foo<double>)<br>error: implicit instantiation of undefined template 'foo<double>'<br>template is declared here<br></div><div><br></div><div>Looking at the debug info, both template instantiations are there, it seems like LLDB just isn't finding it (while GDB is).</div><div><br></div><div> $readelf --debug-dump a.out | grep foo<br>  0x00000000 666f6f00 5400696e 7400666f 6f3c696e foo.T.int.foo<in<br>  0x00000080 00746573 74320066 6f6f3c76 6f69643e .test2.foo<void><br>    <41>   DW_AT_name        : (indirect string, offset: 0xa): foo<int><br>    <49>   DW_AT_name        : (indirect string, offset: 0x0): foo<br>    <8f>   DW_AT_name        : (indirect string, offset: 0x87): foo<void><br>    <97>   DW_AT_name        : (indirect string, offset: 0x0): foo<br>    8d     foo<void><br>    3f     foo<int><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jul 23, 2019 at 8:35 PM Jim Ingham <<a href="mailto:jingham@apple.com">jingham@apple.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">lldb can't currently create new template instantiations.  It can only access ones that were generated in the binary you were debugging.  The debug information doesn't have any code, so we can't create new instantiations from there.  Having the debugger try to include headers into the expression context in the same way the compiler did originally is also tricky since we don't know the header search paths or defines that the compiler used when it built the template instantiations...  Raphael has been working on doing this for the case where the C++ code is build into a clang module, but I don't think that work is done yet, and then you have to build your code with modules to use it...<br>
<br>
The <int> expression is failing because clang is being smart and sees that though you mention foo<int> in reference to "test" you never actually use "test", so it doesn't actually have to make that instantiation. In the case where this works with gdb, did you build with clang or did you build with gcc?  If the latter, this might be working for gdb because gcc emits code for the int template instantiation when you mention it, rather than only when you use it?<br>
<br>
Does it also work for gdb when you try:<br>
<br>
(gdb) p sizeof(foo<double>)<br>
<br>
or any other type you haven't mentioned in your code?<br>
<br>
Not that that really matters for what lldb would have to do, but it would be interesting to know...<br>
<br>
Jim<br>
<br>
<br>
<br>
> On Jul 23, 2019, at 4:22 PM, Scott Funkenhauser via lldb-dev <<a href="mailto:lldb-dev@lists.llvm.org" target="_blank">lldb-dev@lists.llvm.org</a>> wrote:<br>
> <br>
> Hey,<br>
> <br>
> I've noticed that evaluating expressions involving templated classes seems to have some unexpected behavior.<br>
> <br>
> I've created the following sample code to reproduce the issue: <br>
> <br>
> template <typename T> class foo<br>
> { <br>
>   uint32_t data;<br>
> };<br>
> <br>
> foo<int> test;<br>
> <br>
> int main() {<br>
>   foo<void> test2;<br>
>   return 0;<br>
> }<br>
> <br>
> I've set a breakpoint on main and evaluated the following expressions:<br>
> (lldb) p sizeof(foo<void>)<br>
> (unsigned long) $0 = 4<br>
> (lldb) p sizeof(foo<int>)<br>
> error: implicit instantiation of undefined template 'foo<int>'<br>
> template is declared here<br>
> <br>
> It seems like expression evaluation can only find the specialized templated classes that were used in the current scope. Running the same example using GDB works as expected (both expressions are evaluated correctly).<br>
> <br>
> Is this a known issue?<br>
> Does anybody have any insight, or familiarity with expression evaluation that would be able to point me in the right direction?<br>
> <br>
> Thanks,<br>
> Scott<br>
> _______________________________________________<br>
> lldb-dev mailing list<br>
> <a href="mailto:lldb-dev@lists.llvm.org" target="_blank">lldb-dev@lists.llvm.org</a><br>
> <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev</a><br>
<br>
</blockquote></div>