| 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" |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 60 | #include "DWARFDeclContext.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 61 | #include "DWARFDIECollection.h" |
| 62 | #include "DWARFFormValue.h" |
| 63 | #include "DWARFLocationList.h" |
| 64 | #include "LogChannelDWARF.h" |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 65 | #include "SymbolFileDWARFDebugMap.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 66 | |
| 67 | #include <map> |
| 68 | |
| Matthew Gardiner | e81df3b | 2014-08-26 06:57:23 +0000 | [diff] [blame] | 69 | #include <ctype.h> |
| 70 | #include <string.h> |
| 71 | |
| Greg Clayton | 62742b1 | 2010-11-11 01:09:45 +0000 | [diff] [blame] | 72 | //#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 73 | |
| 74 | #ifdef ENABLE_DEBUG_PRINTF |
| 75 | #include <stdio.h> |
| Ed Maste | a0191d1 | 2013-10-17 20:42:56 +0000 | [diff] [blame] | 76 | #define DEBUG_PRINTF(fmt, ...) printf(fmt, __VA_ARGS__) |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 77 | #else |
| 78 | #define DEBUG_PRINTF(fmt, ...) |
| 79 | #endif |
| 80 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 81 | #define DIE_IS_BEING_PARSED ((lldb_private::Type*)1) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 82 | |
| 83 | using namespace lldb; |
| 84 | using namespace lldb_private; |
| 85 | |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 86 | //static inline bool |
| 87 | //child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag) |
| 88 | //{ |
| 89 | // switch (tag) |
| 90 | // { |
| 91 | // default: |
| 92 | // break; |
| 93 | // case DW_TAG_subprogram: |
| 94 | // case DW_TAG_inlined_subroutine: |
| 95 | // case DW_TAG_class_type: |
| 96 | // case DW_TAG_structure_type: |
| 97 | // case DW_TAG_union_type: |
| 98 | // return true; |
| 99 | // } |
| 100 | // return false; |
| 101 | //} |
| 102 | // |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 103 | static AccessType |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 104 | DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 105 | { |
| 106 | switch (dwarf_accessibility) |
| 107 | { |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 108 | case DW_ACCESS_public: return eAccessPublic; |
| 109 | case DW_ACCESS_private: return eAccessPrivate; |
| 110 | case DW_ACCESS_protected: return eAccessProtected; |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 111 | default: break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 112 | } |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 113 | return eAccessNone; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| Matthew Gardiner | e81df3b | 2014-08-26 06:57:23 +0000 | [diff] [blame] | 116 | static const char* |
| 117 | removeHostnameFromPathname(const char* path_from_dwarf) |
| 118 | { |
| 119 | if (!path_from_dwarf || !path_from_dwarf[0]) |
| 120 | { |
| 121 | return path_from_dwarf; |
| 122 | } |
| 123 | |
| 124 | const char *colon_pos = strchr(path_from_dwarf, ':'); |
| 125 | if (!colon_pos) |
| 126 | { |
| 127 | return path_from_dwarf; |
| 128 | } |
| 129 | |
| 130 | // check whether we have a windows path, and so the first character |
| 131 | // is a drive-letter not a hostname. |
| 132 | if ( |
| 133 | colon_pos == path_from_dwarf + 1 && |
| 134 | isalpha(*path_from_dwarf) && |
| 135 | strlen(path_from_dwarf) > 2 && |
| 136 | '\\' == path_from_dwarf[2]) |
| 137 | { |
| 138 | return path_from_dwarf; |
| 139 | } |
| 140 | |
| 141 | return colon_pos + 1; |
| 142 | } |
| 143 | |
| Todd Fiala | 0a70a84 | 2014-05-28 16:43:26 +0000 | [diff] [blame] | 144 | #if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE) |
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 145 | |
| 146 | class DIEStack |
| 147 | { |
| 148 | public: |
| 149 | |
| 150 | void Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) |
| 151 | { |
| 152 | m_dies.push_back (DIEInfo(cu, die)); |
| 153 | } |
| 154 | |
| 155 | |
| 156 | void LogDIEs (Log *log, SymbolFileDWARF *dwarf) |
| 157 | { |
| 158 | StreamString log_strm; |
| 159 | const size_t n = m_dies.size(); |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 160 | log_strm.Printf("DIEStack[%" PRIu64 "]:\n", (uint64_t)n); |
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 161 | for (size_t i=0; i<n; i++) |
| 162 | { |
| 163 | DWARFCompileUnit *cu = m_dies[i].cu; |
| 164 | const DWARFDebugInfoEntry *die = m_dies[i].die; |
| 165 | std::string qualified_name; |
| 166 | die->GetQualifiedName(dwarf, cu, qualified_name); |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 167 | log_strm.Printf ("[%" PRIu64 "] 0x%8.8x: %s name='%s'\n", |
| Greg Clayton | 43e0af0 | 2012-09-18 18:04:04 +0000 | [diff] [blame] | 168 | (uint64_t)i, |
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 169 | die->GetOffset(), |
| 170 | DW_TAG_value_to_name(die->Tag()), |
| 171 | qualified_name.c_str()); |
| 172 | } |
| 173 | log->PutCString(log_strm.GetData()); |
| 174 | } |
| 175 | void Pop () |
| 176 | { |
| 177 | m_dies.pop_back(); |
| 178 | } |
| 179 | |
| 180 | class ScopedPopper |
| 181 | { |
| 182 | public: |
| 183 | ScopedPopper (DIEStack &die_stack) : |
| 184 | m_die_stack (die_stack), |
| 185 | m_valid (false) |
| 186 | { |
| 187 | } |
| 188 | |
| 189 | void |
| 190 | Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) |
| 191 | { |
| 192 | m_valid = true; |
| 193 | m_die_stack.Push (cu, die); |
| 194 | } |
| 195 | |
| 196 | ~ScopedPopper () |
| 197 | { |
| 198 | if (m_valid) |
| 199 | m_die_stack.Pop(); |
| 200 | } |
| 201 | |
| 202 | |
| 203 | |
| 204 | protected: |
| 205 | DIEStack &m_die_stack; |
| 206 | bool m_valid; |
| 207 | }; |
| 208 | |
| 209 | protected: |
| 210 | struct DIEInfo { |
| 211 | DIEInfo (DWARFCompileUnit *c, const DWARFDebugInfoEntry *d) : |
| 212 | cu(c), |
| 213 | die(d) |
| 214 | { |
| 215 | } |
| 216 | DWARFCompileUnit *cu; |
| 217 | const DWARFDebugInfoEntry *die; |
| 218 | }; |
| 219 | typedef std::vector<DIEInfo> Stack; |
| 220 | Stack m_dies; |
| 221 | }; |
| 222 | #endif |
| 223 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 224 | void |
| 225 | SymbolFileDWARF::Initialize() |
| 226 | { |
| 227 | LogChannelDWARF::Initialize(); |
| 228 | PluginManager::RegisterPlugin (GetPluginNameStatic(), |
| 229 | GetPluginDescriptionStatic(), |
| 230 | CreateInstance); |
| 231 | } |
| 232 | |
| 233 | void |
| 234 | SymbolFileDWARF::Terminate() |
| 235 | { |
| 236 | PluginManager::UnregisterPlugin (CreateInstance); |
| 237 | LogChannelDWARF::Initialize(); |
| 238 | } |
| 239 | |
| 240 | |
| Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 241 | lldb_private::ConstString |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 242 | SymbolFileDWARF::GetPluginNameStatic() |
| 243 | { |
| Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 244 | static ConstString g_name("dwarf"); |
| 245 | return g_name; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | const char * |
| 249 | SymbolFileDWARF::GetPluginDescriptionStatic() |
| 250 | { |
| 251 | return "DWARF and DWARF3 debug symbol file reader."; |
| 252 | } |
| 253 | |
| 254 | |
| 255 | SymbolFile* |
| 256 | SymbolFileDWARF::CreateInstance (ObjectFile* obj_file) |
| 257 | { |
| 258 | return new SymbolFileDWARF(obj_file); |
| 259 | } |
| 260 | |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 261 | TypeList * |
| 262 | SymbolFileDWARF::GetTypeList () |
| 263 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 264 | if (GetDebugMapSymfile ()) |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 265 | return m_debug_map_symfile->GetTypeList(); |
| 266 | return m_obj_file->GetModule()->GetTypeList(); |
| 267 | |
| 268 | } |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 269 | void |
| 270 | SymbolFileDWARF::GetTypes (DWARFCompileUnit* cu, |
| 271 | const DWARFDebugInfoEntry *die, |
| 272 | dw_offset_t min_die_offset, |
| 273 | dw_offset_t max_die_offset, |
| 274 | uint32_t type_mask, |
| 275 | TypeSet &type_set) |
| 276 | { |
| 277 | if (cu) |
| 278 | { |
| 279 | if (die) |
| 280 | { |
| 281 | const dw_offset_t die_offset = die->GetOffset(); |
| 282 | |
| 283 | if (die_offset >= max_die_offset) |
| 284 | return; |
| 285 | |
| 286 | if (die_offset >= min_die_offset) |
| 287 | { |
| 288 | const dw_tag_t tag = die->Tag(); |
| 289 | |
| 290 | bool add_type = false; |
| 291 | |
| 292 | switch (tag) |
| 293 | { |
| 294 | case DW_TAG_array_type: add_type = (type_mask & eTypeClassArray ) != 0; break; |
| 295 | case DW_TAG_unspecified_type: |
| 296 | case DW_TAG_base_type: add_type = (type_mask & eTypeClassBuiltin ) != 0; break; |
| 297 | case DW_TAG_class_type: add_type = (type_mask & eTypeClassClass ) != 0; break; |
| 298 | case DW_TAG_structure_type: add_type = (type_mask & eTypeClassStruct ) != 0; break; |
| 299 | case DW_TAG_union_type: add_type = (type_mask & eTypeClassUnion ) != 0; break; |
| 300 | case DW_TAG_enumeration_type: add_type = (type_mask & eTypeClassEnumeration ) != 0; break; |
| 301 | case DW_TAG_subroutine_type: |
| 302 | case DW_TAG_subprogram: |
| 303 | case DW_TAG_inlined_subroutine: add_type = (type_mask & eTypeClassFunction ) != 0; break; |
| 304 | case DW_TAG_pointer_type: add_type = (type_mask & eTypeClassPointer ) != 0; break; |
| 305 | case DW_TAG_rvalue_reference_type: |
| 306 | case DW_TAG_reference_type: add_type = (type_mask & eTypeClassReference ) != 0; break; |
| 307 | case DW_TAG_typedef: add_type = (type_mask & eTypeClassTypedef ) != 0; break; |
| 308 | case DW_TAG_ptr_to_member_type: add_type = (type_mask & eTypeClassMemberPointer ) != 0; break; |
| 309 | } |
| 310 | |
| 311 | if (add_type) |
| 312 | { |
| 313 | const bool assert_not_being_parsed = true; |
| 314 | Type *type = ResolveTypeUID (cu, die, assert_not_being_parsed); |
| 315 | if (type) |
| 316 | { |
| 317 | if (type_set.find(type) == type_set.end()) |
| 318 | type_set.insert(type); |
| 319 | } |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); |
| 324 | child_die != NULL; |
| 325 | child_die = child_die->GetSibling()) |
| 326 | { |
| 327 | GetTypes (cu, child_die, min_die_offset, max_die_offset, type_mask, type_set); |
| 328 | } |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | size_t |
| 334 | SymbolFileDWARF::GetTypes (SymbolContextScope *sc_scope, |
| 335 | uint32_t type_mask, |
| 336 | TypeList &type_list) |
| 337 | |
| 338 | { |
| 339 | TypeSet type_set; |
| 340 | |
| 341 | CompileUnit *comp_unit = NULL; |
| 342 | DWARFCompileUnit* dwarf_cu = NULL; |
| 343 | if (sc_scope) |
| 344 | comp_unit = sc_scope->CalculateSymbolContextCompileUnit(); |
| 345 | |
| 346 | if (comp_unit) |
| 347 | { |
| 348 | dwarf_cu = GetDWARFCompileUnit(comp_unit); |
| 349 | if (dwarf_cu == 0) |
| 350 | return 0; |
| 351 | GetTypes (dwarf_cu, |
| 352 | dwarf_cu->DIE(), |
| 353 | dwarf_cu->GetOffset(), |
| 354 | dwarf_cu->GetNextCompileUnitOffset(), |
| 355 | type_mask, |
| 356 | type_set); |
| 357 | } |
| 358 | else |
| 359 | { |
| 360 | DWARFDebugInfo* info = DebugInfo(); |
| 361 | if (info) |
| 362 | { |
| 363 | const size_t num_cus = info->GetNumCompileUnits(); |
| 364 | for (size_t cu_idx=0; cu_idx<num_cus; ++cu_idx) |
| 365 | { |
| 366 | dwarf_cu = info->GetCompileUnitAtIndex(cu_idx); |
| 367 | if (dwarf_cu) |
| 368 | { |
| 369 | GetTypes (dwarf_cu, |
| 370 | dwarf_cu->DIE(), |
| 371 | 0, |
| 372 | UINT32_MAX, |
| 373 | type_mask, |
| 374 | type_set); |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | } |
| 379 | // if (m_using_apple_tables) |
| 380 | // { |
| 381 | // DWARFMappedHash::MemoryTable *apple_types = m_apple_types_ap.get(); |
| 382 | // if (apple_types) |
| 383 | // { |
| 384 | // apple_types->ForEach([this, &type_set, apple_types, type_mask](const DWARFMappedHash::DIEInfoArray &die_info_array) -> bool { |
| 385 | // |
| 386 | // for (auto die_info: die_info_array) |
| 387 | // { |
| 388 | // bool add_type = TagMatchesTypeMask (type_mask, 0); |
| 389 | // if (!add_type) |
| 390 | // { |
| 391 | // dw_tag_t tag = die_info.tag; |
| 392 | // if (tag == 0) |
| 393 | // { |
| 394 | // const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_info.offset, NULL); |
| 395 | // tag = die->Tag(); |
| 396 | // } |
| 397 | // add_type = TagMatchesTypeMask (type_mask, tag); |
| 398 | // } |
| 399 | // if (add_type) |
| 400 | // { |
| 401 | // Type *type = ResolveTypeUID(die_info.offset); |
| 402 | // |
| 403 | // if (type_set.find(type) == type_set.end()) |
| 404 | // type_set.insert(type); |
| 405 | // } |
| 406 | // } |
| 407 | // return true; // Keep iterating |
| 408 | // }); |
| 409 | // } |
| 410 | // } |
| 411 | // else |
| 412 | // { |
| 413 | // if (!m_indexed) |
| 414 | // Index (); |
| 415 | // |
| 416 | // m_type_index.ForEach([this, &type_set, type_mask](const char *name, uint32_t die_offset) -> bool { |
| 417 | // |
| 418 | // bool add_type = TagMatchesTypeMask (type_mask, 0); |
| 419 | // |
| 420 | // if (!add_type) |
| 421 | // { |
| 422 | // const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_offset, NULL); |
| 423 | // if (die) |
| 424 | // { |
| 425 | // const dw_tag_t tag = die->Tag(); |
| 426 | // add_type = TagMatchesTypeMask (type_mask, tag); |
| 427 | // } |
| 428 | // } |
| 429 | // |
| 430 | // if (add_type) |
| 431 | // { |
| 432 | // Type *type = ResolveTypeUID(die_offset); |
| 433 | // |
| 434 | // if (type_set.find(type) == type_set.end()) |
| 435 | // type_set.insert(type); |
| 436 | // } |
| 437 | // return true; // Keep iterating |
| 438 | // }); |
| 439 | // } |
| 440 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 441 | std::set<ClangASTType> clang_type_set; |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 442 | size_t num_types_added = 0; |
| 443 | for (Type *type : type_set) |
| 444 | { |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 445 | ClangASTType clang_type = type->GetClangForwardType(); |
| Greg Clayton | 0fc4f31 | 2013-06-20 01:23:18 +0000 | [diff] [blame] | 446 | if (clang_type_set.find(clang_type) == clang_type_set.end()) |
| 447 | { |
| 448 | clang_type_set.insert(clang_type); |
| 449 | type_list.Insert (type->shared_from_this()); |
| 450 | ++num_types_added; |
| 451 | } |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 452 | } |
| 453 | return num_types_added; |
| 454 | } |
| 455 | |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 456 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 457 | //---------------------------------------------------------------------- |
| 458 | // Gets the first parent that is a lexical block, function or inlined |
| 459 | // subroutine, or compile unit. |
| 460 | //---------------------------------------------------------------------- |
| 461 | static const DWARFDebugInfoEntry * |
| 462 | GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die) |
| 463 | { |
| 464 | const DWARFDebugInfoEntry *die; |
| 465 | for (die = child_die->GetParent(); die != NULL; die = die->GetParent()) |
| 466 | { |
| 467 | dw_tag_t tag = die->Tag(); |
| 468 | |
| 469 | switch (tag) |
| 470 | { |
| 471 | case DW_TAG_compile_unit: |
| 472 | case DW_TAG_subprogram: |
| 473 | case DW_TAG_inlined_subroutine: |
| 474 | case DW_TAG_lexical_block: |
| 475 | return die; |
| 476 | } |
| 477 | } |
| 478 | return NULL; |
| 479 | } |
| 480 | |
| 481 | |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 482 | SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) : |
| 483 | SymbolFile (objfile), |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 484 | UserID (0), // Used by SymbolFileDWARFDebugMap to when this class parses .o files to contain the .o file index/ID |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 485 | m_debug_map_module_wp (), |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 486 | m_debug_map_symfile (NULL), |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 487 | m_clang_tu_decl (NULL), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 488 | m_flags(), |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 489 | m_data_debug_abbrev (), |
| 490 | m_data_debug_aranges (), |
| 491 | m_data_debug_frame (), |
| 492 | m_data_debug_info (), |
| 493 | m_data_debug_line (), |
| 494 | m_data_debug_loc (), |
| 495 | m_data_debug_ranges (), |
| 496 | m_data_debug_str (), |
| Greg Clayton | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 497 | m_data_apple_names (), |
| 498 | m_data_apple_types (), |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 499 | m_data_apple_namespaces (), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 500 | m_abbr(), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 501 | m_info(), |
| 502 | m_line(), |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 503 | m_apple_names_ap (), |
| 504 | m_apple_types_ap (), |
| 505 | m_apple_namespaces_ap (), |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 506 | m_apple_objc_ap (), |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 507 | m_function_basename_index(), |
| 508 | m_function_fullname_index(), |
| 509 | m_function_method_index(), |
| 510 | m_function_selector_index(), |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 511 | m_objc_class_selectors_index(), |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 512 | m_global_index(), |
| Greg Clayton | 69b0488 | 2010-10-15 02:03:22 +0000 | [diff] [blame] | 513 | m_type_index(), |
| 514 | m_namespace_index(), |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 515 | m_indexed (false), |
| 516 | m_is_external_ast_source (false), |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 517 | m_using_apple_tables (false), |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 518 | m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate), |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 519 | m_ranges(), |
| 520 | m_unique_ast_type_map () |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 521 | { |
| 522 | } |
| 523 | |
| 524 | SymbolFileDWARF::~SymbolFileDWARF() |
| 525 | { |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 526 | if (m_is_external_ast_source) |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 527 | { |
| 528 | ModuleSP module_sp (m_obj_file->GetModule()); |
| 529 | if (module_sp) |
| 530 | module_sp->GetClangASTContext().RemoveExternalSource (); |
| 531 | } |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | static const ConstString & |
| 535 | GetDWARFMachOSegmentName () |
| 536 | { |
| 537 | static ConstString g_dwarf_section_name ("__DWARF"); |
| 538 | return g_dwarf_section_name; |
| 539 | } |
| 540 | |
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 541 | UniqueDWARFASTTypeMap & |
| 542 | SymbolFileDWARF::GetUniqueDWARFASTTypeMap () |
| 543 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 544 | if (GetDebugMapSymfile ()) |
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 545 | return m_debug_map_symfile->GetUniqueDWARFASTTypeMap (); |
| 546 | return m_unique_ast_type_map; |
| 547 | } |
| 548 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 549 | ClangASTContext & |
| 550 | SymbolFileDWARF::GetClangASTContext () |
| 551 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 552 | if (GetDebugMapSymfile ()) |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 553 | return m_debug_map_symfile->GetClangASTContext (); |
| 554 | |
| 555 | ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext(); |
| 556 | if (!m_is_external_ast_source) |
| 557 | { |
| 558 | m_is_external_ast_source = true; |
| Todd Fiala | 955fe6f | 2014-02-27 17:18:23 +0000 | [diff] [blame] | 559 | llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> ast_source_ap ( |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 560 | new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl, |
| 561 | SymbolFileDWARF::CompleteObjCInterfaceDecl, |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 562 | SymbolFileDWARF::FindExternalVisibleDeclsByName, |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 563 | SymbolFileDWARF::LayoutRecordType, |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 564 | this)); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 565 | ast.SetExternalSource (ast_source_ap); |
| 566 | } |
| 567 | return ast; |
| 568 | } |
| 569 | |
| 570 | void |
| 571 | SymbolFileDWARF::InitializeObject() |
| 572 | { |
| 573 | // Install our external AST source callbacks so we can complete Clang types. |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 574 | ModuleSP module_sp (m_obj_file->GetModule()); |
| 575 | if (module_sp) |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 576 | { |
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 577 | const SectionList *section_list = module_sp->GetSectionList(); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 578 | |
| 579 | const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get(); |
| 580 | |
| 581 | // Memory map the DWARF mach-o segment so we have everything mmap'ed |
| 582 | // to keep our heap memory usage down. |
| 583 | if (section) |
| Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 584 | m_obj_file->MemoryMapSectionData(section, m_dwarf_data); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 585 | } |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 586 | get_apple_names_data(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 587 | if (m_data_apple_names.GetByteSize() > 0) |
| 588 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 589 | m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names")); |
| 590 | if (m_apple_names_ap->IsValid()) |
| 591 | m_using_apple_tables = true; |
| 592 | else |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 593 | m_apple_names_ap.reset(); |
| 594 | } |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 595 | get_apple_types_data(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 596 | if (m_data_apple_types.GetByteSize() > 0) |
| 597 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 598 | m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types")); |
| 599 | if (m_apple_types_ap->IsValid()) |
| 600 | m_using_apple_tables = true; |
| 601 | else |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 602 | m_apple_types_ap.reset(); |
| 603 | } |
| 604 | |
| 605 | get_apple_namespaces_data(); |
| 606 | if (m_data_apple_namespaces.GetByteSize() > 0) |
| 607 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 608 | m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces")); |
| 609 | if (m_apple_namespaces_ap->IsValid()) |
| 610 | m_using_apple_tables = true; |
| 611 | else |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 612 | m_apple_namespaces_ap.reset(); |
| 613 | } |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 614 | |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 615 | get_apple_objc_data(); |
| 616 | if (m_data_apple_objc.GetByteSize() > 0) |
| 617 | { |
| 618 | m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc")); |
| 619 | if (m_apple_objc_ap->IsValid()) |
| 620 | m_using_apple_tables = true; |
| 621 | else |
| 622 | m_apple_objc_ap.reset(); |
| 623 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | bool |
| 627 | SymbolFileDWARF::SupportedVersion(uint16_t version) |
| 628 | { |
| Greg Clayton | abcbfe5 | 2013-04-04 00:00:36 +0000 | [diff] [blame] | 629 | return version == 2 || version == 3 || version == 4; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | uint32_t |
| Sean Callanan | bfaf54d | 2011-12-03 04:38:43 +0000 | [diff] [blame] | 633 | SymbolFileDWARF::CalculateAbilities () |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 634 | { |
| 635 | uint32_t abilities = 0; |
| 636 | if (m_obj_file != NULL) |
| 637 | { |
| 638 | const Section* section = NULL; |
| 639 | const SectionList *section_list = m_obj_file->GetSectionList(); |
| 640 | if (section_list == NULL) |
| 641 | return 0; |
| 642 | |
| 643 | uint64_t debug_abbrev_file_size = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 644 | uint64_t debug_info_file_size = 0; |
| 645 | uint64_t debug_line_file_size = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 646 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 647 | section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 648 | |
| 649 | if (section) |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 650 | section_list = §ion->GetChildren (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 651 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 652 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 653 | if (section != NULL) |
| 654 | { |
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 655 | debug_info_file_size = section->GetFileSize(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 656 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 657 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 658 | if (section) |
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 659 | debug_abbrev_file_size = section->GetFileSize(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 660 | else |
| 661 | m_flags.Set (flagsGotDebugAbbrevData); |
| 662 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 663 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 664 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 665 | m_flags.Set (flagsGotDebugArangesData); |
| 666 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 667 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 668 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 669 | m_flags.Set (flagsGotDebugFrameData); |
| 670 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 671 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 672 | if (section) |
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 673 | debug_line_file_size = section->GetFileSize(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 674 | else |
| 675 | m_flags.Set (flagsGotDebugLineData); |
| 676 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 677 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 678 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 679 | m_flags.Set (flagsGotDebugLocData); |
| 680 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 681 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 682 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 683 | m_flags.Set (flagsGotDebugMacInfoData); |
| 684 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 685 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 686 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 687 | m_flags.Set (flagsGotDebugPubNamesData); |
| 688 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 689 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 690 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 691 | m_flags.Set (flagsGotDebugPubTypesData); |
| 692 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 693 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 694 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 695 | m_flags.Set (flagsGotDebugRangesData); |
| 696 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 697 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 698 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 699 | m_flags.Set (flagsGotDebugStrData); |
| 700 | } |
| Greg Clayton | 6c59661 | 2012-05-18 21:47:20 +0000 | [diff] [blame] | 701 | else |
| 702 | { |
| 703 | const char *symfile_dir_cstr = m_obj_file->GetFileSpec().GetDirectory().GetCString(); |
| 704 | if (symfile_dir_cstr) |
| 705 | { |
| 706 | if (strcasestr(symfile_dir_cstr, ".dsym")) |
| 707 | { |
| 708 | if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo) |
| 709 | { |
| 710 | // We have a dSYM file that didn't have a any debug info. |
| 711 | // If the string table has a size of 1, then it was made from |
| 712 | // an executable with no debug info, or from an executable that |
| 713 | // was stripped. |
| 714 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get(); |
| 715 | if (section && section->GetFileSize() == 1) |
| 716 | { |
| 717 | m_obj_file->GetModule()->ReportWarning ("empty dSYM file detected, dSYM was created with an executable with no debug info."); |
| 718 | } |
| 719 | } |
| 720 | } |
| 721 | } |
| 722 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 723 | |
| 724 | if (debug_abbrev_file_size > 0 && debug_info_file_size > 0) |
| 725 | abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes; |
| 726 | |
| 727 | if (debug_line_file_size > 0) |
| 728 | abilities |= LineTables; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 729 | } |
| 730 | return abilities; |
| 731 | } |
| 732 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 733 | const DWARFDataExtractor& |
| 734 | SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DWARFDataExtractor &data) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 735 | { |
| 736 | if (m_flags.IsClear (got_flag)) |
| 737 | { |
| Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 738 | ModuleSP module_sp (m_obj_file->GetModule()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 739 | m_flags.Set (got_flag); |
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 740 | const SectionList *section_list = module_sp->GetSectionList(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 741 | if (section_list) |
| 742 | { |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 743 | SectionSP section_sp (section_list->FindSectionByType(sect_type, true)); |
| 744 | if (section_sp) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 745 | { |
| 746 | // See if we memory mapped the DWARF segment? |
| 747 | if (m_dwarf_data.GetByteSize()) |
| 748 | { |
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 749 | data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetFileSize()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 750 | } |
| 751 | else |
| 752 | { |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 753 | if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 754 | data.Clear(); |
| 755 | } |
| 756 | } |
| 757 | } |
| 758 | } |
| 759 | return data; |
| 760 | } |
| 761 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 762 | const DWARFDataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 763 | SymbolFileDWARF::get_debug_abbrev_data() |
| 764 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 765 | return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 766 | } |
| 767 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 768 | const DWARFDataExtractor& |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 769 | SymbolFileDWARF::get_debug_aranges_data() |
| 770 | { |
| 771 | return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges); |
| 772 | } |
| 773 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 774 | const DWARFDataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 775 | SymbolFileDWARF::get_debug_frame_data() |
| 776 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 777 | return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 778 | } |
| 779 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 780 | const DWARFDataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 781 | SymbolFileDWARF::get_debug_info_data() |
| 782 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 783 | return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 784 | } |
| 785 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 786 | const DWARFDataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 787 | SymbolFileDWARF::get_debug_line_data() |
| 788 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 789 | return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 790 | } |
| 791 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 792 | const DWARFDataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 793 | SymbolFileDWARF::get_debug_loc_data() |
| 794 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 795 | return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 796 | } |
| 797 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 798 | const DWARFDataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 799 | SymbolFileDWARF::get_debug_ranges_data() |
| 800 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 801 | return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 802 | } |
| 803 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 804 | const DWARFDataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 805 | SymbolFileDWARF::get_debug_str_data() |
| 806 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 807 | return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 808 | } |
| 809 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 810 | const DWARFDataExtractor& |
| Greg Clayton | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 811 | SymbolFileDWARF::get_apple_names_data() |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 812 | { |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 813 | return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names); |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 814 | } |
| 815 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 816 | const DWARFDataExtractor& |
| Greg Clayton | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 817 | SymbolFileDWARF::get_apple_types_data() |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 818 | { |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 819 | return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types); |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 820 | } |
| 821 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 822 | const DWARFDataExtractor& |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 823 | SymbolFileDWARF::get_apple_namespaces_data() |
| 824 | { |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 825 | return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces); |
| 826 | } |
| 827 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 828 | const DWARFDataExtractor& |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 829 | SymbolFileDWARF::get_apple_objc_data() |
| 830 | { |
| 831 | return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 832 | } |
| 833 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 834 | |
| 835 | DWARFDebugAbbrev* |
| 836 | SymbolFileDWARF::DebugAbbrev() |
| 837 | { |
| 838 | if (m_abbr.get() == NULL) |
| 839 | { |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 840 | const DWARFDataExtractor &debug_abbrev_data = get_debug_abbrev_data(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 841 | if (debug_abbrev_data.GetByteSize() > 0) |
| 842 | { |
| 843 | m_abbr.reset(new DWARFDebugAbbrev()); |
| 844 | if (m_abbr.get()) |
| 845 | m_abbr->Parse(debug_abbrev_data); |
| 846 | } |
| 847 | } |
| 848 | return m_abbr.get(); |
| 849 | } |
| 850 | |
| 851 | const DWARFDebugAbbrev* |
| 852 | SymbolFileDWARF::DebugAbbrev() const |
| 853 | { |
| 854 | return m_abbr.get(); |
| 855 | } |
| 856 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 857 | |
| 858 | DWARFDebugInfo* |
| 859 | SymbolFileDWARF::DebugInfo() |
| 860 | { |
| 861 | if (m_info.get() == NULL) |
| 862 | { |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 863 | Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", |
| 864 | __PRETTY_FUNCTION__, static_cast<void*>(this)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 865 | if (get_debug_info_data().GetByteSize() > 0) |
| 866 | { |
| 867 | m_info.reset(new DWARFDebugInfo()); |
| 868 | if (m_info.get()) |
| 869 | { |
| 870 | m_info->SetDwarfData(this); |
| 871 | } |
| 872 | } |
| 873 | } |
| 874 | return m_info.get(); |
| 875 | } |
| 876 | |
| 877 | const DWARFDebugInfo* |
| 878 | SymbolFileDWARF::DebugInfo() const |
| 879 | { |
| 880 | return m_info.get(); |
| 881 | } |
| 882 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 883 | DWARFCompileUnit* |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 884 | SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 885 | { |
| 886 | DWARFDebugInfo* info = DebugInfo(); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 887 | if (info) |
| 888 | { |
| 889 | if (GetDebugMapSymfile ()) |
| 890 | { |
| 891 | // The debug map symbol file made the compile units for this DWARF |
| 892 | // file which is .o file with DWARF in it, and we should have |
| 893 | // only 1 compile unit which is at offset zero in the DWARF. |
| 894 | // TODO: modify to support LTO .o files where each .o file might |
| 895 | // have multiple DW_TAG_compile_unit tags. |
| 896 | return info->GetCompileUnit(0).get(); |
| 897 | } |
| 898 | else |
| 899 | { |
| 900 | // Just a normal DWARF file whose user ID for the compile unit is |
| 901 | // the DWARF offset itself |
| 902 | return info->GetCompileUnit((dw_offset_t)comp_unit->GetID()).get(); |
| 903 | } |
| 904 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 905 | return NULL; |
| 906 | } |
| 907 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 908 | |
| 909 | DWARFDebugRanges* |
| 910 | SymbolFileDWARF::DebugRanges() |
| 911 | { |
| 912 | if (m_ranges.get() == NULL) |
| 913 | { |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 914 | Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", |
| 915 | __PRETTY_FUNCTION__, static_cast<void*>(this)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 916 | if (get_debug_ranges_data().GetByteSize() > 0) |
| 917 | { |
| 918 | m_ranges.reset(new DWARFDebugRanges()); |
| 919 | if (m_ranges.get()) |
| 920 | m_ranges->Extract(this); |
| 921 | } |
| 922 | } |
| 923 | return m_ranges.get(); |
| 924 | } |
| 925 | |
| 926 | const DWARFDebugRanges* |
| 927 | SymbolFileDWARF::DebugRanges() const |
| 928 | { |
| 929 | return m_ranges.get(); |
| 930 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 931 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 932 | lldb::CompUnitSP |
| 933 | SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 934 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 935 | CompUnitSP cu_sp; |
| 936 | if (dwarf_cu) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 937 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 938 | CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData(); |
| 939 | if (comp_unit) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 940 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 941 | // We already parsed this compile unit, had out a shared pointer to it |
| 942 | cu_sp = comp_unit->shared_from_this(); |
| 943 | } |
| 944 | else |
| 945 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 946 | if (GetDebugMapSymfile ()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 947 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 948 | // Let the debug map create the compile unit |
| 949 | cu_sp = m_debug_map_symfile->GetCompileUnit(this); |
| 950 | dwarf_cu->SetUserData(cu_sp.get()); |
| 951 | } |
| 952 | else |
| 953 | { |
| 954 | ModuleSP module_sp (m_obj_file->GetModule()); |
| 955 | if (module_sp) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 956 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 957 | const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly (); |
| 958 | if (cu_die) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 959 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 960 | const char * cu_die_name = cu_die->GetName(this, dwarf_cu); |
| 961 | const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL); |
| 962 | LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0); |
| 963 | if (cu_die_name) |
| 964 | { |
| 965 | std::string ramapped_file; |
| 966 | FileSpec cu_file_spec; |
| Jim Ingham | 0909e5f | 2010-09-16 00:57:33 +0000 | [diff] [blame] | 967 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 968 | if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0') |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 969 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 970 | // If we have a full path to the compile unit, we don't need to resolve |
| 971 | // the file. This can be expensive e.g. when the source files are NFS mounted. |
| 972 | if (module_sp->RemapSourceFile(cu_die_name, ramapped_file)) |
| 973 | cu_file_spec.SetFile (ramapped_file.c_str(), false); |
| 974 | else |
| 975 | cu_file_spec.SetFile (cu_die_name, false); |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 976 | } |
| 977 | else |
| 978 | { |
| Matthew Gardiner | e81df3b | 2014-08-26 06:57:23 +0000 | [diff] [blame] | 979 | // DWARF2/3 suggests the form hostname:pathname for compilation directory. |
| 980 | // Remove the host part if present. |
| 981 | cu_comp_dir = removeHostnameFromPathname(cu_comp_dir); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 982 | std::string fullpath(cu_comp_dir); |
| Matthew Gardiner | e81df3b | 2014-08-26 06:57:23 +0000 | [diff] [blame] | 983 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 984 | if (*fullpath.rbegin() != '/') |
| 985 | fullpath += '/'; |
| 986 | fullpath += cu_die_name; |
| 987 | if (module_sp->RemapSourceFile (fullpath.c_str(), ramapped_file)) |
| 988 | cu_file_spec.SetFile (ramapped_file.c_str(), false); |
| 989 | else |
| 990 | cu_file_spec.SetFile (fullpath.c_str(), false); |
| 991 | } |
| 992 | |
| 993 | cu_sp.reset(new CompileUnit (module_sp, |
| 994 | dwarf_cu, |
| 995 | cu_file_spec, |
| 996 | MakeUserID(dwarf_cu->GetOffset()), |
| 997 | cu_language)); |
| 998 | if (cu_sp) |
| 999 | { |
| 1000 | dwarf_cu->SetUserData(cu_sp.get()); |
| 1001 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1002 | // Figure out the compile unit index if we weren't given one |
| 1003 | if (cu_idx == UINT32_MAX) |
| 1004 | DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx); |
| 1005 | |
| 1006 | m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp); |
| 1007 | } |
| 1008 | } |
| 1009 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1010 | } |
| 1011 | } |
| 1012 | } |
| 1013 | } |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1014 | return cu_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1015 | } |
| 1016 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1017 | uint32_t |
| 1018 | SymbolFileDWARF::GetNumCompileUnits() |
| 1019 | { |
| 1020 | DWARFDebugInfo* info = DebugInfo(); |
| 1021 | if (info) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1022 | return info->GetNumCompileUnits(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1023 | return 0; |
| 1024 | } |
| 1025 | |
| 1026 | CompUnitSP |
| 1027 | SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx) |
| 1028 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1029 | CompUnitSP cu_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1030 | DWARFDebugInfo* info = DebugInfo(); |
| 1031 | if (info) |
| 1032 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1033 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx); |
| 1034 | if (dwarf_cu) |
| 1035 | cu_sp = ParseCompileUnit(dwarf_cu, cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1036 | } |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1037 | return cu_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1038 | } |
| 1039 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1040 | Function * |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1041 | SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1042 | { |
| 1043 | DWARFDebugRanges::RangeList func_ranges; |
| 1044 | const char *name = NULL; |
| 1045 | const char *mangled = NULL; |
| 1046 | int decl_file = 0; |
| 1047 | int decl_line = 0; |
| 1048 | int decl_column = 0; |
| 1049 | int call_file = 0; |
| 1050 | int call_line = 0; |
| 1051 | int call_column = 0; |
| 1052 | DWARFExpression frame_base; |
| 1053 | |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1054 | assert (die->Tag() == DW_TAG_subprogram); |
| 1055 | |
| 1056 | if (die->Tag() != DW_TAG_subprogram) |
| 1057 | return NULL; |
| 1058 | |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1059 | if (die->GetDIENamesAndRanges (this, |
| 1060 | dwarf_cu, |
| 1061 | name, |
| 1062 | mangled, |
| 1063 | func_ranges, |
| 1064 | decl_file, |
| 1065 | decl_line, |
| 1066 | decl_column, |
| 1067 | call_file, |
| 1068 | call_line, |
| 1069 | call_column, |
| 1070 | &frame_base)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1071 | { |
| 1072 | // Union of all ranges in the function DIE (if the function is discontiguous) |
| 1073 | AddressRange func_range; |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1074 | lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0); |
| 1075 | lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1076 | if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr) |
| 1077 | { |
| Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1078 | ModuleSP module_sp (m_obj_file->GetModule()); |
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 1079 | func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, module_sp->GetSectionList()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1080 | if (func_range.GetBaseAddress().IsValid()) |
| 1081 | func_range.SetByteSize(highest_func_addr - lowest_func_addr); |
| 1082 | } |
| 1083 | |
| 1084 | if (func_range.GetBaseAddress().IsValid()) |
| 1085 | { |
| 1086 | Mangled func_name; |
| 1087 | if (mangled) |
| Greg Clayton | 037520e | 2012-07-18 23:18:10 +0000 | [diff] [blame] | 1088 | func_name.SetValue(ConstString(mangled), true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1089 | else if (name) |
| Greg Clayton | 037520e | 2012-07-18 23:18:10 +0000 | [diff] [blame] | 1090 | func_name.SetValue(ConstString(name), false); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1091 | |
| 1092 | FunctionSP func_sp; |
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1093 | std::unique_ptr<Declaration> decl_ap; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1094 | if (decl_file != 0 || decl_line != 0 || decl_column != 0) |
| Greg Clayton | d7e0546 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 1095 | decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), |
| 1096 | decl_line, |
| 1097 | decl_column)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1098 | |
| Greg Clayton | 0bd4e1b | 2011-09-30 20:52:25 +0000 | [diff] [blame] | 1099 | // Supply the type _only_ if it has already been parsed |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 1100 | Type *func_type = m_die_to_type.lookup (die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1101 | |
| 1102 | assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED); |
| 1103 | |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1104 | if (FixupAddress (func_range.GetBaseAddress())) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1105 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1106 | const user_id_t func_user_id = MakeUserID(die->GetOffset()); |
| 1107 | func_sp.reset(new Function (sc.comp_unit, |
| 1108 | MakeUserID(func_user_id), // UserID is the DIE offset |
| 1109 | MakeUserID(func_user_id), |
| 1110 | func_name, |
| 1111 | func_type, |
| 1112 | func_range)); // first address range |
| 1113 | |
| 1114 | if (func_sp.get() != NULL) |
| 1115 | { |
| 1116 | if (frame_base.IsValid()) |
| 1117 | func_sp->GetFrameBaseExpression() = frame_base; |
| 1118 | sc.comp_unit->AddFunction(func_sp); |
| 1119 | return func_sp.get(); |
| 1120 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1121 | } |
| 1122 | } |
| 1123 | } |
| 1124 | return NULL; |
| 1125 | } |
| 1126 | |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1127 | bool |
| 1128 | SymbolFileDWARF::FixupAddress (Address &addr) |
| 1129 | { |
| 1130 | SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile (); |
| 1131 | if (debug_map_symfile) |
| 1132 | { |
| 1133 | return debug_map_symfile->LinkOSOAddress(addr); |
| 1134 | } |
| 1135 | // This is a normal DWARF file, no address fixups need to happen |
| 1136 | return true; |
| 1137 | } |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1138 | lldb::LanguageType |
| 1139 | SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc) |
| 1140 | { |
| 1141 | assert (sc.comp_unit); |
| 1142 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| 1143 | if (dwarf_cu) |
| 1144 | { |
| 1145 | const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly(); |
| Jim Ingham | 28eb571 | 2012-10-12 17:34:26 +0000 | [diff] [blame] | 1146 | if (die) |
| 1147 | { |
| 1148 | const uint32_t language = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0); |
| 1149 | if (language) |
| 1150 | return (lldb::LanguageType)language; |
| 1151 | } |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1152 | } |
| 1153 | return eLanguageTypeUnknown; |
| 1154 | } |
| 1155 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1156 | size_t |
| 1157 | SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc) |
| 1158 | { |
| 1159 | assert (sc.comp_unit); |
| 1160 | size_t functions_added = 0; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1161 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1162 | if (dwarf_cu) |
| 1163 | { |
| 1164 | DWARFDIECollection function_dies; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1165 | const size_t num_functions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1166 | size_t func_idx; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1167 | for (func_idx = 0; func_idx < num_functions; ++func_idx) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1168 | { |
| 1169 | const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1170 | if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1171 | { |
| 1172 | if (ParseCompileUnitFunction(sc, dwarf_cu, die)) |
| 1173 | ++functions_added; |
| 1174 | } |
| 1175 | } |
| 1176 | //FixupTypes(); |
| 1177 | } |
| 1178 | return functions_added; |
| 1179 | } |
| 1180 | |
| 1181 | bool |
| 1182 | SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files) |
| 1183 | { |
| 1184 | assert (sc.comp_unit); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1185 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1186 | if (dwarf_cu) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1187 | { |
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1188 | const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1189 | |
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1190 | if (cu_die) |
| 1191 | { |
| 1192 | const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL); |
| Matthew Gardiner | e81df3b | 2014-08-26 06:57:23 +0000 | [diff] [blame] | 1193 | |
| 1194 | // DWARF2/3 suggests the form hostname:pathname for compilation directory. |
| 1195 | // Remove the host part if present. |
| 1196 | cu_comp_dir = removeHostnameFromPathname(cu_comp_dir); |
| 1197 | |
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1198 | dw_offset_t stmt_list = cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1199 | |
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1200 | // All file indexes in DWARF are one based and a file of index zero is |
| 1201 | // supposed to be the compile unit itself. |
| 1202 | support_files.Append (*sc.comp_unit); |
| 1203 | |
| 1204 | return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files); |
| 1205 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1206 | } |
| 1207 | return false; |
| 1208 | } |
| 1209 | |
| 1210 | struct ParseDWARFLineTableCallbackInfo |
| 1211 | { |
| 1212 | LineTable* line_table; |
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1213 | std::unique_ptr<LineSequence> sequence_ap; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1214 | }; |
| 1215 | |
| 1216 | //---------------------------------------------------------------------- |
| 1217 | // ParseStatementTableCallback |
| 1218 | //---------------------------------------------------------------------- |
| 1219 | static void |
| 1220 | ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData) |
| 1221 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1222 | if (state.row == DWARFDebugLine::State::StartParsingLineTable) |
| 1223 | { |
| 1224 | // Just started parsing the line table |
| 1225 | } |
| 1226 | else if (state.row == DWARFDebugLine::State::DoneParsingLineTable) |
| 1227 | { |
| 1228 | // Done parsing line table, nothing to do for the cleanup |
| 1229 | } |
| 1230 | else |
| 1231 | { |
| 1232 | ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData; |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1233 | LineTable* line_table = info->line_table; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1234 | |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1235 | // If this is our first time here, we need to create a |
| 1236 | // sequence container. |
| 1237 | if (!info->sequence_ap.get()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1238 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1239 | info->sequence_ap.reset(line_table->CreateLineSequenceContainer()); |
| 1240 | assert(info->sequence_ap.get()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1241 | } |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1242 | line_table->AppendLineEntryToSequence (info->sequence_ap.get(), |
| 1243 | state.address, |
| 1244 | state.line, |
| 1245 | state.column, |
| 1246 | state.file, |
| 1247 | state.is_stmt, |
| 1248 | state.basic_block, |
| 1249 | state.prologue_end, |
| 1250 | state.epilogue_begin, |
| 1251 | state.end_sequence); |
| 1252 | if (state.end_sequence) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1253 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1254 | // First, put the current sequence into the line table. |
| 1255 | line_table->InsertSequence(info->sequence_ap.get()); |
| 1256 | // Then, empty it to prepare for the next sequence. |
| 1257 | info->sequence_ap->Clear(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1258 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1259 | } |
| 1260 | } |
| 1261 | |
| 1262 | bool |
| 1263 | SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc) |
| 1264 | { |
| 1265 | assert (sc.comp_unit); |
| 1266 | if (sc.comp_unit->GetLineTable() != NULL) |
| 1267 | return true; |
| 1268 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1269 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1270 | if (dwarf_cu) |
| 1271 | { |
| 1272 | const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly(); |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1273 | if (dwarf_cu_die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1274 | { |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1275 | const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET); |
| 1276 | if (cu_line_offset != DW_INVALID_OFFSET) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1277 | { |
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1278 | std::unique_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit)); |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1279 | if (line_table_ap.get()) |
| 1280 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1281 | ParseDWARFLineTableCallbackInfo info; |
| 1282 | info.line_table = line_table_ap.get(); |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1283 | lldb::offset_t offset = cu_line_offset; |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1284 | DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info); |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1285 | if (m_debug_map_symfile) |
| 1286 | { |
| 1287 | // We have an object file that has a line table with addresses |
| 1288 | // that are not linked. We need to link the line table and convert |
| 1289 | // the addresses that are relative to the .o file into addresses |
| 1290 | // for the main executable. |
| 1291 | sc.comp_unit->SetLineTable (m_debug_map_symfile->LinkOSOLineTable (this, line_table_ap.get())); |
| 1292 | } |
| 1293 | else |
| 1294 | { |
| 1295 | sc.comp_unit->SetLineTable(line_table_ap.release()); |
| 1296 | return true; |
| 1297 | } |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1298 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1299 | } |
| 1300 | } |
| 1301 | } |
| 1302 | return false; |
| 1303 | } |
| 1304 | |
| 1305 | size_t |
| 1306 | SymbolFileDWARF::ParseFunctionBlocks |
| 1307 | ( |
| 1308 | const SymbolContext& sc, |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1309 | Block *parent_block, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1310 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1311 | const DWARFDebugInfoEntry *die, |
| 1312 | addr_t subprogram_low_pc, |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1313 | uint32_t depth |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1314 | ) |
| 1315 | { |
| 1316 | size_t blocks_added = 0; |
| 1317 | while (die != NULL) |
| 1318 | { |
| 1319 | dw_tag_t tag = die->Tag(); |
| 1320 | |
| 1321 | switch (tag) |
| 1322 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1323 | case DW_TAG_inlined_subroutine: |
| Greg Clayton | b4d3733 | 2011-08-12 16:22:48 +0000 | [diff] [blame] | 1324 | case DW_TAG_subprogram: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1325 | case DW_TAG_lexical_block: |
| 1326 | { |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1327 | Block *block = NULL; |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1328 | if (tag == DW_TAG_subprogram) |
| 1329 | { |
| 1330 | // Skip any DW_TAG_subprogram DIEs that are inside |
| 1331 | // of a normal or inlined functions. These will be |
| 1332 | // parsed on their own as separate entities. |
| 1333 | |
| 1334 | if (depth > 0) |
| 1335 | break; |
| 1336 | |
| 1337 | block = parent_block; |
| 1338 | } |
| 1339 | else |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1340 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1341 | BlockSP block_sp(new Block (MakeUserID(die->GetOffset()))); |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1342 | parent_block->AddChild(block_sp); |
| 1343 | block = block_sp.get(); |
| 1344 | } |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1345 | DWARFDebugRanges::RangeList ranges; |
| 1346 | const char *name = NULL; |
| 1347 | const char *mangled_name = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1348 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1349 | int decl_file = 0; |
| 1350 | int decl_line = 0; |
| 1351 | int decl_column = 0; |
| 1352 | int call_file = 0; |
| 1353 | int call_line = 0; |
| 1354 | int call_column = 0; |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1355 | if (die->GetDIENamesAndRanges (this, |
| 1356 | dwarf_cu, |
| 1357 | name, |
| 1358 | mangled_name, |
| 1359 | ranges, |
| 1360 | decl_file, decl_line, decl_column, |
| 1361 | call_file, call_line, call_column)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1362 | { |
| 1363 | if (tag == DW_TAG_subprogram) |
| 1364 | { |
| 1365 | assert (subprogram_low_pc == LLDB_INVALID_ADDRESS); |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1366 | subprogram_low_pc = ranges.GetMinRangeBase(0); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1367 | } |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1368 | else if (tag == DW_TAG_inlined_subroutine) |
| 1369 | { |
| 1370 | // We get called here for inlined subroutines in two ways. |
| 1371 | // The first time is when we are making the Function object |
| 1372 | // for this inlined concrete instance. Since we're creating a top level block at |
| 1373 | // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to |
| 1374 | // adjust the containing address. |
| 1375 | // The second time is when we are parsing the blocks inside the function that contains |
| 1376 | // the inlined concrete instance. Since these will be blocks inside the containing "real" |
| 1377 | // function the offset will be for that function. |
| 1378 | if (subprogram_low_pc == LLDB_INVALID_ADDRESS) |
| 1379 | { |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1380 | subprogram_low_pc = ranges.GetMinRangeBase(0); |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1381 | } |
| 1382 | } |
| Greg Clayton | 103f309 | 2015-01-15 03:04:37 +0000 | [diff] [blame^] | 1383 | |
| 1384 | const size_t num_ranges = ranges.GetSize(); |
| 1385 | for (size_t i = 0; i<num_ranges; ++i) |
| 1386 | { |
| 1387 | const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i); |
| 1388 | const addr_t range_base = range.GetRangeBase(); |
| 1389 | if (range_base >= subprogram_low_pc) |
| 1390 | block->AddRange(Block::Range (range_base - subprogram_low_pc, range.GetByteSize())); |
| 1391 | else |
| 1392 | { |
| 1393 | GetObjectFile()->GetModule()->ReportError ("0x%8.8" PRIx64 ": adding range [0x%" PRIx64 "-0x%" PRIx64 ") which has a base that is less than the function's low PC 0x%" PRIx64 ". Please file a bug and attach the file at the start of this error message", |
| 1394 | block->GetID(), |
| 1395 | range_base, |
| 1396 | range.GetRangeEnd(), |
| 1397 | subprogram_low_pc); |
| 1398 | } |
| 1399 | } |
| 1400 | block->FinalizeRanges (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1401 | |
| 1402 | if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL)) |
| 1403 | { |
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1404 | std::unique_ptr<Declaration> decl_ap; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1405 | if (decl_file != 0 || decl_line != 0 || decl_column != 0) |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1406 | decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), |
| 1407 | decl_line, decl_column)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1408 | |
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1409 | std::unique_ptr<Declaration> call_ap; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1410 | if (call_file != 0 || call_line != 0 || call_column != 0) |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1411 | call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file), |
| 1412 | call_line, call_column)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1413 | |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1414 | block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | ++blocks_added; |
| 1418 | |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1419 | if (die->HasChildren()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1420 | { |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1421 | blocks_added += ParseFunctionBlocks (sc, |
| 1422 | block, |
| 1423 | dwarf_cu, |
| 1424 | die->GetFirstChild(), |
| 1425 | subprogram_low_pc, |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1426 | depth + 1); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1427 | } |
| 1428 | } |
| 1429 | } |
| 1430 | break; |
| 1431 | default: |
| 1432 | break; |
| 1433 | } |
| 1434 | |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1435 | // Only parse siblings of the block if we are not at depth zero. A depth |
| 1436 | // of zero indicates we are currently parsing the top level |
| 1437 | // DW_TAG_subprogram DIE |
| 1438 | |
| 1439 | if (depth == 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1440 | die = NULL; |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1441 | else |
| 1442 | die = die->GetSibling(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1443 | } |
| 1444 | return blocks_added; |
| 1445 | } |
| 1446 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1447 | bool |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1448 | SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu, |
| 1449 | const DWARFDebugInfoEntry *die, |
| 1450 | ClangASTContext::TemplateParameterInfos &template_param_infos) |
| 1451 | { |
| 1452 | const dw_tag_t tag = die->Tag(); |
| 1453 | |
| 1454 | switch (tag) |
| 1455 | { |
| 1456 | case DW_TAG_template_type_parameter: |
| 1457 | case DW_TAG_template_value_parameter: |
| 1458 | { |
| Todd Fiala | ee8bfc6 | 2014-09-11 17:29:12 +0000 | [diff] [blame] | 1459 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64()); |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1460 | |
| 1461 | DWARFDebugInfoEntry::Attributes attributes; |
| 1462 | const size_t num_attributes = die->GetAttributes (this, |
| 1463 | dwarf_cu, |
| 1464 | fixed_form_sizes, |
| 1465 | attributes); |
| 1466 | const char *name = NULL; |
| 1467 | Type *lldb_type = NULL; |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1468 | ClangASTType clang_type; |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1469 | uint64_t uval64 = 0; |
| 1470 | bool uval64_valid = false; |
| 1471 | if (num_attributes > 0) |
| 1472 | { |
| 1473 | DWARFFormValue form_value; |
| 1474 | for (size_t i=0; i<num_attributes; ++i) |
| 1475 | { |
| 1476 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 1477 | |
| 1478 | switch (attr) |
| 1479 | { |
| 1480 | case DW_AT_name: |
| 1481 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1482 | name = form_value.AsCString(&get_debug_str_data()); |
| 1483 | break; |
| 1484 | |
| 1485 | case DW_AT_type: |
| 1486 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1487 | { |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 1488 | const dw_offset_t type_die_offset = form_value.Reference(); |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1489 | lldb_type = ResolveTypeUID(type_die_offset); |
| 1490 | if (lldb_type) |
| 1491 | clang_type = lldb_type->GetClangForwardType(); |
| 1492 | } |
| 1493 | break; |
| 1494 | |
| 1495 | case DW_AT_const_value: |
| 1496 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1497 | { |
| 1498 | uval64_valid = true; |
| 1499 | uval64 = form_value.Unsigned(); |
| 1500 | } |
| 1501 | break; |
| 1502 | default: |
| 1503 | break; |
| 1504 | } |
| 1505 | } |
| 1506 | |
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1507 | clang::ASTContext *ast = GetClangASTContext().getASTContext(); |
| 1508 | if (!clang_type) |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1509 | clang_type = GetClangASTContext().GetBasicType(eBasicTypeVoid); |
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1510 | |
| 1511 | if (clang_type) |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1512 | { |
| 1513 | bool is_signed = false; |
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1514 | if (name && name[0]) |
| 1515 | template_param_infos.names.push_back(name); |
| 1516 | else |
| 1517 | template_param_infos.names.push_back(NULL); |
| 1518 | |
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1519 | if (tag == DW_TAG_template_value_parameter && |
| 1520 | lldb_type != NULL && |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1521 | clang_type.IsIntegerType (is_signed) && |
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1522 | uval64_valid) |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1523 | { |
| 1524 | llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed); |
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1525 | template_param_infos.args.push_back (clang::TemplateArgument (*ast, |
| Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1526 | llvm::APSInt(apint), |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1527 | clang_type.GetQualType())); |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1528 | } |
| 1529 | else |
| 1530 | { |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1531 | template_param_infos.args.push_back (clang::TemplateArgument (clang_type.GetQualType())); |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1532 | } |
| 1533 | } |
| 1534 | else |
| 1535 | { |
| 1536 | return false; |
| 1537 | } |
| 1538 | |
| 1539 | } |
| 1540 | } |
| 1541 | return true; |
| 1542 | |
| 1543 | default: |
| 1544 | break; |
| 1545 | } |
| 1546 | return false; |
| 1547 | } |
| 1548 | |
| 1549 | bool |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1550 | SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu, |
| 1551 | const DWARFDebugInfoEntry *parent_die, |
| 1552 | ClangASTContext::TemplateParameterInfos &template_param_infos) |
| 1553 | { |
| 1554 | |
| 1555 | if (parent_die == NULL) |
| Filipe Cabecinhas | 52008c6 | 2012-05-23 16:24:11 +0000 | [diff] [blame] | 1556 | return false; |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1557 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1558 | Args template_parameter_names; |
| 1559 | for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); |
| 1560 | die != NULL; |
| 1561 | die = die->GetSibling()) |
| 1562 | { |
| 1563 | const dw_tag_t tag = die->Tag(); |
| 1564 | |
| 1565 | switch (tag) |
| 1566 | { |
| 1567 | case DW_TAG_template_type_parameter: |
| 1568 | case DW_TAG_template_value_parameter: |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1569 | ParseTemplateDIE (dwarf_cu, die, template_param_infos); |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1570 | break; |
| 1571 | |
| 1572 | default: |
| 1573 | break; |
| 1574 | } |
| 1575 | } |
| 1576 | if (template_param_infos.args.empty()) |
| 1577 | return false; |
| 1578 | return template_param_infos.args.size() == template_param_infos.names.size(); |
| 1579 | } |
| 1580 | |
| 1581 | clang::ClassTemplateDecl * |
| 1582 | SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx, |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1583 | lldb::AccessType access_type, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1584 | const char *parent_name, |
| 1585 | int tag_decl_kind, |
| 1586 | const ClangASTContext::TemplateParameterInfos &template_param_infos) |
| 1587 | { |
| 1588 | if (template_param_infos.IsValid()) |
| 1589 | { |
| 1590 | std::string template_basename(parent_name); |
| 1591 | template_basename.erase (template_basename.find('<')); |
| 1592 | ClangASTContext &ast = GetClangASTContext(); |
| 1593 | |
| 1594 | return ast.CreateClassTemplateDecl (decl_ctx, |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1595 | access_type, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1596 | template_basename.c_str(), |
| 1597 | tag_decl_kind, |
| 1598 | template_param_infos); |
| 1599 | } |
| 1600 | return NULL; |
| 1601 | } |
| 1602 | |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1603 | class SymbolFileDWARF::DelayedAddObjCClassProperty |
| 1604 | { |
| 1605 | public: |
| 1606 | DelayedAddObjCClassProperty |
| 1607 | ( |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1608 | const ClangASTType &class_opaque_type, |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1609 | const char *property_name, |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1610 | const ClangASTType &property_opaque_type, // The property type is only required if you don't have an ivar decl |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1611 | clang::ObjCIvarDecl *ivar_decl, |
| 1612 | const char *property_setter_name, |
| 1613 | const char *property_getter_name, |
| 1614 | uint32_t property_attributes, |
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1615 | const ClangASTMetadata *metadata |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1616 | ) : |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1617 | m_class_opaque_type (class_opaque_type), |
| 1618 | m_property_name (property_name), |
| 1619 | m_property_opaque_type (property_opaque_type), |
| 1620 | m_ivar_decl (ivar_decl), |
| 1621 | m_property_setter_name (property_setter_name), |
| 1622 | m_property_getter_name (property_getter_name), |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1623 | m_property_attributes (property_attributes) |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1624 | { |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1625 | if (metadata != NULL) |
| 1626 | { |
| 1627 | m_metadata_ap.reset(new ClangASTMetadata()); |
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1628 | *m_metadata_ap = *metadata; |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1629 | } |
| 1630 | } |
| 1631 | |
| 1632 | DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs) |
| 1633 | { |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1634 | *this = rhs; |
| Daniel Malea | d4c5be6 | 2012-11-12 21:02:14 +0000 | [diff] [blame] | 1635 | } |
| 1636 | |
| 1637 | DelayedAddObjCClassProperty& operator= (const DelayedAddObjCClassProperty &rhs) |
| 1638 | { |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1639 | m_class_opaque_type = rhs.m_class_opaque_type; |
| 1640 | m_property_name = rhs.m_property_name; |
| 1641 | m_property_opaque_type = rhs.m_property_opaque_type; |
| 1642 | m_ivar_decl = rhs.m_ivar_decl; |
| 1643 | m_property_setter_name = rhs.m_property_setter_name; |
| 1644 | m_property_getter_name = rhs.m_property_getter_name; |
| 1645 | m_property_attributes = rhs.m_property_attributes; |
| 1646 | |
| 1647 | if (rhs.m_metadata_ap.get()) |
| 1648 | { |
| 1649 | m_metadata_ap.reset (new ClangASTMetadata()); |
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1650 | *m_metadata_ap = *rhs.m_metadata_ap; |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1651 | } |
| Daniel Malea | d4c5be6 | 2012-11-12 21:02:14 +0000 | [diff] [blame] | 1652 | return *this; |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1653 | } |
| 1654 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1655 | bool |
| 1656 | Finalize() |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1657 | { |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1658 | return m_class_opaque_type.AddObjCClassProperty (m_property_name, |
| 1659 | m_property_opaque_type, |
| 1660 | m_ivar_decl, |
| 1661 | m_property_setter_name, |
| 1662 | m_property_getter_name, |
| 1663 | m_property_attributes, |
| 1664 | m_metadata_ap.get()); |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1665 | } |
| 1666 | private: |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1667 | ClangASTType m_class_opaque_type; |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1668 | const char *m_property_name; |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1669 | ClangASTType m_property_opaque_type; |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1670 | clang::ObjCIvarDecl *m_ivar_decl; |
| 1671 | const char *m_property_setter_name; |
| 1672 | const char *m_property_getter_name; |
| 1673 | uint32_t m_property_attributes; |
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1674 | std::unique_ptr<ClangASTMetadata> m_metadata_ap; |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1675 | }; |
| 1676 | |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1677 | struct BitfieldInfo |
| 1678 | { |
| 1679 | uint64_t bit_size; |
| 1680 | uint64_t bit_offset; |
| 1681 | |
| 1682 | BitfieldInfo () : |
| 1683 | bit_size (LLDB_INVALID_ADDRESS), |
| 1684 | bit_offset (LLDB_INVALID_ADDRESS) |
| 1685 | { |
| 1686 | } |
| 1687 | |
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 1688 | void |
| 1689 | Clear() |
| 1690 | { |
| 1691 | bit_size = LLDB_INVALID_ADDRESS; |
| 1692 | bit_offset = LLDB_INVALID_ADDRESS; |
| 1693 | } |
| 1694 | |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1695 | bool IsValid () |
| 1696 | { |
| 1697 | return (bit_size != LLDB_INVALID_ADDRESS) && |
| 1698 | (bit_offset != LLDB_INVALID_ADDRESS); |
| 1699 | } |
| 1700 | }; |
| 1701 | |
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1702 | |
| 1703 | bool |
| 1704 | SymbolFileDWARF::ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu, |
| 1705 | const DWARFDebugInfoEntry *parent_die) |
| 1706 | { |
| 1707 | if (parent_die) |
| 1708 | { |
| 1709 | for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 1710 | { |
| 1711 | dw_tag_t tag = die->Tag(); |
| 1712 | bool check_virtuality = false; |
| 1713 | switch (tag) |
| 1714 | { |
| 1715 | case DW_TAG_inheritance: |
| 1716 | case DW_TAG_subprogram: |
| 1717 | check_virtuality = true; |
| 1718 | break; |
| 1719 | default: |
| 1720 | break; |
| 1721 | } |
| 1722 | if (check_virtuality) |
| 1723 | { |
| 1724 | if (die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_virtuality, 0) != 0) |
| 1725 | return true; |
| 1726 | } |
| 1727 | } |
| 1728 | } |
| 1729 | return false; |
| 1730 | } |
| 1731 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1732 | size_t |
| 1733 | SymbolFileDWARF::ParseChildMembers |
| 1734 | ( |
| 1735 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1736 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1737 | const DWARFDebugInfoEntry *parent_die, |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1738 | ClangASTType &class_clang_type, |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1739 | const LanguageType class_language, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1740 | std::vector<clang::CXXBaseSpecifier *>& base_classes, |
| 1741 | std::vector<int>& member_accessibilities, |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1742 | DWARFDIECollection& member_function_dies, |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1743 | DelayedPropertyList& delayed_properties, |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1744 | AccessType& default_accessibility, |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1745 | bool &is_a_class, |
| 1746 | LayoutInfo &layout_info |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1747 | ) |
| 1748 | { |
| 1749 | if (parent_die == NULL) |
| 1750 | return 0; |
| 1751 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1752 | size_t count = 0; |
| 1753 | const DWARFDebugInfoEntry *die; |
| Todd Fiala | ee8bfc6 | 2014-09-11 17:29:12 +0000 | [diff] [blame] | 1754 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64()); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1755 | uint32_t member_idx = 0; |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1756 | BitfieldInfo last_field_info; |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 1757 | ModuleSP module = GetObjectFile()->GetModule(); |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 1758 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1759 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 1760 | { |
| 1761 | dw_tag_t tag = die->Tag(); |
| 1762 | |
| 1763 | switch (tag) |
| 1764 | { |
| 1765 | case DW_TAG_member: |
| Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1766 | case DW_TAG_APPLE_property: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1767 | { |
| 1768 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1769 | const size_t num_attributes = die->GetAttributes (this, |
| 1770 | dwarf_cu, |
| 1771 | fixed_form_sizes, |
| 1772 | attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1773 | if (num_attributes > 0) |
| 1774 | { |
| 1775 | Declaration decl; |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1776 | //DWARFExpression location; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1777 | const char *name = NULL; |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1778 | const char *prop_name = NULL; |
| 1779 | const char *prop_getter_name = NULL; |
| 1780 | const char *prop_setter_name = NULL; |
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1781 | uint32_t prop_attributes = 0; |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1782 | |
| 1783 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1784 | bool is_artificial = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1785 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1786 | AccessType accessibility = eAccessNone; |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1787 | uint32_t member_byte_offset = UINT32_MAX; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1788 | size_t byte_size = 0; |
| 1789 | size_t bit_offset = 0; |
| 1790 | size_t bit_size = 0; |
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1791 | bool is_external = false; // On DW_TAG_members, this means the member is static |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1792 | uint32_t i; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1793 | for (i=0; i<num_attributes && !is_artificial; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1794 | { |
| 1795 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 1796 | DWARFFormValue form_value; |
| 1797 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1798 | { |
| 1799 | switch (attr) |
| 1800 | { |
| 1801 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 1802 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 1803 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 1804 | case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 1805 | case DW_AT_type: encoding_uid = form_value.Reference(); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1806 | case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break; |
| 1807 | case DW_AT_bit_size: bit_size = form_value.Unsigned(); break; |
| 1808 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; |
| 1809 | case DW_AT_data_member_location: |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1810 | if (form_value.BlockData()) |
| 1811 | { |
| 1812 | Value initialValue(0); |
| 1813 | Value memberOffset(0); |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 1814 | const DWARFDataExtractor& debug_info_data = get_debug_info_data(); |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1815 | uint32_t block_length = form_value.Unsigned(); |
| 1816 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 1817 | if (DWARFExpression::Evaluate(NULL, // ExecutionContext * |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1818 | NULL, // ClangExpressionVariableList * |
| 1819 | NULL, // ClangExpressionDeclMap * |
| 1820 | NULL, // RegisterContext * |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 1821 | module, |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1822 | debug_info_data, |
| 1823 | block_offset, |
| 1824 | block_length, |
| 1825 | eRegisterKindDWARF, |
| 1826 | &initialValue, |
| 1827 | memberOffset, |
| 1828 | NULL)) |
| 1829 | { |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1830 | member_byte_offset = memberOffset.ResolveValue(NULL).UInt(); |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1831 | } |
| 1832 | } |
| Ashok Thirumurthi | a4658a5 | 2013-07-30 14:58:39 +0000 | [diff] [blame] | 1833 | else |
| 1834 | { |
| 1835 | // With DWARF 3 and later, if the value is an integer constant, |
| 1836 | // this form value is the offset in bytes from the beginning |
| 1837 | // of the containing entity. |
| 1838 | member_byte_offset = form_value.Unsigned(); |
| 1839 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1840 | break; |
| 1841 | |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1842 | case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break; |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 1843 | case DW_AT_artificial: is_artificial = form_value.Boolean(); break; |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1844 | case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break; |
| 1845 | case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break; |
| 1846 | case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break; |
| 1847 | case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break; |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 1848 | case DW_AT_external: is_external = form_value.Boolean(); break; |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1849 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1850 | default: |
| Greg Clayton | 1b02c17 | 2012-03-14 21:00:47 +0000 | [diff] [blame] | 1851 | case DW_AT_declaration: |
| 1852 | case DW_AT_description: |
| 1853 | case DW_AT_mutable: |
| 1854 | case DW_AT_visibility: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1855 | case DW_AT_sibling: |
| 1856 | break; |
| 1857 | } |
| 1858 | } |
| 1859 | } |
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1860 | |
| 1861 | if (prop_name) |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1862 | { |
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1863 | ConstString fixed_getter; |
| 1864 | ConstString fixed_setter; |
| 1865 | |
| 1866 | // Check if the property getter/setter were provided as full |
| 1867 | // names. We want basenames, so we extract them. |
| 1868 | |
| 1869 | if (prop_getter_name && prop_getter_name[0] == '-') |
| 1870 | { |
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 1871 | ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true); |
| 1872 | prop_getter_name = prop_getter_method.GetSelector().GetCString(); |
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1873 | } |
| 1874 | |
| 1875 | if (prop_setter_name && prop_setter_name[0] == '-') |
| 1876 | { |
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 1877 | ObjCLanguageRuntime::MethodName prop_setter_method(prop_setter_name, true); |
| 1878 | prop_setter_name = prop_setter_method.GetSelector().GetCString(); |
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1879 | } |
| 1880 | |
| 1881 | // If the names haven't been provided, they need to be |
| 1882 | // filled in. |
| 1883 | |
| 1884 | if (!prop_getter_name) |
| 1885 | { |
| 1886 | prop_getter_name = prop_name; |
| 1887 | } |
| 1888 | if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly)) |
| 1889 | { |
| 1890 | StreamString ss; |
| 1891 | |
| 1892 | ss.Printf("set%c%s:", |
| 1893 | toupper(prop_name[0]), |
| 1894 | &prop_name[1]); |
| 1895 | |
| 1896 | fixed_setter.SetCString(ss.GetData()); |
| 1897 | prop_setter_name = fixed_setter.GetCString(); |
| 1898 | } |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1899 | } |
| 1900 | |
| 1901 | // Clang has a DWARF generation bug where sometimes it |
| Greg Clayton | 4495393 | 2011-10-25 01:25:35 +0000 | [diff] [blame] | 1902 | // represents fields that are references with bad byte size |
| 1903 | // and bit size/offset information such as: |
| 1904 | // |
| 1905 | // DW_AT_byte_size( 0x00 ) |
| 1906 | // DW_AT_bit_size( 0x40 ) |
| 1907 | // DW_AT_bit_offset( 0xffffffffffffffc0 ) |
| 1908 | // |
| 1909 | // So check the bit offset to make sure it is sane, and if |
| 1910 | // the values are not sane, remove them. If we don't do this |
| 1911 | // then we will end up with a crash if we try to use this |
| 1912 | // type in an expression when clang becomes unhappy with its |
| 1913 | // recycled debug info. |
| Sean Callanan | 5a477cf | 2010-10-30 01:56:10 +0000 | [diff] [blame] | 1914 | |
| Greg Clayton | 4495393 | 2011-10-25 01:25:35 +0000 | [diff] [blame] | 1915 | if (bit_offset > 128) |
| 1916 | { |
| 1917 | bit_size = 0; |
| 1918 | bit_offset = 0; |
| 1919 | } |
| 1920 | |
| 1921 | // FIXME: Make Clang ignore Objective-C accessibility for expressions |
| Sean Callanan | 5a477cf | 2010-10-30 01:56:10 +0000 | [diff] [blame] | 1922 | if (class_language == eLanguageTypeObjC || |
| 1923 | class_language == eLanguageTypeObjC_plus_plus) |
| 1924 | accessibility = eAccessNone; |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1925 | |
| 1926 | if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name)) |
| 1927 | { |
| 1928 | // Not all compilers will mark the vtable pointer |
| 1929 | // member as artificial (llvm-gcc). We can't have |
| 1930 | // the virtual members in our classes otherwise it |
| 1931 | // throws off all child offsets since we end up |
| 1932 | // having and extra pointer sized member in our |
| 1933 | // class layouts. |
| 1934 | is_artificial = true; |
| 1935 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1936 | |
| Greg Clayton | 2965971 | 2013-07-12 20:08:35 +0000 | [diff] [blame] | 1937 | // Handle static members |
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1938 | if (is_external && member_byte_offset == UINT32_MAX) |
| Greg Clayton | 973b6c9 | 2013-04-11 16:57:51 +0000 | [diff] [blame] | 1939 | { |
| 1940 | Type *var_type = ResolveTypeUID(encoding_uid); |
| 1941 | |
| 1942 | if (var_type) |
| 1943 | { |
| Greg Clayton | 2965971 | 2013-07-12 20:08:35 +0000 | [diff] [blame] | 1944 | if (accessibility == eAccessNone) |
| 1945 | accessibility = eAccessPublic; |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1946 | class_clang_type.AddVariableToRecordType (name, |
| 1947 | var_type->GetClangLayoutType(), |
| 1948 | accessibility); |
| Greg Clayton | 973b6c9 | 2013-04-11 16:57:51 +0000 | [diff] [blame] | 1949 | } |
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1950 | break; |
| Greg Clayton | 973b6c9 | 2013-04-11 16:57:51 +0000 | [diff] [blame] | 1951 | } |
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1952 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1953 | if (is_artificial == false) |
| 1954 | { |
| 1955 | Type *member_type = ResolveTypeUID(encoding_uid); |
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 1956 | |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1957 | clang::FieldDecl *field_decl = NULL; |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1958 | if (tag == DW_TAG_member) |
| Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1959 | { |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1960 | if (member_type) |
| 1961 | { |
| 1962 | if (accessibility == eAccessNone) |
| 1963 | accessibility = default_accessibility; |
| 1964 | member_accessibilities.push_back(accessibility); |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1965 | |
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 1966 | uint64_t field_bit_offset = (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8)); |
| 1967 | if (bit_size > 0) |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1968 | { |
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 1969 | |
| 1970 | BitfieldInfo this_field_info; |
| 1971 | this_field_info.bit_offset = field_bit_offset; |
| 1972 | this_field_info.bit_size = bit_size; |
| 1973 | |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1974 | ///////////////////////////////////////////////////////////// |
| 1975 | // How to locate a field given the DWARF debug information |
| 1976 | // |
| 1977 | // AT_byte_size indicates the size of the word in which the |
| 1978 | // bit offset must be interpreted. |
| 1979 | // |
| 1980 | // AT_data_member_location indicates the byte offset of the |
| 1981 | // word from the base address of the structure. |
| 1982 | // |
| 1983 | // AT_bit_offset indicates how many bits into the word |
| 1984 | // (according to the host endianness) the low-order bit of |
| 1985 | // the field starts. AT_bit_offset can be negative. |
| 1986 | // |
| 1987 | // AT_bit_size indicates the size of the field in bits. |
| 1988 | ///////////////////////////////////////////////////////////// |
| 1989 | |
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 1990 | if (byte_size == 0) |
| 1991 | byte_size = member_type->GetByteSize(); |
| 1992 | |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1993 | if (GetObjectFile()->GetByteOrder() == eByteOrderLittle) |
| 1994 | { |
| 1995 | this_field_info.bit_offset += byte_size * 8; |
| 1996 | this_field_info.bit_offset -= (bit_offset + bit_size); |
| 1997 | } |
| 1998 | else |
| 1999 | { |
| 2000 | this_field_info.bit_offset += bit_offset; |
| 2001 | } |
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 2002 | |
| 2003 | // Update the field bit offset we will report for layout |
| 2004 | field_bit_offset = this_field_info.bit_offset; |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2005 | |
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 2006 | // If the member to be emitted did not start on a character boundary and there is |
| 2007 | // empty space between the last field and this one, then we need to emit an |
| 2008 | // anonymous member filling up the space up to its start. There are three cases |
| 2009 | // here: |
| 2010 | // |
| 2011 | // 1 If the previous member ended on a character boundary, then we can emit an |
| 2012 | // anonymous member starting at the most recent character boundary. |
| 2013 | // |
| 2014 | // 2 If the previous member did not end on a character boundary and the distance |
| 2015 | // from the end of the previous member to the current member is less than a |
| 2016 | // word width, then we can emit an anonymous member starting right after the |
| 2017 | // previous member and right before this member. |
| 2018 | // |
| 2019 | // 3 If the previous member did not end on a character boundary and the distance |
| 2020 | // from the end of the previous member to the current member is greater than |
| 2021 | // or equal a word width, then we act as in Case 1. |
| 2022 | |
| 2023 | const uint64_t character_width = 8; |
| 2024 | const uint64_t word_width = 32; |
| 2025 | |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2026 | // Objective-C has invalid DW_AT_bit_offset values in older versions |
| Bruce Mitchener | aaa0ba3 | 2014-07-08 18:05:41 +0000 | [diff] [blame] | 2027 | // of clang, so we have to be careful and only insert unnamed bitfields |
| Greg Clayton | 37c36e4 | 2012-11-27 00:59:26 +0000 | [diff] [blame] | 2028 | // if we have a new enough clang. |
| 2029 | bool detect_unnamed_bitfields = true; |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2030 | |
| Greg Clayton | 37c36e4 | 2012-11-27 00:59:26 +0000 | [diff] [blame] | 2031 | if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus) |
| 2032 | detect_unnamed_bitfields = dwarf_cu->Supports_unnamed_objc_bitfields (); |
| 2033 | |
| 2034 | if (detect_unnamed_bitfields) |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2035 | { |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2036 | BitfieldInfo anon_field_info; |
| 2037 | |
| 2038 | if ((this_field_info.bit_offset % character_width) != 0) // not char aligned |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2039 | { |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2040 | uint64_t last_field_end = 0; |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2041 | |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2042 | if (last_field_info.IsValid()) |
| 2043 | last_field_end = last_field_info.bit_offset + last_field_info.bit_size; |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2044 | |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2045 | if (this_field_info.bit_offset != last_field_end) |
| 2046 | { |
| 2047 | if (((last_field_end % character_width) == 0) || // case 1 |
| 2048 | (this_field_info.bit_offset - last_field_end >= word_width)) // case 3 |
| 2049 | { |
| 2050 | anon_field_info.bit_size = this_field_info.bit_offset % character_width; |
| 2051 | anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size; |
| 2052 | } |
| 2053 | else // case 2 |
| 2054 | { |
| 2055 | anon_field_info.bit_size = this_field_info.bit_offset - last_field_end; |
| 2056 | anon_field_info.bit_offset = last_field_end; |
| 2057 | } |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2058 | } |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2059 | } |
| 2060 | |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2061 | if (anon_field_info.IsValid()) |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2062 | { |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2063 | clang::FieldDecl *unnamed_bitfield_decl = class_clang_type.AddFieldToRecordType (NULL, |
| 2064 | GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width), |
| 2065 | accessibility, |
| 2066 | anon_field_info.bit_size); |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2067 | |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2068 | layout_info.field_offsets.insert(std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset)); |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2069 | } |
| 2070 | } |
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 2071 | last_field_info = this_field_info; |
| 2072 | } |
| 2073 | else |
| 2074 | { |
| 2075 | last_field_info.Clear(); |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2076 | } |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2077 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2078 | ClangASTType member_clang_type = member_type->GetClangLayoutType(); |
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 2079 | |
| 2080 | { |
| 2081 | // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>). |
| 2082 | // If the current field is at the end of the structure, then there is definitely no room for extra |
| 2083 | // elements and we override the type to array[0]. |
| 2084 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2085 | ClangASTType member_array_element_type; |
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 2086 | uint64_t member_array_size; |
| 2087 | bool member_array_is_incomplete; |
| 2088 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2089 | if (member_clang_type.IsArrayType(&member_array_element_type, |
| 2090 | &member_array_size, |
| 2091 | &member_array_is_incomplete) && |
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 2092 | !member_array_is_incomplete) |
| 2093 | { |
| 2094 | uint64_t parent_byte_size = parent_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, UINT64_MAX); |
| 2095 | |
| 2096 | if (member_byte_offset >= parent_byte_size) |
| 2097 | { |
| 2098 | if (member_array_size != 1) |
| 2099 | { |
| 2100 | GetObjectFile()->GetModule()->ReportError ("0x%8.8" PRIx64 ": DW_TAG_member '%s' refers to type 0x%8.8" PRIx64 " which extends beyond the bounds of 0x%8.8" PRIx64, |
| 2101 | MakeUserID(die->GetOffset()), |
| 2102 | name, |
| 2103 | encoding_uid, |
| 2104 | MakeUserID(parent_die->GetOffset())); |
| 2105 | } |
| 2106 | |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 2107 | member_clang_type = GetClangASTContext().CreateArrayType(member_array_element_type, 0, false); |
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 2108 | } |
| 2109 | } |
| 2110 | } |
| 2111 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2112 | field_decl = class_clang_type.AddFieldToRecordType (name, |
| 2113 | member_clang_type, |
| 2114 | accessibility, |
| 2115 | bit_size); |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2116 | |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 2117 | GetClangASTContext().SetMetadataAsUserID (field_decl, MakeUserID(die->GetOffset())); |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2118 | |
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 2119 | layout_info.field_offsets.insert(std::make_pair(field_decl, field_bit_offset)); |
| 2120 | |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2121 | } |
| 2122 | else |
| 2123 | { |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 2124 | if (name) |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2125 | GetObjectFile()->GetModule()->ReportError ("0x%8.8" PRIx64 ": DW_TAG_member '%s' refers to type 0x%8.8" PRIx64 " which was unable to be parsed", |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 2126 | MakeUserID(die->GetOffset()), |
| 2127 | name, |
| 2128 | encoding_uid); |
| 2129 | else |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2130 | GetObjectFile()->GetModule()->ReportError ("0x%8.8" PRIx64 ": DW_TAG_member refers to type 0x%8.8" PRIx64 " which was unable to be parsed", |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 2131 | MakeUserID(die->GetOffset()), |
| 2132 | encoding_uid); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2133 | } |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2134 | } |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 2135 | |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2136 | if (prop_name != NULL) |
| 2137 | { |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 2138 | clang::ObjCIvarDecl *ivar_decl = NULL; |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2139 | |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 2140 | if (field_decl) |
| 2141 | { |
| 2142 | ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl); |
| 2143 | assert (ivar_decl != NULL); |
| 2144 | } |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2145 | |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 2146 | ClangASTMetadata metadata; |
| 2147 | metadata.SetUserID (MakeUserID(die->GetOffset())); |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2148 | delayed_properties.push_back(DelayedAddObjCClassProperty(class_clang_type, |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2149 | prop_name, |
| 2150 | member_type->GetClangLayoutType(), |
| 2151 | ivar_decl, |
| 2152 | prop_setter_name, |
| 2153 | prop_getter_name, |
| 2154 | prop_attributes, |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 2155 | &metadata)); |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2156 | |
| Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 2157 | if (ivar_decl) |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 2158 | GetClangASTContext().SetMetadataAsUserID (ivar_decl, MakeUserID(die->GetOffset())); |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2159 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2160 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2161 | } |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2162 | ++member_idx; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2163 | } |
| 2164 | break; |
| 2165 | |
| 2166 | case DW_TAG_subprogram: |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2167 | // Let the type parsing code handle this one for us. |
| 2168 | member_function_dies.Append (die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2169 | break; |
| 2170 | |
| 2171 | case DW_TAG_inheritance: |
| 2172 | { |
| 2173 | is_a_class = true; |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 2174 | if (default_accessibility == eAccessNone) |
| 2175 | default_accessibility = eAccessPrivate; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2176 | // TODO: implement DW_TAG_inheritance type parsing |
| 2177 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 2178 | const size_t num_attributes = die->GetAttributes (this, |
| 2179 | dwarf_cu, |
| 2180 | fixed_form_sizes, |
| 2181 | attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2182 | if (num_attributes > 0) |
| 2183 | { |
| 2184 | Declaration decl; |
| 2185 | DWARFExpression location; |
| 2186 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 2187 | AccessType accessibility = default_accessibility; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2188 | bool is_virtual = false; |
| 2189 | bool is_base_of_class = true; |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2190 | off_t member_byte_offset = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2191 | uint32_t i; |
| 2192 | for (i=0; i<num_attributes; ++i) |
| 2193 | { |
| 2194 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 2195 | DWARFFormValue form_value; |
| 2196 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 2197 | { |
| 2198 | switch (attr) |
| 2199 | { |
| 2200 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 2201 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 2202 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 2203 | case DW_AT_type: encoding_uid = form_value.Reference(); break; |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2204 | case DW_AT_data_member_location: |
| 2205 | if (form_value.BlockData()) |
| 2206 | { |
| 2207 | Value initialValue(0); |
| 2208 | Value memberOffset(0); |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 2209 | const DWARFDataExtractor& debug_info_data = get_debug_info_data(); |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2210 | uint32_t block_length = form_value.Unsigned(); |
| 2211 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 2212 | if (DWARFExpression::Evaluate (NULL, |
| 2213 | NULL, |
| 2214 | NULL, |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2215 | NULL, |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 2216 | module, |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2217 | debug_info_data, |
| 2218 | block_offset, |
| 2219 | block_length, |
| 2220 | eRegisterKindDWARF, |
| 2221 | &initialValue, |
| 2222 | memberOffset, |
| 2223 | NULL)) |
| 2224 | { |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2225 | member_byte_offset = memberOffset.ResolveValue(NULL).UInt(); |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2226 | } |
| 2227 | } |
| Ashok Thirumurthi | a4658a5 | 2013-07-30 14:58:39 +0000 | [diff] [blame] | 2228 | else |
| 2229 | { |
| 2230 | // With DWARF 3 and later, if the value is an integer constant, |
| 2231 | // this form value is the offset in bytes from the beginning |
| 2232 | // of the containing entity. |
| 2233 | member_byte_offset = form_value.Unsigned(); |
| 2234 | } |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2235 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2236 | |
| 2237 | case DW_AT_accessibility: |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 2238 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2239 | break; |
| 2240 | |
| Ashok Thirumurthi | a4658a5 | 2013-07-30 14:58:39 +0000 | [diff] [blame] | 2241 | case DW_AT_virtuality: |
| 2242 | is_virtual = form_value.Boolean(); |
| 2243 | break; |
| 2244 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2245 | case DW_AT_sibling: |
| 2246 | break; |
| Ashok Thirumurthi | a4658a5 | 2013-07-30 14:58:39 +0000 | [diff] [blame] | 2247 | |
| 2248 | default: |
| 2249 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2250 | } |
| 2251 | } |
| 2252 | } |
| 2253 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 2254 | Type *base_class_type = ResolveTypeUID(encoding_uid); |
| 2255 | assert(base_class_type); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2256 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2257 | ClangASTType base_class_clang_type = base_class_type->GetClangFullType(); |
| Greg Clayton | f4ecaa5 | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 2258 | assert (base_class_clang_type); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2259 | if (class_language == eLanguageTypeObjC) |
| 2260 | { |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2261 | class_clang_type.SetObjCSuperClass(base_class_clang_type); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2262 | } |
| 2263 | else |
| 2264 | { |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2265 | base_classes.push_back (base_class_clang_type.CreateBaseClassSpecifier (accessibility, |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 2266 | is_virtual, |
| 2267 | is_base_of_class)); |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2268 | |
| 2269 | if (is_virtual) |
| 2270 | { |
| Greg Clayton | 52694e3 | 2013-09-16 21:57:07 +0000 | [diff] [blame] | 2271 | // Do not specify any offset for virtual inheritance. The DWARF produced by clang doesn't |
| 2272 | // give us a constant offset, but gives us a DWARF expressions that requires an actual object |
| 2273 | // in memory. the DW_AT_data_member_location for a virtual base class looks like: |
| 2274 | // DW_AT_data_member_location( DW_OP_dup, DW_OP_deref, DW_OP_constu(0x00000018), DW_OP_minus, DW_OP_deref, DW_OP_plus ) |
| 2275 | // Given this, there is really no valid response we can give to clang for virtual base |
| 2276 | // class offsets, and this should eventually be removed from LayoutRecordType() in the external |
| 2277 | // AST source in clang. |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2278 | } |
| 2279 | else |
| 2280 | { |
| Greg Clayton | 5764873 | 2013-09-12 17:22:32 +0000 | [diff] [blame] | 2281 | layout_info.base_offsets.insert(std::make_pair(base_class_clang_type.GetAsCXXRecordDecl(), |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2282 | clang::CharUnits::fromQuantity(member_byte_offset))); |
| 2283 | } |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2284 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2285 | } |
| 2286 | } |
| 2287 | break; |
| 2288 | |
| 2289 | default: |
| 2290 | break; |
| 2291 | } |
| 2292 | } |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2293 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2294 | return count; |
| 2295 | } |
| 2296 | |
| 2297 | |
| 2298 | clang::DeclContext* |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 2299 | SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2300 | { |
| 2301 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2302 | if (debug_info && UserIDMatches(type_uid)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2303 | { |
| 2304 | DWARFCompileUnitSP cu_sp; |
| 2305 | const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp); |
| 2306 | if (die) |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 2307 | return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL); |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 2308 | } |
| 2309 | return NULL; |
| 2310 | } |
| 2311 | |
| 2312 | clang::DeclContext* |
| 2313 | SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid) |
| 2314 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2315 | if (UserIDMatches(type_uid)) |
| 2316 | return GetClangDeclContextForDIEOffset (sc, type_uid); |
| 2317 | return NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2318 | } |
| 2319 | |
| 2320 | Type* |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2321 | SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2322 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2323 | if (UserIDMatches(type_uid)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2324 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2325 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2326 | if (debug_info) |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2327 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2328 | DWARFCompileUnitSP cu_sp; |
| 2329 | const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp); |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2330 | const bool assert_not_being_parsed = true; |
| 2331 | return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2332 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2333 | } |
| 2334 | return NULL; |
| 2335 | } |
| 2336 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2337 | Type* |
| 2338 | SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed) |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2339 | { |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2340 | if (die != NULL) |
| 2341 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2342 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2343 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2344 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2345 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'", |
| 2346 | die->GetOffset(), |
| 2347 | DW_TAG_value_to_name(die->Tag()), |
| 2348 | die->GetName(this, cu)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2349 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2350 | // We might be coming in in the middle of a type tree (a class |
| 2351 | // withing a class, an enum within a class), so parse any needed |
| 2352 | // parent DIEs before we get to this one... |
| 2353 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); |
| 2354 | switch (decl_ctx_die->Tag()) |
| 2355 | { |
| 2356 | case DW_TAG_structure_type: |
| 2357 | case DW_TAG_union_type: |
| 2358 | case DW_TAG_class_type: |
| 2359 | { |
| 2360 | // Get the type, which could be a forward declaration |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2361 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2362 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2363 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x", |
| 2364 | die->GetOffset(), |
| 2365 | DW_TAG_value_to_name(die->Tag()), |
| 2366 | die->GetName(this, cu), |
| 2367 | decl_ctx_die->GetOffset()); |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2368 | // |
| 2369 | // Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed); |
| 2370 | // if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag())) |
| 2371 | // { |
| 2372 | // if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2373 | // GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2374 | // "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function", |
| 2375 | // die->GetOffset(), |
| 2376 | // DW_TAG_value_to_name(die->Tag()), |
| 2377 | // die->GetName(this, cu), |
| 2378 | // decl_ctx_die->GetOffset()); |
| 2379 | // // Ask the type to complete itself if it already hasn't since if we |
| 2380 | // // want a function (method or static) from a class, the class must |
| 2381 | // // create itself and add it's own methods and class functions. |
| 2382 | // if (parent_type) |
| 2383 | // parent_type->GetClangFullType(); |
| 2384 | // } |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2385 | } |
| 2386 | break; |
| 2387 | |
| 2388 | default: |
| 2389 | break; |
| 2390 | } |
| 2391 | return ResolveType (cu, die); |
| 2392 | } |
| 2393 | return NULL; |
| 2394 | } |
| 2395 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2396 | // This function is used when SymbolFileDWARFDebugMap owns a bunch of |
| 2397 | // SymbolFileDWARF objects to detect if this DWARF file is the one that |
| 2398 | // can resolve a clang_type. |
| 2399 | bool |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2400 | SymbolFileDWARF::HasForwardDeclForClangType (const ClangASTType &clang_type) |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2401 | { |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2402 | ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers(); |
| 2403 | const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType()); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2404 | return die != NULL; |
| 2405 | } |
| 2406 | |
| 2407 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2408 | bool |
| 2409 | SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (ClangASTType &clang_type) |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2410 | { |
| 2411 | // We have a struct/union/class/enum that needs to be fully resolved. |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2412 | ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers(); |
| 2413 | const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType()); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2414 | if (die == NULL) |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2415 | { |
| 2416 | // We have already resolved this type... |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2417 | return true; |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2418 | } |
| 2419 | // Once we start resolving this type, remove it from the forward declaration |
| 2420 | // map in case anyone child members or other types require this type to get resolved. |
| 2421 | // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition |
| 2422 | // are done. |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2423 | m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers.GetOpaqueQualType()); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2424 | |
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 2425 | // Disable external storage for this type so we don't get anymore |
| 2426 | // clang::ExternalASTSource queries for this type. |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2427 | clang_type.SetHasExternalStorage (false); |
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 2428 | |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2429 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2430 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2431 | DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get(); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2432 | Type *type = m_die_to_type.lookup (die); |
| 2433 | |
| 2434 | const dw_tag_t tag = die->Tag(); |
| 2435 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2436 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2437 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2438 | GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2439 | "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...", |
| Greg Clayton | d61c0fc | 2012-04-23 22:55:20 +0000 | [diff] [blame] | 2440 | MakeUserID(die->GetOffset()), |
| 2441 | DW_TAG_value_to_name(tag), |
| 2442 | type->GetName().AsCString()); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2443 | assert (clang_type); |
| 2444 | DWARFDebugInfoEntry::Attributes attributes; |
| 2445 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2446 | switch (tag) |
| 2447 | { |
| 2448 | case DW_TAG_structure_type: |
| 2449 | case DW_TAG_union_type: |
| 2450 | case DW_TAG_class_type: |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2451 | { |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2452 | LayoutInfo layout_info; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2453 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2454 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2455 | if (die->HasChildren()) |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2456 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2457 | LanguageType class_language = eLanguageTypeUnknown; |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2458 | if (clang_type.IsObjCObjectOrInterfaceType()) |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2459 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2460 | class_language = eLanguageTypeObjC; |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2461 | // For objective C we don't start the definition when |
| 2462 | // the class is created. |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2463 | clang_type.StartTagDeclarationDefinition (); |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2464 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2465 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2466 | int tag_decl_kind = -1; |
| 2467 | AccessType default_accessibility = eAccessNone; |
| 2468 | if (tag == DW_TAG_structure_type) |
| 2469 | { |
| 2470 | tag_decl_kind = clang::TTK_Struct; |
| 2471 | default_accessibility = eAccessPublic; |
| 2472 | } |
| 2473 | else if (tag == DW_TAG_union_type) |
| 2474 | { |
| 2475 | tag_decl_kind = clang::TTK_Union; |
| 2476 | default_accessibility = eAccessPublic; |
| 2477 | } |
| 2478 | else if (tag == DW_TAG_class_type) |
| 2479 | { |
| 2480 | tag_decl_kind = clang::TTK_Class; |
| 2481 | default_accessibility = eAccessPrivate; |
| 2482 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2483 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2484 | SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2485 | std::vector<clang::CXXBaseSpecifier *> base_classes; |
| 2486 | std::vector<int> member_accessibilities; |
| 2487 | bool is_a_class = false; |
| 2488 | // Parse members and base classes first |
| 2489 | DWARFDIECollection member_function_dies; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2490 | |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2491 | DelayedPropertyList delayed_properties; |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2492 | ParseChildMembers (sc, |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2493 | dwarf_cu, |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2494 | die, |
| 2495 | clang_type, |
| 2496 | class_language, |
| 2497 | base_classes, |
| 2498 | member_accessibilities, |
| 2499 | member_function_dies, |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2500 | delayed_properties, |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2501 | default_accessibility, |
| 2502 | is_a_class, |
| 2503 | layout_info); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2504 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2505 | // Now parse any methods if there were any... |
| 2506 | size_t num_functions = member_function_dies.Size(); |
| 2507 | if (num_functions > 0) |
| 2508 | { |
| 2509 | for (size_t i=0; i<num_functions; ++i) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2510 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2511 | ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i)); |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2512 | } |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2513 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2514 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2515 | if (class_language == eLanguageTypeObjC) |
| 2516 | { |
| Jim Ingham | fb6fc0d | 2013-09-27 20:59:37 +0000 | [diff] [blame] | 2517 | ConstString class_name (clang_type.GetTypeName()); |
| 2518 | if (class_name) |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2519 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2520 | DIEArray method_die_offsets; |
| 2521 | if (m_using_apple_tables) |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2522 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2523 | if (m_apple_objc_ap.get()) |
| Jim Ingham | fb6fc0d | 2013-09-27 20:59:37 +0000 | [diff] [blame] | 2524 | m_apple_objc_ap->FindByName(class_name.GetCString(), method_die_offsets); |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2525 | } |
| 2526 | else |
| 2527 | { |
| 2528 | if (!m_indexed) |
| 2529 | Index (); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2530 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2531 | m_objc_class_selectors_index.Find (class_name, method_die_offsets); |
| 2532 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2533 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2534 | if (!method_die_offsets.empty()) |
| 2535 | { |
| 2536 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2537 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2538 | DWARFCompileUnit* method_cu = NULL; |
| 2539 | const size_t num_matches = method_die_offsets.size(); |
| 2540 | for (size_t i=0; i<num_matches; ++i) |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2541 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2542 | const dw_offset_t die_offset = method_die_offsets[i]; |
| 2543 | DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2544 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2545 | if (method_die) |
| 2546 | ResolveType (method_cu, method_die); |
| 2547 | else |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2548 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2549 | if (m_using_apple_tables) |
| 2550 | { |
| 2551 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n", |
| Jim Ingham | fb6fc0d | 2013-09-27 20:59:37 +0000 | [diff] [blame] | 2552 | die_offset, class_name.GetCString()); |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2553 | } |
| 2554 | } |
| 2555 | } |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2556 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2557 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2558 | for (DelayedPropertyList::iterator pi = delayed_properties.begin(), pe = delayed_properties.end(); |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2559 | pi != pe; |
| 2560 | ++pi) |
| 2561 | pi->Finalize(); |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2562 | } |
| 2563 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2564 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2565 | // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we |
| 2566 | // need to tell the clang type it is actually a class. |
| 2567 | if (class_language != eLanguageTypeObjC) |
| 2568 | { |
| 2569 | if (is_a_class && tag_decl_kind != clang::TTK_Class) |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2570 | clang_type.SetTagTypeKind (clang::TTK_Class); |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2571 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2572 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2573 | // Since DW_TAG_structure_type gets used for both classes |
| 2574 | // and structures, we may need to set any DW_TAG_member |
| 2575 | // fields to have a "private" access if none was specified. |
| 2576 | // When we parsed the child members we tracked that actual |
| 2577 | // accessibility value for each DW_TAG_member in the |
| 2578 | // "member_accessibilities" array. If the value for the |
| 2579 | // member is zero, then it was set to the "default_accessibility" |
| 2580 | // which for structs was "public". Below we correct this |
| 2581 | // by setting any fields to "private" that weren't correctly |
| 2582 | // set. |
| 2583 | if (is_a_class && !member_accessibilities.empty()) |
| 2584 | { |
| 2585 | // This is a class and all members that didn't have |
| 2586 | // their access specified are private. |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2587 | clang_type.SetDefaultAccessForRecordFields (eAccessPrivate, |
| 2588 | &member_accessibilities.front(), |
| 2589 | member_accessibilities.size()); |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2590 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2591 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2592 | if (!base_classes.empty()) |
| 2593 | { |
| Greg Clayton | 4705f8d | 2013-12-12 01:54:04 +0000 | [diff] [blame] | 2594 | // Make sure all base classes refer to complete types and not |
| 2595 | // forward declarations. If we don't do this, clang will crash |
| 2596 | // with an assertion in the call to clang_type.SetBaseClassesForClassType() |
| 2597 | bool base_class_error = false; |
| 2598 | for (auto &base_class : base_classes) |
| 2599 | { |
| 2600 | clang::TypeSourceInfo *type_source_info = base_class->getTypeSourceInfo(); |
| 2601 | if (type_source_info) |
| 2602 | { |
| 2603 | ClangASTType base_class_type (GetClangASTContext().getASTContext(), type_source_info->getType()); |
| 2604 | if (base_class_type.GetCompleteType() == false) |
| 2605 | { |
| 2606 | if (!base_class_error) |
| 2607 | { |
| 2608 | GetObjectFile()->GetModule()->ReportError ("DWARF DIE at 0x%8.8x for class '%s' has a base class '%s' that is a forward declaration, not a complete definition.\nPlease file a bug against the compiler and include the preprocessed output for %s", |
| 2609 | die->GetOffset(), |
| 2610 | die->GetName(this, dwarf_cu), |
| 2611 | base_class_type.GetTypeName().GetCString(), |
| 2612 | sc.comp_unit ? sc.comp_unit->GetPath().c_str() : "the source file"); |
| 2613 | } |
| 2614 | // We have no choice other than to pretend that the base class |
| 2615 | // is complete. If we don't do this, clang will crash when we |
| 2616 | // call setBases() inside of "clang_type.SetBaseClassesForClassType()" |
| 2617 | // below. Since we provide layout assistance, all ivars in this |
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 2618 | // class and other classes will be fine, this is the best we can do |
| Greg Clayton | 4705f8d | 2013-12-12 01:54:04 +0000 | [diff] [blame] | 2619 | // short of crashing. |
| 2620 | base_class_type.StartTagDeclarationDefinition (); |
| 2621 | base_class_type.CompleteTagDeclarationDefinition (); |
| 2622 | } |
| 2623 | } |
| 2624 | } |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2625 | clang_type.SetBaseClassesForClassType (&base_classes.front(), |
| 2626 | base_classes.size()); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2627 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2628 | // Clang will copy each CXXBaseSpecifier in "base_classes" |
| 2629 | // so we have to free them all. |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2630 | ClangASTType::DeleteBaseClassSpecifiers (&base_classes.front(), |
| 2631 | base_classes.size()); |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2632 | } |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2633 | } |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2634 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2635 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2636 | clang_type.BuildIndirectFields (); |
| 2637 | clang_type.CompleteTagDeclarationDefinition (); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2638 | |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2639 | if (!layout_info.field_offsets.empty() || |
| 2640 | !layout_info.base_offsets.empty() || |
| 2641 | !layout_info.vbase_offsets.empty() ) |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2642 | { |
| 2643 | if (type) |
| 2644 | layout_info.bit_size = type->GetByteSize() * 8; |
| 2645 | if (layout_info.bit_size == 0) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2646 | layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2647 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2648 | clang::CXXRecordDecl *record_decl = clang_type.GetAsCXXRecordDecl(); |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2649 | if (record_decl) |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2650 | { |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2651 | if (log) |
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2652 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2653 | GetObjectFile()->GetModule()->LogMessage (log, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2654 | "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) caching layout info for record_decl = %p, bit_size = %" PRIu64 ", alignment = %" PRIu64 ", field_offsets[%u], base_offsets[%u], vbase_offsets[%u])", |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2655 | static_cast<void*>(clang_type.GetOpaqueQualType()), |
| 2656 | static_cast<void*>(record_decl), |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2657 | layout_info.bit_size, |
| 2658 | layout_info.alignment, |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2659 | static_cast<uint32_t>(layout_info.field_offsets.size()), |
| 2660 | static_cast<uint32_t>(layout_info.base_offsets.size()), |
| 2661 | static_cast<uint32_t>(layout_info.vbase_offsets.size())); |
| 2662 | |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2663 | uint32_t idx; |
| 2664 | { |
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2665 | llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end(); |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2666 | for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx) |
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2667 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2668 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2669 | "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = { bit_offset=%u, name='%s' }", |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2670 | static_cast<void*>(clang_type.GetOpaqueQualType()), |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2671 | idx, |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2672 | static_cast<uint32_t>(pos->second), |
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2673 | pos->first->getNameAsString().c_str()); |
| 2674 | } |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2675 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2676 | |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2677 | { |
| 2678 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos, base_end = layout_info.base_offsets.end(); |
| 2679 | for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end; ++base_pos, ++idx) |
| 2680 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2681 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2682 | "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] = { byte_offset=%u, name='%s' }", |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2683 | clang_type.GetOpaqueQualType(), |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2684 | idx, |
| 2685 | (uint32_t)base_pos->second.getQuantity(), |
| 2686 | base_pos->first->getNameAsString().c_str()); |
| 2687 | } |
| 2688 | } |
| 2689 | { |
| 2690 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos, vbase_end = layout_info.vbase_offsets.end(); |
| 2691 | for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end; ++vbase_pos, ++idx) |
| 2692 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2693 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2694 | "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) vbase[%u] = { byte_offset=%u, name='%s' }", |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2695 | static_cast<void*>(clang_type.GetOpaqueQualType()), |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2696 | idx, |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2697 | static_cast<uint32_t>(vbase_pos->second.getQuantity()), |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2698 | vbase_pos->first->getNameAsString().c_str()); |
| 2699 | } |
| 2700 | } |
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2701 | } |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2702 | m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info)); |
| 2703 | } |
| 2704 | } |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2705 | } |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2706 | |
| Sean Callanan | 9076c0f | 2013-10-04 21:35:29 +0000 | [diff] [blame] | 2707 | return (bool)clang_type; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2708 | |
| 2709 | case DW_TAG_enumeration_type: |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2710 | clang_type.StartTagDeclarationDefinition (); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2711 | if (die->HasChildren()) |
| 2712 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2713 | SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); |
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 2714 | bool is_signed = false; |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2715 | clang_type.IsIntegerType(is_signed); |
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 2716 | ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), dwarf_cu, die); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2717 | } |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2718 | clang_type.CompleteTagDeclarationDefinition (); |
| Sean Callanan | 9076c0f | 2013-10-04 21:35:29 +0000 | [diff] [blame] | 2719 | return (bool)clang_type; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2720 | |
| 2721 | default: |
| 2722 | assert(false && "not a forward clang type decl!"); |
| 2723 | break; |
| 2724 | } |
| Ashok Thirumurthi | a4658a5 | 2013-07-30 14:58:39 +0000 | [diff] [blame] | 2725 | return false; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2726 | } |
| 2727 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2728 | Type* |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2729 | SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed) |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2730 | { |
| 2731 | if (type_die != NULL) |
| 2732 | { |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 2733 | Type *type = m_die_to_type.lookup (type_die); |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2734 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2735 | if (type == NULL) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2736 | type = GetTypeForDIE (dwarf_cu, type_die).get(); |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2737 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2738 | if (assert_not_being_parsed) |
| Jim Ingham | c354928 | 2012-01-11 02:21:12 +0000 | [diff] [blame] | 2739 | { |
| 2740 | if (type != DIE_IS_BEING_PARSED) |
| 2741 | return type; |
| 2742 | |
| 2743 | GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s", |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2744 | type_die->GetOffset(), |
| 2745 | DW_TAG_value_to_name(type_die->Tag()), |
| 2746 | type_die->GetName(this, dwarf_cu)); |
| Jim Ingham | c354928 | 2012-01-11 02:21:12 +0000 | [diff] [blame] | 2747 | |
| 2748 | } |
| 2749 | else |
| 2750 | return type; |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2751 | } |
| 2752 | return NULL; |
| 2753 | } |
| 2754 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2755 | CompileUnit* |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2756 | SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2757 | { |
| 2758 | // Check if the symbol vendor already knows about this compile unit? |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2759 | if (dwarf_cu->GetUserData() == NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2760 | { |
| 2761 | // The symbol vendor doesn't know about this compile unit, we |
| 2762 | // need to parse and add it to the symbol vendor object. |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2763 | return ParseCompileUnit(dwarf_cu, cu_idx).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2764 | } |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2765 | return (CompileUnit*)dwarf_cu->GetUserData(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2766 | } |
| 2767 | |
| 2768 | bool |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2769 | SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2770 | { |
| Greg Clayton | 7231035 | 2013-02-23 04:12:47 +0000 | [diff] [blame] | 2771 | sc.Clear(false); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2772 | // Check if the symbol vendor already knows about this compile unit? |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2773 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2774 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2775 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2776 | if (sc.function == NULL) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2777 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2778 | |
| 2779 | if (sc.function) |
| 2780 | { |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 2781 | sc.module_sp = sc.function->CalculateSymbolContextModule(); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2782 | return true; |
| 2783 | } |
| 2784 | |
| 2785 | return false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2786 | } |
| 2787 | |
| Greg Clayton | 2501e5e | 2015-01-15 02:59:20 +0000 | [diff] [blame] | 2788 | |
| 2789 | |
| 2790 | SymbolFileDWARF::GlobalVariableMap & |
| 2791 | SymbolFileDWARF::GetGlobalAranges() |
| 2792 | { |
| 2793 | if (!m_global_aranges_ap) |
| 2794 | { |
| 2795 | m_global_aranges_ap.reset (new GlobalVariableMap()); |
| 2796 | |
| 2797 | ModuleSP module_sp = GetObjectFile()->GetModule(); |
| 2798 | if (module_sp) |
| 2799 | { |
| 2800 | const size_t num_cus = module_sp->GetNumCompileUnits(); |
| 2801 | for (size_t i = 0; i < num_cus; ++i) |
| 2802 | { |
| 2803 | CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(i); |
| 2804 | if (cu_sp) |
| 2805 | { |
| 2806 | VariableListSP globals_sp = cu_sp->GetVariableList(true); |
| 2807 | if (globals_sp) |
| 2808 | { |
| 2809 | const size_t num_globals = globals_sp->GetSize(); |
| 2810 | for (size_t g = 0; g < num_globals; ++g) |
| 2811 | { |
| 2812 | VariableSP var_sp = globals_sp->GetVariableAtIndex(g); |
| 2813 | if (var_sp && !var_sp->GetLocationIsConstantValueData()) |
| 2814 | { |
| 2815 | const DWARFExpression &location = var_sp->LocationExpression(); |
| 2816 | Value location_result; |
| 2817 | Error error; |
| 2818 | if (location.Evaluate(NULL, NULL, NULL, LLDB_INVALID_ADDRESS, NULL, location_result, &error)) |
| 2819 | { |
| 2820 | if (location_result.GetValueType() == Value::eValueTypeFileAddress) |
| 2821 | { |
| 2822 | lldb::addr_t file_addr = location_result.GetScalar().ULongLong(); |
| 2823 | lldb::addr_t byte_size = 1; |
| 2824 | if (var_sp->GetType()) |
| 2825 | byte_size = var_sp->GetType()->GetByteSize(); |
| 2826 | m_global_aranges_ap->Append(GlobalVariableMap::Entry(file_addr, byte_size, var_sp.get())); |
| 2827 | } |
| 2828 | } |
| 2829 | } |
| 2830 | } |
| 2831 | } |
| 2832 | } |
| 2833 | } |
| 2834 | } |
| 2835 | m_global_aranges_ap->Sort(); |
| 2836 | } |
| 2837 | return *m_global_aranges_ap; |
| 2838 | } |
| 2839 | |
| 2840 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2841 | uint32_t |
| 2842 | SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) |
| 2843 | { |
| 2844 | Timer scoped_timer(__PRETTY_FUNCTION__, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2845 | "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%" PRIx64 " }, resolve_scope = 0x%8.8x)", |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2846 | static_cast<void*>(so_addr.GetSection().get()), |
| 2847 | so_addr.GetOffset(), resolve_scope); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2848 | uint32_t resolved = 0; |
| Greg Clayton | 2501e5e | 2015-01-15 02:59:20 +0000 | [diff] [blame] | 2849 | if (resolve_scope & ( eSymbolContextCompUnit | |
| 2850 | eSymbolContextFunction | |
| 2851 | eSymbolContextBlock | |
| 2852 | eSymbolContextLineEntry | |
| 2853 | eSymbolContextVariable )) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2854 | { |
| 2855 | lldb::addr_t file_vm_addr = so_addr.GetFileAddress(); |
| 2856 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2857 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2858 | if (debug_info) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2859 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2860 | const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr); |
| Greg Clayton | 2501e5e | 2015-01-15 02:59:20 +0000 | [diff] [blame] | 2861 | if (cu_offset == DW_INVALID_OFFSET) |
| 2862 | { |
| 2863 | // Global variables are not in the compile unit address ranges. The only way to |
| 2864 | // currently find global variables is to iterate over the .debug_pubnames or the |
| 2865 | // __apple_names table and find all items in there that point to DW_TAG_variable |
| 2866 | // DIEs and then find the address that matches. |
| 2867 | if (resolve_scope & eSymbolContextVariable) |
| 2868 | { |
| 2869 | GlobalVariableMap &map = GetGlobalAranges(); |
| 2870 | const GlobalVariableMap::Entry *entry = map.FindEntryThatContains(file_vm_addr); |
| 2871 | if (entry && entry->data) |
| 2872 | { |
| 2873 | Variable *variable = entry->data; |
| 2874 | SymbolContextScope *scc = variable->GetSymbolContextScope(); |
| 2875 | if (scc) |
| 2876 | { |
| 2877 | scc->CalculateSymbolContext(&sc); |
| 2878 | sc.variable = variable; |
| 2879 | } |
| 2880 | return sc.GetResolvedMask(); |
| 2881 | } |
| 2882 | } |
| 2883 | } |
| 2884 | else |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2885 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2886 | uint32_t cu_idx = DW_INVALID_INDEX; |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2887 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get(); |
| 2888 | if (dwarf_cu) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2889 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2890 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2891 | if (sc.comp_unit) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2892 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2893 | resolved |= eSymbolContextCompUnit; |
| 2894 | |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2895 | bool force_check_line_table = false; |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2896 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) |
| 2897 | { |
| 2898 | DWARFDebugInfoEntry *function_die = NULL; |
| 2899 | DWARFDebugInfoEntry *block_die = NULL; |
| 2900 | if (resolve_scope & eSymbolContextBlock) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2901 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2902 | dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die); |
| 2903 | } |
| 2904 | else |
| 2905 | { |
| 2906 | dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL); |
| 2907 | } |
| 2908 | |
| 2909 | if (function_die != NULL) |
| 2910 | { |
| 2911 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); |
| 2912 | if (sc.function == NULL) |
| 2913 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die); |
| 2914 | } |
| 2915 | else |
| 2916 | { |
| 2917 | // We might have had a compile unit that had discontiguous |
| 2918 | // address ranges where the gaps are symbols that don't have |
| 2919 | // any debug info. Discontiguous compile unit address ranges |
| 2920 | // should only happen when there aren't other functions from |
| 2921 | // other compile units in these gaps. This helps keep the size |
| 2922 | // of the aranges down. |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2923 | force_check_line_table = true; |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2924 | } |
| 2925 | |
| 2926 | if (sc.function != NULL) |
| 2927 | { |
| 2928 | resolved |= eSymbolContextFunction; |
| 2929 | |
| 2930 | if (resolve_scope & eSymbolContextBlock) |
| 2931 | { |
| 2932 | Block& block = sc.function->GetBlock (true); |
| 2933 | |
| 2934 | if (block_die != NULL) |
| 2935 | sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); |
| 2936 | else |
| 2937 | sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); |
| 2938 | if (sc.block) |
| 2939 | resolved |= eSymbolContextBlock; |
| 2940 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2941 | } |
| 2942 | } |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2943 | |
| 2944 | if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table) |
| 2945 | { |
| 2946 | LineTable *line_table = sc.comp_unit->GetLineTable(); |
| 2947 | if (line_table != NULL) |
| 2948 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 2949 | // And address that makes it into this function should be in terms |
| 2950 | // of this debug file if there is no debug map, or it will be an |
| 2951 | // address in the .o file which needs to be fixed up to be in terms |
| 2952 | // of the debug map executable. Either way, calling FixupAddress() |
| 2953 | // will work for us. |
| 2954 | Address exe_so_addr (so_addr); |
| 2955 | if (FixupAddress(exe_so_addr)) |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2956 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 2957 | if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry)) |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2958 | { |
| 2959 | resolved |= eSymbolContextLineEntry; |
| 2960 | } |
| 2961 | } |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2962 | } |
| 2963 | } |
| 2964 | |
| 2965 | if (force_check_line_table && !(resolved & eSymbolContextLineEntry)) |
| 2966 | { |
| 2967 | // We might have had a compile unit that had discontiguous |
| 2968 | // address ranges where the gaps are symbols that don't have |
| 2969 | // any debug info. Discontiguous compile unit address ranges |
| 2970 | // should only happen when there aren't other functions from |
| 2971 | // other compile units in these gaps. This helps keep the size |
| 2972 | // of the aranges down. |
| 2973 | sc.comp_unit = NULL; |
| 2974 | resolved &= ~eSymbolContextCompUnit; |
| 2975 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2976 | } |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2977 | else |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2978 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2979 | GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.", |
| 2980 | cu_offset, |
| 2981 | cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2982 | } |
| 2983 | } |
| 2984 | } |
| 2985 | } |
| 2986 | } |
| 2987 | return resolved; |
| 2988 | } |
| 2989 | |
| 2990 | |
| 2991 | |
| 2992 | uint32_t |
| 2993 | SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) |
| 2994 | { |
| 2995 | const uint32_t prev_size = sc_list.GetSize(); |
| 2996 | if (resolve_scope & eSymbolContextCompUnit) |
| 2997 | { |
| 2998 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2999 | if (debug_info) |
| 3000 | { |
| 3001 | uint32_t cu_idx; |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3002 | DWARFCompileUnit* dwarf_cu = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3003 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3004 | for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3005 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3006 | CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); |
| Sean Callanan | ddd7a2a | 2013-10-03 22:27:29 +0000 | [diff] [blame] | 3007 | const bool full_match = (bool)file_spec.GetDirectory(); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 3008 | bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Equal(file_spec, *dc_cu, full_match); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3009 | if (check_inlines || file_spec_matches_cu_file_spec) |
| 3010 | { |
| 3011 | SymbolContext sc (m_obj_file->GetModule()); |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3012 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3013 | if (sc.comp_unit) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3014 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3015 | uint32_t file_idx = UINT32_MAX; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3016 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3017 | // If we are looking for inline functions only and we don't |
| 3018 | // find it in the support files, we are done. |
| 3019 | if (check_inlines) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3020 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3021 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); |
| 3022 | if (file_idx == UINT32_MAX) |
| 3023 | continue; |
| 3024 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3025 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3026 | if (line != 0) |
| 3027 | { |
| 3028 | LineTable *line_table = sc.comp_unit->GetLineTable(); |
| 3029 | |
| 3030 | if (line_table != NULL && line != 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3031 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3032 | // We will have already looked up the file index if |
| 3033 | // we are searching for inline entries. |
| 3034 | if (!check_inlines) |
| 3035 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3036 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3037 | if (file_idx != UINT32_MAX) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3038 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3039 | uint32_t found_line; |
| 3040 | uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry); |
| 3041 | found_line = sc.line_entry.line; |
| 3042 | |
| 3043 | while (line_idx != UINT32_MAX) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3044 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3045 | sc.function = NULL; |
| 3046 | sc.block = NULL; |
| 3047 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3048 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3049 | const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress(); |
| 3050 | if (file_vm_addr != LLDB_INVALID_ADDRESS) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3051 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3052 | DWARFDebugInfoEntry *function_die = NULL; |
| 3053 | DWARFDebugInfoEntry *block_die = NULL; |
| 3054 | dwarf_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] | 3055 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3056 | if (function_die != NULL) |
| 3057 | { |
| 3058 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); |
| 3059 | if (sc.function == NULL) |
| 3060 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die); |
| 3061 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3062 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3063 | if (sc.function != NULL) |
| 3064 | { |
| 3065 | Block& block = sc.function->GetBlock (true); |
| 3066 | |
| 3067 | if (block_die != NULL) |
| 3068 | sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); |
| Jason Molenda | 60db6e4 | 2014-10-16 01:40:16 +0000 | [diff] [blame] | 3069 | else if (function_die != NULL) |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3070 | sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); |
| 3071 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3072 | } |
| 3073 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3074 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3075 | sc_list.Append(sc); |
| 3076 | line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry); |
| 3077 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3078 | } |
| 3079 | } |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3080 | else if (file_spec_matches_cu_file_spec && !check_inlines) |
| 3081 | { |
| 3082 | // only append the context if we aren't looking for inline call sites |
| 3083 | // by file and line and if the file spec matches that of the compile unit |
| 3084 | sc_list.Append(sc); |
| 3085 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3086 | } |
| 3087 | else if (file_spec_matches_cu_file_spec && !check_inlines) |
| 3088 | { |
| 3089 | // only append the context if we aren't looking for inline call sites |
| 3090 | // by file and line and if the file spec matches that of the compile unit |
| 3091 | sc_list.Append(sc); |
| 3092 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3093 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3094 | if (!check_inlines) |
| 3095 | break; |
| 3096 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3097 | } |
| 3098 | } |
| 3099 | } |
| 3100 | } |
| 3101 | return sc_list.GetSize() - prev_size; |
| 3102 | } |
| 3103 | |
| 3104 | void |
| 3105 | SymbolFileDWARF::Index () |
| 3106 | { |
| 3107 | if (m_indexed) |
| 3108 | return; |
| 3109 | m_indexed = true; |
| 3110 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 3111 | "SymbolFileDWARF::Index (%s)", |
| Jim Ingham | 4af5961 | 2014-12-19 19:20:44 +0000 | [diff] [blame] | 3112 | GetObjectFile()->GetFileSpec().GetFilename().AsCString("<Unknown>")); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3113 | |
| 3114 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3115 | if (debug_info) |
| 3116 | { |
| 3117 | uint32_t cu_idx = 0; |
| 3118 | const uint32_t num_compile_units = GetNumCompileUnits(); |
| 3119 | for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) |
| 3120 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3121 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3122 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3123 | bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3124 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3125 | dwarf_cu->Index (cu_idx, |
| 3126 | m_function_basename_index, |
| 3127 | m_function_fullname_index, |
| 3128 | m_function_method_index, |
| 3129 | m_function_selector_index, |
| 3130 | m_objc_class_selectors_index, |
| 3131 | m_global_index, |
| 3132 | m_type_index, |
| 3133 | m_namespace_index); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3134 | |
| 3135 | // Keep memory down by clearing DIEs if this generate function |
| 3136 | // caused them to be parsed |
| 3137 | if (clear_dies) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3138 | dwarf_cu->ClearDIEs (true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3139 | } |
| 3140 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3141 | m_function_basename_index.Finalize(); |
| 3142 | m_function_fullname_index.Finalize(); |
| 3143 | m_function_method_index.Finalize(); |
| 3144 | m_function_selector_index.Finalize(); |
| 3145 | m_objc_class_selectors_index.Finalize(); |
| 3146 | m_global_index.Finalize(); |
| 3147 | m_type_index.Finalize(); |
| 3148 | m_namespace_index.Finalize(); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3149 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3150 | #if defined (ENABLE_DEBUG_PRINTF) |
| Greg Clayton | 7bd65b9 | 2011-02-09 23:39:34 +0000 | [diff] [blame] | 3151 | StreamFile s(stdout, false); |
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 3152 | s.Printf ("DWARF index for '%s':", |
| 3153 | GetObjectFile()->GetFileSpec().GetPath().c_str()); |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 3154 | s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s); |
| 3155 | s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s); |
| 3156 | s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s); |
| 3157 | s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s); |
| 3158 | s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s); |
| 3159 | s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s); |
| Greg Clayton | 69b0488 | 2010-10-15 02:03:22 +0000 | [diff] [blame] | 3160 | s.Printf("\nTypes:\n"); m_type_index.Dump (&s); |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 3161 | s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3162 | #endif |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3163 | } |
| 3164 | } |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 3165 | |
| 3166 | bool |
| 3167 | SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl) |
| 3168 | { |
| 3169 | if (namespace_decl == NULL) |
| 3170 | { |
| 3171 | // Invalid namespace decl which means we aren't matching only things |
| 3172 | // in this symbol file, so return true to indicate it matches this |
| 3173 | // symbol file. |
| 3174 | return true; |
| 3175 | } |
| 3176 | |
| 3177 | clang::ASTContext *namespace_ast = namespace_decl->GetASTContext(); |
| 3178 | |
| 3179 | if (namespace_ast == NULL) |
| 3180 | return true; // No AST in the "namespace_decl", return true since it |
| 3181 | // could then match any symbol file, including this one |
| 3182 | |
| 3183 | if (namespace_ast == GetClangASTContext().getASTContext()) |
| 3184 | return true; // The ASTs match, return true |
| 3185 | |
| 3186 | // The namespace AST was valid, and it does not match... |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3187 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Sean Callanan | c41e68b | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 3188 | |
| 3189 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3190 | GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file"); |
| Sean Callanan | c41e68b | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 3191 | |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 3192 | return false; |
| 3193 | } |
| 3194 | |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3195 | bool |
| 3196 | SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl, |
| 3197 | DWARFCompileUnit* cu, |
| 3198 | const DWARFDebugInfoEntry* die) |
| 3199 | { |
| Bruce Mitchener | aaa0ba3 | 2014-07-08 18:05:41 +0000 | [diff] [blame] | 3200 | // No namespace specified, so the answer is |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3201 | if (namespace_decl == NULL) |
| 3202 | return true; |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 3203 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3204 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 3205 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3206 | const DWARFDebugInfoEntry *decl_ctx_die = NULL; |
| 3207 | clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die); |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3208 | if (decl_ctx_die) |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3209 | { |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3210 | clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl(); |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3211 | |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3212 | if (clang_namespace_decl) |
| 3213 | { |
| 3214 | if (decl_ctx_die->Tag() != DW_TAG_namespace) |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 3215 | { |
| 3216 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3217 | GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent is not a namespace"); |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3218 | return false; |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 3219 | } |
| 3220 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3221 | if (clang_namespace_decl == die_clang_decl_ctx) |
| 3222 | return true; |
| 3223 | else |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3224 | return false; |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3225 | } |
| 3226 | else |
| 3227 | { |
| 3228 | // We have a namespace_decl that was not NULL but it contained |
| 3229 | // a NULL "clang::NamespaceDecl", so this means the global namespace |
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 3230 | // So as long the contained decl context DIE isn't a namespace |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3231 | // we should be ok. |
| 3232 | if (decl_ctx_die->Tag() != DW_TAG_namespace) |
| 3233 | return true; |
| 3234 | } |
| 3235 | } |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 3236 | |
| 3237 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3238 | GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent doesn't exist"); |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 3239 | |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3240 | return false; |
| 3241 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3242 | uint32_t |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3243 | 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] | 3244 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3245 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3246 | |
| 3247 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3248 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3249 | "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)", |
| 3250 | name.GetCString(), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3251 | static_cast<const void*>(namespace_decl), |
| 3252 | append, max_matches); |
| 3253 | |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3254 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) |
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 3255 | return 0; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3256 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3257 | DWARFDebugInfo* info = DebugInfo(); |
| 3258 | if (info == NULL) |
| 3259 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3260 | |
| 3261 | // If we aren't appending the results to this list, then clear the list |
| 3262 | if (!append) |
| 3263 | variables.Clear(); |
| 3264 | |
| 3265 | // Remember how many variables are in the list before we search in case |
| 3266 | // we are appending the results to a variable list. |
| 3267 | const uint32_t original_size = variables.GetSize(); |
| 3268 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3269 | DIEArray die_offsets; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3270 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3271 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3272 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3273 | if (m_apple_names_ap.get()) |
| 3274 | { |
| 3275 | const char *name_cstr = name.GetCString(); |
| Jim Ingham | fa39bb4 | 2014-10-25 00:33:55 +0000 | [diff] [blame] | 3276 | llvm::StringRef basename; |
| 3277 | llvm::StringRef context; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3278 | |
| Jim Ingham | fa39bb4 | 2014-10-25 00:33:55 +0000 | [diff] [blame] | 3279 | if (!CPPLanguageRuntime::ExtractContextAndIdentifier(name_cstr, context, basename)) |
| 3280 | basename = name_cstr; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3281 | |
| Jim Ingham | fa39bb4 | 2014-10-25 00:33:55 +0000 | [diff] [blame] | 3282 | m_apple_names_ap->FindByName (basename.data(), die_offsets); |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3283 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3284 | } |
| 3285 | else |
| 3286 | { |
| 3287 | // Index the DWARF if we haven't already |
| 3288 | if (!m_indexed) |
| 3289 | Index (); |
| 3290 | |
| 3291 | m_global_index.Find (name, die_offsets); |
| 3292 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3293 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3294 | const size_t num_die_matches = die_offsets.size(); |
| 3295 | if (num_die_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3296 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3297 | SymbolContext sc; |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 3298 | sc.module_sp = m_obj_file->GetModule(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3299 | assert (sc.module_sp); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3300 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3301 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3302 | DWARFCompileUnit* dwarf_cu = NULL; |
| 3303 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3304 | bool done = false; |
| 3305 | for (size_t i=0; i<num_die_matches && !done; ++i) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3306 | { |
| 3307 | const dw_offset_t die_offset = die_offsets[i]; |
| 3308 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3309 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3310 | if (die) |
| 3311 | { |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3312 | switch (die->Tag()) |
| 3313 | { |
| 3314 | default: |
| 3315 | case DW_TAG_subprogram: |
| 3316 | case DW_TAG_inlined_subroutine: |
| 3317 | case DW_TAG_try_block: |
| 3318 | case DW_TAG_catch_block: |
| 3319 | break; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3320 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3321 | case DW_TAG_variable: |
| 3322 | { |
| 3323 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3324 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3325 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3326 | continue; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3327 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3328 | ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3329 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3330 | if (variables.GetSize() - original_size >= max_matches) |
| 3331 | done = true; |
| 3332 | } |
| 3333 | break; |
| 3334 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3335 | } |
| 3336 | else |
| 3337 | { |
| 3338 | if (m_using_apple_tables) |
| 3339 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3340 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n", |
| 3341 | die_offset, name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3342 | } |
| 3343 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3344 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3345 | } |
| 3346 | |
| 3347 | // Return the number of variable that were appended to the list |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3348 | const uint32_t num_matches = variables.GetSize() - original_size; |
| 3349 | if (log && num_matches > 0) |
| 3350 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3351 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3352 | "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u", |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3353 | name.GetCString(), |
| 3354 | static_cast<const void*>(namespace_decl), |
| 3355 | append, max_matches, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3356 | num_matches); |
| 3357 | } |
| 3358 | return num_matches; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3359 | } |
| 3360 | |
| 3361 | uint32_t |
| 3362 | SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables) |
| 3363 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3364 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3365 | |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3366 | if (log) |
| 3367 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3368 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3369 | "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)", |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3370 | regex.GetText(), append, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3371 | max_matches); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3372 | } |
| 3373 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3374 | DWARFDebugInfo* info = DebugInfo(); |
| 3375 | if (info == NULL) |
| 3376 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3377 | |
| 3378 | // If we aren't appending the results to this list, then clear the list |
| 3379 | if (!append) |
| 3380 | variables.Clear(); |
| 3381 | |
| 3382 | // Remember how many variables are in the list before we search in case |
| 3383 | // we are appending the results to a variable list. |
| 3384 | const uint32_t original_size = variables.GetSize(); |
| 3385 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3386 | DIEArray die_offsets; |
| 3387 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3388 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3389 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3390 | if (m_apple_names_ap.get()) |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3391 | { |
| 3392 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 3393 | if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) |
| 3394 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| 3395 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3396 | } |
| 3397 | else |
| 3398 | { |
| 3399 | // Index the DWARF if we haven't already |
| 3400 | if (!m_indexed) |
| 3401 | Index (); |
| 3402 | |
| 3403 | m_global_index.Find (regex, die_offsets); |
| 3404 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3405 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3406 | SymbolContext sc; |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 3407 | sc.module_sp = m_obj_file->GetModule(); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3408 | assert (sc.module_sp); |
| 3409 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3410 | DWARFCompileUnit* dwarf_cu = NULL; |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3411 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3412 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3413 | if (num_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3414 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3415 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3416 | for (size_t i=0; i<num_matches; ++i) |
| 3417 | { |
| 3418 | const dw_offset_t die_offset = die_offsets[i]; |
| 3419 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3420 | |
| 3421 | if (die) |
| 3422 | { |
| 3423 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3424 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3425 | ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3426 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3427 | if (variables.GetSize() - original_size >= max_matches) |
| 3428 | break; |
| 3429 | } |
| 3430 | else |
| 3431 | { |
| 3432 | if (m_using_apple_tables) |
| 3433 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3434 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n", |
| 3435 | die_offset, regex.GetText()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3436 | } |
| 3437 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3438 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3439 | } |
| 3440 | |
| 3441 | // Return the number of variable that were appended to the list |
| 3442 | return variables.GetSize() - original_size; |
| 3443 | } |
| 3444 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3445 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3446 | bool |
| 3447 | SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset, |
| 3448 | DWARFCompileUnit *&dwarf_cu, |
| 3449 | SymbolContextList& sc_list) |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3450 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3451 | const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| 3452 | return ResolveFunction (dwarf_cu, die, sc_list); |
| 3453 | } |
| 3454 | |
| 3455 | |
| 3456 | bool |
| 3457 | SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu, |
| 3458 | const DWARFDebugInfoEntry *die, |
| 3459 | SymbolContextList& sc_list) |
| 3460 | { |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3461 | SymbolContext sc; |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3462 | |
| 3463 | if (die == NULL) |
| 3464 | return false; |
| 3465 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3466 | // If we were passed a die that is not a function, just return false... |
| 3467 | if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine) |
| 3468 | return false; |
| 3469 | |
| 3470 | const DWARFDebugInfoEntry* inlined_die = NULL; |
| 3471 | if (die->Tag() == DW_TAG_inlined_subroutine) |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3472 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3473 | inlined_die = die; |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3474 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3475 | while ((die = die->GetParent()) != NULL) |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3476 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3477 | if (die->Tag() == DW_TAG_subprogram) |
| 3478 | break; |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3479 | } |
| 3480 | } |
| Jason Molenda | 60db6e4 | 2014-10-16 01:40:16 +0000 | [diff] [blame] | 3481 | assert (die && die->Tag() == DW_TAG_subprogram); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3482 | if (GetFunction (cu, die, sc)) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3483 | { |
| 3484 | Address addr; |
| 3485 | // Parse all blocks if needed |
| 3486 | if (inlined_die) |
| 3487 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 3488 | sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset())); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3489 | assert (sc.block != NULL); |
| 3490 | if (sc.block->GetStartAddress (addr) == false) |
| 3491 | addr.Clear(); |
| 3492 | } |
| 3493 | else |
| 3494 | { |
| 3495 | sc.block = NULL; |
| 3496 | addr = sc.function->GetAddressRange().GetBaseAddress(); |
| 3497 | } |
| 3498 | |
| 3499 | if (addr.IsValid()) |
| 3500 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3501 | sc_list.Append(sc); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3502 | return true; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3503 | } |
| 3504 | } |
| 3505 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3506 | return false; |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3507 | } |
| 3508 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3509 | void |
| 3510 | SymbolFileDWARF::FindFunctions (const ConstString &name, |
| 3511 | const NameToDIE &name_to_die, |
| 3512 | SymbolContextList& sc_list) |
| 3513 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3514 | DIEArray die_offsets; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3515 | if (name_to_die.Find (name, die_offsets)) |
| 3516 | { |
| 3517 | ParseFunctions (die_offsets, sc_list); |
| 3518 | } |
| 3519 | } |
| 3520 | |
| 3521 | |
| 3522 | void |
| 3523 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, |
| 3524 | const NameToDIE &name_to_die, |
| 3525 | SymbolContextList& sc_list) |
| 3526 | { |
| 3527 | DIEArray die_offsets; |
| 3528 | if (name_to_die.Find (regex, die_offsets)) |
| 3529 | { |
| 3530 | ParseFunctions (die_offsets, sc_list); |
| 3531 | } |
| 3532 | } |
| 3533 | |
| 3534 | |
| 3535 | void |
| 3536 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, |
| 3537 | const DWARFMappedHash::MemoryTable &memory_table, |
| 3538 | SymbolContextList& sc_list) |
| 3539 | { |
| 3540 | DIEArray die_offsets; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3541 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 3542 | if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3543 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3544 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3545 | ParseFunctions (die_offsets, sc_list); |
| 3546 | } |
| 3547 | } |
| 3548 | |
| 3549 | void |
| 3550 | SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets, |
| 3551 | SymbolContextList& sc_list) |
| 3552 | { |
| 3553 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3554 | if (num_matches) |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3555 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3556 | SymbolContext sc; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3557 | |
| 3558 | DWARFCompileUnit* dwarf_cu = NULL; |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3559 | for (size_t i=0; i<num_matches; ++i) |
| Greg Clayton | d7e0546 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 3560 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3561 | const dw_offset_t die_offset = die_offsets[i]; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3562 | ResolveFunction (die_offset, dwarf_cu, sc_list); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3563 | } |
| 3564 | } |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3565 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3566 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3567 | bool |
| 3568 | SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die, |
| 3569 | const DWARFCompileUnit *dwarf_cu, |
| 3570 | uint32_t name_type_mask, |
| 3571 | const char *partial_name, |
| 3572 | const char *base_name_start, |
| 3573 | const char *base_name_end) |
| 3574 | { |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3575 | // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes: |
| 3576 | if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3577 | { |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 3578 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset()); |
| 3579 | if (!containing_decl_ctx) |
| 3580 | return false; |
| 3581 | |
| 3582 | bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()); |
| 3583 | |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3584 | if (name_type_mask == eFunctionNameTypeMethod) |
| 3585 | { |
| 3586 | if (is_cxx_method == false) |
| 3587 | return false; |
| 3588 | } |
| 3589 | |
| 3590 | if (name_type_mask == eFunctionNameTypeBase) |
| 3591 | { |
| 3592 | if (is_cxx_method == true) |
| 3593 | return false; |
| 3594 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3595 | } |
| 3596 | |
| 3597 | // Now we need to check whether the name we got back for this type matches the extra specifications |
| 3598 | // that were in the name we're looking up: |
| 3599 | if (base_name_start != partial_name || *base_name_end != '\0') |
| 3600 | { |
| 3601 | // First see if the stuff to the left matches the full name. To do that let's see if |
| 3602 | // we can pull out the mips linkage name attribute: |
| 3603 | |
| 3604 | Mangled best_name; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3605 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3606 | DWARFFormValue form_value; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3607 | die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| 3608 | uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name); |
| Greg Clayton | 7141554 | 2012-12-08 00:24:40 +0000 | [diff] [blame] | 3609 | if (idx == UINT32_MAX) |
| 3610 | idx = attributes.FindAttributeIndex(DW_AT_linkage_name); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3611 | if (idx != UINT32_MAX) |
| 3612 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3613 | if (attributes.ExtractFormValueAtIndex(this, idx, form_value)) |
| 3614 | { |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3615 | const char *mangled_name = form_value.AsCString(&get_debug_str_data()); |
| 3616 | if (mangled_name) |
| 3617 | best_name.SetValue (ConstString(mangled_name), true); |
| 3618 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3619 | } |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3620 | |
| 3621 | if (!best_name) |
| 3622 | { |
| 3623 | idx = attributes.FindAttributeIndex(DW_AT_name); |
| 3624 | if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value)) |
| 3625 | { |
| 3626 | const char *name = form_value.AsCString(&get_debug_str_data()); |
| 3627 | best_name.SetValue (ConstString(name), false); |
| 3628 | } |
| 3629 | } |
| 3630 | |
| 3631 | if (best_name.GetDemangledName()) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3632 | { |
| 3633 | const char *demangled = best_name.GetDemangledName().GetCString(); |
| 3634 | if (demangled) |
| 3635 | { |
| 3636 | std::string name_no_parens(partial_name, base_name_end - partial_name); |
| Jim Ingham | 85c13d7 | 2012-03-02 02:24:42 +0000 | [diff] [blame] | 3637 | const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str()); |
| 3638 | if (partial_in_demangled == NULL) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3639 | return false; |
| Jim Ingham | 85c13d7 | 2012-03-02 02:24:42 +0000 | [diff] [blame] | 3640 | else |
| 3641 | { |
| 3642 | // Sort out the case where our name is something like "Process::Destroy" and the match is |
| 3643 | // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on |
| 3644 | // namespace boundaries... |
| 3645 | |
| 3646 | if (partial_name[0] == ':' && partial_name[1] == ':') |
| 3647 | { |
| 3648 | // The partial name was already on a namespace boundary so all matches are good. |
| 3649 | return true; |
| 3650 | } |
| 3651 | else if (partial_in_demangled == demangled) |
| 3652 | { |
| 3653 | // They both start the same, so this is an good match. |
| 3654 | return true; |
| 3655 | } |
| 3656 | else |
| 3657 | { |
| 3658 | if (partial_in_demangled - demangled == 1) |
| 3659 | { |
| 3660 | // Only one character difference, can't be a namespace boundary... |
| 3661 | return false; |
| 3662 | } |
| 3663 | else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':') |
| 3664 | { |
| 3665 | // We are on a namespace boundary, so this is also good. |
| 3666 | return true; |
| 3667 | } |
| 3668 | else |
| 3669 | return false; |
| 3670 | } |
| 3671 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3672 | } |
| 3673 | } |
| 3674 | } |
| 3675 | |
| 3676 | return true; |
| 3677 | } |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3678 | |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3679 | uint32_t |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3680 | SymbolFileDWARF::FindFunctions (const ConstString &name, |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3681 | const lldb_private::ClangNamespaceDecl *namespace_decl, |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3682 | uint32_t name_type_mask, |
| 3683 | bool include_inlines, |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3684 | bool append, |
| 3685 | SymbolContextList& sc_list) |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3686 | { |
| 3687 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 3688 | "SymbolFileDWARF::FindFunctions (name = '%s')", |
| 3689 | name.AsCString()); |
| 3690 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3691 | // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup() |
| 3692 | assert ((name_type_mask & eFunctionNameTypeAuto) == 0); |
| 3693 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3694 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3695 | |
| 3696 | if (log) |
| 3697 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3698 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3699 | "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)", |
| 3700 | name.GetCString(), |
| 3701 | name_type_mask, |
| 3702 | append); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3703 | } |
| 3704 | |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3705 | // If we aren't appending the results to this list, then clear the list |
| 3706 | if (!append) |
| 3707 | sc_list.Clear(); |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3708 | |
| 3709 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) |
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 3710 | return 0; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3711 | |
| 3712 | // If name is empty then we won't find anything. |
| 3713 | if (name.IsEmpty()) |
| 3714 | return 0; |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3715 | |
| 3716 | // Remember how many sc_list are in the list before we search in case |
| 3717 | // we are appending the results to a variable list. |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3718 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3719 | const char *name_cstr = name.GetCString(); |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3720 | |
| 3721 | const uint32_t original_size = sc_list.GetSize(); |
| 3722 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3723 | DWARFDebugInfo* info = DebugInfo(); |
| 3724 | if (info == NULL) |
| 3725 | return 0; |
| 3726 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3727 | DWARFCompileUnit *dwarf_cu = NULL; |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3728 | std::set<const DWARFDebugInfoEntry *> resolved_dies; |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3729 | if (m_using_apple_tables) |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 3730 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3731 | if (m_apple_names_ap.get()) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3732 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3733 | |
| 3734 | DIEArray die_offsets; |
| 3735 | |
| 3736 | uint32_t num_matches = 0; |
| 3737 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3738 | if (name_type_mask & eFunctionNameTypeFull) |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3739 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3740 | // If they asked for the full name, match what they typed. At some point we may |
| 3741 | // want to canonicalize this (strip double spaces, etc. For now, we just add all the |
| 3742 | // dies that we find by exact match. |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3743 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3744 | for (uint32_t i = 0; i < num_matches; i++) |
| 3745 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3746 | const dw_offset_t die_offset = die_offsets[i]; |
| 3747 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3748 | if (die) |
| 3749 | { |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3750 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3751 | continue; |
| 3752 | |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3753 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) |
| 3754 | continue; |
| 3755 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3756 | if (resolved_dies.find(die) == resolved_dies.end()) |
| 3757 | { |
| 3758 | if (ResolveFunction (dwarf_cu, die, sc_list)) |
| 3759 | resolved_dies.insert(die); |
| 3760 | } |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3761 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3762 | else |
| 3763 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3764 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 3765 | die_offset, name_cstr); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3766 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3767 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3768 | } |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3769 | |
| 3770 | if (name_type_mask & eFunctionNameTypeSelector) |
| 3771 | { |
| 3772 | if (namespace_decl && *namespace_decl) |
| 3773 | return 0; // no selectors in namespaces |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3774 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3775 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); |
| 3776 | // Now make sure these are actually ObjC methods. In this case we can simply look up the name, |
| 3777 | // and if it is an ObjC method name, we're good. |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3778 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3779 | for (uint32_t i = 0; i < num_matches; i++) |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3780 | { |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3781 | const dw_offset_t die_offset = die_offsets[i]; |
| 3782 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| 3783 | if (die) |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3784 | { |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3785 | const char *die_name = die->GetName(this, dwarf_cu); |
| 3786 | if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name)) |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3787 | { |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3788 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) |
| 3789 | continue; |
| 3790 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3791 | if (resolved_dies.find(die) == resolved_dies.end()) |
| 3792 | { |
| 3793 | if (ResolveFunction (dwarf_cu, die, sc_list)) |
| 3794 | resolved_dies.insert(die); |
| 3795 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3796 | } |
| 3797 | } |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3798 | else |
| 3799 | { |
| 3800 | GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 3801 | die_offset, name_cstr); |
| 3802 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3803 | } |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3804 | die_offsets.clear(); |
| 3805 | } |
| 3806 | |
| 3807 | if (((name_type_mask & eFunctionNameTypeMethod) && !namespace_decl) || name_type_mask & eFunctionNameTypeBase) |
| 3808 | { |
| 3809 | // The apple_names table stores just the "base name" of C++ methods in the table. So we have to |
| 3810 | // extract the base name, look that up, and if there is any other information in the name we were |
| 3811 | // passed in we have to post-filter based on that. |
| 3812 | |
| 3813 | // FIXME: Arrange the logic above so that we don't calculate the base name twice: |
| 3814 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); |
| 3815 | |
| 3816 | for (uint32_t i = 0; i < num_matches; i++) |
| 3817 | { |
| 3818 | const dw_offset_t die_offset = die_offsets[i]; |
| 3819 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| 3820 | if (die) |
| 3821 | { |
| 3822 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) |
| 3823 | continue; |
| 3824 | |
| 3825 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3826 | continue; |
| 3827 | |
| 3828 | // If we get to here, the die is good, and we should add it: |
| 3829 | if (resolved_dies.find(die) == resolved_dies.end()) |
| 3830 | if (ResolveFunction (dwarf_cu, die, sc_list)) |
| 3831 | { |
| 3832 | bool keep_die = true; |
| 3833 | if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod)) |
| 3834 | { |
| 3835 | // We are looking for either basenames or methods, so we need to |
| 3836 | // trim out the ones we won't want by looking at the type |
| 3837 | SymbolContext sc; |
| 3838 | if (sc_list.GetLastContext(sc)) |
| 3839 | { |
| 3840 | if (sc.block) |
| 3841 | { |
| 3842 | // We have an inlined function |
| 3843 | } |
| 3844 | else if (sc.function) |
| 3845 | { |
| 3846 | Type *type = sc.function->GetType(); |
| 3847 | |
| Sean Callanan | c370a8a | 2013-09-18 22:59:55 +0000 | [diff] [blame] | 3848 | if (type) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3849 | { |
| Sean Callanan | c370a8a | 2013-09-18 22:59:55 +0000 | [diff] [blame] | 3850 | clang::DeclContext* decl_ctx = GetClangDeclContextContainingTypeUID (type->GetID()); |
| 3851 | if (decl_ctx->isRecord()) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3852 | { |
| Sean Callanan | c370a8a | 2013-09-18 22:59:55 +0000 | [diff] [blame] | 3853 | if (name_type_mask & eFunctionNameTypeBase) |
| 3854 | { |
| 3855 | sc_list.RemoveContextAtIndex(sc_list.GetSize()-1); |
| 3856 | keep_die = false; |
| 3857 | } |
| 3858 | } |
| 3859 | else |
| 3860 | { |
| 3861 | if (name_type_mask & eFunctionNameTypeMethod) |
| 3862 | { |
| 3863 | sc_list.RemoveContextAtIndex(sc_list.GetSize()-1); |
| 3864 | keep_die = false; |
| 3865 | } |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3866 | } |
| 3867 | } |
| 3868 | else |
| 3869 | { |
| Sean Callanan | c370a8a | 2013-09-18 22:59:55 +0000 | [diff] [blame] | 3870 | GetObjectFile()->GetModule()->ReportWarning ("function at die offset 0x%8.8x had no function type", |
| 3871 | die_offset); |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3872 | } |
| 3873 | } |
| 3874 | } |
| 3875 | } |
| 3876 | if (keep_die) |
| 3877 | resolved_dies.insert(die); |
| 3878 | } |
| 3879 | } |
| 3880 | else |
| 3881 | { |
| 3882 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 3883 | die_offset, name_cstr); |
| 3884 | } |
| 3885 | } |
| 3886 | die_offsets.clear(); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3887 | } |
| 3888 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3889 | } |
| 3890 | else |
| 3891 | { |
| 3892 | |
| 3893 | // Index the DWARF if we haven't already |
| 3894 | if (!m_indexed) |
| 3895 | Index (); |
| 3896 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3897 | if (name_type_mask & eFunctionNameTypeFull) |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 3898 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3899 | FindFunctions (name, m_function_fullname_index, sc_list); |
| 3900 | |
| Ed Maste | fc7baa0 | 2013-09-09 18:00:45 +0000 | [diff] [blame] | 3901 | // FIXME Temporary workaround for global/anonymous namespace |
| 3902 | // functions on FreeBSD and Linux |
| 3903 | #if defined (__FreeBSD__) || defined (__linux__) |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 3904 | // If we didn't find any functions in the global namespace try |
| 3905 | // looking in the basename index but ignore any returned |
| 3906 | // functions that have a namespace (ie. mangled names starting with |
| 3907 | // '_ZN') but keep functions which have an anonymous namespace |
| 3908 | if (sc_list.GetSize() == 0) |
| 3909 | { |
| 3910 | SymbolContextList temp_sc_list; |
| 3911 | FindFunctions (name, m_function_basename_index, temp_sc_list); |
| 3912 | if (!namespace_decl) |
| 3913 | { |
| 3914 | SymbolContext sc; |
| 3915 | for (uint32_t i = 0; i < temp_sc_list.GetSize(); i++) |
| 3916 | { |
| 3917 | if (temp_sc_list.GetContextAtIndex(i, sc)) |
| 3918 | { |
| Matt Kopec | a189d49 | 2013-05-10 22:55:24 +0000 | [diff] [blame] | 3919 | ConstString mangled_name = sc.GetFunctionName(Mangled::ePreferMangled); |
| 3920 | ConstString demangled_name = sc.GetFunctionName(Mangled::ePreferDemangled); |
| Matt Kopec | 04e5d58 | 2013-05-14 19:00:41 +0000 | [diff] [blame] | 3921 | if (strncmp(mangled_name.GetCString(), "_ZN", 3) || |
| 3922 | !strncmp(demangled_name.GetCString(), "(anonymous namespace)", 21)) |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 3923 | { |
| 3924 | sc_list.Append(sc); |
| 3925 | } |
| 3926 | } |
| 3927 | } |
| 3928 | } |
| 3929 | } |
| 3930 | #endif |
| 3931 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3932 | DIEArray die_offsets; |
| 3933 | DWARFCompileUnit *dwarf_cu = NULL; |
| 3934 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3935 | if (name_type_mask & eFunctionNameTypeBase) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3936 | { |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3937 | uint32_t num_base = m_function_basename_index.Find(name, die_offsets); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3938 | for (uint32_t i = 0; i < num_base; i++) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3939 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3940 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); |
| 3941 | if (die) |
| 3942 | { |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3943 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) |
| 3944 | continue; |
| 3945 | |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3946 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3947 | continue; |
| 3948 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3949 | // If we get to here, the die is good, and we should add it: |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3950 | if (resolved_dies.find(die) == resolved_dies.end()) |
| 3951 | { |
| 3952 | if (ResolveFunction (dwarf_cu, die, sc_list)) |
| 3953 | resolved_dies.insert(die); |
| 3954 | } |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3955 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3956 | } |
| 3957 | die_offsets.clear(); |
| 3958 | } |
| 3959 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3960 | if (name_type_mask & eFunctionNameTypeMethod) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3961 | { |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3962 | if (namespace_decl && *namespace_decl) |
| 3963 | return 0; // no methods in namespaces |
| 3964 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3965 | uint32_t num_base = m_function_method_index.Find(name, die_offsets); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3966 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3967 | for (uint32_t i = 0; i < num_base; i++) |
| 3968 | { |
| 3969 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); |
| 3970 | if (die) |
| 3971 | { |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3972 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) |
| 3973 | continue; |
| 3974 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3975 | // If we get to here, the die is good, and we should add it: |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3976 | if (resolved_dies.find(die) == resolved_dies.end()) |
| 3977 | { |
| 3978 | if (ResolveFunction (dwarf_cu, die, sc_list)) |
| 3979 | resolved_dies.insert(die); |
| 3980 | } |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3981 | } |
| 3982 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3983 | } |
| 3984 | die_offsets.clear(); |
| 3985 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3986 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3987 | if ((name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl)) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3988 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3989 | FindFunctions (name, m_function_selector_index, sc_list); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3990 | } |
| 3991 | |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 3992 | } |
| 3993 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3994 | // Return the number of variable that were appended to the list |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3995 | const uint32_t num_matches = sc_list.GetSize() - original_size; |
| 3996 | |
| 3997 | if (log && num_matches > 0) |
| 3998 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3999 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4000 | "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list) => %u", |
| 4001 | name.GetCString(), |
| 4002 | name_type_mask, |
| 4003 | append, |
| 4004 | num_matches); |
| 4005 | } |
| 4006 | return num_matches; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4007 | } |
| 4008 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4009 | uint32_t |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 4010 | 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] | 4011 | { |
| 4012 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 4013 | "SymbolFileDWARF::FindFunctions (regex = '%s')", |
| 4014 | regex.GetText()); |
| 4015 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4016 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 4017 | |
| 4018 | if (log) |
| 4019 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4020 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4021 | "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)", |
| 4022 | regex.GetText(), |
| 4023 | append); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 4024 | } |
| 4025 | |
| 4026 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4027 | // If we aren't appending the results to this list, then clear the list |
| 4028 | if (!append) |
| 4029 | sc_list.Clear(); |
| 4030 | |
| 4031 | // Remember how many sc_list are in the list before we search in case |
| 4032 | // we are appending the results to a variable list. |
| 4033 | uint32_t original_size = sc_list.GetSize(); |
| 4034 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4035 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4036 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4037 | if (m_apple_names_ap.get()) |
| 4038 | FindFunctions (regex, *m_apple_names_ap, sc_list); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4039 | } |
| 4040 | else |
| 4041 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 4042 | // Index the DWARF if we haven't already |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4043 | if (!m_indexed) |
| 4044 | Index (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4045 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4046 | FindFunctions (regex, m_function_basename_index, sc_list); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4047 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4048 | FindFunctions (regex, m_function_fullname_index, sc_list); |
| 4049 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4050 | |
| 4051 | // Return the number of variable that were appended to the list |
| 4052 | return sc_list.GetSize() - original_size; |
| 4053 | } |
| Jim Ingham | 318c9f2 | 2011-08-26 19:44:13 +0000 | [diff] [blame] | 4054 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4055 | uint32_t |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4056 | SymbolFileDWARF::FindTypes (const SymbolContext& sc, |
| 4057 | const ConstString &name, |
| 4058 | const lldb_private::ClangNamespaceDecl *namespace_decl, |
| 4059 | bool append, |
| 4060 | uint32_t max_matches, |
| 4061 | TypeList& types) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4062 | { |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 4063 | DWARFDebugInfo* info = DebugInfo(); |
| 4064 | if (info == NULL) |
| 4065 | return 0; |
| 4066 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4067 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4068 | |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 4069 | if (log) |
| 4070 | { |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4071 | if (namespace_decl) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4072 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4073 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)", |
| 4074 | name.GetCString(), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4075 | static_cast<void*>(namespace_decl->GetNamespaceDecl()), |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4076 | namespace_decl->GetQualifiedName().c_str(), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4077 | append, max_matches); |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4078 | else |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4079 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4080 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)", |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4081 | name.GetCString(), append, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4082 | max_matches); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 4083 | } |
| 4084 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4085 | // If we aren't appending the results to this list, then clear the list |
| 4086 | if (!append) |
| 4087 | types.Clear(); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4088 | |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 4089 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) |
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 4090 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4091 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4092 | DIEArray die_offsets; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4093 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4094 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4095 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4096 | if (m_apple_types_ap.get()) |
| 4097 | { |
| 4098 | const char *name_cstr = name.GetCString(); |
| 4099 | m_apple_types_ap->FindByName (name_cstr, die_offsets); |
| 4100 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4101 | } |
| 4102 | else |
| 4103 | { |
| 4104 | if (!m_indexed) |
| 4105 | Index (); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4106 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4107 | m_type_index.Find (name, die_offsets); |
| 4108 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4109 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4110 | const size_t num_die_matches = die_offsets.size(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4111 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4112 | if (num_die_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4113 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4114 | const uint32_t initial_types_size = types.GetSize(); |
| 4115 | DWARFCompileUnit* dwarf_cu = NULL; |
| 4116 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4117 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4118 | for (size_t i=0; i<num_die_matches; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4119 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4120 | const dw_offset_t die_offset = die_offsets[i]; |
| 4121 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| 4122 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4123 | if (die) |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 4124 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4125 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 4126 | continue; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4127 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4128 | Type *matching_type = ResolveType (dwarf_cu, die); |
| 4129 | if (matching_type) |
| 4130 | { |
| 4131 | // 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] | 4132 | types.InsertUnique (matching_type->shared_from_this()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4133 | if (types.GetSize() >= max_matches) |
| 4134 | break; |
| 4135 | } |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 4136 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4137 | else |
| 4138 | { |
| 4139 | if (m_using_apple_tables) |
| 4140 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4141 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 4142 | die_offset, name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4143 | } |
| 4144 | } |
| 4145 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4146 | } |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4147 | const uint32_t num_matches = types.GetSize() - initial_types_size; |
| 4148 | if (log && num_matches) |
| 4149 | { |
| 4150 | if (namespace_decl) |
| 4151 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4152 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4153 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u", |
| 4154 | name.GetCString(), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4155 | static_cast<void*>(namespace_decl->GetNamespaceDecl()), |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4156 | namespace_decl->GetQualifiedName().c_str(), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4157 | append, max_matches, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4158 | num_matches); |
| 4159 | } |
| 4160 | else |
| 4161 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4162 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4163 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u", |
| 4164 | name.GetCString(), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4165 | append, max_matches, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4166 | num_matches); |
| 4167 | } |
| 4168 | } |
| 4169 | return num_matches; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4170 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4171 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4172 | } |
| 4173 | |
| 4174 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4175 | ClangNamespaceDecl |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4176 | SymbolFileDWARF::FindNamespace (const SymbolContext& sc, |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 4177 | const ConstString &name, |
| 4178 | const lldb_private::ClangNamespaceDecl *parent_namespace_decl) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4179 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4180 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 4181 | |
| 4182 | if (log) |
| 4183 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4184 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4185 | "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")", |
| 4186 | name.GetCString()); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 4187 | } |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 4188 | |
| 4189 | if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl)) |
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 4190 | return ClangNamespaceDecl(); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 4191 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4192 | ClangNamespaceDecl namespace_decl; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4193 | DWARFDebugInfo* info = DebugInfo(); |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4194 | if (info) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4195 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4196 | DIEArray die_offsets; |
| 4197 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4198 | // Index if we already haven't to make sure the compile units |
| 4199 | // get indexed and make their global DIE index list |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4200 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4201 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4202 | if (m_apple_namespaces_ap.get()) |
| 4203 | { |
| 4204 | const char *name_cstr = name.GetCString(); |
| 4205 | m_apple_namespaces_ap->FindByName (name_cstr, die_offsets); |
| 4206 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4207 | } |
| 4208 | else |
| 4209 | { |
| 4210 | if (!m_indexed) |
| 4211 | Index (); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4212 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4213 | m_namespace_index.Find (name, die_offsets); |
| 4214 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4215 | |
| 4216 | DWARFCompileUnit* dwarf_cu = NULL; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4217 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4218 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4219 | if (num_matches) |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4220 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4221 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 4222 | for (size_t i=0; i<num_matches; ++i) |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4223 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4224 | const dw_offset_t die_offset = die_offsets[i]; |
| 4225 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 4226 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4227 | if (die) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4228 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4229 | if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die)) |
| 4230 | continue; |
| 4231 | |
| 4232 | clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die); |
| 4233 | if (clang_namespace_decl) |
| 4234 | { |
| 4235 | namespace_decl.SetASTContext (GetClangASTContext().getASTContext()); |
| 4236 | namespace_decl.SetNamespaceDecl (clang_namespace_decl); |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4237 | break; |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4238 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4239 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4240 | else |
| 4241 | { |
| 4242 | if (m_using_apple_tables) |
| 4243 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4244 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n", |
| 4245 | die_offset, name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4246 | } |
| 4247 | } |
| 4248 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4249 | } |
| 4250 | } |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4251 | } |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4252 | if (log && namespace_decl.GetNamespaceDecl()) |
| 4253 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4254 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4255 | "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"", |
| 4256 | name.GetCString(), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4257 | static_cast<const void*>(namespace_decl.GetNamespaceDecl()), |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4258 | namespace_decl.GetQualifiedName().c_str()); |
| 4259 | } |
| 4260 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4261 | return namespace_decl; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4262 | } |
| 4263 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4264 | uint32_t |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4265 | 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] | 4266 | { |
| 4267 | // Remember how many sc_list are in the list before we search in case |
| 4268 | // we are appending the results to a variable list. |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4269 | uint32_t original_size = types.GetSize(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4270 | |
| 4271 | const uint32_t num_die_offsets = die_offsets.size(); |
| 4272 | // Parse all of the types we found from the pubtypes matches |
| 4273 | uint32_t i; |
| 4274 | uint32_t num_matches = 0; |
| 4275 | for (i = 0; i < num_die_offsets; ++i) |
| 4276 | { |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4277 | Type *matching_type = ResolveTypeUID (die_offsets[i]); |
| 4278 | if (matching_type) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4279 | { |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4280 | // 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] | 4281 | types.InsertUnique (matching_type->shared_from_this()); |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4282 | ++num_matches; |
| 4283 | if (num_matches >= max_matches) |
| 4284 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4285 | } |
| 4286 | } |
| 4287 | |
| 4288 | // Return the number of variable that were appended to the list |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4289 | return types.GetSize() - original_size; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4290 | } |
| 4291 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4292 | |
| 4293 | size_t |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4294 | SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc, |
| 4295 | clang::DeclContext *containing_decl_ctx, |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4296 | DWARFCompileUnit* dwarf_cu, |
| 4297 | const DWARFDebugInfoEntry *parent_die, |
| 4298 | bool skip_artificial, |
| 4299 | bool &is_static, |
| Greg Clayton | 0396975 | 2014-02-24 18:53:11 +0000 | [diff] [blame] | 4300 | bool &is_variadic, |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4301 | TypeList* type_list, |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 4302 | std::vector<ClangASTType>& function_param_types, |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4303 | std::vector<clang::ParmVarDecl*>& function_param_decls, |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 4304 | unsigned &type_quals) // , |
| 4305 | // ClangASTContext::TemplateParameterInfos &template_param_infos)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4306 | { |
| 4307 | if (parent_die == NULL) |
| 4308 | return 0; |
| 4309 | |
| Todd Fiala | ee8bfc6 | 2014-09-11 17:29:12 +0000 | [diff] [blame] | 4310 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64()); |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4311 | |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4312 | size_t arg_idx = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4313 | const DWARFDebugInfoEntry *die; |
| 4314 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 4315 | { |
| 4316 | dw_tag_t tag = die->Tag(); |
| 4317 | switch (tag) |
| 4318 | { |
| 4319 | case DW_TAG_formal_parameter: |
| 4320 | { |
| 4321 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4322 | 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] | 4323 | if (num_attributes > 0) |
| 4324 | { |
| 4325 | const char *name = NULL; |
| 4326 | Declaration decl; |
| 4327 | dw_offset_t param_type_die_offset = DW_INVALID_OFFSET; |
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 4328 | bool is_artificial = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4329 | // one of None, Auto, Register, Extern, Static, PrivateExtern |
| 4330 | |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 4331 | clang::StorageClass storage = clang::SC_None; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4332 | uint32_t i; |
| 4333 | for (i=0; i<num_attributes; ++i) |
| 4334 | { |
| 4335 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 4336 | DWARFFormValue form_value; |
| 4337 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 4338 | { |
| 4339 | switch (attr) |
| 4340 | { |
| 4341 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 4342 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 4343 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 4344 | case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 4345 | case DW_AT_type: param_type_die_offset = form_value.Reference(); break; |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 4346 | case DW_AT_artificial: is_artificial = form_value.Boolean(); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4347 | case DW_AT_location: |
| 4348 | // if (form_value.BlockData()) |
| 4349 | // { |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 4350 | // const DWARFDataExtractor& debug_info_data = debug_info(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4351 | // uint32_t block_length = form_value.Unsigned(); |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 4352 | // DWARFDataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4353 | // } |
| 4354 | // else |
| 4355 | // { |
| 4356 | // } |
| 4357 | // break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4358 | case DW_AT_const_value: |
| 4359 | case DW_AT_default_value: |
| 4360 | case DW_AT_description: |
| 4361 | case DW_AT_endianity: |
| 4362 | case DW_AT_is_optional: |
| 4363 | case DW_AT_segment: |
| 4364 | case DW_AT_variable_parameter: |
| 4365 | default: |
| 4366 | case DW_AT_abstract_origin: |
| 4367 | case DW_AT_sibling: |
| 4368 | break; |
| 4369 | } |
| 4370 | } |
| 4371 | } |
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 4372 | |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4373 | bool skip = false; |
| 4374 | if (skip_artificial) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4375 | { |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4376 | if (is_artificial) |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4377 | { |
| 4378 | // In order to determine if a C++ member function is |
| 4379 | // "const" we have to look at the const-ness of "this"... |
| 4380 | // Ugly, but that |
| 4381 | if (arg_idx == 0) |
| 4382 | { |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 4383 | if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind())) |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 4384 | { |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4385 | // Often times compilers omit the "this" name for the |
| 4386 | // specification DIEs, so we can't rely upon the name |
| 4387 | // being in the formal parameter DIE... |
| 4388 | if (name == NULL || ::strcmp(name, "this")==0) |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4389 | { |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4390 | Type *this_type = ResolveTypeUID (param_type_die_offset); |
| 4391 | if (this_type) |
| 4392 | { |
| 4393 | uint32_t encoding_mask = this_type->GetEncodingMask(); |
| 4394 | if (encoding_mask & Type::eEncodingIsPointerUID) |
| 4395 | { |
| 4396 | is_static = false; |
| 4397 | |
| 4398 | if (encoding_mask & (1u << Type::eEncodingIsConstUID)) |
| 4399 | type_quals |= clang::Qualifiers::Const; |
| 4400 | if (encoding_mask & (1u << Type::eEncodingIsVolatileUID)) |
| 4401 | type_quals |= clang::Qualifiers::Volatile; |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4402 | } |
| 4403 | } |
| 4404 | } |
| 4405 | } |
| 4406 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4407 | skip = true; |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4408 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4409 | else |
| 4410 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4411 | |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4412 | // HACK: Objective C formal parameters "self" and "_cmd" |
| 4413 | // are not marked as artificial in the DWARF... |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4414 | CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| 4415 | if (comp_unit) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4416 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4417 | switch (comp_unit->GetLanguage()) |
| 4418 | { |
| 4419 | case eLanguageTypeObjC: |
| 4420 | case eLanguageTypeObjC_plus_plus: |
| 4421 | if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0)) |
| 4422 | skip = true; |
| 4423 | break; |
| 4424 | default: |
| 4425 | break; |
| 4426 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4427 | } |
| 4428 | } |
| 4429 | } |
| 4430 | |
| 4431 | if (!skip) |
| 4432 | { |
| 4433 | Type *type = ResolveTypeUID(param_type_die_offset); |
| 4434 | if (type) |
| 4435 | { |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 4436 | function_param_types.push_back (type->GetClangForwardType()); |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4437 | |
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 4438 | clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name, |
| 4439 | type->GetClangForwardType(), |
| 4440 | storage); |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4441 | assert(param_var_decl); |
| 4442 | function_param_decls.push_back(param_var_decl); |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 4443 | |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 4444 | GetClangASTContext().SetMetadataAsUserID (param_var_decl, MakeUserID(die->GetOffset())); |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4445 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4446 | } |
| 4447 | } |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4448 | arg_idx++; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4449 | } |
| 4450 | break; |
| 4451 | |
| Greg Clayton | 0396975 | 2014-02-24 18:53:11 +0000 | [diff] [blame] | 4452 | case DW_TAG_unspecified_parameters: |
| 4453 | is_variadic = true; |
| 4454 | break; |
| 4455 | |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 4456 | case DW_TAG_template_type_parameter: |
| 4457 | case DW_TAG_template_value_parameter: |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 4458 | // The one caller of this was never using the template_param_infos, |
| 4459 | // and the local variable was taking up a large amount of stack space |
| 4460 | // in SymbolFileDWARF::ParseType() so this was removed. If we ever need |
| 4461 | // the template params back, we can add them back. |
| 4462 | // ParseTemplateDIE (dwarf_cu, die, template_param_infos); |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 4463 | break; |
| 4464 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4465 | default: |
| 4466 | break; |
| 4467 | } |
| 4468 | } |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4469 | return arg_idx; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4470 | } |
| 4471 | |
| 4472 | size_t |
| 4473 | SymbolFileDWARF::ParseChildEnumerators |
| 4474 | ( |
| 4475 | const SymbolContext& sc, |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 4476 | lldb_private::ClangASTType &clang_type, |
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 4477 | bool is_signed, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4478 | uint32_t enumerator_byte_size, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4479 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4480 | const DWARFDebugInfoEntry *parent_die |
| 4481 | ) |
| 4482 | { |
| 4483 | if (parent_die == NULL) |
| 4484 | return 0; |
| 4485 | |
| 4486 | size_t enumerators_added = 0; |
| 4487 | const DWARFDebugInfoEntry *die; |
| Todd Fiala | ee8bfc6 | 2014-09-11 17:29:12 +0000 | [diff] [blame] | 4488 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64()); |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4489 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4490 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 4491 | { |
| 4492 | const dw_tag_t tag = die->Tag(); |
| 4493 | if (tag == DW_TAG_enumerator) |
| 4494 | { |
| 4495 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4496 | 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] | 4497 | if (num_child_attributes > 0) |
| 4498 | { |
| 4499 | const char *name = NULL; |
| 4500 | bool got_value = false; |
| 4501 | int64_t enum_value = 0; |
| 4502 | Declaration decl; |
| 4503 | |
| 4504 | uint32_t i; |
| 4505 | for (i=0; i<num_child_attributes; ++i) |
| 4506 | { |
| 4507 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 4508 | DWARFFormValue form_value; |
| 4509 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 4510 | { |
| 4511 | switch (attr) |
| 4512 | { |
| 4513 | case DW_AT_const_value: |
| 4514 | got_value = true; |
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 4515 | if (is_signed) |
| 4516 | enum_value = form_value.Signed(); |
| 4517 | else |
| 4518 | enum_value = form_value.Unsigned(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4519 | break; |
| 4520 | |
| 4521 | case DW_AT_name: |
| 4522 | name = form_value.AsCString(&get_debug_str_data()); |
| 4523 | break; |
| 4524 | |
| 4525 | case DW_AT_description: |
| 4526 | default: |
| 4527 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 4528 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 4529 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 4530 | case DW_AT_sibling: |
| 4531 | break; |
| 4532 | } |
| 4533 | } |
| 4534 | } |
| 4535 | |
| 4536 | if (name && name[0] && got_value) |
| 4537 | { |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 4538 | clang_type.AddEnumerationValueToEnumerationType (clang_type.GetEnumerationIntegerType(), |
| 4539 | decl, |
| 4540 | name, |
| 4541 | enum_value, |
| 4542 | enumerator_byte_size * 8); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4543 | ++enumerators_added; |
| 4544 | } |
| 4545 | } |
| 4546 | } |
| 4547 | } |
| 4548 | return enumerators_added; |
| 4549 | } |
| 4550 | |
| 4551 | void |
| 4552 | SymbolFileDWARF::ParseChildArrayInfo |
| 4553 | ( |
| 4554 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4555 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4556 | const DWARFDebugInfoEntry *parent_die, |
| 4557 | int64_t& first_index, |
| 4558 | std::vector<uint64_t>& element_orders, |
| 4559 | uint32_t& byte_stride, |
| 4560 | uint32_t& bit_stride |
| 4561 | ) |
| 4562 | { |
| 4563 | if (parent_die == NULL) |
| 4564 | return; |
| 4565 | |
| 4566 | const DWARFDebugInfoEntry *die; |
| Todd Fiala | ee8bfc6 | 2014-09-11 17:29:12 +0000 | [diff] [blame] | 4567 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4568 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 4569 | { |
| 4570 | const dw_tag_t tag = die->Tag(); |
| 4571 | switch (tag) |
| 4572 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4573 | case DW_TAG_subrange_type: |
| 4574 | { |
| 4575 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4576 | 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] | 4577 | if (num_child_attributes > 0) |
| 4578 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4579 | uint64_t num_elements = 0; |
| 4580 | uint64_t lower_bound = 0; |
| 4581 | uint64_t upper_bound = 0; |
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4582 | bool upper_bound_valid = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4583 | uint32_t i; |
| 4584 | for (i=0; i<num_child_attributes; ++i) |
| 4585 | { |
| 4586 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 4587 | DWARFFormValue form_value; |
| 4588 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 4589 | { |
| 4590 | switch (attr) |
| 4591 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4592 | case DW_AT_name: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4593 | break; |
| 4594 | |
| 4595 | case DW_AT_count: |
| 4596 | num_elements = form_value.Unsigned(); |
| 4597 | break; |
| 4598 | |
| 4599 | case DW_AT_bit_stride: |
| 4600 | bit_stride = form_value.Unsigned(); |
| 4601 | break; |
| 4602 | |
| 4603 | case DW_AT_byte_stride: |
| 4604 | byte_stride = form_value.Unsigned(); |
| 4605 | break; |
| 4606 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4607 | case DW_AT_lower_bound: |
| 4608 | lower_bound = form_value.Unsigned(); |
| 4609 | break; |
| 4610 | |
| 4611 | case DW_AT_upper_bound: |
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4612 | upper_bound_valid = true; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4613 | upper_bound = form_value.Unsigned(); |
| 4614 | break; |
| 4615 | |
| 4616 | default: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4617 | case DW_AT_abstract_origin: |
| 4618 | case DW_AT_accessibility: |
| 4619 | case DW_AT_allocated: |
| 4620 | case DW_AT_associated: |
| 4621 | case DW_AT_data_location: |
| 4622 | case DW_AT_declaration: |
| 4623 | case DW_AT_description: |
| 4624 | case DW_AT_sibling: |
| 4625 | case DW_AT_threads_scaled: |
| 4626 | case DW_AT_type: |
| 4627 | case DW_AT_visibility: |
| 4628 | break; |
| 4629 | } |
| 4630 | } |
| 4631 | } |
| 4632 | |
| Greg Clayton | e6a0779 | 2012-12-05 21:59:39 +0000 | [diff] [blame] | 4633 | if (num_elements == 0) |
| 4634 | { |
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4635 | if (upper_bound_valid && upper_bound >= lower_bound) |
| Greg Clayton | e6a0779 | 2012-12-05 21:59:39 +0000 | [diff] [blame] | 4636 | num_elements = upper_bound - lower_bound + 1; |
| 4637 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4638 | |
| Sean Callanan | ec979ba | 2012-10-22 23:56:48 +0000 | [diff] [blame] | 4639 | element_orders.push_back (num_elements); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4640 | } |
| 4641 | } |
| 4642 | break; |
| 4643 | } |
| 4644 | } |
| 4645 | } |
| 4646 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4647 | TypeSP |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4648 | SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4649 | { |
| 4650 | TypeSP type_sp; |
| 4651 | if (die != NULL) |
| 4652 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4653 | assert(dwarf_cu != NULL); |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4654 | Type *type_ptr = m_die_to_type.lookup (die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4655 | if (type_ptr == NULL) |
| 4656 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4657 | CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4658 | assert (lldb_cu); |
| 4659 | SymbolContext sc(lldb_cu); |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4660 | type_sp = ParseType(sc, dwarf_cu, die, NULL); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4661 | } |
| 4662 | else if (type_ptr != DIE_IS_BEING_PARSED) |
| 4663 | { |
| 4664 | // Grab the existing type from the master types lists |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 4665 | type_sp = type_ptr->shared_from_this(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4666 | } |
| 4667 | |
| 4668 | } |
| 4669 | return type_sp; |
| 4670 | } |
| 4671 | |
| 4672 | clang::DeclContext * |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4673 | SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4674 | { |
| 4675 | if (die_offset != DW_INVALID_OFFSET) |
| 4676 | { |
| 4677 | DWARFCompileUnitSP cu_sp; |
| 4678 | const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4679 | return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4680 | } |
| 4681 | return NULL; |
| 4682 | } |
| 4683 | |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4684 | clang::DeclContext * |
| 4685 | SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset) |
| 4686 | { |
| 4687 | if (die_offset != DW_INVALID_OFFSET) |
| 4688 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4689 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 4690 | if (debug_info) |
| 4691 | { |
| 4692 | DWARFCompileUnitSP cu_sp; |
| 4693 | const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp); |
| 4694 | if (die) |
| 4695 | return GetClangDeclContextForDIE (sc, cu_sp.get(), die); |
| 4696 | } |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4697 | } |
| 4698 | return NULL; |
| 4699 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4700 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4701 | clang::NamespaceDecl * |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4702 | SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4703 | { |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4704 | if (die && die->Tag() == DW_TAG_namespace) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4705 | { |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4706 | // See if we already parsed this namespace DIE and associated it with a |
| 4707 | // uniqued namespace declaration |
| 4708 | clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]); |
| 4709 | if (namespace_decl) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4710 | return namespace_decl; |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4711 | else |
| 4712 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4713 | const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL); |
| 4714 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL); |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4715 | namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx); |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4716 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4717 | if (log) |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4718 | { |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4719 | if (namespace_name) |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4720 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4721 | GetObjectFile()->GetModule()->LogMessage (log, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4722 | "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)", |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4723 | static_cast<void*>(GetClangASTContext().getASTContext()), |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4724 | MakeUserID(die->GetOffset()), |
| 4725 | namespace_name, |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4726 | static_cast<void*>(namespace_decl), |
| 4727 | static_cast<void*>(namespace_decl->getOriginalNamespace())); |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4728 | } |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4729 | else |
| 4730 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4731 | GetObjectFile()->GetModule()->LogMessage (log, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4732 | "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)", |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4733 | static_cast<void*>(GetClangASTContext().getASTContext()), |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4734 | MakeUserID(die->GetOffset()), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4735 | static_cast<void*>(namespace_decl), |
| 4736 | static_cast<void*>(namespace_decl->getOriginalNamespace())); |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4737 | } |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4738 | } |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4739 | |
| 4740 | if (namespace_decl) |
| 4741 | LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die); |
| 4742 | return namespace_decl; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4743 | } |
| 4744 | } |
| 4745 | return NULL; |
| 4746 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4747 | |
| 4748 | clang::DeclContext * |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4749 | SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4750 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4751 | clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die); |
| 4752 | if (clang_decl_ctx) |
| 4753 | return clang_decl_ctx; |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4754 | // If this DIE has a specification, or an abstract origin, then trace to those. |
| 4755 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4756 | 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] | 4757 | if (die_offset != DW_INVALID_OFFSET) |
| 4758 | return GetClangDeclContextForDIEOffset (sc, die_offset); |
| 4759 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4760 | 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] | 4761 | if (die_offset != DW_INVALID_OFFSET) |
| 4762 | return GetClangDeclContextForDIEOffset (sc, die_offset); |
| 4763 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4764 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 4765 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4766 | GetObjectFile()->GetModule()->LogMessage(log, "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] | 4767 | // This is the DIE we want. Parse it, then query our map. |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4768 | bool assert_not_being_parsed = true; |
| 4769 | ResolveTypeUID (cu, die, assert_not_being_parsed); |
| 4770 | |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4771 | clang_decl_ctx = GetCachedClangDeclContextForDIE (die); |
| 4772 | |
| 4773 | return clang_decl_ctx; |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4774 | } |
| 4775 | |
| 4776 | clang::DeclContext * |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4777 | 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] | 4778 | { |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4779 | if (m_clang_tu_decl == NULL) |
| 4780 | m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4781 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4782 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4783 | |
| 4784 | if (decl_ctx_die_copy) |
| 4785 | *decl_ctx_die_copy = decl_ctx_die; |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4786 | |
| 4787 | if (decl_ctx_die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4788 | { |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4789 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4790 | DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die); |
| 4791 | if (pos != m_die_to_decl_ctx.end()) |
| 4792 | return pos->second; |
| 4793 | |
| 4794 | switch (decl_ctx_die->Tag()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4795 | { |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4796 | case DW_TAG_compile_unit: |
| 4797 | return m_clang_tu_decl; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4798 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4799 | case DW_TAG_namespace: |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4800 | return ResolveNamespaceDIE (cu, decl_ctx_die); |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4801 | break; |
| 4802 | |
| 4803 | case DW_TAG_structure_type: |
| 4804 | case DW_TAG_union_type: |
| 4805 | case DW_TAG_class_type: |
| 4806 | { |
| 4807 | Type* type = ResolveType (cu, decl_ctx_die); |
| 4808 | if (type) |
| 4809 | { |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 4810 | clang::DeclContext *decl_ctx = type->GetClangForwardType().GetDeclContextForType (); |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4811 | if (decl_ctx) |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4812 | { |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4813 | LinkDeclContextToDIE (decl_ctx, decl_ctx_die); |
| 4814 | if (decl_ctx) |
| 4815 | return decl_ctx; |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4816 | } |
| 4817 | } |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4818 | } |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4819 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4820 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4821 | default: |
| 4822 | break; |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4823 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4824 | } |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 4825 | return m_clang_tu_decl; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4826 | } |
| 4827 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4828 | |
| 4829 | const DWARFDebugInfoEntry * |
| 4830 | SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) |
| 4831 | { |
| 4832 | if (cu && die) |
| 4833 | { |
| 4834 | const DWARFDebugInfoEntry * const decl_die = die; |
| 4835 | |
| 4836 | while (die != NULL) |
| 4837 | { |
| 4838 | // If this is the original DIE that we are searching for a declaration |
| 4839 | // for, then don't look in the cache as we don't want our own decl |
| 4840 | // context to be our decl context... |
| 4841 | if (decl_die != die) |
| 4842 | { |
| 4843 | switch (die->Tag()) |
| 4844 | { |
| 4845 | case DW_TAG_compile_unit: |
| 4846 | case DW_TAG_namespace: |
| 4847 | case DW_TAG_structure_type: |
| 4848 | case DW_TAG_union_type: |
| 4849 | case DW_TAG_class_type: |
| 4850 | return die; |
| 4851 | |
| 4852 | default: |
| 4853 | break; |
| 4854 | } |
| 4855 | } |
| 4856 | |
| 4857 | dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET); |
| 4858 | if (die_offset != DW_INVALID_OFFSET) |
| 4859 | { |
| 4860 | DWARFCompileUnit *spec_cu = cu; |
| 4861 | const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu); |
| 4862 | const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die); |
| 4863 | if (spec_die_decl_ctx_die) |
| 4864 | return spec_die_decl_ctx_die; |
| 4865 | } |
| 4866 | |
| 4867 | die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET); |
| 4868 | if (die_offset != DW_INVALID_OFFSET) |
| 4869 | { |
| 4870 | DWARFCompileUnit *abs_cu = cu; |
| 4871 | const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu); |
| 4872 | const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die); |
| 4873 | if (abs_die_decl_ctx_die) |
| 4874 | return abs_die_decl_ctx_die; |
| 4875 | } |
| 4876 | |
| 4877 | die = die->GetParent(); |
| 4878 | } |
| 4879 | } |
| 4880 | return NULL; |
| 4881 | } |
| 4882 | |
| 4883 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4884 | Symbol * |
| 4885 | SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name) |
| 4886 | { |
| 4887 | Symbol *objc_class_symbol = NULL; |
| 4888 | if (m_obj_file) |
| 4889 | { |
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 4890 | Symtab *symtab = m_obj_file->GetSymtab (); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4891 | if (symtab) |
| 4892 | { |
| 4893 | objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name, |
| 4894 | eSymbolTypeObjCClass, |
| 4895 | Symtab::eDebugNo, |
| 4896 | Symtab::eVisibilityAny); |
| 4897 | } |
| 4898 | } |
| 4899 | return objc_class_symbol; |
| 4900 | } |
| 4901 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4902 | // Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't |
| 4903 | // then we can end up looking through all class types for a complete type and never find |
| 4904 | // the full definition. We need to know if this attribute is supported, so we determine |
| 4905 | // this here and cache th result. We also need to worry about the debug map DWARF file |
| 4906 | // if we are doing darwin DWARF in .o file debugging. |
| 4907 | bool |
| 4908 | SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu) |
| 4909 | { |
| 4910 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate) |
| 4911 | { |
| 4912 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo; |
| 4913 | if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type()) |
| 4914 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; |
| 4915 | else |
| 4916 | { |
| 4917 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 4918 | const uint32_t num_compile_units = GetNumCompileUnits(); |
| 4919 | for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) |
| 4920 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4921 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); |
| 4922 | if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type()) |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4923 | { |
| 4924 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; |
| 4925 | break; |
| 4926 | } |
| 4927 | } |
| 4928 | } |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 4929 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ()) |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4930 | return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this); |
| 4931 | } |
| 4932 | return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes; |
| 4933 | } |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4934 | |
| 4935 | // This function can be used when a DIE is found that is a forward declaration |
| 4936 | // DIE and we want to try and find a type that has the complete definition. |
| 4937 | TypeSP |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4938 | SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die, |
| 4939 | const ConstString &type_name, |
| 4940 | bool must_be_implementation) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4941 | { |
| 4942 | |
| 4943 | TypeSP type_sp; |
| 4944 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4945 | if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name))) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4946 | return type_sp; |
| 4947 | |
| 4948 | DIEArray die_offsets; |
| 4949 | |
| 4950 | if (m_using_apple_tables) |
| 4951 | { |
| 4952 | if (m_apple_types_ap.get()) |
| 4953 | { |
| 4954 | const char *name_cstr = type_name.GetCString(); |
| Greg Clayton | 68221ec | 2012-01-18 20:58:12 +0000 | [diff] [blame] | 4955 | m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4956 | } |
| 4957 | } |
| 4958 | else |
| 4959 | { |
| 4960 | if (!m_indexed) |
| 4961 | Index (); |
| 4962 | |
| 4963 | m_type_index.Find (type_name, die_offsets); |
| 4964 | } |
| 4965 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4966 | const size_t num_matches = die_offsets.size(); |
| 4967 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4968 | DWARFCompileUnit* type_cu = NULL; |
| 4969 | const DWARFDebugInfoEntry* type_die = NULL; |
| 4970 | if (num_matches) |
| 4971 | { |
| 4972 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 4973 | for (size_t i=0; i<num_matches; ++i) |
| 4974 | { |
| 4975 | const dw_offset_t die_offset = die_offsets[i]; |
| 4976 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); |
| 4977 | |
| 4978 | if (type_die) |
| 4979 | { |
| 4980 | bool try_resolving_type = false; |
| 4981 | |
| 4982 | // Don't try and resolve the DIE we are looking for with the DIE itself! |
| 4983 | if (type_die != die) |
| 4984 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4985 | switch (type_die->Tag()) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4986 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4987 | case DW_TAG_class_type: |
| 4988 | case DW_TAG_structure_type: |
| 4989 | try_resolving_type = true; |
| 4990 | break; |
| 4991 | default: |
| 4992 | break; |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4993 | } |
| 4994 | } |
| 4995 | |
| 4996 | if (try_resolving_type) |
| 4997 | { |
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 4998 | if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type()) |
| 4999 | 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] | 5000 | |
| 5001 | if (try_resolving_type) |
| 5002 | { |
| 5003 | Type *resolved_type = ResolveType (type_cu, type_die, false); |
| 5004 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) |
| 5005 | { |
| Ed Maste | a0191d1 | 2013-10-17 20:42:56 +0000 | [diff] [blame] | 5006 | DEBUG_PRINTF ("resolved 0x%8.8" PRIx64 " from %s to 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ")\n", |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5007 | MakeUserID(die->GetOffset()), |
| Jim Ingham | 4af5961 | 2014-12-19 19:20:44 +0000 | [diff] [blame] | 5008 | m_obj_file->GetFileSpec().GetFilename().AsCString("<Unknown>"), |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5009 | MakeUserID(type_die->GetOffset()), |
| 5010 | MakeUserID(type_cu->GetOffset())); |
| 5011 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5012 | if (die) |
| 5013 | m_die_to_type[die] = resolved_type; |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 5014 | type_sp = resolved_type->shared_from_this(); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5015 | break; |
| 5016 | } |
| 5017 | } |
| 5018 | } |
| 5019 | } |
| 5020 | else |
| 5021 | { |
| 5022 | if (m_using_apple_tables) |
| 5023 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5024 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 5025 | die_offset, type_name.GetCString()); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5026 | } |
| 5027 | } |
| 5028 | |
| 5029 | } |
| 5030 | } |
| 5031 | return type_sp; |
| 5032 | } |
| 5033 | |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5034 | |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5035 | //---------------------------------------------------------------------- |
| 5036 | // This function helps to ensure that the declaration contexts match for |
| 5037 | // two different DIEs. Often times debug information will refer to a |
| 5038 | // forward declaration of a type (the equivalent of "struct my_struct;". |
| 5039 | // There will often be a declaration of that type elsewhere that has the |
| 5040 | // full definition. When we go looking for the full type "my_struct", we |
| 5041 | // will find one or more matches in the accelerator tables and we will |
| 5042 | // then need to make sure the type was in the same declaration context |
| 5043 | // as the original DIE. This function can efficiently compare two DIEs |
| 5044 | // and will return true when the declaration context matches, and false |
| 5045 | // when they don't. |
| 5046 | //---------------------------------------------------------------------- |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5047 | bool |
| 5048 | SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1, |
| 5049 | DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2) |
| 5050 | { |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5051 | if (die1 == die2) |
| 5052 | return true; |
| 5053 | |
| 5054 | #if defined (LLDB_CONFIGURATION_DEBUG) |
| 5055 | // You can't and shouldn't call this function with a compile unit from |
| 5056 | // two different SymbolFileDWARF instances. |
| 5057 | assert (DebugInfo()->ContainsCompileUnit (cu1)); |
| 5058 | assert (DebugInfo()->ContainsCompileUnit (cu2)); |
| 5059 | #endif |
| 5060 | |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5061 | DWARFDIECollection decl_ctx_1; |
| 5062 | DWARFDIECollection decl_ctx_2; |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5063 | //The declaration DIE stack is a stack of the declaration context |
| 5064 | // DIEs all the way back to the compile unit. If a type "T" is |
| 5065 | // declared inside a class "B", and class "B" is declared inside |
| 5066 | // a class "A" and class "A" is in a namespace "lldb", and the |
| 5067 | // namespace is in a compile unit, there will be a stack of DIEs: |
| 5068 | // |
| 5069 | // [0] DW_TAG_class_type for "B" |
| 5070 | // [1] DW_TAG_class_type for "A" |
| 5071 | // [2] DW_TAG_namespace for "lldb" |
| 5072 | // [3] DW_TAG_compile_unit for the source file. |
| 5073 | // |
| 5074 | // We grab both contexts and make sure that everything matches |
| 5075 | // all the way back to the compiler unit. |
| 5076 | |
| 5077 | // First lets grab the decl contexts for both DIEs |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5078 | die1->GetDeclContextDIEs (this, cu1, decl_ctx_1); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5079 | die2->GetDeclContextDIEs (this, cu2, decl_ctx_2); |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5080 | // Make sure the context arrays have the same size, otherwise |
| 5081 | // we are done |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5082 | const size_t count1 = decl_ctx_1.Size(); |
| 5083 | const size_t count2 = decl_ctx_2.Size(); |
| 5084 | if (count1 != count2) |
| 5085 | return false; |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5086 | |
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 5087 | // Make sure the DW_TAG values match all the way back up the |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5088 | // compile unit. If they don't, then we are done. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5089 | const DWARFDebugInfoEntry *decl_ctx_die1; |
| 5090 | const DWARFDebugInfoEntry *decl_ctx_die2; |
| 5091 | size_t i; |
| 5092 | for (i=0; i<count1; i++) |
| 5093 | { |
| 5094 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); |
| 5095 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); |
| 5096 | if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag()) |
| 5097 | return false; |
| 5098 | } |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5099 | #if defined LLDB_CONFIGURATION_DEBUG |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5100 | |
| 5101 | // Make sure the top item in the decl context die array is always |
| 5102 | // DW_TAG_compile_unit. If it isn't then something went wrong in |
| 5103 | // the DWARFDebugInfoEntry::GetDeclContextDIEs() function... |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5104 | assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit); |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5105 | |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5106 | #endif |
| 5107 | // Always skip the compile unit when comparing by only iterating up to |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5108 | // "count - 1". Here we compare the names as we go. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5109 | for (i=0; i<count1 - 1; i++) |
| 5110 | { |
| 5111 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); |
| 5112 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); |
| 5113 | const char *name1 = decl_ctx_die1->GetName(this, cu1); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5114 | const char *name2 = decl_ctx_die2->GetName(this, cu2); |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5115 | // If the string was from a DW_FORM_strp, then the pointer will often |
| 5116 | // be the same! |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 5117 | if (name1 == name2) |
| 5118 | continue; |
| 5119 | |
| 5120 | // Name pointers are not equal, so only compare the strings |
| 5121 | // if both are not NULL. |
| 5122 | if (name1 && name2) |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5123 | { |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 5124 | // If the strings don't compare, we are done... |
| 5125 | if (strcmp(name1, name2) != 0) |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5126 | return false; |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 5127 | } |
| 5128 | else |
| 5129 | { |
| 5130 | // One name was NULL while the other wasn't |
| 5131 | return false; |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5132 | } |
| 5133 | } |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5134 | // We made it through all of the checks and the declaration contexts |
| 5135 | // are equal. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5136 | return true; |
| 5137 | } |
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 5138 | |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 5139 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5140 | TypeSP |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5141 | SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx) |
| 5142 | { |
| 5143 | TypeSP type_sp; |
| 5144 | |
| 5145 | const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize(); |
| 5146 | if (dwarf_decl_ctx_count > 0) |
| 5147 | { |
| 5148 | const ConstString type_name(dwarf_decl_ctx[0].name); |
| 5149 | const dw_tag_t tag = dwarf_decl_ctx[0].tag; |
| 5150 | |
| 5151 | if (type_name) |
| 5152 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5153 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS)); |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5154 | if (log) |
| 5155 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5156 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5157 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')", |
| 5158 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), |
| 5159 | dwarf_decl_ctx.GetQualifiedName()); |
| 5160 | } |
| 5161 | |
| 5162 | DIEArray die_offsets; |
| 5163 | |
| 5164 | if (m_using_apple_tables) |
| 5165 | { |
| 5166 | if (m_apple_types_ap.get()) |
| 5167 | { |
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 5168 | const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag); |
| 5169 | const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash); |
| 5170 | if (has_tag && has_qualified_name_hash) |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5171 | { |
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 5172 | const char *qualified_name = dwarf_decl_ctx.GetQualifiedName(); |
| 5173 | const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name); |
| 5174 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5175 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()"); |
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 5176 | m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets); |
| 5177 | } |
| 5178 | else if (has_tag) |
| 5179 | { |
| 5180 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5181 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()"); |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5182 | m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets); |
| 5183 | } |
| 5184 | else |
| 5185 | { |
| 5186 | m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets); |
| 5187 | } |
| 5188 | } |
| 5189 | } |
| 5190 | else |
| 5191 | { |
| 5192 | if (!m_indexed) |
| 5193 | Index (); |
| 5194 | |
| 5195 | m_type_index.Find (type_name, die_offsets); |
| 5196 | } |
| 5197 | |
| 5198 | const size_t num_matches = die_offsets.size(); |
| 5199 | |
| 5200 | |
| 5201 | DWARFCompileUnit* type_cu = NULL; |
| 5202 | const DWARFDebugInfoEntry* type_die = NULL; |
| 5203 | if (num_matches) |
| 5204 | { |
| 5205 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 5206 | for (size_t i=0; i<num_matches; ++i) |
| 5207 | { |
| 5208 | const dw_offset_t die_offset = die_offsets[i]; |
| 5209 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); |
| 5210 | |
| 5211 | if (type_die) |
| 5212 | { |
| 5213 | bool try_resolving_type = false; |
| 5214 | |
| 5215 | // Don't try and resolve the DIE we are looking for with the DIE itself! |
| 5216 | const dw_tag_t type_tag = type_die->Tag(); |
| 5217 | // Make sure the tags match |
| 5218 | if (type_tag == tag) |
| 5219 | { |
| 5220 | // The tags match, lets try resolving this type |
| 5221 | try_resolving_type = true; |
| 5222 | } |
| 5223 | else |
| 5224 | { |
| 5225 | // The tags don't match, but we need to watch our for a |
| 5226 | // forward declaration for a struct and ("struct foo") |
| 5227 | // ends up being a class ("class foo { ... };") or |
| 5228 | // vice versa. |
| 5229 | switch (type_tag) |
| 5230 | { |
| 5231 | case DW_TAG_class_type: |
| 5232 | // We had a "class foo", see if we ended up with a "struct foo { ... };" |
| 5233 | try_resolving_type = (tag == DW_TAG_structure_type); |
| 5234 | break; |
| 5235 | case DW_TAG_structure_type: |
| 5236 | // We had a "struct foo", see if we ended up with a "class foo { ... };" |
| 5237 | try_resolving_type = (tag == DW_TAG_class_type); |
| 5238 | break; |
| 5239 | default: |
| 5240 | // Tags don't match, don't event try to resolve |
| 5241 | // using this type whose name matches.... |
| 5242 | break; |
| 5243 | } |
| 5244 | } |
| 5245 | |
| 5246 | if (try_resolving_type) |
| 5247 | { |
| 5248 | DWARFDeclContext type_dwarf_decl_ctx; |
| 5249 | type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx); |
| 5250 | |
| 5251 | if (log) |
| 5252 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5253 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5254 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)", |
| 5255 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), |
| 5256 | dwarf_decl_ctx.GetQualifiedName(), |
| 5257 | type_die->GetOffset(), |
| 5258 | type_dwarf_decl_ctx.GetQualifiedName()); |
| 5259 | } |
| 5260 | |
| 5261 | // Make sure the decl contexts match all the way up |
| 5262 | if (dwarf_decl_ctx == type_dwarf_decl_ctx) |
| 5263 | { |
| 5264 | Type *resolved_type = ResolveType (type_cu, type_die, false); |
| 5265 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) |
| 5266 | { |
| 5267 | type_sp = resolved_type->shared_from_this(); |
| 5268 | break; |
| 5269 | } |
| 5270 | } |
| 5271 | } |
| 5272 | else |
| 5273 | { |
| 5274 | if (log) |
| 5275 | { |
| 5276 | std::string qualified_name; |
| 5277 | type_die->GetQualifiedName(this, type_cu, qualified_name); |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5278 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5279 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)", |
| 5280 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), |
| 5281 | dwarf_decl_ctx.GetQualifiedName(), |
| 5282 | type_die->GetOffset(), |
| 5283 | qualified_name.c_str()); |
| 5284 | } |
| 5285 | } |
| 5286 | } |
| 5287 | else |
| 5288 | { |
| 5289 | if (m_using_apple_tables) |
| 5290 | { |
| 5291 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 5292 | die_offset, type_name.GetCString()); |
| 5293 | } |
| 5294 | } |
| 5295 | |
| 5296 | } |
| 5297 | } |
| 5298 | } |
| 5299 | } |
| 5300 | return type_sp; |
| 5301 | } |
| 5302 | |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5303 | bool |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5304 | SymbolFileDWARF::CopyUniqueClassMethodTypes (SymbolFileDWARF *src_symfile, |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5305 | Type *class_type, |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5306 | DWARFCompileUnit* src_cu, |
| 5307 | const DWARFDebugInfoEntry *src_class_die, |
| 5308 | DWARFCompileUnit* dst_cu, |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5309 | const DWARFDebugInfoEntry *dst_class_die, |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 5310 | DWARFDIECollection &failures) |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5311 | { |
| 5312 | if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die) |
| 5313 | return false; |
| 5314 | if (src_class_die->Tag() != dst_class_die->Tag()) |
| 5315 | return false; |
| 5316 | |
| 5317 | // We need to complete the class type so we can get all of the method types |
| 5318 | // parsed so we can then unique those types to their equivalent counterparts |
| 5319 | // in "dst_cu" and "dst_class_die" |
| 5320 | class_type->GetClangFullType(); |
| 5321 | |
| 5322 | const DWARFDebugInfoEntry *src_die; |
| 5323 | const DWARFDebugInfoEntry *dst_die; |
| 5324 | UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die; |
| 5325 | UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die; |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5326 | UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die_artificial; |
| 5327 | UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die_artificial; |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5328 | for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling()) |
| 5329 | { |
| 5330 | if (src_die->Tag() == DW_TAG_subprogram) |
| 5331 | { |
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5332 | // Make sure this is a declaration and not a concrete instance by looking |
| 5333 | // for DW_AT_declaration set to 1. Sometimes concrete function instances |
| 5334 | // are placed inside the class definitions and shouldn't be included in |
| 5335 | // the list of things are are tracking here. |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5336 | if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_declaration, 0) == 1) |
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5337 | { |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5338 | const char *src_name = src_die->GetMangledName (src_symfile, src_cu); |
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5339 | if (src_name) |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5340 | { |
| 5341 | ConstString src_const_name(src_name); |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5342 | if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_artificial, 0)) |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5343 | src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die); |
| 5344 | else |
| 5345 | src_name_to_die.Append(src_const_name.GetCString(), src_die); |
| 5346 | } |
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5347 | } |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5348 | } |
| 5349 | } |
| 5350 | for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling()) |
| 5351 | { |
| 5352 | if (dst_die->Tag() == DW_TAG_subprogram) |
| 5353 | { |
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5354 | // Make sure this is a declaration and not a concrete instance by looking |
| 5355 | // for DW_AT_declaration set to 1. Sometimes concrete function instances |
| 5356 | // are placed inside the class definitions and shouldn't be included in |
| 5357 | // the list of things are are tracking here. |
| 5358 | if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_declaration, 0) == 1) |
| 5359 | { |
| 5360 | const char *dst_name = dst_die->GetMangledName (this, dst_cu); |
| 5361 | if (dst_name) |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5362 | { |
| 5363 | ConstString dst_const_name(dst_name); |
| 5364 | if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_artificial, 0)) |
| 5365 | dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die); |
| 5366 | else |
| 5367 | dst_name_to_die.Append(dst_const_name.GetCString(), dst_die); |
| 5368 | } |
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5369 | } |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5370 | } |
| 5371 | } |
| 5372 | const uint32_t src_size = src_name_to_die.GetSize (); |
| 5373 | const uint32_t dst_size = dst_name_to_die.GetSize (); |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5374 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION)); |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5375 | |
| 5376 | // Is everything kosher so we can go through the members at top speed? |
| 5377 | bool fast_path = true; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5378 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5379 | if (src_size != dst_size) |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5380 | { |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5381 | if (src_size != 0 && dst_size != 0) |
| 5382 | { |
| 5383 | if (log) |
| 5384 | log->Printf("warning: trying to unique class DIE 0x%8.8x to 0x%8.8x, but they didn't have the same size (src=%d, dst=%d)", |
| 5385 | src_class_die->GetOffset(), |
| 5386 | dst_class_die->GetOffset(), |
| 5387 | src_size, |
| 5388 | dst_size); |
| 5389 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5390 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5391 | fast_path = false; |
| 5392 | } |
| 5393 | |
| 5394 | uint32_t idx; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5395 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5396 | if (fast_path) |
| 5397 | { |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5398 | for (idx = 0; idx < src_size; ++idx) |
| 5399 | { |
| 5400 | src_die = src_name_to_die.GetValueAtIndexUnchecked (idx); |
| 5401 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx); |
| 5402 | |
| 5403 | if (src_die->Tag() != dst_die->Tag()) |
| 5404 | { |
| 5405 | if (log) |
| 5406 | log->Printf("warning: tried to unique class DIE 0x%8.8x to 0x%8.8x, but 0x%8.8x (%s) tags didn't match 0x%8.8x (%s)", |
| 5407 | src_class_die->GetOffset(), |
| 5408 | dst_class_die->GetOffset(), |
| 5409 | src_die->GetOffset(), |
| 5410 | DW_TAG_value_to_name(src_die->Tag()), |
| 5411 | dst_die->GetOffset(), |
| 5412 | DW_TAG_value_to_name(src_die->Tag())); |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5413 | fast_path = false; |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5414 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5415 | |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5416 | const char *src_name = src_die->GetMangledName (src_symfile, src_cu); |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5417 | const char *dst_name = dst_die->GetMangledName (this, dst_cu); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5418 | |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5419 | // Make sure the names match |
| 5420 | if (src_name == dst_name || (strcmp (src_name, dst_name) == 0)) |
| 5421 | continue; |
| 5422 | |
| 5423 | if (log) |
| 5424 | log->Printf("warning: tried to unique class DIE 0x%8.8x to 0x%8.8x, but 0x%8.8x (%s) names didn't match 0x%8.8x (%s)", |
| 5425 | src_class_die->GetOffset(), |
| 5426 | dst_class_die->GetOffset(), |
| 5427 | src_die->GetOffset(), |
| 5428 | src_name, |
| 5429 | dst_die->GetOffset(), |
| 5430 | dst_name); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5431 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5432 | fast_path = false; |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5433 | } |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5434 | } |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5435 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5436 | // Now do the work of linking the DeclContexts and Types. |
| 5437 | if (fast_path) |
| 5438 | { |
| 5439 | // We can do this quickly. Just run across the tables index-for-index since |
| 5440 | // we know each node has matching names and tags. |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5441 | for (idx = 0; idx < src_size; ++idx) |
| 5442 | { |
| 5443 | src_die = src_name_to_die.GetValueAtIndexUnchecked (idx); |
| 5444 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5445 | |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5446 | clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die]; |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5447 | if (src_decl_ctx) |
| 5448 | { |
| 5449 | if (log) |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5450 | log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", |
| 5451 | static_cast<void*>(src_decl_ctx), |
| 5452 | src_die->GetOffset(), dst_die->GetOffset()); |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5453 | LinkDeclContextToDIE (src_decl_ctx, dst_die); |
| 5454 | } |
| 5455 | else |
| 5456 | { |
| 5457 | if (log) |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5458 | log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found", |
| 5459 | src_die->GetOffset(), dst_die->GetOffset()); |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5460 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5461 | |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5462 | Type *src_child_type = m_die_to_type[src_die]; |
| 5463 | if (src_child_type) |
| 5464 | { |
| 5465 | if (log) |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5466 | log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", |
| 5467 | static_cast<void*>(src_child_type), |
| 5468 | src_child_type->GetID(), |
| 5469 | src_die->GetOffset(), dst_die->GetOffset()); |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5470 | m_die_to_type[dst_die] = src_child_type; |
| 5471 | } |
| 5472 | else |
| 5473 | { |
| 5474 | if (log) |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5475 | log->Printf ("warning: tried to unique lldb_private::Type from 0x%8.8x for 0x%8.8x, but none was found", src_die->GetOffset(), dst_die->GetOffset()); |
| 5476 | } |
| 5477 | } |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5478 | } |
| 5479 | else |
| 5480 | { |
| 5481 | // We must do this slowly. For each member of the destination, look |
| 5482 | // up a member in the source with the same name, check its tag, and |
| 5483 | // unique them if everything matches up. Report failures. |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5484 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5485 | if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty()) |
| 5486 | { |
| 5487 | src_name_to_die.Sort(); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5488 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5489 | for (idx = 0; idx < dst_size; ++idx) |
| 5490 | { |
| 5491 | const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx); |
| 5492 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx); |
| 5493 | src_die = src_name_to_die.Find(dst_name, NULL); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5494 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5495 | if (src_die && (src_die->Tag() == dst_die->Tag())) |
| 5496 | { |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5497 | clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die]; |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5498 | if (src_decl_ctx) |
| 5499 | { |
| 5500 | if (log) |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5501 | log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", |
| 5502 | static_cast<void*>(src_decl_ctx), |
| 5503 | src_die->GetOffset(), |
| 5504 | dst_die->GetOffset()); |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5505 | LinkDeclContextToDIE (src_decl_ctx, dst_die); |
| 5506 | } |
| 5507 | else |
| 5508 | { |
| 5509 | if (log) |
| 5510 | log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found", src_die->GetOffset(), dst_die->GetOffset()); |
| 5511 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5512 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5513 | Type *src_child_type = m_die_to_type[src_die]; |
| 5514 | if (src_child_type) |
| 5515 | { |
| 5516 | if (log) |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5517 | log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", |
| 5518 | static_cast<void*>(src_child_type), |
| 5519 | src_child_type->GetID(), |
| 5520 | src_die->GetOffset(), |
| 5521 | dst_die->GetOffset()); |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5522 | m_die_to_type[dst_die] = src_child_type; |
| 5523 | } |
| 5524 | else |
| 5525 | { |
| 5526 | if (log) |
| 5527 | log->Printf ("warning: tried to unique lldb_private::Type from 0x%8.8x for 0x%8.8x, but none was found", src_die->GetOffset(), dst_die->GetOffset()); |
| 5528 | } |
| 5529 | } |
| 5530 | else |
| 5531 | { |
| 5532 | if (log) |
| 5533 | log->Printf ("warning: couldn't find a match for 0x%8.8x", dst_die->GetOffset()); |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5534 | |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 5535 | failures.Append(dst_die); |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5536 | } |
| 5537 | } |
| 5538 | } |
| 5539 | } |
| 5540 | |
| 5541 | const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize (); |
| 5542 | const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize (); |
| 5543 | |
| 5544 | UniqueCStringMap<const DWARFDebugInfoEntry *> name_to_die_artificial_not_in_src; |
| 5545 | |
| 5546 | if (src_size_artificial && dst_size_artificial) |
| 5547 | { |
| 5548 | dst_name_to_die_artificial.Sort(); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5549 | |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5550 | for (idx = 0; idx < src_size_artificial; ++idx) |
| 5551 | { |
| 5552 | const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx); |
| 5553 | src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx); |
| 5554 | dst_die = dst_name_to_die_artificial.Find(src_name_artificial, NULL); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5555 | |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5556 | if (dst_die) |
| 5557 | { |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5558 | // Both classes have the artificial types, link them |
| 5559 | clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die]; |
| 5560 | if (src_decl_ctx) |
| 5561 | { |
| 5562 | if (log) |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5563 | log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", |
| 5564 | static_cast<void*>(src_decl_ctx), |
| 5565 | src_die->GetOffset(), dst_die->GetOffset()); |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5566 | LinkDeclContextToDIE (src_decl_ctx, dst_die); |
| 5567 | } |
| 5568 | else |
| 5569 | { |
| 5570 | if (log) |
| 5571 | log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found", src_die->GetOffset(), dst_die->GetOffset()); |
| 5572 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5573 | |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5574 | Type *src_child_type = m_die_to_type[src_die]; |
| 5575 | if (src_child_type) |
| 5576 | { |
| 5577 | if (log) |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5578 | log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", |
| 5579 | static_cast<void*>(src_child_type), |
| 5580 | src_child_type->GetID(), |
| 5581 | src_die->GetOffset(), dst_die->GetOffset()); |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5582 | m_die_to_type[dst_die] = src_child_type; |
| 5583 | } |
| 5584 | else |
| 5585 | { |
| 5586 | if (log) |
| 5587 | log->Printf ("warning: tried to unique lldb_private::Type from 0x%8.8x for 0x%8.8x, but none was found", src_die->GetOffset(), dst_die->GetOffset()); |
| 5588 | } |
| 5589 | } |
| 5590 | } |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5591 | } |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5592 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5593 | if (dst_size_artificial) |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5594 | { |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5595 | for (idx = 0; idx < dst_size_artificial; ++idx) |
| 5596 | { |
| 5597 | const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx); |
| 5598 | dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx); |
| 5599 | if (log) |
| 5600 | log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die->GetOffset(), dst_name_artificial); |
| 5601 | |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 5602 | failures.Append(dst_die); |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5603 | } |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5604 | } |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5605 | |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 5606 | return (failures.Size() != 0); |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5607 | } |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5608 | |
| 5609 | TypeSP |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5610 | 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] | 5611 | { |
| 5612 | TypeSP type_sp; |
| 5613 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5614 | if (type_is_new_ptr) |
| 5615 | *type_is_new_ptr = false; |
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5616 | |
| Todd Fiala | 0a70a84 | 2014-05-28 16:43:26 +0000 | [diff] [blame] | 5617 | #if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE) |
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5618 | static DIEStack g_die_stack; |
| 5619 | DIEStack::ScopedPopper scoped_die_logger(g_die_stack); |
| 5620 | #endif |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5621 | |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 5622 | AccessType accessibility = eAccessNone; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5623 | if (die != NULL) |
| 5624 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5625 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5626 | if (log) |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5627 | { |
| 5628 | const DWARFDebugInfoEntry *context_die; |
| 5629 | clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5630 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5631 | GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x, decl_ctx = %p (die 0x%8.8x)) %s name = '%s')", |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5632 | die->GetOffset(), |
| 5633 | static_cast<void*>(context), |
| 5634 | context_die->GetOffset(), |
| 5635 | DW_TAG_value_to_name(die->Tag()), |
| 5636 | die->GetName(this, dwarf_cu)); |
| 5637 | |
| Todd Fiala | 0a70a84 | 2014-05-28 16:43:26 +0000 | [diff] [blame] | 5638 | #if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE) |
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5639 | scoped_die_logger.Push (dwarf_cu, die); |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5640 | g_die_stack.LogDIEs(log, this); |
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5641 | #endif |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5642 | } |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5643 | // |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5644 | // Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5645 | // if (log && dwarf_cu) |
| 5646 | // { |
| 5647 | // StreamString s; |
| 5648 | // die->DumpLocation (this, dwarf_cu, s); |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5649 | // GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData()); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5650 | // |
| 5651 | // } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5652 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5653 | Type *type_ptr = m_die_to_type.lookup (die); |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5654 | TypeList* type_list = GetTypeList(); |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5655 | if (type_ptr == NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5656 | { |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5657 | ClangASTContext &ast = GetClangASTContext(); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5658 | if (type_is_new_ptr) |
| 5659 | *type_is_new_ptr = true; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5660 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5661 | const dw_tag_t tag = die->Tag(); |
| 5662 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5663 | bool is_forward_declaration = false; |
| 5664 | DWARFDebugInfoEntry::Attributes attributes; |
| 5665 | const char *type_name_cstr = NULL; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5666 | ConstString type_name_const_str; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5667 | Type::ResolveState resolve_state = Type::eResolveStateUnresolved; |
| Greg Clayton | faac111 | 2013-03-14 18:31:44 +0000 | [diff] [blame] | 5668 | uint64_t byte_size = 0; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5669 | Declaration decl; |
| 5670 | |
| Greg Clayton | 4957bf6 | 2010-09-30 21:49:03 +0000 | [diff] [blame] | 5671 | Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID; |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5672 | ClangASTType clang_type; |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 5673 | DWARFFormValue form_value; |
| 5674 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5675 | dw_attr_t attr; |
| 5676 | |
| 5677 | switch (tag) |
| 5678 | { |
| 5679 | case DW_TAG_base_type: |
| 5680 | case DW_TAG_pointer_type: |
| 5681 | case DW_TAG_reference_type: |
| Sean Callanan | ce8af86 | 2012-05-21 23:31:51 +0000 | [diff] [blame] | 5682 | case DW_TAG_rvalue_reference_type: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5683 | case DW_TAG_typedef: |
| 5684 | case DW_TAG_const_type: |
| 5685 | case DW_TAG_restrict_type: |
| 5686 | case DW_TAG_volatile_type: |
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5687 | case DW_TAG_unspecified_type: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5688 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5689 | // 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] | 5690 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5691 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5692 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5693 | uint32_t encoding = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5694 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; |
| 5695 | |
| 5696 | if (num_attributes > 0) |
| 5697 | { |
| 5698 | uint32_t i; |
| 5699 | for (i=0; i<num_attributes; ++i) |
| 5700 | { |
| 5701 | attr = attributes.AttributeAtIndex(i); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5702 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 5703 | { |
| 5704 | switch (attr) |
| 5705 | { |
| 5706 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 5707 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 5708 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 5709 | case DW_AT_name: |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5710 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5711 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Jim Ingham | 337030f | 2011-04-15 23:41:23 +0000 | [diff] [blame] | 5712 | // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't |
| 5713 | // include the "&"... |
| 5714 | if (tag == DW_TAG_reference_type) |
| 5715 | { |
| 5716 | if (strchr (type_name_cstr, '&') == NULL) |
| 5717 | type_name_cstr = NULL; |
| 5718 | } |
| 5719 | if (type_name_cstr) |
| 5720 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5721 | break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 5722 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5723 | case DW_AT_encoding: encoding = form_value.Unsigned(); break; |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 5724 | case DW_AT_type: encoding_uid = form_value.Reference(); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5725 | default: |
| 5726 | case DW_AT_sibling: |
| 5727 | break; |
| 5728 | } |
| 5729 | } |
| 5730 | } |
| 5731 | } |
| 5732 | |
| Ed Maste | a0191d1 | 2013-10-17 20:42:56 +0000 | [diff] [blame] | 5733 | DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\") type => 0x%8.8lx\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] | 5734 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5735 | switch (tag) |
| 5736 | { |
| 5737 | default: |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5738 | break; |
| 5739 | |
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5740 | case DW_TAG_unspecified_type: |
| Greg Clayton | 7fba263 | 2013-07-01 21:01:52 +0000 | [diff] [blame] | 5741 | if (strcmp(type_name_cstr, "nullptr_t") == 0 || |
| 5742 | strcmp(type_name_cstr, "decltype(nullptr)") == 0 ) |
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5743 | { |
| 5744 | resolve_state = Type::eResolveStateFull; |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5745 | clang_type = ast.GetBasicType(eBasicTypeNullPtr); |
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5746 | break; |
| 5747 | } |
| 5748 | // Fall through to base type below in case we can handle the type there... |
| 5749 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5750 | case DW_TAG_base_type: |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5751 | resolve_state = Type::eResolveStateFull; |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5752 | clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr, |
| 5753 | encoding, |
| 5754 | byte_size * 8); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5755 | break; |
| 5756 | |
| Sean Callanan | ce8af86 | 2012-05-21 23:31:51 +0000 | [diff] [blame] | 5757 | case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break; |
| 5758 | case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break; |
| 5759 | case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break; |
| 5760 | case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break; |
| 5761 | case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break; |
| 5762 | case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break; |
| 5763 | case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5764 | } |
| 5765 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5766 | if (!clang_type && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID) && sc.comp_unit != NULL) |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 5767 | { |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5768 | bool translation_unit_is_objc = (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5769 | |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5770 | if (translation_unit_is_objc) |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 5771 | { |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5772 | if (type_name_cstr != NULL) |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5773 | { |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5774 | static ConstString g_objc_type_name_id("id"); |
| 5775 | static ConstString g_objc_type_name_Class("Class"); |
| 5776 | static ConstString g_objc_type_name_selector("SEL"); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5777 | |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5778 | if (type_name_const_str == g_objc_type_name_id) |
| 5779 | { |
| 5780 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5781 | GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'id' built-in type.", |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5782 | die->GetOffset(), |
| 5783 | DW_TAG_value_to_name(die->Tag()), |
| 5784 | die->GetName(this, dwarf_cu)); |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5785 | clang_type = ast.GetBasicType(eBasicTypeObjCID); |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5786 | encoding_data_type = Type::eEncodingIsUID; |
| 5787 | encoding_uid = LLDB_INVALID_UID; |
| 5788 | resolve_state = Type::eResolveStateFull; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5789 | |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5790 | } |
| 5791 | else if (type_name_const_str == g_objc_type_name_Class) |
| 5792 | { |
| 5793 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5794 | GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'Class' built-in type.", |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5795 | die->GetOffset(), |
| 5796 | DW_TAG_value_to_name(die->Tag()), |
| 5797 | die->GetName(this, dwarf_cu)); |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5798 | clang_type = ast.GetBasicType(eBasicTypeObjCClass); |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5799 | encoding_data_type = Type::eEncodingIsUID; |
| 5800 | encoding_uid = LLDB_INVALID_UID; |
| 5801 | resolve_state = Type::eResolveStateFull; |
| 5802 | } |
| 5803 | else if (type_name_const_str == g_objc_type_name_selector) |
| 5804 | { |
| 5805 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5806 | GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'selector' built-in type.", |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5807 | die->GetOffset(), |
| 5808 | DW_TAG_value_to_name(die->Tag()), |
| 5809 | die->GetName(this, dwarf_cu)); |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5810 | clang_type = ast.GetBasicType(eBasicTypeObjCSel); |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5811 | encoding_data_type = Type::eEncodingIsUID; |
| 5812 | encoding_uid = LLDB_INVALID_UID; |
| 5813 | resolve_state = Type::eResolveStateFull; |
| 5814 | } |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5815 | } |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5816 | else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid != LLDB_INVALID_UID) |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5817 | { |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5818 | // Clang sometimes erroneously emits id as objc_object*. In that case we fix up the type to "id". |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5819 | |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5820 | DWARFDebugInfoEntry* encoding_die = dwarf_cu->GetDIEPtr(encoding_uid); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5821 | |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5822 | if (encoding_die && encoding_die->Tag() == DW_TAG_structure_type) |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5823 | { |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5824 | if (const char *struct_name = encoding_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL)) |
| 5825 | { |
| 5826 | if (!strcmp(struct_name, "objc_object")) |
| 5827 | { |
| 5828 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5829 | GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is 'objc_object*', which we overrode to 'id'.", |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5830 | die->GetOffset(), |
| 5831 | DW_TAG_value_to_name(die->Tag()), |
| 5832 | die->GetName(this, dwarf_cu)); |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5833 | clang_type = ast.GetBasicType(eBasicTypeObjCID); |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5834 | encoding_data_type = Type::eEncodingIsUID; |
| 5835 | encoding_uid = LLDB_INVALID_UID; |
| 5836 | resolve_state = Type::eResolveStateFull; |
| 5837 | } |
| 5838 | } |
| 5839 | } |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5840 | } |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 5841 | } |
| 5842 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5843 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5844 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5845 | this, |
| 5846 | type_name_const_str, |
| 5847 | byte_size, |
| 5848 | NULL, |
| 5849 | encoding_uid, |
| 5850 | encoding_data_type, |
| 5851 | &decl, |
| 5852 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5853 | resolve_state)); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5854 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5855 | m_die_to_type[die] = type_sp.get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5856 | |
| 5857 | // Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false); |
| 5858 | // if (encoding_type != NULL) |
| 5859 | // { |
| 5860 | // if (encoding_type != DIE_IS_BEING_PARSED) |
| 5861 | // type_sp->SetEncodingType(encoding_type); |
| 5862 | // else |
| 5863 | // m_indirect_fixups.push_back(type_sp.get()); |
| 5864 | // } |
| 5865 | } |
| 5866 | break; |
| 5867 | |
| 5868 | case DW_TAG_structure_type: |
| 5869 | case DW_TAG_union_type: |
| 5870 | case DW_TAG_class_type: |
| 5871 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5872 | // 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] | 5873 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 5874 | bool byte_size_valid = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5875 | |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5876 | LanguageType class_language = eLanguageTypeUnknown; |
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 5877 | bool is_complete_objc_class = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5878 | //bool struct_is_class = false; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5879 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5880 | if (num_attributes > 0) |
| 5881 | { |
| 5882 | uint32_t i; |
| 5883 | for (i=0; i<num_attributes; ++i) |
| 5884 | { |
| 5885 | attr = attributes.AttributeAtIndex(i); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5886 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 5887 | { |
| 5888 | switch (attr) |
| 5889 | { |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5890 | case DW_AT_decl_file: |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5891 | if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid()) |
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 5892 | { |
| 5893 | // llvm-gcc outputs invalid DW_AT_decl_file attributes that always |
| 5894 | // point to the compile unit file, so we clear this invalid value |
| 5895 | // so that we can still unique types efficiently. |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5896 | decl.SetFile(FileSpec ("<invalid>", false)); |
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 5897 | } |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5898 | else |
| 5899 | decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5900 | break; |
| 5901 | |
| 5902 | case DW_AT_decl_line: |
| 5903 | decl.SetLine(form_value.Unsigned()); |
| 5904 | break; |
| 5905 | |
| 5906 | case DW_AT_decl_column: |
| 5907 | decl.SetColumn(form_value.Unsigned()); |
| 5908 | break; |
| 5909 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5910 | case DW_AT_name: |
| 5911 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5912 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5913 | break; |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5914 | |
| 5915 | case DW_AT_byte_size: |
| 5916 | byte_size = form_value.Unsigned(); |
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 5917 | byte_size_valid = true; |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5918 | break; |
| 5919 | |
| 5920 | case DW_AT_accessibility: |
| 5921 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); |
| 5922 | break; |
| 5923 | |
| 5924 | case DW_AT_declaration: |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 5925 | is_forward_declaration = form_value.Boolean(); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5926 | break; |
| 5927 | |
| 5928 | case DW_AT_APPLE_runtime_class: |
| 5929 | class_language = (LanguageType)form_value.Signed(); |
| 5930 | break; |
| 5931 | |
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 5932 | case DW_AT_APPLE_objc_complete_type: |
| 5933 | is_complete_objc_class = form_value.Signed(); |
| 5934 | break; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5935 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5936 | case DW_AT_allocated: |
| 5937 | case DW_AT_associated: |
| 5938 | case DW_AT_data_location: |
| 5939 | case DW_AT_description: |
| 5940 | case DW_AT_start_scope: |
| 5941 | case DW_AT_visibility: |
| 5942 | default: |
| 5943 | case DW_AT_sibling: |
| 5944 | break; |
| 5945 | } |
| 5946 | } |
| 5947 | } |
| 5948 | } |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 5949 | |
| 5950 | // UniqueDWARFASTType is large, so don't create a local variables on the |
| 5951 | // stack, put it on the heap. This function is often called recursively |
| 5952 | // and clang isn't good and sharing the stack space for variables in different blocks. |
| 5953 | std::unique_ptr<UniqueDWARFASTType> unique_ast_entry_ap(new UniqueDWARFASTType()); |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5954 | |
| Greg Clayton | 123edca | 2012-03-02 00:07:15 +0000 | [diff] [blame] | 5955 | // Only try and unique the type if it has a name. |
| 5956 | if (type_name_const_str && |
| 5957 | GetUniqueDWARFASTTypeMap().Find (type_name_const_str, |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5958 | this, |
| 5959 | dwarf_cu, |
| 5960 | die, |
| 5961 | decl, |
| 5962 | byte_size_valid ? byte_size : -1, |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 5963 | *unique_ast_entry_ap)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5964 | { |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5965 | // We have already parsed this type or from another |
| 5966 | // compile unit. GCC loves to use the "one definition |
| 5967 | // rule" which can result in multiple definitions |
| 5968 | // of the same class over and over in each compile |
| 5969 | // unit. |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 5970 | type_sp = unique_ast_entry_ap->m_type_sp; |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5971 | if (type_sp) |
| Greg Clayton | c615ce4 | 2010-11-09 04:42:43 +0000 | [diff] [blame] | 5972 | { |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5973 | m_die_to_type[die] = type_sp.get(); |
| 5974 | return type_sp; |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5975 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5976 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5977 | |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5978 | DEBUG_PRINTF ("0x%8.8" PRIx64 ": %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] | 5979 | |
| 5980 | int tag_decl_kind = -1; |
| 5981 | AccessType default_accessibility = eAccessNone; |
| 5982 | if (tag == DW_TAG_structure_type) |
| 5983 | { |
| 5984 | tag_decl_kind = clang::TTK_Struct; |
| 5985 | default_accessibility = eAccessPublic; |
| 5986 | } |
| 5987 | else if (tag == DW_TAG_union_type) |
| 5988 | { |
| 5989 | tag_decl_kind = clang::TTK_Union; |
| 5990 | default_accessibility = eAccessPublic; |
| 5991 | } |
| 5992 | else if (tag == DW_TAG_class_type) |
| 5993 | { |
| 5994 | tag_decl_kind = clang::TTK_Class; |
| 5995 | default_accessibility = eAccessPrivate; |
| 5996 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5997 | |
| Greg Clayton | 3a5f29a | 2011-11-30 02:48:28 +0000 | [diff] [blame] | 5998 | if (byte_size_valid && byte_size == 0 && type_name_cstr && |
| 5999 | die->HasChildren() == false && |
| 6000 | sc.comp_unit->GetLanguage() == eLanguageTypeObjC) |
| 6001 | { |
| 6002 | // Work around an issue with clang at the moment where |
| 6003 | // forward declarations for objective C classes are emitted |
| 6004 | // as: |
| 6005 | // DW_TAG_structure_type [2] |
| 6006 | // DW_AT_name( "ForwardObjcClass" ) |
| 6007 | // DW_AT_byte_size( 0x00 ) |
| 6008 | // DW_AT_decl_file( "..." ) |
| 6009 | // DW_AT_decl_line( 1 ) |
| 6010 | // |
| 6011 | // Note that there is no DW_AT_declaration and there are |
| 6012 | // no children, and the byte size is zero. |
| 6013 | is_forward_declaration = true; |
| 6014 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6015 | |
| Sean Callanan | 7457f8d | 2012-04-25 01:03:57 +0000 | [diff] [blame] | 6016 | if (class_language == eLanguageTypeObjC || |
| 6017 | class_language == eLanguageTypeObjC_plus_plus) |
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 6018 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6019 | 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] | 6020 | { |
| 6021 | // We have a valid eSymbolTypeObjCClass class symbol whose |
| 6022 | // name matches the current objective C class that we |
| 6023 | // are trying to find and this DIE isn't the complete |
| 6024 | // definition (we checked is_complete_objc_class above and |
| 6025 | // know it is false), so the real definition is in here somewhere |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6026 | type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true); |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6027 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 6028 | if (!type_sp && GetDebugMapSymfile ()) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 6029 | { |
| 6030 | // We weren't able to find a full declaration in |
| 6031 | // this DWARF, see if we have a declaration anywhere |
| 6032 | // else... |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6033 | 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] | 6034 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6035 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 6036 | if (type_sp) |
| 6037 | { |
| 6038 | if (log) |
| 6039 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 6040 | GetObjectFile()->GetModule()->LogMessage (log, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6041 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an incomplete objc type, complete type is 0x%8.8" PRIx64, |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6042 | static_cast<void*>(this), |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6043 | die->GetOffset(), |
| 6044 | DW_TAG_value_to_name(tag), |
| 6045 | type_name_cstr, |
| 6046 | type_sp->GetID()); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 6047 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6048 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 6049 | // We found a real definition for this type elsewhere |
| 6050 | // so lets use it and cache the fact that we found |
| 6051 | // a complete type for this die |
| 6052 | m_die_to_type[die] = type_sp.get(); |
| 6053 | return type_sp; |
| 6054 | } |
| 6055 | } |
| 6056 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6057 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 6058 | |
| 6059 | if (is_forward_declaration) |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6060 | { |
| 6061 | // We have a forward declaration to a type and we need |
| 6062 | // to try and find a full declaration. We look in the |
| 6063 | // current type index just in case we have a forward |
| 6064 | // declaration followed by an actual declarations in the |
| 6065 | // DWARF. If this fails, we need to look elsewhere... |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 6066 | if (log) |
| 6067 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 6068 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6069 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type", |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6070 | static_cast<void*>(this), |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6071 | die->GetOffset(), |
| 6072 | DW_TAG_value_to_name(tag), |
| 6073 | type_name_cstr); |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 6074 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6075 | |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 6076 | DWARFDeclContext die_decl_ctx; |
| 6077 | die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx); |
| 6078 | |
| 6079 | //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str); |
| 6080 | type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6081 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 6082 | if (!type_sp && GetDebugMapSymfile ()) |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 6083 | { |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6084 | // We weren't able to find a full declaration in |
| 6085 | // this DWARF, see if we have a declaration anywhere |
| 6086 | // else... |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 6087 | type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 6088 | } |
| 6089 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6090 | if (type_sp) |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 6091 | { |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 6092 | if (log) |
| 6093 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 6094 | GetObjectFile()->GetModule()->LogMessage (log, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6095 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8" PRIx64, |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6096 | static_cast<void*>(this), |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6097 | die->GetOffset(), |
| 6098 | DW_TAG_value_to_name(tag), |
| 6099 | type_name_cstr, |
| 6100 | type_sp->GetID()); |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 6101 | } |
| 6102 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6103 | // We found a real definition for this type elsewhere |
| 6104 | // so lets use it and cache the fact that we found |
| 6105 | // a complete type for this die |
| 6106 | m_die_to_type[die] = type_sp.get(); |
| 6107 | return type_sp; |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 6108 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6109 | } |
| 6110 | assert (tag_decl_kind != -1); |
| 6111 | bool clang_type_was_created = false; |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6112 | clang_type.SetClangType(ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die)); |
| 6113 | if (!clang_type) |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6114 | { |
| Sean Callanan | 4d04c6a | 2012-02-09 22:54:11 +0000 | [diff] [blame] | 6115 | const DWARFDebugInfoEntry *decl_ctx_die; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6116 | |
| Sean Callanan | 4d04c6a | 2012-02-09 22:54:11 +0000 | [diff] [blame] | 6117 | clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die); |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 6118 | if (accessibility == eAccessNone && decl_ctx) |
| 6119 | { |
| 6120 | // Check the decl context that contains this class/struct/union. |
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 6121 | // If it is a class we must give it an accessibility. |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 6122 | const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind(); |
| 6123 | if (DeclKindIsCXXClass (containing_decl_kind)) |
| 6124 | accessibility = default_accessibility; |
| 6125 | } |
| 6126 | |
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 6127 | ClangASTMetadata metadata; |
| 6128 | metadata.SetUserID(MakeUserID(die->GetOffset())); |
| 6129 | metadata.SetIsDynamicCXXType(ClassOrStructIsVirtual (dwarf_cu, die)); |
| 6130 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6131 | if (type_name_cstr && strchr (type_name_cstr, '<')) |
| 6132 | { |
| 6133 | ClangASTContext::TemplateParameterInfos template_param_infos; |
| 6134 | if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos)) |
| 6135 | { |
| 6136 | clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx, |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 6137 | accessibility, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6138 | type_name_cstr, |
| 6139 | tag_decl_kind, |
| 6140 | template_param_infos); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6141 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6142 | clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx, |
| 6143 | class_template_decl, |
| 6144 | tag_decl_kind, |
| 6145 | template_param_infos); |
| 6146 | clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl); |
| 6147 | clang_type_was_created = true; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6148 | |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6149 | GetClangASTContext().SetMetadata (class_template_decl, metadata); |
| 6150 | GetClangASTContext().SetMetadata (class_specialization_decl, metadata); |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6151 | } |
| 6152 | } |
| 6153 | |
| 6154 | if (!clang_type_was_created) |
| 6155 | { |
| 6156 | clang_type_was_created = true; |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 6157 | clang_type = ast.CreateRecordType (decl_ctx, |
| 6158 | accessibility, |
| 6159 | type_name_cstr, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6160 | tag_decl_kind, |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 6161 | class_language, |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6162 | &metadata); |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6163 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6164 | } |
| 6165 | |
| 6166 | // Store a forward declaration to this class type in case any |
| 6167 | // parameters in any class methods need it for the clang |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6168 | // types for function prototypes. |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6169 | LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6170 | type_sp.reset (new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6171 | this, |
| 6172 | type_name_const_str, |
| 6173 | byte_size, |
| 6174 | NULL, |
| 6175 | LLDB_INVALID_UID, |
| 6176 | Type::eEncodingIsUID, |
| 6177 | &decl, |
| 6178 | clang_type, |
| 6179 | Type::eResolveStateForward)); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6180 | |
| Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 6181 | type_sp->SetIsCompleteObjCClass(is_complete_objc_class); |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6182 | |
| 6183 | |
| 6184 | // Add our type to the unique type map so we don't |
| 6185 | // end up creating many copies of the same type over |
| 6186 | // and over in the ASTContext for our module |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 6187 | unique_ast_entry_ap->m_type_sp = type_sp; |
| 6188 | unique_ast_entry_ap->m_symfile = this; |
| 6189 | unique_ast_entry_ap->m_cu = dwarf_cu; |
| 6190 | unique_ast_entry_ap->m_die = die; |
| 6191 | unique_ast_entry_ap->m_declaration = decl; |
| 6192 | unique_ast_entry_ap->m_byte_size = byte_size; |
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 6193 | GetUniqueDWARFASTTypeMap().Insert (type_name_const_str, |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 6194 | *unique_ast_entry_ap); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6195 | |
| Greg Clayton | 0ec71a0 | 2013-08-10 00:09:35 +0000 | [diff] [blame] | 6196 | if (is_forward_declaration && die->HasChildren()) |
| 6197 | { |
| 6198 | // Check to see if the DIE actually has a definition, some version of GCC will |
| 6199 | // emit DIEs with DW_AT_declaration set to true, but yet still have subprogram, |
| 6200 | // members, or inheritance, so we can't trust it |
| 6201 | const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); |
| 6202 | while (child_die) |
| 6203 | { |
| 6204 | switch (child_die->Tag()) |
| 6205 | { |
| 6206 | case DW_TAG_inheritance: |
| 6207 | case DW_TAG_subprogram: |
| 6208 | case DW_TAG_member: |
| 6209 | case DW_TAG_APPLE_property: |
| Greg Clayton | 4c484ec | 2014-02-07 19:21:56 +0000 | [diff] [blame] | 6210 | case DW_TAG_class_type: |
| 6211 | case DW_TAG_structure_type: |
| 6212 | case DW_TAG_enumeration_type: |
| 6213 | case DW_TAG_typedef: |
| 6214 | case DW_TAG_union_type: |
| Greg Clayton | 0ec71a0 | 2013-08-10 00:09:35 +0000 | [diff] [blame] | 6215 | child_die = NULL; |
| 6216 | is_forward_declaration = false; |
| 6217 | break; |
| 6218 | default: |
| 6219 | child_die = child_die->GetSibling(); |
| 6220 | break; |
| 6221 | } |
| 6222 | } |
| 6223 | } |
| 6224 | |
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6225 | if (!is_forward_declaration) |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 6226 | { |
| 6227 | // Always start the definition for a class type so that |
| 6228 | // if the class has child classes or types that require |
| 6229 | // the class to be created for use as their decl contexts |
| 6230 | // the class will be ready to accept these child definitions. |
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6231 | if (die->HasChildren() == false) |
| 6232 | { |
| 6233 | // No children for this struct/union/class, lets finish it |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6234 | clang_type.StartTagDeclarationDefinition (); |
| 6235 | clang_type.CompleteTagDeclarationDefinition (); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6236 | |
| Sean Callanan | 433cd22 | 2012-10-19 01:37:25 +0000 | [diff] [blame] | 6237 | if (tag == DW_TAG_structure_type) // this only applies in C |
| 6238 | { |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6239 | clang::RecordDecl *record_decl = clang_type.GetAsRecordDecl(); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6240 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6241 | if (record_decl) |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 6242 | m_record_decl_to_layout_map.insert(std::make_pair(record_decl, LayoutInfo())); |
| Sean Callanan | 433cd22 | 2012-10-19 01:37:25 +0000 | [diff] [blame] | 6243 | } |
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6244 | } |
| 6245 | else if (clang_type_was_created) |
| 6246 | { |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 6247 | // Start the definition if the class is not objective C since |
| 6248 | // the underlying decls respond to isCompleteDefinition(). Objective |
| Bruce Mitchener | aaa0ba3 | 2014-07-08 18:05:41 +0000 | [diff] [blame] | 6249 | // C decls don't respond to isCompleteDefinition() so we can't |
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 6250 | // start the declaration definition right away. For C++ class/union/structs |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 6251 | // we want to start the definition in case the class is needed as the |
| 6252 | // declaration context for a contained class or type without the need |
| 6253 | // to complete that type.. |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6254 | |
| Sean Callanan | 7457f8d | 2012-04-25 01:03:57 +0000 | [diff] [blame] | 6255 | if (class_language != eLanguageTypeObjC && |
| 6256 | class_language != eLanguageTypeObjC_plus_plus) |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6257 | clang_type.StartTagDeclarationDefinition (); |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 6258 | |
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6259 | // Leave this as a forward declaration until we need |
| 6260 | // to know the details of the type. lldb_private::Type |
| 6261 | // will automatically call the SymbolFile virtual function |
| 6262 | // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)" |
| 6263 | // When the definition needs to be defined. |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6264 | m_forward_decl_die_to_clang_type[die] = clang_type.GetOpaqueQualType(); |
| 6265 | m_forward_decl_clang_type_to_die[clang_type.RemoveFastQualifiers().GetOpaqueQualType()] = die; |
| 6266 | clang_type.SetHasExternalStorage (true); |
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6267 | } |
| Greg Clayton | c615ce4 | 2010-11-09 04:42:43 +0000 | [diff] [blame] | 6268 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6269 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6270 | } |
| 6271 | break; |
| 6272 | |
| 6273 | case DW_TAG_enumeration_type: |
| 6274 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6275 | // 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] | 6276 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6277 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6278 | lldb::user_id_t encoding_uid = DW_INVALID_OFFSET; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6279 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6280 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6281 | if (num_attributes > 0) |
| 6282 | { |
| 6283 | uint32_t i; |
| 6284 | |
| 6285 | for (i=0; i<num_attributes; ++i) |
| 6286 | { |
| 6287 | attr = attributes.AttributeAtIndex(i); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6288 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 6289 | { |
| 6290 | switch (attr) |
| 6291 | { |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 6292 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 6293 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 6294 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6295 | case DW_AT_name: |
| 6296 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6297 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6298 | break; |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 6299 | case DW_AT_type: encoding_uid = form_value.Reference(); break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6300 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; |
| 6301 | case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 6302 | case DW_AT_declaration: break; //is_forward_declaration = form_value.Boolean(); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6303 | case DW_AT_allocated: |
| 6304 | case DW_AT_associated: |
| 6305 | case DW_AT_bit_stride: |
| 6306 | case DW_AT_byte_stride: |
| 6307 | case DW_AT_data_location: |
| 6308 | case DW_AT_description: |
| 6309 | case DW_AT_start_scope: |
| 6310 | case DW_AT_visibility: |
| 6311 | case DW_AT_specification: |
| 6312 | case DW_AT_abstract_origin: |
| 6313 | case DW_AT_sibling: |
| 6314 | break; |
| 6315 | } |
| 6316 | } |
| 6317 | } |
| 6318 | |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6319 | DEBUG_PRINTF ("0x%8.8" PRIx64 ": %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] | 6320 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6321 | ClangASTType enumerator_clang_type; |
| 6322 | clang_type.SetClangType (ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die)); |
| 6323 | if (!clang_type) |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6324 | { |
| Greg Clayton | 5d14fc0 | 2013-03-06 06:23:54 +0000 | [diff] [blame] | 6325 | if (encoding_uid != DW_INVALID_OFFSET) |
| 6326 | { |
| 6327 | Type *enumerator_type = ResolveTypeUID(encoding_uid); |
| 6328 | if (enumerator_type) |
| 6329 | enumerator_clang_type = enumerator_type->GetClangFullType(); |
| 6330 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6331 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6332 | if (!enumerator_clang_type) |
| Greg Clayton | 5d14fc0 | 2013-03-06 06:23:54 +0000 | [diff] [blame] | 6333 | enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL, |
| 6334 | DW_ATE_signed, |
| 6335 | byte_size * 8); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6336 | |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 6337 | clang_type = ast.CreateEnumerationType (type_name_cstr, |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6338 | GetClangDeclContextContainingDIE (dwarf_cu, die, NULL), |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 6339 | decl, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6340 | enumerator_clang_type); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6341 | } |
| 6342 | else |
| 6343 | { |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6344 | enumerator_clang_type = clang_type.GetEnumerationIntegerType (); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6345 | } |
| 6346 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6347 | LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6348 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6349 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6350 | this, |
| 6351 | type_name_const_str, |
| 6352 | byte_size, |
| 6353 | NULL, |
| 6354 | encoding_uid, |
| 6355 | Type::eEncodingIsUID, |
| 6356 | &decl, |
| 6357 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6358 | Type::eResolveStateForward)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6359 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6360 | clang_type.StartTagDeclarationDefinition (); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 6361 | if (die->HasChildren()) |
| 6362 | { |
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 6363 | SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); |
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 6364 | bool is_signed = false; |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6365 | enumerator_clang_type.IsIntegerType(is_signed); |
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 6366 | ParseChildEnumerators(cu_sc, clang_type, is_signed, type_sp->GetByteSize(), dwarf_cu, die); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 6367 | } |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6368 | clang_type.CompleteTagDeclarationDefinition (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6369 | } |
| 6370 | } |
| 6371 | break; |
| 6372 | |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 6373 | case DW_TAG_inlined_subroutine: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6374 | case DW_TAG_subprogram: |
| 6375 | case DW_TAG_subroutine_type: |
| 6376 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6377 | // 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] | 6378 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6379 | |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6380 | //const char *mangled = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6381 | dw_offset_t type_die_offset = DW_INVALID_OFFSET; |
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 6382 | bool is_variadic = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6383 | bool is_inline = false; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6384 | bool is_static = false; |
| 6385 | bool is_virtual = false; |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6386 | bool is_explicit = false; |
| Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 6387 | bool is_artificial = false; |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6388 | dw_offset_t specification_die_offset = DW_INVALID_OFFSET; |
| 6389 | dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET; |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6390 | dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6391 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6392 | unsigned type_quals = 0; |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 6393 | clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6394 | |
| 6395 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6396 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6397 | if (num_attributes > 0) |
| 6398 | { |
| 6399 | uint32_t i; |
| 6400 | for (i=0; i<num_attributes; ++i) |
| 6401 | { |
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 6402 | attr = attributes.AttributeAtIndex(i); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6403 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 6404 | { |
| 6405 | switch (attr) |
| 6406 | { |
| 6407 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 6408 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 6409 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 6410 | case DW_AT_name: |
| 6411 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6412 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6413 | break; |
| 6414 | |
| Greg Clayton | 7141554 | 2012-12-08 00:24:40 +0000 | [diff] [blame] | 6415 | case DW_AT_linkage_name: |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6416 | case DW_AT_MIPS_linkage_name: break; // mangled = form_value.AsCString(&get_debug_str_data()); break; |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 6417 | case DW_AT_type: type_die_offset = form_value.Reference(); break; |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 6418 | case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 6419 | case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break; |
| 6420 | case DW_AT_inline: is_inline = form_value.Boolean(); break; |
| 6421 | case DW_AT_virtuality: is_virtual = form_value.Boolean(); break; |
| 6422 | case DW_AT_explicit: is_explicit = form_value.Boolean(); break; |
| 6423 | case DW_AT_artificial: is_artificial = form_value.Boolean(); break; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6424 | |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6425 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6426 | case DW_AT_external: |
| 6427 | if (form_value.Unsigned()) |
| 6428 | { |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 6429 | if (storage == clang::SC_None) |
| 6430 | storage = clang::SC_Extern; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6431 | else |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 6432 | storage = clang::SC_PrivateExtern; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6433 | } |
| 6434 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6435 | |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6436 | case DW_AT_specification: |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 6437 | specification_die_offset = form_value.Reference(); |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6438 | break; |
| 6439 | |
| 6440 | case DW_AT_abstract_origin: |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 6441 | abstract_origin_die_offset = form_value.Reference(); |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6442 | break; |
| 6443 | |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6444 | case DW_AT_object_pointer: |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 6445 | object_pointer_die_offset = form_value.Reference(); |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6446 | break; |
| 6447 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6448 | case DW_AT_allocated: |
| 6449 | case DW_AT_associated: |
| 6450 | case DW_AT_address_class: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6451 | case DW_AT_calling_convention: |
| 6452 | case DW_AT_data_location: |
| 6453 | case DW_AT_elemental: |
| 6454 | case DW_AT_entry_pc: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6455 | case DW_AT_frame_base: |
| 6456 | case DW_AT_high_pc: |
| 6457 | case DW_AT_low_pc: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6458 | case DW_AT_prototyped: |
| 6459 | case DW_AT_pure: |
| 6460 | case DW_AT_ranges: |
| 6461 | case DW_AT_recursive: |
| 6462 | case DW_AT_return_addr: |
| 6463 | case DW_AT_segment: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6464 | case DW_AT_start_scope: |
| 6465 | case DW_AT_static_link: |
| 6466 | case DW_AT_trampoline: |
| 6467 | case DW_AT_visibility: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6468 | case DW_AT_vtable_elem_location: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6469 | case DW_AT_description: |
| 6470 | case DW_AT_sibling: |
| 6471 | break; |
| 6472 | } |
| 6473 | } |
| 6474 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6475 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6476 | |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6477 | std::string object_pointer_name; |
| 6478 | if (object_pointer_die_offset != DW_INVALID_OFFSET) |
| 6479 | { |
| 6480 | // Get the name from the object pointer die |
| 6481 | StreamString s; |
| 6482 | if (DWARFDebugInfoEntry::GetName (this, dwarf_cu, object_pointer_die_offset, s)) |
| 6483 | { |
| 6484 | object_pointer_name.assign(s.GetData()); |
| 6485 | } |
| 6486 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6487 | |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6488 | DEBUG_PRINTF ("0x%8.8" PRIx64 ": %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] | 6489 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6490 | ClangASTType return_clang_type; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6491 | Type *func_type = NULL; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6492 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6493 | if (type_die_offset != DW_INVALID_OFFSET) |
| 6494 | func_type = ResolveTypeUID(type_die_offset); |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6495 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6496 | if (func_type) |
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 6497 | return_clang_type = func_type->GetClangForwardType(); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6498 | else |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6499 | return_clang_type = ast.GetBasicType(eBasicTypeVoid); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6500 | |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6501 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6502 | std::vector<ClangASTType> function_param_types; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6503 | std::vector<clang::ParmVarDecl*> function_param_decls; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6504 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6505 | // Parse the function children for the parameters |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6506 | |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6507 | const DWARFDebugInfoEntry *decl_ctx_die = NULL; |
| 6508 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die); |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6509 | const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind(); |
| 6510 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6511 | const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind); |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6512 | // Start off static. This will be set to false in ParseChildParameters(...) |
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 6513 | // if we find a "this" parameters as the first parameter |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6514 | if (is_cxx_method) |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 6515 | is_static = true; |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 6516 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6517 | if (die->HasChildren()) |
| 6518 | { |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6519 | bool skip_artificial = true; |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6520 | ParseChildParameters (sc, |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6521 | containing_decl_ctx, |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6522 | dwarf_cu, |
| 6523 | die, |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 6524 | skip_artificial, |
| 6525 | is_static, |
| Greg Clayton | 0396975 | 2014-02-24 18:53:11 +0000 | [diff] [blame] | 6526 | is_variadic, |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6527 | type_list, |
| 6528 | function_param_types, |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 6529 | function_param_decls, |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 6530 | type_quals); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6531 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6532 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6533 | // clang_type will get the function prototype clang type after this call |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6534 | clang_type = ast.CreateFunctionType (return_clang_type, |
| Greg Clayton | 9cb25c4 | 2012-10-30 17:02:18 +0000 | [diff] [blame] | 6535 | function_param_types.data(), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6536 | function_param_types.size(), |
| 6537 | is_variadic, |
| 6538 | type_quals); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6539 | |
| Sean Callanan | de9ce87 | 2013-05-09 23:13:13 +0000 | [diff] [blame] | 6540 | bool ignore_containing_context = false; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6541 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6542 | if (type_name_cstr) |
| 6543 | { |
| 6544 | bool type_handled = false; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6545 | if (tag == DW_TAG_subprogram) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6546 | { |
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 6547 | ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true); |
| 6548 | if (objc_method.IsValid(true)) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6549 | { |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6550 | ClangASTType class_opaque_type; |
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 6551 | ConstString class_name(objc_method.GetClassName()); |
| Greg Clayton | 7c81042 | 2012-01-18 23:40:49 +0000 | [diff] [blame] | 6552 | if (class_name) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6553 | { |
| Greg Clayton | 278a16b | 2012-01-19 00:52:59 +0000 | [diff] [blame] | 6554 | TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false)); |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6555 | |
| 6556 | if (complete_objc_class_type_sp) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6557 | { |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6558 | ClangASTType type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType(); |
| 6559 | if (type_clang_forward_type.IsObjCObjectOrInterfaceType ()) |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6560 | class_opaque_type = type_clang_forward_type; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6561 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6562 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6563 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6564 | if (class_opaque_type) |
| 6565 | { |
| 6566 | // If accessibility isn't set to anything valid, assume public for |
| 6567 | // now... |
| 6568 | if (accessibility == eAccessNone) |
| 6569 | accessibility = eAccessPublic; |
| 6570 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6571 | clang::ObjCMethodDecl *objc_method_decl = class_opaque_type.AddMethodToObjCObjectType (type_name_cstr, |
| 6572 | clang_type, |
| 6573 | accessibility, |
| 6574 | is_artificial); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6575 | type_handled = objc_method_decl != NULL; |
| Sean Callanan | 464a5b5 | 2012-10-04 22:06:29 +0000 | [diff] [blame] | 6576 | if (type_handled) |
| 6577 | { |
| 6578 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die); |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6579 | GetClangASTContext().SetMetadataAsUserID (objc_method_decl, MakeUserID(die->GetOffset())); |
| Sean Callanan | 464a5b5 | 2012-10-04 22:06:29 +0000 | [diff] [blame] | 6580 | } |
| Sean Callanan | c3a1d56 | 2013-02-06 23:21:59 +0000 | [diff] [blame] | 6581 | else |
| 6582 | { |
| Jason Molenda | c1a6583 | 2013-03-07 22:44:42 +0000 | [diff] [blame] | 6583 | GetObjectFile()->GetModule()->ReportError ("{0x%8.8x}: invalid Objective-C method 0x%4.4x (%s), please file a bug and attach the file at the start of this error message", |
| Sean Callanan | c3a1d56 | 2013-02-06 23:21:59 +0000 | [diff] [blame] | 6584 | die->GetOffset(), |
| 6585 | tag, |
| 6586 | DW_TAG_value_to_name(tag)); |
| 6587 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6588 | } |
| 6589 | } |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6590 | else if (is_cxx_method) |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6591 | { |
| 6592 | // Look at the parent of this DIE and see if is is |
| 6593 | // a class or struct and see if this is actually a |
| 6594 | // C++ method |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6595 | Type *class_type = ResolveType (dwarf_cu, decl_ctx_die); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6596 | if (class_type) |
| 6597 | { |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6598 | if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset())) |
| 6599 | { |
| 6600 | // We uniqued the parent class of this function to another class |
| 6601 | // so we now need to associate all dies under "decl_ctx_die" to |
| 6602 | // DIEs in the DIE for "class_type"... |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 6603 | SymbolFileDWARF *class_symfile = NULL; |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6604 | DWARFCompileUnitSP class_type_cu_sp; |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 6605 | const DWARFDebugInfoEntry *class_type_die = NULL; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6606 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6607 | SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile(); |
| 6608 | if (debug_map_symfile) |
| 6609 | { |
| 6610 | class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID())); |
| 6611 | class_type_die = class_symfile->DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp); |
| 6612 | } |
| 6613 | else |
| 6614 | { |
| 6615 | class_symfile = this; |
| 6616 | class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp); |
| 6617 | } |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6618 | if (class_type_die) |
| 6619 | { |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 6620 | DWARFDIECollection failures; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6621 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6622 | CopyUniqueClassMethodTypes (class_symfile, |
| 6623 | class_type, |
| 6624 | class_type_cu_sp.get(), |
| 6625 | class_type_die, |
| 6626 | dwarf_cu, |
| 6627 | decl_ctx_die, |
| 6628 | failures); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6629 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6630 | // FIXME do something with these failures that's smarter than |
| 6631 | // just dropping them on the ground. Unfortunately classes don't |
| 6632 | // like having stuff added to them after their definitions are |
| 6633 | // complete... |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6634 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6635 | type_ptr = m_die_to_type[die]; |
| 6636 | if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6637 | { |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6638 | type_sp = type_ptr->shared_from_this(); |
| 6639 | break; |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6640 | } |
| 6641 | } |
| 6642 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6643 | |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6644 | if (specification_die_offset != DW_INVALID_OFFSET) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6645 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6646 | // We have a specification which we are going to base our function |
| 6647 | // prototype off of, so we need this type to be completed so that the |
| 6648 | // m_die_to_decl_ctx for the method in the specification has a valid |
| 6649 | // clang decl context. |
| Greg Clayton | 8eb732e | 2011-12-13 04:34:06 +0000 | [diff] [blame] | 6650 | class_type->GetClangForwardType(); |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6651 | // If we have a specification, then the function type should have been |
| 6652 | // made with the specification and not with this die. |
| 6653 | DWARFCompileUnitSP spec_cu_sp; |
| 6654 | const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp); |
| Eric Christopher | 6cc6e60 | 2012-03-25 19:37:33 +0000 | [diff] [blame] | 6655 | clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die); |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6656 | if (spec_clang_decl_ctx) |
| 6657 | { |
| 6658 | LinkDeclContextToDIE(spec_clang_decl_ctx, die); |
| 6659 | } |
| 6660 | else |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6661 | { |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6662 | GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_specification(0x%8.8x) has no decl\n", |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6663 | MakeUserID(die->GetOffset()), |
| 6664 | specification_die_offset); |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6665 | } |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6666 | type_handled = true; |
| 6667 | } |
| 6668 | else if (abstract_origin_die_offset != DW_INVALID_OFFSET) |
| 6669 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6670 | // We have a specification which we are going to base our function |
| 6671 | // prototype off of, so we need this type to be completed so that the |
| 6672 | // m_die_to_decl_ctx for the method in the abstract origin has a valid |
| 6673 | // clang decl context. |
| Greg Clayton | 8eb732e | 2011-12-13 04:34:06 +0000 | [diff] [blame] | 6674 | class_type->GetClangForwardType(); |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6675 | |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6676 | DWARFCompileUnitSP abs_cu_sp; |
| 6677 | 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] | 6678 | clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die); |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6679 | if (abs_clang_decl_ctx) |
| 6680 | { |
| 6681 | LinkDeclContextToDIE (abs_clang_decl_ctx, die); |
| 6682 | } |
| 6683 | else |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6684 | { |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6685 | GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_abstract_origin(0x%8.8x) has no decl\n", |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6686 | MakeUserID(die->GetOffset()), |
| 6687 | abstract_origin_die_offset); |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6688 | } |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6689 | type_handled = true; |
| 6690 | } |
| 6691 | else |
| 6692 | { |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6693 | ClangASTType class_opaque_type = class_type->GetClangForwardType(); |
| 6694 | if (class_opaque_type.IsCXXClassType ()) |
| Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 6695 | { |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6696 | if (class_opaque_type.IsBeingDefined ()) |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6697 | { |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6698 | // Neither GCC 4.2 nor clang++ currently set a valid accessibility |
| 6699 | // in the DWARF for C++ methods... Default to public for now... |
| 6700 | if (accessibility == eAccessNone) |
| 6701 | accessibility = eAccessPublic; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6702 | |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6703 | if (!is_static && !die->HasChildren()) |
| 6704 | { |
| 6705 | // We have a C++ member function with no children (this pointer!) |
| 6706 | // and clang will get mad if we try and make a function that isn't |
| 6707 | // well formed in the DWARF, so we will just skip it... |
| 6708 | type_handled = true; |
| 6709 | } |
| 6710 | else |
| 6711 | { |
| 6712 | clang::CXXMethodDecl *cxx_method_decl; |
| 6713 | // REMOVE THE CRASH DESCRIPTION BELOW |
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 6714 | Host::SetCrashDescriptionWithFormat ("SymbolFileDWARF::ParseType() is adding a method %s to class %s in DIE 0x%8.8" PRIx64 " from %s", |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6715 | type_name_cstr, |
| 6716 | class_type->GetName().GetCString(), |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6717 | MakeUserID(die->GetOffset()), |
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 6718 | m_obj_file->GetFileSpec().GetPath().c_str()); |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6719 | |
| Sean Callanan | c1b732d | 2011-11-01 18:07:13 +0000 | [diff] [blame] | 6720 | const bool is_attr_used = false; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6721 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6722 | cxx_method_decl = class_opaque_type.AddMethodToCXXRecordType (type_name_cstr, |
| 6723 | clang_type, |
| 6724 | accessibility, |
| 6725 | is_virtual, |
| 6726 | is_static, |
| 6727 | is_inline, |
| 6728 | is_explicit, |
| 6729 | is_attr_used, |
| 6730 | is_artificial); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6731 | |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6732 | type_handled = cxx_method_decl != NULL; |
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6733 | |
| 6734 | if (type_handled) |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6735 | { |
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6736 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die); |
| 6737 | |
| 6738 | Host::SetCrashDescription (NULL); |
| 6739 | |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6740 | |
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6741 | ClangASTMetadata metadata; |
| 6742 | metadata.SetUserID(MakeUserID(die->GetOffset())); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6743 | |
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6744 | if (!object_pointer_name.empty()) |
| 6745 | { |
| 6746 | metadata.SetObjectPtrName(object_pointer_name.c_str()); |
| 6747 | if (log) |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6748 | log->Printf ("Setting object pointer name: %s on method object %p.\n", |
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6749 | object_pointer_name.c_str(), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6750 | static_cast<void*>(cxx_method_decl)); |
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6751 | } |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6752 | GetClangASTContext().SetMetadata (cxx_method_decl, metadata); |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6753 | } |
| Sean Callanan | b0640dc | 2013-04-09 23:22:08 +0000 | [diff] [blame] | 6754 | else |
| 6755 | { |
| Sean Callanan | de9ce87 | 2013-05-09 23:13:13 +0000 | [diff] [blame] | 6756 | ignore_containing_context = true; |
| Sean Callanan | b0640dc | 2013-04-09 23:22:08 +0000 | [diff] [blame] | 6757 | } |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6758 | } |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6759 | } |
| 6760 | else |
| 6761 | { |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6762 | // We were asked to parse the type for a method in a class, yet the |
| 6763 | // class hasn't been asked to complete itself through the |
| 6764 | // clang::ExternalASTSource protocol, so we need to just have the |
| 6765 | // class complete itself and do things the right way, then our |
| 6766 | // DIE should then have an entry in the m_die_to_type map. First |
| 6767 | // we need to modify the m_die_to_type so it doesn't think we are |
| 6768 | // trying to parse this DIE anymore... |
| 6769 | m_die_to_type[die] = NULL; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6770 | |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6771 | // Now we get the full type to force our class type to complete itself |
| 6772 | // using the clang::ExternalASTSource protocol which will parse all |
| 6773 | // base classes and all methods (including the method for this DIE). |
| 6774 | class_type->GetClangFullType(); |
| Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 6775 | |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6776 | // The type for this DIE should have been filled in the function call above |
| 6777 | type_ptr = m_die_to_type[die]; |
| Greg Clayton | e5476db | 2012-06-01 20:32:35 +0000 | [diff] [blame] | 6778 | if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6779 | { |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 6780 | type_sp = type_ptr->shared_from_this(); |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6781 | break; |
| 6782 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6783 | |
| Sean Callanan | 02eee4d | 2012-04-12 23:10:00 +0000 | [diff] [blame] | 6784 | // FIXME This is fixing some even uglier behavior but we really need to |
| 6785 | // uniq the methods of each class as well as the class itself. |
| 6786 | // <rdar://problem/11240464> |
| 6787 | type_handled = true; |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6788 | } |
| Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 6789 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6790 | } |
| 6791 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6792 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6793 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6794 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6795 | if (!type_handled) |
| 6796 | { |
| 6797 | // We just have a function that isn't part of a class |
| Sean Callanan | de9ce87 | 2013-05-09 23:13:13 +0000 | [diff] [blame] | 6798 | clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (ignore_containing_context ? GetClangASTContext().GetTranslationUnitDecl() : containing_decl_ctx, |
| Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 6799 | type_name_cstr, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6800 | clang_type, |
| 6801 | storage, |
| 6802 | is_inline); |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 6803 | |
| 6804 | // if (template_param_infos.GetSize() > 0) |
| 6805 | // { |
| 6806 | // clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx, |
| 6807 | // function_decl, |
| 6808 | // type_name_cstr, |
| 6809 | // template_param_infos); |
| 6810 | // |
| 6811 | // ast.CreateFunctionTemplateSpecializationInfo (function_decl, |
| 6812 | // func_template_decl, |
| 6813 | // template_param_infos); |
| 6814 | // } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6815 | // Add the decl to our DIE to decl context map |
| 6816 | assert (function_decl); |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6817 | LinkDeclContextToDIE(function_decl, die); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6818 | if (!function_param_decls.empty()) |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6819 | ast.SetFunctionParameters (function_decl, |
| 6820 | &function_param_decls.front(), |
| 6821 | function_param_decls.size()); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6822 | |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6823 | ClangASTMetadata metadata; |
| 6824 | metadata.SetUserID(MakeUserID(die->GetOffset())); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6825 | |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6826 | if (!object_pointer_name.empty()) |
| 6827 | { |
| 6828 | metadata.SetObjectPtrName(object_pointer_name.c_str()); |
| Jim Ingham | 2cffda3f | 2012-10-30 23:34:07 +0000 | [diff] [blame] | 6829 | if (log) |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6830 | log->Printf ("Setting object pointer name: %s on function object %p.", |
| Jim Ingham | 2cffda3f | 2012-10-30 23:34:07 +0000 | [diff] [blame] | 6831 | object_pointer_name.c_str(), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6832 | static_cast<void*>(function_decl)); |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6833 | } |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6834 | GetClangASTContext().SetMetadata (function_decl, metadata); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6835 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6836 | } |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6837 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6838 | this, |
| 6839 | type_name_const_str, |
| 6840 | 0, |
| 6841 | NULL, |
| 6842 | LLDB_INVALID_UID, |
| 6843 | Type::eEncodingIsUID, |
| 6844 | &decl, |
| 6845 | clang_type, |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6846 | Type::eResolveStateFull)); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6847 | assert(type_sp.get()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6848 | } |
| 6849 | break; |
| 6850 | |
| 6851 | case DW_TAG_array_type: |
| 6852 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6853 | // 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] | 6854 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6855 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6856 | lldb::user_id_t type_die_offset = DW_INVALID_OFFSET; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6857 | int64_t first_index = 0; |
| 6858 | uint32_t byte_stride = 0; |
| 6859 | uint32_t bit_stride = 0; |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 6860 | bool is_vector = false; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6861 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6862 | |
| 6863 | if (num_attributes > 0) |
| 6864 | { |
| 6865 | uint32_t i; |
| 6866 | for (i=0; i<num_attributes; ++i) |
| 6867 | { |
| 6868 | attr = attributes.AttributeAtIndex(i); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6869 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 6870 | { |
| 6871 | switch (attr) |
| 6872 | { |
| 6873 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 6874 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 6875 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 6876 | case DW_AT_name: |
| 6877 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6878 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6879 | break; |
| 6880 | |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 6881 | case DW_AT_type: type_die_offset = form_value.Reference(); break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6882 | case DW_AT_byte_size: break; // byte_size = form_value.Unsigned(); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6883 | case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break; |
| 6884 | case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break; |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 6885 | case DW_AT_GNU_vector: is_vector = form_value.Boolean(); break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6886 | case DW_AT_accessibility: break; // accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 6887 | case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6888 | case DW_AT_allocated: |
| 6889 | case DW_AT_associated: |
| 6890 | case DW_AT_data_location: |
| 6891 | case DW_AT_description: |
| 6892 | case DW_AT_ordering: |
| 6893 | case DW_AT_start_scope: |
| 6894 | case DW_AT_visibility: |
| 6895 | case DW_AT_specification: |
| 6896 | case DW_AT_abstract_origin: |
| 6897 | case DW_AT_sibling: |
| 6898 | break; |
| 6899 | } |
| 6900 | } |
| 6901 | } |
| 6902 | |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6903 | DEBUG_PRINTF ("0x%8.8" PRIx64 ": %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] | 6904 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6905 | Type *element_type = ResolveTypeUID(type_die_offset); |
| 6906 | |
| 6907 | if (element_type) |
| 6908 | { |
| 6909 | std::vector<uint64_t> element_orders; |
| 6910 | ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride); |
| 6911 | if (byte_stride == 0 && bit_stride == 0) |
| 6912 | byte_stride = element_type->GetByteSize(); |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6913 | ClangASTType array_element_type = element_type->GetClangForwardType(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6914 | uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride; |
| Siva Chandra | 89ce955 | 2015-01-05 23:06:14 +0000 | [diff] [blame] | 6915 | if (element_orders.size() > 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6916 | { |
| Siva Chandra | 89ce955 | 2015-01-05 23:06:14 +0000 | [diff] [blame] | 6917 | uint64_t num_elements = 0; |
| 6918 | std::vector<uint64_t>::const_reverse_iterator pos; |
| 6919 | std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend(); |
| 6920 | for (pos = element_orders.rbegin(); pos != end; ++pos) |
| 6921 | { |
| 6922 | num_elements = *pos; |
| 6923 | clang_type = ast.CreateArrayType (array_element_type, |
| 6924 | num_elements, |
| 6925 | is_vector); |
| 6926 | array_element_type = clang_type; |
| 6927 | array_element_bit_stride = num_elements ? |
| 6928 | array_element_bit_stride * num_elements : |
| 6929 | array_element_bit_stride; |
| 6930 | } |
| 6931 | } |
| 6932 | else |
| 6933 | { |
| 6934 | clang_type = ast.CreateArrayType (array_element_type, 0, is_vector); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6935 | } |
| 6936 | ConstString empty_name; |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6937 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6938 | this, |
| 6939 | empty_name, |
| 6940 | array_element_bit_stride / 8, |
| 6941 | NULL, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6942 | type_die_offset, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6943 | Type::eEncodingIsUID, |
| 6944 | &decl, |
| 6945 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6946 | Type::eResolveStateFull)); |
| 6947 | type_sp->SetEncodingType (element_type); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6948 | } |
| 6949 | } |
| 6950 | } |
| 6951 | break; |
| 6952 | |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6953 | case DW_TAG_ptr_to_member_type: |
| 6954 | { |
| 6955 | dw_offset_t type_die_offset = DW_INVALID_OFFSET; |
| 6956 | dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET; |
| 6957 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6958 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6959 | |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6960 | if (num_attributes > 0) { |
| 6961 | uint32_t i; |
| 6962 | for (i=0; i<num_attributes; ++i) |
| 6963 | { |
| 6964 | attr = attributes.AttributeAtIndex(i); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6965 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 6966 | { |
| 6967 | switch (attr) |
| 6968 | { |
| 6969 | case DW_AT_type: |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 6970 | type_die_offset = form_value.Reference(); break; |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6971 | case DW_AT_containing_type: |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 6972 | containing_type_die_offset = form_value.Reference(); break; |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6973 | } |
| 6974 | } |
| 6975 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6976 | |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6977 | Type *pointee_type = ResolveTypeUID(type_die_offset); |
| 6978 | Type *class_type = ResolveTypeUID(containing_type_die_offset); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6979 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6980 | ClangASTType pointee_clang_type = pointee_type->GetClangForwardType(); |
| 6981 | ClangASTType class_clang_type = class_type->GetClangLayoutType(); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6982 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6983 | clang_type = pointee_clang_type.CreateMemberPointerType(class_clang_type); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6984 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6985 | byte_size = clang_type.GetByteSize(); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6986 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6987 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6988 | this, |
| 6989 | type_name_const_str, |
| 6990 | byte_size, |
| 6991 | NULL, |
| 6992 | LLDB_INVALID_UID, |
| 6993 | Type::eEncodingIsUID, |
| 6994 | NULL, |
| 6995 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6996 | Type::eResolveStateForward)); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6997 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6998 | |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6999 | break; |
| 7000 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7001 | default: |
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 7002 | GetObjectFile()->GetModule()->ReportError ("{0x%8.8x}: unhandled type tag 0x%4.4x (%s), please file a bug and attach the file at the start of this error message", |
| 7003 | die->GetOffset(), |
| 7004 | tag, |
| 7005 | DW_TAG_value_to_name(tag)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7006 | break; |
| 7007 | } |
| 7008 | |
| 7009 | if (type_sp.get()) |
| 7010 | { |
| 7011 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); |
| 7012 | dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
| 7013 | |
| 7014 | SymbolContextScope * symbol_context_scope = NULL; |
| 7015 | if (sc_parent_tag == DW_TAG_compile_unit) |
| 7016 | { |
| 7017 | symbol_context_scope = sc.comp_unit; |
| 7018 | } |
| Jason Molenda | 60db6e4 | 2014-10-16 01:40:16 +0000 | [diff] [blame] | 7019 | else if (sc.function != NULL && sc_parent_die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7020 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7021 | 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] | 7022 | if (symbol_context_scope == NULL) |
| 7023 | symbol_context_scope = sc.function; |
| 7024 | } |
| 7025 | |
| 7026 | if (symbol_context_scope != NULL) |
| 7027 | { |
| 7028 | type_sp->SetSymbolContextScope(symbol_context_scope); |
| 7029 | } |
| 7030 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 7031 | // We are ready to put this type into the uniqued list up at the module level |
| 7032 | type_list->Insert (type_sp); |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 7033 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 7034 | m_die_to_type[die] = type_sp.get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7035 | } |
| 7036 | } |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 7037 | else if (type_ptr != DIE_IS_BEING_PARSED) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7038 | { |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 7039 | type_sp = type_ptr->shared_from_this(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7040 | } |
| 7041 | } |
| 7042 | return type_sp; |
| 7043 | } |
| 7044 | |
| 7045 | size_t |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 7046 | SymbolFileDWARF::ParseTypes |
| 7047 | ( |
| 7048 | const SymbolContext& sc, |
| 7049 | DWARFCompileUnit* dwarf_cu, |
| 7050 | const DWARFDebugInfoEntry *die, |
| 7051 | bool parse_siblings, |
| 7052 | bool parse_children |
| 7053 | ) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7054 | { |
| 7055 | size_t types_added = 0; |
| 7056 | while (die != NULL) |
| 7057 | { |
| 7058 | bool type_is_new = false; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 7059 | if (ParseType(sc, dwarf_cu, die, &type_is_new).get()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7060 | { |
| 7061 | if (type_is_new) |
| 7062 | ++types_added; |
| 7063 | } |
| 7064 | |
| 7065 | if (parse_children && die->HasChildren()) |
| 7066 | { |
| 7067 | if (die->Tag() == DW_TAG_subprogram) |
| 7068 | { |
| 7069 | SymbolContext child_sc(sc); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7070 | child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7071 | types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true); |
| 7072 | } |
| 7073 | else |
| 7074 | types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true); |
| 7075 | } |
| 7076 | |
| 7077 | if (parse_siblings) |
| 7078 | die = die->GetSibling(); |
| 7079 | else |
| 7080 | die = NULL; |
| 7081 | } |
| 7082 | return types_added; |
| 7083 | } |
| 7084 | |
| 7085 | |
| 7086 | size_t |
| 7087 | SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc) |
| 7088 | { |
| 7089 | assert(sc.comp_unit && sc.function); |
| 7090 | size_t functions_added = 0; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 7091 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7092 | if (dwarf_cu) |
| 7093 | { |
| 7094 | dw_offset_t function_die_offset = sc.function->GetID(); |
| 7095 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset); |
| 7096 | if (function_die) |
| 7097 | { |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 7098 | 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] | 7099 | } |
| 7100 | } |
| 7101 | |
| 7102 | return functions_added; |
| 7103 | } |
| 7104 | |
| 7105 | |
| 7106 | size_t |
| 7107 | SymbolFileDWARF::ParseTypes (const SymbolContext &sc) |
| 7108 | { |
| 7109 | // At least a compile unit must be valid |
| 7110 | assert(sc.comp_unit); |
| 7111 | size_t types_added = 0; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 7112 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7113 | if (dwarf_cu) |
| 7114 | { |
| 7115 | if (sc.function) |
| 7116 | { |
| 7117 | dw_offset_t function_die_offset = sc.function->GetID(); |
| 7118 | const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset); |
| 7119 | if (func_die && func_die->HasChildren()) |
| 7120 | { |
| 7121 | types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true); |
| 7122 | } |
| 7123 | } |
| 7124 | else |
| 7125 | { |
| 7126 | const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE(); |
| 7127 | if (dwarf_cu_die && dwarf_cu_die->HasChildren()) |
| 7128 | { |
| 7129 | types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true); |
| 7130 | } |
| 7131 | } |
| 7132 | } |
| 7133 | |
| 7134 | return types_added; |
| 7135 | } |
| 7136 | |
| 7137 | size_t |
| 7138 | SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc) |
| 7139 | { |
| 7140 | if (sc.comp_unit != NULL) |
| 7141 | { |
| Greg Clayton | 4b3dc10 | 2010-11-01 20:32:12 +0000 | [diff] [blame] | 7142 | DWARFDebugInfo* info = DebugInfo(); |
| 7143 | if (info == NULL) |
| 7144 | return 0; |
| 7145 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7146 | if (sc.function) |
| 7147 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7148 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnitContainingDIE(sc.function->GetID()).get(); |
| 7149 | |
| 7150 | if (dwarf_cu == NULL) |
| 7151 | return 0; |
| 7152 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7153 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID()); |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 7154 | |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 7155 | dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS); |
| 7156 | if (func_lo_pc != LLDB_INVALID_ADDRESS) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 7157 | { |
| 7158 | 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] | 7159 | |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 7160 | // Let all blocks know they have parse all their variables |
| 7161 | sc.function->GetBlock (false).SetDidParseVariables (true, true); |
| 7162 | return num_variables; |
| 7163 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7164 | } |
| 7165 | else if (sc.comp_unit) |
| 7166 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7167 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()).get(); |
| 7168 | |
| 7169 | if (dwarf_cu == NULL) |
| 7170 | return 0; |
| 7171 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7172 | uint32_t vars_added = 0; |
| 7173 | VariableListSP variables (sc.comp_unit->GetVariableList(false)); |
| 7174 | |
| 7175 | if (variables.get() == NULL) |
| 7176 | { |
| 7177 | variables.reset(new VariableList()); |
| 7178 | sc.comp_unit->SetVariableList(variables); |
| 7179 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7180 | DWARFCompileUnit* match_dwarf_cu = NULL; |
| 7181 | const DWARFDebugInfoEntry* die = NULL; |
| 7182 | DIEArray die_offsets; |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 7183 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7184 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 7185 | if (m_apple_names_ap.get()) |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7186 | { |
| 7187 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 7188 | if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(), |
| 7189 | dwarf_cu->GetNextCompileUnitOffset(), |
| 7190 | hash_data_array)) |
| 7191 | { |
| 7192 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| 7193 | } |
| 7194 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7195 | } |
| 7196 | else |
| 7197 | { |
| 7198 | // Index if we already haven't to make sure the compile units |
| 7199 | // get indexed and make their global DIE index list |
| 7200 | if (!m_indexed) |
| 7201 | Index (); |
| 7202 | |
| 7203 | m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(), |
| 7204 | dwarf_cu->GetNextCompileUnitOffset(), |
| 7205 | die_offsets); |
| 7206 | } |
| 7207 | |
| 7208 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7209 | if (num_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7210 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7211 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 7212 | for (size_t i=0; i<num_matches; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7213 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7214 | const dw_offset_t die_offset = die_offsets[i]; |
| 7215 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 7216 | if (die) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7217 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 7218 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS)); |
| 7219 | if (var_sp) |
| 7220 | { |
| 7221 | variables->AddVariableIfUnique (var_sp); |
| 7222 | ++vars_added; |
| 7223 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7224 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 7225 | else |
| 7226 | { |
| 7227 | if (m_using_apple_tables) |
| 7228 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 7229 | 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] | 7230 | } |
| 7231 | } |
| 7232 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7233 | } |
| 7234 | } |
| 7235 | } |
| 7236 | return vars_added; |
| 7237 | } |
| 7238 | } |
| 7239 | return 0; |
| 7240 | } |
| 7241 | |
| 7242 | |
| 7243 | VariableSP |
| 7244 | SymbolFileDWARF::ParseVariableDIE |
| 7245 | ( |
| 7246 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 7247 | DWARFCompileUnit* dwarf_cu, |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 7248 | const DWARFDebugInfoEntry *die, |
| 7249 | const lldb::addr_t func_low_pc |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7250 | ) |
| 7251 | { |
| Greg Clayton | 83c5cd9 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 7252 | VariableSP var_sp (m_die_to_variable_sp[die]); |
| 7253 | if (var_sp) |
| 7254 | return var_sp; // Already been parsed! |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7255 | |
| 7256 | const dw_tag_t tag = die->Tag(); |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 7257 | ModuleSP module = GetObjectFile()->GetModule(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7258 | |
| 7259 | if ((tag == DW_TAG_variable) || |
| 7260 | (tag == DW_TAG_constant) || |
| 7261 | (tag == DW_TAG_formal_parameter && sc.function)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7262 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7263 | DWARFDebugInfoEntry::Attributes attributes; |
| 7264 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| 7265 | if (num_attributes > 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7266 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7267 | const char *name = NULL; |
| 7268 | const char *mangled = NULL; |
| 7269 | Declaration decl; |
| 7270 | uint32_t i; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7271 | lldb::user_id_t type_uid = LLDB_INVALID_UID; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7272 | DWARFExpression location; |
| 7273 | bool is_external = false; |
| 7274 | bool is_artificial = false; |
| 7275 | bool location_is_const_value_data = false; |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7276 | bool has_explicit_location = false; |
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 7277 | DWARFFormValue const_value; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 7278 | //AccessType accessibility = eAccessNone; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7279 | |
| 7280 | for (i=0; i<num_attributes; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7281 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7282 | dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 7283 | DWARFFormValue form_value; |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 7284 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7285 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7286 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7287 | switch (attr) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7288 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7289 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 7290 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 7291 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 7292 | case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; |
| Greg Clayton | 7141554 | 2012-12-08 00:24:40 +0000 | [diff] [blame] | 7293 | case DW_AT_linkage_name: |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7294 | case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break; |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 7295 | case DW_AT_type: type_uid = form_value.Reference(); break; |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 7296 | case DW_AT_external: is_external = form_value.Boolean(); break; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7297 | case DW_AT_const_value: |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7298 | // If we have already found a DW_AT_location attribute, ignore this attribute. |
| 7299 | if (!has_explicit_location) |
| 7300 | { |
| 7301 | location_is_const_value_data = true; |
| 7302 | // The constant value will be either a block, a data value or a string. |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 7303 | const DWARFDataExtractor& debug_info_data = get_debug_info_data(); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7304 | if (DWARFFormValue::IsBlockForm(form_value.Form())) |
| 7305 | { |
| 7306 | // Retrieve the value as a block expression. |
| 7307 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 7308 | uint32_t block_length = form_value.Unsigned(); |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 7309 | location.CopyOpcodeData(module, debug_info_data, block_offset, block_length); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7310 | } |
| 7311 | else if (DWARFFormValue::IsDataForm(form_value.Form())) |
| 7312 | { |
| 7313 | // Retrieve the value as a data expression. |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 7314 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (attributes.CompileUnitAtIndex(i)->GetAddressByteSize(), attributes.CompileUnitAtIndex(i)->IsDWARF64()); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7315 | uint32_t data_offset = attributes.DIEOffsetAtIndex(i); |
| 7316 | uint32_t data_length = fixed_form_sizes[form_value.Form()]; |
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 7317 | if (data_length == 0) |
| 7318 | { |
| 7319 | const uint8_t *data_pointer = form_value.BlockData(); |
| 7320 | if (data_pointer) |
| 7321 | { |
| Jason Molenda | 18f5fd3 | 2014-10-16 07:52:17 +0000 | [diff] [blame] | 7322 | form_value.Unsigned(); |
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 7323 | } |
| 7324 | else if (DWARFFormValue::IsDataForm(form_value.Form())) |
| 7325 | { |
| 7326 | // we need to get the byte size of the type later after we create the variable |
| 7327 | const_value = form_value; |
| 7328 | } |
| 7329 | } |
| 7330 | else |
| 7331 | location.CopyOpcodeData(module, debug_info_data, data_offset, data_length); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7332 | } |
| 7333 | else |
| 7334 | { |
| 7335 | // Retrieve the value as a string expression. |
| 7336 | if (form_value.Form() == DW_FORM_strp) |
| 7337 | { |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 7338 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (attributes.CompileUnitAtIndex(i)->GetAddressByteSize(), attributes.CompileUnitAtIndex(i)->IsDWARF64()); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7339 | uint32_t data_offset = attributes.DIEOffsetAtIndex(i); |
| 7340 | uint32_t data_length = fixed_form_sizes[form_value.Form()]; |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 7341 | location.CopyOpcodeData(module, debug_info_data, data_offset, data_length); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7342 | } |
| 7343 | else |
| 7344 | { |
| 7345 | const char *str = form_value.AsCString(&debug_info_data); |
| 7346 | uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart(); |
| 7347 | uint32_t string_length = strlen(str) + 1; |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 7348 | location.CopyOpcodeData(module, debug_info_data, string_offset, string_length); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7349 | } |
| 7350 | } |
| 7351 | } |
| 7352 | break; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7353 | case DW_AT_location: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7354 | { |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7355 | location_is_const_value_data = false; |
| 7356 | has_explicit_location = true; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7357 | if (form_value.BlockData()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7358 | { |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 7359 | const DWARFDataExtractor& debug_info_data = get_debug_info_data(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7360 | |
| 7361 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 7362 | uint32_t block_length = form_value.Unsigned(); |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 7363 | location.CopyOpcodeData(module, get_debug_info_data(), block_offset, block_length); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7364 | } |
| 7365 | else |
| 7366 | { |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 7367 | const DWARFDataExtractor& debug_loc_data = get_debug_loc_data(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7368 | const dw_offset_t debug_loc_offset = form_value.Unsigned(); |
| 7369 | |
| 7370 | size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset); |
| 7371 | if (loc_list_length > 0) |
| 7372 | { |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 7373 | location.CopyOpcodeData(module, debug_loc_data, debug_loc_offset, loc_list_length); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7374 | assert (func_low_pc != LLDB_INVALID_ADDRESS); |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 7375 | location.SetLocationListSlide (func_low_pc - attributes.CompileUnitAtIndex(i)->GetBaseAddress()); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7376 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7377 | } |
| 7378 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7379 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7380 | |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 7381 | case DW_AT_artificial: is_artificial = form_value.Boolean(); break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 7382 | case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7383 | case DW_AT_declaration: |
| 7384 | case DW_AT_description: |
| 7385 | case DW_AT_endianity: |
| 7386 | case DW_AT_segment: |
| 7387 | case DW_AT_start_scope: |
| 7388 | case DW_AT_visibility: |
| 7389 | default: |
| 7390 | case DW_AT_abstract_origin: |
| 7391 | case DW_AT_sibling: |
| 7392 | case DW_AT_specification: |
| 7393 | break; |
| 7394 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7395 | } |
| 7396 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7397 | |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7398 | ValueType scope = eValueTypeInvalid; |
| 7399 | |
| 7400 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); |
| 7401 | dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
| 7402 | SymbolContextScope * symbol_context_scope = NULL; |
| 7403 | |
| 7404 | // DWARF doesn't specify if a DW_TAG_variable is a local, global |
| 7405 | // or static variable, so we have to do a little digging by |
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 7406 | // looking at the location of a variable to see if it contains |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7407 | // a DW_OP_addr opcode _somewhere_ in the definition. I say |
| 7408 | // somewhere because clang likes to combine small global variables |
| 7409 | // into the same symbol and have locations like: |
| 7410 | // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus |
| 7411 | // So if we don't have a DW_TAG_formal_parameter, we can look at |
| 7412 | // the location to see if it contains a DW_OP_addr opcode, and |
| 7413 | // then we can correctly classify our variables. |
| 7414 | if (tag == DW_TAG_formal_parameter) |
| 7415 | scope = eValueTypeVariableArgument; |
| 7416 | else |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7417 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7418 | bool op_error = false; |
| 7419 | // Check if the location has a DW_OP_addr with any address value... |
| 7420 | lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS; |
| 7421 | if (!location_is_const_value_data) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7422 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7423 | location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error); |
| 7424 | if (op_error) |
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 7425 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7426 | StreamString strm; |
| 7427 | location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL); |
| 7428 | 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] | 7429 | } |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7430 | } |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7431 | |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7432 | if (location_DW_OP_addr != LLDB_INVALID_ADDRESS) |
| 7433 | { |
| 7434 | if (is_external) |
| 7435 | scope = eValueTypeVariableGlobal; |
| 7436 | else |
| 7437 | scope = eValueTypeVariableStatic; |
| 7438 | |
| 7439 | |
| 7440 | SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile (); |
| 7441 | |
| 7442 | if (debug_map_symfile) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7443 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7444 | // When leaving the DWARF in the .o files on darwin, |
| 7445 | // when we have a global variable that wasn't initialized, |
| 7446 | // the .o file might not have allocated a virtual |
| 7447 | // address for the global variable. In this case it will |
| 7448 | // have created a symbol for the global variable |
| 7449 | // that is undefined/data and external and the value will |
| 7450 | // be the byte size of the variable. When we do the |
| 7451 | // address map in SymbolFileDWARFDebugMap we rely on |
| 7452 | // having an address, we need to do some magic here |
| 7453 | // so we can get the correct address for our global |
| 7454 | // variable. The address for all of these entries |
| 7455 | // will be zero, and there will be an undefined symbol |
| 7456 | // in this object file, and the executable will have |
| 7457 | // a matching symbol with a good address. So here we |
| 7458 | // dig up the correct address and replace it in the |
| 7459 | // location for the variable, and set the variable's |
| 7460 | // symbol context scope to be that of the main executable |
| 7461 | // so the file address will resolve correctly. |
| 7462 | bool linked_oso_file_addr = false; |
| 7463 | if (is_external && location_DW_OP_addr == 0) |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7464 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7465 | // we have a possible uninitialized extern global |
| 7466 | ConstString const_name(mangled ? mangled : name); |
| 7467 | ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile(); |
| 7468 | if (debug_map_objfile) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7469 | { |
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 7470 | Symtab *debug_map_symtab = debug_map_objfile->GetSymtab(); |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7471 | if (debug_map_symtab) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7472 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7473 | Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name, |
| 7474 | eSymbolTypeData, |
| 7475 | Symtab::eDebugYes, |
| 7476 | Symtab::eVisibilityExtern); |
| 7477 | if (exe_symbol) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7478 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7479 | if (exe_symbol->ValueIsAddress()) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7480 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7481 | const addr_t exe_file_addr = exe_symbol->GetAddress().GetFileAddress(); |
| 7482 | if (exe_file_addr != LLDB_INVALID_ADDRESS) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7483 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7484 | if (location.Update_DW_OP_addr (exe_file_addr)) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7485 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7486 | linked_oso_file_addr = true; |
| 7487 | symbol_context_scope = exe_symbol; |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7488 | } |
| 7489 | } |
| 7490 | } |
| 7491 | } |
| 7492 | } |
| 7493 | } |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7494 | } |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7495 | |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7496 | if (!linked_oso_file_addr) |
| 7497 | { |
| 7498 | // The DW_OP_addr is not zero, but it contains a .o file address which |
| 7499 | // needs to be linked up correctly. |
| 7500 | const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr); |
| 7501 | if (exe_file_addr != LLDB_INVALID_ADDRESS) |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7502 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7503 | // Update the file address for this variable |
| 7504 | location.Update_DW_OP_addr (exe_file_addr); |
| 7505 | } |
| 7506 | else |
| 7507 | { |
| 7508 | // Variable didn't make it into the final executable |
| 7509 | return var_sp; |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7510 | } |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7511 | } |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7512 | } |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 7513 | } |
| 7514 | else |
| 7515 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7516 | scope = eValueTypeVariableLocal; |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 7517 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7518 | } |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7519 | |
| 7520 | if (symbol_context_scope == NULL) |
| 7521 | { |
| 7522 | switch (parent_tag) |
| 7523 | { |
| 7524 | case DW_TAG_subprogram: |
| 7525 | case DW_TAG_inlined_subroutine: |
| 7526 | case DW_TAG_lexical_block: |
| 7527 | if (sc.function) |
| 7528 | { |
| 7529 | symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); |
| 7530 | if (symbol_context_scope == NULL) |
| 7531 | symbol_context_scope = sc.function; |
| 7532 | } |
| 7533 | break; |
| 7534 | |
| 7535 | default: |
| 7536 | symbol_context_scope = sc.comp_unit; |
| 7537 | break; |
| 7538 | } |
| 7539 | } |
| 7540 | |
| 7541 | if (symbol_context_scope) |
| 7542 | { |
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 7543 | SymbolFileTypeSP type_sp(new SymbolFileType(*this, type_uid)); |
| 7544 | |
| 7545 | if (const_value.Form() && type_sp && type_sp->GetType()) |
| 7546 | location.CopyOpcodeData(const_value.Unsigned(), type_sp->GetType()->GetByteSize(), dwarf_cu->GetAddressByteSize()); |
| 7547 | |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7548 | var_sp.reset (new Variable (MakeUserID(die->GetOffset()), |
| 7549 | name, |
| 7550 | mangled, |
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 7551 | type_sp, |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7552 | scope, |
| 7553 | symbol_context_scope, |
| 7554 | &decl, |
| 7555 | location, |
| 7556 | is_external, |
| 7557 | is_artificial)); |
| 7558 | |
| 7559 | var_sp->SetLocationIsConstantValueData (location_is_const_value_data); |
| 7560 | } |
| 7561 | else |
| 7562 | { |
| 7563 | // Not ready to parse this variable yet. It might be a global |
| 7564 | // or static variable that is in a function scope and the function |
| 7565 | // in the symbol context wasn't filled in yet |
| 7566 | return var_sp; |
| 7567 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7568 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7569 | // Cache var_sp even if NULL (the variable was just a specification or |
| 7570 | // was missing vital information to be able to be displayed in the debugger |
| 7571 | // (missing location due to optimization, etc)) so we don't re-parse |
| 7572 | // this DIE over and over later... |
| 7573 | m_die_to_variable_sp[die] = var_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7574 | } |
| 7575 | return var_sp; |
| 7576 | } |
| 7577 | |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7578 | |
| 7579 | const DWARFDebugInfoEntry * |
| 7580 | SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset, |
| 7581 | dw_offset_t spec_block_die_offset, |
| 7582 | DWARFCompileUnit **result_die_cu_handle) |
| 7583 | { |
| 7584 | // Give the concrete function die specified by "func_die_offset", find the |
| 7585 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points |
| 7586 | // to "spec_block_die_offset" |
| 7587 | DWARFDebugInfo* info = DebugInfo(); |
| 7588 | |
| 7589 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle); |
| 7590 | if (die) |
| 7591 | { |
| 7592 | assert (*result_die_cu_handle); |
| 7593 | return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle); |
| 7594 | } |
| 7595 | return NULL; |
| 7596 | } |
| 7597 | |
| 7598 | |
| 7599 | const DWARFDebugInfoEntry * |
| 7600 | SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu, |
| 7601 | const DWARFDebugInfoEntry *die, |
| 7602 | dw_offset_t spec_block_die_offset, |
| 7603 | DWARFCompileUnit **result_die_cu_handle) |
| 7604 | { |
| 7605 | if (die) |
| 7606 | { |
| 7607 | switch (die->Tag()) |
| 7608 | { |
| 7609 | case DW_TAG_subprogram: |
| 7610 | case DW_TAG_inlined_subroutine: |
| 7611 | case DW_TAG_lexical_block: |
| 7612 | { |
| 7613 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset) |
| 7614 | { |
| 7615 | *result_die_cu_handle = dwarf_cu; |
| 7616 | return die; |
| 7617 | } |
| 7618 | |
| 7619 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset) |
| 7620 | { |
| 7621 | *result_die_cu_handle = dwarf_cu; |
| 7622 | return die; |
| 7623 | } |
| 7624 | } |
| 7625 | break; |
| 7626 | } |
| 7627 | |
| 7628 | // Give the concrete function die specified by "func_die_offset", find the |
| 7629 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points |
| 7630 | // to "spec_block_die_offset" |
| 7631 | for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling()) |
| 7632 | { |
| 7633 | const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu, |
| 7634 | child_die, |
| 7635 | spec_block_die_offset, |
| 7636 | result_die_cu_handle); |
| 7637 | if (result_die) |
| 7638 | return result_die; |
| 7639 | } |
| 7640 | } |
| 7641 | |
| 7642 | *result_die_cu_handle = NULL; |
| 7643 | return NULL; |
| 7644 | } |
| 7645 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7646 | size_t |
| 7647 | SymbolFileDWARF::ParseVariables |
| 7648 | ( |
| 7649 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 7650 | DWARFCompileUnit* dwarf_cu, |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 7651 | const lldb::addr_t func_low_pc, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7652 | const DWARFDebugInfoEntry *orig_die, |
| 7653 | bool parse_siblings, |
| 7654 | bool parse_children, |
| 7655 | VariableList* cc_variable_list |
| 7656 | ) |
| 7657 | { |
| 7658 | if (orig_die == NULL) |
| 7659 | return 0; |
| 7660 | |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7661 | VariableListSP variable_list_sp; |
| 7662 | |
| 7663 | size_t vars_added = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7664 | const DWARFDebugInfoEntry *die = orig_die; |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7665 | while (die != NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7666 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7667 | dw_tag_t tag = die->Tag(); |
| 7668 | |
| 7669 | // Check to see if we have already parsed this variable or constant? |
| 7670 | if (m_die_to_variable_sp[die]) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7671 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7672 | if (cc_variable_list) |
| 7673 | cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7674 | } |
| 7675 | else |
| 7676 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7677 | // We haven't already parsed it, lets do that now. |
| 7678 | if ((tag == DW_TAG_variable) || |
| 7679 | (tag == DW_TAG_constant) || |
| 7680 | (tag == DW_TAG_formal_parameter && sc.function)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7681 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7682 | if (variable_list_sp.get() == NULL) |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7683 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7684 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die); |
| 7685 | dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
| 7686 | switch (parent_tag) |
| 7687 | { |
| 7688 | case DW_TAG_compile_unit: |
| 7689 | if (sc.comp_unit != NULL) |
| 7690 | { |
| 7691 | variable_list_sp = sc.comp_unit->GetVariableList(false); |
| 7692 | if (variable_list_sp.get() == NULL) |
| 7693 | { |
| 7694 | variable_list_sp.reset(new VariableList()); |
| 7695 | sc.comp_unit->SetVariableList(variable_list_sp); |
| 7696 | } |
| 7697 | } |
| 7698 | else |
| 7699 | { |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 7700 | GetObjectFile()->GetModule()->ReportError ("parent 0x%8.8" PRIx64 " %s with no valid compile unit in symbol context for 0x%8.8" PRIx64 " %s.\n", |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 7701 | MakeUserID(sc_parent_die->GetOffset()), |
| 7702 | DW_TAG_value_to_name (parent_tag), |
| 7703 | MakeUserID(orig_die->GetOffset()), |
| 7704 | DW_TAG_value_to_name (orig_die->Tag())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7705 | } |
| 7706 | break; |
| 7707 | |
| 7708 | case DW_TAG_subprogram: |
| 7709 | case DW_TAG_inlined_subroutine: |
| 7710 | case DW_TAG_lexical_block: |
| 7711 | if (sc.function != NULL) |
| 7712 | { |
| 7713 | // Check to see if we already have parsed the variables for the given scope |
| 7714 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7715 | Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7716 | if (block == NULL) |
| 7717 | { |
| 7718 | // This must be a specification or abstract origin with |
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 7719 | // a concrete block counterpart in the current function. We need |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7720 | // to find the concrete block so we can correctly add the |
| 7721 | // variable to it |
| 7722 | DWARFCompileUnit *concrete_block_die_cu = dwarf_cu; |
| 7723 | const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(), |
| 7724 | sc_parent_die->GetOffset(), |
| 7725 | &concrete_block_die_cu); |
| 7726 | if (concrete_block_die) |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7727 | block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7728 | } |
| 7729 | |
| 7730 | if (block != NULL) |
| 7731 | { |
| 7732 | const bool can_create = false; |
| 7733 | variable_list_sp = block->GetBlockVariableList (can_create); |
| 7734 | if (variable_list_sp.get() == NULL) |
| 7735 | { |
| 7736 | variable_list_sp.reset(new VariableList()); |
| 7737 | block->SetVariableList(variable_list_sp); |
| 7738 | } |
| 7739 | } |
| 7740 | } |
| 7741 | break; |
| 7742 | |
| 7743 | default: |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 7744 | GetObjectFile()->GetModule()->ReportError ("didn't find appropriate parent DIE for variable list for 0x%8.8" PRIx64 " %s.\n", |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 7745 | MakeUserID(orig_die->GetOffset()), |
| 7746 | DW_TAG_value_to_name (orig_die->Tag())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7747 | break; |
| 7748 | } |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7749 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7750 | |
| 7751 | if (variable_list_sp) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7752 | { |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7753 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc)); |
| 7754 | if (var_sp) |
| 7755 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7756 | variable_list_sp->AddVariableIfUnique (var_sp); |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7757 | if (cc_variable_list) |
| 7758 | cc_variable_list->AddVariableIfUnique (var_sp); |
| 7759 | ++vars_added; |
| 7760 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7761 | } |
| 7762 | } |
| 7763 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7764 | |
| 7765 | bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram); |
| 7766 | |
| 7767 | if (!skip_children && parse_children && die->HasChildren()) |
| 7768 | { |
| 7769 | vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list); |
| 7770 | } |
| 7771 | |
| 7772 | if (parse_siblings) |
| 7773 | die = die->GetSibling(); |
| 7774 | else |
| 7775 | die = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7776 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7777 | return vars_added; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7778 | } |
| 7779 | |
| 7780 | //------------------------------------------------------------------ |
| 7781 | // PluginInterface protocol |
| 7782 | //------------------------------------------------------------------ |
| Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 7783 | ConstString |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7784 | SymbolFileDWARF::GetPluginName() |
| 7785 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7786 | return GetPluginNameStatic(); |
| 7787 | } |
| 7788 | |
| 7789 | uint32_t |
| 7790 | SymbolFileDWARF::GetPluginVersion() |
| 7791 | { |
| 7792 | return 1; |
| 7793 | } |
| 7794 | |
| 7795 | void |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 7796 | SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl) |
| 7797 | { |
| 7798 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 7799 | ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 7800 | if (clang_type) |
| 7801 | symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); |
| 7802 | } |
| 7803 | |
| 7804 | void |
| 7805 | SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl) |
| 7806 | { |
| 7807 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 7808 | ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 7809 | if (clang_type) |
| 7810 | symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); |
| 7811 | } |
| 7812 | |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7813 | void |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7814 | SymbolFileDWARF::DumpIndexes () |
| 7815 | { |
| 7816 | StreamFile s(stdout, false); |
| 7817 | |
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 7818 | s.Printf ("DWARF index for (%s) '%s':", |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7819 | GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(), |
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 7820 | GetObjectFile()->GetFileSpec().GetPath().c_str()); |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7821 | s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s); |
| 7822 | s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s); |
| 7823 | s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s); |
| 7824 | s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s); |
| 7825 | s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s); |
| 7826 | s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s); |
| 7827 | s.Printf("\nTypes:\n"); m_type_index.Dump (&s); |
| 7828 | s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s); |
| 7829 | } |
| 7830 | |
| 7831 | void |
| 7832 | SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context, |
| 7833 | const char *name, |
| 7834 | llvm::SmallVectorImpl <clang::NamedDecl *> *results) |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7835 | { |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7836 | DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context); |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7837 | |
| 7838 | if (iter == m_decl_ctx_to_die.end()) |
| 7839 | return; |
| 7840 | |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7841 | 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] | 7842 | { |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7843 | const DWARFDebugInfoEntry *context_die = *pos; |
| 7844 | |
| 7845 | if (!results) |
| 7846 | return; |
| 7847 | |
| 7848 | DWARFDebugInfo* info = DebugInfo(); |
| 7849 | |
| 7850 | DIEArray die_offsets; |
| 7851 | |
| 7852 | DWARFCompileUnit* dwarf_cu = NULL; |
| 7853 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 7854 | |
| 7855 | if (m_using_apple_tables) |
| 7856 | { |
| 7857 | if (m_apple_types_ap.get()) |
| 7858 | m_apple_types_ap->FindByName (name, die_offsets); |
| 7859 | } |
| 7860 | else |
| 7861 | { |
| 7862 | if (!m_indexed) |
| 7863 | Index (); |
| 7864 | |
| 7865 | m_type_index.Find (ConstString(name), die_offsets); |
| 7866 | } |
| 7867 | |
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 7868 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7869 | |
| 7870 | if (num_matches) |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7871 | { |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7872 | for (size_t i = 0; i < num_matches; ++i) |
| 7873 | { |
| 7874 | const dw_offset_t die_offset = die_offsets[i]; |
| 7875 | die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7876 | |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7877 | if (die->GetParent() != context_die) |
| 7878 | continue; |
| 7879 | |
| 7880 | Type *matching_type = ResolveType (dwarf_cu, die); |
| 7881 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 7882 | clang::QualType qual_type = matching_type->GetClangForwardType().GetQualType(); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7883 | |
| 7884 | if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr())) |
| 7885 | { |
| 7886 | clang::TagDecl *tag_decl = tag_type->getDecl(); |
| 7887 | results->push_back(tag_decl); |
| 7888 | } |
| 7889 | else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr())) |
| 7890 | { |
| 7891 | clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl(); |
| 7892 | results->push_back(typedef_decl); |
| 7893 | } |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7894 | } |
| 7895 | } |
| 7896 | } |
| 7897 | } |
| 7898 | |
| 7899 | void |
| 7900 | SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton, |
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 7901 | const clang::DeclContext *decl_context, |
| 7902 | clang::DeclarationName decl_name, |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7903 | llvm::SmallVectorImpl <clang::NamedDecl *> *results) |
| 7904 | { |
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 7905 | |
| 7906 | switch (decl_context->getDeclKind()) |
| 7907 | { |
| 7908 | case clang::Decl::Namespace: |
| 7909 | case clang::Decl::TranslationUnit: |
| 7910 | { |
| 7911 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 7912 | symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results); |
| 7913 | } |
| 7914 | break; |
| 7915 | default: |
| 7916 | break; |
| 7917 | } |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7918 | } |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7919 | |
| 7920 | bool |
| 7921 | SymbolFileDWARF::LayoutRecordType (void *baton, |
| 7922 | const clang::RecordDecl *record_decl, |
| 7923 | uint64_t &size, |
| 7924 | uint64_t &alignment, |
| 7925 | llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, |
| 7926 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, |
| 7927 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) |
| 7928 | { |
| 7929 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 7930 | return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets); |
| 7931 | } |
| 7932 | |
| 7933 | |
| 7934 | bool |
| 7935 | SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl, |
| 7936 | uint64_t &bit_size, |
| 7937 | uint64_t &alignment, |
| 7938 | llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, |
| 7939 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, |
| 7940 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) |
| 7941 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 7942 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7943 | RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl); |
| 7944 | bool success = false; |
| 7945 | base_offsets.clear(); |
| 7946 | vbase_offsets.clear(); |
| 7947 | if (pos != m_record_decl_to_layout_map.end()) |
| 7948 | { |
| 7949 | bit_size = pos->second.bit_size; |
| 7950 | alignment = pos->second.alignment; |
| 7951 | field_offsets.swap(pos->second.field_offsets); |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 7952 | base_offsets.swap (pos->second.base_offsets); |
| 7953 | vbase_offsets.swap (pos->second.vbase_offsets); |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7954 | m_record_decl_to_layout_map.erase(pos); |
| 7955 | success = true; |
| 7956 | } |
| 7957 | else |
| 7958 | { |
| 7959 | bit_size = 0; |
| 7960 | alignment = 0; |
| 7961 | field_offsets.clear(); |
| 7962 | } |
| 7963 | |
| 7964 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 7965 | GetObjectFile()->GetModule()->LogMessage (log, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 7966 | "SymbolFileDWARF::LayoutRecordType (record_decl = %p, bit_size = %" PRIu64 ", alignment = %" PRIu64 ", field_offsets[%u],base_offsets[%u], vbase_offsets[%u]) success = %i", |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 7967 | static_cast<const void*>(record_decl), |
| 7968 | bit_size, alignment, |
| 7969 | static_cast<uint32_t>(field_offsets.size()), |
| 7970 | static_cast<uint32_t>(base_offsets.size()), |
| 7971 | static_cast<uint32_t>(vbase_offsets.size()), |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7972 | success); |
| 7973 | return success; |
| 7974 | } |
| 7975 | |
| 7976 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 7977 | SymbolFileDWARFDebugMap * |
| 7978 | SymbolFileDWARF::GetDebugMapSymfile () |
| 7979 | { |
| 7980 | if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired()) |
| 7981 | { |
| 7982 | lldb::ModuleSP module_sp (m_debug_map_module_wp.lock()); |
| 7983 | if (module_sp) |
| 7984 | { |
| 7985 | SymbolVendor *sym_vendor = module_sp->GetSymbolVendor(); |
| 7986 | if (sym_vendor) |
| 7987 | m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile(); |
| 7988 | } |
| 7989 | } |
| 7990 | return m_debug_map_symfile; |
| 7991 | } |
| 7992 | |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7993 | |