[Lldb-commits] [lldb] [lldb] Fix the semantics of SupportFile equivalence (PR #95606)

2024-06-19 Thread Pavel Labath via lldb-commits

labath wrote:

I think that `operator==` should represent the strictest possible way to 
compare two objects, and ideally mean "the two objects are interchangable". 
Interchangeability implies transitivity, and that doesn't hold here because an 
object with no checksum can match two other objects with different checksums, 
but those two objects won't match each other directly.

This can have implications for this bug as well. I don't know how we can end up 
in a different line table here, but if that can happen twice, and the middle 
line table has no checksum, then it can make a difference in whether you 
compare to the previous line table, or the initial/starting one. (I don't think 
this is likely to happen, I'm just using it to illustrate the point.)

With that in mind, I think `IsSameFile` is still slightly better than 
`operator==` (because it's harder to use it by accident, so you're more likely 
to look up the definition and see the comment next to it -- which hopefully 
explains the subtlety), but it still implies some form of interchangability. 
And fundamentally, I think it's not correct -- without the checksum (and maybe 
even with it) we can't definitively say whether the two objects describe the 
same file. (we may decide we're going to treat them as if they were, but I 
think that's something different)

Unfortunately, I don't know of a concise way to express this difference, maybe 
because the concept is not concise to begin with. `IsProbablySameFile`, 
`MayDescribeSameFile`, `PotentiallySameFile` ?

https://github.com/llvm/llvm-project/pull/95606
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [API] add GetSyntheticValue (PR #95959)

2024-06-19 Thread Pavel Labath via lldb-commits

labath wrote:

We should also add a test case for the new API. You can just take an existing 
test case with some synthetic values (e.g. `TestFormattersSBAPI.py`), add some 
Get(Non)SyntheticValue calls, and make sure they do what they should.

https://github.com/llvm/llvm-project/pull/95959
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][test] Support remote run of Shell tests (PR #95986)

2024-06-19 Thread Pavel Labath via lldb-commits

labath wrote:

Can't say I'm excited to see this feature (although I admit it is looking less 
daunting than I originally feared).  Can you explain why you need this feature? 
Is there some particular aspect of lldb's remote operation that you think isn't 
well covered by the existing tests? Is there a particular category of tests 
that you'd like to have more than other? How many of the existing tests would 
actually exercise the remote platform capability in a meaningful way (a lot of 
these tests don't even build runnable binaries)?

https://github.com/llvm/llvm-project/pull/95986
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Fix incorrect logical operator in 'if' condition check (NFC) (PR #94779)

2024-06-19 Thread Shivam Gupta via lldb-commits

https://github.com/xgupta updated 
https://github.com/llvm/llvm-project/pull/94779

>From b8a387d82ed90c98f6bc9c0c7f9bc9da0d8e4d18 Mon Sep 17 00:00:00 2001
From: Shivam Gupta 
Date: Fri, 7 Jun 2024 23:21:15 +0530
Subject: [PATCH 1/2] [LLDB][NFC] Fix a cppcheck warning in
 Python/Interfaces/ScriptedPythonInterface.h

Fix #89195
---
 .../Python/Interfaces/ScriptedPythonInterface.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
index 163659234466d..30811639c9a95 100644
--- 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
@@ -85,7 +85,7 @@ class ScriptedPythonInterface : virtual public 
ScriptedInterface {
 bool has_class_name = !class_name.empty();
 bool has_interpreter_dict =
 !(llvm::StringRef(m_interpreter.GetDictionaryName()).empty());
-if (!has_class_name && !has_interpreter_dict && !script_obj) {
+if (!has_class_name || !has_interpreter_dict || !script_obj) {
   if (!has_class_name)
 return create_error("Missing script class name.");
   else if (!has_interpreter_dict)

>From 7a53eeb7c42c79f7637a8900a02e782f385d494f Mon Sep 17 00:00:00 2001
From: Shivam Gupta 
Date: Wed, 19 Jun 2024 13:46:57 +0530
Subject: [PATCH 2/2] simplify condition

---
 .../Interfaces/ScriptedPythonInterface.h   | 18 +++---
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
index 30811639c9a95..3d7c640a686ae 100644
--- 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
@@ -85,13 +85,17 @@ class ScriptedPythonInterface : virtual public 
ScriptedInterface {
 bool has_class_name = !class_name.empty();
 bool has_interpreter_dict =
 !(llvm::StringRef(m_interpreter.GetDictionaryName()).empty());
-if (!has_class_name || !has_interpreter_dict || !script_obj) {
-  if (!has_class_name)
-return create_error("Missing script class name.");
-  else if (!has_interpreter_dict)
-return create_error("Invalid script interpreter dictionary.");
-  else
-return create_error("Missing scripting object.");
+
+if (!has_class_name) {
+  return create_error("Missing script class name.");
+}
+
+if (!has_interpreter_dict) {
+  return create_error("Invalid script interpreter dictionary.");
+}
+
+if (!script_obj) {
+  return create_error("Missing scripting object.");
 }
 
 Locker py_lock(&m_interpreter, Locker::AcquireLock | Locker::NoSTDIN,

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


[Lldb-commits] [lldb] [LLDB] Add an assert to verify sign_bit_pos is within the valid range (NFC) (PR #95678)

2024-06-19 Thread Shivam Gupta via lldb-commits

https://github.com/xgupta updated 
https://github.com/llvm/llvm-project/pull/95678

>From 74efb6ae3187fe1e67e61cdca1f99b9de8146db4 Mon Sep 17 00:00:00 2001
From: Shivam Gupta 
Date: Sun, 16 Jun 2024 00:21:51 +0530
Subject: [PATCH 1/2] [LLDB] Add an assert to verify sign_bit_pos is within the
 valid range

---
 lldb/source/Utility/Scalar.cpp | 31 +++
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/lldb/source/Utility/Scalar.cpp b/lldb/source/Utility/Scalar.cpp
index c680101aa9efa..6e2f1ca4c1613 100644
--- a/lldb/source/Utility/Scalar.cpp
+++ b/lldb/source/Utility/Scalar.cpp
@@ -745,26 +745,25 @@ Status Scalar::SetValueFromData(const DataExtractor &data,
 
 bool Scalar::SignExtend(uint32_t sign_bit_pos) {
   const uint32_t max_bit_pos = GetByteSize() * 8;
+  assert(sign_bit_pos < max_bit_pos);
 
-  if (sign_bit_pos < max_bit_pos) {
-switch (m_type) {
-case Scalar::e_void:
-case Scalar::e_float:
-  return false;
+  switch (m_type) {
+  case Scalar::e_void:
+  case Scalar::e_float:
+return false;
 
-case Scalar::e_int:
-  if (sign_bit_pos < (max_bit_pos - 1)) {
-llvm::APInt sign_bit = llvm::APInt::getSignMask(sign_bit_pos + 1);
-llvm::APInt bitwize_and = m_integer & sign_bit;
-if (bitwize_and.getBoolValue()) {
-  llvm::APInt mask =
-  ~(sign_bit) + llvm::APInt(m_integer.getBitWidth(), 1);
-  m_integer |= APSInt(std::move(mask), m_integer.isUnsigned());
-}
-return true;
+  case Scalar::e_int:
+if (sign_bit_pos < (max_bit_pos - 1)) {
+  llvm::APInt sign_bit = llvm::APInt::getSignMask(sign_bit_pos + 1);
+  llvm::APInt bitwize_and = m_integer & sign_bit;
+  if (bitwize_and.getBoolValue()) {
+llvm::APInt mask =
+~(sign_bit) + llvm::APInt(m_integer.getBitWidth(), 1);
+m_integer |= APSInt(std::move(mask), m_integer.isUnsigned());
   }
-  break;
+  return true;
 }
+break;
   }
   return false;
 }

>From 2cc4f83d71229542bdabcba5ffe32b09c8529d57 Mon Sep 17 00:00:00 2001
From: Shivam Gupta 
Date: Wed, 19 Jun 2024 13:57:55 +0530
Subject: [PATCH 2/2] address review suggestion

---
 lldb/source/Utility/Scalar.cpp | 24 
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/lldb/source/Utility/Scalar.cpp b/lldb/source/Utility/Scalar.cpp
index 6e2f1ca4c1613..496f402a74114 100644
--- a/lldb/source/Utility/Scalar.cpp
+++ b/lldb/source/Utility/Scalar.cpp
@@ -747,25 +747,17 @@ bool Scalar::SignExtend(uint32_t sign_bit_pos) {
   const uint32_t max_bit_pos = GetByteSize() * 8;
   assert(sign_bit_pos < max_bit_pos);
 
-  switch (m_type) {
-  case Scalar::e_void:
-  case Scalar::e_float:
+  if (m_type != Scalar::e_int || sign_bit_pos >= (max_bit_pos - 1)) {
 return false;
+  }
 
-  case Scalar::e_int:
-if (sign_bit_pos < (max_bit_pos - 1)) {
-  llvm::APInt sign_bit = llvm::APInt::getSignMask(sign_bit_pos + 1);
-  llvm::APInt bitwize_and = m_integer & sign_bit;
-  if (bitwize_and.getBoolValue()) {
-llvm::APInt mask =
-~(sign_bit) + llvm::APInt(m_integer.getBitWidth(), 1);
-m_integer |= APSInt(std::move(mask), m_integer.isUnsigned());
-  }
-  return true;
-}
-break;
+  llvm::APInt sign_bit = llvm::APInt::getSignMask(sign_bit_pos + 1);
+  llvm::APInt bitwize_and = m_integer & sign_bit;
+  if (bitwize_and.getBoolValue()) {
+llvm::APInt mask = ~(sign_bit) + llvm::APInt(m_integer.getBitWidth(), 1);
+m_integer |= APSInt(std::move(mask), m_integer.isUnsigned());
   }
-  return false;
+  return true;
 }
 
 size_t Scalar::GetAsMemoryData(void *dst, size_t dst_len,

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


[Lldb-commits] [lldb] [lldb/DWARF] Fix type definition search with simple template names (PR #95905)

2024-06-19 Thread Pavel Labath via lldb-commits

https://github.com/labath updated 
https://github.com/llvm/llvm-project/pull/95905

>From 9429eefc79b310731bafa63cf4db46eea3b0756e Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Mon, 17 Jun 2024 13:45:24 +0200
Subject: [PATCH 1/2] [lldb/DWARF] Fix type definition search with simple
 template names

With simple template names the template arguments aren't embedded in the
DW_AT_name attribute of the type. The code in
FindDefinitionTypeForDWARFDeclContext was comparing the synthesized
template arguments on the leaf (most deeply nested) DIE, but was not
sufficient, as the difference get be at any level above that
(Foo::Bar vs. Foo::Bar). This patch makes sure we compare the
entire context.

As a drive-by I also remove the completely unnecessary
ConstStringification of the GetDIEClassTemplateParams result.
---
 .../Plugins/SymbolFile/DWARF/DWARFASTParser.h |  2 +-
 .../SymbolFile/DWARF/DWARFASTParserClang.cpp  | 16 ++---
 .../SymbolFile/DWARF/DWARFASTParserClang.h|  4 +-
 .../SymbolFile/DWARF/SymbolFileDWARF.cpp  | 70 ++-
 .../x86/simple-template-names-context.cpp |  2 +-
 5 files changed, 48 insertions(+), 46 deletions(-)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
index 66db396279e06..abaeb2502cbbd 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
@@ -58,7 +58,7 @@ class DWARFASTParser {
   virtual void EnsureAllDIEsInDeclContextHaveBeenParsed(
   CompilerDeclContext decl_context) = 0;
 
-  virtual ConstString GetDIEClassTemplateParams(const DWARFDIE &die) = 0;
+  virtual std::string GetDIEClassTemplateParams(const DWARFDIE &die) = 0;
 
   static std::optional
   ParseChildArrayInfo(const DWARFDIE &parent_die,
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 02c91ddc57f83..cffe3f7dd6128 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -838,16 +838,16 @@ DWARFASTParserClang::ParseTypeModifier(const 
SymbolContext &sc,
   return type_sp;
 }
 
-ConstString
+std::string
 DWARFASTParserClang::GetDIEClassTemplateParams(const DWARFDIE &die) {
   if (llvm::StringRef(die.GetName()).contains("<"))
-return ConstString();
+return "";
 
   TypeSystemClang::TemplateParameterInfos template_param_infos;
-  if (ParseTemplateParameterInfos(die, template_param_infos)) {
-return ConstString(m_ast.PrintTemplateParams(template_param_infos));
-  }
-  return ConstString();
+  if (ParseTemplateParameterInfos(die, template_param_infos))
+return m_ast.PrintTemplateParams(template_param_infos);
+
+  return "";
 }
 
 TypeSP DWARFASTParserClang::ParseEnum(const SymbolContext &sc,
@@ -1632,7 +1632,7 @@ DWARFASTParserClang::GetCPlusPlusQualifiedName(const 
DWARFDIE &die) {
 case DW_TAG_union_type: {
   if (const char *class_union_struct_name = parent_decl_ctx_die.GetName()) 
{
 qualified_name.insert(
-0, GetDIEClassTemplateParams(parent_decl_ctx_die).AsCString(""));
+0, GetDIEClassTemplateParams(parent_decl_ctx_die));
 qualified_name.insert(0, "::");
 qualified_name.insert(0, class_union_struct_name);
   }
@@ -1650,7 +1650,7 @@ DWARFASTParserClang::GetCPlusPlusQualifiedName(const 
DWARFDIE &die) {
 qualified_name.append("::");
 
   qualified_name.append(name);
-  qualified_name.append(GetDIEClassTemplateParams(die).AsCString(""));
+  qualified_name.append(GetDIEClassTemplateParams(die));
 
   return qualified_name;
 }
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
index 136a49e462fbb..7b5ddbaa2a6b5 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
@@ -104,9 +104,9 @@ class DWARFASTParserClang : public 
lldb_private::plugin::dwarf::DWARFASTParser {
   ///
   /// \param die The struct/class DWARFDIE containing template parameters.
   /// \return A string, including surrounding '<>', of the template parameters.
-  /// If the DIE's name already has '<>', returns an empty ConstString because
+  /// If the DIE's name already has '<>', returns an empty string because
   /// it's assumed that the caller is using the DIE name anyway.
-  lldb_private::ConstString GetDIEClassTemplateParams(
+  std::string GetDIEClassTemplateParams(
   const lldb_private::plugin::dwarf::DWARFDIE &die) override;
 
 protected:
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index 369c742a5ee02..1dd19dbaac137 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -3073,14 +3073,43 

[Lldb-commits] [lldb] [lldb/DWARF] Fix type definition search with simple template names (PR #95905)

2024-06-19 Thread Pavel Labath via lldb-commits


@@ -3073,14 +3073,43 @@ 
SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
 
 // See comments below about -gsimple-template-names for why we attempt to
 // compute missing template parameter names.
-ConstString template_params;
-if (type_system) {
-  DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
-  if (dwarf_ast)
-template_params = dwarf_ast->GetDIEClassTemplateParams(die);
+std::vector template_params;
+DWARFDeclContext die_dwarf_decl_ctx;
+DWARFASTParser *dwarf_ast = type_system ? type_system->GetDWARFParser() : 
nullptr;
+for (DWARFDIE ctx_die = die; ctx_die && !isUnitType(ctx_die.Tag());
+ ctx_die = ctx_die.GetParentDeclContextDIE()) {
+  die_dwarf_decl_ctx.AppendDeclContext(ctx_die.Tag(), ctx_die.GetName());
+  template_params.push_back(
+  (ctx_die.IsStructUnionOrClass() && dwarf_ast)
+  ? dwarf_ast->GetDIEClassTemplateParams(ctx_die)
+  : "");
 }
+const bool any_template_params = llvm::any_of(
+template_params, [](llvm::StringRef p) { return !p.empty(); });
 
-const DWARFDeclContext die_dwarf_decl_ctx = die.GetDWARFDeclContext();
+auto die_matches = [&](DWARFDIE type_die) {
+  // Resolve the type if both have the same tag or {class, struct} tags.
+  const bool tag_matches =
+  type_die.Tag() == tag ||
+  (IsStructOrClassTag(type_die.Tag()) && IsStructOrClassTag(tag));

labath wrote:

Yeah.. Doesn't exactly help here, but I've been wondering about this in the 
context of the CompilerContext class. If we don't care about the class vs. 
struct distinction when resolving types, maybe we could remove the distinction 
at least from there?

https://github.com/llvm/llvm-project/pull/95905
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/DWARF] Fix type definition search with simple template names (PR #95905)

2024-06-19 Thread Pavel Labath via lldb-commits


@@ -3073,14 +3073,43 @@ 
SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
 
 // See comments below about -gsimple-template-names for why we attempt to
 // compute missing template parameter names.
-ConstString template_params;
-if (type_system) {
-  DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
-  if (dwarf_ast)
-template_params = dwarf_ast->GetDIEClassTemplateParams(die);
+std::vector template_params;
+DWARFDeclContext die_dwarf_decl_ctx;
+DWARFASTParser *dwarf_ast = type_system ? type_system->GetDWARFParser() : 
nullptr;
+for (DWARFDIE ctx_die = die; ctx_die && !isUnitType(ctx_die.Tag());
+ ctx_die = ctx_die.GetParentDeclContextDIE()) {
+  die_dwarf_decl_ctx.AppendDeclContext(ctx_die.Tag(), ctx_die.GetName());
+  template_params.push_back(
+  (ctx_die.IsStructUnionOrClass() && dwarf_ast)
+  ? dwarf_ast->GetDIEClassTemplateParams(ctx_die)
+  : "");
 }
+const bool any_template_params = llvm::any_of(
+template_params, [](llvm::StringRef p) { return !p.empty(); });
 
-const DWARFDeclContext die_dwarf_decl_ctx = die.GetDWARFDeclContext();
+auto die_matches = [&](DWARFDIE type_die) {
+  // Resolve the type if both have the same tag or {class, struct} tags.
+  const bool tag_matches =
+  type_die.Tag() == tag ||
+  (IsStructOrClassTag(type_die.Tag()) && IsStructOrClassTag(tag));
+  if (!tag_matches)
+return false;

labath wrote:

I don't think so, as the construction (lines 3079-3085 makes) it pretty clear 
that the two objects are constructed in parallel, and the code here doesn't 
even access `die_dwarf_decl_ctx` (that will be checked in 
GetFullyQualifiedType).

https://github.com/llvm/llvm-project/pull/95905
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/DWARF] Fix type definition search with simple template names (PR #95905)

2024-06-19 Thread Pavel Labath via lldb-commits

https://github.com/labath edited https://github.com/llvm/llvm-project/pull/95905
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Remove the redundent increment of 'properties' variable (PR #95675)

2024-06-19 Thread Shivam Gupta via lldb-commits

https://github.com/xgupta edited https://github.com/llvm/llvm-project/pull/95675
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/DWARF] Fix type definition search with simple template names (PR #95905)

2024-06-19 Thread Michael Buch via lldb-commits


@@ -3073,14 +3073,43 @@ 
SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
 
 // See comments below about -gsimple-template-names for why we attempt to
 // compute missing template parameter names.
-ConstString template_params;
-if (type_system) {
-  DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
-  if (dwarf_ast)
-template_params = dwarf_ast->GetDIEClassTemplateParams(die);
+std::vector template_params;
+DWARFDeclContext die_dwarf_decl_ctx;
+DWARFASTParser *dwarf_ast = type_system ? type_system->GetDWARFParser() : 
nullptr;
+for (DWARFDIE ctx_die = die; ctx_die && !isUnitType(ctx_die.Tag());
+ ctx_die = ctx_die.GetParentDeclContextDIE()) {
+  die_dwarf_decl_ctx.AppendDeclContext(ctx_die.Tag(), ctx_die.GetName());
+  template_params.push_back(
+  (ctx_die.IsStructUnionOrClass() && dwarf_ast)
+  ? dwarf_ast->GetDIEClassTemplateParams(ctx_die)
+  : "");
 }
+const bool any_template_params = llvm::any_of(
+template_params, [](llvm::StringRef p) { return !p.empty(); });
 
-const DWARFDeclContext die_dwarf_decl_ctx = die.GetDWARFDeclContext();
+auto die_matches = [&](DWARFDIE type_die) {
+  // Resolve the type if both have the same tag or {class, struct} tags.
+  const bool tag_matches =
+  type_die.Tag() == tag ||
+  (IsStructOrClassTag(type_die.Tag()) && IsStructOrClassTag(tag));

Michael137 wrote:

>  maybe we could remove the distinction at least from there?

Mind pointing me to the place you're referring to?

https://github.com/llvm/llvm-project/pull/95905
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/DWARF] Fix type definition search with simple template names (PR #95905)

2024-06-19 Thread Michael Buch via lldb-commits

https://github.com/Michael137 approved this pull request.


https://github.com/llvm/llvm-project/pull/95905
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Make LanguageRuntime::GetTypeBitSize return an optional (NFC) (PR #96013)

2024-06-19 Thread Michael Buch via lldb-commits

https://github.com/Michael137 approved this pull request.

LGTM! (minor nit)

https://github.com/llvm/llvm-project/pull/96013
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Make LanguageRuntime::GetTypeBitSize return an optional (NFC) (PR #96013)

2024-06-19 Thread Michael Buch via lldb-commits

https://github.com/Michael137 edited 
https://github.com/llvm/llvm-project/pull/96013
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Make LanguageRuntime::GetTypeBitSize return an optional (NFC) (PR #96013)

2024-06-19 Thread Michael Buch via lldb-commits


@@ -4744,11 +4744,12 @@ 
TypeSystemClang::GetBitSize(lldb::opaque_compiler_type_t type,
   ExecutionContext exe_ctx(exe_scope);
   Process *process = exe_ctx.GetProcessPtr();
   if (process) {
-ObjCLanguageRuntime *objc_runtime = ObjCLanguageRuntime::Get(*process);
-if (objc_runtime) {
-  uint64_t bit_size = 0;
-  if (objc_runtime->GetTypeBitSize(GetType(qual_type), bit_size))
-return bit_size;
+if (ObjCLanguageRuntime *objc_runtime =
+ObjCLanguageRuntime::Get(*process)) {
+  std::optional bit_size =
+  objc_runtime->GetTypeBitSize(GetType(qual_type));
+  if (bit_size)
+return *bit_size;

Michael137 wrote:

Couldn't this just be:
```suggestion
  return objc_runtime->GetTypeBitSize(GetType(qual_type));
```
?

https://github.com/llvm/llvm-project/pull/96013
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/DWARF] Fix type definition search with simple template names (PR #95905)

2024-06-19 Thread Pavel Labath via lldb-commits


@@ -3073,14 +3073,43 @@ 
SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
 
 // See comments below about -gsimple-template-names for why we attempt to
 // compute missing template parameter names.
-ConstString template_params;
-if (type_system) {
-  DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
-  if (dwarf_ast)
-template_params = dwarf_ast->GetDIEClassTemplateParams(die);
+std::vector template_params;
+DWARFDeclContext die_dwarf_decl_ctx;
+DWARFASTParser *dwarf_ast = type_system ? type_system->GetDWARFParser() : 
nullptr;
+for (DWARFDIE ctx_die = die; ctx_die && !isUnitType(ctx_die.Tag());
+ ctx_die = ctx_die.GetParentDeclContextDIE()) {
+  die_dwarf_decl_ctx.AppendDeclContext(ctx_die.Tag(), ctx_die.GetName());
+  template_params.push_back(
+  (ctx_die.IsStructUnionOrClass() && dwarf_ast)
+  ? dwarf_ast->GetDIEClassTemplateParams(ctx_die)
+  : "");
 }
+const bool any_template_params = llvm::any_of(
+template_params, [](llvm::StringRef p) { return !p.empty(); });
 
-const DWARFDeclContext die_dwarf_decl_ctx = die.GetDWARFDeclContext();
+auto die_matches = [&](DWARFDIE type_die) {
+  // Resolve the type if both have the same tag or {class, struct} tags.
+  const bool tag_matches =
+  type_die.Tag() == tag ||
+  (IsStructOrClassTag(type_die.Tag()) && IsStructOrClassTag(tag));

labath wrote:

We have both CompilerContextKind::Class and CompilerContextKind::Struct. Since 
these classes are (mainly?) used for looking things up in the debug info (where 
we treat the two as (mostly) the same), I'm thinking whether we could merge 
these two into one.

https://github.com/llvm/llvm-project/pull/95905
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang] [lldb] [clang][lldb] Don't assert structure layout correctness for layouts provided by LLDB (PR #93809)

2024-06-19 Thread Michael Buch via lldb-commits

Michael137 wrote:

Ah got it, thanks for clarifying.

> so we could instead just check if the field is empty.

Couldn't find an existing API for this on `FieldDecl`. Here "empty" would be 
"field is of a type which is empty"? Which might still cause complications 
because a `CXXRecordDecl::isEmpty` itself depends on `isZeroSize` of its fields.

https://github.com/llvm/llvm-project/pull/93809
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/DWARF] Fix type definition search with simple template names (PR #95905)

2024-06-19 Thread Michael Buch via lldb-commits


@@ -3073,14 +3073,43 @@ 
SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
 
 // See comments below about -gsimple-template-names for why we attempt to
 // compute missing template parameter names.
-ConstString template_params;
-if (type_system) {
-  DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
-  if (dwarf_ast)
-template_params = dwarf_ast->GetDIEClassTemplateParams(die);
+std::vector template_params;
+DWARFDeclContext die_dwarf_decl_ctx;
+DWARFASTParser *dwarf_ast = type_system ? type_system->GetDWARFParser() : 
nullptr;
+for (DWARFDIE ctx_die = die; ctx_die && !isUnitType(ctx_die.Tag());
+ ctx_die = ctx_die.GetParentDeclContextDIE()) {
+  die_dwarf_decl_ctx.AppendDeclContext(ctx_die.Tag(), ctx_die.GetName());
+  template_params.push_back(
+  (ctx_die.IsStructUnionOrClass() && dwarf_ast)
+  ? dwarf_ast->GetDIEClassTemplateParams(ctx_die)
+  : "");
 }
+const bool any_template_params = llvm::any_of(
+template_params, [](llvm::StringRef p) { return !p.empty(); });
 
-const DWARFDeclContext die_dwarf_decl_ctx = die.GetDWARFDeclContext();
+auto die_matches = [&](DWARFDIE type_die) {
+  // Resolve the type if both have the same tag or {class, struct} tags.
+  const bool tag_matches =
+  type_die.Tag() == tag ||
+  (IsStructOrClassTag(type_die.Tag()) && IsStructOrClassTag(tag));

Michael137 wrote:

Ah I see, yea those two seem to always be used in the same way. Merging them 
would make sense. Of course that still leaves us with the 
`DW_TAG_structure_type || DW_TAG_class_type` checks, but that can always be 
cleaned up later.

https://github.com/llvm/llvm-project/pull/95905
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Support DW_OP_WASM_location in DWARFExpression (PR #78977)

2024-06-19 Thread Paolo Severini via lldb-commits

https://github.com/paolosevMSFT updated 
https://github.com/llvm/llvm-project/pull/78977

>From 4bcf2b50123b18752108aad163a059577e360aa6 Mon Sep 17 00:00:00 2001
From: Paolo Severini 
Date: Mon, 22 Jan 2024 06:06:56 -0800
Subject: [PATCH 1/4] Add support for DW_OP_WASM_location to DWARFExpression

---
 lldb/source/Expression/DWARFExpression.cpp | 41 ++
 1 file changed, 41 insertions(+)

diff --git a/lldb/source/Expression/DWARFExpression.cpp 
b/lldb/source/Expression/DWARFExpression.cpp
index fe4928d4f43a4..95033db5ed8f5 100644
--- a/lldb/source/Expression/DWARFExpression.cpp
+++ b/lldb/source/Expression/DWARFExpression.cpp
@@ -346,6 +346,16 @@ static offset_t GetOpcodeDataSize(const DataExtractor 
&data,
 return (offset - data_offset) + subexpr_len;
   }
 
+  case DW_OP_WASM_location: {
+uint8_t wasm_op = data.GetU8(&offset);
+if (wasm_op == 3) {
+  data.GetU32(&offset);
+} else {
+  data.GetULEB128(&offset);
+}
+return offset - data_offset;
+  }
+
   default:
 if (!dwarf_cu) {
   return LLDB_INVALID_OFFSET;
@@ -2595,6 +2605,37 @@ bool DWARFExpression::Evaluate(
   break;
 }
 
+case DW_OP_WASM_location: {
+  uint8_t wasm_op = opcodes.GetU8(&offset);
+  uint32_t index;
+
+  /* LLDB doesn't have an address space to represents WebAssembly locals,
+   * globals and operand stacks.
+   * We encode these elements into virtual registers:
+   *   | tag: 2 bits | index: 30 bits |
+   *   where tag is:
+   *0: Not a WebAssembly location
+   *1: Local
+   *2: Global
+   *3: Operand stack value
+   */
+  if (wasm_op == 3) {
+index = opcodes.GetU32(&offset);
+wasm_op = 2; // Global
+  } else {
+index = opcodes.GetULEB128(&offset);
+  }
+
+  reg_num = (((wasm_op + 1) & 0x03) << 30) | (index & 0x3fff);
+
+  if (ReadRegisterValueAsScalar(reg_ctx, reg_kind, reg_num, error_ptr, 
tmp))
+stack.push_back(tmp);
+  else
+return false;
+
+  break;
+}
+
 default:
   if (dwarf_cu) {
 if (dwarf_cu->GetSymbolFileDWARF().ParseVendorDWARFOpcode(

>From 639295de7bdd4a2e710b62337a511ded92eb702a Mon Sep 17 00:00:00 2001
From: Paolo Severini 
Date: Mon, 29 Jan 2024 06:25:58 -0800
Subject: [PATCH 2/4] Add unite tests

---
 .../include/lldb/Expression/DWARFExpression.h |   5 +
 lldb/source/Expression/DWARFExpression.cpp|  53 +-
 .../ObjectFile/wasm/ObjectFileWasm.cpp|   6 +-
 .../SymbolFile/DWARF/SymbolFileDWARF.cpp  |  66 ++
 .../SymbolFile/DWARF/SymbolFileDWARF.h|  27 +-
 .../SymbolFile/DWARF/SymbolFileDWARFDwo.cpp   |   8 +-
 .../SymbolFile/DWARF/SymbolFileDWARFDwo.h |   8 +-
 lldb/unittests/Expression/CMakeLists.txt  |   2 +
 .../Expression/DWARFExpressionTest.cpp| 562 ++
 9 files changed, 580 insertions(+), 157 deletions(-)

diff --git a/lldb/include/lldb/Expression/DWARFExpression.h 
b/lldb/include/lldb/Expression/DWARFExpression.h
index 1d85308d1caa7..73143399ff147 100644
--- a/lldb/include/lldb/Expression/DWARFExpression.h
+++ b/lldb/include/lldb/Expression/DWARFExpression.h
@@ -153,6 +153,11 @@ class DWARFExpression {
 
   bool MatchesOperand(StackFrame &frame, const Instruction::Operand &op) const;
 
+  static bool ReadRegisterValueAsScalar(RegisterContext *reg_ctx,
+lldb::RegisterKind reg_kind,
+uint32_t reg_num, Status *error_ptr,
+Value &value);
+
 private:
   /// A data extractor capable of reading opcode bytes
   DataExtractor m_data;
diff --git a/lldb/source/Expression/DWARFExpression.cpp 
b/lldb/source/Expression/DWARFExpression.cpp
index 95033db5ed8f5..7298ccbf998d4 100644
--- a/lldb/source/Expression/DWARFExpression.cpp
+++ b/lldb/source/Expression/DWARFExpression.cpp
@@ -95,10 +95,12 @@ void DWARFExpression::SetRegisterKind(RegisterKind 
reg_kind) {
 }
 
 
-static bool ReadRegisterValueAsScalar(RegisterContext *reg_ctx,
-  lldb::RegisterKind reg_kind,
-  uint32_t reg_num, Status *error_ptr,
-  Value &value) {
+// static
+bool DWARFExpression::ReadRegisterValueAsScalar(RegisterContext *reg_ctx,
+lldb::RegisterKind reg_kind,
+uint32_t reg_num,
+Status *error_ptr,
+Value &value) {
   if (reg_ctx == nullptr) {
 if (error_ptr)
   error_ptr->SetErrorString("No register context in frame.\n");
@@ -346,16 +348,6 @@ static offset_t GetOpcodeDataSize(const DataExtractor 
&data,
 return (offset - data_offset) + subexpr_len;
   }
 
-  case DW_OP_WASM_location: {
-uint8_t wasm_op = data.GetU8(&offset);
-if (wasm_op == 3) {

[Lldb-commits] [clang] [lldb] [clang][lldb] Don't assert structure layout correctness for layouts provided by LLDB (PR #93809)

2024-06-19 Thread Eli Friedman via lldb-commits

efriedma-quic wrote:

It's not that hard to compute "no-data": non-RecordDecls are never no-data, 
RecordDecls are no-data if they don't have a vtable pointer (isDynamicClass()), 
and all fields are no-data.  We can save it in the CGRecordLayout.

Assuming that's the route we want to go, of course, as opposed to just making 
LLDB add no_unique_address markings to fields.

https://github.com/llvm/llvm-project/pull/93809
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/DWARF] Fix type definition search with simple template names (PR #95905)

2024-06-19 Thread Pavel Labath via lldb-commits

https://github.com/labath updated 
https://github.com/llvm/llvm-project/pull/95905

>From 9429eefc79b310731bafa63cf4db46eea3b0756e Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Mon, 17 Jun 2024 13:45:24 +0200
Subject: [PATCH 1/3] [lldb/DWARF] Fix type definition search with simple
 template names

With simple template names the template arguments aren't embedded in the
DW_AT_name attribute of the type. The code in
FindDefinitionTypeForDWARFDeclContext was comparing the synthesized
template arguments on the leaf (most deeply nested) DIE, but was not
sufficient, as the difference get be at any level above that
(Foo::Bar vs. Foo::Bar). This patch makes sure we compare the
entire context.

As a drive-by I also remove the completely unnecessary
ConstStringification of the GetDIEClassTemplateParams result.
---
 .../Plugins/SymbolFile/DWARF/DWARFASTParser.h |  2 +-
 .../SymbolFile/DWARF/DWARFASTParserClang.cpp  | 16 ++---
 .../SymbolFile/DWARF/DWARFASTParserClang.h|  4 +-
 .../SymbolFile/DWARF/SymbolFileDWARF.cpp  | 70 ++-
 .../x86/simple-template-names-context.cpp |  2 +-
 5 files changed, 48 insertions(+), 46 deletions(-)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
index 66db396279e06..abaeb2502cbbd 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
@@ -58,7 +58,7 @@ class DWARFASTParser {
   virtual void EnsureAllDIEsInDeclContextHaveBeenParsed(
   CompilerDeclContext decl_context) = 0;
 
-  virtual ConstString GetDIEClassTemplateParams(const DWARFDIE &die) = 0;
+  virtual std::string GetDIEClassTemplateParams(const DWARFDIE &die) = 0;
 
   static std::optional
   ParseChildArrayInfo(const DWARFDIE &parent_die,
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 02c91ddc57f83..cffe3f7dd6128 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -838,16 +838,16 @@ DWARFASTParserClang::ParseTypeModifier(const 
SymbolContext &sc,
   return type_sp;
 }
 
-ConstString
+std::string
 DWARFASTParserClang::GetDIEClassTemplateParams(const DWARFDIE &die) {
   if (llvm::StringRef(die.GetName()).contains("<"))
-return ConstString();
+return "";
 
   TypeSystemClang::TemplateParameterInfos template_param_infos;
-  if (ParseTemplateParameterInfos(die, template_param_infos)) {
-return ConstString(m_ast.PrintTemplateParams(template_param_infos));
-  }
-  return ConstString();
+  if (ParseTemplateParameterInfos(die, template_param_infos))
+return m_ast.PrintTemplateParams(template_param_infos);
+
+  return "";
 }
 
 TypeSP DWARFASTParserClang::ParseEnum(const SymbolContext &sc,
@@ -1632,7 +1632,7 @@ DWARFASTParserClang::GetCPlusPlusQualifiedName(const 
DWARFDIE &die) {
 case DW_TAG_union_type: {
   if (const char *class_union_struct_name = parent_decl_ctx_die.GetName()) 
{
 qualified_name.insert(
-0, GetDIEClassTemplateParams(parent_decl_ctx_die).AsCString(""));
+0, GetDIEClassTemplateParams(parent_decl_ctx_die));
 qualified_name.insert(0, "::");
 qualified_name.insert(0, class_union_struct_name);
   }
@@ -1650,7 +1650,7 @@ DWARFASTParserClang::GetCPlusPlusQualifiedName(const 
DWARFDIE &die) {
 qualified_name.append("::");
 
   qualified_name.append(name);
-  qualified_name.append(GetDIEClassTemplateParams(die).AsCString(""));
+  qualified_name.append(GetDIEClassTemplateParams(die));
 
   return qualified_name;
 }
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
index 136a49e462fbb..7b5ddbaa2a6b5 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
@@ -104,9 +104,9 @@ class DWARFASTParserClang : public 
lldb_private::plugin::dwarf::DWARFASTParser {
   ///
   /// \param die The struct/class DWARFDIE containing template parameters.
   /// \return A string, including surrounding '<>', of the template parameters.
-  /// If the DIE's name already has '<>', returns an empty ConstString because
+  /// If the DIE's name already has '<>', returns an empty string because
   /// it's assumed that the caller is using the DIE name anyway.
-  lldb_private::ConstString GetDIEClassTemplateParams(
+  std::string GetDIEClassTemplateParams(
   const lldb_private::plugin::dwarf::DWARFDIE &die) override;
 
 protected:
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index 369c742a5ee02..1dd19dbaac137 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -3073,14 +3073,43 

[Lldb-commits] [lldb] [lldb/DWARF] Fix type definition search with simple template names (PR #95905)

2024-06-19 Thread Pavel Labath via lldb-commits


@@ -3073,14 +3073,43 @@ 
SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
 
 // See comments below about -gsimple-template-names for why we attempt to
 // compute missing template parameter names.
-ConstString template_params;
-if (type_system) {
-  DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
-  if (dwarf_ast)
-template_params = dwarf_ast->GetDIEClassTemplateParams(die);
+std::vector template_params;
+DWARFDeclContext die_dwarf_decl_ctx;
+DWARFASTParser *dwarf_ast = type_system ? type_system->GetDWARFParser() : 
nullptr;
+for (DWARFDIE ctx_die = die; ctx_die && !isUnitType(ctx_die.Tag());
+ ctx_die = ctx_die.GetParentDeclContextDIE()) {
+  die_dwarf_decl_ctx.AppendDeclContext(ctx_die.Tag(), ctx_die.GetName());
+  template_params.push_back(
+  (ctx_die.IsStructUnionOrClass() && dwarf_ast)
+  ? dwarf_ast->GetDIEClassTemplateParams(ctx_die)
+  : "");
 }
+const bool any_template_params = llvm::any_of(
+template_params, [](llvm::StringRef p) { return !p.empty(); });
 
-const DWARFDeclContext die_dwarf_decl_ctx = die.GetDWARFDeclContext();
+auto die_matches = [&](DWARFDIE type_die) {
+  // Resolve the type if both have the same tag or {class, struct} tags.
+  const bool tag_matches =
+  type_die.Tag() == tag ||
+  (IsStructOrClassTag(type_die.Tag()) && IsStructOrClassTag(tag));

labath wrote:

Yeah, I'm not quite sure how to handle those. We can't just completely erase 
the difference there because they matter for creation of clang asts. One idea 
(that just occurred to me) would be to have a sort of a getCanonicalTag() which 
maps structure_type to class_type (or the other way around), and then do these 
comparisons on the "canonical" tags.

https://github.com/llvm/llvm-project/pull/95905
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] c2f9766 - [lldb/DWARF] Fix type definition search with simple template names (#95905)

2024-06-19 Thread via lldb-commits

Author: Pavel Labath
Date: 2024-06-20T08:09:02+02:00
New Revision: c2f976649a5ef405b224bfe36267966cdd394057

URL: 
https://github.com/llvm/llvm-project/commit/c2f976649a5ef405b224bfe36267966cdd394057
DIFF: 
https://github.com/llvm/llvm-project/commit/c2f976649a5ef405b224bfe36267966cdd394057.diff

LOG: [lldb/DWARF] Fix type definition search with simple template names (#95905)

With simple template names the template arguments aren't embedded in the
DW_AT_name attribute of the type. The code in
FindDefinitionTypeForDWARFDeclContext was comparing the synthesized
template arguments on the leaf (most deeply nested) DIE, but was not
sufficient, as the difference get be at any level above that
(Foo::Bar vs. Foo::Bar). This patch makes sure we compare the
entire context.

As a drive-by I also remove the completely unnecessary
ConstStringification of the GetDIEClassTemplateParams result.

Added: 


Modified: 
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/Shell/SymbolFile/DWARF/x86/simple-template-names-context.cpp

Removed: 




diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
index 66db396279e06..abaeb2502cbbd 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
@@ -58,7 +58,7 @@ class DWARFASTParser {
   virtual void EnsureAllDIEsInDeclContextHaveBeenParsed(
   CompilerDeclContext decl_context) = 0;
 
-  virtual ConstString GetDIEClassTemplateParams(const DWARFDIE &die) = 0;
+  virtual std::string GetDIEClassTemplateParams(const DWARFDIE &die) = 0;
 
   static std::optional
   ParseChildArrayInfo(const DWARFDIE &parent_die,

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 02c91ddc57f83..ae3eaf88ff4a8 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -838,16 +838,16 @@ DWARFASTParserClang::ParseTypeModifier(const 
SymbolContext &sc,
   return type_sp;
 }
 
-ConstString
+std::string
 DWARFASTParserClang::GetDIEClassTemplateParams(const DWARFDIE &die) {
   if (llvm::StringRef(die.GetName()).contains("<"))
-return ConstString();
+return {};
 
   TypeSystemClang::TemplateParameterInfos template_param_infos;
-  if (ParseTemplateParameterInfos(die, template_param_infos)) {
-return ConstString(m_ast.PrintTemplateParams(template_param_infos));
-  }
-  return ConstString();
+  if (ParseTemplateParameterInfos(die, template_param_infos))
+return m_ast.PrintTemplateParams(template_param_infos);
+
+  return {};
 }
 
 TypeSP DWARFASTParserClang::ParseEnum(const SymbolContext &sc,
@@ -1632,7 +1632,7 @@ DWARFASTParserClang::GetCPlusPlusQualifiedName(const 
DWARFDIE &die) {
 case DW_TAG_union_type: {
   if (const char *class_union_struct_name = parent_decl_ctx_die.GetName()) 
{
 qualified_name.insert(
-0, GetDIEClassTemplateParams(parent_decl_ctx_die).AsCString(""));
+0, GetDIEClassTemplateParams(parent_decl_ctx_die));
 qualified_name.insert(0, "::");
 qualified_name.insert(0, class_union_struct_name);
   }
@@ -1650,7 +1650,7 @@ DWARFASTParserClang::GetCPlusPlusQualifiedName(const 
DWARFDIE &die) {
 qualified_name.append("::");
 
   qualified_name.append(name);
-  qualified_name.append(GetDIEClassTemplateParams(die).AsCString(""));
+  qualified_name.append(GetDIEClassTemplateParams(die));
 
   return qualified_name;
 }

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
index 136a49e462fbb..7b5ddbaa2a6b5 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
@@ -104,9 +104,9 @@ class DWARFASTParserClang : public 
lldb_private::plugin::dwarf::DWARFASTParser {
   ///
   /// \param die The struct/class DWARFDIE containing template parameters.
   /// \return A string, including surrounding '<>', of the template parameters.
-  /// If the DIE's name already has '<>', returns an empty ConstString because
+  /// If the DIE's name already has '<>', returns an empty string because
   /// it's assumed that the caller is using the DIE name anyway.
-  lldb_private::ConstString GetDIEClassTemplateParams(
+  std::string GetDIEClassTemplateParams(
   const lldb_private::plugin::dwarf::DWARFDIE &die) override;
 
 protected:

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index 55ddc

[Lldb-commits] [lldb] [lldb/DWARF] Fix type definition search with simple template names (PR #95905)

2024-06-19 Thread Pavel Labath via lldb-commits

https://github.com/labath closed https://github.com/llvm/llvm-project/pull/95905
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits