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