[Lldb-commits] [PATCH] D138315: [lldb] Introduce dwim-print command

2022-11-28 Thread Pavel Labath via Phabricator via lldb-commits
labath accepted this revision.
labath added inline comments.
This revision is now accepted and ready to land.



Comment at: lldb/source/Commands/CommandObjectDWIMPrint.cpp:65
+Target *target_ptr = exe_ctx.GetTargetPtr();
+Target &target = target_ptr ? *target_ptr : GetDummyTarget();
+

I don't think this will work with a dummy target if you specify 
`eCommandRequiresProcess`.



Comment at: lldb/source/Commands/CommandObjectDWIMPrint.cpp:71
+  if (verbosity != eDWIMPrintVerbosityNone)
+result.AppendMessageWithFormatv("note: ran `expression {0}`", expr);
+  valobj_sp->Dump(result.GetOutputStream());

If the expectation is that the users should be able to paste this command, then 
we'd better add a `--` here. Otherwise expressions like `-foo` will not work as 
they will be confused for options.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138315/new/

https://reviews.llvm.org/D138315

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D138176: [dsymutil] Fix assertion: (Ref > InputDIE.getOffset()), function cloneDieReferenceAttribute

2022-11-28 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added a comment.

In D138176#3937163 , @avl wrote:

> That might be an error if referenced DIE is not cloned.

@friss and I were starting to wonder the same thing. I was out last week 
because of Thanksgiving but I'll dig into this a bit more this week.

In D138176#3939686 , @avl wrote:

> @JDevlieghere Is this assertion happened in single thread mode only, or 
> multi-thread mode only, or both?

This is happening in dsymutil which runs in "lockstep mode" where analyze and 
clone happen sequentially per CU (but we start analyzing the next CU while 
we're cloning the previous one). It definitely sounds like that could have 
something to do with it.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138176/new/

https://reviews.llvm.org/D138176

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D138612: [lldb][NFC] Change FindDefinitionTypeForDWARFDeclContext() to take DWARFDIE

2022-11-28 Thread Arthur Eubanks via Phabricator via lldb-commits
aeubanks updated this revision to Diff 478272.
aeubanks added a comment.

potential test fix


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138612/new/

https://reviews.llvm.org/D138612

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h
  lldb/test/API/lang/cpp/accelerator-table/TestCPPAccelerator.py
  lldb/test/API/lang/cpp/accelerator-table/a.cpp
  lldb/test/API/lang/cpp/accelerator-table/b.cpp
  lldb/test/API/lang/cpp/accelerator-table/c.cpp
  lldb/test/API/lang/cpp/accelerator-table/d.cpp
  lldb/test/API/lang/cpp/accelerator-table/e.cpp
  lldb/test/API/lang/cpp/accelerator-table/f.cpp
  lldb/test/API/lang/cpp/accelerator-table/g.cpp
  lldb/test/API/lang/cpp/accelerator-table/main.cpp

Index: lldb/test/API/lang/cpp/accelerator-table/main.cpp
===
--- lldb/test/API/lang/cpp/accelerator-table/main.cpp
+++ lldb/test/API/lang/cpp/accelerator-table/main.cpp
@@ -6,23 +6,23 @@
   };\
 NAME::Inner &getInner##NAME();
 
-CLASS(A)
-CLASS(B)
-CLASS(C)
-CLASS(D)
-CLASS(E)
-CLASS(F)
-CLASS(G)
+CLASS(AFoo)
+CLASS(BFoo)
+CLASS(CFoo)
+CLASS(DFoo)
+CLASS(EFoo)
+CLASS(FFoo)
+CLASS(GFoo)
 
 int main()
 {
-  A::Inner &inner_a = getInnerA();
-  B::Inner &inner_b = getInnerB();
-  C::Inner &inner_c = getInnerC();
-  D::Inner &inner_d = getInnerD();
-  E::Inner &inner_e = getInnerE();
-  F::Inner &inner_f = getInnerF();
-  G::Inner &inner_g = getInnerG();
+  AFoo::Inner &inner_a = getInnerAFoo();
+  BFoo::Inner &inner_b = getInnerBFoo();
+  CFoo::Inner &inner_c = getInnerCFoo();
+  DFoo::Inner &inner_d = getInnerDFoo();
+  EFoo::Inner &inner_e = getInnerEFoo();
+  FFoo::Inner &inner_f = getInnerFFoo();
+  GFoo::Inner &inner_g = getInnerGFoo();
 
   return 0; // break here
 }
Index: lldb/test/API/lang/cpp/accelerator-table/g.cpp
===
--- lldb/test/API/lang/cpp/accelerator-table/g.cpp
+++ lldb/test/API/lang/cpp/accelerator-table/g.cpp
@@ -1,2 +1,2 @@
 #include "source.h"
-CLASS(G)
+CLASS(GFoo)
Index: lldb/test/API/lang/cpp/accelerator-table/f.cpp
===
--- lldb/test/API/lang/cpp/accelerator-table/f.cpp
+++ lldb/test/API/lang/cpp/accelerator-table/f.cpp
@@ -1,2 +1,2 @@
 #include "source.h"
-CLASS(F)
+CLASS(FFoo)
Index: lldb/test/API/lang/cpp/accelerator-table/e.cpp
===
--- lldb/test/API/lang/cpp/accelerator-table/e.cpp
+++ lldb/test/API/lang/cpp/accelerator-table/e.cpp
@@ -1,2 +1,2 @@
 #include "source.h"
-CLASS(E)
+CLASS(EFoo)
Index: lldb/test/API/lang/cpp/accelerator-table/d.cpp
===
--- lldb/test/API/lang/cpp/accelerator-table/d.cpp
+++ lldb/test/API/lang/cpp/accelerator-table/d.cpp
@@ -1,2 +1,2 @@
 #include "source.h"
-CLASS(D)
+CLASS(DFoo)
Index: lldb/test/API/lang/cpp/accelerator-table/c.cpp
===
--- lldb/test/API/lang/cpp/accelerator-table/c.cpp
+++ lldb/test/API/lang/cpp/accelerator-table/c.cpp
@@ -1,2 +1,2 @@
 #include "source.h"
-CLASS(C)
+CLASS(CFoo)
Index: lldb/test/API/lang/cpp/accelerator-table/b.cpp
===
--- lldb/test/API/lang/cpp/accelerator-table/b.cpp
+++ lldb/test/API/lang/cpp/accelerator-table/b.cpp
@@ -1,2 +1,2 @@
 #include "source.h"
-CLASS(B)
+CLASS(BFoo)
Index: lldb/test/API/lang/cpp/accelerator-table/a.cpp
===
--- lldb/test/API/lang/cpp/accelerator-table/a.cpp
+++ lldb/test/API/lang/cpp/accelerator-table/a.cpp
@@ -1,2 +1,2 @@
 #include "source.h"
-CLASS(A)
+CLASS(AFoo)
Index: lldb/test/API/lang/cpp/accelerator-table/TestCPPAccelerator.py
===
--- lldb/test/API/lang/cpp/accelerator-table/TestCPPAccelerator.py
+++ lldb/test/API/lang/cpp/accelerator-table/TestCPPAccelerator.py
@@ -25,8 +25,8 @@
 log = f.readlines()
 n = 0
 for line in log:
-if re.findall(r'[abcdefg]\.o: FindByNameAndTag\(\)', line):
-self.assertIn("d.o", line)
+if re.findall(r'[ABCDEFG]Foo: FindByNameAndTag\(\)', line):
+self.assertIn("DFoo", line)
 n += 1
 
 self.assertEqual(n, 1, "".join(log))
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFile

[Lldb-commits] [PATCH] D138612: [lldb] Change FindDefinitionTypeForDWARFDeclContext() to take DWARFDIE

2022-11-28 Thread Arthur Eubanks via Phabricator via lldb-commits
aeubanks added a comment.

@jasonmolenda could you run check-lldb with this patch? I think this patch may 
fix the test by changing its expectations for logging.

(removed "NFC" from title because the logging changes actually mattered)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138612/new/

https://reviews.llvm.org/D138612

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D138834: [lldb] Fix simple template names interaction with debug info declarations

2022-11-28 Thread Arthur Eubanks via Phabricator via lldb-commits
aeubanks created this revision.
Herald added a reviewer: shafik.
Herald added a project: All.
aeubanks requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Without checking template parameters, we would sometimes lookup the
wrong type definition for a type declaration because different
instantiations of the same template class had the same debug info name.

The added GetForwardDeclarationDIETemplateParams() shouldn't need a
cache because we'll cache the results of the declaration -> definition
lookup anyway. (DWARFASTParserClang::ParseStructureLikeDIE()
is_forward_declaration branch)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138834

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/test/API/lang/cpp/unique-types3/Makefile
  lldb/test/API/lang/cpp/unique-types3/TestUniqueTypes3.py
  lldb/test/API/lang/cpp/unique-types3/a.cpp
  lldb/test/API/lang/cpp/unique-types3/main.cpp

Index: lldb/test/API/lang/cpp/unique-types3/main.cpp
===
--- /dev/null
+++ lldb/test/API/lang/cpp/unique-types3/main.cpp
@@ -0,0 +1,14 @@
+#include 
+#include 
+
+std::atomic a1;
+std::atomic a2;
+std::atomic a3;
+
+std::vector v1;
+std::vector v2;
+std::vector v3;
+
+void f(std::atomic &, std::vector &);
+
+int main() { f(a2, v2); }
Index: lldb/test/API/lang/cpp/unique-types3/a.cpp
===
--- /dev/null
+++ lldb/test/API/lang/cpp/unique-types3/a.cpp
@@ -0,0 +1,6 @@
+#include 
+#include 
+
+void f(std::atomic &a, std::vector &v) {
+  (void)a; // Set breakpoint here
+}
Index: lldb/test/API/lang/cpp/unique-types3/TestUniqueTypes3.py
===
--- /dev/null
+++ lldb/test/API/lang/cpp/unique-types3/TestUniqueTypes3.py
@@ -0,0 +1,28 @@
+"""
+Test that we return only the requested template instantiation.
+"""
+
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+
+class UniqueTypesTestCase3(TestBase):
+def do_test(self, debug_flags):
+"""Test that we display the correct template instantiation."""
+self.build(dictionary=debug_flags)
+lldbutil.run_to_source_breakpoint(self, "// Set breakpoint here", lldb.SBFileSpec("a.cpp"))
+self.assertIn("int", self.frame().GetValueForVariablePath("a").GetDisplayTypeName())
+self.assertIn("int", self.frame().GetValueForVariablePath("v").GetDisplayTypeName())
+
+@skipIf(compiler=no_match("clang"))
+@skipIf(compiler_version=["<", "15.0"])
+def test_simple_template_names(self):
+# Can't directly set CFLAGS_EXTRAS here because the Makefile can't
+# override an environment variable.
+self.do_test(dict(TEST_CFLAGS_EXTRAS="-gsimple-template-names"))
+
+@skipIf(compiler=no_match("clang"))
+@skipIf(compiler_version=["<", "15.0"])
+def test_no_simple_template_names(self):
+self.do_test(dict(CFLAGS_EXTRAS="-gno-simple-template-names"))
Index: lldb/test/API/lang/cpp/unique-types3/Makefile
===
--- /dev/null
+++ lldb/test/API/lang/cpp/unique-types3/Makefile
@@ -0,0 +1,5 @@
+CXX_SOURCES := main.cpp a.cpp
+
+CFLAGS_EXTRAS = $(TEST_CFLAGS_EXTRAS) $(LIMIT_DEBUG_INFO_FLAGS)
+
+include Makefile.rules
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -2979,6 +2979,16 @@
   }
 }
 
+// See comments below about -gsimple-template-names for why we attempt to
+// compute missing template parameter names.
+ConstString template_params;
+if (type_system && !type_name.GetStringRef().contains('<')) {
+  DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
+  if (dwarf_ast)
+template_params =
+dwarf_ast->GetForwardDeclarationDIETemplateParams(die);
+}
+
 m_index->GetTypes(type_name, [&](DWARFDIE type_die) {
   // Make sure type_die's language matches the type system we are
   // looking for. We don't want to find a "Foo" type from Java if we
@@ -3050,6 +3060,25 @@
   if (!resolved_type || resolved_type == DIE_IS_BEING_PARSED)
 return true;
 
+  // With -gsimple-template-names, the DIE name may not contain the template
+  // parameters. If we've the declaration has template parameters but
+  // doesn't contain '<', check that the child template parameters match.
+  if (template_params) {
+llvm::StringRef test_base_name =
+   

[Lldb-commits] [PATCH] D138834: [lldb] Fix simple template names interaction with debug info declarations

2022-11-28 Thread Arthur Eubanks via Phabricator via lldb-commits
aeubanks added a comment.

depends on D132624 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138834/new/

https://reviews.llvm.org/D138834

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D138834: [lldb] Fix simple template names interaction with debug info declarations

2022-11-28 Thread David Blaikie via Phabricator via lldb-commits
dblaikie added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:747-749
+  if (ParseTemplateParameterInfos(die, template_param_infos) &&
+  (!template_param_infos.args.empty() ||
+   template_param_infos.packed_args)) {

Could invert this condition and use an early `return ConstString();` to reduce 
indentation - but I guess this looks more similar to the definition handling 
case and so might be worth keeping in the same shape. (maybe 
`ParseTemplateParameterInfos` should return true only if the result is !empty 
or has packed args, so that test doesn't need to be repeated at multiple 
callers?)



Comment at: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp:3069-3079
+if (auto i = test_base_name.find('<'); i != llvm::StringRef::npos) {
+  llvm::StringRef test_template_params =
+  test_base_name.slice(i, test_base_name.size());
+  // Bail if template parameters don't match.
+  if (test_template_params != template_params.GetStringRef())
+return true;
+} else {

might be worth flipping to reduce indentation:
```
auto i = test_base_name.find('<');
if (i == llvm::StringRef::npos)
  return true;
llvm::StringRef test_template_params = ...
if (test_template_params != template_params.GetStringRef())
  return true;
```



Comment at: lldb/test/API/lang/cpp/unique-types3/main.cpp:1-14
+#include 
+#include 
+
+std::atomic a1;
+std::atomic a2;
+std::atomic a3;
+

maybe good to simplify this a bit - rather than using big/complex templates 
like std::atomic and std::vector, instead using test-only, simpler templates to 
keep the test a bit more focussed (less likely to fail for unrelated 
reasons/other regressions)?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138834/new/

https://reviews.llvm.org/D138834

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D138850: [test] Implement layout for unstable std::string garbage formatter tests.

2022-11-28 Thread Jordan Rupprecht via Phabricator via lldb-commits
rupprecht created this revision.
rupprecht added a reviewer: labath.
Herald added a project: All.
rupprecht requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

The layout is essentially just reversed from the stable std::string layout.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138850

Files:
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/main.cpp

Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/main.cpp
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/main.cpp
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/main.cpp
@@ -7,12 +7,19 @@
 
 // A corrupt string which hits the SSO code path, but has an invalid size.
 static struct {
+#if _LIBCPP_ABI_VERSION == 1
   // Set the size of this short-mode string to 116. Note that in short mode,
   // the size is encoded as `size << 1`.
   unsigned char size = 232;
 
   // 23 garbage bytes for the inline string payload.
   char inline_buf[23] = {0};
+#else  // _LIBCPP_ABI_VERSION == 1
+  // Like above, but data comes first, and use bitfields to indicate size.
+  char inline_buf[23] = {0};
+  unsigned char size : 7 = 116;
+  unsigned char is_long : 1 = 0;
+#endif // #if _LIBCPP_ABI_VERSION == 1
 } garbage_string_short_mode;
 
 // A corrupt libcxx string in long mode with a payload that contains a utf8
@@ -23,9 +30,16 @@
   250, 250, 250
 };
 static struct {
+#if _LIBCPP_ABI_VERSION == 1
   uint64_t cap = 5;
   uint64_t size = 4;
   unsigned char *data = &garbage_utf8_payload1[0];
+#else  // _LIBCPP_ABI_VERSION == 1
+  unsigned char *data = &garbage_utf8_payload1[0];
+  uint64_t size = 4;
+  uint64_t cap : 63 = 4;
+  uint64_t is_long : 1 = 1;
+#endif // #if _LIBCPP_ABI_VERSION == 1
 } garbage_string_long_mode1;
 
 // A corrupt libcxx string in long mode with a payload that contains a utf8
@@ -36,25 +50,46 @@
   240
 };
 static struct {
+#if _LIBCPP_ABI_VERSION == 1
   uint64_t cap = 3;
   uint64_t size = 2;
   unsigned char *data = &garbage_utf8_payload2[0];
+#else  // _LIBCPP_ABI_VERSION == 1
+  unsigned char *data = &garbage_utf8_payload2[0];
+  uint64_t size = 2;
+  uint64_t cap : 63 = 3;
+  uint64_t is_long : 1 = 1;
+#endif // #if _LIBCPP_ABI_VERSION == 1
 } garbage_string_long_mode2;
 
 // A corrupt libcxx string which has an invalid size (i.e. a size greater than
 // the capacity of the string).
 static struct {
+#if _LIBCPP_ABI_VERSION == 1
   uint64_t cap = 5;
   uint64_t size = 7;
   const char *data = "foo";
+#else  // _LIBCPP_ABI_VERSION == 1
+  const char *data = "foo";
+  uint64_t size = 7;
+  uint64_t cap : 63 = 5;
+  uint64_t is_long : 1 = 1;
+#endif // #if _LIBCPP_ABI_VERSION == 1
 } garbage_string_long_mode3;
 
 // A corrupt libcxx string in long mode with a payload that would trigger a
 // buffer overflow.
 static struct {
+#if _LIBCPP_ABI_VERSION == 1
   uint64_t cap = 5;
   uint64_t size = 2;
   uint64_t data = 0xfffeULL;
+#else  // _LIBCPP_ABI_VERSION == 1
+  uint64_t data = 0xfffeULL;
+  uint64_t size = 2;
+  uint64_t cap : 63 = 5;
+  uint64_t is_long : 1 = 1;
+#endif // #if _LIBCPP_ABI_VERSION == 1
 } garbage_string_long_mode4;
 
 size_t touch_string(std::string &in_str)
@@ -81,7 +116,6 @@
 std::basic_string uchar(5, 'a');
 std::string *null_str = nullptr;
 
-#if _LIBCPP_ABI_VERSION == 1
 std::string garbage1, garbage2, garbage3, garbage4, garbage5;
 if (sizeof(std::string) == sizeof(garbage_string_short_mode))
   memcpy((void *)&garbage1, &garbage_string_short_mode, sizeof(std::string));
@@ -93,9 +127,6 @@
   memcpy((void *)&garbage4, &garbage_string_long_mode3, sizeof(std::string));
 if (sizeof(std::string) == sizeof(garbage_string_long_mode4))
   memcpy((void *)&garbage5, &garbage_string_long_mode4, sizeof(std::string));
-#else
-#error "Test potentially needs to be updated for a new std::string ABI."
-#endif
 
 S.assign(L"!"); // Set break point at this line.
 std::string *not_a_string = (std::string *) 0x0;
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D138834: [lldb] Fix simple template names interaction with debug info declarations

2022-11-28 Thread Arthur Eubanks via Phabricator via lldb-commits
aeubanks updated this revision to Diff 478323.
aeubanks marked an inline comment as done.
aeubanks added a comment.

don't use stl in test
simplify some code a bit


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138834/new/

https://reviews.llvm.org/D138834

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/test/API/lang/cpp/unique-types3/Makefile
  lldb/test/API/lang/cpp/unique-types3/TestUniqueTypes3.py
  lldb/test/API/lang/cpp/unique-types3/a.cpp
  lldb/test/API/lang/cpp/unique-types3/a.h
  lldb/test/API/lang/cpp/unique-types3/main.cpp

Index: lldb/test/API/lang/cpp/unique-types3/main.cpp
===
--- /dev/null
+++ lldb/test/API/lang/cpp/unique-types3/main.cpp
@@ -0,0 +1,9 @@
+#include "a.h"
+
+S a1;
+S a2;
+S a3;
+
+void f(S &);
+
+int main() { f(a2); }
Index: lldb/test/API/lang/cpp/unique-types3/a.h
===
--- /dev/null
+++ lldb/test/API/lang/cpp/unique-types3/a.h
@@ -0,0 +1,3 @@
+template  struct S {
+  T t;
+};
Index: lldb/test/API/lang/cpp/unique-types3/a.cpp
===
--- /dev/null
+++ lldb/test/API/lang/cpp/unique-types3/a.cpp
@@ -0,0 +1,5 @@
+#include "a.h"
+
+void f(S &a) {
+  (void)a; // Set breakpoint here
+}
Index: lldb/test/API/lang/cpp/unique-types3/TestUniqueTypes3.py
===
--- /dev/null
+++ lldb/test/API/lang/cpp/unique-types3/TestUniqueTypes3.py
@@ -0,0 +1,27 @@
+"""
+Test that we return only the requested template instantiation.
+"""
+
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+
+class UniqueTypesTestCase3(TestBase):
+def do_test(self, debug_flags):
+"""Test that we display the correct template instantiation."""
+self.build(dictionary=debug_flags)
+lldbutil.run_to_source_breakpoint(self, "// Set breakpoint here", lldb.SBFileSpec("a.cpp"))
+self.expect_expr("a", result_type="S")
+
+@skipIf(compiler=no_match("clang"))
+@skipIf(compiler_version=["<", "15.0"])
+def test_simple_template_names(self):
+# Can't directly set CFLAGS_EXTRAS here because the Makefile can't
+# override an environment variable.
+self.do_test(dict(TEST_CFLAGS_EXTRAS="-gsimple-template-names"))
+
+@skipIf(compiler=no_match("clang"))
+@skipIf(compiler_version=["<", "15.0"])
+def test_no_simple_template_names(self):
+self.do_test(dict(CFLAGS_EXTRAS="-gno-simple-template-names"))
Index: lldb/test/API/lang/cpp/unique-types3/Makefile
===
--- /dev/null
+++ lldb/test/API/lang/cpp/unique-types3/Makefile
@@ -0,0 +1,5 @@
+CXX_SOURCES := main.cpp a.cpp
+
+CFLAGS_EXTRAS = $(TEST_CFLAGS_EXTRAS) $(LIMIT_DEBUG_INFO_FLAGS)
+
+include Makefile.rules
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -2979,6 +2979,16 @@
   }
 }
 
+// See comments below about -gsimple-template-names for why we attempt to
+// compute missing template parameter names.
+ConstString template_params;
+if (type_system && !type_name.GetStringRef().contains('<')) {
+  DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
+  if (dwarf_ast)
+template_params =
+dwarf_ast->GetForwardDeclarationDIETemplateParams(die);
+}
+
 m_index->GetTypes(type_name, [&](DWARFDIE type_die) {
   // Make sure type_die's language matches the type system we are
   // looking for. We don't want to find a "Foo" type from Java if we
@@ -3050,6 +3060,27 @@
   if (!resolved_type || resolved_type == DIE_IS_BEING_PARSED)
 return true;
 
+  // With -gsimple-template-names, the DIE name may not contain the template
+  // parameters. If we've the declaration has template parameters but
+  // doesn't contain '<', check that the child template parameters match.
+  if (template_params) {
+llvm::StringRef test_base_name =
+GetTypeForDIE(type_die)->GetBaseName().GetStringRef();
+auto i = test_base_name.find('<');
+
+// Full name from clang AST doesn't contain '<' so this type_die isn't
+// a template parameter, but we're expecting template parameters, so
+// bail.
+if (i == llvm::StringRef::npos)
+  return true;
+
+llvm::StringRef test_template_params =
+test_base_name.slice(i, test_ba

[Lldb-commits] [PATCH] D138834: [lldb] Fix simple template names interaction with debug info declarations

2022-11-28 Thread Arthur Eubanks via Phabricator via lldb-commits
aeubanks added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:747-749
+  if (ParseTemplateParameterInfos(die, template_param_infos) &&
+  (!template_param_infos.args.empty() ||
+   template_param_infos.packed_args)) {

dblaikie wrote:
> Could invert this condition and use an early `return ConstString();` to 
> reduce indentation - but I guess this looks more similar to the definition 
> handling case and so might be worth keeping in the same shape. (maybe 
> `ParseTemplateParameterInfos` should return true only if the result is !empty 
> or has packed args, so that test doesn't need to be repeated at multiple 
> callers?)
I'll clean this up after this patch lands



Comment at: lldb/test/API/lang/cpp/unique-types3/main.cpp:1-14
+#include 
+#include 
+
+std::atomic a1;
+std::atomic a2;
+std::atomic a3;
+

dblaikie wrote:
> maybe good to simplify this a bit - rather than using big/complex templates 
> like std::atomic and std::vector, instead using test-only, simpler templates 
> to keep the test a bit more focussed (less likely to fail for unrelated 
> reasons/other regressions)?
hmm I swear I tried that and it ended up passing, although that might have been 
before I figured out the Makefile env var vs normal var issue. done


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138834/new/

https://reviews.llvm.org/D138834

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D138430: [lldb/test] Use SBPlatform info for lldbplatformutil.getPlatform()

2022-11-28 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138430/new/

https://reviews.llvm.org/D138430

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D138878: [lldb] Remove timer from Module::GetNumCompileUnits

2022-11-28 Thread Dave Lee via Phabricator via lldb-commits
kastiglione created this revision.
kastiglione added reviewers: JDevlieghere, augusto2112.
Herald added a project: All.
kastiglione requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

`GetNumCompileUnits` has fast execution, and is high firing. Fast and frequent 
functions are not good candidates for timers. In a recent profile, 
`GetNumCompileUnits` was called >>10k times with an average duration of 1 
microsecond.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138878

Files:
  lldb/source/Core/Module.cpp


Index: lldb/source/Core/Module.cpp
===
--- lldb/source/Core/Module.cpp
+++ lldb/source/Core/Module.cpp
@@ -419,8 +419,6 @@
 
 size_t Module::GetNumCompileUnits() {
   std::lock_guard guard(m_mutex);
-  LLDB_SCOPED_TIMERF("Module::GetNumCompileUnits (module = %p)",
- static_cast(this));
   if (SymbolFile *symbols = GetSymbolFile())
 return symbols->GetNumCompileUnits();
   return 0;


Index: lldb/source/Core/Module.cpp
===
--- lldb/source/Core/Module.cpp
+++ lldb/source/Core/Module.cpp
@@ -419,8 +419,6 @@
 
 size_t Module::GetNumCompileUnits() {
   std::lock_guard guard(m_mutex);
-  LLDB_SCOPED_TIMERF("Module::GetNumCompileUnits (module = %p)",
- static_cast(this));
   if (SymbolFile *symbols = GetSymbolFile())
 return symbols->GetNumCompileUnits();
   return 0;
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D138879: [lldb] Make SWIG an autodetected depenency

2022-11-28 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere created this revision.
JDevlieghere added reviewers: bulbazord, mib, labath.
Herald added a project: All.
JDevlieghere requested review of this revision.

This patch makes SWIG itself an autodetected dependency. This allows us to look 
for SWIG once in a centralized place and makes it easier downstream to detect 
whether to use the static bindings: 
https://github.com/apple/llvm-project/pull/5636


https://reviews.llvm.org/D138879

Files:
  lldb/cmake/modules/FindLuaAndSwig.cmake
  lldb/cmake/modules/FindPythonAndSwig.cmake
  lldb/cmake/modules/LLDBConfig.cmake


Index: lldb/cmake/modules/LLDBConfig.cmake
===
--- lldb/cmake/modules/LLDBConfig.cmake
+++ lldb/cmake/modules/LLDBConfig.cmake
@@ -56,6 +56,7 @@
   message(STATUS "${description}: ${${variable}}")
 endmacro()
 
+add_optional_dependency(LLDB_ENABLE_SWIG "Enable SWIG to generate LLDB 
bindings" SWIG SWIG_FOUND VERSION 3)
 add_optional_dependency(LLDB_ENABLE_LIBEDIT "Enable editline support in LLDB" 
LibEdit LibEdit_FOUND)
 add_optional_dependency(LLDB_ENABLE_CURSES "Enable curses support in LLDB" 
CursesAndPanel CURSESANDPANEL_FOUND)
 add_optional_dependency(LLDB_ENABLE_LZMA "Enable LZMA compression support in 
LLDB" LibLZMA LIBLZMA_FOUND)
Index: lldb/cmake/modules/FindPythonAndSwig.cmake
===
--- lldb/cmake/modules/FindPythonAndSwig.cmake
+++ lldb/cmake/modules/FindPythonAndSwig.cmake
@@ -38,9 +38,8 @@
 if(Python3_LIBRARIES AND Python3_INCLUDE_DIRS AND Python3_EXECUTABLE AND 
SWIG_EXECUTABLE)
   set(PYTHONANDSWIG_FOUND TRUE)
 else()
-  find_package(SWIG 3.0)
-  if (SWIG_FOUND)
-  FindPython3()
+  if (LLDB_ENABLE_SWIG)
+FindPython3()
   else()
 message(STATUS "SWIG 3 or later is required for Python support in LLDB but 
could not be found")
   endif()
@@ -64,5 +63,5 @@
   Python3_LIBRARIES
   Python3_INCLUDE_DIRS
   Python3_EXECUTABLE
-  SWIG_EXECUTABLE)
+  LLDB_ENABLE_SWIG)
 endif()
Index: lldb/cmake/modules/FindLuaAndSwig.cmake
===
--- lldb/cmake/modules/FindLuaAndSwig.cmake
+++ lldb/cmake/modules/FindLuaAndSwig.cmake
@@ -7,8 +7,7 @@
 if(LUA_LIBRARIES AND LUA_INCLUDE_DIR AND SWIG_EXECUTABLE)
   set(LUAANDSWIG_FOUND TRUE)
 else()
-  find_package(SWIG 3.0)
-  if (SWIG_FOUND)
+  if (LLDB_ENABLE_SWIG)
 find_package(Lua 5.3 EXACT)
 if(LUA_FOUND AND SWIG_FOUND)
   mark_as_advanced(
@@ -20,6 +19,7 @@
 message(STATUS "SWIG 3 or later is required for Lua support in LLDB but 
could not be found")
   endif()
 
+
   include(FindPackageHandleStandardArgs)
   find_package_handle_standard_args(LuaAndSwig
 FOUND_VAR
@@ -27,5 +27,5 @@
 REQUIRED_VARS
   LUA_LIBRARIES
   LUA_INCLUDE_DIR
-  SWIG_EXECUTABLE)
+  LLDB_ENABLE_SWIG)
 endif()


Index: lldb/cmake/modules/LLDBConfig.cmake
===
--- lldb/cmake/modules/LLDBConfig.cmake
+++ lldb/cmake/modules/LLDBConfig.cmake
@@ -56,6 +56,7 @@
   message(STATUS "${description}: ${${variable}}")
 endmacro()
 
+add_optional_dependency(LLDB_ENABLE_SWIG "Enable SWIG to generate LLDB bindings" SWIG SWIG_FOUND VERSION 3)
 add_optional_dependency(LLDB_ENABLE_LIBEDIT "Enable editline support in LLDB" LibEdit LibEdit_FOUND)
 add_optional_dependency(LLDB_ENABLE_CURSES "Enable curses support in LLDB" CursesAndPanel CURSESANDPANEL_FOUND)
 add_optional_dependency(LLDB_ENABLE_LZMA "Enable LZMA compression support in LLDB" LibLZMA LIBLZMA_FOUND)
Index: lldb/cmake/modules/FindPythonAndSwig.cmake
===
--- lldb/cmake/modules/FindPythonAndSwig.cmake
+++ lldb/cmake/modules/FindPythonAndSwig.cmake
@@ -38,9 +38,8 @@
 if(Python3_LIBRARIES AND Python3_INCLUDE_DIRS AND Python3_EXECUTABLE AND SWIG_EXECUTABLE)
   set(PYTHONANDSWIG_FOUND TRUE)
 else()
-  find_package(SWIG 3.0)
-  if (SWIG_FOUND)
-  FindPython3()
+  if (LLDB_ENABLE_SWIG)
+FindPython3()
   else()
 message(STATUS "SWIG 3 or later is required for Python support in LLDB but could not be found")
   endif()
@@ -64,5 +63,5 @@
   Python3_LIBRARIES
   Python3_INCLUDE_DIRS
   Python3_EXECUTABLE
-  SWIG_EXECUTABLE)
+  LLDB_ENABLE_SWIG)
 endif()
Index: lldb/cmake/modules/FindLuaAndSwig.cmake
===
--- lldb/cmake/mo

[Lldb-commits] [PATCH] D138315: [lldb] Introduce dwim-print command

2022-11-28 Thread Dave Lee via Phabricator via lldb-commits
kastiglione updated this revision to Diff 478419.
kastiglione added a comment.

Address @labath's feedback


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138315/new/

https://reviews.llvm.org/D138315

Files:
  lldb/include/lldb/Core/Debugger.h
  lldb/include/lldb/lldb-enumerations.h
  lldb/source/Commands/CMakeLists.txt
  lldb/source/Commands/CommandObjectDWIMPrint.cpp
  lldb/source/Commands/CommandObjectDWIMPrint.h
  lldb/source/Core/CoreProperties.td
  lldb/source/Core/Debugger.cpp
  lldb/source/Interpreter/CommandInterpreter.cpp
  lldb/test/API/commands/dwim-print/Makefile
  lldb/test/API/commands/dwim-print/TestDWIMPrint.py
  lldb/test/API/commands/dwim-print/main.c

Index: lldb/test/API/commands/dwim-print/main.c
===
--- /dev/null
+++ lldb/test/API/commands/dwim-print/main.c
@@ -0,0 +1,3 @@
+int main(int argc, char **argv) {
+  return 0;
+}
Index: lldb/test/API/commands/dwim-print/TestDWIMPrint.py
===
--- /dev/null
+++ lldb/test/API/commands/dwim-print/TestDWIMPrint.py
@@ -0,0 +1,68 @@
+"""
+Test dwim-print with variables, variable paths, and expressions.
+"""
+
+import re
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.decorators import *
+import lldbsuite.test.lldbutil as lldbutil
+
+
+class TestCase(TestBase):
+def setUp(self):
+TestBase.setUp(self)
+self.build()
+lldbutil.run_to_name_breakpoint(self, "main")
+
+def _run_cmd(self, cmd: str) -> str:
+"""Run the given lldb command and return its output."""
+result = lldb.SBCommandReturnObject()
+self.ci.HandleCommand(cmd, result)
+return result.GetOutput().rstrip()
+
+PERSISTENT_VAR = re.compile(r"\$\d+")
+
+def _mask_persistent_var(self, string: str) -> str:
+"""
+Replace persistent result variables (ex '$0', '$1', etc) with a regex
+that matches any persistent result (r'\$\d+'). The returned string can
+be matched against other `expression` results.
+"""
+before, after = self.PERSISTENT_VAR.split(string, maxsplit=1)
+return re.escape(before) + r"\$\d+" + re.escape(after)
+
+def _expect_cmd(self, expr: str, base_cmd: str) -> None:
+"""Run dwim-print and verify the output against the expected command."""
+cmd = f"{base_cmd} {expr}"
+cmd_output = self._run_cmd(cmd)
+
+# Verify dwim-print chose the expected command.
+self.runCmd("settings set dwim-print-verbosity full")
+substrs = [f"note: ran `{cmd}`"]
+patterns = []
+
+if base_cmd == "expression --" and self.PERSISTENT_VAR.search(cmd_output):
+patterns.append(self._mask_persistent_var(cmd_output))
+else:
+substrs.append(cmd_output)
+
+self.expect(f"dwim-print {expr}", substrs=substrs, patterns=patterns)
+
+def test_variables(self):
+"""Test dwim-print with variables."""
+vars = ("argc", "argv")
+for var in vars:
+self._expect_cmd(var, "frame variable")
+
+def test_variable_paths(self):
+"""Test dwim-print with variable path expressions."""
+exprs = ("&argc", "*argv", "argv[0]")
+for expr in exprs:
+self._expect_cmd(expr, "expression --")
+
+def test_expressions(self):
+"""Test dwim-print with expressions."""
+exprs = ("argc + 1", "(void)argc", "(int)abs(argc)")
+for expr in exprs:
+self._expect_cmd(expr, "expression --")
Index: lldb/test/API/commands/dwim-print/Makefile
===
--- /dev/null
+++ lldb/test/API/commands/dwim-print/Makefile
@@ -0,0 +1,3 @@
+C_SOURCES := main.c
+
+include Makefile.rules
Index: lldb/source/Interpreter/CommandInterpreter.cpp
===
--- lldb/source/Interpreter/CommandInterpreter.cpp
+++ lldb/source/Interpreter/CommandInterpreter.cpp
@@ -15,6 +15,7 @@
 #include "Commands/CommandObjectApropos.h"
 #include "Commands/CommandObjectBreakpoint.h"
 #include "Commands/CommandObjectCommands.h"
+#include "Commands/CommandObjectDWIMPrint.h"
 #include "Commands/CommandObjectDiagnostics.h"
 #include "Commands/CommandObjectDisassemble.h"
 #include "Commands/CommandObjectExpression.h"
@@ -532,6 +533,7 @@
   REGISTER_COMMAND_OBJECT("command", CommandObjectMultiwordCommands);
   REGISTER_COMMAND_OBJECT("diagnostics", CommandObjectDiagnostics);
   REGISTER_COMMAND_OBJECT("disassemble", CommandObjectDisassemble);
+  REGISTER_COMMAND_OBJECT("dwim-print", CommandObjectDWIMPrint);
   REGISTER_COMMAND_OBJECT("expression", CommandObjectExpression);
   REGISTER_COMMAND_OBJECT("frame", CommandObjectMultiwordFrame);
   REGISTER_COMMAND_OBJECT("gui", CommandObjectGUI);
Index: lldb/source/Core/Debugger.cpp

[Lldb-commits] [PATCH] D138310: [NFC] Make headers self-contained.

2022-11-28 Thread Fangrui Song via Phabricator via lldb-commits
MaskRay accepted this revision.
MaskRay added inline comments.
This revision is now accepted and ready to land.
Herald added a subscriber: StephenFan.



Comment at: lldb/source/Plugins/Instruction/RISCV/RISCVInstructions.h:15
 
-#include "EmulateInstructionRISCV.h"
 #include "llvm/ADT/Optional.h"

I assume that this is correct, even after considering IWYU. Perhaps worth a 
double check.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138310/new/

https://reviews.llvm.org/D138310

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D138892: [DataFormatter] Fix variant npos with `_LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION` enabled.

2022-11-28 Thread Jordan Rupprecht via Phabricator via lldb-commits
rupprecht created this revision.
rupprecht added reviewers: labath, Michael137, kastiglione.
Herald added a subscriber: arphaman.
Herald added a project: All.
rupprecht requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

This data formatter should print "No Value" if a variant is unset. It does so 
by checking if `__index` has a value of `-1`, however it does so by 
interpreting it as a signed int.

By default, `__index` has type `unsigned int`. When 
`_LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION` is enabled, the type of `__index` 
is either `unsigned char`, `unsigned short`, or `unsigned int`, depending on 
how many fields there are -- as small as possible. For example, when 
`std::variant` has only a few types, the index type is `unsigned char`, and the 
npos value will be interpreted by LLDB as `255` when it should be `-1`.

This change does not special case the variant optimization; it just reads the 
type instead of assuming it's `unsigned int`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138892

Files:
  lldb/source/Plugins/Language/CPlusPlus/LibCxxVariant.cpp
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/variant/TestDataFormatterLibcxxVariant.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/variant/main.cpp

Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/variant/main.cpp
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/variant/main.cpp
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/variant/main.cpp
@@ -29,6 +29,30 @@
 std::variant v3;
 std::variant> v_v1 ;
 std::variant v_no_value;
+std::variant<
+int, int, int, int, int, int, int, int, int, int, int, int, int, int,
+int, int, int, int, int, int, int, int, int, int, int, int, int, int,
+int, int, int, int, int, int, int, int, int, int, int, int, int, int,
+int, int, int, int, int, int, int, int, int, int, int, int, int, int,
+int, int, int, int, int, int, int, int, int, int, int, int, int, int,
+int, int, int, int, int, int, int, int, int, int, int, int, int, int,
+int, int, int, int, int, int, int, int, int, int, int, int, int, int,
+int, int, int, int, int, int, int, int, int, int, int, int, int, int,
+int, int, int, int, int, int, int, int, int, int, int, int, int, int,
+int, int, int, int, int, int, int, int, int, int, int, int, int, int,
+int, int, int, int, int, int, int, int, int, int, int, int, int, int,
+int, int, int, int, int, int, int, int, int, int, int, int, int, int,
+int, int, int, int, int, int, int, int, int, int, int, int, int, int,
+int, int, int, int, int, int, int, int, int, int, int, int, int, int,
+int, int, int, int, int, int, int, int, int, int, int, int, int, int,
+int, int, int, int, int, int, int, int, int, int, int, int, int, int,
+int, int, int, int, int, int, int, int, int, int, int, int, int, int,
+int, int, int, int, int, int, int, int, int, int, int, int, int, int,
+int, int, int, int, int, int, int, int, int, int, int, int, int, int,
+int, int, int, int, int, int, int, int, int, int, int, int, int, int,
+int, int, int, int, int, int, int, int, int, int, int, int, int, int,
+int, int, int, int, int, int>
+v_300_types_no_value;
 
 v1 = 12; // v contains int
 v_v1 = v1 ;
@@ -54,6 +78,13 @@
  } catch( ... ) {}
 
  printf( "%zu\n", v_no_value.index() ) ;
+
+ try {
+   v_300_types_no_value.emplace<0>(S());
+ } catch (...) {
+ }
+
+ printf("%zu\n", v_300_types_no_value.index());
 #endif
 
 return 0; // break here
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/variant/TestDataFormatterLibcxxVariant.py
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/variant/TestDataFormatterLibcxxVariant.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/variant/TestDataFormatterLibcxxVariant.py
@@ -76,3 +76,6 @@
 
 self.expect("frame variable v_no_value",
 substrs=['v_no_value =  No Value'])
+
+self.expect("frame variable v_300_types_no_value",
+substrs=['v_300_types_no_value =  No Value'])
Index: lldb/source/Plugins/Language/CPlusPlus/LibCxxVariant.cpp
===
--- lldb/source/Plugins/Language/CPlusPlus/LibCxxVariant.cpp
+++ lldb/source/Plugins/Language/CPlusPlus/LibCxxVariant.cpp
@@ -9,6 +9,8 @@
 #include "LibCxxVariant.h"
 #include "LibCxx.h"
 #include "lldb/DataFormatters/FormattersHelpers.h"
+#include "lldb/Symbol/CompilerType.h"
+#include "lldb/Utility/L