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