diff options
Diffstat (limited to 'include/lldb/Expression')
| -rw-r--r-- | include/lldb/Expression/ClangASTSource.h | 127 | ||||
| -rw-r--r-- | include/lldb/Expression/ClangExpressionDeclMap.h | 21 | ||||
| -rw-r--r-- | include/lldb/Expression/ClangExpressionParser.h | 1 | ||||
| -rw-r--r-- | include/lldb/Expression/ClangFunction.h | 3 | ||||
| -rw-r--r-- | include/lldb/Expression/ClangModulesDeclVendor.h | 73 | ||||
| -rw-r--r-- | include/lldb/Expression/ClangPersistentVariables.h | 16 | ||||
| -rw-r--r-- | include/lldb/Expression/ClangUserExpression.h | 13 | ||||
| -rw-r--r-- | include/lldb/Expression/IRForTarget.h | 3 | ||||
| -rw-r--r-- | include/lldb/Expression/IRMemoryMap.h | 12 | ||||
| -rw-r--r-- | include/lldb/Expression/IRToDWARF.h | 2 |
10 files changed, 181 insertions, 90 deletions
diff --git a/include/lldb/Expression/ClangASTSource.h b/include/lldb/Expression/ClangASTSource.h index 3e41a9e69e9b..46140d2f2e64 100644 --- a/include/lldb/Expression/ClangASTSource.h +++ b/include/lldb/Expression/ClangASTSource.h @@ -15,6 +15,7 @@ #include "clang/Basic/IdentifierTable.h" #include "lldb/Symbol/ClangExternalASTSourceCommon.h" #include "lldb/Symbol/ClangASTImporter.h" +#include "lldb/Symbol/ClangASTType.h" #include "lldb/Target/Target.h" #include "llvm/ADT/SmallSet.h" @@ -45,39 +46,40 @@ public: /// @param[in] declMap /// A reference to the LLDB object that handles entity lookup. //------------------------------------------------------------------ - ClangASTSource (const lldb::TargetSP &target) : + ClangASTSource (const lldb::TargetSP &target) : m_import_in_progress (false), m_lookups_enabled (false), m_target (target), m_ast_context (NULL), + m_active_lexical_decls (), m_active_lookups () { m_ast_importer = m_target->GetClangASTImporter(); } - + //------------------------------------------------------------------ /// Destructor //------------------------------------------------------------------ - ~ClangASTSource(); - + ~ClangASTSource(); + //------------------------------------------------------------------ /// Interface stubs. //------------------------------------------------------------------ - clang::Decl *GetExternalDecl (uint32_t) { return NULL; } - clang::Stmt *GetExternalDeclStmt (uint64_t) { return NULL; } - clang::Selector GetExternalSelector (uint32_t) { return clang::Selector(); } - uint32_t GetNumExternalSelectors () { return 0; } - clang::CXXBaseSpecifier *GetExternalCXXBaseSpecifiers (uint64_t Offset) + clang::Decl *GetExternalDecl (uint32_t) override { return NULL; } + clang::Stmt *GetExternalDeclStmt (uint64_t) override { return NULL; } + clang::Selector GetExternalSelector (uint32_t) override { return clang::Selector(); } + uint32_t GetNumExternalSelectors () override { return 0; } + clang::CXXBaseSpecifier *GetExternalCXXBaseSpecifiers (uint64_t Offset) override { return NULL; } void MaterializeVisibleDecls (const clang::DeclContext *DC) { return; } - + void InstallASTContext (clang::ASTContext *ast_context) { m_ast_context = ast_context; m_ast_importer->InstallMapCompleter(ast_context, *this); } - + // // APIs for ExternalASTSource // @@ -100,10 +102,8 @@ public: /// @return /// Whatever SetExternalVisibleDeclsForName returns. //------------------------------------------------------------------ - bool - FindExternalVisibleDeclsByName (const clang::DeclContext *DC, - clang::DeclarationName Name); - + bool FindExternalVisibleDeclsByName(const clang::DeclContext *DC, clang::DeclarationName Name) override; + //------------------------------------------------------------------ /// Enumerate all Decls in a given lexical context. /// @@ -117,11 +117,10 @@ public: /// @param[in] Decls /// A vector that is filled in with matching Decls. //------------------------------------------------------------------ - clang::ExternalLoadResult - FindExternalLexicalDecls (const clang::DeclContext *DC, - bool (*isKindWeWant)(clang::Decl::Kind), - llvm::SmallVectorImpl<clang::Decl*> &Decls); - + clang::ExternalLoadResult FindExternalLexicalDecls(const clang::DeclContext *DC, + bool (*isKindWeWant)(clang::Decl::Kind), + llvm::SmallVectorImpl<clang::Decl *> &Decls) override; + //------------------------------------------------------------------ /// Specify the layout of the contents of a RecordDecl. /// @@ -154,33 +153,28 @@ public: /// /// @return /// True <=> the layout is valid. - //----------------------------------------------------------------- - bool - layoutRecordType(const clang::RecordDecl *Record, - uint64_t &Size, - uint64_t &Alignment, - llvm::DenseMap <const clang::FieldDecl *, uint64_t> &FieldOffsets, - llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &BaseOffsets, - llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &VirtualBaseOffsets); - + //----------------------------------------------------------------- + bool layoutRecordType(const clang::RecordDecl *Record, uint64_t &Size, uint64_t &Alignment, + llvm::DenseMap<const clang::FieldDecl *, uint64_t> &FieldOffsets, + llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &BaseOffsets, + llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &VirtualBaseOffsets) override; + //------------------------------------------------------------------ /// Complete a TagDecl. /// /// @param[in] Tag /// The Decl to be completed in place. //------------------------------------------------------------------ - virtual void - CompleteType (clang::TagDecl *Tag); - + void CompleteType(clang::TagDecl *Tag) override; + //------------------------------------------------------------------ /// Complete an ObjCInterfaceDecl. /// /// @param[in] Class /// The Decl to be completed in place. //------------------------------------------------------------------ - virtual void - CompleteType (clang::ObjCInterfaceDecl *Class); - + void CompleteType(clang::ObjCInterfaceDecl *Class) override; + //------------------------------------------------------------------ /// Called on entering a translation unit. Tells Clang by calling /// setHasExternalVisibleStorage() and setHasExternalLexicalStorage() @@ -189,8 +183,8 @@ public: /// @param[in] ASTConsumer /// Unused. //------------------------------------------------------------------ - void StartTranslationUnit (clang::ASTConsumer *Consumer); - + void StartTranslationUnit(clang::ASTConsumer *Consumer) override; + // // APIs for NamespaceMapCompleter // @@ -209,10 +203,9 @@ public: /// The map for the namespace's parent namespace, if there is /// one. //------------------------------------------------------------------ - void CompleteNamespaceMap (ClangASTImporter::NamespaceMapSP &namespace_map, - const ConstString &name, - ClangASTImporter::NamespaceMapSP &parent_map) const; - + void CompleteNamespaceMap(ClangASTImporter::NamespaceMapSP &namespace_map, const ConstString &name, + ClangASTImporter::NamespaceMapSP &parent_map) const override; + // // Helper APIs // @@ -249,41 +242,37 @@ public: m_original(original) { } - + bool - FindExternalVisibleDeclsByName (const clang::DeclContext *DC, - clang::DeclarationName Name) + FindExternalVisibleDeclsByName(const clang::DeclContext *DC, clang::DeclarationName Name) override { return m_original.FindExternalVisibleDeclsByName(DC, Name); } - - clang::ExternalLoadResult - FindExternalLexicalDecls (const clang::DeclContext *DC, - bool (*isKindWeWant)(clang::Decl::Kind), - llvm::SmallVectorImpl<clang::Decl*> &Decls) + + clang::ExternalLoadResult + FindExternalLexicalDecls(const clang::DeclContext *DC, bool (*isKindWeWant)(clang::Decl::Kind), + llvm::SmallVectorImpl<clang::Decl *> &Decls) override { return m_original.FindExternalLexicalDecls(DC, isKindWeWant, Decls); } - + void - CompleteType (clang::TagDecl *Tag) + CompleteType(clang::TagDecl *Tag) override { return m_original.CompleteType(Tag); } - - void - CompleteType (clang::ObjCInterfaceDecl *Class) + + void + CompleteType(clang::ObjCInterfaceDecl *Class) override { return m_original.CompleteType(Class); } - - bool - layoutRecordType(const clang::RecordDecl *Record, - uint64_t &Size, - uint64_t &Alignment, - llvm::DenseMap <const clang::FieldDecl *, uint64_t> &FieldOffsets, - llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &BaseOffsets, - llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &VirtualBaseOffsets) + + bool + layoutRecordType(const clang::RecordDecl *Record, uint64_t &Size, uint64_t &Alignment, + llvm::DenseMap<const clang::FieldDecl *, uint64_t> &FieldOffsets, + llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &BaseOffsets, + llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &VirtualBaseOffsets) override { return m_original.layoutRecordType(Record, Size, @@ -293,7 +282,8 @@ public: VirtualBaseOffsets); } - void StartTranslationUnit (clang::ASTConsumer *Consumer) + void + StartTranslationUnit(clang::ASTConsumer *Consumer) override { return m_original.StartTranslationUnit(Consumer); } @@ -413,8 +403,9 @@ protected: bool m_lookups_enabled; const lldb::TargetSP m_target; ///< The target to use in finding variables and types. - clang::ASTContext *m_ast_context; ///< The AST context requests are coming in for. + clang::ASTContext *m_ast_context; ///< The AST context requests are coming in for. ClangASTImporter *m_ast_importer; ///< The target's AST importer. + std::set<const clang::Decl *> m_active_lexical_decls; std::set<const char *> m_active_lookups; }; @@ -485,8 +476,12 @@ struct NameSearchContext { /// /// @param[in] type /// The opaque QualType for the FunDecl being registered. + /// + /// @param[in] extern_c + /// If true, build an extern "C" linkage specification for this. //------------------------------------------------------------------ - clang::NamedDecl *AddFunDecl(const ClangASTType &type); + clang::NamedDecl *AddFunDecl(const ClangASTType &type, + bool extern_c = false); //------------------------------------------------------------------ /// Create a FunDecl with the name being searched for and generic @@ -513,7 +508,7 @@ struct NameSearchContext { /// The DeclContextLookupResult, usually returned as the result /// of querying a DeclContext. //------------------------------------------------------------------ - void AddLookupResult (clang::DeclContextLookupConstResult result); + void AddLookupResult (clang::DeclContextLookupResult result); //------------------------------------------------------------------ /// Add a NamedDecl to the list of results. diff --git a/include/lldb/Expression/ClangExpressionDeclMap.h b/include/lldb/Expression/ClangExpressionDeclMap.h index 8a4aa82b8727..f24500ab5237 100644 --- a/include/lldb/Expression/ClangExpressionDeclMap.h +++ b/include/lldb/Expression/ClangExpressionDeclMap.h @@ -100,6 +100,9 @@ public: WillParse (ExecutionContext &exe_ctx, Materializer *materializer); + void + InstallCodeGenerator (clang::ASTConsumer *code_gen); + //------------------------------------------------------------------ /// [Used by ClangExpressionParser] For each variable that had an unknown /// type at the beginning of parsing, determine its final type now. @@ -396,11 +399,6 @@ private: { public: ParserVars(ClangExpressionDeclMap &decl_map) : - m_exe_ctx(), - m_sym_ctx(), - m_persistent_vars(NULL), - m_enable_lookups(false), - m_materializer(NULL), m_decl_map(decl_map) { } @@ -415,12 +413,13 @@ private: return NULL; } - ExecutionContext m_exe_ctx; ///< The execution context to use when parsing. - SymbolContext m_sym_ctx; ///< The symbol context to use in finding variables and types. - ClangPersistentVariables *m_persistent_vars; ///< The persistent variables for the process. - bool m_enable_lookups; ///< Set to true during parsing if we have found the first "$__lldb" name. - TargetInfo m_target_info; ///< Basic information about the target. - Materializer *m_materializer; ///< If non-NULL, the materializer to use when reporting used variables. + ExecutionContext m_exe_ctx; ///< The execution context to use when parsing. + SymbolContext m_sym_ctx; ///< The symbol context to use in finding variables and types. + ClangPersistentVariables *m_persistent_vars = nullptr; ///< The persistent variables for the process. + bool m_enable_lookups = false; ///< Set to true during parsing if we have found the first "$__lldb" name. + TargetInfo m_target_info; ///< Basic information about the target. + Materializer *m_materializer = nullptr; ///< If non-NULL, the materializer to use when reporting used variables. + clang::ASTConsumer *m_code_gen = nullptr; ///< If non-NULL, a code generator that receives new top-level functions. private: ClangExpressionDeclMap &m_decl_map; DISALLOW_COPY_AND_ASSIGN (ParserVars); diff --git a/include/lldb/Expression/ClangExpressionParser.h b/include/lldb/Expression/ClangExpressionParser.h index 0f578c55942e..21a27a489bcd 100644 --- a/include/lldb/Expression/ClangExpressionParser.h +++ b/include/lldb/Expression/ClangExpressionParser.h @@ -145,7 +145,6 @@ private: std::unique_ptr<clang::CompilerInstance> m_compiler; ///< The Clang compiler used to parse expressions into IR std::unique_ptr<clang::Builtin::Context> m_builtin_context; ///< Context for Clang built-ins std::unique_ptr<clang::SelectorTable> m_selector_table; ///< Selector table for Objective-C methods - std::unique_ptr<clang::ASTContext> m_ast_context; ///< The AST context used to hold types and names for the parser std::unique_ptr<clang::CodeGenerator> m_code_generator; ///< The Clang object that generates IR class LLDBPreprocessorCallbacks; diff --git a/include/lldb/Expression/ClangFunction.h b/include/lldb/Expression/ClangFunction.h index c122b21be279..cf7e2592021f 100644 --- a/include/lldb/Expression/ClangFunction.h +++ b/include/lldb/Expression/ClangFunction.h @@ -22,6 +22,7 @@ #include "lldb/Core/Value.h" #include "lldb/Core/ValueObjectList.h" #include "lldb/Expression/ClangExpression.h" +#include "lldb/Symbol/ClangASTType.h" #include "lldb/Target/Process.h" namespace lldb_private @@ -412,7 +413,7 @@ private: //------------------------------------------------------------------ // Note: the parser needs to be destructed before the execution unit, so - // declare the the execution unit first. + // declare the execution unit first. std::shared_ptr<IRExecutionUnit> m_execution_unit_sp; std::unique_ptr<ClangExpressionParser> m_parser; ///< The parser responsible for compiling the function. lldb::ModuleWP m_jit_module_wp; diff --git a/include/lldb/Expression/ClangModulesDeclVendor.h b/include/lldb/Expression/ClangModulesDeclVendor.h index a35b86a665ff..a8297c8fa331 100644 --- a/include/lldb/Expression/ClangModulesDeclVendor.h +++ b/include/lldb/Expression/ClangModulesDeclVendor.h @@ -15,6 +15,7 @@ #include "lldb/Symbol/DeclVendor.h" #include "lldb/Target/Platform.h" +#include <set> #include <vector> namespace lldb_private @@ -34,6 +35,10 @@ public: static ClangModulesDeclVendor * Create(Target &target); + typedef std::vector<ConstString> ModulePath; + typedef uintptr_t ModuleID; + typedef std::vector<ModuleID> ModuleVector; + //------------------------------------------------------------------ /// Add a module to the list of modules to search. /// @@ -41,6 +46,10 @@ public: /// The path to the exact module to be loaded. E.g., if the desired /// module is std.io, then this should be { "std", "io" }. /// + /// @param[in] exported_modules + /// If non-NULL, a pointer to a vector to populate with the ID of every + /// module that is re-exported by the specified module. + /// /// @param[in] error_stream /// A stream to populate with the output of the Clang parser when /// it tries to load the module. @@ -51,7 +60,69 @@ public: /// load, then this will always return false for this ModuleImporter. //------------------------------------------------------------------ virtual bool - AddModule(std::vector<llvm::StringRef> &path, Stream &error_stream) = 0; + AddModule(ModulePath &path, + ModuleVector *exported_modules, + Stream &error_stream) = 0; + + //------------------------------------------------------------------ + /// Add all modules referred to in a given compilation unit to the list + /// of modules to search. + /// + /// @param[in] cu + /// The compilation unit to scan for imported modules. + /// + /// @param[in] exported_modules + /// A vector to populate with the ID of each module loaded (directly + /// and via re-exports) in this way. + /// + /// @param[in] error_stream + /// A stream to populate with the output of the Clang parser when + /// it tries to load the modules. + /// + /// @return + /// True if all modules referred to by the compilation unit could be + /// loaded; false if one could not be loaded. If the compiler + /// encountered a fatal error during a previous module + /// load, then this will always return false for this ModuleImporter. + //------------------------------------------------------------------ + virtual bool + AddModulesForCompileUnit(CompileUnit &cu, + ModuleVector &exported_modules, + Stream &error_stream) = 0; + + //------------------------------------------------------------------ + /// Enumerate all the macros that are defined by a given set of modules + /// that are already imported. + /// + /// @param[in] modules + /// The unique IDs for all modules to query. Later modules have higher + /// priority, just as if you @imported them in that order. This matters + /// if module A #defines a macro and module B #undefs it. + /// + /// @param[in] handler + /// A function to call with the text of each #define (including the + /// #define directive). #undef directives are not included; we simply + /// elide any corresponding #define. If this function returns true, + /// we stop the iteration immediately. + //------------------------------------------------------------------ + virtual void + ForEachMacro(const ModuleVector &modules, + std::function<bool (const std::string &)> handler) = 0; + + //------------------------------------------------------------------ + /// Query whether Clang supports modules for a particular language. + /// LLDB uses this to decide whether to try to find the modules loaded + /// by a gaiven compile unit. + /// + /// @param[in] language + /// The language to query for. + /// + /// @return + /// True if Clang has modules for the given language. + //------------------------------------------------------------------ + static bool + LanguageSupportsClangModules (lldb::LanguageType language); + }; } diff --git a/include/lldb/Expression/ClangPersistentVariables.h b/include/lldb/Expression/ClangPersistentVariables.h index 6d9dae954734..247f87fae41b 100644 --- a/include/lldb/Expression/ClangPersistentVariables.h +++ b/include/lldb/Expression/ClangPersistentVariables.h @@ -11,6 +11,8 @@ #define liblldb_ClangPersistentVariables_h_ #include "lldb/Expression/ClangExpressionVariable.h" +#include "lldb/Expression/ClangModulesDeclVendor.h" + #include "llvm/ADT/DenseMap.h" namespace lldb_private @@ -63,11 +65,25 @@ public: clang::TypeDecl * GetPersistentType (const ConstString &name); + void + AddHandLoadedClangModule(ClangModulesDeclVendor::ModuleID module) + { + m_hand_loaded_clang_modules.push_back(module); + } + + const ClangModulesDeclVendor::ModuleVector &GetHandLoadedClangModules() + { + return m_hand_loaded_clang_modules; + } + private: uint32_t m_next_persistent_variable_id; ///< The counter used by GetNextResultName(). typedef llvm::DenseMap<const char *, clang::TypeDecl *> PersistentTypeMap; PersistentTypeMap m_persistent_types; ///< The persistent types declared by the user. + + ClangModulesDeclVendor::ModuleVector m_hand_loaded_clang_modules; ///< These are Clang modules we hand-loaded; these are the highest- + ///< priority source for macros. }; } diff --git a/include/lldb/Expression/ClangUserExpression.h b/include/lldb/Expression/ClangUserExpression.h index f51c9851789a..dbea48148e14 100644 --- a/include/lldb/Expression/ClangUserExpression.h +++ b/include/lldb/Expression/ClangUserExpression.h @@ -45,8 +45,7 @@ namespace lldb_private class ClangUserExpression : public ClangExpression { public: - typedef std::shared_ptr<ClangUserExpression> ClangUserExpressionSP; - + enum { kDefaultTimeout = 500000u }; //------------------------------------------------------------------ /// Constructor @@ -146,7 +145,7 @@ public: Execute (Stream &error_stream, ExecutionContext &exe_ctx, const EvaluateExpressionOptions& options, - ClangUserExpressionSP &shared_ptr_to_me, + lldb::ClangUserExpressionSP &shared_ptr_to_me, lldb::ClangExpressionVariableSP &result); //------------------------------------------------------------------ @@ -307,7 +306,7 @@ public: static const Error::ValueType kNoResult = 0x1001; ///< ValueObject::GetError() returns this if there is no result from the expression. private: //------------------------------------------------------------------ - /// Populate m_cplusplus and m_objectivec based on the environment. + /// Populate m_in_cplusplus_method and m_in_objectivec_method based on the environment. //------------------------------------------------------------------ void @@ -349,9 +348,9 @@ private: std::unique_ptr<ASTResultSynthesizer> m_result_synthesizer; ///< The result synthesizer, if one is needed. lldb::ModuleWP m_jit_module_wp; bool m_enforce_valid_object; ///< True if the expression parser should enforce the presence of a valid class pointer in order to generate the expression as a method. - bool m_cplusplus; ///< True if the expression is compiled as a C++ member function (true if it was parsed when exe_ctx was in a C++ method). - bool m_objectivec; ///< True if the expression is compiled as an Objective-C method (true if it was parsed when exe_ctx was in an Objective-C method). - bool m_static_method; ///< True if the expression is compiled as a static (or class) method (currently true if it was parsed when exe_ctx was in an Objective-C class method). + bool m_in_cplusplus_method; ///< True if the expression is compiled as a C++ member function (true if it was parsed when exe_ctx was in a C++ method). + bool m_in_objectivec_method; ///< True if the expression is compiled as an Objective-C method (true if it was parsed when exe_ctx was in an Objective-C method). + bool m_in_static_method; ///< True if the expression is compiled as a static (or class) method (currently true if it was parsed when exe_ctx was in an Objective-C class method). bool m_needs_object_ptr; ///< True if "this" or "self" must be looked up and passed in. False if the expression doesn't really use them and they can be NULL. bool m_const_object; ///< True if "this" is const. Target *m_target; ///< The target for storing persistent data like types and variables. diff --git a/include/lldb/Expression/IRForTarget.h b/include/lldb/Expression/IRForTarget.h index 0ad34904f563..b81fab7a8a83 100644 --- a/include/lldb/Expression/IRForTarget.h +++ b/include/lldb/Expression/IRForTarget.h @@ -640,6 +640,9 @@ private: return m_stream_string; } lldb::addr_t Allocate(); + + lldb::TargetSP + GetTarget(); private: lldb_private::IRExecutionUnit &m_execution_unit; lldb_private::StreamString m_stream_string; diff --git a/include/lldb/Expression/IRMemoryMap.h b/include/lldb/Expression/IRMemoryMap.h index 4faa5226d9b4..0da8384c8e63 100644 --- a/include/lldb/Expression/IRMemoryMap.h +++ b/include/lldb/Expression/IRMemoryMap.h @@ -69,14 +69,22 @@ public: // This function can return NULL. ExecutionContextScope *GetBestExecutionContextScope() const; + lldb::TargetSP + GetTarget () + { + return m_target_wp.lock(); + } + protected: // This function should only be used if you know you are using the JIT. // Any other cases should use GetBestExecutionContextScope(). - lldb::ProcessWP GetProcessWP () + + lldb::ProcessWP & + GetProcessWP () { return m_process_wp; } - + private: struct Allocation { diff --git a/include/lldb/Expression/IRToDWARF.h b/include/lldb/Expression/IRToDWARF.h index 43dc99d6d476..a4ae9b7ebfae 100644 --- a/include/lldb/Expression/IRToDWARF.h +++ b/include/lldb/Expression/IRToDWARF.h @@ -11,7 +11,7 @@ #define liblldb_IRToDWARF_h_ #include "llvm/Pass.h" -#include "llvm/PassManager.h" +#include "llvm/IR/LegacyPassManager.h" #include "lldb/lldb-public.h" |
