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