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