This patch adds the associated template parameters to the DWARF name attribute
of all template variable specializations, mirroring how they are referenced in
the source code.
Details
Diff Detail
- Repository
- rC Clang
- Build Status
Buildable 16397 Build 16397: arc lint + arc unit
Event Timeline
lib/CodeGen/CGDebugInfo.cpp | ||
---|---|---|
2992 | Why not use Name.str() directly? |
lib/CodeGen/CGDebugInfo.cpp | ||
---|---|---|
2992 | I got "error: invalid initialization of non-const reference ... from rvalue ...". Using NameString fixed the issue. |
I don't know off the top of my head. Did anybody working on this patch try printing variables in lldb with this name change, particularly global variables? Global lookups are particularly tricky, but it shouldn't be hard to check. You'd want to check that you can print them with frame var and expr.
@ormris Thanks! If you come up with some examples that test this, I can whip up an lldb test case (or you can if you are feeling adventurous.) If you want to try I'd be happy to give you a hand.
@jingham
Doesn't look like it works.
$ cat repro.cpp template <typename T> T crazy = T(); int main(void) { crazy<int> = 5; return crazy<int>; } $ clang++ -g repro.cpp $ lldb a.out ... (lldb) frame variable (lldb) expr crazy error: use of undeclared identifier 'crazy' error: 1 errors parsing expression (lldb) expr crazy<int> error: use of undeclared identifier 'crazy' error: expected '(' for function-style cast or type construction error: expected expression error: 3 errors parsing expression (lldb)
EDIT: Adding version information.
$ clang++ --version clang version 7.0.0 (trunk 328341) Target: x86_64-unknown-linux-gnu Thread model: posix ... $ lldb --version lldb version 7.0.0 (http://llvm.org/svn/llvm-project/lldb/trunk revision 329079) clang revision 328341 llvm revision 328341 $
Apparently this makes a global variable, so "frame var" wouldn't show it by default. What does "frame var -g" show?
We would also need to get:
(lldb) frame var -g crazy
or something like it to work. "frame var" has its own parser to support "->" and ".". That doesn't currently work with:
(lldb) frame var -g crazy<int> error: unexpected char '<' encountered after "crazy<int>" in "<int>"
so for that part to work, either the name lookup must work w/o the <int> or frame var's parser must be updated to cope with this (and of course with any arbitrarily complex type that could get substituted in there). That's likely a non-trivial bit of work.
I wonder if expr is failing because this is a C++14 extension, lldb sets CPlusPlus11 to true in the LangOpts for the compiler it makes, but not CPlusPlus14.
About to test with CPlusPlus14 enabled....
Here's the output from those two commands.
(lldb) frame var -g crazy error: no variable named 'crazy' found in this frame (lldb) frame var -g crazy<int> error: no variable named 'crazy' found in this frame (lldb)
No such luck...
Patch:
Index: source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp =================================================================== --- source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp (revision 329079) +++ source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp (working copy) @@ -400,8 +400,9 @@ break; case lldb::eLanguageTypeC_plus_plus: case lldb::eLanguageTypeC_plus_plus_11: + m_compiler->getLangOpts().CPlusPlus11 = true; case lldb::eLanguageTypeC_plus_plus_14: - m_compiler->getLangOpts().CPlusPlus11 = true; + m_compiler->getLangOpts().CPlusPlus14 = true; m_compiler->getHeaderSearchOpts().UseLibcxx = true; LLVM_FALLTHROUGH; case lldb::eLanguageTypeC_plus_plus_03:
Output:
(lldb) e crazy<int> error: use of undeclared identifier 'crazy' error: expected '(' for function-style cast or type construction error: expected expression
I'm abandoning this revision based on some internal feedback. Thanks for the review @JDevlieghere and @jingham!
Why not use Name.str() directly?