[PDB] Introduce `MSVCUndecoratedNameParser`
This patch introduces the simple MSVCUndecoratedNameParser. It is needed for
parsing names of PDB symbols corresponding to template instantiations. For
example, for the name `operator<<A>'::`2'::B::operator> we can't just split the
name with :: (as it is implemented for now) to retrieve its scopes. This parser
processes such names in a more correct way.
Differential Revision: https://reviews.llvm.org/D52461
llvm-svn: 346213
diff --git a/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
index 6096218..2779aee 100644
--- a/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
+++ b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
@@ -9,6 +9,9 @@
#include "SymbolFilePDB.h"
+#include "PDBASTParser.h"
+#include "PDBLocationToDWARFExpression.h"
+
#include "clang/Lex/Lexer.h"
#include "lldb/Core/Module.h"
@@ -46,9 +49,8 @@
#include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h" // For IsCPPMangledName
+#include "Plugins/Language/CPlusPlus/MSVCUndecoratedNameParser.h"
#include "Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h"
-#include "Plugins/SymbolFile/PDB/PDBASTParser.h"
-#include "Plugins/SymbolFile/PDB/PDBLocationToDWARFExpression.h"
#include <regex>
@@ -1068,7 +1070,7 @@
lldbassert(sc.module_sp.get());
if (!name.GetStringRef().equals(
- PDBASTParser::PDBNameDropScope(pdb_data->getName())))
+ MSVCUndecoratedNameParser::DropScope(pdb_data->getName())))
continue;
sc.comp_unit = ParseCompileUnitForUID(GetCompilandId(*pdb_data)).get();
@@ -1175,22 +1177,11 @@
// Class. We won't bother to check if the parent is UDT or Enum here.
m_func_method_names.Append(ConstString(name), uid);
- ConstString cstr_name(name);
-
// To search a method name, like NS::Class:MemberFunc, LLDB searches
// its base name, i.e. MemberFunc by default. Since PDBSymbolFunc does
// not have inforamtion of this, we extract base names and cache them
// by our own effort.
- llvm::StringRef basename;
- CPlusPlusLanguage::MethodName cpp_method(cstr_name);
- if (cpp_method.IsValid()) {
- llvm::StringRef context;
- basename = cpp_method.GetBasename();
- if (basename.empty())
- CPlusPlusLanguage::ExtractContextAndIdentifier(name.c_str(),
- context, basename);
- }
-
+ llvm::StringRef basename = MSVCUndecoratedNameParser::DropScope(name);
if (!basename.empty())
m_func_base_names.Append(ConstString(basename), uid);
else {
@@ -1203,11 +1194,12 @@
} else {
// Handle not-method symbols.
- // The function name might contain namespace, or its lexical scope. It
- // is not safe to get its base name by applying same scheme as we deal
- // with the method names.
- // FIXME: Remove namespace if function is static in a scope.
- m_func_base_names.Append(ConstString(name), uid);
+ // The function name might contain namespace, or its lexical scope.
+ llvm::StringRef basename = MSVCUndecoratedNameParser::DropScope(name);
+ if (!basename.empty())
+ m_func_base_names.Append(ConstString(basename), uid);
+ else
+ m_func_base_names.Append(ConstString(name), uid);
if (name == "main") {
m_func_full_names.Append(ConstString(name), uid);
@@ -1353,10 +1345,8 @@
searched_symbol_files.clear();
searched_symbol_files.insert(this);
- std::string name_str = name.AsCString();
-
// There is an assumption 'name' is not a regex
- FindTypesByName(name_str, parent_decl_ctx, max_matches, types);
+ FindTypesByName(name.GetStringRef(), parent_decl_ctx, max_matches, types);
return types.GetSize();
}
@@ -1425,7 +1415,7 @@
}
void SymbolFilePDB::FindTypesByName(
- const std::string &name,
+ llvm::StringRef name,
const lldb_private::CompilerDeclContext *parent_decl_ctx,
uint32_t max_matches, lldb_private::TypeMap &types) {
if (!parent_decl_ctx)
@@ -1443,8 +1433,8 @@
if (max_matches > 0 && matches >= max_matches)
break;
- if (PDBASTParser::PDBNameDropScope(result->getRawSymbol().getName()) !=
- name)
+ if (MSVCUndecoratedNameParser::DropScope(
+ result->getRawSymbol().getName()) != name)
continue;
switch (result->getSymTag()) {