| 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" |
| 17 | #include "clang/Basic/Builtins.h" |
| 18 | #include "clang/Basic/IdentifierTable.h" |
| 19 | #include "clang/Basic/LangOptions.h" |
| 20 | #include "clang/Basic/SourceManager.h" |
| 21 | #include "clang/Basic/TargetInfo.h" |
| 22 | #include "clang/Basic/Specifiers.h" |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 23 | #include "clang/Sema/DeclSpec.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 25 | #include "llvm/Support/Casting.h" |
| 26 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 27 | #include "lldb/Core/Module.h" |
| 28 | #include "lldb/Core/PluginManager.h" |
| 29 | #include "lldb/Core/RegularExpression.h" |
| 30 | #include "lldb/Core/Scalar.h" |
| 31 | #include "lldb/Core/Section.h" |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 32 | #include "lldb/Core/StreamFile.h" |
| Jim Ingham | 318c9f2 | 2011-08-26 19:44:13 +0000 | [diff] [blame] | 33 | #include "lldb/Core/StreamString.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 34 | #include "lldb/Core/Timer.h" |
| 35 | #include "lldb/Core/Value.h" |
| 36 | |
| 37 | #include "lldb/Symbol/Block.h" |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 38 | #include "lldb/Symbol/ClangExternalASTSourceCallbacks.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 39 | #include "lldb/Symbol/CompileUnit.h" |
| 40 | #include "lldb/Symbol/LineTable.h" |
| 41 | #include "lldb/Symbol/ObjectFile.h" |
| 42 | #include "lldb/Symbol/SymbolVendor.h" |
| 43 | #include "lldb/Symbol/VariableList.h" |
| 44 | |
| 45 | #include "DWARFCompileUnit.h" |
| 46 | #include "DWARFDebugAbbrev.h" |
| 47 | #include "DWARFDebugAranges.h" |
| 48 | #include "DWARFDebugInfo.h" |
| 49 | #include "DWARFDebugInfoEntry.h" |
| 50 | #include "DWARFDebugLine.h" |
| 51 | #include "DWARFDebugPubnames.h" |
| 52 | #include "DWARFDebugRanges.h" |
| 53 | #include "DWARFDIECollection.h" |
| 54 | #include "DWARFFormValue.h" |
| 55 | #include "DWARFLocationList.h" |
| 56 | #include "LogChannelDWARF.h" |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 57 | #include "SymbolFileDWARFDebugMap.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 58 | |
| 59 | #include <map> |
| 60 | |
| Greg Clayton | 62742b1 | 2010-11-11 01:09:45 +0000 | [diff] [blame] | 61 | //#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 62 | |
| 63 | #ifdef ENABLE_DEBUG_PRINTF |
| 64 | #include <stdio.h> |
| 65 | #define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__) |
| 66 | #else |
| 67 | #define DEBUG_PRINTF(fmt, ...) |
| 68 | #endif |
| 69 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 70 | #define DIE_IS_BEING_PARSED ((lldb_private::Type*)1) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 71 | |
| 72 | using namespace lldb; |
| 73 | using namespace lldb_private; |
| 74 | |
| 75 | |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 76 | static AccessType |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 77 | DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 78 | { |
| 79 | switch (dwarf_accessibility) |
| 80 | { |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 81 | case DW_ACCESS_public: return eAccessPublic; |
| 82 | case DW_ACCESS_private: return eAccessPrivate; |
| 83 | case DW_ACCESS_protected: return eAccessProtected; |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 84 | default: break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 85 | } |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 86 | return eAccessNone; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | void |
| 90 | SymbolFileDWARF::Initialize() |
| 91 | { |
| 92 | LogChannelDWARF::Initialize(); |
| 93 | PluginManager::RegisterPlugin (GetPluginNameStatic(), |
| 94 | GetPluginDescriptionStatic(), |
| 95 | CreateInstance); |
| 96 | } |
| 97 | |
| 98 | void |
| 99 | SymbolFileDWARF::Terminate() |
| 100 | { |
| 101 | PluginManager::UnregisterPlugin (CreateInstance); |
| 102 | LogChannelDWARF::Initialize(); |
| 103 | } |
| 104 | |
| 105 | |
| 106 | const char * |
| 107 | SymbolFileDWARF::GetPluginNameStatic() |
| 108 | { |
| 109 | return "symbol-file.dwarf2"; |
| 110 | } |
| 111 | |
| 112 | const char * |
| 113 | SymbolFileDWARF::GetPluginDescriptionStatic() |
| 114 | { |
| 115 | return "DWARF and DWARF3 debug symbol file reader."; |
| 116 | } |
| 117 | |
| 118 | |
| 119 | SymbolFile* |
| 120 | SymbolFileDWARF::CreateInstance (ObjectFile* obj_file) |
| 121 | { |
| 122 | return new SymbolFileDWARF(obj_file); |
| 123 | } |
| 124 | |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 125 | TypeList * |
| 126 | SymbolFileDWARF::GetTypeList () |
| 127 | { |
| 128 | if (m_debug_map_symfile) |
| 129 | return m_debug_map_symfile->GetTypeList(); |
| 130 | return m_obj_file->GetModule()->GetTypeList(); |
| 131 | |
| 132 | } |
| 133 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 134 | //---------------------------------------------------------------------- |
| 135 | // Gets the first parent that is a lexical block, function or inlined |
| 136 | // subroutine, or compile unit. |
| 137 | //---------------------------------------------------------------------- |
| 138 | static const DWARFDebugInfoEntry * |
| 139 | GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die) |
| 140 | { |
| 141 | const DWARFDebugInfoEntry *die; |
| 142 | for (die = child_die->GetParent(); die != NULL; die = die->GetParent()) |
| 143 | { |
| 144 | dw_tag_t tag = die->Tag(); |
| 145 | |
| 146 | switch (tag) |
| 147 | { |
| 148 | case DW_TAG_compile_unit: |
| 149 | case DW_TAG_subprogram: |
| 150 | case DW_TAG_inlined_subroutine: |
| 151 | case DW_TAG_lexical_block: |
| 152 | return die; |
| 153 | } |
| 154 | } |
| 155 | return NULL; |
| 156 | } |
| 157 | |
| 158 | |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 159 | SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) : |
| 160 | SymbolFile (objfile), |
| 161 | m_debug_map_symfile (NULL), |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 162 | m_clang_tu_decl (NULL), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 163 | m_flags(), |
| 164 | m_data_debug_abbrev(), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 165 | m_data_debug_frame(), |
| 166 | m_data_debug_info(), |
| 167 | m_data_debug_line(), |
| 168 | m_data_debug_loc(), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 169 | m_data_debug_ranges(), |
| 170 | m_data_debug_str(), |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame^] | 171 | m_data_debug_names (), |
| 172 | m_data_debug_types (), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 173 | m_abbr(), |
| 174 | m_aranges(), |
| 175 | m_info(), |
| 176 | m_line(), |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 177 | m_function_basename_index(), |
| 178 | m_function_fullname_index(), |
| 179 | m_function_method_index(), |
| 180 | m_function_selector_index(), |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 181 | m_objc_class_selectors_index(), |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 182 | m_global_index(), |
| Greg Clayton | 69b0488 | 2010-10-15 02:03:22 +0000 | [diff] [blame] | 183 | m_type_index(), |
| 184 | m_namespace_index(), |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 185 | m_indexed (false), |
| 186 | m_is_external_ast_source (false), |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 187 | m_ranges(), |
| 188 | m_unique_ast_type_map () |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 189 | { |
| 190 | } |
| 191 | |
| 192 | SymbolFileDWARF::~SymbolFileDWARF() |
| 193 | { |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 194 | if (m_is_external_ast_source) |
| 195 | m_obj_file->GetModule()->GetClangASTContext().RemoveExternalSource (); |
| 196 | } |
| 197 | |
| 198 | static const ConstString & |
| 199 | GetDWARFMachOSegmentName () |
| 200 | { |
| 201 | static ConstString g_dwarf_section_name ("__DWARF"); |
| 202 | return g_dwarf_section_name; |
| 203 | } |
| 204 | |
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 205 | UniqueDWARFASTTypeMap & |
| 206 | SymbolFileDWARF::GetUniqueDWARFASTTypeMap () |
| 207 | { |
| 208 | if (m_debug_map_symfile) |
| 209 | return m_debug_map_symfile->GetUniqueDWARFASTTypeMap (); |
| 210 | return m_unique_ast_type_map; |
| 211 | } |
| 212 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 213 | ClangASTContext & |
| 214 | SymbolFileDWARF::GetClangASTContext () |
| 215 | { |
| 216 | if (m_debug_map_symfile) |
| 217 | return m_debug_map_symfile->GetClangASTContext (); |
| 218 | |
| 219 | ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext(); |
| 220 | if (!m_is_external_ast_source) |
| 221 | { |
| 222 | m_is_external_ast_source = true; |
| 223 | llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap ( |
| 224 | new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl, |
| 225 | SymbolFileDWARF::CompleteObjCInterfaceDecl, |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 226 | SymbolFileDWARF::FindExternalVisibleDeclsByName, |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 227 | this)); |
| 228 | |
| 229 | ast.SetExternalSource (ast_source_ap); |
| 230 | } |
| 231 | return ast; |
| 232 | } |
| 233 | |
| 234 | void |
| 235 | SymbolFileDWARF::InitializeObject() |
| 236 | { |
| 237 | // Install our external AST source callbacks so we can complete Clang types. |
| 238 | Module *module = m_obj_file->GetModule(); |
| 239 | if (module) |
| 240 | { |
| 241 | const SectionList *section_list = m_obj_file->GetSectionList(); |
| 242 | |
| 243 | const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get(); |
| 244 | |
| 245 | // Memory map the DWARF mach-o segment so we have everything mmap'ed |
| 246 | // to keep our heap memory usage down. |
| 247 | if (section) |
| 248 | section->MemoryMapSectionDataFromObjectFile(m_obj_file, m_dwarf_data); |
| 249 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | bool |
| 253 | SymbolFileDWARF::SupportedVersion(uint16_t version) |
| 254 | { |
| 255 | return version == 2 || version == 3; |
| 256 | } |
| 257 | |
| 258 | uint32_t |
| 259 | SymbolFileDWARF::GetAbilities () |
| 260 | { |
| 261 | uint32_t abilities = 0; |
| 262 | if (m_obj_file != NULL) |
| 263 | { |
| 264 | const Section* section = NULL; |
| 265 | const SectionList *section_list = m_obj_file->GetSectionList(); |
| 266 | if (section_list == NULL) |
| 267 | return 0; |
| 268 | |
| 269 | uint64_t debug_abbrev_file_size = 0; |
| 270 | uint64_t debug_aranges_file_size = 0; |
| 271 | uint64_t debug_frame_file_size = 0; |
| 272 | uint64_t debug_info_file_size = 0; |
| 273 | uint64_t debug_line_file_size = 0; |
| 274 | uint64_t debug_loc_file_size = 0; |
| 275 | uint64_t debug_macinfo_file_size = 0; |
| 276 | uint64_t debug_pubnames_file_size = 0; |
| 277 | uint64_t debug_pubtypes_file_size = 0; |
| 278 | uint64_t debug_ranges_file_size = 0; |
| 279 | uint64_t debug_str_file_size = 0; |
| 280 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 281 | section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 282 | |
| 283 | if (section) |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 284 | section_list = §ion->GetChildren (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 285 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 286 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 287 | if (section != NULL) |
| 288 | { |
| 289 | debug_info_file_size = section->GetByteSize(); |
| 290 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 291 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 292 | if (section) |
| 293 | debug_abbrev_file_size = section->GetByteSize(); |
| 294 | else |
| 295 | m_flags.Set (flagsGotDebugAbbrevData); |
| 296 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 297 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 298 | if (section) |
| 299 | debug_aranges_file_size = section->GetByteSize(); |
| 300 | else |
| 301 | m_flags.Set (flagsGotDebugArangesData); |
| 302 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 303 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 304 | if (section) |
| 305 | debug_frame_file_size = section->GetByteSize(); |
| 306 | else |
| 307 | m_flags.Set (flagsGotDebugFrameData); |
| 308 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 309 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 310 | if (section) |
| 311 | debug_line_file_size = section->GetByteSize(); |
| 312 | else |
| 313 | m_flags.Set (flagsGotDebugLineData); |
| 314 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 315 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 316 | if (section) |
| 317 | debug_loc_file_size = section->GetByteSize(); |
| 318 | else |
| 319 | m_flags.Set (flagsGotDebugLocData); |
| 320 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 321 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 322 | if (section) |
| 323 | debug_macinfo_file_size = section->GetByteSize(); |
| 324 | else |
| 325 | m_flags.Set (flagsGotDebugMacInfoData); |
| 326 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 327 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 328 | if (section) |
| 329 | debug_pubnames_file_size = section->GetByteSize(); |
| 330 | else |
| 331 | m_flags.Set (flagsGotDebugPubNamesData); |
| 332 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 333 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 334 | if (section) |
| 335 | debug_pubtypes_file_size = section->GetByteSize(); |
| 336 | else |
| 337 | m_flags.Set (flagsGotDebugPubTypesData); |
| 338 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 339 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 340 | if (section) |
| 341 | debug_ranges_file_size = section->GetByteSize(); |
| 342 | else |
| 343 | m_flags.Set (flagsGotDebugRangesData); |
| 344 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 345 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 346 | if (section) |
| 347 | debug_str_file_size = section->GetByteSize(); |
| 348 | else |
| 349 | m_flags.Set (flagsGotDebugStrData); |
| 350 | } |
| 351 | |
| 352 | if (debug_abbrev_file_size > 0 && debug_info_file_size > 0) |
| 353 | abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes; |
| 354 | |
| 355 | if (debug_line_file_size > 0) |
| 356 | abilities |= LineTables; |
| 357 | |
| 358 | if (debug_aranges_file_size > 0) |
| 359 | abilities |= AddressAcceleratorTable; |
| 360 | |
| 361 | if (debug_pubnames_file_size > 0) |
| 362 | abilities |= FunctionAcceleratorTable; |
| 363 | |
| 364 | if (debug_pubtypes_file_size > 0) |
| 365 | abilities |= TypeAcceleratorTable; |
| 366 | |
| 367 | if (debug_macinfo_file_size > 0) |
| 368 | abilities |= MacroInformation; |
| 369 | |
| 370 | if (debug_frame_file_size > 0) |
| 371 | abilities |= CallFrameInformation; |
| 372 | } |
| 373 | return abilities; |
| 374 | } |
| 375 | |
| 376 | const DataExtractor& |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 377 | SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 378 | { |
| 379 | if (m_flags.IsClear (got_flag)) |
| 380 | { |
| 381 | m_flags.Set (got_flag); |
| 382 | const SectionList *section_list = m_obj_file->GetSectionList(); |
| 383 | if (section_list) |
| 384 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 385 | Section *section = section_list->FindSectionByType(sect_type, true).get(); |
| 386 | if (section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 387 | { |
| 388 | // See if we memory mapped the DWARF segment? |
| 389 | if (m_dwarf_data.GetByteSize()) |
| 390 | { |
| 391 | data.SetData(m_dwarf_data, section->GetOffset (), section->GetByteSize()); |
| 392 | } |
| 393 | else |
| 394 | { |
| 395 | if (section->ReadSectionDataFromObjectFile(m_obj_file, data) == 0) |
| 396 | data.Clear(); |
| 397 | } |
| 398 | } |
| 399 | } |
| 400 | } |
| 401 | return data; |
| 402 | } |
| 403 | |
| 404 | const DataExtractor& |
| 405 | SymbolFileDWARF::get_debug_abbrev_data() |
| 406 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 407 | return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | const DataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 411 | SymbolFileDWARF::get_debug_frame_data() |
| 412 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 413 | return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | const DataExtractor& |
| 417 | SymbolFileDWARF::get_debug_info_data() |
| 418 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 419 | return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | const DataExtractor& |
| 423 | SymbolFileDWARF::get_debug_line_data() |
| 424 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 425 | return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | const DataExtractor& |
| 429 | SymbolFileDWARF::get_debug_loc_data() |
| 430 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 431 | return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | const DataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 435 | SymbolFileDWARF::get_debug_ranges_data() |
| 436 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 437 | return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | const DataExtractor& |
| 441 | SymbolFileDWARF::get_debug_str_data() |
| 442 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 443 | return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 444 | } |
| 445 | |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame^] | 446 | const DataExtractor& |
| 447 | SymbolFileDWARF::get_debug_names_data() |
| 448 | { |
| 449 | return GetCachedSectionData (flagsGotDebugNamesData, eSectionTypeDWARFDebugNames, m_data_debug_names); |
| 450 | } |
| 451 | |
| 452 | const DataExtractor& |
| 453 | SymbolFileDWARF::get_debug_types_data() |
| 454 | { |
| 455 | return GetCachedSectionData (flagsGotDebugTypesData, eSectionTypeDWARFDebugTypes, m_data_debug_types); |
| 456 | } |
| 457 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 458 | |
| 459 | DWARFDebugAbbrev* |
| 460 | SymbolFileDWARF::DebugAbbrev() |
| 461 | { |
| 462 | if (m_abbr.get() == NULL) |
| 463 | { |
| 464 | const DataExtractor &debug_abbrev_data = get_debug_abbrev_data(); |
| 465 | if (debug_abbrev_data.GetByteSize() > 0) |
| 466 | { |
| 467 | m_abbr.reset(new DWARFDebugAbbrev()); |
| 468 | if (m_abbr.get()) |
| 469 | m_abbr->Parse(debug_abbrev_data); |
| 470 | } |
| 471 | } |
| 472 | return m_abbr.get(); |
| 473 | } |
| 474 | |
| 475 | const DWARFDebugAbbrev* |
| 476 | SymbolFileDWARF::DebugAbbrev() const |
| 477 | { |
| 478 | return m_abbr.get(); |
| 479 | } |
| 480 | |
| 481 | DWARFDebugAranges* |
| 482 | SymbolFileDWARF::DebugAranges() |
| 483 | { |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 484 | // It turns out that llvm-gcc doesn't generate .debug_aranges in .o files |
| 485 | // and we are already parsing all of the DWARF because the .debug_pubnames |
| 486 | // is useless (it only mentions symbols that are externally visible), so |
| 487 | // don't use the .debug_aranges section, we should be using a debug aranges |
| 488 | // we got from SymbolFileDWARF::Index(). |
| 489 | |
| 490 | if (!m_indexed) |
| 491 | Index(); |
| 492 | |
| 493 | |
| 494 | // if (m_aranges.get() == NULL) |
| 495 | // { |
| 496 | // Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this); |
| 497 | // m_aranges.reset(new DWARFDebugAranges()); |
| 498 | // if (m_aranges.get()) |
| 499 | // { |
| 500 | // const DataExtractor &debug_aranges_data = get_debug_aranges_data(); |
| 501 | // if (debug_aranges_data.GetByteSize() > 0) |
| 502 | // m_aranges->Extract(debug_aranges_data); |
| 503 | // else |
| 504 | // m_aranges->Generate(this); |
| 505 | // } |
| 506 | // } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 507 | return m_aranges.get(); |
| 508 | } |
| 509 | |
| 510 | const DWARFDebugAranges* |
| 511 | SymbolFileDWARF::DebugAranges() const |
| 512 | { |
| 513 | return m_aranges.get(); |
| 514 | } |
| 515 | |
| 516 | |
| 517 | DWARFDebugInfo* |
| 518 | SymbolFileDWARF::DebugInfo() |
| 519 | { |
| 520 | if (m_info.get() == NULL) |
| 521 | { |
| 522 | Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this); |
| 523 | if (get_debug_info_data().GetByteSize() > 0) |
| 524 | { |
| 525 | m_info.reset(new DWARFDebugInfo()); |
| 526 | if (m_info.get()) |
| 527 | { |
| 528 | m_info->SetDwarfData(this); |
| 529 | } |
| 530 | } |
| 531 | } |
| 532 | return m_info.get(); |
| 533 | } |
| 534 | |
| 535 | const DWARFDebugInfo* |
| 536 | SymbolFileDWARF::DebugInfo() const |
| 537 | { |
| 538 | return m_info.get(); |
| 539 | } |
| 540 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 541 | DWARFCompileUnit* |
| 542 | SymbolFileDWARF::GetDWARFCompileUnitForUID(lldb::user_id_t cu_uid) |
| 543 | { |
| 544 | DWARFDebugInfo* info = DebugInfo(); |
| 545 | if (info) |
| 546 | return info->GetCompileUnit(cu_uid).get(); |
| 547 | return NULL; |
| 548 | } |
| 549 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 550 | |
| 551 | DWARFDebugRanges* |
| 552 | SymbolFileDWARF::DebugRanges() |
| 553 | { |
| 554 | if (m_ranges.get() == NULL) |
| 555 | { |
| 556 | Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this); |
| 557 | if (get_debug_ranges_data().GetByteSize() > 0) |
| 558 | { |
| 559 | m_ranges.reset(new DWARFDebugRanges()); |
| 560 | if (m_ranges.get()) |
| 561 | m_ranges->Extract(this); |
| 562 | } |
| 563 | } |
| 564 | return m_ranges.get(); |
| 565 | } |
| 566 | |
| 567 | const DWARFDebugRanges* |
| 568 | SymbolFileDWARF::DebugRanges() const |
| 569 | { |
| 570 | return m_ranges.get(); |
| 571 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 572 | |
| 573 | bool |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 574 | SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* curr_cu, CompUnitSP& compile_unit_sp) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 575 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 576 | if (curr_cu != NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 577 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 578 | const DWARFDebugInfoEntry * cu_die = curr_cu->GetCompileUnitDIEOnly (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 579 | if (cu_die) |
| 580 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 581 | const char * cu_die_name = cu_die->GetName(this, curr_cu); |
| 582 | 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] | 583 | 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] | 584 | if (cu_die_name) |
| 585 | { |
| Jim Ingham | 0909e5f | 2010-09-16 00:57:33 +0000 | [diff] [blame] | 586 | FileSpec cu_file_spec; |
| 587 | |
| Greg Clayton | 7bd65b9 | 2011-02-09 23:39:34 +0000 | [diff] [blame] | 588 | 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] | 589 | { |
| Jim Ingham | 0909e5f | 2010-09-16 00:57:33 +0000 | [diff] [blame] | 590 | // If we have a full path to the compile unit, we don't need to resolve |
| 591 | // the file. This can be expensive e.g. when the source files are NFS mounted. |
| 592 | cu_file_spec.SetFile (cu_die_name, false); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 593 | } |
| 594 | else |
| 595 | { |
| 596 | std::string fullpath(cu_comp_dir); |
| 597 | if (*fullpath.rbegin() != '/') |
| 598 | fullpath += '/'; |
| 599 | fullpath += cu_die_name; |
| Jim Ingham | 0909e5f | 2010-09-16 00:57:33 +0000 | [diff] [blame] | 600 | cu_file_spec.SetFile (fullpath.c_str(), false); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 601 | } |
| 602 | |
| Jim Ingham | 0f35ac2 | 2011-08-24 23:34:20 +0000 | [diff] [blame] | 603 | compile_unit_sp.reset(new CompileUnit(m_obj_file->GetModule(), curr_cu, cu_file_spec, curr_cu->GetOffset(), cu_language)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 604 | if (compile_unit_sp.get()) |
| 605 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 606 | curr_cu->SetUserData(compile_unit_sp.get()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 607 | return true; |
| 608 | } |
| 609 | } |
| 610 | } |
| 611 | } |
| 612 | return false; |
| 613 | } |
| 614 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 615 | uint32_t |
| 616 | SymbolFileDWARF::GetNumCompileUnits() |
| 617 | { |
| 618 | DWARFDebugInfo* info = DebugInfo(); |
| 619 | if (info) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 620 | return info->GetNumCompileUnits(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 621 | return 0; |
| 622 | } |
| 623 | |
| 624 | CompUnitSP |
| 625 | SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx) |
| 626 | { |
| 627 | CompUnitSP comp_unit; |
| 628 | DWARFDebugInfo* info = DebugInfo(); |
| 629 | if (info) |
| 630 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 631 | DWARFCompileUnit* curr_cu = info->GetCompileUnitAtIndex(cu_idx); |
| 632 | if (curr_cu != NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 633 | { |
| 634 | // Our symbol vendor shouldn't be asking us to add a compile unit that |
| 635 | // has already been added to it, which this DWARF plug-in knows as it |
| 636 | // stores the lldb compile unit (CompileUnit) pointer in each |
| 637 | // DWARFCompileUnit object when it gets added. |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 638 | assert(curr_cu->GetUserData() == NULL); |
| 639 | ParseCompileUnit(curr_cu, comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 640 | } |
| 641 | } |
| 642 | return comp_unit; |
| 643 | } |
| 644 | |
| 645 | static void |
| 646 | AddRangesToBlock |
| 647 | ( |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 648 | Block& block, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 649 | DWARFDebugRanges::RangeList& ranges, |
| 650 | addr_t block_base_addr |
| 651 | ) |
| 652 | { |
| 653 | ranges.SubtractOffset (block_base_addr); |
| 654 | size_t range_idx = 0; |
| 655 | const DWARFDebugRanges::Range *debug_range; |
| 656 | for (range_idx = 0; (debug_range = ranges.RangeAtIndex(range_idx)) != NULL; range_idx++) |
| 657 | { |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 658 | block.AddRange(debug_range->begin_offset, debug_range->end_offset); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 659 | } |
| 660 | } |
| 661 | |
| 662 | |
| 663 | Function * |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 664 | SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 665 | { |
| 666 | DWARFDebugRanges::RangeList func_ranges; |
| 667 | const char *name = NULL; |
| 668 | const char *mangled = NULL; |
| 669 | int decl_file = 0; |
| 670 | int decl_line = 0; |
| 671 | int decl_column = 0; |
| 672 | int call_file = 0; |
| 673 | int call_line = 0; |
| 674 | int call_column = 0; |
| 675 | DWARFExpression frame_base; |
| 676 | |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 677 | assert (die->Tag() == DW_TAG_subprogram); |
| 678 | |
| 679 | if (die->Tag() != DW_TAG_subprogram) |
| 680 | return NULL; |
| 681 | |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 682 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die); |
| 683 | const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind(); |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 684 | |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 685 | switch (containing_decl_kind) |
| 686 | { |
| 687 | case clang::Decl::Record: |
| 688 | case clang::Decl::CXXRecord: |
| 689 | case clang::Decl::ObjCClass: |
| 690 | case clang::Decl::ObjCImplementation: |
| 691 | case clang::Decl::ObjCInterface: |
| 692 | // We have methods of a class or struct |
| 693 | { |
| 694 | const DWARFDebugInfoEntry *containing_decl_die = m_decl_ctx_to_die[containing_decl_ctx]; |
| 695 | assert (containing_decl_die); |
| 696 | Type *class_type = ResolveType (dwarf_cu, containing_decl_die); |
| 697 | if (class_type) |
| 698 | class_type->GetClangFullType(); |
| 699 | // Make sure the class definition contains the funciton DIE |
| 700 | // we wanted to parse. If it does, we are done. Else, we need |
| 701 | // to fall through and parse the function DIE stil... |
| 702 | if (containing_decl_die->Contains (die)) |
| 703 | break; // DIE has been parsed, we are done |
| 704 | } |
| 705 | // Fall through... |
| 706 | |
| 707 | default: |
| 708 | // Parse the function prototype as a type that can then be added to concrete function instance |
| 709 | ParseTypes (sc, dwarf_cu, die, false, false); |
| 710 | break; |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 711 | } |
| 712 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 713 | //FixupTypes(); |
| 714 | |
| 715 | if (die->GetDIENamesAndRanges(this, dwarf_cu, name, mangled, func_ranges, decl_file, decl_line, decl_column, call_file, call_line, call_column, &frame_base)) |
| 716 | { |
| 717 | // Union of all ranges in the function DIE (if the function is discontiguous) |
| 718 | AddressRange func_range; |
| 719 | lldb::addr_t lowest_func_addr = func_ranges.LowestAddress(0); |
| 720 | lldb::addr_t highest_func_addr = func_ranges.HighestAddress(0); |
| 721 | if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr) |
| 722 | { |
| 723 | func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList()); |
| 724 | if (func_range.GetBaseAddress().IsValid()) |
| 725 | func_range.SetByteSize(highest_func_addr - lowest_func_addr); |
| 726 | } |
| 727 | |
| 728 | if (func_range.GetBaseAddress().IsValid()) |
| 729 | { |
| 730 | Mangled func_name; |
| 731 | if (mangled) |
| 732 | func_name.SetValue(mangled, true); |
| 733 | else if (name) |
| 734 | func_name.SetValue(name, false); |
| 735 | |
| 736 | FunctionSP func_sp; |
| 737 | std::auto_ptr<Declaration> decl_ap; |
| 738 | if (decl_file != 0 || decl_line != 0 || decl_column != 0) |
| Greg Clayton | d7e0546 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 739 | decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), |
| 740 | decl_line, |
| 741 | decl_column)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 742 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 743 | Type *func_type = m_die_to_type.lookup (die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 744 | |
| 745 | assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED); |
| 746 | |
| 747 | func_range.GetBaseAddress().ResolveLinkedAddress(); |
| 748 | |
| 749 | func_sp.reset(new Function (sc.comp_unit, |
| 750 | die->GetOffset(), // UserID is the DIE offset |
| 751 | die->GetOffset(), |
| 752 | func_name, |
| 753 | func_type, |
| 754 | func_range)); // first address range |
| 755 | |
| 756 | if (func_sp.get() != NULL) |
| 757 | { |
| 758 | func_sp->GetFrameBaseExpression() = frame_base; |
| 759 | sc.comp_unit->AddFunction(func_sp); |
| 760 | return func_sp.get(); |
| 761 | } |
| 762 | } |
| 763 | } |
| 764 | return NULL; |
| 765 | } |
| 766 | |
| 767 | size_t |
| 768 | SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc) |
| 769 | { |
| 770 | assert (sc.comp_unit); |
| 771 | size_t functions_added = 0; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 772 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 773 | if (dwarf_cu) |
| 774 | { |
| 775 | DWARFDIECollection function_dies; |
| 776 | const size_t num_funtions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies); |
| 777 | size_t func_idx; |
| 778 | for (func_idx = 0; func_idx < num_funtions; ++func_idx) |
| 779 | { |
| 780 | const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx); |
| 781 | if (sc.comp_unit->FindFunctionByUID (die->GetOffset()).get() == NULL) |
| 782 | { |
| 783 | if (ParseCompileUnitFunction(sc, dwarf_cu, die)) |
| 784 | ++functions_added; |
| 785 | } |
| 786 | } |
| 787 | //FixupTypes(); |
| 788 | } |
| 789 | return functions_added; |
| 790 | } |
| 791 | |
| 792 | bool |
| 793 | SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files) |
| 794 | { |
| 795 | assert (sc.comp_unit); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 796 | DWARFCompileUnit* curr_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID()); |
| 797 | assert (curr_cu); |
| 798 | const DWARFDebugInfoEntry * cu_die = curr_cu->GetCompileUnitDIEOnly(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 799 | |
| 800 | if (cu_die) |
| 801 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 802 | const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, curr_cu, DW_AT_comp_dir, NULL); |
| 803 | 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] | 804 | |
| 805 | // All file indexes in DWARF are one based and a file of index zero is |
| 806 | // supposed to be the compile unit itself. |
| 807 | support_files.Append (*sc.comp_unit); |
| 808 | |
| 809 | return DWARFDebugLine::ParseSupportFiles(get_debug_line_data(), cu_comp_dir, stmt_list, support_files); |
| 810 | } |
| 811 | return false; |
| 812 | } |
| 813 | |
| 814 | struct ParseDWARFLineTableCallbackInfo |
| 815 | { |
| 816 | LineTable* line_table; |
| 817 | const SectionList *section_list; |
| 818 | lldb::addr_t prev_sect_file_base_addr; |
| 819 | lldb::addr_t curr_sect_file_base_addr; |
| 820 | bool is_oso_for_debug_map; |
| 821 | bool prev_in_final_executable; |
| 822 | DWARFDebugLine::Row prev_row; |
| 823 | SectionSP prev_section_sp; |
| 824 | SectionSP curr_section_sp; |
| 825 | }; |
| 826 | |
| 827 | //---------------------------------------------------------------------- |
| 828 | // ParseStatementTableCallback |
| 829 | //---------------------------------------------------------------------- |
| 830 | static void |
| 831 | ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData) |
| 832 | { |
| 833 | LineTable* line_table = ((ParseDWARFLineTableCallbackInfo*)userData)->line_table; |
| 834 | if (state.row == DWARFDebugLine::State::StartParsingLineTable) |
| 835 | { |
| 836 | // Just started parsing the line table |
| 837 | } |
| 838 | else if (state.row == DWARFDebugLine::State::DoneParsingLineTable) |
| 839 | { |
| 840 | // Done parsing line table, nothing to do for the cleanup |
| 841 | } |
| 842 | else |
| 843 | { |
| 844 | ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData; |
| 845 | // We have a new row, lets append it |
| 846 | |
| 847 | if (info->curr_section_sp.get() == NULL || info->curr_section_sp->ContainsFileAddress(state.address) == false) |
| 848 | { |
| 849 | info->prev_section_sp = info->curr_section_sp; |
| 850 | info->prev_sect_file_base_addr = info->curr_sect_file_base_addr; |
| 851 | // If this is an end sequence entry, then we subtract one from the |
| 852 | // address to make sure we get an address that is not the end of |
| 853 | // a section. |
| 854 | if (state.end_sequence && state.address != 0) |
| 855 | info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address - 1); |
| 856 | else |
| 857 | info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address); |
| 858 | |
| 859 | if (info->curr_section_sp.get()) |
| 860 | info->curr_sect_file_base_addr = info->curr_section_sp->GetFileAddress (); |
| 861 | else |
| 862 | info->curr_sect_file_base_addr = 0; |
| 863 | } |
| 864 | if (info->curr_section_sp.get()) |
| 865 | { |
| 866 | lldb::addr_t curr_line_section_offset = state.address - info->curr_sect_file_base_addr; |
| 867 | // Check for the fancy section magic to determine if we |
| 868 | |
| 869 | if (info->is_oso_for_debug_map) |
| 870 | { |
| 871 | // When this is a debug map object file that contains DWARF |
| 872 | // (referenced from an N_OSO debug map nlist entry) we will have |
| 873 | // a file address in the file range for our section from the |
| 874 | // original .o file, and a load address in the executable that |
| 875 | // contains the debug map. |
| 876 | // |
| 877 | // If the sections for the file range and load range are |
| 878 | // different, we have a remapped section for the function and |
| 879 | // this address is resolved. If they are the same, then the |
| 880 | // function for this address didn't make it into the final |
| 881 | // executable. |
| 882 | bool curr_in_final_executable = info->curr_section_sp->GetLinkedSection () != NULL; |
| 883 | |
| 884 | // If we are doing DWARF with debug map, then we need to carefully |
| 885 | // add each line table entry as there may be gaps as functions |
| 886 | // get moved around or removed. |
| 887 | if (!info->prev_row.end_sequence && info->prev_section_sp.get()) |
| 888 | { |
| 889 | if (info->prev_in_final_executable) |
| 890 | { |
| 891 | bool terminate_previous_entry = false; |
| 892 | if (!curr_in_final_executable) |
| 893 | { |
| 894 | // Check for the case where the previous line entry |
| 895 | // in a function made it into the final executable, |
| 896 | // yet the current line entry falls in a function |
| 897 | // that didn't. The line table used to be contiguous |
| 898 | // through this address range but now it isn't. We |
| 899 | // need to terminate the previous line entry so |
| 900 | // that we can reconstruct the line range correctly |
| 901 | // for it and to keep the line table correct. |
| 902 | terminate_previous_entry = true; |
| 903 | } |
| 904 | else if (info->curr_section_sp.get() != info->prev_section_sp.get()) |
| 905 | { |
| 906 | // Check for cases where the line entries used to be |
| 907 | // contiguous address ranges, but now they aren't. |
| 908 | // This can happen when order files specify the |
| 909 | // ordering of the functions. |
| 910 | lldb::addr_t prev_line_section_offset = info->prev_row.address - info->prev_sect_file_base_addr; |
| 911 | Section *curr_sect = info->curr_section_sp.get(); |
| 912 | Section *prev_sect = info->prev_section_sp.get(); |
| 913 | assert (curr_sect->GetLinkedSection()); |
| 914 | assert (prev_sect->GetLinkedSection()); |
| 915 | lldb::addr_t object_file_addr_delta = state.address - info->prev_row.address; |
| 916 | lldb::addr_t curr_linked_file_addr = curr_sect->GetLinkedFileAddress() + curr_line_section_offset; |
| 917 | lldb::addr_t prev_linked_file_addr = prev_sect->GetLinkedFileAddress() + prev_line_section_offset; |
| 918 | lldb::addr_t linked_file_addr_delta = curr_linked_file_addr - prev_linked_file_addr; |
| 919 | if (object_file_addr_delta != linked_file_addr_delta) |
| 920 | terminate_previous_entry = true; |
| 921 | } |
| 922 | |
| 923 | if (terminate_previous_entry) |
| 924 | { |
| 925 | line_table->InsertLineEntry (info->prev_section_sp, |
| 926 | state.address - info->prev_sect_file_base_addr, |
| 927 | info->prev_row.line, |
| 928 | info->prev_row.column, |
| 929 | info->prev_row.file, |
| 930 | false, // is_stmt |
| 931 | false, // basic_block |
| 932 | false, // state.prologue_end |
| 933 | false, // state.epilogue_begin |
| 934 | true); // end_sequence); |
| 935 | } |
| 936 | } |
| 937 | } |
| 938 | |
| 939 | if (curr_in_final_executable) |
| 940 | { |
| 941 | line_table->InsertLineEntry (info->curr_section_sp, |
| 942 | curr_line_section_offset, |
| 943 | state.line, |
| 944 | state.column, |
| 945 | state.file, |
| 946 | state.is_stmt, |
| 947 | state.basic_block, |
| 948 | state.prologue_end, |
| 949 | state.epilogue_begin, |
| 950 | state.end_sequence); |
| 951 | info->prev_section_sp = info->curr_section_sp; |
| 952 | } |
| 953 | else |
| 954 | { |
| 955 | // If the current address didn't make it into the final |
| 956 | // executable, the current section will be the __text |
| 957 | // segment in the .o file, so we need to clear this so |
| 958 | // we can catch the next function that did make it into |
| 959 | // the final executable. |
| 960 | info->prev_section_sp.reset(); |
| 961 | info->curr_section_sp.reset(); |
| 962 | } |
| 963 | |
| 964 | info->prev_in_final_executable = curr_in_final_executable; |
| 965 | } |
| 966 | else |
| 967 | { |
| 968 | // We are not in an object file that contains DWARF for an |
| 969 | // N_OSO, this is just a normal DWARF file. The DWARF spec |
| 970 | // guarantees that the addresses will be in increasing order |
| 971 | // so, since we store line tables in file address order, we |
| 972 | // can always just append the line entry without needing to |
| 973 | // search for the correct insertion point (we don't need to |
| 974 | // use LineEntry::InsertLineEntry()). |
| 975 | line_table->AppendLineEntry (info->curr_section_sp, |
| 976 | curr_line_section_offset, |
| 977 | state.line, |
| 978 | state.column, |
| 979 | state.file, |
| 980 | state.is_stmt, |
| 981 | state.basic_block, |
| 982 | state.prologue_end, |
| 983 | state.epilogue_begin, |
| 984 | state.end_sequence); |
| 985 | } |
| 986 | } |
| 987 | |
| 988 | info->prev_row = state; |
| 989 | } |
| 990 | } |
| 991 | |
| 992 | bool |
| 993 | SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc) |
| 994 | { |
| 995 | assert (sc.comp_unit); |
| 996 | if (sc.comp_unit->GetLineTable() != NULL) |
| 997 | return true; |
| 998 | |
| 999 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID()); |
| 1000 | if (dwarf_cu) |
| 1001 | { |
| 1002 | const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly(); |
| 1003 | const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET); |
| 1004 | if (cu_line_offset != DW_INVALID_OFFSET) |
| 1005 | { |
| 1006 | std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit)); |
| 1007 | if (line_table_ap.get()) |
| 1008 | { |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 1009 | ParseDWARFLineTableCallbackInfo info = { line_table_ap.get(), m_obj_file->GetSectionList(), 0, 0, m_debug_map_symfile != NULL, false}; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1010 | uint32_t offset = cu_line_offset; |
| 1011 | DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info); |
| 1012 | sc.comp_unit->SetLineTable(line_table_ap.release()); |
| 1013 | return true; |
| 1014 | } |
| 1015 | } |
| 1016 | } |
| 1017 | return false; |
| 1018 | } |
| 1019 | |
| 1020 | size_t |
| 1021 | SymbolFileDWARF::ParseFunctionBlocks |
| 1022 | ( |
| 1023 | const SymbolContext& sc, |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1024 | Block *parent_block, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1025 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1026 | const DWARFDebugInfoEntry *die, |
| 1027 | addr_t subprogram_low_pc, |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1028 | uint32_t depth |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1029 | ) |
| 1030 | { |
| 1031 | size_t blocks_added = 0; |
| 1032 | while (die != NULL) |
| 1033 | { |
| 1034 | dw_tag_t tag = die->Tag(); |
| 1035 | |
| 1036 | switch (tag) |
| 1037 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1038 | case DW_TAG_inlined_subroutine: |
| Greg Clayton | b4d3733 | 2011-08-12 16:22:48 +0000 | [diff] [blame] | 1039 | case DW_TAG_subprogram: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1040 | case DW_TAG_lexical_block: |
| 1041 | { |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1042 | Block *block = NULL; |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1043 | if (tag == DW_TAG_subprogram) |
| 1044 | { |
| 1045 | // Skip any DW_TAG_subprogram DIEs that are inside |
| 1046 | // of a normal or inlined functions. These will be |
| 1047 | // parsed on their own as separate entities. |
| 1048 | |
| 1049 | if (depth > 0) |
| 1050 | break; |
| 1051 | |
| 1052 | block = parent_block; |
| 1053 | } |
| 1054 | else |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1055 | { |
| 1056 | BlockSP block_sp(new Block (die->GetOffset())); |
| 1057 | parent_block->AddChild(block_sp); |
| 1058 | block = block_sp.get(); |
| 1059 | } |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1060 | DWARFDebugRanges::RangeList ranges; |
| 1061 | const char *name = NULL; |
| 1062 | const char *mangled_name = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1063 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1064 | int decl_file = 0; |
| 1065 | int decl_line = 0; |
| 1066 | int decl_column = 0; |
| 1067 | int call_file = 0; |
| 1068 | int call_line = 0; |
| 1069 | int call_column = 0; |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1070 | if (die->GetDIENamesAndRanges (this, |
| 1071 | dwarf_cu, |
| 1072 | name, |
| 1073 | mangled_name, |
| 1074 | ranges, |
| 1075 | decl_file, decl_line, decl_column, |
| 1076 | call_file, call_line, call_column)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1077 | { |
| 1078 | if (tag == DW_TAG_subprogram) |
| 1079 | { |
| 1080 | assert (subprogram_low_pc == LLDB_INVALID_ADDRESS); |
| 1081 | subprogram_low_pc = ranges.LowestAddress(0); |
| 1082 | } |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1083 | else if (tag == DW_TAG_inlined_subroutine) |
| 1084 | { |
| 1085 | // We get called here for inlined subroutines in two ways. |
| 1086 | // The first time is when we are making the Function object |
| 1087 | // for this inlined concrete instance. Since we're creating a top level block at |
| 1088 | // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to |
| 1089 | // adjust the containing address. |
| 1090 | // The second time is when we are parsing the blocks inside the function that contains |
| 1091 | // the inlined concrete instance. Since these will be blocks inside the containing "real" |
| 1092 | // function the offset will be for that function. |
| 1093 | if (subprogram_low_pc == LLDB_INVALID_ADDRESS) |
| 1094 | { |
| 1095 | subprogram_low_pc = ranges.LowestAddress(0); |
| 1096 | } |
| 1097 | } |
| 1098 | |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1099 | AddRangesToBlock (*block, ranges, subprogram_low_pc); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1100 | |
| 1101 | if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL)) |
| 1102 | { |
| 1103 | std::auto_ptr<Declaration> decl_ap; |
| 1104 | if (decl_file != 0 || decl_line != 0 || decl_column != 0) |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1105 | decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), |
| 1106 | decl_line, decl_column)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1107 | |
| 1108 | std::auto_ptr<Declaration> call_ap; |
| 1109 | if (call_file != 0 || call_line != 0 || call_column != 0) |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1110 | call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file), |
| 1111 | call_line, call_column)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1112 | |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1113 | block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | ++blocks_added; |
| 1117 | |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1118 | if (die->HasChildren()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1119 | { |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1120 | blocks_added += ParseFunctionBlocks (sc, |
| 1121 | block, |
| 1122 | dwarf_cu, |
| 1123 | die->GetFirstChild(), |
| 1124 | subprogram_low_pc, |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1125 | depth + 1); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1126 | } |
| 1127 | } |
| 1128 | } |
| 1129 | break; |
| 1130 | default: |
| 1131 | break; |
| 1132 | } |
| 1133 | |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1134 | // Only parse siblings of the block if we are not at depth zero. A depth |
| 1135 | // of zero indicates we are currently parsing the top level |
| 1136 | // DW_TAG_subprogram DIE |
| 1137 | |
| 1138 | if (depth == 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1139 | die = NULL; |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1140 | else |
| 1141 | die = die->GetSibling(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1142 | } |
| 1143 | return blocks_added; |
| 1144 | } |
| 1145 | |
| 1146 | size_t |
| 1147 | SymbolFileDWARF::ParseChildMembers |
| 1148 | ( |
| 1149 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1150 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1151 | const DWARFDebugInfoEntry *parent_die, |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1152 | clang_type_t class_clang_type, |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1153 | const LanguageType class_language, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1154 | std::vector<clang::CXXBaseSpecifier *>& base_classes, |
| 1155 | std::vector<int>& member_accessibilities, |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1156 | DWARFDIECollection& member_function_dies, |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1157 | AccessType& default_accessibility, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1158 | bool &is_a_class |
| 1159 | ) |
| 1160 | { |
| 1161 | if (parent_die == NULL) |
| 1162 | return 0; |
| 1163 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1164 | size_t count = 0; |
| 1165 | const DWARFDebugInfoEntry *die; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 1166 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1167 | uint32_t member_idx = 0; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 1168 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1169 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 1170 | { |
| 1171 | dw_tag_t tag = die->Tag(); |
| 1172 | |
| 1173 | switch (tag) |
| 1174 | { |
| 1175 | case DW_TAG_member: |
| 1176 | { |
| 1177 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1178 | const size_t num_attributes = die->GetAttributes (this, |
| 1179 | dwarf_cu, |
| 1180 | fixed_form_sizes, |
| 1181 | attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1182 | if (num_attributes > 0) |
| 1183 | { |
| 1184 | Declaration decl; |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1185 | //DWARFExpression location; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1186 | const char *name = NULL; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1187 | bool is_artificial = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1188 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1189 | AccessType accessibility = eAccessNone; |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1190 | //off_t member_offset = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1191 | size_t byte_size = 0; |
| 1192 | size_t bit_offset = 0; |
| 1193 | size_t bit_size = 0; |
| 1194 | uint32_t i; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1195 | for (i=0; i<num_attributes && !is_artificial; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1196 | { |
| 1197 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 1198 | DWARFFormValue form_value; |
| 1199 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1200 | { |
| 1201 | switch (attr) |
| 1202 | { |
| 1203 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 1204 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 1205 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 1206 | case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; |
| 1207 | case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; |
| 1208 | case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break; |
| 1209 | case DW_AT_bit_size: bit_size = form_value.Unsigned(); break; |
| 1210 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; |
| 1211 | case DW_AT_data_member_location: |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1212 | // if (form_value.BlockData()) |
| 1213 | // { |
| 1214 | // Value initialValue(0); |
| 1215 | // Value memberOffset(0); |
| 1216 | // const DataExtractor& debug_info_data = get_debug_info_data(); |
| 1217 | // uint32_t block_length = form_value.Unsigned(); |
| 1218 | // uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 1219 | // if (DWARFExpression::Evaluate(NULL, NULL, debug_info_data, NULL, NULL, block_offset, block_length, eRegisterKindDWARF, &initialValue, memberOffset, NULL)) |
| 1220 | // { |
| 1221 | // member_offset = memberOffset.ResolveValue(NULL, NULL).UInt(); |
| 1222 | // } |
| 1223 | // } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1224 | break; |
| 1225 | |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1226 | 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] | 1227 | case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1228 | case DW_AT_declaration: |
| 1229 | case DW_AT_description: |
| 1230 | case DW_AT_mutable: |
| 1231 | case DW_AT_visibility: |
| 1232 | default: |
| 1233 | case DW_AT_sibling: |
| 1234 | break; |
| 1235 | } |
| 1236 | } |
| 1237 | } |
| Sean Callanan | 5a477cf | 2010-10-30 01:56:10 +0000 | [diff] [blame] | 1238 | |
| 1239 | // FIXME: Make Clang ignore Objective-C accessibility for expressions |
| 1240 | |
| 1241 | if (class_language == eLanguageTypeObjC || |
| 1242 | class_language == eLanguageTypeObjC_plus_plus) |
| 1243 | accessibility = eAccessNone; |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1244 | |
| 1245 | if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name)) |
| 1246 | { |
| 1247 | // Not all compilers will mark the vtable pointer |
| 1248 | // member as artificial (llvm-gcc). We can't have |
| 1249 | // the virtual members in our classes otherwise it |
| 1250 | // throws off all child offsets since we end up |
| 1251 | // having and extra pointer sized member in our |
| 1252 | // class layouts. |
| 1253 | is_artificial = true; |
| 1254 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1255 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1256 | if (is_artificial == false) |
| 1257 | { |
| 1258 | Type *member_type = ResolveTypeUID(encoding_uid); |
| Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1259 | if (member_type) |
| 1260 | { |
| 1261 | if (accessibility == eAccessNone) |
| 1262 | accessibility = default_accessibility; |
| 1263 | member_accessibilities.push_back(accessibility); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1264 | |
| Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1265 | GetClangASTContext().AddFieldToRecordType (class_clang_type, |
| 1266 | name, |
| 1267 | member_type->GetClangLayoutType(), |
| 1268 | accessibility, |
| 1269 | bit_size); |
| 1270 | } |
| 1271 | else |
| 1272 | { |
| 1273 | if (name) |
| 1274 | ReportError ("0x%8.8x: DW_TAG_member '%s' refers to type 0x%8.8x which was unable to be parsed", |
| 1275 | die->GetOffset(), |
| 1276 | name, |
| 1277 | encoding_uid); |
| 1278 | else |
| 1279 | ReportError ("0x%8.8x: DW_TAG_member refers to type 0x%8.8x which was unable to be parsed", |
| 1280 | die->GetOffset(), |
| 1281 | encoding_uid); |
| 1282 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1283 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1284 | } |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1285 | ++member_idx; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1286 | } |
| 1287 | break; |
| 1288 | |
| 1289 | case DW_TAG_subprogram: |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1290 | // Let the type parsing code handle this one for us. |
| 1291 | member_function_dies.Append (die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1292 | break; |
| 1293 | |
| 1294 | case DW_TAG_inheritance: |
| 1295 | { |
| 1296 | is_a_class = true; |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1297 | if (default_accessibility == eAccessNone) |
| 1298 | default_accessibility = eAccessPrivate; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1299 | // TODO: implement DW_TAG_inheritance type parsing |
| 1300 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1301 | const size_t num_attributes = die->GetAttributes (this, |
| 1302 | dwarf_cu, |
| 1303 | fixed_form_sizes, |
| 1304 | attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1305 | if (num_attributes > 0) |
| 1306 | { |
| 1307 | Declaration decl; |
| 1308 | DWARFExpression location; |
| 1309 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1310 | AccessType accessibility = default_accessibility; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1311 | bool is_virtual = false; |
| 1312 | bool is_base_of_class = true; |
| 1313 | off_t member_offset = 0; |
| 1314 | uint32_t i; |
| 1315 | for (i=0; i<num_attributes; ++i) |
| 1316 | { |
| 1317 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 1318 | DWARFFormValue form_value; |
| 1319 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1320 | { |
| 1321 | switch (attr) |
| 1322 | { |
| 1323 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 1324 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 1325 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 1326 | case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; |
| 1327 | case DW_AT_data_member_location: |
| 1328 | if (form_value.BlockData()) |
| 1329 | { |
| 1330 | Value initialValue(0); |
| 1331 | Value memberOffset(0); |
| 1332 | const DataExtractor& debug_info_data = get_debug_info_data(); |
| 1333 | uint32_t block_length = form_value.Unsigned(); |
| 1334 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1335 | if (DWARFExpression::Evaluate (NULL, |
| 1336 | NULL, |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1337 | NULL, |
| 1338 | NULL, |
| Jason Molenda | 2d107dd | 2010-11-20 01:28:30 +0000 | [diff] [blame] | 1339 | NULL, |
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 1340 | debug_info_data, |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1341 | block_offset, |
| 1342 | block_length, |
| 1343 | eRegisterKindDWARF, |
| 1344 | &initialValue, |
| 1345 | memberOffset, |
| 1346 | NULL)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1347 | { |
| 1348 | member_offset = memberOffset.ResolveValue(NULL, NULL).UInt(); |
| 1349 | } |
| 1350 | } |
| 1351 | break; |
| 1352 | |
| 1353 | case DW_AT_accessibility: |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1354 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1355 | break; |
| 1356 | |
| 1357 | case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break; |
| 1358 | default: |
| 1359 | case DW_AT_sibling: |
| 1360 | break; |
| 1361 | } |
| 1362 | } |
| 1363 | } |
| 1364 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 1365 | Type *base_class_type = ResolveTypeUID(encoding_uid); |
| 1366 | assert(base_class_type); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1367 | |
| Greg Clayton | f4ecaa5 | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 1368 | clang_type_t base_class_clang_type = base_class_type->GetClangFullType(); |
| 1369 | assert (base_class_clang_type); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1370 | if (class_language == eLanguageTypeObjC) |
| 1371 | { |
| Greg Clayton | f4ecaa5 | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 1372 | GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1373 | } |
| 1374 | else |
| 1375 | { |
| Greg Clayton | f4ecaa5 | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 1376 | base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type, |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1377 | accessibility, |
| 1378 | is_virtual, |
| 1379 | is_base_of_class)); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1380 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1381 | } |
| 1382 | } |
| 1383 | break; |
| 1384 | |
| 1385 | default: |
| 1386 | break; |
| 1387 | } |
| 1388 | } |
| 1389 | return count; |
| 1390 | } |
| 1391 | |
| 1392 | |
| 1393 | clang::DeclContext* |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 1394 | SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1395 | { |
| 1396 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 1397 | if (debug_info) |
| 1398 | { |
| 1399 | DWARFCompileUnitSP cu_sp; |
| 1400 | const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp); |
| 1401 | if (die) |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 1402 | return GetClangDeclContextContainingDIE (cu_sp.get(), die); |
| 1403 | } |
| 1404 | return NULL; |
| 1405 | } |
| 1406 | |
| 1407 | clang::DeclContext* |
| 1408 | SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid) |
| 1409 | { |
| 1410 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 1411 | if (debug_info) |
| 1412 | { |
| 1413 | DWARFCompileUnitSP cu_sp; |
| 1414 | const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp); |
| 1415 | if (die) |
| 1416 | return GetClangDeclContextForDIE (sc, cu_sp.get(), die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1417 | } |
| 1418 | return NULL; |
| 1419 | } |
| 1420 | |
| 1421 | Type* |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 1422 | SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1423 | { |
| 1424 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 1425 | if (debug_info) |
| 1426 | { |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 1427 | DWARFCompileUnitSP cu_sp; |
| 1428 | const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1429 | if (type_die != NULL) |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 1430 | { |
| 1431 | // We might be coming in in the middle of a type tree (a class |
| 1432 | // withing a class, an enum within a class), so parse any needed |
| 1433 | // parent DIEs before we get to this one... |
| 1434 | const DWARFDebugInfoEntry* parent_die = type_die->GetParent(); |
| 1435 | switch (parent_die->Tag()) |
| 1436 | { |
| 1437 | case DW_TAG_structure_type: |
| 1438 | case DW_TAG_union_type: |
| 1439 | case DW_TAG_class_type: |
| 1440 | ResolveType(cu_sp.get(), parent_die); |
| 1441 | break; |
| 1442 | } |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 1443 | return ResolveType (cu_sp.get(), type_die); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 1444 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1445 | } |
| 1446 | return NULL; |
| 1447 | } |
| 1448 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1449 | // This function is used when SymbolFileDWARFDebugMap owns a bunch of |
| 1450 | // SymbolFileDWARF objects to detect if this DWARF file is the one that |
| 1451 | // can resolve a clang_type. |
| 1452 | bool |
| 1453 | SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type) |
| 1454 | { |
| 1455 | clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type); |
| 1456 | const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers); |
| 1457 | return die != NULL; |
| 1458 | } |
| 1459 | |
| 1460 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1461 | lldb::clang_type_t |
| 1462 | SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type) |
| 1463 | { |
| 1464 | // 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] | 1465 | clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type); |
| 1466 | 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] | 1467 | if (die == NULL) |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1468 | { |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1469 | // if (m_debug_map_symfile) |
| 1470 | // { |
| 1471 | // Type *type = m_die_to_type[die]; |
| 1472 | // if (type && type->GetSymbolFile() != this) |
| 1473 | // return type->GetClangType(); |
| 1474 | // } |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1475 | // We have already resolved this type... |
| 1476 | return clang_type; |
| 1477 | } |
| 1478 | // Once we start resolving this type, remove it from the forward declaration |
| 1479 | // map in case anyone child members or other types require this type to get resolved. |
| 1480 | // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition |
| 1481 | // are done. |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1482 | m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers); |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1483 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1484 | |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 1485 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 1486 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1487 | DWARFCompileUnit *curr_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get(); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1488 | Type *type = m_die_to_type.lookup (die); |
| 1489 | |
| 1490 | const dw_tag_t tag = die->Tag(); |
| 1491 | |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 1492 | DEBUG_PRINTF ("0x%8.8x: %s (\"%s\") - resolve forward declaration...\n", |
| 1493 | die->GetOffset(), |
| 1494 | DW_TAG_value_to_name(tag), |
| 1495 | type->GetName().AsCString()); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1496 | assert (clang_type); |
| 1497 | DWARFDebugInfoEntry::Attributes attributes; |
| 1498 | |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 1499 | ClangASTContext &ast = GetClangASTContext(); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1500 | |
| 1501 | switch (tag) |
| 1502 | { |
| 1503 | case DW_TAG_structure_type: |
| 1504 | case DW_TAG_union_type: |
| 1505 | case DW_TAG_class_type: |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 1506 | ast.StartTagDeclarationDefinition (clang_type); |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1507 | if (die->HasChildren()) |
| 1508 | { |
| 1509 | LanguageType class_language = eLanguageTypeUnknown; |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 1510 | bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type); |
| 1511 | if (is_objc_class) |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1512 | class_language = eLanguageTypeObjC; |
| 1513 | |
| 1514 | int tag_decl_kind = -1; |
| 1515 | AccessType default_accessibility = eAccessNone; |
| 1516 | if (tag == DW_TAG_structure_type) |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1517 | { |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1518 | tag_decl_kind = clang::TTK_Struct; |
| 1519 | default_accessibility = eAccessPublic; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1520 | } |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1521 | else if (tag == DW_TAG_union_type) |
| 1522 | { |
| 1523 | tag_decl_kind = clang::TTK_Union; |
| 1524 | default_accessibility = eAccessPublic; |
| 1525 | } |
| 1526 | else if (tag == DW_TAG_class_type) |
| 1527 | { |
| 1528 | tag_decl_kind = clang::TTK_Class; |
| 1529 | default_accessibility = eAccessPrivate; |
| 1530 | } |
| 1531 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1532 | SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu)); |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1533 | std::vector<clang::CXXBaseSpecifier *> base_classes; |
| 1534 | std::vector<int> member_accessibilities; |
| 1535 | bool is_a_class = false; |
| 1536 | // Parse members and base classes first |
| 1537 | DWARFDIECollection member_function_dies; |
| 1538 | |
| 1539 | ParseChildMembers (sc, |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1540 | curr_cu, |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1541 | die, |
| 1542 | clang_type, |
| 1543 | class_language, |
| 1544 | base_classes, |
| 1545 | member_accessibilities, |
| 1546 | member_function_dies, |
| 1547 | default_accessibility, |
| 1548 | is_a_class); |
| 1549 | |
| 1550 | // Now parse any methods if there were any... |
| 1551 | size_t num_functions = member_function_dies.Size(); |
| 1552 | if (num_functions > 0) |
| 1553 | { |
| 1554 | for (size_t i=0; i<num_functions; ++i) |
| 1555 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1556 | ResolveType(curr_cu, member_function_dies.GetDIEPtrAtIndex(i)); |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1557 | } |
| 1558 | } |
| 1559 | |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 1560 | if (class_language == eLanguageTypeObjC) |
| 1561 | { |
| Greg Clayton | e305594 | 2011-06-30 02:28:26 +0000 | [diff] [blame] | 1562 | std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(clang_type)); |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 1563 | if (!class_str.empty()) |
| 1564 | { |
| 1565 | |
| 1566 | ConstString class_name (class_str.c_str()); |
| 1567 | std::vector<NameToDIE::Info> method_die_infos; |
| 1568 | if (m_objc_class_selectors_index.Find (class_name, method_die_infos)) |
| 1569 | { |
| 1570 | DWARFCompileUnit* method_cu = NULL; |
| 1571 | DWARFCompileUnit* prev_method_cu = NULL; |
| 1572 | const size_t num_objc_methods = method_die_infos.size(); |
| 1573 | for (size_t i=0;i<num_objc_methods; ++i, prev_method_cu = method_cu) |
| 1574 | { |
| 1575 | method_cu = debug_info->GetCompileUnitAtIndex(method_die_infos[i].cu_idx); |
| 1576 | |
| 1577 | if (method_cu != prev_method_cu) |
| 1578 | method_cu->ExtractDIEsIfNeeded (false); |
| 1579 | |
| 1580 | DWARFDebugInfoEntry *method_die = method_cu->GetDIEAtIndexUnchecked(method_die_infos[i].die_idx); |
| 1581 | |
| 1582 | ResolveType (method_cu, method_die); |
| 1583 | } |
| 1584 | } |
| 1585 | } |
| 1586 | } |
| 1587 | |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1588 | // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we |
| 1589 | // need to tell the clang type it is actually a class. |
| 1590 | if (class_language != eLanguageTypeObjC) |
| 1591 | { |
| 1592 | if (is_a_class && tag_decl_kind != clang::TTK_Class) |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 1593 | ast.SetTagTypeKind (clang_type, clang::TTK_Class); |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1594 | } |
| 1595 | |
| 1596 | // Since DW_TAG_structure_type gets used for both classes |
| 1597 | // and structures, we may need to set any DW_TAG_member |
| 1598 | // fields to have a "private" access if none was specified. |
| 1599 | // When we parsed the child members we tracked that actual |
| 1600 | // accessibility value for each DW_TAG_member in the |
| 1601 | // "member_accessibilities" array. If the value for the |
| 1602 | // member is zero, then it was set to the "default_accessibility" |
| 1603 | // which for structs was "public". Below we correct this |
| 1604 | // by setting any fields to "private" that weren't correctly |
| 1605 | // set. |
| 1606 | if (is_a_class && !member_accessibilities.empty()) |
| 1607 | { |
| 1608 | // This is a class and all members that didn't have |
| 1609 | // their access specified are private. |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 1610 | ast.SetDefaultAccessForRecordFields (clang_type, |
| 1611 | eAccessPrivate, |
| 1612 | &member_accessibilities.front(), |
| 1613 | member_accessibilities.size()); |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1614 | } |
| 1615 | |
| 1616 | if (!base_classes.empty()) |
| 1617 | { |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 1618 | ast.SetBaseClassesForClassType (clang_type, |
| 1619 | &base_classes.front(), |
| 1620 | base_classes.size()); |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1621 | |
| 1622 | // Clang will copy each CXXBaseSpecifier in "base_classes" |
| 1623 | // so we have to free them all. |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 1624 | ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(), |
| 1625 | base_classes.size()); |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1626 | } |
| 1627 | |
| 1628 | } |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 1629 | ast.CompleteTagDeclarationDefinition (clang_type); |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1630 | return clang_type; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1631 | |
| 1632 | case DW_TAG_enumeration_type: |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 1633 | ast.StartTagDeclarationDefinition (clang_type); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1634 | if (die->HasChildren()) |
| 1635 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1636 | SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu)); |
| 1637 | ParseChildEnumerators(sc, clang_type, type->GetByteSize(), curr_cu, die); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1638 | } |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 1639 | ast.CompleteTagDeclarationDefinition (clang_type); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1640 | return clang_type; |
| 1641 | |
| 1642 | default: |
| 1643 | assert(false && "not a forward clang type decl!"); |
| 1644 | break; |
| 1645 | } |
| 1646 | return NULL; |
| 1647 | } |
| 1648 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 1649 | Type* |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1650 | 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] | 1651 | { |
| 1652 | if (type_die != NULL) |
| 1653 | { |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 1654 | Type *type = m_die_to_type.lookup (type_die); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 1655 | if (type == NULL) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1656 | type = GetTypeForDIE (curr_cu, type_die).get(); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1657 | if (assert_not_being_parsed) |
| 1658 | assert (type != DIE_IS_BEING_PARSED); |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 1659 | return type; |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 1660 | } |
| 1661 | return NULL; |
| 1662 | } |
| 1663 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1664 | CompileUnit* |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1665 | SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* curr_cu, uint32_t cu_idx) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1666 | { |
| 1667 | // Check if the symbol vendor already knows about this compile unit? |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1668 | if (curr_cu->GetUserData() == NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1669 | { |
| 1670 | // The symbol vendor doesn't know about this compile unit, we |
| 1671 | // need to parse and add it to the symbol vendor object. |
| 1672 | CompUnitSP dc_cu; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1673 | ParseCompileUnit(curr_cu, dc_cu); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1674 | if (dc_cu.get()) |
| 1675 | { |
| 1676 | // Figure out the compile unit index if we weren't given one |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 1677 | if (cu_idx == UINT32_MAX) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1678 | DebugInfo()->GetCompileUnit(curr_cu->GetOffset(), &cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1679 | |
| 1680 | m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(dc_cu, cu_idx); |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 1681 | |
| 1682 | if (m_debug_map_symfile) |
| 1683 | m_debug_map_symfile->SetCompileUnit(this, dc_cu); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1684 | } |
| 1685 | } |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1686 | return (CompileUnit*)curr_cu->GetUserData(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1687 | } |
| 1688 | |
| 1689 | bool |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1690 | SymbolFileDWARF::GetFunction (DWARFCompileUnit* curr_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1691 | { |
| 1692 | sc.Clear(); |
| 1693 | // Check if the symbol vendor already knows about this compile unit? |
| 1694 | sc.module_sp = m_obj_file->GetModule()->GetSP(); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1695 | sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, UINT32_MAX); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1696 | |
| 1697 | sc.function = sc.comp_unit->FindFunctionByUID (func_die->GetOffset()).get(); |
| 1698 | if (sc.function == NULL) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1699 | sc.function = ParseCompileUnitFunction(sc, curr_cu, func_die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1700 | |
| 1701 | return sc.function != NULL; |
| 1702 | } |
| 1703 | |
| 1704 | uint32_t |
| 1705 | SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) |
| 1706 | { |
| 1707 | Timer scoped_timer(__PRETTY_FUNCTION__, |
| 1708 | "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%llx }, resolve_scope = 0x%8.8x)", |
| 1709 | so_addr.GetSection(), |
| 1710 | so_addr.GetOffset(), |
| 1711 | resolve_scope); |
| 1712 | uint32_t resolved = 0; |
| 1713 | if (resolve_scope & ( eSymbolContextCompUnit | |
| 1714 | eSymbolContextFunction | |
| 1715 | eSymbolContextBlock | |
| 1716 | eSymbolContextLineEntry)) |
| 1717 | { |
| 1718 | lldb::addr_t file_vm_addr = so_addr.GetFileAddress(); |
| 1719 | |
| 1720 | DWARFDebugAranges* debug_aranges = DebugAranges(); |
| 1721 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 1722 | if (debug_aranges) |
| 1723 | { |
| 1724 | dw_offset_t cu_offset = debug_aranges->FindAddress(file_vm_addr); |
| 1725 | if (cu_offset != DW_INVALID_OFFSET) |
| 1726 | { |
| 1727 | uint32_t cu_idx; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1728 | DWARFCompileUnit* curr_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get(); |
| 1729 | if (curr_cu) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1730 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1731 | sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1732 | assert(sc.comp_unit != NULL); |
| 1733 | resolved |= eSymbolContextCompUnit; |
| 1734 | |
| 1735 | if (resolve_scope & eSymbolContextLineEntry) |
| 1736 | { |
| 1737 | LineTable *line_table = sc.comp_unit->GetLineTable(); |
| 1738 | if (line_table == NULL) |
| 1739 | { |
| 1740 | if (ParseCompileUnitLineTable(sc)) |
| 1741 | line_table = sc.comp_unit->GetLineTable(); |
| 1742 | } |
| 1743 | if (line_table != NULL) |
| 1744 | { |
| 1745 | if (so_addr.IsLinkedAddress()) |
| 1746 | { |
| 1747 | Address linked_addr (so_addr); |
| 1748 | linked_addr.ResolveLinkedAddress(); |
| 1749 | if (line_table->FindLineEntryByAddress (linked_addr, sc.line_entry)) |
| 1750 | { |
| 1751 | resolved |= eSymbolContextLineEntry; |
| 1752 | } |
| 1753 | } |
| 1754 | else if (line_table->FindLineEntryByAddress (so_addr, sc.line_entry)) |
| 1755 | { |
| 1756 | resolved |= eSymbolContextLineEntry; |
| 1757 | } |
| 1758 | } |
| 1759 | } |
| 1760 | |
| 1761 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) |
| 1762 | { |
| 1763 | DWARFDebugInfoEntry *function_die = NULL; |
| 1764 | DWARFDebugInfoEntry *block_die = NULL; |
| 1765 | if (resolve_scope & eSymbolContextBlock) |
| 1766 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1767 | curr_cu->LookupAddress(file_vm_addr, &function_die, &block_die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1768 | } |
| 1769 | else |
| 1770 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1771 | curr_cu->LookupAddress(file_vm_addr, &function_die, NULL); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1772 | } |
| 1773 | |
| 1774 | if (function_die != NULL) |
| 1775 | { |
| 1776 | sc.function = sc.comp_unit->FindFunctionByUID (function_die->GetOffset()).get(); |
| 1777 | if (sc.function == NULL) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1778 | sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | if (sc.function != NULL) |
| 1782 | { |
| 1783 | resolved |= eSymbolContextFunction; |
| 1784 | |
| 1785 | if (resolve_scope & eSymbolContextBlock) |
| 1786 | { |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1787 | Block& block = sc.function->GetBlock (true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1788 | |
| 1789 | if (block_die != NULL) |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1790 | sc.block = block.FindBlockByID (block_die->GetOffset()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1791 | else |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1792 | sc.block = block.FindBlockByID (function_die->GetOffset()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1793 | if (sc.block) |
| 1794 | resolved |= eSymbolContextBlock; |
| 1795 | } |
| 1796 | } |
| 1797 | } |
| 1798 | } |
| 1799 | } |
| 1800 | } |
| 1801 | } |
| 1802 | return resolved; |
| 1803 | } |
| 1804 | |
| 1805 | |
| 1806 | |
| 1807 | uint32_t |
| 1808 | SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) |
| 1809 | { |
| 1810 | const uint32_t prev_size = sc_list.GetSize(); |
| 1811 | if (resolve_scope & eSymbolContextCompUnit) |
| 1812 | { |
| 1813 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 1814 | if (debug_info) |
| 1815 | { |
| 1816 | uint32_t cu_idx; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1817 | DWARFCompileUnit* curr_cu = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1818 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1819 | 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] | 1820 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1821 | CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1822 | bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Compare(file_spec, *dc_cu, false) == 0; |
| 1823 | if (check_inlines || file_spec_matches_cu_file_spec) |
| 1824 | { |
| 1825 | SymbolContext sc (m_obj_file->GetModule()); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1826 | sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1827 | assert(sc.comp_unit != NULL); |
| 1828 | |
| 1829 | uint32_t file_idx = UINT32_MAX; |
| 1830 | |
| 1831 | // If we are looking for inline functions only and we don't |
| 1832 | // find it in the support files, we are done. |
| 1833 | if (check_inlines) |
| 1834 | { |
| 1835 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec); |
| 1836 | if (file_idx == UINT32_MAX) |
| 1837 | continue; |
| 1838 | } |
| 1839 | |
| 1840 | if (line != 0) |
| 1841 | { |
| 1842 | LineTable *line_table = sc.comp_unit->GetLineTable(); |
| 1843 | |
| 1844 | if (line_table != NULL && line != 0) |
| 1845 | { |
| 1846 | // We will have already looked up the file index if |
| 1847 | // we are searching for inline entries. |
| 1848 | if (!check_inlines) |
| 1849 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec); |
| 1850 | |
| 1851 | if (file_idx != UINT32_MAX) |
| 1852 | { |
| 1853 | uint32_t found_line; |
| 1854 | uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry); |
| 1855 | found_line = sc.line_entry.line; |
| 1856 | |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 1857 | while (line_idx != UINT32_MAX) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1858 | { |
| 1859 | sc.function = NULL; |
| 1860 | sc.block = NULL; |
| 1861 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) |
| 1862 | { |
| 1863 | const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress(); |
| 1864 | if (file_vm_addr != LLDB_INVALID_ADDRESS) |
| 1865 | { |
| 1866 | DWARFDebugInfoEntry *function_die = NULL; |
| 1867 | DWARFDebugInfoEntry *block_die = NULL; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1868 | 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] | 1869 | |
| 1870 | if (function_die != NULL) |
| 1871 | { |
| 1872 | sc.function = sc.comp_unit->FindFunctionByUID (function_die->GetOffset()).get(); |
| 1873 | if (sc.function == NULL) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1874 | sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1875 | } |
| 1876 | |
| 1877 | if (sc.function != NULL) |
| 1878 | { |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1879 | Block& block = sc.function->GetBlock (true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1880 | |
| 1881 | if (block_die != NULL) |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1882 | sc.block = block.FindBlockByID (block_die->GetOffset()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1883 | else |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1884 | sc.block = block.FindBlockByID (function_die->GetOffset()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1885 | } |
| 1886 | } |
| 1887 | } |
| 1888 | |
| 1889 | sc_list.Append(sc); |
| 1890 | line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry); |
| 1891 | } |
| 1892 | } |
| 1893 | } |
| 1894 | else if (file_spec_matches_cu_file_spec && !check_inlines) |
| 1895 | { |
| 1896 | // only append the context if we aren't looking for inline call sites |
| 1897 | // by file and line and if the file spec matches that of the compile unit |
| 1898 | sc_list.Append(sc); |
| 1899 | } |
| 1900 | } |
| 1901 | else if (file_spec_matches_cu_file_spec && !check_inlines) |
| 1902 | { |
| 1903 | // only append the context if we aren't looking for inline call sites |
| 1904 | // by file and line and if the file spec matches that of the compile unit |
| 1905 | sc_list.Append(sc); |
| 1906 | } |
| 1907 | |
| 1908 | if (!check_inlines) |
| 1909 | break; |
| 1910 | } |
| 1911 | } |
| 1912 | } |
| 1913 | } |
| 1914 | return sc_list.GetSize() - prev_size; |
| 1915 | } |
| 1916 | |
| 1917 | void |
| 1918 | SymbolFileDWARF::Index () |
| 1919 | { |
| 1920 | if (m_indexed) |
| 1921 | return; |
| 1922 | m_indexed = true; |
| 1923 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 1924 | "SymbolFileDWARF::Index (%s)", |
| 1925 | GetObjectFile()->GetFileSpec().GetFilename().AsCString()); |
| 1926 | |
| 1927 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 1928 | if (debug_info) |
| 1929 | { |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 1930 | m_aranges.reset(new DWARFDebugAranges()); |
| 1931 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1932 | uint32_t cu_idx = 0; |
| 1933 | const uint32_t num_compile_units = GetNumCompileUnits(); |
| 1934 | for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) |
| 1935 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1936 | DWARFCompileUnit* curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1937 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1938 | bool clear_dies = curr_cu->ExtractDIEsIfNeeded (false) > 1; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1939 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1940 | curr_cu->Index (cu_idx, |
| Greg Clayton | 83c5cd9 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 1941 | m_function_basename_index, |
| 1942 | m_function_fullname_index, |
| 1943 | m_function_method_index, |
| 1944 | m_function_selector_index, |
| 1945 | m_objc_class_selectors_index, |
| 1946 | m_global_index, |
| 1947 | m_type_index, |
| 1948 | m_namespace_index, |
| 1949 | DebugRanges(), |
| 1950 | m_aranges.get()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1951 | |
| 1952 | // Keep memory down by clearing DIEs if this generate function |
| 1953 | // caused them to be parsed |
| 1954 | if (clear_dies) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1955 | curr_cu->ClearDIEs (true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1956 | } |
| 1957 | |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 1958 | m_aranges->Sort(); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 1959 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1960 | #if defined (ENABLE_DEBUG_PRINTF) |
| Greg Clayton | 7bd65b9 | 2011-02-09 23:39:34 +0000 | [diff] [blame] | 1961 | StreamFile s(stdout, false); |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame^] | 1962 | s.Printf ("DWARF index for '%s/%s':", |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1963 | GetObjectFile()->GetFileSpec().GetDirectory().AsCString(), |
| 1964 | GetObjectFile()->GetFileSpec().GetFilename().AsCString()); |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1965 | s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s); |
| 1966 | s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s); |
| 1967 | s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s); |
| 1968 | s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s); |
| 1969 | s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s); |
| 1970 | s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s); |
| Greg Clayton | 69b0488 | 2010-10-15 02:03:22 +0000 | [diff] [blame] | 1971 | s.Printf("\nTypes:\n"); m_type_index.Dump (&s); |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1972 | s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 1973 | #endif |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1974 | } |
| 1975 | } |
| 1976 | |
| 1977 | uint32_t |
| 1978 | SymbolFileDWARF::FindGlobalVariables (const ConstString &name, bool append, uint32_t max_matches, VariableList& variables) |
| 1979 | { |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 1980 | DWARFDebugInfo* info = DebugInfo(); |
| 1981 | if (info == NULL) |
| 1982 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1983 | |
| 1984 | // If we aren't appending the results to this list, then clear the list |
| 1985 | if (!append) |
| 1986 | variables.Clear(); |
| 1987 | |
| 1988 | // Remember how many variables are in the list before we search in case |
| 1989 | // we are appending the results to a variable list. |
| 1990 | const uint32_t original_size = variables.GetSize(); |
| 1991 | |
| 1992 | // Index the DWARF if we haven't already |
| 1993 | if (!m_indexed) |
| 1994 | Index (); |
| 1995 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 1996 | SymbolContext sc; |
| 1997 | sc.module_sp = m_obj_file->GetModule()->GetSP(); |
| 1998 | assert (sc.module_sp); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1999 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2000 | DWARFCompileUnit* curr_cu = NULL; |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2001 | DWARFCompileUnit* prev_cu = NULL; |
| 2002 | const DWARFDebugInfoEntry* die = NULL; |
| 2003 | std::vector<NameToDIE::Info> die_info_array; |
| 2004 | const size_t num_matches = m_global_index.Find(name, die_info_array); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2005 | for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2006 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2007 | curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2008 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2009 | if (curr_cu != prev_cu) |
| 2010 | curr_cu->ExtractDIEsIfNeeded (false); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2011 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2012 | die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2013 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2014 | sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, UINT32_MAX); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2015 | assert(sc.comp_unit != NULL); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2016 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2017 | ParseVariables(sc, curr_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2018 | |
| 2019 | if (variables.GetSize() - original_size >= max_matches) |
| 2020 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2021 | } |
| 2022 | |
| 2023 | // Return the number of variable that were appended to the list |
| 2024 | return variables.GetSize() - original_size; |
| 2025 | } |
| 2026 | |
| 2027 | uint32_t |
| 2028 | SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables) |
| 2029 | { |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2030 | DWARFDebugInfo* info = DebugInfo(); |
| 2031 | if (info == NULL) |
| 2032 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2033 | |
| 2034 | // If we aren't appending the results to this list, then clear the list |
| 2035 | if (!append) |
| 2036 | variables.Clear(); |
| 2037 | |
| 2038 | // Remember how many variables are in the list before we search in case |
| 2039 | // we are appending the results to a variable list. |
| 2040 | const uint32_t original_size = variables.GetSize(); |
| 2041 | |
| 2042 | // Index the DWARF if we haven't already |
| 2043 | if (!m_indexed) |
| 2044 | Index (); |
| 2045 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2046 | SymbolContext sc; |
| 2047 | sc.module_sp = m_obj_file->GetModule()->GetSP(); |
| 2048 | assert (sc.module_sp); |
| 2049 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2050 | DWARFCompileUnit* curr_cu = NULL; |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2051 | DWARFCompileUnit* prev_cu = NULL; |
| 2052 | const DWARFDebugInfoEntry* die = NULL; |
| 2053 | std::vector<NameToDIE::Info> die_info_array; |
| 2054 | const size_t num_matches = m_global_index.Find(regex, die_info_array); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2055 | for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2056 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2057 | curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2058 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2059 | if (curr_cu != prev_cu) |
| 2060 | curr_cu->ExtractDIEsIfNeeded (false); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2061 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2062 | die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2063 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2064 | sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, UINT32_MAX); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2065 | assert(sc.comp_unit != NULL); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2066 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2067 | ParseVariables(sc, curr_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2068 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2069 | if (variables.GetSize() - original_size >= max_matches) |
| 2070 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2071 | } |
| 2072 | |
| 2073 | // Return the number of variable that were appended to the list |
| 2074 | return variables.GetSize() - original_size; |
| 2075 | } |
| 2076 | |
| 2077 | |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2078 | void |
| 2079 | SymbolFileDWARF::FindFunctions |
| 2080 | ( |
| 2081 | const ConstString &name, |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2082 | const NameToDIE &name_to_die, |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2083 | SymbolContextList& sc_list |
| 2084 | ) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2085 | { |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2086 | DWARFDebugInfo* info = DebugInfo(); |
| 2087 | if (info == NULL) |
| 2088 | return; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2089 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2090 | SymbolContext sc; |
| 2091 | sc.module_sp = m_obj_file->GetModule()->GetSP(); |
| 2092 | assert (sc.module_sp); |
| 2093 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2094 | DWARFCompileUnit* curr_cu = NULL; |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2095 | DWARFCompileUnit* prev_cu = NULL; |
| 2096 | const DWARFDebugInfoEntry* die = NULL; |
| 2097 | std::vector<NameToDIE::Info> die_info_array; |
| Greg Clayton | d7e0546 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 2098 | const size_t num_matches = name_to_die.Find (name, die_info_array); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2099 | for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu) |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2100 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2101 | curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2102 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2103 | if (curr_cu != prev_cu) |
| 2104 | curr_cu->ExtractDIEsIfNeeded (false); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2105 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2106 | die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx); |
| Greg Clayton | d7e0546 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 2107 | |
| 2108 | const DWARFDebugInfoEntry* inlined_die = NULL; |
| 2109 | if (die->Tag() == DW_TAG_inlined_subroutine) |
| 2110 | { |
| 2111 | inlined_die = die; |
| 2112 | |
| 2113 | while ((die = die->GetParent()) != NULL) |
| 2114 | { |
| 2115 | if (die->Tag() == DW_TAG_subprogram) |
| 2116 | break; |
| 2117 | } |
| 2118 | } |
| 2119 | assert (die->Tag() == DW_TAG_subprogram); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2120 | if (GetFunction (curr_cu, die, sc)) |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2121 | { |
| Greg Clayton | d7e0546 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 2122 | Address addr; |
| 2123 | // Parse all blocks if needed |
| 2124 | if (inlined_die) |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2125 | { |
| Greg Clayton | d7e0546 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 2126 | sc.block = sc.function->GetBlock (true).FindBlockByID (inlined_die->GetOffset()); |
| 2127 | assert (sc.block != NULL); |
| 2128 | if (sc.block->GetStartAddress (addr) == false) |
| 2129 | addr.Clear(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2130 | } |
| Greg Clayton | d7e0546 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 2131 | else |
| 2132 | { |
| 2133 | sc.block = NULL; |
| 2134 | addr = sc.function->GetAddressRange().GetBaseAddress(); |
| 2135 | } |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2136 | |
| Greg Clayton | d7e0546 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 2137 | if (addr.IsValid()) |
| 2138 | { |
| 2139 | |
| 2140 | // We found the function, so we should find the line table |
| 2141 | // and line table entry as well |
| 2142 | LineTable *line_table = sc.comp_unit->GetLineTable(); |
| 2143 | if (line_table == NULL) |
| 2144 | { |
| 2145 | if (ParseCompileUnitLineTable(sc)) |
| 2146 | line_table = sc.comp_unit->GetLineTable(); |
| 2147 | } |
| 2148 | if (line_table != NULL) |
| 2149 | line_table->FindLineEntryByAddress (addr, sc.line_entry); |
| 2150 | |
| 2151 | sc_list.Append(sc); |
| 2152 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2153 | } |
| 2154 | } |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2155 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2156 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2157 | |
| 2158 | void |
| 2159 | SymbolFileDWARF::FindFunctions |
| 2160 | ( |
| 2161 | const RegularExpression ®ex, |
| 2162 | const NameToDIE &name_to_die, |
| 2163 | SymbolContextList& sc_list |
| 2164 | ) |
| 2165 | { |
| 2166 | DWARFDebugInfo* info = DebugInfo(); |
| 2167 | if (info == NULL) |
| 2168 | return; |
| 2169 | |
| 2170 | SymbolContext sc; |
| 2171 | sc.module_sp = m_obj_file->GetModule()->GetSP(); |
| 2172 | assert (sc.module_sp); |
| 2173 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2174 | DWARFCompileUnit* curr_cu = NULL; |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2175 | DWARFCompileUnit* prev_cu = NULL; |
| 2176 | const DWARFDebugInfoEntry* die = NULL; |
| 2177 | std::vector<NameToDIE::Info> die_info_array; |
| 2178 | const size_t num_matches = name_to_die.Find(regex, die_info_array); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2179 | for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu) |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2180 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2181 | curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2182 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2183 | if (curr_cu != prev_cu) |
| 2184 | curr_cu->ExtractDIEsIfNeeded (false); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2185 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2186 | die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx); |
| Greg Clayton | ab84339 | 2010-12-03 17:49:14 +0000 | [diff] [blame] | 2187 | |
| 2188 | const DWARFDebugInfoEntry* inlined_die = NULL; |
| 2189 | if (die->Tag() == DW_TAG_inlined_subroutine) |
| 2190 | { |
| 2191 | inlined_die = die; |
| 2192 | |
| 2193 | while ((die = die->GetParent()) != NULL) |
| 2194 | { |
| 2195 | if (die->Tag() == DW_TAG_subprogram) |
| 2196 | break; |
| 2197 | } |
| 2198 | } |
| 2199 | assert (die->Tag() == DW_TAG_subprogram); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2200 | if (GetFunction (curr_cu, die, sc)) |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2201 | { |
| Greg Clayton | ab84339 | 2010-12-03 17:49:14 +0000 | [diff] [blame] | 2202 | Address addr; |
| 2203 | // Parse all blocks if needed |
| 2204 | if (inlined_die) |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2205 | { |
| Greg Clayton | ab84339 | 2010-12-03 17:49:14 +0000 | [diff] [blame] | 2206 | sc.block = sc.function->GetBlock (true).FindBlockByID (inlined_die->GetOffset()); |
| 2207 | assert (sc.block != NULL); |
| 2208 | if (sc.block->GetStartAddress (addr) == false) |
| 2209 | addr.Clear(); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2210 | } |
| Greg Clayton | ab84339 | 2010-12-03 17:49:14 +0000 | [diff] [blame] | 2211 | else |
| 2212 | { |
| 2213 | sc.block = NULL; |
| 2214 | addr = sc.function->GetAddressRange().GetBaseAddress(); |
| 2215 | } |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2216 | |
| Greg Clayton | ab84339 | 2010-12-03 17:49:14 +0000 | [diff] [blame] | 2217 | if (addr.IsValid()) |
| 2218 | { |
| 2219 | |
| 2220 | // We found the function, so we should find the line table |
| 2221 | // and line table entry as well |
| 2222 | LineTable *line_table = sc.comp_unit->GetLineTable(); |
| 2223 | if (line_table == NULL) |
| 2224 | { |
| 2225 | if (ParseCompileUnitLineTable(sc)) |
| 2226 | line_table = sc.comp_unit->GetLineTable(); |
| 2227 | } |
| 2228 | if (line_table != NULL) |
| 2229 | line_table->FindLineEntryByAddress (addr, sc.line_entry); |
| 2230 | |
| 2231 | sc_list.Append(sc); |
| 2232 | } |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2233 | } |
| 2234 | } |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2235 | } |
| 2236 | |
| 2237 | uint32_t |
| 2238 | SymbolFileDWARF::FindFunctions |
| 2239 | ( |
| 2240 | const ConstString &name, |
| 2241 | uint32_t name_type_mask, |
| 2242 | bool append, |
| 2243 | SymbolContextList& sc_list |
| 2244 | ) |
| 2245 | { |
| 2246 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 2247 | "SymbolFileDWARF::FindFunctions (name = '%s')", |
| 2248 | name.AsCString()); |
| 2249 | |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2250 | // If we aren't appending the results to this list, then clear the list |
| 2251 | if (!append) |
| 2252 | sc_list.Clear(); |
| 2253 | |
| 2254 | // Remember how many sc_list are in the list before we search in case |
| 2255 | // we are appending the results to a variable list. |
| 2256 | uint32_t original_size = sc_list.GetSize(); |
| 2257 | |
| 2258 | // Index the DWARF if we haven't already |
| 2259 | if (!m_indexed) |
| 2260 | Index (); |
| 2261 | |
| 2262 | if (name_type_mask & eFunctionNameTypeBase) |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2263 | FindFunctions (name, m_function_basename_index, sc_list); |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2264 | |
| 2265 | if (name_type_mask & eFunctionNameTypeFull) |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2266 | FindFunctions (name, m_function_fullname_index, sc_list); |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2267 | |
| 2268 | if (name_type_mask & eFunctionNameTypeMethod) |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2269 | FindFunctions (name, m_function_method_index, sc_list); |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2270 | |
| 2271 | if (name_type_mask & eFunctionNameTypeSelector) |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2272 | FindFunctions (name, m_function_selector_index, sc_list); |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2273 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2274 | // Return the number of variable that were appended to the list |
| 2275 | return sc_list.GetSize() - original_size; |
| 2276 | } |
| 2277 | |
| 2278 | |
| 2279 | uint32_t |
| 2280 | SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool append, SymbolContextList& sc_list) |
| 2281 | { |
| 2282 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 2283 | "SymbolFileDWARF::FindFunctions (regex = '%s')", |
| 2284 | regex.GetText()); |
| 2285 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2286 | // If we aren't appending the results to this list, then clear the list |
| 2287 | if (!append) |
| 2288 | sc_list.Clear(); |
| 2289 | |
| 2290 | // Remember how many sc_list are in the list before we search in case |
| 2291 | // we are appending the results to a variable list. |
| 2292 | uint32_t original_size = sc_list.GetSize(); |
| 2293 | |
| 2294 | // Index the DWARF if we haven't already |
| 2295 | if (!m_indexed) |
| 2296 | Index (); |
| 2297 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2298 | FindFunctions (regex, m_function_basename_index, sc_list); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2299 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2300 | FindFunctions (regex, m_function_fullname_index, sc_list); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2301 | |
| 2302 | // Return the number of variable that were appended to the list |
| 2303 | return sc_list.GetSize() - original_size; |
| 2304 | } |
| Jim Ingham | 318c9f2 | 2011-08-26 19:44:13 +0000 | [diff] [blame] | 2305 | |
| Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 2306 | void |
| 2307 | SymbolFileDWARF::ReportError (const char *format, ...) |
| 2308 | { |
| 2309 | ::fprintf (stderr, |
| 2310 | "error: %s/%s ", |
| 2311 | m_obj_file->GetFileSpec().GetDirectory().GetCString(), |
| 2312 | m_obj_file->GetFileSpec().GetFilename().GetCString()); |
| 2313 | |
| 2314 | va_list args; |
| 2315 | va_start (args, format); |
| 2316 | vfprintf (stderr, format, args); |
| 2317 | va_end (args); |
| 2318 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2319 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2320 | uint32_t |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 2321 | SymbolFileDWARF::FindTypes(const SymbolContext& sc, const ConstString &name, bool append, uint32_t max_matches, TypeList& types) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2322 | { |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2323 | DWARFDebugInfo* info = DebugInfo(); |
| 2324 | if (info == NULL) |
| 2325 | return 0; |
| 2326 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2327 | // If we aren't appending the results to this list, then clear the list |
| 2328 | if (!append) |
| 2329 | types.Clear(); |
| 2330 | |
| Greg Clayton | 6dbd398 | 2010-09-15 05:51:24 +0000 | [diff] [blame] | 2331 | // Index if we already haven't to make sure the compile units |
| 2332 | // get indexed and make their global DIE index list |
| 2333 | if (!m_indexed) |
| 2334 | Index (); |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 2335 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2336 | const uint32_t initial_types_size = types.GetSize(); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2337 | DWARFCompileUnit* curr_cu = NULL; |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2338 | DWARFCompileUnit* prev_cu = NULL; |
| 2339 | const DWARFDebugInfoEntry* die = NULL; |
| 2340 | std::vector<NameToDIE::Info> die_info_array; |
| Greg Clayton | 69b0488 | 2010-10-15 02:03:22 +0000 | [diff] [blame] | 2341 | const size_t num_matches = m_type_index.Find (name, die_info_array); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2342 | for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2343 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2344 | curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2345 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2346 | if (curr_cu != prev_cu) |
| 2347 | curr_cu->ExtractDIEsIfNeeded (false); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2348 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2349 | die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2350 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2351 | Type *matching_type = ResolveType (curr_cu, die); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2352 | if (matching_type) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2353 | { |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2354 | // We found a type pointer, now find the shared pointer form our type list |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 2355 | TypeSP type_sp (GetTypeList()->FindType(matching_type->GetID())); |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 2356 | if (type_sp) |
| 2357 | { |
| 2358 | types.InsertUnique (type_sp); |
| 2359 | if (types.GetSize() >= max_matches) |
| 2360 | break; |
| 2361 | } |
| 2362 | else |
| 2363 | { |
| 2364 | fprintf (stderr, "error: can't find shared pointer for type 0x%8.8x.\n", matching_type->GetID()); |
| 2365 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2366 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2367 | } |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2368 | return types.GetSize() - initial_types_size; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2369 | } |
| 2370 | |
| 2371 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 2372 | ClangNamespaceDecl |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2373 | SymbolFileDWARF::FindNamespace (const SymbolContext& sc, |
| 2374 | const ConstString &name) |
| 2375 | { |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 2376 | ClangNamespaceDecl namespace_decl; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2377 | DWARFDebugInfo* info = DebugInfo(); |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 2378 | if (info) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2379 | { |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 2380 | // Index if we already haven't to make sure the compile units |
| 2381 | // get indexed and make their global DIE index list |
| 2382 | if (!m_indexed) |
| 2383 | Index (); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2384 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 2385 | DWARFCompileUnit* curr_cu = NULL; |
| 2386 | DWARFCompileUnit* prev_cu = NULL; |
| 2387 | const DWARFDebugInfoEntry* die = NULL; |
| 2388 | std::vector<NameToDIE::Info> die_info_array; |
| 2389 | const size_t num_matches = m_namespace_index.Find (name, die_info_array); |
| 2390 | for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu) |
| 2391 | { |
| 2392 | curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx); |
| 2393 | |
| 2394 | if (curr_cu != prev_cu) |
| 2395 | curr_cu->ExtractDIEsIfNeeded (false); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2396 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 2397 | die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx); |
| 2398 | |
| 2399 | clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (curr_cu, die); |
| 2400 | if (clang_namespace_decl) |
| 2401 | { |
| 2402 | namespace_decl.SetASTContext (GetClangASTContext().getASTContext()); |
| 2403 | namespace_decl.SetNamespaceDecl (clang_namespace_decl); |
| 2404 | } |
| 2405 | } |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2406 | } |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 2407 | return namespace_decl; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2408 | } |
| 2409 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2410 | uint32_t |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 2411 | 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] | 2412 | { |
| 2413 | // Remember how many sc_list are in the list before we search in case |
| 2414 | // we are appending the results to a variable list. |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 2415 | uint32_t original_size = types.GetSize(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2416 | |
| 2417 | const uint32_t num_die_offsets = die_offsets.size(); |
| 2418 | // Parse all of the types we found from the pubtypes matches |
| 2419 | uint32_t i; |
| 2420 | uint32_t num_matches = 0; |
| 2421 | for (i = 0; i < num_die_offsets; ++i) |
| 2422 | { |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 2423 | Type *matching_type = ResolveTypeUID (die_offsets[i]); |
| 2424 | if (matching_type) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2425 | { |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 2426 | // We found a type pointer, now find the shared pointer form our type list |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 2427 | TypeSP type_sp (GetTypeList()->FindType(matching_type->GetID())); |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 2428 | assert (type_sp.get() != NULL); |
| 2429 | types.InsertUnique (type_sp); |
| 2430 | ++num_matches; |
| 2431 | if (num_matches >= max_matches) |
| 2432 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2433 | } |
| 2434 | } |
| 2435 | |
| 2436 | // Return the number of variable that were appended to the list |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 2437 | return types.GetSize() - original_size; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2438 | } |
| 2439 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2440 | |
| 2441 | size_t |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 2442 | SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc, |
| 2443 | clang::DeclContext *containing_decl_ctx, |
| 2444 | TypeSP& type_sp, |
| 2445 | DWARFCompileUnit* dwarf_cu, |
| 2446 | const DWARFDebugInfoEntry *parent_die, |
| 2447 | bool skip_artificial, |
| 2448 | bool &is_static, |
| 2449 | TypeList* type_list, |
| 2450 | std::vector<clang_type_t>& function_param_types, |
| 2451 | std::vector<clang::ParmVarDecl*>& function_param_decls, |
| 2452 | unsigned &type_quals) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2453 | { |
| 2454 | if (parent_die == NULL) |
| 2455 | return 0; |
| 2456 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 2457 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| 2458 | |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 2459 | size_t arg_idx = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2460 | const DWARFDebugInfoEntry *die; |
| 2461 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 2462 | { |
| 2463 | dw_tag_t tag = die->Tag(); |
| 2464 | switch (tag) |
| 2465 | { |
| 2466 | case DW_TAG_formal_parameter: |
| 2467 | { |
| 2468 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 2469 | 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] | 2470 | if (num_attributes > 0) |
| 2471 | { |
| 2472 | const char *name = NULL; |
| 2473 | Declaration decl; |
| 2474 | dw_offset_t param_type_die_offset = DW_INVALID_OFFSET; |
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 2475 | bool is_artificial = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2476 | // one of None, Auto, Register, Extern, Static, PrivateExtern |
| 2477 | |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 2478 | clang::StorageClass storage = clang::SC_None; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2479 | uint32_t i; |
| 2480 | for (i=0; i<num_attributes; ++i) |
| 2481 | { |
| 2482 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 2483 | DWARFFormValue form_value; |
| 2484 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 2485 | { |
| 2486 | switch (attr) |
| 2487 | { |
| 2488 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 2489 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 2490 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 2491 | case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; |
| 2492 | 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] | 2493 | case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2494 | case DW_AT_location: |
| 2495 | // if (form_value.BlockData()) |
| 2496 | // { |
| 2497 | // const DataExtractor& debug_info_data = debug_info(); |
| 2498 | // uint32_t block_length = form_value.Unsigned(); |
| 2499 | // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length); |
| 2500 | // } |
| 2501 | // else |
| 2502 | // { |
| 2503 | // } |
| 2504 | // break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2505 | case DW_AT_const_value: |
| 2506 | case DW_AT_default_value: |
| 2507 | case DW_AT_description: |
| 2508 | case DW_AT_endianity: |
| 2509 | case DW_AT_is_optional: |
| 2510 | case DW_AT_segment: |
| 2511 | case DW_AT_variable_parameter: |
| 2512 | default: |
| 2513 | case DW_AT_abstract_origin: |
| 2514 | case DW_AT_sibling: |
| 2515 | break; |
| 2516 | } |
| 2517 | } |
| 2518 | } |
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 2519 | |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2520 | bool skip = false; |
| 2521 | if (skip_artificial) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2522 | { |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2523 | if (is_artificial) |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 2524 | { |
| 2525 | // In order to determine if a C++ member function is |
| 2526 | // "const" we have to look at the const-ness of "this"... |
| 2527 | // Ugly, but that |
| 2528 | if (arg_idx == 0) |
| 2529 | { |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 2530 | if (containing_decl_ctx->getDeclKind() == clang::Decl::CXXRecord) |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 2531 | { |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 2532 | // Often times compilers omit the "this" name for the |
| 2533 | // specification DIEs, so we can't rely upon the name |
| 2534 | // being in the formal parameter DIE... |
| 2535 | if (name == NULL || ::strcmp(name, "this")==0) |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 2536 | { |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 2537 | Type *this_type = ResolveTypeUID (param_type_die_offset); |
| 2538 | if (this_type) |
| 2539 | { |
| 2540 | uint32_t encoding_mask = this_type->GetEncodingMask(); |
| 2541 | if (encoding_mask & Type::eEncodingIsPointerUID) |
| 2542 | { |
| 2543 | is_static = false; |
| 2544 | |
| 2545 | if (encoding_mask & (1u << Type::eEncodingIsConstUID)) |
| 2546 | type_quals |= clang::Qualifiers::Const; |
| 2547 | if (encoding_mask & (1u << Type::eEncodingIsVolatileUID)) |
| 2548 | type_quals |= clang::Qualifiers::Volatile; |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 2549 | } |
| 2550 | } |
| 2551 | } |
| 2552 | } |
| 2553 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2554 | skip = true; |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 2555 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2556 | else |
| 2557 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2558 | |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2559 | // HACK: Objective C formal parameters "self" and "_cmd" |
| 2560 | // are not marked as artificial in the DWARF... |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2561 | CompileUnit *curr_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| 2562 | 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] | 2563 | { |
| 2564 | if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0)) |
| 2565 | skip = true; |
| 2566 | } |
| 2567 | } |
| 2568 | } |
| 2569 | |
| 2570 | if (!skip) |
| 2571 | { |
| 2572 | Type *type = ResolveTypeUID(param_type_die_offset); |
| 2573 | if (type) |
| 2574 | { |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2575 | function_param_types.push_back (type->GetClangForwardType()); |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2576 | |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 2577 | clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name, type->GetClangForwardType(), storage); |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2578 | assert(param_var_decl); |
| 2579 | function_param_decls.push_back(param_var_decl); |
| 2580 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2581 | } |
| 2582 | } |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 2583 | arg_idx++; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2584 | } |
| 2585 | break; |
| 2586 | |
| 2587 | default: |
| 2588 | break; |
| 2589 | } |
| 2590 | } |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 2591 | return arg_idx; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2592 | } |
| 2593 | |
| 2594 | size_t |
| 2595 | SymbolFileDWARF::ParseChildEnumerators |
| 2596 | ( |
| 2597 | const SymbolContext& sc, |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2598 | clang_type_t enumerator_clang_type, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2599 | uint32_t enumerator_byte_size, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2600 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2601 | const DWARFDebugInfoEntry *parent_die |
| 2602 | ) |
| 2603 | { |
| 2604 | if (parent_die == NULL) |
| 2605 | return 0; |
| 2606 | |
| 2607 | size_t enumerators_added = 0; |
| 2608 | const DWARFDebugInfoEntry *die; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 2609 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| 2610 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2611 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 2612 | { |
| 2613 | const dw_tag_t tag = die->Tag(); |
| 2614 | if (tag == DW_TAG_enumerator) |
| 2615 | { |
| 2616 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 2617 | 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] | 2618 | if (num_child_attributes > 0) |
| 2619 | { |
| 2620 | const char *name = NULL; |
| 2621 | bool got_value = false; |
| 2622 | int64_t enum_value = 0; |
| 2623 | Declaration decl; |
| 2624 | |
| 2625 | uint32_t i; |
| 2626 | for (i=0; i<num_child_attributes; ++i) |
| 2627 | { |
| 2628 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 2629 | DWARFFormValue form_value; |
| 2630 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 2631 | { |
| 2632 | switch (attr) |
| 2633 | { |
| 2634 | case DW_AT_const_value: |
| 2635 | got_value = true; |
| 2636 | enum_value = form_value.Unsigned(); |
| 2637 | break; |
| 2638 | |
| 2639 | case DW_AT_name: |
| 2640 | name = form_value.AsCString(&get_debug_str_data()); |
| 2641 | break; |
| 2642 | |
| 2643 | case DW_AT_description: |
| 2644 | default: |
| 2645 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 2646 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 2647 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 2648 | case DW_AT_sibling: |
| 2649 | break; |
| 2650 | } |
| 2651 | } |
| 2652 | } |
| 2653 | |
| 2654 | if (name && name[0] && got_value) |
| 2655 | { |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 2656 | GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type, |
| 2657 | enumerator_clang_type, |
| 2658 | decl, |
| 2659 | name, |
| 2660 | enum_value, |
| 2661 | enumerator_byte_size * 8); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2662 | ++enumerators_added; |
| 2663 | } |
| 2664 | } |
| 2665 | } |
| 2666 | } |
| 2667 | return enumerators_added; |
| 2668 | } |
| 2669 | |
| 2670 | void |
| 2671 | SymbolFileDWARF::ParseChildArrayInfo |
| 2672 | ( |
| 2673 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2674 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2675 | const DWARFDebugInfoEntry *parent_die, |
| 2676 | int64_t& first_index, |
| 2677 | std::vector<uint64_t>& element_orders, |
| 2678 | uint32_t& byte_stride, |
| 2679 | uint32_t& bit_stride |
| 2680 | ) |
| 2681 | { |
| 2682 | if (parent_die == NULL) |
| 2683 | return; |
| 2684 | |
| 2685 | const DWARFDebugInfoEntry *die; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 2686 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2687 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 2688 | { |
| 2689 | const dw_tag_t tag = die->Tag(); |
| 2690 | switch (tag) |
| 2691 | { |
| 2692 | case DW_TAG_enumerator: |
| 2693 | { |
| 2694 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 2695 | 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] | 2696 | if (num_child_attributes > 0) |
| 2697 | { |
| 2698 | const char *name = NULL; |
| 2699 | bool got_value = false; |
| 2700 | int64_t enum_value = 0; |
| 2701 | |
| 2702 | uint32_t i; |
| 2703 | for (i=0; i<num_child_attributes; ++i) |
| 2704 | { |
| 2705 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 2706 | DWARFFormValue form_value; |
| 2707 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 2708 | { |
| 2709 | switch (attr) |
| 2710 | { |
| 2711 | case DW_AT_const_value: |
| 2712 | got_value = true; |
| 2713 | enum_value = form_value.Unsigned(); |
| 2714 | break; |
| 2715 | |
| 2716 | case DW_AT_name: |
| 2717 | name = form_value.AsCString(&get_debug_str_data()); |
| 2718 | break; |
| 2719 | |
| 2720 | case DW_AT_description: |
| 2721 | default: |
| 2722 | case DW_AT_decl_file: |
| 2723 | case DW_AT_decl_line: |
| 2724 | case DW_AT_decl_column: |
| 2725 | case DW_AT_sibling: |
| 2726 | break; |
| 2727 | } |
| 2728 | } |
| 2729 | } |
| 2730 | } |
| 2731 | } |
| 2732 | break; |
| 2733 | |
| 2734 | case DW_TAG_subrange_type: |
| 2735 | { |
| 2736 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 2737 | 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] | 2738 | if (num_child_attributes > 0) |
| 2739 | { |
| 2740 | const char *name = NULL; |
| 2741 | bool got_value = false; |
| 2742 | uint64_t byte_size = 0; |
| 2743 | int64_t enum_value = 0; |
| 2744 | uint64_t num_elements = 0; |
| 2745 | uint64_t lower_bound = 0; |
| 2746 | uint64_t upper_bound = 0; |
| 2747 | uint32_t i; |
| 2748 | for (i=0; i<num_child_attributes; ++i) |
| 2749 | { |
| 2750 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 2751 | DWARFFormValue form_value; |
| 2752 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 2753 | { |
| 2754 | switch (attr) |
| 2755 | { |
| 2756 | case DW_AT_const_value: |
| 2757 | got_value = true; |
| 2758 | enum_value = form_value.Unsigned(); |
| 2759 | break; |
| 2760 | |
| 2761 | case DW_AT_name: |
| 2762 | name = form_value.AsCString(&get_debug_str_data()); |
| 2763 | break; |
| 2764 | |
| 2765 | case DW_AT_count: |
| 2766 | num_elements = form_value.Unsigned(); |
| 2767 | break; |
| 2768 | |
| 2769 | case DW_AT_bit_stride: |
| 2770 | bit_stride = form_value.Unsigned(); |
| 2771 | break; |
| 2772 | |
| 2773 | case DW_AT_byte_stride: |
| 2774 | byte_stride = form_value.Unsigned(); |
| 2775 | break; |
| 2776 | |
| 2777 | case DW_AT_byte_size: |
| 2778 | byte_size = form_value.Unsigned(); |
| 2779 | break; |
| 2780 | |
| 2781 | case DW_AT_lower_bound: |
| 2782 | lower_bound = form_value.Unsigned(); |
| 2783 | break; |
| 2784 | |
| 2785 | case DW_AT_upper_bound: |
| 2786 | upper_bound = form_value.Unsigned(); |
| 2787 | break; |
| 2788 | |
| 2789 | default: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2790 | case DW_AT_abstract_origin: |
| 2791 | case DW_AT_accessibility: |
| 2792 | case DW_AT_allocated: |
| 2793 | case DW_AT_associated: |
| 2794 | case DW_AT_data_location: |
| 2795 | case DW_AT_declaration: |
| 2796 | case DW_AT_description: |
| 2797 | case DW_AT_sibling: |
| 2798 | case DW_AT_threads_scaled: |
| 2799 | case DW_AT_type: |
| 2800 | case DW_AT_visibility: |
| 2801 | break; |
| 2802 | } |
| 2803 | } |
| 2804 | } |
| 2805 | |
| 2806 | if (upper_bound > lower_bound) |
| 2807 | num_elements = upper_bound - lower_bound + 1; |
| 2808 | |
| 2809 | if (num_elements > 0) |
| 2810 | element_orders.push_back (num_elements); |
| 2811 | } |
| 2812 | } |
| 2813 | break; |
| 2814 | } |
| 2815 | } |
| 2816 | } |
| 2817 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2818 | TypeSP |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2819 | SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry* die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2820 | { |
| 2821 | TypeSP type_sp; |
| 2822 | if (die != NULL) |
| 2823 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2824 | assert(curr_cu != NULL); |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 2825 | Type *type_ptr = m_die_to_type.lookup (die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2826 | if (type_ptr == NULL) |
| 2827 | { |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2828 | CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(curr_cu); |
| 2829 | assert (lldb_cu); |
| 2830 | SymbolContext sc(lldb_cu); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2831 | type_sp = ParseType(sc, curr_cu, die, NULL); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2832 | } |
| 2833 | else if (type_ptr != DIE_IS_BEING_PARSED) |
| 2834 | { |
| 2835 | // Grab the existing type from the master types lists |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 2836 | type_sp = GetTypeList()->FindType(type_ptr->GetID()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2837 | } |
| 2838 | |
| 2839 | } |
| 2840 | return type_sp; |
| 2841 | } |
| 2842 | |
| 2843 | clang::DeclContext * |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 2844 | SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2845 | { |
| 2846 | if (die_offset != DW_INVALID_OFFSET) |
| 2847 | { |
| 2848 | DWARFCompileUnitSP cu_sp; |
| 2849 | const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp); |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 2850 | return GetClangDeclContextContainingDIE (cu_sp.get(), die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2851 | } |
| 2852 | return NULL; |
| 2853 | } |
| 2854 | |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 2855 | clang::DeclContext * |
| 2856 | SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset) |
| 2857 | { |
| 2858 | if (die_offset != DW_INVALID_OFFSET) |
| 2859 | { |
| 2860 | DWARFCompileUnitSP cu_sp; |
| 2861 | const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp); |
| 2862 | return GetClangDeclContextForDIE (sc, cu_sp.get(), die); |
| 2863 | } |
| 2864 | return NULL; |
| 2865 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2866 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2867 | clang::NamespaceDecl * |
| 2868 | SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die) |
| 2869 | { |
| 2870 | if (die->Tag() == DW_TAG_namespace) |
| 2871 | { |
| 2872 | const char *namespace_name = die->GetAttributeValueAsString(this, curr_cu, DW_AT_name, NULL); |
| 2873 | if (namespace_name) |
| 2874 | { |
| 2875 | Declaration decl; // TODO: fill in the decl object |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 2876 | clang::NamespaceDecl *namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, decl, GetClangDeclContextContainingDIE (curr_cu, die->GetParent())); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2877 | if (namespace_decl) |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 2878 | LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2879 | return namespace_decl; |
| 2880 | } |
| 2881 | } |
| 2882 | return NULL; |
| 2883 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2884 | |
| 2885 | clang::DeclContext * |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 2886 | SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die) |
| 2887 | { |
| 2888 | // If this DIE has a specification, or an abstract origin, then trace to those. |
| 2889 | |
| 2890 | dw_offset_t die_offset = die->GetAttributeValueAsReference(this, curr_cu, DW_AT_specification, DW_INVALID_OFFSET); |
| 2891 | if (die_offset != DW_INVALID_OFFSET) |
| 2892 | return GetClangDeclContextForDIEOffset (sc, die_offset); |
| 2893 | |
| 2894 | die_offset = die->GetAttributeValueAsReference(this, curr_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET); |
| 2895 | if (die_offset != DW_INVALID_OFFSET) |
| 2896 | return GetClangDeclContextForDIEOffset (sc, die_offset); |
| 2897 | |
| 2898 | // This is the DIE we want. Parse it, then query our map. |
| 2899 | |
| 2900 | ParseType(sc, curr_cu, die, NULL); |
| 2901 | |
| 2902 | DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find(die); |
| 2903 | if (pos != m_die_to_decl_ctx.end()) |
| 2904 | return pos->second; |
| 2905 | else |
| 2906 | return NULL; |
| 2907 | } |
| 2908 | |
| 2909 | clang::DeclContext * |
| 2910 | SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2911 | { |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2912 | if (m_clang_tu_decl == NULL) |
| 2913 | m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2914 | |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 2915 | //printf ("SymbolFileDWARF::GetClangDeclContextContainingDIE ( die = 0x%8.8x )\n", die->GetOffset()); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2916 | const DWARFDebugInfoEntry * const decl_die = die; |
| Greg Clayton | 4cd1780 | 2011-01-25 06:17:32 +0000 | [diff] [blame] | 2917 | clang::DeclContext *decl_ctx = NULL; |
| 2918 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2919 | while (die != NULL) |
| 2920 | { |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2921 | // If this is the original DIE that we are searching for a declaration |
| 2922 | // for, then don't look in the cache as we don't want our own decl |
| 2923 | // context to be our decl context... |
| 2924 | if (decl_die != die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2925 | { |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2926 | DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find(die); |
| 2927 | if (pos != m_die_to_decl_ctx.end()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2928 | { |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 2929 | //printf ("SymbolFileDWARF::GetClangDeclContextContainingDIE ( die = 0x%8.8x ) => 0x%8.8x\n", decl_die->GetOffset(), die->GetOffset()); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2930 | return pos->second; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2931 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2932 | |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 2933 | //printf ("SymbolFileDWARF::GetClangDeclContextContainingDIE ( die = 0x%8.8x ) checking parent 0x%8.8x\n", decl_die->GetOffset(), die->GetOffset()); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2934 | |
| 2935 | switch (die->Tag()) |
| 2936 | { |
| 2937 | case DW_TAG_namespace: |
| 2938 | { |
| 2939 | const char *namespace_name = die->GetAttributeValueAsString(this, curr_cu, DW_AT_name, NULL); |
| 2940 | if (namespace_name) |
| 2941 | { |
| 2942 | Declaration decl; // TODO: fill in the decl object |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 2943 | clang::NamespaceDecl *namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, decl, GetClangDeclContextContainingDIE (curr_cu, die)); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2944 | if (namespace_decl) |
| 2945 | { |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 2946 | //printf ("SymbolFileDWARF::GetClangDeclContextContainingDIE ( die = 0x%8.8x ) => 0x%8.8x\n", decl_die->GetOffset(), die->GetOffset()); |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 2947 | LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2948 | } |
| 2949 | return namespace_decl; |
| 2950 | } |
| 2951 | } |
| 2952 | break; |
| 2953 | |
| 2954 | case DW_TAG_structure_type: |
| 2955 | case DW_TAG_union_type: |
| 2956 | case DW_TAG_class_type: |
| 2957 | { |
| Greg Clayton | 4cd1780 | 2011-01-25 06:17:32 +0000 | [diff] [blame] | 2958 | Type* type = ResolveType (curr_cu, die); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2959 | pos = m_die_to_decl_ctx.find(die); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2960 | if (pos != m_die_to_decl_ctx.end()) |
| 2961 | { |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 2962 | //printf ("SymbolFileDWARF::GetClangDeclContextContainingDIE ( die = 0x%8.8x ) => 0x%8.8x\n", decl_die->GetOffset(), die->GetOffset()); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2963 | return pos->second; |
| 2964 | } |
| Greg Clayton | 4cd1780 | 2011-01-25 06:17:32 +0000 | [diff] [blame] | 2965 | else |
| 2966 | { |
| 2967 | if (type) |
| 2968 | { |
| 2969 | decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ()); |
| Enrico Granata | 4a04dbc | 2011-08-12 18:43:16 +0000 | [diff] [blame] | 2970 | LinkDeclContextToDIE (decl_ctx, die); |
| Greg Clayton | 4cd1780 | 2011-01-25 06:17:32 +0000 | [diff] [blame] | 2971 | if (decl_ctx) |
| 2972 | return decl_ctx; |
| 2973 | } |
| 2974 | } |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2975 | } |
| 2976 | break; |
| 2977 | |
| 2978 | default: |
| 2979 | break; |
| 2980 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2981 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2982 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2983 | dw_offset_t die_offset = die->GetAttributeValueAsReference(this, curr_cu, DW_AT_specification, DW_INVALID_OFFSET); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2984 | if (die_offset != DW_INVALID_OFFSET) |
| 2985 | { |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 2986 | //printf ("SymbolFileDWARF::GetClangDeclContextContainingDIE ( die = 0x%8.8x ) check DW_AT_specification 0x%8.8x\n", decl_die->GetOffset(), die_offset); |
| 2987 | decl_ctx = GetClangDeclContextContainingDIEOffset (die_offset); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2988 | if (decl_ctx != m_clang_tu_decl) |
| 2989 | return decl_ctx; |
| 2990 | } |
| 2991 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2992 | die_offset = die->GetAttributeValueAsReference(this, curr_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2993 | if (die_offset != DW_INVALID_OFFSET) |
| 2994 | { |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 2995 | //printf ("SymbolFileDWARF::GetClangDeclContextContainingDIE ( die = 0x%8.8x ) check DW_AT_abstract_origin 0x%8.8x\n", decl_die->GetOffset(), die_offset); |
| 2996 | decl_ctx = GetClangDeclContextContainingDIEOffset (die_offset); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2997 | if (decl_ctx != m_clang_tu_decl) |
| 2998 | return decl_ctx; |
| 2999 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3000 | |
| 3001 | die = die->GetParent(); |
| 3002 | } |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 3003 | // Right now we have only one translation unit per module... |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 3004 | //printf ("SymbolFileDWARF::GetClangDeclContextContainingDIE ( die = 0x%8.8x ) => 0x%8.8x\n", decl_die->GetOffset(), curr_cu->GetFirstDIEOffset()); |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 3005 | return m_clang_tu_decl; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3006 | } |
| 3007 | |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 3008 | // This function can be used when a DIE is found that is a forward declaration |
| 3009 | // DIE and we want to try and find a type that has the complete definition. |
| 3010 | TypeSP |
| 3011 | SymbolFileDWARF::FindDefinitionTypeForDIE ( |
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 3012 | DWARFCompileUnit* cu, |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 3013 | const DWARFDebugInfoEntry *die, |
| 3014 | const ConstString &type_name |
| 3015 | ) |
| 3016 | { |
| 3017 | TypeSP type_sp; |
| 3018 | |
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 3019 | if (cu == NULL || die == NULL || !type_name) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 3020 | return type_sp; |
| 3021 | |
| Greg Clayton | 6997489 | 2010-12-03 21:42:06 +0000 | [diff] [blame] | 3022 | if (!m_indexed) |
| 3023 | Index (); |
| 3024 | |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 3025 | const dw_tag_t type_tag = die->Tag(); |
| 3026 | std::vector<NameToDIE::Info> die_info_array; |
| 3027 | const size_t num_matches = m_type_index.Find (type_name, die_info_array); |
| 3028 | if (num_matches > 0) |
| 3029 | { |
| 3030 | DWARFCompileUnit* type_cu = NULL; |
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 3031 | DWARFCompileUnit* curr_cu = cu; |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 3032 | DWARFDebugInfo *info = DebugInfo(); |
| 3033 | for (size_t i=0; i<num_matches; ++i) |
| 3034 | { |
| 3035 | type_cu = info->GetCompileUnitAtIndex (die_info_array[i].cu_idx); |
| 3036 | |
| 3037 | if (type_cu != curr_cu) |
| 3038 | { |
| 3039 | type_cu->ExtractDIEsIfNeeded (false); |
| 3040 | curr_cu = type_cu; |
| 3041 | } |
| 3042 | |
| 3043 | DWARFDebugInfoEntry *type_die = type_cu->GetDIEAtIndexUnchecked (die_info_array[i].die_idx); |
| 3044 | |
| 3045 | if (type_die != die && type_die->Tag() == type_tag) |
| 3046 | { |
| 3047 | // Hold off on comparing parent DIE tags until |
| 3048 | // we know what happens with stuff in namespaces |
| 3049 | // for gcc and clang... |
| 3050 | //DWARFDebugInfoEntry *parent_die = die->GetParent(); |
| 3051 | //DWARFDebugInfoEntry *parent_type_die = type_die->GetParent(); |
| 3052 | //if (parent_die->Tag() == parent_type_die->Tag()) |
| 3053 | { |
| 3054 | Type *resolved_type = ResolveType (type_cu, type_die, false); |
| 3055 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) |
| 3056 | { |
| 3057 | DEBUG_PRINTF ("resolved 0x%8.8x (cu 0x%8.8x) from %s to 0x%8.8x (cu 0x%8.8x)\n", |
| 3058 | die->GetOffset(), |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3059 | curr_cu->GetOffset(), |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 3060 | m_obj_file->GetFileSpec().GetFilename().AsCString(), |
| 3061 | type_die->GetOffset(), |
| 3062 | type_cu->GetOffset()); |
| 3063 | |
| 3064 | m_die_to_type[die] = resolved_type; |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 3065 | type_sp = GetTypeList()->FindType(resolved_type->GetID()); |
| Greg Clayton | 40328bf | 2010-11-08 02:05:08 +0000 | [diff] [blame] | 3066 | if (!type_sp) |
| 3067 | { |
| 3068 | DEBUG_PRINTF("unable to resolve type '%s' from DIE 0x%8.8x\n", type_name.GetCString(), die->GetOffset()); |
| 3069 | } |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 3070 | break; |
| 3071 | } |
| 3072 | } |
| 3073 | } |
| 3074 | } |
| 3075 | } |
| 3076 | return type_sp; |
| 3077 | } |
| 3078 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3079 | TypeSP |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 3080 | 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] | 3081 | { |
| 3082 | TypeSP type_sp; |
| 3083 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 3084 | if (type_is_new_ptr) |
| 3085 | *type_is_new_ptr = false; |
| 3086 | |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 3087 | AccessType accessibility = eAccessNone; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3088 | if (die != NULL) |
| 3089 | { |
| Jim Ingham | 16746d1 | 2011-08-25 23:21:43 +0000 | [diff] [blame] | 3090 | Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO); |
| 3091 | if (log && dwarf_cu) |
| 3092 | { |
| Jim Ingham | 318c9f2 | 2011-08-26 19:44:13 +0000 | [diff] [blame] | 3093 | StreamString s; |
| Jim Ingham | d3d25d9 | 2011-08-27 01:24:54 +0000 | [diff] [blame] | 3094 | die->DumpLocation (this, dwarf_cu, s); |
| Jim Ingham | 318c9f2 | 2011-08-26 19:44:13 +0000 | [diff] [blame] | 3095 | log->Printf ("SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData()); |
| 3096 | |
| Jim Ingham | 16746d1 | 2011-08-25 23:21:43 +0000 | [diff] [blame] | 3097 | } |
| 3098 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 3099 | Type *type_ptr = m_die_to_type.lookup (die); |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 3100 | TypeList* type_list = GetTypeList(); |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 3101 | if (type_ptr == NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3102 | { |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 3103 | ClangASTContext &ast = GetClangASTContext(); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 3104 | if (type_is_new_ptr) |
| 3105 | *type_is_new_ptr = true; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3106 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 3107 | const dw_tag_t tag = die->Tag(); |
| 3108 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3109 | bool is_forward_declaration = false; |
| 3110 | DWARFDebugInfoEntry::Attributes attributes; |
| 3111 | const char *type_name_cstr = NULL; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3112 | ConstString type_name_const_str; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3113 | Type::ResolveState resolve_state = Type::eResolveStateUnresolved; |
| 3114 | size_t byte_size = 0; |
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 3115 | bool byte_size_valid = false; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3116 | Declaration decl; |
| 3117 | |
| Greg Clayton | 4957bf6 | 2010-09-30 21:49:03 +0000 | [diff] [blame] | 3118 | Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 3119 | clang_type_t clang_type = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3120 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3121 | dw_attr_t attr; |
| 3122 | |
| 3123 | switch (tag) |
| 3124 | { |
| 3125 | case DW_TAG_base_type: |
| 3126 | case DW_TAG_pointer_type: |
| 3127 | case DW_TAG_reference_type: |
| 3128 | case DW_TAG_typedef: |
| 3129 | case DW_TAG_const_type: |
| 3130 | case DW_TAG_restrict_type: |
| 3131 | case DW_TAG_volatile_type: |
| 3132 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3133 | // 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] | 3134 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3135 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3136 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3137 | uint32_t encoding = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3138 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; |
| 3139 | |
| 3140 | if (num_attributes > 0) |
| 3141 | { |
| 3142 | uint32_t i; |
| 3143 | for (i=0; i<num_attributes; ++i) |
| 3144 | { |
| 3145 | attr = attributes.AttributeAtIndex(i); |
| 3146 | DWARFFormValue form_value; |
| 3147 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 3148 | { |
| 3149 | switch (attr) |
| 3150 | { |
| 3151 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 3152 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 3153 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 3154 | case DW_AT_name: |
| Jim Ingham | 337030f | 2011-04-15 23:41:23 +0000 | [diff] [blame] | 3155 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3156 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Jim Ingham | 337030f | 2011-04-15 23:41:23 +0000 | [diff] [blame] | 3157 | // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't |
| 3158 | // include the "&"... |
| 3159 | if (tag == DW_TAG_reference_type) |
| 3160 | { |
| 3161 | if (strchr (type_name_cstr, '&') == NULL) |
| 3162 | type_name_cstr = NULL; |
| 3163 | } |
| 3164 | if (type_name_cstr) |
| 3165 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3166 | break; |
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 3167 | 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] | 3168 | case DW_AT_encoding: encoding = form_value.Unsigned(); break; |
| 3169 | case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; |
| 3170 | default: |
| 3171 | case DW_AT_sibling: |
| 3172 | break; |
| 3173 | } |
| 3174 | } |
| 3175 | } |
| 3176 | } |
| 3177 | |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 3178 | DEBUG_PRINTF ("0x%8.8x: %s (\"%s\") type => 0x%8.8x\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr, encoding_uid); |
| 3179 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3180 | switch (tag) |
| 3181 | { |
| 3182 | default: |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3183 | break; |
| 3184 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3185 | case DW_TAG_base_type: |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3186 | resolve_state = Type::eResolveStateFull; |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 3187 | clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr, |
| 3188 | encoding, |
| 3189 | byte_size * 8); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3190 | break; |
| 3191 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3192 | case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break; |
| 3193 | case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break; |
| 3194 | case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break; |
| 3195 | case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break; |
| 3196 | case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break; |
| 3197 | case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3198 | } |
| 3199 | |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3200 | if (type_name_cstr != NULL && sc.comp_unit != NULL && |
| 3201 | (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus)) |
| 3202 | { |
| 3203 | static ConstString g_objc_type_name_id("id"); |
| 3204 | static ConstString g_objc_type_name_Class("Class"); |
| 3205 | static ConstString g_objc_type_name_selector("SEL"); |
| 3206 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3207 | if (type_name_const_str == g_objc_type_name_id) |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3208 | { |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 3209 | clang_type = ast.GetBuiltInType_objc_id(); |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3210 | resolve_state = Type::eResolveStateFull; |
| 3211 | |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3212 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3213 | else if (type_name_const_str == g_objc_type_name_Class) |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3214 | { |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 3215 | clang_type = ast.GetBuiltInType_objc_Class(); |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3216 | resolve_state = Type::eResolveStateFull; |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3217 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3218 | else if (type_name_const_str == g_objc_type_name_selector) |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3219 | { |
| Sean Callanan | f6c7308 | 2010-12-06 23:53:20 +0000 | [diff] [blame] | 3220 | clang_type = ast.GetBuiltInType_objc_selector(); |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3221 | resolve_state = Type::eResolveStateFull; |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3222 | } |
| 3223 | } |
| 3224 | |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 3225 | type_sp.reset( new Type (die->GetOffset(), |
| 3226 | this, |
| 3227 | type_name_const_str, |
| 3228 | byte_size, |
| 3229 | NULL, |
| 3230 | encoding_uid, |
| 3231 | encoding_data_type, |
| 3232 | &decl, |
| 3233 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3234 | resolve_state)); |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 3235 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 3236 | m_die_to_type[die] = type_sp.get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3237 | |
| 3238 | // Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false); |
| 3239 | // if (encoding_type != NULL) |
| 3240 | // { |
| 3241 | // if (encoding_type != DIE_IS_BEING_PARSED) |
| 3242 | // type_sp->SetEncodingType(encoding_type); |
| 3243 | // else |
| 3244 | // m_indirect_fixups.push_back(type_sp.get()); |
| 3245 | // } |
| 3246 | } |
| 3247 | break; |
| 3248 | |
| 3249 | case DW_TAG_structure_type: |
| 3250 | case DW_TAG_union_type: |
| 3251 | case DW_TAG_class_type: |
| 3252 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3253 | // 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] | 3254 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3255 | |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 3256 | LanguageType class_language = eLanguageTypeUnknown; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3257 | //bool struct_is_class = false; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3258 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3259 | if (num_attributes > 0) |
| 3260 | { |
| 3261 | uint32_t i; |
| 3262 | for (i=0; i<num_attributes; ++i) |
| 3263 | { |
| 3264 | attr = attributes.AttributeAtIndex(i); |
| 3265 | DWARFFormValue form_value; |
| 3266 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 3267 | { |
| 3268 | switch (attr) |
| 3269 | { |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 3270 | case DW_AT_decl_file: |
| 3271 | decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); |
| 3272 | break; |
| 3273 | |
| 3274 | case DW_AT_decl_line: |
| 3275 | decl.SetLine(form_value.Unsigned()); |
| 3276 | break; |
| 3277 | |
| 3278 | case DW_AT_decl_column: |
| 3279 | decl.SetColumn(form_value.Unsigned()); |
| 3280 | break; |
| 3281 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3282 | case DW_AT_name: |
| 3283 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3284 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3285 | break; |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 3286 | |
| 3287 | case DW_AT_byte_size: |
| 3288 | byte_size = form_value.Unsigned(); |
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 3289 | byte_size_valid = true; |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 3290 | break; |
| 3291 | |
| 3292 | case DW_AT_accessibility: |
| 3293 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); |
| 3294 | break; |
| 3295 | |
| 3296 | case DW_AT_declaration: |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 3297 | is_forward_declaration = form_value.Unsigned() != 0; |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 3298 | break; |
| 3299 | |
| 3300 | case DW_AT_APPLE_runtime_class: |
| 3301 | class_language = (LanguageType)form_value.Signed(); |
| 3302 | break; |
| 3303 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3304 | case DW_AT_allocated: |
| 3305 | case DW_AT_associated: |
| 3306 | case DW_AT_data_location: |
| 3307 | case DW_AT_description: |
| 3308 | case DW_AT_start_scope: |
| 3309 | case DW_AT_visibility: |
| 3310 | default: |
| 3311 | case DW_AT_sibling: |
| 3312 | break; |
| 3313 | } |
| 3314 | } |
| 3315 | } |
| 3316 | } |
| 3317 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 3318 | UniqueDWARFASTType unique_ast_entry; |
| 3319 | if (decl.IsValid()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3320 | { |
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 3321 | if (GetUniqueDWARFASTTypeMap().Find (type_name_const_str, |
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 3322 | this, |
| 3323 | dwarf_cu, |
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 3324 | die, |
| 3325 | decl, |
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 3326 | byte_size_valid ? byte_size : -1, |
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 3327 | unique_ast_entry)) |
| Greg Clayton | c615ce4 | 2010-11-09 04:42:43 +0000 | [diff] [blame] | 3328 | { |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 3329 | // We have already parsed this type or from another |
| 3330 | // compile unit. GCC loves to use the "one definition |
| 3331 | // rule" which can result in multiple definitions |
| 3332 | // of the same class over and over in each compile |
| 3333 | // unit. |
| 3334 | type_sp = unique_ast_entry.m_type_sp; |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 3335 | if (type_sp) |
| 3336 | { |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 3337 | m_die_to_type[die] = type_sp.get(); |
| 3338 | return type_sp; |
| 3339 | } |
| 3340 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 3341 | } |
| 3342 | |
| 3343 | DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr); |
| 3344 | |
| 3345 | int tag_decl_kind = -1; |
| 3346 | AccessType default_accessibility = eAccessNone; |
| 3347 | if (tag == DW_TAG_structure_type) |
| 3348 | { |
| 3349 | tag_decl_kind = clang::TTK_Struct; |
| 3350 | default_accessibility = eAccessPublic; |
| 3351 | } |
| 3352 | else if (tag == DW_TAG_union_type) |
| 3353 | { |
| 3354 | tag_decl_kind = clang::TTK_Union; |
| 3355 | default_accessibility = eAccessPublic; |
| 3356 | } |
| 3357 | else if (tag == DW_TAG_class_type) |
| 3358 | { |
| 3359 | tag_decl_kind = clang::TTK_Class; |
| 3360 | default_accessibility = eAccessPrivate; |
| 3361 | } |
| 3362 | |
| 3363 | |
| 3364 | if (is_forward_declaration) |
| 3365 | { |
| 3366 | // We have a forward declaration to a type and we need |
| 3367 | // to try and find a full declaration. We look in the |
| 3368 | // current type index just in case we have a forward |
| 3369 | // declaration followed by an actual declarations in the |
| 3370 | // DWARF. If this fails, we need to look elsewhere... |
| 3371 | |
| 3372 | type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str); |
| 3373 | |
| 3374 | if (!type_sp && m_debug_map_symfile) |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 3375 | { |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 3376 | // We weren't able to find a full declaration in |
| 3377 | // this DWARF, see if we have a declaration anywhere |
| 3378 | // else... |
| 3379 | 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] | 3380 | } |
| 3381 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 3382 | if (type_sp) |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 3383 | { |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 3384 | // We found a real definition for this type elsewhere |
| 3385 | // so lets use it and cache the fact that we found |
| 3386 | // a complete type for this die |
| 3387 | m_die_to_type[die] = type_sp.get(); |
| 3388 | return type_sp; |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 3389 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 3390 | } |
| 3391 | assert (tag_decl_kind != -1); |
| 3392 | bool clang_type_was_created = false; |
| 3393 | clang_type = m_forward_decl_die_to_clang_type.lookup (die); |
| 3394 | if (clang_type == NULL) |
| 3395 | { |
| 3396 | clang_type_was_created = true; |
| 3397 | clang_type = ast.CreateRecordType (type_name_cstr, |
| 3398 | tag_decl_kind, |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 3399 | GetClangDeclContextContainingDIE (dwarf_cu, die), |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 3400 | class_language); |
| 3401 | } |
| 3402 | |
| 3403 | // Store a forward declaration to this class type in case any |
| 3404 | // parameters in any class methods need it for the clang |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 3405 | // types for function prototypes. |
| 3406 | LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die); |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 3407 | type_sp.reset (new Type (die->GetOffset(), |
| 3408 | this, |
| 3409 | type_name_const_str, |
| 3410 | byte_size, |
| 3411 | NULL, |
| 3412 | LLDB_INVALID_UID, |
| 3413 | Type::eEncodingIsUID, |
| 3414 | &decl, |
| 3415 | clang_type, |
| 3416 | Type::eResolveStateForward)); |
| 3417 | |
| 3418 | |
| 3419 | // Add our type to the unique type map so we don't |
| 3420 | // end up creating many copies of the same type over |
| 3421 | // and over in the ASTContext for our module |
| 3422 | unique_ast_entry.m_type_sp = type_sp; |
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 3423 | unique_ast_entry.m_symfile = this; |
| 3424 | unique_ast_entry.m_cu = dwarf_cu; |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 3425 | unique_ast_entry.m_die = die; |
| 3426 | unique_ast_entry.m_declaration = decl; |
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 3427 | GetUniqueDWARFASTTypeMap().Insert (type_name_const_str, |
| 3428 | unique_ast_entry); |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 3429 | |
| 3430 | if (die->HasChildren() == false && is_forward_declaration == false) |
| 3431 | { |
| 3432 | // No children for this struct/union/class, lets finish it |
| 3433 | ast.StartTagDeclarationDefinition (clang_type); |
| 3434 | ast.CompleteTagDeclarationDefinition (clang_type); |
| 3435 | } |
| 3436 | else if (clang_type_was_created) |
| 3437 | { |
| 3438 | // Leave this as a forward declaration until we need |
| 3439 | // to know the details of the type. lldb_private::Type |
| 3440 | // will automatically call the SymbolFile virtual function |
| 3441 | // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)" |
| 3442 | // When the definition needs to be defined. |
| 3443 | m_forward_decl_die_to_clang_type[die] = clang_type; |
| 3444 | m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die; |
| 3445 | ClangASTContext::SetHasExternalStorage (clang_type, true); |
| Greg Clayton | c615ce4 | 2010-11-09 04:42:43 +0000 | [diff] [blame] | 3446 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3447 | } |
| 3448 | break; |
| 3449 | |
| 3450 | case DW_TAG_enumeration_type: |
| 3451 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3452 | // 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] | 3453 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3454 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3455 | lldb::user_id_t encoding_uid = DW_INVALID_OFFSET; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3456 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3457 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3458 | if (num_attributes > 0) |
| 3459 | { |
| 3460 | uint32_t i; |
| 3461 | |
| 3462 | for (i=0; i<num_attributes; ++i) |
| 3463 | { |
| 3464 | attr = attributes.AttributeAtIndex(i); |
| 3465 | DWARFFormValue form_value; |
| 3466 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 3467 | { |
| 3468 | switch (attr) |
| 3469 | { |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 3470 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 3471 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 3472 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3473 | case DW_AT_name: |
| 3474 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3475 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3476 | break; |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 3477 | case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; |
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 3478 | 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] | 3479 | case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
| 3480 | case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3481 | case DW_AT_allocated: |
| 3482 | case DW_AT_associated: |
| 3483 | case DW_AT_bit_stride: |
| 3484 | case DW_AT_byte_stride: |
| 3485 | case DW_AT_data_location: |
| 3486 | case DW_AT_description: |
| 3487 | case DW_AT_start_scope: |
| 3488 | case DW_AT_visibility: |
| 3489 | case DW_AT_specification: |
| 3490 | case DW_AT_abstract_origin: |
| 3491 | case DW_AT_sibling: |
| 3492 | break; |
| 3493 | } |
| 3494 | } |
| 3495 | } |
| 3496 | |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 3497 | DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr); |
| 3498 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 3499 | clang_type_t enumerator_clang_type = NULL; |
| 3500 | clang_type = m_forward_decl_die_to_clang_type.lookup (die); |
| 3501 | if (clang_type == NULL) |
| 3502 | { |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 3503 | enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL, |
| 3504 | DW_ATE_signed, |
| 3505 | byte_size * 8); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 3506 | clang_type = ast.CreateEnumerationType (type_name_cstr, |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 3507 | GetClangDeclContextContainingDIE (dwarf_cu, die), |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 3508 | decl, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 3509 | enumerator_clang_type); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 3510 | } |
| 3511 | else |
| 3512 | { |
| 3513 | enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type); |
| 3514 | assert (enumerator_clang_type != NULL); |
| 3515 | } |
| 3516 | |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 3517 | LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die); |
| 3518 | |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 3519 | type_sp.reset( new Type (die->GetOffset(), |
| 3520 | this, |
| 3521 | type_name_const_str, |
| 3522 | byte_size, |
| 3523 | NULL, |
| 3524 | encoding_uid, |
| 3525 | Type::eEncodingIsUID, |
| 3526 | &decl, |
| 3527 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3528 | Type::eResolveStateForward)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3529 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 3530 | #if LEAVE_ENUMS_FORWARD_DECLARED |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 3531 | // Leave this as a forward declaration until we need |
| 3532 | // to know the details of the type. lldb_private::Type |
| 3533 | // will automatically call the SymbolFile virtual function |
| 3534 | // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)" |
| 3535 | // When the definition needs to be defined. |
| 3536 | m_forward_decl_die_to_clang_type[die] = clang_type; |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 3537 | m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die; |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 3538 | ClangASTContext::SetHasExternalStorage (clang_type, true); |
| 3539 | #else |
| 3540 | ast.StartTagDeclarationDefinition (clang_type); |
| 3541 | if (die->HasChildren()) |
| 3542 | { |
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 3543 | SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); |
| 3544 | ParseChildEnumerators(cu_sc, clang_type, type_sp->GetByteSize(), dwarf_cu, die); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 3545 | } |
| 3546 | ast.CompleteTagDeclarationDefinition (clang_type); |
| 3547 | #endif |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3548 | } |
| 3549 | } |
| 3550 | break; |
| 3551 | |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 3552 | case DW_TAG_inlined_subroutine: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3553 | case DW_TAG_subprogram: |
| 3554 | case DW_TAG_subroutine_type: |
| 3555 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3556 | // 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] | 3557 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3558 | |
| 3559 | const char *mangled = NULL; |
| 3560 | dw_offset_t type_die_offset = DW_INVALID_OFFSET; |
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 3561 | bool is_variadic = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3562 | bool is_inline = false; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3563 | bool is_static = false; |
| 3564 | bool is_virtual = false; |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 3565 | bool is_explicit = false; |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 3566 | dw_offset_t specification_die_offset = DW_INVALID_OFFSET; |
| 3567 | dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3568 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3569 | unsigned type_quals = 0; |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 3570 | clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3571 | |
| 3572 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3573 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3574 | if (num_attributes > 0) |
| 3575 | { |
| 3576 | uint32_t i; |
| 3577 | for (i=0; i<num_attributes; ++i) |
| 3578 | { |
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 3579 | attr = attributes.AttributeAtIndex(i); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3580 | DWARFFormValue form_value; |
| 3581 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 3582 | { |
| 3583 | switch (attr) |
| 3584 | { |
| 3585 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 3586 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 3587 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 3588 | case DW_AT_name: |
| 3589 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3590 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3591 | break; |
| 3592 | |
| 3593 | case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break; |
| 3594 | 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] | 3595 | 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] | 3596 | case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3597 | case DW_AT_inline: is_inline = form_value.Unsigned() != 0; break; |
| 3598 | case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break; |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 3599 | case DW_AT_explicit: is_explicit = form_value.Unsigned() != 0; break; |
| 3600 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3601 | case DW_AT_external: |
| 3602 | if (form_value.Unsigned()) |
| 3603 | { |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 3604 | if (storage == clang::SC_None) |
| 3605 | storage = clang::SC_Extern; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3606 | else |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 3607 | storage = clang::SC_PrivateExtern; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3608 | } |
| 3609 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3610 | |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 3611 | case DW_AT_specification: |
| 3612 | specification_die_offset = form_value.Reference(dwarf_cu); |
| 3613 | break; |
| 3614 | |
| 3615 | case DW_AT_abstract_origin: |
| 3616 | abstract_origin_die_offset = form_value.Reference(dwarf_cu); |
| 3617 | break; |
| 3618 | |
| 3619 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3620 | case DW_AT_allocated: |
| 3621 | case DW_AT_associated: |
| 3622 | case DW_AT_address_class: |
| 3623 | case DW_AT_artificial: |
| 3624 | case DW_AT_calling_convention: |
| 3625 | case DW_AT_data_location: |
| 3626 | case DW_AT_elemental: |
| 3627 | case DW_AT_entry_pc: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3628 | case DW_AT_frame_base: |
| 3629 | case DW_AT_high_pc: |
| 3630 | case DW_AT_low_pc: |
| 3631 | case DW_AT_object_pointer: |
| 3632 | case DW_AT_prototyped: |
| 3633 | case DW_AT_pure: |
| 3634 | case DW_AT_ranges: |
| 3635 | case DW_AT_recursive: |
| 3636 | case DW_AT_return_addr: |
| 3637 | case DW_AT_segment: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3638 | case DW_AT_start_scope: |
| 3639 | case DW_AT_static_link: |
| 3640 | case DW_AT_trampoline: |
| 3641 | case DW_AT_visibility: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3642 | case DW_AT_vtable_elem_location: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3643 | case DW_AT_description: |
| 3644 | case DW_AT_sibling: |
| 3645 | break; |
| 3646 | } |
| 3647 | } |
| 3648 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3649 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3650 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3651 | DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr); |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 3652 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3653 | clang_type_t return_clang_type = NULL; |
| 3654 | Type *func_type = NULL; |
| 3655 | |
| 3656 | if (type_die_offset != DW_INVALID_OFFSET) |
| 3657 | func_type = ResolveTypeUID(type_die_offset); |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 3658 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3659 | if (func_type) |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3660 | return_clang_type = func_type->GetClangLayoutType(); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3661 | else |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 3662 | return_clang_type = ast.GetBuiltInType_void(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3663 | |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 3664 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3665 | std::vector<clang_type_t> function_param_types; |
| 3666 | std::vector<clang::ParmVarDecl*> function_param_decls; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3667 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3668 | // Parse the function children for the parameters |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 3669 | |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3670 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die); |
| 3671 | const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind(); |
| 3672 | |
| 3673 | const bool is_cxx_method = containing_decl_kind == clang::Decl::CXXRecord; |
| 3674 | // Start off static. This will be set to false in ParseChildParameters(...) |
| 3675 | // if we find a "this" paramters as the first parameter |
| 3676 | if (is_cxx_method) |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 3677 | is_static = true; |
| 3678 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3679 | if (die->HasChildren()) |
| 3680 | { |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3681 | bool skip_artificial = true; |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 3682 | ParseChildParameters (sc, |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3683 | containing_decl_ctx, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 3684 | type_sp, |
| 3685 | dwarf_cu, |
| 3686 | die, |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 3687 | skip_artificial, |
| 3688 | is_static, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 3689 | type_list, |
| 3690 | function_param_types, |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3691 | function_param_decls, |
| 3692 | type_quals); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3693 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3694 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3695 | // clang_type will get the function prototype clang type after this call |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 3696 | clang_type = ast.CreateFunctionType (return_clang_type, |
| 3697 | &function_param_types[0], |
| 3698 | function_param_types.size(), |
| 3699 | is_variadic, |
| 3700 | type_quals); |
| 3701 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3702 | if (type_name_cstr) |
| 3703 | { |
| 3704 | bool type_handled = false; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3705 | if (tag == DW_TAG_subprogram) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3706 | { |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3707 | if (type_name_cstr[1] == '[' && (type_name_cstr[0] == '-' || type_name_cstr[0] == '+')) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3708 | { |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3709 | // We need to find the DW_TAG_class_type or |
| 3710 | // DW_TAG_struct_type by name so we can add this |
| 3711 | // as a member function of the class. |
| 3712 | const char *class_name_start = type_name_cstr + 2; |
| 3713 | const char *class_name_end = ::strchr (class_name_start, ' '); |
| 3714 | SymbolContext empty_sc; |
| 3715 | clang_type_t class_opaque_type = NULL; |
| 3716 | if (class_name_start < class_name_end) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3717 | { |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3718 | ConstString class_name (class_name_start, class_name_end - class_name_start); |
| 3719 | TypeList types; |
| 3720 | const uint32_t match_count = FindTypes (empty_sc, class_name, true, UINT32_MAX, types); |
| 3721 | if (match_count > 0) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3722 | { |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3723 | for (uint32_t i=0; i<match_count; ++i) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3724 | { |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3725 | Type *type = types.GetTypeAtIndex (i).get(); |
| 3726 | clang_type_t type_clang_forward_type = type->GetClangForwardType(); |
| 3727 | if (ClangASTContext::IsObjCClassType (type_clang_forward_type)) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3728 | { |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3729 | class_opaque_type = type_clang_forward_type; |
| 3730 | break; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3731 | } |
| 3732 | } |
| 3733 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3734 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3735 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3736 | if (class_opaque_type) |
| 3737 | { |
| 3738 | // If accessibility isn't set to anything valid, assume public for |
| 3739 | // now... |
| 3740 | if (accessibility == eAccessNone) |
| 3741 | accessibility = eAccessPublic; |
| 3742 | |
| 3743 | clang::ObjCMethodDecl *objc_method_decl; |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 3744 | objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type, |
| 3745 | type_name_cstr, |
| 3746 | clang_type, |
| 3747 | accessibility); |
| Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 3748 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3749 | type_handled = objc_method_decl != NULL; |
| 3750 | } |
| 3751 | } |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3752 | else if (is_cxx_method) |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3753 | { |
| 3754 | // Look at the parent of this DIE and see if is is |
| 3755 | // a class or struct and see if this is actually a |
| 3756 | // C++ method |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3757 | Type *class_type = ResolveType (dwarf_cu, m_decl_ctx_to_die[containing_decl_ctx]); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3758 | if (class_type) |
| 3759 | { |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 3760 | if (specification_die_offset != DW_INVALID_OFFSET) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3761 | { |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 3762 | // If we have a specification, then the function type should have been |
| 3763 | // made with the specification and not with this die. |
| 3764 | DWARFCompileUnitSP spec_cu_sp; |
| 3765 | const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp); |
| 3766 | if (m_die_to_decl_ctx[spec_die] == NULL) |
| 3767 | fprintf (stderr,"warning: 0x%8.8x: DW_AT_specification(0x%8.8x) has no decl\n", die->GetOffset(), specification_die_offset); |
| 3768 | type_handled = true; |
| 3769 | } |
| 3770 | else if (abstract_origin_die_offset != DW_INVALID_OFFSET) |
| 3771 | { |
| 3772 | DWARFCompileUnitSP abs_cu_sp; |
| 3773 | const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp); |
| 3774 | if (m_die_to_decl_ctx[abs_die] == NULL) |
| 3775 | fprintf (stderr,"warning: 0x%8.8x: DW_AT_abstract_origin(0x%8.8x) has no decl\n", die->GetOffset(), abstract_origin_die_offset); |
| 3776 | type_handled = true; |
| 3777 | } |
| 3778 | else |
| 3779 | { |
| 3780 | clang_type_t class_opaque_type = class_type->GetClangForwardType(); |
| 3781 | if (ClangASTContext::IsCXXClassType (class_opaque_type)) |
| Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 3782 | { |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 3783 | // Neither GCC 4.2 nor clang++ currently set a valid accessibility |
| 3784 | // in the DWARF for C++ methods... Default to public for now... |
| 3785 | if (accessibility == eAccessNone) |
| 3786 | accessibility = eAccessPublic; |
| 3787 | |
| 3788 | if (!is_static && !die->HasChildren()) |
| 3789 | { |
| 3790 | // We have a C++ member function with no children (this pointer!) |
| 3791 | // and clang will get mad if we try and make a function that isn't |
| 3792 | // well formed in the DWARF, so we will just skip it... |
| 3793 | type_handled = true; |
| 3794 | } |
| 3795 | else |
| 3796 | { |
| 3797 | clang::CXXMethodDecl *cxx_method_decl; |
| 3798 | cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type, |
| 3799 | type_name_cstr, |
| 3800 | clang_type, |
| 3801 | accessibility, |
| 3802 | is_virtual, |
| 3803 | is_static, |
| 3804 | is_inline, |
| 3805 | is_explicit); |
| 3806 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die); |
| Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 3807 | |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 3808 | type_handled = cxx_method_decl != NULL; |
| 3809 | } |
| Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 3810 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3811 | } |
| 3812 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3813 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3814 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3815 | |
| 3816 | if (!type_handled) |
| 3817 | { |
| 3818 | // We just have a function that isn't part of a class |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 3819 | clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (type_name_cstr, |
| 3820 | clang_type, |
| 3821 | storage, |
| 3822 | is_inline); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3823 | |
| 3824 | // Add the decl to our DIE to decl context map |
| 3825 | assert (function_decl); |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 3826 | LinkDeclContextToDIE(function_decl, die); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3827 | if (!function_param_decls.empty()) |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 3828 | ast.SetFunctionParameters (function_decl, |
| 3829 | &function_param_decls.front(), |
| 3830 | function_param_decls.size()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3831 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3832 | } |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 3833 | type_sp.reset( new Type (die->GetOffset(), |
| 3834 | this, |
| 3835 | type_name_const_str, |
| 3836 | 0, |
| 3837 | NULL, |
| 3838 | LLDB_INVALID_UID, |
| 3839 | Type::eEncodingIsUID, |
| 3840 | &decl, |
| 3841 | clang_type, |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 3842 | Type::eResolveStateFull)); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3843 | assert(type_sp.get()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3844 | } |
| 3845 | break; |
| 3846 | |
| 3847 | case DW_TAG_array_type: |
| 3848 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3849 | // 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] | 3850 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3851 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3852 | lldb::user_id_t type_die_offset = DW_INVALID_OFFSET; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3853 | int64_t first_index = 0; |
| 3854 | uint32_t byte_stride = 0; |
| 3855 | uint32_t bit_stride = 0; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3856 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3857 | |
| 3858 | if (num_attributes > 0) |
| 3859 | { |
| 3860 | uint32_t i; |
| 3861 | for (i=0; i<num_attributes; ++i) |
| 3862 | { |
| 3863 | attr = attributes.AttributeAtIndex(i); |
| 3864 | DWARFFormValue form_value; |
| 3865 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 3866 | { |
| 3867 | switch (attr) |
| 3868 | { |
| 3869 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 3870 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 3871 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 3872 | case DW_AT_name: |
| 3873 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3874 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3875 | break; |
| 3876 | |
| 3877 | 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] | 3878 | 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] | 3879 | case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break; |
| 3880 | case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break; |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 3881 | 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] | 3882 | case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3883 | case DW_AT_allocated: |
| 3884 | case DW_AT_associated: |
| 3885 | case DW_AT_data_location: |
| 3886 | case DW_AT_description: |
| 3887 | case DW_AT_ordering: |
| 3888 | case DW_AT_start_scope: |
| 3889 | case DW_AT_visibility: |
| 3890 | case DW_AT_specification: |
| 3891 | case DW_AT_abstract_origin: |
| 3892 | case DW_AT_sibling: |
| 3893 | break; |
| 3894 | } |
| 3895 | } |
| 3896 | } |
| 3897 | |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 3898 | DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr); |
| 3899 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3900 | Type *element_type = ResolveTypeUID(type_die_offset); |
| 3901 | |
| 3902 | if (element_type) |
| 3903 | { |
| 3904 | std::vector<uint64_t> element_orders; |
| 3905 | 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] | 3906 | // We have an array that claims to have no members, lets give it at least one member... |
| 3907 | if (element_orders.empty()) |
| 3908 | element_orders.push_back (1); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3909 | if (byte_stride == 0 && bit_stride == 0) |
| 3910 | byte_stride = element_type->GetByteSize(); |
| Greg Clayton | f4ecaa5 | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 3911 | clang_type_t array_element_type = element_type->GetClangFullType(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3912 | uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride; |
| 3913 | uint64_t num_elements = 0; |
| 3914 | std::vector<uint64_t>::const_reverse_iterator pos; |
| 3915 | std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend(); |
| 3916 | for (pos = element_orders.rbegin(); pos != end; ++pos) |
| 3917 | { |
| 3918 | num_elements = *pos; |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 3919 | clang_type = ast.CreateArrayType (array_element_type, |
| 3920 | num_elements, |
| 3921 | num_elements * array_element_bit_stride); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3922 | array_element_type = clang_type; |
| 3923 | array_element_bit_stride = array_element_bit_stride * num_elements; |
| 3924 | } |
| 3925 | ConstString empty_name; |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 3926 | type_sp.reset( new Type (die->GetOffset(), |
| 3927 | this, |
| 3928 | empty_name, |
| 3929 | array_element_bit_stride / 8, |
| 3930 | NULL, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3931 | type_die_offset, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 3932 | Type::eEncodingIsUID, |
| 3933 | &decl, |
| 3934 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3935 | Type::eResolveStateFull)); |
| 3936 | type_sp->SetEncodingType (element_type); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3937 | } |
| 3938 | } |
| 3939 | } |
| 3940 | break; |
| 3941 | |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 3942 | case DW_TAG_ptr_to_member_type: |
| 3943 | { |
| 3944 | dw_offset_t type_die_offset = DW_INVALID_OFFSET; |
| 3945 | dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET; |
| 3946 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3947 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 3948 | |
| 3949 | if (num_attributes > 0) { |
| 3950 | uint32_t i; |
| 3951 | for (i=0; i<num_attributes; ++i) |
| 3952 | { |
| 3953 | attr = attributes.AttributeAtIndex(i); |
| 3954 | DWARFFormValue form_value; |
| 3955 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 3956 | { |
| 3957 | switch (attr) |
| 3958 | { |
| 3959 | case DW_AT_type: |
| 3960 | type_die_offset = form_value.Reference(dwarf_cu); break; |
| 3961 | case DW_AT_containing_type: |
| 3962 | containing_type_die_offset = form_value.Reference(dwarf_cu); break; |
| 3963 | } |
| 3964 | } |
| 3965 | } |
| 3966 | |
| 3967 | Type *pointee_type = ResolveTypeUID(type_die_offset); |
| 3968 | Type *class_type = ResolveTypeUID(containing_type_die_offset); |
| 3969 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3970 | clang_type_t pointee_clang_type = pointee_type->GetClangForwardType(); |
| 3971 | clang_type_t class_clang_type = class_type->GetClangLayoutType(); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 3972 | |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 3973 | clang_type = ast.CreateMemberPointerType(pointee_clang_type, |
| 3974 | class_clang_type); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 3975 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3976 | byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(), |
| 3977 | clang_type) / 8; |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 3978 | |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 3979 | type_sp.reset( new Type (die->GetOffset(), |
| 3980 | this, |
| 3981 | type_name_const_str, |
| 3982 | byte_size, |
| 3983 | NULL, |
| 3984 | LLDB_INVALID_UID, |
| 3985 | Type::eEncodingIsUID, |
| 3986 | NULL, |
| 3987 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3988 | Type::eResolveStateForward)); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 3989 | } |
| 3990 | |
| 3991 | break; |
| 3992 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3993 | default: |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 3994 | assert(false && "Unhandled type tag!"); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3995 | break; |
| 3996 | } |
| 3997 | |
| 3998 | if (type_sp.get()) |
| 3999 | { |
| 4000 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); |
| 4001 | dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
| 4002 | |
| 4003 | SymbolContextScope * symbol_context_scope = NULL; |
| 4004 | if (sc_parent_tag == DW_TAG_compile_unit) |
| 4005 | { |
| 4006 | symbol_context_scope = sc.comp_unit; |
| 4007 | } |
| 4008 | else if (sc.function != NULL) |
| 4009 | { |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 4010 | symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(sc_parent_die->GetOffset()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4011 | if (symbol_context_scope == NULL) |
| 4012 | symbol_context_scope = sc.function; |
| 4013 | } |
| 4014 | |
| 4015 | if (symbol_context_scope != NULL) |
| 4016 | { |
| 4017 | type_sp->SetSymbolContextScope(symbol_context_scope); |
| 4018 | } |
| 4019 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4020 | // We are ready to put this type into the uniqued list up at the module level |
| 4021 | type_list->Insert (type_sp); |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 4022 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4023 | m_die_to_type[die] = type_sp.get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4024 | } |
| 4025 | } |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4026 | else if (type_ptr != DIE_IS_BEING_PARSED) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4027 | { |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 4028 | type_sp = type_list->FindType(type_ptr->GetID()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4029 | } |
| 4030 | } |
| 4031 | return type_sp; |
| 4032 | } |
| 4033 | |
| 4034 | size_t |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 4035 | SymbolFileDWARF::ParseTypes |
| 4036 | ( |
| 4037 | const SymbolContext& sc, |
| 4038 | DWARFCompileUnit* dwarf_cu, |
| 4039 | const DWARFDebugInfoEntry *die, |
| 4040 | bool parse_siblings, |
| 4041 | bool parse_children |
| 4042 | ) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4043 | { |
| 4044 | size_t types_added = 0; |
| 4045 | while (die != NULL) |
| 4046 | { |
| 4047 | bool type_is_new = false; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 4048 | if (ParseType(sc, dwarf_cu, die, &type_is_new).get()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4049 | { |
| 4050 | if (type_is_new) |
| 4051 | ++types_added; |
| 4052 | } |
| 4053 | |
| 4054 | if (parse_children && die->HasChildren()) |
| 4055 | { |
| 4056 | if (die->Tag() == DW_TAG_subprogram) |
| 4057 | { |
| 4058 | SymbolContext child_sc(sc); |
| 4059 | child_sc.function = sc.comp_unit->FindFunctionByUID(die->GetOffset()).get(); |
| 4060 | types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true); |
| 4061 | } |
| 4062 | else |
| 4063 | types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true); |
| 4064 | } |
| 4065 | |
| 4066 | if (parse_siblings) |
| 4067 | die = die->GetSibling(); |
| 4068 | else |
| 4069 | die = NULL; |
| 4070 | } |
| 4071 | return types_added; |
| 4072 | } |
| 4073 | |
| 4074 | |
| 4075 | size_t |
| 4076 | SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc) |
| 4077 | { |
| 4078 | assert(sc.comp_unit && sc.function); |
| 4079 | size_t functions_added = 0; |
| 4080 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID()); |
| 4081 | if (dwarf_cu) |
| 4082 | { |
| 4083 | dw_offset_t function_die_offset = sc.function->GetID(); |
| 4084 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset); |
| 4085 | if (function_die) |
| 4086 | { |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 4087 | 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] | 4088 | } |
| 4089 | } |
| 4090 | |
| 4091 | return functions_added; |
| 4092 | } |
| 4093 | |
| 4094 | |
| 4095 | size_t |
| 4096 | SymbolFileDWARF::ParseTypes (const SymbolContext &sc) |
| 4097 | { |
| 4098 | // At least a compile unit must be valid |
| 4099 | assert(sc.comp_unit); |
| 4100 | size_t types_added = 0; |
| 4101 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID()); |
| 4102 | if (dwarf_cu) |
| 4103 | { |
| 4104 | if (sc.function) |
| 4105 | { |
| 4106 | dw_offset_t function_die_offset = sc.function->GetID(); |
| 4107 | const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset); |
| 4108 | if (func_die && func_die->HasChildren()) |
| 4109 | { |
| 4110 | types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true); |
| 4111 | } |
| 4112 | } |
| 4113 | else |
| 4114 | { |
| 4115 | const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE(); |
| 4116 | if (dwarf_cu_die && dwarf_cu_die->HasChildren()) |
| 4117 | { |
| 4118 | types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true); |
| 4119 | } |
| 4120 | } |
| 4121 | } |
| 4122 | |
| 4123 | return types_added; |
| 4124 | } |
| 4125 | |
| 4126 | size_t |
| 4127 | SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc) |
| 4128 | { |
| 4129 | if (sc.comp_unit != NULL) |
| 4130 | { |
| Greg Clayton | 4b3dc10 | 2010-11-01 20:32:12 +0000 | [diff] [blame] | 4131 | DWARFDebugInfo* info = DebugInfo(); |
| 4132 | if (info == NULL) |
| 4133 | return 0; |
| 4134 | |
| 4135 | uint32_t cu_idx = UINT32_MAX; |
| 4136 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID(), &cu_idx).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4137 | |
| 4138 | if (dwarf_cu == NULL) |
| 4139 | return 0; |
| 4140 | |
| 4141 | if (sc.function) |
| 4142 | { |
| 4143 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID()); |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 4144 | |
| 4145 | dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, DW_INVALID_ADDRESS); |
| 4146 | assert (func_lo_pc != DW_INVALID_ADDRESS); |
| 4147 | |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4148 | const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true); |
| 4149 | |
| 4150 | // Let all blocks know they have parse all their variables |
| 4151 | sc.function->GetBlock (false).SetDidParseVariables (true, true); |
| 4152 | |
| 4153 | return num_variables; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4154 | } |
| 4155 | else if (sc.comp_unit) |
| 4156 | { |
| 4157 | uint32_t vars_added = 0; |
| 4158 | VariableListSP variables (sc.comp_unit->GetVariableList(false)); |
| 4159 | |
| 4160 | if (variables.get() == NULL) |
| 4161 | { |
| 4162 | variables.reset(new VariableList()); |
| 4163 | sc.comp_unit->SetVariableList(variables); |
| 4164 | |
| 4165 | // Index if we already haven't to make sure the compile units |
| 4166 | // get indexed and make their global DIE index list |
| 4167 | if (!m_indexed) |
| 4168 | Index (); |
| 4169 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 4170 | std::vector<NameToDIE::Info> global_die_info_array; |
| Greg Clayton | 4b3dc10 | 2010-11-01 20:32:12 +0000 | [diff] [blame] | 4171 | const size_t num_globals = m_global_index.FindAllEntriesForCompileUnitWithIndex (cu_idx, global_die_info_array); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4172 | for (size_t idx=0; idx<num_globals; ++idx) |
| 4173 | { |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 4174 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, dwarf_cu->GetDIEAtIndexUnchecked(global_die_info_array[idx].die_idx), LLDB_INVALID_ADDRESS)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4175 | if (var_sp) |
| 4176 | { |
| Greg Clayton | 83c5cd9 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 4177 | variables->AddVariableIfUnique (var_sp); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4178 | ++vars_added; |
| 4179 | } |
| 4180 | } |
| 4181 | } |
| 4182 | return vars_added; |
| 4183 | } |
| 4184 | } |
| 4185 | return 0; |
| 4186 | } |
| 4187 | |
| 4188 | |
| 4189 | VariableSP |
| 4190 | SymbolFileDWARF::ParseVariableDIE |
| 4191 | ( |
| 4192 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4193 | DWARFCompileUnit* dwarf_cu, |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 4194 | const DWARFDebugInfoEntry *die, |
| 4195 | const lldb::addr_t func_low_pc |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4196 | ) |
| 4197 | { |
| 4198 | |
| Greg Clayton | 83c5cd9 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 4199 | VariableSP var_sp (m_die_to_variable_sp[die]); |
| 4200 | if (var_sp) |
| 4201 | return var_sp; // Already been parsed! |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4202 | |
| 4203 | const dw_tag_t tag = die->Tag(); |
| 4204 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4205 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4206 | if (num_attributes > 0) |
| 4207 | { |
| 4208 | const char *name = NULL; |
| Greg Clayton | a134cc1 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 4209 | const char *mangled = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4210 | Declaration decl; |
| 4211 | uint32_t i; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4212 | Type *var_type = NULL; |
| 4213 | DWARFExpression location; |
| 4214 | bool is_external = false; |
| 4215 | bool is_artificial = false; |
| Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 4216 | bool location_is_const_value_data = false; |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 4217 | AccessType accessibility = eAccessNone; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4218 | |
| 4219 | for (i=0; i<num_attributes; ++i) |
| 4220 | { |
| 4221 | dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 4222 | DWARFFormValue form_value; |
| 4223 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 4224 | { |
| 4225 | switch (attr) |
| 4226 | { |
| 4227 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 4228 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 4229 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 4230 | case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; |
| Greg Clayton | a134cc1 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 4231 | case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break; |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4232 | case DW_AT_type: var_type = ResolveTypeUID(form_value.Reference(dwarf_cu)); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4233 | case DW_AT_external: is_external = form_value.Unsigned() != 0; break; |
| Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 4234 | case DW_AT_const_value: |
| 4235 | location_is_const_value_data = true; |
| 4236 | // Fall through... |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4237 | case DW_AT_location: |
| 4238 | { |
| 4239 | if (form_value.BlockData()) |
| 4240 | { |
| 4241 | const DataExtractor& debug_info_data = get_debug_info_data(); |
| 4242 | |
| 4243 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 4244 | uint32_t block_length = form_value.Unsigned(); |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 4245 | location.SetOpcodeData(get_debug_info_data(), block_offset, block_length); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4246 | } |
| 4247 | else |
| 4248 | { |
| 4249 | const DataExtractor& debug_loc_data = get_debug_loc_data(); |
| 4250 | const dw_offset_t debug_loc_offset = form_value.Unsigned(); |
| 4251 | |
| 4252 | size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset); |
| 4253 | if (loc_list_length > 0) |
| 4254 | { |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 4255 | location.SetOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length); |
| 4256 | assert (func_low_pc != LLDB_INVALID_ADDRESS); |
| 4257 | location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4258 | } |
| 4259 | } |
| 4260 | } |
| 4261 | break; |
| 4262 | |
| 4263 | case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break; |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 4264 | case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4265 | case DW_AT_declaration: |
| 4266 | case DW_AT_description: |
| 4267 | case DW_AT_endianity: |
| 4268 | case DW_AT_segment: |
| 4269 | case DW_AT_start_scope: |
| 4270 | case DW_AT_visibility: |
| 4271 | default: |
| 4272 | case DW_AT_abstract_origin: |
| 4273 | case DW_AT_sibling: |
| 4274 | case DW_AT_specification: |
| 4275 | break; |
| 4276 | } |
| 4277 | } |
| 4278 | } |
| 4279 | |
| 4280 | if (location.IsValid()) |
| 4281 | { |
| 4282 | assert(var_type != DIE_IS_BEING_PARSED); |
| 4283 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4284 | ValueType scope = eValueTypeInvalid; |
| 4285 | |
| 4286 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); |
| 4287 | dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
| 4288 | |
| 4289 | if (tag == DW_TAG_formal_parameter) |
| 4290 | scope = eValueTypeVariableArgument; |
| 4291 | else if (is_external || parent_tag == DW_TAG_compile_unit) |
| 4292 | scope = eValueTypeVariableGlobal; |
| 4293 | else |
| 4294 | scope = eValueTypeVariableLocal; |
| 4295 | |
| 4296 | SymbolContextScope * symbol_context_scope = NULL; |
| 4297 | if (parent_tag == DW_TAG_compile_unit) |
| 4298 | { |
| 4299 | symbol_context_scope = sc.comp_unit; |
| 4300 | } |
| 4301 | else if (sc.function != NULL) |
| 4302 | { |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 4303 | symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(sc_parent_die->GetOffset()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4304 | if (symbol_context_scope == NULL) |
| 4305 | symbol_context_scope = sc.function; |
| 4306 | } |
| 4307 | |
| 4308 | assert(symbol_context_scope != NULL); |
| 4309 | var_sp.reset (new Variable(die->GetOffset(), |
| Greg Clayton | 83c5cd9 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 4310 | name, |
| 4311 | mangled, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4312 | var_type, |
| 4313 | scope, |
| 4314 | symbol_context_scope, |
| 4315 | &decl, |
| 4316 | location, |
| 4317 | is_external, |
| 4318 | is_artificial)); |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4319 | |
| Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 4320 | var_sp->SetLocationIsConstantValueData (location_is_const_value_data); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4321 | } |
| 4322 | } |
| Greg Clayton | 83c5cd9 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 4323 | // Cache var_sp even if NULL (the variable was just a specification or |
| 4324 | // was missing vital information to be able to be displayed in the debugger |
| 4325 | // (missing location due to optimization, etc)) so we don't re-parse |
| 4326 | // this DIE over and over later... |
| 4327 | m_die_to_variable_sp[die] = var_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4328 | return var_sp; |
| 4329 | } |
| 4330 | |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4331 | |
| 4332 | const DWARFDebugInfoEntry * |
| 4333 | SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset, |
| 4334 | dw_offset_t spec_block_die_offset, |
| 4335 | DWARFCompileUnit **result_die_cu_handle) |
| 4336 | { |
| 4337 | // Give the concrete function die specified by "func_die_offset", find the |
| 4338 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points |
| 4339 | // to "spec_block_die_offset" |
| 4340 | DWARFDebugInfo* info = DebugInfo(); |
| 4341 | |
| 4342 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle); |
| 4343 | if (die) |
| 4344 | { |
| 4345 | assert (*result_die_cu_handle); |
| 4346 | return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle); |
| 4347 | } |
| 4348 | return NULL; |
| 4349 | } |
| 4350 | |
| 4351 | |
| 4352 | const DWARFDebugInfoEntry * |
| 4353 | SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu, |
| 4354 | const DWARFDebugInfoEntry *die, |
| 4355 | dw_offset_t spec_block_die_offset, |
| 4356 | DWARFCompileUnit **result_die_cu_handle) |
| 4357 | { |
| 4358 | if (die) |
| 4359 | { |
| 4360 | switch (die->Tag()) |
| 4361 | { |
| 4362 | case DW_TAG_subprogram: |
| 4363 | case DW_TAG_inlined_subroutine: |
| 4364 | case DW_TAG_lexical_block: |
| 4365 | { |
| 4366 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset) |
| 4367 | { |
| 4368 | *result_die_cu_handle = dwarf_cu; |
| 4369 | return die; |
| 4370 | } |
| 4371 | |
| 4372 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset) |
| 4373 | { |
| 4374 | *result_die_cu_handle = dwarf_cu; |
| 4375 | return die; |
| 4376 | } |
| 4377 | } |
| 4378 | break; |
| 4379 | } |
| 4380 | |
| 4381 | // Give the concrete function die specified by "func_die_offset", find the |
| 4382 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points |
| 4383 | // to "spec_block_die_offset" |
| 4384 | for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling()) |
| 4385 | { |
| 4386 | const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu, |
| 4387 | child_die, |
| 4388 | spec_block_die_offset, |
| 4389 | result_die_cu_handle); |
| 4390 | if (result_die) |
| 4391 | return result_die; |
| 4392 | } |
| 4393 | } |
| 4394 | |
| 4395 | *result_die_cu_handle = NULL; |
| 4396 | return NULL; |
| 4397 | } |
| 4398 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4399 | size_t |
| 4400 | SymbolFileDWARF::ParseVariables |
| 4401 | ( |
| 4402 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4403 | DWARFCompileUnit* dwarf_cu, |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 4404 | const lldb::addr_t func_low_pc, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4405 | const DWARFDebugInfoEntry *orig_die, |
| 4406 | bool parse_siblings, |
| 4407 | bool parse_children, |
| 4408 | VariableList* cc_variable_list |
| 4409 | ) |
| 4410 | { |
| 4411 | if (orig_die == NULL) |
| 4412 | return 0; |
| 4413 | |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4414 | VariableListSP variable_list_sp; |
| 4415 | |
| 4416 | size_t vars_added = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4417 | const DWARFDebugInfoEntry *die = orig_die; |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4418 | while (die != NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4419 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4420 | dw_tag_t tag = die->Tag(); |
| 4421 | |
| 4422 | // Check to see if we have already parsed this variable or constant? |
| 4423 | if (m_die_to_variable_sp[die]) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4424 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4425 | if (cc_variable_list) |
| 4426 | cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4427 | } |
| 4428 | else |
| 4429 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4430 | // We haven't already parsed it, lets do that now. |
| 4431 | if ((tag == DW_TAG_variable) || |
| 4432 | (tag == DW_TAG_constant) || |
| 4433 | (tag == DW_TAG_formal_parameter && sc.function)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4434 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4435 | if (variable_list_sp.get() == NULL) |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 4436 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4437 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die); |
| 4438 | dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
| 4439 | switch (parent_tag) |
| 4440 | { |
| 4441 | case DW_TAG_compile_unit: |
| 4442 | if (sc.comp_unit != NULL) |
| 4443 | { |
| 4444 | variable_list_sp = sc.comp_unit->GetVariableList(false); |
| 4445 | if (variable_list_sp.get() == NULL) |
| 4446 | { |
| 4447 | variable_list_sp.reset(new VariableList()); |
| 4448 | sc.comp_unit->SetVariableList(variable_list_sp); |
| 4449 | } |
| 4450 | } |
| 4451 | else |
| 4452 | { |
| 4453 | fprintf (stderr, |
| 4454 | "error: parent 0x%8.8x %s with no valid compile unit in symbol context for 0x%8.8x %s.\n", |
| 4455 | sc_parent_die->GetOffset(), |
| 4456 | DW_TAG_value_to_name (parent_tag), |
| 4457 | orig_die->GetOffset(), |
| 4458 | DW_TAG_value_to_name (orig_die->Tag())); |
| 4459 | } |
| 4460 | break; |
| 4461 | |
| 4462 | case DW_TAG_subprogram: |
| 4463 | case DW_TAG_inlined_subroutine: |
| 4464 | case DW_TAG_lexical_block: |
| 4465 | if (sc.function != NULL) |
| 4466 | { |
| 4467 | // Check to see if we already have parsed the variables for the given scope |
| 4468 | |
| 4469 | Block *block = sc.function->GetBlock(true).FindBlockByID(sc_parent_die->GetOffset()); |
| 4470 | if (block == NULL) |
| 4471 | { |
| 4472 | // This must be a specification or abstract origin with |
| 4473 | // a concrete block couterpart in the current function. We need |
| 4474 | // to find the concrete block so we can correctly add the |
| 4475 | // variable to it |
| 4476 | DWARFCompileUnit *concrete_block_die_cu = dwarf_cu; |
| 4477 | const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(), |
| 4478 | sc_parent_die->GetOffset(), |
| 4479 | &concrete_block_die_cu); |
| 4480 | if (concrete_block_die) |
| 4481 | block = sc.function->GetBlock(true).FindBlockByID(concrete_block_die->GetOffset()); |
| 4482 | } |
| 4483 | |
| 4484 | if (block != NULL) |
| 4485 | { |
| 4486 | const bool can_create = false; |
| 4487 | variable_list_sp = block->GetBlockVariableList (can_create); |
| 4488 | if (variable_list_sp.get() == NULL) |
| 4489 | { |
| 4490 | variable_list_sp.reset(new VariableList()); |
| 4491 | block->SetVariableList(variable_list_sp); |
| 4492 | } |
| 4493 | } |
| 4494 | } |
| 4495 | break; |
| 4496 | |
| 4497 | default: |
| 4498 | fprintf (stderr, |
| 4499 | "error: didn't find appropriate parent DIE for variable list for 0x%8.8x %s.\n", |
| 4500 | orig_die->GetOffset(), |
| 4501 | DW_TAG_value_to_name (orig_die->Tag())); |
| 4502 | break; |
| 4503 | } |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 4504 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4505 | |
| 4506 | if (variable_list_sp) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4507 | { |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 4508 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc)); |
| 4509 | if (var_sp) |
| 4510 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4511 | variable_list_sp->AddVariableIfUnique (var_sp); |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 4512 | if (cc_variable_list) |
| 4513 | cc_variable_list->AddVariableIfUnique (var_sp); |
| 4514 | ++vars_added; |
| 4515 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4516 | } |
| 4517 | } |
| 4518 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4519 | |
| 4520 | bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram); |
| 4521 | |
| 4522 | if (!skip_children && parse_children && die->HasChildren()) |
| 4523 | { |
| 4524 | vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list); |
| 4525 | } |
| 4526 | |
| 4527 | if (parse_siblings) |
| 4528 | die = die->GetSibling(); |
| 4529 | else |
| 4530 | die = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4531 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4532 | return vars_added; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4533 | } |
| 4534 | |
| 4535 | //------------------------------------------------------------------ |
| 4536 | // PluginInterface protocol |
| 4537 | //------------------------------------------------------------------ |
| 4538 | const char * |
| 4539 | SymbolFileDWARF::GetPluginName() |
| 4540 | { |
| 4541 | return "SymbolFileDWARF"; |
| 4542 | } |
| 4543 | |
| 4544 | const char * |
| 4545 | SymbolFileDWARF::GetShortPluginName() |
| 4546 | { |
| 4547 | return GetPluginNameStatic(); |
| 4548 | } |
| 4549 | |
| 4550 | uint32_t |
| 4551 | SymbolFileDWARF::GetPluginVersion() |
| 4552 | { |
| 4553 | return 1; |
| 4554 | } |
| 4555 | |
| 4556 | void |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 4557 | SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl) |
| 4558 | { |
| 4559 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 4560 | clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); |
| 4561 | if (clang_type) |
| 4562 | symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); |
| 4563 | } |
| 4564 | |
| 4565 | void |
| 4566 | SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl) |
| 4567 | { |
| 4568 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 4569 | clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); |
| 4570 | if (clang_type) |
| 4571 | symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); |
| 4572 | } |
| 4573 | |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 4574 | void |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 4575 | SymbolFileDWARF::DumpIndexes () |
| 4576 | { |
| 4577 | StreamFile s(stdout, false); |
| 4578 | |
| 4579 | s.Printf ("DWARF index for (%s) '%s/%s':", |
| 4580 | GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(), |
| 4581 | GetObjectFile()->GetFileSpec().GetDirectory().AsCString(), |
| 4582 | GetObjectFile()->GetFileSpec().GetFilename().AsCString()); |
| 4583 | s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s); |
| 4584 | s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s); |
| 4585 | s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s); |
| 4586 | s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s); |
| 4587 | s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s); |
| 4588 | s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s); |
| 4589 | s.Printf("\nTypes:\n"); m_type_index.Dump (&s); |
| 4590 | s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s); |
| 4591 | } |
| 4592 | |
| 4593 | void |
| 4594 | SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context, |
| 4595 | const char *name, |
| 4596 | llvm::SmallVectorImpl <clang::NamedDecl *> *results) |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 4597 | { |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 4598 | DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context); |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 4599 | |
| 4600 | if (iter == m_decl_ctx_to_die.end()) |
| 4601 | return; |
| 4602 | |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 4603 | const DWARFDebugInfoEntry *context_die = iter->second; |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 4604 | |
| 4605 | if (!results) |
| 4606 | return; |
| 4607 | |
| 4608 | DWARFDebugInfo* info = DebugInfo(); |
| 4609 | |
| 4610 | std::vector<NameToDIE::Info> die_info_array; |
| 4611 | |
| Greg Clayton | 1d4313b | 2011-07-07 04:49:07 +0000 | [diff] [blame] | 4612 | size_t num_matches = m_type_index.Find (ConstString(name), die_info_array); |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 4613 | |
| 4614 | if (num_matches) |
| 4615 | { |
| 4616 | for (int i = 0; |
| 4617 | i < num_matches; |
| 4618 | ++i) |
| 4619 | { |
| 4620 | DWARFCompileUnit* compile_unit = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx); |
| 4621 | compile_unit->ExtractDIEsIfNeeded (false); |
| 4622 | const DWARFDebugInfoEntry *die = compile_unit->GetDIEAtIndexUnchecked(die_info_array[i].die_idx); |
| 4623 | |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 4624 | if (die->GetParent() != context_die) |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 4625 | continue; |
| 4626 | |
| 4627 | Type *matching_type = ResolveType (compile_unit, die); |
| 4628 | |
| 4629 | lldb::clang_type_t type = matching_type->GetClangFullType(); |
| 4630 | clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type); |
| 4631 | |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 4632 | if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr())) |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 4633 | { |
| 4634 | clang::TagDecl *tag_decl = tag_type->getDecl(); |
| 4635 | results->push_back(tag_decl); |
| 4636 | } |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 4637 | else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr())) |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 4638 | { |
| 4639 | clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl(); |
| 4640 | results->push_back(typedef_decl); |
| 4641 | } |
| 4642 | } |
| 4643 | } |
| 4644 | } |
| 4645 | |
| 4646 | void |
| 4647 | SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton, |
| 4648 | const clang::DeclContext *DC, |
| 4649 | clang::DeclarationName Name, |
| 4650 | llvm::SmallVectorImpl <clang::NamedDecl *> *results) |
| 4651 | { |
| 4652 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 4653 | |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 4654 | symbol_file_dwarf->SearchDeclContext (DC, Name.getAsString().c_str(), results); |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 4655 | } |