Author: martong Date: Wed May 22 02:10:19 2019 New Revision: 361362 URL: http://llvm.org/viewvc/llvm-project?rev=361362&view=rev Log: Add AST logging
Summary: Log the AST of the TU associated with LLDB's `expr` command, once a declaration is completed Reviewers: shafik Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D62061 Modified: lldb/trunk/include/lldb/Utility/Logging.h lldb/trunk/source/Symbol/ClangASTImporter.cpp lldb/trunk/source/Utility/Logging.cpp Modified: lldb/trunk/include/lldb/Utility/Logging.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/Logging.h?rev=361362&r1=361361&r2=361362&view=diff ============================================================================== --- lldb/trunk/include/lldb/Utility/Logging.h (original) +++ lldb/trunk/include/lldb/Utility/Logging.h Wed May 22 02:10:19 2019 @@ -42,6 +42,7 @@ #define LIBLLDB_LOG_LANGUAGE (1u << 28) #define LIBLLDB_LOG_DATAFORMATTERS (1u << 29) #define LIBLLDB_LOG_DEMANGLE (1u << 30) +#define LIBLLDB_LOG_AST (1u << 31) #define LIBLLDB_LOG_ALL (UINT32_MAX) #define LIBLLDB_LOG_DEFAULT \ (LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_THREAD | LIBLLDB_LOG_DYNAMIC_LOADER | \ Modified: lldb/trunk/source/Symbol/ClangASTImporter.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTImporter.cpp?rev=361362&r1=361361&r2=361362&view=diff ============================================================================== --- lldb/trunk/source/Symbol/ClangASTImporter.cpp (original) +++ lldb/trunk/source/Symbol/ClangASTImporter.cpp Wed May 22 02:10:19 2019 @@ -951,6 +951,28 @@ void ClangASTImporter::ASTImporterDelega if (clang::TagDecl *to_tag = dyn_cast<clang::TagDecl>(to)) { if (clang::TagDecl *from_tag = dyn_cast<clang::TagDecl>(from)) { to_tag->setCompleteDefinition(from_tag->isCompleteDefinition()); + + if (Log *log_ast = + lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_AST)) { + std::string name_string; + if (NamedDecl *from_named_decl = dyn_cast<clang::NamedDecl>(from)) { + llvm::raw_string_ostream name_stream(name_string); + from_named_decl->printName(name_stream); + name_stream.flush(); + } + LLDB_LOG(log_ast, "==== [ClangASTImporter][TUDecl: {0}] Imported " + "({1}Decl*){2}, named {3} (from " + "(Decl*){4})", + static_cast<void *>(to->getTranslationUnitDecl()), + from->getDeclKindName(), static_cast<void *>(to), name_string, + static_cast<void *>(from)); + + // Log the AST of the TU. + std::string ast_string; + llvm::raw_string_ostream ast_stream(ast_string); + to->getTranslationUnitDecl()->dump(ast_stream); + LLDB_LOG(log_ast, "{0}", ast_string); + } } } Modified: lldb/trunk/source/Utility/Logging.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/Logging.cpp?rev=361362&r1=361361&r2=361362&view=diff ============================================================================== --- lldb/trunk/source/Utility/Logging.cpp (original) +++ lldb/trunk/source/Utility/Logging.cpp Wed May 22 02:10:19 2019 @@ -17,6 +17,7 @@ using namespace lldb_private; static constexpr Log::Category g_categories[] = { {{"api"}, {"log API calls and return values"}, LIBLLDB_LOG_API}, + {{"ast"}, {"log AST"}, LIBLLDB_LOG_AST}, {{"break"}, {"log breakpoints"}, LIBLLDB_LOG_BREAKPOINTS}, {{"commands"}, {"log command argument parsing"}, LIBLLDB_LOG_COMMANDS}, {{"comm"}, {"log communication activities"}, LIBLLDB_LOG_COMMUNICATION}, _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits