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