This is an archive of the discontinued LLVM Phabricator instance.

Add Parameters to DW_AT_name Attribute of Template Variables
AbandonedPublic

Authored by ormris on Mar 23 2018, 12:27 PM.

Details

Summary

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.

Diff Detail

Event Timeline

ormris created this revision.Mar 23 2018, 12:27 PM

CC'ing LLDB developers because I'm not sure if this could break symbol lookup.

Adding debug-info project tag.

JDevlieghere added inline comments.Mar 27 2018, 2:57 AM
lib/CodeGen/CGDebugInfo.cpp
2992

Why not use Name.str() directly?

ormris added inline comments.Mar 27 2018, 12:05 PM
lib/CodeGen/CGDebugInfo.cpp
2992

I got "error: invalid initialization of non-const reference ... from rvalue ...". Using NameString fixed the issue.

@jingham is this safe to land?

lib/CodeGen/CGDebugInfo.cpp
2992

Right, makes sense, you're using the string as the buffer :-)

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.

jingham added a comment.EditedApr 3 2018, 9:44 AM

@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.

ormris added a comment.EditedApr 3 2018, 10:09 AM

@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
ormris abandoned this revision.Apr 4 2018, 2:58 PM

I'm abandoning this revision based on some internal feedback. Thanks for the review @JDevlieghere and @jingham!