[Lldb-commits] [PATCH] D41086: [lldb] Check that a regex is valid before searching by regex for a symbol in a pdb.
Aaron Smith via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Sat Dec 16 12:23:07 PST 2017
asmith updated this revision to Diff 127255.
asmith added a comment.
This changes SymbolFilePDB::FindTypesByRegex () to take an lldb_private::RegularExpression as the argument and removes the use of the STL regex.
Repository:
rL LLVM
https://reviews.llvm.org/D41086
Files:
source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
Index: source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
===================================================================
--- source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
+++ source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
@@ -172,7 +172,8 @@
const llvm::pdb::PDBSymbolCompiland &cu,
llvm::DenseMap<uint32_t, uint32_t> &index_map) const;
- void FindTypesByRegex(const std::string ®ex, uint32_t max_matches,
+ void FindTypesByRegex(const lldb_private::RegularExpression ®ex,
+ uint32_t max_matches,
lldb_private::TypeMap &types);
void FindTypesByName(const std::string &name, uint32_t max_matches,
Index: source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
===================================================================
--- source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
+++ source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
@@ -251,7 +251,8 @@
return nullptr;
lldb::TypeSP result = pdb->CreateLLDBTypeFromPDBType(*pdb_type);
- m_types.insert(std::make_pair(type_uid, result));
+ if (result.get())
+ m_types.insert(std::make_pair(type_uid, result));
return result.get();
}
@@ -389,23 +390,17 @@
// If this might be a regex, we have to return EVERY symbol and process them
// one by one, which is going to destroy performance on large PDB files. So
// try really hard not to use a regex match.
- bool is_regex = false;
- if (name_str.find_first_of("[]?*.-+\\") != std::string::npos) {
- // Trying to compile an invalid regex could throw an exception.
- // Only search by regex when it's valid.
- lldb_private::RegularExpression name_regex(name_str);
- is_regex = name_regex.IsValid();
- }
- if (is_regex)
- FindTypesByRegex(name_str, max_matches, types);
+ if (name_str.find_first_of("[]?*.-+\\") != std::string::npos)
+ FindTypesByRegex(RegularExpression(name_str), max_matches, types);
else
FindTypesByName(name_str, max_matches, types);
return types.GetSize();
}
-void SymbolFilePDB::FindTypesByRegex(const std::string ®ex,
- uint32_t max_matches,
- lldb_private::TypeMap &types) {
+void
+SymbolFilePDB::FindTypesByRegex(const lldb_private::RegularExpression ®ex,
+ uint32_t max_matches,
+ lldb_private::TypeMap &types) {
// When searching by regex, we need to go out of our way to limit the search
// space as much as possible since this searches EVERYTHING in the PDB,
// manually doing regex comparisons. PDB library isn't optimized for regex
@@ -417,8 +412,6 @@
auto global = m_session_up->getGlobalScope();
std::unique_ptr<IPDBEnumSymbols> results;
- std::regex re(regex);
-
uint32_t matches = 0;
for (auto tag : tags_to_search) {
@@ -441,7 +434,7 @@
continue;
}
- if (!std::regex_match(type_name, re))
+ if (!regex.Execute(type_name))
continue;
// This should cause the type to get cached and stored in the `m_types`
Index: source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
===================================================================
--- source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
+++ source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
@@ -124,6 +124,8 @@
} else if (auto type_def = llvm::dyn_cast<PDBSymbolTypeTypedef>(&type)) {
lldb_private::Type *target_type =
m_ast.GetSymbolFile()->ResolveTypeUID(type_def->getTypeId());
+ if (!target_type)
+ return nullptr;
std::string name = type_def->getName();
uint64_t bytes = type_def->getLength();
if (!target_type)
@@ -179,6 +181,8 @@
lldb_private::Type *element_type =
m_ast.GetSymbolFile()->ResolveTypeUID(element_uid);
+ if (!element_type)
+ return nullptr;
CompilerType element_ast_type = element_type->GetFullCompilerType();
CompilerType array_ast_type =
m_ast.CreateArrayType(element_ast_type, num_elements, false);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41086.127255.patch
Type: text/x-patch
Size: 4020 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20171216/3e3a98a2/attachment.bin>
More information about the lldb-commits
mailing list