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