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