Chris Lattner | 24943d2 | 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 | 2546fd2 | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclObjC.h" |
Chris Lattner | 24943d2 | 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 | 2403b5e | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 24 | #include "clang/Sema/DeclSpec.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 25 | |
Sean Callanan | 9b6898f | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 26 | #include "llvm/Support/Casting.h" |
| 27 | |
Chris Lattner | 24943d2 | 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 | 7412475 | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 33 | #include "lldb/Core/StreamFile.h" |
Jim Ingham | 5454892 | 2011-08-26 19:44:13 +0000 | [diff] [blame] | 34 | #include "lldb/Core/StreamString.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 35 | #include "lldb/Core/Timer.h" |
| 36 | #include "lldb/Core/Value.h" |
| 37 | |
Greg Clayton | 9f54ab7 | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 38 | #include "lldb/Host/Host.h" |
| 39 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 40 | #include "lldb/Symbol/Block.h" |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 41 | #include "lldb/Symbol/ClangExternalASTSourceCallbacks.h" |
Chris Lattner | 24943d2 | 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 | fdf24ef | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 48 | #include "lldb/Target/ObjCLanguageRuntime.h" |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 49 | #include "lldb/Target/CPPLanguageRuntime.h" |
Jim Ingham | fdf24ef | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 50 | |
Chris Lattner | 24943d2 | 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 | ad60bf4 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 63 | #include "SymbolFileDWARFDebugMap.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 64 | |
| 65 | #include <map> |
| 66 | |
Greg Clayton | 07c55d1 | 2010-11-11 01:09:45 +0000 | [diff] [blame] | 67 | //#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN |
Greg Clayton | b433a3d | 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 | 4fb400f | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 76 | #define DIE_IS_BEING_PARSED ((lldb_private::Type*)1) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 77 | |
| 78 | using namespace lldb; |
| 79 | using namespace lldb_private; |
| 80 | |
Greg Clayton | d7fc5b8 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 81 | static inline bool |
Sean Callanan | 8f2e392 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 82 | child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag) |
Greg Clayton | d7fc5b8 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 83 | { |
Sean Callanan | 8f2e392 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 84 | switch (tag) |
| 85 | { |
| 86 | default: |
| 87 | break; |
| 88 | case DW_TAG_subprogram: |
| 89 | case DW_TAG_inlined_subroutine: |
| 90 | case DW_TAG_class_type: |
| 91 | case DW_TAG_structure_type: |
| 92 | case DW_TAG_union_type: |
| 93 | return true; |
| 94 | } |
| 95 | return false; |
Greg Clayton | d7fc5b8 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 96 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 97 | |
Sean Callanan | 70a4f92 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 98 | static AccessType |
Greg Clayton | 84f8075 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 99 | DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 100 | { |
| 101 | switch (dwarf_accessibility) |
| 102 | { |
Sean Callanan | 70a4f92 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 103 | case DW_ACCESS_public: return eAccessPublic; |
| 104 | case DW_ACCESS_private: return eAccessPrivate; |
| 105 | case DW_ACCESS_protected: return eAccessProtected; |
Greg Clayton | 84f8075 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 106 | default: break; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 107 | } |
Sean Callanan | 70a4f92 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 108 | return eAccessNone; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | void |
| 112 | SymbolFileDWARF::Initialize() |
| 113 | { |
| 114 | LogChannelDWARF::Initialize(); |
| 115 | PluginManager::RegisterPlugin (GetPluginNameStatic(), |
| 116 | GetPluginDescriptionStatic(), |
| 117 | CreateInstance); |
| 118 | } |
| 119 | |
| 120 | void |
| 121 | SymbolFileDWARF::Terminate() |
| 122 | { |
| 123 | PluginManager::UnregisterPlugin (CreateInstance); |
| 124 | LogChannelDWARF::Initialize(); |
| 125 | } |
| 126 | |
| 127 | |
| 128 | const char * |
| 129 | SymbolFileDWARF::GetPluginNameStatic() |
| 130 | { |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 131 | return "dwarf"; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | const char * |
| 135 | SymbolFileDWARF::GetPluginDescriptionStatic() |
| 136 | { |
| 137 | return "DWARF and DWARF3 debug symbol file reader."; |
| 138 | } |
| 139 | |
| 140 | |
| 141 | SymbolFile* |
| 142 | SymbolFileDWARF::CreateInstance (ObjectFile* obj_file) |
| 143 | { |
| 144 | return new SymbolFileDWARF(obj_file); |
| 145 | } |
| 146 | |
Greg Clayton | e98ac25 | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 147 | TypeList * |
| 148 | SymbolFileDWARF::GetTypeList () |
| 149 | { |
| 150 | if (m_debug_map_symfile) |
| 151 | return m_debug_map_symfile->GetTypeList(); |
| 152 | return m_obj_file->GetModule()->GetTypeList(); |
| 153 | |
| 154 | } |
| 155 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 156 | //---------------------------------------------------------------------- |
| 157 | // Gets the first parent that is a lexical block, function or inlined |
| 158 | // subroutine, or compile unit. |
| 159 | //---------------------------------------------------------------------- |
| 160 | static const DWARFDebugInfoEntry * |
| 161 | GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die) |
| 162 | { |
| 163 | const DWARFDebugInfoEntry *die; |
| 164 | for (die = child_die->GetParent(); die != NULL; die = die->GetParent()) |
| 165 | { |
| 166 | dw_tag_t tag = die->Tag(); |
| 167 | |
| 168 | switch (tag) |
| 169 | { |
| 170 | case DW_TAG_compile_unit: |
| 171 | case DW_TAG_subprogram: |
| 172 | case DW_TAG_inlined_subroutine: |
| 173 | case DW_TAG_lexical_block: |
| 174 | return die; |
| 175 | } |
| 176 | } |
| 177 | return NULL; |
| 178 | } |
| 179 | |
| 180 | |
Greg Clayton | ad60bf4 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 181 | SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) : |
| 182 | SymbolFile (objfile), |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 183 | UserID (0), // Used by SymbolFileDWARFDebugMap to when this class parses .o files to contain the .o file index/ID |
Greg Clayton | ad60bf4 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 184 | m_debug_map_symfile (NULL), |
Greg Clayton | e5748d8 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 185 | m_clang_tu_decl (NULL), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 186 | m_flags(), |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 187 | m_data_debug_abbrev (), |
| 188 | m_data_debug_aranges (), |
| 189 | m_data_debug_frame (), |
| 190 | m_data_debug_info (), |
| 191 | m_data_debug_line (), |
| 192 | m_data_debug_loc (), |
| 193 | m_data_debug_ranges (), |
| 194 | m_data_debug_str (), |
Greg Clayton | f6e3de2 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 195 | m_data_apple_names (), |
| 196 | m_data_apple_types (), |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 197 | m_data_apple_namespaces (), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 198 | m_abbr(), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 199 | m_info(), |
| 200 | m_line(), |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 201 | m_apple_names_ap (), |
| 202 | m_apple_types_ap (), |
| 203 | m_apple_namespaces_ap (), |
Greg Clayton | 24a6bd9 | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 204 | m_apple_objc_ap (), |
Greg Clayton | 7412475 | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 205 | m_function_basename_index(), |
| 206 | m_function_fullname_index(), |
| 207 | m_function_method_index(), |
| 208 | m_function_selector_index(), |
Greg Clayton | ad60bf4 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 209 | m_objc_class_selectors_index(), |
Greg Clayton | 7412475 | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 210 | m_global_index(), |
Greg Clayton | fcf06fb | 2010-10-15 02:03:22 +0000 | [diff] [blame] | 211 | m_type_index(), |
| 212 | m_namespace_index(), |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 213 | m_indexed (false), |
| 214 | m_is_external_ast_source (false), |
Greg Clayton | bbe3916 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 215 | m_using_apple_tables (false), |
Greg Clayton | e6b976d | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 216 | m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate), |
Greg Clayton | a8d4241 | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 217 | m_ranges(), |
| 218 | m_unique_ast_type_map () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 219 | { |
| 220 | } |
| 221 | |
| 222 | SymbolFileDWARF::~SymbolFileDWARF() |
| 223 | { |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 224 | if (m_is_external_ast_source) |
| 225 | m_obj_file->GetModule()->GetClangASTContext().RemoveExternalSource (); |
| 226 | } |
| 227 | |
| 228 | static const ConstString & |
| 229 | GetDWARFMachOSegmentName () |
| 230 | { |
| 231 | static ConstString g_dwarf_section_name ("__DWARF"); |
| 232 | return g_dwarf_section_name; |
| 233 | } |
| 234 | |
Greg Clayton | c3c4661 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 235 | UniqueDWARFASTTypeMap & |
| 236 | SymbolFileDWARF::GetUniqueDWARFASTTypeMap () |
| 237 | { |
| 238 | if (m_debug_map_symfile) |
| 239 | return m_debug_map_symfile->GetUniqueDWARFASTTypeMap (); |
| 240 | return m_unique_ast_type_map; |
| 241 | } |
| 242 | |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 243 | ClangASTContext & |
| 244 | SymbolFileDWARF::GetClangASTContext () |
| 245 | { |
| 246 | if (m_debug_map_symfile) |
| 247 | return m_debug_map_symfile->GetClangASTContext (); |
| 248 | |
| 249 | ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext(); |
| 250 | if (!m_is_external_ast_source) |
| 251 | { |
| 252 | m_is_external_ast_source = true; |
| 253 | llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap ( |
| 254 | new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl, |
| 255 | SymbolFileDWARF::CompleteObjCInterfaceDecl, |
Greg Clayton | e6d72ca | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 256 | SymbolFileDWARF::FindExternalVisibleDeclsByName, |
Greg Clayton | 3fc0c4f | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 257 | SymbolFileDWARF::LayoutRecordType, |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 258 | this)); |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 259 | ast.SetExternalSource (ast_source_ap); |
| 260 | } |
| 261 | return ast; |
| 262 | } |
| 263 | |
| 264 | void |
| 265 | SymbolFileDWARF::InitializeObject() |
| 266 | { |
| 267 | // Install our external AST source callbacks so we can complete Clang types. |
| 268 | Module *module = m_obj_file->GetModule(); |
| 269 | if (module) |
| 270 | { |
| 271 | const SectionList *section_list = m_obj_file->GetSectionList(); |
| 272 | |
| 273 | const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get(); |
| 274 | |
| 275 | // Memory map the DWARF mach-o segment so we have everything mmap'ed |
| 276 | // to keep our heap memory usage down. |
| 277 | if (section) |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame^] | 278 | m_obj_file->MemoryMapSectionData(section, m_dwarf_data); |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 279 | } |
Greg Clayton | 9a93fcd | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 280 | get_apple_names_data(); |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 281 | if (m_data_apple_names.GetByteSize() > 0) |
| 282 | { |
Greg Clayton | bbe3916 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 283 | m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names")); |
| 284 | if (m_apple_names_ap->IsValid()) |
| 285 | m_using_apple_tables = true; |
| 286 | else |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 287 | m_apple_names_ap.reset(); |
| 288 | } |
Greg Clayton | 9a93fcd | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 289 | get_apple_types_data(); |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 290 | if (m_data_apple_types.GetByteSize() > 0) |
| 291 | { |
Greg Clayton | bbe3916 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 292 | m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types")); |
| 293 | if (m_apple_types_ap->IsValid()) |
| 294 | m_using_apple_tables = true; |
| 295 | else |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 296 | m_apple_types_ap.reset(); |
| 297 | } |
| 298 | |
| 299 | get_apple_namespaces_data(); |
| 300 | if (m_data_apple_namespaces.GetByteSize() > 0) |
| 301 | { |
Greg Clayton | bbe3916 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 302 | m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces")); |
| 303 | if (m_apple_namespaces_ap->IsValid()) |
| 304 | m_using_apple_tables = true; |
| 305 | else |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 306 | m_apple_namespaces_ap.reset(); |
| 307 | } |
Greg Clayton | 9a93fcd | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 308 | |
Greg Clayton | 24a6bd9 | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 309 | get_apple_objc_data(); |
| 310 | if (m_data_apple_objc.GetByteSize() > 0) |
| 311 | { |
| 312 | m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc")); |
| 313 | if (m_apple_objc_ap->IsValid()) |
| 314 | m_using_apple_tables = true; |
| 315 | else |
| 316 | m_apple_objc_ap.reset(); |
| 317 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | bool |
| 321 | SymbolFileDWARF::SupportedVersion(uint16_t version) |
| 322 | { |
| 323 | return version == 2 || version == 3; |
| 324 | } |
| 325 | |
| 326 | uint32_t |
Sean Callanan | d0b7cfa | 2011-12-03 04:38:43 +0000 | [diff] [blame] | 327 | SymbolFileDWARF::CalculateAbilities () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 328 | { |
| 329 | uint32_t abilities = 0; |
| 330 | if (m_obj_file != NULL) |
| 331 | { |
| 332 | const Section* section = NULL; |
| 333 | const SectionList *section_list = m_obj_file->GetSectionList(); |
| 334 | if (section_list == NULL) |
| 335 | return 0; |
| 336 | |
| 337 | uint64_t debug_abbrev_file_size = 0; |
| 338 | uint64_t debug_aranges_file_size = 0; |
| 339 | uint64_t debug_frame_file_size = 0; |
| 340 | uint64_t debug_info_file_size = 0; |
| 341 | uint64_t debug_line_file_size = 0; |
| 342 | uint64_t debug_loc_file_size = 0; |
| 343 | uint64_t debug_macinfo_file_size = 0; |
| 344 | uint64_t debug_pubnames_file_size = 0; |
| 345 | uint64_t debug_pubtypes_file_size = 0; |
| 346 | uint64_t debug_ranges_file_size = 0; |
| 347 | uint64_t debug_str_file_size = 0; |
| 348 | |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 349 | section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 350 | |
| 351 | if (section) |
Greg Clayton | 32a8c7e | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 352 | section_list = §ion->GetChildren (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 353 | |
Greg Clayton | 32a8c7e | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 354 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 355 | if (section != NULL) |
| 356 | { |
| 357 | debug_info_file_size = section->GetByteSize(); |
| 358 | |
Greg Clayton | 32a8c7e | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 359 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 360 | if (section) |
| 361 | debug_abbrev_file_size = section->GetByteSize(); |
| 362 | else |
| 363 | m_flags.Set (flagsGotDebugAbbrevData); |
| 364 | |
Greg Clayton | 32a8c7e | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 365 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 366 | if (section) |
| 367 | debug_aranges_file_size = section->GetByteSize(); |
| 368 | else |
| 369 | m_flags.Set (flagsGotDebugArangesData); |
| 370 | |
Greg Clayton | 32a8c7e | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 371 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 372 | if (section) |
| 373 | debug_frame_file_size = section->GetByteSize(); |
| 374 | else |
| 375 | m_flags.Set (flagsGotDebugFrameData); |
| 376 | |
Greg Clayton | 32a8c7e | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 377 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 378 | if (section) |
| 379 | debug_line_file_size = section->GetByteSize(); |
| 380 | else |
| 381 | m_flags.Set (flagsGotDebugLineData); |
| 382 | |
Greg Clayton | 32a8c7e | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 383 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 384 | if (section) |
| 385 | debug_loc_file_size = section->GetByteSize(); |
| 386 | else |
| 387 | m_flags.Set (flagsGotDebugLocData); |
| 388 | |
Greg Clayton | 32a8c7e | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 389 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 390 | if (section) |
| 391 | debug_macinfo_file_size = section->GetByteSize(); |
| 392 | else |
| 393 | m_flags.Set (flagsGotDebugMacInfoData); |
| 394 | |
Greg Clayton | 32a8c7e | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 395 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 396 | if (section) |
| 397 | debug_pubnames_file_size = section->GetByteSize(); |
| 398 | else |
| 399 | m_flags.Set (flagsGotDebugPubNamesData); |
| 400 | |
Greg Clayton | 32a8c7e | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 401 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 402 | if (section) |
| 403 | debug_pubtypes_file_size = section->GetByteSize(); |
| 404 | else |
| 405 | m_flags.Set (flagsGotDebugPubTypesData); |
| 406 | |
Greg Clayton | 32a8c7e | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 407 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 408 | if (section) |
| 409 | debug_ranges_file_size = section->GetByteSize(); |
| 410 | else |
| 411 | m_flags.Set (flagsGotDebugRangesData); |
| 412 | |
Greg Clayton | 32a8c7e | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 413 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 414 | if (section) |
| 415 | debug_str_file_size = section->GetByteSize(); |
| 416 | else |
| 417 | m_flags.Set (flagsGotDebugStrData); |
| 418 | } |
| 419 | |
| 420 | if (debug_abbrev_file_size > 0 && debug_info_file_size > 0) |
| 421 | abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes; |
| 422 | |
| 423 | if (debug_line_file_size > 0) |
| 424 | abilities |= LineTables; |
| 425 | |
| 426 | if (debug_aranges_file_size > 0) |
| 427 | abilities |= AddressAcceleratorTable; |
| 428 | |
| 429 | if (debug_pubnames_file_size > 0) |
| 430 | abilities |= FunctionAcceleratorTable; |
| 431 | |
| 432 | if (debug_pubtypes_file_size > 0) |
| 433 | abilities |= TypeAcceleratorTable; |
| 434 | |
| 435 | if (debug_macinfo_file_size > 0) |
| 436 | abilities |= MacroInformation; |
| 437 | |
| 438 | if (debug_frame_file_size > 0) |
| 439 | abilities |= CallFrameInformation; |
| 440 | } |
| 441 | return abilities; |
| 442 | } |
| 443 | |
| 444 | const DataExtractor& |
Greg Clayton | 32a8c7e | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 445 | SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 446 | { |
| 447 | if (m_flags.IsClear (got_flag)) |
| 448 | { |
| 449 | m_flags.Set (got_flag); |
| 450 | const SectionList *section_list = m_obj_file->GetSectionList(); |
| 451 | if (section_list) |
| 452 | { |
Greg Clayton | 32a8c7e | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 453 | Section *section = section_list->FindSectionByType(sect_type, true).get(); |
| 454 | if (section) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 455 | { |
| 456 | // See if we memory mapped the DWARF segment? |
| 457 | if (m_dwarf_data.GetByteSize()) |
| 458 | { |
| 459 | data.SetData(m_dwarf_data, section->GetOffset (), section->GetByteSize()); |
| 460 | } |
| 461 | else |
| 462 | { |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame^] | 463 | if (m_obj_file->ReadSectionData (section, data) == 0) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 464 | data.Clear(); |
| 465 | } |
| 466 | } |
| 467 | } |
| 468 | } |
| 469 | return data; |
| 470 | } |
| 471 | |
| 472 | const DataExtractor& |
| 473 | SymbolFileDWARF::get_debug_abbrev_data() |
| 474 | { |
Greg Clayton | 32a8c7e | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 475 | return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | const DataExtractor& |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 479 | SymbolFileDWARF::get_debug_aranges_data() |
| 480 | { |
| 481 | return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges); |
| 482 | } |
| 483 | |
| 484 | const DataExtractor& |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 485 | SymbolFileDWARF::get_debug_frame_data() |
| 486 | { |
Greg Clayton | 32a8c7e | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 487 | return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | const DataExtractor& |
| 491 | SymbolFileDWARF::get_debug_info_data() |
| 492 | { |
Greg Clayton | 32a8c7e | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 493 | return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | const DataExtractor& |
| 497 | SymbolFileDWARF::get_debug_line_data() |
| 498 | { |
Greg Clayton | 32a8c7e | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 499 | return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | const DataExtractor& |
| 503 | SymbolFileDWARF::get_debug_loc_data() |
| 504 | { |
Greg Clayton | 32a8c7e | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 505 | return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | const DataExtractor& |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 509 | SymbolFileDWARF::get_debug_ranges_data() |
| 510 | { |
Greg Clayton | 32a8c7e | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 511 | return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | const DataExtractor& |
| 515 | SymbolFileDWARF::get_debug_str_data() |
| 516 | { |
Greg Clayton | 32a8c7e | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 517 | return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 518 | } |
| 519 | |
Greg Clayton | c8cf5e2 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 520 | const DataExtractor& |
Greg Clayton | f6e3de2 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 521 | SymbolFileDWARF::get_apple_names_data() |
Greg Clayton | c8cf5e2 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 522 | { |
Greg Clayton | 24a6bd9 | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 523 | return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names); |
Greg Clayton | c8cf5e2 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | const DataExtractor& |
Greg Clayton | f6e3de2 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 527 | SymbolFileDWARF::get_apple_types_data() |
Greg Clayton | c8cf5e2 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 528 | { |
Greg Clayton | 24a6bd9 | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 529 | return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types); |
Greg Clayton | c8cf5e2 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 530 | } |
| 531 | |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 532 | const DataExtractor& |
| 533 | SymbolFileDWARF::get_apple_namespaces_data() |
| 534 | { |
Greg Clayton | 24a6bd9 | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 535 | return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces); |
| 536 | } |
| 537 | |
| 538 | const DataExtractor& |
| 539 | SymbolFileDWARF::get_apple_objc_data() |
| 540 | { |
| 541 | return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc); |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 542 | } |
| 543 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 544 | |
| 545 | DWARFDebugAbbrev* |
| 546 | SymbolFileDWARF::DebugAbbrev() |
| 547 | { |
| 548 | if (m_abbr.get() == NULL) |
| 549 | { |
| 550 | const DataExtractor &debug_abbrev_data = get_debug_abbrev_data(); |
| 551 | if (debug_abbrev_data.GetByteSize() > 0) |
| 552 | { |
| 553 | m_abbr.reset(new DWARFDebugAbbrev()); |
| 554 | if (m_abbr.get()) |
| 555 | m_abbr->Parse(debug_abbrev_data); |
| 556 | } |
| 557 | } |
| 558 | return m_abbr.get(); |
| 559 | } |
| 560 | |
| 561 | const DWARFDebugAbbrev* |
| 562 | SymbolFileDWARF::DebugAbbrev() const |
| 563 | { |
| 564 | return m_abbr.get(); |
| 565 | } |
| 566 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 567 | |
| 568 | DWARFDebugInfo* |
| 569 | SymbolFileDWARF::DebugInfo() |
| 570 | { |
| 571 | if (m_info.get() == NULL) |
| 572 | { |
| 573 | Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this); |
| 574 | if (get_debug_info_data().GetByteSize() > 0) |
| 575 | { |
| 576 | m_info.reset(new DWARFDebugInfo()); |
| 577 | if (m_info.get()) |
| 578 | { |
| 579 | m_info->SetDwarfData(this); |
| 580 | } |
| 581 | } |
| 582 | } |
| 583 | return m_info.get(); |
| 584 | } |
| 585 | |
| 586 | const DWARFDebugInfo* |
| 587 | SymbolFileDWARF::DebugInfo() const |
| 588 | { |
| 589 | return m_info.get(); |
| 590 | } |
| 591 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 592 | DWARFCompileUnit* |
| 593 | SymbolFileDWARF::GetDWARFCompileUnitForUID(lldb::user_id_t cu_uid) |
| 594 | { |
| 595 | DWARFDebugInfo* info = DebugInfo(); |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 596 | if (info && UserIDMatches(cu_uid)) |
| 597 | return info->GetCompileUnit((dw_offset_t)cu_uid).get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 598 | return NULL; |
| 599 | } |
| 600 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 601 | |
| 602 | DWARFDebugRanges* |
| 603 | SymbolFileDWARF::DebugRanges() |
| 604 | { |
| 605 | if (m_ranges.get() == NULL) |
| 606 | { |
| 607 | Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this); |
| 608 | if (get_debug_ranges_data().GetByteSize() > 0) |
| 609 | { |
| 610 | m_ranges.reset(new DWARFDebugRanges()); |
| 611 | if (m_ranges.get()) |
| 612 | m_ranges->Extract(this); |
| 613 | } |
| 614 | } |
| 615 | return m_ranges.get(); |
| 616 | } |
| 617 | |
| 618 | const DWARFDebugRanges* |
| 619 | SymbolFileDWARF::DebugRanges() const |
| 620 | { |
| 621 | return m_ranges.get(); |
| 622 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 623 | |
| 624 | bool |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 625 | SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* curr_cu, CompUnitSP& compile_unit_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 626 | { |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 627 | if (curr_cu != NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 628 | { |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 629 | const DWARFDebugInfoEntry * cu_die = curr_cu->GetCompileUnitDIEOnly (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 630 | if (cu_die) |
| 631 | { |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 632 | const char * cu_die_name = cu_die->GetName(this, curr_cu); |
| 633 | const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, curr_cu, DW_AT_comp_dir, NULL); |
Jim Ingham | 24429c0 | 2011-08-24 23:34:20 +0000 | [diff] [blame] | 634 | LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, curr_cu, DW_AT_language, 0); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 635 | if (cu_die_name) |
| 636 | { |
Jim Ingham | c4547c5 | 2010-09-16 00:57:33 +0000 | [diff] [blame] | 637 | FileSpec cu_file_spec; |
| 638 | |
Greg Clayton | 7bb069b | 2011-02-09 23:39:34 +0000 | [diff] [blame] | 639 | if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0') |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 640 | { |
Jim Ingham | c4547c5 | 2010-09-16 00:57:33 +0000 | [diff] [blame] | 641 | // If we have a full path to the compile unit, we don't need to resolve |
| 642 | // the file. This can be expensive e.g. when the source files are NFS mounted. |
| 643 | cu_file_spec.SetFile (cu_die_name, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 644 | } |
| 645 | else |
| 646 | { |
| 647 | std::string fullpath(cu_comp_dir); |
| 648 | if (*fullpath.rbegin() != '/') |
| 649 | fullpath += '/'; |
| 650 | fullpath += cu_die_name; |
Jim Ingham | c4547c5 | 2010-09-16 00:57:33 +0000 | [diff] [blame] | 651 | cu_file_spec.SetFile (fullpath.c_str(), false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 652 | } |
| 653 | |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 654 | compile_unit_sp.reset(new CompileUnit (m_obj_file->GetModule(), |
| 655 | curr_cu, |
| 656 | cu_file_spec, |
| 657 | MakeUserID(curr_cu->GetOffset()), |
| 658 | cu_language)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 659 | if (compile_unit_sp.get()) |
| 660 | { |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 661 | curr_cu->SetUserData(compile_unit_sp.get()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 662 | return true; |
| 663 | } |
| 664 | } |
| 665 | } |
| 666 | } |
| 667 | return false; |
| 668 | } |
| 669 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 670 | uint32_t |
| 671 | SymbolFileDWARF::GetNumCompileUnits() |
| 672 | { |
| 673 | DWARFDebugInfo* info = DebugInfo(); |
| 674 | if (info) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 675 | return info->GetNumCompileUnits(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 676 | return 0; |
| 677 | } |
| 678 | |
| 679 | CompUnitSP |
| 680 | SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx) |
| 681 | { |
| 682 | CompUnitSP comp_unit; |
| 683 | DWARFDebugInfo* info = DebugInfo(); |
| 684 | if (info) |
| 685 | { |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 686 | DWARFCompileUnit* curr_cu = info->GetCompileUnitAtIndex(cu_idx); |
| 687 | if (curr_cu != NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 688 | { |
| 689 | // Our symbol vendor shouldn't be asking us to add a compile unit that |
| 690 | // has already been added to it, which this DWARF plug-in knows as it |
| 691 | // stores the lldb compile unit (CompileUnit) pointer in each |
| 692 | // DWARFCompileUnit object when it gets added. |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 693 | assert(curr_cu->GetUserData() == NULL); |
| 694 | ParseCompileUnit(curr_cu, comp_unit); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 695 | } |
| 696 | } |
| 697 | return comp_unit; |
| 698 | } |
| 699 | |
| 700 | static void |
Greg Clayton | bc36a86 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 701 | AddRangesToBlock (Block& block, |
| 702 | DWARFDebugRanges::RangeList& ranges, |
| 703 | addr_t block_base_addr) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 704 | { |
Greg Clayton | bc36a86 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 705 | const size_t num_ranges = ranges.GetSize(); |
| 706 | for (size_t i = 0; i<num_ranges; ++i) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 707 | { |
Greg Clayton | bc36a86 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 708 | const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i); |
| 709 | const addr_t range_base = range.GetRangeBase(); |
| 710 | assert (range_base >= block_base_addr); |
| 711 | block.AddRange(Block::Range (range_base - block_base_addr, range.GetByteSize()));; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 712 | } |
Greg Clayton | bc36a86 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 713 | block.FinalizeRanges (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | |
| 717 | Function * |
Greg Clayton | 1d8173f | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 718 | SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 719 | { |
| 720 | DWARFDebugRanges::RangeList func_ranges; |
| 721 | const char *name = NULL; |
| 722 | const char *mangled = NULL; |
| 723 | int decl_file = 0; |
| 724 | int decl_line = 0; |
| 725 | int decl_column = 0; |
| 726 | int call_file = 0; |
| 727 | int call_line = 0; |
| 728 | int call_column = 0; |
| 729 | DWARFExpression frame_base; |
| 730 | |
Greg Clayton | b433a3d | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 731 | assert (die->Tag() == DW_TAG_subprogram); |
| 732 | |
| 733 | if (die->Tag() != DW_TAG_subprogram) |
| 734 | return NULL; |
| 735 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 736 | if (die->GetDIENamesAndRanges(this, dwarf_cu, name, mangled, func_ranges, decl_file, decl_line, decl_column, call_file, call_line, call_column, &frame_base)) |
| 737 | { |
| 738 | // Union of all ranges in the function DIE (if the function is discontiguous) |
| 739 | AddressRange func_range; |
Greg Clayton | bc36a86 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 740 | lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0); |
| 741 | lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 742 | if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr) |
| 743 | { |
| 744 | func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList()); |
| 745 | if (func_range.GetBaseAddress().IsValid()) |
| 746 | func_range.SetByteSize(highest_func_addr - lowest_func_addr); |
| 747 | } |
| 748 | |
| 749 | if (func_range.GetBaseAddress().IsValid()) |
| 750 | { |
| 751 | Mangled func_name; |
| 752 | if (mangled) |
| 753 | func_name.SetValue(mangled, true); |
| 754 | else if (name) |
| 755 | func_name.SetValue(name, false); |
| 756 | |
| 757 | FunctionSP func_sp; |
| 758 | std::auto_ptr<Declaration> decl_ap; |
| 759 | if (decl_file != 0 || decl_line != 0 || decl_column != 0) |
Greg Clayton | feb6e56 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 760 | decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), |
| 761 | decl_line, |
| 762 | decl_column)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 763 | |
Greg Clayton | f92d0dd | 2011-09-30 20:52:25 +0000 | [diff] [blame] | 764 | // Supply the type _only_ if it has already been parsed |
Greg Clayton | 4fb400f | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 765 | Type *func_type = m_die_to_type.lookup (die); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 766 | |
| 767 | assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED); |
| 768 | |
| 769 | func_range.GetBaseAddress().ResolveLinkedAddress(); |
| 770 | |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 771 | const user_id_t func_user_id = MakeUserID(die->GetOffset()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 772 | func_sp.reset(new Function (sc.comp_unit, |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 773 | func_user_id, // UserID is the DIE offset |
| 774 | func_user_id, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 775 | func_name, |
| 776 | func_type, |
| 777 | func_range)); // first address range |
| 778 | |
| 779 | if (func_sp.get() != NULL) |
| 780 | { |
Greg Clayton | f92d0dd | 2011-09-30 20:52:25 +0000 | [diff] [blame] | 781 | if (frame_base.IsValid()) |
| 782 | func_sp->GetFrameBaseExpression() = frame_base; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 783 | sc.comp_unit->AddFunction(func_sp); |
| 784 | return func_sp.get(); |
| 785 | } |
| 786 | } |
| 787 | } |
| 788 | return NULL; |
| 789 | } |
| 790 | |
| 791 | size_t |
| 792 | SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc) |
| 793 | { |
| 794 | assert (sc.comp_unit); |
| 795 | size_t functions_added = 0; |
Greg Clayton | 1d8173f | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 796 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 797 | if (dwarf_cu) |
| 798 | { |
| 799 | DWARFDIECollection function_dies; |
| 800 | const size_t num_funtions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies); |
| 801 | size_t func_idx; |
| 802 | for (func_idx = 0; func_idx < num_funtions; ++func_idx) |
| 803 | { |
| 804 | const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx); |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 805 | if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 806 | { |
| 807 | if (ParseCompileUnitFunction(sc, dwarf_cu, die)) |
| 808 | ++functions_added; |
| 809 | } |
| 810 | } |
| 811 | //FixupTypes(); |
| 812 | } |
| 813 | return functions_added; |
| 814 | } |
| 815 | |
| 816 | bool |
| 817 | SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files) |
| 818 | { |
| 819 | assert (sc.comp_unit); |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 820 | DWARFCompileUnit* curr_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID()); |
| 821 | assert (curr_cu); |
| 822 | const DWARFDebugInfoEntry * cu_die = curr_cu->GetCompileUnitDIEOnly(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 823 | |
| 824 | if (cu_die) |
| 825 | { |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 826 | const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, curr_cu, DW_AT_comp_dir, NULL); |
| 827 | dw_offset_t stmt_list = cu_die->GetAttributeValueAsUnsigned(this, curr_cu, DW_AT_stmt_list, DW_INVALID_OFFSET); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 828 | |
| 829 | // All file indexes in DWARF are one based and a file of index zero is |
| 830 | // supposed to be the compile unit itself. |
| 831 | support_files.Append (*sc.comp_unit); |
| 832 | |
| 833 | return DWARFDebugLine::ParseSupportFiles(get_debug_line_data(), cu_comp_dir, stmt_list, support_files); |
| 834 | } |
| 835 | return false; |
| 836 | } |
| 837 | |
| 838 | struct ParseDWARFLineTableCallbackInfo |
| 839 | { |
| 840 | LineTable* line_table; |
| 841 | const SectionList *section_list; |
| 842 | lldb::addr_t prev_sect_file_base_addr; |
| 843 | lldb::addr_t curr_sect_file_base_addr; |
| 844 | bool is_oso_for_debug_map; |
| 845 | bool prev_in_final_executable; |
| 846 | DWARFDebugLine::Row prev_row; |
| 847 | SectionSP prev_section_sp; |
| 848 | SectionSP curr_section_sp; |
| 849 | }; |
| 850 | |
| 851 | //---------------------------------------------------------------------- |
| 852 | // ParseStatementTableCallback |
| 853 | //---------------------------------------------------------------------- |
| 854 | static void |
| 855 | ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData) |
| 856 | { |
| 857 | LineTable* line_table = ((ParseDWARFLineTableCallbackInfo*)userData)->line_table; |
| 858 | if (state.row == DWARFDebugLine::State::StartParsingLineTable) |
| 859 | { |
| 860 | // Just started parsing the line table |
| 861 | } |
| 862 | else if (state.row == DWARFDebugLine::State::DoneParsingLineTable) |
| 863 | { |
| 864 | // Done parsing line table, nothing to do for the cleanup |
| 865 | } |
| 866 | else |
| 867 | { |
| 868 | ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData; |
| 869 | // We have a new row, lets append it |
| 870 | |
| 871 | if (info->curr_section_sp.get() == NULL || info->curr_section_sp->ContainsFileAddress(state.address) == false) |
| 872 | { |
| 873 | info->prev_section_sp = info->curr_section_sp; |
| 874 | info->prev_sect_file_base_addr = info->curr_sect_file_base_addr; |
| 875 | // If this is an end sequence entry, then we subtract one from the |
| 876 | // address to make sure we get an address that is not the end of |
| 877 | // a section. |
| 878 | if (state.end_sequence && state.address != 0) |
| 879 | info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address - 1); |
| 880 | else |
| 881 | info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address); |
| 882 | |
| 883 | if (info->curr_section_sp.get()) |
| 884 | info->curr_sect_file_base_addr = info->curr_section_sp->GetFileAddress (); |
| 885 | else |
| 886 | info->curr_sect_file_base_addr = 0; |
| 887 | } |
| 888 | if (info->curr_section_sp.get()) |
| 889 | { |
| 890 | lldb::addr_t curr_line_section_offset = state.address - info->curr_sect_file_base_addr; |
| 891 | // Check for the fancy section magic to determine if we |
| 892 | |
| 893 | if (info->is_oso_for_debug_map) |
| 894 | { |
| 895 | // When this is a debug map object file that contains DWARF |
| 896 | // (referenced from an N_OSO debug map nlist entry) we will have |
| 897 | // a file address in the file range for our section from the |
| 898 | // original .o file, and a load address in the executable that |
| 899 | // contains the debug map. |
| 900 | // |
| 901 | // If the sections for the file range and load range are |
| 902 | // different, we have a remapped section for the function and |
| 903 | // this address is resolved. If they are the same, then the |
| 904 | // function for this address didn't make it into the final |
| 905 | // executable. |
| 906 | bool curr_in_final_executable = info->curr_section_sp->GetLinkedSection () != NULL; |
| 907 | |
| 908 | // If we are doing DWARF with debug map, then we need to carefully |
| 909 | // add each line table entry as there may be gaps as functions |
| 910 | // get moved around or removed. |
| 911 | if (!info->prev_row.end_sequence && info->prev_section_sp.get()) |
| 912 | { |
| 913 | if (info->prev_in_final_executable) |
| 914 | { |
| 915 | bool terminate_previous_entry = false; |
| 916 | if (!curr_in_final_executable) |
| 917 | { |
| 918 | // Check for the case where the previous line entry |
| 919 | // in a function made it into the final executable, |
| 920 | // yet the current line entry falls in a function |
| 921 | // that didn't. The line table used to be contiguous |
| 922 | // through this address range but now it isn't. We |
| 923 | // need to terminate the previous line entry so |
| 924 | // that we can reconstruct the line range correctly |
| 925 | // for it and to keep the line table correct. |
| 926 | terminate_previous_entry = true; |
| 927 | } |
| 928 | else if (info->curr_section_sp.get() != info->prev_section_sp.get()) |
| 929 | { |
| 930 | // Check for cases where the line entries used to be |
| 931 | // contiguous address ranges, but now they aren't. |
| 932 | // This can happen when order files specify the |
| 933 | // ordering of the functions. |
| 934 | lldb::addr_t prev_line_section_offset = info->prev_row.address - info->prev_sect_file_base_addr; |
| 935 | Section *curr_sect = info->curr_section_sp.get(); |
| 936 | Section *prev_sect = info->prev_section_sp.get(); |
| 937 | assert (curr_sect->GetLinkedSection()); |
| 938 | assert (prev_sect->GetLinkedSection()); |
| 939 | lldb::addr_t object_file_addr_delta = state.address - info->prev_row.address; |
| 940 | lldb::addr_t curr_linked_file_addr = curr_sect->GetLinkedFileAddress() + curr_line_section_offset; |
| 941 | lldb::addr_t prev_linked_file_addr = prev_sect->GetLinkedFileAddress() + prev_line_section_offset; |
| 942 | lldb::addr_t linked_file_addr_delta = curr_linked_file_addr - prev_linked_file_addr; |
| 943 | if (object_file_addr_delta != linked_file_addr_delta) |
| 944 | terminate_previous_entry = true; |
| 945 | } |
| 946 | |
| 947 | if (terminate_previous_entry) |
| 948 | { |
| 949 | line_table->InsertLineEntry (info->prev_section_sp, |
| 950 | state.address - info->prev_sect_file_base_addr, |
| 951 | info->prev_row.line, |
| 952 | info->prev_row.column, |
| 953 | info->prev_row.file, |
| 954 | false, // is_stmt |
| 955 | false, // basic_block |
| 956 | false, // state.prologue_end |
| 957 | false, // state.epilogue_begin |
| 958 | true); // end_sequence); |
| 959 | } |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | if (curr_in_final_executable) |
| 964 | { |
| 965 | line_table->InsertLineEntry (info->curr_section_sp, |
| 966 | curr_line_section_offset, |
| 967 | state.line, |
| 968 | state.column, |
| 969 | state.file, |
| 970 | state.is_stmt, |
| 971 | state.basic_block, |
| 972 | state.prologue_end, |
| 973 | state.epilogue_begin, |
| 974 | state.end_sequence); |
| 975 | info->prev_section_sp = info->curr_section_sp; |
| 976 | } |
| 977 | else |
| 978 | { |
| 979 | // If the current address didn't make it into the final |
| 980 | // executable, the current section will be the __text |
| 981 | // segment in the .o file, so we need to clear this so |
| 982 | // we can catch the next function that did make it into |
| 983 | // the final executable. |
| 984 | info->prev_section_sp.reset(); |
| 985 | info->curr_section_sp.reset(); |
| 986 | } |
| 987 | |
| 988 | info->prev_in_final_executable = curr_in_final_executable; |
| 989 | } |
| 990 | else |
| 991 | { |
| 992 | // We are not in an object file that contains DWARF for an |
| 993 | // N_OSO, this is just a normal DWARF file. The DWARF spec |
| 994 | // guarantees that the addresses will be in increasing order |
| 995 | // so, since we store line tables in file address order, we |
| 996 | // can always just append the line entry without needing to |
| 997 | // search for the correct insertion point (we don't need to |
| 998 | // use LineEntry::InsertLineEntry()). |
| 999 | line_table->AppendLineEntry (info->curr_section_sp, |
| 1000 | curr_line_section_offset, |
| 1001 | state.line, |
| 1002 | state.column, |
| 1003 | state.file, |
| 1004 | state.is_stmt, |
| 1005 | state.basic_block, |
| 1006 | state.prologue_end, |
| 1007 | state.epilogue_begin, |
| 1008 | state.end_sequence); |
| 1009 | } |
| 1010 | } |
| 1011 | |
| 1012 | info->prev_row = state; |
| 1013 | } |
| 1014 | } |
| 1015 | |
| 1016 | bool |
| 1017 | SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc) |
| 1018 | { |
| 1019 | assert (sc.comp_unit); |
| 1020 | if (sc.comp_unit->GetLineTable() != NULL) |
| 1021 | return true; |
| 1022 | |
| 1023 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID()); |
| 1024 | if (dwarf_cu) |
| 1025 | { |
| 1026 | const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly(); |
Greg Clayton | da52c49 | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1027 | if (dwarf_cu_die) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1028 | { |
Greg Clayton | da52c49 | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1029 | const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET); |
| 1030 | if (cu_line_offset != DW_INVALID_OFFSET) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1031 | { |
Greg Clayton | da52c49 | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1032 | std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit)); |
| 1033 | if (line_table_ap.get()) |
| 1034 | { |
| 1035 | ParseDWARFLineTableCallbackInfo info = { |
| 1036 | line_table_ap.get(), |
| 1037 | m_obj_file->GetSectionList(), |
| 1038 | 0, |
| 1039 | 0, |
| 1040 | m_debug_map_symfile != NULL, |
| 1041 | false, |
| 1042 | DWARFDebugLine::Row(), |
| 1043 | SectionSP(), |
| 1044 | SectionSP() |
| 1045 | }; |
| 1046 | uint32_t offset = cu_line_offset; |
| 1047 | DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info); |
| 1048 | sc.comp_unit->SetLineTable(line_table_ap.release()); |
| 1049 | return true; |
| 1050 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1051 | } |
| 1052 | } |
| 1053 | } |
| 1054 | return false; |
| 1055 | } |
| 1056 | |
| 1057 | size_t |
| 1058 | SymbolFileDWARF::ParseFunctionBlocks |
| 1059 | ( |
| 1060 | const SymbolContext& sc, |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1061 | Block *parent_block, |
Greg Clayton | 1d8173f | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1062 | DWARFCompileUnit* dwarf_cu, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1063 | const DWARFDebugInfoEntry *die, |
| 1064 | addr_t subprogram_low_pc, |
Greg Clayton | 2e45b0c | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1065 | uint32_t depth |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1066 | ) |
| 1067 | { |
| 1068 | size_t blocks_added = 0; |
| 1069 | while (die != NULL) |
| 1070 | { |
| 1071 | dw_tag_t tag = die->Tag(); |
| 1072 | |
| 1073 | switch (tag) |
| 1074 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1075 | case DW_TAG_inlined_subroutine: |
Greg Clayton | 11afe6a | 2011-08-12 16:22:48 +0000 | [diff] [blame] | 1076 | case DW_TAG_subprogram: |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1077 | case DW_TAG_lexical_block: |
| 1078 | { |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1079 | Block *block = NULL; |
Greg Clayton | 2e45b0c | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1080 | if (tag == DW_TAG_subprogram) |
| 1081 | { |
| 1082 | // Skip any DW_TAG_subprogram DIEs that are inside |
| 1083 | // of a normal or inlined functions. These will be |
| 1084 | // parsed on their own as separate entities. |
| 1085 | |
| 1086 | if (depth > 0) |
| 1087 | break; |
| 1088 | |
| 1089 | block = parent_block; |
| 1090 | } |
| 1091 | else |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1092 | { |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1093 | BlockSP block_sp(new Block (MakeUserID(die->GetOffset()))); |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1094 | parent_block->AddChild(block_sp); |
| 1095 | block = block_sp.get(); |
| 1096 | } |
Greg Clayton | 2e45b0c | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1097 | DWARFDebugRanges::RangeList ranges; |
| 1098 | const char *name = NULL; |
| 1099 | const char *mangled_name = NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1100 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1101 | int decl_file = 0; |
| 1102 | int decl_line = 0; |
| 1103 | int decl_column = 0; |
| 1104 | int call_file = 0; |
| 1105 | int call_line = 0; |
| 1106 | int call_column = 0; |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1107 | if (die->GetDIENamesAndRanges (this, |
| 1108 | dwarf_cu, |
| 1109 | name, |
| 1110 | mangled_name, |
| 1111 | ranges, |
| 1112 | decl_file, decl_line, decl_column, |
| 1113 | call_file, call_line, call_column)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1114 | { |
| 1115 | if (tag == DW_TAG_subprogram) |
| 1116 | { |
| 1117 | assert (subprogram_low_pc == LLDB_INVALID_ADDRESS); |
Greg Clayton | bc36a86 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1118 | subprogram_low_pc = ranges.GetMinRangeBase(0); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1119 | } |
Jim Ingham | 0007dff | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1120 | else if (tag == DW_TAG_inlined_subroutine) |
| 1121 | { |
| 1122 | // We get called here for inlined subroutines in two ways. |
| 1123 | // The first time is when we are making the Function object |
| 1124 | // for this inlined concrete instance. Since we're creating a top level block at |
| 1125 | // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to |
| 1126 | // adjust the containing address. |
| 1127 | // The second time is when we are parsing the blocks inside the function that contains |
| 1128 | // the inlined concrete instance. Since these will be blocks inside the containing "real" |
| 1129 | // function the offset will be for that function. |
| 1130 | if (subprogram_low_pc == LLDB_INVALID_ADDRESS) |
| 1131 | { |
Greg Clayton | bc36a86 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1132 | subprogram_low_pc = ranges.GetMinRangeBase(0); |
Jim Ingham | 0007dff | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1133 | } |
| 1134 | } |
| 1135 | |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1136 | AddRangesToBlock (*block, ranges, subprogram_low_pc); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1137 | |
| 1138 | if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL)) |
| 1139 | { |
| 1140 | std::auto_ptr<Declaration> decl_ap; |
| 1141 | if (decl_file != 0 || decl_line != 0 || decl_column != 0) |
Jim Ingham | 0007dff | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1142 | decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), |
| 1143 | decl_line, decl_column)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1144 | |
| 1145 | std::auto_ptr<Declaration> call_ap; |
| 1146 | if (call_file != 0 || call_line != 0 || call_column != 0) |
Jim Ingham | 0007dff | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1147 | call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file), |
| 1148 | call_line, call_column)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1149 | |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1150 | block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1151 | } |
| 1152 | |
| 1153 | ++blocks_added; |
| 1154 | |
Greg Clayton | 2e45b0c | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1155 | if (die->HasChildren()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1156 | { |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1157 | blocks_added += ParseFunctionBlocks (sc, |
| 1158 | block, |
| 1159 | dwarf_cu, |
| 1160 | die->GetFirstChild(), |
| 1161 | subprogram_low_pc, |
Greg Clayton | 2e45b0c | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1162 | depth + 1); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1163 | } |
| 1164 | } |
| 1165 | } |
| 1166 | break; |
| 1167 | default: |
| 1168 | break; |
| 1169 | } |
| 1170 | |
Greg Clayton | 2e45b0c | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1171 | // Only parse siblings of the block if we are not at depth zero. A depth |
| 1172 | // of zero indicates we are currently parsing the top level |
| 1173 | // DW_TAG_subprogram DIE |
| 1174 | |
| 1175 | if (depth == 0) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1176 | die = NULL; |
Greg Clayton | 2e45b0c | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1177 | else |
| 1178 | die = die->GetSibling(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1179 | } |
| 1180 | return blocks_added; |
| 1181 | } |
| 1182 | |
Greg Clayton | f6a5bd7 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1183 | bool |
| 1184 | SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu, |
| 1185 | const DWARFDebugInfoEntry *parent_die, |
| 1186 | ClangASTContext::TemplateParameterInfos &template_param_infos) |
| 1187 | { |
| 1188 | |
| 1189 | if (parent_die == NULL) |
| 1190 | return NULL; |
| 1191 | |
| 1192 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| 1193 | |
| 1194 | Args template_parameter_names; |
| 1195 | for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); |
| 1196 | die != NULL; |
| 1197 | die = die->GetSibling()) |
| 1198 | { |
| 1199 | const dw_tag_t tag = die->Tag(); |
| 1200 | |
| 1201 | switch (tag) |
| 1202 | { |
| 1203 | case DW_TAG_template_type_parameter: |
| 1204 | case DW_TAG_template_value_parameter: |
| 1205 | { |
| 1206 | DWARFDebugInfoEntry::Attributes attributes; |
| 1207 | const size_t num_attributes = die->GetAttributes (this, |
| 1208 | dwarf_cu, |
| 1209 | fixed_form_sizes, |
| 1210 | attributes); |
| 1211 | const char *name = NULL; |
| 1212 | Type *lldb_type = NULL; |
| 1213 | clang_type_t clang_type = NULL; |
| 1214 | uint64_t uval64 = 0; |
| 1215 | bool uval64_valid = false; |
| 1216 | if (num_attributes > 0) |
| 1217 | { |
| 1218 | DWARFFormValue form_value; |
| 1219 | for (size_t i=0; i<num_attributes; ++i) |
| 1220 | { |
| 1221 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 1222 | |
| 1223 | switch (attr) |
| 1224 | { |
| 1225 | case DW_AT_name: |
| 1226 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1227 | name = form_value.AsCString(&get_debug_str_data()); |
| 1228 | break; |
| 1229 | |
| 1230 | case DW_AT_type: |
| 1231 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1232 | { |
| 1233 | const dw_offset_t type_die_offset = form_value.Reference(dwarf_cu); |
| 1234 | lldb_type = ResolveTypeUID(type_die_offset); |
| 1235 | if (lldb_type) |
| 1236 | clang_type = lldb_type->GetClangForwardType(); |
| 1237 | } |
| 1238 | break; |
| 1239 | |
| 1240 | case DW_AT_const_value: |
| 1241 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1242 | { |
| 1243 | uval64_valid = true; |
| 1244 | uval64 = form_value.Unsigned(); |
| 1245 | } |
| 1246 | break; |
| 1247 | default: |
| 1248 | break; |
| 1249 | } |
| 1250 | } |
| 1251 | |
| 1252 | if (name && lldb_type && clang_type) |
| 1253 | { |
| 1254 | bool is_signed = false; |
| 1255 | template_param_infos.names.push_back(name); |
| 1256 | clang::QualType clang_qual_type (clang::QualType::getFromOpaquePtr (clang_type)); |
| 1257 | if (tag == DW_TAG_template_value_parameter && ClangASTContext::IsIntegerType (clang_type, is_signed) && uval64_valid) |
| 1258 | { |
| 1259 | llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed); |
| 1260 | template_param_infos.args.push_back (clang::TemplateArgument (llvm::APSInt(apint), clang_qual_type)); |
| 1261 | } |
| 1262 | else |
| 1263 | { |
| 1264 | template_param_infos.args.push_back (clang::TemplateArgument (clang_qual_type)); |
| 1265 | } |
| 1266 | } |
| 1267 | else |
| 1268 | { |
| 1269 | return false; |
| 1270 | } |
| 1271 | |
| 1272 | } |
| 1273 | } |
| 1274 | break; |
| 1275 | |
| 1276 | default: |
| 1277 | break; |
| 1278 | } |
| 1279 | } |
| 1280 | if (template_param_infos.args.empty()) |
| 1281 | return false; |
| 1282 | return template_param_infos.args.size() == template_param_infos.names.size(); |
| 1283 | } |
| 1284 | |
| 1285 | clang::ClassTemplateDecl * |
| 1286 | SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx, |
Greg Clayton | 5e8eb5c | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1287 | lldb::AccessType access_type, |
Greg Clayton | f6a5bd7 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1288 | const char *parent_name, |
| 1289 | int tag_decl_kind, |
| 1290 | const ClangASTContext::TemplateParameterInfos &template_param_infos) |
| 1291 | { |
| 1292 | if (template_param_infos.IsValid()) |
| 1293 | { |
| 1294 | std::string template_basename(parent_name); |
| 1295 | template_basename.erase (template_basename.find('<')); |
| 1296 | ClangASTContext &ast = GetClangASTContext(); |
| 1297 | |
| 1298 | return ast.CreateClassTemplateDecl (decl_ctx, |
Greg Clayton | 5e8eb5c | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1299 | access_type, |
Greg Clayton | f6a5bd7 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1300 | template_basename.c_str(), |
| 1301 | tag_decl_kind, |
| 1302 | template_param_infos); |
| 1303 | } |
| 1304 | return NULL; |
| 1305 | } |
| 1306 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1307 | size_t |
| 1308 | SymbolFileDWARF::ParseChildMembers |
| 1309 | ( |
| 1310 | const SymbolContext& sc, |
Greg Clayton | 1d8173f | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1311 | DWARFCompileUnit* dwarf_cu, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1312 | const DWARFDebugInfoEntry *parent_die, |
Greg Clayton | 462d414 | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1313 | clang_type_t class_clang_type, |
Greg Clayton | 9488b74 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1314 | const LanguageType class_language, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1315 | std::vector<clang::CXXBaseSpecifier *>& base_classes, |
| 1316 | std::vector<int>& member_accessibilities, |
Greg Clayton | b433a3d | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1317 | DWARFDIECollection& member_function_dies, |
Sean Callanan | 70a4f92 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1318 | AccessType& default_accessibility, |
Greg Clayton | 3fc0c4f | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1319 | bool &is_a_class, |
| 1320 | LayoutInfo &layout_info |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1321 | ) |
| 1322 | { |
| 1323 | if (parent_die == NULL) |
| 1324 | return 0; |
| 1325 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1326 | size_t count = 0; |
| 1327 | const DWARFDebugInfoEntry *die; |
Greg Clayton | 5fcff9a | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 1328 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1329 | uint32_t member_idx = 0; |
Greg Clayton | 5fcff9a | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 1330 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1331 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 1332 | { |
| 1333 | dw_tag_t tag = die->Tag(); |
| 1334 | |
| 1335 | switch (tag) |
| 1336 | { |
| 1337 | case DW_TAG_member: |
| 1338 | { |
| 1339 | DWARFDebugInfoEntry::Attributes attributes; |
Greg Clayton | e4b9df0 | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1340 | const size_t num_attributes = die->GetAttributes (this, |
| 1341 | dwarf_cu, |
| 1342 | fixed_form_sizes, |
| 1343 | attributes); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1344 | if (num_attributes > 0) |
| 1345 | { |
| 1346 | Declaration decl; |
Greg Clayton | f3d0b0c | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1347 | //DWARFExpression location; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1348 | const char *name = NULL; |
Jim Ingham | 2546fd2 | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1349 | const char *prop_name = NULL; |
| 1350 | const char *prop_getter_name = NULL; |
| 1351 | const char *prop_setter_name = NULL; |
| 1352 | uint32_t prop_attributes = 0; |
| 1353 | |
| 1354 | |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1355 | bool is_artificial = false; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1356 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; |
Sean Callanan | 70a4f92 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1357 | AccessType accessibility = eAccessNone; |
Greg Clayton | 3fc0c4f | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1358 | uint32_t member_byte_offset = UINT32_MAX; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1359 | size_t byte_size = 0; |
| 1360 | size_t bit_offset = 0; |
| 1361 | size_t bit_size = 0; |
| 1362 | uint32_t i; |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1363 | for (i=0; i<num_attributes && !is_artificial; ++i) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1364 | { |
| 1365 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 1366 | DWARFFormValue form_value; |
| 1367 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1368 | { |
| 1369 | switch (attr) |
| 1370 | { |
| 1371 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 1372 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 1373 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 1374 | case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; |
| 1375 | case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; |
| 1376 | case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break; |
| 1377 | case DW_AT_bit_size: bit_size = form_value.Unsigned(); break; |
| 1378 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; |
| 1379 | case DW_AT_data_member_location: |
Greg Clayton | 3fc0c4f | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1380 | if (form_value.BlockData()) |
| 1381 | { |
| 1382 | Value initialValue(0); |
| 1383 | Value memberOffset(0); |
| 1384 | const DataExtractor& debug_info_data = get_debug_info_data(); |
| 1385 | uint32_t block_length = form_value.Unsigned(); |
| 1386 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 1387 | if (DWARFExpression::Evaluate(NULL, // ExecutionContext * |
| 1388 | NULL, // clang::ASTContext * |
| 1389 | NULL, // ClangExpressionVariableList * |
| 1390 | NULL, // ClangExpressionDeclMap * |
| 1391 | NULL, // RegisterContext * |
| 1392 | debug_info_data, |
| 1393 | block_offset, |
| 1394 | block_length, |
| 1395 | eRegisterKindDWARF, |
| 1396 | &initialValue, |
| 1397 | memberOffset, |
| 1398 | NULL)) |
| 1399 | { |
| 1400 | member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt(); |
| 1401 | } |
| 1402 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1403 | break; |
| 1404 | |
Greg Clayton | 84f8075 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1405 | case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break; |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1406 | case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1407 | case DW_AT_declaration: |
| 1408 | case DW_AT_description: |
| 1409 | case DW_AT_mutable: |
| 1410 | case DW_AT_visibility: |
Jim Ingham | 2546fd2 | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1411 | |
| 1412 | case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break; |
| 1413 | case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break; |
| 1414 | case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break; |
| 1415 | case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break; |
| 1416 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1417 | default: |
| 1418 | case DW_AT_sibling: |
| 1419 | break; |
| 1420 | } |
| 1421 | } |
| 1422 | } |
Sean Callanan | 4ee40ac | 2010-10-30 01:56:10 +0000 | [diff] [blame] | 1423 | |
Greg Clayton | 66756c2 | 2011-10-25 01:25:35 +0000 | [diff] [blame] | 1424 | // Clang has a DWARF generation bug where sometimes it |
| 1425 | // represents fields that are references with bad byte size |
| 1426 | // and bit size/offset information such as: |
| 1427 | // |
| 1428 | // DW_AT_byte_size( 0x00 ) |
| 1429 | // DW_AT_bit_size( 0x40 ) |
| 1430 | // DW_AT_bit_offset( 0xffffffffffffffc0 ) |
| 1431 | // |
| 1432 | // So check the bit offset to make sure it is sane, and if |
| 1433 | // the values are not sane, remove them. If we don't do this |
| 1434 | // then we will end up with a crash if we try to use this |
| 1435 | // type in an expression when clang becomes unhappy with its |
| 1436 | // recycled debug info. |
Sean Callanan | 4ee40ac | 2010-10-30 01:56:10 +0000 | [diff] [blame] | 1437 | |
Greg Clayton | 66756c2 | 2011-10-25 01:25:35 +0000 | [diff] [blame] | 1438 | if (bit_offset > 128) |
| 1439 | { |
| 1440 | bit_size = 0; |
| 1441 | bit_offset = 0; |
| 1442 | } |
| 1443 | |
| 1444 | // FIXME: Make Clang ignore Objective-C accessibility for expressions |
Sean Callanan | 4ee40ac | 2010-10-30 01:56:10 +0000 | [diff] [blame] | 1445 | if (class_language == eLanguageTypeObjC || |
| 1446 | class_language == eLanguageTypeObjC_plus_plus) |
| 1447 | accessibility = eAccessNone; |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1448 | |
| 1449 | if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name)) |
| 1450 | { |
| 1451 | // Not all compilers will mark the vtable pointer |
| 1452 | // member as artificial (llvm-gcc). We can't have |
| 1453 | // the virtual members in our classes otherwise it |
| 1454 | // throws off all child offsets since we end up |
| 1455 | // having and extra pointer sized member in our |
| 1456 | // class layouts. |
| 1457 | is_artificial = true; |
| 1458 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1459 | |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1460 | if (is_artificial == false) |
| 1461 | { |
| 1462 | Type *member_type = ResolveTypeUID(encoding_uid); |
Jim Ingham | 2546fd2 | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1463 | clang::FieldDecl *field_decl = NULL; |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1464 | if (member_type) |
| 1465 | { |
| 1466 | if (accessibility == eAccessNone) |
| 1467 | accessibility = default_accessibility; |
| 1468 | member_accessibilities.push_back(accessibility); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1469 | |
Jim Ingham | 2546fd2 | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1470 | field_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type, |
Greg Clayton | bcb0adc | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 1471 | name, |
| 1472 | member_type->GetClangLayoutType(), |
| 1473 | accessibility, |
| 1474 | bit_size); |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1475 | } |
| 1476 | else |
| 1477 | { |
| 1478 | if (name) |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1479 | GetObjectFile()->GetModule()->ReportError ("0x%8.8llx: DW_TAG_member '%s' refers to type 0x%8.8llx which was unable to be parsed", |
| 1480 | MakeUserID(die->GetOffset()), |
| 1481 | name, |
| 1482 | encoding_uid); |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1483 | else |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1484 | GetObjectFile()->GetModule()->ReportError ("0x%8.8llx: DW_TAG_member refers to type 0x%8.8llx which was unable to be parsed", |
| 1485 | MakeUserID(die->GetOffset()), |
| 1486 | encoding_uid); |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1487 | } |
Jim Ingham | 2546fd2 | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1488 | |
Sean Callanan | 8f2e392 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1489 | if (member_byte_offset != UINT32_MAX || bit_size != 0) |
Greg Clayton | 3fc0c4f | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1490 | { |
Sean Callanan | 8f2e392 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1491 | ///////////////////////////////////////////////////////////// |
| 1492 | // How to locate a field given the DWARF debug information |
| 1493 | // |
| 1494 | // AT_byte_size indicates the size of the word in which the |
| 1495 | // bit offset must be interpreted. |
| 1496 | // |
| 1497 | // AT_data_member_location indicates the byte offset of the |
| 1498 | // word from the base address of the structure. |
| 1499 | // |
| 1500 | // AT_bit_offset indicates how many bits into the word |
| 1501 | // (according to the host endianness) the low-order bit of |
| 1502 | // the field starts. AT_bit_offset can be negative. |
| 1503 | // |
| 1504 | // AT_bit_size indicates the size of the field in bits. |
| 1505 | ///////////////////////////////////////////////////////////// |
| 1506 | |
| 1507 | ByteOrder object_endian = GetObjectFile()->GetModule()->GetArchitecture().GetDefaultEndian(); |
| 1508 | |
| 1509 | uint64_t total_bit_offset = 0; |
| 1510 | |
| 1511 | total_bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8)); |
| 1512 | |
| 1513 | if (object_endian == eByteOrderLittle) |
| 1514 | { |
| 1515 | total_bit_offset += byte_size * 8; |
| 1516 | total_bit_offset -= (bit_offset + bit_size); |
| 1517 | } |
| 1518 | else |
| 1519 | { |
| 1520 | total_bit_offset += bit_offset; |
| 1521 | } |
| 1522 | |
| 1523 | layout_info.field_offsets.insert(std::make_pair(field_decl, total_bit_offset)); |
Greg Clayton | 3fc0c4f | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1524 | } |
Jim Ingham | 2546fd2 | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1525 | if (prop_name != NULL) |
| 1526 | { |
| 1527 | |
| 1528 | clang::ObjCIvarDecl *ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl); |
| 1529 | assert (ivar_decl != NULL); |
| 1530 | |
| 1531 | |
| 1532 | GetClangASTContext().AddObjCClassProperty (class_clang_type, |
| 1533 | prop_name, |
| 1534 | 0, |
| 1535 | ivar_decl, |
| 1536 | prop_setter_name, |
| 1537 | prop_getter_name, |
| 1538 | prop_attributes); |
| 1539 | } |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1540 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1541 | } |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1542 | ++member_idx; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1543 | } |
| 1544 | break; |
| 1545 | |
| 1546 | case DW_TAG_subprogram: |
Greg Clayton | b433a3d | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1547 | // Let the type parsing code handle this one for us. |
| 1548 | member_function_dies.Append (die); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1549 | break; |
| 1550 | |
| 1551 | case DW_TAG_inheritance: |
| 1552 | { |
| 1553 | is_a_class = true; |
Sean Callanan | 70a4f92 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1554 | if (default_accessibility == eAccessNone) |
| 1555 | default_accessibility = eAccessPrivate; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1556 | // TODO: implement DW_TAG_inheritance type parsing |
| 1557 | DWARFDebugInfoEntry::Attributes attributes; |
Greg Clayton | e4b9df0 | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1558 | const size_t num_attributes = die->GetAttributes (this, |
| 1559 | dwarf_cu, |
| 1560 | fixed_form_sizes, |
| 1561 | attributes); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1562 | if (num_attributes > 0) |
| 1563 | { |
| 1564 | Declaration decl; |
| 1565 | DWARFExpression location; |
| 1566 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; |
Sean Callanan | 70a4f92 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1567 | AccessType accessibility = default_accessibility; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1568 | bool is_virtual = false; |
| 1569 | bool is_base_of_class = true; |
| 1570 | off_t member_offset = 0; |
| 1571 | uint32_t i; |
| 1572 | for (i=0; i<num_attributes; ++i) |
| 1573 | { |
| 1574 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 1575 | DWARFFormValue form_value; |
| 1576 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1577 | { |
| 1578 | switch (attr) |
| 1579 | { |
| 1580 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 1581 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 1582 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 1583 | case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; |
| 1584 | case DW_AT_data_member_location: |
| 1585 | if (form_value.BlockData()) |
| 1586 | { |
| 1587 | Value initialValue(0); |
| 1588 | Value memberOffset(0); |
| 1589 | const DataExtractor& debug_info_data = get_debug_info_data(); |
| 1590 | uint32_t block_length = form_value.Unsigned(); |
| 1591 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
Greg Clayton | e4b9df0 | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1592 | if (DWARFExpression::Evaluate (NULL, |
| 1593 | NULL, |
Greg Clayton | e4b9df0 | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1594 | NULL, |
| 1595 | NULL, |
Jason Molenda | 8e69de4 | 2010-11-20 01:28:30 +0000 | [diff] [blame] | 1596 | NULL, |
Greg Clayton | bdcb6ab | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 1597 | debug_info_data, |
Greg Clayton | e4b9df0 | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1598 | block_offset, |
| 1599 | block_length, |
| 1600 | eRegisterKindDWARF, |
| 1601 | &initialValue, |
| 1602 | memberOffset, |
| 1603 | NULL)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1604 | { |
| 1605 | member_offset = memberOffset.ResolveValue(NULL, NULL).UInt(); |
| 1606 | } |
| 1607 | } |
| 1608 | break; |
| 1609 | |
| 1610 | case DW_AT_accessibility: |
Greg Clayton | 84f8075 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1611 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1612 | break; |
| 1613 | |
| 1614 | case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break; |
| 1615 | default: |
| 1616 | case DW_AT_sibling: |
| 1617 | break; |
| 1618 | } |
| 1619 | } |
| 1620 | } |
| 1621 | |
Greg Clayton | 6916e35 | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 1622 | Type *base_class_type = ResolveTypeUID(encoding_uid); |
| 1623 | assert(base_class_type); |
Greg Clayton | 9488b74 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1624 | |
Greg Clayton | 04c9c7b | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 1625 | clang_type_t base_class_clang_type = base_class_type->GetClangFullType(); |
| 1626 | assert (base_class_clang_type); |
Greg Clayton | 9488b74 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1627 | if (class_language == eLanguageTypeObjC) |
| 1628 | { |
Greg Clayton | 04c9c7b | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 1629 | GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type); |
Greg Clayton | 9488b74 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1630 | } |
| 1631 | else |
| 1632 | { |
Greg Clayton | 04c9c7b | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 1633 | base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type, |
Greg Clayton | e4b9df0 | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1634 | accessibility, |
| 1635 | is_virtual, |
| 1636 | is_base_of_class)); |
Greg Clayton | 9488b74 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1637 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1638 | } |
| 1639 | } |
| 1640 | break; |
| 1641 | |
| 1642 | default: |
| 1643 | break; |
| 1644 | } |
| 1645 | } |
| 1646 | return count; |
| 1647 | } |
| 1648 | |
| 1649 | |
| 1650 | clang::DeclContext* |
Sean Callanan | c617a4c | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 1651 | SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1652 | { |
| 1653 | DWARFDebugInfo* debug_info = DebugInfo(); |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1654 | if (debug_info && UserIDMatches(type_uid)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1655 | { |
| 1656 | DWARFCompileUnitSP cu_sp; |
| 1657 | const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp); |
| 1658 | if (die) |
Greg Clayton | 03fd0d0 | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 1659 | return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL); |
Sean Callanan | c617a4c | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 1660 | } |
| 1661 | return NULL; |
| 1662 | } |
| 1663 | |
| 1664 | clang::DeclContext* |
| 1665 | SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid) |
| 1666 | { |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1667 | if (UserIDMatches(type_uid)) |
| 1668 | return GetClangDeclContextForDIEOffset (sc, type_uid); |
| 1669 | return NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1670 | } |
| 1671 | |
| 1672 | Type* |
Greg Clayton | 7412475 | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 1673 | SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1674 | { |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1675 | if (UserIDMatches(type_uid)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1676 | { |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1677 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 1678 | if (debug_info) |
Greg Clayton | 0d62dfd | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 1679 | { |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1680 | DWARFCompileUnitSP cu_sp; |
| 1681 | const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp); |
Greg Clayton | d7088cf | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1682 | const bool assert_not_being_parsed = true; |
| 1683 | return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed); |
Greg Clayton | 0d62dfd | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 1684 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1685 | } |
| 1686 | return NULL; |
| 1687 | } |
| 1688 | |
Greg Clayton | d7088cf | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1689 | Type* |
| 1690 | SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed) |
Sean Callanan | 8f2e392 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1691 | { |
Greg Clayton | d7088cf | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1692 | if (die != NULL) |
| 1693 | { |
Greg Clayton | d7fc5b8 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1694 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| 1695 | if (log) |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1696 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 1697 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'", |
| 1698 | die->GetOffset(), |
| 1699 | DW_TAG_value_to_name(die->Tag()), |
| 1700 | die->GetName(this, cu)); |
Greg Clayton | d7fc5b8 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1701 | |
Greg Clayton | d7088cf | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1702 | // We might be coming in in the middle of a type tree (a class |
| 1703 | // withing a class, an enum within a class), so parse any needed |
| 1704 | // parent DIEs before we get to this one... |
| 1705 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); |
| 1706 | switch (decl_ctx_die->Tag()) |
| 1707 | { |
| 1708 | case DW_TAG_structure_type: |
| 1709 | case DW_TAG_union_type: |
| 1710 | case DW_TAG_class_type: |
| 1711 | { |
| 1712 | // Get the type, which could be a forward declaration |
Greg Clayton | d7fc5b8 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1713 | if (log) |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1714 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 1715 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x", |
| 1716 | die->GetOffset(), |
| 1717 | DW_TAG_value_to_name(die->Tag()), |
| 1718 | die->GetName(this, cu), |
| 1719 | decl_ctx_die->GetOffset()); |
Greg Clayton | d7fc5b8 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1720 | |
Greg Clayton | d7088cf | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1721 | Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed); |
Sean Callanan | 8f2e392 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1722 | if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag())) |
Greg Clayton | d7fc5b8 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1723 | { |
| 1724 | if (log) |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1725 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 1726 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function", |
| 1727 | die->GetOffset(), |
| 1728 | DW_TAG_value_to_name(die->Tag()), |
| 1729 | die->GetName(this, cu), |
| 1730 | decl_ctx_die->GetOffset()); |
Greg Clayton | d7fc5b8 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1731 | // Ask the type to complete itself if it already hasn't since if we |
| 1732 | // want a function (method or static) from a class, the class must |
| 1733 | // create itself and add it's own methods and class functions. |
| 1734 | if (parent_type) |
| 1735 | parent_type->GetClangFullType(); |
| 1736 | } |
Greg Clayton | d7088cf | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1737 | } |
| 1738 | break; |
| 1739 | |
| 1740 | default: |
| 1741 | break; |
| 1742 | } |
| 1743 | return ResolveType (cu, die); |
| 1744 | } |
| 1745 | return NULL; |
| 1746 | } |
| 1747 | |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1748 | // This function is used when SymbolFileDWARFDebugMap owns a bunch of |
| 1749 | // SymbolFileDWARF objects to detect if this DWARF file is the one that |
| 1750 | // can resolve a clang_type. |
| 1751 | bool |
| 1752 | SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type) |
| 1753 | { |
| 1754 | clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type); |
| 1755 | const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers); |
| 1756 | return die != NULL; |
| 1757 | } |
| 1758 | |
| 1759 | |
Greg Clayton | 462d414 | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1760 | lldb::clang_type_t |
| 1761 | SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type) |
| 1762 | { |
| 1763 | // We have a struct/union/class/enum that needs to be fully resolved. |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1764 | clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type); |
| 1765 | const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers); |
Greg Clayton | 462d414 | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1766 | if (die == NULL) |
Greg Clayton | f3d0b0c | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1767 | { |
| 1768 | // We have already resolved this type... |
| 1769 | return clang_type; |
| 1770 | } |
| 1771 | // Once we start resolving this type, remove it from the forward declaration |
| 1772 | // map in case anyone child members or other types require this type to get resolved. |
| 1773 | // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition |
| 1774 | // are done. |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1775 | m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers); |
Greg Clayton | f3d0b0c | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1776 | |
Greg Clayton | 462d414 | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1777 | |
Greg Clayton | 4c8353b | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 1778 | // Disable external storage for this type so we don't get anymore |
| 1779 | // clang::ExternalASTSource queries for this type. |
| 1780 | ClangASTContext::SetHasExternalStorage (clang_type, false); |
| 1781 | |
Greg Clayton | ad60bf4 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 1782 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 1783 | |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1784 | DWARFCompileUnit *curr_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get(); |
Greg Clayton | 462d414 | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1785 | Type *type = m_die_to_type.lookup (die); |
| 1786 | |
| 1787 | const dw_tag_t tag = die->Tag(); |
| 1788 | |
Greg Clayton | d7fc5b8 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1789 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| 1790 | if (log) |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1791 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 1792 | "0x%8.8llx: %s '%s' resolving forward declaration...\n", |
| 1793 | MakeUserID(die->GetOffset()), |
| 1794 | DW_TAG_value_to_name(tag), |
| 1795 | type->GetName().AsCString()); |
Greg Clayton | 462d414 | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1796 | assert (clang_type); |
| 1797 | DWARFDebugInfoEntry::Attributes attributes; |
| 1798 | |
Greg Clayton | e98ac25 | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 1799 | ClangASTContext &ast = GetClangASTContext(); |
Greg Clayton | 462d414 | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1800 | |
| 1801 | switch (tag) |
| 1802 | { |
| 1803 | case DW_TAG_structure_type: |
| 1804 | case DW_TAG_union_type: |
| 1805 | case DW_TAG_class_type: |
Greg Clayton | e98ac25 | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 1806 | ast.StartTagDeclarationDefinition (clang_type); |
Greg Clayton | b433a3d | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1807 | { |
Greg Clayton | 3fc0c4f | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1808 | LayoutInfo layout_info; |
| 1809 | if (die->HasChildren()) |
Greg Clayton | 462d414 | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1810 | { |
Greg Clayton | b433a3d | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1811 | |
Greg Clayton | 3fc0c4f | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1812 | LanguageType class_language = eLanguageTypeUnknown; |
| 1813 | bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type); |
| 1814 | if (is_objc_class) |
| 1815 | class_language = eLanguageTypeObjC; |
Greg Clayton | b433a3d | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1816 | |
Greg Clayton | 3fc0c4f | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1817 | int tag_decl_kind = -1; |
| 1818 | AccessType default_accessibility = eAccessNone; |
| 1819 | if (tag == DW_TAG_structure_type) |
Greg Clayton | b433a3d | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1820 | { |
Greg Clayton | 3fc0c4f | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1821 | tag_decl_kind = clang::TTK_Struct; |
| 1822 | default_accessibility = eAccessPublic; |
Greg Clayton | b433a3d | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1823 | } |
Greg Clayton | 3fc0c4f | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1824 | else if (tag == DW_TAG_union_type) |
Greg Clayton | ad60bf4 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 1825 | { |
Greg Clayton | 3fc0c4f | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1826 | tag_decl_kind = clang::TTK_Union; |
| 1827 | default_accessibility = eAccessPublic; |
| 1828 | } |
| 1829 | else if (tag == DW_TAG_class_type) |
| 1830 | { |
| 1831 | tag_decl_kind = clang::TTK_Class; |
| 1832 | default_accessibility = eAccessPrivate; |
| 1833 | } |
| 1834 | |
| 1835 | SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu)); |
| 1836 | std::vector<clang::CXXBaseSpecifier *> base_classes; |
| 1837 | std::vector<int> member_accessibilities; |
| 1838 | bool is_a_class = false; |
| 1839 | // Parse members and base classes first |
| 1840 | DWARFDIECollection member_function_dies; |
| 1841 | |
| 1842 | ParseChildMembers (sc, |
| 1843 | curr_cu, |
| 1844 | die, |
| 1845 | clang_type, |
| 1846 | class_language, |
| 1847 | base_classes, |
| 1848 | member_accessibilities, |
| 1849 | member_function_dies, |
| 1850 | default_accessibility, |
| 1851 | is_a_class, |
| 1852 | layout_info); |
| 1853 | |
| 1854 | // Now parse any methods if there were any... |
| 1855 | size_t num_functions = member_function_dies.Size(); |
| 1856 | if (num_functions > 0) |
| 1857 | { |
| 1858 | for (size_t i=0; i<num_functions; ++i) |
| 1859 | { |
| 1860 | ResolveType(curr_cu, member_function_dies.GetDIEPtrAtIndex(i)); |
| 1861 | } |
| 1862 | } |
Greg Clayton | ad60bf4 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 1863 | |
Greg Clayton | 3fc0c4f | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1864 | if (class_language == eLanguageTypeObjC) |
| 1865 | { |
| 1866 | std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(clang_type)); |
| 1867 | if (!class_str.empty()) |
Greg Clayton | 24a6bd9 | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 1868 | { |
Greg Clayton | 3fc0c4f | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1869 | |
| 1870 | DIEArray method_die_offsets; |
| 1871 | if (m_using_apple_tables) |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 1872 | { |
Greg Clayton | 3fc0c4f | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1873 | if (m_apple_objc_ap.get()) |
| 1874 | m_apple_objc_ap->FindByName(class_str.c_str(), method_die_offsets); |
| 1875 | } |
| 1876 | else |
| 1877 | { |
| 1878 | if (!m_indexed) |
| 1879 | Index (); |
Greg Clayton | ad60bf4 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 1880 | |
Greg Clayton | 3fc0c4f | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1881 | ConstString class_name (class_str.c_str()); |
| 1882 | m_objc_class_selectors_index.Find (class_name, method_die_offsets); |
| 1883 | } |
| 1884 | |
| 1885 | if (!method_die_offsets.empty()) |
| 1886 | { |
| 1887 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 1888 | |
| 1889 | DWARFCompileUnit* method_cu = NULL; |
| 1890 | const size_t num_matches = method_die_offsets.size(); |
| 1891 | for (size_t i=0; i<num_matches; ++i) |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 1892 | { |
Greg Clayton | 3fc0c4f | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1893 | const dw_offset_t die_offset = method_die_offsets[i]; |
| 1894 | DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu); |
| 1895 | |
| 1896 | if (method_die) |
| 1897 | ResolveType (method_cu, method_die); |
| 1898 | else |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 1899 | { |
Greg Clayton | 3fc0c4f | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1900 | if (m_using_apple_tables) |
| 1901 | { |
| 1902 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n", |
| 1903 | die_offset, class_str.c_str()); |
| 1904 | } |
| 1905 | } |
| 1906 | } |
Greg Clayton | ad60bf4 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 1907 | } |
| 1908 | } |
| 1909 | } |
Greg Clayton | 3fc0c4f | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1910 | |
| 1911 | // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we |
| 1912 | // need to tell the clang type it is actually a class. |
| 1913 | if (class_language != eLanguageTypeObjC) |
| 1914 | { |
| 1915 | if (is_a_class && tag_decl_kind != clang::TTK_Class) |
| 1916 | ast.SetTagTypeKind (clang_type, clang::TTK_Class); |
| 1917 | } |
Greg Clayton | b433a3d | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1918 | |
Greg Clayton | 3fc0c4f | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1919 | // Since DW_TAG_structure_type gets used for both classes |
| 1920 | // and structures, we may need to set any DW_TAG_member |
| 1921 | // fields to have a "private" access if none was specified. |
| 1922 | // When we parsed the child members we tracked that actual |
| 1923 | // accessibility value for each DW_TAG_member in the |
| 1924 | // "member_accessibilities" array. If the value for the |
| 1925 | // member is zero, then it was set to the "default_accessibility" |
| 1926 | // which for structs was "public". Below we correct this |
| 1927 | // by setting any fields to "private" that weren't correctly |
| 1928 | // set. |
| 1929 | if (is_a_class && !member_accessibilities.empty()) |
| 1930 | { |
| 1931 | // This is a class and all members that didn't have |
| 1932 | // their access specified are private. |
| 1933 | ast.SetDefaultAccessForRecordFields (clang_type, |
| 1934 | eAccessPrivate, |
| 1935 | &member_accessibilities.front(), |
| 1936 | member_accessibilities.size()); |
| 1937 | } |
Greg Clayton | b433a3d | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1938 | |
Greg Clayton | 3fc0c4f | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1939 | if (!base_classes.empty()) |
| 1940 | { |
| 1941 | ast.SetBaseClassesForClassType (clang_type, |
| 1942 | &base_classes.front(), |
| 1943 | base_classes.size()); |
Greg Clayton | b433a3d | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1944 | |
Greg Clayton | 3fc0c4f | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1945 | // Clang will copy each CXXBaseSpecifier in "base_classes" |
| 1946 | // so we have to free them all. |
| 1947 | ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(), |
| 1948 | base_classes.size()); |
| 1949 | } |
| 1950 | |
Greg Clayton | b433a3d | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1951 | } |
Sean Callanan | 8f2e392 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1952 | |
Greg Clayton | 3fc0c4f | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1953 | if (!layout_info.field_offsets.empty()) |
| 1954 | { |
| 1955 | if (type) |
| 1956 | layout_info.bit_size = type->GetByteSize() * 8; |
| 1957 | if (layout_info.bit_size == 0) |
| 1958 | layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, curr_cu, DW_AT_byte_size, 0) * 8; |
| 1959 | clang::QualType qual_type(clang::QualType::getFromOpaquePtr(clang_type)); |
| 1960 | const clang::RecordType *record_type = clang::dyn_cast<clang::RecordType>(qual_type.getTypePtr()); |
| 1961 | if (record_type) |
| 1962 | { |
| 1963 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 1964 | |
| 1965 | if (log) |
Greg Clayton | a792abe | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 1966 | { |
Greg Clayton | 3fc0c4f | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1967 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
Greg Clayton | a792abe | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 1968 | "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) caching layout info for record_decl = %p, bit_size = %llu, alignment = %llu, field_offsets[%u], base_offsets[0], vbase_offsets[0])", |
Greg Clayton | 3fc0c4f | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1969 | clang_type, |
| 1970 | record_decl, |
| 1971 | layout_info.bit_size, |
| 1972 | layout_info.alignment, |
| 1973 | (uint32_t)layout_info.field_offsets.size()); |
| 1974 | |
Greg Clayton | a792abe | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 1975 | llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end(); |
| 1976 | for (pos = layout_info.field_offsets.begin(); pos != end; ++pos) |
| 1977 | { |
| 1978 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 1979 | "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field = { bit_offset=%u, name='%s' }", |
| 1980 | clang_type, |
| 1981 | (uint32_t)pos->second, |
| 1982 | pos->first->getNameAsString().c_str()); |
| 1983 | } |
| 1984 | } |
Greg Clayton | 3fc0c4f | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1985 | m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info)); |
| 1986 | } |
| 1987 | } |
Greg Clayton | b433a3d | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1988 | } |
Greg Clayton | e98ac25 | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 1989 | ast.CompleteTagDeclarationDefinition (clang_type); |
Greg Clayton | b433a3d | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1990 | return clang_type; |
Greg Clayton | 462d414 | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1991 | |
| 1992 | case DW_TAG_enumeration_type: |
Greg Clayton | e98ac25 | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 1993 | ast.StartTagDeclarationDefinition (clang_type); |
Greg Clayton | 462d414 | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1994 | if (die->HasChildren()) |
| 1995 | { |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1996 | SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu)); |
| 1997 | ParseChildEnumerators(sc, clang_type, type->GetByteSize(), curr_cu, die); |
Greg Clayton | 462d414 | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1998 | } |
Greg Clayton | e98ac25 | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 1999 | ast.CompleteTagDeclarationDefinition (clang_type); |
Greg Clayton | 462d414 | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2000 | return clang_type; |
| 2001 | |
| 2002 | default: |
| 2003 | assert(false && "not a forward clang type decl!"); |
| 2004 | break; |
| 2005 | } |
| 2006 | return NULL; |
| 2007 | } |
| 2008 | |
Greg Clayton | 7412475 | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2009 | Type* |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2010 | SymbolFileDWARF::ResolveType (DWARFCompileUnit* curr_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed) |
Greg Clayton | 7412475 | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2011 | { |
| 2012 | if (type_die != NULL) |
| 2013 | { |
Greg Clayton | 4fb400f | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 2014 | Type *type = m_die_to_type.lookup (type_die); |
Greg Clayton | d7088cf | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2015 | |
Greg Clayton | 7412475 | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2016 | if (type == NULL) |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2017 | type = GetTypeForDIE (curr_cu, type_die).get(); |
Greg Clayton | d7088cf | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2018 | |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2019 | if (assert_not_being_parsed) |
Jim Ingham | 1c6b461 | 2012-01-11 02:21:12 +0000 | [diff] [blame] | 2020 | { |
| 2021 | if (type != DIE_IS_BEING_PARSED) |
| 2022 | return type; |
| 2023 | |
| 2024 | GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s", |
| 2025 | type_die->GetOffset(), |
| 2026 | DW_TAG_value_to_name(type_die->Tag()), |
| 2027 | type_die->GetName(this, curr_cu)); |
| 2028 | |
| 2029 | } |
| 2030 | else |
| 2031 | return type; |
Greg Clayton | 7412475 | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2032 | } |
| 2033 | return NULL; |
| 2034 | } |
| 2035 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2036 | CompileUnit* |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2037 | SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* curr_cu, uint32_t cu_idx) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2038 | { |
| 2039 | // Check if the symbol vendor already knows about this compile unit? |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2040 | if (curr_cu->GetUserData() == NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2041 | { |
| 2042 | // The symbol vendor doesn't know about this compile unit, we |
| 2043 | // need to parse and add it to the symbol vendor object. |
| 2044 | CompUnitSP dc_cu; |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2045 | ParseCompileUnit(curr_cu, dc_cu); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2046 | if (dc_cu.get()) |
| 2047 | { |
| 2048 | // Figure out the compile unit index if we weren't given one |
Greg Clayton | 178710c | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 2049 | if (cu_idx == UINT32_MAX) |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2050 | DebugInfo()->GetCompileUnit(curr_cu->GetOffset(), &cu_idx); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2051 | |
| 2052 | m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(dc_cu, cu_idx); |
Greg Clayton | ad60bf4 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2053 | |
| 2054 | if (m_debug_map_symfile) |
| 2055 | m_debug_map_symfile->SetCompileUnit(this, dc_cu); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2056 | } |
| 2057 | } |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2058 | return (CompileUnit*)curr_cu->GetUserData(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2059 | } |
| 2060 | |
| 2061 | bool |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2062 | SymbolFileDWARF::GetFunction (DWARFCompileUnit* curr_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2063 | { |
| 2064 | sc.Clear(); |
| 2065 | // Check if the symbol vendor already knows about this compile unit? |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2066 | sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, UINT32_MAX); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2067 | |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2068 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2069 | if (sc.function == NULL) |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2070 | sc.function = ParseCompileUnitFunction(sc, curr_cu, func_die); |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2071 | |
| 2072 | if (sc.function) |
| 2073 | { |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 2074 | sc.module_sp = sc.function->CalculateSymbolContextModule()->shared_from_this(); |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2075 | return true; |
| 2076 | } |
| 2077 | |
| 2078 | return false; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2079 | } |
| 2080 | |
| 2081 | uint32_t |
| 2082 | SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) |
| 2083 | { |
| 2084 | Timer scoped_timer(__PRETTY_FUNCTION__, |
| 2085 | "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%llx }, resolve_scope = 0x%8.8x)", |
| 2086 | so_addr.GetSection(), |
| 2087 | so_addr.GetOffset(), |
| 2088 | resolve_scope); |
| 2089 | uint32_t resolved = 0; |
| 2090 | if (resolve_scope & ( eSymbolContextCompUnit | |
| 2091 | eSymbolContextFunction | |
| 2092 | eSymbolContextBlock | |
| 2093 | eSymbolContextLineEntry)) |
| 2094 | { |
| 2095 | lldb::addr_t file_vm_addr = so_addr.GetFileAddress(); |
| 2096 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2097 | DWARFDebugInfo* debug_info = DebugInfo(); |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2098 | if (debug_info) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2099 | { |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2100 | dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2101 | if (cu_offset != DW_INVALID_OFFSET) |
| 2102 | { |
| 2103 | uint32_t cu_idx; |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2104 | DWARFCompileUnit* curr_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get(); |
| 2105 | if (curr_cu) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2106 | { |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2107 | sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2108 | assert(sc.comp_unit != NULL); |
| 2109 | resolved |= eSymbolContextCompUnit; |
| 2110 | |
| 2111 | if (resolve_scope & eSymbolContextLineEntry) |
| 2112 | { |
| 2113 | LineTable *line_table = sc.comp_unit->GetLineTable(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2114 | if (line_table != NULL) |
| 2115 | { |
| 2116 | if (so_addr.IsLinkedAddress()) |
| 2117 | { |
| 2118 | Address linked_addr (so_addr); |
| 2119 | linked_addr.ResolveLinkedAddress(); |
| 2120 | if (line_table->FindLineEntryByAddress (linked_addr, sc.line_entry)) |
| 2121 | { |
| 2122 | resolved |= eSymbolContextLineEntry; |
| 2123 | } |
| 2124 | } |
| 2125 | else if (line_table->FindLineEntryByAddress (so_addr, sc.line_entry)) |
| 2126 | { |
| 2127 | resolved |= eSymbolContextLineEntry; |
| 2128 | } |
| 2129 | } |
| 2130 | } |
| 2131 | |
| 2132 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) |
| 2133 | { |
| 2134 | DWARFDebugInfoEntry *function_die = NULL; |
| 2135 | DWARFDebugInfoEntry *block_die = NULL; |
| 2136 | if (resolve_scope & eSymbolContextBlock) |
| 2137 | { |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2138 | curr_cu->LookupAddress(file_vm_addr, &function_die, &block_die); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2139 | } |
| 2140 | else |
| 2141 | { |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2142 | curr_cu->LookupAddress(file_vm_addr, &function_die, NULL); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2143 | } |
| 2144 | |
| 2145 | if (function_die != NULL) |
| 2146 | { |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2147 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2148 | if (sc.function == NULL) |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2149 | sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2150 | } |
| 2151 | |
| 2152 | if (sc.function != NULL) |
| 2153 | { |
| 2154 | resolved |= eSymbolContextFunction; |
| 2155 | |
| 2156 | if (resolve_scope & eSymbolContextBlock) |
| 2157 | { |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 2158 | Block& block = sc.function->GetBlock (true); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2159 | |
| 2160 | if (block_die != NULL) |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2161 | sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2162 | else |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2163 | sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2164 | if (sc.block) |
| 2165 | resolved |= eSymbolContextBlock; |
| 2166 | } |
| 2167 | } |
| 2168 | } |
| 2169 | } |
| 2170 | } |
| 2171 | } |
| 2172 | } |
| 2173 | return resolved; |
| 2174 | } |
| 2175 | |
| 2176 | |
| 2177 | |
| 2178 | uint32_t |
| 2179 | SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) |
| 2180 | { |
| 2181 | const uint32_t prev_size = sc_list.GetSize(); |
| 2182 | if (resolve_scope & eSymbolContextCompUnit) |
| 2183 | { |
| 2184 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2185 | if (debug_info) |
| 2186 | { |
| 2187 | uint32_t cu_idx; |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2188 | DWARFCompileUnit* curr_cu = NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2189 | |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2190 | for (cu_idx = 0; (curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2191 | { |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2192 | CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2193 | bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Compare(file_spec, *dc_cu, false) == 0; |
| 2194 | if (check_inlines || file_spec_matches_cu_file_spec) |
| 2195 | { |
| 2196 | SymbolContext sc (m_obj_file->GetModule()); |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2197 | sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2198 | assert(sc.comp_unit != NULL); |
| 2199 | |
| 2200 | uint32_t file_idx = UINT32_MAX; |
| 2201 | |
| 2202 | // If we are looking for inline functions only and we don't |
| 2203 | // find it in the support files, we are done. |
| 2204 | if (check_inlines) |
| 2205 | { |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 2206 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2207 | if (file_idx == UINT32_MAX) |
| 2208 | continue; |
| 2209 | } |
| 2210 | |
| 2211 | if (line != 0) |
| 2212 | { |
| 2213 | LineTable *line_table = sc.comp_unit->GetLineTable(); |
| 2214 | |
| 2215 | if (line_table != NULL && line != 0) |
| 2216 | { |
| 2217 | // We will have already looked up the file index if |
| 2218 | // we are searching for inline entries. |
| 2219 | if (!check_inlines) |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 2220 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2221 | |
| 2222 | if (file_idx != UINT32_MAX) |
| 2223 | { |
| 2224 | uint32_t found_line; |
| 2225 | uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry); |
| 2226 | found_line = sc.line_entry.line; |
| 2227 | |
Greg Clayton | 178710c | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 2228 | while (line_idx != UINT32_MAX) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2229 | { |
| 2230 | sc.function = NULL; |
| 2231 | sc.block = NULL; |
| 2232 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) |
| 2233 | { |
| 2234 | const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress(); |
| 2235 | if (file_vm_addr != LLDB_INVALID_ADDRESS) |
| 2236 | { |
| 2237 | DWARFDebugInfoEntry *function_die = NULL; |
| 2238 | DWARFDebugInfoEntry *block_die = NULL; |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2239 | curr_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2240 | |
| 2241 | if (function_die != NULL) |
| 2242 | { |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2243 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2244 | if (sc.function == NULL) |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2245 | sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2246 | } |
| 2247 | |
| 2248 | if (sc.function != NULL) |
| 2249 | { |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 2250 | Block& block = sc.function->GetBlock (true); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2251 | |
| 2252 | if (block_die != NULL) |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2253 | sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2254 | else |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2255 | sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2256 | } |
| 2257 | } |
| 2258 | } |
| 2259 | |
| 2260 | sc_list.Append(sc); |
| 2261 | line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry); |
| 2262 | } |
| 2263 | } |
| 2264 | } |
| 2265 | else if (file_spec_matches_cu_file_spec && !check_inlines) |
| 2266 | { |
| 2267 | // only append the context if we aren't looking for inline call sites |
| 2268 | // by file and line and if the file spec matches that of the compile unit |
| 2269 | sc_list.Append(sc); |
| 2270 | } |
| 2271 | } |
| 2272 | else if (file_spec_matches_cu_file_spec && !check_inlines) |
| 2273 | { |
| 2274 | // only append the context if we aren't looking for inline call sites |
| 2275 | // by file and line and if the file spec matches that of the compile unit |
| 2276 | sc_list.Append(sc); |
| 2277 | } |
| 2278 | |
| 2279 | if (!check_inlines) |
| 2280 | break; |
| 2281 | } |
| 2282 | } |
| 2283 | } |
| 2284 | } |
| 2285 | return sc_list.GetSize() - prev_size; |
| 2286 | } |
| 2287 | |
| 2288 | void |
| 2289 | SymbolFileDWARF::Index () |
| 2290 | { |
| 2291 | if (m_indexed) |
| 2292 | return; |
| 2293 | m_indexed = true; |
| 2294 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 2295 | "SymbolFileDWARF::Index (%s)", |
| 2296 | GetObjectFile()->GetFileSpec().GetFilename().AsCString()); |
| 2297 | |
| 2298 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2299 | if (debug_info) |
| 2300 | { |
| 2301 | uint32_t cu_idx = 0; |
| 2302 | const uint32_t num_compile_units = GetNumCompileUnits(); |
| 2303 | for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) |
| 2304 | { |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2305 | DWARFCompileUnit* curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2306 | |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2307 | bool clear_dies = curr_cu->ExtractDIEsIfNeeded (false) > 1; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2308 | |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2309 | curr_cu->Index (cu_idx, |
Greg Clayton | 3bc52d0 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 2310 | m_function_basename_index, |
| 2311 | m_function_fullname_index, |
| 2312 | m_function_method_index, |
| 2313 | m_function_selector_index, |
| 2314 | m_objc_class_selectors_index, |
| 2315 | m_global_index, |
| 2316 | m_type_index, |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2317 | m_namespace_index); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2318 | |
| 2319 | // Keep memory down by clearing DIEs if this generate function |
| 2320 | // caused them to be parsed |
| 2321 | if (clear_dies) |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2322 | curr_cu->ClearDIEs (true); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2323 | } |
| 2324 | |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2325 | m_function_basename_index.Finalize(); |
| 2326 | m_function_fullname_index.Finalize(); |
| 2327 | m_function_method_index.Finalize(); |
| 2328 | m_function_selector_index.Finalize(); |
| 2329 | m_objc_class_selectors_index.Finalize(); |
| 2330 | m_global_index.Finalize(); |
| 2331 | m_type_index.Finalize(); |
| 2332 | m_namespace_index.Finalize(); |
Greg Clayton | 7412475 | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2333 | |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2334 | #if defined (ENABLE_DEBUG_PRINTF) |
Greg Clayton | 7bb069b | 2011-02-09 23:39:34 +0000 | [diff] [blame] | 2335 | StreamFile s(stdout, false); |
Greg Clayton | c8cf5e2 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 2336 | s.Printf ("DWARF index for '%s/%s':", |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2337 | GetObjectFile()->GetFileSpec().GetDirectory().AsCString(), |
| 2338 | GetObjectFile()->GetFileSpec().GetFilename().AsCString()); |
Greg Clayton | e4b9df0 | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 2339 | s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s); |
| 2340 | s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s); |
| 2341 | s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s); |
| 2342 | s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s); |
| 2343 | s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s); |
| 2344 | s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s); |
Greg Clayton | fcf06fb | 2010-10-15 02:03:22 +0000 | [diff] [blame] | 2345 | s.Printf("\nTypes:\n"); m_type_index.Dump (&s); |
Greg Clayton | e4b9df0 | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 2346 | s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s); |
Greg Clayton | 7412475 | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2347 | #endif |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2348 | } |
| 2349 | } |
Greg Clayton | db29bba | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2350 | |
| 2351 | bool |
| 2352 | SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl) |
| 2353 | { |
| 2354 | if (namespace_decl == NULL) |
| 2355 | { |
| 2356 | // Invalid namespace decl which means we aren't matching only things |
| 2357 | // in this symbol file, so return true to indicate it matches this |
| 2358 | // symbol file. |
| 2359 | return true; |
| 2360 | } |
| 2361 | |
| 2362 | clang::ASTContext *namespace_ast = namespace_decl->GetASTContext(); |
| 2363 | |
| 2364 | if (namespace_ast == NULL) |
| 2365 | return true; // No AST in the "namespace_decl", return true since it |
| 2366 | // could then match any symbol file, including this one |
| 2367 | |
| 2368 | if (namespace_ast == GetClangASTContext().getASTContext()) |
| 2369 | return true; // The ASTs match, return true |
| 2370 | |
| 2371 | // The namespace AST was valid, and it does not match... |
Sean Callanan | a759706 | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 2372 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 2373 | |
| 2374 | if (log) |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2375 | GetObjectFile()->GetModule()->LogMessage(log.get(), "Valid namespace does not match symbol file"); |
Sean Callanan | a759706 | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 2376 | |
Greg Clayton | db29bba | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2377 | return false; |
| 2378 | } |
| 2379 | |
Greg Clayton | 82770e0 | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2380 | bool |
| 2381 | SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl, |
| 2382 | DWARFCompileUnit* cu, |
| 2383 | const DWARFDebugInfoEntry* die) |
| 2384 | { |
| 2385 | // No namespace specified, so the answesr i |
| 2386 | if (namespace_decl == NULL) |
| 2387 | return true; |
Sean Callanan | c839adc | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2388 | |
| 2389 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
Greg Clayton | db29bba | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2390 | |
Greg Clayton | 82770e0 | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2391 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); |
| 2392 | if (decl_ctx_die) |
| 2393 | { |
Greg Clayton | db29bba | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2394 | |
Greg Clayton | 82770e0 | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2395 | clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl(); |
| 2396 | if (clang_namespace_decl) |
| 2397 | { |
| 2398 | if (decl_ctx_die->Tag() != DW_TAG_namespace) |
Sean Callanan | c839adc | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2399 | { |
| 2400 | if (log) |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2401 | GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent is not a namespace"); |
Greg Clayton | 82770e0 | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2402 | return false; |
Sean Callanan | c839adc | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2403 | } |
| 2404 | |
Greg Clayton | 82770e0 | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2405 | DeclContextToDIEMap::iterator pos = m_decl_ctx_to_die.find(clang_namespace_decl); |
| 2406 | |
| 2407 | if (pos == m_decl_ctx_to_die.end()) |
Sean Callanan | c839adc | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2408 | { |
| 2409 | if (log) |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2410 | GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match in a namespace, but its parent is not the requested namespace"); |
Sean Callanan | c839adc | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2411 | |
Greg Clayton | 82770e0 | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2412 | return false; |
Sean Callanan | c839adc | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2413 | } |
Greg Clayton | 82770e0 | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2414 | |
Greg Clayton | 03fd0d0 | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 2415 | return pos->second.count (decl_ctx_die); |
Greg Clayton | 82770e0 | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2416 | } |
| 2417 | else |
| 2418 | { |
| 2419 | // We have a namespace_decl that was not NULL but it contained |
| 2420 | // a NULL "clang::NamespaceDecl", so this means the global namespace |
| 2421 | // So as long the the contained decl context DIE isn't a namespace |
| 2422 | // we should be ok. |
| 2423 | if (decl_ctx_die->Tag() != DW_TAG_namespace) |
| 2424 | return true; |
| 2425 | } |
| 2426 | } |
Sean Callanan | c839adc | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2427 | |
| 2428 | if (log) |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2429 | GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent doesn't exist"); |
Sean Callanan | c839adc | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2430 | |
Greg Clayton | 82770e0 | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2431 | return false; |
| 2432 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2433 | uint32_t |
Sean Callanan | 0fcec13 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2434 | SymbolFileDWARF::FindGlobalVariables (const ConstString &name, const lldb_private::ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, VariableList& variables) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2435 | { |
Greg Clayton | c7bbd27 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2436 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 2437 | |
| 2438 | if (log) |
| 2439 | { |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2440 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 2441 | "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)", |
| 2442 | name.GetCString(), |
| 2443 | namespace_decl, |
| 2444 | append, |
| 2445 | max_matches); |
Greg Clayton | c7bbd27 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2446 | } |
Sean Callanan | 0fcec13 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2447 | |
| 2448 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) |
| 2449 | return 0; |
| 2450 | |
Greg Clayton | 7412475 | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2451 | DWARFDebugInfo* info = DebugInfo(); |
| 2452 | if (info == NULL) |
| 2453 | return 0; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2454 | |
| 2455 | // If we aren't appending the results to this list, then clear the list |
| 2456 | if (!append) |
| 2457 | variables.Clear(); |
| 2458 | |
| 2459 | // Remember how many variables are in the list before we search in case |
| 2460 | // we are appending the results to a variable list. |
| 2461 | const uint32_t original_size = variables.GetSize(); |
| 2462 | |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2463 | DIEArray die_offsets; |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2464 | |
Greg Clayton | bbe3916 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2465 | if (m_using_apple_tables) |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2466 | { |
Greg Clayton | bbe3916 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2467 | if (m_apple_names_ap.get()) |
| 2468 | { |
| 2469 | const char *name_cstr = name.GetCString(); |
| 2470 | const char *base_name_start; |
| 2471 | const char *base_name_end = NULL; |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2472 | |
Greg Clayton | bbe3916 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2473 | if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end)) |
| 2474 | base_name_start = name_cstr; |
| 2475 | |
| 2476 | m_apple_names_ap->FindByName (base_name_start, die_offsets); |
| 2477 | } |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2478 | } |
| 2479 | else |
| 2480 | { |
| 2481 | // Index the DWARF if we haven't already |
| 2482 | if (!m_indexed) |
| 2483 | Index (); |
| 2484 | |
| 2485 | m_global_index.Find (name, die_offsets); |
| 2486 | } |
| 2487 | |
| 2488 | const size_t num_matches = die_offsets.size(); |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2489 | if (num_matches) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2490 | { |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2491 | SymbolContext sc; |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 2492 | sc.module_sp = m_obj_file->GetModule()->shared_from_this(); |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2493 | assert (sc.module_sp); |
| 2494 | |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2495 | DWARFDebugInfo* debug_info = DebugInfo(); |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2496 | DWARFCompileUnit* dwarf_cu = NULL; |
| 2497 | const DWARFDebugInfoEntry* die = NULL; |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2498 | for (size_t i=0; i<num_matches; ++i) |
| 2499 | { |
| 2500 | const dw_offset_t die_offset = die_offsets[i]; |
| 2501 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2502 | |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2503 | if (die) |
| 2504 | { |
| 2505 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| 2506 | assert(sc.comp_unit != NULL); |
| 2507 | |
| 2508 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 2509 | continue; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2510 | |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2511 | ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2512 | |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2513 | if (variables.GetSize() - original_size >= max_matches) |
| 2514 | break; |
| 2515 | } |
| 2516 | else |
| 2517 | { |
| 2518 | if (m_using_apple_tables) |
| 2519 | { |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2520 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n", |
| 2521 | die_offset, name.GetCString()); |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2522 | } |
| 2523 | } |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2524 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2525 | } |
| 2526 | |
| 2527 | // Return the number of variable that were appended to the list |
| 2528 | return variables.GetSize() - original_size; |
| 2529 | } |
| 2530 | |
| 2531 | uint32_t |
| 2532 | SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables) |
| 2533 | { |
Greg Clayton | c7bbd27 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2534 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 2535 | |
| 2536 | if (log) |
| 2537 | { |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2538 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 2539 | "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)", |
| 2540 | regex.GetText(), |
| 2541 | append, |
| 2542 | max_matches); |
Greg Clayton | c7bbd27 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2543 | } |
| 2544 | |
Greg Clayton | 7412475 | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2545 | DWARFDebugInfo* info = DebugInfo(); |
| 2546 | if (info == NULL) |
| 2547 | return 0; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2548 | |
| 2549 | // If we aren't appending the results to this list, then clear the list |
| 2550 | if (!append) |
| 2551 | variables.Clear(); |
| 2552 | |
| 2553 | // Remember how many variables are in the list before we search in case |
| 2554 | // we are appending the results to a variable list. |
| 2555 | const uint32_t original_size = variables.GetSize(); |
| 2556 | |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2557 | DIEArray die_offsets; |
| 2558 | |
Greg Clayton | bbe3916 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2559 | if (m_using_apple_tables) |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2560 | { |
Greg Clayton | bbe3916 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2561 | if (m_apple_names_ap.get()) |
Greg Clayton | 37bb8dd | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 2562 | { |
| 2563 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 2564 | if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) |
| 2565 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| 2566 | } |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2567 | } |
| 2568 | else |
| 2569 | { |
| 2570 | // Index the DWARF if we haven't already |
| 2571 | if (!m_indexed) |
| 2572 | Index (); |
| 2573 | |
| 2574 | m_global_index.Find (regex, die_offsets); |
| 2575 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2576 | |
Greg Clayton | 7412475 | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2577 | SymbolContext sc; |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 2578 | sc.module_sp = m_obj_file->GetModule()->shared_from_this(); |
Greg Clayton | 7412475 | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2579 | assert (sc.module_sp); |
| 2580 | |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2581 | DWARFCompileUnit* dwarf_cu = NULL; |
Greg Clayton | 7412475 | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2582 | const DWARFDebugInfoEntry* die = NULL; |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2583 | const size_t num_matches = die_offsets.size(); |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2584 | if (num_matches) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2585 | { |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2586 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2587 | for (size_t i=0; i<num_matches; ++i) |
| 2588 | { |
| 2589 | const dw_offset_t die_offset = die_offsets[i]; |
| 2590 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2591 | |
| 2592 | if (die) |
| 2593 | { |
| 2594 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2595 | |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2596 | ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2597 | |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2598 | if (variables.GetSize() - original_size >= max_matches) |
| 2599 | break; |
| 2600 | } |
| 2601 | else |
| 2602 | { |
| 2603 | if (m_using_apple_tables) |
| 2604 | { |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2605 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n", |
| 2606 | die_offset, regex.GetText()); |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2607 | } |
| 2608 | } |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2609 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2610 | } |
| 2611 | |
| 2612 | // Return the number of variable that were appended to the list |
| 2613 | return variables.GetSize() - original_size; |
| 2614 | } |
| 2615 | |
Greg Clayton | 7a1e5da | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2616 | |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2617 | bool |
| 2618 | SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset, |
| 2619 | DWARFCompileUnit *&dwarf_cu, |
| 2620 | SymbolContextList& sc_list) |
Greg Clayton | d74270e | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2621 | { |
Greg Clayton | 7a1e5da | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2622 | const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| 2623 | return ResolveFunction (dwarf_cu, die, sc_list); |
| 2624 | } |
| 2625 | |
| 2626 | |
| 2627 | bool |
| 2628 | SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu, |
| 2629 | const DWARFDebugInfoEntry *die, |
| 2630 | SymbolContextList& sc_list) |
| 2631 | { |
Greg Clayton | d74270e | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2632 | SymbolContext sc; |
Greg Clayton | 7a1e5da | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2633 | |
| 2634 | if (die == NULL) |
| 2635 | return false; |
| 2636 | |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2637 | // If we were passed a die that is not a function, just return false... |
| 2638 | if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine) |
| 2639 | return false; |
| 2640 | |
| 2641 | const DWARFDebugInfoEntry* inlined_die = NULL; |
| 2642 | if (die->Tag() == DW_TAG_inlined_subroutine) |
Greg Clayton | d74270e | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2643 | { |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2644 | inlined_die = die; |
Greg Clayton | d74270e | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2645 | |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2646 | while ((die = die->GetParent()) != NULL) |
Greg Clayton | 6c19c8a | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 2647 | { |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2648 | if (die->Tag() == DW_TAG_subprogram) |
| 2649 | break; |
Greg Clayton | d74270e | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2650 | } |
| 2651 | } |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2652 | assert (die->Tag() == DW_TAG_subprogram); |
Greg Clayton | 7a1e5da | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2653 | if (GetFunction (cu, die, sc)) |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2654 | { |
| 2655 | Address addr; |
| 2656 | // Parse all blocks if needed |
| 2657 | if (inlined_die) |
| 2658 | { |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2659 | sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset())); |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2660 | assert (sc.block != NULL); |
| 2661 | if (sc.block->GetStartAddress (addr) == false) |
| 2662 | addr.Clear(); |
| 2663 | } |
| 2664 | else |
| 2665 | { |
| 2666 | sc.block = NULL; |
| 2667 | addr = sc.function->GetAddressRange().GetBaseAddress(); |
| 2668 | } |
| 2669 | |
| 2670 | if (addr.IsValid()) |
| 2671 | { |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2672 | sc_list.Append(sc); |
Greg Clayton | 7a1e5da | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2673 | return true; |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2674 | } |
| 2675 | } |
| 2676 | |
Greg Clayton | 7a1e5da | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2677 | return false; |
Greg Clayton | d74270e | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2678 | } |
| 2679 | |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2680 | void |
| 2681 | SymbolFileDWARF::FindFunctions (const ConstString &name, |
| 2682 | const NameToDIE &name_to_die, |
| 2683 | SymbolContextList& sc_list) |
| 2684 | { |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2685 | DIEArray die_offsets; |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2686 | if (name_to_die.Find (name, die_offsets)) |
| 2687 | { |
| 2688 | ParseFunctions (die_offsets, sc_list); |
| 2689 | } |
| 2690 | } |
| 2691 | |
| 2692 | |
| 2693 | void |
| 2694 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, |
| 2695 | const NameToDIE &name_to_die, |
| 2696 | SymbolContextList& sc_list) |
| 2697 | { |
| 2698 | DIEArray die_offsets; |
| 2699 | if (name_to_die.Find (regex, die_offsets)) |
| 2700 | { |
| 2701 | ParseFunctions (die_offsets, sc_list); |
| 2702 | } |
| 2703 | } |
| 2704 | |
| 2705 | |
| 2706 | void |
| 2707 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, |
| 2708 | const DWARFMappedHash::MemoryTable &memory_table, |
| 2709 | SymbolContextList& sc_list) |
| 2710 | { |
| 2711 | DIEArray die_offsets; |
Greg Clayton | 37bb8dd | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 2712 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 2713 | if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2714 | { |
Greg Clayton | 37bb8dd | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 2715 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2716 | ParseFunctions (die_offsets, sc_list); |
| 2717 | } |
| 2718 | } |
| 2719 | |
| 2720 | void |
| 2721 | SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets, |
| 2722 | SymbolContextList& sc_list) |
| 2723 | { |
| 2724 | const size_t num_matches = die_offsets.size(); |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2725 | if (num_matches) |
Greg Clayton | 7412475 | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2726 | { |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2727 | SymbolContext sc; |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2728 | |
| 2729 | DWARFCompileUnit* dwarf_cu = NULL; |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2730 | for (size_t i=0; i<num_matches; ++i) |
Greg Clayton | feb6e56 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 2731 | { |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2732 | const dw_offset_t die_offset = die_offsets[i]; |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2733 | ResolveFunction (die_offset, dwarf_cu, sc_list); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2734 | } |
| 2735 | } |
Greg Clayton | 7412475 | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2736 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2737 | |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2738 | bool |
| 2739 | SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die, |
| 2740 | const DWARFCompileUnit *dwarf_cu, |
| 2741 | uint32_t name_type_mask, |
| 2742 | const char *partial_name, |
| 2743 | const char *base_name_start, |
| 2744 | const char *base_name_end) |
| 2745 | { |
| 2746 | // If we are looking only for methods, throw away all the ones that aren't in C++ classes: |
| 2747 | if (name_type_mask == eFunctionNameTypeMethod |
| 2748 | || name_type_mask == eFunctionNameTypeBase) |
| 2749 | { |
Greg Clayton | f6a5bd7 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 2750 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset()); |
| 2751 | if (!containing_decl_ctx) |
| 2752 | return false; |
| 2753 | |
| 2754 | bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()); |
| 2755 | |
| 2756 | if (!is_cxx_method && name_type_mask == eFunctionNameTypeMethod) |
| 2757 | return false; |
| 2758 | if (is_cxx_method && name_type_mask == eFunctionNameTypeBase) |
| 2759 | return false; |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2760 | } |
| 2761 | |
| 2762 | // Now we need to check whether the name we got back for this type matches the extra specifications |
| 2763 | // that were in the name we're looking up: |
| 2764 | if (base_name_start != partial_name || *base_name_end != '\0') |
| 2765 | { |
| 2766 | // First see if the stuff to the left matches the full name. To do that let's see if |
| 2767 | // we can pull out the mips linkage name attribute: |
| 2768 | |
| 2769 | Mangled best_name; |
| 2770 | |
| 2771 | DWARFDebugInfoEntry::Attributes attributes; |
| 2772 | die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| 2773 | uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name); |
| 2774 | if (idx != UINT32_MAX) |
| 2775 | { |
| 2776 | DWARFFormValue form_value; |
| 2777 | if (attributes.ExtractFormValueAtIndex(this, idx, form_value)) |
| 2778 | { |
| 2779 | const char *name = form_value.AsCString(&get_debug_str_data()); |
| 2780 | best_name.SetValue (name, true); |
| 2781 | } |
| 2782 | } |
| 2783 | if (best_name) |
| 2784 | { |
| 2785 | const char *demangled = best_name.GetDemangledName().GetCString(); |
| 2786 | if (demangled) |
| 2787 | { |
| 2788 | std::string name_no_parens(partial_name, base_name_end - partial_name); |
| 2789 | if (strstr (demangled, name_no_parens.c_str()) == NULL) |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2790 | return false; |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2791 | } |
| 2792 | } |
| 2793 | } |
| 2794 | |
| 2795 | return true; |
| 2796 | } |
Greg Clayton | 7412475 | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2797 | |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2798 | uint32_t |
Greg Clayton | 6c19c8a | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 2799 | SymbolFileDWARF::FindFunctions (const ConstString &name, |
Sean Callanan | 0fcec13 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2800 | const lldb_private::ClangNamespaceDecl *namespace_decl, |
Greg Clayton | 6c19c8a | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 2801 | uint32_t name_type_mask, |
| 2802 | bool append, |
| 2803 | SymbolContextList& sc_list) |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2804 | { |
| 2805 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 2806 | "SymbolFileDWARF::FindFunctions (name = '%s')", |
| 2807 | name.AsCString()); |
| 2808 | |
Greg Clayton | c7bbd27 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2809 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 2810 | |
| 2811 | if (log) |
| 2812 | { |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2813 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 2814 | "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)", |
| 2815 | name.GetCString(), |
| 2816 | name_type_mask, |
| 2817 | append); |
Greg Clayton | c7bbd27 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2818 | } |
| 2819 | |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2820 | // If we aren't appending the results to this list, then clear the list |
| 2821 | if (!append) |
| 2822 | sc_list.Clear(); |
Sean Callanan | 0fcec13 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2823 | |
| 2824 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) |
| 2825 | return 0; |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2826 | |
| 2827 | // If name is empty then we won't find anything. |
| 2828 | if (name.IsEmpty()) |
| 2829 | return 0; |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2830 | |
| 2831 | // Remember how many sc_list are in the list before we search in case |
| 2832 | // we are appending the results to a variable list. |
Greg Clayton | d74270e | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2833 | |
Greg Clayton | d74270e | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2834 | const uint32_t original_size = sc_list.GetSize(); |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2835 | |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2836 | const char *name_cstr = name.GetCString(); |
| 2837 | uint32_t effective_name_type_mask = eFunctionNameTypeNone; |
| 2838 | const char *base_name_start = name_cstr; |
| 2839 | const char *base_name_end = name_cstr + strlen(name_cstr); |
| 2840 | |
| 2841 | if (name_type_mask & eFunctionNameTypeAuto) |
| 2842 | { |
| 2843 | if (CPPLanguageRuntime::IsCPPMangledName (name_cstr)) |
| 2844 | effective_name_type_mask = eFunctionNameTypeFull; |
| 2845 | else if (ObjCLanguageRuntime::IsPossibleObjCMethodName (name_cstr)) |
| 2846 | effective_name_type_mask = eFunctionNameTypeFull; |
| 2847 | else |
| 2848 | { |
| 2849 | if (ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr)) |
| 2850 | effective_name_type_mask |= eFunctionNameTypeSelector; |
| 2851 | |
| 2852 | if (CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end)) |
| 2853 | effective_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase); |
| 2854 | } |
| 2855 | } |
| 2856 | else |
| 2857 | { |
| 2858 | effective_name_type_mask = name_type_mask; |
| 2859 | if (effective_name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase) |
| 2860 | { |
| 2861 | // If they've asked for a CPP method or function name and it can't be that, we don't |
| 2862 | // even need to search for CPP methods or names. |
| 2863 | if (!CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end)) |
| 2864 | { |
| 2865 | effective_name_type_mask &= ~(eFunctionNameTypeMethod | eFunctionNameTypeBase); |
| 2866 | if (effective_name_type_mask == eFunctionNameTypeNone) |
| 2867 | return 0; |
| 2868 | } |
| 2869 | } |
| 2870 | |
| 2871 | if (effective_name_type_mask & eFunctionNameTypeSelector) |
| 2872 | { |
| 2873 | if (!ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr)) |
| 2874 | { |
| 2875 | effective_name_type_mask &= ~(eFunctionNameTypeSelector); |
| 2876 | if (effective_name_type_mask == eFunctionNameTypeNone) |
| 2877 | return 0; |
| 2878 | } |
| 2879 | } |
| 2880 | } |
| 2881 | |
| 2882 | DWARFDebugInfo* info = DebugInfo(); |
| 2883 | if (info == NULL) |
| 2884 | return 0; |
| 2885 | |
Greg Clayton | 7a1e5da | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2886 | DWARFCompileUnit *dwarf_cu = NULL; |
Greg Clayton | bbe3916 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2887 | if (m_using_apple_tables) |
Greg Clayton | 9a93fcd | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 2888 | { |
Greg Clayton | bbe3916 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2889 | if (m_apple_names_ap.get()) |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2890 | { |
Greg Clayton | bbe3916 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2891 | |
| 2892 | DIEArray die_offsets; |
| 2893 | |
| 2894 | uint32_t num_matches = 0; |
| 2895 | |
| 2896 | if (effective_name_type_mask & eFunctionNameTypeFull) |
Greg Clayton | 7a1e5da | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2897 | { |
Greg Clayton | bbe3916 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2898 | // If they asked for the full name, match what they typed. At some point we may |
| 2899 | // want to canonicalize this (strip double spaces, etc. For now, we just add all the |
| 2900 | // dies that we find by exact match. |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2901 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2902 | for (uint32_t i = 0; i < num_matches; i++) |
| 2903 | { |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2904 | const dw_offset_t die_offset = die_offsets[i]; |
| 2905 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
Greg Clayton | 7a1e5da | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2906 | if (die) |
| 2907 | { |
Sean Callanan | 0fcec13 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2908 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 2909 | continue; |
| 2910 | |
Greg Clayton | 7a1e5da | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2911 | ResolveFunction (dwarf_cu, die, sc_list); |
| 2912 | } |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2913 | else |
| 2914 | { |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2915 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 2916 | die_offset, name_cstr); |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2917 | } |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2918 | } |
Greg Clayton | bbe3916 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2919 | } |
| 2920 | else |
| 2921 | { |
| 2922 | if (effective_name_type_mask & eFunctionNameTypeSelector) |
| 2923 | { |
| 2924 | if (namespace_decl && *namespace_decl) |
| 2925 | return 0; // no selectors in namespaces |
| 2926 | |
| 2927 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); |
| 2928 | // Now make sure these are actually ObjC methods. In this case we can simply look up the name, |
| 2929 | // and if it is an ObjC method name, we're good. |
| 2930 | |
| 2931 | for (uint32_t i = 0; i < num_matches; i++) |
| 2932 | { |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2933 | const dw_offset_t die_offset = die_offsets[i]; |
| 2934 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
Greg Clayton | bbe3916 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2935 | if (die) |
| 2936 | { |
| 2937 | const char *die_name = die->GetName(this, dwarf_cu); |
| 2938 | if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name)) |
| 2939 | ResolveFunction (dwarf_cu, die, sc_list); |
| 2940 | } |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2941 | else |
| 2942 | { |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2943 | GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 2944 | die_offset, name_cstr); |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2945 | } |
Greg Clayton | bbe3916 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2946 | } |
| 2947 | die_offsets.clear(); |
| 2948 | } |
| 2949 | |
| 2950 | if (effective_name_type_mask & eFunctionNameTypeMethod |
| 2951 | || effective_name_type_mask & eFunctionNameTypeBase) |
| 2952 | { |
| 2953 | if ((effective_name_type_mask & eFunctionNameTypeMethod) && |
| 2954 | (namespace_decl && *namespace_decl)) |
| 2955 | return 0; // no methods in namespaces |
| 2956 | |
| 2957 | // The apple_names table stores just the "base name" of C++ methods in the table. So we have to |
| 2958 | // extract the base name, look that up, and if there is any other information in the name we were |
| 2959 | // passed in we have to post-filter based on that. |
| 2960 | |
| 2961 | // FIXME: Arrange the logic above so that we don't calculate the base name twice: |
| 2962 | std::string base_name(base_name_start, base_name_end - base_name_start); |
| 2963 | num_matches = m_apple_names_ap->FindByName (base_name.c_str(), die_offsets); |
| 2964 | |
| 2965 | for (uint32_t i = 0; i < num_matches; i++) |
| 2966 | { |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2967 | const dw_offset_t die_offset = die_offsets[i]; |
| 2968 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
Greg Clayton | bbe3916 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2969 | if (die) |
| 2970 | { |
| 2971 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 2972 | continue; |
| 2973 | |
| 2974 | if (!FunctionDieMatchesPartialName(die, |
| 2975 | dwarf_cu, |
| 2976 | effective_name_type_mask, |
| 2977 | name_cstr, |
| 2978 | base_name_start, |
| 2979 | base_name_end)) |
| 2980 | continue; |
| 2981 | |
| 2982 | // If we get to here, the die is good, and we should add it: |
| 2983 | ResolveFunction (dwarf_cu, die, sc_list); |
| 2984 | } |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2985 | else |
| 2986 | { |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2987 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 2988 | die_offset, name_cstr); |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2989 | } |
Greg Clayton | bbe3916 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2990 | } |
| 2991 | die_offsets.clear(); |
| 2992 | } |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2993 | } |
| 2994 | } |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2995 | } |
| 2996 | else |
| 2997 | { |
| 2998 | |
| 2999 | // Index the DWARF if we haven't already |
| 3000 | if (!m_indexed) |
| 3001 | Index (); |
| 3002 | |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3003 | if (name_type_mask & eFunctionNameTypeFull) |
| 3004 | FindFunctions (name, m_function_fullname_index, sc_list); |
| 3005 | |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3006 | std::string base_name(base_name_start, base_name_end - base_name_start); |
| 3007 | ConstString base_name_const(base_name.c_str()); |
| 3008 | DIEArray die_offsets; |
| 3009 | DWARFCompileUnit *dwarf_cu = NULL; |
| 3010 | |
| 3011 | if (effective_name_type_mask & eFunctionNameTypeBase) |
| 3012 | { |
| 3013 | uint32_t num_base = m_function_basename_index.Find(base_name_const, die_offsets); |
Greg Clayton | 7a1e5da | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3014 | for (uint32_t i = 0; i < num_base; i++) |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3015 | { |
Greg Clayton | 7a1e5da | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3016 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); |
| 3017 | if (die) |
| 3018 | { |
Sean Callanan | 0fcec13 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3019 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3020 | continue; |
| 3021 | |
Greg Clayton | 7a1e5da | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3022 | if (!FunctionDieMatchesPartialName(die, |
| 3023 | dwarf_cu, |
| 3024 | effective_name_type_mask, |
| 3025 | name_cstr, |
| 3026 | base_name_start, |
| 3027 | base_name_end)) |
| 3028 | continue; |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3029 | |
Greg Clayton | 7a1e5da | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3030 | // If we get to here, the die is good, and we should add it: |
| 3031 | ResolveFunction (dwarf_cu, die, sc_list); |
| 3032 | } |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3033 | } |
| 3034 | die_offsets.clear(); |
| 3035 | } |
| 3036 | |
Jim Ingham | 52f794a | 2011-10-11 01:18:11 +0000 | [diff] [blame] | 3037 | if (effective_name_type_mask & eFunctionNameTypeMethod) |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3038 | { |
Sean Callanan | 0fcec13 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3039 | if (namespace_decl && *namespace_decl) |
| 3040 | return 0; // no methods in namespaces |
| 3041 | |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3042 | uint32_t num_base = m_function_method_index.Find(base_name_const, die_offsets); |
| 3043 | { |
Greg Clayton | 7a1e5da | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3044 | for (uint32_t i = 0; i < num_base; i++) |
| 3045 | { |
| 3046 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); |
| 3047 | if (die) |
| 3048 | { |
| 3049 | if (!FunctionDieMatchesPartialName(die, |
| 3050 | dwarf_cu, |
| 3051 | effective_name_type_mask, |
| 3052 | name_cstr, |
| 3053 | base_name_start, |
| 3054 | base_name_end)) |
| 3055 | continue; |
| 3056 | |
| 3057 | // If we get to here, the die is good, and we should add it: |
| 3058 | ResolveFunction (dwarf_cu, die, sc_list); |
| 3059 | } |
| 3060 | } |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3061 | } |
| 3062 | die_offsets.clear(); |
| 3063 | } |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3064 | |
Sean Callanan | 0fcec13 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3065 | if ((effective_name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl)) |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3066 | { |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3067 | FindFunctions (name, m_function_selector_index, sc_list); |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3068 | } |
| 3069 | |
Greg Clayton | 9a93fcd | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 3070 | } |
| 3071 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3072 | // Return the number of variable that were appended to the list |
| 3073 | return sc_list.GetSize() - original_size; |
| 3074 | } |
| 3075 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3076 | uint32_t |
| 3077 | SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool append, SymbolContextList& sc_list) |
| 3078 | { |
| 3079 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 3080 | "SymbolFileDWARF::FindFunctions (regex = '%s')", |
| 3081 | regex.GetText()); |
| 3082 | |
Greg Clayton | c7bbd27 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3083 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 3084 | |
| 3085 | if (log) |
| 3086 | { |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3087 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3088 | "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)", |
| 3089 | regex.GetText(), |
| 3090 | append); |
Greg Clayton | c7bbd27 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3091 | } |
| 3092 | |
| 3093 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3094 | // If we aren't appending the results to this list, then clear the list |
| 3095 | if (!append) |
| 3096 | sc_list.Clear(); |
| 3097 | |
| 3098 | // Remember how many sc_list are in the list before we search in case |
| 3099 | // we are appending the results to a variable list. |
| 3100 | uint32_t original_size = sc_list.GetSize(); |
| 3101 | |
Greg Clayton | bbe3916 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3102 | if (m_using_apple_tables) |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3103 | { |
Greg Clayton | bbe3916 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3104 | if (m_apple_names_ap.get()) |
| 3105 | FindFunctions (regex, *m_apple_names_ap, sc_list); |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3106 | } |
| 3107 | else |
| 3108 | { |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3109 | // Index the DWARF if we haven't already |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3110 | if (!m_indexed) |
| 3111 | Index (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3112 | |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3113 | FindFunctions (regex, m_function_basename_index, sc_list); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3114 | |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3115 | FindFunctions (regex, m_function_fullname_index, sc_list); |
| 3116 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3117 | |
| 3118 | // Return the number of variable that were appended to the list |
| 3119 | return sc_list.GetSize() - original_size; |
| 3120 | } |
Jim Ingham | 5454892 | 2011-08-26 19:44:13 +0000 | [diff] [blame] | 3121 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3122 | uint32_t |
Greg Clayton | 37bb8dd | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3123 | SymbolFileDWARF::FindTypes (const SymbolContext& sc, |
| 3124 | const ConstString &name, |
| 3125 | const lldb_private::ClangNamespaceDecl *namespace_decl, |
| 3126 | bool append, |
| 3127 | uint32_t max_matches, |
| 3128 | TypeList& types) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3129 | { |
Greg Clayton | 7412475 | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3130 | DWARFDebugInfo* info = DebugInfo(); |
| 3131 | if (info == NULL) |
| 3132 | return 0; |
| 3133 | |
Greg Clayton | c7bbd27 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3134 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 3135 | |
| 3136 | if (log) |
| 3137 | { |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3138 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3139 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", append=%u, max_matches=%u, type_list)", |
| 3140 | name.GetCString(), |
| 3141 | append, |
| 3142 | max_matches); |
Greg Clayton | c7bbd27 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3143 | } |
| 3144 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3145 | // If we aren't appending the results to this list, then clear the list |
| 3146 | if (!append) |
| 3147 | types.Clear(); |
Sean Callanan | 0fcec13 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3148 | |
| 3149 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) |
| 3150 | return 0; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3151 | |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3152 | DIEArray die_offsets; |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3153 | |
Greg Clayton | bbe3916 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3154 | if (m_using_apple_tables) |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3155 | { |
Greg Clayton | bbe3916 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3156 | if (m_apple_types_ap.get()) |
| 3157 | { |
| 3158 | const char *name_cstr = name.GetCString(); |
| 3159 | m_apple_types_ap->FindByName (name_cstr, die_offsets); |
| 3160 | } |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3161 | } |
| 3162 | else |
| 3163 | { |
| 3164 | if (!m_indexed) |
| 3165 | Index (); |
| 3166 | |
| 3167 | m_type_index.Find (name, die_offsets); |
| 3168 | } |
| 3169 | |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3170 | const size_t num_matches = die_offsets.size(); |
| 3171 | |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3172 | if (num_matches) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3173 | { |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3174 | const uint32_t initial_types_size = types.GetSize(); |
| 3175 | DWARFCompileUnit* dwarf_cu = NULL; |
| 3176 | const DWARFDebugInfoEntry* die = NULL; |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3177 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3178 | for (size_t i=0; i<num_matches; ++i) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3179 | { |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3180 | const dw_offset_t die_offset = die_offsets[i]; |
| 3181 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| 3182 | |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3183 | if (die) |
Greg Clayton | 63afdb0 | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 3184 | { |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3185 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3186 | continue; |
| 3187 | |
| 3188 | Type *matching_type = ResolveType (dwarf_cu, die); |
| 3189 | if (matching_type) |
| 3190 | { |
| 3191 | // We found a type pointer, now find the shared pointer form our type list |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 3192 | types.InsertUnique (matching_type->shared_from_this()); |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3193 | if (types.GetSize() >= max_matches) |
| 3194 | break; |
| 3195 | } |
Greg Clayton | 63afdb0 | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 3196 | } |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3197 | else |
| 3198 | { |
| 3199 | if (m_using_apple_tables) |
| 3200 | { |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3201 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 3202 | die_offset, name.GetCString()); |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3203 | } |
| 3204 | } |
| 3205 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3206 | } |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3207 | return types.GetSize() - initial_types_size; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3208 | } |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3209 | return 0; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3210 | } |
| 3211 | |
| 3212 | |
Greg Clayton | 6916e35 | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3213 | ClangNamespaceDecl |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3214 | SymbolFileDWARF::FindNamespace (const SymbolContext& sc, |
Sean Callanan | 0fcec13 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3215 | const ConstString &name, |
| 3216 | const lldb_private::ClangNamespaceDecl *parent_namespace_decl) |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3217 | { |
Greg Clayton | c7bbd27 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3218 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 3219 | |
| 3220 | if (log) |
| 3221 | { |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3222 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3223 | "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")", |
| 3224 | name.GetCString()); |
Greg Clayton | c7bbd27 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3225 | } |
Sean Callanan | 0fcec13 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3226 | |
| 3227 | if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl)) |
| 3228 | return ClangNamespaceDecl(); |
Greg Clayton | c7bbd27 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3229 | |
Greg Clayton | 6916e35 | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3230 | ClangNamespaceDecl namespace_decl; |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3231 | DWARFDebugInfo* info = DebugInfo(); |
Greg Clayton | 6916e35 | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3232 | if (info) |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3233 | { |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3234 | DIEArray die_offsets; |
| 3235 | |
Greg Clayton | 6916e35 | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3236 | // Index if we already haven't to make sure the compile units |
| 3237 | // get indexed and make their global DIE index list |
Greg Clayton | bbe3916 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3238 | if (m_using_apple_tables) |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3239 | { |
Greg Clayton | bbe3916 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3240 | if (m_apple_namespaces_ap.get()) |
| 3241 | { |
| 3242 | const char *name_cstr = name.GetCString(); |
| 3243 | m_apple_namespaces_ap->FindByName (name_cstr, die_offsets); |
| 3244 | } |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3245 | } |
| 3246 | else |
| 3247 | { |
| 3248 | if (!m_indexed) |
| 3249 | Index (); |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3250 | |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3251 | m_namespace_index.Find (name, die_offsets); |
| 3252 | } |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3253 | |
| 3254 | DWARFCompileUnit* dwarf_cu = NULL; |
Greg Clayton | 6916e35 | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3255 | const DWARFDebugInfoEntry* die = NULL; |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3256 | const size_t num_matches = die_offsets.size(); |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3257 | if (num_matches) |
Greg Clayton | 6916e35 | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3258 | { |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3259 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3260 | for (size_t i=0; i<num_matches; ++i) |
Greg Clayton | 6916e35 | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3261 | { |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3262 | const dw_offset_t die_offset = die_offsets[i]; |
| 3263 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
Sean Callanan | 0fcec13 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3264 | |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3265 | if (die) |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3266 | { |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3267 | if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die)) |
| 3268 | continue; |
| 3269 | |
| 3270 | clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die); |
| 3271 | if (clang_namespace_decl) |
| 3272 | { |
| 3273 | namespace_decl.SetASTContext (GetClangASTContext().getASTContext()); |
| 3274 | namespace_decl.SetNamespaceDecl (clang_namespace_decl); |
Greg Clayton | 37bb8dd | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3275 | break; |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3276 | } |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3277 | } |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3278 | else |
| 3279 | { |
| 3280 | if (m_using_apple_tables) |
| 3281 | { |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3282 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n", |
| 3283 | die_offset, name.GetCString()); |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3284 | } |
| 3285 | } |
| 3286 | |
Greg Clayton | 6916e35 | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3287 | } |
| 3288 | } |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3289 | } |
Greg Clayton | 6916e35 | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3290 | return namespace_decl; |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3291 | } |
| 3292 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3293 | uint32_t |
Greg Clayton | 960d6a4 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3294 | SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3295 | { |
| 3296 | // Remember how many sc_list are in the list before we search in case |
| 3297 | // we are appending the results to a variable list. |
Greg Clayton | 960d6a4 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3298 | uint32_t original_size = types.GetSize(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3299 | |
| 3300 | const uint32_t num_die_offsets = die_offsets.size(); |
| 3301 | // Parse all of the types we found from the pubtypes matches |
| 3302 | uint32_t i; |
| 3303 | uint32_t num_matches = 0; |
| 3304 | for (i = 0; i < num_die_offsets; ++i) |
| 3305 | { |
Greg Clayton | 960d6a4 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3306 | Type *matching_type = ResolveTypeUID (die_offsets[i]); |
| 3307 | if (matching_type) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3308 | { |
Greg Clayton | 960d6a4 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3309 | // We found a type pointer, now find the shared pointer form our type list |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 3310 | types.InsertUnique (matching_type->shared_from_this()); |
Greg Clayton | 960d6a4 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3311 | ++num_matches; |
| 3312 | if (num_matches >= max_matches) |
| 3313 | break; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3314 | } |
| 3315 | } |
| 3316 | |
| 3317 | // Return the number of variable that were appended to the list |
Greg Clayton | 960d6a4 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3318 | return types.GetSize() - original_size; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3319 | } |
| 3320 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3321 | |
| 3322 | size_t |
Greg Clayton | c5dca6c | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3323 | SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc, |
| 3324 | clang::DeclContext *containing_decl_ctx, |
Greg Clayton | c5dca6c | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3325 | DWARFCompileUnit* dwarf_cu, |
| 3326 | const DWARFDebugInfoEntry *parent_die, |
| 3327 | bool skip_artificial, |
| 3328 | bool &is_static, |
| 3329 | TypeList* type_list, |
| 3330 | std::vector<clang_type_t>& function_param_types, |
| 3331 | std::vector<clang::ParmVarDecl*>& function_param_decls, |
| 3332 | unsigned &type_quals) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3333 | { |
| 3334 | if (parent_die == NULL) |
| 3335 | return 0; |
| 3336 | |
Greg Clayton | 5fcff9a | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3337 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| 3338 | |
Greg Clayton | 2403b5e | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3339 | size_t arg_idx = 0; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3340 | const DWARFDebugInfoEntry *die; |
| 3341 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 3342 | { |
| 3343 | dw_tag_t tag = die->Tag(); |
| 3344 | switch (tag) |
| 3345 | { |
| 3346 | case DW_TAG_formal_parameter: |
| 3347 | { |
| 3348 | DWARFDebugInfoEntry::Attributes attributes; |
Greg Clayton | 5fcff9a | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3349 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3350 | if (num_attributes > 0) |
| 3351 | { |
| 3352 | const char *name = NULL; |
| 3353 | Declaration decl; |
| 3354 | dw_offset_t param_type_die_offset = DW_INVALID_OFFSET; |
Greg Clayton | 412440a | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 3355 | bool is_artificial = false; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3356 | // one of None, Auto, Register, Extern, Static, PrivateExtern |
| 3357 | |
Sean Callanan | 47a5c4c | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 3358 | clang::StorageClass storage = clang::SC_None; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3359 | uint32_t i; |
| 3360 | for (i=0; i<num_attributes; ++i) |
| 3361 | { |
| 3362 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 3363 | DWARFFormValue form_value; |
| 3364 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 3365 | { |
| 3366 | switch (attr) |
| 3367 | { |
| 3368 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 3369 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 3370 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 3371 | case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; |
| 3372 | case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break; |
Greg Clayton | 412440a | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 3373 | case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3374 | case DW_AT_location: |
| 3375 | // if (form_value.BlockData()) |
| 3376 | // { |
| 3377 | // const DataExtractor& debug_info_data = debug_info(); |
| 3378 | // uint32_t block_length = form_value.Unsigned(); |
| 3379 | // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length); |
| 3380 | // } |
| 3381 | // else |
| 3382 | // { |
| 3383 | // } |
| 3384 | // break; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3385 | case DW_AT_const_value: |
| 3386 | case DW_AT_default_value: |
| 3387 | case DW_AT_description: |
| 3388 | case DW_AT_endianity: |
| 3389 | case DW_AT_is_optional: |
| 3390 | case DW_AT_segment: |
| 3391 | case DW_AT_variable_parameter: |
| 3392 | default: |
| 3393 | case DW_AT_abstract_origin: |
| 3394 | case DW_AT_sibling: |
| 3395 | break; |
| 3396 | } |
| 3397 | } |
| 3398 | } |
Greg Clayton | 412440a | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 3399 | |
Greg Clayton | 1d8173f | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3400 | bool skip = false; |
| 3401 | if (skip_artificial) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3402 | { |
Greg Clayton | 1d8173f | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3403 | if (is_artificial) |
Greg Clayton | 2403b5e | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3404 | { |
| 3405 | // In order to determine if a C++ member function is |
| 3406 | // "const" we have to look at the const-ness of "this"... |
| 3407 | // Ugly, but that |
| 3408 | if (arg_idx == 0) |
| 3409 | { |
Greg Clayton | f6a5bd7 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 3410 | if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind())) |
Sean Callanan | 9930990 | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 3411 | { |
Greg Clayton | c5dca6c | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3412 | // Often times compilers omit the "this" name for the |
| 3413 | // specification DIEs, so we can't rely upon the name |
| 3414 | // being in the formal parameter DIE... |
| 3415 | if (name == NULL || ::strcmp(name, "this")==0) |
Greg Clayton | 2403b5e | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3416 | { |
Greg Clayton | c5dca6c | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3417 | Type *this_type = ResolveTypeUID (param_type_die_offset); |
| 3418 | if (this_type) |
| 3419 | { |
| 3420 | uint32_t encoding_mask = this_type->GetEncodingMask(); |
| 3421 | if (encoding_mask & Type::eEncodingIsPointerUID) |
| 3422 | { |
| 3423 | is_static = false; |
| 3424 | |
| 3425 | if (encoding_mask & (1u << Type::eEncodingIsConstUID)) |
| 3426 | type_quals |= clang::Qualifiers::Const; |
| 3427 | if (encoding_mask & (1u << Type::eEncodingIsVolatileUID)) |
| 3428 | type_quals |= clang::Qualifiers::Volatile; |
Greg Clayton | 2403b5e | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3429 | } |
| 3430 | } |
| 3431 | } |
| 3432 | } |
| 3433 | } |
Greg Clayton | 1d8173f | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3434 | skip = true; |
Greg Clayton | 2403b5e | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3435 | } |
Greg Clayton | 1d8173f | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3436 | else |
| 3437 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3438 | |
Greg Clayton | 1d8173f | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3439 | // HACK: Objective C formal parameters "self" and "_cmd" |
| 3440 | // are not marked as artificial in the DWARF... |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3441 | CompileUnit *curr_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| 3442 | if (curr_cu && (curr_cu->GetLanguage() == eLanguageTypeObjC || curr_cu->GetLanguage() == eLanguageTypeObjC_plus_plus)) |
Greg Clayton | 1d8173f | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3443 | { |
| 3444 | if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0)) |
| 3445 | skip = true; |
| 3446 | } |
| 3447 | } |
| 3448 | } |
| 3449 | |
| 3450 | if (!skip) |
| 3451 | { |
| 3452 | Type *type = ResolveTypeUID(param_type_die_offset); |
| 3453 | if (type) |
| 3454 | { |
Greg Clayton | b433a3d | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 3455 | function_param_types.push_back (type->GetClangForwardType()); |
Greg Clayton | 1d8173f | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3456 | |
Greg Clayton | bcb0adc | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 3457 | clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name, |
| 3458 | type->GetClangForwardType(), |
| 3459 | storage); |
Greg Clayton | 1d8173f | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3460 | assert(param_var_decl); |
| 3461 | function_param_decls.push_back(param_var_decl); |
| 3462 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3463 | } |
| 3464 | } |
Greg Clayton | 2403b5e | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3465 | arg_idx++; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3466 | } |
| 3467 | break; |
| 3468 | |
| 3469 | default: |
| 3470 | break; |
| 3471 | } |
| 3472 | } |
Greg Clayton | 2403b5e | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3473 | return arg_idx; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3474 | } |
| 3475 | |
| 3476 | size_t |
| 3477 | SymbolFileDWARF::ParseChildEnumerators |
| 3478 | ( |
| 3479 | const SymbolContext& sc, |
Greg Clayton | 462d414 | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 3480 | clang_type_t enumerator_clang_type, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3481 | uint32_t enumerator_byte_size, |
Greg Clayton | 1d8173f | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3482 | DWARFCompileUnit* dwarf_cu, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3483 | const DWARFDebugInfoEntry *parent_die |
| 3484 | ) |
| 3485 | { |
| 3486 | if (parent_die == NULL) |
| 3487 | return 0; |
| 3488 | |
| 3489 | size_t enumerators_added = 0; |
| 3490 | const DWARFDebugInfoEntry *die; |
Greg Clayton | 5fcff9a | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3491 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| 3492 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3493 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 3494 | { |
| 3495 | const dw_tag_t tag = die->Tag(); |
| 3496 | if (tag == DW_TAG_enumerator) |
| 3497 | { |
| 3498 | DWARFDebugInfoEntry::Attributes attributes; |
Greg Clayton | 5fcff9a | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3499 | const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3500 | if (num_child_attributes > 0) |
| 3501 | { |
| 3502 | const char *name = NULL; |
| 3503 | bool got_value = false; |
| 3504 | int64_t enum_value = 0; |
| 3505 | Declaration decl; |
| 3506 | |
| 3507 | uint32_t i; |
| 3508 | for (i=0; i<num_child_attributes; ++i) |
| 3509 | { |
| 3510 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 3511 | DWARFFormValue form_value; |
| 3512 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 3513 | { |
| 3514 | switch (attr) |
| 3515 | { |
| 3516 | case DW_AT_const_value: |
| 3517 | got_value = true; |
| 3518 | enum_value = form_value.Unsigned(); |
| 3519 | break; |
| 3520 | |
| 3521 | case DW_AT_name: |
| 3522 | name = form_value.AsCString(&get_debug_str_data()); |
| 3523 | break; |
| 3524 | |
| 3525 | case DW_AT_description: |
| 3526 | default: |
| 3527 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 3528 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 3529 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 3530 | case DW_AT_sibling: |
| 3531 | break; |
| 3532 | } |
| 3533 | } |
| 3534 | } |
| 3535 | |
| 3536 | if (name && name[0] && got_value) |
| 3537 | { |
Greg Clayton | e98ac25 | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 3538 | GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type, |
| 3539 | enumerator_clang_type, |
| 3540 | decl, |
| 3541 | name, |
| 3542 | enum_value, |
| 3543 | enumerator_byte_size * 8); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3544 | ++enumerators_added; |
| 3545 | } |
| 3546 | } |
| 3547 | } |
| 3548 | } |
| 3549 | return enumerators_added; |
| 3550 | } |
| 3551 | |
| 3552 | void |
| 3553 | SymbolFileDWARF::ParseChildArrayInfo |
| 3554 | ( |
| 3555 | const SymbolContext& sc, |
Greg Clayton | 1d8173f | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3556 | DWARFCompileUnit* dwarf_cu, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3557 | const DWARFDebugInfoEntry *parent_die, |
| 3558 | int64_t& first_index, |
| 3559 | std::vector<uint64_t>& element_orders, |
| 3560 | uint32_t& byte_stride, |
| 3561 | uint32_t& bit_stride |
| 3562 | ) |
| 3563 | { |
| 3564 | if (parent_die == NULL) |
| 3565 | return; |
| 3566 | |
| 3567 | const DWARFDebugInfoEntry *die; |
Greg Clayton | 5fcff9a | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3568 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3569 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 3570 | { |
| 3571 | const dw_tag_t tag = die->Tag(); |
| 3572 | switch (tag) |
| 3573 | { |
| 3574 | case DW_TAG_enumerator: |
| 3575 | { |
| 3576 | DWARFDebugInfoEntry::Attributes attributes; |
Greg Clayton | 5fcff9a | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3577 | const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3578 | if (num_child_attributes > 0) |
| 3579 | { |
| 3580 | const char *name = NULL; |
| 3581 | bool got_value = false; |
| 3582 | int64_t enum_value = 0; |
| 3583 | |
| 3584 | uint32_t i; |
| 3585 | for (i=0; i<num_child_attributes; ++i) |
| 3586 | { |
| 3587 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 3588 | DWARFFormValue form_value; |
| 3589 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 3590 | { |
| 3591 | switch (attr) |
| 3592 | { |
| 3593 | case DW_AT_const_value: |
| 3594 | got_value = true; |
| 3595 | enum_value = form_value.Unsigned(); |
| 3596 | break; |
| 3597 | |
| 3598 | case DW_AT_name: |
| 3599 | name = form_value.AsCString(&get_debug_str_data()); |
| 3600 | break; |
| 3601 | |
| 3602 | case DW_AT_description: |
| 3603 | default: |
| 3604 | case DW_AT_decl_file: |
| 3605 | case DW_AT_decl_line: |
| 3606 | case DW_AT_decl_column: |
| 3607 | case DW_AT_sibling: |
| 3608 | break; |
| 3609 | } |
| 3610 | } |
| 3611 | } |
| 3612 | } |
| 3613 | } |
| 3614 | break; |
| 3615 | |
| 3616 | case DW_TAG_subrange_type: |
| 3617 | { |
| 3618 | DWARFDebugInfoEntry::Attributes attributes; |
Greg Clayton | 5fcff9a | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3619 | const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3620 | if (num_child_attributes > 0) |
| 3621 | { |
| 3622 | const char *name = NULL; |
| 3623 | bool got_value = false; |
| 3624 | uint64_t byte_size = 0; |
| 3625 | int64_t enum_value = 0; |
| 3626 | uint64_t num_elements = 0; |
| 3627 | uint64_t lower_bound = 0; |
| 3628 | uint64_t upper_bound = 0; |
| 3629 | uint32_t i; |
| 3630 | for (i=0; i<num_child_attributes; ++i) |
| 3631 | { |
| 3632 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 3633 | DWARFFormValue form_value; |
| 3634 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 3635 | { |
| 3636 | switch (attr) |
| 3637 | { |
| 3638 | case DW_AT_const_value: |
| 3639 | got_value = true; |
| 3640 | enum_value = form_value.Unsigned(); |
| 3641 | break; |
| 3642 | |
| 3643 | case DW_AT_name: |
| 3644 | name = form_value.AsCString(&get_debug_str_data()); |
| 3645 | break; |
| 3646 | |
| 3647 | case DW_AT_count: |
| 3648 | num_elements = form_value.Unsigned(); |
| 3649 | break; |
| 3650 | |
| 3651 | case DW_AT_bit_stride: |
| 3652 | bit_stride = form_value.Unsigned(); |
| 3653 | break; |
| 3654 | |
| 3655 | case DW_AT_byte_stride: |
| 3656 | byte_stride = form_value.Unsigned(); |
| 3657 | break; |
| 3658 | |
| 3659 | case DW_AT_byte_size: |
| 3660 | byte_size = form_value.Unsigned(); |
| 3661 | break; |
| 3662 | |
| 3663 | case DW_AT_lower_bound: |
| 3664 | lower_bound = form_value.Unsigned(); |
| 3665 | break; |
| 3666 | |
| 3667 | case DW_AT_upper_bound: |
| 3668 | upper_bound = form_value.Unsigned(); |
| 3669 | break; |
| 3670 | |
| 3671 | default: |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3672 | case DW_AT_abstract_origin: |
| 3673 | case DW_AT_accessibility: |
| 3674 | case DW_AT_allocated: |
| 3675 | case DW_AT_associated: |
| 3676 | case DW_AT_data_location: |
| 3677 | case DW_AT_declaration: |
| 3678 | case DW_AT_description: |
| 3679 | case DW_AT_sibling: |
| 3680 | case DW_AT_threads_scaled: |
| 3681 | case DW_AT_type: |
| 3682 | case DW_AT_visibility: |
| 3683 | break; |
| 3684 | } |
| 3685 | } |
| 3686 | } |
| 3687 | |
| 3688 | if (upper_bound > lower_bound) |
| 3689 | num_elements = upper_bound - lower_bound + 1; |
| 3690 | |
| 3691 | if (num_elements > 0) |
| 3692 | element_orders.push_back (num_elements); |
| 3693 | } |
| 3694 | } |
| 3695 | break; |
| 3696 | } |
| 3697 | } |
| 3698 | } |
| 3699 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3700 | TypeSP |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3701 | SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry* die) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3702 | { |
| 3703 | TypeSP type_sp; |
| 3704 | if (die != NULL) |
| 3705 | { |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3706 | assert(curr_cu != NULL); |
Greg Clayton | 4fb400f | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 3707 | Type *type_ptr = m_die_to_type.lookup (die); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3708 | if (type_ptr == NULL) |
| 3709 | { |
Greg Clayton | 0d62dfd | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 3710 | CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(curr_cu); |
| 3711 | assert (lldb_cu); |
| 3712 | SymbolContext sc(lldb_cu); |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3713 | type_sp = ParseType(sc, curr_cu, die, NULL); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3714 | } |
| 3715 | else if (type_ptr != DIE_IS_BEING_PARSED) |
| 3716 | { |
| 3717 | // Grab the existing type from the master types lists |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 3718 | type_sp = type_ptr->shared_from_this(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3719 | } |
| 3720 | |
| 3721 | } |
| 3722 | return type_sp; |
| 3723 | } |
| 3724 | |
| 3725 | clang::DeclContext * |
Sean Callanan | c617a4c | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 3726 | SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3727 | { |
| 3728 | if (die_offset != DW_INVALID_OFFSET) |
| 3729 | { |
| 3730 | DWARFCompileUnitSP cu_sp; |
| 3731 | const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp); |
Greg Clayton | 03fd0d0 | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 3732 | return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3733 | } |
| 3734 | return NULL; |
| 3735 | } |
| 3736 | |
Sean Callanan | c617a4c | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 3737 | clang::DeclContext * |
| 3738 | SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset) |
| 3739 | { |
| 3740 | if (die_offset != DW_INVALID_OFFSET) |
| 3741 | { |
Greg Clayton | b523031 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 3742 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3743 | if (debug_info) |
| 3744 | { |
| 3745 | DWARFCompileUnitSP cu_sp; |
| 3746 | const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp); |
| 3747 | if (die) |
| 3748 | return GetClangDeclContextForDIE (sc, cu_sp.get(), die); |
| 3749 | } |
Sean Callanan | c617a4c | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 3750 | } |
| 3751 | return NULL; |
| 3752 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3753 | |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3754 | clang::NamespaceDecl * |
| 3755 | SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die) |
| 3756 | { |
Greg Clayton | 6364304 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 3757 | if (die && die->Tag() == DW_TAG_namespace) |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3758 | { |
Greg Clayton | 6364304 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 3759 | // See if we already parsed this namespace DIE and associated it with a |
| 3760 | // uniqued namespace declaration |
| 3761 | clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]); |
| 3762 | if (namespace_decl) |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3763 | return namespace_decl; |
Greg Clayton | 6364304 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 3764 | else |
| 3765 | { |
| 3766 | const char *namespace_name = die->GetAttributeValueAsString(this, curr_cu, DW_AT_name, NULL); |
Greg Clayton | b516939 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 3767 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (curr_cu, die, NULL); |
| 3768 | namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx); |
| 3769 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| 3770 | if (log) |
Greg Clayton | 6364304 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 3771 | { |
Greg Clayton | b516939 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 3772 | if (namespace_name) |
Greg Clayton | 6364304 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 3773 | { |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3774 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3775 | "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)", |
| 3776 | GetClangASTContext().getASTContext(), |
| 3777 | MakeUserID(die->GetOffset()), |
| 3778 | namespace_name, |
| 3779 | namespace_decl, |
| 3780 | namespace_decl->getOriginalNamespace()); |
Greg Clayton | 6364304 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 3781 | } |
Greg Clayton | b516939 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 3782 | else |
| 3783 | { |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3784 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3785 | "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)", |
| 3786 | GetClangASTContext().getASTContext(), |
| 3787 | MakeUserID(die->GetOffset()), |
| 3788 | namespace_decl, |
| 3789 | namespace_decl->getOriginalNamespace()); |
Greg Clayton | b516939 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 3790 | } |
Greg Clayton | 6364304 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 3791 | } |
Greg Clayton | b516939 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 3792 | |
| 3793 | if (namespace_decl) |
| 3794 | LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die); |
| 3795 | return namespace_decl; |
Greg Clayton | d7cb26e | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3796 | } |
| 3797 | } |
| 3798 | return NULL; |
| 3799 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3800 | |
| 3801 | clang::DeclContext * |
Greg Clayton | d7088cf | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 3802 | SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) |
Sean Callanan | c617a4c | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 3803 | { |
Greg Clayton | b523031 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 3804 | clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die); |
| 3805 | if (clang_decl_ctx) |
| 3806 | return clang_decl_ctx; |
Sean Callanan | c617a4c | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 3807 | // If this DIE has a specification, or an abstract origin, then trace to those. |
| 3808 | |
Greg Clayton | d7088cf | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 3809 | dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET); |
Sean Callanan | c617a4c | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 3810 | if (die_offset != DW_INVALID_OFFSET) |
| 3811 | return GetClangDeclContextForDIEOffset (sc, die_offset); |
| 3812 | |
Greg Clayton | d7088cf | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 3813 | die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET); |
Sean Callanan | c617a4c | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 3814 | if (die_offset != DW_INVALID_OFFSET) |
| 3815 | return GetClangDeclContextForDIEOffset (sc, die_offset); |
| 3816 | |
Greg Clayton | d7fc5b8 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 3817 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| 3818 | if (log) |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3819 | GetObjectFile()->GetModule()->LogMessage(log.get(), "SymbolFileDWARF::GetClangDeclContextForDIE (die = 0x%8.8x) %s '%s'", die->GetOffset(), DW_TAG_value_to_name(die->Tag()), die->GetName(this, cu)); |
Sean Callanan | c617a4c | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 3820 | // This is the DIE we want. Parse it, then query our map. |
Greg Clayton | d7088cf | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 3821 | bool assert_not_being_parsed = true; |
| 3822 | ResolveTypeUID (cu, die, assert_not_being_parsed); |
| 3823 | |
Greg Clayton | b523031 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 3824 | clang_decl_ctx = GetCachedClangDeclContextForDIE (die); |
| 3825 | |
| 3826 | return clang_decl_ctx; |
Sean Callanan | c617a4c | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 3827 | } |
| 3828 | |
| 3829 | clang::DeclContext * |
Greg Clayton | 03fd0d0 | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 3830 | SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3831 | { |
Greg Clayton | 0d62dfd | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 3832 | if (m_clang_tu_decl == NULL) |
| 3833 | m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3834 | |
Greg Clayton | 6c19c8a | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3835 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); |
Greg Clayton | 03fd0d0 | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 3836 | |
| 3837 | if (decl_ctx_die_copy) |
| 3838 | *decl_ctx_die_copy = decl_ctx_die; |
Greg Clayton | 6c19c8a | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3839 | |
| 3840 | if (decl_ctx_die) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3841 | { |
Greg Clayton | 03fd0d0 | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 3842 | |
Greg Clayton | 6c19c8a | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3843 | DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die); |
| 3844 | if (pos != m_die_to_decl_ctx.end()) |
| 3845 | return pos->second; |
| 3846 | |
| 3847 | switch (decl_ctx_die->Tag()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3848 | { |
Greg Clayton | 6c19c8a | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3849 | case DW_TAG_compile_unit: |
| 3850 | return m_clang_tu_decl; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3851 | |
Greg Clayton | 6c19c8a | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3852 | case DW_TAG_namespace: |
Greg Clayton | 6364304 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 3853 | return ResolveNamespaceDIE (cu, decl_ctx_die); |
Greg Clayton | 6c19c8a | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3854 | break; |
| 3855 | |
| 3856 | case DW_TAG_structure_type: |
| 3857 | case DW_TAG_union_type: |
| 3858 | case DW_TAG_class_type: |
| 3859 | { |
| 3860 | Type* type = ResolveType (cu, decl_ctx_die); |
| 3861 | if (type) |
| 3862 | { |
| 3863 | clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ()); |
| 3864 | if (decl_ctx) |
Greg Clayton | 0d62dfd | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 3865 | { |
Greg Clayton | 6c19c8a | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3866 | LinkDeclContextToDIE (decl_ctx, decl_ctx_die); |
| 3867 | if (decl_ctx) |
| 3868 | return decl_ctx; |
Greg Clayton | 0d62dfd | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 3869 | } |
| 3870 | } |
Greg Clayton | 0d62dfd | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 3871 | } |
Greg Clayton | 6c19c8a | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3872 | break; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3873 | |
Greg Clayton | 6c19c8a | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3874 | default: |
| 3875 | break; |
Greg Clayton | 0d62dfd | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 3876 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3877 | } |
Greg Clayton | e5748d8 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 3878 | return m_clang_tu_decl; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3879 | } |
| 3880 | |
Greg Clayton | 6c19c8a | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3881 | |
| 3882 | const DWARFDebugInfoEntry * |
| 3883 | SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) |
| 3884 | { |
| 3885 | if (cu && die) |
| 3886 | { |
| 3887 | const DWARFDebugInfoEntry * const decl_die = die; |
| 3888 | |
| 3889 | while (die != NULL) |
| 3890 | { |
| 3891 | // If this is the original DIE that we are searching for a declaration |
| 3892 | // for, then don't look in the cache as we don't want our own decl |
| 3893 | // context to be our decl context... |
| 3894 | if (decl_die != die) |
| 3895 | { |
| 3896 | switch (die->Tag()) |
| 3897 | { |
| 3898 | case DW_TAG_compile_unit: |
| 3899 | case DW_TAG_namespace: |
| 3900 | case DW_TAG_structure_type: |
| 3901 | case DW_TAG_union_type: |
| 3902 | case DW_TAG_class_type: |
| 3903 | return die; |
| 3904 | |
| 3905 | default: |
| 3906 | break; |
| 3907 | } |
| 3908 | } |
| 3909 | |
| 3910 | dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET); |
| 3911 | if (die_offset != DW_INVALID_OFFSET) |
| 3912 | { |
| 3913 | DWARFCompileUnit *spec_cu = cu; |
| 3914 | const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu); |
| 3915 | const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die); |
| 3916 | if (spec_die_decl_ctx_die) |
| 3917 | return spec_die_decl_ctx_die; |
| 3918 | } |
| 3919 | |
| 3920 | die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET); |
| 3921 | if (die_offset != DW_INVALID_OFFSET) |
| 3922 | { |
| 3923 | DWARFCompileUnit *abs_cu = cu; |
| 3924 | const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu); |
| 3925 | const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die); |
| 3926 | if (abs_die_decl_ctx_die) |
| 3927 | return abs_die_decl_ctx_die; |
| 3928 | } |
| 3929 | |
| 3930 | die = die->GetParent(); |
| 3931 | } |
| 3932 | } |
| 3933 | return NULL; |
| 3934 | } |
| 3935 | |
| 3936 | |
Greg Clayton | 7791722 | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3937 | Symbol * |
| 3938 | SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name) |
| 3939 | { |
| 3940 | Symbol *objc_class_symbol = NULL; |
| 3941 | if (m_obj_file) |
| 3942 | { |
| 3943 | Symtab *symtab = m_obj_file->GetSymtab(); |
| 3944 | if (symtab) |
| 3945 | { |
| 3946 | objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name, |
| 3947 | eSymbolTypeObjCClass, |
| 3948 | Symtab::eDebugNo, |
| 3949 | Symtab::eVisibilityAny); |
| 3950 | } |
| 3951 | } |
| 3952 | return objc_class_symbol; |
| 3953 | } |
| 3954 | |
Greg Clayton | e6b976d | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 3955 | // Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't |
| 3956 | // then we can end up looking through all class types for a complete type and never find |
| 3957 | // the full definition. We need to know if this attribute is supported, so we determine |
| 3958 | // this here and cache th result. We also need to worry about the debug map DWARF file |
| 3959 | // if we are doing darwin DWARF in .o file debugging. |
| 3960 | bool |
| 3961 | SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu) |
| 3962 | { |
| 3963 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate) |
| 3964 | { |
| 3965 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo; |
| 3966 | if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type()) |
| 3967 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; |
| 3968 | else |
| 3969 | { |
| 3970 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3971 | const uint32_t num_compile_units = GetNumCompileUnits(); |
| 3972 | for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) |
| 3973 | { |
| 3974 | DWARFCompileUnit* curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx); |
| 3975 | if (curr_cu != cu && curr_cu->Supports_DW_AT_APPLE_objc_complete_type()) |
| 3976 | { |
| 3977 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; |
| 3978 | break; |
| 3979 | } |
| 3980 | } |
| 3981 | } |
| 3982 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && m_debug_map_symfile) |
| 3983 | return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this); |
| 3984 | } |
| 3985 | return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes; |
| 3986 | } |
Greg Clayton | 7791722 | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3987 | |
| 3988 | // This function can be used when a DIE is found that is a forward declaration |
| 3989 | // DIE and we want to try and find a type that has the complete definition. |
| 3990 | TypeSP |
Greg Clayton | e6b976d | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 3991 | SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die, |
| 3992 | const ConstString &type_name, |
| 3993 | bool must_be_implementation) |
Greg Clayton | 7791722 | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3994 | { |
| 3995 | |
| 3996 | TypeSP type_sp; |
| 3997 | |
Greg Clayton | e6b976d | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 3998 | if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name))) |
Greg Clayton | 7791722 | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3999 | return type_sp; |
| 4000 | |
| 4001 | DIEArray die_offsets; |
| 4002 | |
| 4003 | if (m_using_apple_tables) |
| 4004 | { |
| 4005 | if (m_apple_types_ap.get()) |
| 4006 | { |
| 4007 | const char *name_cstr = type_name.GetCString(); |
Greg Clayton | cc63936 | 2012-01-18 20:58:12 +0000 | [diff] [blame] | 4008 | m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation); |
Greg Clayton | 7791722 | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4009 | } |
| 4010 | } |
| 4011 | else |
| 4012 | { |
| 4013 | if (!m_indexed) |
| 4014 | Index (); |
| 4015 | |
| 4016 | m_type_index.Find (type_name, die_offsets); |
| 4017 | } |
| 4018 | |
Greg Clayton | 7791722 | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4019 | const size_t num_matches = die_offsets.size(); |
| 4020 | |
Greg Clayton | 7791722 | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4021 | DWARFCompileUnit* type_cu = NULL; |
| 4022 | const DWARFDebugInfoEntry* type_die = NULL; |
| 4023 | if (num_matches) |
| 4024 | { |
| 4025 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 4026 | for (size_t i=0; i<num_matches; ++i) |
| 4027 | { |
| 4028 | const dw_offset_t die_offset = die_offsets[i]; |
| 4029 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); |
| 4030 | |
| 4031 | if (type_die) |
| 4032 | { |
| 4033 | bool try_resolving_type = false; |
| 4034 | |
| 4035 | // Don't try and resolve the DIE we are looking for with the DIE itself! |
| 4036 | if (type_die != die) |
| 4037 | { |
Greg Clayton | e6b976d | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4038 | switch (type_die->Tag()) |
Greg Clayton | 7791722 | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4039 | { |
Greg Clayton | e6b976d | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4040 | case DW_TAG_class_type: |
| 4041 | case DW_TAG_structure_type: |
| 4042 | try_resolving_type = true; |
| 4043 | break; |
| 4044 | default: |
| 4045 | break; |
Greg Clayton | 7791722 | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4046 | } |
| 4047 | } |
| 4048 | |
| 4049 | if (try_resolving_type) |
| 4050 | { |
Sean Callanan | e0028b8 | 2012-01-19 02:17:40 +0000 | [diff] [blame] | 4051 | if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type()) |
Greg Clayton | e6b976d | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4052 | try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0); |
Greg Clayton | 7791722 | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4053 | |
| 4054 | if (try_resolving_type) |
| 4055 | { |
| 4056 | Type *resolved_type = ResolveType (type_cu, type_die, false); |
| 4057 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) |
| 4058 | { |
| 4059 | DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n", |
| 4060 | MakeUserID(die->GetOffset()), |
| 4061 | MakeUserID(curr_cu->GetOffset()), |
| 4062 | m_obj_file->GetFileSpec().GetFilename().AsCString(), |
| 4063 | MakeUserID(type_die->GetOffset()), |
| 4064 | MakeUserID(type_cu->GetOffset())); |
| 4065 | |
Greg Clayton | e6b976d | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4066 | if (die) |
| 4067 | m_die_to_type[die] = resolved_type; |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 4068 | type_sp = resolved_type->shared_from_this(); |
Greg Clayton | 7791722 | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4069 | break; |
| 4070 | } |
| 4071 | } |
| 4072 | } |
| 4073 | } |
| 4074 | else |
| 4075 | { |
| 4076 | if (m_using_apple_tables) |
| 4077 | { |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4078 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 4079 | die_offset, type_name.GetCString()); |
Greg Clayton | 7791722 | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4080 | } |
| 4081 | } |
| 4082 | |
| 4083 | } |
| 4084 | } |
| 4085 | return type_sp; |
| 4086 | } |
| 4087 | |
Greg Clayton | b88575e | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4088 | bool |
| 4089 | SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1, |
| 4090 | DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2) |
| 4091 | { |
| 4092 | assert (die1 != die2); |
| 4093 | DWARFDIECollection decl_ctx_1; |
| 4094 | DWARFDIECollection decl_ctx_2; |
| 4095 | die1->GetDeclContextDIEs (this, cu1, decl_ctx_1); |
Sean Callanan | 8f2e392 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 4096 | die2->GetDeclContextDIEs (this, cu2, decl_ctx_2); |
Greg Clayton | b88575e | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4097 | const size_t count1 = decl_ctx_1.Size(); |
| 4098 | const size_t count2 = decl_ctx_2.Size(); |
| 4099 | if (count1 != count2) |
| 4100 | return false; |
| 4101 | const DWARFDebugInfoEntry *decl_ctx_die1; |
| 4102 | const DWARFDebugInfoEntry *decl_ctx_die2; |
| 4103 | size_t i; |
| 4104 | for (i=0; i<count1; i++) |
| 4105 | { |
| 4106 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); |
| 4107 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); |
| 4108 | if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag()) |
| 4109 | return false; |
| 4110 | } |
| 4111 | // Make sure the top item in the decl context die array is always a compile unit |
| 4112 | #if defined LLDB_CONFIGURATION_DEBUG |
| 4113 | assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit); |
| 4114 | #endif |
| 4115 | // Always skip the compile unit when comparing by only iterating up to |
| 4116 | // "count1 - 1" |
| 4117 | for (i=0; i<count1 - 1; i++) |
| 4118 | { |
| 4119 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); |
| 4120 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); |
| 4121 | const char *name1 = decl_ctx_die1->GetName(this, cu1); |
Sean Callanan | 8f2e392 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 4122 | const char *name2 = decl_ctx_die2->GetName(this, cu2); |
Greg Clayton | b88575e | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4123 | // If the string was from a DW_FORM_strp, then the pointer will often |
| 4124 | // be the same! |
| 4125 | if (name1 != name2) |
| 4126 | { |
| 4127 | if (name1 && name2) |
| 4128 | { |
| 4129 | // If the strings don't compare, we are done... |
| 4130 | if (strcmp(name1, name2) != 0) |
| 4131 | return false; |
| 4132 | } |
| 4133 | else |
| 4134 | { |
| 4135 | // One name was NULL while the other wasn't |
| 4136 | return false; |
| 4137 | } |
| 4138 | } |
| 4139 | } |
| 4140 | return true; |
| 4141 | } |
Greg Clayton | b5c023a | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 4142 | |
Greg Clayton | 95e33b7 | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4143 | // This function can be used when a DIE is found that is a forward declaration |
| 4144 | // DIE and we want to try and find a type that has the complete definition. |
| 4145 | TypeSP |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4146 | SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu, |
| 4147 | const DWARFDebugInfoEntry *die, |
| 4148 | const ConstString &type_name) |
Greg Clayton | 95e33b7 | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4149 | { |
| 4150 | TypeSP type_sp; |
| 4151 | |
Greg Clayton | bdcb6ab | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 4152 | if (cu == NULL || die == NULL || !type_name) |
Greg Clayton | 95e33b7 | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4153 | return type_sp; |
| 4154 | |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4155 | DIEArray die_offsets; |
| 4156 | |
Greg Clayton | bbe3916 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4157 | if (m_using_apple_tables) |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4158 | { |
Greg Clayton | bbe3916 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4159 | if (m_apple_types_ap.get()) |
| 4160 | { |
Greg Clayton | 37bb8dd | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4161 | if (m_apple_types_ap->GetHeader().header_data.atoms.size() > 1) |
| 4162 | { |
Greg Clayton | c80dca7 | 2012-01-06 00:17:16 +0000 | [diff] [blame] | 4163 | m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets); |
Greg Clayton | 37bb8dd | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4164 | } |
| 4165 | else |
| 4166 | { |
| 4167 | m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets); |
| 4168 | } |
Greg Clayton | bbe3916 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4169 | } |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4170 | } |
| 4171 | else |
| 4172 | { |
| 4173 | if (!m_indexed) |
| 4174 | Index (); |
| 4175 | |
| 4176 | m_type_index.Find (type_name, die_offsets); |
| 4177 | } |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4178 | |
| 4179 | const size_t num_matches = die_offsets.size(); |
Greg Clayton | 539d945 | 2010-12-03 21:42:06 +0000 | [diff] [blame] | 4180 | |
Greg Clayton | a32dc70 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4181 | const dw_tag_t die_tag = die->Tag(); |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4182 | |
| 4183 | DWARFCompileUnit* type_cu = NULL; |
| 4184 | const DWARFDebugInfoEntry* type_die = NULL; |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4185 | if (num_matches) |
Greg Clayton | 95e33b7 | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4186 | { |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4187 | DWARFDebugInfo* debug_info = DebugInfo(); |
Greg Clayton | 95e33b7 | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4188 | for (size_t i=0; i<num_matches; ++i) |
| 4189 | { |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4190 | const dw_offset_t die_offset = die_offsets[i]; |
| 4191 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); |
Greg Clayton | 95e33b7 | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4192 | |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4193 | if (type_die) |
Greg Clayton | 95e33b7 | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4194 | { |
Greg Clayton | a32dc70 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4195 | bool try_resolving_type = false; |
| 4196 | |
| 4197 | // Don't try and resolve the DIE we are looking for with the DIE itself! |
| 4198 | if (type_die != die) |
Greg Clayton | 95e33b7 | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4199 | { |
Greg Clayton | a32dc70 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4200 | const dw_tag_t type_die_tag = type_die->Tag(); |
| 4201 | // Make sure the tags match |
| 4202 | if (type_die_tag == die_tag) |
Greg Clayton | 95e33b7 | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4203 | { |
Greg Clayton | a32dc70 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4204 | // The tags match, lets try resolving this type |
| 4205 | try_resolving_type = true; |
| 4206 | } |
| 4207 | else |
| 4208 | { |
| 4209 | // The tags don't match, but we need to watch our for a |
| 4210 | // forward declaration for a struct and ("struct foo") |
| 4211 | // ends up being a class ("class foo { ... };") or |
| 4212 | // vice versa. |
| 4213 | switch (type_die_tag) |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4214 | { |
Greg Clayton | a32dc70 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4215 | case DW_TAG_class_type: |
| 4216 | // We had a "class foo", see if we ended up with a "struct foo { ... };" |
| 4217 | try_resolving_type = (die_tag == DW_TAG_structure_type); |
| 4218 | break; |
| 4219 | case DW_TAG_structure_type: |
| 4220 | // We had a "struct foo", see if we ended up with a "class foo { ... };" |
| 4221 | try_resolving_type = (die_tag == DW_TAG_class_type); |
| 4222 | break; |
| 4223 | default: |
| 4224 | // Tags don't match, don't event try to resolve |
| 4225 | // using this type whose name matches.... |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4226 | break; |
| 4227 | } |
Greg Clayton | 95e33b7 | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4228 | } |
| 4229 | } |
Greg Clayton | a32dc70 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4230 | |
| 4231 | if (try_resolving_type) |
| 4232 | { |
Greg Clayton | b88575e | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4233 | // Make sure the decl contexts match all the way up |
| 4234 | if (DIEDeclContextsMatch(cu, die, type_cu, type_die)) |
Greg Clayton | a32dc70 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4235 | { |
Greg Clayton | b88575e | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4236 | Type *resolved_type = ResolveType (type_cu, type_die, false); |
| 4237 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) |
| 4238 | { |
| 4239 | DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n", |
| 4240 | MakeUserID(die->GetOffset()), |
| 4241 | MakeUserID(curr_cu->GetOffset()), |
| 4242 | m_obj_file->GetFileSpec().GetFilename().AsCString(), |
| 4243 | MakeUserID(type_die->GetOffset()), |
| 4244 | MakeUserID(type_cu->GetOffset())); |
| 4245 | |
| 4246 | m_die_to_type[die] = resolved_type; |
Greg Clayton | efa4e22 | 2012-02-02 18:16:59 +0000 | [diff] [blame] | 4247 | type_sp = resolved_type->shared_from_this(); |
Greg Clayton | b88575e | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4248 | break; |
| 4249 | } |
Greg Clayton | a32dc70 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4250 | } |
| 4251 | } |
Greg Clayton | 95e33b7 | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4252 | } |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4253 | else |
| 4254 | { |
| 4255 | if (m_using_apple_tables) |
| 4256 | { |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4257 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 4258 | die_offset, type_name.GetCString()); |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4259 | } |
| 4260 | } |
| 4261 | |
Greg Clayton | 95e33b7 | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4262 | } |
| 4263 | } |
| 4264 | return type_sp; |
| 4265 | } |
| 4266 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4267 | TypeSP |
Greg Clayton | 462d414 | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 4268 | SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4269 | { |
| 4270 | TypeSP type_sp; |
| 4271 | |
Greg Clayton | 462d414 | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 4272 | if (type_is_new_ptr) |
| 4273 | *type_is_new_ptr = false; |
Sean Callanan | 8f2e392 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 4274 | |
| 4275 | static int depth = -1; |
| 4276 | |
| 4277 | class DepthTaker { |
| 4278 | public: |
| 4279 | DepthTaker (int &depth) : m_depth(depth) { ++m_depth; } |
| 4280 | ~DepthTaker () { --m_depth; } |
| 4281 | int &m_depth; |
| 4282 | } depth_taker(depth); |
Greg Clayton | 462d414 | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 4283 | |
Sean Callanan | 70a4f92 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 4284 | AccessType accessibility = eAccessNone; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4285 | if (die != NULL) |
| 4286 | { |
Greg Clayton | c7bbd27 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 4287 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
Greg Clayton | d7fc5b8 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 4288 | if (log) |
Sean Callanan | 8f2e392 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 4289 | { |
| 4290 | const DWARFDebugInfoEntry *context_die; |
| 4291 | clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die); |
| 4292 | |
| 4293 | std::string name_storage; |
| 4294 | |
| 4295 | const char* qual_name = die->GetQualifiedName(this, |
| 4296 | dwarf_cu, |
| 4297 | name_storage); |
| 4298 | |
| 4299 | GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (depth = %d, die = 0x%8.8x, decl_ctx = %p (die 0x%8.8x)) %s '%s'='%s')", |
| 4300 | depth, |
| 4301 | die->GetOffset(), |
| 4302 | context, |
| 4303 | context_die->GetOffset(), |
Greg Clayton | d7fc5b8 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 4304 | DW_TAG_value_to_name(die->Tag()), |
Sean Callanan | 8f2e392 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 4305 | die->GetName(this, dwarf_cu), |
| 4306 | qual_name); |
| 4307 | } |
Greg Clayton | d7fc5b8 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 4308 | // |
| 4309 | // LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| 4310 | // if (log && dwarf_cu) |
| 4311 | // { |
| 4312 | // StreamString s; |
| 4313 | // die->DumpLocation (this, dwarf_cu, s); |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4314 | // GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData()); |
Greg Clayton | d7fc5b8 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 4315 | // |
| 4316 | // } |
Jim Ingham | 9ecdaac | 2011-08-25 23:21:43 +0000 | [diff] [blame] | 4317 | |
Greg Clayton | 4fb400f | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4318 | Type *type_ptr = m_die_to_type.lookup (die); |
Greg Clayton | e98ac25 | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 4319 | TypeList* type_list = GetTypeList(); |
Greg Clayton | 4fb400f | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4320 | if (type_ptr == NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4321 | { |
Greg Clayton | e98ac25 | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 4322 | ClangASTContext &ast = GetClangASTContext(); |
Greg Clayton | 462d414 | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 4323 | if (type_is_new_ptr) |
| 4324 | *type_is_new_ptr = true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4325 | |
Greg Clayton | 4fb400f | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4326 | const dw_tag_t tag = die->Tag(); |
| 4327 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4328 | bool is_forward_declaration = false; |
| 4329 | DWARFDebugInfoEntry::Attributes attributes; |
| 4330 | const char *type_name_cstr = NULL; |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 4331 | ConstString type_name_const_str; |
Greg Clayton | 6916e35 | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4332 | Type::ResolveState resolve_state = Type::eResolveStateUnresolved; |
| 4333 | size_t byte_size = 0; |
Greg Clayton | f1b73af | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 4334 | bool byte_size_valid = false; |
Greg Clayton | 6916e35 | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4335 | Declaration decl; |
| 4336 | |
Greg Clayton | 4b40711 | 2010-09-30 21:49:03 +0000 | [diff] [blame] | 4337 | Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID; |
Greg Clayton | 462d414 | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 4338 | clang_type_t clang_type = NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4339 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4340 | dw_attr_t attr; |
| 4341 | |
| 4342 | switch (tag) |
| 4343 | { |
| 4344 | case DW_TAG_base_type: |
| 4345 | case DW_TAG_pointer_type: |
| 4346 | case DW_TAG_reference_type: |
| 4347 | case DW_TAG_typedef: |
| 4348 | case DW_TAG_const_type: |
| 4349 | case DW_TAG_restrict_type: |
| 4350 | case DW_TAG_volatile_type: |
Greg Clayton | 18fedd7 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 4351 | case DW_TAG_unspecified_type: |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4352 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4353 | // Set a bit that lets us know that we are currently parsing this |
Greg Clayton | 4fb400f | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4354 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4355 | |
Greg Clayton | 5fcff9a | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4356 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4357 | uint32_t encoding = 0; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4358 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; |
| 4359 | |
| 4360 | if (num_attributes > 0) |
| 4361 | { |
| 4362 | uint32_t i; |
| 4363 | for (i=0; i<num_attributes; ++i) |
| 4364 | { |
| 4365 | attr = attributes.AttributeAtIndex(i); |
| 4366 | DWARFFormValue form_value; |
| 4367 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 4368 | { |
| 4369 | switch (attr) |
| 4370 | { |
| 4371 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 4372 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 4373 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 4374 | case DW_AT_name: |
Jim Ingham | 87a58ce | 2011-04-15 23:41:23 +0000 | [diff] [blame] | 4375 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4376 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
Jim Ingham | 87a58ce | 2011-04-15 23:41:23 +0000 | [diff] [blame] | 4377 | // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't |
| 4378 | // include the "&"... |
| 4379 | if (tag == DW_TAG_reference_type) |
| 4380 | { |
| 4381 | if (strchr (type_name_cstr, '&') == NULL) |
| 4382 | type_name_cstr = NULL; |
| 4383 | } |
| 4384 | if (type_name_cstr) |
| 4385 | type_name_const_str.SetCString(type_name_cstr); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4386 | break; |
Greg Clayton | f1b73af | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 4387 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4388 | case DW_AT_encoding: encoding = form_value.Unsigned(); break; |
| 4389 | case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; |
| 4390 | default: |
| 4391 | case DW_AT_sibling: |
| 4392 | break; |
| 4393 | } |
| 4394 | } |
| 4395 | } |
| 4396 | } |
| 4397 | |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 4398 | 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 | b433a3d | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 4399 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4400 | switch (tag) |
| 4401 | { |
| 4402 | default: |
Greg Clayton | 6916e35 | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4403 | break; |
| 4404 | |
Greg Clayton | 18fedd7 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 4405 | case DW_TAG_unspecified_type: |
| 4406 | if (strcmp(type_name_cstr, "nullptr_t") == 0) |
| 4407 | { |
| 4408 | resolve_state = Type::eResolveStateFull; |
| 4409 | clang_type = ast.getASTContext()->NullPtrTy.getAsOpaquePtr(); |
| 4410 | break; |
| 4411 | } |
| 4412 | // Fall through to base type below in case we can handle the type there... |
| 4413 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4414 | case DW_TAG_base_type: |
Greg Clayton | 6916e35 | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4415 | resolve_state = Type::eResolveStateFull; |
Greg Clayton | e98ac25 | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 4416 | clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr, |
| 4417 | encoding, |
| 4418 | byte_size * 8); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4419 | break; |
| 4420 | |
Greg Clayton | 6916e35 | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4421 | case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break; |
| 4422 | case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break; |
| 4423 | case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break; |
| 4424 | case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break; |
| 4425 | case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break; |
| 4426 | case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4427 | } |
| 4428 | |
Greg Clayton | e6b976d | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4429 | if (clang_type == NULL && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID)) |
Greg Clayton | 960d6a4 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4430 | { |
Greg Clayton | e6b976d | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4431 | if (type_name_cstr != NULL && sc.comp_unit != NULL && |
| 4432 | (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus)) |
Greg Clayton | 960d6a4 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4433 | { |
Greg Clayton | e6b976d | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4434 | static ConstString g_objc_type_name_id("id"); |
| 4435 | static ConstString g_objc_type_name_Class("Class"); |
| 4436 | static ConstString g_objc_type_name_selector("SEL"); |
| 4437 | |
| 4438 | if (type_name_const_str == g_objc_type_name_id) |
| 4439 | { |
| 4440 | if (log) |
| 4441 | GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'id' built-in type.", |
| 4442 | die->GetOffset(), |
| 4443 | DW_TAG_value_to_name(die->Tag()), |
| 4444 | die->GetName(this, dwarf_cu)); |
| 4445 | clang_type = ast.GetBuiltInType_objc_id(); |
| 4446 | encoding_data_type = Type::eEncodingIsUID; |
| 4447 | encoding_uid = LLDB_INVALID_UID; |
| 4448 | resolve_state = Type::eResolveStateFull; |
Greg Clayton | 6916e35 | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4449 | |
Greg Clayton | e6b976d | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4450 | } |
| 4451 | else if (type_name_const_str == g_objc_type_name_Class) |
| 4452 | { |
| 4453 | if (log) |
| 4454 | GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'Class' built-in type.", |
| 4455 | die->GetOffset(), |
| 4456 | DW_TAG_value_to_name(die->Tag()), |
| 4457 | die->GetName(this, dwarf_cu)); |
| 4458 | clang_type = ast.GetBuiltInType_objc_Class(); |
| 4459 | encoding_data_type = Type::eEncodingIsUID; |
| 4460 | encoding_uid = LLDB_INVALID_UID; |
| 4461 | resolve_state = Type::eResolveStateFull; |
| 4462 | } |
| 4463 | else if (type_name_const_str == g_objc_type_name_selector) |
| 4464 | { |
| 4465 | if (log) |
| 4466 | GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'selector' built-in type.", |
| 4467 | die->GetOffset(), |
| 4468 | DW_TAG_value_to_name(die->Tag()), |
| 4469 | die->GetName(this, dwarf_cu)); |
| 4470 | clang_type = ast.GetBuiltInType_objc_selector(); |
| 4471 | encoding_data_type = Type::eEncodingIsUID; |
| 4472 | encoding_uid = LLDB_INVALID_UID; |
| 4473 | resolve_state = Type::eResolveStateFull; |
| 4474 | } |
Greg Clayton | 960d6a4 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4475 | } |
| 4476 | } |
| 4477 | |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 4478 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
Greg Clayton | e98ac25 | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 4479 | this, |
| 4480 | type_name_const_str, |
| 4481 | byte_size, |
| 4482 | NULL, |
| 4483 | encoding_uid, |
| 4484 | encoding_data_type, |
| 4485 | &decl, |
| 4486 | clang_type, |
Greg Clayton | 6916e35 | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4487 | resolve_state)); |
Greg Clayton | e98ac25 | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 4488 | |
Greg Clayton | 4fb400f | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4489 | m_die_to_type[die] = type_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4490 | |
| 4491 | // Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false); |
| 4492 | // if (encoding_type != NULL) |
| 4493 | // { |
| 4494 | // if (encoding_type != DIE_IS_BEING_PARSED) |
| 4495 | // type_sp->SetEncodingType(encoding_type); |
| 4496 | // else |
| 4497 | // m_indirect_fixups.push_back(type_sp.get()); |
| 4498 | // } |
| 4499 | } |
| 4500 | break; |
| 4501 | |
| 4502 | case DW_TAG_structure_type: |
| 4503 | case DW_TAG_union_type: |
| 4504 | case DW_TAG_class_type: |
| 4505 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4506 | // Set a bit that lets us know that we are currently parsing this |
Greg Clayton | 4fb400f | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4507 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4508 | |
Greg Clayton | 9488b74 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4509 | LanguageType class_language = eLanguageTypeUnknown; |
Greg Clayton | f332c53 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 4510 | bool is_complete_objc_class = false; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4511 | //bool struct_is_class = false; |
Greg Clayton | 5fcff9a | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4512 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4513 | if (num_attributes > 0) |
| 4514 | { |
| 4515 | uint32_t i; |
| 4516 | for (i=0; i<num_attributes; ++i) |
| 4517 | { |
| 4518 | attr = attributes.AttributeAtIndex(i); |
| 4519 | DWARFFormValue form_value; |
| 4520 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 4521 | { |
| 4522 | switch (attr) |
| 4523 | { |
Greg Clayton | 9488b74 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4524 | case DW_AT_decl_file: |
Greg Clayton | e6b976d | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4525 | if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid()) |
| 4526 | { |
| 4527 | // llvm-gcc outputs invalid DW_AT_decl_file attributes that always |
| 4528 | // point to the compile unit file, so we clear this invalid value |
| 4529 | // so that we can still unique types efficiently. |
| 4530 | decl.SetFile(FileSpec ("<invalid>", false)); |
| 4531 | } |
| 4532 | else |
| 4533 | decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); |
Greg Clayton | 9488b74 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4534 | break; |
| 4535 | |
| 4536 | case DW_AT_decl_line: |
| 4537 | decl.SetLine(form_value.Unsigned()); |
| 4538 | break; |
| 4539 | |
| 4540 | case DW_AT_decl_column: |
| 4541 | decl.SetColumn(form_value.Unsigned()); |
| 4542 | break; |
| 4543 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4544 | case DW_AT_name: |
| 4545 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 4546 | type_name_const_str.SetCString(type_name_cstr); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4547 | break; |
Greg Clayton | 9488b74 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4548 | |
| 4549 | case DW_AT_byte_size: |
| 4550 | byte_size = form_value.Unsigned(); |
Greg Clayton | f1b73af | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 4551 | byte_size_valid = true; |
Greg Clayton | 9488b74 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4552 | break; |
| 4553 | |
| 4554 | case DW_AT_accessibility: |
| 4555 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); |
| 4556 | break; |
| 4557 | |
| 4558 | case DW_AT_declaration: |
Greg Clayton | e5748d8 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 4559 | is_forward_declaration = form_value.Unsigned() != 0; |
Greg Clayton | 9488b74 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4560 | break; |
| 4561 | |
| 4562 | case DW_AT_APPLE_runtime_class: |
| 4563 | class_language = (LanguageType)form_value.Signed(); |
| 4564 | break; |
| 4565 | |
Greg Clayton | f332c53 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 4566 | case DW_AT_APPLE_objc_complete_type: |
| 4567 | is_complete_objc_class = form_value.Signed(); |
| 4568 | break; |
| 4569 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4570 | case DW_AT_allocated: |
| 4571 | case DW_AT_associated: |
| 4572 | case DW_AT_data_location: |
| 4573 | case DW_AT_description: |
| 4574 | case DW_AT_start_scope: |
| 4575 | case DW_AT_visibility: |
| 4576 | default: |
| 4577 | case DW_AT_sibling: |
| 4578 | break; |
| 4579 | } |
| 4580 | } |
| 4581 | } |
| 4582 | } |
| 4583 | |
Greg Clayton | a8d4241 | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4584 | UniqueDWARFASTType unique_ast_entry; |
| 4585 | if (decl.IsValid()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4586 | { |
Greg Clayton | c3c4661 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 4587 | if (GetUniqueDWARFASTTypeMap().Find (type_name_const_str, |
Greg Clayton | f1b73af | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 4588 | this, |
| 4589 | dwarf_cu, |
Greg Clayton | c3c4661 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 4590 | die, |
| 4591 | decl, |
Greg Clayton | f1b73af | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 4592 | byte_size_valid ? byte_size : -1, |
Greg Clayton | c3c4661 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 4593 | unique_ast_entry)) |
Greg Clayton | 5745283 | 2010-11-09 04:42:43 +0000 | [diff] [blame] | 4594 | { |
Greg Clayton | a8d4241 | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4595 | // We have already parsed this type or from another |
| 4596 | // compile unit. GCC loves to use the "one definition |
| 4597 | // rule" which can result in multiple definitions |
| 4598 | // of the same class over and over in each compile |
| 4599 | // unit. |
| 4600 | type_sp = unique_ast_entry.m_type_sp; |
Greg Clayton | 52fd984 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 4601 | if (type_sp) |
| 4602 | { |
Greg Clayton | 52fd984 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 4603 | m_die_to_type[die] = type_sp.get(); |
| 4604 | return type_sp; |
| 4605 | } |
| 4606 | } |
Greg Clayton | a8d4241 | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4607 | } |
| 4608 | |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 4609 | DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr); |
Greg Clayton | a8d4241 | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4610 | |
| 4611 | int tag_decl_kind = -1; |
| 4612 | AccessType default_accessibility = eAccessNone; |
| 4613 | if (tag == DW_TAG_structure_type) |
| 4614 | { |
| 4615 | tag_decl_kind = clang::TTK_Struct; |
| 4616 | default_accessibility = eAccessPublic; |
| 4617 | } |
| 4618 | else if (tag == DW_TAG_union_type) |
| 4619 | { |
| 4620 | tag_decl_kind = clang::TTK_Union; |
| 4621 | default_accessibility = eAccessPublic; |
| 4622 | } |
| 4623 | else if (tag == DW_TAG_class_type) |
| 4624 | { |
| 4625 | tag_decl_kind = clang::TTK_Class; |
| 4626 | default_accessibility = eAccessPrivate; |
| 4627 | } |
Greg Clayton | d37ffd9 | 2011-11-30 02:48:28 +0000 | [diff] [blame] | 4628 | |
| 4629 | if (byte_size_valid && byte_size == 0 && type_name_cstr && |
| 4630 | die->HasChildren() == false && |
| 4631 | sc.comp_unit->GetLanguage() == eLanguageTypeObjC) |
| 4632 | { |
| 4633 | // Work around an issue with clang at the moment where |
| 4634 | // forward declarations for objective C classes are emitted |
| 4635 | // as: |
| 4636 | // DW_TAG_structure_type [2] |
| 4637 | // DW_AT_name( "ForwardObjcClass" ) |
| 4638 | // DW_AT_byte_size( 0x00 ) |
| 4639 | // DW_AT_decl_file( "..." ) |
| 4640 | // DW_AT_decl_line( 1 ) |
| 4641 | // |
| 4642 | // Note that there is no DW_AT_declaration and there are |
| 4643 | // no children, and the byte size is zero. |
| 4644 | is_forward_declaration = true; |
| 4645 | } |
Greg Clayton | a8d4241 | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4646 | |
Greg Clayton | f332c53 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 4647 | if (class_language == eLanguageTypeObjC) |
| 4648 | { |
Greg Clayton | e6b976d | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4649 | if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu)) |
Greg Clayton | 7791722 | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4650 | { |
| 4651 | // We have a valid eSymbolTypeObjCClass class symbol whose |
| 4652 | // name matches the current objective C class that we |
| 4653 | // are trying to find and this DIE isn't the complete |
| 4654 | // definition (we checked is_complete_objc_class above and |
| 4655 | // know it is false), so the real definition is in here somewhere |
Greg Clayton | e6b976d | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4656 | type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true); |
Greg Clayton | a8d4241 | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4657 | |
Greg Clayton | 7791722 | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4658 | if (!type_sp && m_debug_map_symfile) |
| 4659 | { |
| 4660 | // We weren't able to find a full declaration in |
| 4661 | // this DWARF, see if we have a declaration anywhere |
| 4662 | // else... |
Greg Clayton | e6b976d | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4663 | type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true); |
Greg Clayton | 7791722 | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4664 | } |
| 4665 | |
| 4666 | if (type_sp) |
| 4667 | { |
| 4668 | if (log) |
| 4669 | { |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4670 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 4671 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an incomplete objc type, complete type is 0x%8.8llx", |
| 4672 | this, |
| 4673 | die->GetOffset(), |
| 4674 | DW_TAG_value_to_name(tag), |
| 4675 | type_name_cstr, |
| 4676 | type_sp->GetID()); |
Greg Clayton | 7791722 | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4677 | } |
| 4678 | |
| 4679 | // We found a real definition for this type elsewhere |
| 4680 | // so lets use it and cache the fact that we found |
| 4681 | // a complete type for this die |
| 4682 | m_die_to_type[die] = type_sp.get(); |
| 4683 | return type_sp; |
| 4684 | } |
| 4685 | } |
| 4686 | } |
| 4687 | |
| 4688 | |
| 4689 | if (is_forward_declaration) |
Greg Clayton | a8d4241 | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4690 | { |
| 4691 | // We have a forward declaration to a type and we need |
| 4692 | // to try and find a full declaration. We look in the |
| 4693 | // current type index just in case we have a forward |
| 4694 | // declaration followed by an actual declarations in the |
| 4695 | // DWARF. If this fails, we need to look elsewhere... |
Greg Clayton | 75d8c25 | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 4696 | if (log) |
| 4697 | { |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4698 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 4699 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type", |
| 4700 | this, |
| 4701 | die->GetOffset(), |
| 4702 | DW_TAG_value_to_name(tag), |
| 4703 | type_name_cstr); |
Greg Clayton | 75d8c25 | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 4704 | } |
Greg Clayton | a8d4241 | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4705 | |
| 4706 | type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str); |
| 4707 | |
| 4708 | if (!type_sp && m_debug_map_symfile) |
Greg Clayton | 52fd984 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 4709 | { |
Greg Clayton | a8d4241 | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4710 | // We weren't able to find a full declaration in |
| 4711 | // this DWARF, see if we have a declaration anywhere |
| 4712 | // else... |
| 4713 | type_sp = m_debug_map_symfile->FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str); |
Greg Clayton | 52fd984 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 4714 | } |
| 4715 | |
Greg Clayton | a8d4241 | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4716 | if (type_sp) |
Greg Clayton | 52fd984 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 4717 | { |
Greg Clayton | 75d8c25 | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 4718 | if (log) |
| 4719 | { |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4720 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 4721 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8llx", |
| 4722 | this, |
| 4723 | die->GetOffset(), |
| 4724 | DW_TAG_value_to_name(tag), |
| 4725 | type_name_cstr, |
| 4726 | type_sp->GetID()); |
Greg Clayton | 75d8c25 | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 4727 | } |
| 4728 | |
Greg Clayton | a8d4241 | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4729 | // We found a real definition for this type elsewhere |
| 4730 | // so lets use it and cache the fact that we found |
| 4731 | // a complete type for this die |
| 4732 | m_die_to_type[die] = type_sp.get(); |
| 4733 | return type_sp; |
Greg Clayton | 52fd984 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 4734 | } |
Greg Clayton | a8d4241 | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4735 | } |
| 4736 | assert (tag_decl_kind != -1); |
| 4737 | bool clang_type_was_created = false; |
| 4738 | clang_type = m_forward_decl_die_to_clang_type.lookup (die); |
| 4739 | if (clang_type == NULL) |
| 4740 | { |
Greg Clayton | f6a5bd7 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 4741 | clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL); |
Greg Clayton | 5e8eb5c | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 4742 | if (accessibility == eAccessNone && decl_ctx) |
| 4743 | { |
| 4744 | // Check the decl context that contains this class/struct/union. |
| 4745 | // If it is a class we must give it an accessability. |
| 4746 | const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind(); |
| 4747 | if (DeclKindIsCXXClass (containing_decl_kind)) |
| 4748 | accessibility = default_accessibility; |
| 4749 | } |
| 4750 | |
Greg Clayton | f6a5bd7 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 4751 | if (type_name_cstr && strchr (type_name_cstr, '<')) |
| 4752 | { |
| 4753 | ClangASTContext::TemplateParameterInfos template_param_infos; |
| 4754 | if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos)) |
| 4755 | { |
| 4756 | clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx, |
Greg Clayton | 5e8eb5c | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 4757 | accessibility, |
Greg Clayton | f6a5bd7 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 4758 | type_name_cstr, |
| 4759 | tag_decl_kind, |
| 4760 | template_param_infos); |
| 4761 | |
| 4762 | clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx, |
| 4763 | class_template_decl, |
| 4764 | tag_decl_kind, |
| 4765 | template_param_infos); |
| 4766 | clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl); |
| 4767 | clang_type_was_created = true; |
| 4768 | } |
| 4769 | } |
| 4770 | |
| 4771 | if (!clang_type_was_created) |
| 4772 | { |
| 4773 | clang_type_was_created = true; |
Greg Clayton | 5e8eb5c | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 4774 | clang_type = ast.CreateRecordType (decl_ctx, |
| 4775 | accessibility, |
| 4776 | type_name_cstr, |
Greg Clayton | f6a5bd7 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 4777 | tag_decl_kind, |
Greg Clayton | f6a5bd7 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 4778 | class_language); |
| 4779 | } |
Greg Clayton | a8d4241 | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4780 | } |
| 4781 | |
| 4782 | // Store a forward declaration to this class type in case any |
| 4783 | // parameters in any class methods need it for the clang |
Greg Clayton | e6d72ca | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 4784 | // types for function prototypes. |
| 4785 | LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die); |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 4786 | type_sp.reset (new Type (MakeUserID(die->GetOffset()), |
Greg Clayton | a8d4241 | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4787 | this, |
| 4788 | type_name_const_str, |
| 4789 | byte_size, |
| 4790 | NULL, |
| 4791 | LLDB_INVALID_UID, |
| 4792 | Type::eEncodingIsUID, |
| 4793 | &decl, |
| 4794 | clang_type, |
| 4795 | Type::eResolveStateForward)); |
| 4796 | |
| 4797 | |
| 4798 | // Add our type to the unique type map so we don't |
| 4799 | // end up creating many copies of the same type over |
| 4800 | // and over in the ASTContext for our module |
| 4801 | unique_ast_entry.m_type_sp = type_sp; |
Greg Clayton | f1b73af | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 4802 | unique_ast_entry.m_symfile = this; |
| 4803 | unique_ast_entry.m_cu = dwarf_cu; |
Greg Clayton | a8d4241 | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4804 | unique_ast_entry.m_die = die; |
| 4805 | unique_ast_entry.m_declaration = decl; |
Greg Clayton | c3c4661 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 4806 | GetUniqueDWARFASTTypeMap().Insert (type_name_const_str, |
| 4807 | unique_ast_entry); |
Greg Clayton | a8d4241 | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4808 | |
Sean Callanan | b2027ec | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 4809 | if (!is_forward_declaration) |
| 4810 | { |
| 4811 | if (die->HasChildren() == false) |
| 4812 | { |
| 4813 | // No children for this struct/union/class, lets finish it |
| 4814 | ast.StartTagDeclarationDefinition (clang_type); |
| 4815 | ast.CompleteTagDeclarationDefinition (clang_type); |
| 4816 | } |
| 4817 | else if (clang_type_was_created) |
| 4818 | { |
| 4819 | // Leave this as a forward declaration until we need |
| 4820 | // to know the details of the type. lldb_private::Type |
| 4821 | // will automatically call the SymbolFile virtual function |
| 4822 | // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)" |
| 4823 | // When the definition needs to be defined. |
| 4824 | m_forward_decl_die_to_clang_type[die] = clang_type; |
| 4825 | m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die; |
| 4826 | ClangASTContext::SetHasExternalStorage (clang_type, true); |
| 4827 | } |
Greg Clayton | 5745283 | 2010-11-09 04:42:43 +0000 | [diff] [blame] | 4828 | } |
Greg Clayton | d7088cf | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4829 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4830 | } |
| 4831 | break; |
| 4832 | |
| 4833 | case DW_TAG_enumeration_type: |
| 4834 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4835 | // Set a bit that lets us know that we are currently parsing this |
Greg Clayton | 4fb400f | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4836 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4837 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4838 | lldb::user_id_t encoding_uid = DW_INVALID_OFFSET; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4839 | |
Greg Clayton | 5fcff9a | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4840 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4841 | if (num_attributes > 0) |
| 4842 | { |
| 4843 | uint32_t i; |
| 4844 | |
| 4845 | for (i=0; i<num_attributes; ++i) |
| 4846 | { |
| 4847 | attr = attributes.AttributeAtIndex(i); |
| 4848 | DWARFFormValue form_value; |
| 4849 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 4850 | { |
| 4851 | switch (attr) |
| 4852 | { |
Greg Clayton | e5748d8 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 4853 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 4854 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 4855 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4856 | case DW_AT_name: |
| 4857 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 4858 | type_name_const_str.SetCString(type_name_cstr); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4859 | break; |
Greg Clayton | e5748d8 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 4860 | case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; |
Greg Clayton | f1b73af | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 4861 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break; |
Greg Clayton | e5748d8 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 4862 | case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
| 4863 | case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4864 | case DW_AT_allocated: |
| 4865 | case DW_AT_associated: |
| 4866 | case DW_AT_bit_stride: |
| 4867 | case DW_AT_byte_stride: |
| 4868 | case DW_AT_data_location: |
| 4869 | case DW_AT_description: |
| 4870 | case DW_AT_start_scope: |
| 4871 | case DW_AT_visibility: |
| 4872 | case DW_AT_specification: |
| 4873 | case DW_AT_abstract_origin: |
| 4874 | case DW_AT_sibling: |
| 4875 | break; |
| 4876 | } |
| 4877 | } |
| 4878 | } |
| 4879 | |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 4880 | DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr); |
Greg Clayton | b433a3d | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 4881 | |
Greg Clayton | 462d414 | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 4882 | clang_type_t enumerator_clang_type = NULL; |
| 4883 | clang_type = m_forward_decl_die_to_clang_type.lookup (die); |
| 4884 | if (clang_type == NULL) |
| 4885 | { |
Greg Clayton | e98ac25 | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 4886 | enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL, |
| 4887 | DW_ATE_signed, |
| 4888 | byte_size * 8); |
Greg Clayton | 0d62dfd | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4889 | clang_type = ast.CreateEnumerationType (type_name_cstr, |
Greg Clayton | 03fd0d0 | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4890 | GetClangDeclContextContainingDIE (dwarf_cu, die, NULL), |
Greg Clayton | 0d62dfd | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4891 | decl, |
Greg Clayton | e98ac25 | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 4892 | enumerator_clang_type); |
Greg Clayton | 462d414 | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 4893 | } |
| 4894 | else |
| 4895 | { |
| 4896 | enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type); |
| 4897 | assert (enumerator_clang_type != NULL); |
| 4898 | } |
| 4899 | |
Greg Clayton | e6d72ca | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 4900 | LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die); |
| 4901 | |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 4902 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
Greg Clayton | e98ac25 | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 4903 | this, |
| 4904 | type_name_const_str, |
| 4905 | byte_size, |
| 4906 | NULL, |
| 4907 | encoding_uid, |
| 4908 | Type::eEncodingIsUID, |
| 4909 | &decl, |
| 4910 | clang_type, |
Greg Clayton | 6916e35 | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4911 | Type::eResolveStateForward)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4912 | |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 4913 | ast.StartTagDeclarationDefinition (clang_type); |
| 4914 | if (die->HasChildren()) |
| 4915 | { |
Greg Clayton | bdcb6ab | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 4916 | SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); |
| 4917 | ParseChildEnumerators(cu_sc, clang_type, type_sp->GetByteSize(), dwarf_cu, die); |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 4918 | } |
| 4919 | ast.CompleteTagDeclarationDefinition (clang_type); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4920 | } |
| 4921 | } |
| 4922 | break; |
| 4923 | |
Jim Ingham | 0007dff | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 4924 | case DW_TAG_inlined_subroutine: |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4925 | case DW_TAG_subprogram: |
| 4926 | case DW_TAG_subroutine_type: |
| 4927 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4928 | // Set a bit that lets us know that we are currently parsing this |
Greg Clayton | 4fb400f | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4929 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4930 | |
| 4931 | const char *mangled = NULL; |
| 4932 | dw_offset_t type_die_offset = DW_INVALID_OFFSET; |
Greg Clayton | 412440a | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 4933 | bool is_variadic = false; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4934 | bool is_inline = false; |
Greg Clayton | 1d8173f | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4935 | bool is_static = false; |
| 4936 | bool is_virtual = false; |
Greg Clayton | 30449d5 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 4937 | bool is_explicit = false; |
Sean Callanan | 2581dbf | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 4938 | bool is_artificial = false; |
Greg Clayton | 6c3e4af | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 4939 | dw_offset_t specification_die_offset = DW_INVALID_OFFSET; |
| 4940 | dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET; |
Greg Clayton | 1d8173f | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4941 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4942 | unsigned type_quals = 0; |
Sean Callanan | 47a5c4c | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 4943 | clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4944 | |
| 4945 | |
Greg Clayton | 5fcff9a | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4946 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4947 | if (num_attributes > 0) |
| 4948 | { |
| 4949 | uint32_t i; |
| 4950 | for (i=0; i<num_attributes; ++i) |
| 4951 | { |
Greg Clayton | bdcb6ab | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 4952 | attr = attributes.AttributeAtIndex(i); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4953 | DWARFFormValue form_value; |
| 4954 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 4955 | { |
| 4956 | switch (attr) |
| 4957 | { |
| 4958 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 4959 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 4960 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 4961 | case DW_AT_name: |
| 4962 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 4963 | type_name_const_str.SetCString(type_name_cstr); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4964 | break; |
| 4965 | |
| 4966 | case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break; |
| 4967 | case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break; |
Greg Clayton | 84f8075 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 4968 | case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
Greg Clayton | e5748d8 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 4969 | case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break; |
Greg Clayton | 1d8173f | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4970 | case DW_AT_inline: is_inline = form_value.Unsigned() != 0; break; |
| 4971 | case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break; |
Greg Clayton | 30449d5 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 4972 | case DW_AT_explicit: is_explicit = form_value.Unsigned() != 0; break; |
Sean Callanan | 2581dbf | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 4973 | case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break; |
| 4974 | |
Greg Clayton | 30449d5 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 4975 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4976 | case DW_AT_external: |
| 4977 | if (form_value.Unsigned()) |
| 4978 | { |
Sean Callanan | 47a5c4c | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 4979 | if (storage == clang::SC_None) |
| 4980 | storage = clang::SC_Extern; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4981 | else |
Sean Callanan | 47a5c4c | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 4982 | storage = clang::SC_PrivateExtern; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4983 | } |
| 4984 | break; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4985 | |
Greg Clayton | 6c3e4af | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 4986 | case DW_AT_specification: |
| 4987 | specification_die_offset = form_value.Reference(dwarf_cu); |
| 4988 | break; |
| 4989 | |
| 4990 | case DW_AT_abstract_origin: |
| 4991 | abstract_origin_die_offset = form_value.Reference(dwarf_cu); |
| 4992 | break; |
| 4993 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4994 | case DW_AT_allocated: |
| 4995 | case DW_AT_associated: |
| 4996 | case DW_AT_address_class: |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4997 | case DW_AT_calling_convention: |
| 4998 | case DW_AT_data_location: |
| 4999 | case DW_AT_elemental: |
| 5000 | case DW_AT_entry_pc: |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5001 | case DW_AT_frame_base: |
| 5002 | case DW_AT_high_pc: |
| 5003 | case DW_AT_low_pc: |
| 5004 | case DW_AT_object_pointer: |
| 5005 | case DW_AT_prototyped: |
| 5006 | case DW_AT_pure: |
| 5007 | case DW_AT_ranges: |
| 5008 | case DW_AT_recursive: |
| 5009 | case DW_AT_return_addr: |
| 5010 | case DW_AT_segment: |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5011 | case DW_AT_start_scope: |
| 5012 | case DW_AT_static_link: |
| 5013 | case DW_AT_trampoline: |
| 5014 | case DW_AT_visibility: |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5015 | case DW_AT_vtable_elem_location: |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5016 | case DW_AT_description: |
| 5017 | case DW_AT_sibling: |
| 5018 | break; |
| 5019 | } |
| 5020 | } |
| 5021 | } |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5022 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5023 | |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5024 | DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr); |
Greg Clayton | b433a3d | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 5025 | |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5026 | clang_type_t return_clang_type = NULL; |
| 5027 | Type *func_type = NULL; |
| 5028 | |
| 5029 | if (type_die_offset != DW_INVALID_OFFSET) |
| 5030 | func_type = ResolveTypeUID(type_die_offset); |
Greg Clayton | 30449d5 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 5031 | |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5032 | if (func_type) |
Greg Clayton | bcb0adc | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 5033 | return_clang_type = func_type->GetClangForwardType(); |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5034 | else |
Greg Clayton | e98ac25 | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5035 | return_clang_type = ast.GetBuiltInType_void(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5036 | |
Greg Clayton | 30449d5 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 5037 | |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5038 | std::vector<clang_type_t> function_param_types; |
| 5039 | std::vector<clang::ParmVarDecl*> function_param_decls; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5040 | |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5041 | // Parse the function children for the parameters |
Sean Callanan | 9930990 | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 5042 | |
Greg Clayton | 03fd0d0 | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 5043 | const DWARFDebugInfoEntry *decl_ctx_die = NULL; |
| 5044 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die); |
Greg Clayton | c5dca6c | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 5045 | const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind(); |
| 5046 | |
Greg Clayton | f6a5bd7 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5047 | const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind); |
Greg Clayton | c5dca6c | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 5048 | // Start off static. This will be set to false in ParseChildParameters(...) |
| 5049 | // if we find a "this" paramters as the first parameter |
| 5050 | if (is_cxx_method) |
Sean Callanan | 9930990 | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 5051 | is_static = true; |
| 5052 | |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5053 | if (die->HasChildren()) |
| 5054 | { |
Greg Clayton | 1d8173f | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5055 | bool skip_artificial = true; |
Greg Clayton | e98ac25 | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5056 | ParseChildParameters (sc, |
Greg Clayton | c5dca6c | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 5057 | containing_decl_ctx, |
Greg Clayton | e98ac25 | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5058 | dwarf_cu, |
| 5059 | die, |
Sean Callanan | 9930990 | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 5060 | skip_artificial, |
| 5061 | is_static, |
Greg Clayton | e98ac25 | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5062 | type_list, |
| 5063 | function_param_types, |
Greg Clayton | 2403b5e | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 5064 | function_param_decls, |
| 5065 | type_quals); |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5066 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5067 | |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5068 | // clang_type will get the function prototype clang type after this call |
Greg Clayton | e98ac25 | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5069 | clang_type = ast.CreateFunctionType (return_clang_type, |
| 5070 | &function_param_types[0], |
| 5071 | function_param_types.size(), |
| 5072 | is_variadic, |
| 5073 | type_quals); |
| 5074 | |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5075 | if (type_name_cstr) |
| 5076 | { |
Sean Callanan | 8f2e392 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5077 | if (die->GetOffset() == 0xaeaba) |
| 5078 | fprintf(stderr, "This is the one!"); |
| 5079 | |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5080 | bool type_handled = false; |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5081 | if (tag == DW_TAG_subprogram) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5082 | { |
Greg Clayton | 445c086 | 2012-01-18 23:40:49 +0000 | [diff] [blame] | 5083 | ConstString class_name; |
Greg Clayton | 662e567 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 5084 | ConstString class_name_no_category; |
| 5085 | if (ObjCLanguageRuntime::ParseMethodName (type_name_cstr, &class_name, NULL, NULL, &class_name_no_category)) |
Greg Clayton | 1d8173f | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5086 | { |
Greg Clayton | 662e567 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 5087 | // Use the class name with no category if there is one |
| 5088 | if (class_name_no_category) |
| 5089 | class_name = class_name_no_category; |
| 5090 | |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5091 | SymbolContext empty_sc; |
| 5092 | clang_type_t class_opaque_type = NULL; |
Greg Clayton | 445c086 | 2012-01-18 23:40:49 +0000 | [diff] [blame] | 5093 | if (class_name) |
Greg Clayton | 1d8173f | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5094 | { |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5095 | TypeList types; |
Greg Clayton | e14d3d3 | 2012-01-19 00:52:59 +0000 | [diff] [blame] | 5096 | TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false)); |
Greg Clayton | e6b976d | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5097 | |
| 5098 | if (complete_objc_class_type_sp) |
Greg Clayton | 1d8173f | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5099 | { |
Greg Clayton | e6b976d | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5100 | clang_type_t type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType(); |
| 5101 | if (ClangASTContext::IsObjCClassType (type_clang_forward_type)) |
| 5102 | class_opaque_type = type_clang_forward_type; |
Greg Clayton | 1d8173f | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5103 | } |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5104 | } |
Greg Clayton | 1d8173f | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5105 | |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5106 | if (class_opaque_type) |
| 5107 | { |
| 5108 | // If accessibility isn't set to anything valid, assume public for |
| 5109 | // now... |
| 5110 | if (accessibility == eAccessNone) |
| 5111 | accessibility = eAccessPublic; |
| 5112 | |
| 5113 | clang::ObjCMethodDecl *objc_method_decl; |
Greg Clayton | e98ac25 | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5114 | objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type, |
| 5115 | type_name_cstr, |
| 5116 | clang_type, |
| 5117 | accessibility); |
Greg Clayton | a83f877 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 5118 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die); |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5119 | type_handled = objc_method_decl != NULL; |
| 5120 | } |
| 5121 | } |
Greg Clayton | c5dca6c | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 5122 | else if (is_cxx_method) |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5123 | { |
| 5124 | // Look at the parent of this DIE and see if is is |
| 5125 | // a class or struct and see if this is actually a |
| 5126 | // C++ method |
Greg Clayton | 03fd0d0 | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 5127 | Type *class_type = ResolveType (dwarf_cu, decl_ctx_die); |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5128 | if (class_type) |
| 5129 | { |
Greg Clayton | 6c3e4af | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5130 | if (specification_die_offset != DW_INVALID_OFFSET) |
Greg Clayton | 1d8173f | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5131 | { |
Greg Clayton | b523031 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 5132 | // We have a specification which we are going to base our function |
| 5133 | // prototype off of, so we need this type to be completed so that the |
| 5134 | // m_die_to_decl_ctx for the method in the specification has a valid |
| 5135 | // clang decl context. |
Greg Clayton | e367aa8 | 2011-12-13 04:34:06 +0000 | [diff] [blame] | 5136 | class_type->GetClangForwardType(); |
Greg Clayton | 6c3e4af | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5137 | // If we have a specification, then the function type should have been |
| 5138 | // made with the specification and not with this die. |
| 5139 | DWARFCompileUnitSP spec_cu_sp; |
| 5140 | const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp); |
Greg Clayton | b523031 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 5141 | clang::DeclContext *spec_clang_decl_ctx = GetCachedClangDeclContextForDIE (spec_die); |
| 5142 | if (spec_clang_decl_ctx) |
| 5143 | { |
| 5144 | LinkDeclContextToDIE(spec_clang_decl_ctx, die); |
| 5145 | } |
| 5146 | else |
Jim Ingham | 90b2079 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 5147 | { |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5148 | GetObjectFile()->GetModule()->ReportWarning ("0x%8.8llx: DW_AT_specification(0x%8.8x) has no decl\n", |
| 5149 | MakeUserID(die->GetOffset()), |
| 5150 | specification_die_offset); |
Jim Ingham | 90b2079 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 5151 | } |
Greg Clayton | 6c3e4af | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5152 | type_handled = true; |
| 5153 | } |
| 5154 | else if (abstract_origin_die_offset != DW_INVALID_OFFSET) |
| 5155 | { |
Greg Clayton | b523031 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 5156 | // We have a specification which we are going to base our function |
| 5157 | // prototype off of, so we need this type to be completed so that the |
| 5158 | // m_die_to_decl_ctx for the method in the abstract origin has a valid |
| 5159 | // clang decl context. |
Greg Clayton | e367aa8 | 2011-12-13 04:34:06 +0000 | [diff] [blame] | 5160 | class_type->GetClangForwardType(); |
Greg Clayton | b523031 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 5161 | |
Greg Clayton | 6c3e4af | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5162 | DWARFCompileUnitSP abs_cu_sp; |
| 5163 | const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp); |
Greg Clayton | b523031 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 5164 | clang::DeclContext *abs_clang_decl_ctx = GetCachedClangDeclContextForDIE (abs_die); |
| 5165 | if (abs_clang_decl_ctx) |
| 5166 | { |
| 5167 | LinkDeclContextToDIE (abs_clang_decl_ctx, die); |
| 5168 | } |
| 5169 | else |
Jim Ingham | 90b2079 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 5170 | { |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5171 | GetObjectFile()->GetModule()->ReportWarning ("0x%8.8llx: DW_AT_abstract_origin(0x%8.8x) has no decl\n", |
| 5172 | MakeUserID(die->GetOffset()), |
| 5173 | abstract_origin_die_offset); |
Jim Ingham | 90b2079 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 5174 | } |
Greg Clayton | 6c3e4af | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5175 | type_handled = true; |
| 5176 | } |
| 5177 | else |
| 5178 | { |
| 5179 | clang_type_t class_opaque_type = class_type->GetClangForwardType(); |
| 5180 | if (ClangASTContext::IsCXXClassType (class_opaque_type)) |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 5181 | { |
Greg Clayton | 9f54ab7 | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 5182 | if (ClangASTContext::IsBeingDefined (class_opaque_type)) |
Greg Clayton | 6c3e4af | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5183 | { |
Greg Clayton | 9f54ab7 | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 5184 | // Neither GCC 4.2 nor clang++ currently set a valid accessibility |
| 5185 | // in the DWARF for C++ methods... Default to public for now... |
| 5186 | if (accessibility == eAccessNone) |
| 5187 | accessibility = eAccessPublic; |
| 5188 | |
| 5189 | if (!is_static && !die->HasChildren()) |
| 5190 | { |
| 5191 | // We have a C++ member function with no children (this pointer!) |
| 5192 | // and clang will get mad if we try and make a function that isn't |
| 5193 | // well formed in the DWARF, so we will just skip it... |
| 5194 | type_handled = true; |
| 5195 | } |
| 5196 | else |
| 5197 | { |
| 5198 | clang::CXXMethodDecl *cxx_method_decl; |
| 5199 | // REMOVE THE CRASH DESCRIPTION BELOW |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5200 | Host::SetCrashDescriptionWithFormat ("SymbolFileDWARF::ParseType() is adding a method %s to class %s in DIE 0x%8.8llx from %s/%s", |
Greg Clayton | 9f54ab7 | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 5201 | type_name_cstr, |
| 5202 | class_type->GetName().GetCString(), |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5203 | MakeUserID(die->GetOffset()), |
Greg Clayton | 9f54ab7 | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 5204 | m_obj_file->GetFileSpec().GetDirectory().GetCString(), |
| 5205 | m_obj_file->GetFileSpec().GetFilename().GetCString()); |
| 5206 | |
Sean Callanan | 716e3f0 | 2011-11-01 18:07:13 +0000 | [diff] [blame] | 5207 | const bool is_attr_used = false; |
| 5208 | |
Greg Clayton | 9f54ab7 | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 5209 | cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type, |
| 5210 | type_name_cstr, |
| 5211 | clang_type, |
| 5212 | accessibility, |
| 5213 | is_virtual, |
| 5214 | is_static, |
| 5215 | is_inline, |
Sean Callanan | 716e3f0 | 2011-11-01 18:07:13 +0000 | [diff] [blame] | 5216 | is_explicit, |
Sean Callanan | 2581dbf | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 5217 | is_attr_used, |
| 5218 | is_artificial); |
Greg Clayton | 9f54ab7 | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 5219 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die); |
| 5220 | |
Greg Clayton | 668a6c7 | 2011-11-10 18:31:53 +0000 | [diff] [blame] | 5221 | Host::SetCrashDescription (NULL); |
| 5222 | |
Greg Clayton | 9f54ab7 | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 5223 | type_handled = cxx_method_decl != NULL; |
| 5224 | } |
Greg Clayton | 6c3e4af | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5225 | } |
| 5226 | else |
| 5227 | { |
Greg Clayton | 9f54ab7 | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 5228 | // We were asked to parse the type for a method in a class, yet the |
| 5229 | // class hasn't been asked to complete itself through the |
| 5230 | // clang::ExternalASTSource protocol, so we need to just have the |
| 5231 | // class complete itself and do things the right way, then our |
| 5232 | // DIE should then have an entry in the m_die_to_type map. First |
| 5233 | // we need to modify the m_die_to_type so it doesn't think we are |
| 5234 | // trying to parse this DIE anymore... |
| 5235 | m_die_to_type[die] = NULL; |
| 5236 | |
| 5237 | // Now we get the full type to force our class type to complete itself |
| 5238 | // using the clang::ExternalASTSource protocol which will parse all |
| 5239 | // base classes and all methods (including the method for this DIE). |
| 5240 | class_type->GetClangFullType(); |
Greg Clayton | a83f877 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 5241 | |
Greg Clayton | 9f54ab7 | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 5242 | // The type for this DIE should have been filled in the function call above |
| 5243 | type_ptr = m_die_to_type[die]; |
| 5244 | if (type_ptr) |
| 5245 | { |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 5246 | type_sp = type_ptr->shared_from_this(); |
Greg Clayton | 9f54ab7 | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 5247 | break; |
| 5248 | } |
Greg Clayton | 6c3e4af | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5249 | } |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 5250 | } |
Greg Clayton | 1d8173f | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5251 | } |
| 5252 | } |
Greg Clayton | 1d8173f | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5253 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5254 | } |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5255 | |
| 5256 | if (!type_handled) |
| 5257 | { |
| 5258 | // We just have a function that isn't part of a class |
Greg Clayton | 5f24c50 | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 5259 | clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (containing_decl_ctx, |
| 5260 | type_name_cstr, |
Greg Clayton | e98ac25 | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5261 | clang_type, |
| 5262 | storage, |
| 5263 | is_inline); |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5264 | |
| 5265 | // Add the decl to our DIE to decl context map |
| 5266 | assert (function_decl); |
Greg Clayton | e6d72ca | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 5267 | LinkDeclContextToDIE(function_decl, die); |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5268 | if (!function_param_decls.empty()) |
Greg Clayton | e98ac25 | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5269 | ast.SetFunctionParameters (function_decl, |
| 5270 | &function_param_decls.front(), |
| 5271 | function_param_decls.size()); |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5272 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5273 | } |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5274 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
Greg Clayton | e98ac25 | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5275 | this, |
| 5276 | type_name_const_str, |
| 5277 | 0, |
| 5278 | NULL, |
| 5279 | LLDB_INVALID_UID, |
| 5280 | Type::eEncodingIsUID, |
| 5281 | &decl, |
| 5282 | clang_type, |
Greg Clayton | a8d4241 | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5283 | Type::eResolveStateFull)); |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5284 | assert(type_sp.get()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5285 | } |
| 5286 | break; |
| 5287 | |
| 5288 | case DW_TAG_array_type: |
| 5289 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5290 | // Set a bit that lets us know that we are currently parsing this |
Greg Clayton | 4fb400f | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5291 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5292 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5293 | lldb::user_id_t type_die_offset = DW_INVALID_OFFSET; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5294 | int64_t first_index = 0; |
| 5295 | uint32_t byte_stride = 0; |
| 5296 | uint32_t bit_stride = 0; |
Greg Clayton | 5fcff9a | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5297 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5298 | |
| 5299 | if (num_attributes > 0) |
| 5300 | { |
| 5301 | uint32_t i; |
| 5302 | for (i=0; i<num_attributes; ++i) |
| 5303 | { |
| 5304 | attr = attributes.AttributeAtIndex(i); |
| 5305 | DWARFFormValue form_value; |
| 5306 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 5307 | { |
| 5308 | switch (attr) |
| 5309 | { |
| 5310 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 5311 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 5312 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 5313 | case DW_AT_name: |
| 5314 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
Greg Clayton | fb7c51c | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5315 | type_name_const_str.SetCString(type_name_cstr); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5316 | break; |
| 5317 | |
| 5318 | case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break; |
Greg Clayton | f1b73af | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 5319 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5320 | case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break; |
| 5321 | case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break; |
Greg Clayton | 84f8075 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 5322 | case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
Greg Clayton | e5748d8 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 5323 | case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5324 | case DW_AT_allocated: |
| 5325 | case DW_AT_associated: |
| 5326 | case DW_AT_data_location: |
| 5327 | case DW_AT_description: |
| 5328 | case DW_AT_ordering: |
| 5329 | case DW_AT_start_scope: |
| 5330 | case DW_AT_visibility: |
| 5331 | case DW_AT_specification: |
| 5332 | case DW_AT_abstract_origin: |
| 5333 | case DW_AT_sibling: |
| 5334 | break; |
| 5335 | } |
| 5336 | } |
| 5337 | } |
| 5338 | |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5339 | DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr); |
Greg Clayton | b433a3d | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 5340 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5341 | Type *element_type = ResolveTypeUID(type_die_offset); |
| 5342 | |
| 5343 | if (element_type) |
| 5344 | { |
| 5345 | std::vector<uint64_t> element_orders; |
| 5346 | ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride); |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 5347 | // We have an array that claims to have no members, lets give it at least one member... |
| 5348 | if (element_orders.empty()) |
| 5349 | element_orders.push_back (1); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5350 | if (byte_stride == 0 && bit_stride == 0) |
| 5351 | byte_stride = element_type->GetByteSize(); |
Greg Clayton | bcb0adc | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 5352 | clang_type_t array_element_type = element_type->GetClangForwardType(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5353 | uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride; |
| 5354 | uint64_t num_elements = 0; |
| 5355 | std::vector<uint64_t>::const_reverse_iterator pos; |
| 5356 | std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend(); |
| 5357 | for (pos = element_orders.rbegin(); pos != end; ++pos) |
| 5358 | { |
| 5359 | num_elements = *pos; |
Greg Clayton | e98ac25 | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5360 | clang_type = ast.CreateArrayType (array_element_type, |
| 5361 | num_elements, |
| 5362 | num_elements * array_element_bit_stride); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5363 | array_element_type = clang_type; |
| 5364 | array_element_bit_stride = array_element_bit_stride * num_elements; |
| 5365 | } |
| 5366 | ConstString empty_name; |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5367 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
Greg Clayton | e98ac25 | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5368 | this, |
| 5369 | empty_name, |
| 5370 | array_element_bit_stride / 8, |
| 5371 | NULL, |
Greg Clayton | 6916e35 | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5372 | type_die_offset, |
Greg Clayton | e98ac25 | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5373 | Type::eEncodingIsUID, |
| 5374 | &decl, |
| 5375 | clang_type, |
Greg Clayton | 6916e35 | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5376 | Type::eResolveStateFull)); |
| 5377 | type_sp->SetEncodingType (element_type); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5378 | } |
| 5379 | } |
| 5380 | } |
| 5381 | break; |
| 5382 | |
Greg Clayton | fa97069 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 5383 | case DW_TAG_ptr_to_member_type: |
| 5384 | { |
| 5385 | dw_offset_t type_die_offset = DW_INVALID_OFFSET; |
| 5386 | dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET; |
| 5387 | |
Greg Clayton | 5fcff9a | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5388 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
Greg Clayton | fa97069 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 5389 | |
| 5390 | if (num_attributes > 0) { |
| 5391 | uint32_t i; |
| 5392 | for (i=0; i<num_attributes; ++i) |
| 5393 | { |
| 5394 | attr = attributes.AttributeAtIndex(i); |
| 5395 | DWARFFormValue form_value; |
| 5396 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 5397 | { |
| 5398 | switch (attr) |
| 5399 | { |
| 5400 | case DW_AT_type: |
| 5401 | type_die_offset = form_value.Reference(dwarf_cu); break; |
| 5402 | case DW_AT_containing_type: |
| 5403 | containing_type_die_offset = form_value.Reference(dwarf_cu); break; |
| 5404 | } |
| 5405 | } |
| 5406 | } |
| 5407 | |
| 5408 | Type *pointee_type = ResolveTypeUID(type_die_offset); |
| 5409 | Type *class_type = ResolveTypeUID(containing_type_die_offset); |
| 5410 | |
Greg Clayton | 6916e35 | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5411 | clang_type_t pointee_clang_type = pointee_type->GetClangForwardType(); |
| 5412 | clang_type_t class_clang_type = class_type->GetClangLayoutType(); |
Greg Clayton | fa97069 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 5413 | |
Greg Clayton | e98ac25 | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5414 | clang_type = ast.CreateMemberPointerType(pointee_clang_type, |
| 5415 | class_clang_type); |
Greg Clayton | fa97069 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 5416 | |
Greg Clayton | 6916e35 | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5417 | byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(), |
| 5418 | clang_type) / 8; |
Greg Clayton | fa97069 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 5419 | |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5420 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
Greg Clayton | e98ac25 | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5421 | this, |
| 5422 | type_name_const_str, |
| 5423 | byte_size, |
| 5424 | NULL, |
| 5425 | LLDB_INVALID_UID, |
| 5426 | Type::eEncodingIsUID, |
| 5427 | NULL, |
| 5428 | clang_type, |
Greg Clayton | 6916e35 | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5429 | Type::eResolveStateForward)); |
Greg Clayton | fa97069 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 5430 | } |
| 5431 | |
| 5432 | break; |
| 5433 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5434 | default: |
Greg Clayton | fa97069 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 5435 | assert(false && "Unhandled type tag!"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5436 | break; |
| 5437 | } |
| 5438 | |
| 5439 | if (type_sp.get()) |
| 5440 | { |
| 5441 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); |
| 5442 | dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
| 5443 | |
| 5444 | SymbolContextScope * symbol_context_scope = NULL; |
| 5445 | if (sc_parent_tag == DW_TAG_compile_unit) |
| 5446 | { |
| 5447 | symbol_context_scope = sc.comp_unit; |
| 5448 | } |
| 5449 | else if (sc.function != NULL) |
| 5450 | { |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5451 | symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5452 | if (symbol_context_scope == NULL) |
| 5453 | symbol_context_scope = sc.function; |
| 5454 | } |
| 5455 | |
| 5456 | if (symbol_context_scope != NULL) |
| 5457 | { |
| 5458 | type_sp->SetSymbolContextScope(symbol_context_scope); |
| 5459 | } |
| 5460 | |
Greg Clayton | a8d4241 | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5461 | // We are ready to put this type into the uniqued list up at the module level |
| 5462 | type_list->Insert (type_sp); |
Greg Clayton | ad60bf4 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 5463 | |
Greg Clayton | a8d4241 | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5464 | m_die_to_type[die] = type_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5465 | } |
| 5466 | } |
Greg Clayton | 4fb400f | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5467 | else if (type_ptr != DIE_IS_BEING_PARSED) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5468 | { |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 5469 | type_sp = type_ptr->shared_from_this(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5470 | } |
| 5471 | } |
| 5472 | return type_sp; |
| 5473 | } |
| 5474 | |
| 5475 | size_t |
Greg Clayton | 462d414 | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5476 | SymbolFileDWARF::ParseTypes |
| 5477 | ( |
| 5478 | const SymbolContext& sc, |
| 5479 | DWARFCompileUnit* dwarf_cu, |
| 5480 | const DWARFDebugInfoEntry *die, |
| 5481 | bool parse_siblings, |
| 5482 | bool parse_children |
| 5483 | ) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5484 | { |
| 5485 | size_t types_added = 0; |
| 5486 | while (die != NULL) |
| 5487 | { |
| 5488 | bool type_is_new = false; |
Greg Clayton | 462d414 | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5489 | if (ParseType(sc, dwarf_cu, die, &type_is_new).get()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5490 | { |
| 5491 | if (type_is_new) |
| 5492 | ++types_added; |
| 5493 | } |
| 5494 | |
| 5495 | if (parse_children && die->HasChildren()) |
| 5496 | { |
| 5497 | if (die->Tag() == DW_TAG_subprogram) |
| 5498 | { |
| 5499 | SymbolContext child_sc(sc); |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5500 | child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5501 | types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true); |
| 5502 | } |
| 5503 | else |
| 5504 | types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true); |
| 5505 | } |
| 5506 | |
| 5507 | if (parse_siblings) |
| 5508 | die = die->GetSibling(); |
| 5509 | else |
| 5510 | die = NULL; |
| 5511 | } |
| 5512 | return types_added; |
| 5513 | } |
| 5514 | |
| 5515 | |
| 5516 | size_t |
| 5517 | SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc) |
| 5518 | { |
| 5519 | assert(sc.comp_unit && sc.function); |
| 5520 | size_t functions_added = 0; |
| 5521 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID()); |
| 5522 | if (dwarf_cu) |
| 5523 | { |
| 5524 | dw_offset_t function_die_offset = sc.function->GetID(); |
| 5525 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset); |
| 5526 | if (function_die) |
| 5527 | { |
Greg Clayton | 2e45b0c | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 5528 | ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5529 | } |
| 5530 | } |
| 5531 | |
| 5532 | return functions_added; |
| 5533 | } |
| 5534 | |
| 5535 | |
| 5536 | size_t |
| 5537 | SymbolFileDWARF::ParseTypes (const SymbolContext &sc) |
| 5538 | { |
| 5539 | // At least a compile unit must be valid |
| 5540 | assert(sc.comp_unit); |
| 5541 | size_t types_added = 0; |
| 5542 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID()); |
| 5543 | if (dwarf_cu) |
| 5544 | { |
| 5545 | if (sc.function) |
| 5546 | { |
| 5547 | dw_offset_t function_die_offset = sc.function->GetID(); |
| 5548 | const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset); |
| 5549 | if (func_die && func_die->HasChildren()) |
| 5550 | { |
| 5551 | types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true); |
| 5552 | } |
| 5553 | } |
| 5554 | else |
| 5555 | { |
| 5556 | const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE(); |
| 5557 | if (dwarf_cu_die && dwarf_cu_die->HasChildren()) |
| 5558 | { |
| 5559 | types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true); |
| 5560 | } |
| 5561 | } |
| 5562 | } |
| 5563 | |
| 5564 | return types_added; |
| 5565 | } |
| 5566 | |
| 5567 | size_t |
| 5568 | SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc) |
| 5569 | { |
| 5570 | if (sc.comp_unit != NULL) |
| 5571 | { |
Greg Clayton | 9bcf31e | 2010-11-01 20:32:12 +0000 | [diff] [blame] | 5572 | DWARFDebugInfo* info = DebugInfo(); |
| 5573 | if (info == NULL) |
| 5574 | return 0; |
| 5575 | |
| 5576 | uint32_t cu_idx = UINT32_MAX; |
| 5577 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID(), &cu_idx).get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5578 | |
| 5579 | if (dwarf_cu == NULL) |
| 5580 | return 0; |
| 5581 | |
| 5582 | if (sc.function) |
| 5583 | { |
| 5584 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID()); |
Greg Clayton | 178710c | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 5585 | |
| 5586 | dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, DW_INVALID_ADDRESS); |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5587 | if (func_lo_pc != DW_INVALID_ADDRESS) |
| 5588 | { |
| 5589 | const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true); |
Greg Clayton | 1bd2b2f | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 5590 | |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5591 | // Let all blocks know they have parse all their variables |
| 5592 | sc.function->GetBlock (false).SetDidParseVariables (true, true); |
| 5593 | return num_variables; |
| 5594 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5595 | } |
| 5596 | else if (sc.comp_unit) |
| 5597 | { |
| 5598 | uint32_t vars_added = 0; |
| 5599 | VariableListSP variables (sc.comp_unit->GetVariableList(false)); |
| 5600 | |
| 5601 | if (variables.get() == NULL) |
| 5602 | { |
| 5603 | variables.reset(new VariableList()); |
| 5604 | sc.comp_unit->SetVariableList(variables); |
| 5605 | |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 5606 | DWARFCompileUnit* match_dwarf_cu = NULL; |
| 5607 | const DWARFDebugInfoEntry* die = NULL; |
| 5608 | DIEArray die_offsets; |
Greg Clayton | bbe3916 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 5609 | if (m_using_apple_tables) |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5610 | { |
Greg Clayton | bbe3916 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 5611 | if (m_apple_names_ap.get()) |
Greg Clayton | 37bb8dd | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5612 | { |
| 5613 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 5614 | if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(), |
| 5615 | dwarf_cu->GetNextCompileUnitOffset(), |
| 5616 | hash_data_array)) |
| 5617 | { |
| 5618 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| 5619 | } |
| 5620 | } |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5621 | } |
| 5622 | else |
| 5623 | { |
| 5624 | // Index if we already haven't to make sure the compile units |
| 5625 | // get indexed and make their global DIE index list |
| 5626 | if (!m_indexed) |
| 5627 | Index (); |
| 5628 | |
| 5629 | m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(), |
| 5630 | dwarf_cu->GetNextCompileUnitOffset(), |
| 5631 | die_offsets); |
| 5632 | } |
| 5633 | |
| 5634 | const size_t num_matches = die_offsets.size(); |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 5635 | if (num_matches) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5636 | { |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 5637 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 5638 | for (size_t i=0; i<num_matches; ++i) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5639 | { |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 5640 | const dw_offset_t die_offset = die_offsets[i]; |
| 5641 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu); |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 5642 | if (die) |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 5643 | { |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 5644 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS)); |
| 5645 | if (var_sp) |
| 5646 | { |
| 5647 | variables->AddVariableIfUnique (var_sp); |
| 5648 | ++vars_added; |
| 5649 | } |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 5650 | } |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 5651 | else |
| 5652 | { |
| 5653 | if (m_using_apple_tables) |
| 5654 | { |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5655 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x)\n", die_offset); |
Greg Clayton | bc50070 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 5656 | } |
| 5657 | } |
| 5658 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5659 | } |
| 5660 | } |
| 5661 | } |
| 5662 | return vars_added; |
| 5663 | } |
| 5664 | } |
| 5665 | return 0; |
| 5666 | } |
| 5667 | |
| 5668 | |
| 5669 | VariableSP |
| 5670 | SymbolFileDWARF::ParseVariableDIE |
| 5671 | ( |
| 5672 | const SymbolContext& sc, |
Greg Clayton | 1d8173f | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5673 | DWARFCompileUnit* dwarf_cu, |
Greg Clayton | 178710c | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 5674 | const DWARFDebugInfoEntry *die, |
| 5675 | const lldb::addr_t func_low_pc |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5676 | ) |
| 5677 | { |
| 5678 | |
Greg Clayton | 3bc52d0 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 5679 | VariableSP var_sp (m_die_to_variable_sp[die]); |
| 5680 | if (var_sp) |
| 5681 | return var_sp; // Already been parsed! |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5682 | |
| 5683 | const dw_tag_t tag = die->Tag(); |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5684 | |
| 5685 | if ((tag == DW_TAG_variable) || |
| 5686 | (tag == DW_TAG_constant) || |
| 5687 | (tag == DW_TAG_formal_parameter && sc.function)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5688 | { |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5689 | DWARFDebugInfoEntry::Attributes attributes; |
| 5690 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| 5691 | if (num_attributes > 0) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5692 | { |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5693 | const char *name = NULL; |
| 5694 | const char *mangled = NULL; |
| 5695 | Declaration decl; |
| 5696 | uint32_t i; |
Greg Clayton | 37bb8dd | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5697 | lldb::user_id_t type_uid = LLDB_INVALID_UID; |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5698 | DWARFExpression location; |
| 5699 | bool is_external = false; |
| 5700 | bool is_artificial = false; |
| 5701 | bool location_is_const_value_data = false; |
| 5702 | AccessType accessibility = eAccessNone; |
| 5703 | |
| 5704 | for (i=0; i<num_attributes; ++i) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5705 | { |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5706 | dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 5707 | DWARFFormValue form_value; |
| 5708 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5709 | { |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5710 | switch (attr) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5711 | { |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5712 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 5713 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 5714 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 5715 | case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; |
| 5716 | case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break; |
Greg Clayton | 37bb8dd | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5717 | case DW_AT_type: type_uid = form_value.Reference(dwarf_cu); break; |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5718 | case DW_AT_external: is_external = form_value.Unsigned() != 0; break; |
| 5719 | case DW_AT_const_value: |
| 5720 | location_is_const_value_data = true; |
| 5721 | // Fall through... |
| 5722 | case DW_AT_location: |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5723 | { |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5724 | if (form_value.BlockData()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5725 | { |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5726 | const DataExtractor& debug_info_data = get_debug_info_data(); |
| 5727 | |
| 5728 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 5729 | uint32_t block_length = form_value.Unsigned(); |
| 5730 | location.SetOpcodeData(get_debug_info_data(), block_offset, block_length); |
| 5731 | } |
| 5732 | else |
| 5733 | { |
| 5734 | const DataExtractor& debug_loc_data = get_debug_loc_data(); |
| 5735 | const dw_offset_t debug_loc_offset = form_value.Unsigned(); |
| 5736 | |
| 5737 | size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset); |
| 5738 | if (loc_list_length > 0) |
| 5739 | { |
| 5740 | location.SetOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length); |
| 5741 | assert (func_low_pc != LLDB_INVALID_ADDRESS); |
| 5742 | location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress()); |
| 5743 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5744 | } |
| 5745 | } |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5746 | break; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5747 | |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5748 | case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break; |
| 5749 | case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
| 5750 | case DW_AT_declaration: |
| 5751 | case DW_AT_description: |
| 5752 | case DW_AT_endianity: |
| 5753 | case DW_AT_segment: |
| 5754 | case DW_AT_start_scope: |
| 5755 | case DW_AT_visibility: |
| 5756 | default: |
| 5757 | case DW_AT_abstract_origin: |
| 5758 | case DW_AT_sibling: |
| 5759 | case DW_AT_specification: |
| 5760 | break; |
| 5761 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5762 | } |
| 5763 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5764 | |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5765 | if (location.IsValid()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5766 | { |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5767 | ValueType scope = eValueTypeInvalid; |
| 5768 | |
| 5769 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); |
| 5770 | dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
Greg Clayton | a1b9a90 | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5771 | SymbolContextScope * symbol_context_scope = NULL; |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5772 | |
Greg Clayton | a1b9a90 | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5773 | // DWARF doesn't specify if a DW_TAG_variable is a local, global |
| 5774 | // or static variable, so we have to do a little digging by |
| 5775 | // looking at the location of a varaible to see if it contains |
| 5776 | // a DW_OP_addr opcode _somewhere_ in the definition. I say |
| 5777 | // somewhere because clang likes to combine small global variables |
| 5778 | // into the same symbol and have locations like: |
| 5779 | // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus |
| 5780 | // So if we don't have a DW_TAG_formal_parameter, we can look at |
| 5781 | // the location to see if it contains a DW_OP_addr opcode, and |
| 5782 | // then we can correctly classify our variables. |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5783 | if (tag == DW_TAG_formal_parameter) |
| 5784 | scope = eValueTypeVariableArgument; |
Greg Clayton | 37bb8dd | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5785 | else |
Greg Clayton | a1b9a90 | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5786 | { |
Greg Clayton | 2f28ece | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 5787 | bool op_error = false; |
Greg Clayton | 37bb8dd | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5788 | // Check if the location has a DW_OP_addr with any address value... |
| 5789 | addr_t location_has_op_addr = false; |
| 5790 | if (!location_is_const_value_data) |
Greg Clayton | 2f28ece | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 5791 | { |
| 5792 | location_has_op_addr = location.LocationContains_DW_OP_addr (LLDB_INVALID_ADDRESS, op_error); |
| 5793 | if (op_error) |
| 5794 | { |
| 5795 | StreamString strm; |
| 5796 | location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL); |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5797 | GetObjectFile()->GetModule()->ReportError ("0x%8.8x: %s has an invalid location: %s", die->GetOffset(), DW_TAG_value_to_name(die->Tag()), strm.GetString().c_str()); |
Greg Clayton | 2f28ece | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 5798 | } |
| 5799 | } |
Greg Clayton | 37bb8dd | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5800 | |
| 5801 | if (location_has_op_addr) |
Greg Clayton | a1b9a90 | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5802 | { |
Greg Clayton | 37bb8dd | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5803 | if (is_external) |
Greg Clayton | a1b9a90 | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5804 | { |
Greg Clayton | 37bb8dd | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5805 | scope = eValueTypeVariableGlobal; |
| 5806 | |
| 5807 | if (m_debug_map_symfile) |
Greg Clayton | a1b9a90 | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5808 | { |
Greg Clayton | 37bb8dd | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5809 | // When leaving the DWARF in the .o files on darwin, |
| 5810 | // when we have a global variable that wasn't initialized, |
| 5811 | // the .o file might not have allocated a virtual |
| 5812 | // address for the global variable. In this case it will |
| 5813 | // have created a symbol for the global variable |
| 5814 | // that is undefined and external and the value will |
| 5815 | // be the byte size of the variable. When we do the |
| 5816 | // address map in SymbolFileDWARFDebugMap we rely on |
| 5817 | // having an address, we need to do some magic here |
| 5818 | // so we can get the correct address for our global |
| 5819 | // variable. The address for all of these entries |
| 5820 | // will be zero, and there will be an undefined symbol |
| 5821 | // in this object file, and the executable will have |
| 5822 | // a matching symbol with a good address. So here we |
| 5823 | // dig up the correct address and replace it in the |
| 5824 | // location for the variable, and set the variable's |
| 5825 | // symbol context scope to be that of the main executable |
| 5826 | // so the file address will resolve correctly. |
Greg Clayton | 2f28ece | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 5827 | if (location.LocationContains_DW_OP_addr (0, op_error)) |
Greg Clayton | a1b9a90 | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5828 | { |
Greg Clayton | a1b9a90 | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5829 | |
Greg Clayton | 37bb8dd | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5830 | // we have a possible uninitialized extern global |
| 5831 | Symtab *symtab = m_obj_file->GetSymtab(); |
| 5832 | if (symtab) |
Greg Clayton | a1b9a90 | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5833 | { |
Greg Clayton | 37bb8dd | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5834 | ConstString const_name(name); |
| 5835 | Symbol *undefined_symbol = symtab->FindFirstSymbolWithNameAndType (const_name, |
| 5836 | eSymbolTypeUndefined, |
| 5837 | Symtab::eDebugNo, |
| 5838 | Symtab::eVisibilityExtern); |
| 5839 | |
| 5840 | if (undefined_symbol) |
Greg Clayton | a1b9a90 | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5841 | { |
Greg Clayton | 37bb8dd | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5842 | ObjectFile *debug_map_objfile = m_debug_map_symfile->GetObjectFile(); |
| 5843 | if (debug_map_objfile) |
Greg Clayton | a1b9a90 | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5844 | { |
Greg Clayton | 37bb8dd | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5845 | Symtab *debug_map_symtab = debug_map_objfile->GetSymtab(); |
| 5846 | Symbol *defined_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name, |
| 5847 | eSymbolTypeData, |
| 5848 | Symtab::eDebugYes, |
| 5849 | Symtab::eVisibilityExtern); |
| 5850 | if (defined_symbol) |
Greg Clayton | a1b9a90 | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5851 | { |
Greg Clayton | 37bb8dd | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5852 | const AddressRange *defined_range = defined_symbol->GetAddressRangePtr(); |
| 5853 | if (defined_range) |
Greg Clayton | a1b9a90 | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5854 | { |
Greg Clayton | 37bb8dd | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5855 | const addr_t defined_addr = defined_range->GetBaseAddress().GetFileAddress(); |
| 5856 | if (defined_addr != LLDB_INVALID_ADDRESS) |
Greg Clayton | a1b9a90 | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5857 | { |
Greg Clayton | 37bb8dd | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5858 | if (location.Update_DW_OP_addr (defined_addr)) |
| 5859 | { |
| 5860 | symbol_context_scope = defined_symbol; |
| 5861 | } |
Greg Clayton | a1b9a90 | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5862 | } |
| 5863 | } |
| 5864 | } |
| 5865 | } |
| 5866 | } |
| 5867 | } |
| 5868 | } |
| 5869 | } |
| 5870 | } |
Greg Clayton | 37bb8dd | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5871 | else |
| 5872 | { |
| 5873 | scope = eValueTypeVariableStatic; |
| 5874 | } |
Greg Clayton | a1b9a90 | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5875 | } |
| 5876 | else |
Greg Clayton | 37bb8dd | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5877 | { |
| 5878 | scope = eValueTypeVariableLocal; |
| 5879 | } |
Greg Clayton | a1b9a90 | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5880 | } |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5881 | |
Greg Clayton | a1b9a90 | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5882 | if (symbol_context_scope == NULL) |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5883 | { |
Greg Clayton | a1b9a90 | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5884 | switch (parent_tag) |
Greg Clayton | b523031 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 5885 | { |
Greg Clayton | a1b9a90 | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5886 | case DW_TAG_subprogram: |
| 5887 | case DW_TAG_inlined_subroutine: |
| 5888 | case DW_TAG_lexical_block: |
| 5889 | if (sc.function) |
| 5890 | { |
| 5891 | symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); |
| 5892 | if (symbol_context_scope == NULL) |
| 5893 | symbol_context_scope = sc.function; |
| 5894 | } |
| 5895 | break; |
| 5896 | |
| 5897 | default: |
| 5898 | symbol_context_scope = sc.comp_unit; |
| 5899 | break; |
Greg Clayton | b523031 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 5900 | } |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5901 | } |
| 5902 | |
Greg Clayton | b523031 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 5903 | if (symbol_context_scope) |
| 5904 | { |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5905 | var_sp.reset (new Variable (MakeUserID(die->GetOffset()), |
| 5906 | name, |
| 5907 | mangled, |
Greg Clayton | 37bb8dd | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5908 | SymbolFileTypeSP (new SymbolFileType(*this, type_uid)), |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5909 | scope, |
| 5910 | symbol_context_scope, |
| 5911 | &decl, |
| 5912 | location, |
| 5913 | is_external, |
| 5914 | is_artificial)); |
Greg Clayton | b523031 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 5915 | |
| 5916 | var_sp->SetLocationIsConstantValueData (location_is_const_value_data); |
| 5917 | } |
| 5918 | else |
| 5919 | { |
| 5920 | // Not ready to parse this variable yet. It might be a global |
| 5921 | // or static variable that is in a function scope and the function |
| 5922 | // in the symbol context wasn't filled in yet |
| 5923 | return var_sp; |
| 5924 | } |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5925 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5926 | } |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5927 | // Cache var_sp even if NULL (the variable was just a specification or |
| 5928 | // was missing vital information to be able to be displayed in the debugger |
| 5929 | // (missing location due to optimization, etc)) so we don't re-parse |
| 5930 | // this DIE over and over later... |
| 5931 | m_die_to_variable_sp[die] = var_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5932 | } |
| 5933 | return var_sp; |
| 5934 | } |
| 5935 | |
Greg Clayton | 1bd2b2f | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 5936 | |
| 5937 | const DWARFDebugInfoEntry * |
| 5938 | SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset, |
| 5939 | dw_offset_t spec_block_die_offset, |
| 5940 | DWARFCompileUnit **result_die_cu_handle) |
| 5941 | { |
| 5942 | // Give the concrete function die specified by "func_die_offset", find the |
| 5943 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points |
| 5944 | // to "spec_block_die_offset" |
| 5945 | DWARFDebugInfo* info = DebugInfo(); |
| 5946 | |
| 5947 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle); |
| 5948 | if (die) |
| 5949 | { |
| 5950 | assert (*result_die_cu_handle); |
| 5951 | return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle); |
| 5952 | } |
| 5953 | return NULL; |
| 5954 | } |
| 5955 | |
| 5956 | |
| 5957 | const DWARFDebugInfoEntry * |
| 5958 | SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu, |
| 5959 | const DWARFDebugInfoEntry *die, |
| 5960 | dw_offset_t spec_block_die_offset, |
| 5961 | DWARFCompileUnit **result_die_cu_handle) |
| 5962 | { |
| 5963 | if (die) |
| 5964 | { |
| 5965 | switch (die->Tag()) |
| 5966 | { |
| 5967 | case DW_TAG_subprogram: |
| 5968 | case DW_TAG_inlined_subroutine: |
| 5969 | case DW_TAG_lexical_block: |
| 5970 | { |
| 5971 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset) |
| 5972 | { |
| 5973 | *result_die_cu_handle = dwarf_cu; |
| 5974 | return die; |
| 5975 | } |
| 5976 | |
| 5977 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset) |
| 5978 | { |
| 5979 | *result_die_cu_handle = dwarf_cu; |
| 5980 | return die; |
| 5981 | } |
| 5982 | } |
| 5983 | break; |
| 5984 | } |
| 5985 | |
| 5986 | // Give the concrete function die specified by "func_die_offset", find the |
| 5987 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points |
| 5988 | // to "spec_block_die_offset" |
| 5989 | for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling()) |
| 5990 | { |
| 5991 | const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu, |
| 5992 | child_die, |
| 5993 | spec_block_die_offset, |
| 5994 | result_die_cu_handle); |
| 5995 | if (result_die) |
| 5996 | return result_die; |
| 5997 | } |
| 5998 | } |
| 5999 | |
| 6000 | *result_die_cu_handle = NULL; |
| 6001 | return NULL; |
| 6002 | } |
| 6003 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6004 | size_t |
| 6005 | SymbolFileDWARF::ParseVariables |
| 6006 | ( |
| 6007 | const SymbolContext& sc, |
Greg Clayton | 1d8173f | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6008 | DWARFCompileUnit* dwarf_cu, |
Greg Clayton | 178710c | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 6009 | const lldb::addr_t func_low_pc, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6010 | const DWARFDebugInfoEntry *orig_die, |
| 6011 | bool parse_siblings, |
| 6012 | bool parse_children, |
| 6013 | VariableList* cc_variable_list |
| 6014 | ) |
| 6015 | { |
| 6016 | if (orig_die == NULL) |
| 6017 | return 0; |
| 6018 | |
Greg Clayton | 1bd2b2f | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6019 | VariableListSP variable_list_sp; |
| 6020 | |
| 6021 | size_t vars_added = 0; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6022 | const DWARFDebugInfoEntry *die = orig_die; |
Greg Clayton | 1bd2b2f | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6023 | while (die != NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6024 | { |
Greg Clayton | 1bd2b2f | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6025 | dw_tag_t tag = die->Tag(); |
| 6026 | |
| 6027 | // Check to see if we have already parsed this variable or constant? |
| 6028 | if (m_die_to_variable_sp[die]) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6029 | { |
Greg Clayton | 1bd2b2f | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6030 | if (cc_variable_list) |
| 6031 | cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6032 | } |
| 6033 | else |
| 6034 | { |
Greg Clayton | 1bd2b2f | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6035 | // We haven't already parsed it, lets do that now. |
| 6036 | if ((tag == DW_TAG_variable) || |
| 6037 | (tag == DW_TAG_constant) || |
| 6038 | (tag == DW_TAG_formal_parameter && sc.function)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6039 | { |
Greg Clayton | 1bd2b2f | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6040 | if (variable_list_sp.get() == NULL) |
Greg Clayton | 63afdb0 | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 6041 | { |
Greg Clayton | 1bd2b2f | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6042 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die); |
| 6043 | dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
| 6044 | switch (parent_tag) |
| 6045 | { |
| 6046 | case DW_TAG_compile_unit: |
| 6047 | if (sc.comp_unit != NULL) |
| 6048 | { |
| 6049 | variable_list_sp = sc.comp_unit->GetVariableList(false); |
| 6050 | if (variable_list_sp.get() == NULL) |
| 6051 | { |
| 6052 | variable_list_sp.reset(new VariableList()); |
| 6053 | sc.comp_unit->SetVariableList(variable_list_sp); |
| 6054 | } |
| 6055 | } |
| 6056 | else |
| 6057 | { |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6058 | GetObjectFile()->GetModule()->ReportError ("parent 0x%8.8llx %s with no valid compile unit in symbol context for 0x%8.8llx %s.\n", |
| 6059 | MakeUserID(sc_parent_die->GetOffset()), |
| 6060 | DW_TAG_value_to_name (parent_tag), |
| 6061 | MakeUserID(orig_die->GetOffset()), |
| 6062 | DW_TAG_value_to_name (orig_die->Tag())); |
Greg Clayton | 1bd2b2f | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6063 | } |
| 6064 | break; |
| 6065 | |
| 6066 | case DW_TAG_subprogram: |
| 6067 | case DW_TAG_inlined_subroutine: |
| 6068 | case DW_TAG_lexical_block: |
| 6069 | if (sc.function != NULL) |
| 6070 | { |
| 6071 | // Check to see if we already have parsed the variables for the given scope |
| 6072 | |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6073 | Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); |
Greg Clayton | 1bd2b2f | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6074 | if (block == NULL) |
| 6075 | { |
| 6076 | // This must be a specification or abstract origin with |
| 6077 | // a concrete block couterpart in the current function. We need |
| 6078 | // to find the concrete block so we can correctly add the |
| 6079 | // variable to it |
| 6080 | DWARFCompileUnit *concrete_block_die_cu = dwarf_cu; |
| 6081 | const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(), |
| 6082 | sc_parent_die->GetOffset(), |
| 6083 | &concrete_block_die_cu); |
| 6084 | if (concrete_block_die) |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6085 | block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset())); |
Greg Clayton | 1bd2b2f | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6086 | } |
| 6087 | |
| 6088 | if (block != NULL) |
| 6089 | { |
| 6090 | const bool can_create = false; |
| 6091 | variable_list_sp = block->GetBlockVariableList (can_create); |
| 6092 | if (variable_list_sp.get() == NULL) |
| 6093 | { |
| 6094 | variable_list_sp.reset(new VariableList()); |
| 6095 | block->SetVariableList(variable_list_sp); |
| 6096 | } |
| 6097 | } |
| 6098 | } |
| 6099 | break; |
| 6100 | |
| 6101 | default: |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6102 | GetObjectFile()->GetModule()->ReportError ("didn't find appropriate parent DIE for variable list for 0x%8.8llx %s.\n", |
| 6103 | MakeUserID(orig_die->GetOffset()), |
| 6104 | DW_TAG_value_to_name (orig_die->Tag())); |
Greg Clayton | 1bd2b2f | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6105 | break; |
| 6106 | } |
Greg Clayton | 63afdb0 | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 6107 | } |
Greg Clayton | 1bd2b2f | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6108 | |
| 6109 | if (variable_list_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6110 | { |
Greg Clayton | 63afdb0 | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 6111 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc)); |
| 6112 | if (var_sp) |
| 6113 | { |
Greg Clayton | 1bd2b2f | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6114 | variable_list_sp->AddVariableIfUnique (var_sp); |
Greg Clayton | 63afdb0 | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 6115 | if (cc_variable_list) |
| 6116 | cc_variable_list->AddVariableIfUnique (var_sp); |
| 6117 | ++vars_added; |
| 6118 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6119 | } |
| 6120 | } |
| 6121 | } |
Greg Clayton | 1bd2b2f | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6122 | |
| 6123 | bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram); |
| 6124 | |
| 6125 | if (!skip_children && parse_children && die->HasChildren()) |
| 6126 | { |
| 6127 | vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list); |
| 6128 | } |
| 6129 | |
| 6130 | if (parse_siblings) |
| 6131 | die = die->GetSibling(); |
| 6132 | else |
| 6133 | die = NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6134 | } |
Greg Clayton | 1bd2b2f | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6135 | return vars_added; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6136 | } |
| 6137 | |
| 6138 | //------------------------------------------------------------------ |
| 6139 | // PluginInterface protocol |
| 6140 | //------------------------------------------------------------------ |
| 6141 | const char * |
| 6142 | SymbolFileDWARF::GetPluginName() |
| 6143 | { |
| 6144 | return "SymbolFileDWARF"; |
| 6145 | } |
| 6146 | |
| 6147 | const char * |
| 6148 | SymbolFileDWARF::GetShortPluginName() |
| 6149 | { |
| 6150 | return GetPluginNameStatic(); |
| 6151 | } |
| 6152 | |
| 6153 | uint32_t |
| 6154 | SymbolFileDWARF::GetPluginVersion() |
| 6155 | { |
| 6156 | return 1; |
| 6157 | } |
| 6158 | |
| 6159 | void |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 6160 | SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl) |
| 6161 | { |
| 6162 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 6163 | clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); |
| 6164 | if (clang_type) |
| 6165 | symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); |
| 6166 | } |
| 6167 | |
| 6168 | void |
| 6169 | SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl) |
| 6170 | { |
| 6171 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 6172 | clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); |
| 6173 | if (clang_type) |
| 6174 | symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); |
| 6175 | } |
| 6176 | |
Greg Clayton | e6d72ca | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6177 | void |
Sean Callanan | 9b6898f | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 6178 | SymbolFileDWARF::DumpIndexes () |
| 6179 | { |
| 6180 | StreamFile s(stdout, false); |
| 6181 | |
| 6182 | s.Printf ("DWARF index for (%s) '%s/%s':", |
| 6183 | GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(), |
| 6184 | GetObjectFile()->GetFileSpec().GetDirectory().AsCString(), |
| 6185 | GetObjectFile()->GetFileSpec().GetFilename().AsCString()); |
| 6186 | s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s); |
| 6187 | s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s); |
| 6188 | s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s); |
| 6189 | s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s); |
| 6190 | s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s); |
| 6191 | s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s); |
| 6192 | s.Printf("\nTypes:\n"); m_type_index.Dump (&s); |
| 6193 | s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s); |
| 6194 | } |
| 6195 | |
| 6196 | void |
| 6197 | SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context, |
| 6198 | const char *name, |
| 6199 | llvm::SmallVectorImpl <clang::NamedDecl *> *results) |
Greg Clayton | e6d72ca | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6200 | { |
Sean Callanan | 9b6898f | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 6201 | DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context); |
Greg Clayton | e6d72ca | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6202 | |
| 6203 | if (iter == m_decl_ctx_to_die.end()) |
| 6204 | return; |
| 6205 | |
Greg Clayton | 03fd0d0 | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6206 | for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos) |
Greg Clayton | e6d72ca | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6207 | { |
Greg Clayton | 03fd0d0 | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6208 | const DWARFDebugInfoEntry *context_die = *pos; |
| 6209 | |
| 6210 | if (!results) |
| 6211 | return; |
| 6212 | |
| 6213 | DWARFDebugInfo* info = DebugInfo(); |
| 6214 | |
| 6215 | DIEArray die_offsets; |
| 6216 | |
| 6217 | DWARFCompileUnit* dwarf_cu = NULL; |
| 6218 | const DWARFDebugInfoEntry* die = NULL; |
Greg Clayton | b5c023a | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 6219 | |
| 6220 | if (m_using_apple_tables) |
| 6221 | { |
| 6222 | if (m_apple_types_ap.get()) |
| 6223 | m_apple_types_ap->FindByName (name, die_offsets); |
| 6224 | } |
| 6225 | else |
| 6226 | { |
| 6227 | if (!m_indexed) |
| 6228 | Index (); |
| 6229 | |
| 6230 | m_type_index.Find (ConstString(name), die_offsets); |
| 6231 | } |
| 6232 | |
Greg Clayton | b5c023a | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 6233 | const size_t num_matches = die_offsets.size(); |
Greg Clayton | 03fd0d0 | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6234 | |
| 6235 | if (num_matches) |
Greg Clayton | e6d72ca | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6236 | { |
Greg Clayton | 03fd0d0 | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6237 | for (size_t i = 0; i < num_matches; ++i) |
| 6238 | { |
| 6239 | const dw_offset_t die_offset = die_offsets[i]; |
| 6240 | die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
Greg Clayton | 144188b | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 6241 | |
Greg Clayton | 03fd0d0 | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6242 | if (die->GetParent() != context_die) |
| 6243 | continue; |
| 6244 | |
| 6245 | Type *matching_type = ResolveType (dwarf_cu, die); |
| 6246 | |
Greg Clayton | bcb0adc | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 6247 | lldb::clang_type_t type = matching_type->GetClangForwardType(); |
Greg Clayton | 03fd0d0 | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6248 | clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type); |
| 6249 | |
| 6250 | if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr())) |
| 6251 | { |
| 6252 | clang::TagDecl *tag_decl = tag_type->getDecl(); |
| 6253 | results->push_back(tag_decl); |
| 6254 | } |
| 6255 | else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr())) |
| 6256 | { |
| 6257 | clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl(); |
| 6258 | results->push_back(typedef_decl); |
| 6259 | } |
Greg Clayton | e6d72ca | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6260 | } |
| 6261 | } |
| 6262 | } |
| 6263 | } |
| 6264 | |
| 6265 | void |
| 6266 | SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton, |
Greg Clayton | 4c8353b | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 6267 | const clang::DeclContext *decl_context, |
| 6268 | clang::DeclarationName decl_name, |
Greg Clayton | e6d72ca | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6269 | llvm::SmallVectorImpl <clang::NamedDecl *> *results) |
| 6270 | { |
Greg Clayton | 4c8353b | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 6271 | |
| 6272 | switch (decl_context->getDeclKind()) |
| 6273 | { |
| 6274 | case clang::Decl::Namespace: |
| 6275 | case clang::Decl::TranslationUnit: |
| 6276 | { |
| 6277 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 6278 | symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results); |
| 6279 | } |
| 6280 | break; |
| 6281 | default: |
| 6282 | break; |
| 6283 | } |
Greg Clayton | e6d72ca | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6284 | } |
Greg Clayton | 3fc0c4f | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 6285 | |
| 6286 | bool |
| 6287 | SymbolFileDWARF::LayoutRecordType (void *baton, |
| 6288 | const clang::RecordDecl *record_decl, |
| 6289 | uint64_t &size, |
| 6290 | uint64_t &alignment, |
| 6291 | llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, |
| 6292 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, |
| 6293 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) |
| 6294 | { |
| 6295 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 6296 | return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets); |
| 6297 | } |
| 6298 | |
| 6299 | |
| 6300 | bool |
| 6301 | SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl, |
| 6302 | uint64_t &bit_size, |
| 6303 | uint64_t &alignment, |
| 6304 | llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, |
| 6305 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, |
| 6306 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) |
| 6307 | { |
| 6308 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| 6309 | RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl); |
| 6310 | bool success = false; |
| 6311 | base_offsets.clear(); |
| 6312 | vbase_offsets.clear(); |
| 6313 | if (pos != m_record_decl_to_layout_map.end()) |
| 6314 | { |
| 6315 | bit_size = pos->second.bit_size; |
| 6316 | alignment = pos->second.alignment; |
| 6317 | field_offsets.swap(pos->second.field_offsets); |
| 6318 | m_record_decl_to_layout_map.erase(pos); |
| 6319 | success = true; |
| 6320 | } |
| 6321 | else |
| 6322 | { |
| 6323 | bit_size = 0; |
| 6324 | alignment = 0; |
| 6325 | field_offsets.clear(); |
| 6326 | } |
| 6327 | |
| 6328 | if (log) |
| 6329 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 6330 | "SymbolFileDWARF::LayoutRecordType (record_decl = %p, bit_size = %llu, alignment = %llu, field_offsets[%u],base_offsets[%u], vbase_offsets[%u]) success = %i", |
| 6331 | record_decl, |
| 6332 | bit_size, |
| 6333 | alignment, |
| 6334 | (uint32_t)field_offsets.size(), |
| 6335 | (uint32_t)base_offsets.size(), |
| 6336 | (uint32_t)vbase_offsets.size(), |
| 6337 | success); |
| 6338 | return success; |
| 6339 | } |
| 6340 | |
| 6341 | |
| 6342 | |