shafik created this revision. shafik added reviewers: labath, JDevlieghere, xiaobai, aam, amccarth. Herald added a subscriber: aprantl. shafik marked an inline comment as done. shafik added inline comments.
================ Comment at: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp:3060 + + switch (tag) { + case DW_TAG_array_type: ---------------- I added this change because currently when end up trying to parse non-types which generates diagnostic like the following: ``` error: anon.o {0x0000001e}: unhandled type tag 0x0034 (DW_TAG_variable), please file a bug and attach the file at the start of this error message ``` Currently when invoking `lldb-test symbols -dump-ast` it parses all the debug symbols and calls `print(...)` on the `TranslationUnitDecl`. While useful the `TranslationUnitDecl::print(...)` method gives us a higher level view then the dump from `ASTDumper` which is what we get when we invoke `dump()` on a specific AST node. The main motivation for this change is allow us to verify that the AST nodes we create when we parse DWARF. For example in order to verify we are correctly using `DIFlagExportSymbols` added by D66667 <https://reviews.llvm.org/D66667> we would want to dump a `CXXRecordDecl`: CXXRecordDecl 0x7fdc578295f8 <<invalid sloc>> <invalid sloc> struct definition |-DefinitionData is_anonymous pass_in_registers aggregate standard_layout trivially_copyable pod trivial literal ... and check for the `is_anonymous` flag or the lack thereof. My current approach is to enumerate the symbols and to obtain specific AST nodes if possible and dump them. It looks in some cases such as `FunctionDecl`s we don't have direct access to it but I don't think that is an major problem at this point. I did not implement it but we should probably have a way of request a specific type instead of indiscriminately dumping all of them. This is a work in progress and I am not sure if the following is the best approach and I am open to alternative approaches or modification to the current one. https://reviews.llvm.org/D67994 Files: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp tools/lldb-test/lldb-test.cpp
Index: tools/lldb-test/lldb-test.cpp =================================================================== --- tools/lldb-test/lldb-test.cpp +++ tools/lldb-test/lldb-test.cpp @@ -42,6 +42,7 @@ #include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/Signals.h" #include "llvm/Support/WithColor.h" + #include <cstdio> #include <thread> @@ -547,6 +548,35 @@ return make_string_error("Can't retrieve translation unit declaration."); tu->print(outs()); + + + lldb_private::TypeList type_list; + size_t ntypes = symfile->GetTypes(nullptr, eTypeClassAny, type_list); + printf( "Type list size: %zu\n", ntypes); + + for( size_t i = 0; i < ntypes; ++i) { + auto type = type_list.GetTypeAtIndex(i); + printf( "%s\n", type->GetName().AsCString() ); + + if (clang::CXXRecordDecl *record_decl = + clang_ast_ctx->GetAsCXXRecordDecl(type->GetFullCompilerType().GetOpaqueQualType()) ) + record_decl->dump(); + else if( clang::TagDecl *tag_decl = + clang_ast_ctx->GetAsTagDecl(type->GetFullCompilerType()) ) + tag_decl->dump(); + else if( clang::TypedefNameDecl *typedef_decl = + clang_ast_ctx->GetAsTypedefDecl(type->GetFullCompilerType()) ) + typedef_decl->dump(); + else if( clang::EnumDecl *enum_decl = clang_ast_ctx->GetAsEnumDecl(type->GetFullCompilerType()) ) + enum_decl->dump(); + else if ( const clang::FunctionDecl* func_decl = llvm::dyn_cast<clang::FunctionDecl>( + (clang::Decl*) + clang_ast_ctx->GetCanonicalQualType(type->GetFullCompilerType().GetOpaqueQualType()).getAsOpaquePtr()) ) + func_decl->dump(); + else { + clang_ast_ctx->GetCanonicalQualType(type->GetFullCompilerType().GetOpaqueQualType()).dump(); + } + } return Error::success(); } Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -3026,7 +3026,10 @@ return {}; Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO); - TypeSP type_sp = dwarf_ast->ParseTypeFromDWARF(sc, die, log, type_is_new_ptr); + + TypeSP type_sp; + + type_sp = dwarf_ast->ParseTypeFromDWARF(sc, die, log, type_is_new_ptr); if (type_sp) { GetTypeList().Insert(type_sp); @@ -3049,12 +3052,37 @@ bool parse_siblings, bool parse_children) { size_t types_added = 0; DWARFDIE die = orig_die; + while (die) { + const dw_tag_t tag = die.Tag(); bool type_is_new = false; - if (ParseType(sc, die, &type_is_new).get()) { - if (type_is_new) - ++types_added; + + switch (tag) { + case DW_TAG_array_type: + case DW_TAG_unspecified_type: + case DW_TAG_base_type: + case DW_TAG_class_type: + case DW_TAG_structure_type: + case DW_TAG_union_type: + case DW_TAG_enumeration_type: + case DW_TAG_subroutine_type: + case DW_TAG_subprogram: + case DW_TAG_inlined_subroutine: + case DW_TAG_pointer_type: + case DW_TAG_rvalue_reference_type: + case DW_TAG_reference_type: + case DW_TAG_typedef: + case DW_TAG_ptr_to_member_type: + ParseType(sc, die, &type_is_new).get(); + printf( "pubname: %s is_type = %d\n", die.GetPubname(), true); + break; + default: + printf( "pubname: %s is_type = %d\n", die.GetPubname(), false); + break; } + + if (type_is_new) + ++types_added; if (parse_children && die.HasChildren()) { if (die.Tag() == DW_TAG_subprogram) {
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits