| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- SymbolFileDWARF.cpp ------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "SymbolFileDWARF.h" |
| 11 | |
| 12 | // Other libraries and framework includes |
| 13 | #include "clang/AST/ASTConsumer.h" |
| 14 | #include "clang/AST/ASTContext.h" |
| 15 | #include "clang/AST/Decl.h" |
| 16 | #include "clang/AST/DeclGroup.h" |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclObjC.h" |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclTemplate.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | #include "clang/Basic/Builtins.h" |
| 20 | #include "clang/Basic/IdentifierTable.h" |
| 21 | #include "clang/Basic/LangOptions.h" |
| 22 | #include "clang/Basic/SourceManager.h" |
| 23 | #include "clang/Basic/TargetInfo.h" |
| 24 | #include "clang/Basic/Specifiers.h" |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 25 | #include "clang/Sema/DeclSpec.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 26 | |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 27 | #include "llvm/Support/Casting.h" |
| 28 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | #include "lldb/Core/Module.h" |
| 30 | #include "lldb/Core/PluginManager.h" |
| 31 | #include "lldb/Core/RegularExpression.h" |
| 32 | #include "lldb/Core/Scalar.h" |
| 33 | #include "lldb/Core/Section.h" |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 34 | #include "lldb/Core/StreamFile.h" |
| Jim Ingham | 318c9f2 | 2011-08-26 19:44:13 +0000 | [diff] [blame] | 35 | #include "lldb/Core/StreamString.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 36 | #include "lldb/Core/Timer.h" |
| 37 | #include "lldb/Core/Value.h" |
| 38 | |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 39 | #include "lldb/Host/Host.h" |
| 40 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 41 | #include "lldb/Symbol/Block.h" |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 42 | #include "lldb/Symbol/ClangExternalASTSourceCallbacks.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | #include "lldb/Symbol/CompileUnit.h" |
| 44 | #include "lldb/Symbol/LineTable.h" |
| 45 | #include "lldb/Symbol/ObjectFile.h" |
| 46 | #include "lldb/Symbol/SymbolVendor.h" |
| 47 | #include "lldb/Symbol/VariableList.h" |
| 48 | |
| Jim Ingham | b7f6b2f | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 49 | #include "lldb/Target/ObjCLanguageRuntime.h" |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 50 | #include "lldb/Target/CPPLanguageRuntime.h" |
| Jim Ingham | b7f6b2f | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 51 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 52 | #include "DWARFCompileUnit.h" |
| 53 | #include "DWARFDebugAbbrev.h" |
| 54 | #include "DWARFDebugAranges.h" |
| 55 | #include "DWARFDebugInfo.h" |
| 56 | #include "DWARFDebugInfoEntry.h" |
| 57 | #include "DWARFDebugLine.h" |
| 58 | #include "DWARFDebugPubnames.h" |
| 59 | #include "DWARFDebugRanges.h" |
| 60 | #include "DWARFDIECollection.h" |
| 61 | #include "DWARFFormValue.h" |
| 62 | #include "DWARFLocationList.h" |
| 63 | #include "LogChannelDWARF.h" |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 64 | #include "SymbolFileDWARFDebugMap.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 65 | |
| 66 | #include <map> |
| 67 | |
| Greg Clayton | 62742b1 | 2010-11-11 01:09:45 +0000 | [diff] [blame] | 68 | //#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 69 | |
| 70 | #ifdef ENABLE_DEBUG_PRINTF |
| 71 | #include <stdio.h> |
| 72 | #define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__) |
| 73 | #else |
| 74 | #define DEBUG_PRINTF(fmt, ...) |
| 75 | #endif |
| 76 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 77 | #define DIE_IS_BEING_PARSED ((lldb_private::Type*)1) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 78 | |
| 79 | using namespace lldb; |
| 80 | using namespace lldb_private; |
| 81 | |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 82 | static inline bool |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 83 | child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag) |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 84 | { |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 85 | switch (tag) |
| 86 | { |
| 87 | default: |
| 88 | break; |
| 89 | case DW_TAG_subprogram: |
| 90 | case DW_TAG_inlined_subroutine: |
| 91 | case DW_TAG_class_type: |
| 92 | case DW_TAG_structure_type: |
| 93 | case DW_TAG_union_type: |
| 94 | return true; |
| 95 | } |
| 96 | return false; |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 97 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 98 | |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 99 | static AccessType |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 100 | DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 101 | { |
| 102 | switch (dwarf_accessibility) |
| 103 | { |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 104 | case DW_ACCESS_public: return eAccessPublic; |
| 105 | case DW_ACCESS_private: return eAccessPrivate; |
| 106 | case DW_ACCESS_protected: return eAccessProtected; |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 107 | default: break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 108 | } |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 109 | return eAccessNone; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | void |
| 113 | SymbolFileDWARF::Initialize() |
| 114 | { |
| 115 | LogChannelDWARF::Initialize(); |
| 116 | PluginManager::RegisterPlugin (GetPluginNameStatic(), |
| 117 | GetPluginDescriptionStatic(), |
| 118 | CreateInstance); |
| 119 | } |
| 120 | |
| 121 | void |
| 122 | SymbolFileDWARF::Terminate() |
| 123 | { |
| 124 | PluginManager::UnregisterPlugin (CreateInstance); |
| 125 | LogChannelDWARF::Initialize(); |
| 126 | } |
| 127 | |
| 128 | |
| 129 | const char * |
| 130 | SymbolFileDWARF::GetPluginNameStatic() |
| 131 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 132 | return "dwarf"; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | const char * |
| 136 | SymbolFileDWARF::GetPluginDescriptionStatic() |
| 137 | { |
| 138 | return "DWARF and DWARF3 debug symbol file reader."; |
| 139 | } |
| 140 | |
| 141 | |
| 142 | SymbolFile* |
| 143 | SymbolFileDWARF::CreateInstance (ObjectFile* obj_file) |
| 144 | { |
| 145 | return new SymbolFileDWARF(obj_file); |
| 146 | } |
| 147 | |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 148 | TypeList * |
| 149 | SymbolFileDWARF::GetTypeList () |
| 150 | { |
| 151 | if (m_debug_map_symfile) |
| 152 | return m_debug_map_symfile->GetTypeList(); |
| 153 | return m_obj_file->GetModule()->GetTypeList(); |
| 154 | |
| 155 | } |
| 156 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 157 | //---------------------------------------------------------------------- |
| 158 | // Gets the first parent that is a lexical block, function or inlined |
| 159 | // subroutine, or compile unit. |
| 160 | //---------------------------------------------------------------------- |
| 161 | static const DWARFDebugInfoEntry * |
| 162 | GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die) |
| 163 | { |
| 164 | const DWARFDebugInfoEntry *die; |
| 165 | for (die = child_die->GetParent(); die != NULL; die = die->GetParent()) |
| 166 | { |
| 167 | dw_tag_t tag = die->Tag(); |
| 168 | |
| 169 | switch (tag) |
| 170 | { |
| 171 | case DW_TAG_compile_unit: |
| 172 | case DW_TAG_subprogram: |
| 173 | case DW_TAG_inlined_subroutine: |
| 174 | case DW_TAG_lexical_block: |
| 175 | return die; |
| 176 | } |
| 177 | } |
| 178 | return NULL; |
| 179 | } |
| 180 | |
| 181 | |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 182 | SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) : |
| 183 | SymbolFile (objfile), |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 184 | UserID (0), // Used by SymbolFileDWARFDebugMap to when this class parses .o files to contain the .o file index/ID |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 185 | m_debug_map_symfile (NULL), |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 186 | m_clang_tu_decl (NULL), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 187 | m_flags(), |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 188 | m_data_debug_abbrev (), |
| 189 | m_data_debug_aranges (), |
| 190 | m_data_debug_frame (), |
| 191 | m_data_debug_info (), |
| 192 | m_data_debug_line (), |
| 193 | m_data_debug_loc (), |
| 194 | m_data_debug_ranges (), |
| 195 | m_data_debug_str (), |
| Greg Clayton | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 196 | m_data_apple_names (), |
| 197 | m_data_apple_types (), |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 198 | m_data_apple_namespaces (), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 199 | m_abbr(), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 200 | m_info(), |
| 201 | m_line(), |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 202 | m_apple_names_ap (), |
| 203 | m_apple_types_ap (), |
| 204 | m_apple_namespaces_ap (), |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 205 | m_apple_objc_ap (), |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 206 | m_function_basename_index(), |
| 207 | m_function_fullname_index(), |
| 208 | m_function_method_index(), |
| 209 | m_function_selector_index(), |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 210 | m_objc_class_selectors_index(), |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 211 | m_global_index(), |
| Greg Clayton | 69b0488 | 2010-10-15 02:03:22 +0000 | [diff] [blame] | 212 | m_type_index(), |
| 213 | m_namespace_index(), |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 214 | m_indexed (false), |
| 215 | m_is_external_ast_source (false), |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 216 | m_using_apple_tables (false), |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 217 | m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate), |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 218 | m_ranges(), |
| 219 | m_unique_ast_type_map () |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 220 | { |
| 221 | } |
| 222 | |
| 223 | SymbolFileDWARF::~SymbolFileDWARF() |
| 224 | { |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 225 | if (m_is_external_ast_source) |
| 226 | m_obj_file->GetModule()->GetClangASTContext().RemoveExternalSource (); |
| 227 | } |
| 228 | |
| 229 | static const ConstString & |
| 230 | GetDWARFMachOSegmentName () |
| 231 | { |
| 232 | static ConstString g_dwarf_section_name ("__DWARF"); |
| 233 | return g_dwarf_section_name; |
| 234 | } |
| 235 | |
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 236 | UniqueDWARFASTTypeMap & |
| 237 | SymbolFileDWARF::GetUniqueDWARFASTTypeMap () |
| 238 | { |
| 239 | if (m_debug_map_symfile) |
| 240 | return m_debug_map_symfile->GetUniqueDWARFASTTypeMap (); |
| 241 | return m_unique_ast_type_map; |
| 242 | } |
| 243 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 244 | ClangASTContext & |
| 245 | SymbolFileDWARF::GetClangASTContext () |
| 246 | { |
| 247 | if (m_debug_map_symfile) |
| 248 | return m_debug_map_symfile->GetClangASTContext (); |
| 249 | |
| 250 | ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext(); |
| 251 | if (!m_is_external_ast_source) |
| 252 | { |
| 253 | m_is_external_ast_source = true; |
| 254 | llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap ( |
| 255 | new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl, |
| 256 | SymbolFileDWARF::CompleteObjCInterfaceDecl, |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 257 | SymbolFileDWARF::FindExternalVisibleDeclsByName, |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 258 | SymbolFileDWARF::LayoutRecordType, |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 259 | this)); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 260 | ast.SetExternalSource (ast_source_ap); |
| 261 | } |
| 262 | return ast; |
| 263 | } |
| 264 | |
| 265 | void |
| 266 | SymbolFileDWARF::InitializeObject() |
| 267 | { |
| 268 | // Install our external AST source callbacks so we can complete Clang types. |
| 269 | Module *module = m_obj_file->GetModule(); |
| 270 | if (module) |
| 271 | { |
| 272 | const SectionList *section_list = m_obj_file->GetSectionList(); |
| 273 | |
| 274 | const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get(); |
| 275 | |
| 276 | // Memory map the DWARF mach-o segment so we have everything mmap'ed |
| 277 | // to keep our heap memory usage down. |
| 278 | if (section) |
| Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 279 | m_obj_file->MemoryMapSectionData(section, m_dwarf_data); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 280 | } |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 281 | get_apple_names_data(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 282 | if (m_data_apple_names.GetByteSize() > 0) |
| 283 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 284 | m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names")); |
| 285 | if (m_apple_names_ap->IsValid()) |
| 286 | m_using_apple_tables = true; |
| 287 | else |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 288 | m_apple_names_ap.reset(); |
| 289 | } |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 290 | get_apple_types_data(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 291 | if (m_data_apple_types.GetByteSize() > 0) |
| 292 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 293 | m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types")); |
| 294 | if (m_apple_types_ap->IsValid()) |
| 295 | m_using_apple_tables = true; |
| 296 | else |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 297 | m_apple_types_ap.reset(); |
| 298 | } |
| 299 | |
| 300 | get_apple_namespaces_data(); |
| 301 | if (m_data_apple_namespaces.GetByteSize() > 0) |
| 302 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 303 | m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces")); |
| 304 | if (m_apple_namespaces_ap->IsValid()) |
| 305 | m_using_apple_tables = true; |
| 306 | else |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 307 | m_apple_namespaces_ap.reset(); |
| 308 | } |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 309 | |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 310 | get_apple_objc_data(); |
| 311 | if (m_data_apple_objc.GetByteSize() > 0) |
| 312 | { |
| 313 | m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc")); |
| 314 | if (m_apple_objc_ap->IsValid()) |
| 315 | m_using_apple_tables = true; |
| 316 | else |
| 317 | m_apple_objc_ap.reset(); |
| 318 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | bool |
| 322 | SymbolFileDWARF::SupportedVersion(uint16_t version) |
| 323 | { |
| 324 | return version == 2 || version == 3; |
| 325 | } |
| 326 | |
| 327 | uint32_t |
| Sean Callanan | bfaf54d | 2011-12-03 04:38:43 +0000 | [diff] [blame] | 328 | SymbolFileDWARF::CalculateAbilities () |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 329 | { |
| 330 | uint32_t abilities = 0; |
| 331 | if (m_obj_file != NULL) |
| 332 | { |
| 333 | const Section* section = NULL; |
| 334 | const SectionList *section_list = m_obj_file->GetSectionList(); |
| 335 | if (section_list == NULL) |
| 336 | return 0; |
| 337 | |
| 338 | uint64_t debug_abbrev_file_size = 0; |
| 339 | uint64_t debug_aranges_file_size = 0; |
| 340 | uint64_t debug_frame_file_size = 0; |
| 341 | uint64_t debug_info_file_size = 0; |
| 342 | uint64_t debug_line_file_size = 0; |
| 343 | uint64_t debug_loc_file_size = 0; |
| 344 | uint64_t debug_macinfo_file_size = 0; |
| 345 | uint64_t debug_pubnames_file_size = 0; |
| 346 | uint64_t debug_pubtypes_file_size = 0; |
| 347 | uint64_t debug_ranges_file_size = 0; |
| 348 | uint64_t debug_str_file_size = 0; |
| 349 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 350 | section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 351 | |
| 352 | if (section) |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 353 | section_list = §ion->GetChildren (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 354 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 355 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 356 | if (section != NULL) |
| 357 | { |
| 358 | debug_info_file_size = section->GetByteSize(); |
| 359 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 360 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 361 | if (section) |
| 362 | debug_abbrev_file_size = section->GetByteSize(); |
| 363 | else |
| 364 | m_flags.Set (flagsGotDebugAbbrevData); |
| 365 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 366 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 367 | if (section) |
| 368 | debug_aranges_file_size = section->GetByteSize(); |
| 369 | else |
| 370 | m_flags.Set (flagsGotDebugArangesData); |
| 371 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 372 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 373 | if (section) |
| 374 | debug_frame_file_size = section->GetByteSize(); |
| 375 | else |
| 376 | m_flags.Set (flagsGotDebugFrameData); |
| 377 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 378 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 379 | if (section) |
| 380 | debug_line_file_size = section->GetByteSize(); |
| 381 | else |
| 382 | m_flags.Set (flagsGotDebugLineData); |
| 383 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 384 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 385 | if (section) |
| 386 | debug_loc_file_size = section->GetByteSize(); |
| 387 | else |
| 388 | m_flags.Set (flagsGotDebugLocData); |
| 389 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 390 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 391 | if (section) |
| 392 | debug_macinfo_file_size = section->GetByteSize(); |
| 393 | else |
| 394 | m_flags.Set (flagsGotDebugMacInfoData); |
| 395 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 396 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 397 | if (section) |
| 398 | debug_pubnames_file_size = section->GetByteSize(); |
| 399 | else |
| 400 | m_flags.Set (flagsGotDebugPubNamesData); |
| 401 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 402 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 403 | if (section) |
| 404 | debug_pubtypes_file_size = section->GetByteSize(); |
| 405 | else |
| 406 | m_flags.Set (flagsGotDebugPubTypesData); |
| 407 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 408 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 409 | if (section) |
| 410 | debug_ranges_file_size = section->GetByteSize(); |
| 411 | else |
| 412 | m_flags.Set (flagsGotDebugRangesData); |
| 413 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 414 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 415 | if (section) |
| 416 | debug_str_file_size = section->GetByteSize(); |
| 417 | else |
| 418 | m_flags.Set (flagsGotDebugStrData); |
| 419 | } |
| 420 | |
| 421 | if (debug_abbrev_file_size > 0 && debug_info_file_size > 0) |
| 422 | abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes; |
| 423 | |
| 424 | if (debug_line_file_size > 0) |
| 425 | abilities |= LineTables; |
| 426 | |
| 427 | if (debug_aranges_file_size > 0) |
| 428 | abilities |= AddressAcceleratorTable; |
| 429 | |
| 430 | if (debug_pubnames_file_size > 0) |
| 431 | abilities |= FunctionAcceleratorTable; |
| 432 | |
| 433 | if (debug_pubtypes_file_size > 0) |
| 434 | abilities |= TypeAcceleratorTable; |
| 435 | |
| 436 | if (debug_macinfo_file_size > 0) |
| 437 | abilities |= MacroInformation; |
| 438 | |
| 439 | if (debug_frame_file_size > 0) |
| 440 | abilities |= CallFrameInformation; |
| 441 | } |
| 442 | return abilities; |
| 443 | } |
| 444 | |
| 445 | const DataExtractor& |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 446 | SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 447 | { |
| 448 | if (m_flags.IsClear (got_flag)) |
| 449 | { |
| 450 | m_flags.Set (got_flag); |
| 451 | const SectionList *section_list = m_obj_file->GetSectionList(); |
| 452 | if (section_list) |
| 453 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 454 | Section *section = section_list->FindSectionByType(sect_type, true).get(); |
| 455 | if (section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 456 | { |
| 457 | // See if we memory mapped the DWARF segment? |
| 458 | if (m_dwarf_data.GetByteSize()) |
| 459 | { |
| 460 | data.SetData(m_dwarf_data, section->GetOffset (), section->GetByteSize()); |
| 461 | } |
| 462 | else |
| 463 | { |
| Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 464 | if (m_obj_file->ReadSectionData (section, data) == 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 465 | data.Clear(); |
| 466 | } |
| 467 | } |
| 468 | } |
| 469 | } |
| 470 | return data; |
| 471 | } |
| 472 | |
| 473 | const DataExtractor& |
| 474 | SymbolFileDWARF::get_debug_abbrev_data() |
| 475 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 476 | return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | const DataExtractor& |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 480 | SymbolFileDWARF::get_debug_aranges_data() |
| 481 | { |
| 482 | return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges); |
| 483 | } |
| 484 | |
| 485 | const DataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 486 | SymbolFileDWARF::get_debug_frame_data() |
| 487 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 488 | return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | const DataExtractor& |
| 492 | SymbolFileDWARF::get_debug_info_data() |
| 493 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 494 | return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | const DataExtractor& |
| 498 | SymbolFileDWARF::get_debug_line_data() |
| 499 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 500 | return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | const DataExtractor& |
| 504 | SymbolFileDWARF::get_debug_loc_data() |
| 505 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 506 | return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | const DataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 510 | SymbolFileDWARF::get_debug_ranges_data() |
| 511 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 512 | return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | const DataExtractor& |
| 516 | SymbolFileDWARF::get_debug_str_data() |
| 517 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 518 | return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 519 | } |
| 520 | |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 521 | const DataExtractor& |
| Greg Clayton | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 522 | SymbolFileDWARF::get_apple_names_data() |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 523 | { |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 524 | return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names); |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | const DataExtractor& |
| Greg Clayton | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 528 | SymbolFileDWARF::get_apple_types_data() |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 529 | { |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 530 | return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types); |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 531 | } |
| 532 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 533 | const DataExtractor& |
| 534 | SymbolFileDWARF::get_apple_namespaces_data() |
| 535 | { |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 536 | return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces); |
| 537 | } |
| 538 | |
| 539 | const DataExtractor& |
| 540 | SymbolFileDWARF::get_apple_objc_data() |
| 541 | { |
| 542 | return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 543 | } |
| 544 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 545 | |
| 546 | DWARFDebugAbbrev* |
| 547 | SymbolFileDWARF::DebugAbbrev() |
| 548 | { |
| 549 | if (m_abbr.get() == NULL) |
| 550 | { |
| 551 | const DataExtractor &debug_abbrev_data = get_debug_abbrev_data(); |
| 552 | if (debug_abbrev_data.GetByteSize() > 0) |
| 553 | { |
| 554 | m_abbr.reset(new DWARFDebugAbbrev()); |
| 555 | if (m_abbr.get()) |
| 556 | m_abbr->Parse(debug_abbrev_data); |
| 557 | } |
| 558 | } |
| 559 | return m_abbr.get(); |
| 560 | } |
| 561 | |
| 562 | const DWARFDebugAbbrev* |
| 563 | SymbolFileDWARF::DebugAbbrev() const |
| 564 | { |
| 565 | return m_abbr.get(); |
| 566 | } |
| 567 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 568 | |
| 569 | DWARFDebugInfo* |
| 570 | SymbolFileDWARF::DebugInfo() |
| 571 | { |
| 572 | if (m_info.get() == NULL) |
| 573 | { |
| 574 | Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this); |
| 575 | if (get_debug_info_data().GetByteSize() > 0) |
| 576 | { |
| 577 | m_info.reset(new DWARFDebugInfo()); |
| 578 | if (m_info.get()) |
| 579 | { |
| 580 | m_info->SetDwarfData(this); |
| 581 | } |
| 582 | } |
| 583 | } |
| 584 | return m_info.get(); |
| 585 | } |
| 586 | |
| 587 | const DWARFDebugInfo* |
| 588 | SymbolFileDWARF::DebugInfo() const |
| 589 | { |
| 590 | return m_info.get(); |
| 591 | } |
| 592 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 593 | DWARFCompileUnit* |
| 594 | SymbolFileDWARF::GetDWARFCompileUnitForUID(lldb::user_id_t cu_uid) |
| 595 | { |
| 596 | DWARFDebugInfo* info = DebugInfo(); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 597 | if (info && UserIDMatches(cu_uid)) |
| 598 | return info->GetCompileUnit((dw_offset_t)cu_uid).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 599 | return NULL; |
| 600 | } |
| 601 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 602 | |
| 603 | DWARFDebugRanges* |
| 604 | SymbolFileDWARF::DebugRanges() |
| 605 | { |
| 606 | if (m_ranges.get() == NULL) |
| 607 | { |
| 608 | Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this); |
| 609 | if (get_debug_ranges_data().GetByteSize() > 0) |
| 610 | { |
| 611 | m_ranges.reset(new DWARFDebugRanges()); |
| 612 | if (m_ranges.get()) |
| 613 | m_ranges->Extract(this); |
| 614 | } |
| 615 | } |
| 616 | return m_ranges.get(); |
| 617 | } |
| 618 | |
| 619 | const DWARFDebugRanges* |
| 620 | SymbolFileDWARF::DebugRanges() const |
| 621 | { |
| 622 | return m_ranges.get(); |
| 623 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 624 | |
| 625 | bool |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 626 | SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* curr_cu, CompUnitSP& compile_unit_sp) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 627 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 628 | if (curr_cu != NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 629 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 630 | const DWARFDebugInfoEntry * cu_die = curr_cu->GetCompileUnitDIEOnly (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 631 | if (cu_die) |
| 632 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 633 | const char * cu_die_name = cu_die->GetName(this, curr_cu); |
| 634 | const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, curr_cu, DW_AT_comp_dir, NULL); |
| Jim Ingham | 0f35ac2 | 2011-08-24 23:34:20 +0000 | [diff] [blame] | 635 | LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, curr_cu, DW_AT_language, 0); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 636 | if (cu_die_name) |
| 637 | { |
| Jim Ingham | 0909e5f | 2010-09-16 00:57:33 +0000 | [diff] [blame] | 638 | FileSpec cu_file_spec; |
| 639 | |
| Greg Clayton | 7bd65b9 | 2011-02-09 23:39:34 +0000 | [diff] [blame] | 640 | if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0') |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 641 | { |
| Jim Ingham | 0909e5f | 2010-09-16 00:57:33 +0000 | [diff] [blame] | 642 | // If we have a full path to the compile unit, we don't need to resolve |
| 643 | // the file. This can be expensive e.g. when the source files are NFS mounted. |
| 644 | cu_file_spec.SetFile (cu_die_name, false); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 645 | } |
| 646 | else |
| 647 | { |
| 648 | std::string fullpath(cu_comp_dir); |
| 649 | if (*fullpath.rbegin() != '/') |
| 650 | fullpath += '/'; |
| 651 | fullpath += cu_die_name; |
| Jim Ingham | 0909e5f | 2010-09-16 00:57:33 +0000 | [diff] [blame] | 652 | cu_file_spec.SetFile (fullpath.c_str(), false); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 653 | } |
| 654 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 655 | compile_unit_sp.reset(new CompileUnit (m_obj_file->GetModule(), |
| 656 | curr_cu, |
| 657 | cu_file_spec, |
| 658 | MakeUserID(curr_cu->GetOffset()), |
| 659 | cu_language)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 660 | if (compile_unit_sp.get()) |
| 661 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 662 | curr_cu->SetUserData(compile_unit_sp.get()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 663 | return true; |
| 664 | } |
| 665 | } |
| 666 | } |
| 667 | } |
| 668 | return false; |
| 669 | } |
| 670 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 671 | uint32_t |
| 672 | SymbolFileDWARF::GetNumCompileUnits() |
| 673 | { |
| 674 | DWARFDebugInfo* info = DebugInfo(); |
| 675 | if (info) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 676 | return info->GetNumCompileUnits(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 677 | return 0; |
| 678 | } |
| 679 | |
| 680 | CompUnitSP |
| 681 | SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx) |
| 682 | { |
| 683 | CompUnitSP comp_unit; |
| 684 | DWARFDebugInfo* info = DebugInfo(); |
| 685 | if (info) |
| 686 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 687 | DWARFCompileUnit* curr_cu = info->GetCompileUnitAtIndex(cu_idx); |
| 688 | if (curr_cu != NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 689 | { |
| 690 | // Our symbol vendor shouldn't be asking us to add a compile unit that |
| 691 | // has already been added to it, which this DWARF plug-in knows as it |
| 692 | // stores the lldb compile unit (CompileUnit) pointer in each |
| 693 | // DWARFCompileUnit object when it gets added. |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 694 | assert(curr_cu->GetUserData() == NULL); |
| 695 | ParseCompileUnit(curr_cu, comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 696 | } |
| 697 | } |
| 698 | return comp_unit; |
| 699 | } |
| 700 | |
| 701 | static void |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 702 | AddRangesToBlock (Block& block, |
| 703 | DWARFDebugRanges::RangeList& ranges, |
| 704 | addr_t block_base_addr) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 705 | { |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 706 | const size_t num_ranges = ranges.GetSize(); |
| 707 | for (size_t i = 0; i<num_ranges; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 708 | { |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 709 | const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i); |
| 710 | const addr_t range_base = range.GetRangeBase(); |
| 711 | assert (range_base >= block_base_addr); |
| 712 | block.AddRange(Block::Range (range_base - block_base_addr, range.GetByteSize()));; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 713 | } |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 714 | block.FinalizeRanges (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | |
| 718 | Function * |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 719 | SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 720 | { |
| 721 | DWARFDebugRanges::RangeList func_ranges; |
| 722 | const char *name = NULL; |
| 723 | const char *mangled = NULL; |
| 724 | int decl_file = 0; |
| 725 | int decl_line = 0; |
| 726 | int decl_column = 0; |
| 727 | int call_file = 0; |
| 728 | int call_line = 0; |
| 729 | int call_column = 0; |
| 730 | DWARFExpression frame_base; |
| 731 | |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 732 | assert (die->Tag() == DW_TAG_subprogram); |
| 733 | |
| 734 | if (die->Tag() != DW_TAG_subprogram) |
| 735 | return NULL; |
| 736 | |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 737 | if (die->GetDIENamesAndRanges (this, |
| 738 | dwarf_cu, |
| 739 | name, |
| 740 | mangled, |
| 741 | func_ranges, |
| 742 | decl_file, |
| 743 | decl_line, |
| 744 | decl_column, |
| 745 | call_file, |
| 746 | call_line, |
| 747 | call_column, |
| 748 | &frame_base)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 749 | { |
| 750 | // Union of all ranges in the function DIE (if the function is discontiguous) |
| 751 | AddressRange func_range; |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 752 | lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0); |
| 753 | lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 754 | if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr) |
| 755 | { |
| 756 | func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList()); |
| 757 | if (func_range.GetBaseAddress().IsValid()) |
| 758 | func_range.SetByteSize(highest_func_addr - lowest_func_addr); |
| 759 | } |
| 760 | |
| 761 | if (func_range.GetBaseAddress().IsValid()) |
| 762 | { |
| 763 | Mangled func_name; |
| 764 | if (mangled) |
| 765 | func_name.SetValue(mangled, true); |
| 766 | else if (name) |
| 767 | func_name.SetValue(name, false); |
| 768 | |
| 769 | FunctionSP func_sp; |
| 770 | std::auto_ptr<Declaration> decl_ap; |
| 771 | if (decl_file != 0 || decl_line != 0 || decl_column != 0) |
| Greg Clayton | d7e0546 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 772 | decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), |
| 773 | decl_line, |
| 774 | decl_column)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 775 | |
| Greg Clayton | 0bd4e1b | 2011-09-30 20:52:25 +0000 | [diff] [blame] | 776 | // Supply the type _only_ if it has already been parsed |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 777 | Type *func_type = m_die_to_type.lookup (die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 778 | |
| 779 | assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED); |
| 780 | |
| 781 | func_range.GetBaseAddress().ResolveLinkedAddress(); |
| 782 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 783 | const user_id_t func_user_id = MakeUserID(die->GetOffset()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 784 | func_sp.reset(new Function (sc.comp_unit, |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 785 | func_user_id, // UserID is the DIE offset |
| 786 | func_user_id, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 787 | func_name, |
| 788 | func_type, |
| 789 | func_range)); // first address range |
| 790 | |
| 791 | if (func_sp.get() != NULL) |
| 792 | { |
| Greg Clayton | 0bd4e1b | 2011-09-30 20:52:25 +0000 | [diff] [blame] | 793 | if (frame_base.IsValid()) |
| 794 | func_sp->GetFrameBaseExpression() = frame_base; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 795 | sc.comp_unit->AddFunction(func_sp); |
| 796 | return func_sp.get(); |
| 797 | } |
| 798 | } |
| 799 | } |
| 800 | return NULL; |
| 801 | } |
| 802 | |
| 803 | size_t |
| 804 | SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc) |
| 805 | { |
| 806 | assert (sc.comp_unit); |
| 807 | size_t functions_added = 0; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 808 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 809 | if (dwarf_cu) |
| 810 | { |
| 811 | DWARFDIECollection function_dies; |
| 812 | const size_t num_funtions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies); |
| 813 | size_t func_idx; |
| 814 | for (func_idx = 0; func_idx < num_funtions; ++func_idx) |
| 815 | { |
| 816 | const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 817 | if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 818 | { |
| 819 | if (ParseCompileUnitFunction(sc, dwarf_cu, die)) |
| 820 | ++functions_added; |
| 821 | } |
| 822 | } |
| 823 | //FixupTypes(); |
| 824 | } |
| 825 | return functions_added; |
| 826 | } |
| 827 | |
| 828 | bool |
| 829 | SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files) |
| 830 | { |
| 831 | assert (sc.comp_unit); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 832 | DWARFCompileUnit* curr_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID()); |
| 833 | assert (curr_cu); |
| 834 | const DWARFDebugInfoEntry * cu_die = curr_cu->GetCompileUnitDIEOnly(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 835 | |
| 836 | if (cu_die) |
| 837 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 838 | const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, curr_cu, DW_AT_comp_dir, NULL); |
| 839 | dw_offset_t stmt_list = cu_die->GetAttributeValueAsUnsigned(this, curr_cu, DW_AT_stmt_list, DW_INVALID_OFFSET); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 840 | |
| 841 | // All file indexes in DWARF are one based and a file of index zero is |
| 842 | // supposed to be the compile unit itself. |
| 843 | support_files.Append (*sc.comp_unit); |
| 844 | |
| 845 | return DWARFDebugLine::ParseSupportFiles(get_debug_line_data(), cu_comp_dir, stmt_list, support_files); |
| 846 | } |
| 847 | return false; |
| 848 | } |
| 849 | |
| 850 | struct ParseDWARFLineTableCallbackInfo |
| 851 | { |
| 852 | LineTable* line_table; |
| 853 | const SectionList *section_list; |
| 854 | lldb::addr_t prev_sect_file_base_addr; |
| 855 | lldb::addr_t curr_sect_file_base_addr; |
| 856 | bool is_oso_for_debug_map; |
| 857 | bool prev_in_final_executable; |
| 858 | DWARFDebugLine::Row prev_row; |
| 859 | SectionSP prev_section_sp; |
| 860 | SectionSP curr_section_sp; |
| 861 | }; |
| 862 | |
| 863 | //---------------------------------------------------------------------- |
| 864 | // ParseStatementTableCallback |
| 865 | //---------------------------------------------------------------------- |
| 866 | static void |
| 867 | ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData) |
| 868 | { |
| 869 | LineTable* line_table = ((ParseDWARFLineTableCallbackInfo*)userData)->line_table; |
| 870 | if (state.row == DWARFDebugLine::State::StartParsingLineTable) |
| 871 | { |
| 872 | // Just started parsing the line table |
| 873 | } |
| 874 | else if (state.row == DWARFDebugLine::State::DoneParsingLineTable) |
| 875 | { |
| 876 | // Done parsing line table, nothing to do for the cleanup |
| 877 | } |
| 878 | else |
| 879 | { |
| 880 | ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData; |
| 881 | // We have a new row, lets append it |
| 882 | |
| 883 | if (info->curr_section_sp.get() == NULL || info->curr_section_sp->ContainsFileAddress(state.address) == false) |
| 884 | { |
| 885 | info->prev_section_sp = info->curr_section_sp; |
| 886 | info->prev_sect_file_base_addr = info->curr_sect_file_base_addr; |
| 887 | // If this is an end sequence entry, then we subtract one from the |
| 888 | // address to make sure we get an address that is not the end of |
| 889 | // a section. |
| 890 | if (state.end_sequence && state.address != 0) |
| 891 | info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address - 1); |
| 892 | else |
| 893 | info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address); |
| 894 | |
| 895 | if (info->curr_section_sp.get()) |
| 896 | info->curr_sect_file_base_addr = info->curr_section_sp->GetFileAddress (); |
| 897 | else |
| 898 | info->curr_sect_file_base_addr = 0; |
| 899 | } |
| 900 | if (info->curr_section_sp.get()) |
| 901 | { |
| 902 | lldb::addr_t curr_line_section_offset = state.address - info->curr_sect_file_base_addr; |
| 903 | // Check for the fancy section magic to determine if we |
| 904 | |
| 905 | if (info->is_oso_for_debug_map) |
| 906 | { |
| 907 | // When this is a debug map object file that contains DWARF |
| 908 | // (referenced from an N_OSO debug map nlist entry) we will have |
| 909 | // a file address in the file range for our section from the |
| 910 | // original .o file, and a load address in the executable that |
| 911 | // contains the debug map. |
| 912 | // |
| 913 | // If the sections for the file range and load range are |
| 914 | // different, we have a remapped section for the function and |
| 915 | // this address is resolved. If they are the same, then the |
| 916 | // function for this address didn't make it into the final |
| 917 | // executable. |
| 918 | bool curr_in_final_executable = info->curr_section_sp->GetLinkedSection () != NULL; |
| 919 | |
| 920 | // If we are doing DWARF with debug map, then we need to carefully |
| 921 | // add each line table entry as there may be gaps as functions |
| 922 | // get moved around or removed. |
| 923 | if (!info->prev_row.end_sequence && info->prev_section_sp.get()) |
| 924 | { |
| 925 | if (info->prev_in_final_executable) |
| 926 | { |
| 927 | bool terminate_previous_entry = false; |
| 928 | if (!curr_in_final_executable) |
| 929 | { |
| 930 | // Check for the case where the previous line entry |
| 931 | // in a function made it into the final executable, |
| 932 | // yet the current line entry falls in a function |
| 933 | // that didn't. The line table used to be contiguous |
| 934 | // through this address range but now it isn't. We |
| 935 | // need to terminate the previous line entry so |
| 936 | // that we can reconstruct the line range correctly |
| 937 | // for it and to keep the line table correct. |
| 938 | terminate_previous_entry = true; |
| 939 | } |
| 940 | else if (info->curr_section_sp.get() != info->prev_section_sp.get()) |
| 941 | { |
| 942 | // Check for cases where the line entries used to be |
| 943 | // contiguous address ranges, but now they aren't. |
| 944 | // This can happen when order files specify the |
| 945 | // ordering of the functions. |
| 946 | lldb::addr_t prev_line_section_offset = info->prev_row.address - info->prev_sect_file_base_addr; |
| 947 | Section *curr_sect = info->curr_section_sp.get(); |
| 948 | Section *prev_sect = info->prev_section_sp.get(); |
| 949 | assert (curr_sect->GetLinkedSection()); |
| 950 | assert (prev_sect->GetLinkedSection()); |
| 951 | lldb::addr_t object_file_addr_delta = state.address - info->prev_row.address; |
| 952 | lldb::addr_t curr_linked_file_addr = curr_sect->GetLinkedFileAddress() + curr_line_section_offset; |
| 953 | lldb::addr_t prev_linked_file_addr = prev_sect->GetLinkedFileAddress() + prev_line_section_offset; |
| 954 | lldb::addr_t linked_file_addr_delta = curr_linked_file_addr - prev_linked_file_addr; |
| 955 | if (object_file_addr_delta != linked_file_addr_delta) |
| 956 | terminate_previous_entry = true; |
| 957 | } |
| 958 | |
| 959 | if (terminate_previous_entry) |
| 960 | { |
| 961 | line_table->InsertLineEntry (info->prev_section_sp, |
| 962 | state.address - info->prev_sect_file_base_addr, |
| 963 | info->prev_row.line, |
| 964 | info->prev_row.column, |
| 965 | info->prev_row.file, |
| 966 | false, // is_stmt |
| 967 | false, // basic_block |
| 968 | false, // state.prologue_end |
| 969 | false, // state.epilogue_begin |
| 970 | true); // end_sequence); |
| 971 | } |
| 972 | } |
| 973 | } |
| 974 | |
| 975 | if (curr_in_final_executable) |
| 976 | { |
| 977 | line_table->InsertLineEntry (info->curr_section_sp, |
| 978 | curr_line_section_offset, |
| 979 | state.line, |
| 980 | state.column, |
| 981 | state.file, |
| 982 | state.is_stmt, |
| 983 | state.basic_block, |
| 984 | state.prologue_end, |
| 985 | state.epilogue_begin, |
| 986 | state.end_sequence); |
| 987 | info->prev_section_sp = info->curr_section_sp; |
| 988 | } |
| 989 | else |
| 990 | { |
| 991 | // If the current address didn't make it into the final |
| 992 | // executable, the current section will be the __text |
| 993 | // segment in the .o file, so we need to clear this so |
| 994 | // we can catch the next function that did make it into |
| 995 | // the final executable. |
| 996 | info->prev_section_sp.reset(); |
| 997 | info->curr_section_sp.reset(); |
| 998 | } |
| 999 | |
| 1000 | info->prev_in_final_executable = curr_in_final_executable; |
| 1001 | } |
| 1002 | else |
| 1003 | { |
| 1004 | // We are not in an object file that contains DWARF for an |
| 1005 | // N_OSO, this is just a normal DWARF file. The DWARF spec |
| 1006 | // guarantees that the addresses will be in increasing order |
| 1007 | // so, since we store line tables in file address order, we |
| 1008 | // can always just append the line entry without needing to |
| 1009 | // search for the correct insertion point (we don't need to |
| 1010 | // use LineEntry::InsertLineEntry()). |
| 1011 | line_table->AppendLineEntry (info->curr_section_sp, |
| 1012 | curr_line_section_offset, |
| 1013 | state.line, |
| 1014 | state.column, |
| 1015 | state.file, |
| 1016 | state.is_stmt, |
| 1017 | state.basic_block, |
| 1018 | state.prologue_end, |
| 1019 | state.epilogue_begin, |
| 1020 | state.end_sequence); |
| 1021 | } |
| 1022 | } |
| 1023 | |
| 1024 | info->prev_row = state; |
| 1025 | } |
| 1026 | } |
| 1027 | |
| 1028 | bool |
| 1029 | SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc) |
| 1030 | { |
| 1031 | assert (sc.comp_unit); |
| 1032 | if (sc.comp_unit->GetLineTable() != NULL) |
| 1033 | return true; |
| 1034 | |
| 1035 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID()); |
| 1036 | if (dwarf_cu) |
| 1037 | { |
| 1038 | const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly(); |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1039 | if (dwarf_cu_die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1040 | { |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1041 | const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET); |
| 1042 | if (cu_line_offset != DW_INVALID_OFFSET) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1043 | { |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1044 | std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit)); |
| 1045 | if (line_table_ap.get()) |
| 1046 | { |
| 1047 | ParseDWARFLineTableCallbackInfo info = { |
| 1048 | line_table_ap.get(), |
| 1049 | m_obj_file->GetSectionList(), |
| 1050 | 0, |
| 1051 | 0, |
| 1052 | m_debug_map_symfile != NULL, |
| 1053 | false, |
| 1054 | DWARFDebugLine::Row(), |
| 1055 | SectionSP(), |
| 1056 | SectionSP() |
| 1057 | }; |
| 1058 | uint32_t offset = cu_line_offset; |
| 1059 | DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info); |
| 1060 | sc.comp_unit->SetLineTable(line_table_ap.release()); |
| 1061 | return true; |
| 1062 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1063 | } |
| 1064 | } |
| 1065 | } |
| 1066 | return false; |
| 1067 | } |
| 1068 | |
| 1069 | size_t |
| 1070 | SymbolFileDWARF::ParseFunctionBlocks |
| 1071 | ( |
| 1072 | const SymbolContext& sc, |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1073 | Block *parent_block, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1074 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1075 | const DWARFDebugInfoEntry *die, |
| 1076 | addr_t subprogram_low_pc, |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1077 | uint32_t depth |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1078 | ) |
| 1079 | { |
| 1080 | size_t blocks_added = 0; |
| 1081 | while (die != NULL) |
| 1082 | { |
| 1083 | dw_tag_t tag = die->Tag(); |
| 1084 | |
| 1085 | switch (tag) |
| 1086 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1087 | case DW_TAG_inlined_subroutine: |
| Greg Clayton | b4d3733 | 2011-08-12 16:22:48 +0000 | [diff] [blame] | 1088 | case DW_TAG_subprogram: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1089 | case DW_TAG_lexical_block: |
| 1090 | { |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1091 | Block *block = NULL; |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1092 | if (tag == DW_TAG_subprogram) |
| 1093 | { |
| 1094 | // Skip any DW_TAG_subprogram DIEs that are inside |
| 1095 | // of a normal or inlined functions. These will be |
| 1096 | // parsed on their own as separate entities. |
| 1097 | |
| 1098 | if (depth > 0) |
| 1099 | break; |
| 1100 | |
| 1101 | block = parent_block; |
| 1102 | } |
| 1103 | else |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1104 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1105 | BlockSP block_sp(new Block (MakeUserID(die->GetOffset()))); |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1106 | parent_block->AddChild(block_sp); |
| 1107 | block = block_sp.get(); |
| 1108 | } |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1109 | DWARFDebugRanges::RangeList ranges; |
| 1110 | const char *name = NULL; |
| 1111 | const char *mangled_name = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1112 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1113 | int decl_file = 0; |
| 1114 | int decl_line = 0; |
| 1115 | int decl_column = 0; |
| 1116 | int call_file = 0; |
| 1117 | int call_line = 0; |
| 1118 | int call_column = 0; |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1119 | if (die->GetDIENamesAndRanges (this, |
| 1120 | dwarf_cu, |
| 1121 | name, |
| 1122 | mangled_name, |
| 1123 | ranges, |
| 1124 | decl_file, decl_line, decl_column, |
| 1125 | call_file, call_line, call_column)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1126 | { |
| 1127 | if (tag == DW_TAG_subprogram) |
| 1128 | { |
| 1129 | assert (subprogram_low_pc == LLDB_INVALID_ADDRESS); |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1130 | subprogram_low_pc = ranges.GetMinRangeBase(0); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1131 | } |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1132 | else if (tag == DW_TAG_inlined_subroutine) |
| 1133 | { |
| 1134 | // We get called here for inlined subroutines in two ways. |
| 1135 | // The first time is when we are making the Function object |
| 1136 | // for this inlined concrete instance. Since we're creating a top level block at |
| 1137 | // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to |
| 1138 | // adjust the containing address. |
| 1139 | // The second time is when we are parsing the blocks inside the function that contains |
| 1140 | // the inlined concrete instance. Since these will be blocks inside the containing "real" |
| 1141 | // function the offset will be for that function. |
| 1142 | if (subprogram_low_pc == LLDB_INVALID_ADDRESS) |
| 1143 | { |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1144 | subprogram_low_pc = ranges.GetMinRangeBase(0); |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1145 | } |
| 1146 | } |
| 1147 | |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1148 | AddRangesToBlock (*block, ranges, subprogram_low_pc); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1149 | |
| 1150 | if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL)) |
| 1151 | { |
| 1152 | std::auto_ptr<Declaration> decl_ap; |
| 1153 | if (decl_file != 0 || decl_line != 0 || decl_column != 0) |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1154 | decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), |
| 1155 | decl_line, decl_column)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1156 | |
| 1157 | std::auto_ptr<Declaration> call_ap; |
| 1158 | if (call_file != 0 || call_line != 0 || call_column != 0) |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1159 | call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file), |
| 1160 | call_line, call_column)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1161 | |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1162 | block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | ++blocks_added; |
| 1166 | |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1167 | if (die->HasChildren()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1168 | { |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1169 | blocks_added += ParseFunctionBlocks (sc, |
| 1170 | block, |
| 1171 | dwarf_cu, |
| 1172 | die->GetFirstChild(), |
| 1173 | subprogram_low_pc, |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1174 | depth + 1); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1175 | } |
| 1176 | } |
| 1177 | } |
| 1178 | break; |
| 1179 | default: |
| 1180 | break; |
| 1181 | } |
| 1182 | |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1183 | // Only parse siblings of the block if we are not at depth zero. A depth |
| 1184 | // of zero indicates we are currently parsing the top level |
| 1185 | // DW_TAG_subprogram DIE |
| 1186 | |
| 1187 | if (depth == 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1188 | die = NULL; |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1189 | else |
| 1190 | die = die->GetSibling(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1191 | } |
| 1192 | return blocks_added; |
| 1193 | } |
| 1194 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1195 | bool |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1196 | SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu, |
| 1197 | const DWARFDebugInfoEntry *die, |
| 1198 | ClangASTContext::TemplateParameterInfos &template_param_infos) |
| 1199 | { |
| 1200 | const dw_tag_t tag = die->Tag(); |
| 1201 | |
| 1202 | switch (tag) |
| 1203 | { |
| 1204 | case DW_TAG_template_type_parameter: |
| 1205 | case DW_TAG_template_value_parameter: |
| 1206 | { |
| 1207 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| 1208 | |
| 1209 | DWARFDebugInfoEntry::Attributes attributes; |
| 1210 | const size_t num_attributes = die->GetAttributes (this, |
| 1211 | dwarf_cu, |
| 1212 | fixed_form_sizes, |
| 1213 | attributes); |
| 1214 | const char *name = NULL; |
| 1215 | Type *lldb_type = NULL; |
| 1216 | clang_type_t clang_type = NULL; |
| 1217 | uint64_t uval64 = 0; |
| 1218 | bool uval64_valid = false; |
| 1219 | if (num_attributes > 0) |
| 1220 | { |
| 1221 | DWARFFormValue form_value; |
| 1222 | for (size_t i=0; i<num_attributes; ++i) |
| 1223 | { |
| 1224 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 1225 | |
| 1226 | switch (attr) |
| 1227 | { |
| 1228 | case DW_AT_name: |
| 1229 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1230 | name = form_value.AsCString(&get_debug_str_data()); |
| 1231 | break; |
| 1232 | |
| 1233 | case DW_AT_type: |
| 1234 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1235 | { |
| 1236 | const dw_offset_t type_die_offset = form_value.Reference(dwarf_cu); |
| 1237 | lldb_type = ResolveTypeUID(type_die_offset); |
| 1238 | if (lldb_type) |
| 1239 | clang_type = lldb_type->GetClangForwardType(); |
| 1240 | } |
| 1241 | break; |
| 1242 | |
| 1243 | case DW_AT_const_value: |
| 1244 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1245 | { |
| 1246 | uval64_valid = true; |
| 1247 | uval64 = form_value.Unsigned(); |
| 1248 | } |
| 1249 | break; |
| 1250 | default: |
| 1251 | break; |
| 1252 | } |
| 1253 | } |
| 1254 | |
| 1255 | if (name && lldb_type && clang_type) |
| 1256 | { |
| 1257 | bool is_signed = false; |
| 1258 | template_param_infos.names.push_back(name); |
| 1259 | clang::QualType clang_qual_type (clang::QualType::getFromOpaquePtr (clang_type)); |
| 1260 | if (tag == DW_TAG_template_value_parameter && ClangASTContext::IsIntegerType (clang_type, is_signed) && uval64_valid) |
| 1261 | { |
| 1262 | llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed); |
| 1263 | template_param_infos.args.push_back (clang::TemplateArgument (llvm::APSInt(apint), clang_qual_type)); |
| 1264 | } |
| 1265 | else |
| 1266 | { |
| 1267 | template_param_infos.args.push_back (clang::TemplateArgument (clang_qual_type)); |
| 1268 | } |
| 1269 | } |
| 1270 | else |
| 1271 | { |
| 1272 | return false; |
| 1273 | } |
| 1274 | |
| 1275 | } |
| 1276 | } |
| 1277 | return true; |
| 1278 | |
| 1279 | default: |
| 1280 | break; |
| 1281 | } |
| 1282 | return false; |
| 1283 | } |
| 1284 | |
| 1285 | bool |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1286 | SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu, |
| 1287 | const DWARFDebugInfoEntry *parent_die, |
| 1288 | ClangASTContext::TemplateParameterInfos &template_param_infos) |
| 1289 | { |
| 1290 | |
| 1291 | if (parent_die == NULL) |
| 1292 | return NULL; |
| 1293 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1294 | Args template_parameter_names; |
| 1295 | for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); |
| 1296 | die != NULL; |
| 1297 | die = die->GetSibling()) |
| 1298 | { |
| 1299 | const dw_tag_t tag = die->Tag(); |
| 1300 | |
| 1301 | switch (tag) |
| 1302 | { |
| 1303 | case DW_TAG_template_type_parameter: |
| 1304 | case DW_TAG_template_value_parameter: |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1305 | ParseTemplateDIE (dwarf_cu, die, template_param_infos); |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1306 | break; |
| 1307 | |
| 1308 | default: |
| 1309 | break; |
| 1310 | } |
| 1311 | } |
| 1312 | if (template_param_infos.args.empty()) |
| 1313 | return false; |
| 1314 | return template_param_infos.args.size() == template_param_infos.names.size(); |
| 1315 | } |
| 1316 | |
| 1317 | clang::ClassTemplateDecl * |
| 1318 | SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx, |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1319 | lldb::AccessType access_type, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1320 | const char *parent_name, |
| 1321 | int tag_decl_kind, |
| 1322 | const ClangASTContext::TemplateParameterInfos &template_param_infos) |
| 1323 | { |
| 1324 | if (template_param_infos.IsValid()) |
| 1325 | { |
| 1326 | std::string template_basename(parent_name); |
| 1327 | template_basename.erase (template_basename.find('<')); |
| 1328 | ClangASTContext &ast = GetClangASTContext(); |
| 1329 | |
| 1330 | return ast.CreateClassTemplateDecl (decl_ctx, |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1331 | access_type, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1332 | template_basename.c_str(), |
| 1333 | tag_decl_kind, |
| 1334 | template_param_infos); |
| 1335 | } |
| 1336 | return NULL; |
| 1337 | } |
| 1338 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1339 | size_t |
| 1340 | SymbolFileDWARF::ParseChildMembers |
| 1341 | ( |
| 1342 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1343 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1344 | const DWARFDebugInfoEntry *parent_die, |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1345 | clang_type_t class_clang_type, |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1346 | const LanguageType class_language, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1347 | std::vector<clang::CXXBaseSpecifier *>& base_classes, |
| 1348 | std::vector<int>& member_accessibilities, |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1349 | DWARFDIECollection& member_function_dies, |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1350 | AccessType& default_accessibility, |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1351 | bool &is_a_class, |
| 1352 | LayoutInfo &layout_info |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1353 | ) |
| 1354 | { |
| 1355 | if (parent_die == NULL) |
| 1356 | return 0; |
| 1357 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1358 | size_t count = 0; |
| 1359 | const DWARFDebugInfoEntry *die; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 1360 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1361 | uint32_t member_idx = 0; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 1362 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1363 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 1364 | { |
| 1365 | dw_tag_t tag = die->Tag(); |
| 1366 | |
| 1367 | switch (tag) |
| 1368 | { |
| 1369 | case DW_TAG_member: |
| 1370 | { |
| 1371 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1372 | const size_t num_attributes = die->GetAttributes (this, |
| 1373 | dwarf_cu, |
| 1374 | fixed_form_sizes, |
| 1375 | attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1376 | if (num_attributes > 0) |
| 1377 | { |
| 1378 | Declaration decl; |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1379 | //DWARFExpression location; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1380 | const char *name = NULL; |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1381 | const char *prop_name = NULL; |
| 1382 | const char *prop_getter_name = NULL; |
| 1383 | const char *prop_setter_name = NULL; |
| 1384 | uint32_t prop_attributes = 0; |
| 1385 | |
| 1386 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1387 | bool is_artificial = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1388 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1389 | AccessType accessibility = eAccessNone; |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1390 | uint32_t member_byte_offset = UINT32_MAX; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1391 | size_t byte_size = 0; |
| 1392 | size_t bit_offset = 0; |
| 1393 | size_t bit_size = 0; |
| 1394 | uint32_t i; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1395 | for (i=0; i<num_attributes && !is_artificial; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1396 | { |
| 1397 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 1398 | DWARFFormValue form_value; |
| 1399 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1400 | { |
| 1401 | switch (attr) |
| 1402 | { |
| 1403 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 1404 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 1405 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 1406 | case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; |
| 1407 | case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; |
| 1408 | case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break; |
| 1409 | case DW_AT_bit_size: bit_size = form_value.Unsigned(); break; |
| 1410 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; |
| 1411 | case DW_AT_data_member_location: |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1412 | if (form_value.BlockData()) |
| 1413 | { |
| 1414 | Value initialValue(0); |
| 1415 | Value memberOffset(0); |
| 1416 | const DataExtractor& debug_info_data = get_debug_info_data(); |
| 1417 | uint32_t block_length = form_value.Unsigned(); |
| 1418 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 1419 | if (DWARFExpression::Evaluate(NULL, // ExecutionContext * |
| 1420 | NULL, // clang::ASTContext * |
| 1421 | NULL, // ClangExpressionVariableList * |
| 1422 | NULL, // ClangExpressionDeclMap * |
| 1423 | NULL, // RegisterContext * |
| 1424 | debug_info_data, |
| 1425 | block_offset, |
| 1426 | block_length, |
| 1427 | eRegisterKindDWARF, |
| 1428 | &initialValue, |
| 1429 | memberOffset, |
| 1430 | NULL)) |
| 1431 | { |
| 1432 | member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt(); |
| 1433 | } |
| 1434 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1435 | break; |
| 1436 | |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1437 | case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1438 | case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1439 | case DW_AT_declaration: |
| 1440 | case DW_AT_description: |
| 1441 | case DW_AT_mutable: |
| 1442 | case DW_AT_visibility: |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1443 | |
| 1444 | case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break; |
| 1445 | case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break; |
| 1446 | case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break; |
| 1447 | case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break; |
| 1448 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1449 | default: |
| 1450 | case DW_AT_sibling: |
| 1451 | break; |
| 1452 | } |
| 1453 | } |
| 1454 | } |
| Sean Callanan | 5a477cf | 2010-10-30 01:56:10 +0000 | [diff] [blame] | 1455 | |
| Greg Clayton | 4495393 | 2011-10-25 01:25:35 +0000 | [diff] [blame] | 1456 | // Clang has a DWARF generation bug where sometimes it |
| 1457 | // represents fields that are references with bad byte size |
| 1458 | // and bit size/offset information such as: |
| 1459 | // |
| 1460 | // DW_AT_byte_size( 0x00 ) |
| 1461 | // DW_AT_bit_size( 0x40 ) |
| 1462 | // DW_AT_bit_offset( 0xffffffffffffffc0 ) |
| 1463 | // |
| 1464 | // So check the bit offset to make sure it is sane, and if |
| 1465 | // the values are not sane, remove them. If we don't do this |
| 1466 | // then we will end up with a crash if we try to use this |
| 1467 | // type in an expression when clang becomes unhappy with its |
| 1468 | // recycled debug info. |
| Sean Callanan | 5a477cf | 2010-10-30 01:56:10 +0000 | [diff] [blame] | 1469 | |
| Greg Clayton | 4495393 | 2011-10-25 01:25:35 +0000 | [diff] [blame] | 1470 | if (bit_offset > 128) |
| 1471 | { |
| 1472 | bit_size = 0; |
| 1473 | bit_offset = 0; |
| 1474 | } |
| 1475 | |
| 1476 | // FIXME: Make Clang ignore Objective-C accessibility for expressions |
| Sean Callanan | 5a477cf | 2010-10-30 01:56:10 +0000 | [diff] [blame] | 1477 | if (class_language == eLanguageTypeObjC || |
| 1478 | class_language == eLanguageTypeObjC_plus_plus) |
| 1479 | accessibility = eAccessNone; |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1480 | |
| 1481 | if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name)) |
| 1482 | { |
| 1483 | // Not all compilers will mark the vtable pointer |
| 1484 | // member as artificial (llvm-gcc). We can't have |
| 1485 | // the virtual members in our classes otherwise it |
| 1486 | // throws off all child offsets since we end up |
| 1487 | // having and extra pointer sized member in our |
| 1488 | // class layouts. |
| 1489 | is_artificial = true; |
| 1490 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1491 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1492 | if (is_artificial == false) |
| 1493 | { |
| 1494 | Type *member_type = ResolveTypeUID(encoding_uid); |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1495 | clang::FieldDecl *field_decl = NULL; |
| Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1496 | if (member_type) |
| 1497 | { |
| 1498 | if (accessibility == eAccessNone) |
| 1499 | accessibility = default_accessibility; |
| 1500 | member_accessibilities.push_back(accessibility); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1501 | |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1502 | field_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type, |
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 1503 | name, |
| 1504 | member_type->GetClangLayoutType(), |
| 1505 | accessibility, |
| 1506 | bit_size); |
| Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1507 | } |
| 1508 | else |
| 1509 | { |
| 1510 | if (name) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1511 | GetObjectFile()->GetModule()->ReportError ("0x%8.8llx: DW_TAG_member '%s' refers to type 0x%8.8llx which was unable to be parsed", |
| 1512 | MakeUserID(die->GetOffset()), |
| 1513 | name, |
| 1514 | encoding_uid); |
| Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1515 | else |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1516 | GetObjectFile()->GetModule()->ReportError ("0x%8.8llx: DW_TAG_member refers to type 0x%8.8llx which was unable to be parsed", |
| 1517 | MakeUserID(die->GetOffset()), |
| 1518 | encoding_uid); |
| Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1519 | } |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1520 | |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1521 | if (member_byte_offset != UINT32_MAX || bit_size != 0) |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1522 | { |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1523 | ///////////////////////////////////////////////////////////// |
| 1524 | // How to locate a field given the DWARF debug information |
| 1525 | // |
| 1526 | // AT_byte_size indicates the size of the word in which the |
| 1527 | // bit offset must be interpreted. |
| 1528 | // |
| 1529 | // AT_data_member_location indicates the byte offset of the |
| 1530 | // word from the base address of the structure. |
| 1531 | // |
| 1532 | // AT_bit_offset indicates how many bits into the word |
| 1533 | // (according to the host endianness) the low-order bit of |
| 1534 | // the field starts. AT_bit_offset can be negative. |
| 1535 | // |
| 1536 | // AT_bit_size indicates the size of the field in bits. |
| 1537 | ///////////////////////////////////////////////////////////// |
| 1538 | |
| 1539 | ByteOrder object_endian = GetObjectFile()->GetModule()->GetArchitecture().GetDefaultEndian(); |
| 1540 | |
| 1541 | uint64_t total_bit_offset = 0; |
| 1542 | |
| 1543 | total_bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8)); |
| 1544 | |
| 1545 | if (object_endian == eByteOrderLittle) |
| 1546 | { |
| 1547 | total_bit_offset += byte_size * 8; |
| 1548 | total_bit_offset -= (bit_offset + bit_size); |
| 1549 | } |
| 1550 | else |
| 1551 | { |
| 1552 | total_bit_offset += bit_offset; |
| 1553 | } |
| 1554 | |
| 1555 | layout_info.field_offsets.insert(std::make_pair(field_decl, total_bit_offset)); |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1556 | } |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1557 | if (prop_name != NULL) |
| 1558 | { |
| 1559 | |
| 1560 | clang::ObjCIvarDecl *ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl); |
| 1561 | assert (ivar_decl != NULL); |
| 1562 | |
| 1563 | |
| 1564 | GetClangASTContext().AddObjCClassProperty (class_clang_type, |
| 1565 | prop_name, |
| 1566 | 0, |
| 1567 | ivar_decl, |
| 1568 | prop_setter_name, |
| 1569 | prop_getter_name, |
| 1570 | prop_attributes); |
| 1571 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1572 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1573 | } |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1574 | ++member_idx; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1575 | } |
| 1576 | break; |
| 1577 | |
| 1578 | case DW_TAG_subprogram: |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1579 | // Let the type parsing code handle this one for us. |
| 1580 | member_function_dies.Append (die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1581 | break; |
| 1582 | |
| 1583 | case DW_TAG_inheritance: |
| 1584 | { |
| 1585 | is_a_class = true; |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1586 | if (default_accessibility == eAccessNone) |
| 1587 | default_accessibility = eAccessPrivate; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1588 | // TODO: implement DW_TAG_inheritance type parsing |
| 1589 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1590 | const size_t num_attributes = die->GetAttributes (this, |
| 1591 | dwarf_cu, |
| 1592 | fixed_form_sizes, |
| 1593 | attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1594 | if (num_attributes > 0) |
| 1595 | { |
| 1596 | Declaration decl; |
| 1597 | DWARFExpression location; |
| 1598 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1599 | AccessType accessibility = default_accessibility; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1600 | bool is_virtual = false; |
| 1601 | bool is_base_of_class = true; |
| 1602 | off_t member_offset = 0; |
| 1603 | uint32_t i; |
| 1604 | for (i=0; i<num_attributes; ++i) |
| 1605 | { |
| 1606 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 1607 | DWARFFormValue form_value; |
| 1608 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1609 | { |
| 1610 | switch (attr) |
| 1611 | { |
| 1612 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 1613 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 1614 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 1615 | case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; |
| 1616 | case DW_AT_data_member_location: |
| 1617 | if (form_value.BlockData()) |
| 1618 | { |
| 1619 | Value initialValue(0); |
| 1620 | Value memberOffset(0); |
| 1621 | const DataExtractor& debug_info_data = get_debug_info_data(); |
| 1622 | uint32_t block_length = form_value.Unsigned(); |
| 1623 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1624 | if (DWARFExpression::Evaluate (NULL, |
| 1625 | NULL, |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1626 | NULL, |
| 1627 | NULL, |
| Jason Molenda | 2d107dd | 2010-11-20 01:28:30 +0000 | [diff] [blame] | 1628 | NULL, |
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 1629 | debug_info_data, |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1630 | block_offset, |
| 1631 | block_length, |
| 1632 | eRegisterKindDWARF, |
| 1633 | &initialValue, |
| 1634 | memberOffset, |
| 1635 | NULL)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1636 | { |
| 1637 | member_offset = memberOffset.ResolveValue(NULL, NULL).UInt(); |
| 1638 | } |
| 1639 | } |
| 1640 | break; |
| 1641 | |
| 1642 | case DW_AT_accessibility: |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1643 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1644 | break; |
| 1645 | |
| 1646 | case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break; |
| 1647 | default: |
| 1648 | case DW_AT_sibling: |
| 1649 | break; |
| 1650 | } |
| 1651 | } |
| 1652 | } |
| 1653 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 1654 | Type *base_class_type = ResolveTypeUID(encoding_uid); |
| 1655 | assert(base_class_type); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1656 | |
| Greg Clayton | f4ecaa5 | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 1657 | clang_type_t base_class_clang_type = base_class_type->GetClangFullType(); |
| 1658 | assert (base_class_clang_type); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1659 | if (class_language == eLanguageTypeObjC) |
| 1660 | { |
| Greg Clayton | f4ecaa5 | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 1661 | GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1662 | } |
| 1663 | else |
| 1664 | { |
| Greg Clayton | f4ecaa5 | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 1665 | base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type, |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1666 | accessibility, |
| 1667 | is_virtual, |
| 1668 | is_base_of_class)); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1669 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1670 | } |
| 1671 | } |
| 1672 | break; |
| 1673 | |
| 1674 | default: |
| 1675 | break; |
| 1676 | } |
| 1677 | } |
| 1678 | return count; |
| 1679 | } |
| 1680 | |
| 1681 | |
| 1682 | clang::DeclContext* |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 1683 | SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1684 | { |
| 1685 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1686 | if (debug_info && UserIDMatches(type_uid)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1687 | { |
| 1688 | DWARFCompileUnitSP cu_sp; |
| 1689 | const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp); |
| 1690 | if (die) |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 1691 | return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL); |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 1692 | } |
| 1693 | return NULL; |
| 1694 | } |
| 1695 | |
| 1696 | clang::DeclContext* |
| 1697 | SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid) |
| 1698 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1699 | if (UserIDMatches(type_uid)) |
| 1700 | return GetClangDeclContextForDIEOffset (sc, type_uid); |
| 1701 | return NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1702 | } |
| 1703 | |
| 1704 | Type* |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 1705 | SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1706 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1707 | if (UserIDMatches(type_uid)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1708 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1709 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 1710 | if (debug_info) |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 1711 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1712 | DWARFCompileUnitSP cu_sp; |
| 1713 | const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp); |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1714 | const bool assert_not_being_parsed = true; |
| 1715 | return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 1716 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1717 | } |
| 1718 | return NULL; |
| 1719 | } |
| 1720 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1721 | Type* |
| 1722 | SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed) |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1723 | { |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1724 | if (die != NULL) |
| 1725 | { |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1726 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| 1727 | if (log) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1728 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 1729 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'", |
| 1730 | die->GetOffset(), |
| 1731 | DW_TAG_value_to_name(die->Tag()), |
| 1732 | die->GetName(this, cu)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1733 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1734 | // We might be coming in in the middle of a type tree (a class |
| 1735 | // withing a class, an enum within a class), so parse any needed |
| 1736 | // parent DIEs before we get to this one... |
| 1737 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); |
| 1738 | switch (decl_ctx_die->Tag()) |
| 1739 | { |
| 1740 | case DW_TAG_structure_type: |
| 1741 | case DW_TAG_union_type: |
| 1742 | case DW_TAG_class_type: |
| 1743 | { |
| 1744 | // Get the type, which could be a forward declaration |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1745 | if (log) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1746 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 1747 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x", |
| 1748 | die->GetOffset(), |
| 1749 | DW_TAG_value_to_name(die->Tag()), |
| 1750 | die->GetName(this, cu), |
| 1751 | decl_ctx_die->GetOffset()); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1752 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1753 | Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1754 | if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag())) |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1755 | { |
| 1756 | if (log) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1757 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 1758 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function", |
| 1759 | die->GetOffset(), |
| 1760 | DW_TAG_value_to_name(die->Tag()), |
| 1761 | die->GetName(this, cu), |
| 1762 | decl_ctx_die->GetOffset()); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1763 | // Ask the type to complete itself if it already hasn't since if we |
| 1764 | // want a function (method or static) from a class, the class must |
| 1765 | // create itself and add it's own methods and class functions. |
| 1766 | if (parent_type) |
| 1767 | parent_type->GetClangFullType(); |
| 1768 | } |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1769 | } |
| 1770 | break; |
| 1771 | |
| 1772 | default: |
| 1773 | break; |
| 1774 | } |
| 1775 | return ResolveType (cu, die); |
| 1776 | } |
| 1777 | return NULL; |
| 1778 | } |
| 1779 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1780 | // This function is used when SymbolFileDWARFDebugMap owns a bunch of |
| 1781 | // SymbolFileDWARF objects to detect if this DWARF file is the one that |
| 1782 | // can resolve a clang_type. |
| 1783 | bool |
| 1784 | SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type) |
| 1785 | { |
| 1786 | clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type); |
| 1787 | const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers); |
| 1788 | return die != NULL; |
| 1789 | } |
| 1790 | |
| 1791 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1792 | lldb::clang_type_t |
| 1793 | SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type) |
| 1794 | { |
| 1795 | // We have a struct/union/class/enum that needs to be fully resolved. |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1796 | clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type); |
| 1797 | const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1798 | if (die == NULL) |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1799 | { |
| 1800 | // We have already resolved this type... |
| 1801 | return clang_type; |
| 1802 | } |
| 1803 | // Once we start resolving this type, remove it from the forward declaration |
| 1804 | // map in case anyone child members or other types require this type to get resolved. |
| 1805 | // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition |
| 1806 | // are done. |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1807 | m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers); |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1808 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1809 | |
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 1810 | // Disable external storage for this type so we don't get anymore |
| 1811 | // clang::ExternalASTSource queries for this type. |
| 1812 | ClangASTContext::SetHasExternalStorage (clang_type, false); |
| 1813 | |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 1814 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 1815 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1816 | DWARFCompileUnit *curr_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get(); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1817 | Type *type = m_die_to_type.lookup (die); |
| 1818 | |
| 1819 | const dw_tag_t tag = die->Tag(); |
| 1820 | |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1821 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| 1822 | if (log) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1823 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 1824 | "0x%8.8llx: %s '%s' resolving forward declaration...\n", |
| 1825 | MakeUserID(die->GetOffset()), |
| 1826 | DW_TAG_value_to_name(tag), |
| 1827 | type->GetName().AsCString()); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1828 | assert (clang_type); |
| 1829 | DWARFDebugInfoEntry::Attributes attributes; |
| 1830 | |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 1831 | ClangASTContext &ast = GetClangASTContext(); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1832 | |
| 1833 | switch (tag) |
| 1834 | { |
| 1835 | case DW_TAG_structure_type: |
| 1836 | case DW_TAG_union_type: |
| 1837 | case DW_TAG_class_type: |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 1838 | ast.StartTagDeclarationDefinition (clang_type); |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1839 | { |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1840 | LayoutInfo layout_info; |
| 1841 | if (die->HasChildren()) |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1842 | { |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1843 | |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1844 | LanguageType class_language = eLanguageTypeUnknown; |
| 1845 | bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type); |
| 1846 | if (is_objc_class) |
| 1847 | class_language = eLanguageTypeObjC; |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1848 | |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1849 | int tag_decl_kind = -1; |
| 1850 | AccessType default_accessibility = eAccessNone; |
| 1851 | if (tag == DW_TAG_structure_type) |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1852 | { |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1853 | tag_decl_kind = clang::TTK_Struct; |
| 1854 | default_accessibility = eAccessPublic; |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1855 | } |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1856 | else if (tag == DW_TAG_union_type) |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 1857 | { |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1858 | tag_decl_kind = clang::TTK_Union; |
| 1859 | default_accessibility = eAccessPublic; |
| 1860 | } |
| 1861 | else if (tag == DW_TAG_class_type) |
| 1862 | { |
| 1863 | tag_decl_kind = clang::TTK_Class; |
| 1864 | default_accessibility = eAccessPrivate; |
| 1865 | } |
| 1866 | |
| 1867 | SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu)); |
| 1868 | std::vector<clang::CXXBaseSpecifier *> base_classes; |
| 1869 | std::vector<int> member_accessibilities; |
| 1870 | bool is_a_class = false; |
| 1871 | // Parse members and base classes first |
| 1872 | DWARFDIECollection member_function_dies; |
| 1873 | |
| 1874 | ParseChildMembers (sc, |
| 1875 | curr_cu, |
| 1876 | die, |
| 1877 | clang_type, |
| 1878 | class_language, |
| 1879 | base_classes, |
| 1880 | member_accessibilities, |
| 1881 | member_function_dies, |
| 1882 | default_accessibility, |
| 1883 | is_a_class, |
| 1884 | layout_info); |
| 1885 | |
| 1886 | // Now parse any methods if there were any... |
| 1887 | size_t num_functions = member_function_dies.Size(); |
| 1888 | if (num_functions > 0) |
| 1889 | { |
| 1890 | for (size_t i=0; i<num_functions; ++i) |
| 1891 | { |
| 1892 | ResolveType(curr_cu, member_function_dies.GetDIEPtrAtIndex(i)); |
| 1893 | } |
| 1894 | } |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 1895 | |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1896 | if (class_language == eLanguageTypeObjC) |
| 1897 | { |
| 1898 | std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(clang_type)); |
| 1899 | if (!class_str.empty()) |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 1900 | { |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1901 | |
| 1902 | DIEArray method_die_offsets; |
| 1903 | if (m_using_apple_tables) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 1904 | { |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1905 | if (m_apple_objc_ap.get()) |
| 1906 | m_apple_objc_ap->FindByName(class_str.c_str(), method_die_offsets); |
| 1907 | } |
| 1908 | else |
| 1909 | { |
| 1910 | if (!m_indexed) |
| 1911 | Index (); |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 1912 | |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1913 | ConstString class_name (class_str.c_str()); |
| 1914 | m_objc_class_selectors_index.Find (class_name, method_die_offsets); |
| 1915 | } |
| 1916 | |
| 1917 | if (!method_die_offsets.empty()) |
| 1918 | { |
| 1919 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 1920 | |
| 1921 | DWARFCompileUnit* method_cu = NULL; |
| 1922 | const size_t num_matches = method_die_offsets.size(); |
| 1923 | for (size_t i=0; i<num_matches; ++i) |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 1924 | { |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1925 | const dw_offset_t die_offset = method_die_offsets[i]; |
| 1926 | DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu); |
| 1927 | |
| 1928 | if (method_die) |
| 1929 | ResolveType (method_cu, method_die); |
| 1930 | else |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 1931 | { |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1932 | if (m_using_apple_tables) |
| 1933 | { |
| 1934 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n", |
| 1935 | die_offset, class_str.c_str()); |
| 1936 | } |
| 1937 | } |
| 1938 | } |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 1939 | } |
| 1940 | } |
| 1941 | } |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1942 | |
| 1943 | // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we |
| 1944 | // need to tell the clang type it is actually a class. |
| 1945 | if (class_language != eLanguageTypeObjC) |
| 1946 | { |
| 1947 | if (is_a_class && tag_decl_kind != clang::TTK_Class) |
| 1948 | ast.SetTagTypeKind (clang_type, clang::TTK_Class); |
| 1949 | } |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1950 | |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1951 | // Since DW_TAG_structure_type gets used for both classes |
| 1952 | // and structures, we may need to set any DW_TAG_member |
| 1953 | // fields to have a "private" access if none was specified. |
| 1954 | // When we parsed the child members we tracked that actual |
| 1955 | // accessibility value for each DW_TAG_member in the |
| 1956 | // "member_accessibilities" array. If the value for the |
| 1957 | // member is zero, then it was set to the "default_accessibility" |
| 1958 | // which for structs was "public". Below we correct this |
| 1959 | // by setting any fields to "private" that weren't correctly |
| 1960 | // set. |
| 1961 | if (is_a_class && !member_accessibilities.empty()) |
| 1962 | { |
| 1963 | // This is a class and all members that didn't have |
| 1964 | // their access specified are private. |
| 1965 | ast.SetDefaultAccessForRecordFields (clang_type, |
| 1966 | eAccessPrivate, |
| 1967 | &member_accessibilities.front(), |
| 1968 | member_accessibilities.size()); |
| 1969 | } |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1970 | |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1971 | if (!base_classes.empty()) |
| 1972 | { |
| 1973 | ast.SetBaseClassesForClassType (clang_type, |
| 1974 | &base_classes.front(), |
| 1975 | base_classes.size()); |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1976 | |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1977 | // Clang will copy each CXXBaseSpecifier in "base_classes" |
| 1978 | // so we have to free them all. |
| 1979 | ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(), |
| 1980 | base_classes.size()); |
| 1981 | } |
| 1982 | |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1983 | } |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1984 | |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1985 | if (!layout_info.field_offsets.empty()) |
| 1986 | { |
| 1987 | if (type) |
| 1988 | layout_info.bit_size = type->GetByteSize() * 8; |
| 1989 | if (layout_info.bit_size == 0) |
| 1990 | layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, curr_cu, DW_AT_byte_size, 0) * 8; |
| 1991 | clang::QualType qual_type(clang::QualType::getFromOpaquePtr(clang_type)); |
| 1992 | const clang::RecordType *record_type = clang::dyn_cast<clang::RecordType>(qual_type.getTypePtr()); |
| 1993 | if (record_type) |
| 1994 | { |
| 1995 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 1996 | |
| 1997 | if (log) |
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 1998 | { |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1999 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2000 | "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) caching layout info for record_decl = %p, bit_size = %llu, alignment = %llu, field_offsets[%u], base_offsets[0], vbase_offsets[0])", |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2001 | clang_type, |
| 2002 | record_decl, |
| 2003 | layout_info.bit_size, |
| 2004 | layout_info.alignment, |
| 2005 | (uint32_t)layout_info.field_offsets.size()); |
| 2006 | |
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2007 | llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end(); |
| 2008 | for (pos = layout_info.field_offsets.begin(); pos != end; ++pos) |
| 2009 | { |
| 2010 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 2011 | "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field = { bit_offset=%u, name='%s' }", |
| 2012 | clang_type, |
| 2013 | (uint32_t)pos->second, |
| 2014 | pos->first->getNameAsString().c_str()); |
| 2015 | } |
| 2016 | } |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2017 | m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info)); |
| 2018 | } |
| 2019 | } |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2020 | } |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 2021 | ast.CompleteTagDeclarationDefinition (clang_type); |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2022 | return clang_type; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2023 | |
| 2024 | case DW_TAG_enumeration_type: |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 2025 | ast.StartTagDeclarationDefinition (clang_type); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2026 | if (die->HasChildren()) |
| 2027 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2028 | SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu)); |
| 2029 | ParseChildEnumerators(sc, clang_type, type->GetByteSize(), curr_cu, die); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2030 | } |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 2031 | ast.CompleteTagDeclarationDefinition (clang_type); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2032 | return clang_type; |
| 2033 | |
| 2034 | default: |
| 2035 | assert(false && "not a forward clang type decl!"); |
| 2036 | break; |
| 2037 | } |
| 2038 | return NULL; |
| 2039 | } |
| 2040 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2041 | Type* |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2042 | SymbolFileDWARF::ResolveType (DWARFCompileUnit* curr_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed) |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2043 | { |
| 2044 | if (type_die != NULL) |
| 2045 | { |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 2046 | Type *type = m_die_to_type.lookup (type_die); |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2047 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2048 | if (type == NULL) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2049 | type = GetTypeForDIE (curr_cu, type_die).get(); |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2050 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2051 | if (assert_not_being_parsed) |
| Jim Ingham | c354928 | 2012-01-11 02:21:12 +0000 | [diff] [blame] | 2052 | { |
| 2053 | if (type != DIE_IS_BEING_PARSED) |
| 2054 | return type; |
| 2055 | |
| 2056 | GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s", |
| 2057 | type_die->GetOffset(), |
| 2058 | DW_TAG_value_to_name(type_die->Tag()), |
| 2059 | type_die->GetName(this, curr_cu)); |
| 2060 | |
| 2061 | } |
| 2062 | else |
| 2063 | return type; |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2064 | } |
| 2065 | return NULL; |
| 2066 | } |
| 2067 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2068 | CompileUnit* |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2069 | SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* curr_cu, uint32_t cu_idx) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2070 | { |
| 2071 | // Check if the symbol vendor already knows about this compile unit? |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2072 | if (curr_cu->GetUserData() == NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2073 | { |
| 2074 | // The symbol vendor doesn't know about this compile unit, we |
| 2075 | // need to parse and add it to the symbol vendor object. |
| 2076 | CompUnitSP dc_cu; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2077 | ParseCompileUnit(curr_cu, dc_cu); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2078 | if (dc_cu.get()) |
| 2079 | { |
| 2080 | // Figure out the compile unit index if we weren't given one |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 2081 | if (cu_idx == UINT32_MAX) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2082 | DebugInfo()->GetCompileUnit(curr_cu->GetOffset(), &cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2083 | |
| 2084 | m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(dc_cu, cu_idx); |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2085 | |
| 2086 | if (m_debug_map_symfile) |
| 2087 | m_debug_map_symfile->SetCompileUnit(this, dc_cu); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2088 | } |
| 2089 | } |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2090 | return (CompileUnit*)curr_cu->GetUserData(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2091 | } |
| 2092 | |
| 2093 | bool |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2094 | SymbolFileDWARF::GetFunction (DWARFCompileUnit* curr_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2095 | { |
| 2096 | sc.Clear(); |
| 2097 | // Check if the symbol vendor already knows about this compile unit? |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2098 | sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, UINT32_MAX); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2099 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2100 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2101 | if (sc.function == NULL) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2102 | sc.function = ParseCompileUnitFunction(sc, curr_cu, func_die); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2103 | |
| 2104 | if (sc.function) |
| 2105 | { |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 2106 | sc.module_sp = sc.function->CalculateSymbolContextModule()->shared_from_this(); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2107 | return true; |
| 2108 | } |
| 2109 | |
| 2110 | return false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2111 | } |
| 2112 | |
| 2113 | uint32_t |
| 2114 | SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) |
| 2115 | { |
| 2116 | Timer scoped_timer(__PRETTY_FUNCTION__, |
| 2117 | "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%llx }, resolve_scope = 0x%8.8x)", |
| 2118 | so_addr.GetSection(), |
| 2119 | so_addr.GetOffset(), |
| 2120 | resolve_scope); |
| 2121 | uint32_t resolved = 0; |
| 2122 | if (resolve_scope & ( eSymbolContextCompUnit | |
| 2123 | eSymbolContextFunction | |
| 2124 | eSymbolContextBlock | |
| 2125 | eSymbolContextLineEntry)) |
| 2126 | { |
| 2127 | lldb::addr_t file_vm_addr = so_addr.GetFileAddress(); |
| 2128 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2129 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2130 | if (debug_info) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2131 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2132 | dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2133 | if (cu_offset != DW_INVALID_OFFSET) |
| 2134 | { |
| 2135 | uint32_t cu_idx; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2136 | DWARFCompileUnit* curr_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get(); |
| 2137 | if (curr_cu) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2138 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2139 | sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2140 | assert(sc.comp_unit != NULL); |
| 2141 | resolved |= eSymbolContextCompUnit; |
| 2142 | |
| 2143 | if (resolve_scope & eSymbolContextLineEntry) |
| 2144 | { |
| 2145 | LineTable *line_table = sc.comp_unit->GetLineTable(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2146 | if (line_table != NULL) |
| 2147 | { |
| 2148 | if (so_addr.IsLinkedAddress()) |
| 2149 | { |
| 2150 | Address linked_addr (so_addr); |
| 2151 | linked_addr.ResolveLinkedAddress(); |
| 2152 | if (line_table->FindLineEntryByAddress (linked_addr, sc.line_entry)) |
| 2153 | { |
| 2154 | resolved |= eSymbolContextLineEntry; |
| 2155 | } |
| 2156 | } |
| 2157 | else if (line_table->FindLineEntryByAddress (so_addr, sc.line_entry)) |
| 2158 | { |
| 2159 | resolved |= eSymbolContextLineEntry; |
| 2160 | } |
| 2161 | } |
| 2162 | } |
| 2163 | |
| 2164 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) |
| 2165 | { |
| 2166 | DWARFDebugInfoEntry *function_die = NULL; |
| 2167 | DWARFDebugInfoEntry *block_die = NULL; |
| 2168 | if (resolve_scope & eSymbolContextBlock) |
| 2169 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2170 | curr_cu->LookupAddress(file_vm_addr, &function_die, &block_die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2171 | } |
| 2172 | else |
| 2173 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2174 | curr_cu->LookupAddress(file_vm_addr, &function_die, NULL); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2175 | } |
| 2176 | |
| 2177 | if (function_die != NULL) |
| 2178 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2179 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2180 | if (sc.function == NULL) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2181 | sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2182 | } |
| 2183 | |
| 2184 | if (sc.function != NULL) |
| 2185 | { |
| 2186 | resolved |= eSymbolContextFunction; |
| 2187 | |
| 2188 | if (resolve_scope & eSymbolContextBlock) |
| 2189 | { |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 2190 | Block& block = sc.function->GetBlock (true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2191 | |
| 2192 | if (block_die != NULL) |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2193 | sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2194 | else |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2195 | sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2196 | if (sc.block) |
| 2197 | resolved |= eSymbolContextBlock; |
| 2198 | } |
| 2199 | } |
| 2200 | } |
| 2201 | } |
| 2202 | } |
| 2203 | } |
| 2204 | } |
| 2205 | return resolved; |
| 2206 | } |
| 2207 | |
| 2208 | |
| 2209 | |
| 2210 | uint32_t |
| 2211 | SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) |
| 2212 | { |
| 2213 | const uint32_t prev_size = sc_list.GetSize(); |
| 2214 | if (resolve_scope & eSymbolContextCompUnit) |
| 2215 | { |
| 2216 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2217 | if (debug_info) |
| 2218 | { |
| 2219 | uint32_t cu_idx; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2220 | DWARFCompileUnit* curr_cu = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2221 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2222 | for (cu_idx = 0; (curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2223 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2224 | CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2225 | bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Compare(file_spec, *dc_cu, false) == 0; |
| 2226 | if (check_inlines || file_spec_matches_cu_file_spec) |
| 2227 | { |
| 2228 | SymbolContext sc (m_obj_file->GetModule()); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2229 | sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2230 | assert(sc.comp_unit != NULL); |
| 2231 | |
| 2232 | uint32_t file_idx = UINT32_MAX; |
| 2233 | |
| 2234 | // If we are looking for inline functions only and we don't |
| 2235 | // find it in the support files, we are done. |
| 2236 | if (check_inlines) |
| 2237 | { |
| Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 2238 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2239 | if (file_idx == UINT32_MAX) |
| 2240 | continue; |
| 2241 | } |
| 2242 | |
| 2243 | if (line != 0) |
| 2244 | { |
| 2245 | LineTable *line_table = sc.comp_unit->GetLineTable(); |
| 2246 | |
| 2247 | if (line_table != NULL && line != 0) |
| 2248 | { |
| 2249 | // We will have already looked up the file index if |
| 2250 | // we are searching for inline entries. |
| 2251 | if (!check_inlines) |
| Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 2252 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2253 | |
| 2254 | if (file_idx != UINT32_MAX) |
| 2255 | { |
| 2256 | uint32_t found_line; |
| 2257 | uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry); |
| 2258 | found_line = sc.line_entry.line; |
| 2259 | |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 2260 | while (line_idx != UINT32_MAX) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2261 | { |
| 2262 | sc.function = NULL; |
| 2263 | sc.block = NULL; |
| 2264 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) |
| 2265 | { |
| 2266 | const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress(); |
| 2267 | if (file_vm_addr != LLDB_INVALID_ADDRESS) |
| 2268 | { |
| 2269 | DWARFDebugInfoEntry *function_die = NULL; |
| 2270 | DWARFDebugInfoEntry *block_die = NULL; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2271 | curr_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2272 | |
| 2273 | if (function_die != NULL) |
| 2274 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2275 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2276 | if (sc.function == NULL) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2277 | sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2278 | } |
| 2279 | |
| 2280 | if (sc.function != NULL) |
| 2281 | { |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 2282 | Block& block = sc.function->GetBlock (true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2283 | |
| 2284 | if (block_die != NULL) |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2285 | sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2286 | else |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2287 | sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2288 | } |
| 2289 | } |
| 2290 | } |
| 2291 | |
| 2292 | sc_list.Append(sc); |
| 2293 | line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry); |
| 2294 | } |
| 2295 | } |
| 2296 | } |
| 2297 | else if (file_spec_matches_cu_file_spec && !check_inlines) |
| 2298 | { |
| 2299 | // only append the context if we aren't looking for inline call sites |
| 2300 | // by file and line and if the file spec matches that of the compile unit |
| 2301 | sc_list.Append(sc); |
| 2302 | } |
| 2303 | } |
| 2304 | else if (file_spec_matches_cu_file_spec && !check_inlines) |
| 2305 | { |
| 2306 | // only append the context if we aren't looking for inline call sites |
| 2307 | // by file and line and if the file spec matches that of the compile unit |
| 2308 | sc_list.Append(sc); |
| 2309 | } |
| 2310 | |
| 2311 | if (!check_inlines) |
| 2312 | break; |
| 2313 | } |
| 2314 | } |
| 2315 | } |
| 2316 | } |
| 2317 | return sc_list.GetSize() - prev_size; |
| 2318 | } |
| 2319 | |
| 2320 | void |
| 2321 | SymbolFileDWARF::Index () |
| 2322 | { |
| 2323 | if (m_indexed) |
| 2324 | return; |
| 2325 | m_indexed = true; |
| 2326 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 2327 | "SymbolFileDWARF::Index (%s)", |
| 2328 | GetObjectFile()->GetFileSpec().GetFilename().AsCString()); |
| 2329 | |
| 2330 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2331 | if (debug_info) |
| 2332 | { |
| 2333 | uint32_t cu_idx = 0; |
| 2334 | const uint32_t num_compile_units = GetNumCompileUnits(); |
| 2335 | for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) |
| 2336 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2337 | DWARFCompileUnit* curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2338 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2339 | bool clear_dies = curr_cu->ExtractDIEsIfNeeded (false) > 1; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2340 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2341 | curr_cu->Index (cu_idx, |
| Greg Clayton | 83c5cd9 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 2342 | m_function_basename_index, |
| 2343 | m_function_fullname_index, |
| 2344 | m_function_method_index, |
| 2345 | m_function_selector_index, |
| 2346 | m_objc_class_selectors_index, |
| 2347 | m_global_index, |
| 2348 | m_type_index, |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2349 | m_namespace_index); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2350 | |
| 2351 | // Keep memory down by clearing DIEs if this generate function |
| 2352 | // caused them to be parsed |
| 2353 | if (clear_dies) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2354 | curr_cu->ClearDIEs (true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2355 | } |
| 2356 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2357 | m_function_basename_index.Finalize(); |
| 2358 | m_function_fullname_index.Finalize(); |
| 2359 | m_function_method_index.Finalize(); |
| 2360 | m_function_selector_index.Finalize(); |
| 2361 | m_objc_class_selectors_index.Finalize(); |
| 2362 | m_global_index.Finalize(); |
| 2363 | m_type_index.Finalize(); |
| 2364 | m_namespace_index.Finalize(); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2365 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2366 | #if defined (ENABLE_DEBUG_PRINTF) |
| Greg Clayton | 7bd65b9 | 2011-02-09 23:39:34 +0000 | [diff] [blame] | 2367 | StreamFile s(stdout, false); |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 2368 | s.Printf ("DWARF index for '%s/%s':", |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2369 | GetObjectFile()->GetFileSpec().GetDirectory().AsCString(), |
| 2370 | GetObjectFile()->GetFileSpec().GetFilename().AsCString()); |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 2371 | s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s); |
| 2372 | s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s); |
| 2373 | s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s); |
| 2374 | s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s); |
| 2375 | s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s); |
| 2376 | s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s); |
| Greg Clayton | 69b0488 | 2010-10-15 02:03:22 +0000 | [diff] [blame] | 2377 | s.Printf("\nTypes:\n"); m_type_index.Dump (&s); |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 2378 | s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2379 | #endif |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2380 | } |
| 2381 | } |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2382 | |
| 2383 | bool |
| 2384 | SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl) |
| 2385 | { |
| 2386 | if (namespace_decl == NULL) |
| 2387 | { |
| 2388 | // Invalid namespace decl which means we aren't matching only things |
| 2389 | // in this symbol file, so return true to indicate it matches this |
| 2390 | // symbol file. |
| 2391 | return true; |
| 2392 | } |
| 2393 | |
| 2394 | clang::ASTContext *namespace_ast = namespace_decl->GetASTContext(); |
| 2395 | |
| 2396 | if (namespace_ast == NULL) |
| 2397 | return true; // No AST in the "namespace_decl", return true since it |
| 2398 | // could then match any symbol file, including this one |
| 2399 | |
| 2400 | if (namespace_ast == GetClangASTContext().getASTContext()) |
| 2401 | return true; // The ASTs match, return true |
| 2402 | |
| 2403 | // The namespace AST was valid, and it does not match... |
| Sean Callanan | c41e68b | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 2404 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 2405 | |
| 2406 | if (log) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2407 | GetObjectFile()->GetModule()->LogMessage(log.get(), "Valid namespace does not match symbol file"); |
| Sean Callanan | c41e68b | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 2408 | |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2409 | return false; |
| 2410 | } |
| 2411 | |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2412 | bool |
| 2413 | SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl, |
| 2414 | DWARFCompileUnit* cu, |
| 2415 | const DWARFDebugInfoEntry* die) |
| 2416 | { |
| 2417 | // No namespace specified, so the answesr i |
| 2418 | if (namespace_decl == NULL) |
| 2419 | return true; |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2420 | |
| 2421 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2422 | |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2423 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); |
| 2424 | if (decl_ctx_die) |
| 2425 | { |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2426 | |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2427 | clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl(); |
| 2428 | if (clang_namespace_decl) |
| 2429 | { |
| 2430 | if (decl_ctx_die->Tag() != DW_TAG_namespace) |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2431 | { |
| 2432 | if (log) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2433 | GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent is not a namespace"); |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2434 | return false; |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2435 | } |
| 2436 | |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2437 | DeclContextToDIEMap::iterator pos = m_decl_ctx_to_die.find(clang_namespace_decl); |
| 2438 | |
| 2439 | if (pos == m_decl_ctx_to_die.end()) |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2440 | { |
| 2441 | if (log) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2442 | GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match in a namespace, but its parent is not the requested namespace"); |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2443 | |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2444 | return false; |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2445 | } |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2446 | |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 2447 | return pos->second.count (decl_ctx_die); |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2448 | } |
| 2449 | else |
| 2450 | { |
| 2451 | // We have a namespace_decl that was not NULL but it contained |
| 2452 | // a NULL "clang::NamespaceDecl", so this means the global namespace |
| 2453 | // So as long the the contained decl context DIE isn't a namespace |
| 2454 | // we should be ok. |
| 2455 | if (decl_ctx_die->Tag() != DW_TAG_namespace) |
| 2456 | return true; |
| 2457 | } |
| 2458 | } |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2459 | |
| 2460 | if (log) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2461 | GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent doesn't exist"); |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2462 | |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2463 | return false; |
| 2464 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2465 | uint32_t |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2466 | SymbolFileDWARF::FindGlobalVariables (const ConstString &name, const lldb_private::ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, VariableList& variables) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2467 | { |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2468 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 2469 | |
| 2470 | if (log) |
| 2471 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2472 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 2473 | "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)", |
| 2474 | name.GetCString(), |
| 2475 | namespace_decl, |
| 2476 | append, |
| 2477 | max_matches); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2478 | } |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2479 | |
| 2480 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) |
| 2481 | return 0; |
| 2482 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2483 | DWARFDebugInfo* info = DebugInfo(); |
| 2484 | if (info == NULL) |
| 2485 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2486 | |
| 2487 | // If we aren't appending the results to this list, then clear the list |
| 2488 | if (!append) |
| 2489 | variables.Clear(); |
| 2490 | |
| 2491 | // Remember how many variables are in the list before we search in case |
| 2492 | // we are appending the results to a variable list. |
| 2493 | const uint32_t original_size = variables.GetSize(); |
| 2494 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2495 | DIEArray die_offsets; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2496 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2497 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2498 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2499 | if (m_apple_names_ap.get()) |
| 2500 | { |
| 2501 | const char *name_cstr = name.GetCString(); |
| 2502 | const char *base_name_start; |
| 2503 | const char *base_name_end = NULL; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2504 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2505 | if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end)) |
| 2506 | base_name_start = name_cstr; |
| 2507 | |
| 2508 | m_apple_names_ap->FindByName (base_name_start, die_offsets); |
| 2509 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2510 | } |
| 2511 | else |
| 2512 | { |
| 2513 | // Index the DWARF if we haven't already |
| 2514 | if (!m_indexed) |
| 2515 | Index (); |
| 2516 | |
| 2517 | m_global_index.Find (name, die_offsets); |
| 2518 | } |
| 2519 | |
| 2520 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2521 | if (num_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2522 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2523 | SymbolContext sc; |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 2524 | sc.module_sp = m_obj_file->GetModule()->shared_from_this(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2525 | assert (sc.module_sp); |
| 2526 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2527 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2528 | DWARFCompileUnit* dwarf_cu = NULL; |
| 2529 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2530 | for (size_t i=0; i<num_matches; ++i) |
| 2531 | { |
| 2532 | const dw_offset_t die_offset = die_offsets[i]; |
| 2533 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2534 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2535 | if (die) |
| 2536 | { |
| 2537 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| 2538 | assert(sc.comp_unit != NULL); |
| 2539 | |
| 2540 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 2541 | continue; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2542 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2543 | ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2544 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2545 | if (variables.GetSize() - original_size >= max_matches) |
| 2546 | break; |
| 2547 | } |
| 2548 | else |
| 2549 | { |
| 2550 | if (m_using_apple_tables) |
| 2551 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2552 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n", |
| 2553 | die_offset, name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2554 | } |
| 2555 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2556 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2557 | } |
| 2558 | |
| 2559 | // Return the number of variable that were appended to the list |
| 2560 | return variables.GetSize() - original_size; |
| 2561 | } |
| 2562 | |
| 2563 | uint32_t |
| 2564 | SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables) |
| 2565 | { |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2566 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 2567 | |
| 2568 | if (log) |
| 2569 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2570 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 2571 | "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)", |
| 2572 | regex.GetText(), |
| 2573 | append, |
| 2574 | max_matches); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2575 | } |
| 2576 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2577 | DWARFDebugInfo* info = DebugInfo(); |
| 2578 | if (info == NULL) |
| 2579 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2580 | |
| 2581 | // If we aren't appending the results to this list, then clear the list |
| 2582 | if (!append) |
| 2583 | variables.Clear(); |
| 2584 | |
| 2585 | // Remember how many variables are in the list before we search in case |
| 2586 | // we are appending the results to a variable list. |
| 2587 | const uint32_t original_size = variables.GetSize(); |
| 2588 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2589 | DIEArray die_offsets; |
| 2590 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2591 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2592 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2593 | if (m_apple_names_ap.get()) |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 2594 | { |
| 2595 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 2596 | if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) |
| 2597 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| 2598 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2599 | } |
| 2600 | else |
| 2601 | { |
| 2602 | // Index the DWARF if we haven't already |
| 2603 | if (!m_indexed) |
| 2604 | Index (); |
| 2605 | |
| 2606 | m_global_index.Find (regex, die_offsets); |
| 2607 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2608 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2609 | SymbolContext sc; |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 2610 | sc.module_sp = m_obj_file->GetModule()->shared_from_this(); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2611 | assert (sc.module_sp); |
| 2612 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2613 | DWARFCompileUnit* dwarf_cu = NULL; |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2614 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2615 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2616 | if (num_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2617 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2618 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2619 | for (size_t i=0; i<num_matches; ++i) |
| 2620 | { |
| 2621 | const dw_offset_t die_offset = die_offsets[i]; |
| 2622 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2623 | |
| 2624 | if (die) |
| 2625 | { |
| 2626 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2627 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2628 | ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2629 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2630 | if (variables.GetSize() - original_size >= max_matches) |
| 2631 | break; |
| 2632 | } |
| 2633 | else |
| 2634 | { |
| 2635 | if (m_using_apple_tables) |
| 2636 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2637 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n", |
| 2638 | die_offset, regex.GetText()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2639 | } |
| 2640 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2641 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2642 | } |
| 2643 | |
| 2644 | // Return the number of variable that were appended to the list |
| 2645 | return variables.GetSize() - original_size; |
| 2646 | } |
| 2647 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2648 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2649 | bool |
| 2650 | SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset, |
| 2651 | DWARFCompileUnit *&dwarf_cu, |
| 2652 | SymbolContextList& sc_list) |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2653 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2654 | const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| 2655 | return ResolveFunction (dwarf_cu, die, sc_list); |
| 2656 | } |
| 2657 | |
| 2658 | |
| 2659 | bool |
| 2660 | SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu, |
| 2661 | const DWARFDebugInfoEntry *die, |
| 2662 | SymbolContextList& sc_list) |
| 2663 | { |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2664 | SymbolContext sc; |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2665 | |
| 2666 | if (die == NULL) |
| 2667 | return false; |
| 2668 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2669 | // If we were passed a die that is not a function, just return false... |
| 2670 | if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine) |
| 2671 | return false; |
| 2672 | |
| 2673 | const DWARFDebugInfoEntry* inlined_die = NULL; |
| 2674 | if (die->Tag() == DW_TAG_inlined_subroutine) |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2675 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2676 | inlined_die = die; |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2677 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2678 | while ((die = die->GetParent()) != NULL) |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 2679 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2680 | if (die->Tag() == DW_TAG_subprogram) |
| 2681 | break; |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2682 | } |
| 2683 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2684 | assert (die->Tag() == DW_TAG_subprogram); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2685 | if (GetFunction (cu, die, sc)) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2686 | { |
| 2687 | Address addr; |
| 2688 | // Parse all blocks if needed |
| 2689 | if (inlined_die) |
| 2690 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2691 | sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset())); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2692 | assert (sc.block != NULL); |
| 2693 | if (sc.block->GetStartAddress (addr) == false) |
| 2694 | addr.Clear(); |
| 2695 | } |
| 2696 | else |
| 2697 | { |
| 2698 | sc.block = NULL; |
| 2699 | addr = sc.function->GetAddressRange().GetBaseAddress(); |
| 2700 | } |
| 2701 | |
| 2702 | if (addr.IsValid()) |
| 2703 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2704 | sc_list.Append(sc); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2705 | return true; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2706 | } |
| 2707 | } |
| 2708 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2709 | return false; |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2710 | } |
| 2711 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2712 | void |
| 2713 | SymbolFileDWARF::FindFunctions (const ConstString &name, |
| 2714 | const NameToDIE &name_to_die, |
| 2715 | SymbolContextList& sc_list) |
| 2716 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2717 | DIEArray die_offsets; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2718 | if (name_to_die.Find (name, die_offsets)) |
| 2719 | { |
| 2720 | ParseFunctions (die_offsets, sc_list); |
| 2721 | } |
| 2722 | } |
| 2723 | |
| 2724 | |
| 2725 | void |
| 2726 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, |
| 2727 | const NameToDIE &name_to_die, |
| 2728 | SymbolContextList& sc_list) |
| 2729 | { |
| 2730 | DIEArray die_offsets; |
| 2731 | if (name_to_die.Find (regex, die_offsets)) |
| 2732 | { |
| 2733 | ParseFunctions (die_offsets, sc_list); |
| 2734 | } |
| 2735 | } |
| 2736 | |
| 2737 | |
| 2738 | void |
| 2739 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, |
| 2740 | const DWARFMappedHash::MemoryTable &memory_table, |
| 2741 | SymbolContextList& sc_list) |
| 2742 | { |
| 2743 | DIEArray die_offsets; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 2744 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 2745 | if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2746 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 2747 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2748 | ParseFunctions (die_offsets, sc_list); |
| 2749 | } |
| 2750 | } |
| 2751 | |
| 2752 | void |
| 2753 | SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets, |
| 2754 | SymbolContextList& sc_list) |
| 2755 | { |
| 2756 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2757 | if (num_matches) |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2758 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2759 | SymbolContext sc; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2760 | |
| 2761 | DWARFCompileUnit* dwarf_cu = NULL; |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2762 | for (size_t i=0; i<num_matches; ++i) |
| Greg Clayton | d7e0546 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 2763 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2764 | const dw_offset_t die_offset = die_offsets[i]; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2765 | ResolveFunction (die_offset, dwarf_cu, sc_list); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2766 | } |
| 2767 | } |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2768 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2769 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2770 | bool |
| 2771 | SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die, |
| 2772 | const DWARFCompileUnit *dwarf_cu, |
| 2773 | uint32_t name_type_mask, |
| 2774 | const char *partial_name, |
| 2775 | const char *base_name_start, |
| 2776 | const char *base_name_end) |
| 2777 | { |
| 2778 | // If we are looking only for methods, throw away all the ones that aren't in C++ classes: |
| 2779 | if (name_type_mask == eFunctionNameTypeMethod |
| 2780 | || name_type_mask == eFunctionNameTypeBase) |
| 2781 | { |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 2782 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset()); |
| 2783 | if (!containing_decl_ctx) |
| 2784 | return false; |
| 2785 | |
| 2786 | bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()); |
| 2787 | |
| 2788 | if (!is_cxx_method && name_type_mask == eFunctionNameTypeMethod) |
| 2789 | return false; |
| 2790 | if (is_cxx_method && name_type_mask == eFunctionNameTypeBase) |
| 2791 | return false; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2792 | } |
| 2793 | |
| 2794 | // Now we need to check whether the name we got back for this type matches the extra specifications |
| 2795 | // that were in the name we're looking up: |
| 2796 | if (base_name_start != partial_name || *base_name_end != '\0') |
| 2797 | { |
| 2798 | // First see if the stuff to the left matches the full name. To do that let's see if |
| 2799 | // we can pull out the mips linkage name attribute: |
| 2800 | |
| 2801 | Mangled best_name; |
| 2802 | |
| 2803 | DWARFDebugInfoEntry::Attributes attributes; |
| 2804 | die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| 2805 | uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name); |
| 2806 | if (idx != UINT32_MAX) |
| 2807 | { |
| 2808 | DWARFFormValue form_value; |
| 2809 | if (attributes.ExtractFormValueAtIndex(this, idx, form_value)) |
| 2810 | { |
| 2811 | const char *name = form_value.AsCString(&get_debug_str_data()); |
| 2812 | best_name.SetValue (name, true); |
| 2813 | } |
| 2814 | } |
| 2815 | if (best_name) |
| 2816 | { |
| 2817 | const char *demangled = best_name.GetDemangledName().GetCString(); |
| 2818 | if (demangled) |
| 2819 | { |
| 2820 | std::string name_no_parens(partial_name, base_name_end - partial_name); |
| 2821 | if (strstr (demangled, name_no_parens.c_str()) == NULL) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2822 | return false; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2823 | } |
| 2824 | } |
| 2825 | } |
| 2826 | |
| 2827 | return true; |
| 2828 | } |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2829 | |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2830 | uint32_t |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 2831 | SymbolFileDWARF::FindFunctions (const ConstString &name, |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2832 | const lldb_private::ClangNamespaceDecl *namespace_decl, |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 2833 | uint32_t name_type_mask, |
| 2834 | bool append, |
| 2835 | SymbolContextList& sc_list) |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2836 | { |
| 2837 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 2838 | "SymbolFileDWARF::FindFunctions (name = '%s')", |
| 2839 | name.AsCString()); |
| 2840 | |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2841 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 2842 | |
| 2843 | if (log) |
| 2844 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2845 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 2846 | "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)", |
| 2847 | name.GetCString(), |
| 2848 | name_type_mask, |
| 2849 | append); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2850 | } |
| 2851 | |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2852 | // If we aren't appending the results to this list, then clear the list |
| 2853 | if (!append) |
| 2854 | sc_list.Clear(); |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2855 | |
| 2856 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) |
| 2857 | return 0; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2858 | |
| 2859 | // If name is empty then we won't find anything. |
| 2860 | if (name.IsEmpty()) |
| 2861 | return 0; |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2862 | |
| 2863 | // Remember how many sc_list are in the list before we search in case |
| 2864 | // we are appending the results to a variable list. |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2865 | |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2866 | const uint32_t original_size = sc_list.GetSize(); |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2867 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2868 | const char *name_cstr = name.GetCString(); |
| 2869 | uint32_t effective_name_type_mask = eFunctionNameTypeNone; |
| 2870 | const char *base_name_start = name_cstr; |
| 2871 | const char *base_name_end = name_cstr + strlen(name_cstr); |
| 2872 | |
| 2873 | if (name_type_mask & eFunctionNameTypeAuto) |
| 2874 | { |
| 2875 | if (CPPLanguageRuntime::IsCPPMangledName (name_cstr)) |
| 2876 | effective_name_type_mask = eFunctionNameTypeFull; |
| 2877 | else if (ObjCLanguageRuntime::IsPossibleObjCMethodName (name_cstr)) |
| 2878 | effective_name_type_mask = eFunctionNameTypeFull; |
| 2879 | else |
| 2880 | { |
| 2881 | if (ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr)) |
| 2882 | effective_name_type_mask |= eFunctionNameTypeSelector; |
| 2883 | |
| 2884 | if (CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end)) |
| 2885 | effective_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase); |
| 2886 | } |
| 2887 | } |
| 2888 | else |
| 2889 | { |
| 2890 | effective_name_type_mask = name_type_mask; |
| 2891 | if (effective_name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase) |
| 2892 | { |
| 2893 | // If they've asked for a CPP method or function name and it can't be that, we don't |
| 2894 | // even need to search for CPP methods or names. |
| 2895 | if (!CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end)) |
| 2896 | { |
| 2897 | effective_name_type_mask &= ~(eFunctionNameTypeMethod | eFunctionNameTypeBase); |
| 2898 | if (effective_name_type_mask == eFunctionNameTypeNone) |
| 2899 | return 0; |
| 2900 | } |
| 2901 | } |
| 2902 | |
| 2903 | if (effective_name_type_mask & eFunctionNameTypeSelector) |
| 2904 | { |
| 2905 | if (!ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr)) |
| 2906 | { |
| 2907 | effective_name_type_mask &= ~(eFunctionNameTypeSelector); |
| 2908 | if (effective_name_type_mask == eFunctionNameTypeNone) |
| 2909 | return 0; |
| 2910 | } |
| 2911 | } |
| 2912 | } |
| 2913 | |
| 2914 | DWARFDebugInfo* info = DebugInfo(); |
| 2915 | if (info == NULL) |
| 2916 | return 0; |
| 2917 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2918 | DWARFCompileUnit *dwarf_cu = NULL; |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2919 | if (m_using_apple_tables) |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 2920 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2921 | if (m_apple_names_ap.get()) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2922 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2923 | |
| 2924 | DIEArray die_offsets; |
| 2925 | |
| 2926 | uint32_t num_matches = 0; |
| 2927 | |
| 2928 | if (effective_name_type_mask & eFunctionNameTypeFull) |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2929 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2930 | // If they asked for the full name, match what they typed. At some point we may |
| 2931 | // want to canonicalize this (strip double spaces, etc. For now, we just add all the |
| 2932 | // dies that we find by exact match. |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2933 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2934 | for (uint32_t i = 0; i < num_matches; i++) |
| 2935 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2936 | const dw_offset_t die_offset = die_offsets[i]; |
| 2937 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2938 | if (die) |
| 2939 | { |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2940 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 2941 | continue; |
| 2942 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2943 | ResolveFunction (dwarf_cu, die, sc_list); |
| 2944 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2945 | else |
| 2946 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2947 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 2948 | die_offset, name_cstr); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2949 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2950 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2951 | } |
| 2952 | else |
| 2953 | { |
| 2954 | if (effective_name_type_mask & eFunctionNameTypeSelector) |
| 2955 | { |
| 2956 | if (namespace_decl && *namespace_decl) |
| 2957 | return 0; // no selectors in namespaces |
| 2958 | |
| 2959 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); |
| 2960 | // Now make sure these are actually ObjC methods. In this case we can simply look up the name, |
| 2961 | // and if it is an ObjC method name, we're good. |
| 2962 | |
| 2963 | for (uint32_t i = 0; i < num_matches; i++) |
| 2964 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2965 | const dw_offset_t die_offset = die_offsets[i]; |
| 2966 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2967 | if (die) |
| 2968 | { |
| 2969 | const char *die_name = die->GetName(this, dwarf_cu); |
| 2970 | if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name)) |
| 2971 | ResolveFunction (dwarf_cu, die, sc_list); |
| 2972 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2973 | else |
| 2974 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2975 | GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 2976 | die_offset, name_cstr); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2977 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2978 | } |
| 2979 | die_offsets.clear(); |
| 2980 | } |
| 2981 | |
| 2982 | if (effective_name_type_mask & eFunctionNameTypeMethod |
| 2983 | || effective_name_type_mask & eFunctionNameTypeBase) |
| 2984 | { |
| 2985 | if ((effective_name_type_mask & eFunctionNameTypeMethod) && |
| 2986 | (namespace_decl && *namespace_decl)) |
| 2987 | return 0; // no methods in namespaces |
| 2988 | |
| 2989 | // The apple_names table stores just the "base name" of C++ methods in the table. So we have to |
| 2990 | // extract the base name, look that up, and if there is any other information in the name we were |
| 2991 | // passed in we have to post-filter based on that. |
| 2992 | |
| 2993 | // FIXME: Arrange the logic above so that we don't calculate the base name twice: |
| 2994 | std::string base_name(base_name_start, base_name_end - base_name_start); |
| 2995 | num_matches = m_apple_names_ap->FindByName (base_name.c_str(), die_offsets); |
| 2996 | |
| 2997 | for (uint32_t i = 0; i < num_matches; i++) |
| 2998 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2999 | const dw_offset_t die_offset = die_offsets[i]; |
| 3000 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3001 | if (die) |
| 3002 | { |
| 3003 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3004 | continue; |
| 3005 | |
| 3006 | if (!FunctionDieMatchesPartialName(die, |
| 3007 | dwarf_cu, |
| 3008 | effective_name_type_mask, |
| 3009 | name_cstr, |
| 3010 | base_name_start, |
| 3011 | base_name_end)) |
| 3012 | continue; |
| 3013 | |
| 3014 | // If we get to here, the die is good, and we should add it: |
| 3015 | ResolveFunction (dwarf_cu, die, sc_list); |
| 3016 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3017 | else |
| 3018 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3019 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 3020 | die_offset, name_cstr); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3021 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3022 | } |
| 3023 | die_offsets.clear(); |
| 3024 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3025 | } |
| 3026 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3027 | } |
| 3028 | else |
| 3029 | { |
| 3030 | |
| 3031 | // Index the DWARF if we haven't already |
| 3032 | if (!m_indexed) |
| 3033 | Index (); |
| 3034 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3035 | if (name_type_mask & eFunctionNameTypeFull) |
| 3036 | FindFunctions (name, m_function_fullname_index, sc_list); |
| 3037 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3038 | std::string base_name(base_name_start, base_name_end - base_name_start); |
| 3039 | ConstString base_name_const(base_name.c_str()); |
| 3040 | DIEArray die_offsets; |
| 3041 | DWARFCompileUnit *dwarf_cu = NULL; |
| 3042 | |
| 3043 | if (effective_name_type_mask & eFunctionNameTypeBase) |
| 3044 | { |
| 3045 | uint32_t num_base = m_function_basename_index.Find(base_name_const, die_offsets); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3046 | for (uint32_t i = 0; i < num_base; i++) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3047 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3048 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); |
| 3049 | if (die) |
| 3050 | { |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3051 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3052 | continue; |
| 3053 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3054 | if (!FunctionDieMatchesPartialName(die, |
| 3055 | dwarf_cu, |
| 3056 | effective_name_type_mask, |
| 3057 | name_cstr, |
| 3058 | base_name_start, |
| 3059 | base_name_end)) |
| 3060 | continue; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3061 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3062 | // If we get to here, the die is good, and we should add it: |
| 3063 | ResolveFunction (dwarf_cu, die, sc_list); |
| 3064 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3065 | } |
| 3066 | die_offsets.clear(); |
| 3067 | } |
| 3068 | |
| Jim Ingham | ea8005a | 2011-10-11 01:18:11 +0000 | [diff] [blame] | 3069 | if (effective_name_type_mask & eFunctionNameTypeMethod) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3070 | { |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3071 | if (namespace_decl && *namespace_decl) |
| 3072 | return 0; // no methods in namespaces |
| 3073 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3074 | uint32_t num_base = m_function_method_index.Find(base_name_const, die_offsets); |
| 3075 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3076 | for (uint32_t i = 0; i < num_base; i++) |
| 3077 | { |
| 3078 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); |
| 3079 | if (die) |
| 3080 | { |
| 3081 | if (!FunctionDieMatchesPartialName(die, |
| 3082 | dwarf_cu, |
| 3083 | effective_name_type_mask, |
| 3084 | name_cstr, |
| 3085 | base_name_start, |
| 3086 | base_name_end)) |
| 3087 | continue; |
| 3088 | |
| 3089 | // If we get to here, the die is good, and we should add it: |
| 3090 | ResolveFunction (dwarf_cu, die, sc_list); |
| 3091 | } |
| 3092 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3093 | } |
| 3094 | die_offsets.clear(); |
| 3095 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3096 | |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3097 | if ((effective_name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl)) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3098 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3099 | FindFunctions (name, m_function_selector_index, sc_list); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3100 | } |
| 3101 | |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 3102 | } |
| 3103 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3104 | // Return the number of variable that were appended to the list |
| 3105 | return sc_list.GetSize() - original_size; |
| 3106 | } |
| 3107 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3108 | uint32_t |
| 3109 | SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool append, SymbolContextList& sc_list) |
| 3110 | { |
| 3111 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 3112 | "SymbolFileDWARF::FindFunctions (regex = '%s')", |
| 3113 | regex.GetText()); |
| 3114 | |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3115 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 3116 | |
| 3117 | if (log) |
| 3118 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3119 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3120 | "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)", |
| 3121 | regex.GetText(), |
| 3122 | append); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3123 | } |
| 3124 | |
| 3125 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3126 | // If we aren't appending the results to this list, then clear the list |
| 3127 | if (!append) |
| 3128 | sc_list.Clear(); |
| 3129 | |
| 3130 | // Remember how many sc_list are in the list before we search in case |
| 3131 | // we are appending the results to a variable list. |
| 3132 | uint32_t original_size = sc_list.GetSize(); |
| 3133 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3134 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3135 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3136 | if (m_apple_names_ap.get()) |
| 3137 | FindFunctions (regex, *m_apple_names_ap, sc_list); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3138 | } |
| 3139 | else |
| 3140 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3141 | // Index the DWARF if we haven't already |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3142 | if (!m_indexed) |
| 3143 | Index (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3144 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3145 | FindFunctions (regex, m_function_basename_index, sc_list); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3146 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3147 | FindFunctions (regex, m_function_fullname_index, sc_list); |
| 3148 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3149 | |
| 3150 | // Return the number of variable that were appended to the list |
| 3151 | return sc_list.GetSize() - original_size; |
| 3152 | } |
| Jim Ingham | 318c9f2 | 2011-08-26 19:44:13 +0000 | [diff] [blame] | 3153 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3154 | uint32_t |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3155 | SymbolFileDWARF::FindTypes (const SymbolContext& sc, |
| 3156 | const ConstString &name, |
| 3157 | const lldb_private::ClangNamespaceDecl *namespace_decl, |
| 3158 | bool append, |
| 3159 | uint32_t max_matches, |
| 3160 | TypeList& types) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3161 | { |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3162 | DWARFDebugInfo* info = DebugInfo(); |
| 3163 | if (info == NULL) |
| 3164 | return 0; |
| 3165 | |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3166 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 3167 | |
| 3168 | if (log) |
| 3169 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3170 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3171 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", append=%u, max_matches=%u, type_list)", |
| 3172 | name.GetCString(), |
| 3173 | append, |
| 3174 | max_matches); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3175 | } |
| 3176 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3177 | // If we aren't appending the results to this list, then clear the list |
| 3178 | if (!append) |
| 3179 | types.Clear(); |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3180 | |
| 3181 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) |
| 3182 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3183 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3184 | DIEArray die_offsets; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3185 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3186 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3187 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3188 | if (m_apple_types_ap.get()) |
| 3189 | { |
| 3190 | const char *name_cstr = name.GetCString(); |
| 3191 | m_apple_types_ap->FindByName (name_cstr, die_offsets); |
| 3192 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3193 | } |
| 3194 | else |
| 3195 | { |
| 3196 | if (!m_indexed) |
| 3197 | Index (); |
| 3198 | |
| 3199 | m_type_index.Find (name, die_offsets); |
| 3200 | } |
| 3201 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3202 | const size_t num_matches = die_offsets.size(); |
| 3203 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3204 | if (num_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3205 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3206 | const uint32_t initial_types_size = types.GetSize(); |
| 3207 | DWARFCompileUnit* dwarf_cu = NULL; |
| 3208 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3209 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3210 | for (size_t i=0; i<num_matches; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3211 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3212 | const dw_offset_t die_offset = die_offsets[i]; |
| 3213 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| 3214 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3215 | if (die) |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 3216 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3217 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3218 | continue; |
| 3219 | |
| 3220 | Type *matching_type = ResolveType (dwarf_cu, die); |
| 3221 | if (matching_type) |
| 3222 | { |
| 3223 | // We found a type pointer, now find the shared pointer form our type list |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 3224 | types.InsertUnique (matching_type->shared_from_this()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3225 | if (types.GetSize() >= max_matches) |
| 3226 | break; |
| 3227 | } |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 3228 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3229 | else |
| 3230 | { |
| 3231 | if (m_using_apple_tables) |
| 3232 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3233 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 3234 | die_offset, name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3235 | } |
| 3236 | } |
| 3237 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3238 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3239 | return types.GetSize() - initial_types_size; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3240 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3241 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3242 | } |
| 3243 | |
| 3244 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3245 | ClangNamespaceDecl |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3246 | SymbolFileDWARF::FindNamespace (const SymbolContext& sc, |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3247 | const ConstString &name, |
| 3248 | const lldb_private::ClangNamespaceDecl *parent_namespace_decl) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3249 | { |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3250 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 3251 | |
| 3252 | if (log) |
| 3253 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3254 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3255 | "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")", |
| 3256 | name.GetCString()); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3257 | } |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3258 | |
| 3259 | if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl)) |
| 3260 | return ClangNamespaceDecl(); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3261 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3262 | ClangNamespaceDecl namespace_decl; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3263 | DWARFDebugInfo* info = DebugInfo(); |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3264 | if (info) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3265 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3266 | DIEArray die_offsets; |
| 3267 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3268 | // Index if we already haven't to make sure the compile units |
| 3269 | // get indexed and make their global DIE index list |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3270 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3271 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3272 | if (m_apple_namespaces_ap.get()) |
| 3273 | { |
| 3274 | const char *name_cstr = name.GetCString(); |
| 3275 | m_apple_namespaces_ap->FindByName (name_cstr, die_offsets); |
| 3276 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3277 | } |
| 3278 | else |
| 3279 | { |
| 3280 | if (!m_indexed) |
| 3281 | Index (); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3282 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3283 | m_namespace_index.Find (name, die_offsets); |
| 3284 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3285 | |
| 3286 | DWARFCompileUnit* dwarf_cu = NULL; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3287 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3288 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3289 | if (num_matches) |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3290 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3291 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3292 | for (size_t i=0; i<num_matches; ++i) |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3293 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3294 | const dw_offset_t die_offset = die_offsets[i]; |
| 3295 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3296 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3297 | if (die) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3298 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3299 | if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die)) |
| 3300 | continue; |
| 3301 | |
| 3302 | clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die); |
| 3303 | if (clang_namespace_decl) |
| 3304 | { |
| 3305 | namespace_decl.SetASTContext (GetClangASTContext().getASTContext()); |
| 3306 | namespace_decl.SetNamespaceDecl (clang_namespace_decl); |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3307 | break; |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3308 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3309 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3310 | else |
| 3311 | { |
| 3312 | if (m_using_apple_tables) |
| 3313 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3314 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n", |
| 3315 | die_offset, name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3316 | } |
| 3317 | } |
| 3318 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3319 | } |
| 3320 | } |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3321 | } |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3322 | return namespace_decl; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3323 | } |
| 3324 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3325 | uint32_t |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3326 | SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3327 | { |
| 3328 | // Remember how many sc_list are in the list before we search in case |
| 3329 | // we are appending the results to a variable list. |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3330 | uint32_t original_size = types.GetSize(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3331 | |
| 3332 | const uint32_t num_die_offsets = die_offsets.size(); |
| 3333 | // Parse all of the types we found from the pubtypes matches |
| 3334 | uint32_t i; |
| 3335 | uint32_t num_matches = 0; |
| 3336 | for (i = 0; i < num_die_offsets; ++i) |
| 3337 | { |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3338 | Type *matching_type = ResolveTypeUID (die_offsets[i]); |
| 3339 | if (matching_type) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3340 | { |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3341 | // We found a type pointer, now find the shared pointer form our type list |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 3342 | types.InsertUnique (matching_type->shared_from_this()); |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3343 | ++num_matches; |
| 3344 | if (num_matches >= max_matches) |
| 3345 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3346 | } |
| 3347 | } |
| 3348 | |
| 3349 | // Return the number of variable that were appended to the list |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3350 | return types.GetSize() - original_size; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3351 | } |
| 3352 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3353 | |
| 3354 | size_t |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3355 | SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc, |
| 3356 | clang::DeclContext *containing_decl_ctx, |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3357 | DWARFCompileUnit* dwarf_cu, |
| 3358 | const DWARFDebugInfoEntry *parent_die, |
| 3359 | bool skip_artificial, |
| 3360 | bool &is_static, |
| 3361 | TypeList* type_list, |
| 3362 | std::vector<clang_type_t>& function_param_types, |
| 3363 | std::vector<clang::ParmVarDecl*>& function_param_decls, |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 3364 | unsigned &type_quals, |
| 3365 | ClangASTContext::TemplateParameterInfos &template_param_infos) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3366 | { |
| 3367 | if (parent_die == NULL) |
| 3368 | return 0; |
| 3369 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3370 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| 3371 | |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3372 | size_t arg_idx = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3373 | const DWARFDebugInfoEntry *die; |
| 3374 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 3375 | { |
| 3376 | dw_tag_t tag = die->Tag(); |
| 3377 | switch (tag) |
| 3378 | { |
| 3379 | case DW_TAG_formal_parameter: |
| 3380 | { |
| 3381 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3382 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3383 | if (num_attributes > 0) |
| 3384 | { |
| 3385 | const char *name = NULL; |
| 3386 | Declaration decl; |
| 3387 | dw_offset_t param_type_die_offset = DW_INVALID_OFFSET; |
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 3388 | bool is_artificial = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3389 | // one of None, Auto, Register, Extern, Static, PrivateExtern |
| 3390 | |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 3391 | clang::StorageClass storage = clang::SC_None; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3392 | uint32_t i; |
| 3393 | for (i=0; i<num_attributes; ++i) |
| 3394 | { |
| 3395 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 3396 | DWARFFormValue form_value; |
| 3397 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 3398 | { |
| 3399 | switch (attr) |
| 3400 | { |
| 3401 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 3402 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 3403 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 3404 | case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; |
| 3405 | case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break; |
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 3406 | case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3407 | case DW_AT_location: |
| 3408 | // if (form_value.BlockData()) |
| 3409 | // { |
| 3410 | // const DataExtractor& debug_info_data = debug_info(); |
| 3411 | // uint32_t block_length = form_value.Unsigned(); |
| 3412 | // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length); |
| 3413 | // } |
| 3414 | // else |
| 3415 | // { |
| 3416 | // } |
| 3417 | // break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3418 | case DW_AT_const_value: |
| 3419 | case DW_AT_default_value: |
| 3420 | case DW_AT_description: |
| 3421 | case DW_AT_endianity: |
| 3422 | case DW_AT_is_optional: |
| 3423 | case DW_AT_segment: |
| 3424 | case DW_AT_variable_parameter: |
| 3425 | default: |
| 3426 | case DW_AT_abstract_origin: |
| 3427 | case DW_AT_sibling: |
| 3428 | break; |
| 3429 | } |
| 3430 | } |
| 3431 | } |
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 3432 | |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3433 | bool skip = false; |
| 3434 | if (skip_artificial) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3435 | { |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3436 | if (is_artificial) |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3437 | { |
| 3438 | // In order to determine if a C++ member function is |
| 3439 | // "const" we have to look at the const-ness of "this"... |
| 3440 | // Ugly, but that |
| 3441 | if (arg_idx == 0) |
| 3442 | { |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 3443 | if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind())) |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 3444 | { |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3445 | // Often times compilers omit the "this" name for the |
| 3446 | // specification DIEs, so we can't rely upon the name |
| 3447 | // being in the formal parameter DIE... |
| 3448 | if (name == NULL || ::strcmp(name, "this")==0) |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3449 | { |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3450 | Type *this_type = ResolveTypeUID (param_type_die_offset); |
| 3451 | if (this_type) |
| 3452 | { |
| 3453 | uint32_t encoding_mask = this_type->GetEncodingMask(); |
| 3454 | if (encoding_mask & Type::eEncodingIsPointerUID) |
| 3455 | { |
| 3456 | is_static = false; |
| 3457 | |
| 3458 | if (encoding_mask & (1u << Type::eEncodingIsConstUID)) |
| 3459 | type_quals |= clang::Qualifiers::Const; |
| 3460 | if (encoding_mask & (1u << Type::eEncodingIsVolatileUID)) |
| 3461 | type_quals |= clang::Qualifiers::Volatile; |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3462 | } |
| 3463 | } |
| 3464 | } |
| 3465 | } |
| 3466 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3467 | skip = true; |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3468 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3469 | else |
| 3470 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3471 | |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3472 | // HACK: Objective C formal parameters "self" and "_cmd" |
| 3473 | // are not marked as artificial in the DWARF... |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3474 | CompileUnit *curr_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| 3475 | if (curr_cu && (curr_cu->GetLanguage() == eLanguageTypeObjC || curr_cu->GetLanguage() == eLanguageTypeObjC_plus_plus)) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3476 | { |
| 3477 | if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0)) |
| 3478 | skip = true; |
| 3479 | } |
| 3480 | } |
| 3481 | } |
| 3482 | |
| 3483 | if (!skip) |
| 3484 | { |
| 3485 | Type *type = ResolveTypeUID(param_type_die_offset); |
| 3486 | if (type) |
| 3487 | { |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 3488 | function_param_types.push_back (type->GetClangForwardType()); |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3489 | |
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 3490 | clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name, |
| 3491 | type->GetClangForwardType(), |
| 3492 | storage); |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3493 | assert(param_var_decl); |
| 3494 | function_param_decls.push_back(param_var_decl); |
| 3495 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3496 | } |
| 3497 | } |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3498 | arg_idx++; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3499 | } |
| 3500 | break; |
| 3501 | |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 3502 | case DW_TAG_template_type_parameter: |
| 3503 | case DW_TAG_template_value_parameter: |
| 3504 | ParseTemplateDIE (dwarf_cu, die,template_param_infos); |
| 3505 | break; |
| 3506 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3507 | default: |
| 3508 | break; |
| 3509 | } |
| 3510 | } |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3511 | return arg_idx; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3512 | } |
| 3513 | |
| 3514 | size_t |
| 3515 | SymbolFileDWARF::ParseChildEnumerators |
| 3516 | ( |
| 3517 | const SymbolContext& sc, |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 3518 | clang_type_t enumerator_clang_type, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3519 | uint32_t enumerator_byte_size, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3520 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3521 | const DWARFDebugInfoEntry *parent_die |
| 3522 | ) |
| 3523 | { |
| 3524 | if (parent_die == NULL) |
| 3525 | return 0; |
| 3526 | |
| 3527 | size_t enumerators_added = 0; |
| 3528 | const DWARFDebugInfoEntry *die; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3529 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| 3530 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3531 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 3532 | { |
| 3533 | const dw_tag_t tag = die->Tag(); |
| 3534 | if (tag == DW_TAG_enumerator) |
| 3535 | { |
| 3536 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3537 | const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3538 | if (num_child_attributes > 0) |
| 3539 | { |
| 3540 | const char *name = NULL; |
| 3541 | bool got_value = false; |
| 3542 | int64_t enum_value = 0; |
| 3543 | Declaration decl; |
| 3544 | |
| 3545 | uint32_t i; |
| 3546 | for (i=0; i<num_child_attributes; ++i) |
| 3547 | { |
| 3548 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 3549 | DWARFFormValue form_value; |
| 3550 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 3551 | { |
| 3552 | switch (attr) |
| 3553 | { |
| 3554 | case DW_AT_const_value: |
| 3555 | got_value = true; |
| 3556 | enum_value = form_value.Unsigned(); |
| 3557 | break; |
| 3558 | |
| 3559 | case DW_AT_name: |
| 3560 | name = form_value.AsCString(&get_debug_str_data()); |
| 3561 | break; |
| 3562 | |
| 3563 | case DW_AT_description: |
| 3564 | default: |
| 3565 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 3566 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 3567 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 3568 | case DW_AT_sibling: |
| 3569 | break; |
| 3570 | } |
| 3571 | } |
| 3572 | } |
| 3573 | |
| 3574 | if (name && name[0] && got_value) |
| 3575 | { |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 3576 | GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type, |
| 3577 | enumerator_clang_type, |
| 3578 | decl, |
| 3579 | name, |
| 3580 | enum_value, |
| 3581 | enumerator_byte_size * 8); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3582 | ++enumerators_added; |
| 3583 | } |
| 3584 | } |
| 3585 | } |
| 3586 | } |
| 3587 | return enumerators_added; |
| 3588 | } |
| 3589 | |
| 3590 | void |
| 3591 | SymbolFileDWARF::ParseChildArrayInfo |
| 3592 | ( |
| 3593 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3594 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3595 | const DWARFDebugInfoEntry *parent_die, |
| 3596 | int64_t& first_index, |
| 3597 | std::vector<uint64_t>& element_orders, |
| 3598 | uint32_t& byte_stride, |
| 3599 | uint32_t& bit_stride |
| 3600 | ) |
| 3601 | { |
| 3602 | if (parent_die == NULL) |
| 3603 | return; |
| 3604 | |
| 3605 | const DWARFDebugInfoEntry *die; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3606 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3607 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 3608 | { |
| 3609 | const dw_tag_t tag = die->Tag(); |
| 3610 | switch (tag) |
| 3611 | { |
| 3612 | case DW_TAG_enumerator: |
| 3613 | { |
| 3614 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3615 | const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3616 | if (num_child_attributes > 0) |
| 3617 | { |
| 3618 | const char *name = NULL; |
| 3619 | bool got_value = false; |
| 3620 | int64_t enum_value = 0; |
| 3621 | |
| 3622 | uint32_t i; |
| 3623 | for (i=0; i<num_child_attributes; ++i) |
| 3624 | { |
| 3625 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 3626 | DWARFFormValue form_value; |
| 3627 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 3628 | { |
| 3629 | switch (attr) |
| 3630 | { |
| 3631 | case DW_AT_const_value: |
| 3632 | got_value = true; |
| 3633 | enum_value = form_value.Unsigned(); |
| 3634 | break; |
| 3635 | |
| 3636 | case DW_AT_name: |
| 3637 | name = form_value.AsCString(&get_debug_str_data()); |
| 3638 | break; |
| 3639 | |
| 3640 | case DW_AT_description: |
| 3641 | default: |
| 3642 | case DW_AT_decl_file: |
| 3643 | case DW_AT_decl_line: |
| 3644 | case DW_AT_decl_column: |
| 3645 | case DW_AT_sibling: |
| 3646 | break; |
| 3647 | } |
| 3648 | } |
| 3649 | } |
| 3650 | } |
| 3651 | } |
| 3652 | break; |
| 3653 | |
| 3654 | case DW_TAG_subrange_type: |
| 3655 | { |
| 3656 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3657 | const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3658 | if (num_child_attributes > 0) |
| 3659 | { |
| 3660 | const char *name = NULL; |
| 3661 | bool got_value = false; |
| 3662 | uint64_t byte_size = 0; |
| 3663 | int64_t enum_value = 0; |
| 3664 | uint64_t num_elements = 0; |
| 3665 | uint64_t lower_bound = 0; |
| 3666 | uint64_t upper_bound = 0; |
| 3667 | uint32_t i; |
| 3668 | for (i=0; i<num_child_attributes; ++i) |
| 3669 | { |
| 3670 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 3671 | DWARFFormValue form_value; |
| 3672 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 3673 | { |
| 3674 | switch (attr) |
| 3675 | { |
| 3676 | case DW_AT_const_value: |
| 3677 | got_value = true; |
| 3678 | enum_value = form_value.Unsigned(); |
| 3679 | break; |
| 3680 | |
| 3681 | case DW_AT_name: |
| 3682 | name = form_value.AsCString(&get_debug_str_data()); |
| 3683 | break; |
| 3684 | |
| 3685 | case DW_AT_count: |
| 3686 | num_elements = form_value.Unsigned(); |
| 3687 | break; |
| 3688 | |
| 3689 | case DW_AT_bit_stride: |
| 3690 | bit_stride = form_value.Unsigned(); |
| 3691 | break; |
| 3692 | |
| 3693 | case DW_AT_byte_stride: |
| 3694 | byte_stride = form_value.Unsigned(); |
| 3695 | break; |
| 3696 | |
| 3697 | case DW_AT_byte_size: |
| 3698 | byte_size = form_value.Unsigned(); |
| 3699 | break; |
| 3700 | |
| 3701 | case DW_AT_lower_bound: |
| 3702 | lower_bound = form_value.Unsigned(); |
| 3703 | break; |
| 3704 | |
| 3705 | case DW_AT_upper_bound: |
| 3706 | upper_bound = form_value.Unsigned(); |
| 3707 | break; |
| 3708 | |
| 3709 | default: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3710 | case DW_AT_abstract_origin: |
| 3711 | case DW_AT_accessibility: |
| 3712 | case DW_AT_allocated: |
| 3713 | case DW_AT_associated: |
| 3714 | case DW_AT_data_location: |
| 3715 | case DW_AT_declaration: |
| 3716 | case DW_AT_description: |
| 3717 | case DW_AT_sibling: |
| 3718 | case DW_AT_threads_scaled: |
| 3719 | case DW_AT_type: |
| 3720 | case DW_AT_visibility: |
| 3721 | break; |
| 3722 | } |
| 3723 | } |
| 3724 | } |
| 3725 | |
| 3726 | if (upper_bound > lower_bound) |
| 3727 | num_elements = upper_bound - lower_bound + 1; |
| 3728 | |
| 3729 | if (num_elements > 0) |
| 3730 | element_orders.push_back (num_elements); |
| 3731 | } |
| 3732 | } |
| 3733 | break; |
| 3734 | } |
| 3735 | } |
| 3736 | } |
| 3737 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3738 | TypeSP |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3739 | SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry* die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3740 | { |
| 3741 | TypeSP type_sp; |
| 3742 | if (die != NULL) |
| 3743 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3744 | assert(curr_cu != NULL); |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 3745 | Type *type_ptr = m_die_to_type.lookup (die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3746 | if (type_ptr == NULL) |
| 3747 | { |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 3748 | CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(curr_cu); |
| 3749 | assert (lldb_cu); |
| 3750 | SymbolContext sc(lldb_cu); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3751 | type_sp = ParseType(sc, curr_cu, die, NULL); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3752 | } |
| 3753 | else if (type_ptr != DIE_IS_BEING_PARSED) |
| 3754 | { |
| 3755 | // Grab the existing type from the master types lists |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 3756 | type_sp = type_ptr->shared_from_this(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3757 | } |
| 3758 | |
| 3759 | } |
| 3760 | return type_sp; |
| 3761 | } |
| 3762 | |
| 3763 | clang::DeclContext * |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 3764 | SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3765 | { |
| 3766 | if (die_offset != DW_INVALID_OFFSET) |
| 3767 | { |
| 3768 | DWARFCompileUnitSP cu_sp; |
| 3769 | const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 3770 | return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3771 | } |
| 3772 | return NULL; |
| 3773 | } |
| 3774 | |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 3775 | clang::DeclContext * |
| 3776 | SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset) |
| 3777 | { |
| 3778 | if (die_offset != DW_INVALID_OFFSET) |
| 3779 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 3780 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3781 | if (debug_info) |
| 3782 | { |
| 3783 | DWARFCompileUnitSP cu_sp; |
| 3784 | const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp); |
| 3785 | if (die) |
| 3786 | return GetClangDeclContextForDIE (sc, cu_sp.get(), die); |
| 3787 | } |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 3788 | } |
| 3789 | return NULL; |
| 3790 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3791 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3792 | clang::NamespaceDecl * |
| 3793 | SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die) |
| 3794 | { |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 3795 | if (die && die->Tag() == DW_TAG_namespace) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3796 | { |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 3797 | // See if we already parsed this namespace DIE and associated it with a |
| 3798 | // uniqued namespace declaration |
| 3799 | clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]); |
| 3800 | if (namespace_decl) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3801 | return namespace_decl; |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 3802 | else |
| 3803 | { |
| 3804 | const char *namespace_name = die->GetAttributeValueAsString(this, curr_cu, DW_AT_name, NULL); |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 3805 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (curr_cu, die, NULL); |
| 3806 | namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx); |
| 3807 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| 3808 | if (log) |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 3809 | { |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 3810 | if (namespace_name) |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 3811 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3812 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3813 | "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)", |
| 3814 | GetClangASTContext().getASTContext(), |
| 3815 | MakeUserID(die->GetOffset()), |
| 3816 | namespace_name, |
| 3817 | namespace_decl, |
| 3818 | namespace_decl->getOriginalNamespace()); |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 3819 | } |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 3820 | else |
| 3821 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3822 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3823 | "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)", |
| 3824 | GetClangASTContext().getASTContext(), |
| 3825 | MakeUserID(die->GetOffset()), |
| 3826 | namespace_decl, |
| 3827 | namespace_decl->getOriginalNamespace()); |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 3828 | } |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 3829 | } |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 3830 | |
| 3831 | if (namespace_decl) |
| 3832 | LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die); |
| 3833 | return namespace_decl; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3834 | } |
| 3835 | } |
| 3836 | return NULL; |
| 3837 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3838 | |
| 3839 | clang::DeclContext * |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 3840 | SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 3841 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 3842 | clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die); |
| 3843 | if (clang_decl_ctx) |
| 3844 | return clang_decl_ctx; |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 3845 | // If this DIE has a specification, or an abstract origin, then trace to those. |
| 3846 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 3847 | dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET); |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 3848 | if (die_offset != DW_INVALID_OFFSET) |
| 3849 | return GetClangDeclContextForDIEOffset (sc, die_offset); |
| 3850 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 3851 | die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET); |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 3852 | if (die_offset != DW_INVALID_OFFSET) |
| 3853 | return GetClangDeclContextForDIEOffset (sc, die_offset); |
| 3854 | |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 3855 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| 3856 | if (log) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3857 | GetObjectFile()->GetModule()->LogMessage(log.get(), "SymbolFileDWARF::GetClangDeclContextForDIE (die = 0x%8.8x) %s '%s'", die->GetOffset(), DW_TAG_value_to_name(die->Tag()), die->GetName(this, cu)); |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 3858 | // This is the DIE we want. Parse it, then query our map. |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 3859 | bool assert_not_being_parsed = true; |
| 3860 | ResolveTypeUID (cu, die, assert_not_being_parsed); |
| 3861 | |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 3862 | clang_decl_ctx = GetCachedClangDeclContextForDIE (die); |
| 3863 | |
| 3864 | return clang_decl_ctx; |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 3865 | } |
| 3866 | |
| 3867 | clang::DeclContext * |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 3868 | SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3869 | { |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 3870 | if (m_clang_tu_decl == NULL) |
| 3871 | m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3872 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3873 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 3874 | |
| 3875 | if (decl_ctx_die_copy) |
| 3876 | *decl_ctx_die_copy = decl_ctx_die; |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3877 | |
| 3878 | if (decl_ctx_die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3879 | { |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 3880 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3881 | DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die); |
| 3882 | if (pos != m_die_to_decl_ctx.end()) |
| 3883 | return pos->second; |
| 3884 | |
| 3885 | switch (decl_ctx_die->Tag()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3886 | { |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3887 | case DW_TAG_compile_unit: |
| 3888 | return m_clang_tu_decl; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3889 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3890 | case DW_TAG_namespace: |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 3891 | return ResolveNamespaceDIE (cu, decl_ctx_die); |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3892 | break; |
| 3893 | |
| 3894 | case DW_TAG_structure_type: |
| 3895 | case DW_TAG_union_type: |
| 3896 | case DW_TAG_class_type: |
| 3897 | { |
| 3898 | Type* type = ResolveType (cu, decl_ctx_die); |
| 3899 | if (type) |
| 3900 | { |
| 3901 | clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ()); |
| 3902 | if (decl_ctx) |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 3903 | { |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3904 | LinkDeclContextToDIE (decl_ctx, decl_ctx_die); |
| 3905 | if (decl_ctx) |
| 3906 | return decl_ctx; |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 3907 | } |
| 3908 | } |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 3909 | } |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3910 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3911 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3912 | default: |
| 3913 | break; |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 3914 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3915 | } |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 3916 | return m_clang_tu_decl; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3917 | } |
| 3918 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3919 | |
| 3920 | const DWARFDebugInfoEntry * |
| 3921 | SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) |
| 3922 | { |
| 3923 | if (cu && die) |
| 3924 | { |
| 3925 | const DWARFDebugInfoEntry * const decl_die = die; |
| 3926 | |
| 3927 | while (die != NULL) |
| 3928 | { |
| 3929 | // If this is the original DIE that we are searching for a declaration |
| 3930 | // for, then don't look in the cache as we don't want our own decl |
| 3931 | // context to be our decl context... |
| 3932 | if (decl_die != die) |
| 3933 | { |
| 3934 | switch (die->Tag()) |
| 3935 | { |
| 3936 | case DW_TAG_compile_unit: |
| 3937 | case DW_TAG_namespace: |
| 3938 | case DW_TAG_structure_type: |
| 3939 | case DW_TAG_union_type: |
| 3940 | case DW_TAG_class_type: |
| 3941 | return die; |
| 3942 | |
| 3943 | default: |
| 3944 | break; |
| 3945 | } |
| 3946 | } |
| 3947 | |
| 3948 | dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET); |
| 3949 | if (die_offset != DW_INVALID_OFFSET) |
| 3950 | { |
| 3951 | DWARFCompileUnit *spec_cu = cu; |
| 3952 | const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu); |
| 3953 | const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die); |
| 3954 | if (spec_die_decl_ctx_die) |
| 3955 | return spec_die_decl_ctx_die; |
| 3956 | } |
| 3957 | |
| 3958 | die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET); |
| 3959 | if (die_offset != DW_INVALID_OFFSET) |
| 3960 | { |
| 3961 | DWARFCompileUnit *abs_cu = cu; |
| 3962 | const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu); |
| 3963 | const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die); |
| 3964 | if (abs_die_decl_ctx_die) |
| 3965 | return abs_die_decl_ctx_die; |
| 3966 | } |
| 3967 | |
| 3968 | die = die->GetParent(); |
| 3969 | } |
| 3970 | } |
| 3971 | return NULL; |
| 3972 | } |
| 3973 | |
| 3974 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3975 | Symbol * |
| 3976 | SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name) |
| 3977 | { |
| 3978 | Symbol *objc_class_symbol = NULL; |
| 3979 | if (m_obj_file) |
| 3980 | { |
| 3981 | Symtab *symtab = m_obj_file->GetSymtab(); |
| 3982 | if (symtab) |
| 3983 | { |
| 3984 | objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name, |
| 3985 | eSymbolTypeObjCClass, |
| 3986 | Symtab::eDebugNo, |
| 3987 | Symtab::eVisibilityAny); |
| 3988 | } |
| 3989 | } |
| 3990 | return objc_class_symbol; |
| 3991 | } |
| 3992 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 3993 | // Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't |
| 3994 | // then we can end up looking through all class types for a complete type and never find |
| 3995 | // the full definition. We need to know if this attribute is supported, so we determine |
| 3996 | // this here and cache th result. We also need to worry about the debug map DWARF file |
| 3997 | // if we are doing darwin DWARF in .o file debugging. |
| 3998 | bool |
| 3999 | SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu) |
| 4000 | { |
| 4001 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate) |
| 4002 | { |
| 4003 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo; |
| 4004 | if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type()) |
| 4005 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; |
| 4006 | else |
| 4007 | { |
| 4008 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 4009 | const uint32_t num_compile_units = GetNumCompileUnits(); |
| 4010 | for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) |
| 4011 | { |
| 4012 | DWARFCompileUnit* curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx); |
| 4013 | if (curr_cu != cu && curr_cu->Supports_DW_AT_APPLE_objc_complete_type()) |
| 4014 | { |
| 4015 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; |
| 4016 | break; |
| 4017 | } |
| 4018 | } |
| 4019 | } |
| 4020 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && m_debug_map_symfile) |
| 4021 | return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this); |
| 4022 | } |
| 4023 | return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes; |
| 4024 | } |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4025 | |
| 4026 | // This function can be used when a DIE is found that is a forward declaration |
| 4027 | // DIE and we want to try and find a type that has the complete definition. |
| 4028 | TypeSP |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4029 | SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die, |
| 4030 | const ConstString &type_name, |
| 4031 | bool must_be_implementation) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4032 | { |
| 4033 | |
| 4034 | TypeSP type_sp; |
| 4035 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4036 | if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name))) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4037 | return type_sp; |
| 4038 | |
| 4039 | DIEArray die_offsets; |
| 4040 | |
| 4041 | if (m_using_apple_tables) |
| 4042 | { |
| 4043 | if (m_apple_types_ap.get()) |
| 4044 | { |
| 4045 | const char *name_cstr = type_name.GetCString(); |
| Greg Clayton | 68221ec | 2012-01-18 20:58:12 +0000 | [diff] [blame] | 4046 | m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4047 | } |
| 4048 | } |
| 4049 | else |
| 4050 | { |
| 4051 | if (!m_indexed) |
| 4052 | Index (); |
| 4053 | |
| 4054 | m_type_index.Find (type_name, die_offsets); |
| 4055 | } |
| 4056 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4057 | const size_t num_matches = die_offsets.size(); |
| 4058 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4059 | DWARFCompileUnit* type_cu = NULL; |
| 4060 | const DWARFDebugInfoEntry* type_die = NULL; |
| 4061 | if (num_matches) |
| 4062 | { |
| 4063 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 4064 | for (size_t i=0; i<num_matches; ++i) |
| 4065 | { |
| 4066 | const dw_offset_t die_offset = die_offsets[i]; |
| 4067 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); |
| 4068 | |
| 4069 | if (type_die) |
| 4070 | { |
| 4071 | bool try_resolving_type = false; |
| 4072 | |
| 4073 | // Don't try and resolve the DIE we are looking for with the DIE itself! |
| 4074 | if (type_die != die) |
| 4075 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4076 | switch (type_die->Tag()) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4077 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4078 | case DW_TAG_class_type: |
| 4079 | case DW_TAG_structure_type: |
| 4080 | try_resolving_type = true; |
| 4081 | break; |
| 4082 | default: |
| 4083 | break; |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4084 | } |
| 4085 | } |
| 4086 | |
| 4087 | if (try_resolving_type) |
| 4088 | { |
| Sean Callanan | a9bc065 | 2012-01-19 02:17:40 +0000 | [diff] [blame] | 4089 | if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type()) |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4090 | try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4091 | |
| 4092 | if (try_resolving_type) |
| 4093 | { |
| 4094 | Type *resolved_type = ResolveType (type_cu, type_die, false); |
| 4095 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) |
| 4096 | { |
| 4097 | DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n", |
| 4098 | MakeUserID(die->GetOffset()), |
| 4099 | MakeUserID(curr_cu->GetOffset()), |
| 4100 | m_obj_file->GetFileSpec().GetFilename().AsCString(), |
| 4101 | MakeUserID(type_die->GetOffset()), |
| 4102 | MakeUserID(type_cu->GetOffset())); |
| 4103 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4104 | if (die) |
| 4105 | m_die_to_type[die] = resolved_type; |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 4106 | type_sp = resolved_type->shared_from_this(); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4107 | break; |
| 4108 | } |
| 4109 | } |
| 4110 | } |
| 4111 | } |
| 4112 | else |
| 4113 | { |
| 4114 | if (m_using_apple_tables) |
| 4115 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4116 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 4117 | die_offset, type_name.GetCString()); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4118 | } |
| 4119 | } |
| 4120 | |
| 4121 | } |
| 4122 | } |
| 4123 | return type_sp; |
| 4124 | } |
| 4125 | |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4126 | //---------------------------------------------------------------------- |
| 4127 | // This function helps to ensure that the declaration contexts match for |
| 4128 | // two different DIEs. Often times debug information will refer to a |
| 4129 | // forward declaration of a type (the equivalent of "struct my_struct;". |
| 4130 | // There will often be a declaration of that type elsewhere that has the |
| 4131 | // full definition. When we go looking for the full type "my_struct", we |
| 4132 | // will find one or more matches in the accelerator tables and we will |
| 4133 | // then need to make sure the type was in the same declaration context |
| 4134 | // as the original DIE. This function can efficiently compare two DIEs |
| 4135 | // and will return true when the declaration context matches, and false |
| 4136 | // when they don't. |
| 4137 | //---------------------------------------------------------------------- |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4138 | bool |
| 4139 | SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1, |
| 4140 | DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2) |
| 4141 | { |
| 4142 | assert (die1 != die2); |
| 4143 | DWARFDIECollection decl_ctx_1; |
| 4144 | DWARFDIECollection decl_ctx_2; |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4145 | //The declaration DIE stack is a stack of the declaration context |
| 4146 | // DIEs all the way back to the compile unit. If a type "T" is |
| 4147 | // declared inside a class "B", and class "B" is declared inside |
| 4148 | // a class "A" and class "A" is in a namespace "lldb", and the |
| 4149 | // namespace is in a compile unit, there will be a stack of DIEs: |
| 4150 | // |
| 4151 | // [0] DW_TAG_class_type for "B" |
| 4152 | // [1] DW_TAG_class_type for "A" |
| 4153 | // [2] DW_TAG_namespace for "lldb" |
| 4154 | // [3] DW_TAG_compile_unit for the source file. |
| 4155 | // |
| 4156 | // We grab both contexts and make sure that everything matches |
| 4157 | // all the way back to the compiler unit. |
| 4158 | |
| 4159 | // First lets grab the decl contexts for both DIEs |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4160 | die1->GetDeclContextDIEs (this, cu1, decl_ctx_1); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 4161 | die2->GetDeclContextDIEs (this, cu2, decl_ctx_2); |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4162 | // Make sure the context arrays have the same size, otherwise |
| 4163 | // we are done |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4164 | const size_t count1 = decl_ctx_1.Size(); |
| 4165 | const size_t count2 = decl_ctx_2.Size(); |
| 4166 | if (count1 != count2) |
| 4167 | return false; |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4168 | |
| 4169 | // Make sure the DW_TAG values match all the way back up the the |
| 4170 | // compile unit. If they don't, then we are done. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4171 | const DWARFDebugInfoEntry *decl_ctx_die1; |
| 4172 | const DWARFDebugInfoEntry *decl_ctx_die2; |
| 4173 | size_t i; |
| 4174 | for (i=0; i<count1; i++) |
| 4175 | { |
| 4176 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); |
| 4177 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); |
| 4178 | if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag()) |
| 4179 | return false; |
| 4180 | } |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4181 | #if defined LLDB_CONFIGURATION_DEBUG |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4182 | |
| 4183 | // Make sure the top item in the decl context die array is always |
| 4184 | // DW_TAG_compile_unit. If it isn't then something went wrong in |
| 4185 | // the DWARFDebugInfoEntry::GetDeclContextDIEs() function... |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4186 | assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit); |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4187 | |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4188 | #endif |
| 4189 | // Always skip the compile unit when comparing by only iterating up to |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4190 | // "count - 1". Here we compare the names as we go. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4191 | for (i=0; i<count1 - 1; i++) |
| 4192 | { |
| 4193 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); |
| 4194 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); |
| 4195 | const char *name1 = decl_ctx_die1->GetName(this, cu1); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 4196 | const char *name2 = decl_ctx_die2->GetName(this, cu2); |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4197 | // If the string was from a DW_FORM_strp, then the pointer will often |
| 4198 | // be the same! |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 4199 | if (name1 == name2) |
| 4200 | continue; |
| 4201 | |
| 4202 | // Name pointers are not equal, so only compare the strings |
| 4203 | // if both are not NULL. |
| 4204 | if (name1 && name2) |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4205 | { |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 4206 | // If the strings don't compare, we are done... |
| 4207 | if (strcmp(name1, name2) != 0) |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4208 | return false; |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 4209 | } |
| 4210 | else |
| 4211 | { |
| 4212 | // One name was NULL while the other wasn't |
| 4213 | return false; |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4214 | } |
| 4215 | } |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4216 | // We made it through all of the checks and the declaration contexts |
| 4217 | // are equal. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4218 | return true; |
| 4219 | } |
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 4220 | |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4221 | // This function can be used when a DIE is found that is a forward declaration |
| 4222 | // DIE and we want to try and find a type that has the complete definition. |
| 4223 | TypeSP |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4224 | SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu, |
| 4225 | const DWARFDebugInfoEntry *die, |
| 4226 | const ConstString &type_name) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4227 | { |
| 4228 | TypeSP type_sp; |
| 4229 | |
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 4230 | if (cu == NULL || die == NULL || !type_name) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4231 | return type_sp; |
| 4232 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4233 | DIEArray die_offsets; |
| 4234 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4235 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4236 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4237 | if (m_apple_types_ap.get()) |
| 4238 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4239 | if (m_apple_types_ap->GetHeader().header_data.atoms.size() > 1) |
| 4240 | { |
| Greg Clayton | ae920b6 | 2012-01-06 00:17:16 +0000 | [diff] [blame] | 4241 | m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets); |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4242 | } |
| 4243 | else |
| 4244 | { |
| 4245 | m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets); |
| 4246 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4247 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4248 | } |
| 4249 | else |
| 4250 | { |
| 4251 | if (!m_indexed) |
| 4252 | Index (); |
| 4253 | |
| 4254 | m_type_index.Find (type_name, die_offsets); |
| 4255 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4256 | |
| 4257 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | 6997489 | 2010-12-03 21:42:06 +0000 | [diff] [blame] | 4258 | |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4259 | const dw_tag_t die_tag = die->Tag(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4260 | |
| 4261 | DWARFCompileUnit* type_cu = NULL; |
| 4262 | const DWARFDebugInfoEntry* type_die = NULL; |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4263 | if (num_matches) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4264 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4265 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4266 | for (size_t i=0; i<num_matches; ++i) |
| 4267 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4268 | const dw_offset_t die_offset = die_offsets[i]; |
| 4269 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4270 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4271 | if (type_die) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4272 | { |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4273 | bool try_resolving_type = false; |
| 4274 | |
| 4275 | // Don't try and resolve the DIE we are looking for with the DIE itself! |
| 4276 | if (type_die != die) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4277 | { |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4278 | const dw_tag_t type_die_tag = type_die->Tag(); |
| 4279 | // Make sure the tags match |
| 4280 | if (type_die_tag == die_tag) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4281 | { |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4282 | // The tags match, lets try resolving this type |
| 4283 | try_resolving_type = true; |
| 4284 | } |
| 4285 | else |
| 4286 | { |
| 4287 | // The tags don't match, but we need to watch our for a |
| 4288 | // forward declaration for a struct and ("struct foo") |
| 4289 | // ends up being a class ("class foo { ... };") or |
| 4290 | // vice versa. |
| 4291 | switch (type_die_tag) |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4292 | { |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4293 | case DW_TAG_class_type: |
| 4294 | // We had a "class foo", see if we ended up with a "struct foo { ... };" |
| 4295 | try_resolving_type = (die_tag == DW_TAG_structure_type); |
| 4296 | break; |
| 4297 | case DW_TAG_structure_type: |
| 4298 | // We had a "struct foo", see if we ended up with a "class foo { ... };" |
| 4299 | try_resolving_type = (die_tag == DW_TAG_class_type); |
| 4300 | break; |
| 4301 | default: |
| 4302 | // Tags don't match, don't event try to resolve |
| 4303 | // using this type whose name matches.... |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4304 | break; |
| 4305 | } |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4306 | } |
| 4307 | } |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4308 | |
| 4309 | if (try_resolving_type) |
| 4310 | { |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4311 | // Make sure the decl contexts match all the way up |
| 4312 | if (DIEDeclContextsMatch(cu, die, type_cu, type_die)) |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4313 | { |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4314 | Type *resolved_type = ResolveType (type_cu, type_die, false); |
| 4315 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) |
| 4316 | { |
| 4317 | DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n", |
| 4318 | MakeUserID(die->GetOffset()), |
| 4319 | MakeUserID(curr_cu->GetOffset()), |
| 4320 | m_obj_file->GetFileSpec().GetFilename().AsCString(), |
| 4321 | MakeUserID(type_die->GetOffset()), |
| 4322 | MakeUserID(type_cu->GetOffset())); |
| 4323 | |
| 4324 | m_die_to_type[die] = resolved_type; |
| Greg Clayton | ff7692a | 2012-02-02 18:16:59 +0000 | [diff] [blame] | 4325 | type_sp = resolved_type->shared_from_this(); |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4326 | break; |
| 4327 | } |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4328 | } |
| 4329 | } |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4330 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4331 | else |
| 4332 | { |
| 4333 | if (m_using_apple_tables) |
| 4334 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4335 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 4336 | die_offset, type_name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4337 | } |
| 4338 | } |
| 4339 | |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4340 | } |
| 4341 | } |
| 4342 | return type_sp; |
| 4343 | } |
| 4344 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4345 | TypeSP |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 4346 | SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4347 | { |
| 4348 | TypeSP type_sp; |
| 4349 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 4350 | if (type_is_new_ptr) |
| 4351 | *type_is_new_ptr = false; |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 4352 | |
| 4353 | static int depth = -1; |
| 4354 | |
| 4355 | class DepthTaker { |
| 4356 | public: |
| 4357 | DepthTaker (int &depth) : m_depth(depth) { ++m_depth; } |
| 4358 | ~DepthTaker () { --m_depth; } |
| 4359 | int &m_depth; |
| 4360 | } depth_taker(depth); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 4361 | |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 4362 | AccessType accessibility = eAccessNone; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4363 | if (die != NULL) |
| 4364 | { |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 4365 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 4366 | if (log) |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 4367 | { |
| 4368 | const DWARFDebugInfoEntry *context_die; |
| 4369 | clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die); |
| 4370 | |
| 4371 | std::string name_storage; |
| 4372 | |
| 4373 | const char* qual_name = die->GetQualifiedName(this, |
| 4374 | dwarf_cu, |
| 4375 | name_storage); |
| 4376 | |
| 4377 | GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (depth = %d, die = 0x%8.8x, decl_ctx = %p (die 0x%8.8x)) %s '%s'='%s')", |
| 4378 | depth, |
| 4379 | die->GetOffset(), |
| 4380 | context, |
| 4381 | context_die->GetOffset(), |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 4382 | DW_TAG_value_to_name(die->Tag()), |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 4383 | die->GetName(this, dwarf_cu), |
| 4384 | qual_name); |
| 4385 | } |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 4386 | // |
| 4387 | // LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| 4388 | // if (log && dwarf_cu) |
| 4389 | // { |
| 4390 | // StreamString s; |
| 4391 | // die->DumpLocation (this, dwarf_cu, s); |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4392 | // GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData()); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 4393 | // |
| 4394 | // } |
| Jim Ingham | 16746d1 | 2011-08-25 23:21:43 +0000 | [diff] [blame] | 4395 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4396 | Type *type_ptr = m_die_to_type.lookup (die); |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 4397 | TypeList* type_list = GetTypeList(); |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4398 | if (type_ptr == NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4399 | { |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 4400 | ClangASTContext &ast = GetClangASTContext(); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 4401 | if (type_is_new_ptr) |
| 4402 | *type_is_new_ptr = true; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4403 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4404 | const dw_tag_t tag = die->Tag(); |
| 4405 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4406 | bool is_forward_declaration = false; |
| 4407 | DWARFDebugInfoEntry::Attributes attributes; |
| 4408 | const char *type_name_cstr = NULL; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 4409 | ConstString type_name_const_str; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4410 | Type::ResolveState resolve_state = Type::eResolveStateUnresolved; |
| 4411 | size_t byte_size = 0; |
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 4412 | bool byte_size_valid = false; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4413 | Declaration decl; |
| 4414 | |
| Greg Clayton | 4957bf6 | 2010-09-30 21:49:03 +0000 | [diff] [blame] | 4415 | Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 4416 | clang_type_t clang_type = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4417 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4418 | dw_attr_t attr; |
| 4419 | |
| 4420 | switch (tag) |
| 4421 | { |
| 4422 | case DW_TAG_base_type: |
| 4423 | case DW_TAG_pointer_type: |
| 4424 | case DW_TAG_reference_type: |
| 4425 | case DW_TAG_typedef: |
| 4426 | case DW_TAG_const_type: |
| 4427 | case DW_TAG_restrict_type: |
| 4428 | case DW_TAG_volatile_type: |
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 4429 | case DW_TAG_unspecified_type: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4430 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4431 | // Set a bit that lets us know that we are currently parsing this |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4432 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4433 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4434 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4435 | uint32_t encoding = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4436 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; |
| 4437 | |
| 4438 | if (num_attributes > 0) |
| 4439 | { |
| 4440 | uint32_t i; |
| 4441 | for (i=0; i<num_attributes; ++i) |
| 4442 | { |
| 4443 | attr = attributes.AttributeAtIndex(i); |
| 4444 | DWARFFormValue form_value; |
| 4445 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 4446 | { |
| 4447 | switch (attr) |
| 4448 | { |
| 4449 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 4450 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 4451 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 4452 | case DW_AT_name: |
| Jim Ingham | 337030f | 2011-04-15 23:41:23 +0000 | [diff] [blame] | 4453 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4454 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Jim Ingham | 337030f | 2011-04-15 23:41:23 +0000 | [diff] [blame] | 4455 | // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't |
| 4456 | // include the "&"... |
| 4457 | if (tag == DW_TAG_reference_type) |
| 4458 | { |
| 4459 | if (strchr (type_name_cstr, '&') == NULL) |
| 4460 | type_name_cstr = NULL; |
| 4461 | } |
| 4462 | if (type_name_cstr) |
| 4463 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4464 | break; |
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 4465 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4466 | case DW_AT_encoding: encoding = form_value.Unsigned(); break; |
| 4467 | case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; |
| 4468 | default: |
| 4469 | case DW_AT_sibling: |
| 4470 | break; |
| 4471 | } |
| 4472 | } |
| 4473 | } |
| 4474 | } |
| 4475 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 4476 | DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\") type => 0x%8.8x\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr, encoding_uid); |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 4477 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4478 | switch (tag) |
| 4479 | { |
| 4480 | default: |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4481 | break; |
| 4482 | |
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 4483 | case DW_TAG_unspecified_type: |
| 4484 | if (strcmp(type_name_cstr, "nullptr_t") == 0) |
| 4485 | { |
| 4486 | resolve_state = Type::eResolveStateFull; |
| 4487 | clang_type = ast.getASTContext()->NullPtrTy.getAsOpaquePtr(); |
| 4488 | break; |
| 4489 | } |
| 4490 | // Fall through to base type below in case we can handle the type there... |
| 4491 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4492 | case DW_TAG_base_type: |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4493 | resolve_state = Type::eResolveStateFull; |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 4494 | clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr, |
| 4495 | encoding, |
| 4496 | byte_size * 8); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4497 | break; |
| 4498 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4499 | case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break; |
| 4500 | case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break; |
| 4501 | case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break; |
| 4502 | case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break; |
| 4503 | case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break; |
| 4504 | case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4505 | } |
| 4506 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4507 | if (clang_type == NULL && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID)) |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4508 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4509 | if (type_name_cstr != NULL && sc.comp_unit != NULL && |
| 4510 | (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus)) |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4511 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4512 | static ConstString g_objc_type_name_id("id"); |
| 4513 | static ConstString g_objc_type_name_Class("Class"); |
| 4514 | static ConstString g_objc_type_name_selector("SEL"); |
| 4515 | |
| 4516 | if (type_name_const_str == g_objc_type_name_id) |
| 4517 | { |
| 4518 | if (log) |
| 4519 | GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'id' built-in type.", |
| 4520 | die->GetOffset(), |
| 4521 | DW_TAG_value_to_name(die->Tag()), |
| 4522 | die->GetName(this, dwarf_cu)); |
| 4523 | clang_type = ast.GetBuiltInType_objc_id(); |
| 4524 | encoding_data_type = Type::eEncodingIsUID; |
| 4525 | encoding_uid = LLDB_INVALID_UID; |
| 4526 | resolve_state = Type::eResolveStateFull; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4527 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4528 | } |
| 4529 | else if (type_name_const_str == g_objc_type_name_Class) |
| 4530 | { |
| 4531 | if (log) |
| 4532 | GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'Class' built-in type.", |
| 4533 | die->GetOffset(), |
| 4534 | DW_TAG_value_to_name(die->Tag()), |
| 4535 | die->GetName(this, dwarf_cu)); |
| 4536 | clang_type = ast.GetBuiltInType_objc_Class(); |
| 4537 | encoding_data_type = Type::eEncodingIsUID; |
| 4538 | encoding_uid = LLDB_INVALID_UID; |
| 4539 | resolve_state = Type::eResolveStateFull; |
| 4540 | } |
| 4541 | else if (type_name_const_str == g_objc_type_name_selector) |
| 4542 | { |
| 4543 | if (log) |
| 4544 | GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'selector' built-in type.", |
| 4545 | die->GetOffset(), |
| 4546 | DW_TAG_value_to_name(die->Tag()), |
| 4547 | die->GetName(this, dwarf_cu)); |
| 4548 | clang_type = ast.GetBuiltInType_objc_selector(); |
| 4549 | encoding_data_type = Type::eEncodingIsUID; |
| 4550 | encoding_uid = LLDB_INVALID_UID; |
| 4551 | resolve_state = Type::eResolveStateFull; |
| 4552 | } |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4553 | } |
| 4554 | } |
| 4555 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 4556 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 4557 | this, |
| 4558 | type_name_const_str, |
| 4559 | byte_size, |
| 4560 | NULL, |
| 4561 | encoding_uid, |
| 4562 | encoding_data_type, |
| 4563 | &decl, |
| 4564 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4565 | resolve_state)); |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 4566 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4567 | m_die_to_type[die] = type_sp.get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4568 | |
| 4569 | // Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false); |
| 4570 | // if (encoding_type != NULL) |
| 4571 | // { |
| 4572 | // if (encoding_type != DIE_IS_BEING_PARSED) |
| 4573 | // type_sp->SetEncodingType(encoding_type); |
| 4574 | // else |
| 4575 | // m_indirect_fixups.push_back(type_sp.get()); |
| 4576 | // } |
| 4577 | } |
| 4578 | break; |
| 4579 | |
| 4580 | case DW_TAG_structure_type: |
| 4581 | case DW_TAG_union_type: |
| 4582 | case DW_TAG_class_type: |
| 4583 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4584 | // Set a bit that lets us know that we are currently parsing this |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4585 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4586 | |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4587 | LanguageType class_language = eLanguageTypeUnknown; |
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 4588 | bool is_complete_objc_class = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4589 | //bool struct_is_class = false; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4590 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4591 | if (num_attributes > 0) |
| 4592 | { |
| 4593 | uint32_t i; |
| 4594 | for (i=0; i<num_attributes; ++i) |
| 4595 | { |
| 4596 | attr = attributes.AttributeAtIndex(i); |
| 4597 | DWARFFormValue form_value; |
| 4598 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 4599 | { |
| 4600 | switch (attr) |
| 4601 | { |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4602 | case DW_AT_decl_file: |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4603 | if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid()) |
| 4604 | { |
| 4605 | // llvm-gcc outputs invalid DW_AT_decl_file attributes that always |
| 4606 | // point to the compile unit file, so we clear this invalid value |
| 4607 | // so that we can still unique types efficiently. |
| 4608 | decl.SetFile(FileSpec ("<invalid>", false)); |
| 4609 | } |
| 4610 | else |
| 4611 | decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4612 | break; |
| 4613 | |
| 4614 | case DW_AT_decl_line: |
| 4615 | decl.SetLine(form_value.Unsigned()); |
| 4616 | break; |
| 4617 | |
| 4618 | case DW_AT_decl_column: |
| 4619 | decl.SetColumn(form_value.Unsigned()); |
| 4620 | break; |
| 4621 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4622 | case DW_AT_name: |
| 4623 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 4624 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4625 | break; |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4626 | |
| 4627 | case DW_AT_byte_size: |
| 4628 | byte_size = form_value.Unsigned(); |
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 4629 | byte_size_valid = true; |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4630 | break; |
| 4631 | |
| 4632 | case DW_AT_accessibility: |
| 4633 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); |
| 4634 | break; |
| 4635 | |
| 4636 | case DW_AT_declaration: |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 4637 | is_forward_declaration = form_value.Unsigned() != 0; |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4638 | break; |
| 4639 | |
| 4640 | case DW_AT_APPLE_runtime_class: |
| 4641 | class_language = (LanguageType)form_value.Signed(); |
| 4642 | break; |
| 4643 | |
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 4644 | case DW_AT_APPLE_objc_complete_type: |
| 4645 | is_complete_objc_class = form_value.Signed(); |
| 4646 | break; |
| 4647 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4648 | case DW_AT_allocated: |
| 4649 | case DW_AT_associated: |
| 4650 | case DW_AT_data_location: |
| 4651 | case DW_AT_description: |
| 4652 | case DW_AT_start_scope: |
| 4653 | case DW_AT_visibility: |
| 4654 | default: |
| 4655 | case DW_AT_sibling: |
| 4656 | break; |
| 4657 | } |
| 4658 | } |
| 4659 | } |
| 4660 | } |
| 4661 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4662 | UniqueDWARFASTType unique_ast_entry; |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame^] | 4663 | |
| 4664 | if (GetUniqueDWARFASTTypeMap().Find (type_name_const_str, |
| 4665 | this, |
| 4666 | dwarf_cu, |
| 4667 | die, |
| 4668 | decl, |
| 4669 | byte_size_valid ? byte_size : -1, |
| 4670 | unique_ast_entry)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4671 | { |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame^] | 4672 | // We have already parsed this type or from another |
| 4673 | // compile unit. GCC loves to use the "one definition |
| 4674 | // rule" which can result in multiple definitions |
| 4675 | // of the same class over and over in each compile |
| 4676 | // unit. |
| 4677 | type_sp = unique_ast_entry.m_type_sp; |
| 4678 | if (type_sp) |
| Greg Clayton | c615ce4 | 2010-11-09 04:42:43 +0000 | [diff] [blame] | 4679 | { |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame^] | 4680 | m_die_to_type[die] = type_sp.get(); |
| 4681 | return type_sp; |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 4682 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4683 | } |
| 4684 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 4685 | DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr); |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4686 | |
| 4687 | int tag_decl_kind = -1; |
| 4688 | AccessType default_accessibility = eAccessNone; |
| 4689 | if (tag == DW_TAG_structure_type) |
| 4690 | { |
| 4691 | tag_decl_kind = clang::TTK_Struct; |
| 4692 | default_accessibility = eAccessPublic; |
| 4693 | } |
| 4694 | else if (tag == DW_TAG_union_type) |
| 4695 | { |
| 4696 | tag_decl_kind = clang::TTK_Union; |
| 4697 | default_accessibility = eAccessPublic; |
| 4698 | } |
| 4699 | else if (tag == DW_TAG_class_type) |
| 4700 | { |
| 4701 | tag_decl_kind = clang::TTK_Class; |
| 4702 | default_accessibility = eAccessPrivate; |
| 4703 | } |
| Greg Clayton | 3a5f29a | 2011-11-30 02:48:28 +0000 | [diff] [blame] | 4704 | |
| 4705 | if (byte_size_valid && byte_size == 0 && type_name_cstr && |
| 4706 | die->HasChildren() == false && |
| 4707 | sc.comp_unit->GetLanguage() == eLanguageTypeObjC) |
| 4708 | { |
| 4709 | // Work around an issue with clang at the moment where |
| 4710 | // forward declarations for objective C classes are emitted |
| 4711 | // as: |
| 4712 | // DW_TAG_structure_type [2] |
| 4713 | // DW_AT_name( "ForwardObjcClass" ) |
| 4714 | // DW_AT_byte_size( 0x00 ) |
| 4715 | // DW_AT_decl_file( "..." ) |
| 4716 | // DW_AT_decl_line( 1 ) |
| 4717 | // |
| 4718 | // Note that there is no DW_AT_declaration and there are |
| 4719 | // no children, and the byte size is zero. |
| 4720 | is_forward_declaration = true; |
| 4721 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4722 | |
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 4723 | if (class_language == eLanguageTypeObjC) |
| 4724 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4725 | if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu)) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4726 | { |
| 4727 | // We have a valid eSymbolTypeObjCClass class symbol whose |
| 4728 | // name matches the current objective C class that we |
| 4729 | // are trying to find and this DIE isn't the complete |
| 4730 | // definition (we checked is_complete_objc_class above and |
| 4731 | // know it is false), so the real definition is in here somewhere |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4732 | type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true); |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4733 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4734 | if (!type_sp && m_debug_map_symfile) |
| 4735 | { |
| 4736 | // We weren't able to find a full declaration in |
| 4737 | // this DWARF, see if we have a declaration anywhere |
| 4738 | // else... |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4739 | type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4740 | } |
| 4741 | |
| 4742 | if (type_sp) |
| 4743 | { |
| 4744 | if (log) |
| 4745 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4746 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 4747 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an incomplete objc type, complete type is 0x%8.8llx", |
| 4748 | this, |
| 4749 | die->GetOffset(), |
| 4750 | DW_TAG_value_to_name(tag), |
| 4751 | type_name_cstr, |
| 4752 | type_sp->GetID()); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4753 | } |
| 4754 | |
| 4755 | // We found a real definition for this type elsewhere |
| 4756 | // so lets use it and cache the fact that we found |
| 4757 | // a complete type for this die |
| 4758 | m_die_to_type[die] = type_sp.get(); |
| 4759 | return type_sp; |
| 4760 | } |
| 4761 | } |
| 4762 | } |
| 4763 | |
| 4764 | |
| 4765 | if (is_forward_declaration) |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4766 | { |
| 4767 | // We have a forward declaration to a type and we need |
| 4768 | // to try and find a full declaration. We look in the |
| 4769 | // current type index just in case we have a forward |
| 4770 | // declaration followed by an actual declarations in the |
| 4771 | // DWARF. If this fails, we need to look elsewhere... |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 4772 | if (log) |
| 4773 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4774 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 4775 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type", |
| 4776 | this, |
| 4777 | die->GetOffset(), |
| 4778 | DW_TAG_value_to_name(tag), |
| 4779 | type_name_cstr); |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 4780 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4781 | |
| 4782 | type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str); |
| 4783 | |
| 4784 | if (!type_sp && m_debug_map_symfile) |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 4785 | { |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4786 | // We weren't able to find a full declaration in |
| 4787 | // this DWARF, see if we have a declaration anywhere |
| 4788 | // else... |
| 4789 | type_sp = m_debug_map_symfile->FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str); |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 4790 | } |
| 4791 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4792 | if (type_sp) |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 4793 | { |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 4794 | if (log) |
| 4795 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4796 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 4797 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8llx", |
| 4798 | this, |
| 4799 | die->GetOffset(), |
| 4800 | DW_TAG_value_to_name(tag), |
| 4801 | type_name_cstr, |
| 4802 | type_sp->GetID()); |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 4803 | } |
| 4804 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4805 | // We found a real definition for this type elsewhere |
| 4806 | // so lets use it and cache the fact that we found |
| 4807 | // a complete type for this die |
| 4808 | m_die_to_type[die] = type_sp.get(); |
| 4809 | return type_sp; |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 4810 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4811 | } |
| 4812 | assert (tag_decl_kind != -1); |
| 4813 | bool clang_type_was_created = false; |
| 4814 | clang_type = m_forward_decl_die_to_clang_type.lookup (die); |
| 4815 | if (clang_type == NULL) |
| 4816 | { |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 4817 | clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL); |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 4818 | if (accessibility == eAccessNone && decl_ctx) |
| 4819 | { |
| 4820 | // Check the decl context that contains this class/struct/union. |
| 4821 | // If it is a class we must give it an accessability. |
| 4822 | const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind(); |
| 4823 | if (DeclKindIsCXXClass (containing_decl_kind)) |
| 4824 | accessibility = default_accessibility; |
| 4825 | } |
| 4826 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 4827 | if (type_name_cstr && strchr (type_name_cstr, '<')) |
| 4828 | { |
| 4829 | ClangASTContext::TemplateParameterInfos template_param_infos; |
| 4830 | if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos)) |
| 4831 | { |
| 4832 | clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx, |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 4833 | accessibility, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 4834 | type_name_cstr, |
| 4835 | tag_decl_kind, |
| 4836 | template_param_infos); |
| 4837 | |
| 4838 | clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx, |
| 4839 | class_template_decl, |
| 4840 | tag_decl_kind, |
| 4841 | template_param_infos); |
| 4842 | clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl); |
| 4843 | clang_type_was_created = true; |
| 4844 | } |
| 4845 | } |
| 4846 | |
| 4847 | if (!clang_type_was_created) |
| 4848 | { |
| 4849 | clang_type_was_created = true; |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 4850 | clang_type = ast.CreateRecordType (decl_ctx, |
| 4851 | accessibility, |
| 4852 | type_name_cstr, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 4853 | tag_decl_kind, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 4854 | class_language); |
| 4855 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4856 | } |
| 4857 | |
| 4858 | // Store a forward declaration to this class type in case any |
| 4859 | // parameters in any class methods need it for the clang |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 4860 | // types for function prototypes. |
| 4861 | LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 4862 | type_sp.reset (new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4863 | this, |
| 4864 | type_name_const_str, |
| 4865 | byte_size, |
| 4866 | NULL, |
| 4867 | LLDB_INVALID_UID, |
| 4868 | Type::eEncodingIsUID, |
| 4869 | &decl, |
| 4870 | clang_type, |
| 4871 | Type::eResolveStateForward)); |
| 4872 | |
| 4873 | |
| 4874 | // Add our type to the unique type map so we don't |
| 4875 | // end up creating many copies of the same type over |
| 4876 | // and over in the ASTContext for our module |
| 4877 | unique_ast_entry.m_type_sp = type_sp; |
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 4878 | unique_ast_entry.m_symfile = this; |
| 4879 | unique_ast_entry.m_cu = dwarf_cu; |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4880 | unique_ast_entry.m_die = die; |
| 4881 | unique_ast_entry.m_declaration = decl; |
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 4882 | GetUniqueDWARFASTTypeMap().Insert (type_name_const_str, |
| 4883 | unique_ast_entry); |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4884 | |
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 4885 | if (!is_forward_declaration) |
| 4886 | { |
| 4887 | if (die->HasChildren() == false) |
| 4888 | { |
| 4889 | // No children for this struct/union/class, lets finish it |
| 4890 | ast.StartTagDeclarationDefinition (clang_type); |
| 4891 | ast.CompleteTagDeclarationDefinition (clang_type); |
| 4892 | } |
| 4893 | else if (clang_type_was_created) |
| 4894 | { |
| 4895 | // Leave this as a forward declaration until we need |
| 4896 | // to know the details of the type. lldb_private::Type |
| 4897 | // will automatically call the SymbolFile virtual function |
| 4898 | // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)" |
| 4899 | // When the definition needs to be defined. |
| 4900 | m_forward_decl_die_to_clang_type[die] = clang_type; |
| 4901 | m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die; |
| 4902 | ClangASTContext::SetHasExternalStorage (clang_type, true); |
| 4903 | } |
| Greg Clayton | c615ce4 | 2010-11-09 04:42:43 +0000 | [diff] [blame] | 4904 | } |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4905 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4906 | } |
| 4907 | break; |
| 4908 | |
| 4909 | case DW_TAG_enumeration_type: |
| 4910 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4911 | // Set a bit that lets us know that we are currently parsing this |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4912 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4913 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4914 | lldb::user_id_t encoding_uid = DW_INVALID_OFFSET; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4915 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4916 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4917 | if (num_attributes > 0) |
| 4918 | { |
| 4919 | uint32_t i; |
| 4920 | |
| 4921 | for (i=0; i<num_attributes; ++i) |
| 4922 | { |
| 4923 | attr = attributes.AttributeAtIndex(i); |
| 4924 | DWARFFormValue form_value; |
| 4925 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 4926 | { |
| 4927 | switch (attr) |
| 4928 | { |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 4929 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 4930 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 4931 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4932 | case DW_AT_name: |
| 4933 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 4934 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4935 | break; |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 4936 | case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; |
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 4937 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break; |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 4938 | case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
| 4939 | case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4940 | case DW_AT_allocated: |
| 4941 | case DW_AT_associated: |
| 4942 | case DW_AT_bit_stride: |
| 4943 | case DW_AT_byte_stride: |
| 4944 | case DW_AT_data_location: |
| 4945 | case DW_AT_description: |
| 4946 | case DW_AT_start_scope: |
| 4947 | case DW_AT_visibility: |
| 4948 | case DW_AT_specification: |
| 4949 | case DW_AT_abstract_origin: |
| 4950 | case DW_AT_sibling: |
| 4951 | break; |
| 4952 | } |
| 4953 | } |
| 4954 | } |
| 4955 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 4956 | DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr); |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 4957 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 4958 | clang_type_t enumerator_clang_type = NULL; |
| 4959 | clang_type = m_forward_decl_die_to_clang_type.lookup (die); |
| 4960 | if (clang_type == NULL) |
| 4961 | { |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 4962 | enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL, |
| 4963 | DW_ATE_signed, |
| 4964 | byte_size * 8); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4965 | clang_type = ast.CreateEnumerationType (type_name_cstr, |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4966 | GetClangDeclContextContainingDIE (dwarf_cu, die, NULL), |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4967 | decl, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 4968 | enumerator_clang_type); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 4969 | } |
| 4970 | else |
| 4971 | { |
| 4972 | enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type); |
| 4973 | assert (enumerator_clang_type != NULL); |
| 4974 | } |
| 4975 | |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 4976 | LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die); |
| 4977 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 4978 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 4979 | this, |
| 4980 | type_name_const_str, |
| 4981 | byte_size, |
| 4982 | NULL, |
| 4983 | encoding_uid, |
| 4984 | Type::eEncodingIsUID, |
| 4985 | &decl, |
| 4986 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4987 | Type::eResolveStateForward)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4988 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 4989 | ast.StartTagDeclarationDefinition (clang_type); |
| 4990 | if (die->HasChildren()) |
| 4991 | { |
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 4992 | SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); |
| 4993 | ParseChildEnumerators(cu_sc, clang_type, type_sp->GetByteSize(), dwarf_cu, die); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 4994 | } |
| 4995 | ast.CompleteTagDeclarationDefinition (clang_type); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4996 | } |
| 4997 | } |
| 4998 | break; |
| 4999 | |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 5000 | case DW_TAG_inlined_subroutine: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5001 | case DW_TAG_subprogram: |
| 5002 | case DW_TAG_subroutine_type: |
| 5003 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5004 | // Set a bit that lets us know that we are currently parsing this |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5005 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5006 | |
| 5007 | const char *mangled = NULL; |
| 5008 | dw_offset_t type_die_offset = DW_INVALID_OFFSET; |
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 5009 | bool is_variadic = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5010 | bool is_inline = false; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5011 | bool is_static = false; |
| 5012 | bool is_virtual = false; |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 5013 | bool is_explicit = false; |
| Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 5014 | bool is_artificial = false; |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5015 | dw_offset_t specification_die_offset = DW_INVALID_OFFSET; |
| 5016 | dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5017 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5018 | unsigned type_quals = 0; |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 5019 | clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5020 | |
| 5021 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5022 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5023 | if (num_attributes > 0) |
| 5024 | { |
| 5025 | uint32_t i; |
| 5026 | for (i=0; i<num_attributes; ++i) |
| 5027 | { |
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 5028 | attr = attributes.AttributeAtIndex(i); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5029 | DWARFFormValue form_value; |
| 5030 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 5031 | { |
| 5032 | switch (attr) |
| 5033 | { |
| 5034 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 5035 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 5036 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 5037 | case DW_AT_name: |
| 5038 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5039 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5040 | break; |
| 5041 | |
| 5042 | case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break; |
| 5043 | case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break; |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 5044 | case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 5045 | case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5046 | case DW_AT_inline: is_inline = form_value.Unsigned() != 0; break; |
| 5047 | case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break; |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 5048 | case DW_AT_explicit: is_explicit = form_value.Unsigned() != 0; break; |
| Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 5049 | case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break; |
| 5050 | |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 5051 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5052 | case DW_AT_external: |
| 5053 | if (form_value.Unsigned()) |
| 5054 | { |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 5055 | if (storage == clang::SC_None) |
| 5056 | storage = clang::SC_Extern; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5057 | else |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 5058 | storage = clang::SC_PrivateExtern; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5059 | } |
| 5060 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5061 | |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5062 | case DW_AT_specification: |
| 5063 | specification_die_offset = form_value.Reference(dwarf_cu); |
| 5064 | break; |
| 5065 | |
| 5066 | case DW_AT_abstract_origin: |
| 5067 | abstract_origin_die_offset = form_value.Reference(dwarf_cu); |
| 5068 | break; |
| 5069 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5070 | case DW_AT_allocated: |
| 5071 | case DW_AT_associated: |
| 5072 | case DW_AT_address_class: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5073 | case DW_AT_calling_convention: |
| 5074 | case DW_AT_data_location: |
| 5075 | case DW_AT_elemental: |
| 5076 | case DW_AT_entry_pc: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5077 | case DW_AT_frame_base: |
| 5078 | case DW_AT_high_pc: |
| 5079 | case DW_AT_low_pc: |
| 5080 | case DW_AT_object_pointer: |
| 5081 | case DW_AT_prototyped: |
| 5082 | case DW_AT_pure: |
| 5083 | case DW_AT_ranges: |
| 5084 | case DW_AT_recursive: |
| 5085 | case DW_AT_return_addr: |
| 5086 | case DW_AT_segment: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5087 | case DW_AT_start_scope: |
| 5088 | case DW_AT_static_link: |
| 5089 | case DW_AT_trampoline: |
| 5090 | case DW_AT_visibility: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5091 | case DW_AT_vtable_elem_location: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5092 | case DW_AT_description: |
| 5093 | case DW_AT_sibling: |
| 5094 | break; |
| 5095 | } |
| 5096 | } |
| 5097 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5098 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5099 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5100 | DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr); |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 5101 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5102 | clang_type_t return_clang_type = NULL; |
| 5103 | Type *func_type = NULL; |
| 5104 | |
| 5105 | if (type_die_offset != DW_INVALID_OFFSET) |
| 5106 | func_type = ResolveTypeUID(type_die_offset); |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 5107 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5108 | if (func_type) |
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 5109 | return_clang_type = func_type->GetClangForwardType(); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5110 | else |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5111 | return_clang_type = ast.GetBuiltInType_void(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5112 | |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 5113 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5114 | std::vector<clang_type_t> function_param_types; |
| 5115 | std::vector<clang::ParmVarDecl*> function_param_decls; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5116 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5117 | // Parse the function children for the parameters |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 5118 | |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 5119 | const DWARFDebugInfoEntry *decl_ctx_die = NULL; |
| 5120 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die); |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 5121 | const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind(); |
| 5122 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5123 | const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind); |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 5124 | // Start off static. This will be set to false in ParseChildParameters(...) |
| 5125 | // if we find a "this" paramters as the first parameter |
| 5126 | if (is_cxx_method) |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 5127 | is_static = true; |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 5128 | ClangASTContext::TemplateParameterInfos template_param_infos; |
| 5129 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5130 | if (die->HasChildren()) |
| 5131 | { |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5132 | bool skip_artificial = true; |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5133 | ParseChildParameters (sc, |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 5134 | containing_decl_ctx, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5135 | dwarf_cu, |
| 5136 | die, |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 5137 | skip_artificial, |
| 5138 | is_static, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5139 | type_list, |
| 5140 | function_param_types, |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 5141 | function_param_decls, |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 5142 | type_quals, |
| 5143 | template_param_infos); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5144 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5145 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5146 | // clang_type will get the function prototype clang type after this call |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5147 | clang_type = ast.CreateFunctionType (return_clang_type, |
| 5148 | &function_param_types[0], |
| 5149 | function_param_types.size(), |
| 5150 | is_variadic, |
| 5151 | type_quals); |
| 5152 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5153 | if (type_name_cstr) |
| 5154 | { |
| 5155 | bool type_handled = false; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5156 | if (tag == DW_TAG_subprogram) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5157 | { |
| Greg Clayton | 7c81042 | 2012-01-18 23:40:49 +0000 | [diff] [blame] | 5158 | ConstString class_name; |
| Greg Clayton | e42ae84 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 5159 | ConstString class_name_no_category; |
| 5160 | if (ObjCLanguageRuntime::ParseMethodName (type_name_cstr, &class_name, NULL, NULL, &class_name_no_category)) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5161 | { |
| Greg Clayton | e42ae84 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 5162 | // Use the class name with no category if there is one |
| 5163 | if (class_name_no_category) |
| 5164 | class_name = class_name_no_category; |
| 5165 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5166 | SymbolContext empty_sc; |
| 5167 | clang_type_t class_opaque_type = NULL; |
| Greg Clayton | 7c81042 | 2012-01-18 23:40:49 +0000 | [diff] [blame] | 5168 | if (class_name) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5169 | { |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5170 | TypeList types; |
| Greg Clayton | 278a16b | 2012-01-19 00:52:59 +0000 | [diff] [blame] | 5171 | TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false)); |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5172 | |
| 5173 | if (complete_objc_class_type_sp) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5174 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5175 | clang_type_t type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType(); |
| 5176 | if (ClangASTContext::IsObjCClassType (type_clang_forward_type)) |
| 5177 | class_opaque_type = type_clang_forward_type; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5178 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5179 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5180 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5181 | if (class_opaque_type) |
| 5182 | { |
| 5183 | // If accessibility isn't set to anything valid, assume public for |
| 5184 | // now... |
| 5185 | if (accessibility == eAccessNone) |
| 5186 | accessibility = eAccessPublic; |
| 5187 | |
| 5188 | clang::ObjCMethodDecl *objc_method_decl; |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5189 | objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type, |
| 5190 | type_name_cstr, |
| 5191 | clang_type, |
| 5192 | accessibility); |
| Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 5193 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5194 | type_handled = objc_method_decl != NULL; |
| 5195 | } |
| 5196 | } |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 5197 | else if (is_cxx_method) |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5198 | { |
| 5199 | // Look at the parent of this DIE and see if is is |
| 5200 | // a class or struct and see if this is actually a |
| 5201 | // C++ method |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 5202 | Type *class_type = ResolveType (dwarf_cu, decl_ctx_die); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5203 | if (class_type) |
| 5204 | { |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5205 | if (specification_die_offset != DW_INVALID_OFFSET) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5206 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 5207 | // We have a specification which we are going to base our function |
| 5208 | // prototype off of, so we need this type to be completed so that the |
| 5209 | // m_die_to_decl_ctx for the method in the specification has a valid |
| 5210 | // clang decl context. |
| Greg Clayton | 8eb732e | 2011-12-13 04:34:06 +0000 | [diff] [blame] | 5211 | class_type->GetClangForwardType(); |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5212 | // If we have a specification, then the function type should have been |
| 5213 | // made with the specification and not with this die. |
| 5214 | DWARFCompileUnitSP spec_cu_sp; |
| 5215 | const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp); |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 5216 | clang::DeclContext *spec_clang_decl_ctx = GetCachedClangDeclContextForDIE (spec_die); |
| 5217 | if (spec_clang_decl_ctx) |
| 5218 | { |
| 5219 | LinkDeclContextToDIE(spec_clang_decl_ctx, die); |
| 5220 | } |
| 5221 | else |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 5222 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5223 | GetObjectFile()->GetModule()->ReportWarning ("0x%8.8llx: DW_AT_specification(0x%8.8x) has no decl\n", |
| 5224 | MakeUserID(die->GetOffset()), |
| 5225 | specification_die_offset); |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 5226 | } |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5227 | type_handled = true; |
| 5228 | } |
| 5229 | else if (abstract_origin_die_offset != DW_INVALID_OFFSET) |
| 5230 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 5231 | // We have a specification which we are going to base our function |
| 5232 | // prototype off of, so we need this type to be completed so that the |
| 5233 | // m_die_to_decl_ctx for the method in the abstract origin has a valid |
| 5234 | // clang decl context. |
| Greg Clayton | 8eb732e | 2011-12-13 04:34:06 +0000 | [diff] [blame] | 5235 | class_type->GetClangForwardType(); |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 5236 | |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5237 | DWARFCompileUnitSP abs_cu_sp; |
| 5238 | const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp); |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 5239 | clang::DeclContext *abs_clang_decl_ctx = GetCachedClangDeclContextForDIE (abs_die); |
| 5240 | if (abs_clang_decl_ctx) |
| 5241 | { |
| 5242 | LinkDeclContextToDIE (abs_clang_decl_ctx, die); |
| 5243 | } |
| 5244 | else |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 5245 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5246 | GetObjectFile()->GetModule()->ReportWarning ("0x%8.8llx: DW_AT_abstract_origin(0x%8.8x) has no decl\n", |
| 5247 | MakeUserID(die->GetOffset()), |
| 5248 | abstract_origin_die_offset); |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 5249 | } |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5250 | type_handled = true; |
| 5251 | } |
| 5252 | else |
| 5253 | { |
| 5254 | clang_type_t class_opaque_type = class_type->GetClangForwardType(); |
| 5255 | if (ClangASTContext::IsCXXClassType (class_opaque_type)) |
| Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 5256 | { |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 5257 | if (ClangASTContext::IsBeingDefined (class_opaque_type)) |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5258 | { |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 5259 | // Neither GCC 4.2 nor clang++ currently set a valid accessibility |
| 5260 | // in the DWARF for C++ methods... Default to public for now... |
| 5261 | if (accessibility == eAccessNone) |
| 5262 | accessibility = eAccessPublic; |
| 5263 | |
| 5264 | if (!is_static && !die->HasChildren()) |
| 5265 | { |
| 5266 | // We have a C++ member function with no children (this pointer!) |
| 5267 | // and clang will get mad if we try and make a function that isn't |
| 5268 | // well formed in the DWARF, so we will just skip it... |
| 5269 | type_handled = true; |
| 5270 | } |
| 5271 | else |
| 5272 | { |
| 5273 | clang::CXXMethodDecl *cxx_method_decl; |
| 5274 | // REMOVE THE CRASH DESCRIPTION BELOW |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5275 | Host::SetCrashDescriptionWithFormat ("SymbolFileDWARF::ParseType() is adding a method %s to class %s in DIE 0x%8.8llx from %s/%s", |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 5276 | type_name_cstr, |
| 5277 | class_type->GetName().GetCString(), |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5278 | MakeUserID(die->GetOffset()), |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 5279 | m_obj_file->GetFileSpec().GetDirectory().GetCString(), |
| 5280 | m_obj_file->GetFileSpec().GetFilename().GetCString()); |
| 5281 | |
| Sean Callanan | c1b732d | 2011-11-01 18:07:13 +0000 | [diff] [blame] | 5282 | const bool is_attr_used = false; |
| 5283 | |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 5284 | cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type, |
| 5285 | type_name_cstr, |
| 5286 | clang_type, |
| 5287 | accessibility, |
| 5288 | is_virtual, |
| 5289 | is_static, |
| 5290 | is_inline, |
| Sean Callanan | c1b732d | 2011-11-01 18:07:13 +0000 | [diff] [blame] | 5291 | is_explicit, |
| Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 5292 | is_attr_used, |
| 5293 | is_artificial); |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 5294 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die); |
| 5295 | |
| Greg Clayton | f49e65a | 2011-11-10 18:31:53 +0000 | [diff] [blame] | 5296 | Host::SetCrashDescription (NULL); |
| 5297 | |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 5298 | type_handled = cxx_method_decl != NULL; |
| 5299 | } |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5300 | } |
| 5301 | else |
| 5302 | { |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 5303 | // We were asked to parse the type for a method in a class, yet the |
| 5304 | // class hasn't been asked to complete itself through the |
| 5305 | // clang::ExternalASTSource protocol, so we need to just have the |
| 5306 | // class complete itself and do things the right way, then our |
| 5307 | // DIE should then have an entry in the m_die_to_type map. First |
| 5308 | // we need to modify the m_die_to_type so it doesn't think we are |
| 5309 | // trying to parse this DIE anymore... |
| 5310 | m_die_to_type[die] = NULL; |
| 5311 | |
| 5312 | // Now we get the full type to force our class type to complete itself |
| 5313 | // using the clang::ExternalASTSource protocol which will parse all |
| 5314 | // base classes and all methods (including the method for this DIE). |
| 5315 | class_type->GetClangFullType(); |
| Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 5316 | |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 5317 | // The type for this DIE should have been filled in the function call above |
| 5318 | type_ptr = m_die_to_type[die]; |
| 5319 | if (type_ptr) |
| 5320 | { |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 5321 | type_sp = type_ptr->shared_from_this(); |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 5322 | break; |
| 5323 | } |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5324 | } |
| Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 5325 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5326 | } |
| 5327 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5328 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5329 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5330 | |
| 5331 | if (!type_handled) |
| 5332 | { |
| 5333 | // We just have a function that isn't part of a class |
| Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 5334 | clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (containing_decl_ctx, |
| 5335 | type_name_cstr, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5336 | clang_type, |
| 5337 | storage, |
| 5338 | is_inline); |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 5339 | |
| 5340 | // if (template_param_infos.GetSize() > 0) |
| 5341 | // { |
| 5342 | // clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx, |
| 5343 | // function_decl, |
| 5344 | // type_name_cstr, |
| 5345 | // template_param_infos); |
| 5346 | // |
| 5347 | // ast.CreateFunctionTemplateSpecializationInfo (function_decl, |
| 5348 | // func_template_decl, |
| 5349 | // template_param_infos); |
| 5350 | // } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5351 | // Add the decl to our DIE to decl context map |
| 5352 | assert (function_decl); |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 5353 | LinkDeclContextToDIE(function_decl, die); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5354 | if (!function_param_decls.empty()) |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5355 | ast.SetFunctionParameters (function_decl, |
| 5356 | &function_param_decls.front(), |
| 5357 | function_param_decls.size()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5358 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5359 | } |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5360 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5361 | this, |
| 5362 | type_name_const_str, |
| 5363 | 0, |
| 5364 | NULL, |
| 5365 | LLDB_INVALID_UID, |
| 5366 | Type::eEncodingIsUID, |
| 5367 | &decl, |
| 5368 | clang_type, |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5369 | Type::eResolveStateFull)); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5370 | assert(type_sp.get()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5371 | } |
| 5372 | break; |
| 5373 | |
| 5374 | case DW_TAG_array_type: |
| 5375 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5376 | // Set a bit that lets us know that we are currently parsing this |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5377 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5378 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5379 | lldb::user_id_t type_die_offset = DW_INVALID_OFFSET; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5380 | int64_t first_index = 0; |
| 5381 | uint32_t byte_stride = 0; |
| 5382 | uint32_t bit_stride = 0; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5383 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5384 | |
| 5385 | if (num_attributes > 0) |
| 5386 | { |
| 5387 | uint32_t i; |
| 5388 | for (i=0; i<num_attributes; ++i) |
| 5389 | { |
| 5390 | attr = attributes.AttributeAtIndex(i); |
| 5391 | DWARFFormValue form_value; |
| 5392 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 5393 | { |
| 5394 | switch (attr) |
| 5395 | { |
| 5396 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 5397 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 5398 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 5399 | case DW_AT_name: |
| 5400 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5401 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5402 | break; |
| 5403 | |
| 5404 | case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break; |
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 5405 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5406 | case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break; |
| 5407 | case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break; |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 5408 | case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 5409 | case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5410 | case DW_AT_allocated: |
| 5411 | case DW_AT_associated: |
| 5412 | case DW_AT_data_location: |
| 5413 | case DW_AT_description: |
| 5414 | case DW_AT_ordering: |
| 5415 | case DW_AT_start_scope: |
| 5416 | case DW_AT_visibility: |
| 5417 | case DW_AT_specification: |
| 5418 | case DW_AT_abstract_origin: |
| 5419 | case DW_AT_sibling: |
| 5420 | break; |
| 5421 | } |
| 5422 | } |
| 5423 | } |
| 5424 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5425 | DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr); |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 5426 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5427 | Type *element_type = ResolveTypeUID(type_die_offset); |
| 5428 | |
| 5429 | if (element_type) |
| 5430 | { |
| 5431 | std::vector<uint64_t> element_orders; |
| 5432 | ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride); |
| Greg Clayton | a134cc1 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 5433 | // We have an array that claims to have no members, lets give it at least one member... |
| 5434 | if (element_orders.empty()) |
| 5435 | element_orders.push_back (1); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5436 | if (byte_stride == 0 && bit_stride == 0) |
| 5437 | byte_stride = element_type->GetByteSize(); |
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 5438 | clang_type_t array_element_type = element_type->GetClangForwardType(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5439 | uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride; |
| 5440 | uint64_t num_elements = 0; |
| 5441 | std::vector<uint64_t>::const_reverse_iterator pos; |
| 5442 | std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend(); |
| 5443 | for (pos = element_orders.rbegin(); pos != end; ++pos) |
| 5444 | { |
| 5445 | num_elements = *pos; |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5446 | clang_type = ast.CreateArrayType (array_element_type, |
| 5447 | num_elements, |
| 5448 | num_elements * array_element_bit_stride); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5449 | array_element_type = clang_type; |
| 5450 | array_element_bit_stride = array_element_bit_stride * num_elements; |
| 5451 | } |
| 5452 | ConstString empty_name; |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5453 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5454 | this, |
| 5455 | empty_name, |
| 5456 | array_element_bit_stride / 8, |
| 5457 | NULL, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5458 | type_die_offset, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5459 | Type::eEncodingIsUID, |
| 5460 | &decl, |
| 5461 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5462 | Type::eResolveStateFull)); |
| 5463 | type_sp->SetEncodingType (element_type); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5464 | } |
| 5465 | } |
| 5466 | } |
| 5467 | break; |
| 5468 | |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 5469 | case DW_TAG_ptr_to_member_type: |
| 5470 | { |
| 5471 | dw_offset_t type_die_offset = DW_INVALID_OFFSET; |
| 5472 | dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET; |
| 5473 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5474 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 5475 | |
| 5476 | if (num_attributes > 0) { |
| 5477 | uint32_t i; |
| 5478 | for (i=0; i<num_attributes; ++i) |
| 5479 | { |
| 5480 | attr = attributes.AttributeAtIndex(i); |
| 5481 | DWARFFormValue form_value; |
| 5482 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 5483 | { |
| 5484 | switch (attr) |
| 5485 | { |
| 5486 | case DW_AT_type: |
| 5487 | type_die_offset = form_value.Reference(dwarf_cu); break; |
| 5488 | case DW_AT_containing_type: |
| 5489 | containing_type_die_offset = form_value.Reference(dwarf_cu); break; |
| 5490 | } |
| 5491 | } |
| 5492 | } |
| 5493 | |
| 5494 | Type *pointee_type = ResolveTypeUID(type_die_offset); |
| 5495 | Type *class_type = ResolveTypeUID(containing_type_die_offset); |
| 5496 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5497 | clang_type_t pointee_clang_type = pointee_type->GetClangForwardType(); |
| 5498 | clang_type_t class_clang_type = class_type->GetClangLayoutType(); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 5499 | |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5500 | clang_type = ast.CreateMemberPointerType(pointee_clang_type, |
| 5501 | class_clang_type); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 5502 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5503 | byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(), |
| 5504 | clang_type) / 8; |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 5505 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5506 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5507 | this, |
| 5508 | type_name_const_str, |
| 5509 | byte_size, |
| 5510 | NULL, |
| 5511 | LLDB_INVALID_UID, |
| 5512 | Type::eEncodingIsUID, |
| 5513 | NULL, |
| 5514 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5515 | Type::eResolveStateForward)); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 5516 | } |
| 5517 | |
| 5518 | break; |
| 5519 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5520 | default: |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 5521 | assert(false && "Unhandled type tag!"); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5522 | break; |
| 5523 | } |
| 5524 | |
| 5525 | if (type_sp.get()) |
| 5526 | { |
| 5527 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); |
| 5528 | dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
| 5529 | |
| 5530 | SymbolContextScope * symbol_context_scope = NULL; |
| 5531 | if (sc_parent_tag == DW_TAG_compile_unit) |
| 5532 | { |
| 5533 | symbol_context_scope = sc.comp_unit; |
| 5534 | } |
| 5535 | else if (sc.function != NULL) |
| 5536 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5537 | symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5538 | if (symbol_context_scope == NULL) |
| 5539 | symbol_context_scope = sc.function; |
| 5540 | } |
| 5541 | |
| 5542 | if (symbol_context_scope != NULL) |
| 5543 | { |
| 5544 | type_sp->SetSymbolContextScope(symbol_context_scope); |
| 5545 | } |
| 5546 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5547 | // We are ready to put this type into the uniqued list up at the module level |
| 5548 | type_list->Insert (type_sp); |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 5549 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5550 | m_die_to_type[die] = type_sp.get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5551 | } |
| 5552 | } |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5553 | else if (type_ptr != DIE_IS_BEING_PARSED) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5554 | { |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 5555 | type_sp = type_ptr->shared_from_this(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5556 | } |
| 5557 | } |
| 5558 | return type_sp; |
| 5559 | } |
| 5560 | |
| 5561 | size_t |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5562 | SymbolFileDWARF::ParseTypes |
| 5563 | ( |
| 5564 | const SymbolContext& sc, |
| 5565 | DWARFCompileUnit* dwarf_cu, |
| 5566 | const DWARFDebugInfoEntry *die, |
| 5567 | bool parse_siblings, |
| 5568 | bool parse_children |
| 5569 | ) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5570 | { |
| 5571 | size_t types_added = 0; |
| 5572 | while (die != NULL) |
| 5573 | { |
| 5574 | bool type_is_new = false; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5575 | if (ParseType(sc, dwarf_cu, die, &type_is_new).get()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5576 | { |
| 5577 | if (type_is_new) |
| 5578 | ++types_added; |
| 5579 | } |
| 5580 | |
| 5581 | if (parse_children && die->HasChildren()) |
| 5582 | { |
| 5583 | if (die->Tag() == DW_TAG_subprogram) |
| 5584 | { |
| 5585 | SymbolContext child_sc(sc); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5586 | child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5587 | types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true); |
| 5588 | } |
| 5589 | else |
| 5590 | types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true); |
| 5591 | } |
| 5592 | |
| 5593 | if (parse_siblings) |
| 5594 | die = die->GetSibling(); |
| 5595 | else |
| 5596 | die = NULL; |
| 5597 | } |
| 5598 | return types_added; |
| 5599 | } |
| 5600 | |
| 5601 | |
| 5602 | size_t |
| 5603 | SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc) |
| 5604 | { |
| 5605 | assert(sc.comp_unit && sc.function); |
| 5606 | size_t functions_added = 0; |
| 5607 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID()); |
| 5608 | if (dwarf_cu) |
| 5609 | { |
| 5610 | dw_offset_t function_die_offset = sc.function->GetID(); |
| 5611 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset); |
| 5612 | if (function_die) |
| 5613 | { |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 5614 | ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5615 | } |
| 5616 | } |
| 5617 | |
| 5618 | return functions_added; |
| 5619 | } |
| 5620 | |
| 5621 | |
| 5622 | size_t |
| 5623 | SymbolFileDWARF::ParseTypes (const SymbolContext &sc) |
| 5624 | { |
| 5625 | // At least a compile unit must be valid |
| 5626 | assert(sc.comp_unit); |
| 5627 | size_t types_added = 0; |
| 5628 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID()); |
| 5629 | if (dwarf_cu) |
| 5630 | { |
| 5631 | if (sc.function) |
| 5632 | { |
| 5633 | dw_offset_t function_die_offset = sc.function->GetID(); |
| 5634 | const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset); |
| 5635 | if (func_die && func_die->HasChildren()) |
| 5636 | { |
| 5637 | types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true); |
| 5638 | } |
| 5639 | } |
| 5640 | else |
| 5641 | { |
| 5642 | const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE(); |
| 5643 | if (dwarf_cu_die && dwarf_cu_die->HasChildren()) |
| 5644 | { |
| 5645 | types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true); |
| 5646 | } |
| 5647 | } |
| 5648 | } |
| 5649 | |
| 5650 | return types_added; |
| 5651 | } |
| 5652 | |
| 5653 | size_t |
| 5654 | SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc) |
| 5655 | { |
| 5656 | if (sc.comp_unit != NULL) |
| 5657 | { |
| Greg Clayton | 4b3dc10 | 2010-11-01 20:32:12 +0000 | [diff] [blame] | 5658 | DWARFDebugInfo* info = DebugInfo(); |
| 5659 | if (info == NULL) |
| 5660 | return 0; |
| 5661 | |
| 5662 | uint32_t cu_idx = UINT32_MAX; |
| 5663 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID(), &cu_idx).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5664 | |
| 5665 | if (dwarf_cu == NULL) |
| 5666 | return 0; |
| 5667 | |
| 5668 | if (sc.function) |
| 5669 | { |
| 5670 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID()); |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 5671 | |
| 5672 | dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, DW_INVALID_ADDRESS); |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5673 | if (func_lo_pc != DW_INVALID_ADDRESS) |
| 5674 | { |
| 5675 | const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 5676 | |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5677 | // Let all blocks know they have parse all their variables |
| 5678 | sc.function->GetBlock (false).SetDidParseVariables (true, true); |
| 5679 | return num_variables; |
| 5680 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5681 | } |
| 5682 | else if (sc.comp_unit) |
| 5683 | { |
| 5684 | uint32_t vars_added = 0; |
| 5685 | VariableListSP variables (sc.comp_unit->GetVariableList(false)); |
| 5686 | |
| 5687 | if (variables.get() == NULL) |
| 5688 | { |
| 5689 | variables.reset(new VariableList()); |
| 5690 | sc.comp_unit->SetVariableList(variables); |
| 5691 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 5692 | DWARFCompileUnit* match_dwarf_cu = NULL; |
| 5693 | const DWARFDebugInfoEntry* die = NULL; |
| 5694 | DIEArray die_offsets; |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 5695 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5696 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 5697 | if (m_apple_names_ap.get()) |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5698 | { |
| 5699 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 5700 | if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(), |
| 5701 | dwarf_cu->GetNextCompileUnitOffset(), |
| 5702 | hash_data_array)) |
| 5703 | { |
| 5704 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| 5705 | } |
| 5706 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5707 | } |
| 5708 | else |
| 5709 | { |
| 5710 | // Index if we already haven't to make sure the compile units |
| 5711 | // get indexed and make their global DIE index list |
| 5712 | if (!m_indexed) |
| 5713 | Index (); |
| 5714 | |
| 5715 | m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(), |
| 5716 | dwarf_cu->GetNextCompileUnitOffset(), |
| 5717 | die_offsets); |
| 5718 | } |
| 5719 | |
| 5720 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 5721 | if (num_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5722 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 5723 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 5724 | for (size_t i=0; i<num_matches; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5725 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 5726 | const dw_offset_t die_offset = die_offsets[i]; |
| 5727 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 5728 | if (die) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 5729 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 5730 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS)); |
| 5731 | if (var_sp) |
| 5732 | { |
| 5733 | variables->AddVariableIfUnique (var_sp); |
| 5734 | ++vars_added; |
| 5735 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 5736 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 5737 | else |
| 5738 | { |
| 5739 | if (m_using_apple_tables) |
| 5740 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5741 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x)\n", die_offset); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 5742 | } |
| 5743 | } |
| 5744 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5745 | } |
| 5746 | } |
| 5747 | } |
| 5748 | return vars_added; |
| 5749 | } |
| 5750 | } |
| 5751 | return 0; |
| 5752 | } |
| 5753 | |
| 5754 | |
| 5755 | VariableSP |
| 5756 | SymbolFileDWARF::ParseVariableDIE |
| 5757 | ( |
| 5758 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5759 | DWARFCompileUnit* dwarf_cu, |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 5760 | const DWARFDebugInfoEntry *die, |
| 5761 | const lldb::addr_t func_low_pc |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5762 | ) |
| 5763 | { |
| 5764 | |
| Greg Clayton | 83c5cd9 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 5765 | VariableSP var_sp (m_die_to_variable_sp[die]); |
| 5766 | if (var_sp) |
| 5767 | return var_sp; // Already been parsed! |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5768 | |
| 5769 | const dw_tag_t tag = die->Tag(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5770 | |
| 5771 | if ((tag == DW_TAG_variable) || |
| 5772 | (tag == DW_TAG_constant) || |
| 5773 | (tag == DW_TAG_formal_parameter && sc.function)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5774 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5775 | DWARFDebugInfoEntry::Attributes attributes; |
| 5776 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| 5777 | if (num_attributes > 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5778 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5779 | const char *name = NULL; |
| 5780 | const char *mangled = NULL; |
| 5781 | Declaration decl; |
| 5782 | uint32_t i; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5783 | lldb::user_id_t type_uid = LLDB_INVALID_UID; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5784 | DWARFExpression location; |
| 5785 | bool is_external = false; |
| 5786 | bool is_artificial = false; |
| 5787 | bool location_is_const_value_data = false; |
| 5788 | AccessType accessibility = eAccessNone; |
| 5789 | |
| 5790 | for (i=0; i<num_attributes; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5791 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5792 | dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 5793 | DWARFFormValue form_value; |
| 5794 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5795 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5796 | switch (attr) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5797 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5798 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 5799 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 5800 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 5801 | case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; |
| 5802 | case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5803 | case DW_AT_type: type_uid = form_value.Reference(dwarf_cu); break; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5804 | case DW_AT_external: is_external = form_value.Unsigned() != 0; break; |
| 5805 | case DW_AT_const_value: |
| 5806 | location_is_const_value_data = true; |
| 5807 | // Fall through... |
| 5808 | case DW_AT_location: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5809 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5810 | if (form_value.BlockData()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5811 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5812 | const DataExtractor& debug_info_data = get_debug_info_data(); |
| 5813 | |
| 5814 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 5815 | uint32_t block_length = form_value.Unsigned(); |
| 5816 | location.SetOpcodeData(get_debug_info_data(), block_offset, block_length); |
| 5817 | } |
| 5818 | else |
| 5819 | { |
| 5820 | const DataExtractor& debug_loc_data = get_debug_loc_data(); |
| 5821 | const dw_offset_t debug_loc_offset = form_value.Unsigned(); |
| 5822 | |
| 5823 | size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset); |
| 5824 | if (loc_list_length > 0) |
| 5825 | { |
| 5826 | location.SetOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length); |
| 5827 | assert (func_low_pc != LLDB_INVALID_ADDRESS); |
| 5828 | location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress()); |
| 5829 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5830 | } |
| 5831 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5832 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5833 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5834 | case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break; |
| 5835 | case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
| 5836 | case DW_AT_declaration: |
| 5837 | case DW_AT_description: |
| 5838 | case DW_AT_endianity: |
| 5839 | case DW_AT_segment: |
| 5840 | case DW_AT_start_scope: |
| 5841 | case DW_AT_visibility: |
| 5842 | default: |
| 5843 | case DW_AT_abstract_origin: |
| 5844 | case DW_AT_sibling: |
| 5845 | case DW_AT_specification: |
| 5846 | break; |
| 5847 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5848 | } |
| 5849 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5850 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5851 | if (location.IsValid()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5852 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5853 | ValueType scope = eValueTypeInvalid; |
| 5854 | |
| 5855 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); |
| 5856 | dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5857 | SymbolContextScope * symbol_context_scope = NULL; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5858 | |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5859 | // DWARF doesn't specify if a DW_TAG_variable is a local, global |
| 5860 | // or static variable, so we have to do a little digging by |
| 5861 | // looking at the location of a varaible to see if it contains |
| 5862 | // a DW_OP_addr opcode _somewhere_ in the definition. I say |
| 5863 | // somewhere because clang likes to combine small global variables |
| 5864 | // into the same symbol and have locations like: |
| 5865 | // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus |
| 5866 | // So if we don't have a DW_TAG_formal_parameter, we can look at |
| 5867 | // the location to see if it contains a DW_OP_addr opcode, and |
| 5868 | // then we can correctly classify our variables. |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5869 | if (tag == DW_TAG_formal_parameter) |
| 5870 | scope = eValueTypeVariableArgument; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5871 | else |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5872 | { |
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 5873 | bool op_error = false; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5874 | // Check if the location has a DW_OP_addr with any address value... |
| 5875 | addr_t location_has_op_addr = false; |
| 5876 | if (!location_is_const_value_data) |
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 5877 | { |
| 5878 | location_has_op_addr = location.LocationContains_DW_OP_addr (LLDB_INVALID_ADDRESS, op_error); |
| 5879 | if (op_error) |
| 5880 | { |
| 5881 | StreamString strm; |
| 5882 | location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL); |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5883 | GetObjectFile()->GetModule()->ReportError ("0x%8.8x: %s has an invalid location: %s", die->GetOffset(), DW_TAG_value_to_name(die->Tag()), strm.GetString().c_str()); |
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 5884 | } |
| 5885 | } |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5886 | |
| 5887 | if (location_has_op_addr) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5888 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5889 | if (is_external) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5890 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5891 | scope = eValueTypeVariableGlobal; |
| 5892 | |
| 5893 | if (m_debug_map_symfile) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5894 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5895 | // When leaving the DWARF in the .o files on darwin, |
| 5896 | // when we have a global variable that wasn't initialized, |
| 5897 | // the .o file might not have allocated a virtual |
| 5898 | // address for the global variable. In this case it will |
| 5899 | // have created a symbol for the global variable |
| 5900 | // that is undefined and external and the value will |
| 5901 | // be the byte size of the variable. When we do the |
| 5902 | // address map in SymbolFileDWARFDebugMap we rely on |
| 5903 | // having an address, we need to do some magic here |
| 5904 | // so we can get the correct address for our global |
| 5905 | // variable. The address for all of these entries |
| 5906 | // will be zero, and there will be an undefined symbol |
| 5907 | // in this object file, and the executable will have |
| 5908 | // a matching symbol with a good address. So here we |
| 5909 | // dig up the correct address and replace it in the |
| 5910 | // location for the variable, and set the variable's |
| 5911 | // symbol context scope to be that of the main executable |
| 5912 | // so the file address will resolve correctly. |
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 5913 | if (location.LocationContains_DW_OP_addr (0, op_error)) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5914 | { |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5915 | |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5916 | // we have a possible uninitialized extern global |
| 5917 | Symtab *symtab = m_obj_file->GetSymtab(); |
| 5918 | if (symtab) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5919 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5920 | ConstString const_name(name); |
| 5921 | Symbol *undefined_symbol = symtab->FindFirstSymbolWithNameAndType (const_name, |
| 5922 | eSymbolTypeUndefined, |
| 5923 | Symtab::eDebugNo, |
| 5924 | Symtab::eVisibilityExtern); |
| 5925 | |
| 5926 | if (undefined_symbol) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5927 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5928 | ObjectFile *debug_map_objfile = m_debug_map_symfile->GetObjectFile(); |
| 5929 | if (debug_map_objfile) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5930 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5931 | Symtab *debug_map_symtab = debug_map_objfile->GetSymtab(); |
| 5932 | Symbol *defined_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name, |
| 5933 | eSymbolTypeData, |
| 5934 | Symtab::eDebugYes, |
| 5935 | Symtab::eVisibilityExtern); |
| 5936 | if (defined_symbol) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5937 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5938 | const AddressRange *defined_range = defined_symbol->GetAddressRangePtr(); |
| 5939 | if (defined_range) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5940 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5941 | const addr_t defined_addr = defined_range->GetBaseAddress().GetFileAddress(); |
| 5942 | if (defined_addr != LLDB_INVALID_ADDRESS) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5943 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5944 | if (location.Update_DW_OP_addr (defined_addr)) |
| 5945 | { |
| 5946 | symbol_context_scope = defined_symbol; |
| 5947 | } |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5948 | } |
| 5949 | } |
| 5950 | } |
| 5951 | } |
| 5952 | } |
| 5953 | } |
| 5954 | } |
| 5955 | } |
| 5956 | } |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5957 | else |
| 5958 | { |
| 5959 | scope = eValueTypeVariableStatic; |
| 5960 | } |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5961 | } |
| 5962 | else |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5963 | { |
| 5964 | scope = eValueTypeVariableLocal; |
| 5965 | } |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5966 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5967 | |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5968 | if (symbol_context_scope == NULL) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5969 | { |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5970 | switch (parent_tag) |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 5971 | { |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5972 | case DW_TAG_subprogram: |
| 5973 | case DW_TAG_inlined_subroutine: |
| 5974 | case DW_TAG_lexical_block: |
| 5975 | if (sc.function) |
| 5976 | { |
| 5977 | symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); |
| 5978 | if (symbol_context_scope == NULL) |
| 5979 | symbol_context_scope = sc.function; |
| 5980 | } |
| 5981 | break; |
| 5982 | |
| 5983 | default: |
| 5984 | symbol_context_scope = sc.comp_unit; |
| 5985 | break; |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 5986 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5987 | } |
| 5988 | |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 5989 | if (symbol_context_scope) |
| 5990 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5991 | var_sp.reset (new Variable (MakeUserID(die->GetOffset()), |
| 5992 | name, |
| 5993 | mangled, |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5994 | SymbolFileTypeSP (new SymbolFileType(*this, type_uid)), |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5995 | scope, |
| 5996 | symbol_context_scope, |
| 5997 | &decl, |
| 5998 | location, |
| 5999 | is_external, |
| 6000 | is_artificial)); |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6001 | |
| 6002 | var_sp->SetLocationIsConstantValueData (location_is_const_value_data); |
| 6003 | } |
| 6004 | else |
| 6005 | { |
| 6006 | // Not ready to parse this variable yet. It might be a global |
| 6007 | // or static variable that is in a function scope and the function |
| 6008 | // in the symbol context wasn't filled in yet |
| 6009 | return var_sp; |
| 6010 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6011 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6012 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6013 | // Cache var_sp even if NULL (the variable was just a specification or |
| 6014 | // was missing vital information to be able to be displayed in the debugger |
| 6015 | // (missing location due to optimization, etc)) so we don't re-parse |
| 6016 | // this DIE over and over later... |
| 6017 | m_die_to_variable_sp[die] = var_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6018 | } |
| 6019 | return var_sp; |
| 6020 | } |
| 6021 | |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6022 | |
| 6023 | const DWARFDebugInfoEntry * |
| 6024 | SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset, |
| 6025 | dw_offset_t spec_block_die_offset, |
| 6026 | DWARFCompileUnit **result_die_cu_handle) |
| 6027 | { |
| 6028 | // Give the concrete function die specified by "func_die_offset", find the |
| 6029 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points |
| 6030 | // to "spec_block_die_offset" |
| 6031 | DWARFDebugInfo* info = DebugInfo(); |
| 6032 | |
| 6033 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle); |
| 6034 | if (die) |
| 6035 | { |
| 6036 | assert (*result_die_cu_handle); |
| 6037 | return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle); |
| 6038 | } |
| 6039 | return NULL; |
| 6040 | } |
| 6041 | |
| 6042 | |
| 6043 | const DWARFDebugInfoEntry * |
| 6044 | SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu, |
| 6045 | const DWARFDebugInfoEntry *die, |
| 6046 | dw_offset_t spec_block_die_offset, |
| 6047 | DWARFCompileUnit **result_die_cu_handle) |
| 6048 | { |
| 6049 | if (die) |
| 6050 | { |
| 6051 | switch (die->Tag()) |
| 6052 | { |
| 6053 | case DW_TAG_subprogram: |
| 6054 | case DW_TAG_inlined_subroutine: |
| 6055 | case DW_TAG_lexical_block: |
| 6056 | { |
| 6057 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset) |
| 6058 | { |
| 6059 | *result_die_cu_handle = dwarf_cu; |
| 6060 | return die; |
| 6061 | } |
| 6062 | |
| 6063 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset) |
| 6064 | { |
| 6065 | *result_die_cu_handle = dwarf_cu; |
| 6066 | return die; |
| 6067 | } |
| 6068 | } |
| 6069 | break; |
| 6070 | } |
| 6071 | |
| 6072 | // Give the concrete function die specified by "func_die_offset", find the |
| 6073 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points |
| 6074 | // to "spec_block_die_offset" |
| 6075 | for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling()) |
| 6076 | { |
| 6077 | const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu, |
| 6078 | child_die, |
| 6079 | spec_block_die_offset, |
| 6080 | result_die_cu_handle); |
| 6081 | if (result_die) |
| 6082 | return result_die; |
| 6083 | } |
| 6084 | } |
| 6085 | |
| 6086 | *result_die_cu_handle = NULL; |
| 6087 | return NULL; |
| 6088 | } |
| 6089 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6090 | size_t |
| 6091 | SymbolFileDWARF::ParseVariables |
| 6092 | ( |
| 6093 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6094 | DWARFCompileUnit* dwarf_cu, |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 6095 | const lldb::addr_t func_low_pc, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6096 | const DWARFDebugInfoEntry *orig_die, |
| 6097 | bool parse_siblings, |
| 6098 | bool parse_children, |
| 6099 | VariableList* cc_variable_list |
| 6100 | ) |
| 6101 | { |
| 6102 | if (orig_die == NULL) |
| 6103 | return 0; |
| 6104 | |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6105 | VariableListSP variable_list_sp; |
| 6106 | |
| 6107 | size_t vars_added = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6108 | const DWARFDebugInfoEntry *die = orig_die; |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6109 | while (die != NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6110 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6111 | dw_tag_t tag = die->Tag(); |
| 6112 | |
| 6113 | // Check to see if we have already parsed this variable or constant? |
| 6114 | if (m_die_to_variable_sp[die]) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6115 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6116 | if (cc_variable_list) |
| 6117 | cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6118 | } |
| 6119 | else |
| 6120 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6121 | // We haven't already parsed it, lets do that now. |
| 6122 | if ((tag == DW_TAG_variable) || |
| 6123 | (tag == DW_TAG_constant) || |
| 6124 | (tag == DW_TAG_formal_parameter && sc.function)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6125 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6126 | if (variable_list_sp.get() == NULL) |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 6127 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6128 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die); |
| 6129 | dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
| 6130 | switch (parent_tag) |
| 6131 | { |
| 6132 | case DW_TAG_compile_unit: |
| 6133 | if (sc.comp_unit != NULL) |
| 6134 | { |
| 6135 | variable_list_sp = sc.comp_unit->GetVariableList(false); |
| 6136 | if (variable_list_sp.get() == NULL) |
| 6137 | { |
| 6138 | variable_list_sp.reset(new VariableList()); |
| 6139 | sc.comp_unit->SetVariableList(variable_list_sp); |
| 6140 | } |
| 6141 | } |
| 6142 | else |
| 6143 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6144 | GetObjectFile()->GetModule()->ReportError ("parent 0x%8.8llx %s with no valid compile unit in symbol context for 0x%8.8llx %s.\n", |
| 6145 | MakeUserID(sc_parent_die->GetOffset()), |
| 6146 | DW_TAG_value_to_name (parent_tag), |
| 6147 | MakeUserID(orig_die->GetOffset()), |
| 6148 | DW_TAG_value_to_name (orig_die->Tag())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6149 | } |
| 6150 | break; |
| 6151 | |
| 6152 | case DW_TAG_subprogram: |
| 6153 | case DW_TAG_inlined_subroutine: |
| 6154 | case DW_TAG_lexical_block: |
| 6155 | if (sc.function != NULL) |
| 6156 | { |
| 6157 | // Check to see if we already have parsed the variables for the given scope |
| 6158 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6159 | Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6160 | if (block == NULL) |
| 6161 | { |
| 6162 | // This must be a specification or abstract origin with |
| 6163 | // a concrete block couterpart in the current function. We need |
| 6164 | // to find the concrete block so we can correctly add the |
| 6165 | // variable to it |
| 6166 | DWARFCompileUnit *concrete_block_die_cu = dwarf_cu; |
| 6167 | const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(), |
| 6168 | sc_parent_die->GetOffset(), |
| 6169 | &concrete_block_die_cu); |
| 6170 | if (concrete_block_die) |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6171 | block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6172 | } |
| 6173 | |
| 6174 | if (block != NULL) |
| 6175 | { |
| 6176 | const bool can_create = false; |
| 6177 | variable_list_sp = block->GetBlockVariableList (can_create); |
| 6178 | if (variable_list_sp.get() == NULL) |
| 6179 | { |
| 6180 | variable_list_sp.reset(new VariableList()); |
| 6181 | block->SetVariableList(variable_list_sp); |
| 6182 | } |
| 6183 | } |
| 6184 | } |
| 6185 | break; |
| 6186 | |
| 6187 | default: |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6188 | GetObjectFile()->GetModule()->ReportError ("didn't find appropriate parent DIE for variable list for 0x%8.8llx %s.\n", |
| 6189 | MakeUserID(orig_die->GetOffset()), |
| 6190 | DW_TAG_value_to_name (orig_die->Tag())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6191 | break; |
| 6192 | } |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 6193 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6194 | |
| 6195 | if (variable_list_sp) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6196 | { |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 6197 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc)); |
| 6198 | if (var_sp) |
| 6199 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6200 | variable_list_sp->AddVariableIfUnique (var_sp); |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 6201 | if (cc_variable_list) |
| 6202 | cc_variable_list->AddVariableIfUnique (var_sp); |
| 6203 | ++vars_added; |
| 6204 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6205 | } |
| 6206 | } |
| 6207 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6208 | |
| 6209 | bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram); |
| 6210 | |
| 6211 | if (!skip_children && parse_children && die->HasChildren()) |
| 6212 | { |
| 6213 | vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list); |
| 6214 | } |
| 6215 | |
| 6216 | if (parse_siblings) |
| 6217 | die = die->GetSibling(); |
| 6218 | else |
| 6219 | die = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6220 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6221 | return vars_added; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6222 | } |
| 6223 | |
| 6224 | //------------------------------------------------------------------ |
| 6225 | // PluginInterface protocol |
| 6226 | //------------------------------------------------------------------ |
| 6227 | const char * |
| 6228 | SymbolFileDWARF::GetPluginName() |
| 6229 | { |
| 6230 | return "SymbolFileDWARF"; |
| 6231 | } |
| 6232 | |
| 6233 | const char * |
| 6234 | SymbolFileDWARF::GetShortPluginName() |
| 6235 | { |
| 6236 | return GetPluginNameStatic(); |
| 6237 | } |
| 6238 | |
| 6239 | uint32_t |
| 6240 | SymbolFileDWARF::GetPluginVersion() |
| 6241 | { |
| 6242 | return 1; |
| 6243 | } |
| 6244 | |
| 6245 | void |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 6246 | SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl) |
| 6247 | { |
| 6248 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 6249 | clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); |
| 6250 | if (clang_type) |
| 6251 | symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); |
| 6252 | } |
| 6253 | |
| 6254 | void |
| 6255 | SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl) |
| 6256 | { |
| 6257 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 6258 | clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); |
| 6259 | if (clang_type) |
| 6260 | symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); |
| 6261 | } |
| 6262 | |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6263 | void |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 6264 | SymbolFileDWARF::DumpIndexes () |
| 6265 | { |
| 6266 | StreamFile s(stdout, false); |
| 6267 | |
| 6268 | s.Printf ("DWARF index for (%s) '%s/%s':", |
| 6269 | GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(), |
| 6270 | GetObjectFile()->GetFileSpec().GetDirectory().AsCString(), |
| 6271 | GetObjectFile()->GetFileSpec().GetFilename().AsCString()); |
| 6272 | s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s); |
| 6273 | s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s); |
| 6274 | s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s); |
| 6275 | s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s); |
| 6276 | s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s); |
| 6277 | s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s); |
| 6278 | s.Printf("\nTypes:\n"); m_type_index.Dump (&s); |
| 6279 | s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s); |
| 6280 | } |
| 6281 | |
| 6282 | void |
| 6283 | SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context, |
| 6284 | const char *name, |
| 6285 | llvm::SmallVectorImpl <clang::NamedDecl *> *results) |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6286 | { |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 6287 | DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context); |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6288 | |
| 6289 | if (iter == m_decl_ctx_to_die.end()) |
| 6290 | return; |
| 6291 | |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6292 | for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos) |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6293 | { |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6294 | const DWARFDebugInfoEntry *context_die = *pos; |
| 6295 | |
| 6296 | if (!results) |
| 6297 | return; |
| 6298 | |
| 6299 | DWARFDebugInfo* info = DebugInfo(); |
| 6300 | |
| 6301 | DIEArray die_offsets; |
| 6302 | |
| 6303 | DWARFCompileUnit* dwarf_cu = NULL; |
| 6304 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 6305 | |
| 6306 | if (m_using_apple_tables) |
| 6307 | { |
| 6308 | if (m_apple_types_ap.get()) |
| 6309 | m_apple_types_ap->FindByName (name, die_offsets); |
| 6310 | } |
| 6311 | else |
| 6312 | { |
| 6313 | if (!m_indexed) |
| 6314 | Index (); |
| 6315 | |
| 6316 | m_type_index.Find (ConstString(name), die_offsets); |
| 6317 | } |
| 6318 | |
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 6319 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6320 | |
| 6321 | if (num_matches) |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6322 | { |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6323 | for (size_t i = 0; i < num_matches; ++i) |
| 6324 | { |
| 6325 | const dw_offset_t die_offset = die_offsets[i]; |
| 6326 | die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 6327 | |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6328 | if (die->GetParent() != context_die) |
| 6329 | continue; |
| 6330 | |
| 6331 | Type *matching_type = ResolveType (dwarf_cu, die); |
| 6332 | |
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 6333 | lldb::clang_type_t type = matching_type->GetClangForwardType(); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6334 | clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type); |
| 6335 | |
| 6336 | if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr())) |
| 6337 | { |
| 6338 | clang::TagDecl *tag_decl = tag_type->getDecl(); |
| 6339 | results->push_back(tag_decl); |
| 6340 | } |
| 6341 | else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr())) |
| 6342 | { |
| 6343 | clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl(); |
| 6344 | results->push_back(typedef_decl); |
| 6345 | } |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6346 | } |
| 6347 | } |
| 6348 | } |
| 6349 | } |
| 6350 | |
| 6351 | void |
| 6352 | SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton, |
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 6353 | const clang::DeclContext *decl_context, |
| 6354 | clang::DeclarationName decl_name, |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6355 | llvm::SmallVectorImpl <clang::NamedDecl *> *results) |
| 6356 | { |
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 6357 | |
| 6358 | switch (decl_context->getDeclKind()) |
| 6359 | { |
| 6360 | case clang::Decl::Namespace: |
| 6361 | case clang::Decl::TranslationUnit: |
| 6362 | { |
| 6363 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 6364 | symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results); |
| 6365 | } |
| 6366 | break; |
| 6367 | default: |
| 6368 | break; |
| 6369 | } |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6370 | } |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 6371 | |
| 6372 | bool |
| 6373 | SymbolFileDWARF::LayoutRecordType (void *baton, |
| 6374 | const clang::RecordDecl *record_decl, |
| 6375 | uint64_t &size, |
| 6376 | uint64_t &alignment, |
| 6377 | llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, |
| 6378 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, |
| 6379 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) |
| 6380 | { |
| 6381 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 6382 | return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets); |
| 6383 | } |
| 6384 | |
| 6385 | |
| 6386 | bool |
| 6387 | SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl, |
| 6388 | uint64_t &bit_size, |
| 6389 | uint64_t &alignment, |
| 6390 | llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, |
| 6391 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, |
| 6392 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) |
| 6393 | { |
| 6394 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| 6395 | RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl); |
| 6396 | bool success = false; |
| 6397 | base_offsets.clear(); |
| 6398 | vbase_offsets.clear(); |
| 6399 | if (pos != m_record_decl_to_layout_map.end()) |
| 6400 | { |
| 6401 | bit_size = pos->second.bit_size; |
| 6402 | alignment = pos->second.alignment; |
| 6403 | field_offsets.swap(pos->second.field_offsets); |
| 6404 | m_record_decl_to_layout_map.erase(pos); |
| 6405 | success = true; |
| 6406 | } |
| 6407 | else |
| 6408 | { |
| 6409 | bit_size = 0; |
| 6410 | alignment = 0; |
| 6411 | field_offsets.clear(); |
| 6412 | } |
| 6413 | |
| 6414 | if (log) |
| 6415 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 6416 | "SymbolFileDWARF::LayoutRecordType (record_decl = %p, bit_size = %llu, alignment = %llu, field_offsets[%u],base_offsets[%u], vbase_offsets[%u]) success = %i", |
| 6417 | record_decl, |
| 6418 | bit_size, |
| 6419 | alignment, |
| 6420 | (uint32_t)field_offsets.size(), |
| 6421 | (uint32_t)base_offsets.size(), |
| 6422 | (uint32_t)vbase_offsets.size(), |
| 6423 | success); |
| 6424 | return success; |
| 6425 | } |
| 6426 | |
| 6427 | |
| 6428 | |