[Lldb-commits] [lldb] 7a6588a - [lldb] Remove lldb's own ASTDumper
Raphael Isemann via lldb-commits
lldb-commits at lists.llvm.org
Mon Nov 25 04:28:46 PST 2019
Author: Raphael Isemann
Date: 2019-11-25T13:27:51+01:00
New Revision: 7a6588abf8bac99d716188608adfbfb4928714db
URL: https://github.com/llvm/llvm-project/commit/7a6588abf8bac99d716188608adfbfb4928714db
DIFF: https://github.com/llvm/llvm-project/commit/7a6588abf8bac99d716188608adfbfb4928714db.diff
LOG: [lldb] Remove lldb's own ASTDumper
Summary:
LLDB's ASTDumper is just a clone of Clang's ASTDumper but with some scary code and
some unrelated functionality (like dumping name/attributes of types). This removes LLDB's ASTDumper
and replaces its uses with the `ClangUtils::DumpDecl` method that just calls Clang's ASTDumper
and returns the result as a string.
The few uses where we just want a textual representation of a type (which will print their name/attributes but not
dump any AST) are now also in ClangUtil under a `ToString` name until we find a better home for them.
Reviewers: labath
Reviewed By: labath
Subscribers: mgorny, JDevlieghere, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D70663
Added:
Modified:
lldb/include/lldb/Symbol/ClangUtil.h
lldb/source/Plugins/ExpressionParser/Clang/CMakeLists.txt
lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp
lldb/source/Symbol/ClangUtil.cpp
Removed:
lldb/source/Plugins/ExpressionParser/Clang/ASTDumper.cpp
lldb/source/Plugins/ExpressionParser/Clang/ASTDumper.h
################################################################################
diff --git a/lldb/include/lldb/Symbol/ClangUtil.h b/lldb/include/lldb/Symbol/ClangUtil.h
index d6106032190c..5ffbce340e59 100644
--- a/lldb/include/lldb/Symbol/ClangUtil.h
+++ b/lldb/include/lldb/Symbol/ClangUtil.h
@@ -11,6 +11,7 @@
#ifndef LLDB_SYMBOL_CLANGUTIL_H
#define LLDB_SYMBOL_CLANGUTIL_H
+#include "clang/AST/DeclBase.h"
#include "clang/AST/Type.h"
#include "lldb/Symbol/CompilerType.h"
@@ -30,6 +31,15 @@ struct ClangUtil {
static CompilerType RemoveFastQualifiers(const CompilerType &ct);
static clang::TagDecl *GetAsTagDecl(const CompilerType &type);
+
+ /// Returns a textual representation of the given Decl's AST. Does not
+ /// deserialize any child nodes.
+ static std::string DumpDecl(const clang::Decl *d);
+ /// Returns a textual representation of the given type.
+ static std::string ToString(const clang::Type *t);
+ /// Returns a textual representation of the given CompilerType (assuming
+ /// its underlying type is a Clang type).
+ static std::string ToString(const CompilerType &c);
};
}
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ASTDumper.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ASTDumper.cpp
deleted file mode 100644
index f33a713cc0b2..000000000000
--- a/lldb/source/Plugins/ExpressionParser/Clang/ASTDumper.cpp
+++ /dev/null
@@ -1,104 +0,0 @@
-//===-- ASTDumper.cpp -------------------------------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "ASTDumper.h"
-
-#include "lldb/Symbol/ClangASTContext.h"
-#include "lldb/Symbol/ClangUtil.h"
-#include "lldb/Symbol/CompilerType.h"
-#include "lldb/Utility/Log.h"
-
-#include "llvm/Support/raw_ostream.h"
-
-using namespace lldb_private;
-
-ASTDumper::ASTDumper(clang::Decl *decl) {
- clang::DeclContext *decl_ctx = llvm::dyn_cast<clang::DeclContext>(decl);
-
- bool has_external_lexical_storage;
- bool has_external_visible_storage;
-
- if (decl_ctx) {
- has_external_lexical_storage = decl_ctx->hasExternalLexicalStorage();
- has_external_visible_storage = decl_ctx->hasExternalVisibleStorage();
- decl_ctx->setHasExternalLexicalStorage(false);
- decl_ctx->setHasExternalVisibleStorage(false);
- }
-
- llvm::raw_string_ostream os(m_dump);
- decl->print(os);
- os.flush();
-
- if (decl_ctx) {
- decl_ctx->setHasExternalLexicalStorage(has_external_lexical_storage);
- decl_ctx->setHasExternalVisibleStorage(has_external_visible_storage);
- }
-}
-
-ASTDumper::ASTDumper(clang::DeclContext *decl_ctx) {
- bool has_external_lexical_storage = decl_ctx->hasExternalLexicalStorage();
- bool has_external_visible_storage = decl_ctx->hasExternalVisibleStorage();
-
- decl_ctx->setHasExternalLexicalStorage(false);
- decl_ctx->setHasExternalVisibleStorage(false);
-
- if (clang::Decl *decl = llvm::dyn_cast<clang::Decl>(decl_ctx)) {
- llvm::raw_string_ostream os(m_dump);
- decl->print(os);
- os.flush();
- } else {
- m_dump.assign("<DeclContext is not a Decl>");
- }
-
- decl_ctx->setHasExternalLexicalStorage(has_external_lexical_storage);
- decl_ctx->setHasExternalVisibleStorage(has_external_visible_storage);
-}
-
-ASTDumper::ASTDumper(const clang::Type *type) {
- m_dump = clang::QualType(type, 0).getAsString();
-}
-
-ASTDumper::ASTDumper(clang::QualType type) { m_dump = type.getAsString(); }
-
-ASTDumper::ASTDumper(lldb::opaque_compiler_type_t type) {
- m_dump = clang::QualType::getFromOpaquePtr(type).getAsString();
-}
-
-ASTDumper::ASTDumper(const CompilerType &compiler_type) {
- m_dump = ClangUtil::GetQualType(compiler_type).getAsString();
-}
-
-const char *ASTDumper::GetCString() { return m_dump.c_str(); }
-
-void ASTDumper::ToLog(Log *log, const char *prefix) {
- size_t len = m_dump.length() + 1;
-
- char *alloc = (char *)malloc(len);
- char *str = alloc;
-
- memcpy(str, m_dump.c_str(), len);
-
- char *end = nullptr;
-
- end = strchr(str, '\n');
-
- while (end) {
- *end = '\0';
-
- LLDB_LOGF(log, "%s%s", prefix, str);
-
- *end = '\n';
-
- str = end + 1;
- end = strchr(str, '\n');
- }
-
- LLDB_LOGF(log, "%s%s", prefix, str);
-
- free(alloc);
-}
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ASTDumper.h b/lldb/source/Plugins/ExpressionParser/Clang/ASTDumper.h
deleted file mode 100644
index ddf055d9c0c3..000000000000
--- a/lldb/source/Plugins/ExpressionParser/Clang/ASTDumper.h
+++ /dev/null
@@ -1,40 +0,0 @@
-//===-- ASTDumper.h ---------------------------------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef liblldb_ASTDumper_h_
-#define liblldb_ASTDumper_h_
-
-#include "clang/AST/DeclVisitor.h"
-#include "clang/AST/TypeVisitor.h"
-
-#include "lldb/Utility/Stream.h"
-#include "llvm/ADT/DenseSet.h"
-
-namespace lldb_private {
-
-class ASTDumper {
-public:
- ASTDumper(clang::Decl *decl);
- ASTDumper(clang::DeclContext *decl_ctx);
- ASTDumper(const clang::Type *type);
- ASTDumper(clang::QualType type);
- ASTDumper(lldb::opaque_compiler_type_t type);
- ASTDumper(const CompilerType &compiler_type);
-
- const char *GetCString();
- void ToSTDERR();
- void ToLog(Log *log, const char *prefix);
- void ToStream(lldb::StreamSP &stream);
-
-private:
- std::string m_dump;
-};
-
-} // namespace lldb_private
-
-#endif
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/CMakeLists.txt b/lldb/source/Plugins/ExpressionParser/Clang/CMakeLists.txt
index 81d9166bb7df..e92d089cab10 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/CMakeLists.txt
+++ b/lldb/source/Plugins/ExpressionParser/Clang/CMakeLists.txt
@@ -3,7 +3,6 @@ if(NOT LLDB_BUILT_STANDALONE)
endif()
add_lldb_library(lldbPluginExpressionParserClang PLUGIN
- ASTDumper.cpp
ASTResultSynthesizer.cpp
ASTStructExtractor.cpp
ASTUtils.cpp
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
index 372c2439ebf0..7440f6a0c363 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -8,7 +8,6 @@
#include "ClangASTSource.h"
-#include "ASTDumper.h"
#include "ClangDeclVendor.h"
#include "ClangModulesDeclVendor.h"
@@ -279,9 +278,8 @@ void ClangASTSource::CompleteType(TagDecl *tag_decl) {
current_id, static_cast<void *>(m_ast_context),
static_cast<void *>(tag_decl), tag_decl->getName().str().c_str());
- LLDB_LOGF(log, " CTD[%u] Before:", current_id);
- ASTDumper dumper((Decl *)tag_decl);
- dumper.ToLog(log, " [CTD] ");
+ LLDB_LOG(log, " CTD[%u] Before:\n{0}", current_id,
+ ClangUtil::DumpDecl(tag_decl));
}
auto iter = m_active_lexical_decls.find(tag_decl);
@@ -407,26 +405,19 @@ void ClangASTSource::CompleteType(TagDecl *tag_decl) {
}
}
- if (log) {
- LLDB_LOGF(log, " [CTD] After:");
- ASTDumper dumper((Decl *)tag_decl);
- dumper.ToLog(log, " [CTD] ");
- }
+ LLDB_LOG(log, " [CTD] After:\n{0}", ClangUtil::DumpDecl(tag_decl));
}
void ClangASTSource::CompleteType(clang::ObjCInterfaceDecl *interface_decl) {
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
- if (log) {
- LLDB_LOGF(log,
- " [CompleteObjCInterfaceDecl] on (ASTContext*)%p Completing "
- "an ObjCInterfaceDecl named %s",
- static_cast<void *>(m_ast_context),
- interface_decl->getName().str().c_str());
- LLDB_LOGF(log, " [COID] Before:");
- ASTDumper dumper((Decl *)interface_decl);
- dumper.ToLog(log, " [COID] ");
- }
+ LLDB_LOGF(log,
+ " [CompleteObjCInterfaceDecl] on (ASTContext*)%p Completing "
+ "an ObjCInterfaceDecl named %s",
+ static_cast<void *>(m_ast_context),
+ interface_decl->getName().str().c_str());
+ LLDB_LOG(log, " [COID] Before:\n{0}",
+ ClangUtil::DumpDecl(interface_decl));
if (!m_ast_importer_sp) {
if (HasMerger()) {
@@ -468,8 +459,7 @@ void ClangASTSource::CompleteType(clang::ObjCInterfaceDecl *interface_decl) {
if (log) {
LLDB_LOGF(log, " [COID] After:");
- ASTDumper dumper((Decl *)interface_decl);
- dumper.ToLog(log, " [COID] ");
+ LLDB_LOG(log, " [COID] {0}", ClangUtil::DumpDecl(interface_decl));
}
}
@@ -581,12 +571,10 @@ void ClangASTSource::FindExternalLexicalDecls(
&original_ctx))
return;
- if (log) {
- LLDB_LOGF(
- log, " FELD[%u] Original decl (ASTContext*)%p (Decl*)%p:", current_id,
- static_cast<void *>(original_ctx), static_cast<void *>(original_decl));
- ASTDumper(original_decl).ToLog(log, " ");
- }
+ LLDB_LOG(
+ log, " FELD[{0}] Original decl (ASTContext*){1:x} (Decl*){2:x}:\n{3}",
+ current_id, static_cast<void *>(original_ctx),
+ static_cast<void *>(original_decl), ClangUtil::DumpDecl(original_decl));
if (ObjCInterfaceDecl *original_iface_decl =
dyn_cast<ObjCInterfaceDecl>(original_decl)) {
@@ -625,16 +613,16 @@ void ClangASTSource::FindExternalLexicalDecls(
// See clang::ExternalASTSource::FindExternalLexicalDecls()
if (predicate(decl->getKind())) {
if (log) {
- ASTDumper ast_dumper(decl);
+ std::string ast_dump = ClangUtil::DumpDecl(decl);
if (const NamedDecl *context_named_decl =
dyn_cast<NamedDecl>(context_decl))
LLDB_LOGF(log, " FELD[%d] Adding [to %sDecl %s] lexical %sDecl %s",
current_id, context_named_decl->getDeclKindName(),
context_named_decl->getNameAsString().c_str(),
- decl->getDeclKindName(), ast_dumper.GetCString());
+ decl->getDeclKindName(), ast_dump.c_str());
else
LLDB_LOGF(log, " FELD[%d] Adding lexical %sDecl %s", current_id,
- decl->getDeclKindName(), ast_dumper.GetCString());
+ decl->getDeclKindName(), ast_dump.c_str());
}
Decl *copied_decl = CopyDecl(decl);
@@ -1137,11 +1125,8 @@ bool ClangASTSource::FindObjCMethodDeclsWithOrigin(
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
- if (log) {
- ASTDumper dumper((Decl *)copied_method_decl);
- LLDB_LOGF(log, " CAS::FOMD[%d] found (%s) %s", current_id, log_info,
- dumper.GetCString());
- }
+ LLDB_LOG(log, " CAS::FOMD[{0}] found ({1}) {2}", current_id, log_info,
+ ClangUtil::DumpDecl(copied_method_decl));
context.AddNamedDecl(copied_method_decl);
}
@@ -1343,11 +1328,8 @@ void ClangASTSource::FindObjCMethodDecls(NameSearchContext &context) {
if (!copied_method_decl)
continue;
- if (log) {
- ASTDumper dumper((Decl *)copied_method_decl);
- LLDB_LOGF(log, " CAS::FOMD[%d] found (in symbols) %s", current_id,
- dumper.GetCString());
- }
+ LLDB_LOG(log, " CAS::FOMD[{0}] found (in symbols)\n{1}", current_id,
+ ClangUtil::DumpDecl(copied_method_decl));
context.AddNamedDecl(copied_method_decl);
}
@@ -1476,11 +1458,8 @@ static bool FindObjCPropertyAndIvarDeclsWithOrigin(
DeclFromParser<ObjCPropertyDecl> parser_property_decl(
origin_property_decl.Import(source));
if (parser_property_decl.IsValid()) {
- if (log) {
- ASTDumper dumper((Decl *)parser_property_decl.decl);
- LLDB_LOGF(log, " CAS::FOPD[%d] found %s", current_id,
- dumper.GetCString());
- }
+ LLDB_LOG(log, " CAS::FOPD[{0}] found\n{1}", current_id,
+ ClangUtil::DumpDecl(parser_property_decl.decl));
context.AddNamedDecl(parser_property_decl.decl);
found = true;
@@ -1495,9 +1474,8 @@ static bool FindObjCPropertyAndIvarDeclsWithOrigin(
origin_ivar_decl.Import(source));
if (parser_ivar_decl.IsValid()) {
if (log) {
- ASTDumper dumper((Decl *)parser_ivar_decl.decl);
- LLDB_LOGF(log, " CAS::FOPD[%d] found %s", current_id,
- dumper.GetCString());
+ LLDB_LOG(log, " CAS::FOPD[{0}] found\n{1}", current_id,
+ ClangUtil::DumpDecl(parser_ivar_decl.decl));
}
context.AddNamedDecl(parser_ivar_decl.decl);
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
index 30c0ddd3f2a0..88534d07200f 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -8,7 +8,6 @@
#include "ClangExpressionDeclMap.h"
-#include "ASTDumper.h"
#include "ClangASTSource.h"
#include "ClangModulesDeclVendor.h"
#include "ClangPersistentVariables.h"
@@ -20,6 +19,7 @@
#include "lldb/Core/ValueObjectVariable.h"
#include "lldb/Expression/Materializer.h"
#include "lldb/Symbol/ClangASTContext.h"
+#include "lldb/Symbol/ClangUtil.h"
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/CompilerDecl.h"
#include "lldb/Symbol/CompilerDeclContext.h"
@@ -878,11 +878,8 @@ void ClangExpressionDeclMap::LookUpLldbClass(NameSearchContext &context,
class_qual_type.getAsOpaquePtr(),
ClangASTContext::GetASTContext(&class_decl->getASTContext()));
- if (log) {
- ASTDumper ast_dumper(class_qual_type);
- LLDB_LOGF(log, " CEDM::FEVD[%u] Adding type for $__lldb_class: %s",
- current_id, ast_dumper.GetCString());
- }
+ LLDB_LOG(log, " CEDM::FEVD[{0}] Adding type for $__lldb_class: {1}",
+ current_id, class_qual_type.getAsString());
AddThisType(context, class_user_type, current_id);
@@ -924,17 +921,12 @@ void ClangExpressionDeclMap::LookUpLldbClass(NameSearchContext &context,
TypeFromUser pointee_type =
this_type->GetForwardCompilerType().GetPointeeType();
- if (pointee_type.IsValid()) {
- if (log) {
- ASTDumper ast_dumper(pointee_type);
- LLDB_LOGF(log, " FEVD[%u] Adding type for $__lldb_class: %s",
- current_id, ast_dumper.GetCString());
- }
+ LLDB_LOG(log, " FEVD[{0}] Adding type for $__lldb_class: {1}", current_id,
+ ClangUtil::GetQualType(pointee_type).getAsString());
- AddThisType(context, pointee_type, current_id);
- TypeFromUser this_user_type(this_type->GetFullCompilerType());
- m_struct_vars->m_object_pointer_type = this_user_type;
- }
+ AddThisType(context, pointee_type, current_id);
+ TypeFromUser this_user_type(this_type->GetFullCompilerType());
+ m_struct_vars->m_object_pointer_type = this_user_type;
}
}
@@ -996,11 +988,8 @@ void ClangExpressionDeclMap::LookUpLldbObjCClass(NameSearchContext &context,
QualType(interface_type, 0).getAsOpaquePtr(),
ClangASTContext::GetASTContext(&method_decl->getASTContext()));
- if (log) {
- ASTDumper ast_dumper(interface_type);
- LLDB_LOGF(log, " FEVD[%u] Adding type for $__lldb_objc_class: %s",
- current_id, ast_dumper.GetCString());
- }
+ LLDB_LOG(log, " FEVD[{0}] Adding type for $__lldb_objc_class: {1}",
+ current_id, ClangUtil::ToString(interface_type));
AddOneType(context, class_user_type, current_id);
@@ -1063,11 +1052,8 @@ void ClangExpressionDeclMap::LookUpLldbObjCClass(NameSearchContext &context,
if (!self_clang_type)
return;
- if (log) {
- ASTDumper ast_dumper(self_type->GetFullCompilerType());
- LLDB_LOGF(log, " FEVD[%u] Adding type for $__lldb_objc_class: %s",
- current_id, ast_dumper.GetCString());
- }
+ LLDB_LOG(log, " FEVD[{0}] Adding type for $__lldb_objc_class: {1}",
+ current_id, ClangUtil::ToString(self_type->GetFullCompilerType()));
TypeFromUser class_user_type(self_clang_type);
@@ -1684,14 +1670,10 @@ void ClangExpressionDeclMap::AddOneVariable(NameSearchContext &context,
if (is_reference)
entity->m_flags |= ClangExpressionVariable::EVTypeIsReference;
- if (log) {
- ASTDumper orig_dumper(ut.GetOpaqueQualType());
- ASTDumper ast_dumper(var_decl);
- LLDB_LOGF(log,
- " CEDM::FEVD[%u] Found variable %s, returned %s (original %s)",
- current_id, decl_name.c_str(), ast_dumper.GetCString(),
- orig_dumper.GetCString());
- }
+ LLDB_LOG(log,
+ " CEDM::FEVD[{0}] Found variable {1}, returned\n{2} (original {3})",
+ current_id, decl_name, ClangUtil::DumpDecl(var_decl),
+ ClangUtil::ToString(ut));
}
void ClangExpressionDeclMap::AddOneVariable(NameSearchContext &context,
@@ -1723,11 +1705,8 @@ void ClangExpressionDeclMap::AddOneVariable(NameSearchContext &context,
parser_vars->m_llvm_value = nullptr;
parser_vars->m_lldb_value.Clear();
- if (log) {
- ASTDumper ast_dumper(var_decl);
- LLDB_LOGF(log, " CEDM::FEVD[%u] Added pvar %s, returned %s", current_id,
- pvar_sp->GetName().GetCString(), ast_dumper.GetCString());
- }
+ LLDB_LOG(log, " CEDM::FEVD[{0}] Added pvar {1}, returned\n{2}", current_id,
+ pvar_sp->GetName(), ClangUtil::DumpDecl(var_decl));
}
void ClangExpressionDeclMap::AddOneGenericVariable(NameSearchContext &context,
@@ -1779,12 +1758,8 @@ void ClangExpressionDeclMap::AddOneGenericVariable(NameSearchContext &context,
parser_vars->m_llvm_value = nullptr;
parser_vars->m_lldb_sym = &symbol;
- if (log) {
- ASTDumper ast_dumper(var_decl);
-
- LLDB_LOGF(log, " CEDM::FEVD[%u] Found variable %s, returned %s",
- current_id, decl_name.c_str(), ast_dumper.GetCString());
- }
+ LLDB_LOG(log, " CEDM::FEVD[{0}] Found variable {1}, returned\n{2}",
+ current_id, decl_name, ClangUtil::DumpDecl(var_decl));
}
void ClangExpressionDeclMap::AddOneRegister(NameSearchContext &context,
@@ -1824,12 +1799,9 @@ void ClangExpressionDeclMap::AddOneRegister(NameSearchContext &context,
parser_vars->m_lldb_value.Clear();
entity->m_flags |= ClangExpressionVariable::EVBareRegister;
- if (log) {
- ASTDumper ast_dumper(var_decl);
- LLDB_LOGF(log, " CEDM::FEVD[%d] Added register %s, returned %s",
- current_id, context.m_decl_name.getAsString().c_str(),
- ast_dumper.GetCString());
- }
+ LLDB_LOG(log, " CEDM::FEVD[{0}] Added register {1}, returned\n{2}",
+ current_id, context.m_decl_name.getAsString(),
+ ClangUtil::DumpDecl(var_decl));
}
void ClangExpressionDeclMap::AddOneFunction(NameSearchContext &context,
@@ -1872,17 +1844,16 @@ void ClangExpressionDeclMap::AddOneFunction(NameSearchContext &context,
CopyDecl(function_template));
if (copied_function_template) {
if (log) {
- ASTDumper ast_dumper((clang::Decl *)copied_function_template);
-
StreamString ss;
function->DumpSymbolContext(&ss);
- log->Printf(" CEDM::FEVD[%u] Imported decl for function template"
- " %s (description %s), returned %s",
- current_id,
- copied_function_template->getNameAsString().c_str(),
- ss.GetData(), ast_dumper.GetCString());
+ LLDB_LOG(log,
+ " CEDM::FEVD[{0}] Imported decl for function template"
+ " {1} (description {2}), returned\n{3}",
+ current_id, copied_function_template->getNameAsString(),
+ ss.GetData(),
+ ClangUtil::DumpDecl(copied_function_template));
}
context.AddNamedDecl(copied_function_template);
@@ -1892,18 +1863,15 @@ void ClangExpressionDeclMap::AddOneFunction(NameSearchContext &context,
llvm::dyn_cast_or_null<clang::FunctionDecl>(
CopyDecl(src_function_decl))) {
if (log) {
- ASTDumper ast_dumper((clang::Decl *)copied_function_decl);
-
StreamString ss;
function->DumpSymbolContext(&ss);
- LLDB_LOGF(log,
- " CEDM::FEVD[%u] Imported decl for function %s "
- "(description %s), returned %s",
- current_id,
- copied_function_decl->getNameAsString().c_str(),
- ss.GetData(), ast_dumper.GetCString());
+ LLDB_LOG(log,
+ " CEDM::FEVD[{0}]] Imported decl for function {1} "
+ "(description {2}), returned\n{3}",
+ current_id, copied_function_decl->getNameAsString(),
+ ss.GetData(), ClangUtil::DumpDecl(copied_function_decl));
}
context.AddNamedDecl(copied_function_decl);
@@ -2005,20 +1973,17 @@ void ClangExpressionDeclMap::AddOneFunction(NameSearchContext &context,
parser_vars->m_llvm_value = nullptr;
if (log) {
- std::string function_str =
- function_decl ? ASTDumper(function_decl).GetCString() : "nullptr";
-
StreamString ss;
fun_address.Dump(&ss,
m_parser_vars->m_exe_ctx.GetBestExecutionContextScope(),
Address::DumpStyleResolvedDescription);
- LLDB_LOGF(
- log,
- " CEDM::FEVD[%u] Found %s function %s (description %s), returned %s",
- current_id, (function ? "specific" : "generic"), decl_name.c_str(),
- ss.GetData(), function_str.c_str());
+ LLDB_LOG(log,
+ " CEDM::FEVD[{0}] Found {1} function {2} (description {3}), "
+ "returned\n{4}",
+ current_id, (function ? "specific" : "generic"), decl_name,
+ ss.GetData(), ClangUtil::DumpDecl(function_decl));
}
}
@@ -2062,15 +2027,11 @@ void ClangExpressionDeclMap::AddThisType(NameSearchContext &context,
method_type, lldb::eAccessPublic, is_virtual, is_static,
is_inline, is_explicit, is_attr_used, is_artificial);
- if (log) {
- ASTDumper method_ast_dumper((clang::Decl *)method_decl);
- ASTDumper type_ast_dumper(copied_clang_type);
-
- LLDB_LOGF(log,
- " CEDM::AddThisType Added function $__lldb_expr "
- "(description %s) for this type %s",
- method_ast_dumper.GetCString(), type_ast_dumper.GetCString());
- }
+ LLDB_LOG(log,
+ " CEDM::AddThisType Added function $__lldb_expr "
+ "(description {0}) for this type\n{1}",
+ ClangUtil::ToString(copied_clang_type),
+ ClangUtil::DumpDecl(method_decl));
}
if (!copied_clang_type.IsValid())
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp
index e13b0d1b0cd2..435392023001 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp
@@ -8,7 +8,6 @@
#include "AppleObjCDeclVendor.h"
-#include "Plugins/ExpressionParser/Clang/ASTDumper.h"
#include "Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h"
#include "lldb/Core/Module.h"
#include "lldb/Symbol/ClangExternalASTSourceCommon.h"
@@ -77,24 +76,18 @@ class lldb_private::AppleObjCExternalASTSource
Log *log(GetLogIfAllCategoriesSet(
LIBLLDB_LOG_EXPRESSIONS)); // FIXME - a more appropriate log channel?
- if (log) {
- LLDB_LOGF(log,
- "AppleObjCExternalASTSource::CompleteType[%u] on "
- "(ASTContext*)%p Completing (TagDecl*)%p named %s",
- current_id, static_cast<void *>(&tag_decl->getASTContext()),
- static_cast<void *>(tag_decl),
- tag_decl->getName().str().c_str());
+ LLDB_LOGF(log,
+ "AppleObjCExternalASTSource::CompleteType[%u] on "
+ "(ASTContext*)%p Completing (TagDecl*)%p named %s",
+ current_id, static_cast<void *>(&tag_decl->getASTContext()),
+ static_cast<void *>(tag_decl), tag_decl->getName().str().c_str());
- LLDB_LOGF(log, " AOEAS::CT[%u] Before:", current_id);
- ASTDumper dumper((clang::Decl *)tag_decl);
- dumper.ToLog(log, " [CT] ");
- }
+ LLDB_LOG(log, " AOEAS::CT[{0}] Before:\n{1}", current_id,
+ ClangUtil::DumpDecl(tag_decl));
+
+ LLDB_LOG(log, " AOEAS::CT[{1}] After:{1}", current_id,
+ ClangUtil::DumpDecl(tag_decl));
- if (log) {
- LLDB_LOGF(log, " AOEAS::CT[%u] After:", current_id);
- ASTDumper dumper((clang::Decl *)tag_decl);
- dumper.ToLog(log, " [CT] ");
- }
return;
}
@@ -115,16 +108,14 @@ class lldb_private::AppleObjCExternalASTSource
interface_decl->getName().str().c_str());
LLDB_LOGF(log, " AOEAS::CT[%u] Before:", current_id);
- ASTDumper dumper((clang::Decl *)interface_decl);
- dumper.ToLog(log, " [CT] ");
+ LLDB_LOG(log, " [CT] {0}", ClangUtil::DumpDecl(interface_decl));
}
m_decl_vendor.FinishDecl(interface_decl);
if (log) {
LLDB_LOGF(log, " [CT] After:");
- ASTDumper dumper((clang::Decl *)interface_decl);
- dumper.ToLog(log, " [CT] ");
+ LLDB_LOG(log, " [CT] {0}", ClangUtil::DumpDecl(interface_decl));
}
return;
}
@@ -526,27 +517,21 @@ bool AppleObjCDeclVendor::FinishDecl(clang::ObjCInterfaceDecl *interface_decl) {
return false;
};
- if (log) {
- ASTDumper method_dumper((clang::Decl *)interface_decl);
-
- LLDB_LOGF(log,
- "[AppleObjCDeclVendor::FinishDecl] Finishing Objective-C "
- "interface for %s",
- descriptor->GetClassName().AsCString());
- }
+ LLDB_LOG(log,
+ "[AppleObjCDeclVendor::FinishDecl] Finishing Objective-C "
+ "interface for %s",
+ descriptor->GetClassName().AsCString());
if (!descriptor->Describe(superclass_func, instance_method_func,
class_method_func, ivar_func))
return false;
if (log) {
- ASTDumper method_dumper((clang::Decl *)interface_decl);
-
LLDB_LOGF(
log,
"[AppleObjCDeclVendor::FinishDecl] Finished Objective-C interface");
- method_dumper.ToLog(log, " [AOTV::FD] ");
+ LLDB_LOG(log, " [AOTV::FD] {0}", ClangUtil::DumpDecl(interface_decl));
}
return true;
@@ -590,7 +575,6 @@ AppleObjCDeclVendor::FindDecls(ConstString name, bool append,
if (log) {
clang::QualType result_iface_type =
ast_ctx->getObjCInterfaceType(result_iface_decl);
- ASTDumper dumper(result_iface_type);
uint64_t isa_value = LLDB_INVALID_ADDRESS;
ClangASTMetadata *metadata =
@@ -598,10 +582,10 @@ AppleObjCDeclVendor::FindDecls(ConstString name, bool append,
if (metadata)
isa_value = metadata->GetISAPtr();
- LLDB_LOGF(log,
- "AOCTV::FT [%u] Found %s (isa 0x%" PRIx64
- ") in the ASTContext",
- current_id, dumper.GetCString(), isa_value);
+ LLDB_LOG(log,
+ "AOCTV::FT [%u] Found %s (isa 0x%" PRIx64
+ ") in the ASTContext",
+ current_id, result_iface_type.getAsString(), isa_value);
}
decls.push_back(result_iface_decl);
@@ -643,9 +627,9 @@ AppleObjCDeclVendor::FindDecls(ConstString name, bool append,
if (log) {
clang::QualType new_iface_type =
ast_ctx->getObjCInterfaceType(iface_decl);
- ASTDumper dumper(new_iface_type);
- LLDB_LOGF(log, "AOCTV::FT [%u] Created %s (isa 0x%" PRIx64 ")",
- current_id, dumper.GetCString(), (uint64_t)isa);
+
+ LLDB_LOG(log, "AOCTV::FT [{0}] Created {1} (isa 0x{2:x})", current_id,
+ new_iface_type.getAsString(), (uint64_t)isa);
}
decls.push_back(iface_decl);
diff --git a/lldb/source/Symbol/ClangUtil.cpp b/lldb/source/Symbol/ClangUtil.cpp
index 71ff36a5ebab..52ea4f5111d6 100644
--- a/lldb/source/Symbol/ClangUtil.cpp
+++ b/lldb/source/Symbol/ClangUtil.cpp
@@ -59,3 +59,24 @@ clang::TagDecl *ClangUtil::GetAsTagDecl(const CompilerType &type) {
return qual_type->getAsTagDecl();
}
+
+std::string ClangUtil::DumpDecl(const clang::Decl *d) {
+ if (!d)
+ return "nullptr";
+
+ std::string result;
+ llvm::raw_string_ostream stream(result);
+ bool deserialize = false;
+ d->dump(stream, deserialize);
+
+ stream.flush();
+ return result;
+}
+
+std::string ClangUtil::ToString(const clang::Type *t) {
+ return clang::QualType(t, 0).getAsString();
+}
+
+std::string ClangUtil::ToString(const CompilerType &c) {
+ return ClangUtil::GetQualType(c).getAsString();
+}
More information about the lldb-commits
mailing list