[Lldb-commits] [lldb] [lldb] Extend FindTypes to optionally search by mangled type name (PR #113007)

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Thu Oct 24 14:47:00 PDT 2024


================
@@ -2758,6 +2758,15 @@ void SymbolFileDWARF::FindTypes(const TypeQuery &query, TypeResults &results) {
         return true; // Keep iterating over index types, language mismatch.
     }
 
+    // Since mangled names are unique, we only need to check if the names are
+    // the same.
+    if (query.GetSearchByMangledName()) {
+      if (die.GetMangledName() == query.GetTypeBasename().GetStringRef())
+        if (Type *matching_type = ResolveType(die, true, true))
+          results.InsertUnique(matching_type->shared_from_this());
+      return !results.Done(query); // Keep iterating if we aren't done.
+    }
----------------
clayborg wrote:

This logic needs doesn't need to check if results are done if we didn't add anything to the results. Maybe this would be more clear?:
```
    if (query.GetSearchByMangledName()) {
      if (die.GetMangledName() != query.GetTypeBasename().GetStringRef()) 
        return true; // Keep iterating over index types, mangled name mismatch.
      if (Type *matching_type = ResolveType(die, true, true)) {
        results.InsertUnique(matching_type->shared_from_this());
        return !results.Done(query); // Keep iterating if we aren't done.
      }
      return true; // Keep iterating over index types, weren't able to resolve this type
    }
```
One other issue is that `DWARFDie::GetMangledName()` will return the `DW_AT_name` if there is no mangled name:
```
const char *DWARFDIE::GetMangledName() const {
  if (IsValid())
    return m_die->GetMangledName(m_cu);
  else
    return nullptr;
}
```
But `const char *DWARFDebugInfoEntry::GetMangledName(const DWARFUnit *cu, bool substitute_name_allowed)` has a boolean option `substitute_name_allowed` that defaults to true. So we should probably also change:
```
const char *DWARFDIE::GetMangledName() const;
```
To have that same option with a default value:
```
const char *DWARFDIE::GetMangledName(bool substitute_name_allowed = true) const
```
And then change your code to pass in `false` for the `substitute_name_allowed`

https://github.com/llvm/llvm-project/pull/113007


More information about the lldb-commits mailing list