[Lldb-commits] [PATCH] D114627: [lldb] add new overload for SymbolFile::FindTypes that accepts a scope

2022-03-28 Thread Lasse Folger via Phabricator via lldb-commits
lassefolger added a comment.
Herald added a project: All.

Sorry for the very late response.

I looked into using the `CompilerDeclContext()`.

This does not work in this case because the context is not set in this specific 
use case and I'm not sure if it case be set.
It is initialized with an invalid context when the function is called 
.

The entry point in our use case is `lldb::SBTarget::FindTypes(const char *)`. A 
stacktrace looks like this:
SymbolFileDWARF::FindTypes()
lldb_private::Module::FindTypes_Impl()
lldb_private::ModuleList::FindTypes()
lldb::SBTarget::FindTypes()

Given that the input is just a C-string, I'm not sure how to derive a 
`CompilerDeclContext()` from that.
What we are trying to optimize is a call like:
`lldb.target.FindTypes("Some::Namespace::Type")`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114627

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


[Lldb-commits] [PATCH] D114627: [lldb] add new overload for SymbolFile::FindTypes that accepts a scope

2022-02-25 Thread Lasse Folger via Phabricator via lldb-commits
lassefolger added a comment.

I'm still planning to look into this just couldn't find the time this week and 
the last. Sorry for the delay.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114627

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


[Lldb-commits] [PATCH] D114627: [lldb] add new overload for SymbolFile::FindTypes that accepts a scope

2022-02-13 Thread Lasse Folger via Phabricator via lldb-commits
lassefolger added a comment.

In D114627#3306300 , @clayborg wrote:

> Sorry I am late to making comments on this patch.
>
> This patch wants to add "llvm::StringRef scope" to the FindTypes calls, but 
> this is what "const CompilerDeclContext &parent_decl_ctx" is actually for. If 
> "parent_decl_ctx" is set, it is a declaration context that each type must 
> exist in. So the CompilerDeclContext  might be something like "namespace foo" 
> and it might have a parent decl context of "namespace bar". This is currently 
> how filtering types that exist in a decl context works.
>
> The "scope" seems redundant in light of this no? Also, a string based "scope" 
> isn't accurate enough to correctly identify the exact scoping of a type as 
> "a:🅱️:some_type" might be "namespace a -> class b -> some_type" or "namespace 
> a -> namespace b -> some_type".
>
> The one difficult thing about this is currently the "parent_decl_ctx" that is 
> a parameter only works if the decl context comes from the current module. 
> Each module creates types using its own TypeSystem subclass. Those types are 
> vended as CompilerType objects which contain the TypeSystem pointer and a 
> void * for the type. This allows each TypeSystem to create types. For clang 
> compiled code we use lldb_private::TypeSystemClang and we create types as 
> types in a clang::ASTContext. We can also specify declaration contexts by 
> using CompilerDeclContext objects. Each CompilerDeclContext object has a 
> "TypeSystem *" and a "void *" inside of it. Each expression makes its own 
> TypeSystem as well, and one for each expression and one in the target. It 
> should be possible to fix the issue of needing the compiler decl context to 
> come from the current module by having the code that compares the decl 
> context make by using:
>
>   ConstString CompilerDeclContext::GetScopeQualifiedName() const;
>
> Or we can modify the CompilerDeclContext class to get the current name:
>
>   ConstString CompilerDeclContext::GetName() const; 
>
> And then also add an API to return an enumeration for the kind of the 
> declaration context (Namespace, Class, Struct, Union, etc).

The idea is that the scope is a hint which implementations can use to improve 
the performance.
However, I see that this redundancy might be confusing. I have not looked to 
much into the ComplierDeclContext.
I'll try to take another look later this week.

FWIW there has been a discussion between werat@ and teemperor@ about this on 
Discord about this topic in general. The results was to use a string rather 
than a CompilerDeclContext. Although the discussion didn't go into detail why 
this is:
https://discord.com/channels/636084430946959380/636732809708306432/849218944581632001


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114627

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


[Lldb-commits] [PATCH] D114627: [lldb] add new overload for SymbolFile::FindTypes that accepts a scope

2022-02-07 Thread Lasse Folger via Phabricator via lldb-commits
lassefolger added inline comments.



Comment at: lldb/include/lldb/Symbol/SymbolFile.h:241
+  virtual void
+  FindTypes(ConstString name, ConstString scope,
+const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches,

JDevlieghere wrote:
> Does the scope need to be a ConstString? These strings are kept in memory 
> forever and we should be mindful of their use. Could this a StringRef? 
I don't think it has to be a ConstString. I used a ConstString for consistency 
with `name`.
Let me change it to StringRef



Comment at: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp:2456
+  }
+  std::string storage;
+

JDevlieghere wrote:
> Can this go into `if (has_scope) {`?
I don't mind putting it in there but thought reusing the same storage would 
avoid allocations.
Moving it into the function will lead to an allocation each time the function 
is called and the qualified name is too long for small string optimization.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114627

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


[Lldb-commits] [PATCH] D114627: [lldb] add new overload for SymbolFile::FindTypes that accepts a scope

2022-02-07 Thread Lasse Folger via Phabricator via lldb-commits
lassefolger updated this revision to Diff 406355.
lassefolger marked 2 inline comments as done.
lassefolger added a comment.

update according to comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114627

Files:
  lldb/include/lldb/Core/Module.h
  lldb/include/lldb/Symbol/SymbolFile.h
  lldb/source/Core/Module.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/source/Symbol/SymbolFile.cpp

Index: lldb/source/Symbol/SymbolFile.cpp
===
--- lldb/source/Symbol/SymbolFile.cpp
+++ lldb/source/Symbol/SymbolFile.cpp
@@ -18,6 +18,7 @@
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/StreamString.h"
 #include "lldb/lldb-private.h"
+#include "llvm/ADT/StringRef.h"
 
 #include 
 
@@ -133,6 +134,18 @@
 llvm::DenseSet &searched_symbol_files,
 TypeMap &types) {}
 
+void SymbolFile::FindTypes(
+ConstString basename, llvm::StringRef scope,
+const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches,
+llvm::DenseSet &searched_symbol_files,
+TypeMap &types) {
+  FindTypes(basename, parent_decl_ctx, max_matches, searched_symbol_files,
+types);
+  TypeClass type_class = eTypeClassAny;
+  types.RemoveMismatchedTypes(std::string(basename.GetCString()), scope.str(),
+  type_class, scope.startswith("::"));
+}
+
 void SymbolFile::FindTypes(llvm::ArrayRef pattern,
LanguageSet languages,
llvm::DenseSet &searched_symbol_files,
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -17,6 +17,7 @@
 
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SetVector.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Threading.h"
 
 #include "lldb/Core/UniqueCStringMap.h"
@@ -191,6 +192,13 @@
   const std::string &scope_qualified_name,
   std::vector &mangled_names) override;
 
+  void
+  FindTypes(lldb_private::ConstString name, llvm::StringRef scope,
+const lldb_private::CompilerDeclContext &parent_decl_ctx,
+uint32_t max_matches,
+llvm::DenseSet &searched_symbol_files,
+lldb_private::TypeMap &types) override;
+
   void
   FindTypes(lldb_private::ConstString name,
 const lldb_private::CompilerDeclContext &parent_decl_ctx,
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -9,6 +9,7 @@
 #include "SymbolFileDWARF.h"
 
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Threading.h"
 
@@ -21,6 +22,7 @@
 #include "lldb/Core/StreamFile.h"
 #include "lldb/Core/Value.h"
 #include "lldb/Utility/ArchSpec.h"
+#include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/RegularExpression.h"
 #include "lldb/Utility/Scalar.h"
 #include "lldb/Utility/StreamString.h"
@@ -2409,6 +2411,15 @@
 uint32_t max_matches,
 llvm::DenseSet &searched_symbol_files,
 TypeMap &types) {
+  FindTypes(name, llvm::StringRef(), parent_decl_ctx, max_matches,
+searched_symbol_files, types);
+}
+
+void SymbolFileDWARF::FindTypes(
+ConstString name, llvm::StringRef scope,
+const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches,
+llvm::DenseSet &searched_symbol_files,
+TypeMap &types) {
   std::lock_guard guard(GetModuleMutex());
   // Make sure we haven't already searched this SymbolFile before.
   if (!searched_symbol_files.insert(this).second)
@@ -2435,10 +2446,24 @@
   if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
 return;
 
+  // prepare string to check against in case this is a fully qualified search
+  bool has_scope = !scope.empty();
+  if (scope.size() != 2) {
+// DWARFDIE prefixes only variables in global scope with '::'
+scope.consume_front("::");
+  }
+
   m_index->GetTypes(name, [&](DWARFDIE die) {
 if (!DIEInDeclContext(parent_decl_ctx, die))
   return true; // The containing decl contexts don't match
 
+if (has_scope) {
+  std::string storage;
+  die.GetQualifiedName(storage);
+  if (!storage.empty() && !llvm::StringRef(storage).startswith(scope))
+return true;
+}
+
 Type *matching_type = ResolveType(die, true, true);
 if (!matching_type)
   return true;
Index: lldb/source/Core/Module.cpp
===
--- lldb/source/Core/Module.cpp
+++ lldb/source/Core/Module.cpp
@@ -46,6 +46,7 @@
 #include "lldb

[Lldb-commits] [PATCH] D114627: [lldb] add new overload for SymbolFile::FindTypes that accepts a scope

2022-01-21 Thread Lasse Folger via Phabricator via lldb-commits
lassefolger updated this revision to Diff 401947.
lassefolger added a comment.

rebase patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114627

Files:
  lldb/include/lldb/Core/Module.h
  lldb/include/lldb/Symbol/SymbolFile.h
  lldb/source/Core/Module.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/source/Symbol/SymbolFile.cpp

Index: lldb/source/Symbol/SymbolFile.cpp
===
--- lldb/source/Symbol/SymbolFile.cpp
+++ lldb/source/Symbol/SymbolFile.cpp
@@ -133,6 +133,19 @@
 llvm::DenseSet &searched_symbol_files,
 TypeMap &types) {}
 
+void SymbolFile::FindTypes(
+ConstString basename, ConstString scope,
+const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches,
+llvm::DenseSet &searched_symbol_files,
+TypeMap &types) {
+  FindTypes(basename, parent_decl_ctx, max_matches, searched_symbol_files,
+types);
+  TypeClass type_class = eTypeClassAny;
+  types.RemoveMismatchedTypes(std::string(basename.GetCString()),
+  std::string(scope.GetCString()), type_class,
+  scope.GetStringRef().startswith("::"));
+}
+
 void SymbolFile::FindTypes(llvm::ArrayRef pattern,
LanguageSet languages,
llvm::DenseSet &searched_symbol_files,
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -191,6 +191,13 @@
   const std::string &scope_qualified_name,
   std::vector &mangled_names) override;
 
+  void
+  FindTypes(lldb_private::ConstString name, lldb_private::ConstString scope,
+const lldb_private::CompilerDeclContext &parent_decl_ctx,
+uint32_t max_matches,
+llvm::DenseSet &searched_symbol_files,
+lldb_private::TypeMap &types) override;
+
   void
   FindTypes(lldb_private::ConstString name,
 const lldb_private::CompilerDeclContext &parent_decl_ctx,
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -9,6 +9,7 @@
 #include "SymbolFileDWARF.h"
 
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Threading.h"
 
@@ -21,6 +22,7 @@
 #include "lldb/Core/StreamFile.h"
 #include "lldb/Core/Value.h"
 #include "lldb/Utility/ArchSpec.h"
+#include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/RegularExpression.h"
 #include "lldb/Utility/Scalar.h"
 #include "lldb/Utility/StreamString.h"
@@ -2409,6 +2411,15 @@
 uint32_t max_matches,
 llvm::DenseSet &searched_symbol_files,
 TypeMap &types) {
+  FindTypes(name, ConstString(), parent_decl_ctx, max_matches,
+searched_symbol_files, types);
+}
+
+void SymbolFileDWARF::FindTypes(
+ConstString name, ConstString scope,
+const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches,
+llvm::DenseSet &searched_symbol_files,
+TypeMap &types) {
   std::lock_guard guard(GetModuleMutex());
   // Make sure we haven't already searched this SymbolFile before.
   if (!searched_symbol_files.insert(this).second)
@@ -2435,10 +2446,25 @@
   if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
 return;
 
+  // prepare string to check against in case this is a fully qualified search
+  bool has_scope = !scope.IsEmpty();
+  llvm::StringRef scope_ref(scope.GetStringRef());
+  if (scope_ref.size() != 2) {
+// DWARFDIE prefixes only variables in global scope with '::'
+scope_ref.consume_front("::");
+  }
+  std::string storage;
+
   m_index->GetTypes(name, [&](DWARFDIE die) {
 if (!DIEInDeclContext(parent_decl_ctx, die))
   return true; // The containing decl contexts don't match
 
+if (has_scope) {
+  die.GetQualifiedName(storage);
+  if (!storage.empty() && !llvm::StringRef(storage).startswith(scope_ref))
+return true;
+}
+
 Type *matching_type = ResolveType(die, true, true);
 if (!matching_type)
   return true;
Index: lldb/source/Core/Module.cpp
===
--- lldb/source/Core/Module.cpp
+++ lldb/source/Core/Module.cpp
@@ -947,6 +947,17 @@
searched_symbol_files, types);
 }
 
+void Module::FindTypes_Impl(
+ConstString name, ConstString scope,
+const CompilerDeclContext &parent_decl_ctx, size_t max_matches,
+llvm::DenseSet &searched_symbol_files,
+TypeMap &types) {
+  LLDB_SCOPED_TIMER();
+  if (SymbolFile *symb

[Lldb-commits] [PATCH] D114627: [lldb] add new overload for SymbolFile::FindTypes that accepts a scope

2021-12-10 Thread Lasse Folger via Phabricator via lldb-commits
lassefolger added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp:2470
+  const char *qn = die.GetQualifiedName(storage);
+  if (qn && !llvm::StringRef(qn).startswith(sc))
+return true;

werat wrote:
> `llvm::StringRef(storage)` is slightly more efficient here than 
> `llvm::StringRef(qn)`. The latter uses strlen in the constructor to calculate 
> the length of the source string.
I wasn't sure about the semantics of die.GetQualifiedName().
It does not document whether it's guaranteed that storage contains the results. 
FWIW, the current implementation does that.
I changed it to use the storage.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114627

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


[Lldb-commits] [PATCH] D114627: [lldb] add new overload for SymbolFile::FindTypes that accepts a scope

2021-12-10 Thread Lasse Folger via Phabricator via lldb-commits
lassefolger updated this revision to Diff 393485.
lassefolger marked 2 inline comments as done.
lassefolger added a comment.

fixed comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114627

Files:
  lldb/include/lldb/Core/Module.h
  lldb/include/lldb/Symbol/SymbolFile.h
  lldb/source/Core/Module.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/source/Symbol/SymbolFile.cpp

Index: lldb/source/Symbol/SymbolFile.cpp
===
--- lldb/source/Symbol/SymbolFile.cpp
+++ lldb/source/Symbol/SymbolFile.cpp
@@ -135,6 +135,19 @@
 llvm::DenseSet &searched_symbol_files,
 TypeMap &types) {}
 
+void SymbolFile::FindTypes(
+ConstString basename, ConstString scope,
+const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches,
+llvm::DenseSet &searched_symbol_files,
+TypeMap &types) {
+  FindTypes(basename, parent_decl_ctx, max_matches, searched_symbol_files,
+types);
+  TypeClass type_class = eTypeClassAny;
+  types.RemoveMismatchedTypes(std::string(basename.GetCString()),
+  std::string(scope.GetCString()), type_class,
+  scope.GetStringRef().startswith("::"));
+}
+
 void SymbolFile::FindTypes(llvm::ArrayRef pattern,
LanguageSet languages,
llvm::DenseSet &searched_symbol_files,
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -191,6 +191,13 @@
   const std::string &scope_qualified_name,
   std::vector &mangled_names) override;
 
+  void
+  FindTypes(lldb_private::ConstString name, lldb_private::ConstString scope,
+const lldb_private::CompilerDeclContext &parent_decl_ctx,
+uint32_t max_matches,
+llvm::DenseSet &searched_symbol_files,
+lldb_private::TypeMap &types) override;
+
   void
   FindTypes(lldb_private::ConstString name,
 const lldb_private::CompilerDeclContext &parent_decl_ctx,
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -9,6 +9,7 @@
 #include "SymbolFileDWARF.h"
 
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Threading.h"
 
@@ -21,6 +22,7 @@
 #include "lldb/Core/StreamFile.h"
 #include "lldb/Core/Value.h"
 #include "lldb/Utility/ArchSpec.h"
+#include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/RegularExpression.h"
 #include "lldb/Utility/Scalar.h"
 #include "lldb/Utility/StreamString.h"
@@ -2419,6 +2421,15 @@
 uint32_t max_matches,
 llvm::DenseSet &searched_symbol_files,
 TypeMap &types) {
+  FindTypes(name, ConstString(), parent_decl_ctx, max_matches,
+searched_symbol_files, types);
+}
+
+void SymbolFileDWARF::FindTypes(
+ConstString name, ConstString scope,
+const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches,
+llvm::DenseSet &searched_symbol_files,
+TypeMap &types) {
   std::lock_guard guard(GetModuleMutex());
   // Make sure we haven't already searched this SymbolFile before.
   if (!searched_symbol_files.insert(this).second)
@@ -2445,10 +2456,25 @@
   if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
 return;
 
+  // prepare string to check against in case this is a fully qualified search
+  bool has_scope = !scope.IsEmpty();
+  llvm::StringRef scope_ref(scope.GetStringRef());
+  if (scope_ref.size() != 2) {
+// DWARFDIE prefixes only variables in global scope with '::'
+scope_ref.consume_front("::");
+  }
+  std::string storage;
+
   m_index->GetTypes(name, [&](DWARFDIE die) {
 if (!DIEInDeclContext(parent_decl_ctx, die))
   return true; // The containing decl contexts don't match
 
+if (has_scope) {
+  die.GetQualifiedName(storage);
+  if (!storage.empty() && !llvm::StringRef(storage).startswith(scope_ref))
+return true;
+}
+
 Type *matching_type = ResolveType(die, true, true);
 if (!matching_type)
   return true;
Index: lldb/source/Core/Module.cpp
===
--- lldb/source/Core/Module.cpp
+++ lldb/source/Core/Module.cpp
@@ -944,6 +944,17 @@
searched_symbol_files, types);
 }
 
+void Module::FindTypes_Impl(
+ConstString name, ConstString scope,
+const CompilerDeclContext &parent_decl_ctx, size_t max_matches,
+llvm::DenseSet &searched_symbol_files,
+TypeMap &types) {

[Lldb-commits] [PATCH] D114627: [lldb] add new overload for SymbolFile::FindTypes that accepts a scope

2021-12-07 Thread Lasse Folger via Phabricator via lldb-commits
lassefolger added inline comments.



Comment at: lldb/source/Symbol/SymbolFile.cpp:148
+  std::string(scope.GetCString()), type_class,
+  true);
+}

I need to change this. This was correct in the first iteration but is no longer 
correct in the current iteration of this change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114627

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


[Lldb-commits] [PATCH] D114627: [lldb] add new overload for SymbolFile::FindTypes that accepts a scope

2021-12-05 Thread Lasse Folger via Phabricator via lldb-commits
lassefolger updated this revision to Diff 391896.
lassefolger added a comment.

rebased on nfc and completed implementation to expose function in API


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114627

Files:
  lldb/include/lldb/Core/Module.h
  lldb/include/lldb/Symbol/SymbolFile.h
  lldb/source/Core/Module.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/source/Symbol/SymbolFile.cpp

Index: lldb/source/Symbol/SymbolFile.cpp
===
--- lldb/source/Symbol/SymbolFile.cpp
+++ lldb/source/Symbol/SymbolFile.cpp
@@ -135,6 +135,19 @@
 llvm::DenseSet &searched_symbol_files,
 TypeMap &types) {}
 
+void SymbolFile::FindTypes(
+ConstString basename, ConstString scope,
+const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches,
+llvm::DenseSet &searched_symbol_files,
+TypeMap &types) {
+  FindTypes(basename, parent_decl_ctx, max_matches, searched_symbol_files,
+types);
+  TypeClass type_class = eTypeClassAny;
+  types.RemoveMismatchedTypes(std::string(basename.GetCString()),
+  std::string(scope.GetCString()), type_class,
+  true);
+}
+
 void SymbolFile::FindTypes(llvm::ArrayRef pattern,
LanguageSet languages,
llvm::DenseSet &searched_symbol_files,
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -191,6 +191,13 @@
   const std::string &scope_qualified_name,
   std::vector &mangled_names) override;
 
+  void
+  FindTypes(lldb_private::ConstString name, lldb_private::ConstString scope,
+const lldb_private::CompilerDeclContext &parent_decl_ctx,
+uint32_t max_matches,
+llvm::DenseSet &searched_symbol_files,
+lldb_private::TypeMap &types) override;
+
   void
   FindTypes(lldb_private::ConstString name,
 const lldb_private::CompilerDeclContext &parent_decl_ctx,
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -9,6 +9,7 @@
 #include "SymbolFileDWARF.h"
 
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Threading.h"
 
@@ -21,6 +22,7 @@
 #include "lldb/Core/StreamFile.h"
 #include "lldb/Core/Value.h"
 #include "lldb/Utility/ArchSpec.h"
+#include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/RegularExpression.h"
 #include "lldb/Utility/Scalar.h"
 #include "lldb/Utility/StreamString.h"
@@ -2419,6 +2421,15 @@
 uint32_t max_matches,
 llvm::DenseSet &searched_symbol_files,
 TypeMap &types) {
+  FindTypes(name, ConstString(), parent_decl_ctx, max_matches,
+searched_symbol_files, types);
+}
+
+void SymbolFileDWARF::FindTypes(
+ConstString name, ConstString scope,
+const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches,
+llvm::DenseSet &searched_symbol_files,
+TypeMap &types) {
   std::lock_guard guard(GetModuleMutex());
   // Make sure we haven't already searched this SymbolFile before.
   if (!searched_symbol_files.insert(this).second)
@@ -2445,10 +2456,21 @@
   if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
 return;
 
+  // prepare string to check against in case this is a fully qualified search
+  bool has_scope = !scope.IsEmpty();
+  llvm::StringRef sc(scope.GetStringRef());
+  std::string storage;
+
   m_index->GetTypes(name, [&](DWARFDIE die) {
 if (!DIEInDeclContext(parent_decl_ctx, die))
   return true; // The containing decl contexts don't match
 
+if (has_scope) {
+  const char *qn = die.GetQualifiedName(storage);
+  if (qn && !llvm::StringRef(qn).startswith(sc))
+return true;
+}
+
 Type *matching_type = ResolveType(die, true, true);
 if (!matching_type)
   return true;
Index: lldb/source/Core/Module.cpp
===
--- lldb/source/Core/Module.cpp
+++ lldb/source/Core/Module.cpp
@@ -944,6 +944,17 @@
searched_symbol_files, types);
 }
 
+void Module::FindTypes_Impl(
+ConstString name, ConstString scope,
+const CompilerDeclContext &parent_decl_ctx, size_t max_matches,
+llvm::DenseSet &searched_symbol_files,
+TypeMap &types) {
+  LLDB_SCOPED_TIMER();
+  if (SymbolFile *symbols = GetSymbolFile())
+symbols->FindTypes(name, scope, parent_decl_ctx, max_matches,
+   searched_symbol_fi

[Lldb-commits] [PATCH] D115110: [lldb][nfc] clang-format some files as preperation for https://reviews.llvm.org/D114627

2021-12-05 Thread Lasse Folger via Phabricator via lldb-commits
lassefolger created this revision.
lassefolger requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115110

Files:
  lldb/include/lldb/Core/Module.h
  lldb/include/lldb/Symbol/SymbolFile.h
  lldb/source/Core/Module.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/source/Symbol/SymbolFile.cpp

Index: lldb/source/Symbol/SymbolFile.cpp
===
--- lldb/source/Symbol/SymbolFile.cpp
+++ lldb/source/Symbol/SymbolFile.cpp
@@ -147,9 +147,11 @@
   // We assert that we have to module lock by trying to acquire the lock from a
   // different thread. Note that we must abort if the result is true to
   // guarantee correctness.
-  assert(std::async(std::launch::async,
-[this] { return this->GetModuleMutex().try_lock(); })
- .get() == false &&
+  assert(std::async(
+ std::launch::async,
+ [this] {
+   return this->GetModuleMutex().try_lock();
+ }).get() == false &&
  "Module is not locked");
 #endif
 }
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -253,8 +253,8 @@
   ExternalTypeModuleMap;
 
   /// Return the list of Clang modules imported by this SymbolFile.
-  const ExternalTypeModuleMap& getExternalTypeModules() const {
-  return m_external_type_modules;
+  const ExternalTypeModuleMap &getExternalTypeModules() const {
+return m_external_type_modules;
   }
 
   virtual DWARFDIE GetDIE(const DIERef &die_ref);
@@ -328,7 +328,6 @@
 return m_parse_time;
   }
 
-
 protected:
   typedef llvm::DenseMap
   DIEToTypePtr;
@@ -428,9 +427,10 @@
   virtual lldb::TypeSP
   FindDefinitionTypeForDWARFDeclContext(const DWARFDeclContext &die_decl_ctx);
 
-  virtual lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(
-  const DWARFDIE &die, lldb_private::ConstString type_name,
-  bool must_be_implementation);
+  virtual lldb::TypeSP
+  FindCompleteObjCDefinitionTypeForDIE(const DWARFDIE &die,
+   lldb_private::ConstString type_name,
+   bool must_be_implementation);
 
   lldb_private::Symbol *
   GetObjCClassSymbol(lldb_private::ConstString objc_class_name);
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -1115,7 +1115,8 @@
   if (const char *include_path = module_die.GetAttributeValueAsString(
   DW_AT_LLVM_include_path, nullptr)) {
 FileSpec include_spec(include_path, dwarf_cu->GetPathStyle());
-MakeAbsoluteAndRemap(include_spec, *dwarf_cu, m_objfile_sp->GetModule());
+MakeAbsoluteAndRemap(include_spec, *dwarf_cu,
+ m_objfile_sp->GetModule());
 module.search_path = ConstString(include_spec.GetPath());
   }
   if (const char *sysroot = dwarf_cu->DIE().GetAttributeValueAsString(
@@ -1942,7 +1943,7 @@
   block_die = function_die.LookupDeepestBlock(file_vm_addr);
   }
 
-  if (!sc.function || ! lookup_block)
+  if (!sc.function || !lookup_block)
 return;
 
   Block &block = sc.function->GetBlock(true);
@@ -2330,7 +2331,8 @@
   if (log) {
 GetObjectFile()->GetModule()->LogMessage(
 log,
-"SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, sc_list)",
+"SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, "
+"sc_list)",
 name.GetCString(), name_type_mask);
   }
 
@@ -2363,8 +2365,7 @@
 log,
 "SymbolFileDWARF::FindFunctions (name=\"%s\", "
 "name_type_mask=0x%x, include_inlines=%d, sc_list) => %u",
-name.GetCString(), name_type_mask, include_inlines,
-num_matches);
+name.GetCString(), name_type_mask, include_inlines, num_matches);
   }
 }
 
Index: lldb/source/Core/Module.cpp
===
--- lldb/source/Core/Module.cpp
+++ lldb/source/Core/Module.cpp
@@ -233,8 +233,8 @@
 Module::Module(const FileSpec &file_spec, const ArchSpec &arch,
const ConstString *object_name, lldb::offset_t object_offset,
const llvm::sys::TimePoint<> &object_mod_time)
-: m_mod_time(FileSystem::Instance().GetModificationTime(file_spec)), m_arch(arch),
-  m_file(file_spec), m_object_offset(object_offset),
+: m_mod_time(FileSystem::Instance().GetModificationTime(file_spec)),
+  m_arch(arch), m_file(file_spec), m_object

[Lldb-commits] [PATCH] D114627: [lldb] add new overload for SymbolFile::FindTypes that accepts a scope

2021-11-30 Thread Lasse Folger via Phabricator via lldb-commits
lassefolger added a comment.

In D114627#3162109 , @shafik wrote:

> Is there a specific use case that motivated this feature?

The motivation is performance. If there are many (>1000) types with the same 
base name this implementation performs much better than the current 
implementation.
This is mostly important for the first access (because later ones use the 
caches results). In our scenarios it reduced the time for the first access from 
86s to 6s and from 12s to 2s. And the access for subsequest accesses from 0.15 
to 0.08 and 0.12 to 0.06.

The primary reason is that Type::GetQualifiedName is executed for every type 
with the same basename when the types are filtered at the end. This triggers 
type completion each type which is very expensive.

I'm still working on this commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114627

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


[Lldb-commits] [PATCH] D114627: [lldb] add new overload for SymbolFile::FindTypes that accepts a scope

2021-11-26 Thread Lasse Folger via Phabricator via lldb-commits
lassefolger updated this revision to Diff 390001.
lassefolger added a comment.

rebased on nfc


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114627

Files:
  lldb/include/lldb/Symbol/SymbolFile.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/source/Symbol/SymbolFile.cpp

Index: lldb/source/Symbol/SymbolFile.cpp
===
--- lldb/source/Symbol/SymbolFile.cpp
+++ lldb/source/Symbol/SymbolFile.cpp
@@ -135,6 +135,19 @@
 llvm::DenseSet &searched_symbol_files,
 TypeMap &types) {}
 
+void SymbolFile::FindTypes(
+ConstString basename, ConstString scope,
+const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches,
+llvm::DenseSet &searched_symbol_files,
+TypeMap &types) {
+  FindTypes(basename, parent_decl_ctx, max_matches, searched_symbol_files,
+types);
+  TypeClass type_class = eTypeClassAny;
+  types.RemoveMismatchedTypes(std::string(basename.GetCString()),
+  std::string(scope.GetCString()), type_class,
+  true);
+}
+
 void SymbolFile::FindTypes(llvm::ArrayRef pattern,
LanguageSet languages,
llvm::DenseSet &searched_symbol_files,
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -191,6 +191,13 @@
   const std::string &scope_qualified_name,
   std::vector &mangled_names) override;
 
+  void
+  FindTypes(lldb_private::ConstString name, lldb_private::ConstString scope,
+const lldb_private::CompilerDeclContext &parent_decl_ctx,
+uint32_t max_matches,
+llvm::DenseSet &searched_symbol_files,
+lldb_private::TypeMap &types) override;
+
   void
   FindTypes(lldb_private::ConstString name,
 const lldb_private::CompilerDeclContext &parent_decl_ctx,
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -21,6 +21,7 @@
 #include "lldb/Core/StreamFile.h"
 #include "lldb/Core/Value.h"
 #include "lldb/Utility/ArchSpec.h"
+#include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/RegularExpression.h"
 #include "lldb/Utility/Scalar.h"
 #include "lldb/Utility/StreamString.h"
@@ -2419,6 +2420,15 @@
 uint32_t max_matches,
 llvm::DenseSet &searched_symbol_files,
 TypeMap &types) {
+  FindTypes(name, ConstString(), parent_decl_ctx, max_matches,
+searched_symbol_files, types);
+}
+
+void SymbolFileDWARF::FindTypes(
+ConstString name, ConstString scope,
+const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches,
+llvm::DenseSet &searched_symbol_files,
+TypeMap &types) {
   std::lock_guard guard(GetModuleMutex());
   // Make sure we haven't already searched this SymbolFile before.
   if (!searched_symbol_files.insert(this).second)
@@ -2445,10 +2455,16 @@
   if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
 return;
 
+  const char *sc = scope.AsCString("");
+  std::string s;
   m_index->GetTypes(name, [&](DWARFDIE die) {
 if (!DIEInDeclContext(parent_decl_ctx, die))
   return true; // The containing decl contexts don't match
 
+const char *qn = die.GetQualifiedName(s);
+if (strncmp(sc, qn, strlen(sc)))
+  return true;
+
 Type *matching_type = ResolveType(die, true, true);
 if (!matching_type)
   return true;
Index: lldb/include/lldb/Symbol/SymbolFile.h
===
--- lldb/include/lldb/Symbol/SymbolFile.h
+++ lldb/include/lldb/Symbol/SymbolFile.h
@@ -235,6 +235,15 @@
 llvm::DenseSet &searched_symbol_files,
 TypeMap &types);
 
+  // Find types in a specific scope.
+  // \param scope
+  // Must be either the fully qualified scope (without leading ::) or empty
+  virtual void
+  FindTypes(ConstString name, ConstString scope,
+const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches,
+llvm::DenseSet &searched_symbol_files,
+TypeMap &types);
+
   /// Find types specified by a CompilerContextPattern.
   /// \param languages
   /// Only return results in these languages.
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D114627: [lldb] add new overload for SymbolFile::FindTypes that accepts a scope

2021-11-26 Thread Lasse Folger via Phabricator via lldb-commits
lassefolger created this revision.
lassefolger added reviewers: werat, teemperor.
lassefolger requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Searching for fully qualified types in a SymbolFile can be inefficient
if it contains many types with the same basename. This is because the
SymbolFile does not offer and an interface to search for qualified
types. To get qualified typed you first need to query all types with the
same basename and then filter based on the scope.

This change introduces a new overload that accepts a scope which the
SymbolFile implementations can use to return filtered by scope.

This change also includes an implementation for DWARF that uses this
scope for filtering. All other implementation use the overload without
scope and filter afterwards.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114627

Files:
  lldb/include/lldb/Symbol/SymbolFile.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/source/Symbol/SymbolFile.cpp

Index: lldb/source/Symbol/SymbolFile.cpp
===
--- lldb/source/Symbol/SymbolFile.cpp
+++ lldb/source/Symbol/SymbolFile.cpp
@@ -135,6 +135,19 @@
 llvm::DenseSet &searched_symbol_files,
 TypeMap &types) {}
 
+void SymbolFile::FindTypes(
+ConstString basename, ConstString scope,
+const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches,
+llvm::DenseSet &searched_symbol_files,
+TypeMap &types) {
+  FindTypes(basename, parent_decl_ctx, max_matches, searched_symbol_files,
+types);
+  TypeClass type_class = eTypeClassAny;
+  types.RemoveMismatchedTypes(std::string(basename.GetCString()),
+  std::string(scope.GetCString()), type_class,
+  true);
+}
+
 void SymbolFile::FindTypes(llvm::ArrayRef pattern,
LanguageSet languages,
llvm::DenseSet &searched_symbol_files,
@@ -147,9 +160,11 @@
   // We assert that we have to module lock by trying to acquire the lock from a
   // different thread. Note that we must abort if the result is true to
   // guarantee correctness.
-  assert(std::async(std::launch::async,
-[this] { return this->GetModuleMutex().try_lock(); })
- .get() == false &&
+  assert(std::async(
+ std::launch::async,
+ [this] {
+   return this->GetModuleMutex().try_lock();
+ }).get() == false &&
  "Module is not locked");
 #endif
 }
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -191,6 +191,13 @@
   const std::string &scope_qualified_name,
   std::vector &mangled_names) override;
 
+  void
+  FindTypes(lldb_private::ConstString name, lldb_private::ConstString scope,
+const lldb_private::CompilerDeclContext &parent_decl_ctx,
+uint32_t max_matches,
+llvm::DenseSet &searched_symbol_files,
+lldb_private::TypeMap &types) override;
+
   void
   FindTypes(lldb_private::ConstString name,
 const lldb_private::CompilerDeclContext &parent_decl_ctx,
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -21,6 +21,7 @@
 #include "lldb/Core/StreamFile.h"
 #include "lldb/Core/Value.h"
 #include "lldb/Utility/ArchSpec.h"
+#include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/RegularExpression.h"
 #include "lldb/Utility/Scalar.h"
 #include "lldb/Utility/StreamString.h"
@@ -1115,7 +1116,8 @@
   if (const char *include_path = module_die.GetAttributeValueAsString(
   DW_AT_LLVM_include_path, nullptr)) {
 FileSpec include_spec(include_path, dwarf_cu->GetPathStyle());
-MakeAbsoluteAndRemap(include_spec, *dwarf_cu, m_objfile_sp->GetModule());
+MakeAbsoluteAndRemap(include_spec, *dwarf_cu,
+ m_objfile_sp->GetModule());
 module.search_path = ConstString(include_spec.GetPath());
   }
   if (const char *sysroot = dwarf_cu->DIE().GetAttributeValueAsString(
@@ -1942,7 +1944,7 @@
   block_die = function_die.LookupDeepestBlock(file_vm_addr);
   }
 
-  if (!sc.function || ! lookup_block)
+  if (!sc.function || !lookup_block)
 return;
 
   Block &block = sc.function->GetBlock(true);
@@ -2330,7 +2332,8 @@
   if (log) {
 GetObjectFile()->GetModule()->LogMessage(
 log,
-"SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, sc_list)",
+"SymbolFileDWAR

[Lldb-commits] [PATCH] D111715: [WIP] [lldb] change name demangling to be consistent between windows and linx

2021-10-18 Thread Lasse Folger via Phabricator via lldb-commits
lassefolger updated this revision to Diff 380435.
lassefolger added a comment.

rebased after NFC


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111715

Files:
  lldb/source/Core/Mangled.cpp
  llvm/include/llvm/Demangle/Demangle.h
  llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
  llvm/lib/Demangle/MicrosoftDemangle.cpp
  llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
  llvm/test/Demangle/ms-options.test
  llvm/tools/llvm-undname/llvm-undname.cpp

Index: llvm/tools/llvm-undname/llvm-undname.cpp
===
--- llvm/tools/llvm-undname/llvm-undname.cpp
+++ llvm/tools/llvm-undname/llvm-undname.cpp
@@ -46,6 +46,9 @@
 cl::opt NoMemberType("no-member-type", cl::Optional,
cl::desc("skip member types"), cl::Hidden,
cl::init(false), cl::cat(UndNameCategory));
+cl::opt NoVariableType("no-variable-type", cl::Optional,
+ cl::desc("skip variable types"), cl::Hidden,
+ cl::init(false), cl::cat(UndNameCategory));
 cl::opt RawFile("raw-file", cl::Optional,
  cl::desc("for fuzzer data"), cl::Hidden,
  cl::cat(UndNameCategory));
@@ -68,6 +71,8 @@
 Flags = MSDemangleFlags(Flags | MSDF_NoReturnType);
   if (NoMemberType)
 Flags = MSDemangleFlags(Flags | MSDF_NoMemberType);
+  if (NoVariableType)
+Flags = MSDemangleFlags(Flags | MSDF_NoVariableType);
 
   size_t NRead;
   char *ResultBuf =
Index: llvm/test/Demangle/ms-options.test
===
--- llvm/test/Demangle/ms-options.test
+++ llvm/test/Demangle/ms-options.test
@@ -1,14 +1,43 @@
-; RUN: llvm-undname < %s | FileCheck %s
-; RUN: llvm-undname --no-calling-convention < %s | FileCheck %s --check-prefix=CHECK-NO-CALLING-CONV
-; RUN: llvm-undname --no-return-type < %s | FileCheck %s --check-prefix=CHECK-NO-RETURN
-; RUN: llvm-undname --no-access-specifier < %s | FileCheck %s --check-prefix=CHECK-NO-ACCESS
-; RUN: llvm-undname --no-member-type < %s | FileCheck %s --check-prefix=CHECK-NO-MEMBER-TYPE
-; RUN: llvm-undname --no-calling-convention --no-return-type --no-access-specifier --no-member-type < %s | FileCheck %s --check-prefix=CHECK-NO-ALL
-
-?func@MyClass@@UEAAHHH@Z
-; CHECK: public: virtual int __cdecl MyClass::func(int, int)
-; CHECK-NO-CALLING-CONV: public: virtual int MyClass::func(int, int)
-; CHECK-NO-RETURN: public: virtual __cdecl MyClass::func(int, int)
-; CHECK-NO-ACCESS: {{^}}virtual int __cdecl MyClass::func(int, int)
-; CHECK-NO-MEMBER-TYPE: public: int __cdecl MyClass::func(int, int)
-; CHECK-NO-ALL: {{^}}MyClass::func(int, int)
+; RUN: llvm-undname < %s | FileCheck %s
+; RUN: llvm-undname --no-calling-convention < %s | FileCheck %s --check-prefix=CHECK-NO-CALLING-CONV
+; RUN: llvm-undname --no-return-type < %s | FileCheck %s --check-prefix=CHECK-NO-RETURN
+; RUN: llvm-undname --no-access-specifier < %s | FileCheck %s --check-prefix=CHECK-NO-ACCESS
+; RUN: llvm-undname --no-member-type < %s | FileCheck %s --check-prefix=CHECK-NO-MEMBER-TYPE
+; RUN: llvm-undname --no-variable-type < %s | FileCheck %s --check-prefix=CHECK-NO-VARIABLE-TYPE
+; RUN: llvm-undname --no-calling-convention --no-return-type --no-access-specifier --no-member-type --no-variable-type < %s | FileCheck %s --check-prefix=CHECK-NO-ALL
+
+?func@MyClass@@UEAAHHH@Z
+; CHECK: public: virtual int __cdecl MyClass::func(int, int)
+; CHECK-NO-CALLING-CONV: public: virtual int MyClass::func(int, int)
+; CHECK-NO-RETURN: public: virtual __cdecl MyClass::func(int, int)
+; CHECK-NO-ACCESS: {{^}}virtual int __cdecl MyClass::func(int, int)
+; CHECK-NO-MEMBER-TYPE: public: int __cdecl MyClass::func(int, int)
+; CHECK-NO-VARIABLE-TYPE: public: virtual int __cdecl MyClass::func(int, int)
+; CHECK-NO-ALL: {{^}}MyClass::func(int, int)
+
+?array2d@@3PAY09HA
+; CHECK: int (*array2d)[10]
+; CHECK-NO-CALLING-CONV: int (*array2d)[10]
+; CHECK-NO-RETURN: int (*array2d)[10]
+; CHECK-NO-ACCESS: int (*array2d)[10]
+; CHECK-NO-MEMBER-TYPE: int (*array2d)[10]
+; CHECK-NO-VARIABLE-TYPE: array2d
+; CHECK-NO-ALL: array2d
+
+?a@abc@@3PAY09HA
+; CHECK: int (*abc::a)[10]
+; CHECK-NO-CALLING-CONV: int (*abc::a)[10]
+; CHECK-NO-RETURN: int (*abc::a)[10]
+; CHECK-NO-ACCESS: int (*abc::a)[10]
+; CHECK-NO-MEMBER-TYPE: int (*abc::a)[10]
+; CHECK-NO-VARIABLE-TYPE: abc::a
+; CHECK-NO-ALL: abc::a
+
+?x@@3PEAEEA
+; CHECK: unsigned char *x
+; CHECK-NO-CALLING-CONV: unsigned char *x
+; CHECK-NO-RETURN: unsigned char *x
+; CHECK-NO-ACCESS: unsigned char *x
+; CHECK-NO-MEMBER-TYPE: unsigned char *x
+; CHECK-NO-VARIABLE-TYPE: x
+; CHECK-NO-ALL: x
Index: llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
+++ llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
@@ -6

[Lldb-commits] [PATCH] D111715: [WIP] [lldb] change name demangling to be consistent between windows and linx

2021-10-16 Thread Lasse Folger via Phabricator via lldb-commits
lassefolger added a comment.

created a NFC for formatting: https://reviews.llvm.org/D111934


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111715

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


[Lldb-commits] [PATCH] D111934: [NFC] clang format change

2021-10-16 Thread Lasse Folger via Phabricator via lldb-commits
lassefolger created this revision.
lassefolger added reviewers: teemperor, werat.
lassefolger requested review of this revision.
Herald added projects: LLDB, LLVM.
Herald added subscribers: llvm-commits, lldb-commits.

clang format on some demangling files


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111934

Files:
  lldb/source/Core/Mangled.cpp
  llvm/include/llvm/Demangle/Demangle.h


Index: llvm/include/llvm/Demangle/Demangle.h
===
--- llvm/include/llvm/Demangle/Demangle.h
+++ llvm/include/llvm/Demangle/Demangle.h
@@ -31,7 +31,6 @@
 char *itaniumDemangle(const char *mangled_name, char *buf, size_t *n,
   int *status);
 
-
 enum MSDemangleFlags {
   MSDF_None = 0,
   MSDF_DumpBackrefs = 1 << 0,
@@ -53,9 +52,9 @@
 /// receives the size of the demangled string on output if n_buf is not 
nullptr.
 /// status receives one of the demangle_ enum entries above if it's not 
nullptr.
 /// Flags controls various details of the demangled representation.
-char *microsoftDemangle(const char *mangled_name, size_t *n_read,
-char *buf, size_t *n_buf,
-int *status, MSDemangleFlags Flags = MSDF_None);
+char *microsoftDemangle(const char *mangled_name, size_t *n_read, char *buf,
+size_t *n_buf, int *status,
+MSDemangleFlags Flags = MSDF_None);
 
 // Demangles a Rust v0 mangled symbol. The API follows that of __cxa_demangle.
 char *rustDemangle(const char *MangledName, char *Buf, size_t *N, int *Status);
@@ -118,6 +117,7 @@
   bool isSpecialName() const;
 
   ~ItaniumPartialDemangler();
+
 private:
   void *RootNode;
   void *Context;
Index: lldb/source/Core/Mangled.cpp
===
--- lldb/source/Core/Mangled.cpp
+++ lldb/source/Core/Mangled.cpp
@@ -260,7 +260,8 @@
   if (m_mangled && m_demangled.IsNull()) {
 // Don't bother running anything that isn't mangled
 const char *mangled_name = m_mangled.GetCString();
-ManglingScheme mangling_scheme = 
GetManglingScheme(m_mangled.GetStringRef());
+ManglingScheme mangling_scheme =
+GetManglingScheme(m_mangled.GetStringRef());
 if (mangling_scheme != eManglingSchemeNone &&
 !m_mangled.GetMangledCounterpart(m_demangled)) {
   // We didn't already mangle this name, demangle it and if all goes well
@@ -296,8 +297,7 @@
   return m_demangled;
 }
 
-ConstString
-Mangled::GetDisplayDemangledName() const {
+ConstString Mangled::GetDisplayDemangledName() const {
   return GetDemangledName();
 }
 


Index: llvm/include/llvm/Demangle/Demangle.h
===
--- llvm/include/llvm/Demangle/Demangle.h
+++ llvm/include/llvm/Demangle/Demangle.h
@@ -31,7 +31,6 @@
 char *itaniumDemangle(const char *mangled_name, char *buf, size_t *n,
   int *status);
 
-
 enum MSDemangleFlags {
   MSDF_None = 0,
   MSDF_DumpBackrefs = 1 << 0,
@@ -53,9 +52,9 @@
 /// receives the size of the demangled string on output if n_buf is not nullptr.
 /// status receives one of the demangle_ enum entries above if it's not nullptr.
 /// Flags controls various details of the demangled representation.
-char *microsoftDemangle(const char *mangled_name, size_t *n_read,
-char *buf, size_t *n_buf,
-int *status, MSDemangleFlags Flags = MSDF_None);
+char *microsoftDemangle(const char *mangled_name, size_t *n_read, char *buf,
+size_t *n_buf, int *status,
+MSDemangleFlags Flags = MSDF_None);
 
 // Demangles a Rust v0 mangled symbol. The API follows that of __cxa_demangle.
 char *rustDemangle(const char *MangledName, char *Buf, size_t *N, int *Status);
@@ -118,6 +117,7 @@
   bool isSpecialName() const;
 
   ~ItaniumPartialDemangler();
+
 private:
   void *RootNode;
   void *Context;
Index: lldb/source/Core/Mangled.cpp
===
--- lldb/source/Core/Mangled.cpp
+++ lldb/source/Core/Mangled.cpp
@@ -260,7 +260,8 @@
   if (m_mangled && m_demangled.IsNull()) {
 // Don't bother running anything that isn't mangled
 const char *mangled_name = m_mangled.GetCString();
-ManglingScheme mangling_scheme = GetManglingScheme(m_mangled.GetStringRef());
+ManglingScheme mangling_scheme =
+GetManglingScheme(m_mangled.GetStringRef());
 if (mangling_scheme != eManglingSchemeNone &&
 !m_mangled.GetMangledCounterpart(m_demangled)) {
   // We didn't already mangle this name, demangle it and if all goes well
@@ -296,8 +297,7 @@
   return m_demangled;
 }
 
-ConstString
-Mangled::GetDisplayDemangledName() const {
+ConstString Mangled::GetDisplayDemangledName() const {
   return GetDemangledName();
 }
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https:

[Lldb-commits] [PATCH] D111715: [WIP] [lldb] change name demangling to be consistent between windows and linx

2021-10-16 Thread Lasse Folger via Phabricator via lldb-commits
lassefolger updated this revision to Diff 380155.
lassefolger added a comment.

add tests for the change and adjust description to include examples


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111715

Files:
  lldb/source/Core/Mangled.cpp
  llvm/include/llvm/Demangle/Demangle.h
  llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
  llvm/lib/Demangle/MicrosoftDemangle.cpp
  llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
  llvm/test/Demangle/ms-options.test
  llvm/tools/llvm-undname/llvm-undname.cpp

Index: llvm/tools/llvm-undname/llvm-undname.cpp
===
--- llvm/tools/llvm-undname/llvm-undname.cpp
+++ llvm/tools/llvm-undname/llvm-undname.cpp
@@ -46,6 +46,9 @@
 cl::opt NoMemberType("no-member-type", cl::Optional,
cl::desc("skip member types"), cl::Hidden,
cl::init(false), cl::cat(UndNameCategory));
+cl::opt NoVariableType("no-variable-type", cl::Optional,
+ cl::desc("skip variable types"), cl::Hidden,
+ cl::init(false), cl::cat(UndNameCategory));
 cl::opt RawFile("raw-file", cl::Optional,
  cl::desc("for fuzzer data"), cl::Hidden,
  cl::cat(UndNameCategory));
@@ -68,6 +71,8 @@
 Flags = MSDemangleFlags(Flags | MSDF_NoReturnType);
   if (NoMemberType)
 Flags = MSDemangleFlags(Flags | MSDF_NoMemberType);
+  if (NoVariableType)
+Flags = MSDemangleFlags(Flags | MSDF_NoVariableType);
 
   size_t NRead;
   char *ResultBuf =
Index: llvm/test/Demangle/ms-options.test
===
--- llvm/test/Demangle/ms-options.test
+++ llvm/test/Demangle/ms-options.test
@@ -1,14 +1,43 @@
-; RUN: llvm-undname < %s | FileCheck %s
-; RUN: llvm-undname --no-calling-convention < %s | FileCheck %s --check-prefix=CHECK-NO-CALLING-CONV
-; RUN: llvm-undname --no-return-type < %s | FileCheck %s --check-prefix=CHECK-NO-RETURN
-; RUN: llvm-undname --no-access-specifier < %s | FileCheck %s --check-prefix=CHECK-NO-ACCESS
-; RUN: llvm-undname --no-member-type < %s | FileCheck %s --check-prefix=CHECK-NO-MEMBER-TYPE
-; RUN: llvm-undname --no-calling-convention --no-return-type --no-access-specifier --no-member-type < %s | FileCheck %s --check-prefix=CHECK-NO-ALL
-
-?func@MyClass@@UEAAHHH@Z
-; CHECK: public: virtual int __cdecl MyClass::func(int, int)
-; CHECK-NO-CALLING-CONV: public: virtual int MyClass::func(int, int)
-; CHECK-NO-RETURN: public: virtual __cdecl MyClass::func(int, int)
-; CHECK-NO-ACCESS: {{^}}virtual int __cdecl MyClass::func(int, int)
-; CHECK-NO-MEMBER-TYPE: public: int __cdecl MyClass::func(int, int)
-; CHECK-NO-ALL: {{^}}MyClass::func(int, int)
+; RUN: llvm-undname < %s | FileCheck %s
+; RUN: llvm-undname --no-calling-convention < %s | FileCheck %s --check-prefix=CHECK-NO-CALLING-CONV
+; RUN: llvm-undname --no-return-type < %s | FileCheck %s --check-prefix=CHECK-NO-RETURN
+; RUN: llvm-undname --no-access-specifier < %s | FileCheck %s --check-prefix=CHECK-NO-ACCESS
+; RUN: llvm-undname --no-member-type < %s | FileCheck %s --check-prefix=CHECK-NO-MEMBER-TYPE
+; RUN: llvm-undname --no-variable-type < %s | FileCheck %s --check-prefix=CHECK-NO-VARIABLE-TYPE
+; RUN: llvm-undname --no-calling-convention --no-return-type --no-access-specifier --no-member-type --no-variable-type < %s | FileCheck %s --check-prefix=CHECK-NO-ALL
+
+?func@MyClass@@UEAAHHH@Z
+; CHECK: public: virtual int __cdecl MyClass::func(int, int)
+; CHECK-NO-CALLING-CONV: public: virtual int MyClass::func(int, int)
+; CHECK-NO-RETURN: public: virtual __cdecl MyClass::func(int, int)
+; CHECK-NO-ACCESS: {{^}}virtual int __cdecl MyClass::func(int, int)
+; CHECK-NO-MEMBER-TYPE: public: int __cdecl MyClass::func(int, int)
+; CHECK-NO-VARIABLE-TYPE: public: virtual int __cdecl MyClass::func(int, int)
+; CHECK-NO-ALL: {{^}}MyClass::func(int, int)
+
+?array2d@@3PAY09HA
+; CHECK: int (*array2d)[10]
+; CHECK-NO-CALLING-CONV: int (*array2d)[10]
+; CHECK-NO-RETURN: int (*array2d)[10]
+; CHECK-NO-ACCESS: int (*array2d)[10]
+; CHECK-NO-MEMBER-TYPE: int (*array2d)[10]
+; CHECK-NO-VARIABLE-TYPE: array2d
+; CHECK-NO-ALL: array2d
+
+?a@abc@@3PAY09HA
+; CHECK: int (*abc::a)[10]
+; CHECK-NO-CALLING-CONV: int (*abc::a)[10]
+; CHECK-NO-RETURN: int (*abc::a)[10]
+; CHECK-NO-ACCESS: int (*abc::a)[10]
+; CHECK-NO-MEMBER-TYPE: int (*abc::a)[10]
+; CHECK-NO-VARIABLE-TYPE: abc::a
+; CHECK-NO-ALL: abc::a
+
+?x@@3PEAEEA
+; CHECK: unsigned char *x
+; CHECK-NO-CALLING-CONV: unsigned char *x
+; CHECK-NO-RETURN: unsigned char *x
+; CHECK-NO-ACCESS: unsigned char *x
+; CHECK-NO-MEMBER-TYPE: unsigned char *x
+; CHECK-NO-VARIABLE-TYPE: x
+; CHECK-NO-ALL: x
Index: llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
+++ 

[Lldb-commits] [PATCH] D111715: [WIP] [lldb] change name demangling to be consistent between windows and linx

2021-10-13 Thread Lasse Folger via Phabricator via lldb-commits
lassefolger created this revision.
lassefolger added reviewers: teemperor, werat.
Herald added a subscriber: hiraditya.
lassefolger requested review of this revision.
Herald added projects: LLDB, LLVM.
Herald added subscribers: llvm-commits, lldb-commits.

When printing names in lldb on windows these names contain the full type 
information while on linux only the name is contained.

This change introduces a flag in the Microsoft demangler to control if the type 
information should be included.

For globals there is a second inconsistency which is not yet addressed by this 
change. On linux globals (in global namespace) are prefixed with :: while on 
windows they are not.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111715

Files:
  lldb/source/Core/Mangled.cpp
  llvm/include/llvm/Demangle/Demangle.h
  llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
  llvm/lib/Demangle/MicrosoftDemangle.cpp
  llvm/lib/Demangle/MicrosoftDemangleNodes.cpp

Index: llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
+++ llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
@@ -613,12 +613,12 @@
   if (!(Flags & OF_NoMemberType) && IsStatic)
 OS << "static ";
 
-  if (Type) {
+  if (!(Flags & OF_NoVariableType) && Type) {
 Type->outputPre(OS, Flags);
 outputSpaceIfNecessary(OS);
   }
   Name->output(OS, Flags);
-  if (Type)
+  if (!(Flags & OF_NoVariableType) && Type)
 Type->outputPost(OS, Flags);
 }
 
Index: llvm/lib/Demangle/MicrosoftDemangle.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangle.cpp
+++ llvm/lib/Demangle/MicrosoftDemangle.cpp
@@ -2361,6 +2361,8 @@
 OF = OutputFlags(OF | OF_NoReturnType);
   if (Flags & MSDF_NoMemberType)
 OF = OutputFlags(OF | OF_NoMemberType);
+  if (Flags & MSDF_NoVariableType)
+OF = OutputFlags(OF | OF_NoVariableType);
 
   int InternalStatus = demangle_success;
   if (D.Error)
Index: llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
===
--- llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
+++ llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
@@ -80,6 +80,7 @@
   OF_NoAccessSpecifier = 4,
   OF_NoMemberType = 8,
   OF_NoReturnType = 16,
+  OF_NoVariableType = 32,
 };
 
 // Types
Index: llvm/include/llvm/Demangle/Demangle.h
===
--- llvm/include/llvm/Demangle/Demangle.h
+++ llvm/include/llvm/Demangle/Demangle.h
@@ -31,7 +31,6 @@
 char *itaniumDemangle(const char *mangled_name, char *buf, size_t *n,
   int *status);
 
-
 enum MSDemangleFlags {
   MSDF_None = 0,
   MSDF_DumpBackrefs = 1 << 0,
@@ -39,6 +38,7 @@
   MSDF_NoCallingConvention = 1 << 2,
   MSDF_NoReturnType = 1 << 3,
   MSDF_NoMemberType = 1 << 4,
+  MSDF_NoVariableType = 1 << 5,
 };
 
 /// Demangles the Microsoft symbol pointed at by mangled_name and returns it.
Index: lldb/source/Core/Mangled.cpp
===
--- lldb/source/Core/Mangled.cpp
+++ lldb/source/Core/Mangled.cpp
@@ -131,9 +131,9 @@
 static char *GetMSVCDemangledStr(const char *M) {
   char *demangled_cstr = llvm::microsoftDemangle(
   M, nullptr, nullptr, nullptr, nullptr,
-  llvm::MSDemangleFlags(llvm::MSDF_NoAccessSpecifier |
-llvm::MSDF_NoCallingConvention |
-llvm::MSDF_NoMemberType));
+  llvm::MSDemangleFlags(
+  llvm::MSDF_NoAccessSpecifier | llvm::MSDF_NoCallingConvention |
+  llvm::MSDF_NoMemberType | llvm::MSDF_NoVariableType));
 
   if (Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_DEMANGLE)) {
 if (demangled_cstr && demangled_cstr[0])
@@ -260,7 +260,8 @@
   if (m_mangled && m_demangled.IsNull()) {
 // Don't bother running anything that isn't mangled
 const char *mangled_name = m_mangled.GetCString();
-ManglingScheme mangling_scheme = GetManglingScheme(m_mangled.GetStringRef());
+ManglingScheme mangling_scheme =
+GetManglingScheme(m_mangled.GetStringRef());
 if (mangling_scheme != eManglingSchemeNone &&
 !m_mangled.GetMangledCounterpart(m_demangled)) {
   // We didn't already mangle this name, demangle it and if all goes well
@@ -296,8 +297,7 @@
   return m_demangled;
 }
 
-ConstString
-Mangled::GetDisplayDemangledName() const {
+ConstString Mangled::GetDisplayDemangledName() const {
   return GetDemangledName();
 }
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits