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