[PATCH] D133499: [clang]: Add DeclContext::dumpDecl() in order to conveniently dump an AST from a DeclContext.

Tom Honermann via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 8 08:06:59 PDT 2022


tahonermann created this revision.
tahonermann added reviewers: erichkeane, aaron.ballman, shafik.
Herald added a project: All.
tahonermann requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This change enables a declaration to be conveniently displayed within a debugger when only a DeclContext is available. For example, in gdb:

  (gdb) p Ctx
  $1 = (const clang::DeclContext *) 0x145a54f0
  (gdb) p Ctx->dumpDecl()
  ClassTemplateSpecializationDecl 0x145a54b0 <t.cpp:6:5, line:7:12> col:12 struct ict
  `-TemplateArgument type 'int'
    `-BuiltinType 0x14538600 'int'
  $2 = void


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133499

Files:
  clang/include/clang/AST/DeclBase.h
  clang/lib/AST/ASTDumper.cpp


Index: clang/lib/AST/ASTDumper.cpp
===================================================================
--- clang/lib/AST/ASTDumper.cpp
+++ clang/lib/AST/ASTDumper.cpp
@@ -200,6 +200,11 @@
   P.Visit(this);
 }
 
+LLVM_DUMP_METHOD void DeclContext::dumpDecl() const {
+  if (const Decl *D = dyn_cast<Decl>(this))
+    D->dump();
+}
+
 LLVM_DUMP_METHOD void DeclContext::dumpLookups() const {
   dumpLookups(llvm::errs());
 }
Index: clang/include/clang/AST/DeclBase.h
===================================================================
--- clang/include/clang/AST/DeclBase.h
+++ clang/include/clang/AST/DeclBase.h
@@ -2524,6 +2524,7 @@
   static bool classof(const DeclContext *D) { return true; }
 
   void dumpDeclContext() const;
+  void dumpDecl() const;
   void dumpLookups() const;
   void dumpLookups(llvm::raw_ostream &OS, bool DumpDecls = false,
                    bool Deserialize = false) const;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133499.458747.patch
Type: text/x-patch
Size: 905 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220908/80760398/attachment-0001.bin>


More information about the cfe-commits mailing list