| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- SymbolFileDWARF.cpp ------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "SymbolFileDWARF.h" |
| 11 | |
| 12 | // Other libraries and framework includes |
| 13 | #include "clang/AST/ASTConsumer.h" |
| 14 | #include "clang/AST/ASTContext.h" |
| 15 | #include "clang/AST/Decl.h" |
| 16 | #include "clang/AST/DeclGroup.h" |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclObjC.h" |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclTemplate.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | #include "clang/Basic/Builtins.h" |
| 20 | #include "clang/Basic/IdentifierTable.h" |
| 21 | #include "clang/Basic/LangOptions.h" |
| 22 | #include "clang/Basic/SourceManager.h" |
| 23 | #include "clang/Basic/TargetInfo.h" |
| 24 | #include "clang/Basic/Specifiers.h" |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 25 | #include "clang/Sema/DeclSpec.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 26 | |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 27 | #include "llvm/Support/Casting.h" |
| 28 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | #include "lldb/Core/Module.h" |
| 30 | #include "lldb/Core/PluginManager.h" |
| 31 | #include "lldb/Core/RegularExpression.h" |
| 32 | #include "lldb/Core/Scalar.h" |
| 33 | #include "lldb/Core/Section.h" |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 34 | #include "lldb/Core/StreamFile.h" |
| Jim Ingham | 318c9f2 | 2011-08-26 19:44:13 +0000 | [diff] [blame] | 35 | #include "lldb/Core/StreamString.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 36 | #include "lldb/Core/Timer.h" |
| 37 | #include "lldb/Core/Value.h" |
| 38 | |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 39 | #include "lldb/Host/Host.h" |
| 40 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 41 | #include "lldb/Symbol/Block.h" |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 42 | #include "lldb/Symbol/ClangExternalASTSourceCallbacks.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | #include "lldb/Symbol/CompileUnit.h" |
| 44 | #include "lldb/Symbol/LineTable.h" |
| 45 | #include "lldb/Symbol/ObjectFile.h" |
| 46 | #include "lldb/Symbol/SymbolVendor.h" |
| 47 | #include "lldb/Symbol/VariableList.h" |
| 48 | |
| Jim Ingham | b7f6b2f | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 49 | #include "lldb/Target/ObjCLanguageRuntime.h" |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 50 | #include "lldb/Target/CPPLanguageRuntime.h" |
| Jim Ingham | b7f6b2f | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 51 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 52 | #include "DWARFCompileUnit.h" |
| 53 | #include "DWARFDebugAbbrev.h" |
| 54 | #include "DWARFDebugAranges.h" |
| 55 | #include "DWARFDebugInfo.h" |
| 56 | #include "DWARFDebugInfoEntry.h" |
| 57 | #include "DWARFDebugLine.h" |
| 58 | #include "DWARFDebugPubnames.h" |
| 59 | #include "DWARFDebugRanges.h" |
| 60 | #include "DWARFDIECollection.h" |
| 61 | #include "DWARFFormValue.h" |
| 62 | #include "DWARFLocationList.h" |
| 63 | #include "LogChannelDWARF.h" |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 64 | #include "SymbolFileDWARFDebugMap.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 65 | |
| 66 | #include <map> |
| 67 | |
| Greg Clayton | 62742b1 | 2010-11-11 01:09:45 +0000 | [diff] [blame] | 68 | //#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 69 | |
| 70 | #ifdef ENABLE_DEBUG_PRINTF |
| 71 | #include <stdio.h> |
| 72 | #define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__) |
| 73 | #else |
| 74 | #define DEBUG_PRINTF(fmt, ...) |
| 75 | #endif |
| 76 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 77 | #define DIE_IS_BEING_PARSED ((lldb_private::Type*)1) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 78 | |
| 79 | using namespace lldb; |
| 80 | using namespace lldb_private; |
| 81 | |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 82 | static inline bool |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 83 | child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag) |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 84 | { |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 85 | switch (tag) |
| 86 | { |
| 87 | default: |
| 88 | break; |
| 89 | case DW_TAG_subprogram: |
| 90 | case DW_TAG_inlined_subroutine: |
| 91 | case DW_TAG_class_type: |
| 92 | case DW_TAG_structure_type: |
| 93 | case DW_TAG_union_type: |
| 94 | return true; |
| 95 | } |
| 96 | return false; |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 97 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 98 | |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 99 | static AccessType |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 100 | DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 101 | { |
| 102 | switch (dwarf_accessibility) |
| 103 | { |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 104 | case DW_ACCESS_public: return eAccessPublic; |
| 105 | case DW_ACCESS_private: return eAccessPrivate; |
| 106 | case DW_ACCESS_protected: return eAccessProtected; |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 107 | default: break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 108 | } |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 109 | return eAccessNone; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 112 | #if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE) |
| 113 | |
| 114 | class DIEStack |
| 115 | { |
| 116 | public: |
| 117 | |
| 118 | void Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) |
| 119 | { |
| 120 | m_dies.push_back (DIEInfo(cu, die)); |
| 121 | } |
| 122 | |
| 123 | |
| 124 | void LogDIEs (Log *log, SymbolFileDWARF *dwarf) |
| 125 | { |
| 126 | StreamString log_strm; |
| 127 | const size_t n = m_dies.size(); |
| 128 | log_strm.Printf("DIEStack[%zu]:\n", n); |
| 129 | for (size_t i=0; i<n; i++) |
| 130 | { |
| 131 | DWARFCompileUnit *cu = m_dies[i].cu; |
| 132 | const DWARFDebugInfoEntry *die = m_dies[i].die; |
| 133 | std::string qualified_name; |
| 134 | die->GetQualifiedName(dwarf, cu, qualified_name); |
| 135 | log_strm.Printf ("[%zu] 0x%8.8x: %s name='%s'\n", |
| 136 | i, |
| 137 | die->GetOffset(), |
| 138 | DW_TAG_value_to_name(die->Tag()), |
| 139 | qualified_name.c_str()); |
| 140 | } |
| 141 | log->PutCString(log_strm.GetData()); |
| 142 | } |
| 143 | void Pop () |
| 144 | { |
| 145 | m_dies.pop_back(); |
| 146 | } |
| 147 | |
| 148 | class ScopedPopper |
| 149 | { |
| 150 | public: |
| 151 | ScopedPopper (DIEStack &die_stack) : |
| 152 | m_die_stack (die_stack), |
| 153 | m_valid (false) |
| 154 | { |
| 155 | } |
| 156 | |
| 157 | void |
| 158 | Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) |
| 159 | { |
| 160 | m_valid = true; |
| 161 | m_die_stack.Push (cu, die); |
| 162 | } |
| 163 | |
| 164 | ~ScopedPopper () |
| 165 | { |
| 166 | if (m_valid) |
| 167 | m_die_stack.Pop(); |
| 168 | } |
| 169 | |
| 170 | |
| 171 | |
| 172 | protected: |
| 173 | DIEStack &m_die_stack; |
| 174 | bool m_valid; |
| 175 | }; |
| 176 | |
| 177 | protected: |
| 178 | struct DIEInfo { |
| 179 | DIEInfo (DWARFCompileUnit *c, const DWARFDebugInfoEntry *d) : |
| 180 | cu(c), |
| 181 | die(d) |
| 182 | { |
| 183 | } |
| 184 | DWARFCompileUnit *cu; |
| 185 | const DWARFDebugInfoEntry *die; |
| 186 | }; |
| 187 | typedef std::vector<DIEInfo> Stack; |
| 188 | Stack m_dies; |
| 189 | }; |
| 190 | #endif |
| 191 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 192 | void |
| 193 | SymbolFileDWARF::Initialize() |
| 194 | { |
| 195 | LogChannelDWARF::Initialize(); |
| 196 | PluginManager::RegisterPlugin (GetPluginNameStatic(), |
| 197 | GetPluginDescriptionStatic(), |
| 198 | CreateInstance); |
| 199 | } |
| 200 | |
| 201 | void |
| 202 | SymbolFileDWARF::Terminate() |
| 203 | { |
| 204 | PluginManager::UnregisterPlugin (CreateInstance); |
| 205 | LogChannelDWARF::Initialize(); |
| 206 | } |
| 207 | |
| 208 | |
| 209 | const char * |
| 210 | SymbolFileDWARF::GetPluginNameStatic() |
| 211 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 212 | return "dwarf"; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | const char * |
| 216 | SymbolFileDWARF::GetPluginDescriptionStatic() |
| 217 | { |
| 218 | return "DWARF and DWARF3 debug symbol file reader."; |
| 219 | } |
| 220 | |
| 221 | |
| 222 | SymbolFile* |
| 223 | SymbolFileDWARF::CreateInstance (ObjectFile* obj_file) |
| 224 | { |
| 225 | return new SymbolFileDWARF(obj_file); |
| 226 | } |
| 227 | |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 228 | TypeList * |
| 229 | SymbolFileDWARF::GetTypeList () |
| 230 | { |
| 231 | if (m_debug_map_symfile) |
| 232 | return m_debug_map_symfile->GetTypeList(); |
| 233 | return m_obj_file->GetModule()->GetTypeList(); |
| 234 | |
| 235 | } |
| 236 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 237 | //---------------------------------------------------------------------- |
| 238 | // Gets the first parent that is a lexical block, function or inlined |
| 239 | // subroutine, or compile unit. |
| 240 | //---------------------------------------------------------------------- |
| 241 | static const DWARFDebugInfoEntry * |
| 242 | GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die) |
| 243 | { |
| 244 | const DWARFDebugInfoEntry *die; |
| 245 | for (die = child_die->GetParent(); die != NULL; die = die->GetParent()) |
| 246 | { |
| 247 | dw_tag_t tag = die->Tag(); |
| 248 | |
| 249 | switch (tag) |
| 250 | { |
| 251 | case DW_TAG_compile_unit: |
| 252 | case DW_TAG_subprogram: |
| 253 | case DW_TAG_inlined_subroutine: |
| 254 | case DW_TAG_lexical_block: |
| 255 | return die; |
| 256 | } |
| 257 | } |
| 258 | return NULL; |
| 259 | } |
| 260 | |
| 261 | |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 262 | SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) : |
| 263 | SymbolFile (objfile), |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 264 | UserID (0), // Used by SymbolFileDWARFDebugMap to when this class parses .o files to contain the .o file index/ID |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 265 | m_debug_map_symfile (NULL), |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 266 | m_clang_tu_decl (NULL), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 267 | m_flags(), |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 268 | m_data_debug_abbrev (), |
| 269 | m_data_debug_aranges (), |
| 270 | m_data_debug_frame (), |
| 271 | m_data_debug_info (), |
| 272 | m_data_debug_line (), |
| 273 | m_data_debug_loc (), |
| 274 | m_data_debug_ranges (), |
| 275 | m_data_debug_str (), |
| Greg Clayton | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 276 | m_data_apple_names (), |
| 277 | m_data_apple_types (), |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 278 | m_data_apple_namespaces (), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 279 | m_abbr(), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 280 | m_info(), |
| 281 | m_line(), |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 282 | m_apple_names_ap (), |
| 283 | m_apple_types_ap (), |
| 284 | m_apple_namespaces_ap (), |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 285 | m_apple_objc_ap (), |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 286 | m_function_basename_index(), |
| 287 | m_function_fullname_index(), |
| 288 | m_function_method_index(), |
| 289 | m_function_selector_index(), |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 290 | m_objc_class_selectors_index(), |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 291 | m_global_index(), |
| Greg Clayton | 69b0488 | 2010-10-15 02:03:22 +0000 | [diff] [blame] | 292 | m_type_index(), |
| 293 | m_namespace_index(), |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 294 | m_indexed (false), |
| 295 | m_is_external_ast_source (false), |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 296 | m_using_apple_tables (false), |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 297 | m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate), |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 298 | m_ranges(), |
| 299 | m_unique_ast_type_map () |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 300 | { |
| 301 | } |
| 302 | |
| 303 | SymbolFileDWARF::~SymbolFileDWARF() |
| 304 | { |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 305 | if (m_is_external_ast_source) |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 306 | { |
| 307 | ModuleSP module_sp (m_obj_file->GetModule()); |
| 308 | if (module_sp) |
| 309 | module_sp->GetClangASTContext().RemoveExternalSource (); |
| 310 | } |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | static const ConstString & |
| 314 | GetDWARFMachOSegmentName () |
| 315 | { |
| 316 | static ConstString g_dwarf_section_name ("__DWARF"); |
| 317 | return g_dwarf_section_name; |
| 318 | } |
| 319 | |
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 320 | UniqueDWARFASTTypeMap & |
| 321 | SymbolFileDWARF::GetUniqueDWARFASTTypeMap () |
| 322 | { |
| 323 | if (m_debug_map_symfile) |
| 324 | return m_debug_map_symfile->GetUniqueDWARFASTTypeMap (); |
| 325 | return m_unique_ast_type_map; |
| 326 | } |
| 327 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 328 | ClangASTContext & |
| 329 | SymbolFileDWARF::GetClangASTContext () |
| 330 | { |
| 331 | if (m_debug_map_symfile) |
| 332 | return m_debug_map_symfile->GetClangASTContext (); |
| 333 | |
| 334 | ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext(); |
| 335 | if (!m_is_external_ast_source) |
| 336 | { |
| 337 | m_is_external_ast_source = true; |
| 338 | llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap ( |
| 339 | new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl, |
| 340 | SymbolFileDWARF::CompleteObjCInterfaceDecl, |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 341 | SymbolFileDWARF::FindExternalVisibleDeclsByName, |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 342 | SymbolFileDWARF::LayoutRecordType, |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 343 | this)); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 344 | ast.SetExternalSource (ast_source_ap); |
| 345 | } |
| 346 | return ast; |
| 347 | } |
| 348 | |
| 349 | void |
| 350 | SymbolFileDWARF::InitializeObject() |
| 351 | { |
| 352 | // Install our external AST source callbacks so we can complete Clang types. |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 353 | ModuleSP module_sp (m_obj_file->GetModule()); |
| 354 | if (module_sp) |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 355 | { |
| 356 | const SectionList *section_list = m_obj_file->GetSectionList(); |
| 357 | |
| 358 | const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get(); |
| 359 | |
| 360 | // Memory map the DWARF mach-o segment so we have everything mmap'ed |
| 361 | // to keep our heap memory usage down. |
| 362 | if (section) |
| Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 363 | m_obj_file->MemoryMapSectionData(section, m_dwarf_data); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 364 | } |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 365 | get_apple_names_data(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 366 | if (m_data_apple_names.GetByteSize() > 0) |
| 367 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 368 | m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names")); |
| 369 | if (m_apple_names_ap->IsValid()) |
| 370 | m_using_apple_tables = true; |
| 371 | else |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 372 | m_apple_names_ap.reset(); |
| 373 | } |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 374 | get_apple_types_data(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 375 | if (m_data_apple_types.GetByteSize() > 0) |
| 376 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 377 | m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types")); |
| 378 | if (m_apple_types_ap->IsValid()) |
| 379 | m_using_apple_tables = true; |
| 380 | else |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 381 | m_apple_types_ap.reset(); |
| 382 | } |
| 383 | |
| 384 | get_apple_namespaces_data(); |
| 385 | if (m_data_apple_namespaces.GetByteSize() > 0) |
| 386 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 387 | m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces")); |
| 388 | if (m_apple_namespaces_ap->IsValid()) |
| 389 | m_using_apple_tables = true; |
| 390 | else |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 391 | m_apple_namespaces_ap.reset(); |
| 392 | } |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 393 | |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 394 | get_apple_objc_data(); |
| 395 | if (m_data_apple_objc.GetByteSize() > 0) |
| 396 | { |
| 397 | m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc")); |
| 398 | if (m_apple_objc_ap->IsValid()) |
| 399 | m_using_apple_tables = true; |
| 400 | else |
| 401 | m_apple_objc_ap.reset(); |
| 402 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | bool |
| 406 | SymbolFileDWARF::SupportedVersion(uint16_t version) |
| 407 | { |
| 408 | return version == 2 || version == 3; |
| 409 | } |
| 410 | |
| 411 | uint32_t |
| Sean Callanan | bfaf54d | 2011-12-03 04:38:43 +0000 | [diff] [blame] | 412 | SymbolFileDWARF::CalculateAbilities () |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 413 | { |
| 414 | uint32_t abilities = 0; |
| 415 | if (m_obj_file != NULL) |
| 416 | { |
| 417 | const Section* section = NULL; |
| 418 | const SectionList *section_list = m_obj_file->GetSectionList(); |
| 419 | if (section_list == NULL) |
| 420 | return 0; |
| 421 | |
| 422 | uint64_t debug_abbrev_file_size = 0; |
| 423 | uint64_t debug_aranges_file_size = 0; |
| 424 | uint64_t debug_frame_file_size = 0; |
| 425 | uint64_t debug_info_file_size = 0; |
| 426 | uint64_t debug_line_file_size = 0; |
| 427 | uint64_t debug_loc_file_size = 0; |
| 428 | uint64_t debug_macinfo_file_size = 0; |
| 429 | uint64_t debug_pubnames_file_size = 0; |
| 430 | uint64_t debug_pubtypes_file_size = 0; |
| 431 | uint64_t debug_ranges_file_size = 0; |
| 432 | uint64_t debug_str_file_size = 0; |
| 433 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 434 | section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 435 | |
| 436 | if (section) |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 437 | section_list = §ion->GetChildren (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 438 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 439 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 440 | if (section != NULL) |
| 441 | { |
| 442 | debug_info_file_size = section->GetByteSize(); |
| 443 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 444 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 445 | if (section) |
| 446 | debug_abbrev_file_size = section->GetByteSize(); |
| 447 | else |
| 448 | m_flags.Set (flagsGotDebugAbbrevData); |
| 449 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 450 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 451 | if (section) |
| 452 | debug_aranges_file_size = section->GetByteSize(); |
| 453 | else |
| 454 | m_flags.Set (flagsGotDebugArangesData); |
| 455 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 456 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 457 | if (section) |
| 458 | debug_frame_file_size = section->GetByteSize(); |
| 459 | else |
| 460 | m_flags.Set (flagsGotDebugFrameData); |
| 461 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 462 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 463 | if (section) |
| 464 | debug_line_file_size = section->GetByteSize(); |
| 465 | else |
| 466 | m_flags.Set (flagsGotDebugLineData); |
| 467 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 468 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 469 | if (section) |
| 470 | debug_loc_file_size = section->GetByteSize(); |
| 471 | else |
| 472 | m_flags.Set (flagsGotDebugLocData); |
| 473 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 474 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 475 | if (section) |
| 476 | debug_macinfo_file_size = section->GetByteSize(); |
| 477 | else |
| 478 | m_flags.Set (flagsGotDebugMacInfoData); |
| 479 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 480 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 481 | if (section) |
| 482 | debug_pubnames_file_size = section->GetByteSize(); |
| 483 | else |
| 484 | m_flags.Set (flagsGotDebugPubNamesData); |
| 485 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 486 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 487 | if (section) |
| 488 | debug_pubtypes_file_size = section->GetByteSize(); |
| 489 | else |
| 490 | m_flags.Set (flagsGotDebugPubTypesData); |
| 491 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 492 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 493 | if (section) |
| 494 | debug_ranges_file_size = section->GetByteSize(); |
| 495 | else |
| 496 | m_flags.Set (flagsGotDebugRangesData); |
| 497 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 498 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 499 | if (section) |
| 500 | debug_str_file_size = section->GetByteSize(); |
| 501 | else |
| 502 | m_flags.Set (flagsGotDebugStrData); |
| 503 | } |
| 504 | |
| 505 | if (debug_abbrev_file_size > 0 && debug_info_file_size > 0) |
| 506 | abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes; |
| 507 | |
| 508 | if (debug_line_file_size > 0) |
| 509 | abilities |= LineTables; |
| 510 | |
| 511 | if (debug_aranges_file_size > 0) |
| 512 | abilities |= AddressAcceleratorTable; |
| 513 | |
| 514 | if (debug_pubnames_file_size > 0) |
| 515 | abilities |= FunctionAcceleratorTable; |
| 516 | |
| 517 | if (debug_pubtypes_file_size > 0) |
| 518 | abilities |= TypeAcceleratorTable; |
| 519 | |
| 520 | if (debug_macinfo_file_size > 0) |
| 521 | abilities |= MacroInformation; |
| 522 | |
| 523 | if (debug_frame_file_size > 0) |
| 524 | abilities |= CallFrameInformation; |
| 525 | } |
| 526 | return abilities; |
| 527 | } |
| 528 | |
| 529 | const DataExtractor& |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 530 | SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 531 | { |
| 532 | if (m_flags.IsClear (got_flag)) |
| 533 | { |
| 534 | m_flags.Set (got_flag); |
| 535 | const SectionList *section_list = m_obj_file->GetSectionList(); |
| 536 | if (section_list) |
| 537 | { |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 538 | SectionSP section_sp (section_list->FindSectionByType(sect_type, true)); |
| 539 | if (section_sp) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 540 | { |
| 541 | // See if we memory mapped the DWARF segment? |
| 542 | if (m_dwarf_data.GetByteSize()) |
| 543 | { |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 544 | data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetByteSize()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 545 | } |
| 546 | else |
| 547 | { |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 548 | if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 549 | data.Clear(); |
| 550 | } |
| 551 | } |
| 552 | } |
| 553 | } |
| 554 | return data; |
| 555 | } |
| 556 | |
| 557 | const DataExtractor& |
| 558 | SymbolFileDWARF::get_debug_abbrev_data() |
| 559 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 560 | return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | const DataExtractor& |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 564 | SymbolFileDWARF::get_debug_aranges_data() |
| 565 | { |
| 566 | return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges); |
| 567 | } |
| 568 | |
| 569 | const DataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 570 | SymbolFileDWARF::get_debug_frame_data() |
| 571 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 572 | return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | const DataExtractor& |
| 576 | SymbolFileDWARF::get_debug_info_data() |
| 577 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 578 | return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | const DataExtractor& |
| 582 | SymbolFileDWARF::get_debug_line_data() |
| 583 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 584 | return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | const DataExtractor& |
| 588 | SymbolFileDWARF::get_debug_loc_data() |
| 589 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 590 | return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | const DataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 594 | SymbolFileDWARF::get_debug_ranges_data() |
| 595 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 596 | return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | const DataExtractor& |
| 600 | SymbolFileDWARF::get_debug_str_data() |
| 601 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 602 | return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 603 | } |
| 604 | |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 605 | const DataExtractor& |
| Greg Clayton | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 606 | SymbolFileDWARF::get_apple_names_data() |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 607 | { |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 608 | return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names); |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | const DataExtractor& |
| Greg Clayton | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 612 | SymbolFileDWARF::get_apple_types_data() |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 613 | { |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 614 | return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types); |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 615 | } |
| 616 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 617 | const DataExtractor& |
| 618 | SymbolFileDWARF::get_apple_namespaces_data() |
| 619 | { |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 620 | return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces); |
| 621 | } |
| 622 | |
| 623 | const DataExtractor& |
| 624 | SymbolFileDWARF::get_apple_objc_data() |
| 625 | { |
| 626 | return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 627 | } |
| 628 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 629 | |
| 630 | DWARFDebugAbbrev* |
| 631 | SymbolFileDWARF::DebugAbbrev() |
| 632 | { |
| 633 | if (m_abbr.get() == NULL) |
| 634 | { |
| 635 | const DataExtractor &debug_abbrev_data = get_debug_abbrev_data(); |
| 636 | if (debug_abbrev_data.GetByteSize() > 0) |
| 637 | { |
| 638 | m_abbr.reset(new DWARFDebugAbbrev()); |
| 639 | if (m_abbr.get()) |
| 640 | m_abbr->Parse(debug_abbrev_data); |
| 641 | } |
| 642 | } |
| 643 | return m_abbr.get(); |
| 644 | } |
| 645 | |
| 646 | const DWARFDebugAbbrev* |
| 647 | SymbolFileDWARF::DebugAbbrev() const |
| 648 | { |
| 649 | return m_abbr.get(); |
| 650 | } |
| 651 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 652 | |
| 653 | DWARFDebugInfo* |
| 654 | SymbolFileDWARF::DebugInfo() |
| 655 | { |
| 656 | if (m_info.get() == NULL) |
| 657 | { |
| 658 | Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this); |
| 659 | if (get_debug_info_data().GetByteSize() > 0) |
| 660 | { |
| 661 | m_info.reset(new DWARFDebugInfo()); |
| 662 | if (m_info.get()) |
| 663 | { |
| 664 | m_info->SetDwarfData(this); |
| 665 | } |
| 666 | } |
| 667 | } |
| 668 | return m_info.get(); |
| 669 | } |
| 670 | |
| 671 | const DWARFDebugInfo* |
| 672 | SymbolFileDWARF::DebugInfo() const |
| 673 | { |
| 674 | return m_info.get(); |
| 675 | } |
| 676 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 677 | DWARFCompileUnit* |
| 678 | SymbolFileDWARF::GetDWARFCompileUnitForUID(lldb::user_id_t cu_uid) |
| 679 | { |
| 680 | DWARFDebugInfo* info = DebugInfo(); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 681 | if (info && UserIDMatches(cu_uid)) |
| 682 | return info->GetCompileUnit((dw_offset_t)cu_uid).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 683 | return NULL; |
| 684 | } |
| 685 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 686 | |
| 687 | DWARFDebugRanges* |
| 688 | SymbolFileDWARF::DebugRanges() |
| 689 | { |
| 690 | if (m_ranges.get() == NULL) |
| 691 | { |
| 692 | Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this); |
| 693 | if (get_debug_ranges_data().GetByteSize() > 0) |
| 694 | { |
| 695 | m_ranges.reset(new DWARFDebugRanges()); |
| 696 | if (m_ranges.get()) |
| 697 | m_ranges->Extract(this); |
| 698 | } |
| 699 | } |
| 700 | return m_ranges.get(); |
| 701 | } |
| 702 | |
| 703 | const DWARFDebugRanges* |
| 704 | SymbolFileDWARF::DebugRanges() const |
| 705 | { |
| 706 | return m_ranges.get(); |
| 707 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 708 | |
| 709 | bool |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 710 | SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* curr_cu, CompUnitSP& compile_unit_sp) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 711 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 712 | if (curr_cu != NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 713 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 714 | const DWARFDebugInfoEntry * cu_die = curr_cu->GetCompileUnitDIEOnly (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 715 | if (cu_die) |
| 716 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 717 | const char * cu_die_name = cu_die->GetName(this, curr_cu); |
| 718 | const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, curr_cu, DW_AT_comp_dir, NULL); |
| Jim Ingham | 0f35ac2 | 2011-08-24 23:34:20 +0000 | [diff] [blame] | 719 | LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, curr_cu, DW_AT_language, 0); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 720 | if (cu_die_name) |
| 721 | { |
| Jim Ingham | 0909e5f | 2010-09-16 00:57:33 +0000 | [diff] [blame] | 722 | FileSpec cu_file_spec; |
| 723 | |
| Greg Clayton | 7bd65b9 | 2011-02-09 23:39:34 +0000 | [diff] [blame] | 724 | if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0') |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 725 | { |
| Jim Ingham | 0909e5f | 2010-09-16 00:57:33 +0000 | [diff] [blame] | 726 | // If we have a full path to the compile unit, we don't need to resolve |
| 727 | // the file. This can be expensive e.g. when the source files are NFS mounted. |
| 728 | cu_file_spec.SetFile (cu_die_name, false); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 729 | } |
| 730 | else |
| 731 | { |
| 732 | std::string fullpath(cu_comp_dir); |
| 733 | if (*fullpath.rbegin() != '/') |
| 734 | fullpath += '/'; |
| 735 | fullpath += cu_die_name; |
| Jim Ingham | 0909e5f | 2010-09-16 00:57:33 +0000 | [diff] [blame] | 736 | cu_file_spec.SetFile (fullpath.c_str(), false); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 737 | } |
| 738 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 739 | compile_unit_sp.reset(new CompileUnit (m_obj_file->GetModule(), |
| 740 | curr_cu, |
| 741 | cu_file_spec, |
| 742 | MakeUserID(curr_cu->GetOffset()), |
| 743 | cu_language)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 744 | if (compile_unit_sp.get()) |
| 745 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 746 | curr_cu->SetUserData(compile_unit_sp.get()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 747 | return true; |
| 748 | } |
| 749 | } |
| 750 | } |
| 751 | } |
| 752 | return false; |
| 753 | } |
| 754 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 755 | uint32_t |
| 756 | SymbolFileDWARF::GetNumCompileUnits() |
| 757 | { |
| 758 | DWARFDebugInfo* info = DebugInfo(); |
| 759 | if (info) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 760 | return info->GetNumCompileUnits(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 761 | return 0; |
| 762 | } |
| 763 | |
| 764 | CompUnitSP |
| 765 | SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx) |
| 766 | { |
| 767 | CompUnitSP comp_unit; |
| 768 | DWARFDebugInfo* info = DebugInfo(); |
| 769 | if (info) |
| 770 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 771 | DWARFCompileUnit* curr_cu = info->GetCompileUnitAtIndex(cu_idx); |
| 772 | if (curr_cu != NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 773 | { |
| 774 | // Our symbol vendor shouldn't be asking us to add a compile unit that |
| 775 | // has already been added to it, which this DWARF plug-in knows as it |
| 776 | // stores the lldb compile unit (CompileUnit) pointer in each |
| 777 | // DWARFCompileUnit object when it gets added. |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 778 | assert(curr_cu->GetUserData() == NULL); |
| 779 | ParseCompileUnit(curr_cu, comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 780 | } |
| 781 | } |
| 782 | return comp_unit; |
| 783 | } |
| 784 | |
| 785 | static void |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 786 | AddRangesToBlock (Block& block, |
| 787 | DWARFDebugRanges::RangeList& ranges, |
| 788 | addr_t block_base_addr) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 789 | { |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 790 | const size_t num_ranges = ranges.GetSize(); |
| 791 | for (size_t i = 0; i<num_ranges; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 792 | { |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 793 | const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i); |
| 794 | const addr_t range_base = range.GetRangeBase(); |
| 795 | assert (range_base >= block_base_addr); |
| 796 | block.AddRange(Block::Range (range_base - block_base_addr, range.GetByteSize()));; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 797 | } |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 798 | block.FinalizeRanges (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | |
| 802 | Function * |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 803 | SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 804 | { |
| 805 | DWARFDebugRanges::RangeList func_ranges; |
| 806 | const char *name = NULL; |
| 807 | const char *mangled = NULL; |
| 808 | int decl_file = 0; |
| 809 | int decl_line = 0; |
| 810 | int decl_column = 0; |
| 811 | int call_file = 0; |
| 812 | int call_line = 0; |
| 813 | int call_column = 0; |
| 814 | DWARFExpression frame_base; |
| 815 | |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 816 | assert (die->Tag() == DW_TAG_subprogram); |
| 817 | |
| 818 | if (die->Tag() != DW_TAG_subprogram) |
| 819 | return NULL; |
| 820 | |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 821 | if (die->GetDIENamesAndRanges (this, |
| 822 | dwarf_cu, |
| 823 | name, |
| 824 | mangled, |
| 825 | func_ranges, |
| 826 | decl_file, |
| 827 | decl_line, |
| 828 | decl_column, |
| 829 | call_file, |
| 830 | call_line, |
| 831 | call_column, |
| 832 | &frame_base)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 833 | { |
| 834 | // Union of all ranges in the function DIE (if the function is discontiguous) |
| 835 | AddressRange func_range; |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 836 | lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0); |
| 837 | lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 838 | if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr) |
| 839 | { |
| 840 | func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList()); |
| 841 | if (func_range.GetBaseAddress().IsValid()) |
| 842 | func_range.SetByteSize(highest_func_addr - lowest_func_addr); |
| 843 | } |
| 844 | |
| 845 | if (func_range.GetBaseAddress().IsValid()) |
| 846 | { |
| 847 | Mangled func_name; |
| 848 | if (mangled) |
| 849 | func_name.SetValue(mangled, true); |
| 850 | else if (name) |
| 851 | func_name.SetValue(name, false); |
| 852 | |
| 853 | FunctionSP func_sp; |
| 854 | std::auto_ptr<Declaration> decl_ap; |
| 855 | if (decl_file != 0 || decl_line != 0 || decl_column != 0) |
| Greg Clayton | d7e0546 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 856 | decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), |
| 857 | decl_line, |
| 858 | decl_column)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 859 | |
| Greg Clayton | 0bd4e1b | 2011-09-30 20:52:25 +0000 | [diff] [blame] | 860 | // Supply the type _only_ if it has already been parsed |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 861 | Type *func_type = m_die_to_type.lookup (die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 862 | |
| 863 | assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED); |
| 864 | |
| 865 | func_range.GetBaseAddress().ResolveLinkedAddress(); |
| 866 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 867 | const user_id_t func_user_id = MakeUserID(die->GetOffset()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 868 | func_sp.reset(new Function (sc.comp_unit, |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 869 | func_user_id, // UserID is the DIE offset |
| 870 | func_user_id, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 871 | func_name, |
| 872 | func_type, |
| 873 | func_range)); // first address range |
| 874 | |
| 875 | if (func_sp.get() != NULL) |
| 876 | { |
| Greg Clayton | 0bd4e1b | 2011-09-30 20:52:25 +0000 | [diff] [blame] | 877 | if (frame_base.IsValid()) |
| 878 | func_sp->GetFrameBaseExpression() = frame_base; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 879 | sc.comp_unit->AddFunction(func_sp); |
| 880 | return func_sp.get(); |
| 881 | } |
| 882 | } |
| 883 | } |
| 884 | return NULL; |
| 885 | } |
| 886 | |
| 887 | size_t |
| 888 | SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc) |
| 889 | { |
| 890 | assert (sc.comp_unit); |
| 891 | size_t functions_added = 0; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 892 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 893 | if (dwarf_cu) |
| 894 | { |
| 895 | DWARFDIECollection function_dies; |
| 896 | const size_t num_funtions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies); |
| 897 | size_t func_idx; |
| 898 | for (func_idx = 0; func_idx < num_funtions; ++func_idx) |
| 899 | { |
| 900 | const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 901 | if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 902 | { |
| 903 | if (ParseCompileUnitFunction(sc, dwarf_cu, die)) |
| 904 | ++functions_added; |
| 905 | } |
| 906 | } |
| 907 | //FixupTypes(); |
| 908 | } |
| 909 | return functions_added; |
| 910 | } |
| 911 | |
| 912 | bool |
| 913 | SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files) |
| 914 | { |
| 915 | assert (sc.comp_unit); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 916 | DWARFCompileUnit* curr_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID()); |
| 917 | assert (curr_cu); |
| 918 | const DWARFDebugInfoEntry * cu_die = curr_cu->GetCompileUnitDIEOnly(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 919 | |
| 920 | if (cu_die) |
| 921 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 922 | const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, curr_cu, DW_AT_comp_dir, NULL); |
| 923 | dw_offset_t stmt_list = cu_die->GetAttributeValueAsUnsigned(this, curr_cu, DW_AT_stmt_list, DW_INVALID_OFFSET); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 924 | |
| 925 | // All file indexes in DWARF are one based and a file of index zero is |
| 926 | // supposed to be the compile unit itself. |
| 927 | support_files.Append (*sc.comp_unit); |
| 928 | |
| 929 | return DWARFDebugLine::ParseSupportFiles(get_debug_line_data(), cu_comp_dir, stmt_list, support_files); |
| 930 | } |
| 931 | return false; |
| 932 | } |
| 933 | |
| 934 | struct ParseDWARFLineTableCallbackInfo |
| 935 | { |
| 936 | LineTable* line_table; |
| 937 | const SectionList *section_list; |
| 938 | lldb::addr_t prev_sect_file_base_addr; |
| 939 | lldb::addr_t curr_sect_file_base_addr; |
| 940 | bool is_oso_for_debug_map; |
| 941 | bool prev_in_final_executable; |
| 942 | DWARFDebugLine::Row prev_row; |
| 943 | SectionSP prev_section_sp; |
| 944 | SectionSP curr_section_sp; |
| 945 | }; |
| 946 | |
| 947 | //---------------------------------------------------------------------- |
| 948 | // ParseStatementTableCallback |
| 949 | //---------------------------------------------------------------------- |
| 950 | static void |
| 951 | ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData) |
| 952 | { |
| 953 | LineTable* line_table = ((ParseDWARFLineTableCallbackInfo*)userData)->line_table; |
| 954 | if (state.row == DWARFDebugLine::State::StartParsingLineTable) |
| 955 | { |
| 956 | // Just started parsing the line table |
| 957 | } |
| 958 | else if (state.row == DWARFDebugLine::State::DoneParsingLineTable) |
| 959 | { |
| 960 | // Done parsing line table, nothing to do for the cleanup |
| 961 | } |
| 962 | else |
| 963 | { |
| 964 | ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData; |
| 965 | // We have a new row, lets append it |
| 966 | |
| 967 | if (info->curr_section_sp.get() == NULL || info->curr_section_sp->ContainsFileAddress(state.address) == false) |
| 968 | { |
| 969 | info->prev_section_sp = info->curr_section_sp; |
| 970 | info->prev_sect_file_base_addr = info->curr_sect_file_base_addr; |
| 971 | // If this is an end sequence entry, then we subtract one from the |
| 972 | // address to make sure we get an address that is not the end of |
| 973 | // a section. |
| 974 | if (state.end_sequence && state.address != 0) |
| 975 | info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address - 1); |
| 976 | else |
| 977 | info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address); |
| 978 | |
| 979 | if (info->curr_section_sp.get()) |
| 980 | info->curr_sect_file_base_addr = info->curr_section_sp->GetFileAddress (); |
| 981 | else |
| 982 | info->curr_sect_file_base_addr = 0; |
| 983 | } |
| 984 | if (info->curr_section_sp.get()) |
| 985 | { |
| 986 | lldb::addr_t curr_line_section_offset = state.address - info->curr_sect_file_base_addr; |
| 987 | // Check for the fancy section magic to determine if we |
| 988 | |
| 989 | if (info->is_oso_for_debug_map) |
| 990 | { |
| 991 | // When this is a debug map object file that contains DWARF |
| 992 | // (referenced from an N_OSO debug map nlist entry) we will have |
| 993 | // a file address in the file range for our section from the |
| 994 | // original .o file, and a load address in the executable that |
| 995 | // contains the debug map. |
| 996 | // |
| 997 | // If the sections for the file range and load range are |
| 998 | // different, we have a remapped section for the function and |
| 999 | // this address is resolved. If they are the same, then the |
| 1000 | // function for this address didn't make it into the final |
| 1001 | // executable. |
| 1002 | bool curr_in_final_executable = info->curr_section_sp->GetLinkedSection () != NULL; |
| 1003 | |
| 1004 | // If we are doing DWARF with debug map, then we need to carefully |
| 1005 | // add each line table entry as there may be gaps as functions |
| 1006 | // get moved around or removed. |
| 1007 | if (!info->prev_row.end_sequence && info->prev_section_sp.get()) |
| 1008 | { |
| 1009 | if (info->prev_in_final_executable) |
| 1010 | { |
| 1011 | bool terminate_previous_entry = false; |
| 1012 | if (!curr_in_final_executable) |
| 1013 | { |
| 1014 | // Check for the case where the previous line entry |
| 1015 | // in a function made it into the final executable, |
| 1016 | // yet the current line entry falls in a function |
| 1017 | // that didn't. The line table used to be contiguous |
| 1018 | // through this address range but now it isn't. We |
| 1019 | // need to terminate the previous line entry so |
| 1020 | // that we can reconstruct the line range correctly |
| 1021 | // for it and to keep the line table correct. |
| 1022 | terminate_previous_entry = true; |
| 1023 | } |
| 1024 | else if (info->curr_section_sp.get() != info->prev_section_sp.get()) |
| 1025 | { |
| 1026 | // Check for cases where the line entries used to be |
| 1027 | // contiguous address ranges, but now they aren't. |
| 1028 | // This can happen when order files specify the |
| 1029 | // ordering of the functions. |
| 1030 | lldb::addr_t prev_line_section_offset = info->prev_row.address - info->prev_sect_file_base_addr; |
| 1031 | Section *curr_sect = info->curr_section_sp.get(); |
| 1032 | Section *prev_sect = info->prev_section_sp.get(); |
| 1033 | assert (curr_sect->GetLinkedSection()); |
| 1034 | assert (prev_sect->GetLinkedSection()); |
| 1035 | lldb::addr_t object_file_addr_delta = state.address - info->prev_row.address; |
| 1036 | lldb::addr_t curr_linked_file_addr = curr_sect->GetLinkedFileAddress() + curr_line_section_offset; |
| 1037 | lldb::addr_t prev_linked_file_addr = prev_sect->GetLinkedFileAddress() + prev_line_section_offset; |
| 1038 | lldb::addr_t linked_file_addr_delta = curr_linked_file_addr - prev_linked_file_addr; |
| 1039 | if (object_file_addr_delta != linked_file_addr_delta) |
| 1040 | terminate_previous_entry = true; |
| 1041 | } |
| 1042 | |
| 1043 | if (terminate_previous_entry) |
| 1044 | { |
| 1045 | line_table->InsertLineEntry (info->prev_section_sp, |
| 1046 | state.address - info->prev_sect_file_base_addr, |
| 1047 | info->prev_row.line, |
| 1048 | info->prev_row.column, |
| 1049 | info->prev_row.file, |
| 1050 | false, // is_stmt |
| 1051 | false, // basic_block |
| 1052 | false, // state.prologue_end |
| 1053 | false, // state.epilogue_begin |
| 1054 | true); // end_sequence); |
| 1055 | } |
| 1056 | } |
| 1057 | } |
| 1058 | |
| 1059 | if (curr_in_final_executable) |
| 1060 | { |
| 1061 | line_table->InsertLineEntry (info->curr_section_sp, |
| 1062 | curr_line_section_offset, |
| 1063 | state.line, |
| 1064 | state.column, |
| 1065 | state.file, |
| 1066 | state.is_stmt, |
| 1067 | state.basic_block, |
| 1068 | state.prologue_end, |
| 1069 | state.epilogue_begin, |
| 1070 | state.end_sequence); |
| 1071 | info->prev_section_sp = info->curr_section_sp; |
| 1072 | } |
| 1073 | else |
| 1074 | { |
| 1075 | // If the current address didn't make it into the final |
| 1076 | // executable, the current section will be the __text |
| 1077 | // segment in the .o file, so we need to clear this so |
| 1078 | // we can catch the next function that did make it into |
| 1079 | // the final executable. |
| 1080 | info->prev_section_sp.reset(); |
| 1081 | info->curr_section_sp.reset(); |
| 1082 | } |
| 1083 | |
| 1084 | info->prev_in_final_executable = curr_in_final_executable; |
| 1085 | } |
| 1086 | else |
| 1087 | { |
| 1088 | // We are not in an object file that contains DWARF for an |
| 1089 | // N_OSO, this is just a normal DWARF file. The DWARF spec |
| 1090 | // guarantees that the addresses will be in increasing order |
| 1091 | // so, since we store line tables in file address order, we |
| 1092 | // can always just append the line entry without needing to |
| 1093 | // search for the correct insertion point (we don't need to |
| 1094 | // use LineEntry::InsertLineEntry()). |
| 1095 | line_table->AppendLineEntry (info->curr_section_sp, |
| 1096 | curr_line_section_offset, |
| 1097 | state.line, |
| 1098 | state.column, |
| 1099 | state.file, |
| 1100 | state.is_stmt, |
| 1101 | state.basic_block, |
| 1102 | state.prologue_end, |
| 1103 | state.epilogue_begin, |
| 1104 | state.end_sequence); |
| 1105 | } |
| 1106 | } |
| 1107 | |
| 1108 | info->prev_row = state; |
| 1109 | } |
| 1110 | } |
| 1111 | |
| 1112 | bool |
| 1113 | SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc) |
| 1114 | { |
| 1115 | assert (sc.comp_unit); |
| 1116 | if (sc.comp_unit->GetLineTable() != NULL) |
| 1117 | return true; |
| 1118 | |
| 1119 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID()); |
| 1120 | if (dwarf_cu) |
| 1121 | { |
| 1122 | const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly(); |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1123 | if (dwarf_cu_die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1124 | { |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1125 | const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET); |
| 1126 | if (cu_line_offset != DW_INVALID_OFFSET) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1127 | { |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1128 | std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit)); |
| 1129 | if (line_table_ap.get()) |
| 1130 | { |
| 1131 | ParseDWARFLineTableCallbackInfo info = { |
| 1132 | line_table_ap.get(), |
| 1133 | m_obj_file->GetSectionList(), |
| 1134 | 0, |
| 1135 | 0, |
| 1136 | m_debug_map_symfile != NULL, |
| 1137 | false, |
| 1138 | DWARFDebugLine::Row(), |
| 1139 | SectionSP(), |
| 1140 | SectionSP() |
| 1141 | }; |
| 1142 | uint32_t offset = cu_line_offset; |
| 1143 | DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info); |
| 1144 | sc.comp_unit->SetLineTable(line_table_ap.release()); |
| 1145 | return true; |
| 1146 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1147 | } |
| 1148 | } |
| 1149 | } |
| 1150 | return false; |
| 1151 | } |
| 1152 | |
| 1153 | size_t |
| 1154 | SymbolFileDWARF::ParseFunctionBlocks |
| 1155 | ( |
| 1156 | const SymbolContext& sc, |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1157 | Block *parent_block, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1158 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1159 | const DWARFDebugInfoEntry *die, |
| 1160 | addr_t subprogram_low_pc, |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1161 | uint32_t depth |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1162 | ) |
| 1163 | { |
| 1164 | size_t blocks_added = 0; |
| 1165 | while (die != NULL) |
| 1166 | { |
| 1167 | dw_tag_t tag = die->Tag(); |
| 1168 | |
| 1169 | switch (tag) |
| 1170 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1171 | case DW_TAG_inlined_subroutine: |
| Greg Clayton | b4d3733 | 2011-08-12 16:22:48 +0000 | [diff] [blame] | 1172 | case DW_TAG_subprogram: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1173 | case DW_TAG_lexical_block: |
| 1174 | { |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1175 | Block *block = NULL; |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1176 | if (tag == DW_TAG_subprogram) |
| 1177 | { |
| 1178 | // Skip any DW_TAG_subprogram DIEs that are inside |
| 1179 | // of a normal or inlined functions. These will be |
| 1180 | // parsed on their own as separate entities. |
| 1181 | |
| 1182 | if (depth > 0) |
| 1183 | break; |
| 1184 | |
| 1185 | block = parent_block; |
| 1186 | } |
| 1187 | else |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1188 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1189 | BlockSP block_sp(new Block (MakeUserID(die->GetOffset()))); |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1190 | parent_block->AddChild(block_sp); |
| 1191 | block = block_sp.get(); |
| 1192 | } |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1193 | DWARFDebugRanges::RangeList ranges; |
| 1194 | const char *name = NULL; |
| 1195 | const char *mangled_name = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1196 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1197 | int decl_file = 0; |
| 1198 | int decl_line = 0; |
| 1199 | int decl_column = 0; |
| 1200 | int call_file = 0; |
| 1201 | int call_line = 0; |
| 1202 | int call_column = 0; |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1203 | if (die->GetDIENamesAndRanges (this, |
| 1204 | dwarf_cu, |
| 1205 | name, |
| 1206 | mangled_name, |
| 1207 | ranges, |
| 1208 | decl_file, decl_line, decl_column, |
| 1209 | call_file, call_line, call_column)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1210 | { |
| 1211 | if (tag == DW_TAG_subprogram) |
| 1212 | { |
| 1213 | assert (subprogram_low_pc == LLDB_INVALID_ADDRESS); |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1214 | subprogram_low_pc = ranges.GetMinRangeBase(0); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1215 | } |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1216 | else if (tag == DW_TAG_inlined_subroutine) |
| 1217 | { |
| 1218 | // We get called here for inlined subroutines in two ways. |
| 1219 | // The first time is when we are making the Function object |
| 1220 | // for this inlined concrete instance. Since we're creating a top level block at |
| 1221 | // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to |
| 1222 | // adjust the containing address. |
| 1223 | // The second time is when we are parsing the blocks inside the function that contains |
| 1224 | // the inlined concrete instance. Since these will be blocks inside the containing "real" |
| 1225 | // function the offset will be for that function. |
| 1226 | if (subprogram_low_pc == LLDB_INVALID_ADDRESS) |
| 1227 | { |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1228 | subprogram_low_pc = ranges.GetMinRangeBase(0); |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1229 | } |
| 1230 | } |
| 1231 | |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1232 | AddRangesToBlock (*block, ranges, subprogram_low_pc); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1233 | |
| 1234 | if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL)) |
| 1235 | { |
| 1236 | std::auto_ptr<Declaration> decl_ap; |
| 1237 | if (decl_file != 0 || decl_line != 0 || decl_column != 0) |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1238 | decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), |
| 1239 | decl_line, decl_column)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1240 | |
| 1241 | std::auto_ptr<Declaration> call_ap; |
| 1242 | if (call_file != 0 || call_line != 0 || call_column != 0) |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1243 | call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file), |
| 1244 | call_line, call_column)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1245 | |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1246 | block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1247 | } |
| 1248 | |
| 1249 | ++blocks_added; |
| 1250 | |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1251 | if (die->HasChildren()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1252 | { |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1253 | blocks_added += ParseFunctionBlocks (sc, |
| 1254 | block, |
| 1255 | dwarf_cu, |
| 1256 | die->GetFirstChild(), |
| 1257 | subprogram_low_pc, |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1258 | depth + 1); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1259 | } |
| 1260 | } |
| 1261 | } |
| 1262 | break; |
| 1263 | default: |
| 1264 | break; |
| 1265 | } |
| 1266 | |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1267 | // Only parse siblings of the block if we are not at depth zero. A depth |
| 1268 | // of zero indicates we are currently parsing the top level |
| 1269 | // DW_TAG_subprogram DIE |
| 1270 | |
| 1271 | if (depth == 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1272 | die = NULL; |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1273 | else |
| 1274 | die = die->GetSibling(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1275 | } |
| 1276 | return blocks_added; |
| 1277 | } |
| 1278 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1279 | bool |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1280 | SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu, |
| 1281 | const DWARFDebugInfoEntry *die, |
| 1282 | ClangASTContext::TemplateParameterInfos &template_param_infos) |
| 1283 | { |
| 1284 | const dw_tag_t tag = die->Tag(); |
| 1285 | |
| 1286 | switch (tag) |
| 1287 | { |
| 1288 | case DW_TAG_template_type_parameter: |
| 1289 | case DW_TAG_template_value_parameter: |
| 1290 | { |
| 1291 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| 1292 | |
| 1293 | DWARFDebugInfoEntry::Attributes attributes; |
| 1294 | const size_t num_attributes = die->GetAttributes (this, |
| 1295 | dwarf_cu, |
| 1296 | fixed_form_sizes, |
| 1297 | attributes); |
| 1298 | const char *name = NULL; |
| 1299 | Type *lldb_type = NULL; |
| 1300 | clang_type_t clang_type = NULL; |
| 1301 | uint64_t uval64 = 0; |
| 1302 | bool uval64_valid = false; |
| 1303 | if (num_attributes > 0) |
| 1304 | { |
| 1305 | DWARFFormValue form_value; |
| 1306 | for (size_t i=0; i<num_attributes; ++i) |
| 1307 | { |
| 1308 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 1309 | |
| 1310 | switch (attr) |
| 1311 | { |
| 1312 | case DW_AT_name: |
| 1313 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1314 | name = form_value.AsCString(&get_debug_str_data()); |
| 1315 | break; |
| 1316 | |
| 1317 | case DW_AT_type: |
| 1318 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1319 | { |
| 1320 | const dw_offset_t type_die_offset = form_value.Reference(dwarf_cu); |
| 1321 | lldb_type = ResolveTypeUID(type_die_offset); |
| 1322 | if (lldb_type) |
| 1323 | clang_type = lldb_type->GetClangForwardType(); |
| 1324 | } |
| 1325 | break; |
| 1326 | |
| 1327 | case DW_AT_const_value: |
| 1328 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1329 | { |
| 1330 | uval64_valid = true; |
| 1331 | uval64 = form_value.Unsigned(); |
| 1332 | } |
| 1333 | break; |
| 1334 | default: |
| 1335 | break; |
| 1336 | } |
| 1337 | } |
| 1338 | |
| 1339 | if (name && lldb_type && clang_type) |
| 1340 | { |
| 1341 | bool is_signed = false; |
| 1342 | template_param_infos.names.push_back(name); |
| 1343 | clang::QualType clang_qual_type (clang::QualType::getFromOpaquePtr (clang_type)); |
| 1344 | if (tag == DW_TAG_template_value_parameter && ClangASTContext::IsIntegerType (clang_type, is_signed) && uval64_valid) |
| 1345 | { |
| 1346 | llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed); |
| 1347 | template_param_infos.args.push_back (clang::TemplateArgument (llvm::APSInt(apint), clang_qual_type)); |
| 1348 | } |
| 1349 | else |
| 1350 | { |
| 1351 | template_param_infos.args.push_back (clang::TemplateArgument (clang_qual_type)); |
| 1352 | } |
| 1353 | } |
| 1354 | else |
| 1355 | { |
| 1356 | return false; |
| 1357 | } |
| 1358 | |
| 1359 | } |
| 1360 | } |
| 1361 | return true; |
| 1362 | |
| 1363 | default: |
| 1364 | break; |
| 1365 | } |
| 1366 | return false; |
| 1367 | } |
| 1368 | |
| 1369 | bool |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1370 | SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu, |
| 1371 | const DWARFDebugInfoEntry *parent_die, |
| 1372 | ClangASTContext::TemplateParameterInfos &template_param_infos) |
| 1373 | { |
| 1374 | |
| 1375 | if (parent_die == NULL) |
| 1376 | return NULL; |
| 1377 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1378 | Args template_parameter_names; |
| 1379 | for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); |
| 1380 | die != NULL; |
| 1381 | die = die->GetSibling()) |
| 1382 | { |
| 1383 | const dw_tag_t tag = die->Tag(); |
| 1384 | |
| 1385 | switch (tag) |
| 1386 | { |
| 1387 | case DW_TAG_template_type_parameter: |
| 1388 | case DW_TAG_template_value_parameter: |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1389 | ParseTemplateDIE (dwarf_cu, die, template_param_infos); |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1390 | break; |
| 1391 | |
| 1392 | default: |
| 1393 | break; |
| 1394 | } |
| 1395 | } |
| 1396 | if (template_param_infos.args.empty()) |
| 1397 | return false; |
| 1398 | return template_param_infos.args.size() == template_param_infos.names.size(); |
| 1399 | } |
| 1400 | |
| 1401 | clang::ClassTemplateDecl * |
| 1402 | SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx, |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1403 | lldb::AccessType access_type, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1404 | const char *parent_name, |
| 1405 | int tag_decl_kind, |
| 1406 | const ClangASTContext::TemplateParameterInfos &template_param_infos) |
| 1407 | { |
| 1408 | if (template_param_infos.IsValid()) |
| 1409 | { |
| 1410 | std::string template_basename(parent_name); |
| 1411 | template_basename.erase (template_basename.find('<')); |
| 1412 | ClangASTContext &ast = GetClangASTContext(); |
| 1413 | |
| 1414 | return ast.CreateClassTemplateDecl (decl_ctx, |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1415 | access_type, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1416 | template_basename.c_str(), |
| 1417 | tag_decl_kind, |
| 1418 | template_param_infos); |
| 1419 | } |
| 1420 | return NULL; |
| 1421 | } |
| 1422 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1423 | size_t |
| 1424 | SymbolFileDWARF::ParseChildMembers |
| 1425 | ( |
| 1426 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1427 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1428 | const DWARFDebugInfoEntry *parent_die, |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1429 | clang_type_t class_clang_type, |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1430 | const LanguageType class_language, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1431 | std::vector<clang::CXXBaseSpecifier *>& base_classes, |
| 1432 | std::vector<int>& member_accessibilities, |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1433 | DWARFDIECollection& member_function_dies, |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1434 | AccessType& default_accessibility, |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1435 | bool &is_a_class, |
| 1436 | LayoutInfo &layout_info |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1437 | ) |
| 1438 | { |
| 1439 | if (parent_die == NULL) |
| 1440 | return 0; |
| 1441 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1442 | size_t count = 0; |
| 1443 | const DWARFDebugInfoEntry *die; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 1444 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1445 | uint32_t member_idx = 0; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 1446 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1447 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 1448 | { |
| 1449 | dw_tag_t tag = die->Tag(); |
| 1450 | |
| 1451 | switch (tag) |
| 1452 | { |
| 1453 | case DW_TAG_member: |
| 1454 | { |
| 1455 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1456 | const size_t num_attributes = die->GetAttributes (this, |
| 1457 | dwarf_cu, |
| 1458 | fixed_form_sizes, |
| 1459 | attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1460 | if (num_attributes > 0) |
| 1461 | { |
| 1462 | Declaration decl; |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1463 | //DWARFExpression location; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1464 | const char *name = NULL; |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1465 | const char *prop_name = NULL; |
| 1466 | const char *prop_getter_name = NULL; |
| 1467 | const char *prop_setter_name = NULL; |
| 1468 | uint32_t prop_attributes = 0; |
| 1469 | |
| 1470 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1471 | bool is_artificial = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1472 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1473 | AccessType accessibility = eAccessNone; |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1474 | uint32_t member_byte_offset = UINT32_MAX; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1475 | size_t byte_size = 0; |
| 1476 | size_t bit_offset = 0; |
| 1477 | size_t bit_size = 0; |
| 1478 | uint32_t i; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1479 | for (i=0; i<num_attributes && !is_artificial; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1480 | { |
| 1481 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 1482 | DWARFFormValue form_value; |
| 1483 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1484 | { |
| 1485 | switch (attr) |
| 1486 | { |
| 1487 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 1488 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 1489 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 1490 | case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; |
| 1491 | case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; |
| 1492 | case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break; |
| 1493 | case DW_AT_bit_size: bit_size = form_value.Unsigned(); break; |
| 1494 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; |
| 1495 | case DW_AT_data_member_location: |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1496 | if (form_value.BlockData()) |
| 1497 | { |
| 1498 | Value initialValue(0); |
| 1499 | Value memberOffset(0); |
| 1500 | const DataExtractor& debug_info_data = get_debug_info_data(); |
| 1501 | uint32_t block_length = form_value.Unsigned(); |
| 1502 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 1503 | if (DWARFExpression::Evaluate(NULL, // ExecutionContext * |
| 1504 | NULL, // clang::ASTContext * |
| 1505 | NULL, // ClangExpressionVariableList * |
| 1506 | NULL, // ClangExpressionDeclMap * |
| 1507 | NULL, // RegisterContext * |
| 1508 | debug_info_data, |
| 1509 | block_offset, |
| 1510 | block_length, |
| 1511 | eRegisterKindDWARF, |
| 1512 | &initialValue, |
| 1513 | memberOffset, |
| 1514 | NULL)) |
| 1515 | { |
| 1516 | member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt(); |
| 1517 | } |
| 1518 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1519 | break; |
| 1520 | |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1521 | case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1522 | case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1523 | case DW_AT_declaration: |
| 1524 | case DW_AT_description: |
| 1525 | case DW_AT_mutable: |
| 1526 | case DW_AT_visibility: |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1527 | |
| 1528 | case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break; |
| 1529 | case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break; |
| 1530 | case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break; |
| 1531 | case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break; |
| 1532 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1533 | default: |
| 1534 | case DW_AT_sibling: |
| 1535 | break; |
| 1536 | } |
| 1537 | } |
| 1538 | } |
| Sean Callanan | 5a477cf | 2010-10-30 01:56:10 +0000 | [diff] [blame] | 1539 | |
| Greg Clayton | 4495393 | 2011-10-25 01:25:35 +0000 | [diff] [blame] | 1540 | // Clang has a DWARF generation bug where sometimes it |
| 1541 | // represents fields that are references with bad byte size |
| 1542 | // and bit size/offset information such as: |
| 1543 | // |
| 1544 | // DW_AT_byte_size( 0x00 ) |
| 1545 | // DW_AT_bit_size( 0x40 ) |
| 1546 | // DW_AT_bit_offset( 0xffffffffffffffc0 ) |
| 1547 | // |
| 1548 | // So check the bit offset to make sure it is sane, and if |
| 1549 | // the values are not sane, remove them. If we don't do this |
| 1550 | // then we will end up with a crash if we try to use this |
| 1551 | // type in an expression when clang becomes unhappy with its |
| 1552 | // recycled debug info. |
| Sean Callanan | 5a477cf | 2010-10-30 01:56:10 +0000 | [diff] [blame] | 1553 | |
| Greg Clayton | 4495393 | 2011-10-25 01:25:35 +0000 | [diff] [blame] | 1554 | if (bit_offset > 128) |
| 1555 | { |
| 1556 | bit_size = 0; |
| 1557 | bit_offset = 0; |
| 1558 | } |
| 1559 | |
| 1560 | // FIXME: Make Clang ignore Objective-C accessibility for expressions |
| Sean Callanan | 5a477cf | 2010-10-30 01:56:10 +0000 | [diff] [blame] | 1561 | if (class_language == eLanguageTypeObjC || |
| 1562 | class_language == eLanguageTypeObjC_plus_plus) |
| 1563 | accessibility = eAccessNone; |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1564 | |
| 1565 | if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name)) |
| 1566 | { |
| 1567 | // Not all compilers will mark the vtable pointer |
| 1568 | // member as artificial (llvm-gcc). We can't have |
| 1569 | // the virtual members in our classes otherwise it |
| 1570 | // throws off all child offsets since we end up |
| 1571 | // having and extra pointer sized member in our |
| 1572 | // class layouts. |
| 1573 | is_artificial = true; |
| 1574 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1575 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1576 | if (is_artificial == false) |
| 1577 | { |
| 1578 | Type *member_type = ResolveTypeUID(encoding_uid); |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1579 | clang::FieldDecl *field_decl = NULL; |
| Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1580 | if (member_type) |
| 1581 | { |
| 1582 | if (accessibility == eAccessNone) |
| 1583 | accessibility = default_accessibility; |
| 1584 | member_accessibilities.push_back(accessibility); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1585 | |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1586 | field_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type, |
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 1587 | name, |
| 1588 | member_type->GetClangLayoutType(), |
| 1589 | accessibility, |
| 1590 | bit_size); |
| Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1591 | } |
| 1592 | else |
| 1593 | { |
| 1594 | if (name) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1595 | GetObjectFile()->GetModule()->ReportError ("0x%8.8llx: DW_TAG_member '%s' refers to type 0x%8.8llx which was unable to be parsed", |
| 1596 | MakeUserID(die->GetOffset()), |
| 1597 | name, |
| 1598 | encoding_uid); |
| Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1599 | else |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1600 | GetObjectFile()->GetModule()->ReportError ("0x%8.8llx: DW_TAG_member refers to type 0x%8.8llx which was unable to be parsed", |
| 1601 | MakeUserID(die->GetOffset()), |
| 1602 | encoding_uid); |
| Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1603 | } |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1604 | |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1605 | if (member_byte_offset != UINT32_MAX || bit_size != 0) |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1606 | { |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1607 | ///////////////////////////////////////////////////////////// |
| 1608 | // How to locate a field given the DWARF debug information |
| 1609 | // |
| 1610 | // AT_byte_size indicates the size of the word in which the |
| 1611 | // bit offset must be interpreted. |
| 1612 | // |
| 1613 | // AT_data_member_location indicates the byte offset of the |
| 1614 | // word from the base address of the structure. |
| 1615 | // |
| 1616 | // AT_bit_offset indicates how many bits into the word |
| 1617 | // (according to the host endianness) the low-order bit of |
| 1618 | // the field starts. AT_bit_offset can be negative. |
| 1619 | // |
| 1620 | // AT_bit_size indicates the size of the field in bits. |
| 1621 | ///////////////////////////////////////////////////////////// |
| 1622 | |
| 1623 | ByteOrder object_endian = GetObjectFile()->GetModule()->GetArchitecture().GetDefaultEndian(); |
| 1624 | |
| 1625 | uint64_t total_bit_offset = 0; |
| 1626 | |
| 1627 | total_bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8)); |
| 1628 | |
| 1629 | if (object_endian == eByteOrderLittle) |
| 1630 | { |
| 1631 | total_bit_offset += byte_size * 8; |
| 1632 | total_bit_offset -= (bit_offset + bit_size); |
| 1633 | } |
| 1634 | else |
| 1635 | { |
| 1636 | total_bit_offset += bit_offset; |
| 1637 | } |
| 1638 | |
| 1639 | layout_info.field_offsets.insert(std::make_pair(field_decl, total_bit_offset)); |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1640 | } |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1641 | if (prop_name != NULL) |
| 1642 | { |
| 1643 | |
| 1644 | clang::ObjCIvarDecl *ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl); |
| 1645 | assert (ivar_decl != NULL); |
| 1646 | |
| 1647 | |
| 1648 | GetClangASTContext().AddObjCClassProperty (class_clang_type, |
| 1649 | prop_name, |
| 1650 | 0, |
| 1651 | ivar_decl, |
| 1652 | prop_setter_name, |
| 1653 | prop_getter_name, |
| 1654 | prop_attributes); |
| 1655 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1656 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1657 | } |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1658 | ++member_idx; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1659 | } |
| 1660 | break; |
| 1661 | |
| 1662 | case DW_TAG_subprogram: |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1663 | // Let the type parsing code handle this one for us. |
| 1664 | member_function_dies.Append (die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1665 | break; |
| 1666 | |
| 1667 | case DW_TAG_inheritance: |
| 1668 | { |
| 1669 | is_a_class = true; |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1670 | if (default_accessibility == eAccessNone) |
| 1671 | default_accessibility = eAccessPrivate; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1672 | // TODO: implement DW_TAG_inheritance type parsing |
| 1673 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1674 | const size_t num_attributes = die->GetAttributes (this, |
| 1675 | dwarf_cu, |
| 1676 | fixed_form_sizes, |
| 1677 | attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1678 | if (num_attributes > 0) |
| 1679 | { |
| 1680 | Declaration decl; |
| 1681 | DWARFExpression location; |
| 1682 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1683 | AccessType accessibility = default_accessibility; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1684 | bool is_virtual = false; |
| 1685 | bool is_base_of_class = true; |
| 1686 | off_t member_offset = 0; |
| 1687 | uint32_t i; |
| 1688 | for (i=0; i<num_attributes; ++i) |
| 1689 | { |
| 1690 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 1691 | DWARFFormValue form_value; |
| 1692 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1693 | { |
| 1694 | switch (attr) |
| 1695 | { |
| 1696 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 1697 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 1698 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 1699 | case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; |
| 1700 | case DW_AT_data_member_location: |
| 1701 | if (form_value.BlockData()) |
| 1702 | { |
| 1703 | Value initialValue(0); |
| 1704 | Value memberOffset(0); |
| 1705 | const DataExtractor& debug_info_data = get_debug_info_data(); |
| 1706 | uint32_t block_length = form_value.Unsigned(); |
| 1707 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1708 | if (DWARFExpression::Evaluate (NULL, |
| 1709 | NULL, |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1710 | NULL, |
| 1711 | NULL, |
| Jason Molenda | 2d107dd | 2010-11-20 01:28:30 +0000 | [diff] [blame] | 1712 | NULL, |
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 1713 | debug_info_data, |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1714 | block_offset, |
| 1715 | block_length, |
| 1716 | eRegisterKindDWARF, |
| 1717 | &initialValue, |
| 1718 | memberOffset, |
| 1719 | NULL)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1720 | { |
| 1721 | member_offset = memberOffset.ResolveValue(NULL, NULL).UInt(); |
| 1722 | } |
| 1723 | } |
| 1724 | break; |
| 1725 | |
| 1726 | case DW_AT_accessibility: |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1727 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1728 | break; |
| 1729 | |
| 1730 | case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break; |
| 1731 | default: |
| 1732 | case DW_AT_sibling: |
| 1733 | break; |
| 1734 | } |
| 1735 | } |
| 1736 | } |
| 1737 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 1738 | Type *base_class_type = ResolveTypeUID(encoding_uid); |
| 1739 | assert(base_class_type); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1740 | |
| Greg Clayton | f4ecaa5 | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 1741 | clang_type_t base_class_clang_type = base_class_type->GetClangFullType(); |
| 1742 | assert (base_class_clang_type); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1743 | if (class_language == eLanguageTypeObjC) |
| 1744 | { |
| Greg Clayton | f4ecaa5 | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 1745 | GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1746 | } |
| 1747 | else |
| 1748 | { |
| Greg Clayton | f4ecaa5 | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 1749 | base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type, |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1750 | accessibility, |
| 1751 | is_virtual, |
| 1752 | is_base_of_class)); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1753 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1754 | } |
| 1755 | } |
| 1756 | break; |
| 1757 | |
| 1758 | default: |
| 1759 | break; |
| 1760 | } |
| 1761 | } |
| 1762 | return count; |
| 1763 | } |
| 1764 | |
| 1765 | |
| 1766 | clang::DeclContext* |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 1767 | SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1768 | { |
| 1769 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1770 | if (debug_info && UserIDMatches(type_uid)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1771 | { |
| 1772 | DWARFCompileUnitSP cu_sp; |
| 1773 | const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp); |
| 1774 | if (die) |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 1775 | return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL); |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 1776 | } |
| 1777 | return NULL; |
| 1778 | } |
| 1779 | |
| 1780 | clang::DeclContext* |
| 1781 | SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid) |
| 1782 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1783 | if (UserIDMatches(type_uid)) |
| 1784 | return GetClangDeclContextForDIEOffset (sc, type_uid); |
| 1785 | return NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | Type* |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 1789 | SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1790 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1791 | if (UserIDMatches(type_uid)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1792 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1793 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 1794 | if (debug_info) |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 1795 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1796 | DWARFCompileUnitSP cu_sp; |
| 1797 | const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp); |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1798 | const bool assert_not_being_parsed = true; |
| 1799 | return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 1800 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1801 | } |
| 1802 | return NULL; |
| 1803 | } |
| 1804 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1805 | Type* |
| 1806 | SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed) |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1807 | { |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1808 | if (die != NULL) |
| 1809 | { |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1810 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| 1811 | if (log) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1812 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 1813 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'", |
| 1814 | die->GetOffset(), |
| 1815 | DW_TAG_value_to_name(die->Tag()), |
| 1816 | die->GetName(this, cu)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1817 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1818 | // We might be coming in in the middle of a type tree (a class |
| 1819 | // withing a class, an enum within a class), so parse any needed |
| 1820 | // parent DIEs before we get to this one... |
| 1821 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); |
| 1822 | switch (decl_ctx_die->Tag()) |
| 1823 | { |
| 1824 | case DW_TAG_structure_type: |
| 1825 | case DW_TAG_union_type: |
| 1826 | case DW_TAG_class_type: |
| 1827 | { |
| 1828 | // Get the type, which could be a forward declaration |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1829 | if (log) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1830 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 1831 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x", |
| 1832 | die->GetOffset(), |
| 1833 | DW_TAG_value_to_name(die->Tag()), |
| 1834 | die->GetName(this, cu), |
| 1835 | decl_ctx_die->GetOffset()); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1836 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1837 | Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1838 | if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag())) |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1839 | { |
| 1840 | if (log) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1841 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 1842 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function", |
| 1843 | die->GetOffset(), |
| 1844 | DW_TAG_value_to_name(die->Tag()), |
| 1845 | die->GetName(this, cu), |
| 1846 | decl_ctx_die->GetOffset()); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1847 | // Ask the type to complete itself if it already hasn't since if we |
| 1848 | // want a function (method or static) from a class, the class must |
| 1849 | // create itself and add it's own methods and class functions. |
| 1850 | if (parent_type) |
| 1851 | parent_type->GetClangFullType(); |
| 1852 | } |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1853 | } |
| 1854 | break; |
| 1855 | |
| 1856 | default: |
| 1857 | break; |
| 1858 | } |
| 1859 | return ResolveType (cu, die); |
| 1860 | } |
| 1861 | return NULL; |
| 1862 | } |
| 1863 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1864 | // This function is used when SymbolFileDWARFDebugMap owns a bunch of |
| 1865 | // SymbolFileDWARF objects to detect if this DWARF file is the one that |
| 1866 | // can resolve a clang_type. |
| 1867 | bool |
| 1868 | SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type) |
| 1869 | { |
| 1870 | clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type); |
| 1871 | const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers); |
| 1872 | return die != NULL; |
| 1873 | } |
| 1874 | |
| 1875 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1876 | lldb::clang_type_t |
| 1877 | SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type) |
| 1878 | { |
| 1879 | // We have a struct/union/class/enum that needs to be fully resolved. |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1880 | clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type); |
| 1881 | const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1882 | if (die == NULL) |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1883 | { |
| 1884 | // We have already resolved this type... |
| 1885 | return clang_type; |
| 1886 | } |
| 1887 | // Once we start resolving this type, remove it from the forward declaration |
| 1888 | // map in case anyone child members or other types require this type to get resolved. |
| 1889 | // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition |
| 1890 | // are done. |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1891 | m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers); |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1892 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1893 | |
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 1894 | // Disable external storage for this type so we don't get anymore |
| 1895 | // clang::ExternalASTSource queries for this type. |
| 1896 | ClangASTContext::SetHasExternalStorage (clang_type, false); |
| 1897 | |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 1898 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 1899 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1900 | DWARFCompileUnit *curr_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get(); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1901 | Type *type = m_die_to_type.lookup (die); |
| 1902 | |
| 1903 | const dw_tag_t tag = die->Tag(); |
| 1904 | |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1905 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| 1906 | if (log) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1907 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 1908 | "0x%8.8llx: %s '%s' resolving forward declaration...\n", |
| 1909 | MakeUserID(die->GetOffset()), |
| 1910 | DW_TAG_value_to_name(tag), |
| 1911 | type->GetName().AsCString()); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1912 | assert (clang_type); |
| 1913 | DWARFDebugInfoEntry::Attributes attributes; |
| 1914 | |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 1915 | ClangASTContext &ast = GetClangASTContext(); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1916 | |
| 1917 | switch (tag) |
| 1918 | { |
| 1919 | case DW_TAG_structure_type: |
| 1920 | case DW_TAG_union_type: |
| 1921 | case DW_TAG_class_type: |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1922 | { |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1923 | LayoutInfo layout_info; |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 1924 | |
| 1925 | ast.StartTagDeclarationDefinition (clang_type); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1926 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 1927 | if (die->HasChildren()) |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1928 | { |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1929 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 1930 | LanguageType class_language = eLanguageTypeUnknown; |
| 1931 | bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type); |
| 1932 | if (is_objc_class) |
| 1933 | class_language = eLanguageTypeObjC; |
| 1934 | |
| 1935 | int tag_decl_kind = -1; |
| 1936 | AccessType default_accessibility = eAccessNone; |
| 1937 | if (tag == DW_TAG_structure_type) |
| 1938 | { |
| 1939 | tag_decl_kind = clang::TTK_Struct; |
| 1940 | default_accessibility = eAccessPublic; |
| 1941 | } |
| 1942 | else if (tag == DW_TAG_union_type) |
| 1943 | { |
| 1944 | tag_decl_kind = clang::TTK_Union; |
| 1945 | default_accessibility = eAccessPublic; |
| 1946 | } |
| 1947 | else if (tag == DW_TAG_class_type) |
| 1948 | { |
| 1949 | tag_decl_kind = clang::TTK_Class; |
| 1950 | default_accessibility = eAccessPrivate; |
| 1951 | } |
| 1952 | |
| 1953 | SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu)); |
| 1954 | std::vector<clang::CXXBaseSpecifier *> base_classes; |
| 1955 | std::vector<int> member_accessibilities; |
| 1956 | bool is_a_class = false; |
| 1957 | // Parse members and base classes first |
| 1958 | DWARFDIECollection member_function_dies; |
| 1959 | |
| 1960 | ParseChildMembers (sc, |
| 1961 | curr_cu, |
| 1962 | die, |
| 1963 | clang_type, |
| 1964 | class_language, |
| 1965 | base_classes, |
| 1966 | member_accessibilities, |
| 1967 | member_function_dies, |
| 1968 | default_accessibility, |
| 1969 | is_a_class, |
| 1970 | layout_info); |
| 1971 | |
| 1972 | // Now parse any methods if there were any... |
| 1973 | size_t num_functions = member_function_dies.Size(); |
| 1974 | if (num_functions > 0) |
| 1975 | { |
| 1976 | for (size_t i=0; i<num_functions; ++i) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 1977 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 1978 | ResolveType(curr_cu, member_function_dies.GetDIEPtrAtIndex(i)); |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1979 | } |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 1980 | } |
| 1981 | |
| 1982 | if (class_language == eLanguageTypeObjC) |
| 1983 | { |
| 1984 | std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(clang_type)); |
| 1985 | if (!class_str.empty()) |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1986 | { |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 1987 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 1988 | DIEArray method_die_offsets; |
| 1989 | if (m_using_apple_tables) |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 1990 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 1991 | if (m_apple_objc_ap.get()) |
| 1992 | m_apple_objc_ap->FindByName(class_str.c_str(), method_die_offsets); |
| 1993 | } |
| 1994 | else |
| 1995 | { |
| 1996 | if (!m_indexed) |
| 1997 | Index (); |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1998 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 1999 | ConstString class_name (class_str.c_str()); |
| 2000 | m_objc_class_selectors_index.Find (class_name, method_die_offsets); |
| 2001 | } |
| 2002 | |
| 2003 | if (!method_die_offsets.empty()) |
| 2004 | { |
| 2005 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2006 | |
| 2007 | DWARFCompileUnit* method_cu = NULL; |
| 2008 | const size_t num_matches = method_die_offsets.size(); |
| 2009 | for (size_t i=0; i<num_matches; ++i) |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2010 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2011 | const dw_offset_t die_offset = method_die_offsets[i]; |
| 2012 | DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu); |
| 2013 | |
| 2014 | if (method_die) |
| 2015 | ResolveType (method_cu, method_die); |
| 2016 | else |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2017 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2018 | if (m_using_apple_tables) |
| 2019 | { |
| 2020 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n", |
| 2021 | die_offset, class_str.c_str()); |
| 2022 | } |
| 2023 | } |
| 2024 | } |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2025 | } |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2026 | } |
| 2027 | } |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2028 | |
| 2029 | // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we |
| 2030 | // need to tell the clang type it is actually a class. |
| 2031 | if (class_language != eLanguageTypeObjC) |
| 2032 | { |
| 2033 | if (is_a_class && tag_decl_kind != clang::TTK_Class) |
| 2034 | ast.SetTagTypeKind (clang_type, clang::TTK_Class); |
| 2035 | } |
| 2036 | |
| 2037 | // Since DW_TAG_structure_type gets used for both classes |
| 2038 | // and structures, we may need to set any DW_TAG_member |
| 2039 | // fields to have a "private" access if none was specified. |
| 2040 | // When we parsed the child members we tracked that actual |
| 2041 | // accessibility value for each DW_TAG_member in the |
| 2042 | // "member_accessibilities" array. If the value for the |
| 2043 | // member is zero, then it was set to the "default_accessibility" |
| 2044 | // which for structs was "public". Below we correct this |
| 2045 | // by setting any fields to "private" that weren't correctly |
| 2046 | // set. |
| 2047 | if (is_a_class && !member_accessibilities.empty()) |
| 2048 | { |
| 2049 | // This is a class and all members that didn't have |
| 2050 | // their access specified are private. |
| 2051 | ast.SetDefaultAccessForRecordFields (clang_type, |
| 2052 | eAccessPrivate, |
| 2053 | &member_accessibilities.front(), |
| 2054 | member_accessibilities.size()); |
| 2055 | } |
| 2056 | |
| 2057 | if (!base_classes.empty()) |
| 2058 | { |
| 2059 | ast.SetBaseClassesForClassType (clang_type, |
| 2060 | &base_classes.front(), |
| 2061 | base_classes.size()); |
| 2062 | |
| 2063 | // Clang will copy each CXXBaseSpecifier in "base_classes" |
| 2064 | // so we have to free them all. |
| 2065 | ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(), |
| 2066 | base_classes.size()); |
| 2067 | } |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2068 | } |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2069 | } |
| Sean Callanan | e8c0cfb | 2012-03-02 01:03:45 +0000 | [diff] [blame] | 2070 | |
| 2071 | ast.BuildIndirectFields (clang_type); |
| 2072 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2073 | ast.CompleteTagDeclarationDefinition (clang_type); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2074 | |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2075 | if (!layout_info.field_offsets.empty()) |
| 2076 | { |
| 2077 | if (type) |
| 2078 | layout_info.bit_size = type->GetByteSize() * 8; |
| 2079 | if (layout_info.bit_size == 0) |
| 2080 | layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, curr_cu, DW_AT_byte_size, 0) * 8; |
| 2081 | clang::QualType qual_type(clang::QualType::getFromOpaquePtr(clang_type)); |
| 2082 | const clang::RecordType *record_type = clang::dyn_cast<clang::RecordType>(qual_type.getTypePtr()); |
| 2083 | if (record_type) |
| 2084 | { |
| 2085 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 2086 | |
| 2087 | if (log) |
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2088 | { |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2089 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2090 | "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 | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2091 | clang_type, |
| 2092 | record_decl, |
| 2093 | layout_info.bit_size, |
| 2094 | layout_info.alignment, |
| 2095 | (uint32_t)layout_info.field_offsets.size()); |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2096 | |
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2097 | llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end(); |
| 2098 | for (pos = layout_info.field_offsets.begin(); pos != end; ++pos) |
| 2099 | { |
| 2100 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 2101 | "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field = { bit_offset=%u, name='%s' }", |
| 2102 | clang_type, |
| 2103 | (uint32_t)pos->second, |
| 2104 | pos->first->getNameAsString().c_str()); |
| 2105 | } |
| 2106 | } |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2107 | m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info)); |
| 2108 | } |
| 2109 | } |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2110 | } |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2111 | |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2112 | return clang_type; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2113 | |
| 2114 | case DW_TAG_enumeration_type: |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 2115 | ast.StartTagDeclarationDefinition (clang_type); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2116 | if (die->HasChildren()) |
| 2117 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2118 | SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu)); |
| 2119 | ParseChildEnumerators(sc, clang_type, type->GetByteSize(), curr_cu, die); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2120 | } |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 2121 | ast.CompleteTagDeclarationDefinition (clang_type); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2122 | return clang_type; |
| 2123 | |
| 2124 | default: |
| 2125 | assert(false && "not a forward clang type decl!"); |
| 2126 | break; |
| 2127 | } |
| 2128 | return NULL; |
| 2129 | } |
| 2130 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2131 | Type* |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2132 | SymbolFileDWARF::ResolveType (DWARFCompileUnit* curr_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed) |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2133 | { |
| 2134 | if (type_die != NULL) |
| 2135 | { |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 2136 | Type *type = m_die_to_type.lookup (type_die); |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2137 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2138 | if (type == NULL) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2139 | type = GetTypeForDIE (curr_cu, type_die).get(); |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2140 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2141 | if (assert_not_being_parsed) |
| Jim Ingham | c354928 | 2012-01-11 02:21:12 +0000 | [diff] [blame] | 2142 | { |
| 2143 | if (type != DIE_IS_BEING_PARSED) |
| 2144 | return type; |
| 2145 | |
| 2146 | GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s", |
| 2147 | type_die->GetOffset(), |
| 2148 | DW_TAG_value_to_name(type_die->Tag()), |
| 2149 | type_die->GetName(this, curr_cu)); |
| 2150 | |
| 2151 | } |
| 2152 | else |
| 2153 | return type; |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2154 | } |
| 2155 | return NULL; |
| 2156 | } |
| 2157 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2158 | CompileUnit* |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2159 | SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* curr_cu, uint32_t cu_idx) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2160 | { |
| 2161 | // Check if the symbol vendor already knows about this compile unit? |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2162 | if (curr_cu->GetUserData() == NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2163 | { |
| 2164 | // The symbol vendor doesn't know about this compile unit, we |
| 2165 | // need to parse and add it to the symbol vendor object. |
| 2166 | CompUnitSP dc_cu; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2167 | ParseCompileUnit(curr_cu, dc_cu); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2168 | if (dc_cu.get()) |
| 2169 | { |
| 2170 | // Figure out the compile unit index if we weren't given one |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 2171 | if (cu_idx == UINT32_MAX) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2172 | DebugInfo()->GetCompileUnit(curr_cu->GetOffset(), &cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2173 | |
| 2174 | m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(dc_cu, cu_idx); |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2175 | |
| 2176 | if (m_debug_map_symfile) |
| 2177 | m_debug_map_symfile->SetCompileUnit(this, dc_cu); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2178 | } |
| 2179 | } |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2180 | return (CompileUnit*)curr_cu->GetUserData(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2181 | } |
| 2182 | |
| 2183 | bool |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2184 | SymbolFileDWARF::GetFunction (DWARFCompileUnit* curr_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2185 | { |
| 2186 | sc.Clear(); |
| 2187 | // Check if the symbol vendor already knows about this compile unit? |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2188 | sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, UINT32_MAX); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2189 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2190 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2191 | if (sc.function == NULL) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2192 | sc.function = ParseCompileUnitFunction(sc, curr_cu, func_die); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2193 | |
| 2194 | if (sc.function) |
| 2195 | { |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 2196 | sc.module_sp = sc.function->CalculateSymbolContextModule(); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2197 | return true; |
| 2198 | } |
| 2199 | |
| 2200 | return false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2201 | } |
| 2202 | |
| 2203 | uint32_t |
| 2204 | SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) |
| 2205 | { |
| 2206 | Timer scoped_timer(__PRETTY_FUNCTION__, |
| 2207 | "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%llx }, resolve_scope = 0x%8.8x)", |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 2208 | so_addr.GetSection().get(), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2209 | so_addr.GetOffset(), |
| 2210 | resolve_scope); |
| 2211 | uint32_t resolved = 0; |
| 2212 | if (resolve_scope & ( eSymbolContextCompUnit | |
| 2213 | eSymbolContextFunction | |
| 2214 | eSymbolContextBlock | |
| 2215 | eSymbolContextLineEntry)) |
| 2216 | { |
| 2217 | lldb::addr_t file_vm_addr = so_addr.GetFileAddress(); |
| 2218 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2219 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2220 | if (debug_info) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2221 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2222 | dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2223 | if (cu_offset != DW_INVALID_OFFSET) |
| 2224 | { |
| 2225 | uint32_t cu_idx; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2226 | DWARFCompileUnit* curr_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get(); |
| 2227 | if (curr_cu) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2228 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2229 | sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2230 | assert(sc.comp_unit != NULL); |
| 2231 | resolved |= eSymbolContextCompUnit; |
| 2232 | |
| 2233 | if (resolve_scope & eSymbolContextLineEntry) |
| 2234 | { |
| 2235 | LineTable *line_table = sc.comp_unit->GetLineTable(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2236 | if (line_table != NULL) |
| 2237 | { |
| 2238 | if (so_addr.IsLinkedAddress()) |
| 2239 | { |
| 2240 | Address linked_addr (so_addr); |
| 2241 | linked_addr.ResolveLinkedAddress(); |
| 2242 | if (line_table->FindLineEntryByAddress (linked_addr, sc.line_entry)) |
| 2243 | { |
| 2244 | resolved |= eSymbolContextLineEntry; |
| 2245 | } |
| 2246 | } |
| 2247 | else if (line_table->FindLineEntryByAddress (so_addr, sc.line_entry)) |
| 2248 | { |
| 2249 | resolved |= eSymbolContextLineEntry; |
| 2250 | } |
| 2251 | } |
| 2252 | } |
| 2253 | |
| 2254 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) |
| 2255 | { |
| 2256 | DWARFDebugInfoEntry *function_die = NULL; |
| 2257 | DWARFDebugInfoEntry *block_die = NULL; |
| 2258 | if (resolve_scope & eSymbolContextBlock) |
| 2259 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2260 | curr_cu->LookupAddress(file_vm_addr, &function_die, &block_die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2261 | } |
| 2262 | else |
| 2263 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2264 | curr_cu->LookupAddress(file_vm_addr, &function_die, NULL); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2265 | } |
| 2266 | |
| 2267 | if (function_die != NULL) |
| 2268 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2269 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2270 | if (sc.function == NULL) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2271 | sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2272 | } |
| 2273 | |
| 2274 | if (sc.function != NULL) |
| 2275 | { |
| 2276 | resolved |= eSymbolContextFunction; |
| 2277 | |
| 2278 | if (resolve_scope & eSymbolContextBlock) |
| 2279 | { |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 2280 | Block& block = sc.function->GetBlock (true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2281 | |
| 2282 | if (block_die != NULL) |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2283 | sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2284 | else |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2285 | sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2286 | if (sc.block) |
| 2287 | resolved |= eSymbolContextBlock; |
| 2288 | } |
| 2289 | } |
| 2290 | } |
| 2291 | } |
| 2292 | } |
| 2293 | } |
| 2294 | } |
| 2295 | return resolved; |
| 2296 | } |
| 2297 | |
| 2298 | |
| 2299 | |
| 2300 | uint32_t |
| 2301 | SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) |
| 2302 | { |
| 2303 | const uint32_t prev_size = sc_list.GetSize(); |
| 2304 | if (resolve_scope & eSymbolContextCompUnit) |
| 2305 | { |
| 2306 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2307 | if (debug_info) |
| 2308 | { |
| 2309 | uint32_t cu_idx; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2310 | DWARFCompileUnit* curr_cu = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2311 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2312 | for (cu_idx = 0; (curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2313 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2314 | CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2315 | bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Compare(file_spec, *dc_cu, false) == 0; |
| 2316 | if (check_inlines || file_spec_matches_cu_file_spec) |
| 2317 | { |
| 2318 | SymbolContext sc (m_obj_file->GetModule()); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2319 | sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2320 | assert(sc.comp_unit != NULL); |
| 2321 | |
| 2322 | uint32_t file_idx = UINT32_MAX; |
| 2323 | |
| 2324 | // If we are looking for inline functions only and we don't |
| 2325 | // find it in the support files, we are done. |
| 2326 | if (check_inlines) |
| 2327 | { |
| Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 2328 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2329 | if (file_idx == UINT32_MAX) |
| 2330 | continue; |
| 2331 | } |
| 2332 | |
| 2333 | if (line != 0) |
| 2334 | { |
| 2335 | LineTable *line_table = sc.comp_unit->GetLineTable(); |
| 2336 | |
| 2337 | if (line_table != NULL && line != 0) |
| 2338 | { |
| 2339 | // We will have already looked up the file index if |
| 2340 | // we are searching for inline entries. |
| 2341 | if (!check_inlines) |
| Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 2342 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2343 | |
| 2344 | if (file_idx != UINT32_MAX) |
| 2345 | { |
| 2346 | uint32_t found_line; |
| 2347 | uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry); |
| 2348 | found_line = sc.line_entry.line; |
| 2349 | |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 2350 | while (line_idx != UINT32_MAX) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2351 | { |
| 2352 | sc.function = NULL; |
| 2353 | sc.block = NULL; |
| 2354 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) |
| 2355 | { |
| 2356 | const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress(); |
| 2357 | if (file_vm_addr != LLDB_INVALID_ADDRESS) |
| 2358 | { |
| 2359 | DWARFDebugInfoEntry *function_die = NULL; |
| 2360 | DWARFDebugInfoEntry *block_die = NULL; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2361 | curr_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2362 | |
| 2363 | if (function_die != NULL) |
| 2364 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2365 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2366 | if (sc.function == NULL) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2367 | sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2368 | } |
| 2369 | |
| 2370 | if (sc.function != NULL) |
| 2371 | { |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 2372 | Block& block = sc.function->GetBlock (true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2373 | |
| 2374 | if (block_die != NULL) |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2375 | sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2376 | else |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2377 | sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2378 | } |
| 2379 | } |
| 2380 | } |
| 2381 | |
| 2382 | sc_list.Append(sc); |
| 2383 | line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry); |
| 2384 | } |
| 2385 | } |
| 2386 | } |
| 2387 | else if (file_spec_matches_cu_file_spec && !check_inlines) |
| 2388 | { |
| 2389 | // only append the context if we aren't looking for inline call sites |
| 2390 | // by file and line and if the file spec matches that of the compile unit |
| 2391 | sc_list.Append(sc); |
| 2392 | } |
| 2393 | } |
| 2394 | else if (file_spec_matches_cu_file_spec && !check_inlines) |
| 2395 | { |
| 2396 | // only append the context if we aren't looking for inline call sites |
| 2397 | // by file and line and if the file spec matches that of the compile unit |
| 2398 | sc_list.Append(sc); |
| 2399 | } |
| 2400 | |
| 2401 | if (!check_inlines) |
| 2402 | break; |
| 2403 | } |
| 2404 | } |
| 2405 | } |
| 2406 | } |
| 2407 | return sc_list.GetSize() - prev_size; |
| 2408 | } |
| 2409 | |
| 2410 | void |
| 2411 | SymbolFileDWARF::Index () |
| 2412 | { |
| 2413 | if (m_indexed) |
| 2414 | return; |
| 2415 | m_indexed = true; |
| 2416 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 2417 | "SymbolFileDWARF::Index (%s)", |
| 2418 | GetObjectFile()->GetFileSpec().GetFilename().AsCString()); |
| 2419 | |
| 2420 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2421 | if (debug_info) |
| 2422 | { |
| 2423 | uint32_t cu_idx = 0; |
| 2424 | const uint32_t num_compile_units = GetNumCompileUnits(); |
| 2425 | for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) |
| 2426 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2427 | DWARFCompileUnit* curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2428 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2429 | bool clear_dies = curr_cu->ExtractDIEsIfNeeded (false) > 1; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2430 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2431 | curr_cu->Index (cu_idx, |
| Greg Clayton | 83c5cd9 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 2432 | m_function_basename_index, |
| 2433 | m_function_fullname_index, |
| 2434 | m_function_method_index, |
| 2435 | m_function_selector_index, |
| 2436 | m_objc_class_selectors_index, |
| 2437 | m_global_index, |
| 2438 | m_type_index, |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2439 | m_namespace_index); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2440 | |
| 2441 | // Keep memory down by clearing DIEs if this generate function |
| 2442 | // caused them to be parsed |
| 2443 | if (clear_dies) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2444 | curr_cu->ClearDIEs (true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2445 | } |
| 2446 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2447 | m_function_basename_index.Finalize(); |
| 2448 | m_function_fullname_index.Finalize(); |
| 2449 | m_function_method_index.Finalize(); |
| 2450 | m_function_selector_index.Finalize(); |
| 2451 | m_objc_class_selectors_index.Finalize(); |
| 2452 | m_global_index.Finalize(); |
| 2453 | m_type_index.Finalize(); |
| 2454 | m_namespace_index.Finalize(); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2455 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2456 | #if defined (ENABLE_DEBUG_PRINTF) |
| Greg Clayton | 7bd65b9 | 2011-02-09 23:39:34 +0000 | [diff] [blame] | 2457 | StreamFile s(stdout, false); |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 2458 | s.Printf ("DWARF index for '%s/%s':", |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2459 | GetObjectFile()->GetFileSpec().GetDirectory().AsCString(), |
| 2460 | GetObjectFile()->GetFileSpec().GetFilename().AsCString()); |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 2461 | s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s); |
| 2462 | s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s); |
| 2463 | s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s); |
| 2464 | s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s); |
| 2465 | s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s); |
| 2466 | s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s); |
| Greg Clayton | 69b0488 | 2010-10-15 02:03:22 +0000 | [diff] [blame] | 2467 | s.Printf("\nTypes:\n"); m_type_index.Dump (&s); |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 2468 | s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2469 | #endif |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2470 | } |
| 2471 | } |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2472 | |
| 2473 | bool |
| 2474 | SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl) |
| 2475 | { |
| 2476 | if (namespace_decl == NULL) |
| 2477 | { |
| 2478 | // Invalid namespace decl which means we aren't matching only things |
| 2479 | // in this symbol file, so return true to indicate it matches this |
| 2480 | // symbol file. |
| 2481 | return true; |
| 2482 | } |
| 2483 | |
| 2484 | clang::ASTContext *namespace_ast = namespace_decl->GetASTContext(); |
| 2485 | |
| 2486 | if (namespace_ast == NULL) |
| 2487 | return true; // No AST in the "namespace_decl", return true since it |
| 2488 | // could then match any symbol file, including this one |
| 2489 | |
| 2490 | if (namespace_ast == GetClangASTContext().getASTContext()) |
| 2491 | return true; // The ASTs match, return true |
| 2492 | |
| 2493 | // The namespace AST was valid, and it does not match... |
| Sean Callanan | c41e68b | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 2494 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 2495 | |
| 2496 | if (log) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2497 | GetObjectFile()->GetModule()->LogMessage(log.get(), "Valid namespace does not match symbol file"); |
| Sean Callanan | c41e68b | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 2498 | |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2499 | return false; |
| 2500 | } |
| 2501 | |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2502 | bool |
| 2503 | SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl, |
| 2504 | DWARFCompileUnit* cu, |
| 2505 | const DWARFDebugInfoEntry* die) |
| 2506 | { |
| 2507 | // No namespace specified, so the answesr i |
| 2508 | if (namespace_decl == NULL) |
| 2509 | return true; |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2510 | |
| 2511 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2512 | |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2513 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); |
| 2514 | if (decl_ctx_die) |
| 2515 | { |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2516 | |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2517 | clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl(); |
| 2518 | if (clang_namespace_decl) |
| 2519 | { |
| 2520 | if (decl_ctx_die->Tag() != DW_TAG_namespace) |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2521 | { |
| 2522 | if (log) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2523 | GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent is not a namespace"); |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2524 | return false; |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2525 | } |
| 2526 | |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2527 | DeclContextToDIEMap::iterator pos = m_decl_ctx_to_die.find(clang_namespace_decl); |
| 2528 | |
| 2529 | if (pos == m_decl_ctx_to_die.end()) |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2530 | { |
| 2531 | if (log) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2532 | GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match in a namespace, but its parent is not the requested namespace"); |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2533 | |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2534 | return false; |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2535 | } |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2536 | |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 2537 | return pos->second.count (decl_ctx_die); |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2538 | } |
| 2539 | else |
| 2540 | { |
| 2541 | // We have a namespace_decl that was not NULL but it contained |
| 2542 | // a NULL "clang::NamespaceDecl", so this means the global namespace |
| 2543 | // So as long the the contained decl context DIE isn't a namespace |
| 2544 | // we should be ok. |
| 2545 | if (decl_ctx_die->Tag() != DW_TAG_namespace) |
| 2546 | return true; |
| 2547 | } |
| 2548 | } |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2549 | |
| 2550 | if (log) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2551 | GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent doesn't exist"); |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2552 | |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2553 | return false; |
| 2554 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2555 | uint32_t |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2556 | SymbolFileDWARF::FindGlobalVariables (const ConstString &name, const lldb_private::ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, VariableList& variables) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2557 | { |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2558 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 2559 | |
| 2560 | if (log) |
| 2561 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2562 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 2563 | "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)", |
| 2564 | name.GetCString(), |
| 2565 | namespace_decl, |
| 2566 | append, |
| 2567 | max_matches); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2568 | } |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2569 | |
| 2570 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) |
| 2571 | return 0; |
| 2572 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2573 | DWARFDebugInfo* info = DebugInfo(); |
| 2574 | if (info == NULL) |
| 2575 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2576 | |
| 2577 | // If we aren't appending the results to this list, then clear the list |
| 2578 | if (!append) |
| 2579 | variables.Clear(); |
| 2580 | |
| 2581 | // Remember how many variables are in the list before we search in case |
| 2582 | // we are appending the results to a variable list. |
| 2583 | const uint32_t original_size = variables.GetSize(); |
| 2584 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2585 | DIEArray die_offsets; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2586 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2587 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2588 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2589 | if (m_apple_names_ap.get()) |
| 2590 | { |
| 2591 | const char *name_cstr = name.GetCString(); |
| 2592 | const char *base_name_start; |
| 2593 | const char *base_name_end = NULL; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2594 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2595 | if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end)) |
| 2596 | base_name_start = name_cstr; |
| 2597 | |
| 2598 | m_apple_names_ap->FindByName (base_name_start, die_offsets); |
| 2599 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2600 | } |
| 2601 | else |
| 2602 | { |
| 2603 | // Index the DWARF if we haven't already |
| 2604 | if (!m_indexed) |
| 2605 | Index (); |
| 2606 | |
| 2607 | m_global_index.Find (name, die_offsets); |
| 2608 | } |
| 2609 | |
| 2610 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2611 | if (num_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2612 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2613 | SymbolContext sc; |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 2614 | sc.module_sp = m_obj_file->GetModule(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2615 | assert (sc.module_sp); |
| 2616 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2617 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2618 | DWARFCompileUnit* dwarf_cu = NULL; |
| 2619 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2620 | for (size_t i=0; i<num_matches; ++i) |
| 2621 | { |
| 2622 | const dw_offset_t die_offset = die_offsets[i]; |
| 2623 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2624 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2625 | if (die) |
| 2626 | { |
| 2627 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| 2628 | assert(sc.comp_unit != NULL); |
| 2629 | |
| 2630 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 2631 | continue; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2632 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2633 | ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2634 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2635 | if (variables.GetSize() - original_size >= max_matches) |
| 2636 | break; |
| 2637 | } |
| 2638 | else |
| 2639 | { |
| 2640 | if (m_using_apple_tables) |
| 2641 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2642 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n", |
| 2643 | die_offset, name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2644 | } |
| 2645 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2646 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2647 | } |
| 2648 | |
| 2649 | // Return the number of variable that were appended to the list |
| 2650 | return variables.GetSize() - original_size; |
| 2651 | } |
| 2652 | |
| 2653 | uint32_t |
| 2654 | SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables) |
| 2655 | { |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2656 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 2657 | |
| 2658 | if (log) |
| 2659 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2660 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 2661 | "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)", |
| 2662 | regex.GetText(), |
| 2663 | append, |
| 2664 | max_matches); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2665 | } |
| 2666 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2667 | DWARFDebugInfo* info = DebugInfo(); |
| 2668 | if (info == NULL) |
| 2669 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2670 | |
| 2671 | // If we aren't appending the results to this list, then clear the list |
| 2672 | if (!append) |
| 2673 | variables.Clear(); |
| 2674 | |
| 2675 | // Remember how many variables are in the list before we search in case |
| 2676 | // we are appending the results to a variable list. |
| 2677 | const uint32_t original_size = variables.GetSize(); |
| 2678 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2679 | DIEArray die_offsets; |
| 2680 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2681 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2682 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2683 | if (m_apple_names_ap.get()) |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 2684 | { |
| 2685 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 2686 | if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) |
| 2687 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| 2688 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2689 | } |
| 2690 | else |
| 2691 | { |
| 2692 | // Index the DWARF if we haven't already |
| 2693 | if (!m_indexed) |
| 2694 | Index (); |
| 2695 | |
| 2696 | m_global_index.Find (regex, die_offsets); |
| 2697 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2698 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2699 | SymbolContext sc; |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 2700 | sc.module_sp = m_obj_file->GetModule(); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2701 | assert (sc.module_sp); |
| 2702 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2703 | DWARFCompileUnit* dwarf_cu = NULL; |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2704 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2705 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2706 | if (num_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2707 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2708 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2709 | for (size_t i=0; i<num_matches; ++i) |
| 2710 | { |
| 2711 | const dw_offset_t die_offset = die_offsets[i]; |
| 2712 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2713 | |
| 2714 | if (die) |
| 2715 | { |
| 2716 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2717 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2718 | ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2719 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2720 | if (variables.GetSize() - original_size >= max_matches) |
| 2721 | break; |
| 2722 | } |
| 2723 | else |
| 2724 | { |
| 2725 | if (m_using_apple_tables) |
| 2726 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2727 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n", |
| 2728 | die_offset, regex.GetText()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2729 | } |
| 2730 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2731 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2732 | } |
| 2733 | |
| 2734 | // Return the number of variable that were appended to the list |
| 2735 | return variables.GetSize() - original_size; |
| 2736 | } |
| 2737 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2738 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2739 | bool |
| 2740 | SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset, |
| 2741 | DWARFCompileUnit *&dwarf_cu, |
| 2742 | SymbolContextList& sc_list) |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2743 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2744 | const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| 2745 | return ResolveFunction (dwarf_cu, die, sc_list); |
| 2746 | } |
| 2747 | |
| 2748 | |
| 2749 | bool |
| 2750 | SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu, |
| 2751 | const DWARFDebugInfoEntry *die, |
| 2752 | SymbolContextList& sc_list) |
| 2753 | { |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2754 | SymbolContext sc; |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2755 | |
| 2756 | if (die == NULL) |
| 2757 | return false; |
| 2758 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2759 | // If we were passed a die that is not a function, just return false... |
| 2760 | if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine) |
| 2761 | return false; |
| 2762 | |
| 2763 | const DWARFDebugInfoEntry* inlined_die = NULL; |
| 2764 | if (die->Tag() == DW_TAG_inlined_subroutine) |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2765 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2766 | inlined_die = die; |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2767 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2768 | while ((die = die->GetParent()) != NULL) |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 2769 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2770 | if (die->Tag() == DW_TAG_subprogram) |
| 2771 | break; |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2772 | } |
| 2773 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2774 | assert (die->Tag() == DW_TAG_subprogram); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2775 | if (GetFunction (cu, die, sc)) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2776 | { |
| 2777 | Address addr; |
| 2778 | // Parse all blocks if needed |
| 2779 | if (inlined_die) |
| 2780 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2781 | sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset())); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2782 | assert (sc.block != NULL); |
| 2783 | if (sc.block->GetStartAddress (addr) == false) |
| 2784 | addr.Clear(); |
| 2785 | } |
| 2786 | else |
| 2787 | { |
| 2788 | sc.block = NULL; |
| 2789 | addr = sc.function->GetAddressRange().GetBaseAddress(); |
| 2790 | } |
| 2791 | |
| 2792 | if (addr.IsValid()) |
| 2793 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2794 | sc_list.Append(sc); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2795 | return true; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2796 | } |
| 2797 | } |
| 2798 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2799 | return false; |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2800 | } |
| 2801 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2802 | void |
| 2803 | SymbolFileDWARF::FindFunctions (const ConstString &name, |
| 2804 | const NameToDIE &name_to_die, |
| 2805 | SymbolContextList& sc_list) |
| 2806 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2807 | DIEArray die_offsets; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2808 | if (name_to_die.Find (name, die_offsets)) |
| 2809 | { |
| 2810 | ParseFunctions (die_offsets, sc_list); |
| 2811 | } |
| 2812 | } |
| 2813 | |
| 2814 | |
| 2815 | void |
| 2816 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, |
| 2817 | const NameToDIE &name_to_die, |
| 2818 | SymbolContextList& sc_list) |
| 2819 | { |
| 2820 | DIEArray die_offsets; |
| 2821 | if (name_to_die.Find (regex, die_offsets)) |
| 2822 | { |
| 2823 | ParseFunctions (die_offsets, sc_list); |
| 2824 | } |
| 2825 | } |
| 2826 | |
| 2827 | |
| 2828 | void |
| 2829 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, |
| 2830 | const DWARFMappedHash::MemoryTable &memory_table, |
| 2831 | SymbolContextList& sc_list) |
| 2832 | { |
| 2833 | DIEArray die_offsets; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 2834 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 2835 | if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2836 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 2837 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2838 | ParseFunctions (die_offsets, sc_list); |
| 2839 | } |
| 2840 | } |
| 2841 | |
| 2842 | void |
| 2843 | SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets, |
| 2844 | SymbolContextList& sc_list) |
| 2845 | { |
| 2846 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2847 | if (num_matches) |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2848 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2849 | SymbolContext sc; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2850 | |
| 2851 | DWARFCompileUnit* dwarf_cu = NULL; |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2852 | for (size_t i=0; i<num_matches; ++i) |
| Greg Clayton | d7e0546 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 2853 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2854 | const dw_offset_t die_offset = die_offsets[i]; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2855 | ResolveFunction (die_offset, dwarf_cu, sc_list); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2856 | } |
| 2857 | } |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2858 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2859 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2860 | bool |
| 2861 | SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die, |
| 2862 | const DWARFCompileUnit *dwarf_cu, |
| 2863 | uint32_t name_type_mask, |
| 2864 | const char *partial_name, |
| 2865 | const char *base_name_start, |
| 2866 | const char *base_name_end) |
| 2867 | { |
| 2868 | // If we are looking only for methods, throw away all the ones that aren't in C++ classes: |
| 2869 | if (name_type_mask == eFunctionNameTypeMethod |
| 2870 | || name_type_mask == eFunctionNameTypeBase) |
| 2871 | { |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 2872 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset()); |
| 2873 | if (!containing_decl_ctx) |
| 2874 | return false; |
| 2875 | |
| 2876 | bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()); |
| 2877 | |
| 2878 | if (!is_cxx_method && name_type_mask == eFunctionNameTypeMethod) |
| 2879 | return false; |
| 2880 | if (is_cxx_method && name_type_mask == eFunctionNameTypeBase) |
| 2881 | return false; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2882 | } |
| 2883 | |
| 2884 | // Now we need to check whether the name we got back for this type matches the extra specifications |
| 2885 | // that were in the name we're looking up: |
| 2886 | if (base_name_start != partial_name || *base_name_end != '\0') |
| 2887 | { |
| 2888 | // First see if the stuff to the left matches the full name. To do that let's see if |
| 2889 | // we can pull out the mips linkage name attribute: |
| 2890 | |
| 2891 | Mangled best_name; |
| 2892 | |
| 2893 | DWARFDebugInfoEntry::Attributes attributes; |
| 2894 | die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| 2895 | uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name); |
| 2896 | if (idx != UINT32_MAX) |
| 2897 | { |
| 2898 | DWARFFormValue form_value; |
| 2899 | if (attributes.ExtractFormValueAtIndex(this, idx, form_value)) |
| 2900 | { |
| 2901 | const char *name = form_value.AsCString(&get_debug_str_data()); |
| 2902 | best_name.SetValue (name, true); |
| 2903 | } |
| 2904 | } |
| 2905 | if (best_name) |
| 2906 | { |
| 2907 | const char *demangled = best_name.GetDemangledName().GetCString(); |
| 2908 | if (demangled) |
| 2909 | { |
| 2910 | std::string name_no_parens(partial_name, base_name_end - partial_name); |
| Jim Ingham | 85c13d7 | 2012-03-02 02:24:42 +0000 | [diff] [blame^] | 2911 | const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str()); |
| 2912 | if (partial_in_demangled == NULL) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2913 | return false; |
| Jim Ingham | 85c13d7 | 2012-03-02 02:24:42 +0000 | [diff] [blame^] | 2914 | else |
| 2915 | { |
| 2916 | // Sort out the case where our name is something like "Process::Destroy" and the match is |
| 2917 | // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on |
| 2918 | // namespace boundaries... |
| 2919 | |
| 2920 | if (partial_name[0] == ':' && partial_name[1] == ':') |
| 2921 | { |
| 2922 | // The partial name was already on a namespace boundary so all matches are good. |
| 2923 | return true; |
| 2924 | } |
| 2925 | else if (partial_in_demangled == demangled) |
| 2926 | { |
| 2927 | // They both start the same, so this is an good match. |
| 2928 | return true; |
| 2929 | } |
| 2930 | else |
| 2931 | { |
| 2932 | if (partial_in_demangled - demangled == 1) |
| 2933 | { |
| 2934 | // Only one character difference, can't be a namespace boundary... |
| 2935 | return false; |
| 2936 | } |
| 2937 | else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':') |
| 2938 | { |
| 2939 | // We are on a namespace boundary, so this is also good. |
| 2940 | return true; |
| 2941 | } |
| 2942 | else |
| 2943 | return false; |
| 2944 | } |
| 2945 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2946 | } |
| 2947 | } |
| 2948 | } |
| 2949 | |
| 2950 | return true; |
| 2951 | } |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2952 | |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2953 | uint32_t |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 2954 | SymbolFileDWARF::FindFunctions (const ConstString &name, |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2955 | const lldb_private::ClangNamespaceDecl *namespace_decl, |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 2956 | uint32_t name_type_mask, |
| 2957 | bool include_inlines, |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 2958 | bool append, |
| 2959 | SymbolContextList& sc_list) |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2960 | { |
| 2961 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 2962 | "SymbolFileDWARF::FindFunctions (name = '%s')", |
| 2963 | name.AsCString()); |
| 2964 | |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2965 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 2966 | |
| 2967 | if (log) |
| 2968 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2969 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 2970 | "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)", |
| 2971 | name.GetCString(), |
| 2972 | name_type_mask, |
| 2973 | append); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2974 | } |
| 2975 | |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2976 | // If we aren't appending the results to this list, then clear the list |
| 2977 | if (!append) |
| 2978 | sc_list.Clear(); |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2979 | |
| 2980 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) |
| 2981 | return 0; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2982 | |
| 2983 | // If name is empty then we won't find anything. |
| 2984 | if (name.IsEmpty()) |
| 2985 | return 0; |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2986 | |
| 2987 | // Remember how many sc_list are in the list before we search in case |
| 2988 | // we are appending the results to a variable list. |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2989 | |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2990 | const uint32_t original_size = sc_list.GetSize(); |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2991 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2992 | const char *name_cstr = name.GetCString(); |
| 2993 | uint32_t effective_name_type_mask = eFunctionNameTypeNone; |
| 2994 | const char *base_name_start = name_cstr; |
| 2995 | const char *base_name_end = name_cstr + strlen(name_cstr); |
| 2996 | |
| 2997 | if (name_type_mask & eFunctionNameTypeAuto) |
| 2998 | { |
| 2999 | if (CPPLanguageRuntime::IsCPPMangledName (name_cstr)) |
| 3000 | effective_name_type_mask = eFunctionNameTypeFull; |
| 3001 | else if (ObjCLanguageRuntime::IsPossibleObjCMethodName (name_cstr)) |
| 3002 | effective_name_type_mask = eFunctionNameTypeFull; |
| 3003 | else |
| 3004 | { |
| 3005 | if (ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr)) |
| 3006 | effective_name_type_mask |= eFunctionNameTypeSelector; |
| 3007 | |
| 3008 | if (CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end)) |
| 3009 | effective_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase); |
| 3010 | } |
| 3011 | } |
| 3012 | else |
| 3013 | { |
| 3014 | effective_name_type_mask = name_type_mask; |
| 3015 | if (effective_name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase) |
| 3016 | { |
| 3017 | // If they've asked for a CPP method or function name and it can't be that, we don't |
| 3018 | // even need to search for CPP methods or names. |
| 3019 | if (!CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end)) |
| 3020 | { |
| 3021 | effective_name_type_mask &= ~(eFunctionNameTypeMethod | eFunctionNameTypeBase); |
| 3022 | if (effective_name_type_mask == eFunctionNameTypeNone) |
| 3023 | return 0; |
| 3024 | } |
| 3025 | } |
| 3026 | |
| 3027 | if (effective_name_type_mask & eFunctionNameTypeSelector) |
| 3028 | { |
| 3029 | if (!ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr)) |
| 3030 | { |
| 3031 | effective_name_type_mask &= ~(eFunctionNameTypeSelector); |
| 3032 | if (effective_name_type_mask == eFunctionNameTypeNone) |
| 3033 | return 0; |
| 3034 | } |
| 3035 | } |
| 3036 | } |
| 3037 | |
| 3038 | DWARFDebugInfo* info = DebugInfo(); |
| 3039 | if (info == NULL) |
| 3040 | return 0; |
| 3041 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3042 | DWARFCompileUnit *dwarf_cu = NULL; |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3043 | if (m_using_apple_tables) |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 3044 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3045 | if (m_apple_names_ap.get()) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3046 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3047 | |
| 3048 | DIEArray die_offsets; |
| 3049 | |
| 3050 | uint32_t num_matches = 0; |
| 3051 | |
| 3052 | if (effective_name_type_mask & eFunctionNameTypeFull) |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3053 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3054 | // If they asked for the full name, match what they typed. At some point we may |
| 3055 | // want to canonicalize this (strip double spaces, etc. For now, we just add all the |
| 3056 | // dies that we find by exact match. |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3057 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3058 | for (uint32_t i = 0; i < num_matches; i++) |
| 3059 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3060 | const dw_offset_t die_offset = die_offsets[i]; |
| 3061 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3062 | if (die) |
| 3063 | { |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3064 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3065 | continue; |
| 3066 | |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3067 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) |
| 3068 | continue; |
| 3069 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3070 | ResolveFunction (dwarf_cu, die, sc_list); |
| 3071 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3072 | else |
| 3073 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3074 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 3075 | die_offset, name_cstr); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3076 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3077 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3078 | } |
| 3079 | else |
| 3080 | { |
| 3081 | if (effective_name_type_mask & eFunctionNameTypeSelector) |
| 3082 | { |
| 3083 | if (namespace_decl && *namespace_decl) |
| 3084 | return 0; // no selectors in namespaces |
| 3085 | |
| 3086 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); |
| 3087 | // Now make sure these are actually ObjC methods. In this case we can simply look up the name, |
| 3088 | // and if it is an ObjC method name, we're good. |
| 3089 | |
| 3090 | for (uint32_t i = 0; i < num_matches; i++) |
| 3091 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3092 | const dw_offset_t die_offset = die_offsets[i]; |
| 3093 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3094 | if (die) |
| 3095 | { |
| 3096 | const char *die_name = die->GetName(this, dwarf_cu); |
| 3097 | if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name)) |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3098 | { |
| 3099 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) |
| 3100 | continue; |
| 3101 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3102 | ResolveFunction (dwarf_cu, die, sc_list); |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3103 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3104 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3105 | else |
| 3106 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3107 | GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 3108 | die_offset, name_cstr); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3109 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3110 | } |
| 3111 | die_offsets.clear(); |
| 3112 | } |
| 3113 | |
| 3114 | if (effective_name_type_mask & eFunctionNameTypeMethod |
| 3115 | || effective_name_type_mask & eFunctionNameTypeBase) |
| 3116 | { |
| 3117 | if ((effective_name_type_mask & eFunctionNameTypeMethod) && |
| 3118 | (namespace_decl && *namespace_decl)) |
| 3119 | return 0; // no methods in namespaces |
| 3120 | |
| 3121 | // The apple_names table stores just the "base name" of C++ methods in the table. So we have to |
| 3122 | // extract the base name, look that up, and if there is any other information in the name we were |
| 3123 | // passed in we have to post-filter based on that. |
| 3124 | |
| 3125 | // FIXME: Arrange the logic above so that we don't calculate the base name twice: |
| 3126 | std::string base_name(base_name_start, base_name_end - base_name_start); |
| 3127 | num_matches = m_apple_names_ap->FindByName (base_name.c_str(), die_offsets); |
| 3128 | |
| 3129 | for (uint32_t i = 0; i < num_matches; i++) |
| 3130 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3131 | const dw_offset_t die_offset = die_offsets[i]; |
| 3132 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3133 | if (die) |
| 3134 | { |
| 3135 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3136 | continue; |
| 3137 | |
| 3138 | if (!FunctionDieMatchesPartialName(die, |
| 3139 | dwarf_cu, |
| 3140 | effective_name_type_mask, |
| 3141 | name_cstr, |
| 3142 | base_name_start, |
| 3143 | base_name_end)) |
| 3144 | continue; |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3145 | |
| 3146 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) |
| 3147 | continue; |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3148 | |
| 3149 | // If we get to here, the die is good, and we should add it: |
| 3150 | ResolveFunction (dwarf_cu, die, sc_list); |
| 3151 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3152 | else |
| 3153 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3154 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 3155 | die_offset, name_cstr); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3156 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3157 | } |
| 3158 | die_offsets.clear(); |
| 3159 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3160 | } |
| 3161 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3162 | } |
| 3163 | else |
| 3164 | { |
| 3165 | |
| 3166 | // Index the DWARF if we haven't already |
| 3167 | if (!m_indexed) |
| 3168 | Index (); |
| 3169 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3170 | if (name_type_mask & eFunctionNameTypeFull) |
| 3171 | FindFunctions (name, m_function_fullname_index, sc_list); |
| 3172 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3173 | std::string base_name(base_name_start, base_name_end - base_name_start); |
| 3174 | ConstString base_name_const(base_name.c_str()); |
| 3175 | DIEArray die_offsets; |
| 3176 | DWARFCompileUnit *dwarf_cu = NULL; |
| 3177 | |
| 3178 | if (effective_name_type_mask & eFunctionNameTypeBase) |
| 3179 | { |
| 3180 | uint32_t num_base = m_function_basename_index.Find(base_name_const, die_offsets); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3181 | for (uint32_t i = 0; i < num_base; i++) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3182 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3183 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); |
| 3184 | if (die) |
| 3185 | { |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3186 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3187 | continue; |
| 3188 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3189 | if (!FunctionDieMatchesPartialName(die, |
| 3190 | dwarf_cu, |
| 3191 | effective_name_type_mask, |
| 3192 | name_cstr, |
| 3193 | base_name_start, |
| 3194 | base_name_end)) |
| 3195 | continue; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3196 | |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3197 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) |
| 3198 | continue; |
| 3199 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3200 | // If we get to here, the die is good, and we should add it: |
| 3201 | ResolveFunction (dwarf_cu, die, sc_list); |
| 3202 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3203 | } |
| 3204 | die_offsets.clear(); |
| 3205 | } |
| 3206 | |
| Jim Ingham | ea8005a | 2011-10-11 01:18:11 +0000 | [diff] [blame] | 3207 | if (effective_name_type_mask & eFunctionNameTypeMethod) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3208 | { |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3209 | if (namespace_decl && *namespace_decl) |
| 3210 | return 0; // no methods in namespaces |
| 3211 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3212 | uint32_t num_base = m_function_method_index.Find(base_name_const, die_offsets); |
| 3213 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3214 | for (uint32_t i = 0; i < num_base; i++) |
| 3215 | { |
| 3216 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); |
| 3217 | if (die) |
| 3218 | { |
| 3219 | if (!FunctionDieMatchesPartialName(die, |
| 3220 | dwarf_cu, |
| 3221 | effective_name_type_mask, |
| 3222 | name_cstr, |
| 3223 | base_name_start, |
| 3224 | base_name_end)) |
| 3225 | continue; |
| 3226 | |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3227 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) |
| 3228 | continue; |
| 3229 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3230 | // If we get to here, the die is good, and we should add it: |
| 3231 | ResolveFunction (dwarf_cu, die, sc_list); |
| 3232 | } |
| 3233 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3234 | } |
| 3235 | die_offsets.clear(); |
| 3236 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3237 | |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3238 | if ((effective_name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl)) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3239 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3240 | FindFunctions (name, m_function_selector_index, sc_list); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3241 | } |
| 3242 | |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 3243 | } |
| 3244 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3245 | // Return the number of variable that were appended to the list |
| 3246 | return sc_list.GetSize() - original_size; |
| 3247 | } |
| 3248 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3249 | uint32_t |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3250 | SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3251 | { |
| 3252 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 3253 | "SymbolFileDWARF::FindFunctions (regex = '%s')", |
| 3254 | regex.GetText()); |
| 3255 | |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3256 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 3257 | |
| 3258 | if (log) |
| 3259 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3260 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3261 | "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)", |
| 3262 | regex.GetText(), |
| 3263 | append); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3264 | } |
| 3265 | |
| 3266 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3267 | // If we aren't appending the results to this list, then clear the list |
| 3268 | if (!append) |
| 3269 | sc_list.Clear(); |
| 3270 | |
| 3271 | // Remember how many sc_list are in the list before we search in case |
| 3272 | // we are appending the results to a variable list. |
| 3273 | uint32_t original_size = sc_list.GetSize(); |
| 3274 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3275 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3276 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3277 | if (m_apple_names_ap.get()) |
| 3278 | FindFunctions (regex, *m_apple_names_ap, sc_list); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3279 | } |
| 3280 | else |
| 3281 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3282 | // Index the DWARF if we haven't already |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3283 | if (!m_indexed) |
| 3284 | Index (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3285 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3286 | FindFunctions (regex, m_function_basename_index, sc_list); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3287 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3288 | FindFunctions (regex, m_function_fullname_index, sc_list); |
| 3289 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3290 | |
| 3291 | // Return the number of variable that were appended to the list |
| 3292 | return sc_list.GetSize() - original_size; |
| 3293 | } |
| Jim Ingham | 318c9f2 | 2011-08-26 19:44:13 +0000 | [diff] [blame] | 3294 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3295 | uint32_t |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3296 | SymbolFileDWARF::FindTypes (const SymbolContext& sc, |
| 3297 | const ConstString &name, |
| 3298 | const lldb_private::ClangNamespaceDecl *namespace_decl, |
| 3299 | bool append, |
| 3300 | uint32_t max_matches, |
| 3301 | TypeList& types) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3302 | { |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3303 | DWARFDebugInfo* info = DebugInfo(); |
| 3304 | if (info == NULL) |
| 3305 | return 0; |
| 3306 | |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3307 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 3308 | |
| 3309 | if (log) |
| 3310 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3311 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3312 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", append=%u, max_matches=%u, type_list)", |
| 3313 | name.GetCString(), |
| 3314 | append, |
| 3315 | max_matches); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3316 | } |
| 3317 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3318 | // If we aren't appending the results to this list, then clear the list |
| 3319 | if (!append) |
| 3320 | types.Clear(); |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3321 | |
| 3322 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) |
| 3323 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3324 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3325 | DIEArray die_offsets; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3326 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3327 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3328 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3329 | if (m_apple_types_ap.get()) |
| 3330 | { |
| 3331 | const char *name_cstr = name.GetCString(); |
| 3332 | m_apple_types_ap->FindByName (name_cstr, die_offsets); |
| 3333 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3334 | } |
| 3335 | else |
| 3336 | { |
| 3337 | if (!m_indexed) |
| 3338 | Index (); |
| 3339 | |
| 3340 | m_type_index.Find (name, die_offsets); |
| 3341 | } |
| 3342 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3343 | const size_t num_matches = die_offsets.size(); |
| 3344 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3345 | if (num_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3346 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3347 | const uint32_t initial_types_size = types.GetSize(); |
| 3348 | DWARFCompileUnit* dwarf_cu = NULL; |
| 3349 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3350 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3351 | for (size_t i=0; i<num_matches; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3352 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3353 | const dw_offset_t die_offset = die_offsets[i]; |
| 3354 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| 3355 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3356 | if (die) |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 3357 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3358 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3359 | continue; |
| 3360 | |
| 3361 | Type *matching_type = ResolveType (dwarf_cu, die); |
| 3362 | if (matching_type) |
| 3363 | { |
| 3364 | // We found a type pointer, now find the shared pointer form our type list |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 3365 | types.InsertUnique (matching_type->shared_from_this()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3366 | if (types.GetSize() >= max_matches) |
| 3367 | break; |
| 3368 | } |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 3369 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3370 | else |
| 3371 | { |
| 3372 | if (m_using_apple_tables) |
| 3373 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3374 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 3375 | die_offset, name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3376 | } |
| 3377 | } |
| 3378 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3379 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3380 | return types.GetSize() - initial_types_size; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3381 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3382 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3383 | } |
| 3384 | |
| 3385 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3386 | ClangNamespaceDecl |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3387 | SymbolFileDWARF::FindNamespace (const SymbolContext& sc, |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3388 | const ConstString &name, |
| 3389 | const lldb_private::ClangNamespaceDecl *parent_namespace_decl) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3390 | { |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3391 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 3392 | |
| 3393 | if (log) |
| 3394 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3395 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3396 | "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")", |
| 3397 | name.GetCString()); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3398 | } |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3399 | |
| 3400 | if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl)) |
| 3401 | return ClangNamespaceDecl(); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3402 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3403 | ClangNamespaceDecl namespace_decl; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3404 | DWARFDebugInfo* info = DebugInfo(); |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3405 | if (info) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3406 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3407 | DIEArray die_offsets; |
| 3408 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3409 | // Index if we already haven't to make sure the compile units |
| 3410 | // get indexed and make their global DIE index list |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3411 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3412 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3413 | if (m_apple_namespaces_ap.get()) |
| 3414 | { |
| 3415 | const char *name_cstr = name.GetCString(); |
| 3416 | m_apple_namespaces_ap->FindByName (name_cstr, die_offsets); |
| 3417 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3418 | } |
| 3419 | else |
| 3420 | { |
| 3421 | if (!m_indexed) |
| 3422 | Index (); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3423 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3424 | m_namespace_index.Find (name, die_offsets); |
| 3425 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3426 | |
| 3427 | DWARFCompileUnit* dwarf_cu = NULL; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3428 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3429 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3430 | if (num_matches) |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3431 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3432 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3433 | for (size_t i=0; i<num_matches; ++i) |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3434 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3435 | const dw_offset_t die_offset = die_offsets[i]; |
| 3436 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3437 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3438 | if (die) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3439 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3440 | if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die)) |
| 3441 | continue; |
| 3442 | |
| 3443 | clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die); |
| 3444 | if (clang_namespace_decl) |
| 3445 | { |
| 3446 | namespace_decl.SetASTContext (GetClangASTContext().getASTContext()); |
| 3447 | namespace_decl.SetNamespaceDecl (clang_namespace_decl); |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3448 | break; |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3449 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3450 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3451 | else |
| 3452 | { |
| 3453 | if (m_using_apple_tables) |
| 3454 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3455 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n", |
| 3456 | die_offset, name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3457 | } |
| 3458 | } |
| 3459 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3460 | } |
| 3461 | } |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3462 | } |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3463 | return namespace_decl; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3464 | } |
| 3465 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3466 | uint32_t |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3467 | SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3468 | { |
| 3469 | // Remember how many sc_list are in the list before we search in case |
| 3470 | // we are appending the results to a variable list. |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3471 | uint32_t original_size = types.GetSize(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3472 | |
| 3473 | const uint32_t num_die_offsets = die_offsets.size(); |
| 3474 | // Parse all of the types we found from the pubtypes matches |
| 3475 | uint32_t i; |
| 3476 | uint32_t num_matches = 0; |
| 3477 | for (i = 0; i < num_die_offsets; ++i) |
| 3478 | { |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3479 | Type *matching_type = ResolveTypeUID (die_offsets[i]); |
| 3480 | if (matching_type) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3481 | { |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3482 | // We found a type pointer, now find the shared pointer form our type list |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 3483 | types.InsertUnique (matching_type->shared_from_this()); |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3484 | ++num_matches; |
| 3485 | if (num_matches >= max_matches) |
| 3486 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3487 | } |
| 3488 | } |
| 3489 | |
| 3490 | // Return the number of variable that were appended to the list |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3491 | return types.GetSize() - original_size; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3492 | } |
| 3493 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3494 | |
| 3495 | size_t |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3496 | SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc, |
| 3497 | clang::DeclContext *containing_decl_ctx, |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3498 | DWARFCompileUnit* dwarf_cu, |
| 3499 | const DWARFDebugInfoEntry *parent_die, |
| 3500 | bool skip_artificial, |
| 3501 | bool &is_static, |
| 3502 | TypeList* type_list, |
| 3503 | std::vector<clang_type_t>& function_param_types, |
| 3504 | std::vector<clang::ParmVarDecl*>& function_param_decls, |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 3505 | unsigned &type_quals, |
| 3506 | ClangASTContext::TemplateParameterInfos &template_param_infos) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3507 | { |
| 3508 | if (parent_die == NULL) |
| 3509 | return 0; |
| 3510 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3511 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| 3512 | |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3513 | size_t arg_idx = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3514 | const DWARFDebugInfoEntry *die; |
| 3515 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 3516 | { |
| 3517 | dw_tag_t tag = die->Tag(); |
| 3518 | switch (tag) |
| 3519 | { |
| 3520 | case DW_TAG_formal_parameter: |
| 3521 | { |
| 3522 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3523 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3524 | if (num_attributes > 0) |
| 3525 | { |
| 3526 | const char *name = NULL; |
| 3527 | Declaration decl; |
| 3528 | dw_offset_t param_type_die_offset = DW_INVALID_OFFSET; |
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 3529 | bool is_artificial = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3530 | // one of None, Auto, Register, Extern, Static, PrivateExtern |
| 3531 | |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 3532 | clang::StorageClass storage = clang::SC_None; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3533 | uint32_t i; |
| 3534 | for (i=0; i<num_attributes; ++i) |
| 3535 | { |
| 3536 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 3537 | DWARFFormValue form_value; |
| 3538 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 3539 | { |
| 3540 | switch (attr) |
| 3541 | { |
| 3542 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 3543 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 3544 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 3545 | case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; |
| 3546 | case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break; |
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 3547 | case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3548 | case DW_AT_location: |
| 3549 | // if (form_value.BlockData()) |
| 3550 | // { |
| 3551 | // const DataExtractor& debug_info_data = debug_info(); |
| 3552 | // uint32_t block_length = form_value.Unsigned(); |
| 3553 | // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length); |
| 3554 | // } |
| 3555 | // else |
| 3556 | // { |
| 3557 | // } |
| 3558 | // break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3559 | case DW_AT_const_value: |
| 3560 | case DW_AT_default_value: |
| 3561 | case DW_AT_description: |
| 3562 | case DW_AT_endianity: |
| 3563 | case DW_AT_is_optional: |
| 3564 | case DW_AT_segment: |
| 3565 | case DW_AT_variable_parameter: |
| 3566 | default: |
| 3567 | case DW_AT_abstract_origin: |
| 3568 | case DW_AT_sibling: |
| 3569 | break; |
| 3570 | } |
| 3571 | } |
| 3572 | } |
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 3573 | |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3574 | bool skip = false; |
| 3575 | if (skip_artificial) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3576 | { |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3577 | if (is_artificial) |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3578 | { |
| 3579 | // In order to determine if a C++ member function is |
| 3580 | // "const" we have to look at the const-ness of "this"... |
| 3581 | // Ugly, but that |
| 3582 | if (arg_idx == 0) |
| 3583 | { |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 3584 | if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind())) |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 3585 | { |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3586 | // Often times compilers omit the "this" name for the |
| 3587 | // specification DIEs, so we can't rely upon the name |
| 3588 | // being in the formal parameter DIE... |
| 3589 | if (name == NULL || ::strcmp(name, "this")==0) |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3590 | { |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3591 | Type *this_type = ResolveTypeUID (param_type_die_offset); |
| 3592 | if (this_type) |
| 3593 | { |
| 3594 | uint32_t encoding_mask = this_type->GetEncodingMask(); |
| 3595 | if (encoding_mask & Type::eEncodingIsPointerUID) |
| 3596 | { |
| 3597 | is_static = false; |
| 3598 | |
| 3599 | if (encoding_mask & (1u << Type::eEncodingIsConstUID)) |
| 3600 | type_quals |= clang::Qualifiers::Const; |
| 3601 | if (encoding_mask & (1u << Type::eEncodingIsVolatileUID)) |
| 3602 | type_quals |= clang::Qualifiers::Volatile; |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3603 | } |
| 3604 | } |
| 3605 | } |
| 3606 | } |
| 3607 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3608 | skip = true; |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3609 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3610 | else |
| 3611 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3612 | |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3613 | // HACK: Objective C formal parameters "self" and "_cmd" |
| 3614 | // are not marked as artificial in the DWARF... |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3615 | CompileUnit *curr_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| 3616 | if (curr_cu && (curr_cu->GetLanguage() == eLanguageTypeObjC || curr_cu->GetLanguage() == eLanguageTypeObjC_plus_plus)) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3617 | { |
| 3618 | if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0)) |
| 3619 | skip = true; |
| 3620 | } |
| 3621 | } |
| 3622 | } |
| 3623 | |
| 3624 | if (!skip) |
| 3625 | { |
| 3626 | Type *type = ResolveTypeUID(param_type_die_offset); |
| 3627 | if (type) |
| 3628 | { |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 3629 | function_param_types.push_back (type->GetClangForwardType()); |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3630 | |
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 3631 | clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name, |
| 3632 | type->GetClangForwardType(), |
| 3633 | storage); |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3634 | assert(param_var_decl); |
| 3635 | function_param_decls.push_back(param_var_decl); |
| 3636 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3637 | } |
| 3638 | } |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3639 | arg_idx++; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3640 | } |
| 3641 | break; |
| 3642 | |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 3643 | case DW_TAG_template_type_parameter: |
| 3644 | case DW_TAG_template_value_parameter: |
| 3645 | ParseTemplateDIE (dwarf_cu, die,template_param_infos); |
| 3646 | break; |
| 3647 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3648 | default: |
| 3649 | break; |
| 3650 | } |
| 3651 | } |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3652 | return arg_idx; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3653 | } |
| 3654 | |
| 3655 | size_t |
| 3656 | SymbolFileDWARF::ParseChildEnumerators |
| 3657 | ( |
| 3658 | const SymbolContext& sc, |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 3659 | clang_type_t enumerator_clang_type, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3660 | uint32_t enumerator_byte_size, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3661 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3662 | const DWARFDebugInfoEntry *parent_die |
| 3663 | ) |
| 3664 | { |
| 3665 | if (parent_die == NULL) |
| 3666 | return 0; |
| 3667 | |
| 3668 | size_t enumerators_added = 0; |
| 3669 | const DWARFDebugInfoEntry *die; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3670 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| 3671 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3672 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 3673 | { |
| 3674 | const dw_tag_t tag = die->Tag(); |
| 3675 | if (tag == DW_TAG_enumerator) |
| 3676 | { |
| 3677 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3678 | const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3679 | if (num_child_attributes > 0) |
| 3680 | { |
| 3681 | const char *name = NULL; |
| 3682 | bool got_value = false; |
| 3683 | int64_t enum_value = 0; |
| 3684 | Declaration decl; |
| 3685 | |
| 3686 | uint32_t i; |
| 3687 | for (i=0; i<num_child_attributes; ++i) |
| 3688 | { |
| 3689 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 3690 | DWARFFormValue form_value; |
| 3691 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 3692 | { |
| 3693 | switch (attr) |
| 3694 | { |
| 3695 | case DW_AT_const_value: |
| 3696 | got_value = true; |
| 3697 | enum_value = form_value.Unsigned(); |
| 3698 | break; |
| 3699 | |
| 3700 | case DW_AT_name: |
| 3701 | name = form_value.AsCString(&get_debug_str_data()); |
| 3702 | break; |
| 3703 | |
| 3704 | case DW_AT_description: |
| 3705 | default: |
| 3706 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 3707 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 3708 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 3709 | case DW_AT_sibling: |
| 3710 | break; |
| 3711 | } |
| 3712 | } |
| 3713 | } |
| 3714 | |
| 3715 | if (name && name[0] && got_value) |
| 3716 | { |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 3717 | GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type, |
| 3718 | enumerator_clang_type, |
| 3719 | decl, |
| 3720 | name, |
| 3721 | enum_value, |
| 3722 | enumerator_byte_size * 8); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3723 | ++enumerators_added; |
| 3724 | } |
| 3725 | } |
| 3726 | } |
| 3727 | } |
| 3728 | return enumerators_added; |
| 3729 | } |
| 3730 | |
| 3731 | void |
| 3732 | SymbolFileDWARF::ParseChildArrayInfo |
| 3733 | ( |
| 3734 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3735 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3736 | const DWARFDebugInfoEntry *parent_die, |
| 3737 | int64_t& first_index, |
| 3738 | std::vector<uint64_t>& element_orders, |
| 3739 | uint32_t& byte_stride, |
| 3740 | uint32_t& bit_stride |
| 3741 | ) |
| 3742 | { |
| 3743 | if (parent_die == NULL) |
| 3744 | return; |
| 3745 | |
| 3746 | const DWARFDebugInfoEntry *die; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3747 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3748 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 3749 | { |
| 3750 | const dw_tag_t tag = die->Tag(); |
| 3751 | switch (tag) |
| 3752 | { |
| 3753 | case DW_TAG_enumerator: |
| 3754 | { |
| 3755 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3756 | const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3757 | if (num_child_attributes > 0) |
| 3758 | { |
| 3759 | const char *name = NULL; |
| 3760 | bool got_value = false; |
| 3761 | int64_t enum_value = 0; |
| 3762 | |
| 3763 | uint32_t i; |
| 3764 | for (i=0; i<num_child_attributes; ++i) |
| 3765 | { |
| 3766 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 3767 | DWARFFormValue form_value; |
| 3768 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 3769 | { |
| 3770 | switch (attr) |
| 3771 | { |
| 3772 | case DW_AT_const_value: |
| 3773 | got_value = true; |
| 3774 | enum_value = form_value.Unsigned(); |
| 3775 | break; |
| 3776 | |
| 3777 | case DW_AT_name: |
| 3778 | name = form_value.AsCString(&get_debug_str_data()); |
| 3779 | break; |
| 3780 | |
| 3781 | case DW_AT_description: |
| 3782 | default: |
| 3783 | case DW_AT_decl_file: |
| 3784 | case DW_AT_decl_line: |
| 3785 | case DW_AT_decl_column: |
| 3786 | case DW_AT_sibling: |
| 3787 | break; |
| 3788 | } |
| 3789 | } |
| 3790 | } |
| 3791 | } |
| 3792 | } |
| 3793 | break; |
| 3794 | |
| 3795 | case DW_TAG_subrange_type: |
| 3796 | { |
| 3797 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3798 | const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3799 | if (num_child_attributes > 0) |
| 3800 | { |
| 3801 | const char *name = NULL; |
| 3802 | bool got_value = false; |
| 3803 | uint64_t byte_size = 0; |
| 3804 | int64_t enum_value = 0; |
| 3805 | uint64_t num_elements = 0; |
| 3806 | uint64_t lower_bound = 0; |
| 3807 | uint64_t upper_bound = 0; |
| 3808 | uint32_t i; |
| 3809 | for (i=0; i<num_child_attributes; ++i) |
| 3810 | { |
| 3811 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 3812 | DWARFFormValue form_value; |
| 3813 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 3814 | { |
| 3815 | switch (attr) |
| 3816 | { |
| 3817 | case DW_AT_const_value: |
| 3818 | got_value = true; |
| 3819 | enum_value = form_value.Unsigned(); |
| 3820 | break; |
| 3821 | |
| 3822 | case DW_AT_name: |
| 3823 | name = form_value.AsCString(&get_debug_str_data()); |
| 3824 | break; |
| 3825 | |
| 3826 | case DW_AT_count: |
| 3827 | num_elements = form_value.Unsigned(); |
| 3828 | break; |
| 3829 | |
| 3830 | case DW_AT_bit_stride: |
| 3831 | bit_stride = form_value.Unsigned(); |
| 3832 | break; |
| 3833 | |
| 3834 | case DW_AT_byte_stride: |
| 3835 | byte_stride = form_value.Unsigned(); |
| 3836 | break; |
| 3837 | |
| 3838 | case DW_AT_byte_size: |
| 3839 | byte_size = form_value.Unsigned(); |
| 3840 | break; |
| 3841 | |
| 3842 | case DW_AT_lower_bound: |
| 3843 | lower_bound = form_value.Unsigned(); |
| 3844 | break; |
| 3845 | |
| 3846 | case DW_AT_upper_bound: |
| 3847 | upper_bound = form_value.Unsigned(); |
| 3848 | break; |
| 3849 | |
| 3850 | default: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3851 | case DW_AT_abstract_origin: |
| 3852 | case DW_AT_accessibility: |
| 3853 | case DW_AT_allocated: |
| 3854 | case DW_AT_associated: |
| 3855 | case DW_AT_data_location: |
| 3856 | case DW_AT_declaration: |
| 3857 | case DW_AT_description: |
| 3858 | case DW_AT_sibling: |
| 3859 | case DW_AT_threads_scaled: |
| 3860 | case DW_AT_type: |
| 3861 | case DW_AT_visibility: |
| 3862 | break; |
| 3863 | } |
| 3864 | } |
| 3865 | } |
| 3866 | |
| 3867 | if (upper_bound > lower_bound) |
| 3868 | num_elements = upper_bound - lower_bound + 1; |
| 3869 | |
| 3870 | if (num_elements > 0) |
| 3871 | element_orders.push_back (num_elements); |
| 3872 | } |
| 3873 | } |
| 3874 | break; |
| 3875 | } |
| 3876 | } |
| 3877 | } |
| 3878 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3879 | TypeSP |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3880 | SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry* die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3881 | { |
| 3882 | TypeSP type_sp; |
| 3883 | if (die != NULL) |
| 3884 | { |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3885 | assert(curr_cu != NULL); |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 3886 | Type *type_ptr = m_die_to_type.lookup (die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3887 | if (type_ptr == NULL) |
| 3888 | { |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 3889 | CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(curr_cu); |
| 3890 | assert (lldb_cu); |
| 3891 | SymbolContext sc(lldb_cu); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3892 | type_sp = ParseType(sc, curr_cu, die, NULL); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3893 | } |
| 3894 | else if (type_ptr != DIE_IS_BEING_PARSED) |
| 3895 | { |
| 3896 | // Grab the existing type from the master types lists |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 3897 | type_sp = type_ptr->shared_from_this(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3898 | } |
| 3899 | |
| 3900 | } |
| 3901 | return type_sp; |
| 3902 | } |
| 3903 | |
| 3904 | clang::DeclContext * |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 3905 | SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3906 | { |
| 3907 | if (die_offset != DW_INVALID_OFFSET) |
| 3908 | { |
| 3909 | DWARFCompileUnitSP cu_sp; |
| 3910 | const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 3911 | return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3912 | } |
| 3913 | return NULL; |
| 3914 | } |
| 3915 | |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 3916 | clang::DeclContext * |
| 3917 | SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset) |
| 3918 | { |
| 3919 | if (die_offset != DW_INVALID_OFFSET) |
| 3920 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 3921 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3922 | if (debug_info) |
| 3923 | { |
| 3924 | DWARFCompileUnitSP cu_sp; |
| 3925 | const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp); |
| 3926 | if (die) |
| 3927 | return GetClangDeclContextForDIE (sc, cu_sp.get(), die); |
| 3928 | } |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 3929 | } |
| 3930 | return NULL; |
| 3931 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3932 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3933 | clang::NamespaceDecl * |
| 3934 | SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die) |
| 3935 | { |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 3936 | if (die && die->Tag() == DW_TAG_namespace) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3937 | { |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 3938 | // See if we already parsed this namespace DIE and associated it with a |
| 3939 | // uniqued namespace declaration |
| 3940 | clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]); |
| 3941 | if (namespace_decl) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3942 | return namespace_decl; |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 3943 | else |
| 3944 | { |
| 3945 | const char *namespace_name = die->GetAttributeValueAsString(this, curr_cu, DW_AT_name, NULL); |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 3946 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (curr_cu, die, NULL); |
| 3947 | namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx); |
| 3948 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| 3949 | if (log) |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 3950 | { |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 3951 | if (namespace_name) |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 3952 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3953 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3954 | "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)", |
| 3955 | GetClangASTContext().getASTContext(), |
| 3956 | MakeUserID(die->GetOffset()), |
| 3957 | namespace_name, |
| 3958 | namespace_decl, |
| 3959 | namespace_decl->getOriginalNamespace()); |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 3960 | } |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 3961 | else |
| 3962 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3963 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3964 | "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)", |
| 3965 | GetClangASTContext().getASTContext(), |
| 3966 | MakeUserID(die->GetOffset()), |
| 3967 | namespace_decl, |
| 3968 | namespace_decl->getOriginalNamespace()); |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 3969 | } |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 3970 | } |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 3971 | |
| 3972 | if (namespace_decl) |
| 3973 | LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die); |
| 3974 | return namespace_decl; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3975 | } |
| 3976 | } |
| 3977 | return NULL; |
| 3978 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3979 | |
| 3980 | clang::DeclContext * |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 3981 | SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 3982 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 3983 | clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die); |
| 3984 | if (clang_decl_ctx) |
| 3985 | return clang_decl_ctx; |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 3986 | // If this DIE has a specification, or an abstract origin, then trace to those. |
| 3987 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 3988 | dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET); |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 3989 | if (die_offset != DW_INVALID_OFFSET) |
| 3990 | return GetClangDeclContextForDIEOffset (sc, die_offset); |
| 3991 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 3992 | die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET); |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 3993 | if (die_offset != DW_INVALID_OFFSET) |
| 3994 | return GetClangDeclContextForDIEOffset (sc, die_offset); |
| 3995 | |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 3996 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| 3997 | if (log) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3998 | GetObjectFile()->GetModule()->LogMessage(log.get(), "SymbolFileDWARF::GetClangDeclContextForDIE (die = 0x%8.8x) %s '%s'", die->GetOffset(), DW_TAG_value_to_name(die->Tag()), die->GetName(this, cu)); |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 3999 | // This is the DIE we want. Parse it, then query our map. |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4000 | bool assert_not_being_parsed = true; |
| 4001 | ResolveTypeUID (cu, die, assert_not_being_parsed); |
| 4002 | |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4003 | clang_decl_ctx = GetCachedClangDeclContextForDIE (die); |
| 4004 | |
| 4005 | return clang_decl_ctx; |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4006 | } |
| 4007 | |
| 4008 | clang::DeclContext * |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4009 | SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4010 | { |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4011 | if (m_clang_tu_decl == NULL) |
| 4012 | m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4013 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4014 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4015 | |
| 4016 | if (decl_ctx_die_copy) |
| 4017 | *decl_ctx_die_copy = decl_ctx_die; |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4018 | |
| 4019 | if (decl_ctx_die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4020 | { |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4021 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4022 | DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die); |
| 4023 | if (pos != m_die_to_decl_ctx.end()) |
| 4024 | return pos->second; |
| 4025 | |
| 4026 | switch (decl_ctx_die->Tag()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4027 | { |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4028 | case DW_TAG_compile_unit: |
| 4029 | return m_clang_tu_decl; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4030 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4031 | case DW_TAG_namespace: |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4032 | return ResolveNamespaceDIE (cu, decl_ctx_die); |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4033 | break; |
| 4034 | |
| 4035 | case DW_TAG_structure_type: |
| 4036 | case DW_TAG_union_type: |
| 4037 | case DW_TAG_class_type: |
| 4038 | { |
| 4039 | Type* type = ResolveType (cu, decl_ctx_die); |
| 4040 | if (type) |
| 4041 | { |
| 4042 | clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ()); |
| 4043 | if (decl_ctx) |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4044 | { |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4045 | LinkDeclContextToDIE (decl_ctx, decl_ctx_die); |
| 4046 | if (decl_ctx) |
| 4047 | return decl_ctx; |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4048 | } |
| 4049 | } |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4050 | } |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4051 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4052 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4053 | default: |
| 4054 | break; |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4055 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4056 | } |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 4057 | return m_clang_tu_decl; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4058 | } |
| 4059 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4060 | |
| 4061 | const DWARFDebugInfoEntry * |
| 4062 | SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) |
| 4063 | { |
| 4064 | if (cu && die) |
| 4065 | { |
| 4066 | const DWARFDebugInfoEntry * const decl_die = die; |
| 4067 | |
| 4068 | while (die != NULL) |
| 4069 | { |
| 4070 | // If this is the original DIE that we are searching for a declaration |
| 4071 | // for, then don't look in the cache as we don't want our own decl |
| 4072 | // context to be our decl context... |
| 4073 | if (decl_die != die) |
| 4074 | { |
| 4075 | switch (die->Tag()) |
| 4076 | { |
| 4077 | case DW_TAG_compile_unit: |
| 4078 | case DW_TAG_namespace: |
| 4079 | case DW_TAG_structure_type: |
| 4080 | case DW_TAG_union_type: |
| 4081 | case DW_TAG_class_type: |
| 4082 | return die; |
| 4083 | |
| 4084 | default: |
| 4085 | break; |
| 4086 | } |
| 4087 | } |
| 4088 | |
| 4089 | dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET); |
| 4090 | if (die_offset != DW_INVALID_OFFSET) |
| 4091 | { |
| 4092 | DWARFCompileUnit *spec_cu = cu; |
| 4093 | const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu); |
| 4094 | const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die); |
| 4095 | if (spec_die_decl_ctx_die) |
| 4096 | return spec_die_decl_ctx_die; |
| 4097 | } |
| 4098 | |
| 4099 | die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET); |
| 4100 | if (die_offset != DW_INVALID_OFFSET) |
| 4101 | { |
| 4102 | DWARFCompileUnit *abs_cu = cu; |
| 4103 | const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu); |
| 4104 | const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die); |
| 4105 | if (abs_die_decl_ctx_die) |
| 4106 | return abs_die_decl_ctx_die; |
| 4107 | } |
| 4108 | |
| 4109 | die = die->GetParent(); |
| 4110 | } |
| 4111 | } |
| 4112 | return NULL; |
| 4113 | } |
| 4114 | |
| 4115 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4116 | Symbol * |
| 4117 | SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name) |
| 4118 | { |
| 4119 | Symbol *objc_class_symbol = NULL; |
| 4120 | if (m_obj_file) |
| 4121 | { |
| 4122 | Symtab *symtab = m_obj_file->GetSymtab(); |
| 4123 | if (symtab) |
| 4124 | { |
| 4125 | objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name, |
| 4126 | eSymbolTypeObjCClass, |
| 4127 | Symtab::eDebugNo, |
| 4128 | Symtab::eVisibilityAny); |
| 4129 | } |
| 4130 | } |
| 4131 | return objc_class_symbol; |
| 4132 | } |
| 4133 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4134 | // Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't |
| 4135 | // then we can end up looking through all class types for a complete type and never find |
| 4136 | // the full definition. We need to know if this attribute is supported, so we determine |
| 4137 | // this here and cache th result. We also need to worry about the debug map DWARF file |
| 4138 | // if we are doing darwin DWARF in .o file debugging. |
| 4139 | bool |
| 4140 | SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu) |
| 4141 | { |
| 4142 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate) |
| 4143 | { |
| 4144 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo; |
| 4145 | if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type()) |
| 4146 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; |
| 4147 | else |
| 4148 | { |
| 4149 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 4150 | const uint32_t num_compile_units = GetNumCompileUnits(); |
| 4151 | for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) |
| 4152 | { |
| 4153 | DWARFCompileUnit* curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx); |
| 4154 | if (curr_cu != cu && curr_cu->Supports_DW_AT_APPLE_objc_complete_type()) |
| 4155 | { |
| 4156 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; |
| 4157 | break; |
| 4158 | } |
| 4159 | } |
| 4160 | } |
| 4161 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && m_debug_map_symfile) |
| 4162 | return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this); |
| 4163 | } |
| 4164 | return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes; |
| 4165 | } |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4166 | |
| 4167 | // This function can be used when a DIE is found that is a forward declaration |
| 4168 | // DIE and we want to try and find a type that has the complete definition. |
| 4169 | TypeSP |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4170 | SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die, |
| 4171 | const ConstString &type_name, |
| 4172 | bool must_be_implementation) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4173 | { |
| 4174 | |
| 4175 | TypeSP type_sp; |
| 4176 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4177 | if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name))) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4178 | return type_sp; |
| 4179 | |
| 4180 | DIEArray die_offsets; |
| 4181 | |
| 4182 | if (m_using_apple_tables) |
| 4183 | { |
| 4184 | if (m_apple_types_ap.get()) |
| 4185 | { |
| 4186 | const char *name_cstr = type_name.GetCString(); |
| Greg Clayton | 68221ec | 2012-01-18 20:58:12 +0000 | [diff] [blame] | 4187 | m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4188 | } |
| 4189 | } |
| 4190 | else |
| 4191 | { |
| 4192 | if (!m_indexed) |
| 4193 | Index (); |
| 4194 | |
| 4195 | m_type_index.Find (type_name, die_offsets); |
| 4196 | } |
| 4197 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4198 | const size_t num_matches = die_offsets.size(); |
| 4199 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4200 | DWARFCompileUnit* type_cu = NULL; |
| 4201 | const DWARFDebugInfoEntry* type_die = NULL; |
| 4202 | if (num_matches) |
| 4203 | { |
| 4204 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 4205 | for (size_t i=0; i<num_matches; ++i) |
| 4206 | { |
| 4207 | const dw_offset_t die_offset = die_offsets[i]; |
| 4208 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); |
| 4209 | |
| 4210 | if (type_die) |
| 4211 | { |
| 4212 | bool try_resolving_type = false; |
| 4213 | |
| 4214 | // Don't try and resolve the DIE we are looking for with the DIE itself! |
| 4215 | if (type_die != die) |
| 4216 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4217 | switch (type_die->Tag()) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4218 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4219 | case DW_TAG_class_type: |
| 4220 | case DW_TAG_structure_type: |
| 4221 | try_resolving_type = true; |
| 4222 | break; |
| 4223 | default: |
| 4224 | break; |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4225 | } |
| 4226 | } |
| 4227 | |
| 4228 | if (try_resolving_type) |
| 4229 | { |
| Sean Callanan | a9bc065 | 2012-01-19 02:17:40 +0000 | [diff] [blame] | 4230 | if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type()) |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4231 | try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4232 | |
| 4233 | if (try_resolving_type) |
| 4234 | { |
| 4235 | Type *resolved_type = ResolveType (type_cu, type_die, false); |
| 4236 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) |
| 4237 | { |
| 4238 | DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n", |
| 4239 | MakeUserID(die->GetOffset()), |
| 4240 | MakeUserID(curr_cu->GetOffset()), |
| 4241 | m_obj_file->GetFileSpec().GetFilename().AsCString(), |
| 4242 | MakeUserID(type_die->GetOffset()), |
| 4243 | MakeUserID(type_cu->GetOffset())); |
| 4244 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4245 | if (die) |
| 4246 | m_die_to_type[die] = resolved_type; |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 4247 | type_sp = resolved_type->shared_from_this(); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4248 | break; |
| 4249 | } |
| 4250 | } |
| 4251 | } |
| 4252 | } |
| 4253 | else |
| 4254 | { |
| 4255 | if (m_using_apple_tables) |
| 4256 | { |
| Greg Clayton | e38a5ed | 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 | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4259 | } |
| 4260 | } |
| 4261 | |
| 4262 | } |
| 4263 | } |
| 4264 | return type_sp; |
| 4265 | } |
| 4266 | |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4267 | //---------------------------------------------------------------------- |
| 4268 | // This function helps to ensure that the declaration contexts match for |
| 4269 | // two different DIEs. Often times debug information will refer to a |
| 4270 | // forward declaration of a type (the equivalent of "struct my_struct;". |
| 4271 | // There will often be a declaration of that type elsewhere that has the |
| 4272 | // full definition. When we go looking for the full type "my_struct", we |
| 4273 | // will find one or more matches in the accelerator tables and we will |
| 4274 | // then need to make sure the type was in the same declaration context |
| 4275 | // as the original DIE. This function can efficiently compare two DIEs |
| 4276 | // and will return true when the declaration context matches, and false |
| 4277 | // when they don't. |
| 4278 | //---------------------------------------------------------------------- |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4279 | bool |
| 4280 | SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1, |
| 4281 | DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2) |
| 4282 | { |
| 4283 | assert (die1 != die2); |
| 4284 | DWARFDIECollection decl_ctx_1; |
| 4285 | DWARFDIECollection decl_ctx_2; |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4286 | //The declaration DIE stack is a stack of the declaration context |
| 4287 | // DIEs all the way back to the compile unit. If a type "T" is |
| 4288 | // declared inside a class "B", and class "B" is declared inside |
| 4289 | // a class "A" and class "A" is in a namespace "lldb", and the |
| 4290 | // namespace is in a compile unit, there will be a stack of DIEs: |
| 4291 | // |
| 4292 | // [0] DW_TAG_class_type for "B" |
| 4293 | // [1] DW_TAG_class_type for "A" |
| 4294 | // [2] DW_TAG_namespace for "lldb" |
| 4295 | // [3] DW_TAG_compile_unit for the source file. |
| 4296 | // |
| 4297 | // We grab both contexts and make sure that everything matches |
| 4298 | // all the way back to the compiler unit. |
| 4299 | |
| 4300 | // First lets grab the decl contexts for both DIEs |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4301 | die1->GetDeclContextDIEs (this, cu1, decl_ctx_1); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 4302 | die2->GetDeclContextDIEs (this, cu2, decl_ctx_2); |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4303 | // Make sure the context arrays have the same size, otherwise |
| 4304 | // we are done |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4305 | const size_t count1 = decl_ctx_1.Size(); |
| 4306 | const size_t count2 = decl_ctx_2.Size(); |
| 4307 | if (count1 != count2) |
| 4308 | return false; |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4309 | |
| 4310 | // Make sure the DW_TAG values match all the way back up the the |
| 4311 | // compile unit. If they don't, then we are done. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4312 | const DWARFDebugInfoEntry *decl_ctx_die1; |
| 4313 | const DWARFDebugInfoEntry *decl_ctx_die2; |
| 4314 | size_t i; |
| 4315 | for (i=0; i<count1; i++) |
| 4316 | { |
| 4317 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); |
| 4318 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); |
| 4319 | if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag()) |
| 4320 | return false; |
| 4321 | } |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4322 | #if defined LLDB_CONFIGURATION_DEBUG |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4323 | |
| 4324 | // Make sure the top item in the decl context die array is always |
| 4325 | // DW_TAG_compile_unit. If it isn't then something went wrong in |
| 4326 | // the DWARFDebugInfoEntry::GetDeclContextDIEs() function... |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4327 | assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit); |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4328 | |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4329 | #endif |
| 4330 | // Always skip the compile unit when comparing by only iterating up to |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4331 | // "count - 1". Here we compare the names as we go. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4332 | for (i=0; i<count1 - 1; i++) |
| 4333 | { |
| 4334 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); |
| 4335 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); |
| 4336 | const char *name1 = decl_ctx_die1->GetName(this, cu1); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 4337 | const char *name2 = decl_ctx_die2->GetName(this, cu2); |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4338 | // If the string was from a DW_FORM_strp, then the pointer will often |
| 4339 | // be the same! |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 4340 | if (name1 == name2) |
| 4341 | continue; |
| 4342 | |
| 4343 | // Name pointers are not equal, so only compare the strings |
| 4344 | // if both are not NULL. |
| 4345 | if (name1 && name2) |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4346 | { |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 4347 | // If the strings don't compare, we are done... |
| 4348 | if (strcmp(name1, name2) != 0) |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4349 | return false; |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 4350 | } |
| 4351 | else |
| 4352 | { |
| 4353 | // One name was NULL while the other wasn't |
| 4354 | return false; |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4355 | } |
| 4356 | } |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4357 | // We made it through all of the checks and the declaration contexts |
| 4358 | // are equal. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4359 | return true; |
| 4360 | } |
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 4361 | |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4362 | // This function can be used when a DIE is found that is a forward declaration |
| 4363 | // DIE and we want to try and find a type that has the complete definition. |
| 4364 | TypeSP |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4365 | SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu, |
| 4366 | const DWARFDebugInfoEntry *die, |
| 4367 | const ConstString &type_name) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4368 | { |
| 4369 | TypeSP type_sp; |
| 4370 | |
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 4371 | if (cu == NULL || die == NULL || !type_name) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4372 | return type_sp; |
| 4373 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4374 | DIEArray die_offsets; |
| 4375 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4376 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4377 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4378 | if (m_apple_types_ap.get()) |
| 4379 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4380 | if (m_apple_types_ap->GetHeader().header_data.atoms.size() > 1) |
| 4381 | { |
| Greg Clayton | ae920b6 | 2012-01-06 00:17:16 +0000 | [diff] [blame] | 4382 | m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets); |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4383 | } |
| 4384 | else |
| 4385 | { |
| 4386 | m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets); |
| 4387 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4388 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4389 | } |
| 4390 | else |
| 4391 | { |
| 4392 | if (!m_indexed) |
| 4393 | Index (); |
| 4394 | |
| 4395 | m_type_index.Find (type_name, die_offsets); |
| 4396 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4397 | |
| 4398 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | 6997489 | 2010-12-03 21:42:06 +0000 | [diff] [blame] | 4399 | |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4400 | const dw_tag_t die_tag = die->Tag(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4401 | |
| 4402 | DWARFCompileUnit* type_cu = NULL; |
| 4403 | const DWARFDebugInfoEntry* type_die = NULL; |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4404 | if (num_matches) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4405 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4406 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4407 | for (size_t i=0; i<num_matches; ++i) |
| 4408 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4409 | const dw_offset_t die_offset = die_offsets[i]; |
| 4410 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4411 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4412 | if (type_die) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4413 | { |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4414 | bool try_resolving_type = false; |
| 4415 | |
| 4416 | // Don't try and resolve the DIE we are looking for with the DIE itself! |
| 4417 | if (type_die != die) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4418 | { |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4419 | const dw_tag_t type_die_tag = type_die->Tag(); |
| 4420 | // Make sure the tags match |
| 4421 | if (type_die_tag == die_tag) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4422 | { |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4423 | // The tags match, lets try resolving this type |
| 4424 | try_resolving_type = true; |
| 4425 | } |
| 4426 | else |
| 4427 | { |
| 4428 | // The tags don't match, but we need to watch our for a |
| 4429 | // forward declaration for a struct and ("struct foo") |
| 4430 | // ends up being a class ("class foo { ... };") or |
| 4431 | // vice versa. |
| 4432 | switch (type_die_tag) |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4433 | { |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4434 | case DW_TAG_class_type: |
| 4435 | // We had a "class foo", see if we ended up with a "struct foo { ... };" |
| 4436 | try_resolving_type = (die_tag == DW_TAG_structure_type); |
| 4437 | break; |
| 4438 | case DW_TAG_structure_type: |
| 4439 | // We had a "struct foo", see if we ended up with a "class foo { ... };" |
| 4440 | try_resolving_type = (die_tag == DW_TAG_class_type); |
| 4441 | break; |
| 4442 | default: |
| 4443 | // Tags don't match, don't event try to resolve |
| 4444 | // using this type whose name matches.... |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4445 | break; |
| 4446 | } |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4447 | } |
| 4448 | } |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4449 | |
| 4450 | if (try_resolving_type) |
| 4451 | { |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4452 | // Make sure the decl contexts match all the way up |
| 4453 | if (DIEDeclContextsMatch(cu, die, type_cu, type_die)) |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4454 | { |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4455 | Type *resolved_type = ResolveType (type_cu, type_die, false); |
| 4456 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) |
| 4457 | { |
| 4458 | DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n", |
| 4459 | MakeUserID(die->GetOffset()), |
| 4460 | MakeUserID(curr_cu->GetOffset()), |
| 4461 | m_obj_file->GetFileSpec().GetFilename().AsCString(), |
| 4462 | MakeUserID(type_die->GetOffset()), |
| 4463 | MakeUserID(type_cu->GetOffset())); |
| 4464 | |
| 4465 | m_die_to_type[die] = resolved_type; |
| Greg Clayton | ff7692a | 2012-02-02 18:16:59 +0000 | [diff] [blame] | 4466 | type_sp = resolved_type->shared_from_this(); |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4467 | break; |
| 4468 | } |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4469 | } |
| 4470 | } |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4471 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4472 | else |
| 4473 | { |
| 4474 | if (m_using_apple_tables) |
| 4475 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4476 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 4477 | die_offset, type_name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4478 | } |
| 4479 | } |
| 4480 | |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4481 | } |
| 4482 | } |
| 4483 | return type_sp; |
| 4484 | } |
| 4485 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4486 | TypeSP |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 4487 | SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4488 | { |
| 4489 | TypeSP type_sp; |
| 4490 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 4491 | if (type_is_new_ptr) |
| 4492 | *type_is_new_ptr = false; |
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 4493 | |
| 4494 | #if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE) |
| 4495 | static DIEStack g_die_stack; |
| 4496 | DIEStack::ScopedPopper scoped_die_logger(g_die_stack); |
| 4497 | #endif |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 4498 | |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 4499 | AccessType accessibility = eAccessNone; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4500 | if (die != NULL) |
| 4501 | { |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 4502 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 4503 | if (log) |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 4504 | { |
| 4505 | const DWARFDebugInfoEntry *context_die; |
| 4506 | clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die); |
| 4507 | |
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 4508 | GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x, decl_ctx = %p (die 0x%8.8x)) %s name = '%s')", |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 4509 | die->GetOffset(), |
| 4510 | context, |
| 4511 | context_die->GetOffset(), |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 4512 | DW_TAG_value_to_name(die->Tag()), |
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 4513 | die->GetName(this, dwarf_cu)); |
| 4514 | |
| 4515 | #if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE) |
| 4516 | scoped_die_logger.Push (dwarf_cu, die); |
| 4517 | g_die_stack.LogDIEs(log.get(), this); |
| 4518 | #endif |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 4519 | } |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 4520 | // |
| 4521 | // LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| 4522 | // if (log && dwarf_cu) |
| 4523 | // { |
| 4524 | // StreamString s; |
| 4525 | // die->DumpLocation (this, dwarf_cu, s); |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4526 | // GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData()); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 4527 | // |
| 4528 | // } |
| Jim Ingham | 16746d1 | 2011-08-25 23:21:43 +0000 | [diff] [blame] | 4529 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4530 | Type *type_ptr = m_die_to_type.lookup (die); |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 4531 | TypeList* type_list = GetTypeList(); |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4532 | if (type_ptr == NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4533 | { |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 4534 | ClangASTContext &ast = GetClangASTContext(); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 4535 | if (type_is_new_ptr) |
| 4536 | *type_is_new_ptr = true; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4537 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4538 | const dw_tag_t tag = die->Tag(); |
| 4539 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4540 | bool is_forward_declaration = false; |
| 4541 | DWARFDebugInfoEntry::Attributes attributes; |
| 4542 | const char *type_name_cstr = NULL; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 4543 | ConstString type_name_const_str; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4544 | Type::ResolveState resolve_state = Type::eResolveStateUnresolved; |
| 4545 | size_t byte_size = 0; |
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 4546 | bool byte_size_valid = false; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4547 | Declaration decl; |
| 4548 | |
| Greg Clayton | 4957bf6 | 2010-09-30 21:49:03 +0000 | [diff] [blame] | 4549 | Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 4550 | clang_type_t clang_type = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4551 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4552 | dw_attr_t attr; |
| 4553 | |
| 4554 | switch (tag) |
| 4555 | { |
| 4556 | case DW_TAG_base_type: |
| 4557 | case DW_TAG_pointer_type: |
| 4558 | case DW_TAG_reference_type: |
| 4559 | case DW_TAG_typedef: |
| 4560 | case DW_TAG_const_type: |
| 4561 | case DW_TAG_restrict_type: |
| 4562 | case DW_TAG_volatile_type: |
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 4563 | case DW_TAG_unspecified_type: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4564 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4565 | // Set a bit that lets us know that we are currently parsing this |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4566 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4567 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4568 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4569 | uint32_t encoding = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4570 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; |
| 4571 | |
| 4572 | if (num_attributes > 0) |
| 4573 | { |
| 4574 | uint32_t i; |
| 4575 | for (i=0; i<num_attributes; ++i) |
| 4576 | { |
| 4577 | attr = attributes.AttributeAtIndex(i); |
| 4578 | DWARFFormValue form_value; |
| 4579 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 4580 | { |
| 4581 | switch (attr) |
| 4582 | { |
| 4583 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 4584 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 4585 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 4586 | case DW_AT_name: |
| Jim Ingham | 337030f | 2011-04-15 23:41:23 +0000 | [diff] [blame] | 4587 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4588 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Jim Ingham | 337030f | 2011-04-15 23:41:23 +0000 | [diff] [blame] | 4589 | // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't |
| 4590 | // include the "&"... |
| 4591 | if (tag == DW_TAG_reference_type) |
| 4592 | { |
| 4593 | if (strchr (type_name_cstr, '&') == NULL) |
| 4594 | type_name_cstr = NULL; |
| 4595 | } |
| 4596 | if (type_name_cstr) |
| 4597 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4598 | break; |
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 4599 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4600 | case DW_AT_encoding: encoding = form_value.Unsigned(); break; |
| 4601 | case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; |
| 4602 | default: |
| 4603 | case DW_AT_sibling: |
| 4604 | break; |
| 4605 | } |
| 4606 | } |
| 4607 | } |
| 4608 | } |
| 4609 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 4610 | DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\") type => 0x%8.8x\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr, encoding_uid); |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 4611 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4612 | switch (tag) |
| 4613 | { |
| 4614 | default: |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4615 | break; |
| 4616 | |
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 4617 | case DW_TAG_unspecified_type: |
| 4618 | if (strcmp(type_name_cstr, "nullptr_t") == 0) |
| 4619 | { |
| 4620 | resolve_state = Type::eResolveStateFull; |
| 4621 | clang_type = ast.getASTContext()->NullPtrTy.getAsOpaquePtr(); |
| 4622 | break; |
| 4623 | } |
| 4624 | // Fall through to base type below in case we can handle the type there... |
| 4625 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4626 | case DW_TAG_base_type: |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4627 | resolve_state = Type::eResolveStateFull; |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 4628 | clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr, |
| 4629 | encoding, |
| 4630 | byte_size * 8); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4631 | break; |
| 4632 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4633 | case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break; |
| 4634 | case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break; |
| 4635 | case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break; |
| 4636 | case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break; |
| 4637 | case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break; |
| 4638 | case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4639 | } |
| 4640 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4641 | if (clang_type == NULL && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID)) |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4642 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4643 | if (type_name_cstr != NULL && sc.comp_unit != NULL && |
| 4644 | (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus)) |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4645 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4646 | static ConstString g_objc_type_name_id("id"); |
| 4647 | static ConstString g_objc_type_name_Class("Class"); |
| 4648 | static ConstString g_objc_type_name_selector("SEL"); |
| 4649 | |
| 4650 | if (type_name_const_str == g_objc_type_name_id) |
| 4651 | { |
| 4652 | if (log) |
| 4653 | GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'id' built-in type.", |
| 4654 | die->GetOffset(), |
| 4655 | DW_TAG_value_to_name(die->Tag()), |
| 4656 | die->GetName(this, dwarf_cu)); |
| 4657 | clang_type = ast.GetBuiltInType_objc_id(); |
| 4658 | encoding_data_type = Type::eEncodingIsUID; |
| 4659 | encoding_uid = LLDB_INVALID_UID; |
| 4660 | resolve_state = Type::eResolveStateFull; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4661 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4662 | } |
| 4663 | else if (type_name_const_str == g_objc_type_name_Class) |
| 4664 | { |
| 4665 | if (log) |
| 4666 | GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'Class' built-in type.", |
| 4667 | die->GetOffset(), |
| 4668 | DW_TAG_value_to_name(die->Tag()), |
| 4669 | die->GetName(this, dwarf_cu)); |
| 4670 | clang_type = ast.GetBuiltInType_objc_Class(); |
| 4671 | encoding_data_type = Type::eEncodingIsUID; |
| 4672 | encoding_uid = LLDB_INVALID_UID; |
| 4673 | resolve_state = Type::eResolveStateFull; |
| 4674 | } |
| 4675 | else if (type_name_const_str == g_objc_type_name_selector) |
| 4676 | { |
| 4677 | if (log) |
| 4678 | GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'selector' built-in type.", |
| 4679 | die->GetOffset(), |
| 4680 | DW_TAG_value_to_name(die->Tag()), |
| 4681 | die->GetName(this, dwarf_cu)); |
| 4682 | clang_type = ast.GetBuiltInType_objc_selector(); |
| 4683 | encoding_data_type = Type::eEncodingIsUID; |
| 4684 | encoding_uid = LLDB_INVALID_UID; |
| 4685 | resolve_state = Type::eResolveStateFull; |
| 4686 | } |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4687 | } |
| 4688 | } |
| 4689 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 4690 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 4691 | this, |
| 4692 | type_name_const_str, |
| 4693 | byte_size, |
| 4694 | NULL, |
| 4695 | encoding_uid, |
| 4696 | encoding_data_type, |
| 4697 | &decl, |
| 4698 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4699 | resolve_state)); |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 4700 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4701 | m_die_to_type[die] = type_sp.get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4702 | |
| 4703 | // Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false); |
| 4704 | // if (encoding_type != NULL) |
| 4705 | // { |
| 4706 | // if (encoding_type != DIE_IS_BEING_PARSED) |
| 4707 | // type_sp->SetEncodingType(encoding_type); |
| 4708 | // else |
| 4709 | // m_indirect_fixups.push_back(type_sp.get()); |
| 4710 | // } |
| 4711 | } |
| 4712 | break; |
| 4713 | |
| 4714 | case DW_TAG_structure_type: |
| 4715 | case DW_TAG_union_type: |
| 4716 | case DW_TAG_class_type: |
| 4717 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4718 | // Set a bit that lets us know that we are currently parsing this |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4719 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4720 | |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4721 | LanguageType class_language = eLanguageTypeUnknown; |
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 4722 | bool is_complete_objc_class = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4723 | //bool struct_is_class = false; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4724 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4725 | if (num_attributes > 0) |
| 4726 | { |
| 4727 | uint32_t i; |
| 4728 | for (i=0; i<num_attributes; ++i) |
| 4729 | { |
| 4730 | attr = attributes.AttributeAtIndex(i); |
| 4731 | DWARFFormValue form_value; |
| 4732 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 4733 | { |
| 4734 | switch (attr) |
| 4735 | { |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4736 | case DW_AT_decl_file: |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4737 | if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid()) |
| 4738 | { |
| 4739 | // llvm-gcc outputs invalid DW_AT_decl_file attributes that always |
| 4740 | // point to the compile unit file, so we clear this invalid value |
| 4741 | // so that we can still unique types efficiently. |
| 4742 | decl.SetFile(FileSpec ("<invalid>", false)); |
| 4743 | } |
| 4744 | else |
| 4745 | decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4746 | break; |
| 4747 | |
| 4748 | case DW_AT_decl_line: |
| 4749 | decl.SetLine(form_value.Unsigned()); |
| 4750 | break; |
| 4751 | |
| 4752 | case DW_AT_decl_column: |
| 4753 | decl.SetColumn(form_value.Unsigned()); |
| 4754 | break; |
| 4755 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4756 | case DW_AT_name: |
| 4757 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 4758 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4759 | break; |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4760 | |
| 4761 | case DW_AT_byte_size: |
| 4762 | byte_size = form_value.Unsigned(); |
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 4763 | byte_size_valid = true; |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4764 | break; |
| 4765 | |
| 4766 | case DW_AT_accessibility: |
| 4767 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); |
| 4768 | break; |
| 4769 | |
| 4770 | case DW_AT_declaration: |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 4771 | is_forward_declaration = form_value.Unsigned() != 0; |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4772 | break; |
| 4773 | |
| 4774 | case DW_AT_APPLE_runtime_class: |
| 4775 | class_language = (LanguageType)form_value.Signed(); |
| 4776 | break; |
| 4777 | |
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 4778 | case DW_AT_APPLE_objc_complete_type: |
| 4779 | is_complete_objc_class = form_value.Signed(); |
| 4780 | break; |
| 4781 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4782 | case DW_AT_allocated: |
| 4783 | case DW_AT_associated: |
| 4784 | case DW_AT_data_location: |
| 4785 | case DW_AT_description: |
| 4786 | case DW_AT_start_scope: |
| 4787 | case DW_AT_visibility: |
| 4788 | default: |
| 4789 | case DW_AT_sibling: |
| 4790 | break; |
| 4791 | } |
| 4792 | } |
| 4793 | } |
| 4794 | } |
| 4795 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4796 | UniqueDWARFASTType unique_ast_entry; |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 4797 | |
| Greg Clayton | 123edca | 2012-03-02 00:07:15 +0000 | [diff] [blame] | 4798 | // Only try and unique the type if it has a name. |
| 4799 | if (type_name_const_str && |
| 4800 | GetUniqueDWARFASTTypeMap().Find (type_name_const_str, |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 4801 | this, |
| 4802 | dwarf_cu, |
| 4803 | die, |
| 4804 | decl, |
| 4805 | byte_size_valid ? byte_size : -1, |
| 4806 | unique_ast_entry)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4807 | { |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 4808 | // We have already parsed this type or from another |
| 4809 | // compile unit. GCC loves to use the "one definition |
| 4810 | // rule" which can result in multiple definitions |
| 4811 | // of the same class over and over in each compile |
| 4812 | // unit. |
| 4813 | type_sp = unique_ast_entry.m_type_sp; |
| 4814 | if (type_sp) |
| Greg Clayton | c615ce4 | 2010-11-09 04:42:43 +0000 | [diff] [blame] | 4815 | { |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 4816 | m_die_to_type[die] = type_sp.get(); |
| 4817 | return type_sp; |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 4818 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4819 | } |
| 4820 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 4821 | DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr); |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4822 | |
| 4823 | int tag_decl_kind = -1; |
| 4824 | AccessType default_accessibility = eAccessNone; |
| 4825 | if (tag == DW_TAG_structure_type) |
| 4826 | { |
| 4827 | tag_decl_kind = clang::TTK_Struct; |
| 4828 | default_accessibility = eAccessPublic; |
| 4829 | } |
| 4830 | else if (tag == DW_TAG_union_type) |
| 4831 | { |
| 4832 | tag_decl_kind = clang::TTK_Union; |
| 4833 | default_accessibility = eAccessPublic; |
| 4834 | } |
| 4835 | else if (tag == DW_TAG_class_type) |
| 4836 | { |
| 4837 | tag_decl_kind = clang::TTK_Class; |
| 4838 | default_accessibility = eAccessPrivate; |
| 4839 | } |
| Greg Clayton | 3a5f29a | 2011-11-30 02:48:28 +0000 | [diff] [blame] | 4840 | |
| 4841 | if (byte_size_valid && byte_size == 0 && type_name_cstr && |
| 4842 | die->HasChildren() == false && |
| 4843 | sc.comp_unit->GetLanguage() == eLanguageTypeObjC) |
| 4844 | { |
| 4845 | // Work around an issue with clang at the moment where |
| 4846 | // forward declarations for objective C classes are emitted |
| 4847 | // as: |
| 4848 | // DW_TAG_structure_type [2] |
| 4849 | // DW_AT_name( "ForwardObjcClass" ) |
| 4850 | // DW_AT_byte_size( 0x00 ) |
| 4851 | // DW_AT_decl_file( "..." ) |
| 4852 | // DW_AT_decl_line( 1 ) |
| 4853 | // |
| 4854 | // Note that there is no DW_AT_declaration and there are |
| 4855 | // no children, and the byte size is zero. |
| 4856 | is_forward_declaration = true; |
| 4857 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4858 | |
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 4859 | if (class_language == eLanguageTypeObjC) |
| 4860 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4861 | if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu)) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4862 | { |
| 4863 | // We have a valid eSymbolTypeObjCClass class symbol whose |
| 4864 | // name matches the current objective C class that we |
| 4865 | // are trying to find and this DIE isn't the complete |
| 4866 | // definition (we checked is_complete_objc_class above and |
| 4867 | // know it is false), so the real definition is in here somewhere |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4868 | type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true); |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4869 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4870 | if (!type_sp && m_debug_map_symfile) |
| 4871 | { |
| 4872 | // We weren't able to find a full declaration in |
| 4873 | // this DWARF, see if we have a declaration anywhere |
| 4874 | // else... |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4875 | type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4876 | } |
| 4877 | |
| 4878 | if (type_sp) |
| 4879 | { |
| 4880 | if (log) |
| 4881 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4882 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 4883 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an incomplete objc type, complete type is 0x%8.8llx", |
| 4884 | this, |
| 4885 | die->GetOffset(), |
| 4886 | DW_TAG_value_to_name(tag), |
| 4887 | type_name_cstr, |
| 4888 | type_sp->GetID()); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4889 | } |
| 4890 | |
| 4891 | // We found a real definition for this type elsewhere |
| 4892 | // so lets use it and cache the fact that we found |
| 4893 | // a complete type for this die |
| 4894 | m_die_to_type[die] = type_sp.get(); |
| 4895 | return type_sp; |
| 4896 | } |
| 4897 | } |
| 4898 | } |
| 4899 | |
| 4900 | |
| 4901 | if (is_forward_declaration) |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4902 | { |
| 4903 | // We have a forward declaration to a type and we need |
| 4904 | // to try and find a full declaration. We look in the |
| 4905 | // current type index just in case we have a forward |
| 4906 | // declaration followed by an actual declarations in the |
| 4907 | // DWARF. If this fails, we need to look elsewhere... |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 4908 | if (log) |
| 4909 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4910 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 4911 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type", |
| 4912 | this, |
| 4913 | die->GetOffset(), |
| 4914 | DW_TAG_value_to_name(tag), |
| 4915 | type_name_cstr); |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 4916 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4917 | |
| 4918 | type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str); |
| 4919 | |
| 4920 | if (!type_sp && m_debug_map_symfile) |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 4921 | { |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4922 | // We weren't able to find a full declaration in |
| 4923 | // this DWARF, see if we have a declaration anywhere |
| 4924 | // else... |
| 4925 | type_sp = m_debug_map_symfile->FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str); |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 4926 | } |
| 4927 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4928 | if (type_sp) |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 4929 | { |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 4930 | if (log) |
| 4931 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4932 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 4933 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8llx", |
| 4934 | this, |
| 4935 | die->GetOffset(), |
| 4936 | DW_TAG_value_to_name(tag), |
| 4937 | type_name_cstr, |
| 4938 | type_sp->GetID()); |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 4939 | } |
| 4940 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4941 | // We found a real definition for this type elsewhere |
| 4942 | // so lets use it and cache the fact that we found |
| 4943 | // a complete type for this die |
| 4944 | m_die_to_type[die] = type_sp.get(); |
| 4945 | return type_sp; |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 4946 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4947 | } |
| 4948 | assert (tag_decl_kind != -1); |
| 4949 | bool clang_type_was_created = false; |
| 4950 | clang_type = m_forward_decl_die_to_clang_type.lookup (die); |
| 4951 | if (clang_type == NULL) |
| 4952 | { |
| Sean Callanan | 4d04c6a | 2012-02-09 22:54:11 +0000 | [diff] [blame] | 4953 | const DWARFDebugInfoEntry *decl_ctx_die; |
| 4954 | |
| 4955 | clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die); |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 4956 | if (accessibility == eAccessNone && decl_ctx) |
| 4957 | { |
| 4958 | // Check the decl context that contains this class/struct/union. |
| 4959 | // If it is a class we must give it an accessability. |
| 4960 | const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind(); |
| 4961 | if (DeclKindIsCXXClass (containing_decl_kind)) |
| 4962 | accessibility = default_accessibility; |
| 4963 | } |
| 4964 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 4965 | if (type_name_cstr && strchr (type_name_cstr, '<')) |
| 4966 | { |
| 4967 | ClangASTContext::TemplateParameterInfos template_param_infos; |
| 4968 | if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos)) |
| 4969 | { |
| 4970 | clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx, |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 4971 | accessibility, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 4972 | type_name_cstr, |
| 4973 | tag_decl_kind, |
| 4974 | template_param_infos); |
| 4975 | |
| 4976 | clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx, |
| 4977 | class_template_decl, |
| 4978 | tag_decl_kind, |
| 4979 | template_param_infos); |
| 4980 | clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl); |
| 4981 | clang_type_was_created = true; |
| 4982 | } |
| 4983 | } |
| 4984 | |
| 4985 | if (!clang_type_was_created) |
| 4986 | { |
| 4987 | clang_type_was_created = true; |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 4988 | clang_type = ast.CreateRecordType (decl_ctx, |
| 4989 | accessibility, |
| 4990 | type_name_cstr, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 4991 | tag_decl_kind, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 4992 | class_language); |
| 4993 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 4994 | } |
| 4995 | |
| 4996 | // Store a forward declaration to this class type in case any |
| 4997 | // parameters in any class methods need it for the clang |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 4998 | // types for function prototypes. |
| 4999 | LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5000 | type_sp.reset (new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5001 | this, |
| 5002 | type_name_const_str, |
| 5003 | byte_size, |
| 5004 | NULL, |
| 5005 | LLDB_INVALID_UID, |
| 5006 | Type::eEncodingIsUID, |
| 5007 | &decl, |
| 5008 | clang_type, |
| 5009 | Type::eResolveStateForward)); |
| Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 5010 | |
| 5011 | type_sp->SetIsCompleteObjCClass(is_complete_objc_class); |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5012 | |
| 5013 | |
| 5014 | // Add our type to the unique type map so we don't |
| 5015 | // end up creating many copies of the same type over |
| 5016 | // and over in the ASTContext for our module |
| 5017 | unique_ast_entry.m_type_sp = type_sp; |
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 5018 | unique_ast_entry.m_symfile = this; |
| 5019 | unique_ast_entry.m_cu = dwarf_cu; |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5020 | unique_ast_entry.m_die = die; |
| 5021 | unique_ast_entry.m_declaration = decl; |
| Sean Callanan | 5970059 | 2012-02-13 22:30:16 +0000 | [diff] [blame] | 5022 | unique_ast_entry.m_byte_size = byte_size; |
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 5023 | GetUniqueDWARFASTTypeMap().Insert (type_name_const_str, |
| 5024 | unique_ast_entry); |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5025 | |
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 5026 | if (!is_forward_declaration) |
| 5027 | { |
| 5028 | if (die->HasChildren() == false) |
| 5029 | { |
| 5030 | // No children for this struct/union/class, lets finish it |
| 5031 | ast.StartTagDeclarationDefinition (clang_type); |
| 5032 | ast.CompleteTagDeclarationDefinition (clang_type); |
| 5033 | } |
| 5034 | else if (clang_type_was_created) |
| 5035 | { |
| 5036 | // Leave this as a forward declaration until we need |
| 5037 | // to know the details of the type. lldb_private::Type |
| 5038 | // will automatically call the SymbolFile virtual function |
| 5039 | // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)" |
| 5040 | // When the definition needs to be defined. |
| 5041 | m_forward_decl_die_to_clang_type[die] = clang_type; |
| 5042 | m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die; |
| 5043 | ClangASTContext::SetHasExternalStorage (clang_type, true); |
| 5044 | } |
| Greg Clayton | c615ce4 | 2010-11-09 04:42:43 +0000 | [diff] [blame] | 5045 | } |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 5046 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5047 | } |
| 5048 | break; |
| 5049 | |
| 5050 | case DW_TAG_enumeration_type: |
| 5051 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5052 | // Set a bit that lets us know that we are currently parsing this |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5053 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5054 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5055 | lldb::user_id_t encoding_uid = DW_INVALID_OFFSET; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5056 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5057 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5058 | if (num_attributes > 0) |
| 5059 | { |
| 5060 | uint32_t i; |
| 5061 | |
| 5062 | for (i=0; i<num_attributes; ++i) |
| 5063 | { |
| 5064 | attr = attributes.AttributeAtIndex(i); |
| 5065 | DWARFFormValue form_value; |
| 5066 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 5067 | { |
| 5068 | switch (attr) |
| 5069 | { |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 5070 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 5071 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 5072 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5073 | case DW_AT_name: |
| 5074 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5075 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5076 | break; |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 5077 | case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; |
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 5078 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break; |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 5079 | case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
| 5080 | case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5081 | case DW_AT_allocated: |
| 5082 | case DW_AT_associated: |
| 5083 | case DW_AT_bit_stride: |
| 5084 | case DW_AT_byte_stride: |
| 5085 | case DW_AT_data_location: |
| 5086 | case DW_AT_description: |
| 5087 | case DW_AT_start_scope: |
| 5088 | case DW_AT_visibility: |
| 5089 | case DW_AT_specification: |
| 5090 | case DW_AT_abstract_origin: |
| 5091 | case DW_AT_sibling: |
| 5092 | break; |
| 5093 | } |
| 5094 | } |
| 5095 | } |
| 5096 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5097 | DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr); |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 5098 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5099 | clang_type_t enumerator_clang_type = NULL; |
| 5100 | clang_type = m_forward_decl_die_to_clang_type.lookup (die); |
| 5101 | if (clang_type == NULL) |
| 5102 | { |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5103 | enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL, |
| 5104 | DW_ATE_signed, |
| 5105 | byte_size * 8); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 5106 | clang_type = ast.CreateEnumerationType (type_name_cstr, |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 5107 | GetClangDeclContextContainingDIE (dwarf_cu, die, NULL), |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 5108 | decl, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5109 | enumerator_clang_type); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5110 | } |
| 5111 | else |
| 5112 | { |
| 5113 | enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type); |
| 5114 | assert (enumerator_clang_type != NULL); |
| 5115 | } |
| 5116 | |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 5117 | LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die); |
| 5118 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5119 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5120 | this, |
| 5121 | type_name_const_str, |
| 5122 | byte_size, |
| 5123 | NULL, |
| 5124 | encoding_uid, |
| 5125 | Type::eEncodingIsUID, |
| 5126 | &decl, |
| 5127 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5128 | Type::eResolveStateForward)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5129 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 5130 | ast.StartTagDeclarationDefinition (clang_type); |
| 5131 | if (die->HasChildren()) |
| 5132 | { |
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 5133 | SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); |
| 5134 | ParseChildEnumerators(cu_sc, clang_type, type_sp->GetByteSize(), dwarf_cu, die); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 5135 | } |
| 5136 | ast.CompleteTagDeclarationDefinition (clang_type); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5137 | } |
| 5138 | } |
| 5139 | break; |
| 5140 | |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 5141 | case DW_TAG_inlined_subroutine: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5142 | case DW_TAG_subprogram: |
| 5143 | case DW_TAG_subroutine_type: |
| 5144 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5145 | // Set a bit that lets us know that we are currently parsing this |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5146 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5147 | |
| 5148 | const char *mangled = NULL; |
| 5149 | dw_offset_t type_die_offset = DW_INVALID_OFFSET; |
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 5150 | bool is_variadic = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5151 | bool is_inline = false; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5152 | bool is_static = false; |
| 5153 | bool is_virtual = false; |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 5154 | bool is_explicit = false; |
| Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 5155 | bool is_artificial = false; |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5156 | dw_offset_t specification_die_offset = DW_INVALID_OFFSET; |
| 5157 | dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5158 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5159 | unsigned type_quals = 0; |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 5160 | clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5161 | |
| 5162 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5163 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5164 | if (num_attributes > 0) |
| 5165 | { |
| 5166 | uint32_t i; |
| 5167 | for (i=0; i<num_attributes; ++i) |
| 5168 | { |
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 5169 | attr = attributes.AttributeAtIndex(i); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5170 | DWARFFormValue form_value; |
| 5171 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 5172 | { |
| 5173 | switch (attr) |
| 5174 | { |
| 5175 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 5176 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 5177 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 5178 | case DW_AT_name: |
| 5179 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5180 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5181 | break; |
| 5182 | |
| 5183 | case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break; |
| 5184 | case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break; |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 5185 | case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 5186 | case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5187 | case DW_AT_inline: is_inline = form_value.Unsigned() != 0; break; |
| 5188 | case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break; |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 5189 | case DW_AT_explicit: is_explicit = form_value.Unsigned() != 0; break; |
| Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 5190 | case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break; |
| 5191 | |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 5192 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5193 | case DW_AT_external: |
| 5194 | if (form_value.Unsigned()) |
| 5195 | { |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 5196 | if (storage == clang::SC_None) |
| 5197 | storage = clang::SC_Extern; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5198 | else |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 5199 | storage = clang::SC_PrivateExtern; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5200 | } |
| 5201 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5202 | |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5203 | case DW_AT_specification: |
| 5204 | specification_die_offset = form_value.Reference(dwarf_cu); |
| 5205 | break; |
| 5206 | |
| 5207 | case DW_AT_abstract_origin: |
| 5208 | abstract_origin_die_offset = form_value.Reference(dwarf_cu); |
| 5209 | break; |
| 5210 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5211 | case DW_AT_allocated: |
| 5212 | case DW_AT_associated: |
| 5213 | case DW_AT_address_class: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5214 | case DW_AT_calling_convention: |
| 5215 | case DW_AT_data_location: |
| 5216 | case DW_AT_elemental: |
| 5217 | case DW_AT_entry_pc: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5218 | case DW_AT_frame_base: |
| 5219 | case DW_AT_high_pc: |
| 5220 | case DW_AT_low_pc: |
| 5221 | case DW_AT_object_pointer: |
| 5222 | case DW_AT_prototyped: |
| 5223 | case DW_AT_pure: |
| 5224 | case DW_AT_ranges: |
| 5225 | case DW_AT_recursive: |
| 5226 | case DW_AT_return_addr: |
| 5227 | case DW_AT_segment: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5228 | case DW_AT_start_scope: |
| 5229 | case DW_AT_static_link: |
| 5230 | case DW_AT_trampoline: |
| 5231 | case DW_AT_visibility: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5232 | case DW_AT_vtable_elem_location: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5233 | case DW_AT_description: |
| 5234 | case DW_AT_sibling: |
| 5235 | break; |
| 5236 | } |
| 5237 | } |
| 5238 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5239 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5240 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5241 | DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr); |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 5242 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5243 | clang_type_t return_clang_type = NULL; |
| 5244 | Type *func_type = NULL; |
| 5245 | |
| 5246 | if (type_die_offset != DW_INVALID_OFFSET) |
| 5247 | func_type = ResolveTypeUID(type_die_offset); |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 5248 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5249 | if (func_type) |
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 5250 | return_clang_type = func_type->GetClangForwardType(); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5251 | else |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5252 | return_clang_type = ast.GetBuiltInType_void(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5253 | |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 5254 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5255 | std::vector<clang_type_t> function_param_types; |
| 5256 | std::vector<clang::ParmVarDecl*> function_param_decls; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5257 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5258 | // Parse the function children for the parameters |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 5259 | |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 5260 | const DWARFDebugInfoEntry *decl_ctx_die = NULL; |
| 5261 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die); |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 5262 | const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind(); |
| 5263 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5264 | const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind); |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 5265 | // Start off static. This will be set to false in ParseChildParameters(...) |
| 5266 | // if we find a "this" paramters as the first parameter |
| 5267 | if (is_cxx_method) |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 5268 | is_static = true; |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 5269 | ClangASTContext::TemplateParameterInfos template_param_infos; |
| 5270 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5271 | if (die->HasChildren()) |
| 5272 | { |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5273 | bool skip_artificial = true; |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5274 | ParseChildParameters (sc, |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 5275 | containing_decl_ctx, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5276 | dwarf_cu, |
| 5277 | die, |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 5278 | skip_artificial, |
| 5279 | is_static, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5280 | type_list, |
| 5281 | function_param_types, |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 5282 | function_param_decls, |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 5283 | type_quals, |
| 5284 | template_param_infos); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5285 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5286 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5287 | // clang_type will get the function prototype clang type after this call |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5288 | clang_type = ast.CreateFunctionType (return_clang_type, |
| 5289 | &function_param_types[0], |
| 5290 | function_param_types.size(), |
| 5291 | is_variadic, |
| 5292 | type_quals); |
| 5293 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5294 | if (type_name_cstr) |
| 5295 | { |
| 5296 | bool type_handled = false; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5297 | if (tag == DW_TAG_subprogram) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5298 | { |
| Greg Clayton | 7c81042 | 2012-01-18 23:40:49 +0000 | [diff] [blame] | 5299 | ConstString class_name; |
| Greg Clayton | e42ae84 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 5300 | ConstString class_name_no_category; |
| 5301 | if (ObjCLanguageRuntime::ParseMethodName (type_name_cstr, &class_name, NULL, NULL, &class_name_no_category)) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5302 | { |
| Greg Clayton | e42ae84 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 5303 | // Use the class name with no category if there is one |
| 5304 | if (class_name_no_category) |
| 5305 | class_name = class_name_no_category; |
| 5306 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5307 | SymbolContext empty_sc; |
| 5308 | clang_type_t class_opaque_type = NULL; |
| Greg Clayton | 7c81042 | 2012-01-18 23:40:49 +0000 | [diff] [blame] | 5309 | if (class_name) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5310 | { |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5311 | TypeList types; |
| Greg Clayton | 278a16b | 2012-01-19 00:52:59 +0000 | [diff] [blame] | 5312 | TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false)); |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5313 | |
| 5314 | if (complete_objc_class_type_sp) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5315 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5316 | clang_type_t type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType(); |
| 5317 | if (ClangASTContext::IsObjCClassType (type_clang_forward_type)) |
| 5318 | class_opaque_type = type_clang_forward_type; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5319 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5320 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5321 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5322 | if (class_opaque_type) |
| 5323 | { |
| 5324 | // If accessibility isn't set to anything valid, assume public for |
| 5325 | // now... |
| 5326 | if (accessibility == eAccessNone) |
| 5327 | accessibility = eAccessPublic; |
| 5328 | |
| 5329 | clang::ObjCMethodDecl *objc_method_decl; |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5330 | objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type, |
| 5331 | type_name_cstr, |
| 5332 | clang_type, |
| 5333 | accessibility); |
| Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 5334 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5335 | type_handled = objc_method_decl != NULL; |
| 5336 | } |
| 5337 | } |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 5338 | else if (is_cxx_method) |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5339 | { |
| 5340 | // Look at the parent of this DIE and see if is is |
| 5341 | // a class or struct and see if this is actually a |
| 5342 | // C++ method |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 5343 | Type *class_type = ResolveType (dwarf_cu, decl_ctx_die); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5344 | if (class_type) |
| 5345 | { |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5346 | if (specification_die_offset != DW_INVALID_OFFSET) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5347 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 5348 | // We have a specification which we are going to base our function |
| 5349 | // prototype off of, so we need this type to be completed so that the |
| 5350 | // m_die_to_decl_ctx for the method in the specification has a valid |
| 5351 | // clang decl context. |
| Greg Clayton | 8eb732e | 2011-12-13 04:34:06 +0000 | [diff] [blame] | 5352 | class_type->GetClangForwardType(); |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5353 | // If we have a specification, then the function type should have been |
| 5354 | // made with the specification and not with this die. |
| 5355 | DWARFCompileUnitSP spec_cu_sp; |
| 5356 | const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp); |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 5357 | clang::DeclContext *spec_clang_decl_ctx = GetCachedClangDeclContextForDIE (spec_die); |
| 5358 | if (spec_clang_decl_ctx) |
| 5359 | { |
| 5360 | LinkDeclContextToDIE(spec_clang_decl_ctx, die); |
| 5361 | } |
| 5362 | else |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 5363 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5364 | GetObjectFile()->GetModule()->ReportWarning ("0x%8.8llx: DW_AT_specification(0x%8.8x) has no decl\n", |
| 5365 | MakeUserID(die->GetOffset()), |
| 5366 | specification_die_offset); |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 5367 | } |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5368 | type_handled = true; |
| 5369 | } |
| 5370 | else if (abstract_origin_die_offset != DW_INVALID_OFFSET) |
| 5371 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 5372 | // We have a specification which we are going to base our function |
| 5373 | // prototype off of, so we need this type to be completed so that the |
| 5374 | // m_die_to_decl_ctx for the method in the abstract origin has a valid |
| 5375 | // clang decl context. |
| Greg Clayton | 8eb732e | 2011-12-13 04:34:06 +0000 | [diff] [blame] | 5376 | class_type->GetClangForwardType(); |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 5377 | |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5378 | DWARFCompileUnitSP abs_cu_sp; |
| 5379 | const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp); |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 5380 | clang::DeclContext *abs_clang_decl_ctx = GetCachedClangDeclContextForDIE (abs_die); |
| 5381 | if (abs_clang_decl_ctx) |
| 5382 | { |
| 5383 | LinkDeclContextToDIE (abs_clang_decl_ctx, die); |
| 5384 | } |
| 5385 | else |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 5386 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5387 | GetObjectFile()->GetModule()->ReportWarning ("0x%8.8llx: DW_AT_abstract_origin(0x%8.8x) has no decl\n", |
| 5388 | MakeUserID(die->GetOffset()), |
| 5389 | abstract_origin_die_offset); |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 5390 | } |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5391 | type_handled = true; |
| 5392 | } |
| 5393 | else |
| 5394 | { |
| 5395 | clang_type_t class_opaque_type = class_type->GetClangForwardType(); |
| 5396 | if (ClangASTContext::IsCXXClassType (class_opaque_type)) |
| Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 5397 | { |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 5398 | if (ClangASTContext::IsBeingDefined (class_opaque_type)) |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5399 | { |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 5400 | // Neither GCC 4.2 nor clang++ currently set a valid accessibility |
| 5401 | // in the DWARF for C++ methods... Default to public for now... |
| 5402 | if (accessibility == eAccessNone) |
| 5403 | accessibility = eAccessPublic; |
| 5404 | |
| 5405 | if (!is_static && !die->HasChildren()) |
| 5406 | { |
| 5407 | // We have a C++ member function with no children (this pointer!) |
| 5408 | // and clang will get mad if we try and make a function that isn't |
| 5409 | // well formed in the DWARF, so we will just skip it... |
| 5410 | type_handled = true; |
| 5411 | } |
| 5412 | else |
| 5413 | { |
| 5414 | clang::CXXMethodDecl *cxx_method_decl; |
| 5415 | // REMOVE THE CRASH DESCRIPTION BELOW |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5416 | Host::SetCrashDescriptionWithFormat ("SymbolFileDWARF::ParseType() is adding a method %s to class %s in DIE 0x%8.8llx from %s/%s", |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 5417 | type_name_cstr, |
| 5418 | class_type->GetName().GetCString(), |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5419 | MakeUserID(die->GetOffset()), |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 5420 | m_obj_file->GetFileSpec().GetDirectory().GetCString(), |
| 5421 | m_obj_file->GetFileSpec().GetFilename().GetCString()); |
| 5422 | |
| Sean Callanan | c1b732d | 2011-11-01 18:07:13 +0000 | [diff] [blame] | 5423 | const bool is_attr_used = false; |
| 5424 | |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 5425 | cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type, |
| 5426 | type_name_cstr, |
| 5427 | clang_type, |
| 5428 | accessibility, |
| 5429 | is_virtual, |
| 5430 | is_static, |
| 5431 | is_inline, |
| Sean Callanan | c1b732d | 2011-11-01 18:07:13 +0000 | [diff] [blame] | 5432 | is_explicit, |
| Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 5433 | is_attr_used, |
| 5434 | is_artificial); |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 5435 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die); |
| 5436 | |
| Greg Clayton | f49e65a | 2011-11-10 18:31:53 +0000 | [diff] [blame] | 5437 | Host::SetCrashDescription (NULL); |
| 5438 | |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 5439 | type_handled = cxx_method_decl != NULL; |
| 5440 | } |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5441 | } |
| 5442 | else |
| 5443 | { |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 5444 | // We were asked to parse the type for a method in a class, yet the |
| 5445 | // class hasn't been asked to complete itself through the |
| 5446 | // clang::ExternalASTSource protocol, so we need to just have the |
| 5447 | // class complete itself and do things the right way, then our |
| 5448 | // DIE should then have an entry in the m_die_to_type map. First |
| 5449 | // we need to modify the m_die_to_type so it doesn't think we are |
| 5450 | // trying to parse this DIE anymore... |
| 5451 | m_die_to_type[die] = NULL; |
| 5452 | |
| 5453 | // Now we get the full type to force our class type to complete itself |
| 5454 | // using the clang::ExternalASTSource protocol which will parse all |
| 5455 | // base classes and all methods (including the method for this DIE). |
| 5456 | class_type->GetClangFullType(); |
| Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 5457 | |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 5458 | // The type for this DIE should have been filled in the function call above |
| 5459 | type_ptr = m_die_to_type[die]; |
| 5460 | if (type_ptr) |
| 5461 | { |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 5462 | type_sp = type_ptr->shared_from_this(); |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 5463 | break; |
| 5464 | } |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5465 | } |
| Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 5466 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5467 | } |
| 5468 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5469 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5470 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5471 | |
| 5472 | if (!type_handled) |
| 5473 | { |
| 5474 | // We just have a function that isn't part of a class |
| Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 5475 | clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (containing_decl_ctx, |
| 5476 | type_name_cstr, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5477 | clang_type, |
| 5478 | storage, |
| 5479 | is_inline); |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 5480 | |
| 5481 | // if (template_param_infos.GetSize() > 0) |
| 5482 | // { |
| 5483 | // clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx, |
| 5484 | // function_decl, |
| 5485 | // type_name_cstr, |
| 5486 | // template_param_infos); |
| 5487 | // |
| 5488 | // ast.CreateFunctionTemplateSpecializationInfo (function_decl, |
| 5489 | // func_template_decl, |
| 5490 | // template_param_infos); |
| 5491 | // } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5492 | // Add the decl to our DIE to decl context map |
| 5493 | assert (function_decl); |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 5494 | LinkDeclContextToDIE(function_decl, die); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5495 | if (!function_param_decls.empty()) |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5496 | ast.SetFunctionParameters (function_decl, |
| 5497 | &function_param_decls.front(), |
| 5498 | function_param_decls.size()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5499 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5500 | } |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5501 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5502 | this, |
| 5503 | type_name_const_str, |
| 5504 | 0, |
| 5505 | NULL, |
| 5506 | LLDB_INVALID_UID, |
| 5507 | Type::eEncodingIsUID, |
| 5508 | &decl, |
| 5509 | clang_type, |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5510 | Type::eResolveStateFull)); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5511 | assert(type_sp.get()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5512 | } |
| 5513 | break; |
| 5514 | |
| 5515 | case DW_TAG_array_type: |
| 5516 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5517 | // Set a bit that lets us know that we are currently parsing this |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5518 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5519 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5520 | lldb::user_id_t type_die_offset = DW_INVALID_OFFSET; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5521 | int64_t first_index = 0; |
| 5522 | uint32_t byte_stride = 0; |
| 5523 | uint32_t bit_stride = 0; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5524 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5525 | |
| 5526 | if (num_attributes > 0) |
| 5527 | { |
| 5528 | uint32_t i; |
| 5529 | for (i=0; i<num_attributes; ++i) |
| 5530 | { |
| 5531 | attr = attributes.AttributeAtIndex(i); |
| 5532 | DWARFFormValue form_value; |
| 5533 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 5534 | { |
| 5535 | switch (attr) |
| 5536 | { |
| 5537 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 5538 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 5539 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 5540 | case DW_AT_name: |
| 5541 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5542 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5543 | break; |
| 5544 | |
| 5545 | case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break; |
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 5546 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5547 | case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break; |
| 5548 | case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break; |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 5549 | case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 5550 | case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5551 | case DW_AT_allocated: |
| 5552 | case DW_AT_associated: |
| 5553 | case DW_AT_data_location: |
| 5554 | case DW_AT_description: |
| 5555 | case DW_AT_ordering: |
| 5556 | case DW_AT_start_scope: |
| 5557 | case DW_AT_visibility: |
| 5558 | case DW_AT_specification: |
| 5559 | case DW_AT_abstract_origin: |
| 5560 | case DW_AT_sibling: |
| 5561 | break; |
| 5562 | } |
| 5563 | } |
| 5564 | } |
| 5565 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5566 | DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr); |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 5567 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5568 | Type *element_type = ResolveTypeUID(type_die_offset); |
| 5569 | |
| 5570 | if (element_type) |
| 5571 | { |
| 5572 | std::vector<uint64_t> element_orders; |
| 5573 | ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride); |
| Greg Clayton | a134cc1 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 5574 | // We have an array that claims to have no members, lets give it at least one member... |
| 5575 | if (element_orders.empty()) |
| 5576 | element_orders.push_back (1); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5577 | if (byte_stride == 0 && bit_stride == 0) |
| 5578 | byte_stride = element_type->GetByteSize(); |
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 5579 | clang_type_t array_element_type = element_type->GetClangForwardType(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5580 | uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride; |
| 5581 | uint64_t num_elements = 0; |
| 5582 | std::vector<uint64_t>::const_reverse_iterator pos; |
| 5583 | std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend(); |
| 5584 | for (pos = element_orders.rbegin(); pos != end; ++pos) |
| 5585 | { |
| 5586 | num_elements = *pos; |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5587 | clang_type = ast.CreateArrayType (array_element_type, |
| 5588 | num_elements, |
| 5589 | num_elements * array_element_bit_stride); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5590 | array_element_type = clang_type; |
| 5591 | array_element_bit_stride = array_element_bit_stride * num_elements; |
| 5592 | } |
| 5593 | ConstString empty_name; |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5594 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5595 | this, |
| 5596 | empty_name, |
| 5597 | array_element_bit_stride / 8, |
| 5598 | NULL, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5599 | type_die_offset, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5600 | Type::eEncodingIsUID, |
| 5601 | &decl, |
| 5602 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5603 | Type::eResolveStateFull)); |
| 5604 | type_sp->SetEncodingType (element_type); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5605 | } |
| 5606 | } |
| 5607 | } |
| 5608 | break; |
| 5609 | |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 5610 | case DW_TAG_ptr_to_member_type: |
| 5611 | { |
| 5612 | dw_offset_t type_die_offset = DW_INVALID_OFFSET; |
| 5613 | dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET; |
| 5614 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5615 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 5616 | |
| 5617 | if (num_attributes > 0) { |
| 5618 | uint32_t i; |
| 5619 | for (i=0; i<num_attributes; ++i) |
| 5620 | { |
| 5621 | attr = attributes.AttributeAtIndex(i); |
| 5622 | DWARFFormValue form_value; |
| 5623 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 5624 | { |
| 5625 | switch (attr) |
| 5626 | { |
| 5627 | case DW_AT_type: |
| 5628 | type_die_offset = form_value.Reference(dwarf_cu); break; |
| 5629 | case DW_AT_containing_type: |
| 5630 | containing_type_die_offset = form_value.Reference(dwarf_cu); break; |
| 5631 | } |
| 5632 | } |
| 5633 | } |
| 5634 | |
| 5635 | Type *pointee_type = ResolveTypeUID(type_die_offset); |
| 5636 | Type *class_type = ResolveTypeUID(containing_type_die_offset); |
| 5637 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5638 | clang_type_t pointee_clang_type = pointee_type->GetClangForwardType(); |
| 5639 | clang_type_t class_clang_type = class_type->GetClangLayoutType(); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 5640 | |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5641 | clang_type = ast.CreateMemberPointerType(pointee_clang_type, |
| 5642 | class_clang_type); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 5643 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5644 | byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(), |
| 5645 | clang_type) / 8; |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 5646 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5647 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5648 | this, |
| 5649 | type_name_const_str, |
| 5650 | byte_size, |
| 5651 | NULL, |
| 5652 | LLDB_INVALID_UID, |
| 5653 | Type::eEncodingIsUID, |
| 5654 | NULL, |
| 5655 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5656 | Type::eResolveStateForward)); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 5657 | } |
| 5658 | |
| 5659 | break; |
| 5660 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5661 | default: |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 5662 | assert(false && "Unhandled type tag!"); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5663 | break; |
| 5664 | } |
| 5665 | |
| 5666 | if (type_sp.get()) |
| 5667 | { |
| 5668 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); |
| 5669 | dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
| 5670 | |
| 5671 | SymbolContextScope * symbol_context_scope = NULL; |
| 5672 | if (sc_parent_tag == DW_TAG_compile_unit) |
| 5673 | { |
| 5674 | symbol_context_scope = sc.comp_unit; |
| 5675 | } |
| 5676 | else if (sc.function != NULL) |
| 5677 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5678 | symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5679 | if (symbol_context_scope == NULL) |
| 5680 | symbol_context_scope = sc.function; |
| 5681 | } |
| 5682 | |
| 5683 | if (symbol_context_scope != NULL) |
| 5684 | { |
| 5685 | type_sp->SetSymbolContextScope(symbol_context_scope); |
| 5686 | } |
| 5687 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5688 | // We are ready to put this type into the uniqued list up at the module level |
| 5689 | type_list->Insert (type_sp); |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 5690 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5691 | m_die_to_type[die] = type_sp.get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5692 | } |
| 5693 | } |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5694 | else if (type_ptr != DIE_IS_BEING_PARSED) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5695 | { |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 5696 | type_sp = type_ptr->shared_from_this(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5697 | } |
| 5698 | } |
| 5699 | return type_sp; |
| 5700 | } |
| 5701 | |
| 5702 | size_t |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5703 | SymbolFileDWARF::ParseTypes |
| 5704 | ( |
| 5705 | const SymbolContext& sc, |
| 5706 | DWARFCompileUnit* dwarf_cu, |
| 5707 | const DWARFDebugInfoEntry *die, |
| 5708 | bool parse_siblings, |
| 5709 | bool parse_children |
| 5710 | ) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5711 | { |
| 5712 | size_t types_added = 0; |
| 5713 | while (die != NULL) |
| 5714 | { |
| 5715 | bool type_is_new = false; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5716 | if (ParseType(sc, dwarf_cu, die, &type_is_new).get()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5717 | { |
| 5718 | if (type_is_new) |
| 5719 | ++types_added; |
| 5720 | } |
| 5721 | |
| 5722 | if (parse_children && die->HasChildren()) |
| 5723 | { |
| 5724 | if (die->Tag() == DW_TAG_subprogram) |
| 5725 | { |
| 5726 | SymbolContext child_sc(sc); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5727 | child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5728 | types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true); |
| 5729 | } |
| 5730 | else |
| 5731 | types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true); |
| 5732 | } |
| 5733 | |
| 5734 | if (parse_siblings) |
| 5735 | die = die->GetSibling(); |
| 5736 | else |
| 5737 | die = NULL; |
| 5738 | } |
| 5739 | return types_added; |
| 5740 | } |
| 5741 | |
| 5742 | |
| 5743 | size_t |
| 5744 | SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc) |
| 5745 | { |
| 5746 | assert(sc.comp_unit && sc.function); |
| 5747 | size_t functions_added = 0; |
| 5748 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID()); |
| 5749 | if (dwarf_cu) |
| 5750 | { |
| 5751 | dw_offset_t function_die_offset = sc.function->GetID(); |
| 5752 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset); |
| 5753 | if (function_die) |
| 5754 | { |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 5755 | ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5756 | } |
| 5757 | } |
| 5758 | |
| 5759 | return functions_added; |
| 5760 | } |
| 5761 | |
| 5762 | |
| 5763 | size_t |
| 5764 | SymbolFileDWARF::ParseTypes (const SymbolContext &sc) |
| 5765 | { |
| 5766 | // At least a compile unit must be valid |
| 5767 | assert(sc.comp_unit); |
| 5768 | size_t types_added = 0; |
| 5769 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID()); |
| 5770 | if (dwarf_cu) |
| 5771 | { |
| 5772 | if (sc.function) |
| 5773 | { |
| 5774 | dw_offset_t function_die_offset = sc.function->GetID(); |
| 5775 | const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset); |
| 5776 | if (func_die && func_die->HasChildren()) |
| 5777 | { |
| 5778 | types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true); |
| 5779 | } |
| 5780 | } |
| 5781 | else |
| 5782 | { |
| 5783 | const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE(); |
| 5784 | if (dwarf_cu_die && dwarf_cu_die->HasChildren()) |
| 5785 | { |
| 5786 | types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true); |
| 5787 | } |
| 5788 | } |
| 5789 | } |
| 5790 | |
| 5791 | return types_added; |
| 5792 | } |
| 5793 | |
| 5794 | size_t |
| 5795 | SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc) |
| 5796 | { |
| 5797 | if (sc.comp_unit != NULL) |
| 5798 | { |
| Greg Clayton | 4b3dc10 | 2010-11-01 20:32:12 +0000 | [diff] [blame] | 5799 | DWARFDebugInfo* info = DebugInfo(); |
| 5800 | if (info == NULL) |
| 5801 | return 0; |
| 5802 | |
| 5803 | uint32_t cu_idx = UINT32_MAX; |
| 5804 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID(), &cu_idx).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5805 | |
| 5806 | if (dwarf_cu == NULL) |
| 5807 | return 0; |
| 5808 | |
| 5809 | if (sc.function) |
| 5810 | { |
| 5811 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID()); |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 5812 | |
| 5813 | dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, DW_INVALID_ADDRESS); |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5814 | if (func_lo_pc != DW_INVALID_ADDRESS) |
| 5815 | { |
| 5816 | const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 5817 | |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5818 | // Let all blocks know they have parse all their variables |
| 5819 | sc.function->GetBlock (false).SetDidParseVariables (true, true); |
| 5820 | return num_variables; |
| 5821 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5822 | } |
| 5823 | else if (sc.comp_unit) |
| 5824 | { |
| 5825 | uint32_t vars_added = 0; |
| 5826 | VariableListSP variables (sc.comp_unit->GetVariableList(false)); |
| 5827 | |
| 5828 | if (variables.get() == NULL) |
| 5829 | { |
| 5830 | variables.reset(new VariableList()); |
| 5831 | sc.comp_unit->SetVariableList(variables); |
| 5832 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 5833 | DWARFCompileUnit* match_dwarf_cu = NULL; |
| 5834 | const DWARFDebugInfoEntry* die = NULL; |
| 5835 | DIEArray die_offsets; |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 5836 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5837 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 5838 | if (m_apple_names_ap.get()) |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5839 | { |
| 5840 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 5841 | if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(), |
| 5842 | dwarf_cu->GetNextCompileUnitOffset(), |
| 5843 | hash_data_array)) |
| 5844 | { |
| 5845 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| 5846 | } |
| 5847 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5848 | } |
| 5849 | else |
| 5850 | { |
| 5851 | // Index if we already haven't to make sure the compile units |
| 5852 | // get indexed and make their global DIE index list |
| 5853 | if (!m_indexed) |
| 5854 | Index (); |
| 5855 | |
| 5856 | m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(), |
| 5857 | dwarf_cu->GetNextCompileUnitOffset(), |
| 5858 | die_offsets); |
| 5859 | } |
| 5860 | |
| 5861 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 5862 | if (num_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5863 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 5864 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 5865 | for (size_t i=0; i<num_matches; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5866 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 5867 | const dw_offset_t die_offset = die_offsets[i]; |
| 5868 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 5869 | if (die) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 5870 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 5871 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS)); |
| 5872 | if (var_sp) |
| 5873 | { |
| 5874 | variables->AddVariableIfUnique (var_sp); |
| 5875 | ++vars_added; |
| 5876 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 5877 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 5878 | else |
| 5879 | { |
| 5880 | if (m_using_apple_tables) |
| 5881 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5882 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x)\n", die_offset); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 5883 | } |
| 5884 | } |
| 5885 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5886 | } |
| 5887 | } |
| 5888 | } |
| 5889 | return vars_added; |
| 5890 | } |
| 5891 | } |
| 5892 | return 0; |
| 5893 | } |
| 5894 | |
| 5895 | |
| 5896 | VariableSP |
| 5897 | SymbolFileDWARF::ParseVariableDIE |
| 5898 | ( |
| 5899 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5900 | DWARFCompileUnit* dwarf_cu, |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 5901 | const DWARFDebugInfoEntry *die, |
| 5902 | const lldb::addr_t func_low_pc |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5903 | ) |
| 5904 | { |
| 5905 | |
| Greg Clayton | 83c5cd9 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 5906 | VariableSP var_sp (m_die_to_variable_sp[die]); |
| 5907 | if (var_sp) |
| 5908 | return var_sp; // Already been parsed! |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5909 | |
| 5910 | const dw_tag_t tag = die->Tag(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5911 | |
| 5912 | if ((tag == DW_TAG_variable) || |
| 5913 | (tag == DW_TAG_constant) || |
| 5914 | (tag == DW_TAG_formal_parameter && sc.function)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5915 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5916 | DWARFDebugInfoEntry::Attributes attributes; |
| 5917 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| 5918 | if (num_attributes > 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5919 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5920 | const char *name = NULL; |
| 5921 | const char *mangled = NULL; |
| 5922 | Declaration decl; |
| 5923 | uint32_t i; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5924 | lldb::user_id_t type_uid = LLDB_INVALID_UID; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5925 | DWARFExpression location; |
| 5926 | bool is_external = false; |
| 5927 | bool is_artificial = false; |
| 5928 | bool location_is_const_value_data = false; |
| 5929 | AccessType accessibility = eAccessNone; |
| 5930 | |
| 5931 | for (i=0; i<num_attributes; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5932 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5933 | dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 5934 | DWARFFormValue form_value; |
| 5935 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5936 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5937 | switch (attr) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5938 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5939 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 5940 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 5941 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 5942 | case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; |
| 5943 | case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5944 | case DW_AT_type: type_uid = form_value.Reference(dwarf_cu); break; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5945 | case DW_AT_external: is_external = form_value.Unsigned() != 0; break; |
| 5946 | case DW_AT_const_value: |
| 5947 | location_is_const_value_data = true; |
| 5948 | // Fall through... |
| 5949 | case DW_AT_location: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5950 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5951 | if (form_value.BlockData()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5952 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5953 | const DataExtractor& debug_info_data = get_debug_info_data(); |
| 5954 | |
| 5955 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 5956 | uint32_t block_length = form_value.Unsigned(); |
| 5957 | location.SetOpcodeData(get_debug_info_data(), block_offset, block_length); |
| 5958 | } |
| 5959 | else |
| 5960 | { |
| 5961 | const DataExtractor& debug_loc_data = get_debug_loc_data(); |
| 5962 | const dw_offset_t debug_loc_offset = form_value.Unsigned(); |
| 5963 | |
| 5964 | size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset); |
| 5965 | if (loc_list_length > 0) |
| 5966 | { |
| 5967 | location.SetOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length); |
| 5968 | assert (func_low_pc != LLDB_INVALID_ADDRESS); |
| 5969 | location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress()); |
| 5970 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5971 | } |
| 5972 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5973 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5974 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5975 | case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break; |
| 5976 | case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
| 5977 | case DW_AT_declaration: |
| 5978 | case DW_AT_description: |
| 5979 | case DW_AT_endianity: |
| 5980 | case DW_AT_segment: |
| 5981 | case DW_AT_start_scope: |
| 5982 | case DW_AT_visibility: |
| 5983 | default: |
| 5984 | case DW_AT_abstract_origin: |
| 5985 | case DW_AT_sibling: |
| 5986 | case DW_AT_specification: |
| 5987 | break; |
| 5988 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5989 | } |
| 5990 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5991 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5992 | if (location.IsValid()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5993 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5994 | ValueType scope = eValueTypeInvalid; |
| 5995 | |
| 5996 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); |
| 5997 | dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 5998 | SymbolContextScope * symbol_context_scope = NULL; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5999 | |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6000 | // DWARF doesn't specify if a DW_TAG_variable is a local, global |
| 6001 | // or static variable, so we have to do a little digging by |
| 6002 | // looking at the location of a varaible to see if it contains |
| 6003 | // a DW_OP_addr opcode _somewhere_ in the definition. I say |
| 6004 | // somewhere because clang likes to combine small global variables |
| 6005 | // into the same symbol and have locations like: |
| 6006 | // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus |
| 6007 | // So if we don't have a DW_TAG_formal_parameter, we can look at |
| 6008 | // the location to see if it contains a DW_OP_addr opcode, and |
| 6009 | // then we can correctly classify our variables. |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6010 | if (tag == DW_TAG_formal_parameter) |
| 6011 | scope = eValueTypeVariableArgument; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6012 | else |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6013 | { |
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 6014 | bool op_error = false; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6015 | // Check if the location has a DW_OP_addr with any address value... |
| 6016 | addr_t location_has_op_addr = false; |
| 6017 | if (!location_is_const_value_data) |
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 6018 | { |
| 6019 | location_has_op_addr = location.LocationContains_DW_OP_addr (LLDB_INVALID_ADDRESS, op_error); |
| 6020 | if (op_error) |
| 6021 | { |
| 6022 | StreamString strm; |
| 6023 | location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL); |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6024 | GetObjectFile()->GetModule()->ReportError ("0x%8.8x: %s has an invalid location: %s", die->GetOffset(), DW_TAG_value_to_name(die->Tag()), strm.GetString().c_str()); |
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 6025 | } |
| 6026 | } |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6027 | |
| 6028 | if (location_has_op_addr) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6029 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6030 | if (is_external) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6031 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6032 | scope = eValueTypeVariableGlobal; |
| 6033 | |
| 6034 | if (m_debug_map_symfile) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6035 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6036 | // When leaving the DWARF in the .o files on darwin, |
| 6037 | // when we have a global variable that wasn't initialized, |
| 6038 | // the .o file might not have allocated a virtual |
| 6039 | // address for the global variable. In this case it will |
| 6040 | // have created a symbol for the global variable |
| 6041 | // that is undefined and external and the value will |
| 6042 | // be the byte size of the variable. When we do the |
| 6043 | // address map in SymbolFileDWARFDebugMap we rely on |
| 6044 | // having an address, we need to do some magic here |
| 6045 | // so we can get the correct address for our global |
| 6046 | // variable. The address for all of these entries |
| 6047 | // will be zero, and there will be an undefined symbol |
| 6048 | // in this object file, and the executable will have |
| 6049 | // a matching symbol with a good address. So here we |
| 6050 | // dig up the correct address and replace it in the |
| 6051 | // location for the variable, and set the variable's |
| 6052 | // symbol context scope to be that of the main executable |
| 6053 | // so the file address will resolve correctly. |
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 6054 | if (location.LocationContains_DW_OP_addr (0, op_error)) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6055 | { |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6056 | |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6057 | // we have a possible uninitialized extern global |
| 6058 | Symtab *symtab = m_obj_file->GetSymtab(); |
| 6059 | if (symtab) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6060 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6061 | ConstString const_name(name); |
| 6062 | Symbol *undefined_symbol = symtab->FindFirstSymbolWithNameAndType (const_name, |
| 6063 | eSymbolTypeUndefined, |
| 6064 | Symtab::eDebugNo, |
| 6065 | Symtab::eVisibilityExtern); |
| 6066 | |
| 6067 | if (undefined_symbol) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6068 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6069 | ObjectFile *debug_map_objfile = m_debug_map_symfile->GetObjectFile(); |
| 6070 | if (debug_map_objfile) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6071 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6072 | Symtab *debug_map_symtab = debug_map_objfile->GetSymtab(); |
| 6073 | Symbol *defined_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name, |
| 6074 | eSymbolTypeData, |
| 6075 | Symtab::eDebugYes, |
| 6076 | Symtab::eVisibilityExtern); |
| 6077 | if (defined_symbol) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6078 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6079 | const AddressRange *defined_range = defined_symbol->GetAddressRangePtr(); |
| 6080 | if (defined_range) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6081 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6082 | const addr_t defined_addr = defined_range->GetBaseAddress().GetFileAddress(); |
| 6083 | if (defined_addr != LLDB_INVALID_ADDRESS) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6084 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6085 | if (location.Update_DW_OP_addr (defined_addr)) |
| 6086 | { |
| 6087 | symbol_context_scope = defined_symbol; |
| 6088 | } |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6089 | } |
| 6090 | } |
| 6091 | } |
| 6092 | } |
| 6093 | } |
| 6094 | } |
| 6095 | } |
| 6096 | } |
| 6097 | } |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6098 | else |
| 6099 | { |
| 6100 | scope = eValueTypeVariableStatic; |
| 6101 | } |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6102 | } |
| 6103 | else |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6104 | { |
| 6105 | scope = eValueTypeVariableLocal; |
| 6106 | } |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6107 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6108 | |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6109 | if (symbol_context_scope == NULL) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6110 | { |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6111 | switch (parent_tag) |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6112 | { |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6113 | case DW_TAG_subprogram: |
| 6114 | case DW_TAG_inlined_subroutine: |
| 6115 | case DW_TAG_lexical_block: |
| 6116 | if (sc.function) |
| 6117 | { |
| 6118 | symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); |
| 6119 | if (symbol_context_scope == NULL) |
| 6120 | symbol_context_scope = sc.function; |
| 6121 | } |
| 6122 | break; |
| 6123 | |
| 6124 | default: |
| 6125 | symbol_context_scope = sc.comp_unit; |
| 6126 | break; |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6127 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6128 | } |
| 6129 | |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6130 | if (symbol_context_scope) |
| 6131 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6132 | var_sp.reset (new Variable (MakeUserID(die->GetOffset()), |
| 6133 | name, |
| 6134 | mangled, |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6135 | SymbolFileTypeSP (new SymbolFileType(*this, type_uid)), |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6136 | scope, |
| 6137 | symbol_context_scope, |
| 6138 | &decl, |
| 6139 | location, |
| 6140 | is_external, |
| 6141 | is_artificial)); |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6142 | |
| 6143 | var_sp->SetLocationIsConstantValueData (location_is_const_value_data); |
| 6144 | } |
| 6145 | else |
| 6146 | { |
| 6147 | // Not ready to parse this variable yet. It might be a global |
| 6148 | // or static variable that is in a function scope and the function |
| 6149 | // in the symbol context wasn't filled in yet |
| 6150 | return var_sp; |
| 6151 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6152 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6153 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6154 | // Cache var_sp even if NULL (the variable was just a specification or |
| 6155 | // was missing vital information to be able to be displayed in the debugger |
| 6156 | // (missing location due to optimization, etc)) so we don't re-parse |
| 6157 | // this DIE over and over later... |
| 6158 | m_die_to_variable_sp[die] = var_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6159 | } |
| 6160 | return var_sp; |
| 6161 | } |
| 6162 | |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6163 | |
| 6164 | const DWARFDebugInfoEntry * |
| 6165 | SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset, |
| 6166 | dw_offset_t spec_block_die_offset, |
| 6167 | DWARFCompileUnit **result_die_cu_handle) |
| 6168 | { |
| 6169 | // Give the concrete function die specified by "func_die_offset", find the |
| 6170 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points |
| 6171 | // to "spec_block_die_offset" |
| 6172 | DWARFDebugInfo* info = DebugInfo(); |
| 6173 | |
| 6174 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle); |
| 6175 | if (die) |
| 6176 | { |
| 6177 | assert (*result_die_cu_handle); |
| 6178 | return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle); |
| 6179 | } |
| 6180 | return NULL; |
| 6181 | } |
| 6182 | |
| 6183 | |
| 6184 | const DWARFDebugInfoEntry * |
| 6185 | SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu, |
| 6186 | const DWARFDebugInfoEntry *die, |
| 6187 | dw_offset_t spec_block_die_offset, |
| 6188 | DWARFCompileUnit **result_die_cu_handle) |
| 6189 | { |
| 6190 | if (die) |
| 6191 | { |
| 6192 | switch (die->Tag()) |
| 6193 | { |
| 6194 | case DW_TAG_subprogram: |
| 6195 | case DW_TAG_inlined_subroutine: |
| 6196 | case DW_TAG_lexical_block: |
| 6197 | { |
| 6198 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset) |
| 6199 | { |
| 6200 | *result_die_cu_handle = dwarf_cu; |
| 6201 | return die; |
| 6202 | } |
| 6203 | |
| 6204 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset) |
| 6205 | { |
| 6206 | *result_die_cu_handle = dwarf_cu; |
| 6207 | return die; |
| 6208 | } |
| 6209 | } |
| 6210 | break; |
| 6211 | } |
| 6212 | |
| 6213 | // Give the concrete function die specified by "func_die_offset", find the |
| 6214 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points |
| 6215 | // to "spec_block_die_offset" |
| 6216 | for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling()) |
| 6217 | { |
| 6218 | const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu, |
| 6219 | child_die, |
| 6220 | spec_block_die_offset, |
| 6221 | result_die_cu_handle); |
| 6222 | if (result_die) |
| 6223 | return result_die; |
| 6224 | } |
| 6225 | } |
| 6226 | |
| 6227 | *result_die_cu_handle = NULL; |
| 6228 | return NULL; |
| 6229 | } |
| 6230 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6231 | size_t |
| 6232 | SymbolFileDWARF::ParseVariables |
| 6233 | ( |
| 6234 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6235 | DWARFCompileUnit* dwarf_cu, |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 6236 | const lldb::addr_t func_low_pc, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6237 | const DWARFDebugInfoEntry *orig_die, |
| 6238 | bool parse_siblings, |
| 6239 | bool parse_children, |
| 6240 | VariableList* cc_variable_list |
| 6241 | ) |
| 6242 | { |
| 6243 | if (orig_die == NULL) |
| 6244 | return 0; |
| 6245 | |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6246 | VariableListSP variable_list_sp; |
| 6247 | |
| 6248 | size_t vars_added = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6249 | const DWARFDebugInfoEntry *die = orig_die; |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6250 | while (die != NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6251 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6252 | dw_tag_t tag = die->Tag(); |
| 6253 | |
| 6254 | // Check to see if we have already parsed this variable or constant? |
| 6255 | if (m_die_to_variable_sp[die]) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6256 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6257 | if (cc_variable_list) |
| 6258 | cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6259 | } |
| 6260 | else |
| 6261 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6262 | // We haven't already parsed it, lets do that now. |
| 6263 | if ((tag == DW_TAG_variable) || |
| 6264 | (tag == DW_TAG_constant) || |
| 6265 | (tag == DW_TAG_formal_parameter && sc.function)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6266 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6267 | if (variable_list_sp.get() == NULL) |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 6268 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6269 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die); |
| 6270 | dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
| 6271 | switch (parent_tag) |
| 6272 | { |
| 6273 | case DW_TAG_compile_unit: |
| 6274 | if (sc.comp_unit != NULL) |
| 6275 | { |
| 6276 | variable_list_sp = sc.comp_unit->GetVariableList(false); |
| 6277 | if (variable_list_sp.get() == NULL) |
| 6278 | { |
| 6279 | variable_list_sp.reset(new VariableList()); |
| 6280 | sc.comp_unit->SetVariableList(variable_list_sp); |
| 6281 | } |
| 6282 | } |
| 6283 | else |
| 6284 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6285 | GetObjectFile()->GetModule()->ReportError ("parent 0x%8.8llx %s with no valid compile unit in symbol context for 0x%8.8llx %s.\n", |
| 6286 | MakeUserID(sc_parent_die->GetOffset()), |
| 6287 | DW_TAG_value_to_name (parent_tag), |
| 6288 | MakeUserID(orig_die->GetOffset()), |
| 6289 | DW_TAG_value_to_name (orig_die->Tag())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6290 | } |
| 6291 | break; |
| 6292 | |
| 6293 | case DW_TAG_subprogram: |
| 6294 | case DW_TAG_inlined_subroutine: |
| 6295 | case DW_TAG_lexical_block: |
| 6296 | if (sc.function != NULL) |
| 6297 | { |
| 6298 | // Check to see if we already have parsed the variables for the given scope |
| 6299 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6300 | Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6301 | if (block == NULL) |
| 6302 | { |
| 6303 | // This must be a specification or abstract origin with |
| 6304 | // a concrete block couterpart in the current function. We need |
| 6305 | // to find the concrete block so we can correctly add the |
| 6306 | // variable to it |
| 6307 | DWARFCompileUnit *concrete_block_die_cu = dwarf_cu; |
| 6308 | const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(), |
| 6309 | sc_parent_die->GetOffset(), |
| 6310 | &concrete_block_die_cu); |
| 6311 | if (concrete_block_die) |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6312 | block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6313 | } |
| 6314 | |
| 6315 | if (block != NULL) |
| 6316 | { |
| 6317 | const bool can_create = false; |
| 6318 | variable_list_sp = block->GetBlockVariableList (can_create); |
| 6319 | if (variable_list_sp.get() == NULL) |
| 6320 | { |
| 6321 | variable_list_sp.reset(new VariableList()); |
| 6322 | block->SetVariableList(variable_list_sp); |
| 6323 | } |
| 6324 | } |
| 6325 | } |
| 6326 | break; |
| 6327 | |
| 6328 | default: |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6329 | GetObjectFile()->GetModule()->ReportError ("didn't find appropriate parent DIE for variable list for 0x%8.8llx %s.\n", |
| 6330 | MakeUserID(orig_die->GetOffset()), |
| 6331 | DW_TAG_value_to_name (orig_die->Tag())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6332 | break; |
| 6333 | } |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 6334 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6335 | |
| 6336 | if (variable_list_sp) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6337 | { |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 6338 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc)); |
| 6339 | if (var_sp) |
| 6340 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6341 | variable_list_sp->AddVariableIfUnique (var_sp); |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 6342 | if (cc_variable_list) |
| 6343 | cc_variable_list->AddVariableIfUnique (var_sp); |
| 6344 | ++vars_added; |
| 6345 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6346 | } |
| 6347 | } |
| 6348 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6349 | |
| 6350 | bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram); |
| 6351 | |
| 6352 | if (!skip_children && parse_children && die->HasChildren()) |
| 6353 | { |
| 6354 | vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list); |
| 6355 | } |
| 6356 | |
| 6357 | if (parse_siblings) |
| 6358 | die = die->GetSibling(); |
| 6359 | else |
| 6360 | die = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6361 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6362 | return vars_added; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6363 | } |
| 6364 | |
| 6365 | //------------------------------------------------------------------ |
| 6366 | // PluginInterface protocol |
| 6367 | //------------------------------------------------------------------ |
| 6368 | const char * |
| 6369 | SymbolFileDWARF::GetPluginName() |
| 6370 | { |
| 6371 | return "SymbolFileDWARF"; |
| 6372 | } |
| 6373 | |
| 6374 | const char * |
| 6375 | SymbolFileDWARF::GetShortPluginName() |
| 6376 | { |
| 6377 | return GetPluginNameStatic(); |
| 6378 | } |
| 6379 | |
| 6380 | uint32_t |
| 6381 | SymbolFileDWARF::GetPluginVersion() |
| 6382 | { |
| 6383 | return 1; |
| 6384 | } |
| 6385 | |
| 6386 | void |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 6387 | SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl) |
| 6388 | { |
| 6389 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 6390 | clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); |
| 6391 | if (clang_type) |
| 6392 | symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); |
| 6393 | } |
| 6394 | |
| 6395 | void |
| 6396 | SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl) |
| 6397 | { |
| 6398 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 6399 | clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); |
| 6400 | if (clang_type) |
| 6401 | symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); |
| 6402 | } |
| 6403 | |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6404 | void |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 6405 | SymbolFileDWARF::DumpIndexes () |
| 6406 | { |
| 6407 | StreamFile s(stdout, false); |
| 6408 | |
| 6409 | s.Printf ("DWARF index for (%s) '%s/%s':", |
| 6410 | GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(), |
| 6411 | GetObjectFile()->GetFileSpec().GetDirectory().AsCString(), |
| 6412 | GetObjectFile()->GetFileSpec().GetFilename().AsCString()); |
| 6413 | s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s); |
| 6414 | s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s); |
| 6415 | s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s); |
| 6416 | s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s); |
| 6417 | s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s); |
| 6418 | s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s); |
| 6419 | s.Printf("\nTypes:\n"); m_type_index.Dump (&s); |
| 6420 | s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s); |
| 6421 | } |
| 6422 | |
| 6423 | void |
| 6424 | SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context, |
| 6425 | const char *name, |
| 6426 | llvm::SmallVectorImpl <clang::NamedDecl *> *results) |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6427 | { |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 6428 | DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context); |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6429 | |
| 6430 | if (iter == m_decl_ctx_to_die.end()) |
| 6431 | return; |
| 6432 | |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6433 | for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos) |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6434 | { |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6435 | const DWARFDebugInfoEntry *context_die = *pos; |
| 6436 | |
| 6437 | if (!results) |
| 6438 | return; |
| 6439 | |
| 6440 | DWARFDebugInfo* info = DebugInfo(); |
| 6441 | |
| 6442 | DIEArray die_offsets; |
| 6443 | |
| 6444 | DWARFCompileUnit* dwarf_cu = NULL; |
| 6445 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 6446 | |
| 6447 | if (m_using_apple_tables) |
| 6448 | { |
| 6449 | if (m_apple_types_ap.get()) |
| 6450 | m_apple_types_ap->FindByName (name, die_offsets); |
| 6451 | } |
| 6452 | else |
| 6453 | { |
| 6454 | if (!m_indexed) |
| 6455 | Index (); |
| 6456 | |
| 6457 | m_type_index.Find (ConstString(name), die_offsets); |
| 6458 | } |
| 6459 | |
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 6460 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6461 | |
| 6462 | if (num_matches) |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6463 | { |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6464 | for (size_t i = 0; i < num_matches; ++i) |
| 6465 | { |
| 6466 | const dw_offset_t die_offset = die_offsets[i]; |
| 6467 | die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 6468 | |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6469 | if (die->GetParent() != context_die) |
| 6470 | continue; |
| 6471 | |
| 6472 | Type *matching_type = ResolveType (dwarf_cu, die); |
| 6473 | |
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 6474 | lldb::clang_type_t type = matching_type->GetClangForwardType(); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6475 | clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type); |
| 6476 | |
| 6477 | if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr())) |
| 6478 | { |
| 6479 | clang::TagDecl *tag_decl = tag_type->getDecl(); |
| 6480 | results->push_back(tag_decl); |
| 6481 | } |
| 6482 | else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr())) |
| 6483 | { |
| 6484 | clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl(); |
| 6485 | results->push_back(typedef_decl); |
| 6486 | } |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6487 | } |
| 6488 | } |
| 6489 | } |
| 6490 | } |
| 6491 | |
| 6492 | void |
| 6493 | SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton, |
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 6494 | const clang::DeclContext *decl_context, |
| 6495 | clang::DeclarationName decl_name, |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6496 | llvm::SmallVectorImpl <clang::NamedDecl *> *results) |
| 6497 | { |
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 6498 | |
| 6499 | switch (decl_context->getDeclKind()) |
| 6500 | { |
| 6501 | case clang::Decl::Namespace: |
| 6502 | case clang::Decl::TranslationUnit: |
| 6503 | { |
| 6504 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 6505 | symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results); |
| 6506 | } |
| 6507 | break; |
| 6508 | default: |
| 6509 | break; |
| 6510 | } |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6511 | } |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 6512 | |
| 6513 | bool |
| 6514 | SymbolFileDWARF::LayoutRecordType (void *baton, |
| 6515 | const clang::RecordDecl *record_decl, |
| 6516 | uint64_t &size, |
| 6517 | uint64_t &alignment, |
| 6518 | llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, |
| 6519 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, |
| 6520 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) |
| 6521 | { |
| 6522 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 6523 | return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets); |
| 6524 | } |
| 6525 | |
| 6526 | |
| 6527 | bool |
| 6528 | SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl, |
| 6529 | uint64_t &bit_size, |
| 6530 | uint64_t &alignment, |
| 6531 | llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, |
| 6532 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, |
| 6533 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) |
| 6534 | { |
| 6535 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| 6536 | RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl); |
| 6537 | bool success = false; |
| 6538 | base_offsets.clear(); |
| 6539 | vbase_offsets.clear(); |
| 6540 | if (pos != m_record_decl_to_layout_map.end()) |
| 6541 | { |
| 6542 | bit_size = pos->second.bit_size; |
| 6543 | alignment = pos->second.alignment; |
| 6544 | field_offsets.swap(pos->second.field_offsets); |
| 6545 | m_record_decl_to_layout_map.erase(pos); |
| 6546 | success = true; |
| 6547 | } |
| 6548 | else |
| 6549 | { |
| 6550 | bit_size = 0; |
| 6551 | alignment = 0; |
| 6552 | field_offsets.clear(); |
| 6553 | } |
| 6554 | |
| 6555 | if (log) |
| 6556 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 6557 | "SymbolFileDWARF::LayoutRecordType (record_decl = %p, bit_size = %llu, alignment = %llu, field_offsets[%u],base_offsets[%u], vbase_offsets[%u]) success = %i", |
| 6558 | record_decl, |
| 6559 | bit_size, |
| 6560 | alignment, |
| 6561 | (uint32_t)field_offsets.size(), |
| 6562 | (uint32_t)base_offsets.size(), |
| 6563 | (uint32_t)vbase_offsets.size(), |
| 6564 | success); |
| 6565 | return success; |
| 6566 | } |
| 6567 | |
| 6568 | |
| 6569 | |