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