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