Extend FindTypes with CompilerContext to allow filtering by language.

This patch is also motivated by the Swift branch and is effectively NFC for the single-TypeSystem llvm.org branch.

In multi-language projects it is extremely common to have, e.g., a
Clang type and a similarly-named rendition of that same type in
another language. When searching for a type It is much cheaper to pass
a set of supported languages to the SymbolFile than having it
materialize every result and then rejecting the materialized types
that have the wrong language.

Differential Revision: https://reviews.llvm.org/D66546

<rdar://problem/54471165>

This reapplies r369690 with a previously missing constructor for LanguageSet.

llvm-svn: 369710
This commit is contained in:
Adrian Prantl 2019-08-22 21:45:58 +00:00
parent f88dfd8309
commit aa97a89d83
27 changed files with 218 additions and 197 deletions

View File

@ -454,6 +454,14 @@ public:
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
TypeList &types);
/// Find types by name.
///
/// This behaves like the other FindTypes method but allows to
/// specify a DeclContext and a language for the type being searched
/// for.
size_t FindTypes(llvm::ArrayRef<CompilerContext> pattern,
LanguageSet languages, bool append, TypeMap &types);
lldb::TypeSP FindFirstType(const SymbolContext &sc,
ConstString type_name, bool exact_match);

View File

@ -385,10 +385,10 @@ public:
GetInstrumentationRuntimeCreateCallbackForPluginName(ConstString name);
// TypeSystem
static bool RegisterPlugin(
ConstString name, const char *description,
static bool RegisterPlugin(ConstString name, const char *description,
TypeSystemCreateInstance create_callback,
TypeSystemEnumerateSupportedLanguages enumerate_languages_callback);
LanguageSet supported_languages_for_types,
LanguageSet supported_languages_for_expressions);
static bool UnregisterPlugin(TypeSystemCreateInstance create_callback);
@ -398,18 +398,14 @@ public:
static TypeSystemCreateInstance
GetTypeSystemCreateCallbackForPluginName(ConstString name);
static TypeSystemEnumerateSupportedLanguages
GetTypeSystemEnumerateSupportedLanguagesCallbackAtIndex(uint32_t idx);
static LanguageSet GetAllTypeSystemSupportedLanguagesForTypes();
static TypeSystemEnumerateSupportedLanguages
GetTypeSystemEnumerateSupportedLanguagesCallbackForPluginName(
ConstString name);
static LanguageSet GetAllTypeSystemSupportedLanguagesForExpressions();
// REPL
static bool
RegisterPlugin(ConstString name, const char *description,
static bool RegisterPlugin(ConstString name, const char *description,
REPLCreateInstance create_callback,
REPLEnumerateSupportedLanguages enumerate_languages_callback);
LanguageSet supported_languages);
static bool UnregisterPlugin(REPLCreateInstance create_callback);
@ -418,12 +414,7 @@ public:
static REPLCreateInstance
GetREPLCreateCallbackForPluginName(ConstString name);
static REPLEnumerateSupportedLanguages
GetREPLEnumerateSupportedLanguagesCallbackAtIndex(uint32_t idx);
static REPLEnumerateSupportedLanguages
GetREPLSystemEnumerateSupportedLanguagesCallbackForPluginName(
ConstString name);
static LanguageSet GetREPLAllTypeSystemSupportedLanguages();
// Some plug-ins might register a DebuggerInitializeCallback callback when
// registering the plug-in. After a new Debugger instance is created, this
@ -441,32 +432,28 @@ public:
ConstString description, bool is_global_property);
static lldb::OptionValuePropertiesSP
GetSettingForPlatformPlugin(Debugger &debugger,
ConstString setting_name);
GetSettingForPlatformPlugin(Debugger &debugger, ConstString setting_name);
static bool CreateSettingForPlatformPlugin(
Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
ConstString description, bool is_global_property);
static lldb::OptionValuePropertiesSP
GetSettingForProcessPlugin(Debugger &debugger,
ConstString setting_name);
GetSettingForProcessPlugin(Debugger &debugger, ConstString setting_name);
static bool CreateSettingForProcessPlugin(
Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
ConstString description, bool is_global_property);
static lldb::OptionValuePropertiesSP
GetSettingForSymbolFilePlugin(Debugger &debugger,
ConstString setting_name);
GetSettingForSymbolFilePlugin(Debugger &debugger, ConstString setting_name);
static bool CreateSettingForSymbolFilePlugin(
Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
ConstString description, bool is_global_property);
static lldb::OptionValuePropertiesSP
GetSettingForJITLoaderPlugin(Debugger &debugger,
ConstString setting_name);
GetSettingForJITLoaderPlugin(Debugger &debugger, ConstString setting_name);
static bool CreateSettingForJITLoaderPlugin(
Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,

View File

@ -68,9 +68,8 @@ public:
static lldb::TypeSystemSP CreateInstance(lldb::LanguageType language,
Module *module, Target *target);
static void EnumerateSupportedLanguages(
std::set<lldb::LanguageType> &languages_for_types,
std::set<lldb::LanguageType> &languages_for_expressions);
static LanguageSet GetSupportedLanguagesForTypes();
static LanguageSet GetSupportedLanguagesForExpressions();
static void Initialize();

View File

@ -17,6 +17,7 @@
#include "lldb/Symbol/SourceModule.h"
#include "lldb/Symbol/Type.h"
#include "lldb/Symbol/TypeList.h"
#include "lldb/Symbol/TypeSystem.h"
#include "lldb/lldb-private.h"
#include "llvm/ADT/DenseSet.h"
@ -189,7 +190,11 @@ public:
bool append, uint32_t max_matches,
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
TypeMap &types);
virtual size_t FindTypes(llvm::ArrayRef<CompilerContext> pattern, bool append,
/// Find types specified by a CompilerContextPattern.
/// \param languages Only return results in these languages.
virtual size_t FindTypes(llvm::ArrayRef<CompilerContext> pattern,
LanguageSet languages, bool append,
TypeMap &types);
virtual void

View File

@ -15,6 +15,7 @@
#include <string>
#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/SmallBitVector.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Error.h"
@ -30,7 +31,24 @@ class PDBASTParser;
namespace lldb_private {
// Interface for representing the Type Systems in different languages.
/// A SmallBitVector that represents a set of source languages (\p
/// lldb::LanguageType). Each lldb::LanguageType is represented by
/// the bit with the position of its enumerator. The largest
/// LanguageType is < 64, so this is space-efficient and on 64-bit
/// architectures a LanguageSet can be completely stack-allocated.
struct LanguageSet {
llvm::SmallBitVector bitvector;
LanguageSet();
/// If the set contains a single language only, return it.
llvm::Optional<lldb::LanguageType> GetSingularLanguage();
void Insert(lldb::LanguageType language);
bool Empty() const;
size_t Size() const;
bool operator[](unsigned i) const;
};
/// Interface for representing the Type Systems in different languages.
class TypeSystem : public PluginInterface {
public:
// Intrusive type system that allows us to use llvm casting.

View File

@ -267,12 +267,9 @@ public:
static std::set<lldb::LanguageType> GetSupportedLanguages();
static void GetLanguagesSupportingTypeSystems(
std::set<lldb::LanguageType> &languages,
std::set<lldb::LanguageType> &languages_for_expressions);
static void
GetLanguagesSupportingREPLs(std::set<lldb::LanguageType> &languages);
static LanguageSet GetLanguagesSupportingTypeSystems();
static LanguageSet GetLanguagesSupportingTypeSystemsForExpressions();
static LanguageSet GetLanguagesSupportingREPLs();
protected:
// Classes that inherit from Language can see and modify these

View File

@ -102,11 +102,6 @@ typedef lldb::REPLSP (*REPLCreateInstance)(Status &error,
lldb::LanguageType language,
Debugger *debugger, Target *target,
const char *repl_options);
typedef void (*TypeSystemEnumerateSupportedLanguages)(
std::set<lldb::LanguageType> &languages_for_types,
std::set<lldb::LanguageType> &languages_for_expressions);
typedef void (*REPLEnumerateSupportedLanguages)(
std::set<lldb::LanguageType> &languages);
typedef int (*ComparisonFunction)(const void *, const void *);
typedef void (*DebuggerInitializeCallback)(Debugger &debugger);

View File

@ -1,18 +1,21 @@
; Test finding types by CompilerContext.
; RUN: llc %s -filetype=obj -o %t.o
; RUN: lldb-test symbols %t.o -find=type \
; RUN: lldb-test symbols %t.o -find=type --language=C99 \
; RUN: -compiler-context="Module:CModule,Module:SubModule,Struct:FromSubmoduleX" \
; RUN: | FileCheck %s --check-prefix=NORESULTS
; RUN: lldb-test symbols %t.o -find=type \
; RUN: lldb-test symbols %t.o -find=type --language=C++ \
; RUN: -compiler-context="Module:CModule,Module:SubModule,Struct:FromSubmodule" \
; RUN: | FileCheck %s --check-prefix=NORESULTS
; RUN: lldb-test symbols %t.o -find=type --language=C99 \
; RUN: -compiler-context="Module:CModule,Module:SubModule,Struct:FromSubmodule" \
; RUN: | FileCheck %s
; RUN: lldb-test symbols %t.o -find=type \
; RUN: lldb-test symbols %t.o -find=type --language=C99 \
; RUN: -compiler-context="Module:CModule,AnyModule:*,Struct:FromSubmodule" \
; RUN: | FileCheck %s
; RUN: lldb-test symbols %t.o -find=type \
; RUN: lldb-test symbols %t.o -find=type --language=C99 \
; RUN: -compiler-context="AnyModule:*,Struct:FromSubmodule" \
; RUN: | FileCheck %s
; RUN: lldb-test symbols %t.o -find=type \
; RUN: lldb-test symbols %t.o -find=type --language=C99 \
; RUN: -compiler-context="Module:CModule,Module:SubModule,AnyType:FromSubmodule" \
; RUN: | FileCheck %s
;

View File

@ -1623,13 +1623,11 @@ Status Debugger::RunREPL(LanguageType language, const char *repl_options) {
FileSpec repl_executable;
if (language == eLanguageTypeUnknown) {
std::set<LanguageType> repl_languages;
LanguageSet repl_languages = Language::GetLanguagesSupportingREPLs();
Language::GetLanguagesSupportingREPLs(repl_languages);
if (repl_languages.size() == 1) {
language = *repl_languages.begin();
} else if (repl_languages.empty()) {
if (auto single_lang = repl_languages.GetSingularLanguage()) {
language = *single_lang;
} else if (repl_languages.Empty()) {
err.SetErrorStringWithFormat(
"LLDB isn't configured with REPL support for any languages.");
return err;

View File

@ -1037,6 +1037,15 @@ size_t Module::FindTypes(
return num_matches;
}
size_t Module::FindTypes(llvm::ArrayRef<CompilerContext> pattern,
LanguageSet languages, bool append, TypeMap &types) {
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
if (SymbolFile *symbols = GetSymbolFile())
return symbols->FindTypes(pattern, languages, append, types);
return 0;
}
SymbolFile *Module::GetSymbolFile(bool can_create, Stream *feedback_strm) {
if (!m_did_load_symfile.load()) {
std::lock_guard<std::recursive_mutex> guard(m_mutex);

View File

@ -2083,12 +2083,11 @@ PluginManager::GetInstrumentationRuntimeCreateCallbackForPluginName(
#pragma mark TypeSystem
struct TypeSystemInstance {
TypeSystemInstance() : name(), description(), create_callback(nullptr) {}
ConstString name;
std::string description;
TypeSystemCreateInstance create_callback;
TypeSystemEnumerateSupportedLanguages enumerate_callback;
LanguageSet supported_languages_for_types;
LanguageSet supported_languages_for_expressions;
};
typedef std::vector<TypeSystemInstance> TypeSystemInstances;
@ -2103,11 +2102,11 @@ static TypeSystemInstances &GetTypeSystemInstances() {
return g_instances;
}
bool PluginManager::RegisterPlugin(ConstString name,
const char *description,
bool PluginManager::RegisterPlugin(
ConstString name, const char *description,
TypeSystemCreateInstance create_callback,
TypeSystemEnumerateSupportedLanguages
enumerate_supported_languages_callback) {
LanguageSet supported_languages_for_types,
LanguageSet supported_languages_for_expressions) {
if (create_callback) {
TypeSystemInstance instance;
assert((bool)name);
@ -2115,7 +2114,8 @@ bool PluginManager::RegisterPlugin(ConstString name,
if (description && description[0])
instance.description = description;
instance.create_callback = create_callback;
instance.enumerate_callback = enumerate_supported_languages_callback;
instance.supported_languages_for_types = supported_languages_for_types;
instance.supported_languages_for_expressions = supported_languages_for_expressions;
std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex());
GetTypeSystemInstances().push_back(instance);
}
@ -2163,30 +2163,22 @@ PluginManager::GetTypeSystemCreateCallbackForPluginName(
return nullptr;
}
TypeSystemEnumerateSupportedLanguages
PluginManager::GetTypeSystemEnumerateSupportedLanguagesCallbackAtIndex(
uint32_t idx) {
LanguageSet PluginManager::GetAllTypeSystemSupportedLanguagesForTypes() {
std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex());
LanguageSet all;
TypeSystemInstances &instances = GetTypeSystemInstances();
if (idx < instances.size())
return instances[idx].enumerate_callback;
return nullptr;
for (unsigned i = 0; i < instances.size(); ++i)
all.bitvector |= instances[i].supported_languages_for_types.bitvector;
return all;
}
TypeSystemEnumerateSupportedLanguages
PluginManager::GetTypeSystemEnumerateSupportedLanguagesCallbackForPluginName(
ConstString name) {
if (name) {
LanguageSet PluginManager::GetAllTypeSystemSupportedLanguagesForExpressions() {
std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex());
LanguageSet all;
TypeSystemInstances &instances = GetTypeSystemInstances();
TypeSystemInstances::iterator pos, end = instances.end();
for (pos = instances.begin(); pos != end; ++pos) {
if (name == pos->name)
return pos->enumerate_callback;
}
}
return nullptr;
for (unsigned i = 0; i < instances.size(); ++i)
all.bitvector |= instances[i].supported_languages_for_expressions.bitvector;
return all;
}
#pragma mark REPL
@ -2197,7 +2189,7 @@ struct REPLInstance {
ConstString name;
std::string description;
REPLCreateInstance create_callback;
REPLEnumerateSupportedLanguages enumerate_languages_callback;
LanguageSet supported_languages;
};
typedef std::vector<REPLInstance> REPLInstances;
@ -2212,10 +2204,9 @@ static REPLInstances &GetREPLInstances() {
return g_instances;
}
bool PluginManager::RegisterPlugin(
ConstString name, const char *description,
bool PluginManager::RegisterPlugin(ConstString name, const char *description,
REPLCreateInstance create_callback,
REPLEnumerateSupportedLanguages enumerate_languages_callback) {
LanguageSet supported_languages) {
if (create_callback) {
REPLInstance instance;
assert((bool)name);
@ -2223,7 +2214,7 @@ bool PluginManager::RegisterPlugin(
if (description && description[0])
instance.description = description;
instance.create_callback = create_callback;
instance.enumerate_languages_callback = enumerate_languages_callback;
instance.supported_languages = supported_languages;
std::lock_guard<std::recursive_mutex> guard(GetREPLMutex());
GetREPLInstances().push_back(instance);
}
@ -2269,29 +2260,13 @@ PluginManager::GetREPLCreateCallbackForPluginName(ConstString name) {
return nullptr;
}
REPLEnumerateSupportedLanguages
PluginManager::GetREPLEnumerateSupportedLanguagesCallbackAtIndex(uint32_t idx) {
LanguageSet PluginManager::GetREPLAllTypeSystemSupportedLanguages() {
std::lock_guard<std::recursive_mutex> guard(GetREPLMutex());
LanguageSet all;
REPLInstances &instances = GetREPLInstances();
if (idx < instances.size())
return instances[idx].enumerate_languages_callback;
return nullptr;
}
REPLEnumerateSupportedLanguages
PluginManager::GetREPLSystemEnumerateSupportedLanguagesCallbackForPluginName(
ConstString name) {
if (name) {
std::lock_guard<std::recursive_mutex> guard(GetREPLMutex());
REPLInstances &instances = GetREPLInstances();
REPLInstances::iterator pos, end = instances.end();
for (pos = instances.begin(); pos != end; ++pos) {
if (name == pos->name)
return pos->enumerate_languages_callback;
}
}
return nullptr;
for (unsigned i = 0; i < instances.size(); ++i)
all.bitvector |= instances[i].supported_languages.bitvector;
return all;
}
#pragma mark PluginManager

View File

@ -10,6 +10,7 @@
#include "lldb/DataFormatters/FormatManager.h"
#include "lldb/Target/Language.h"
#include "lldb/Symbol/TypeSystem.h"
#include "lldb/Utility/Args.h"
#include "lldb/Utility/Stream.h"
@ -39,23 +40,20 @@ Status OptionValueLanguage::SetValueFromString(llvm::StringRef value,
case eVarSetOperationReplace:
case eVarSetOperationAssign: {
ConstString lang_name(value.trim());
std::set<lldb::LanguageType> languages_for_types;
std::set<lldb::LanguageType> languages_for_expressions;
Language::GetLanguagesSupportingTypeSystems(languages_for_types,
languages_for_expressions);
LanguageSet languages_for_types = Language::GetLanguagesSupportingTypeSystems();
LanguageType new_type =
Language::GetLanguageTypeFromString(lang_name.GetStringRef());
if (new_type && languages_for_types.count(new_type)) {
if (new_type && languages_for_types[new_type]) {
m_value_was_set = true;
m_current_value = new_type;
} else {
StreamString error_strm;
error_strm.Printf("invalid language type '%s', ", value.str().c_str());
error_strm.Printf("valid values are:\n");
for (lldb::LanguageType language : languages_for_types) {
error_strm.Printf("%s%s%s", " ",
Language::GetNameForLanguageType(language), "\n");
for (int bit : languages_for_types.bitvector.set_bits()) {
auto language = (LanguageType)bit;
error_strm.Printf(" %s\n",
Language::GetNameForLanguageType(language));
}
error.SetErrorString(error_strm.GetString());
}

View File

@ -319,7 +319,8 @@ uint32_t SymbolFileBreakpad::FindTypes(
}
size_t SymbolFileBreakpad::FindTypes(llvm::ArrayRef<CompilerContext> pattern,
bool append, TypeMap &types) {
LanguageSet languages, bool append,
TypeMap &types) {
if (!append)
types.Clear();
return types.GetSize();

View File

@ -116,8 +116,8 @@ public:
llvm::DenseSet<SymbolFile *> &searched_symbol_files,
TypeMap &types) override;
size_t FindTypes(llvm::ArrayRef<CompilerContext> pattern, bool append,
TypeMap &types) override;
size_t FindTypes(llvm::ArrayRef<CompilerContext> pattern,
LanguageSet languages, bool append, TypeMap &types) override;
llvm::Expected<TypeSystem &>
GetTypeSystemForLanguage(lldb::LanguageType language) override {

View File

@ -148,7 +148,10 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWO(const DWARFDIE &die, Log *log) {
die.GetDeclContext(decl_context);
TypeMap dwo_types;
if (!dwo_module_sp->GetSymbolFile()->FindTypes(decl_context, true,
// The type in the Clang module must have the same langage as the current CU.
LanguageSet languages;
languages.Insert(die.GetCU()->GetLanguageType());
if (!dwo_module_sp->GetSymbolFile()->FindTypes(decl_context, languages, true,
dwo_types)) {
if (!IsClangModuleFwdDecl(die))
return TypeSP();
@ -159,8 +162,8 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWO(const DWARFDIE &die, Log *log) {
for (const auto &name_module : sym_file.getExternalTypeModules()) {
if (!name_module.second)
continue;
if (name_module.second->GetSymbolFile()->FindTypes(decl_context, true,
dwo_types))
if (name_module.second->GetSymbolFile()->FindTypes(
decl_context, languages, true, dwo_types))
break;
}
}

View File

@ -2485,7 +2485,8 @@ uint32_t SymbolFileDWARF::FindTypes(
}
size_t SymbolFileDWARF::FindTypes(llvm::ArrayRef<CompilerContext> pattern,
bool append, TypeMap &types) {
LanguageSet languages, bool append,
TypeMap &types) {
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
if (!append)
types.Clear();
@ -2508,6 +2509,9 @@ size_t SymbolFileDWARF::FindTypes(llvm::ArrayRef<CompilerContext> pattern,
DWARFDIE die = GetDIE(die_ref);
if (die) {
if (!languages[die.GetCU()->GetLanguageType()])
continue;
llvm::SmallVector<CompilerContext, 4> die_context;
die.GetDeclContext(die_context);
if (!contextMatches(die_context, pattern))

View File

@ -185,7 +185,8 @@ public:
lldb_private::TypeMap &types) override;
size_t FindTypes(llvm::ArrayRef<lldb_private::CompilerContext> pattern,
bool append, lldb_private::TypeMap &types) override;
lldb_private::LanguageSet languages, bool append,
lldb_private::TypeMap &types) override;
size_t GetTypes(lldb_private::SymbolContextScope *sc_scope,
lldb::TypeClass type_mask,

View File

@ -1270,7 +1270,10 @@ uint32_t SymbolFileNativePDB::FindTypes(
}
size_t SymbolFileNativePDB::FindTypes(llvm::ArrayRef<CompilerContext> pattern,
bool append, TypeMap &types) {
LanguageSet languages, bool append,
TypeMap &types) {
if (!append)
types.Clear();
return 0;
}

View File

@ -134,8 +134,8 @@ public:
llvm::DenseSet<SymbolFile *> &searched_symbol_files,
TypeMap &types) override;
size_t FindTypes(llvm::ArrayRef<CompilerContext> pattern, bool append,
TypeMap &types) override;
size_t FindTypes(llvm::ArrayRef<CompilerContext> pattern,
LanguageSet languages, bool append, TypeMap &types) override;
llvm::Expected<TypeSystem &>
GetTypeSystemForLanguage(lldb::LanguageType language) override;

View File

@ -1585,7 +1585,10 @@ void SymbolFilePDB::FindTypesByName(
}
size_t SymbolFilePDB::FindTypes(llvm::ArrayRef<CompilerContext> pattern,
bool append, lldb_private::TypeMap &types) {
LanguageSet languages, bool append,
lldb_private::TypeMap &types) {
if (!append)
types.Clear();
return 0;
}

View File

@ -133,7 +133,8 @@ public:
lldb_private::TypeMap &types) override;
size_t FindTypes(llvm::ArrayRef<lldb_private::CompilerContext> pattern,
bool append, lldb_private::TypeMap &types) override;
lldb_private::LanguageSet languages, bool append,
lldb_private::TypeMap &types) override;
void FindTypesByRegex(const lldb_private::RegularExpression &regex,
uint32_t max_matches, lldb_private::TypeMap &types);

View File

@ -734,32 +734,36 @@ lldb::TypeSystemSP ClangASTContext::CreateInstance(lldb::LanguageType language,
return lldb::TypeSystemSP();
}
void ClangASTContext::EnumerateSupportedLanguages(
std::set<lldb::LanguageType> &languages_for_types,
std::set<lldb::LanguageType> &languages_for_expressions) {
static std::vector<lldb::LanguageType> s_supported_languages_for_types(
{lldb::eLanguageTypeC89, lldb::eLanguageTypeC, lldb::eLanguageTypeC11,
lldb::eLanguageTypeC_plus_plus, lldb::eLanguageTypeC99,
lldb::eLanguageTypeObjC, lldb::eLanguageTypeObjC_plus_plus,
lldb::eLanguageTypeC_plus_plus_03, lldb::eLanguageTypeC_plus_plus_11,
lldb::eLanguageTypeC11, lldb::eLanguageTypeC_plus_plus_14});
LanguageSet ClangASTContext::GetSupportedLanguagesForTypes() {
LanguageSet languages;
languages.Insert(lldb::eLanguageTypeC89);
languages.Insert(lldb::eLanguageTypeC);
languages.Insert(lldb::eLanguageTypeC11);
languages.Insert(lldb::eLanguageTypeC_plus_plus);
languages.Insert(lldb::eLanguageTypeC99);
languages.Insert(lldb::eLanguageTypeObjC);
languages.Insert(lldb::eLanguageTypeObjC_plus_plus);
languages.Insert(lldb::eLanguageTypeC_plus_plus_03);
languages.Insert(lldb::eLanguageTypeC_plus_plus_11);
languages.Insert(lldb::eLanguageTypeC11);
languages.Insert(lldb::eLanguageTypeC_plus_plus_14);
return languages;
}
static std::vector<lldb::LanguageType> s_supported_languages_for_expressions(
{lldb::eLanguageTypeC_plus_plus, lldb::eLanguageTypeObjC_plus_plus,
lldb::eLanguageTypeC_plus_plus_03, lldb::eLanguageTypeC_plus_plus_11,
lldb::eLanguageTypeC_plus_plus_14});
languages_for_types.insert(s_supported_languages_for_types.begin(),
s_supported_languages_for_types.end());
languages_for_expressions.insert(
s_supported_languages_for_expressions.begin(),
s_supported_languages_for_expressions.end());
LanguageSet ClangASTContext::GetSupportedLanguagesForExpressions() {
LanguageSet languages;
languages.Insert(lldb::eLanguageTypeC_plus_plus);
languages.Insert(lldb::eLanguageTypeObjC_plus_plus);
languages.Insert(lldb::eLanguageTypeC_plus_plus_03);
languages.Insert(lldb::eLanguageTypeC_plus_plus_11);
languages.Insert(lldb::eLanguageTypeC_plus_plus_14);
return languages;
}
void ClangASTContext::Initialize() {
PluginManager::RegisterPlugin(GetPluginNameStatic(),
"clang base AST context plug-in",
CreateInstance, EnumerateSupportedLanguages);
PluginManager::RegisterPlugin(
GetPluginNameStatic(), "clang base AST context plug-in", CreateInstance,
GetSupportedLanguagesForTypes(), GetSupportedLanguagesForExpressions());
}
void ClangASTContext::Terminate() {

View File

@ -150,7 +150,8 @@ uint32_t SymbolFile::FindTypes(
}
size_t SymbolFile::FindTypes(llvm::ArrayRef<CompilerContext> pattern,
bool append, TypeMap &types) {
LanguageSet languages, bool append,
TypeMap &types) {
if (!append)
types.Clear();
return 0;

View File

@ -25,6 +25,24 @@
using namespace lldb_private;
using namespace lldb;
/// A 64-bit SmallBitVector is only small up to 64-7 bits, and the
/// setBitsInMask interface wants to write full bytes.
static const size_t g_num_small_bitvector_bits = 64 - 8;
static_assert(eNumLanguageTypes < g_num_small_bitvector_bits,
"Languages bit vector is no longer small on 64 bit systems");
LanguageSet::LanguageSet() : bitvector(eNumLanguageTypes, 0) {}
llvm::Optional<LanguageType> LanguageSet::GetSingularLanguage() {
if (bitvector.count() == 1)
return (LanguageType)bitvector.find_first();
return {};
}
void LanguageSet::Insert(LanguageType language) { bitvector.set(language); }
size_t LanguageSet::Size() const { return bitvector.count(); }
bool LanguageSet::Empty() const { return bitvector.none(); }
bool LanguageSet::operator[](unsigned i) const { return bitvector[i]; }
TypeSystem::TypeSystem(LLVMCastKind kind) : m_kind(kind), m_sym_file(nullptr) {}
TypeSystem::~TypeSystem() {}

View File

@ -357,26 +357,16 @@ std::set<lldb::LanguageType> Language::GetSupportedLanguages() {
return supported_languages;
}
void Language::GetLanguagesSupportingTypeSystems(
std::set<lldb::LanguageType> &languages,
std::set<lldb::LanguageType> &languages_for_expressions) {
uint32_t idx = 0;
while (TypeSystemEnumerateSupportedLanguages enumerate = PluginManager::
GetTypeSystemEnumerateSupportedLanguagesCallbackAtIndex(idx++)) {
(*enumerate)(languages, languages_for_expressions);
}
LanguageSet Language::GetLanguagesSupportingTypeSystems() {
return PluginManager::GetAllTypeSystemSupportedLanguagesForTypes();
}
void Language::GetLanguagesSupportingREPLs(
std::set<lldb::LanguageType> &languages) {
uint32_t idx = 0;
while (REPLEnumerateSupportedLanguages enumerate =
PluginManager::GetREPLEnumerateSupportedLanguagesCallbackAtIndex(
idx++)) {
(*enumerate)(languages);
LanguageSet Language::GetLanguagesSupportingTypeSystemsForExpressions() {
return PluginManager::GetAllTypeSystemSupportedLanguagesForExpressions();
}
LanguageSet Language::GetLanguagesSupportingREPLs() {
return PluginManager::GetREPLAllTypeSystemSupportedLanguages();
}
std::unique_ptr<Language::TypeScavenger> Language::GetTypeScavenger() {

View File

@ -206,13 +206,11 @@ const lldb::ProcessSP &Target::GetProcessSP() const { return m_process_sp; }
lldb::REPLSP Target::GetREPL(Status &err, lldb::LanguageType language,
const char *repl_options, bool can_create) {
if (language == eLanguageTypeUnknown) {
std::set<LanguageType> repl_languages;
LanguageSet repl_languages = Language::GetLanguagesSupportingREPLs();
Language::GetLanguagesSupportingREPLs(repl_languages);
if (repl_languages.size() == 1) {
language = *repl_languages.begin();
} else if (repl_languages.size() == 0) {
if (auto single_lang = repl_languages.GetSingularLanguage()) {
language = *single_lang;
} else if (repl_languages.Empty()) {
err.SetErrorStringWithFormat(
"LLDB isn't configured with REPL support for any languages.");
return REPLSP();
@ -2129,23 +2127,18 @@ Target::GetScratchTypeSystemForLanguage(lldb::LanguageType language,
if (language == eLanguageTypeMipsAssembler // GNU AS and LLVM use it for all
// assembly code
|| language == eLanguageTypeUnknown) {
std::set<lldb::LanguageType> languages_for_types;
std::set<lldb::LanguageType> languages_for_expressions;
LanguageSet languages_for_expressions =
Language::GetLanguagesSupportingTypeSystemsForExpressions();
Language::GetLanguagesSupportingTypeSystems(languages_for_types,
languages_for_expressions);
if (languages_for_expressions.count(eLanguageTypeC)) {
if (languages_for_expressions[eLanguageTypeC]) {
language = eLanguageTypeC; // LLDB's default. Override by setting the
// target language.
} else {
if (languages_for_expressions.empty()) {
if (languages_for_expressions.Empty())
return llvm::make_error<llvm::StringError>(
"No expression support for any languages",
llvm::inconvertibleErrorCode());
} else {
language = *languages_for_expressions.begin();
}
language = (LanguageType)languages_for_expressions.bitvector.find_first();
}
}
@ -2159,21 +2152,19 @@ std::vector<TypeSystem *> Target::GetScratchTypeSystems(bool create_on_demand) {
std::vector<TypeSystem *> scratch_type_systems;
std::set<lldb::LanguageType> languages_for_types;
std::set<lldb::LanguageType> languages_for_expressions;
LanguageSet languages_for_expressions =
Language::GetLanguagesSupportingTypeSystemsForExpressions();
Language::GetLanguagesSupportingTypeSystems(languages_for_types,
languages_for_expressions);
for (auto lang : languages_for_expressions) {
for (auto bit : languages_for_expressions.bitvector.set_bits()) {
auto language = (LanguageType)bit;
auto type_system_or_err =
GetScratchTypeSystemForLanguage(lang, create_on_demand);
GetScratchTypeSystemForLanguage(language, create_on_demand);
if (!type_system_or_err)
LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_TARGET),
type_system_or_err.takeError(),
"Language '{}' has expression support but no scratch type "
"system available",
Language::GetNameForLanguageType(lang));
Language::GetNameForLanguageType(language));
else
scratch_type_systems.emplace_back(&type_system_or_err.get());
}

View File

@ -26,6 +26,7 @@
#include "lldb/Symbol/TypeList.h"
#include "lldb/Symbol/TypeMap.h"
#include "lldb/Symbol/VariableList.h"
#include "lldb/Target/Language.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/CleanUp.h"
@ -144,6 +145,10 @@ static cl::opt<std::string> CompilerContext(
cl::desc("Specify a compiler context as \"kind:name,...\"."),
cl::value_desc("context"), cl::sub(SymbolsSubcommand));
static cl::opt<std::string>
Language("language", cl::desc("Specify a language type, like C99."),
cl::value_desc("language"), cl::sub(SymbolsSubcommand));
static cl::list<FunctionNameType> FunctionNameFlags(
"function-flags", cl::desc("Function search flags:"),
cl::values(clEnumValN(eFunctionNameTypeAuto, "auto",
@ -507,13 +512,17 @@ Error opts::symbols::findTypes(lldb_private::Module &Module) {
CompilerDeclContext *ContextPtr =
ContextOr->IsValid() ? &*ContextOr : nullptr;
LanguageSet languages;
if (!Language.empty())
languages.Insert(Language::GetLanguageTypeFromString(Language));
DenseSet<SymbolFile *> SearchedFiles;
TypeMap Map;
if (!Name.empty())
Symfile.FindTypes(ConstString(Name), ContextPtr, true, UINT32_MAX,
SearchedFiles, Map);
else
Symfile.FindTypes(parseCompilerContext(), true, Map);
Module.FindTypes(parseCompilerContext(), languages, true, Map);
outs() << formatv("Found {0} types:\n", Map.GetSize());
StreamString Stream;