diff options
| author | Sean Callanan <scallanan@apple.com> | 2011-08-05 23:43:37 +0000 |
|---|---|---|
| committer | Sean Callanan <scallanan@apple.com> | 2011-08-05 23:43:37 +0000 |
| commit | 72e4940bd1765afaab46619921cfef681c990d83 (patch) | |
| tree | f49f14cc3da8f89c173d4ef08e04108aafd4c10a /lldb/source | |
| parent | 1cd34b8fea60940f99b6a8ce3fd6418953887125 (diff) | |
| download | bcm5719-llvm-72e4940bd1765afaab46619921cfef681c990d83.tar.gz bcm5719-llvm-72e4940bd1765afaab46619921cfef681c990d83.zip | |
This is an overhaul of the expression parser code
that detects what context the current expression is
meant to execute in. LLDB now properly consults
the method declaration in the debug information
rather than trying to hunt down the "this" or "self"
pointer by name, which can be misleading.
Other fixes include:
- LLDB now properly detects that it is inside
an inlined C++ member function.
- LLDB now allows access to non-const members when
in const code.
- The functions in SymbolFile that locate the
DeclContext containing a DIE have been renamed
to reflect what they actually do. I have added
new functions that find the DeclContext for the
DIE itself.
I have also introduced testcases for C++ and
Objective-C.
llvm-svn: 136999
Diffstat (limited to 'lldb/source')
| -rw-r--r-- | lldb/source/Expression/ClangExpressionDeclMap.cpp | 7 | ||||
| -rw-r--r-- | lldb/source/Expression/ClangUserExpression.cpp | 59 | ||||
| -rw-r--r-- | lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp | 87 | ||||
| -rw-r--r-- | lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h | 13 | ||||
| -rw-r--r-- | lldb/source/Symbol/Block.cpp | 24 | ||||
| -rw-r--r-- | lldb/source/Symbol/Function.cpp | 24 | ||||
| -rw-r--r-- | lldb/source/Symbol/Type.cpp | 2 |
7 files changed, 165 insertions, 51 deletions
diff --git a/lldb/source/Expression/ClangExpressionDeclMap.cpp b/lldb/source/Expression/ClangExpressionDeclMap.cpp index ebcaa013c42..f4598dd364a 100644 --- a/lldb/source/Expression/ClangExpressionDeclMap.cpp +++ b/lldb/source/Expression/ClangExpressionDeclMap.cpp @@ -1874,7 +1874,12 @@ ClangExpressionDeclMap::GetDecls (NameSearchContext &context, const ConstString &pointer_target_type)) return; - TypeFromUser class_user_type(pointer_target_type, + clang::QualType pointer_target_qual_type = QualType::getFromOpaquePtr(pointer_target_type); + + if (pointer_target_qual_type.isConstQualified()) + pointer_target_qual_type.removeLocalConst(); + + TypeFromUser class_user_type(pointer_target_qual_type.getAsOpaquePtr(), this_type->GetClangAST()); if (log) diff --git a/lldb/source/Expression/ClangUserExpression.cpp b/lldb/source/Expression/ClangUserExpression.cpp index 71a528280d9..b4a704cf33c 100644 --- a/lldb/source/Expression/ClangUserExpression.cpp +++ b/lldb/source/Expression/ClangUserExpression.cpp @@ -37,6 +37,9 @@ #include "lldb/Target/ThreadPlan.h" #include "lldb/Target/ThreadPlanCallUserExpression.h" +#include "clang/AST/DeclCXX.h" +#include "clang/AST/DeclObjC.h" + using namespace lldb_private; ClangUserExpression::ClangUserExpression (const char *expr, @@ -68,44 +71,46 @@ ClangUserExpression::ASTTransformer (clang::ASTConsumer *passthrough) void ClangUserExpression::ScanContext(ExecutionContext &exe_ctx) { - VariableList *vars = exe_ctx.frame->GetVariableList(false); + if (!exe_ctx.frame) + return; + + SymbolContext sym_ctx = exe_ctx.frame->GetSymbolContext(lldb::eSymbolContextFunction); - if (!vars) + if (!sym_ctx.function) return; - lldb::VariableSP this_var(vars->FindVariable(ConstString("this"))); - lldb::VariableSP self_var(vars->FindVariable(ConstString("self"))); + clang::DeclContext *decl_context; - if (this_var.get()) - { - Type *this_type = this_var->GetType(); + if (sym_ctx.block && sym_ctx.block->GetInlinedFunctionInfo()) + decl_context = sym_ctx.block->GetClangDeclContextForInlinedFunction(); + else + decl_context = sym_ctx.function->GetClangDeclContext(); - lldb::clang_type_t pointer_target_type; + if (!decl_context) + return; - if (ClangASTContext::IsPointerType(this_type->GetClangForwardType(), - &pointer_target_type)) + if (clang::CXXMethodDecl *method_decl = llvm::dyn_cast<clang::CXXMethodDecl>(decl_context)) + { + if (method_decl->isInstance()) { - TypeFromUser target_ast_type(pointer_target_type, this_type->GetClangAST()); - - if (ClangASTContext::IsCXXClassType(target_ast_type.GetOpaqueQualType())) - { - m_cplusplus = true; + m_cplusplus = true; - if (target_ast_type.IsConst()) - m_const_object = true; - } + do { + clang::QualType this_type = method_decl->getThisType(decl_context->getParentASTContext()); + + const clang::PointerType *this_pointer_type = llvm::dyn_cast<clang::PointerType>(this_type.getTypePtr()); + + if (!this_pointer_type) + break; + + clang::QualType this_pointee_type = this_pointer_type->getPointeeType(); + } while (0); } } - else if (self_var.get()) + else if (clang::ObjCMethodDecl *method_decl = llvm::dyn_cast<clang::ObjCMethodDecl>(decl_context)) { - m_objectivec = true; - - Type *self_type = self_var->GetType(); - - if (self_type->GetClangForwardType() == self_type->GetClangASTContext().GetBuiltInType_objc_id()) - { - m_objectivec = false; - } + if (method_decl->isInstanceMethod()) + m_objectivec = true; } } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp index c29a78db9b4..4cb3576a194 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -1355,7 +1355,7 @@ SymbolFileDWARF::ParseChildMembers clang::DeclContext* -SymbolFileDWARF::GetClangDeclContextForTypeUID (lldb::user_id_t type_uid) +SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid) { DWARFDebugInfo* debug_info = DebugInfo(); if (debug_info) @@ -1363,7 +1363,21 @@ SymbolFileDWARF::GetClangDeclContextForTypeUID (lldb::user_id_t type_uid) DWARFCompileUnitSP cu_sp; const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp); if (die) - return GetClangDeclContextForDIE (cu_sp.get(), die); + return GetClangDeclContextContainingDIE (cu_sp.get(), die); + } + return NULL; +} + +clang::DeclContext* +SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid) +{ + DWARFDebugInfo* debug_info = DebugInfo(); + if (debug_info) + { + DWARFCompileUnitSP cu_sp; + const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp); + if (die) + return GetClangDeclContextForDIE (sc, cu_sp.get(), die); } return NULL; } @@ -2799,17 +2813,28 @@ SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoE } clang::DeclContext * -SymbolFileDWARF::GetClangDeclContextForDIEOffset (dw_offset_t die_offset) +SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset) { if (die_offset != DW_INVALID_OFFSET) { DWARFCompileUnitSP cu_sp; const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp); - return GetClangDeclContextForDIE (cu_sp.get(), die); + return GetClangDeclContextContainingDIE (cu_sp.get(), die); } return NULL; } +clang::DeclContext * +SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset) +{ + if (die_offset != DW_INVALID_OFFSET) + { + DWARFCompileUnitSP cu_sp; + const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp); + return GetClangDeclContextForDIE (sc, cu_sp.get(), die); + } + return NULL; +} clang::NamespaceDecl * SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die) @@ -2820,7 +2845,7 @@ SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *curr_cu, const DWARFDebu if (namespace_name) { Declaration decl; // TODO: fill in the decl object - clang::NamespaceDecl *namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, decl, GetClangDeclContextForDIE (curr_cu, die->GetParent())); + clang::NamespaceDecl *namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, decl, GetClangDeclContextContainingDIE (curr_cu, die->GetParent())); if (namespace_decl) LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die); return namespace_decl; @@ -2830,12 +2855,36 @@ SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *curr_cu, const DWARFDebu } clang::DeclContext * -SymbolFileDWARF::GetClangDeclContextForDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die) +SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die) +{ + // If this DIE has a specification, or an abstract origin, then trace to those. + + dw_offset_t die_offset = die->GetAttributeValueAsReference(this, curr_cu, DW_AT_specification, DW_INVALID_OFFSET); + if (die_offset != DW_INVALID_OFFSET) + return GetClangDeclContextForDIEOffset (sc, die_offset); + + die_offset = die->GetAttributeValueAsReference(this, curr_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET); + if (die_offset != DW_INVALID_OFFSET) + return GetClangDeclContextForDIEOffset (sc, die_offset); + + // This is the DIE we want. Parse it, then query our map. + + ParseType(sc, curr_cu, die, NULL); + + DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find(die); + if (pos != m_die_to_decl_ctx.end()) + return pos->second; + else + return NULL; +} + +clang::DeclContext * +SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die) { if (m_clang_tu_decl == NULL) m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl(); - //printf ("SymbolFileDWARF::GetClangDeclContextForDIE ( die = 0x%8.8x )\n", die->GetOffset()); + //printf ("SymbolFileDWARF::GetClangDeclContextContainingDIE ( die = 0x%8.8x )\n", die->GetOffset()); const DWARFDebugInfoEntry * const decl_die = die; clang::DeclContext *decl_ctx = NULL; @@ -2849,11 +2898,11 @@ SymbolFileDWARF::GetClangDeclContextForDIE (DWARFCompileUnit *curr_cu, const DWA DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find(die); if (pos != m_die_to_decl_ctx.end()) { - //printf ("SymbolFileDWARF::GetClangDeclContextForDIE ( die = 0x%8.8x ) => 0x%8.8x\n", decl_die->GetOffset(), die->GetOffset()); + //printf ("SymbolFileDWARF::GetClangDeclContextContainingDIE ( die = 0x%8.8x ) => 0x%8.8x\n", decl_die->GetOffset(), die->GetOffset()); return pos->second; } - //printf ("SymbolFileDWARF::GetClangDeclContextForDIE ( die = 0x%8.8x ) checking parent 0x%8.8x\n", decl_die->GetOffset(), die->GetOffset()); + //printf ("SymbolFileDWARF::GetClangDeclContextContainingDIE ( die = 0x%8.8x ) checking parent 0x%8.8x\n", decl_die->GetOffset(), die->GetOffset()); switch (die->Tag()) { @@ -2863,10 +2912,10 @@ SymbolFileDWARF::GetClangDeclContextForDIE (DWARFCompileUnit *curr_cu, const DWA if (namespace_name) { Declaration decl; // TODO: fill in the decl object - clang::NamespaceDecl *namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, decl, GetClangDeclContextForDIE (curr_cu, die)); + clang::NamespaceDecl *namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, decl, GetClangDeclContextContainingDIE (curr_cu, die)); if (namespace_decl) { - //printf ("SymbolFileDWARF::GetClangDeclContextForDIE ( die = 0x%8.8x ) => 0x%8.8x\n", decl_die->GetOffset(), die->GetOffset()); + //printf ("SymbolFileDWARF::GetClangDeclContextContainingDIE ( die = 0x%8.8x ) => 0x%8.8x\n", decl_die->GetOffset(), die->GetOffset()); LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die); } return namespace_decl; @@ -2882,7 +2931,7 @@ SymbolFileDWARF::GetClangDeclContextForDIE (DWARFCompileUnit *curr_cu, const DWA pos = m_die_to_decl_ctx.find(die); if (pos != m_die_to_decl_ctx.end()) { - //printf ("SymbolFileDWARF::GetClangDeclContextForDIE ( die = 0x%8.8x ) => 0x%8.8x\n", decl_die->GetOffset(), die->GetOffset()); + //printf ("SymbolFileDWARF::GetClangDeclContextContainingDIE ( die = 0x%8.8x ) => 0x%8.8x\n", decl_die->GetOffset(), die->GetOffset()); return pos->second; } else @@ -2905,8 +2954,8 @@ SymbolFileDWARF::GetClangDeclContextForDIE (DWARFCompileUnit *curr_cu, const DWA dw_offset_t die_offset = die->GetAttributeValueAsReference(this, curr_cu, DW_AT_specification, DW_INVALID_OFFSET); if (die_offset != DW_INVALID_OFFSET) { - //printf ("SymbolFileDWARF::GetClangDeclContextForDIE ( die = 0x%8.8x ) check DW_AT_specification 0x%8.8x\n", decl_die->GetOffset(), die_offset); - decl_ctx = GetClangDeclContextForDIEOffset (die_offset); + //printf ("SymbolFileDWARF::GetClangDeclContextContainingDIE ( die = 0x%8.8x ) check DW_AT_specification 0x%8.8x\n", decl_die->GetOffset(), die_offset); + decl_ctx = GetClangDeclContextContainingDIEOffset (die_offset); if (decl_ctx != m_clang_tu_decl) return decl_ctx; } @@ -2914,8 +2963,8 @@ SymbolFileDWARF::GetClangDeclContextForDIE (DWARFCompileUnit *curr_cu, const DWA die_offset = die->GetAttributeValueAsReference(this, curr_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET); if (die_offset != DW_INVALID_OFFSET) { - //printf ("SymbolFileDWARF::GetClangDeclContextForDIE ( die = 0x%8.8x ) check DW_AT_abstract_origin 0x%8.8x\n", decl_die->GetOffset(), die_offset); - decl_ctx = GetClangDeclContextForDIEOffset (die_offset); + //printf ("SymbolFileDWARF::GetClangDeclContextContainingDIE ( die = 0x%8.8x ) check DW_AT_abstract_origin 0x%8.8x\n", decl_die->GetOffset(), die_offset); + decl_ctx = GetClangDeclContextContainingDIEOffset (die_offset); if (decl_ctx != m_clang_tu_decl) return decl_ctx; } @@ -2923,7 +2972,7 @@ SymbolFileDWARF::GetClangDeclContextForDIE (DWARFCompileUnit *curr_cu, const DWA die = die->GetParent(); } // Right now we have only one translation unit per module... - //printf ("SymbolFileDWARF::GetClangDeclContextForDIE ( die = 0x%8.8x ) => 0x%8.8x\n", decl_die->GetOffset(), curr_cu->GetFirstDIEOffset()); + //printf ("SymbolFileDWARF::GetClangDeclContextContainingDIE ( die = 0x%8.8x ) => 0x%8.8x\n", decl_die->GetOffset(), curr_cu->GetFirstDIEOffset()); return m_clang_tu_decl; } @@ -3309,7 +3358,7 @@ SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, clang_type_was_created = true; clang_type = ast.CreateRecordType (type_name_cstr, tag_decl_kind, - GetClangDeclContextForDIE (dwarf_cu, die), + GetClangDeclContextContainingDIE (dwarf_cu, die), class_language); } @@ -3417,7 +3466,7 @@ SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, DW_ATE_signed, byte_size * 8); clang_type = ast.CreateEnumerationType (type_name_cstr, - GetClangDeclContextForDIE (dwarf_cu, die), + GetClangDeclContextContainingDIE (dwarf_cu, die), decl, enumerator_clang_type); } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h index 56e7abed291..374092325b5 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h @@ -101,7 +101,8 @@ public: virtual lldb::clang_type_t ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_opaque_type); virtual lldb_private::Type* ResolveType (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed = true); - virtual clang::DeclContext* GetClangDeclContextForTypeUID (lldb::user_id_t type_uid); + virtual clang::DeclContext* GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid); + virtual clang::DeclContext* GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid); virtual uint32_t ResolveSymbolContext (const lldb_private::Address& so_addr, uint32_t resolve_scope, lldb_private::SymbolContext& sc); virtual uint32_t ResolveSymbolContext (const lldb_private::FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, lldb_private::SymbolContextList& sc_list); @@ -183,10 +184,16 @@ public: SupportedVersion(uint16_t version); clang::DeclContext * - GetClangDeclContextForDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die); + GetClangDeclContextForDIE (const lldb_private::SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die); + + clang::DeclContext * + GetClangDeclContextForDIEOffset (const lldb_private::SymbolContext &sc, dw_offset_t die_offset); + + clang::DeclContext * + GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die); clang::DeclContext * - GetClangDeclContextForDIEOffset (dw_offset_t die_offset); + GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset); void SearchDeclContext (const clang::DeclContext *decl_context, diff --git a/lldb/source/Symbol/Block.cpp b/lldb/source/Symbol/Block.cpp index a7d5c5c6f87..8be43e7825d 100644 --- a/lldb/source/Symbol/Block.cpp +++ b/lldb/source/Symbol/Block.cpp @@ -11,6 +11,7 @@ #include "lldb/Symbol/Function.h" #include "lldb/Core/Module.h" #include "lldb/Core/Section.h" +#include "lldb/Symbol/SymbolFile.h" #include "lldb/Symbol/SymbolVendor.h" #include "lldb/Symbol/VariableList.h" @@ -535,6 +536,29 @@ Block::AppendVariables return num_variables_added; } +clang::DeclContext * +Block::GetClangDeclContextForInlinedFunction() +{ + SymbolContext sc; + + CalculateSymbolContext (&sc); + + if (!sc.module_sp) + return NULL; + + SymbolVendor *sym_vendor = sc.module_sp->GetSymbolVendor(); + + if (!sym_vendor) + return NULL; + + SymbolFile *sym_file = sym_vendor->GetSymbolFile(); + + if (!sym_file) + return NULL; + + return sym_file->GetClangDeclContextForTypeUID (sc, m_uid); +} + void Block::SetBlockInfoHasBeenParsed (bool b, bool set_children) { diff --git a/lldb/source/Symbol/Function.cpp b/lldb/source/Symbol/Function.cpp index c2ef05d3251..5328159fdb7 100644 --- a/lldb/source/Symbol/Function.cpp +++ b/lldb/source/Symbol/Function.cpp @@ -14,6 +14,7 @@ #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Symbol/CompileUnit.h" #include "lldb/Symbol/LineTable.h" +#include "lldb/Symbol/SymbolFile.h" #include "lldb/Symbol/SymbolVendor.h" #include "clang/AST/Type.h" #include "clang/AST/CanonicalType.h" @@ -399,6 +400,29 @@ Function::MemorySize () const return mem_size; } +clang::DeclContext * +Function::GetClangDeclContext() +{ + SymbolContext sc; + + CalculateSymbolContext (&sc); + + if (!sc.module_sp) + return NULL; + + SymbolVendor *sym_vendor = sc.module_sp->GetSymbolVendor(); + + if (!sym_vendor) + return NULL; + + SymbolFile *sym_file = sym_vendor->GetSymbolFile(); + + if (!sym_file) + return NULL; + + return sym_file->GetClangDeclContextForTypeUID (sc, m_uid); +} + Type* Function::GetType() { diff --git a/lldb/source/Symbol/Type.cpp b/lldb/source/Symbol/Type.cpp index 67f2e80262b..46d8700db80 100644 --- a/lldb/source/Symbol/Type.cpp +++ b/lldb/source/Symbol/Type.cpp @@ -640,7 +640,7 @@ Type::CreateClangTypedefType (Type *typedef_type, Type *base_type) assert(typedef_type && base_type); return GetClangASTContext().CreateTypedefType (typedef_type->GetName().AsCString(), base_type->GetClangForwardType(), - typedef_type->GetSymbolFile()->GetClangDeclContextForTypeUID(typedef_type->GetID())); + typedef_type->GetSymbolFile()->GetClangDeclContextContainingTypeUID(typedef_type->GetID())); } void * |

