| 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 | |
| Robert Flack | eb83fab | 2015-05-15 18:59:59 +0000 | [diff] [blame] | 29 | #include "lldb/Core/ArchSpec.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | #include "lldb/Core/Module.h" |
| Sean Callanan | f0c5aeb | 2015-04-20 16:31:29 +0000 | [diff] [blame] | 31 | #include "lldb/Core/ModuleList.h" |
| 32 | #include "lldb/Core/ModuleSpec.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 33 | #include "lldb/Core/PluginManager.h" |
| 34 | #include "lldb/Core/RegularExpression.h" |
| 35 | #include "lldb/Core/Scalar.h" |
| 36 | #include "lldb/Core/Section.h" |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 37 | #include "lldb/Core/StreamFile.h" |
| Jim Ingham | 318c9f2 | 2011-08-26 19:44:13 +0000 | [diff] [blame] | 38 | #include "lldb/Core/StreamString.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 39 | #include "lldb/Core/Timer.h" |
| 40 | #include "lldb/Core/Value.h" |
| 41 | |
| Sean Callanan | f0c5aeb | 2015-04-20 16:31:29 +0000 | [diff] [blame] | 42 | #include "lldb/Expression/ClangModulesDeclVendor.h" |
| 43 | |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 44 | #include "lldb/Host/Host.h" |
| 45 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 46 | #include "lldb/Symbol/Block.h" |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 47 | #include "lldb/Symbol/ClangExternalASTSourceCallbacks.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 48 | #include "lldb/Symbol/CompileUnit.h" |
| 49 | #include "lldb/Symbol/LineTable.h" |
| 50 | #include "lldb/Symbol/ObjectFile.h" |
| 51 | #include "lldb/Symbol/SymbolVendor.h" |
| 52 | #include "lldb/Symbol/VariableList.h" |
| 53 | |
| Jim Ingham | b7f6b2f | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 54 | #include "lldb/Target/ObjCLanguageRuntime.h" |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 55 | #include "lldb/Target/CPPLanguageRuntime.h" |
| Jim Ingham | b7f6b2f | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 56 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 57 | #include "DWARFCompileUnit.h" |
| 58 | #include "DWARFDebugAbbrev.h" |
| 59 | #include "DWARFDebugAranges.h" |
| 60 | #include "DWARFDebugInfo.h" |
| 61 | #include "DWARFDebugInfoEntry.h" |
| 62 | #include "DWARFDebugLine.h" |
| 63 | #include "DWARFDebugPubnames.h" |
| 64 | #include "DWARFDebugRanges.h" |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 65 | #include "DWARFDeclContext.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 66 | #include "DWARFDIECollection.h" |
| 67 | #include "DWARFFormValue.h" |
| 68 | #include "DWARFLocationList.h" |
| 69 | #include "LogChannelDWARF.h" |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 70 | #include "SymbolFileDWARFDebugMap.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 71 | |
| 72 | #include <map> |
| 73 | |
| Matthew Gardiner | e81df3b | 2014-08-26 06:57:23 +0000 | [diff] [blame] | 74 | #include <ctype.h> |
| 75 | #include <string.h> |
| 76 | |
| Greg Clayton | 62742b1 | 2010-11-11 01:09:45 +0000 | [diff] [blame] | 77 | //#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 78 | |
| 79 | #ifdef ENABLE_DEBUG_PRINTF |
| 80 | #include <stdio.h> |
| Ed Maste | a0191d1 | 2013-10-17 20:42:56 +0000 | [diff] [blame] | 81 | #define DEBUG_PRINTF(fmt, ...) printf(fmt, __VA_ARGS__) |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 82 | #else |
| 83 | #define DEBUG_PRINTF(fmt, ...) |
| 84 | #endif |
| 85 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 86 | #define DIE_IS_BEING_PARSED ((lldb_private::Type*)1) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 87 | |
| 88 | using namespace lldb; |
| 89 | using namespace lldb_private; |
| 90 | |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 91 | //static inline bool |
| 92 | //child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag) |
| 93 | //{ |
| 94 | // switch (tag) |
| 95 | // { |
| 96 | // default: |
| 97 | // break; |
| 98 | // case DW_TAG_subprogram: |
| 99 | // case DW_TAG_inlined_subroutine: |
| 100 | // case DW_TAG_class_type: |
| 101 | // case DW_TAG_structure_type: |
| 102 | // case DW_TAG_union_type: |
| 103 | // return true; |
| 104 | // } |
| 105 | // return false; |
| 106 | //} |
| 107 | // |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 108 | static AccessType |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 109 | DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 110 | { |
| 111 | switch (dwarf_accessibility) |
| 112 | { |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 113 | case DW_ACCESS_public: return eAccessPublic; |
| 114 | case DW_ACCESS_private: return eAccessPrivate; |
| 115 | case DW_ACCESS_protected: return eAccessProtected; |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 116 | default: break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 117 | } |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 118 | return eAccessNone; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| Matthew Gardiner | e81df3b | 2014-08-26 06:57:23 +0000 | [diff] [blame] | 121 | static const char* |
| 122 | removeHostnameFromPathname(const char* path_from_dwarf) |
| 123 | { |
| 124 | if (!path_from_dwarf || !path_from_dwarf[0]) |
| 125 | { |
| 126 | return path_from_dwarf; |
| 127 | } |
| 128 | |
| 129 | const char *colon_pos = strchr(path_from_dwarf, ':'); |
| 130 | if (!colon_pos) |
| 131 | { |
| 132 | return path_from_dwarf; |
| 133 | } |
| 134 | |
| 135 | // check whether we have a windows path, and so the first character |
| 136 | // is a drive-letter not a hostname. |
| 137 | if ( |
| 138 | colon_pos == path_from_dwarf + 1 && |
| 139 | isalpha(*path_from_dwarf) && |
| 140 | strlen(path_from_dwarf) > 2 && |
| 141 | '\\' == path_from_dwarf[2]) |
| 142 | { |
| 143 | return path_from_dwarf; |
| 144 | } |
| 145 | |
| 146 | return colon_pos + 1; |
| 147 | } |
| 148 | |
| Todd Fiala | 0a70a84 | 2014-05-28 16:43:26 +0000 | [diff] [blame] | 149 | #if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE) |
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 150 | |
| 151 | class DIEStack |
| 152 | { |
| 153 | public: |
| 154 | |
| 155 | void Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) |
| 156 | { |
| 157 | m_dies.push_back (DIEInfo(cu, die)); |
| 158 | } |
| 159 | |
| 160 | |
| 161 | void LogDIEs (Log *log, SymbolFileDWARF *dwarf) |
| 162 | { |
| 163 | StreamString log_strm; |
| 164 | const size_t n = m_dies.size(); |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 165 | log_strm.Printf("DIEStack[%" PRIu64 "]:\n", (uint64_t)n); |
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 166 | for (size_t i=0; i<n; i++) |
| 167 | { |
| 168 | DWARFCompileUnit *cu = m_dies[i].cu; |
| 169 | const DWARFDebugInfoEntry *die = m_dies[i].die; |
| 170 | std::string qualified_name; |
| 171 | die->GetQualifiedName(dwarf, cu, qualified_name); |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 172 | log_strm.Printf ("[%" PRIu64 "] 0x%8.8x: %s name='%s'\n", |
| Greg Clayton | 43e0af0 | 2012-09-18 18:04:04 +0000 | [diff] [blame] | 173 | (uint64_t)i, |
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 174 | die->GetOffset(), |
| 175 | DW_TAG_value_to_name(die->Tag()), |
| 176 | qualified_name.c_str()); |
| 177 | } |
| 178 | log->PutCString(log_strm.GetData()); |
| 179 | } |
| 180 | void Pop () |
| 181 | { |
| 182 | m_dies.pop_back(); |
| 183 | } |
| 184 | |
| 185 | class ScopedPopper |
| 186 | { |
| 187 | public: |
| 188 | ScopedPopper (DIEStack &die_stack) : |
| 189 | m_die_stack (die_stack), |
| 190 | m_valid (false) |
| 191 | { |
| 192 | } |
| 193 | |
| 194 | void |
| 195 | Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) |
| 196 | { |
| 197 | m_valid = true; |
| 198 | m_die_stack.Push (cu, die); |
| 199 | } |
| 200 | |
| 201 | ~ScopedPopper () |
| 202 | { |
| 203 | if (m_valid) |
| 204 | m_die_stack.Pop(); |
| 205 | } |
| 206 | |
| 207 | |
| 208 | |
| 209 | protected: |
| 210 | DIEStack &m_die_stack; |
| 211 | bool m_valid; |
| 212 | }; |
| 213 | |
| 214 | protected: |
| 215 | struct DIEInfo { |
| 216 | DIEInfo (DWARFCompileUnit *c, const DWARFDebugInfoEntry *d) : |
| 217 | cu(c), |
| 218 | die(d) |
| 219 | { |
| 220 | } |
| 221 | DWARFCompileUnit *cu; |
| 222 | const DWARFDebugInfoEntry *die; |
| 223 | }; |
| 224 | typedef std::vector<DIEInfo> Stack; |
| 225 | Stack m_dies; |
| 226 | }; |
| 227 | #endif |
| 228 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 229 | void |
| 230 | SymbolFileDWARF::Initialize() |
| 231 | { |
| 232 | LogChannelDWARF::Initialize(); |
| 233 | PluginManager::RegisterPlugin (GetPluginNameStatic(), |
| 234 | GetPluginDescriptionStatic(), |
| 235 | CreateInstance); |
| 236 | } |
| 237 | |
| 238 | void |
| 239 | SymbolFileDWARF::Terminate() |
| 240 | { |
| 241 | PluginManager::UnregisterPlugin (CreateInstance); |
| 242 | LogChannelDWARF::Initialize(); |
| 243 | } |
| 244 | |
| 245 | |
| Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 246 | lldb_private::ConstString |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 247 | SymbolFileDWARF::GetPluginNameStatic() |
| 248 | { |
| Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 249 | static ConstString g_name("dwarf"); |
| 250 | return g_name; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | const char * |
| 254 | SymbolFileDWARF::GetPluginDescriptionStatic() |
| 255 | { |
| 256 | return "DWARF and DWARF3 debug symbol file reader."; |
| 257 | } |
| 258 | |
| 259 | |
| 260 | SymbolFile* |
| 261 | SymbolFileDWARF::CreateInstance (ObjectFile* obj_file) |
| 262 | { |
| 263 | return new SymbolFileDWARF(obj_file); |
| 264 | } |
| 265 | |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 266 | TypeList * |
| 267 | SymbolFileDWARF::GetTypeList () |
| 268 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 269 | if (GetDebugMapSymfile ()) |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 270 | return m_debug_map_symfile->GetTypeList(); |
| 271 | return m_obj_file->GetModule()->GetTypeList(); |
| 272 | |
| 273 | } |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 274 | void |
| 275 | SymbolFileDWARF::GetTypes (DWARFCompileUnit* cu, |
| 276 | const DWARFDebugInfoEntry *die, |
| 277 | dw_offset_t min_die_offset, |
| 278 | dw_offset_t max_die_offset, |
| 279 | uint32_t type_mask, |
| 280 | TypeSet &type_set) |
| 281 | { |
| 282 | if (cu) |
| 283 | { |
| 284 | if (die) |
| 285 | { |
| 286 | const dw_offset_t die_offset = die->GetOffset(); |
| 287 | |
| 288 | if (die_offset >= max_die_offset) |
| 289 | return; |
| 290 | |
| 291 | if (die_offset >= min_die_offset) |
| 292 | { |
| 293 | const dw_tag_t tag = die->Tag(); |
| 294 | |
| 295 | bool add_type = false; |
| 296 | |
| 297 | switch (tag) |
| 298 | { |
| 299 | case DW_TAG_array_type: add_type = (type_mask & eTypeClassArray ) != 0; break; |
| 300 | case DW_TAG_unspecified_type: |
| 301 | case DW_TAG_base_type: add_type = (type_mask & eTypeClassBuiltin ) != 0; break; |
| 302 | case DW_TAG_class_type: add_type = (type_mask & eTypeClassClass ) != 0; break; |
| 303 | case DW_TAG_structure_type: add_type = (type_mask & eTypeClassStruct ) != 0; break; |
| 304 | case DW_TAG_union_type: add_type = (type_mask & eTypeClassUnion ) != 0; break; |
| 305 | case DW_TAG_enumeration_type: add_type = (type_mask & eTypeClassEnumeration ) != 0; break; |
| 306 | case DW_TAG_subroutine_type: |
| 307 | case DW_TAG_subprogram: |
| 308 | case DW_TAG_inlined_subroutine: add_type = (type_mask & eTypeClassFunction ) != 0; break; |
| 309 | case DW_TAG_pointer_type: add_type = (type_mask & eTypeClassPointer ) != 0; break; |
| 310 | case DW_TAG_rvalue_reference_type: |
| 311 | case DW_TAG_reference_type: add_type = (type_mask & eTypeClassReference ) != 0; break; |
| 312 | case DW_TAG_typedef: add_type = (type_mask & eTypeClassTypedef ) != 0; break; |
| 313 | case DW_TAG_ptr_to_member_type: add_type = (type_mask & eTypeClassMemberPointer ) != 0; break; |
| 314 | } |
| 315 | |
| 316 | if (add_type) |
| 317 | { |
| 318 | const bool assert_not_being_parsed = true; |
| 319 | Type *type = ResolveTypeUID (cu, die, assert_not_being_parsed); |
| 320 | if (type) |
| 321 | { |
| 322 | if (type_set.find(type) == type_set.end()) |
| 323 | type_set.insert(type); |
| 324 | } |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); |
| 329 | child_die != NULL; |
| 330 | child_die = child_die->GetSibling()) |
| 331 | { |
| 332 | GetTypes (cu, child_die, min_die_offset, max_die_offset, type_mask, type_set); |
| 333 | } |
| 334 | } |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | size_t |
| 339 | SymbolFileDWARF::GetTypes (SymbolContextScope *sc_scope, |
| 340 | uint32_t type_mask, |
| 341 | TypeList &type_list) |
| 342 | |
| 343 | { |
| 344 | TypeSet type_set; |
| 345 | |
| 346 | CompileUnit *comp_unit = NULL; |
| 347 | DWARFCompileUnit* dwarf_cu = NULL; |
| 348 | if (sc_scope) |
| 349 | comp_unit = sc_scope->CalculateSymbolContextCompileUnit(); |
| 350 | |
| 351 | if (comp_unit) |
| 352 | { |
| 353 | dwarf_cu = GetDWARFCompileUnit(comp_unit); |
| 354 | if (dwarf_cu == 0) |
| 355 | return 0; |
| 356 | GetTypes (dwarf_cu, |
| 357 | dwarf_cu->DIE(), |
| 358 | dwarf_cu->GetOffset(), |
| 359 | dwarf_cu->GetNextCompileUnitOffset(), |
| 360 | type_mask, |
| 361 | type_set); |
| 362 | } |
| 363 | else |
| 364 | { |
| 365 | DWARFDebugInfo* info = DebugInfo(); |
| 366 | if (info) |
| 367 | { |
| 368 | const size_t num_cus = info->GetNumCompileUnits(); |
| 369 | for (size_t cu_idx=0; cu_idx<num_cus; ++cu_idx) |
| 370 | { |
| 371 | dwarf_cu = info->GetCompileUnitAtIndex(cu_idx); |
| 372 | if (dwarf_cu) |
| 373 | { |
| 374 | GetTypes (dwarf_cu, |
| 375 | dwarf_cu->DIE(), |
| 376 | 0, |
| 377 | UINT32_MAX, |
| 378 | type_mask, |
| 379 | type_set); |
| 380 | } |
| 381 | } |
| 382 | } |
| 383 | } |
| 384 | // if (m_using_apple_tables) |
| 385 | // { |
| 386 | // DWARFMappedHash::MemoryTable *apple_types = m_apple_types_ap.get(); |
| 387 | // if (apple_types) |
| 388 | // { |
| 389 | // apple_types->ForEach([this, &type_set, apple_types, type_mask](const DWARFMappedHash::DIEInfoArray &die_info_array) -> bool { |
| 390 | // |
| 391 | // for (auto die_info: die_info_array) |
| 392 | // { |
| 393 | // bool add_type = TagMatchesTypeMask (type_mask, 0); |
| 394 | // if (!add_type) |
| 395 | // { |
| 396 | // dw_tag_t tag = die_info.tag; |
| 397 | // if (tag == 0) |
| 398 | // { |
| 399 | // const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_info.offset, NULL); |
| 400 | // tag = die->Tag(); |
| 401 | // } |
| 402 | // add_type = TagMatchesTypeMask (type_mask, tag); |
| 403 | // } |
| 404 | // if (add_type) |
| 405 | // { |
| 406 | // Type *type = ResolveTypeUID(die_info.offset); |
| 407 | // |
| 408 | // if (type_set.find(type) == type_set.end()) |
| 409 | // type_set.insert(type); |
| 410 | // } |
| 411 | // } |
| 412 | // return true; // Keep iterating |
| 413 | // }); |
| 414 | // } |
| 415 | // } |
| 416 | // else |
| 417 | // { |
| 418 | // if (!m_indexed) |
| 419 | // Index (); |
| 420 | // |
| 421 | // m_type_index.ForEach([this, &type_set, type_mask](const char *name, uint32_t die_offset) -> bool { |
| 422 | // |
| 423 | // bool add_type = TagMatchesTypeMask (type_mask, 0); |
| 424 | // |
| 425 | // if (!add_type) |
| 426 | // { |
| 427 | // const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_offset, NULL); |
| 428 | // if (die) |
| 429 | // { |
| 430 | // const dw_tag_t tag = die->Tag(); |
| 431 | // add_type = TagMatchesTypeMask (type_mask, tag); |
| 432 | // } |
| 433 | // } |
| 434 | // |
| 435 | // if (add_type) |
| 436 | // { |
| 437 | // Type *type = ResolveTypeUID(die_offset); |
| 438 | // |
| 439 | // if (type_set.find(type) == type_set.end()) |
| 440 | // type_set.insert(type); |
| 441 | // } |
| 442 | // return true; // Keep iterating |
| 443 | // }); |
| 444 | // } |
| 445 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 446 | std::set<ClangASTType> clang_type_set; |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 447 | size_t num_types_added = 0; |
| 448 | for (Type *type : type_set) |
| 449 | { |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 450 | ClangASTType clang_type = type->GetClangForwardType(); |
| Greg Clayton | 0fc4f31 | 2013-06-20 01:23:18 +0000 | [diff] [blame] | 451 | if (clang_type_set.find(clang_type) == clang_type_set.end()) |
| 452 | { |
| 453 | clang_type_set.insert(clang_type); |
| 454 | type_list.Insert (type->shared_from_this()); |
| 455 | ++num_types_added; |
| 456 | } |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 457 | } |
| 458 | return num_types_added; |
| 459 | } |
| 460 | |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 461 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 462 | //---------------------------------------------------------------------- |
| 463 | // Gets the first parent that is a lexical block, function or inlined |
| 464 | // subroutine, or compile unit. |
| 465 | //---------------------------------------------------------------------- |
| 466 | static const DWARFDebugInfoEntry * |
| 467 | GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die) |
| 468 | { |
| 469 | const DWARFDebugInfoEntry *die; |
| 470 | for (die = child_die->GetParent(); die != NULL; die = die->GetParent()) |
| 471 | { |
| 472 | dw_tag_t tag = die->Tag(); |
| 473 | |
| 474 | switch (tag) |
| 475 | { |
| 476 | case DW_TAG_compile_unit: |
| 477 | case DW_TAG_subprogram: |
| 478 | case DW_TAG_inlined_subroutine: |
| 479 | case DW_TAG_lexical_block: |
| 480 | return die; |
| 481 | } |
| 482 | } |
| 483 | return NULL; |
| 484 | } |
| 485 | |
| 486 | |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 487 | SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) : |
| 488 | SymbolFile (objfile), |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 489 | 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] | 490 | m_debug_map_module_wp (), |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 491 | m_debug_map_symfile (NULL), |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 492 | m_clang_tu_decl (NULL), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 493 | m_flags(), |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 494 | m_data_debug_abbrev (), |
| 495 | m_data_debug_aranges (), |
| 496 | m_data_debug_frame (), |
| 497 | m_data_debug_info (), |
| 498 | m_data_debug_line (), |
| 499 | m_data_debug_loc (), |
| 500 | m_data_debug_ranges (), |
| 501 | m_data_debug_str (), |
| Greg Clayton | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 502 | m_data_apple_names (), |
| 503 | m_data_apple_types (), |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 504 | m_data_apple_namespaces (), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 505 | m_abbr(), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 506 | m_info(), |
| 507 | m_line(), |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 508 | m_apple_names_ap (), |
| 509 | m_apple_types_ap (), |
| 510 | m_apple_namespaces_ap (), |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 511 | m_apple_objc_ap (), |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 512 | m_function_basename_index(), |
| 513 | m_function_fullname_index(), |
| 514 | m_function_method_index(), |
| 515 | m_function_selector_index(), |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 516 | m_objc_class_selectors_index(), |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 517 | m_global_index(), |
| Greg Clayton | 69b0488 | 2010-10-15 02:03:22 +0000 | [diff] [blame] | 518 | m_type_index(), |
| 519 | m_namespace_index(), |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 520 | m_indexed (false), |
| 521 | m_is_external_ast_source (false), |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 522 | m_using_apple_tables (false), |
| Sean Callanan | f0c5aeb | 2015-04-20 16:31:29 +0000 | [diff] [blame] | 523 | m_fetched_external_modules (false), |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 524 | m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate), |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 525 | m_ranges(), |
| 526 | m_unique_ast_type_map () |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 527 | { |
| 528 | } |
| 529 | |
| 530 | SymbolFileDWARF::~SymbolFileDWARF() |
| 531 | { |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 532 | if (m_is_external_ast_source) |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 533 | { |
| 534 | ModuleSP module_sp (m_obj_file->GetModule()); |
| 535 | if (module_sp) |
| 536 | module_sp->GetClangASTContext().RemoveExternalSource (); |
| 537 | } |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | static const ConstString & |
| 541 | GetDWARFMachOSegmentName () |
| 542 | { |
| 543 | static ConstString g_dwarf_section_name ("__DWARF"); |
| 544 | return g_dwarf_section_name; |
| 545 | } |
| 546 | |
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 547 | UniqueDWARFASTTypeMap & |
| 548 | SymbolFileDWARF::GetUniqueDWARFASTTypeMap () |
| 549 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 550 | if (GetDebugMapSymfile ()) |
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 551 | return m_debug_map_symfile->GetUniqueDWARFASTTypeMap (); |
| 552 | return m_unique_ast_type_map; |
| 553 | } |
| 554 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 555 | ClangASTContext & |
| 556 | SymbolFileDWARF::GetClangASTContext () |
| 557 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 558 | if (GetDebugMapSymfile ()) |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 559 | return m_debug_map_symfile->GetClangASTContext (); |
| 560 | |
| 561 | ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext(); |
| 562 | if (!m_is_external_ast_source) |
| 563 | { |
| 564 | m_is_external_ast_source = true; |
| Todd Fiala | 955fe6f | 2014-02-27 17:18:23 +0000 | [diff] [blame] | 565 | llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> ast_source_ap ( |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 566 | new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl, |
| 567 | SymbolFileDWARF::CompleteObjCInterfaceDecl, |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 568 | SymbolFileDWARF::FindExternalVisibleDeclsByName, |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 569 | SymbolFileDWARF::LayoutRecordType, |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 570 | this)); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 571 | ast.SetExternalSource (ast_source_ap); |
| 572 | } |
| 573 | return ast; |
| 574 | } |
| 575 | |
| 576 | void |
| 577 | SymbolFileDWARF::InitializeObject() |
| 578 | { |
| 579 | // Install our external AST source callbacks so we can complete Clang types. |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 580 | ModuleSP module_sp (m_obj_file->GetModule()); |
| 581 | if (module_sp) |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 582 | { |
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 583 | const SectionList *section_list = module_sp->GetSectionList(); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 584 | |
| 585 | const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get(); |
| 586 | |
| 587 | // Memory map the DWARF mach-o segment so we have everything mmap'ed |
| 588 | // to keep our heap memory usage down. |
| 589 | if (section) |
| Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 590 | m_obj_file->MemoryMapSectionData(section, m_dwarf_data); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 591 | } |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 592 | get_apple_names_data(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 593 | if (m_data_apple_names.GetByteSize() > 0) |
| 594 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 595 | m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names")); |
| 596 | if (m_apple_names_ap->IsValid()) |
| 597 | m_using_apple_tables = true; |
| 598 | else |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 599 | m_apple_names_ap.reset(); |
| 600 | } |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 601 | get_apple_types_data(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 602 | if (m_data_apple_types.GetByteSize() > 0) |
| 603 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 604 | m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types")); |
| 605 | if (m_apple_types_ap->IsValid()) |
| 606 | m_using_apple_tables = true; |
| 607 | else |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 608 | m_apple_types_ap.reset(); |
| 609 | } |
| 610 | |
| 611 | get_apple_namespaces_data(); |
| 612 | if (m_data_apple_namespaces.GetByteSize() > 0) |
| 613 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 614 | m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces")); |
| 615 | if (m_apple_namespaces_ap->IsValid()) |
| 616 | m_using_apple_tables = true; |
| 617 | else |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 618 | m_apple_namespaces_ap.reset(); |
| 619 | } |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 620 | |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 621 | get_apple_objc_data(); |
| 622 | if (m_data_apple_objc.GetByteSize() > 0) |
| 623 | { |
| 624 | m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc")); |
| 625 | if (m_apple_objc_ap->IsValid()) |
| 626 | m_using_apple_tables = true; |
| 627 | else |
| 628 | m_apple_objc_ap.reset(); |
| 629 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | bool |
| 633 | SymbolFileDWARF::SupportedVersion(uint16_t version) |
| 634 | { |
| Greg Clayton | abcbfe5 | 2013-04-04 00:00:36 +0000 | [diff] [blame] | 635 | return version == 2 || version == 3 || version == 4; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | uint32_t |
| Sean Callanan | bfaf54d | 2011-12-03 04:38:43 +0000 | [diff] [blame] | 639 | SymbolFileDWARF::CalculateAbilities () |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 640 | { |
| 641 | uint32_t abilities = 0; |
| 642 | if (m_obj_file != NULL) |
| 643 | { |
| 644 | const Section* section = NULL; |
| 645 | const SectionList *section_list = m_obj_file->GetSectionList(); |
| 646 | if (section_list == NULL) |
| 647 | return 0; |
| 648 | |
| 649 | uint64_t debug_abbrev_file_size = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 650 | uint64_t debug_info_file_size = 0; |
| 651 | uint64_t debug_line_file_size = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 652 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 653 | section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 654 | |
| 655 | if (section) |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 656 | section_list = §ion->GetChildren (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 657 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 658 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 659 | if (section != NULL) |
| 660 | { |
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 661 | debug_info_file_size = section->GetFileSize(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 662 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 663 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 664 | if (section) |
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 665 | debug_abbrev_file_size = section->GetFileSize(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 666 | else |
| 667 | m_flags.Set (flagsGotDebugAbbrevData); |
| 668 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 669 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 670 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 671 | m_flags.Set (flagsGotDebugArangesData); |
| 672 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 673 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 674 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 675 | m_flags.Set (flagsGotDebugFrameData); |
| 676 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 677 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 678 | if (section) |
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 679 | debug_line_file_size = section->GetFileSize(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 680 | else |
| 681 | m_flags.Set (flagsGotDebugLineData); |
| 682 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 683 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 684 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 685 | m_flags.Set (flagsGotDebugLocData); |
| 686 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 687 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 688 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 689 | m_flags.Set (flagsGotDebugMacInfoData); |
| 690 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 691 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 692 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 693 | m_flags.Set (flagsGotDebugPubNamesData); |
| 694 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 695 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 696 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 697 | m_flags.Set (flagsGotDebugPubTypesData); |
| 698 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 699 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 700 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 701 | m_flags.Set (flagsGotDebugRangesData); |
| 702 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 703 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 704 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 705 | m_flags.Set (flagsGotDebugStrData); |
| 706 | } |
| Greg Clayton | 6c59661 | 2012-05-18 21:47:20 +0000 | [diff] [blame] | 707 | else |
| 708 | { |
| 709 | const char *symfile_dir_cstr = m_obj_file->GetFileSpec().GetDirectory().GetCString(); |
| 710 | if (symfile_dir_cstr) |
| 711 | { |
| 712 | if (strcasestr(symfile_dir_cstr, ".dsym")) |
| 713 | { |
| 714 | if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo) |
| 715 | { |
| 716 | // We have a dSYM file that didn't have a any debug info. |
| 717 | // If the string table has a size of 1, then it was made from |
| 718 | // an executable with no debug info, or from an executable that |
| 719 | // was stripped. |
| 720 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get(); |
| 721 | if (section && section->GetFileSize() == 1) |
| 722 | { |
| 723 | m_obj_file->GetModule()->ReportWarning ("empty dSYM file detected, dSYM was created with an executable with no debug info."); |
| 724 | } |
| 725 | } |
| 726 | } |
| 727 | } |
| 728 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 729 | |
| 730 | if (debug_abbrev_file_size > 0 && debug_info_file_size > 0) |
| 731 | abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes; |
| 732 | |
| 733 | if (debug_line_file_size > 0) |
| 734 | abilities |= LineTables; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 735 | } |
| 736 | return abilities; |
| 737 | } |
| 738 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 739 | const DWARFDataExtractor& |
| 740 | SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DWARFDataExtractor &data) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 741 | { |
| 742 | if (m_flags.IsClear (got_flag)) |
| 743 | { |
| Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 744 | ModuleSP module_sp (m_obj_file->GetModule()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 745 | m_flags.Set (got_flag); |
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 746 | const SectionList *section_list = module_sp->GetSectionList(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 747 | if (section_list) |
| 748 | { |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 749 | SectionSP section_sp (section_list->FindSectionByType(sect_type, true)); |
| 750 | if (section_sp) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 751 | { |
| 752 | // See if we memory mapped the DWARF segment? |
| 753 | if (m_dwarf_data.GetByteSize()) |
| 754 | { |
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 755 | data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetFileSize()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 756 | } |
| 757 | else |
| 758 | { |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 759 | if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 760 | data.Clear(); |
| 761 | } |
| 762 | } |
| 763 | } |
| 764 | } |
| 765 | return data; |
| 766 | } |
| 767 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 768 | const DWARFDataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 769 | SymbolFileDWARF::get_debug_abbrev_data() |
| 770 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 771 | return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 772 | } |
| 773 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 774 | const DWARFDataExtractor& |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 775 | SymbolFileDWARF::get_debug_aranges_data() |
| 776 | { |
| 777 | return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges); |
| 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_frame_data() |
| 782 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 783 | return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame); |
| 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_info_data() |
| 788 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 789 | return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info); |
| 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_line_data() |
| 794 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 795 | return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line); |
| 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_loc_data() |
| 800 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 801 | return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc); |
| 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_ranges_data() |
| 806 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 807 | return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges); |
| 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& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 811 | SymbolFileDWARF::get_debug_str_data() |
| 812 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 813 | return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +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_names_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 (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names); |
| 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 | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 823 | SymbolFileDWARF::get_apple_types_data() |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 824 | { |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 825 | return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types); |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 826 | } |
| 827 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 828 | const DWARFDataExtractor& |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 829 | SymbolFileDWARF::get_apple_namespaces_data() |
| 830 | { |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 831 | return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces); |
| 832 | } |
| 833 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 834 | const DWARFDataExtractor& |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 835 | SymbolFileDWARF::get_apple_objc_data() |
| 836 | { |
| 837 | return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 838 | } |
| 839 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 840 | |
| 841 | DWARFDebugAbbrev* |
| 842 | SymbolFileDWARF::DebugAbbrev() |
| 843 | { |
| 844 | if (m_abbr.get() == NULL) |
| 845 | { |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 846 | const DWARFDataExtractor &debug_abbrev_data = get_debug_abbrev_data(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 847 | if (debug_abbrev_data.GetByteSize() > 0) |
| 848 | { |
| 849 | m_abbr.reset(new DWARFDebugAbbrev()); |
| 850 | if (m_abbr.get()) |
| 851 | m_abbr->Parse(debug_abbrev_data); |
| 852 | } |
| 853 | } |
| 854 | return m_abbr.get(); |
| 855 | } |
| 856 | |
| 857 | const DWARFDebugAbbrev* |
| 858 | SymbolFileDWARF::DebugAbbrev() const |
| 859 | { |
| 860 | return m_abbr.get(); |
| 861 | } |
| 862 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 863 | |
| 864 | DWARFDebugInfo* |
| 865 | SymbolFileDWARF::DebugInfo() |
| 866 | { |
| 867 | if (m_info.get() == NULL) |
| 868 | { |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 869 | Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", |
| 870 | __PRETTY_FUNCTION__, static_cast<void*>(this)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 871 | if (get_debug_info_data().GetByteSize() > 0) |
| 872 | { |
| 873 | m_info.reset(new DWARFDebugInfo()); |
| 874 | if (m_info.get()) |
| 875 | { |
| 876 | m_info->SetDwarfData(this); |
| 877 | } |
| 878 | } |
| 879 | } |
| 880 | return m_info.get(); |
| 881 | } |
| 882 | |
| 883 | const DWARFDebugInfo* |
| 884 | SymbolFileDWARF::DebugInfo() const |
| 885 | { |
| 886 | return m_info.get(); |
| 887 | } |
| 888 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 889 | DWARFCompileUnit* |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 890 | SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 891 | { |
| 892 | DWARFDebugInfo* info = DebugInfo(); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 893 | if (info) |
| 894 | { |
| 895 | if (GetDebugMapSymfile ()) |
| 896 | { |
| 897 | // The debug map symbol file made the compile units for this DWARF |
| 898 | // file which is .o file with DWARF in it, and we should have |
| 899 | // only 1 compile unit which is at offset zero in the DWARF. |
| 900 | // TODO: modify to support LTO .o files where each .o file might |
| 901 | // have multiple DW_TAG_compile_unit tags. |
| Greg Clayton | 68c00bd | 2015-02-05 02:10:29 +0000 | [diff] [blame] | 902 | |
| 903 | DWARFCompileUnit *dwarf_cu = info->GetCompileUnit(0).get(); |
| 904 | if (dwarf_cu && dwarf_cu->GetUserData() == NULL) |
| 905 | dwarf_cu->SetUserData(comp_unit); |
| 906 | return dwarf_cu; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 907 | } |
| 908 | else |
| 909 | { |
| 910 | // Just a normal DWARF file whose user ID for the compile unit is |
| 911 | // the DWARF offset itself |
| Greg Clayton | 68c00bd | 2015-02-05 02:10:29 +0000 | [diff] [blame] | 912 | |
| 913 | DWARFCompileUnit *dwarf_cu = info->GetCompileUnit((dw_offset_t)comp_unit->GetID()).get(); |
| 914 | if (dwarf_cu && dwarf_cu->GetUserData() == NULL) |
| 915 | dwarf_cu->SetUserData(comp_unit); |
| 916 | return dwarf_cu; |
| 917 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 918 | } |
| 919 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 920 | return NULL; |
| 921 | } |
| 922 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 923 | |
| 924 | DWARFDebugRanges* |
| 925 | SymbolFileDWARF::DebugRanges() |
| 926 | { |
| 927 | if (m_ranges.get() == NULL) |
| 928 | { |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 929 | Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", |
| 930 | __PRETTY_FUNCTION__, static_cast<void*>(this)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 931 | if (get_debug_ranges_data().GetByteSize() > 0) |
| 932 | { |
| 933 | m_ranges.reset(new DWARFDebugRanges()); |
| 934 | if (m_ranges.get()) |
| 935 | m_ranges->Extract(this); |
| 936 | } |
| 937 | } |
| 938 | return m_ranges.get(); |
| 939 | } |
| 940 | |
| 941 | const DWARFDebugRanges* |
| 942 | SymbolFileDWARF::DebugRanges() const |
| 943 | { |
| 944 | return m_ranges.get(); |
| 945 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 946 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 947 | lldb::CompUnitSP |
| 948 | SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 949 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 950 | CompUnitSP cu_sp; |
| 951 | if (dwarf_cu) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 952 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 953 | CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData(); |
| 954 | if (comp_unit) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 955 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 956 | // We already parsed this compile unit, had out a shared pointer to it |
| 957 | cu_sp = comp_unit->shared_from_this(); |
| 958 | } |
| 959 | else |
| 960 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 961 | if (GetDebugMapSymfile ()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 962 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 963 | // Let the debug map create the compile unit |
| 964 | cu_sp = m_debug_map_symfile->GetCompileUnit(this); |
| 965 | dwarf_cu->SetUserData(cu_sp.get()); |
| 966 | } |
| 967 | else |
| 968 | { |
| 969 | ModuleSP module_sp (m_obj_file->GetModule()); |
| 970 | if (module_sp) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 971 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 972 | const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly (); |
| 973 | if (cu_die) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 974 | { |
| Chaoren Lin | 0c5a9c1 | 2015-06-05 00:28:06 +0000 | [diff] [blame] | 975 | FileSpec cu_file_spec{cu_die->GetName(this, dwarf_cu), false}; |
| 976 | if (cu_file_spec) |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 977 | { |
| Chaoren Lin | 0c5a9c1 | 2015-06-05 00:28:06 +0000 | [diff] [blame] | 978 | // If we have a full path to the compile unit, we don't need to resolve |
| 979 | // the file. This can be expensive e.g. when the source files are NFS mounted. |
| Chaoren Lin | 372e906 | 2015-06-09 17:54:27 +0000 | [diff] [blame] | 980 | if (cu_file_spec.IsRelative()) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 981 | { |
| Matthew Gardiner | e81df3b | 2014-08-26 06:57:23 +0000 | [diff] [blame] | 982 | // DWARF2/3 suggests the form hostname:pathname for compilation directory. |
| 983 | // Remove the host part if present. |
| Chaoren Lin | 0c5a9c1 | 2015-06-05 00:28:06 +0000 | [diff] [blame] | 984 | const char *cu_comp_dir{cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, nullptr)}; |
| 985 | cu_file_spec.PrependPathComponent(removeHostnameFromPathname(cu_comp_dir)); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 986 | } |
| 987 | |
| Chaoren Lin | 0c5a9c1 | 2015-06-05 00:28:06 +0000 | [diff] [blame] | 988 | std::string remapped_file; |
| 989 | if (module_sp->RemapSourceFile(cu_file_spec.GetCString(), remapped_file)) |
| 990 | cu_file_spec.SetFile(remapped_file, false); |
| David Srbecky | d515e94 | 2015-07-08 14:00:04 +0000 | [diff] [blame] | 991 | } |
| Chaoren Lin | 0c5a9c1 | 2015-06-05 00:28:06 +0000 | [diff] [blame] | 992 | |
| David Srbecky | d515e94 | 2015-07-08 14:00:04 +0000 | [diff] [blame] | 993 | LanguageType cu_language = DWARFCompileUnit::LanguageTypeFromDWARF(cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0)); |
| Chaoren Lin | 0c5a9c1 | 2015-06-05 00:28:06 +0000 | [diff] [blame] | 994 | |
| David Srbecky | d515e94 | 2015-07-08 14:00:04 +0000 | [diff] [blame] | 995 | cu_sp.reset(new CompileUnit (module_sp, |
| 996 | dwarf_cu, |
| 997 | cu_file_spec, |
| 998 | MakeUserID(dwarf_cu->GetOffset()), |
| 999 | cu_language)); |
| 1000 | if (cu_sp) |
| 1001 | { |
| 1002 | // If we just created a compile unit with an invalid file spec, try and get the |
| 1003 | // first entry in the supports files from the line table as that should be the |
| 1004 | // compile unit. |
| 1005 | if (!cu_file_spec) |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1006 | { |
| David Srbecky | d515e94 | 2015-07-08 14:00:04 +0000 | [diff] [blame] | 1007 | cu_file_spec = cu_sp->GetSupportFiles().GetFileSpecAtIndex(1); |
| 1008 | if (cu_file_spec) |
| 1009 | { |
| 1010 | (FileSpec &)(*cu_sp) = cu_file_spec; |
| 1011 | // Also fix the invalid file spec which was copied from the compile unit. |
| 1012 | cu_sp->GetSupportFiles().Replace(0, cu_file_spec); |
| 1013 | } |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1014 | } |
| David Srbecky | d515e94 | 2015-07-08 14:00:04 +0000 | [diff] [blame] | 1015 | |
| 1016 | dwarf_cu->SetUserData(cu_sp.get()); |
| 1017 | |
| 1018 | // Figure out the compile unit index if we weren't given one |
| 1019 | if (cu_idx == UINT32_MAX) |
| 1020 | DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx); |
| 1021 | |
| 1022 | m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp); |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1023 | } |
| 1024 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1025 | } |
| 1026 | } |
| 1027 | } |
| 1028 | } |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1029 | return cu_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1030 | } |
| 1031 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1032 | uint32_t |
| 1033 | SymbolFileDWARF::GetNumCompileUnits() |
| 1034 | { |
| 1035 | DWARFDebugInfo* info = DebugInfo(); |
| 1036 | if (info) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1037 | return info->GetNumCompileUnits(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1038 | return 0; |
| 1039 | } |
| 1040 | |
| 1041 | CompUnitSP |
| 1042 | SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx) |
| 1043 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1044 | CompUnitSP cu_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1045 | DWARFDebugInfo* info = DebugInfo(); |
| 1046 | if (info) |
| 1047 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1048 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx); |
| 1049 | if (dwarf_cu) |
| 1050 | cu_sp = ParseCompileUnit(dwarf_cu, cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1051 | } |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1052 | return cu_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1055 | Function * |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1056 | SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1057 | { |
| 1058 | DWARFDebugRanges::RangeList func_ranges; |
| 1059 | const char *name = NULL; |
| 1060 | const char *mangled = NULL; |
| 1061 | int decl_file = 0; |
| 1062 | int decl_line = 0; |
| 1063 | int decl_column = 0; |
| 1064 | int call_file = 0; |
| 1065 | int call_line = 0; |
| 1066 | int call_column = 0; |
| 1067 | DWARFExpression frame_base; |
| 1068 | |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1069 | assert (die->Tag() == DW_TAG_subprogram); |
| 1070 | |
| 1071 | if (die->Tag() != DW_TAG_subprogram) |
| 1072 | return NULL; |
| 1073 | |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1074 | if (die->GetDIENamesAndRanges (this, |
| 1075 | dwarf_cu, |
| 1076 | name, |
| 1077 | mangled, |
| 1078 | func_ranges, |
| 1079 | decl_file, |
| 1080 | decl_line, |
| 1081 | decl_column, |
| 1082 | call_file, |
| 1083 | call_line, |
| 1084 | call_column, |
| 1085 | &frame_base)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1086 | { |
| 1087 | // Union of all ranges in the function DIE (if the function is discontiguous) |
| 1088 | AddressRange func_range; |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1089 | lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0); |
| 1090 | lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1091 | if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr) |
| 1092 | { |
| Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1093 | ModuleSP module_sp (m_obj_file->GetModule()); |
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 1094 | func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, module_sp->GetSectionList()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1095 | if (func_range.GetBaseAddress().IsValid()) |
| 1096 | func_range.SetByteSize(highest_func_addr - lowest_func_addr); |
| 1097 | } |
| 1098 | |
| 1099 | if (func_range.GetBaseAddress().IsValid()) |
| 1100 | { |
| 1101 | Mangled func_name; |
| 1102 | if (mangled) |
| Greg Clayton | 037520e | 2012-07-18 23:18:10 +0000 | [diff] [blame] | 1103 | func_name.SetValue(ConstString(mangled), true); |
| Siva Chandra | 462722d | 2015-03-27 00:10:04 +0000 | [diff] [blame] | 1104 | else if (die->GetParent()->Tag() == DW_TAG_compile_unit && |
| 1105 | LanguageRuntime::LanguageIsCPlusPlus(dwarf_cu->GetLanguageType()) && |
| Greg Clayton | 9438056 | 2015-05-15 22:20:29 +0000 | [diff] [blame] | 1106 | name && strcmp(name, "main") != 0) |
| Siva Chandra | 462722d | 2015-03-27 00:10:04 +0000 | [diff] [blame] | 1107 | { |
| 1108 | // If the mangled name is not present in the DWARF, generate the demangled name |
| 1109 | // using the decl context. We skip if the function is "main" as its name is |
| 1110 | // never mangled. |
| 1111 | bool is_static = false; |
| 1112 | bool is_variadic = false; |
| 1113 | unsigned type_quals = 0; |
| 1114 | std::vector<ClangASTType> param_types; |
| 1115 | std::vector<clang::ParmVarDecl*> param_decls; |
| 1116 | const DWARFDebugInfoEntry *decl_ctx_die = NULL; |
| 1117 | DWARFDeclContext decl_ctx; |
| 1118 | StreamString sstr; |
| 1119 | |
| 1120 | die->GetDWARFDeclContext(this, dwarf_cu, decl_ctx); |
| 1121 | sstr << decl_ctx.GetQualifiedName(); |
| 1122 | |
| 1123 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE(dwarf_cu, |
| 1124 | die, |
| 1125 | &decl_ctx_die); |
| 1126 | ParseChildParameters(sc, |
| 1127 | containing_decl_ctx, |
| 1128 | dwarf_cu, |
| 1129 | die, |
| 1130 | true, |
| 1131 | is_static, |
| 1132 | is_variadic, |
| 1133 | param_types, |
| 1134 | param_decls, |
| 1135 | type_quals); |
| 1136 | sstr << "("; |
| 1137 | for (size_t i = 0; i < param_types.size(); i++) |
| 1138 | { |
| 1139 | if (i > 0) |
| 1140 | sstr << ", "; |
| 1141 | sstr << param_types[i].GetTypeName(); |
| 1142 | } |
| 1143 | if (is_variadic) |
| 1144 | sstr << ", ..."; |
| 1145 | sstr << ")"; |
| 1146 | if (type_quals & clang::Qualifiers::Const) |
| 1147 | sstr << " const"; |
| 1148 | |
| 1149 | func_name.SetValue(ConstString(sstr.GetData()), false); |
| 1150 | } |
| 1151 | else |
| Greg Clayton | 037520e | 2012-07-18 23:18:10 +0000 | [diff] [blame] | 1152 | func_name.SetValue(ConstString(name), false); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1153 | |
| 1154 | FunctionSP func_sp; |
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1155 | std::unique_ptr<Declaration> decl_ap; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1156 | if (decl_file != 0 || decl_line != 0 || decl_column != 0) |
| Greg Clayton | d7e0546 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 1157 | decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), |
| 1158 | decl_line, |
| 1159 | decl_column)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1160 | |
| Greg Clayton | 0bd4e1b | 2011-09-30 20:52:25 +0000 | [diff] [blame] | 1161 | // Supply the type _only_ if it has already been parsed |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 1162 | Type *func_type = m_die_to_type.lookup (die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1163 | |
| 1164 | assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED); |
| 1165 | |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1166 | if (FixupAddress (func_range.GetBaseAddress())) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1167 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1168 | const user_id_t func_user_id = MakeUserID(die->GetOffset()); |
| 1169 | func_sp.reset(new Function (sc.comp_unit, |
| 1170 | MakeUserID(func_user_id), // UserID is the DIE offset |
| 1171 | MakeUserID(func_user_id), |
| 1172 | func_name, |
| 1173 | func_type, |
| 1174 | func_range)); // first address range |
| 1175 | |
| 1176 | if (func_sp.get() != NULL) |
| 1177 | { |
| 1178 | if (frame_base.IsValid()) |
| 1179 | func_sp->GetFrameBaseExpression() = frame_base; |
| 1180 | sc.comp_unit->AddFunction(func_sp); |
| 1181 | return func_sp.get(); |
| 1182 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1183 | } |
| 1184 | } |
| 1185 | } |
| 1186 | return NULL; |
| 1187 | } |
| 1188 | |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1189 | bool |
| 1190 | SymbolFileDWARF::FixupAddress (Address &addr) |
| 1191 | { |
| 1192 | SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile (); |
| 1193 | if (debug_map_symfile) |
| 1194 | { |
| 1195 | return debug_map_symfile->LinkOSOAddress(addr); |
| 1196 | } |
| 1197 | // This is a normal DWARF file, no address fixups need to happen |
| 1198 | return true; |
| 1199 | } |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1200 | lldb::LanguageType |
| 1201 | SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc) |
| 1202 | { |
| 1203 | assert (sc.comp_unit); |
| 1204 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| 1205 | if (dwarf_cu) |
| 1206 | { |
| 1207 | const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly(); |
| Jim Ingham | 28eb571 | 2012-10-12 17:34:26 +0000 | [diff] [blame] | 1208 | if (die) |
| Dawn Perchik | d0e87eb | 2015-06-17 22:30:24 +0000 | [diff] [blame] | 1209 | return DWARFCompileUnit::LanguageTypeFromDWARF(die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0)); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1210 | } |
| 1211 | return eLanguageTypeUnknown; |
| 1212 | } |
| 1213 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1214 | size_t |
| 1215 | SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc) |
| 1216 | { |
| 1217 | assert (sc.comp_unit); |
| 1218 | size_t functions_added = 0; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1219 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1220 | if (dwarf_cu) |
| 1221 | { |
| 1222 | DWARFDIECollection function_dies; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1223 | 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] | 1224 | size_t func_idx; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1225 | for (func_idx = 0; func_idx < num_functions; ++func_idx) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1226 | { |
| 1227 | const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1228 | if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1229 | { |
| 1230 | if (ParseCompileUnitFunction(sc, dwarf_cu, die)) |
| 1231 | ++functions_added; |
| 1232 | } |
| 1233 | } |
| 1234 | //FixupTypes(); |
| 1235 | } |
| 1236 | return functions_added; |
| 1237 | } |
| 1238 | |
| 1239 | bool |
| 1240 | SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files) |
| 1241 | { |
| 1242 | assert (sc.comp_unit); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1243 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1244 | if (dwarf_cu) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1245 | { |
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1246 | const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1247 | |
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1248 | if (cu_die) |
| 1249 | { |
| 1250 | 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] | 1251 | |
| 1252 | // DWARF2/3 suggests the form hostname:pathname for compilation directory. |
| 1253 | // Remove the host part if present. |
| 1254 | cu_comp_dir = removeHostnameFromPathname(cu_comp_dir); |
| 1255 | |
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1256 | 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] | 1257 | |
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1258 | // All file indexes in DWARF are one based and a file of index zero is |
| 1259 | // supposed to be the compile unit itself. |
| 1260 | support_files.Append (*sc.comp_unit); |
| 1261 | |
| 1262 | return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files); |
| 1263 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1264 | } |
| 1265 | return false; |
| 1266 | } |
| 1267 | |
| Sean Callanan | f0c5aeb | 2015-04-20 16:31:29 +0000 | [diff] [blame] | 1268 | bool |
| 1269 | SymbolFileDWARF::ParseImportedModules (const lldb_private::SymbolContext &sc, std::vector<lldb_private::ConstString> &imported_modules) |
| 1270 | { |
| 1271 | assert (sc.comp_unit); |
| 1272 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| 1273 | if (dwarf_cu) |
| 1274 | { |
| 1275 | if (ClangModulesDeclVendor::LanguageSupportsClangModules(sc.comp_unit->GetLanguage())) |
| 1276 | { |
| 1277 | UpdateExternalModuleListIfNeeded(); |
| 1278 | for (const std::pair<uint64_t, const ClangModuleInfo> &external_type_module : m_external_type_modules) |
| 1279 | { |
| 1280 | imported_modules.push_back(external_type_module.second.m_name); |
| 1281 | } |
| 1282 | } |
| 1283 | } |
| 1284 | return false; |
| 1285 | } |
| 1286 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1287 | struct ParseDWARFLineTableCallbackInfo |
| 1288 | { |
| 1289 | LineTable* line_table; |
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1290 | std::unique_ptr<LineSequence> sequence_ap; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1291 | }; |
| 1292 | |
| 1293 | //---------------------------------------------------------------------- |
| 1294 | // ParseStatementTableCallback |
| 1295 | //---------------------------------------------------------------------- |
| 1296 | static void |
| 1297 | ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData) |
| 1298 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1299 | if (state.row == DWARFDebugLine::State::StartParsingLineTable) |
| 1300 | { |
| 1301 | // Just started parsing the line table |
| 1302 | } |
| 1303 | else if (state.row == DWARFDebugLine::State::DoneParsingLineTable) |
| 1304 | { |
| 1305 | // Done parsing line table, nothing to do for the cleanup |
| 1306 | } |
| 1307 | else |
| 1308 | { |
| 1309 | ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData; |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1310 | LineTable* line_table = info->line_table; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1311 | |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1312 | // If this is our first time here, we need to create a |
| 1313 | // sequence container. |
| 1314 | if (!info->sequence_ap.get()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1315 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1316 | info->sequence_ap.reset(line_table->CreateLineSequenceContainer()); |
| 1317 | assert(info->sequence_ap.get()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1318 | } |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1319 | line_table->AppendLineEntryToSequence (info->sequence_ap.get(), |
| 1320 | state.address, |
| 1321 | state.line, |
| 1322 | state.column, |
| 1323 | state.file, |
| 1324 | state.is_stmt, |
| 1325 | state.basic_block, |
| 1326 | state.prologue_end, |
| 1327 | state.epilogue_begin, |
| 1328 | state.end_sequence); |
| 1329 | if (state.end_sequence) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1330 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1331 | // First, put the current sequence into the line table. |
| 1332 | line_table->InsertSequence(info->sequence_ap.get()); |
| 1333 | // Then, empty it to prepare for the next sequence. |
| 1334 | info->sequence_ap->Clear(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1335 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1336 | } |
| 1337 | } |
| 1338 | |
| 1339 | bool |
| 1340 | SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc) |
| 1341 | { |
| 1342 | assert (sc.comp_unit); |
| 1343 | if (sc.comp_unit->GetLineTable() != NULL) |
| 1344 | return true; |
| 1345 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1346 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1347 | if (dwarf_cu) |
| 1348 | { |
| 1349 | const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly(); |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1350 | if (dwarf_cu_die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1351 | { |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1352 | const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET); |
| 1353 | if (cu_line_offset != DW_INVALID_OFFSET) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1354 | { |
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1355 | std::unique_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit)); |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1356 | if (line_table_ap.get()) |
| 1357 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1358 | ParseDWARFLineTableCallbackInfo info; |
| 1359 | info.line_table = line_table_ap.get(); |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1360 | lldb::offset_t offset = cu_line_offset; |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1361 | DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info); |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1362 | if (m_debug_map_symfile) |
| 1363 | { |
| 1364 | // We have an object file that has a line table with addresses |
| 1365 | // that are not linked. We need to link the line table and convert |
| 1366 | // the addresses that are relative to the .o file into addresses |
| 1367 | // for the main executable. |
| 1368 | sc.comp_unit->SetLineTable (m_debug_map_symfile->LinkOSOLineTable (this, line_table_ap.get())); |
| 1369 | } |
| 1370 | else |
| 1371 | { |
| 1372 | sc.comp_unit->SetLineTable(line_table_ap.release()); |
| 1373 | return true; |
| 1374 | } |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1375 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1376 | } |
| 1377 | } |
| 1378 | } |
| 1379 | return false; |
| 1380 | } |
| 1381 | |
| 1382 | size_t |
| 1383 | SymbolFileDWARF::ParseFunctionBlocks |
| 1384 | ( |
| 1385 | const SymbolContext& sc, |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1386 | Block *parent_block, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1387 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1388 | const DWARFDebugInfoEntry *die, |
| 1389 | addr_t subprogram_low_pc, |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1390 | uint32_t depth |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1391 | ) |
| 1392 | { |
| 1393 | size_t blocks_added = 0; |
| 1394 | while (die != NULL) |
| 1395 | { |
| 1396 | dw_tag_t tag = die->Tag(); |
| 1397 | |
| 1398 | switch (tag) |
| 1399 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1400 | case DW_TAG_inlined_subroutine: |
| Greg Clayton | b4d3733 | 2011-08-12 16:22:48 +0000 | [diff] [blame] | 1401 | case DW_TAG_subprogram: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1402 | case DW_TAG_lexical_block: |
| 1403 | { |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1404 | Block *block = NULL; |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1405 | if (tag == DW_TAG_subprogram) |
| 1406 | { |
| 1407 | // Skip any DW_TAG_subprogram DIEs that are inside |
| 1408 | // of a normal or inlined functions. These will be |
| 1409 | // parsed on their own as separate entities. |
| 1410 | |
| 1411 | if (depth > 0) |
| 1412 | break; |
| 1413 | |
| 1414 | block = parent_block; |
| 1415 | } |
| 1416 | else |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1417 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1418 | BlockSP block_sp(new Block (MakeUserID(die->GetOffset()))); |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1419 | parent_block->AddChild(block_sp); |
| 1420 | block = block_sp.get(); |
| 1421 | } |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1422 | DWARFDebugRanges::RangeList ranges; |
| 1423 | const char *name = NULL; |
| 1424 | const char *mangled_name = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1425 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1426 | int decl_file = 0; |
| 1427 | int decl_line = 0; |
| 1428 | int decl_column = 0; |
| 1429 | int call_file = 0; |
| 1430 | int call_line = 0; |
| 1431 | int call_column = 0; |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1432 | if (die->GetDIENamesAndRanges (this, |
| 1433 | dwarf_cu, |
| 1434 | name, |
| 1435 | mangled_name, |
| 1436 | ranges, |
| 1437 | decl_file, decl_line, decl_column, |
| 1438 | call_file, call_line, call_column)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1439 | { |
| 1440 | if (tag == DW_TAG_subprogram) |
| 1441 | { |
| 1442 | assert (subprogram_low_pc == LLDB_INVALID_ADDRESS); |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1443 | subprogram_low_pc = ranges.GetMinRangeBase(0); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1444 | } |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1445 | else if (tag == DW_TAG_inlined_subroutine) |
| 1446 | { |
| 1447 | // We get called here for inlined subroutines in two ways. |
| 1448 | // The first time is when we are making the Function object |
| 1449 | // for this inlined concrete instance. Since we're creating a top level block at |
| 1450 | // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to |
| 1451 | // adjust the containing address. |
| 1452 | // The second time is when we are parsing the blocks inside the function that contains |
| 1453 | // the inlined concrete instance. Since these will be blocks inside the containing "real" |
| 1454 | // function the offset will be for that function. |
| 1455 | if (subprogram_low_pc == LLDB_INVALID_ADDRESS) |
| 1456 | { |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1457 | subprogram_low_pc = ranges.GetMinRangeBase(0); |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1458 | } |
| 1459 | } |
| Greg Clayton | 103f309 | 2015-01-15 03:04:37 +0000 | [diff] [blame] | 1460 | |
| 1461 | const size_t num_ranges = ranges.GetSize(); |
| 1462 | for (size_t i = 0; i<num_ranges; ++i) |
| 1463 | { |
| 1464 | const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i); |
| 1465 | const addr_t range_base = range.GetRangeBase(); |
| 1466 | if (range_base >= subprogram_low_pc) |
| 1467 | block->AddRange(Block::Range (range_base - subprogram_low_pc, range.GetByteSize())); |
| 1468 | else |
| 1469 | { |
| 1470 | 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", |
| 1471 | block->GetID(), |
| 1472 | range_base, |
| 1473 | range.GetRangeEnd(), |
| 1474 | subprogram_low_pc); |
| 1475 | } |
| 1476 | } |
| 1477 | block->FinalizeRanges (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1478 | |
| 1479 | if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL)) |
| 1480 | { |
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1481 | std::unique_ptr<Declaration> decl_ap; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1482 | if (decl_file != 0 || decl_line != 0 || decl_column != 0) |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1483 | decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), |
| 1484 | decl_line, decl_column)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1485 | |
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1486 | std::unique_ptr<Declaration> call_ap; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1487 | if (call_file != 0 || call_line != 0 || call_column != 0) |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1488 | call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file), |
| 1489 | call_line, call_column)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1490 | |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1491 | block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1492 | } |
| 1493 | |
| 1494 | ++blocks_added; |
| 1495 | |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1496 | if (die->HasChildren()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1497 | { |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1498 | blocks_added += ParseFunctionBlocks (sc, |
| 1499 | block, |
| 1500 | dwarf_cu, |
| 1501 | die->GetFirstChild(), |
| 1502 | subprogram_low_pc, |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1503 | depth + 1); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1504 | } |
| 1505 | } |
| 1506 | } |
| 1507 | break; |
| 1508 | default: |
| 1509 | break; |
| 1510 | } |
| 1511 | |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1512 | // Only parse siblings of the block if we are not at depth zero. A depth |
| 1513 | // of zero indicates we are currently parsing the top level |
| 1514 | // DW_TAG_subprogram DIE |
| 1515 | |
| 1516 | if (depth == 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1517 | die = NULL; |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1518 | else |
| 1519 | die = die->GetSibling(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1520 | } |
| 1521 | return blocks_added; |
| 1522 | } |
| 1523 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1524 | bool |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1525 | SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu, |
| 1526 | const DWARFDebugInfoEntry *die, |
| 1527 | ClangASTContext::TemplateParameterInfos &template_param_infos) |
| 1528 | { |
| 1529 | const dw_tag_t tag = die->Tag(); |
| 1530 | |
| 1531 | switch (tag) |
| 1532 | { |
| 1533 | case DW_TAG_template_type_parameter: |
| 1534 | case DW_TAG_template_value_parameter: |
| 1535 | { |
| Todd Fiala | ee8bfc6 | 2014-09-11 17:29:12 +0000 | [diff] [blame] | 1536 | 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] | 1537 | |
| 1538 | DWARFDebugInfoEntry::Attributes attributes; |
| 1539 | const size_t num_attributes = die->GetAttributes (this, |
| 1540 | dwarf_cu, |
| 1541 | fixed_form_sizes, |
| 1542 | attributes); |
| 1543 | const char *name = NULL; |
| 1544 | Type *lldb_type = NULL; |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1545 | ClangASTType clang_type; |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1546 | uint64_t uval64 = 0; |
| 1547 | bool uval64_valid = false; |
| 1548 | if (num_attributes > 0) |
| 1549 | { |
| 1550 | DWARFFormValue form_value; |
| 1551 | for (size_t i=0; i<num_attributes; ++i) |
| 1552 | { |
| 1553 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 1554 | |
| 1555 | switch (attr) |
| 1556 | { |
| 1557 | case DW_AT_name: |
| 1558 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1559 | name = form_value.AsCString(&get_debug_str_data()); |
| 1560 | break; |
| 1561 | |
| 1562 | case DW_AT_type: |
| 1563 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1564 | { |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 1565 | const dw_offset_t type_die_offset = form_value.Reference(); |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1566 | lldb_type = ResolveTypeUID(type_die_offset); |
| 1567 | if (lldb_type) |
| 1568 | clang_type = lldb_type->GetClangForwardType(); |
| 1569 | } |
| 1570 | break; |
| 1571 | |
| 1572 | case DW_AT_const_value: |
| 1573 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1574 | { |
| 1575 | uval64_valid = true; |
| 1576 | uval64 = form_value.Unsigned(); |
| 1577 | } |
| 1578 | break; |
| 1579 | default: |
| 1580 | break; |
| 1581 | } |
| 1582 | } |
| 1583 | |
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1584 | clang::ASTContext *ast = GetClangASTContext().getASTContext(); |
| 1585 | if (!clang_type) |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1586 | clang_type = GetClangASTContext().GetBasicType(eBasicTypeVoid); |
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1587 | |
| 1588 | if (clang_type) |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1589 | { |
| 1590 | bool is_signed = false; |
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1591 | if (name && name[0]) |
| 1592 | template_param_infos.names.push_back(name); |
| 1593 | else |
| 1594 | template_param_infos.names.push_back(NULL); |
| 1595 | |
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1596 | if (tag == DW_TAG_template_value_parameter && |
| 1597 | lldb_type != NULL && |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1598 | clang_type.IsIntegerType (is_signed) && |
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1599 | uval64_valid) |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1600 | { |
| 1601 | llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed); |
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1602 | template_param_infos.args.push_back (clang::TemplateArgument (*ast, |
| Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1603 | llvm::APSInt(apint), |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 1604 | clang_type.GetQualType())); |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1605 | } |
| 1606 | else |
| 1607 | { |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 1608 | template_param_infos.args.push_back (clang::TemplateArgument (clang_type.GetQualType())); |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1609 | } |
| 1610 | } |
| 1611 | else |
| 1612 | { |
| 1613 | return false; |
| 1614 | } |
| 1615 | |
| 1616 | } |
| 1617 | } |
| 1618 | return true; |
| 1619 | |
| 1620 | default: |
| 1621 | break; |
| 1622 | } |
| 1623 | return false; |
| 1624 | } |
| 1625 | |
| 1626 | bool |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1627 | SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu, |
| 1628 | const DWARFDebugInfoEntry *parent_die, |
| 1629 | ClangASTContext::TemplateParameterInfos &template_param_infos) |
| 1630 | { |
| 1631 | |
| 1632 | if (parent_die == NULL) |
| Filipe Cabecinhas | 52008c6 | 2012-05-23 16:24:11 +0000 | [diff] [blame] | 1633 | return false; |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1634 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1635 | Args template_parameter_names; |
| 1636 | for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); |
| 1637 | die != NULL; |
| 1638 | die = die->GetSibling()) |
| 1639 | { |
| 1640 | const dw_tag_t tag = die->Tag(); |
| 1641 | |
| 1642 | switch (tag) |
| 1643 | { |
| 1644 | case DW_TAG_template_type_parameter: |
| 1645 | case DW_TAG_template_value_parameter: |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1646 | ParseTemplateDIE (dwarf_cu, die, template_param_infos); |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1647 | break; |
| 1648 | |
| 1649 | default: |
| 1650 | break; |
| 1651 | } |
| 1652 | } |
| 1653 | if (template_param_infos.args.empty()) |
| 1654 | return false; |
| 1655 | return template_param_infos.args.size() == template_param_infos.names.size(); |
| 1656 | } |
| 1657 | |
| 1658 | clang::ClassTemplateDecl * |
| 1659 | SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx, |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1660 | lldb::AccessType access_type, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1661 | const char *parent_name, |
| 1662 | int tag_decl_kind, |
| 1663 | const ClangASTContext::TemplateParameterInfos &template_param_infos) |
| 1664 | { |
| 1665 | if (template_param_infos.IsValid()) |
| 1666 | { |
| 1667 | std::string template_basename(parent_name); |
| 1668 | template_basename.erase (template_basename.find('<')); |
| 1669 | ClangASTContext &ast = GetClangASTContext(); |
| 1670 | |
| 1671 | return ast.CreateClassTemplateDecl (decl_ctx, |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1672 | access_type, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1673 | template_basename.c_str(), |
| 1674 | tag_decl_kind, |
| 1675 | template_param_infos); |
| 1676 | } |
| 1677 | return NULL; |
| 1678 | } |
| 1679 | |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1680 | class SymbolFileDWARF::DelayedAddObjCClassProperty |
| 1681 | { |
| 1682 | public: |
| 1683 | DelayedAddObjCClassProperty |
| 1684 | ( |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1685 | const ClangASTType &class_opaque_type, |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1686 | const char *property_name, |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1687 | 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] | 1688 | clang::ObjCIvarDecl *ivar_decl, |
| 1689 | const char *property_setter_name, |
| 1690 | const char *property_getter_name, |
| 1691 | uint32_t property_attributes, |
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1692 | const ClangASTMetadata *metadata |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1693 | ) : |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1694 | m_class_opaque_type (class_opaque_type), |
| 1695 | m_property_name (property_name), |
| 1696 | m_property_opaque_type (property_opaque_type), |
| 1697 | m_ivar_decl (ivar_decl), |
| 1698 | m_property_setter_name (property_setter_name), |
| 1699 | m_property_getter_name (property_getter_name), |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1700 | m_property_attributes (property_attributes) |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1701 | { |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1702 | if (metadata != NULL) |
| 1703 | { |
| 1704 | m_metadata_ap.reset(new ClangASTMetadata()); |
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1705 | *m_metadata_ap = *metadata; |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1706 | } |
| 1707 | } |
| 1708 | |
| 1709 | DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs) |
| 1710 | { |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1711 | *this = rhs; |
| Daniel Malea | d4c5be6 | 2012-11-12 21:02:14 +0000 | [diff] [blame] | 1712 | } |
| 1713 | |
| 1714 | DelayedAddObjCClassProperty& operator= (const DelayedAddObjCClassProperty &rhs) |
| 1715 | { |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1716 | m_class_opaque_type = rhs.m_class_opaque_type; |
| 1717 | m_property_name = rhs.m_property_name; |
| 1718 | m_property_opaque_type = rhs.m_property_opaque_type; |
| 1719 | m_ivar_decl = rhs.m_ivar_decl; |
| 1720 | m_property_setter_name = rhs.m_property_setter_name; |
| 1721 | m_property_getter_name = rhs.m_property_getter_name; |
| 1722 | m_property_attributes = rhs.m_property_attributes; |
| 1723 | |
| 1724 | if (rhs.m_metadata_ap.get()) |
| 1725 | { |
| 1726 | m_metadata_ap.reset (new ClangASTMetadata()); |
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1727 | *m_metadata_ap = *rhs.m_metadata_ap; |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1728 | } |
| Daniel Malea | d4c5be6 | 2012-11-12 21:02:14 +0000 | [diff] [blame] | 1729 | return *this; |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1730 | } |
| 1731 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1732 | bool |
| 1733 | Finalize() |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1734 | { |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 1735 | return m_class_opaque_type.AddObjCClassProperty (m_property_name, |
| 1736 | m_property_opaque_type, |
| 1737 | m_ivar_decl, |
| 1738 | m_property_setter_name, |
| 1739 | m_property_getter_name, |
| 1740 | m_property_attributes, |
| 1741 | m_metadata_ap.get()); |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1742 | } |
| 1743 | private: |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1744 | ClangASTType m_class_opaque_type; |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1745 | const char *m_property_name; |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1746 | ClangASTType m_property_opaque_type; |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1747 | clang::ObjCIvarDecl *m_ivar_decl; |
| 1748 | const char *m_property_setter_name; |
| 1749 | const char *m_property_getter_name; |
| 1750 | uint32_t m_property_attributes; |
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1751 | std::unique_ptr<ClangASTMetadata> m_metadata_ap; |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1752 | }; |
| 1753 | |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1754 | struct BitfieldInfo |
| 1755 | { |
| 1756 | uint64_t bit_size; |
| 1757 | uint64_t bit_offset; |
| 1758 | |
| 1759 | BitfieldInfo () : |
| 1760 | bit_size (LLDB_INVALID_ADDRESS), |
| 1761 | bit_offset (LLDB_INVALID_ADDRESS) |
| 1762 | { |
| 1763 | } |
| 1764 | |
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 1765 | void |
| 1766 | Clear() |
| 1767 | { |
| 1768 | bit_size = LLDB_INVALID_ADDRESS; |
| 1769 | bit_offset = LLDB_INVALID_ADDRESS; |
| 1770 | } |
| 1771 | |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1772 | bool IsValid () |
| 1773 | { |
| 1774 | return (bit_size != LLDB_INVALID_ADDRESS) && |
| 1775 | (bit_offset != LLDB_INVALID_ADDRESS); |
| 1776 | } |
| 1777 | }; |
| 1778 | |
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1779 | |
| 1780 | bool |
| 1781 | SymbolFileDWARF::ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu, |
| 1782 | const DWARFDebugInfoEntry *parent_die) |
| 1783 | { |
| 1784 | if (parent_die) |
| 1785 | { |
| 1786 | for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 1787 | { |
| 1788 | dw_tag_t tag = die->Tag(); |
| 1789 | bool check_virtuality = false; |
| 1790 | switch (tag) |
| 1791 | { |
| 1792 | case DW_TAG_inheritance: |
| 1793 | case DW_TAG_subprogram: |
| 1794 | check_virtuality = true; |
| 1795 | break; |
| 1796 | default: |
| 1797 | break; |
| 1798 | } |
| 1799 | if (check_virtuality) |
| 1800 | { |
| 1801 | if (die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_virtuality, 0) != 0) |
| 1802 | return true; |
| 1803 | } |
| 1804 | } |
| 1805 | } |
| 1806 | return false; |
| 1807 | } |
| 1808 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1809 | size_t |
| 1810 | SymbolFileDWARF::ParseChildMembers |
| 1811 | ( |
| 1812 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1813 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1814 | const DWARFDebugInfoEntry *parent_die, |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1815 | ClangASTType &class_clang_type, |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1816 | const LanguageType class_language, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1817 | std::vector<clang::CXXBaseSpecifier *>& base_classes, |
| 1818 | std::vector<int>& member_accessibilities, |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1819 | DWARFDIECollection& member_function_dies, |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1820 | DelayedPropertyList& delayed_properties, |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1821 | AccessType& default_accessibility, |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1822 | bool &is_a_class, |
| 1823 | LayoutInfo &layout_info |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1824 | ) |
| 1825 | { |
| 1826 | if (parent_die == NULL) |
| 1827 | return 0; |
| 1828 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1829 | size_t count = 0; |
| 1830 | const DWARFDebugInfoEntry *die; |
| Todd Fiala | ee8bfc6 | 2014-09-11 17:29:12 +0000 | [diff] [blame] | 1831 | 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] | 1832 | uint32_t member_idx = 0; |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1833 | BitfieldInfo last_field_info; |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 1834 | ModuleSP module = GetObjectFile()->GetModule(); |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 1835 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1836 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 1837 | { |
| 1838 | dw_tag_t tag = die->Tag(); |
| 1839 | |
| 1840 | switch (tag) |
| 1841 | { |
| 1842 | case DW_TAG_member: |
| Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1843 | case DW_TAG_APPLE_property: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1844 | { |
| 1845 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1846 | const size_t num_attributes = die->GetAttributes (this, |
| 1847 | dwarf_cu, |
| 1848 | fixed_form_sizes, |
| 1849 | attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1850 | if (num_attributes > 0) |
| 1851 | { |
| 1852 | Declaration decl; |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1853 | //DWARFExpression location; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1854 | const char *name = NULL; |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1855 | const char *prop_name = NULL; |
| 1856 | const char *prop_getter_name = NULL; |
| 1857 | const char *prop_setter_name = NULL; |
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1858 | uint32_t prop_attributes = 0; |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1859 | |
| 1860 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1861 | bool is_artificial = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1862 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1863 | AccessType accessibility = eAccessNone; |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1864 | uint32_t member_byte_offset = UINT32_MAX; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1865 | size_t byte_size = 0; |
| 1866 | size_t bit_offset = 0; |
| 1867 | size_t bit_size = 0; |
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1868 | 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] | 1869 | uint32_t i; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1870 | for (i=0; i<num_attributes && !is_artificial; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1871 | { |
| 1872 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 1873 | DWARFFormValue form_value; |
| 1874 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1875 | { |
| 1876 | switch (attr) |
| 1877 | { |
| 1878 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 1879 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 1880 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 1881 | 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] | 1882 | case DW_AT_type: encoding_uid = form_value.Reference(); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1883 | case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break; |
| 1884 | case DW_AT_bit_size: bit_size = form_value.Unsigned(); break; |
| 1885 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; |
| 1886 | case DW_AT_data_member_location: |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1887 | if (form_value.BlockData()) |
| 1888 | { |
| 1889 | Value initialValue(0); |
| 1890 | Value memberOffset(0); |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 1891 | const DWARFDataExtractor& debug_info_data = get_debug_info_data(); |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1892 | uint32_t block_length = form_value.Unsigned(); |
| 1893 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 1894 | if (DWARFExpression::Evaluate(NULL, // ExecutionContext * |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1895 | NULL, // ClangExpressionVariableList * |
| 1896 | NULL, // ClangExpressionDeclMap * |
| 1897 | NULL, // RegisterContext * |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 1898 | module, |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1899 | debug_info_data, |
| 1900 | block_offset, |
| 1901 | block_length, |
| 1902 | eRegisterKindDWARF, |
| 1903 | &initialValue, |
| 1904 | memberOffset, |
| 1905 | NULL)) |
| 1906 | { |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1907 | member_byte_offset = memberOffset.ResolveValue(NULL).UInt(); |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1908 | } |
| 1909 | } |
| Ashok Thirumurthi | a4658a5 | 2013-07-30 14:58:39 +0000 | [diff] [blame] | 1910 | else |
| 1911 | { |
| 1912 | // With DWARF 3 and later, if the value is an integer constant, |
| 1913 | // this form value is the offset in bytes from the beginning |
| 1914 | // of the containing entity. |
| 1915 | member_byte_offset = form_value.Unsigned(); |
| 1916 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1917 | break; |
| 1918 | |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1919 | 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] | 1920 | case DW_AT_artificial: is_artificial = form_value.Boolean(); break; |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1921 | case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break; |
| 1922 | case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break; |
| 1923 | case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break; |
| 1924 | case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break; |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 1925 | case DW_AT_external: is_external = form_value.Boolean(); break; |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1926 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1927 | default: |
| Greg Clayton | 1b02c17 | 2012-03-14 21:00:47 +0000 | [diff] [blame] | 1928 | case DW_AT_declaration: |
| 1929 | case DW_AT_description: |
| 1930 | case DW_AT_mutable: |
| 1931 | case DW_AT_visibility: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1932 | case DW_AT_sibling: |
| 1933 | break; |
| 1934 | } |
| 1935 | } |
| 1936 | } |
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1937 | |
| 1938 | if (prop_name) |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1939 | { |
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1940 | ConstString fixed_getter; |
| 1941 | ConstString fixed_setter; |
| 1942 | |
| 1943 | // Check if the property getter/setter were provided as full |
| 1944 | // names. We want basenames, so we extract them. |
| 1945 | |
| 1946 | if (prop_getter_name && prop_getter_name[0] == '-') |
| 1947 | { |
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 1948 | ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true); |
| 1949 | prop_getter_name = prop_getter_method.GetSelector().GetCString(); |
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1950 | } |
| 1951 | |
| 1952 | if (prop_setter_name && prop_setter_name[0] == '-') |
| 1953 | { |
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 1954 | ObjCLanguageRuntime::MethodName prop_setter_method(prop_setter_name, true); |
| 1955 | prop_setter_name = prop_setter_method.GetSelector().GetCString(); |
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | // If the names haven't been provided, they need to be |
| 1959 | // filled in. |
| 1960 | |
| 1961 | if (!prop_getter_name) |
| 1962 | { |
| 1963 | prop_getter_name = prop_name; |
| 1964 | } |
| 1965 | if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly)) |
| 1966 | { |
| 1967 | StreamString ss; |
| 1968 | |
| 1969 | ss.Printf("set%c%s:", |
| 1970 | toupper(prop_name[0]), |
| 1971 | &prop_name[1]); |
| 1972 | |
| 1973 | fixed_setter.SetCString(ss.GetData()); |
| 1974 | prop_setter_name = fixed_setter.GetCString(); |
| 1975 | } |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1976 | } |
| 1977 | |
| 1978 | // Clang has a DWARF generation bug where sometimes it |
| Greg Clayton | 4495393 | 2011-10-25 01:25:35 +0000 | [diff] [blame] | 1979 | // represents fields that are references with bad byte size |
| 1980 | // and bit size/offset information such as: |
| 1981 | // |
| 1982 | // DW_AT_byte_size( 0x00 ) |
| 1983 | // DW_AT_bit_size( 0x40 ) |
| 1984 | // DW_AT_bit_offset( 0xffffffffffffffc0 ) |
| 1985 | // |
| 1986 | // So check the bit offset to make sure it is sane, and if |
| 1987 | // the values are not sane, remove them. If we don't do this |
| 1988 | // then we will end up with a crash if we try to use this |
| 1989 | // type in an expression when clang becomes unhappy with its |
| 1990 | // recycled debug info. |
| Sean Callanan | 5a477cf | 2010-10-30 01:56:10 +0000 | [diff] [blame] | 1991 | |
| Greg Clayton | 4495393 | 2011-10-25 01:25:35 +0000 | [diff] [blame] | 1992 | if (bit_offset > 128) |
| 1993 | { |
| 1994 | bit_size = 0; |
| 1995 | bit_offset = 0; |
| 1996 | } |
| 1997 | |
| 1998 | // FIXME: Make Clang ignore Objective-C accessibility for expressions |
| Sean Callanan | 5a477cf | 2010-10-30 01:56:10 +0000 | [diff] [blame] | 1999 | if (class_language == eLanguageTypeObjC || |
| 2000 | class_language == eLanguageTypeObjC_plus_plus) |
| 2001 | accessibility = eAccessNone; |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2002 | |
| 2003 | if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name)) |
| 2004 | { |
| 2005 | // Not all compilers will mark the vtable pointer |
| 2006 | // member as artificial (llvm-gcc). We can't have |
| 2007 | // the virtual members in our classes otherwise it |
| 2008 | // throws off all child offsets since we end up |
| 2009 | // having and extra pointer sized member in our |
| 2010 | // class layouts. |
| 2011 | is_artificial = true; |
| 2012 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2013 | |
| Greg Clayton | 2965971 | 2013-07-12 20:08:35 +0000 | [diff] [blame] | 2014 | // Handle static members |
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 2015 | if (is_external && member_byte_offset == UINT32_MAX) |
| Greg Clayton | 973b6c9 | 2013-04-11 16:57:51 +0000 | [diff] [blame] | 2016 | { |
| 2017 | Type *var_type = ResolveTypeUID(encoding_uid); |
| 2018 | |
| 2019 | if (var_type) |
| 2020 | { |
| Greg Clayton | 2965971 | 2013-07-12 20:08:35 +0000 | [diff] [blame] | 2021 | if (accessibility == eAccessNone) |
| 2022 | accessibility = eAccessPublic; |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 2023 | class_clang_type.AddVariableToRecordType (name, |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2024 | var_type->GetClangLayoutType(), |
| 2025 | accessibility); |
| Greg Clayton | 973b6c9 | 2013-04-11 16:57:51 +0000 | [diff] [blame] | 2026 | } |
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 2027 | break; |
| Greg Clayton | 973b6c9 | 2013-04-11 16:57:51 +0000 | [diff] [blame] | 2028 | } |
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 2029 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2030 | if (is_artificial == false) |
| 2031 | { |
| 2032 | Type *member_type = ResolveTypeUID(encoding_uid); |
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 2033 | |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2034 | clang::FieldDecl *field_decl = NULL; |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 2035 | if (tag == DW_TAG_member) |
| Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 2036 | { |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 2037 | if (member_type) |
| 2038 | { |
| 2039 | if (accessibility == eAccessNone) |
| 2040 | accessibility = default_accessibility; |
| 2041 | member_accessibilities.push_back(accessibility); |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2042 | |
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 2043 | uint64_t field_bit_offset = (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8)); |
| 2044 | if (bit_size > 0) |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2045 | { |
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 2046 | |
| 2047 | BitfieldInfo this_field_info; |
| 2048 | this_field_info.bit_offset = field_bit_offset; |
| 2049 | this_field_info.bit_size = bit_size; |
| 2050 | |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2051 | ///////////////////////////////////////////////////////////// |
| 2052 | // How to locate a field given the DWARF debug information |
| 2053 | // |
| 2054 | // AT_byte_size indicates the size of the word in which the |
| 2055 | // bit offset must be interpreted. |
| 2056 | // |
| 2057 | // AT_data_member_location indicates the byte offset of the |
| 2058 | // word from the base address of the structure. |
| 2059 | // |
| 2060 | // AT_bit_offset indicates how many bits into the word |
| 2061 | // (according to the host endianness) the low-order bit of |
| 2062 | // the field starts. AT_bit_offset can be negative. |
| 2063 | // |
| 2064 | // AT_bit_size indicates the size of the field in bits. |
| 2065 | ///////////////////////////////////////////////////////////// |
| 2066 | |
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 2067 | if (byte_size == 0) |
| 2068 | byte_size = member_type->GetByteSize(); |
| 2069 | |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2070 | if (GetObjectFile()->GetByteOrder() == eByteOrderLittle) |
| 2071 | { |
| 2072 | this_field_info.bit_offset += byte_size * 8; |
| 2073 | this_field_info.bit_offset -= (bit_offset + bit_size); |
| 2074 | } |
| 2075 | else |
| 2076 | { |
| 2077 | this_field_info.bit_offset += bit_offset; |
| 2078 | } |
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 2079 | |
| 2080 | // Update the field bit offset we will report for layout |
| 2081 | field_bit_offset = this_field_info.bit_offset; |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2082 | |
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 2083 | // If the member to be emitted did not start on a character boundary and there is |
| 2084 | // empty space between the last field and this one, then we need to emit an |
| 2085 | // anonymous member filling up the space up to its start. There are three cases |
| 2086 | // here: |
| 2087 | // |
| 2088 | // 1 If the previous member ended on a character boundary, then we can emit an |
| 2089 | // anonymous member starting at the most recent character boundary. |
| 2090 | // |
| 2091 | // 2 If the previous member did not end on a character boundary and the distance |
| 2092 | // from the end of the previous member to the current member is less than a |
| 2093 | // word width, then we can emit an anonymous member starting right after the |
| 2094 | // previous member and right before this member. |
| 2095 | // |
| 2096 | // 3 If the previous member did not end on a character boundary and the distance |
| 2097 | // from the end of the previous member to the current member is greater than |
| 2098 | // or equal a word width, then we act as in Case 1. |
| 2099 | |
| 2100 | const uint64_t character_width = 8; |
| 2101 | const uint64_t word_width = 32; |
| 2102 | |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2103 | // Objective-C has invalid DW_AT_bit_offset values in older versions |
| Bruce Mitchener | aaa0ba3 | 2014-07-08 18:05:41 +0000 | [diff] [blame] | 2104 | // 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] | 2105 | // if we have a new enough clang. |
| 2106 | bool detect_unnamed_bitfields = true; |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2107 | |
| Greg Clayton | 37c36e4 | 2012-11-27 00:59:26 +0000 | [diff] [blame] | 2108 | if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus) |
| 2109 | detect_unnamed_bitfields = dwarf_cu->Supports_unnamed_objc_bitfields (); |
| 2110 | |
| 2111 | if (detect_unnamed_bitfields) |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2112 | { |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2113 | BitfieldInfo anon_field_info; |
| 2114 | |
| 2115 | if ((this_field_info.bit_offset % character_width) != 0) // not char aligned |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2116 | { |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2117 | uint64_t last_field_end = 0; |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2118 | |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2119 | if (last_field_info.IsValid()) |
| 2120 | 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] | 2121 | |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2122 | if (this_field_info.bit_offset != last_field_end) |
| 2123 | { |
| 2124 | if (((last_field_end % character_width) == 0) || // case 1 |
| 2125 | (this_field_info.bit_offset - last_field_end >= word_width)) // case 3 |
| 2126 | { |
| 2127 | anon_field_info.bit_size = this_field_info.bit_offset % character_width; |
| 2128 | anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size; |
| 2129 | } |
| 2130 | else // case 2 |
| 2131 | { |
| 2132 | anon_field_info.bit_size = this_field_info.bit_offset - last_field_end; |
| 2133 | anon_field_info.bit_offset = last_field_end; |
| 2134 | } |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2135 | } |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2136 | } |
| 2137 | |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2138 | if (anon_field_info.IsValid()) |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2139 | { |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 2140 | clang::FieldDecl *unnamed_bitfield_decl = class_clang_type.AddFieldToRecordType (NULL, |
| 2141 | GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width), |
| 2142 | accessibility, |
| 2143 | anon_field_info.bit_size); |
| Zachary Turner | 504f38d | 2015-03-24 16:24:50 +0000 | [diff] [blame] | 2144 | |
| Zachary Turner | a98fac2 | 2015-03-24 18:56:08 +0000 | [diff] [blame] | 2145 | layout_info.field_offsets.insert( |
| Zachary Turner | 504f38d | 2015-03-24 16:24:50 +0000 | [diff] [blame] | 2146 | std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset)); |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2147 | } |
| 2148 | } |
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 2149 | last_field_info = this_field_info; |
| 2150 | } |
| 2151 | else |
| 2152 | { |
| 2153 | last_field_info.Clear(); |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2154 | } |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2155 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2156 | ClangASTType member_clang_type = member_type->GetClangLayoutType(); |
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 2157 | |
| 2158 | { |
| 2159 | // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>). |
| 2160 | // If the current field is at the end of the structure, then there is definitely no room for extra |
| 2161 | // elements and we override the type to array[0]. |
| 2162 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2163 | ClangASTType member_array_element_type; |
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 2164 | uint64_t member_array_size; |
| 2165 | bool member_array_is_incomplete; |
| 2166 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2167 | if (member_clang_type.IsArrayType(&member_array_element_type, |
| 2168 | &member_array_size, |
| 2169 | &member_array_is_incomplete) && |
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 2170 | !member_array_is_incomplete) |
| 2171 | { |
| 2172 | uint64_t parent_byte_size = parent_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, UINT64_MAX); |
| 2173 | |
| 2174 | if (member_byte_offset >= parent_byte_size) |
| 2175 | { |
| 2176 | if (member_array_size != 1) |
| 2177 | { |
| 2178 | 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, |
| 2179 | MakeUserID(die->GetOffset()), |
| 2180 | name, |
| 2181 | encoding_uid, |
| 2182 | MakeUserID(parent_die->GetOffset())); |
| 2183 | } |
| 2184 | |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 2185 | member_clang_type = GetClangASTContext().CreateArrayType(member_array_element_type, 0, false); |
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 2186 | } |
| 2187 | } |
| 2188 | } |
| 2189 | |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 2190 | field_decl = class_clang_type.AddFieldToRecordType (name, |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2191 | member_clang_type, |
| 2192 | accessibility, |
| 2193 | bit_size); |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2194 | |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 2195 | GetClangASTContext().SetMetadataAsUserID (field_decl, MakeUserID(die->GetOffset())); |
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 2196 | |
| Zachary Turner | a98fac2 | 2015-03-24 18:56:08 +0000 | [diff] [blame] | 2197 | layout_info.field_offsets.insert(std::make_pair(field_decl, field_bit_offset)); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2198 | } |
| 2199 | else |
| 2200 | { |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 2201 | if (name) |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2202 | 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] | 2203 | MakeUserID(die->GetOffset()), |
| 2204 | name, |
| 2205 | encoding_uid); |
| 2206 | else |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2207 | 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] | 2208 | MakeUserID(die->GetOffset()), |
| 2209 | encoding_uid); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2210 | } |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2211 | } |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 2212 | |
| Greg Clayton | 3ca8f42 | 2015-07-13 22:08:16 +0000 | [diff] [blame^] | 2213 | if (prop_name != NULL && member_type) |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2214 | { |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 2215 | clang::ObjCIvarDecl *ivar_decl = NULL; |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2216 | |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 2217 | if (field_decl) |
| 2218 | { |
| 2219 | ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl); |
| 2220 | assert (ivar_decl != NULL); |
| 2221 | } |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2222 | |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 2223 | ClangASTMetadata metadata; |
| 2224 | metadata.SetUserID (MakeUserID(die->GetOffset())); |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2225 | delayed_properties.push_back(DelayedAddObjCClassProperty(class_clang_type, |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2226 | prop_name, |
| 2227 | member_type->GetClangLayoutType(), |
| 2228 | ivar_decl, |
| 2229 | prop_setter_name, |
| 2230 | prop_getter_name, |
| 2231 | prop_attributes, |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 2232 | &metadata)); |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2233 | |
| Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 2234 | if (ivar_decl) |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 2235 | GetClangASTContext().SetMetadataAsUserID (ivar_decl, MakeUserID(die->GetOffset())); |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2236 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2237 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2238 | } |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2239 | ++member_idx; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2240 | } |
| 2241 | break; |
| 2242 | |
| 2243 | case DW_TAG_subprogram: |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2244 | // Let the type parsing code handle this one for us. |
| 2245 | member_function_dies.Append (die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2246 | break; |
| 2247 | |
| 2248 | case DW_TAG_inheritance: |
| 2249 | { |
| 2250 | is_a_class = true; |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 2251 | if (default_accessibility == eAccessNone) |
| 2252 | default_accessibility = eAccessPrivate; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2253 | // TODO: implement DW_TAG_inheritance type parsing |
| 2254 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 2255 | const size_t num_attributes = die->GetAttributes (this, |
| 2256 | dwarf_cu, |
| 2257 | fixed_form_sizes, |
| 2258 | attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2259 | if (num_attributes > 0) |
| 2260 | { |
| 2261 | Declaration decl; |
| 2262 | DWARFExpression location; |
| 2263 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 2264 | AccessType accessibility = default_accessibility; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2265 | bool is_virtual = false; |
| 2266 | bool is_base_of_class = true; |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2267 | off_t member_byte_offset = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2268 | uint32_t i; |
| 2269 | for (i=0; i<num_attributes; ++i) |
| 2270 | { |
| 2271 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 2272 | DWARFFormValue form_value; |
| 2273 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 2274 | { |
| 2275 | switch (attr) |
| 2276 | { |
| 2277 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 2278 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 2279 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 2280 | case DW_AT_type: encoding_uid = form_value.Reference(); break; |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2281 | case DW_AT_data_member_location: |
| 2282 | if (form_value.BlockData()) |
| 2283 | { |
| 2284 | Value initialValue(0); |
| 2285 | Value memberOffset(0); |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 2286 | const DWARFDataExtractor& debug_info_data = get_debug_info_data(); |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2287 | uint32_t block_length = form_value.Unsigned(); |
| 2288 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 2289 | if (DWARFExpression::Evaluate (NULL, |
| 2290 | NULL, |
| 2291 | NULL, |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2292 | NULL, |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 2293 | module, |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2294 | debug_info_data, |
| 2295 | block_offset, |
| 2296 | block_length, |
| 2297 | eRegisterKindDWARF, |
| 2298 | &initialValue, |
| 2299 | memberOffset, |
| 2300 | NULL)) |
| 2301 | { |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2302 | member_byte_offset = memberOffset.ResolveValue(NULL).UInt(); |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2303 | } |
| 2304 | } |
| Ashok Thirumurthi | a4658a5 | 2013-07-30 14:58:39 +0000 | [diff] [blame] | 2305 | else |
| 2306 | { |
| 2307 | // With DWARF 3 and later, if the value is an integer constant, |
| 2308 | // this form value is the offset in bytes from the beginning |
| 2309 | // of the containing entity. |
| 2310 | member_byte_offset = form_value.Unsigned(); |
| 2311 | } |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2312 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2313 | |
| 2314 | case DW_AT_accessibility: |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 2315 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2316 | break; |
| 2317 | |
| Ashok Thirumurthi | a4658a5 | 2013-07-30 14:58:39 +0000 | [diff] [blame] | 2318 | case DW_AT_virtuality: |
| 2319 | is_virtual = form_value.Boolean(); |
| 2320 | break; |
| 2321 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2322 | case DW_AT_sibling: |
| 2323 | break; |
| Ashok Thirumurthi | a4658a5 | 2013-07-30 14:58:39 +0000 | [diff] [blame] | 2324 | |
| 2325 | default: |
| 2326 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2327 | } |
| 2328 | } |
| 2329 | } |
| 2330 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 2331 | Type *base_class_type = ResolveTypeUID(encoding_uid); |
| Greg Clayton | 898c1b2 | 2015-05-15 22:31:18 +0000 | [diff] [blame] | 2332 | if (base_class_type == NULL) |
| 2333 | { |
| Bruce Mitchener | 58ef391 | 2015-06-18 05:27:05 +0000 | [diff] [blame] | 2334 | GetObjectFile()->GetModule()->ReportError("0x%8.8x: DW_TAG_inheritance failed to resolve the base class at 0x%8.8" PRIx64 " from enclosing type 0x%8.8x. \nPlease file a bug and attach the file at the start of this error message", |
| Greg Clayton | 898c1b2 | 2015-05-15 22:31:18 +0000 | [diff] [blame] | 2335 | die->GetOffset(), |
| 2336 | encoding_uid, |
| 2337 | parent_die->GetOffset()); |
| 2338 | break; |
| 2339 | } |
| 2340 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2341 | ClangASTType base_class_clang_type = base_class_type->GetClangFullType(); |
| Greg Clayton | f4ecaa5 | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 2342 | assert (base_class_clang_type); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2343 | if (class_language == eLanguageTypeObjC) |
| 2344 | { |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 2345 | class_clang_type.SetObjCSuperClass(base_class_clang_type); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2346 | } |
| 2347 | else |
| 2348 | { |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 2349 | base_classes.push_back (base_class_clang_type.CreateBaseClassSpecifier (accessibility, |
| 2350 | is_virtual, |
| 2351 | is_base_of_class)); |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2352 | |
| 2353 | if (is_virtual) |
| 2354 | { |
| Greg Clayton | 52694e3 | 2013-09-16 21:57:07 +0000 | [diff] [blame] | 2355 | // Do not specify any offset for virtual inheritance. The DWARF produced by clang doesn't |
| 2356 | // give us a constant offset, but gives us a DWARF expressions that requires an actual object |
| 2357 | // in memory. the DW_AT_data_member_location for a virtual base class looks like: |
| 2358 | // DW_AT_data_member_location( DW_OP_dup, DW_OP_deref, DW_OP_constu(0x00000018), DW_OP_minus, DW_OP_deref, DW_OP_plus ) |
| 2359 | // Given this, there is really no valid response we can give to clang for virtual base |
| 2360 | // class offsets, and this should eventually be removed from LayoutRecordType() in the external |
| 2361 | // AST source in clang. |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2362 | } |
| 2363 | else |
| 2364 | { |
| Zachary Turner | a98fac2 | 2015-03-24 18:56:08 +0000 | [diff] [blame] | 2365 | layout_info.base_offsets.insert( |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 2366 | std::make_pair(base_class_clang_type.GetAsCXXRecordDecl(), |
| Zachary Turner | 504f38d | 2015-03-24 16:24:50 +0000 | [diff] [blame] | 2367 | clang::CharUnits::fromQuantity(member_byte_offset))); |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2368 | } |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2369 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2370 | } |
| 2371 | } |
| 2372 | break; |
| 2373 | |
| 2374 | default: |
| 2375 | break; |
| 2376 | } |
| 2377 | } |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2378 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2379 | return count; |
| 2380 | } |
| 2381 | |
| 2382 | |
| 2383 | clang::DeclContext* |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 2384 | SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2385 | { |
| 2386 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2387 | if (debug_info && UserIDMatches(type_uid)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2388 | { |
| 2389 | DWARFCompileUnitSP cu_sp; |
| 2390 | const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp); |
| 2391 | if (die) |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 2392 | return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL); |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 2393 | } |
| 2394 | return NULL; |
| 2395 | } |
| 2396 | |
| 2397 | clang::DeclContext* |
| 2398 | SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid) |
| 2399 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2400 | if (UserIDMatches(type_uid)) |
| 2401 | return GetClangDeclContextForDIEOffset (sc, type_uid); |
| 2402 | return NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2403 | } |
| 2404 | |
| 2405 | Type* |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2406 | SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2407 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2408 | if (UserIDMatches(type_uid)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2409 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2410 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2411 | if (debug_info) |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2412 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2413 | DWARFCompileUnitSP cu_sp; |
| 2414 | const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp); |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2415 | const bool assert_not_being_parsed = true; |
| 2416 | return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2417 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2418 | } |
| 2419 | return NULL; |
| 2420 | } |
| 2421 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2422 | Type* |
| 2423 | SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed) |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2424 | { |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2425 | if (die != NULL) |
| 2426 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2427 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2428 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2429 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2430 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'", |
| 2431 | die->GetOffset(), |
| 2432 | DW_TAG_value_to_name(die->Tag()), |
| 2433 | die->GetName(this, cu)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2434 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2435 | // We might be coming in in the middle of a type tree (a class |
| 2436 | // withing a class, an enum within a class), so parse any needed |
| 2437 | // parent DIEs before we get to this one... |
| 2438 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); |
| 2439 | switch (decl_ctx_die->Tag()) |
| 2440 | { |
| 2441 | case DW_TAG_structure_type: |
| 2442 | case DW_TAG_union_type: |
| 2443 | case DW_TAG_class_type: |
| 2444 | { |
| 2445 | // Get the type, which could be a forward declaration |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2446 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2447 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2448 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x", |
| 2449 | die->GetOffset(), |
| 2450 | DW_TAG_value_to_name(die->Tag()), |
| 2451 | die->GetName(this, cu), |
| 2452 | decl_ctx_die->GetOffset()); |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2453 | // |
| 2454 | // Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed); |
| 2455 | // if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag())) |
| 2456 | // { |
| 2457 | // if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2458 | // GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2459 | // "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function", |
| 2460 | // die->GetOffset(), |
| 2461 | // DW_TAG_value_to_name(die->Tag()), |
| 2462 | // die->GetName(this, cu), |
| 2463 | // decl_ctx_die->GetOffset()); |
| 2464 | // // Ask the type to complete itself if it already hasn't since if we |
| 2465 | // // want a function (method or static) from a class, the class must |
| 2466 | // // create itself and add it's own methods and class functions. |
| 2467 | // if (parent_type) |
| 2468 | // parent_type->GetClangFullType(); |
| 2469 | // } |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2470 | } |
| 2471 | break; |
| 2472 | |
| 2473 | default: |
| 2474 | break; |
| 2475 | } |
| 2476 | return ResolveType (cu, die); |
| 2477 | } |
| 2478 | return NULL; |
| 2479 | } |
| 2480 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2481 | // This function is used when SymbolFileDWARFDebugMap owns a bunch of |
| 2482 | // SymbolFileDWARF objects to detect if this DWARF file is the one that |
| 2483 | // can resolve a clang_type. |
| 2484 | bool |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2485 | SymbolFileDWARF::HasForwardDeclForClangType (const ClangASTType &clang_type) |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2486 | { |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 2487 | ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers(); |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2488 | 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] | 2489 | return die != NULL; |
| 2490 | } |
| 2491 | |
| 2492 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2493 | bool |
| 2494 | SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (ClangASTType &clang_type) |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2495 | { |
| 2496 | // We have a struct/union/class/enum that needs to be fully resolved. |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 2497 | ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers(); |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2498 | 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] | 2499 | if (die == NULL) |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2500 | { |
| 2501 | // We have already resolved this type... |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2502 | return true; |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2503 | } |
| 2504 | // Once we start resolving this type, remove it from the forward declaration |
| 2505 | // map in case anyone child members or other types require this type to get resolved. |
| 2506 | // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition |
| 2507 | // are done. |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2508 | 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] | 2509 | |
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 2510 | // Disable external storage for this type so we don't get anymore |
| 2511 | // clang::ExternalASTSource queries for this type. |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 2512 | clang_type.SetHasExternalStorage (false); |
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 2513 | |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2514 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2515 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2516 | DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get(); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2517 | Type *type = m_die_to_type.lookup (die); |
| 2518 | |
| 2519 | const dw_tag_t tag = die->Tag(); |
| 2520 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2521 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2522 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2523 | GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2524 | "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...", |
| Greg Clayton | d61c0fc | 2012-04-23 22:55:20 +0000 | [diff] [blame] | 2525 | MakeUserID(die->GetOffset()), |
| 2526 | DW_TAG_value_to_name(tag), |
| 2527 | type->GetName().AsCString()); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2528 | assert (clang_type); |
| 2529 | DWARFDebugInfoEntry::Attributes attributes; |
| 2530 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2531 | switch (tag) |
| 2532 | { |
| 2533 | case DW_TAG_structure_type: |
| 2534 | case DW_TAG_union_type: |
| 2535 | case DW_TAG_class_type: |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2536 | { |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2537 | LayoutInfo layout_info; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2538 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2539 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2540 | if (die->HasChildren()) |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2541 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2542 | LanguageType class_language = eLanguageTypeUnknown; |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 2543 | if (clang_type.IsObjCObjectOrInterfaceType()) |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2544 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2545 | class_language = eLanguageTypeObjC; |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2546 | // For objective C we don't start the definition when |
| 2547 | // the class is created. |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 2548 | clang_type.StartTagDeclarationDefinition (); |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2549 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2550 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2551 | int tag_decl_kind = -1; |
| 2552 | AccessType default_accessibility = eAccessNone; |
| 2553 | if (tag == DW_TAG_structure_type) |
| 2554 | { |
| 2555 | tag_decl_kind = clang::TTK_Struct; |
| 2556 | default_accessibility = eAccessPublic; |
| 2557 | } |
| 2558 | else if (tag == DW_TAG_union_type) |
| 2559 | { |
| 2560 | tag_decl_kind = clang::TTK_Union; |
| 2561 | default_accessibility = eAccessPublic; |
| 2562 | } |
| 2563 | else if (tag == DW_TAG_class_type) |
| 2564 | { |
| 2565 | tag_decl_kind = clang::TTK_Class; |
| 2566 | default_accessibility = eAccessPrivate; |
| 2567 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2568 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2569 | SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2570 | std::vector<clang::CXXBaseSpecifier *> base_classes; |
| 2571 | std::vector<int> member_accessibilities; |
| 2572 | bool is_a_class = false; |
| 2573 | // Parse members and base classes first |
| 2574 | DWARFDIECollection member_function_dies; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2575 | |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2576 | DelayedPropertyList delayed_properties; |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2577 | ParseChildMembers (sc, |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2578 | dwarf_cu, |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2579 | die, |
| 2580 | clang_type, |
| 2581 | class_language, |
| 2582 | base_classes, |
| 2583 | member_accessibilities, |
| 2584 | member_function_dies, |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2585 | delayed_properties, |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2586 | default_accessibility, |
| 2587 | is_a_class, |
| 2588 | layout_info); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2589 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2590 | // Now parse any methods if there were any... |
| 2591 | size_t num_functions = member_function_dies.Size(); |
| 2592 | if (num_functions > 0) |
| 2593 | { |
| 2594 | for (size_t i=0; i<num_functions; ++i) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2595 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2596 | ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i)); |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2597 | } |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2598 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2599 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2600 | if (class_language == eLanguageTypeObjC) |
| 2601 | { |
| Jim Ingham | fb6fc0d | 2013-09-27 20:59:37 +0000 | [diff] [blame] | 2602 | ConstString class_name (clang_type.GetTypeName()); |
| 2603 | if (class_name) |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2604 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2605 | DIEArray method_die_offsets; |
| 2606 | if (m_using_apple_tables) |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2607 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2608 | if (m_apple_objc_ap.get()) |
| Jim Ingham | fb6fc0d | 2013-09-27 20:59:37 +0000 | [diff] [blame] | 2609 | m_apple_objc_ap->FindByName(class_name.GetCString(), method_die_offsets); |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2610 | } |
| 2611 | else |
| 2612 | { |
| 2613 | if (!m_indexed) |
| 2614 | Index (); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2615 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2616 | m_objc_class_selectors_index.Find (class_name, method_die_offsets); |
| 2617 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2618 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2619 | if (!method_die_offsets.empty()) |
| 2620 | { |
| 2621 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2622 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2623 | DWARFCompileUnit* method_cu = NULL; |
| 2624 | const size_t num_matches = method_die_offsets.size(); |
| 2625 | for (size_t i=0; i<num_matches; ++i) |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2626 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2627 | const dw_offset_t die_offset = method_die_offsets[i]; |
| 2628 | DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2629 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2630 | if (method_die) |
| 2631 | ResolveType (method_cu, method_die); |
| 2632 | else |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2633 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2634 | if (m_using_apple_tables) |
| 2635 | { |
| 2636 | 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] | 2637 | die_offset, class_name.GetCString()); |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2638 | } |
| 2639 | } |
| 2640 | } |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2641 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2642 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2643 | for (DelayedPropertyList::iterator pi = delayed_properties.begin(), pe = delayed_properties.end(); |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2644 | pi != pe; |
| 2645 | ++pi) |
| 2646 | pi->Finalize(); |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2647 | } |
| 2648 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2649 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2650 | // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we |
| 2651 | // need to tell the clang type it is actually a class. |
| 2652 | if (class_language != eLanguageTypeObjC) |
| 2653 | { |
| 2654 | if (is_a_class && tag_decl_kind != clang::TTK_Class) |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 2655 | clang_type.SetTagTypeKind (clang::TTK_Class); |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2656 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2657 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2658 | // Since DW_TAG_structure_type gets used for both classes |
| 2659 | // and structures, we may need to set any DW_TAG_member |
| 2660 | // fields to have a "private" access if none was specified. |
| 2661 | // When we parsed the child members we tracked that actual |
| 2662 | // accessibility value for each DW_TAG_member in the |
| 2663 | // "member_accessibilities" array. If the value for the |
| 2664 | // member is zero, then it was set to the "default_accessibility" |
| 2665 | // which for structs was "public". Below we correct this |
| 2666 | // by setting any fields to "private" that weren't correctly |
| 2667 | // set. |
| 2668 | if (is_a_class && !member_accessibilities.empty()) |
| 2669 | { |
| 2670 | // This is a class and all members that didn't have |
| 2671 | // their access specified are private. |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 2672 | clang_type.SetDefaultAccessForRecordFields (eAccessPrivate, |
| 2673 | &member_accessibilities.front(), |
| 2674 | member_accessibilities.size()); |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2675 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2676 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2677 | if (!base_classes.empty()) |
| 2678 | { |
| Greg Clayton | 4705f8d | 2013-12-12 01:54:04 +0000 | [diff] [blame] | 2679 | // Make sure all base classes refer to complete types and not |
| 2680 | // forward declarations. If we don't do this, clang will crash |
| 2681 | // with an assertion in the call to clang_type.SetBaseClassesForClassType() |
| 2682 | bool base_class_error = false; |
| 2683 | for (auto &base_class : base_classes) |
| 2684 | { |
| 2685 | clang::TypeSourceInfo *type_source_info = base_class->getTypeSourceInfo(); |
| 2686 | if (type_source_info) |
| 2687 | { |
| 2688 | ClangASTType base_class_type (GetClangASTContext().getASTContext(), type_source_info->getType()); |
| 2689 | if (base_class_type.GetCompleteType() == false) |
| 2690 | { |
| 2691 | if (!base_class_error) |
| 2692 | { |
| 2693 | 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", |
| 2694 | die->GetOffset(), |
| 2695 | die->GetName(this, dwarf_cu), |
| 2696 | base_class_type.GetTypeName().GetCString(), |
| 2697 | sc.comp_unit ? sc.comp_unit->GetPath().c_str() : "the source file"); |
| 2698 | } |
| 2699 | // We have no choice other than to pretend that the base class |
| 2700 | // is complete. If we don't do this, clang will crash when we |
| 2701 | // call setBases() inside of "clang_type.SetBaseClassesForClassType()" |
| 2702 | // below. Since we provide layout assistance, all ivars in this |
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 2703 | // 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] | 2704 | // short of crashing. |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 2705 | base_class_type.StartTagDeclarationDefinition (); |
| 2706 | base_class_type.CompleteTagDeclarationDefinition (); |
| Greg Clayton | 4705f8d | 2013-12-12 01:54:04 +0000 | [diff] [blame] | 2707 | } |
| 2708 | } |
| 2709 | } |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 2710 | clang_type.SetBaseClassesForClassType (&base_classes.front(), |
| 2711 | base_classes.size()); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2712 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2713 | // Clang will copy each CXXBaseSpecifier in "base_classes" |
| 2714 | // so we have to free them all. |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 2715 | ClangASTType::DeleteBaseClassSpecifiers (&base_classes.front(), |
| 2716 | base_classes.size()); |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2717 | } |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2718 | } |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2719 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2720 | |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 2721 | clang_type.BuildIndirectFields (); |
| 2722 | clang_type.CompleteTagDeclarationDefinition (); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2723 | |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2724 | if (!layout_info.field_offsets.empty() || |
| 2725 | !layout_info.base_offsets.empty() || |
| 2726 | !layout_info.vbase_offsets.empty() ) |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2727 | { |
| 2728 | if (type) |
| 2729 | layout_info.bit_size = type->GetByteSize() * 8; |
| 2730 | if (layout_info.bit_size == 0) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2731 | 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] | 2732 | |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 2733 | clang::CXXRecordDecl *record_decl = clang_type.GetAsCXXRecordDecl(); |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2734 | if (record_decl) |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2735 | { |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2736 | if (log) |
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2737 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2738 | GetObjectFile()->GetModule()->LogMessage (log, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2739 | "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] | 2740 | static_cast<void*>(clang_type.GetOpaqueQualType()), |
| 2741 | static_cast<void*>(record_decl), |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2742 | layout_info.bit_size, |
| 2743 | layout_info.alignment, |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2744 | static_cast<uint32_t>(layout_info.field_offsets.size()), |
| 2745 | static_cast<uint32_t>(layout_info.base_offsets.size()), |
| 2746 | static_cast<uint32_t>(layout_info.vbase_offsets.size())); |
| 2747 | |
| Zachary Turner | a98fac2 | 2015-03-24 18:56:08 +0000 | [diff] [blame] | 2748 | uint32_t idx; |
| 2749 | { |
| 2750 | llvm::DenseMap<const clang::FieldDecl *, uint64_t>::const_iterator pos, |
| 2751 | end = layout_info.field_offsets.end(); |
| 2752 | for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx) |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2753 | { |
| Zachary Turner | 504f38d | 2015-03-24 16:24:50 +0000 | [diff] [blame] | 2754 | GetObjectFile()->GetModule()->LogMessage( |
| 2755 | log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = " |
| 2756 | "{ bit_offset=%u, name='%s' }", |
| Zachary Turner | 504f38d | 2015-03-24 16:24:50 +0000 | [diff] [blame] | 2757 | static_cast<void *>(clang_type.GetOpaqueQualType()), idx, |
| Zachary Turner | a98fac2 | 2015-03-24 18:56:08 +0000 | [diff] [blame] | 2758 | static_cast<uint32_t>(pos->second), pos->first->getNameAsString().c_str()); |
| 2759 | } |
| 2760 | } |
| 2761 | |
| 2762 | { |
| 2763 | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos, |
| 2764 | base_end = layout_info.base_offsets.end(); |
| 2765 | for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end; |
| 2766 | ++base_pos, ++idx) |
| 2767 | { |
| 2768 | GetObjectFile()->GetModule()->LogMessage( |
| 2769 | log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] " |
| 2770 | "= { byte_offset=%u, name='%s' }", |
| 2771 | clang_type.GetOpaqueQualType(), idx, (uint32_t)base_pos->second.getQuantity(), |
| 2772 | base_pos->first->getNameAsString().c_str()); |
| 2773 | } |
| 2774 | } |
| 2775 | { |
| 2776 | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos, |
| 2777 | vbase_end = layout_info.vbase_offsets.end(); |
| 2778 | for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end; |
| 2779 | ++vbase_pos, ++idx) |
| 2780 | { |
| 2781 | GetObjectFile()->GetModule()->LogMessage( |
| 2782 | log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) " |
| 2783 | "vbase[%u] = { byte_offset=%u, name='%s' }", |
| 2784 | static_cast<void *>(clang_type.GetOpaqueQualType()), idx, |
| 2785 | static_cast<uint32_t>(vbase_pos->second.getQuantity()), |
| 2786 | vbase_pos->first->getNameAsString().c_str()); |
| 2787 | } |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2788 | } |
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2789 | } |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2790 | m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info)); |
| 2791 | } |
| 2792 | } |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2793 | } |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2794 | |
| Sean Callanan | 9076c0f | 2013-10-04 21:35:29 +0000 | [diff] [blame] | 2795 | return (bool)clang_type; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2796 | |
| 2797 | case DW_TAG_enumeration_type: |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 2798 | clang_type.StartTagDeclarationDefinition (); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2799 | if (die->HasChildren()) |
| 2800 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2801 | SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); |
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 2802 | bool is_signed = false; |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2803 | clang_type.IsIntegerType(is_signed); |
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 2804 | ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), dwarf_cu, die); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2805 | } |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 2806 | clang_type.CompleteTagDeclarationDefinition (); |
| Sean Callanan | 9076c0f | 2013-10-04 21:35:29 +0000 | [diff] [blame] | 2807 | return (bool)clang_type; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2808 | |
| 2809 | default: |
| 2810 | assert(false && "not a forward clang type decl!"); |
| 2811 | break; |
| 2812 | } |
| Ashok Thirumurthi | a4658a5 | 2013-07-30 14:58:39 +0000 | [diff] [blame] | 2813 | return false; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2814 | } |
| 2815 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2816 | Type* |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2817 | 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] | 2818 | { |
| 2819 | if (type_die != NULL) |
| 2820 | { |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 2821 | Type *type = m_die_to_type.lookup (type_die); |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2822 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2823 | if (type == NULL) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2824 | type = GetTypeForDIE (dwarf_cu, type_die).get(); |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2825 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2826 | if (assert_not_being_parsed) |
| Jim Ingham | c354928 | 2012-01-11 02:21:12 +0000 | [diff] [blame] | 2827 | { |
| 2828 | if (type != DIE_IS_BEING_PARSED) |
| 2829 | return type; |
| 2830 | |
| 2831 | 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] | 2832 | type_die->GetOffset(), |
| 2833 | DW_TAG_value_to_name(type_die->Tag()), |
| 2834 | type_die->GetName(this, dwarf_cu)); |
| Jim Ingham | c354928 | 2012-01-11 02:21:12 +0000 | [diff] [blame] | 2835 | |
| 2836 | } |
| 2837 | else |
| 2838 | return type; |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2839 | } |
| 2840 | return NULL; |
| 2841 | } |
| 2842 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2843 | CompileUnit* |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2844 | SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2845 | { |
| 2846 | // Check if the symbol vendor already knows about this compile unit? |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2847 | if (dwarf_cu->GetUserData() == NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2848 | { |
| 2849 | // The symbol vendor doesn't know about this compile unit, we |
| 2850 | // need to parse and add it to the symbol vendor object. |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2851 | return ParseCompileUnit(dwarf_cu, cu_idx).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2852 | } |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2853 | return (CompileUnit*)dwarf_cu->GetUserData(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2854 | } |
| 2855 | |
| 2856 | bool |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2857 | SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2858 | { |
| Greg Clayton | 7231035 | 2013-02-23 04:12:47 +0000 | [diff] [blame] | 2859 | sc.Clear(false); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2860 | // Check if the symbol vendor already knows about this compile unit? |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2861 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2862 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2863 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2864 | if (sc.function == NULL) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2865 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2866 | |
| 2867 | if (sc.function) |
| 2868 | { |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 2869 | sc.module_sp = sc.function->CalculateSymbolContextModule(); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2870 | return true; |
| 2871 | } |
| 2872 | |
| 2873 | return false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2874 | } |
| 2875 | |
| Sean Callanan | f0c5aeb | 2015-04-20 16:31:29 +0000 | [diff] [blame] | 2876 | void |
| 2877 | SymbolFileDWARF::UpdateExternalModuleListIfNeeded() |
| 2878 | { |
| 2879 | if (m_fetched_external_modules) |
| 2880 | return; |
| 2881 | m_fetched_external_modules = true; |
| 2882 | |
| 2883 | DWARFDebugInfo * debug_info = DebugInfo(); |
| 2884 | debug_info->GetNumCompileUnits(); |
| 2885 | |
| 2886 | const uint32_t num_compile_units = GetNumCompileUnits(); |
| 2887 | for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) |
| 2888 | { |
| 2889 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); |
| 2890 | |
| 2891 | const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly(); |
| 2892 | if (die && die->HasChildren() == false) |
| 2893 | { |
| 2894 | const uint64_t name_strp = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_name, UINT64_MAX); |
| 2895 | const uint64_t dwo_path_strp = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_GNU_dwo_name, UINT64_MAX); |
| 2896 | |
| 2897 | if (name_strp != UINT64_MAX) |
| 2898 | { |
| 2899 | if (m_external_type_modules.find(dwo_path_strp) == m_external_type_modules.end()) |
| 2900 | { |
| 2901 | const char *name = get_debug_str_data().PeekCStr(name_strp); |
| 2902 | const char *dwo_path = get_debug_str_data().PeekCStr(dwo_path_strp); |
| 2903 | if (name || dwo_path) |
| 2904 | { |
| 2905 | ModuleSP module_sp; |
| 2906 | if (dwo_path) |
| 2907 | { |
| 2908 | ModuleSpec dwo_module_spec; |
| 2909 | dwo_module_spec.GetFileSpec().SetFile(dwo_path, false); |
| 2910 | dwo_module_spec.GetArchitecture() = m_obj_file->GetModule()->GetArchitecture(); |
| 2911 | //printf ("Loading dwo = '%s'\n", dwo_path); |
| 2912 | Error error = ModuleList::GetSharedModule (dwo_module_spec, module_sp, NULL, NULL, NULL); |
| 2913 | } |
| 2914 | |
| 2915 | if (dwo_path_strp != LLDB_INVALID_UID) |
| 2916 | { |
| 2917 | m_external_type_modules[dwo_path_strp] = ClangModuleInfo { ConstString(name), module_sp }; |
| 2918 | } |
| 2919 | else |
| 2920 | { |
| 2921 | // This hack should be removed promptly once clang emits both. |
| 2922 | m_external_type_modules[name_strp] = ClangModuleInfo { ConstString(name), module_sp }; |
| 2923 | } |
| 2924 | } |
| 2925 | } |
| 2926 | } |
| 2927 | } |
| 2928 | } |
| 2929 | } |
| Greg Clayton | 2501e5e | 2015-01-15 02:59:20 +0000 | [diff] [blame] | 2930 | |
| 2931 | SymbolFileDWARF::GlobalVariableMap & |
| 2932 | SymbolFileDWARF::GetGlobalAranges() |
| 2933 | { |
| 2934 | if (!m_global_aranges_ap) |
| 2935 | { |
| 2936 | m_global_aranges_ap.reset (new GlobalVariableMap()); |
| 2937 | |
| 2938 | ModuleSP module_sp = GetObjectFile()->GetModule(); |
| 2939 | if (module_sp) |
| 2940 | { |
| 2941 | const size_t num_cus = module_sp->GetNumCompileUnits(); |
| 2942 | for (size_t i = 0; i < num_cus; ++i) |
| 2943 | { |
| 2944 | CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(i); |
| 2945 | if (cu_sp) |
| 2946 | { |
| 2947 | VariableListSP globals_sp = cu_sp->GetVariableList(true); |
| 2948 | if (globals_sp) |
| 2949 | { |
| 2950 | const size_t num_globals = globals_sp->GetSize(); |
| 2951 | for (size_t g = 0; g < num_globals; ++g) |
| 2952 | { |
| 2953 | VariableSP var_sp = globals_sp->GetVariableAtIndex(g); |
| 2954 | if (var_sp && !var_sp->GetLocationIsConstantValueData()) |
| 2955 | { |
| 2956 | const DWARFExpression &location = var_sp->LocationExpression(); |
| 2957 | Value location_result; |
| 2958 | Error error; |
| 2959 | if (location.Evaluate(NULL, NULL, NULL, LLDB_INVALID_ADDRESS, NULL, location_result, &error)) |
| 2960 | { |
| 2961 | if (location_result.GetValueType() == Value::eValueTypeFileAddress) |
| 2962 | { |
| 2963 | lldb::addr_t file_addr = location_result.GetScalar().ULongLong(); |
| 2964 | lldb::addr_t byte_size = 1; |
| 2965 | if (var_sp->GetType()) |
| 2966 | byte_size = var_sp->GetType()->GetByteSize(); |
| 2967 | m_global_aranges_ap->Append(GlobalVariableMap::Entry(file_addr, byte_size, var_sp.get())); |
| 2968 | } |
| 2969 | } |
| 2970 | } |
| 2971 | } |
| 2972 | } |
| 2973 | } |
| 2974 | } |
| 2975 | } |
| 2976 | m_global_aranges_ap->Sort(); |
| 2977 | } |
| 2978 | return *m_global_aranges_ap; |
| 2979 | } |
| 2980 | |
| 2981 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2982 | uint32_t |
| 2983 | SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) |
| 2984 | { |
| 2985 | Timer scoped_timer(__PRETTY_FUNCTION__, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2986 | "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] | 2987 | static_cast<void*>(so_addr.GetSection().get()), |
| 2988 | so_addr.GetOffset(), resolve_scope); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2989 | uint32_t resolved = 0; |
| Greg Clayton | 2501e5e | 2015-01-15 02:59:20 +0000 | [diff] [blame] | 2990 | if (resolve_scope & ( eSymbolContextCompUnit | |
| 2991 | eSymbolContextFunction | |
| 2992 | eSymbolContextBlock | |
| 2993 | eSymbolContextLineEntry | |
| 2994 | eSymbolContextVariable )) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2995 | { |
| 2996 | lldb::addr_t file_vm_addr = so_addr.GetFileAddress(); |
| 2997 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2998 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2999 | if (debug_info) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3000 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3001 | 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] | 3002 | if (cu_offset == DW_INVALID_OFFSET) |
| 3003 | { |
| 3004 | // Global variables are not in the compile unit address ranges. The only way to |
| 3005 | // currently find global variables is to iterate over the .debug_pubnames or the |
| 3006 | // __apple_names table and find all items in there that point to DW_TAG_variable |
| 3007 | // DIEs and then find the address that matches. |
| 3008 | if (resolve_scope & eSymbolContextVariable) |
| 3009 | { |
| 3010 | GlobalVariableMap &map = GetGlobalAranges(); |
| 3011 | const GlobalVariableMap::Entry *entry = map.FindEntryThatContains(file_vm_addr); |
| 3012 | if (entry && entry->data) |
| 3013 | { |
| 3014 | Variable *variable = entry->data; |
| 3015 | SymbolContextScope *scc = variable->GetSymbolContextScope(); |
| 3016 | if (scc) |
| 3017 | { |
| 3018 | scc->CalculateSymbolContext(&sc); |
| 3019 | sc.variable = variable; |
| 3020 | } |
| 3021 | return sc.GetResolvedMask(); |
| 3022 | } |
| 3023 | } |
| 3024 | } |
| 3025 | else |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3026 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3027 | uint32_t cu_idx = DW_INVALID_INDEX; |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3028 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get(); |
| 3029 | if (dwarf_cu) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3030 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3031 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3032 | if (sc.comp_unit) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3033 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3034 | resolved |= eSymbolContextCompUnit; |
| 3035 | |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 3036 | bool force_check_line_table = false; |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3037 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) |
| 3038 | { |
| 3039 | DWARFDebugInfoEntry *function_die = NULL; |
| 3040 | DWARFDebugInfoEntry *block_die = NULL; |
| 3041 | if (resolve_scope & eSymbolContextBlock) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3042 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3043 | dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die); |
| 3044 | } |
| 3045 | else |
| 3046 | { |
| 3047 | dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL); |
| 3048 | } |
| 3049 | |
| 3050 | if (function_die != NULL) |
| 3051 | { |
| 3052 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); |
| 3053 | if (sc.function == NULL) |
| 3054 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die); |
| 3055 | } |
| 3056 | else |
| 3057 | { |
| 3058 | // We might have had a compile unit that had discontiguous |
| 3059 | // address ranges where the gaps are symbols that don't have |
| 3060 | // any debug info. Discontiguous compile unit address ranges |
| 3061 | // should only happen when there aren't other functions from |
| 3062 | // other compile units in these gaps. This helps keep the size |
| 3063 | // of the aranges down. |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 3064 | force_check_line_table = true; |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3065 | } |
| 3066 | |
| 3067 | if (sc.function != NULL) |
| 3068 | { |
| 3069 | resolved |= eSymbolContextFunction; |
| 3070 | |
| 3071 | if (resolve_scope & eSymbolContextBlock) |
| 3072 | { |
| 3073 | Block& block = sc.function->GetBlock (true); |
| 3074 | |
| 3075 | if (block_die != NULL) |
| 3076 | sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); |
| 3077 | else |
| 3078 | sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); |
| 3079 | if (sc.block) |
| 3080 | resolved |= eSymbolContextBlock; |
| 3081 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3082 | } |
| 3083 | } |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 3084 | |
| 3085 | if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table) |
| 3086 | { |
| 3087 | LineTable *line_table = sc.comp_unit->GetLineTable(); |
| 3088 | if (line_table != NULL) |
| 3089 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 3090 | // And address that makes it into this function should be in terms |
| 3091 | // of this debug file if there is no debug map, or it will be an |
| 3092 | // address in the .o file which needs to be fixed up to be in terms |
| 3093 | // of the debug map executable. Either way, calling FixupAddress() |
| 3094 | // will work for us. |
| 3095 | Address exe_so_addr (so_addr); |
| 3096 | if (FixupAddress(exe_so_addr)) |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 3097 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 3098 | if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry)) |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 3099 | { |
| 3100 | resolved |= eSymbolContextLineEntry; |
| 3101 | } |
| 3102 | } |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 3103 | } |
| 3104 | } |
| 3105 | |
| 3106 | if (force_check_line_table && !(resolved & eSymbolContextLineEntry)) |
| 3107 | { |
| 3108 | // We might have had a compile unit that had discontiguous |
| 3109 | // address ranges where the gaps are symbols that don't have |
| 3110 | // any debug info. Discontiguous compile unit address ranges |
| 3111 | // should only happen when there aren't other functions from |
| 3112 | // other compile units in these gaps. This helps keep the size |
| 3113 | // of the aranges down. |
| 3114 | sc.comp_unit = NULL; |
| 3115 | resolved &= ~eSymbolContextCompUnit; |
| 3116 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3117 | } |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3118 | else |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3119 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3120 | GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.", |
| 3121 | cu_offset, |
| 3122 | cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3123 | } |
| 3124 | } |
| 3125 | } |
| 3126 | } |
| 3127 | } |
| 3128 | return resolved; |
| 3129 | } |
| 3130 | |
| 3131 | |
| 3132 | |
| 3133 | uint32_t |
| 3134 | SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) |
| 3135 | { |
| 3136 | const uint32_t prev_size = sc_list.GetSize(); |
| 3137 | if (resolve_scope & eSymbolContextCompUnit) |
| 3138 | { |
| 3139 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3140 | if (debug_info) |
| 3141 | { |
| 3142 | uint32_t cu_idx; |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3143 | DWARFCompileUnit* dwarf_cu = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3144 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3145 | 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] | 3146 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3147 | CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); |
| Sean Callanan | ddd7a2a | 2013-10-03 22:27:29 +0000 | [diff] [blame] | 3148 | const bool full_match = (bool)file_spec.GetDirectory(); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 3149 | 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] | 3150 | if (check_inlines || file_spec_matches_cu_file_spec) |
| 3151 | { |
| 3152 | SymbolContext sc (m_obj_file->GetModule()); |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3153 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3154 | if (sc.comp_unit) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3155 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3156 | uint32_t file_idx = UINT32_MAX; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3157 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3158 | // If we are looking for inline functions only and we don't |
| 3159 | // find it in the support files, we are done. |
| 3160 | if (check_inlines) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3161 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3162 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); |
| 3163 | if (file_idx == UINT32_MAX) |
| 3164 | continue; |
| 3165 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3166 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3167 | if (line != 0) |
| 3168 | { |
| 3169 | LineTable *line_table = sc.comp_unit->GetLineTable(); |
| 3170 | |
| 3171 | if (line_table != NULL && line != 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3172 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3173 | // We will have already looked up the file index if |
| 3174 | // we are searching for inline entries. |
| 3175 | if (!check_inlines) |
| 3176 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3177 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3178 | if (file_idx != UINT32_MAX) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3179 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3180 | uint32_t found_line; |
| 3181 | uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry); |
| 3182 | found_line = sc.line_entry.line; |
| 3183 | |
| 3184 | while (line_idx != UINT32_MAX) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3185 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3186 | sc.function = NULL; |
| 3187 | sc.block = NULL; |
| 3188 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3189 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3190 | const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress(); |
| 3191 | if (file_vm_addr != LLDB_INVALID_ADDRESS) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3192 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3193 | DWARFDebugInfoEntry *function_die = NULL; |
| 3194 | DWARFDebugInfoEntry *block_die = NULL; |
| 3195 | 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] | 3196 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3197 | if (function_die != NULL) |
| 3198 | { |
| 3199 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); |
| 3200 | if (sc.function == NULL) |
| 3201 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die); |
| 3202 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3203 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3204 | if (sc.function != NULL) |
| 3205 | { |
| 3206 | Block& block = sc.function->GetBlock (true); |
| 3207 | |
| 3208 | if (block_die != NULL) |
| 3209 | sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); |
| Jason Molenda | 60db6e4 | 2014-10-16 01:40:16 +0000 | [diff] [blame] | 3210 | else if (function_die != NULL) |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3211 | sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); |
| 3212 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3213 | } |
| 3214 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3215 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3216 | sc_list.Append(sc); |
| 3217 | line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry); |
| 3218 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3219 | } |
| 3220 | } |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3221 | else if (file_spec_matches_cu_file_spec && !check_inlines) |
| 3222 | { |
| 3223 | // only append the context if we aren't looking for inline call sites |
| 3224 | // by file and line and if the file spec matches that of the compile unit |
| 3225 | sc_list.Append(sc); |
| 3226 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3227 | } |
| 3228 | else if (file_spec_matches_cu_file_spec && !check_inlines) |
| 3229 | { |
| 3230 | // only append the context if we aren't looking for inline call sites |
| 3231 | // by file and line and if the file spec matches that of the compile unit |
| 3232 | sc_list.Append(sc); |
| 3233 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3234 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3235 | if (!check_inlines) |
| 3236 | break; |
| 3237 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3238 | } |
| 3239 | } |
| 3240 | } |
| 3241 | } |
| 3242 | return sc_list.GetSize() - prev_size; |
| 3243 | } |
| 3244 | |
| 3245 | void |
| 3246 | SymbolFileDWARF::Index () |
| 3247 | { |
| 3248 | if (m_indexed) |
| 3249 | return; |
| 3250 | m_indexed = true; |
| 3251 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 3252 | "SymbolFileDWARF::Index (%s)", |
| Jim Ingham | 4af5961 | 2014-12-19 19:20:44 +0000 | [diff] [blame] | 3253 | GetObjectFile()->GetFileSpec().GetFilename().AsCString("<Unknown>")); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3254 | |
| 3255 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3256 | if (debug_info) |
| 3257 | { |
| 3258 | uint32_t cu_idx = 0; |
| 3259 | const uint32_t num_compile_units = GetNumCompileUnits(); |
| 3260 | for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) |
| 3261 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3262 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3263 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3264 | bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3265 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3266 | dwarf_cu->Index (cu_idx, |
| 3267 | m_function_basename_index, |
| 3268 | m_function_fullname_index, |
| 3269 | m_function_method_index, |
| 3270 | m_function_selector_index, |
| 3271 | m_objc_class_selectors_index, |
| 3272 | m_global_index, |
| 3273 | m_type_index, |
| 3274 | m_namespace_index); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3275 | |
| 3276 | // Keep memory down by clearing DIEs if this generate function |
| 3277 | // caused them to be parsed |
| 3278 | if (clear_dies) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3279 | dwarf_cu->ClearDIEs (true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3280 | } |
| 3281 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3282 | m_function_basename_index.Finalize(); |
| 3283 | m_function_fullname_index.Finalize(); |
| 3284 | m_function_method_index.Finalize(); |
| 3285 | m_function_selector_index.Finalize(); |
| 3286 | m_objc_class_selectors_index.Finalize(); |
| 3287 | m_global_index.Finalize(); |
| 3288 | m_type_index.Finalize(); |
| 3289 | m_namespace_index.Finalize(); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3290 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3291 | #if defined (ENABLE_DEBUG_PRINTF) |
| Greg Clayton | 7bd65b9 | 2011-02-09 23:39:34 +0000 | [diff] [blame] | 3292 | StreamFile s(stdout, false); |
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 3293 | s.Printf ("DWARF index for '%s':", |
| 3294 | GetObjectFile()->GetFileSpec().GetPath().c_str()); |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 3295 | s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s); |
| 3296 | s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s); |
| 3297 | s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s); |
| 3298 | s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s); |
| 3299 | s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s); |
| 3300 | s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s); |
| Greg Clayton | 69b0488 | 2010-10-15 02:03:22 +0000 | [diff] [blame] | 3301 | s.Printf("\nTypes:\n"); m_type_index.Dump (&s); |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 3302 | s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3303 | #endif |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3304 | } |
| 3305 | } |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 3306 | |
| 3307 | bool |
| 3308 | SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl) |
| 3309 | { |
| 3310 | if (namespace_decl == NULL) |
| 3311 | { |
| 3312 | // Invalid namespace decl which means we aren't matching only things |
| 3313 | // in this symbol file, so return true to indicate it matches this |
| 3314 | // symbol file. |
| 3315 | return true; |
| 3316 | } |
| 3317 | |
| 3318 | clang::ASTContext *namespace_ast = namespace_decl->GetASTContext(); |
| 3319 | |
| 3320 | if (namespace_ast == NULL) |
| 3321 | return true; // No AST in the "namespace_decl", return true since it |
| 3322 | // could then match any symbol file, including this one |
| 3323 | |
| 3324 | if (namespace_ast == GetClangASTContext().getASTContext()) |
| 3325 | return true; // The ASTs match, return true |
| 3326 | |
| 3327 | // The namespace AST was valid, and it does not match... |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3328 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Sean Callanan | c41e68b | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 3329 | |
| 3330 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3331 | GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file"); |
| Sean Callanan | c41e68b | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 3332 | |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 3333 | return false; |
| 3334 | } |
| 3335 | |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3336 | bool |
| 3337 | SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl, |
| 3338 | DWARFCompileUnit* cu, |
| 3339 | const DWARFDebugInfoEntry* die) |
| 3340 | { |
| Bruce Mitchener | aaa0ba3 | 2014-07-08 18:05:41 +0000 | [diff] [blame] | 3341 | // No namespace specified, so the answer is |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3342 | if (namespace_decl == NULL) |
| 3343 | return true; |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 3344 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3345 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 3346 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3347 | const DWARFDebugInfoEntry *decl_ctx_die = NULL; |
| 3348 | clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die); |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3349 | if (decl_ctx_die) |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3350 | { |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3351 | clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl(); |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3352 | |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3353 | if (clang_namespace_decl) |
| 3354 | { |
| 3355 | if (decl_ctx_die->Tag() != DW_TAG_namespace) |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 3356 | { |
| 3357 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3358 | 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] | 3359 | return false; |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 3360 | } |
| 3361 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3362 | if (clang_namespace_decl == die_clang_decl_ctx) |
| 3363 | return true; |
| 3364 | else |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3365 | return false; |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3366 | } |
| 3367 | else |
| 3368 | { |
| 3369 | // We have a namespace_decl that was not NULL but it contained |
| 3370 | // a NULL "clang::NamespaceDecl", so this means the global namespace |
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 3371 | // So as long the contained decl context DIE isn't a namespace |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3372 | // we should be ok. |
| 3373 | if (decl_ctx_die->Tag() != DW_TAG_namespace) |
| 3374 | return true; |
| 3375 | } |
| 3376 | } |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 3377 | |
| 3378 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3379 | 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] | 3380 | |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3381 | return false; |
| 3382 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3383 | uint32_t |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3384 | 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] | 3385 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3386 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3387 | |
| 3388 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3389 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3390 | "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)", |
| 3391 | name.GetCString(), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3392 | static_cast<const void*>(namespace_decl), |
| 3393 | append, max_matches); |
| 3394 | |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3395 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) |
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 3396 | return 0; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3397 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3398 | DWARFDebugInfo* info = DebugInfo(); |
| 3399 | if (info == NULL) |
| 3400 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3401 | |
| 3402 | // If we aren't appending the results to this list, then clear the list |
| 3403 | if (!append) |
| 3404 | variables.Clear(); |
| 3405 | |
| 3406 | // Remember how many variables are in the list before we search in case |
| 3407 | // we are appending the results to a variable list. |
| 3408 | const uint32_t original_size = variables.GetSize(); |
| 3409 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3410 | DIEArray die_offsets; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3411 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3412 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3413 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3414 | if (m_apple_names_ap.get()) |
| 3415 | { |
| 3416 | const char *name_cstr = name.GetCString(); |
| Jim Ingham | fa39bb4 | 2014-10-25 00:33:55 +0000 | [diff] [blame] | 3417 | llvm::StringRef basename; |
| 3418 | llvm::StringRef context; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3419 | |
| Jim Ingham | fa39bb4 | 2014-10-25 00:33:55 +0000 | [diff] [blame] | 3420 | if (!CPPLanguageRuntime::ExtractContextAndIdentifier(name_cstr, context, basename)) |
| 3421 | basename = name_cstr; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3422 | |
| Jim Ingham | fa39bb4 | 2014-10-25 00:33:55 +0000 | [diff] [blame] | 3423 | m_apple_names_ap->FindByName (basename.data(), die_offsets); |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3424 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3425 | } |
| 3426 | else |
| 3427 | { |
| 3428 | // Index the DWARF if we haven't already |
| 3429 | if (!m_indexed) |
| 3430 | Index (); |
| 3431 | |
| 3432 | m_global_index.Find (name, die_offsets); |
| 3433 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3434 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3435 | const size_t num_die_matches = die_offsets.size(); |
| 3436 | if (num_die_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3437 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3438 | SymbolContext sc; |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 3439 | sc.module_sp = m_obj_file->GetModule(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3440 | assert (sc.module_sp); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3441 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3442 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3443 | DWARFCompileUnit* dwarf_cu = NULL; |
| 3444 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3445 | bool done = false; |
| 3446 | for (size_t i=0; i<num_die_matches && !done; ++i) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3447 | { |
| 3448 | const dw_offset_t die_offset = die_offsets[i]; |
| 3449 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3450 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3451 | if (die) |
| 3452 | { |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3453 | switch (die->Tag()) |
| 3454 | { |
| 3455 | default: |
| 3456 | case DW_TAG_subprogram: |
| 3457 | case DW_TAG_inlined_subroutine: |
| 3458 | case DW_TAG_try_block: |
| 3459 | case DW_TAG_catch_block: |
| 3460 | break; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3461 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3462 | case DW_TAG_variable: |
| 3463 | { |
| 3464 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3465 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3466 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3467 | continue; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3468 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3469 | ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3470 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3471 | if (variables.GetSize() - original_size >= max_matches) |
| 3472 | done = true; |
| 3473 | } |
| 3474 | break; |
| 3475 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3476 | } |
| 3477 | else |
| 3478 | { |
| 3479 | if (m_using_apple_tables) |
| 3480 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3481 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n", |
| 3482 | die_offset, name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3483 | } |
| 3484 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3485 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3486 | } |
| 3487 | |
| 3488 | // Return the number of variable that were appended to the list |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3489 | const uint32_t num_matches = variables.GetSize() - original_size; |
| 3490 | if (log && num_matches > 0) |
| 3491 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3492 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3493 | "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] | 3494 | name.GetCString(), |
| 3495 | static_cast<const void*>(namespace_decl), |
| 3496 | append, max_matches, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3497 | num_matches); |
| 3498 | } |
| 3499 | return num_matches; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3500 | } |
| 3501 | |
| 3502 | uint32_t |
| 3503 | SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables) |
| 3504 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3505 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3506 | |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3507 | if (log) |
| 3508 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3509 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3510 | "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)", |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3511 | regex.GetText(), append, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3512 | max_matches); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3513 | } |
| 3514 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3515 | DWARFDebugInfo* info = DebugInfo(); |
| 3516 | if (info == NULL) |
| 3517 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3518 | |
| 3519 | // If we aren't appending the results to this list, then clear the list |
| 3520 | if (!append) |
| 3521 | variables.Clear(); |
| 3522 | |
| 3523 | // Remember how many variables are in the list before we search in case |
| 3524 | // we are appending the results to a variable list. |
| 3525 | const uint32_t original_size = variables.GetSize(); |
| 3526 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3527 | DIEArray die_offsets; |
| 3528 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3529 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3530 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3531 | if (m_apple_names_ap.get()) |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3532 | { |
| 3533 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 3534 | if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) |
| 3535 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| 3536 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3537 | } |
| 3538 | else |
| 3539 | { |
| 3540 | // Index the DWARF if we haven't already |
| 3541 | if (!m_indexed) |
| 3542 | Index (); |
| 3543 | |
| 3544 | m_global_index.Find (regex, die_offsets); |
| 3545 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3546 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3547 | SymbolContext sc; |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 3548 | sc.module_sp = m_obj_file->GetModule(); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3549 | assert (sc.module_sp); |
| 3550 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3551 | DWARFCompileUnit* dwarf_cu = NULL; |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3552 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 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) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3555 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3556 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3557 | for (size_t i=0; i<num_matches; ++i) |
| 3558 | { |
| 3559 | const dw_offset_t die_offset = die_offsets[i]; |
| 3560 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3561 | |
| 3562 | if (die) |
| 3563 | { |
| 3564 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3565 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3566 | ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3567 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3568 | if (variables.GetSize() - original_size >= max_matches) |
| 3569 | break; |
| 3570 | } |
| 3571 | else |
| 3572 | { |
| 3573 | if (m_using_apple_tables) |
| 3574 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3575 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n", |
| 3576 | die_offset, regex.GetText()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3577 | } |
| 3578 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3579 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3580 | } |
| 3581 | |
| 3582 | // Return the number of variable that were appended to the list |
| 3583 | return variables.GetSize() - original_size; |
| 3584 | } |
| 3585 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3586 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3587 | bool |
| 3588 | SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset, |
| 3589 | DWARFCompileUnit *&dwarf_cu, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3590 | bool include_inlines, |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3591 | SymbolContextList& sc_list) |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3592 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3593 | const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3594 | return ResolveFunction (dwarf_cu, die, include_inlines, sc_list); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3595 | } |
| 3596 | |
| 3597 | |
| 3598 | bool |
| 3599 | SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu, |
| 3600 | const DWARFDebugInfoEntry *die, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3601 | bool include_inlines, |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3602 | SymbolContextList& sc_list) |
| 3603 | { |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3604 | SymbolContext sc; |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3605 | |
| 3606 | if (die == NULL) |
| 3607 | return false; |
| 3608 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3609 | // If we were passed a die that is not a function, just return false... |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3610 | if (! (die->Tag() == DW_TAG_subprogram || (include_inlines && die->Tag() == DW_TAG_inlined_subroutine))) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3611 | return false; |
| 3612 | |
| 3613 | const DWARFDebugInfoEntry* inlined_die = NULL; |
| 3614 | if (die->Tag() == DW_TAG_inlined_subroutine) |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3615 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3616 | inlined_die = die; |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3617 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3618 | while ((die = die->GetParent()) != NULL) |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3619 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3620 | if (die->Tag() == DW_TAG_subprogram) |
| 3621 | break; |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3622 | } |
| 3623 | } |
| Jason Molenda | 60db6e4 | 2014-10-16 01:40:16 +0000 | [diff] [blame] | 3624 | assert (die && die->Tag() == DW_TAG_subprogram); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3625 | if (GetFunction (cu, die, sc)) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3626 | { |
| 3627 | Address addr; |
| 3628 | // Parse all blocks if needed |
| 3629 | if (inlined_die) |
| 3630 | { |
| Greg Clayton | f7bb1fb | 2015-01-15 03:13:44 +0000 | [diff] [blame] | 3631 | Block &function_block = sc.function->GetBlock (true); |
| 3632 | sc.block = function_block.FindBlockByID (MakeUserID(inlined_die->GetOffset())); |
| 3633 | if (sc.block == NULL) |
| 3634 | sc.block = function_block.FindBlockByID (inlined_die->GetOffset()); |
| 3635 | if (sc.block == NULL || sc.block->GetStartAddress (addr) == false) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3636 | addr.Clear(); |
| 3637 | } |
| 3638 | else |
| 3639 | { |
| 3640 | sc.block = NULL; |
| 3641 | addr = sc.function->GetAddressRange().GetBaseAddress(); |
| 3642 | } |
| 3643 | |
| 3644 | if (addr.IsValid()) |
| 3645 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3646 | sc_list.Append(sc); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3647 | return true; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3648 | } |
| 3649 | } |
| 3650 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3651 | return false; |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3652 | } |
| 3653 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3654 | void |
| 3655 | SymbolFileDWARF::FindFunctions (const ConstString &name, |
| 3656 | const NameToDIE &name_to_die, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3657 | bool include_inlines, |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3658 | SymbolContextList& sc_list) |
| 3659 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3660 | DIEArray die_offsets; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3661 | if (name_to_die.Find (name, die_offsets)) |
| 3662 | { |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3663 | ParseFunctions (die_offsets, include_inlines, sc_list); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3664 | } |
| 3665 | } |
| 3666 | |
| 3667 | |
| 3668 | void |
| 3669 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, |
| 3670 | const NameToDIE &name_to_die, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3671 | bool include_inlines, |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3672 | SymbolContextList& sc_list) |
| 3673 | { |
| 3674 | DIEArray die_offsets; |
| 3675 | if (name_to_die.Find (regex, die_offsets)) |
| 3676 | { |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3677 | ParseFunctions (die_offsets, include_inlines, sc_list); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3678 | } |
| 3679 | } |
| 3680 | |
| 3681 | |
| 3682 | void |
| 3683 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, |
| 3684 | const DWARFMappedHash::MemoryTable &memory_table, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3685 | bool include_inlines, |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3686 | SymbolContextList& sc_list) |
| 3687 | { |
| 3688 | DIEArray die_offsets; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3689 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 3690 | if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3691 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3692 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3693 | ParseFunctions (die_offsets, include_inlines, sc_list); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3694 | } |
| 3695 | } |
| 3696 | |
| 3697 | void |
| 3698 | SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3699 | bool include_inlines, |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3700 | SymbolContextList& sc_list) |
| 3701 | { |
| 3702 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3703 | if (num_matches) |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3704 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3705 | DWARFCompileUnit* dwarf_cu = NULL; |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3706 | for (size_t i=0; i<num_matches; ++i) |
| Greg Clayton | d7e0546 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 3707 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3708 | const dw_offset_t die_offset = die_offsets[i]; |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3709 | ResolveFunction (die_offset, dwarf_cu, include_inlines, sc_list); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3710 | } |
| 3711 | } |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3712 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3713 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3714 | bool |
| 3715 | SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die, |
| 3716 | const DWARFCompileUnit *dwarf_cu, |
| 3717 | uint32_t name_type_mask, |
| 3718 | const char *partial_name, |
| 3719 | const char *base_name_start, |
| 3720 | const char *base_name_end) |
| 3721 | { |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3722 | // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes: |
| 3723 | if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3724 | { |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 3725 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset()); |
| 3726 | if (!containing_decl_ctx) |
| 3727 | return false; |
| 3728 | |
| 3729 | bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()); |
| 3730 | |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3731 | if (name_type_mask == eFunctionNameTypeMethod) |
| 3732 | { |
| 3733 | if (is_cxx_method == false) |
| 3734 | return false; |
| 3735 | } |
| 3736 | |
| 3737 | if (name_type_mask == eFunctionNameTypeBase) |
| 3738 | { |
| 3739 | if (is_cxx_method == true) |
| 3740 | return false; |
| 3741 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3742 | } |
| 3743 | |
| 3744 | // Now we need to check whether the name we got back for this type matches the extra specifications |
| 3745 | // that were in the name we're looking up: |
| 3746 | if (base_name_start != partial_name || *base_name_end != '\0') |
| 3747 | { |
| 3748 | // First see if the stuff to the left matches the full name. To do that let's see if |
| 3749 | // we can pull out the mips linkage name attribute: |
| 3750 | |
| 3751 | Mangled best_name; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3752 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3753 | DWARFFormValue form_value; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3754 | die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| 3755 | uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name); |
| Greg Clayton | 7141554 | 2012-12-08 00:24:40 +0000 | [diff] [blame] | 3756 | if (idx == UINT32_MAX) |
| 3757 | idx = attributes.FindAttributeIndex(DW_AT_linkage_name); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3758 | if (idx != UINT32_MAX) |
| 3759 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3760 | if (attributes.ExtractFormValueAtIndex(this, idx, form_value)) |
| 3761 | { |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3762 | const char *mangled_name = form_value.AsCString(&get_debug_str_data()); |
| 3763 | if (mangled_name) |
| 3764 | best_name.SetValue (ConstString(mangled_name), true); |
| 3765 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3766 | } |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3767 | |
| 3768 | if (!best_name) |
| 3769 | { |
| 3770 | idx = attributes.FindAttributeIndex(DW_AT_name); |
| 3771 | if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value)) |
| 3772 | { |
| 3773 | const char *name = form_value.AsCString(&get_debug_str_data()); |
| 3774 | best_name.SetValue (ConstString(name), false); |
| 3775 | } |
| 3776 | } |
| 3777 | |
| Greg Clayton | ddaf6a7 | 2015-07-08 22:32:23 +0000 | [diff] [blame] | 3778 | const LanguageType cu_language = const_cast<DWARFCompileUnit *>(dwarf_cu)->GetLanguageType(); |
| 3779 | if (best_name.GetDemangledName(cu_language)) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3780 | { |
| Greg Clayton | ddaf6a7 | 2015-07-08 22:32:23 +0000 | [diff] [blame] | 3781 | const char *demangled = best_name.GetDemangledName(cu_language).GetCString(); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3782 | if (demangled) |
| 3783 | { |
| 3784 | std::string name_no_parens(partial_name, base_name_end - partial_name); |
| Jim Ingham | 85c13d7 | 2012-03-02 02:24:42 +0000 | [diff] [blame] | 3785 | const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str()); |
| 3786 | if (partial_in_demangled == NULL) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3787 | return false; |
| Jim Ingham | 85c13d7 | 2012-03-02 02:24:42 +0000 | [diff] [blame] | 3788 | else |
| 3789 | { |
| 3790 | // Sort out the case where our name is something like "Process::Destroy" and the match is |
| 3791 | // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on |
| 3792 | // namespace boundaries... |
| 3793 | |
| 3794 | if (partial_name[0] == ':' && partial_name[1] == ':') |
| 3795 | { |
| 3796 | // The partial name was already on a namespace boundary so all matches are good. |
| 3797 | return true; |
| 3798 | } |
| 3799 | else if (partial_in_demangled == demangled) |
| 3800 | { |
| 3801 | // They both start the same, so this is an good match. |
| 3802 | return true; |
| 3803 | } |
| 3804 | else |
| 3805 | { |
| 3806 | if (partial_in_demangled - demangled == 1) |
| 3807 | { |
| 3808 | // Only one character difference, can't be a namespace boundary... |
| 3809 | return false; |
| 3810 | } |
| 3811 | else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':') |
| 3812 | { |
| 3813 | // We are on a namespace boundary, so this is also good. |
| 3814 | return true; |
| 3815 | } |
| 3816 | else |
| 3817 | return false; |
| 3818 | } |
| 3819 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3820 | } |
| 3821 | } |
| 3822 | } |
| 3823 | |
| 3824 | return true; |
| 3825 | } |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3826 | |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3827 | uint32_t |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3828 | SymbolFileDWARF::FindFunctions (const ConstString &name, |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3829 | const lldb_private::ClangNamespaceDecl *namespace_decl, |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3830 | uint32_t name_type_mask, |
| 3831 | bool include_inlines, |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3832 | bool append, |
| 3833 | SymbolContextList& sc_list) |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3834 | { |
| 3835 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 3836 | "SymbolFileDWARF::FindFunctions (name = '%s')", |
| 3837 | name.AsCString()); |
| 3838 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3839 | // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup() |
| 3840 | assert ((name_type_mask & eFunctionNameTypeAuto) == 0); |
| 3841 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3842 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3843 | |
| 3844 | if (log) |
| 3845 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3846 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3847 | "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)", |
| 3848 | name.GetCString(), |
| 3849 | name_type_mask, |
| 3850 | append); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3851 | } |
| 3852 | |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3853 | // If we aren't appending the results to this list, then clear the list |
| 3854 | if (!append) |
| 3855 | sc_list.Clear(); |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3856 | |
| 3857 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) |
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 3858 | return 0; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3859 | |
| 3860 | // If name is empty then we won't find anything. |
| 3861 | if (name.IsEmpty()) |
| 3862 | return 0; |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3863 | |
| 3864 | // Remember how many sc_list are in the list before we search in case |
| 3865 | // we are appending the results to a variable list. |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3866 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3867 | const char *name_cstr = name.GetCString(); |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3868 | |
| 3869 | const uint32_t original_size = sc_list.GetSize(); |
| 3870 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3871 | DWARFDebugInfo* info = DebugInfo(); |
| 3872 | if (info == NULL) |
| 3873 | return 0; |
| 3874 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3875 | DWARFCompileUnit *dwarf_cu = NULL; |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3876 | std::set<const DWARFDebugInfoEntry *> resolved_dies; |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3877 | if (m_using_apple_tables) |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 3878 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3879 | if (m_apple_names_ap.get()) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3880 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3881 | |
| 3882 | DIEArray die_offsets; |
| 3883 | |
| 3884 | uint32_t num_matches = 0; |
| 3885 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3886 | if (name_type_mask & eFunctionNameTypeFull) |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3887 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3888 | // If they asked for the full name, match what they typed. At some point we may |
| 3889 | // want to canonicalize this (strip double spaces, etc. For now, we just add all the |
| 3890 | // dies that we find by exact match. |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3891 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3892 | for (uint32_t i = 0; i < num_matches; i++) |
| 3893 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3894 | const dw_offset_t die_offset = die_offsets[i]; |
| 3895 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3896 | if (die) |
| 3897 | { |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3898 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3899 | continue; |
| 3900 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3901 | if (resolved_dies.find(die) == resolved_dies.end()) |
| 3902 | { |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3903 | if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list)) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3904 | resolved_dies.insert(die); |
| 3905 | } |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3906 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3907 | else |
| 3908 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3909 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 3910 | die_offset, name_cstr); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3911 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3912 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3913 | } |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3914 | |
| 3915 | if (name_type_mask & eFunctionNameTypeSelector) |
| 3916 | { |
| 3917 | if (namespace_decl && *namespace_decl) |
| 3918 | return 0; // no selectors in namespaces |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3919 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3920 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); |
| 3921 | // Now make sure these are actually ObjC methods. In this case we can simply look up the name, |
| 3922 | // and if it is an ObjC method name, we're good. |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3923 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3924 | for (uint32_t i = 0; i < num_matches; i++) |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3925 | { |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3926 | const dw_offset_t die_offset = die_offsets[i]; |
| 3927 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| 3928 | if (die) |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3929 | { |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3930 | const char *die_name = die->GetName(this, dwarf_cu); |
| 3931 | if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name)) |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3932 | { |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3933 | if (resolved_dies.find(die) == resolved_dies.end()) |
| 3934 | { |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3935 | if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list)) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3936 | resolved_dies.insert(die); |
| 3937 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3938 | } |
| 3939 | } |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3940 | else |
| 3941 | { |
| 3942 | GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 3943 | die_offset, name_cstr); |
| 3944 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3945 | } |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3946 | die_offsets.clear(); |
| 3947 | } |
| 3948 | |
| 3949 | if (((name_type_mask & eFunctionNameTypeMethod) && !namespace_decl) || name_type_mask & eFunctionNameTypeBase) |
| 3950 | { |
| 3951 | // The apple_names table stores just the "base name" of C++ methods in the table. So we have to |
| 3952 | // extract the base name, look that up, and if there is any other information in the name we were |
| 3953 | // passed in we have to post-filter based on that. |
| 3954 | |
| 3955 | // FIXME: Arrange the logic above so that we don't calculate the base name twice: |
| 3956 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); |
| 3957 | |
| 3958 | for (uint32_t i = 0; i < num_matches; i++) |
| 3959 | { |
| 3960 | const dw_offset_t die_offset = die_offsets[i]; |
| 3961 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| 3962 | if (die) |
| 3963 | { |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3964 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3965 | continue; |
| 3966 | |
| 3967 | // If we get to here, the die is good, and we should add it: |
| 3968 | if (resolved_dies.find(die) == resolved_dies.end()) |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3969 | if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list)) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3970 | { |
| 3971 | bool keep_die = true; |
| 3972 | if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod)) |
| 3973 | { |
| 3974 | // We are looking for either basenames or methods, so we need to |
| 3975 | // trim out the ones we won't want by looking at the type |
| 3976 | SymbolContext sc; |
| 3977 | if (sc_list.GetLastContext(sc)) |
| 3978 | { |
| 3979 | if (sc.block) |
| 3980 | { |
| 3981 | // We have an inlined function |
| 3982 | } |
| 3983 | else if (sc.function) |
| 3984 | { |
| 3985 | Type *type = sc.function->GetType(); |
| 3986 | |
| Sean Callanan | c370a8a | 2013-09-18 22:59:55 +0000 | [diff] [blame] | 3987 | if (type) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3988 | { |
| Sean Callanan | c370a8a | 2013-09-18 22:59:55 +0000 | [diff] [blame] | 3989 | clang::DeclContext* decl_ctx = GetClangDeclContextContainingTypeUID (type->GetID()); |
| 3990 | if (decl_ctx->isRecord()) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3991 | { |
| Sean Callanan | c370a8a | 2013-09-18 22:59:55 +0000 | [diff] [blame] | 3992 | if (name_type_mask & eFunctionNameTypeBase) |
| 3993 | { |
| 3994 | sc_list.RemoveContextAtIndex(sc_list.GetSize()-1); |
| 3995 | keep_die = false; |
| 3996 | } |
| 3997 | } |
| 3998 | else |
| 3999 | { |
| 4000 | if (name_type_mask & eFunctionNameTypeMethod) |
| 4001 | { |
| 4002 | sc_list.RemoveContextAtIndex(sc_list.GetSize()-1); |
| 4003 | keep_die = false; |
| 4004 | } |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 4005 | } |
| 4006 | } |
| 4007 | else |
| 4008 | { |
| Sean Callanan | c370a8a | 2013-09-18 22:59:55 +0000 | [diff] [blame] | 4009 | GetObjectFile()->GetModule()->ReportWarning ("function at die offset 0x%8.8x had no function type", |
| 4010 | die_offset); |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 4011 | } |
| 4012 | } |
| 4013 | } |
| 4014 | } |
| 4015 | if (keep_die) |
| 4016 | resolved_dies.insert(die); |
| 4017 | } |
| 4018 | } |
| 4019 | else |
| 4020 | { |
| 4021 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 4022 | die_offset, name_cstr); |
| 4023 | } |
| 4024 | } |
| 4025 | die_offsets.clear(); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 4026 | } |
| 4027 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4028 | } |
| 4029 | else |
| 4030 | { |
| 4031 | |
| 4032 | // Index the DWARF if we haven't already |
| 4033 | if (!m_indexed) |
| 4034 | Index (); |
| 4035 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4036 | if (name_type_mask & eFunctionNameTypeFull) |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 4037 | { |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 4038 | FindFunctions (name, m_function_fullname_index, include_inlines, sc_list); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4039 | |
| Ed Maste | fc7baa0 | 2013-09-09 18:00:45 +0000 | [diff] [blame] | 4040 | // FIXME Temporary workaround for global/anonymous namespace |
| Robert Flack | 5cbd3bf | 2015-05-13 18:20:02 +0000 | [diff] [blame] | 4041 | // functions debugging FreeBSD and Linux binaries. |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 4042 | // If we didn't find any functions in the global namespace try |
| 4043 | // looking in the basename index but ignore any returned |
| Robert Flack | eb83fab | 2015-05-15 18:59:59 +0000 | [diff] [blame] | 4044 | // functions that have a namespace but keep functions which |
| 4045 | // have an anonymous namespace |
| 4046 | // TODO: The arch in the object file isn't correct for MSVC |
| 4047 | // binaries on windows, we should find a way to make it |
| 4048 | // correct and handle those symbols as well. |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 4049 | if (sc_list.GetSize() == 0) |
| 4050 | { |
| Robert Flack | eb83fab | 2015-05-15 18:59:59 +0000 | [diff] [blame] | 4051 | ArchSpec arch; |
| 4052 | if (!namespace_decl && |
| 4053 | GetObjectFile()->GetArchitecture(arch) && |
| 4054 | (arch.GetTriple().isOSFreeBSD() || arch.GetTriple().isOSLinux() || |
| 4055 | arch.GetMachine() == llvm::Triple::hexagon)) |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 4056 | { |
| Robert Flack | eb83fab | 2015-05-15 18:59:59 +0000 | [diff] [blame] | 4057 | SymbolContextList temp_sc_list; |
| 4058 | FindFunctions (name, m_function_basename_index, include_inlines, temp_sc_list); |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 4059 | SymbolContext sc; |
| 4060 | for (uint32_t i = 0; i < temp_sc_list.GetSize(); i++) |
| 4061 | { |
| 4062 | if (temp_sc_list.GetContextAtIndex(i, sc)) |
| 4063 | { |
| Matt Kopec | a189d49 | 2013-05-10 22:55:24 +0000 | [diff] [blame] | 4064 | ConstString mangled_name = sc.GetFunctionName(Mangled::ePreferMangled); |
| 4065 | ConstString demangled_name = sc.GetFunctionName(Mangled::ePreferDemangled); |
| Robert Flack | eb83fab | 2015-05-15 18:59:59 +0000 | [diff] [blame] | 4066 | // Mangled names on Linux and FreeBSD are of the form: |
| 4067 | // _ZN18function_namespace13function_nameEv. |
| Matt Kopec | 04e5d58 | 2013-05-14 19:00:41 +0000 | [diff] [blame] | 4068 | if (strncmp(mangled_name.GetCString(), "_ZN", 3) || |
| 4069 | !strncmp(demangled_name.GetCString(), "(anonymous namespace)", 21)) |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 4070 | { |
| 4071 | sc_list.Append(sc); |
| 4072 | } |
| 4073 | } |
| 4074 | } |
| 4075 | } |
| 4076 | } |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 4077 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 4078 | DIEArray die_offsets; |
| 4079 | DWARFCompileUnit *dwarf_cu = NULL; |
| 4080 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 4081 | if (name_type_mask & eFunctionNameTypeBase) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 4082 | { |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 4083 | uint32_t num_base = m_function_basename_index.Find(name, die_offsets); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 4084 | for (uint32_t i = 0; i < num_base; i++) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 4085 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 4086 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); |
| 4087 | if (die) |
| 4088 | { |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 4089 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 4090 | continue; |
| 4091 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 4092 | // 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] | 4093 | if (resolved_dies.find(die) == resolved_dies.end()) |
| 4094 | { |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 4095 | if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list)) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 4096 | resolved_dies.insert(die); |
| 4097 | } |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 4098 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 4099 | } |
| 4100 | die_offsets.clear(); |
| 4101 | } |
| 4102 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 4103 | if (name_type_mask & eFunctionNameTypeMethod) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 4104 | { |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 4105 | if (namespace_decl && *namespace_decl) |
| 4106 | return 0; // no methods in namespaces |
| 4107 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 4108 | uint32_t num_base = m_function_method_index.Find(name, die_offsets); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 4109 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 4110 | for (uint32_t i = 0; i < num_base; i++) |
| 4111 | { |
| 4112 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); |
| 4113 | if (die) |
| 4114 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 4115 | // 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] | 4116 | if (resolved_dies.find(die) == resolved_dies.end()) |
| 4117 | { |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 4118 | if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list)) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 4119 | resolved_dies.insert(die); |
| 4120 | } |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 4121 | } |
| 4122 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 4123 | } |
| 4124 | die_offsets.clear(); |
| 4125 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4126 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 4127 | if ((name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl)) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 4128 | { |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 4129 | FindFunctions (name, m_function_selector_index, include_inlines, sc_list); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 4130 | } |
| 4131 | |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 4132 | } |
| 4133 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4134 | // Return the number of variable that were appended to the list |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4135 | const uint32_t num_matches = sc_list.GetSize() - original_size; |
| 4136 | |
| 4137 | if (log && num_matches > 0) |
| 4138 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4139 | GetObjectFile()->GetModule()->LogMessage (log, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 4140 | "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, include_inlines=%d, append=%u, sc_list) => %u", |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4141 | name.GetCString(), |
| 4142 | name_type_mask, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 4143 | include_inlines, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4144 | append, |
| 4145 | num_matches); |
| 4146 | } |
| 4147 | return num_matches; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4148 | } |
| 4149 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4150 | uint32_t |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 4151 | 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] | 4152 | { |
| 4153 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 4154 | "SymbolFileDWARF::FindFunctions (regex = '%s')", |
| 4155 | regex.GetText()); |
| 4156 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4157 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 4158 | |
| 4159 | if (log) |
| 4160 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4161 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4162 | "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)", |
| 4163 | regex.GetText(), |
| 4164 | append); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 4165 | } |
| 4166 | |
| 4167 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4168 | // If we aren't appending the results to this list, then clear the list |
| 4169 | if (!append) |
| 4170 | sc_list.Clear(); |
| 4171 | |
| 4172 | // Remember how many sc_list are in the list before we search in case |
| 4173 | // we are appending the results to a variable list. |
| 4174 | uint32_t original_size = sc_list.GetSize(); |
| 4175 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4176 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4177 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4178 | if (m_apple_names_ap.get()) |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 4179 | FindFunctions (regex, *m_apple_names_ap, include_inlines, sc_list); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4180 | } |
| 4181 | else |
| 4182 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 4183 | // Index the DWARF if we haven't already |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4184 | if (!m_indexed) |
| 4185 | Index (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4186 | |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 4187 | FindFunctions (regex, m_function_basename_index, include_inlines, sc_list); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4188 | |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 4189 | FindFunctions (regex, m_function_fullname_index, include_inlines, sc_list); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4190 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4191 | |
| 4192 | // Return the number of variable that were appended to the list |
| 4193 | return sc_list.GetSize() - original_size; |
| 4194 | } |
| Jim Ingham | 318c9f2 | 2011-08-26 19:44:13 +0000 | [diff] [blame] | 4195 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4196 | uint32_t |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4197 | SymbolFileDWARF::FindTypes (const SymbolContext& sc, |
| 4198 | const ConstString &name, |
| 4199 | const lldb_private::ClangNamespaceDecl *namespace_decl, |
| 4200 | bool append, |
| 4201 | uint32_t max_matches, |
| 4202 | TypeList& types) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4203 | { |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 4204 | DWARFDebugInfo* info = DebugInfo(); |
| 4205 | if (info == NULL) |
| 4206 | return 0; |
| 4207 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4208 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4209 | |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 4210 | if (log) |
| 4211 | { |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4212 | if (namespace_decl) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4213 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4214 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)", |
| 4215 | name.GetCString(), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4216 | static_cast<void*>(namespace_decl->GetNamespaceDecl()), |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4217 | namespace_decl->GetQualifiedName().c_str(), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4218 | append, max_matches); |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4219 | else |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4220 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4221 | "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] | 4222 | name.GetCString(), append, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4223 | max_matches); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 4224 | } |
| 4225 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4226 | // If we aren't appending the results to this list, then clear the list |
| 4227 | if (!append) |
| 4228 | types.Clear(); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4229 | |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 4230 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) |
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 4231 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4232 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4233 | DIEArray die_offsets; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4234 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4235 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4236 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4237 | if (m_apple_types_ap.get()) |
| 4238 | { |
| 4239 | const char *name_cstr = name.GetCString(); |
| 4240 | m_apple_types_ap->FindByName (name_cstr, die_offsets); |
| 4241 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4242 | } |
| 4243 | else |
| 4244 | { |
| 4245 | if (!m_indexed) |
| 4246 | Index (); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4247 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4248 | m_type_index.Find (name, die_offsets); |
| 4249 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4250 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4251 | const size_t num_die_matches = die_offsets.size(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4252 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4253 | if (num_die_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4254 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4255 | const uint32_t initial_types_size = types.GetSize(); |
| 4256 | DWARFCompileUnit* dwarf_cu = NULL; |
| 4257 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4258 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4259 | for (size_t i=0; i<num_die_matches; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4260 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4261 | const dw_offset_t die_offset = die_offsets[i]; |
| 4262 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| 4263 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4264 | if (die) |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 4265 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4266 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 4267 | continue; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4268 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4269 | Type *matching_type = ResolveType (dwarf_cu, die); |
| 4270 | if (matching_type) |
| 4271 | { |
| 4272 | // 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] | 4273 | types.InsertUnique (matching_type->shared_from_this()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4274 | if (types.GetSize() >= max_matches) |
| 4275 | break; |
| 4276 | } |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 4277 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4278 | else |
| 4279 | { |
| 4280 | if (m_using_apple_tables) |
| 4281 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4282 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 4283 | die_offset, name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4284 | } |
| 4285 | } |
| 4286 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4287 | } |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4288 | const uint32_t num_matches = types.GetSize() - initial_types_size; |
| 4289 | if (log && num_matches) |
| 4290 | { |
| 4291 | if (namespace_decl) |
| 4292 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4293 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4294 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u", |
| 4295 | name.GetCString(), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4296 | static_cast<void*>(namespace_decl->GetNamespaceDecl()), |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4297 | namespace_decl->GetQualifiedName().c_str(), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4298 | append, max_matches, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4299 | num_matches); |
| 4300 | } |
| 4301 | else |
| 4302 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4303 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4304 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u", |
| 4305 | name.GetCString(), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4306 | append, max_matches, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4307 | num_matches); |
| 4308 | } |
| 4309 | } |
| 4310 | return num_matches; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4311 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4312 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4313 | } |
| 4314 | |
| 4315 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4316 | ClangNamespaceDecl |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4317 | SymbolFileDWARF::FindNamespace (const SymbolContext& sc, |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 4318 | const ConstString &name, |
| 4319 | const lldb_private::ClangNamespaceDecl *parent_namespace_decl) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4320 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4321 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 4322 | |
| 4323 | if (log) |
| 4324 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4325 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4326 | "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")", |
| 4327 | name.GetCString()); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 4328 | } |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 4329 | |
| 4330 | if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl)) |
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 4331 | return ClangNamespaceDecl(); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 4332 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4333 | ClangNamespaceDecl namespace_decl; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4334 | DWARFDebugInfo* info = DebugInfo(); |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4335 | if (info) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4336 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4337 | DIEArray die_offsets; |
| 4338 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4339 | // Index if we already haven't to make sure the compile units |
| 4340 | // get indexed and make their global DIE index list |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4341 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4342 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4343 | if (m_apple_namespaces_ap.get()) |
| 4344 | { |
| 4345 | const char *name_cstr = name.GetCString(); |
| 4346 | m_apple_namespaces_ap->FindByName (name_cstr, die_offsets); |
| 4347 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4348 | } |
| 4349 | else |
| 4350 | { |
| 4351 | if (!m_indexed) |
| 4352 | Index (); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4353 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4354 | m_namespace_index.Find (name, die_offsets); |
| 4355 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4356 | |
| 4357 | DWARFCompileUnit* dwarf_cu = NULL; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4358 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4359 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4360 | if (num_matches) |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4361 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4362 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 4363 | for (size_t i=0; i<num_matches; ++i) |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4364 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4365 | const dw_offset_t die_offset = die_offsets[i]; |
| 4366 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 4367 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4368 | if (die) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4369 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4370 | if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die)) |
| 4371 | continue; |
| 4372 | |
| 4373 | clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die); |
| 4374 | if (clang_namespace_decl) |
| 4375 | { |
| 4376 | namespace_decl.SetASTContext (GetClangASTContext().getASTContext()); |
| 4377 | namespace_decl.SetNamespaceDecl (clang_namespace_decl); |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4378 | break; |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4379 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4380 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4381 | else |
| 4382 | { |
| 4383 | if (m_using_apple_tables) |
| 4384 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4385 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n", |
| 4386 | die_offset, name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4387 | } |
| 4388 | } |
| 4389 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4390 | } |
| 4391 | } |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4392 | } |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4393 | if (log && namespace_decl.GetNamespaceDecl()) |
| 4394 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4395 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4396 | "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"", |
| 4397 | name.GetCString(), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4398 | static_cast<const void*>(namespace_decl.GetNamespaceDecl()), |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4399 | namespace_decl.GetQualifiedName().c_str()); |
| 4400 | } |
| 4401 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4402 | return namespace_decl; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4403 | } |
| 4404 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4405 | uint32_t |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4406 | 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] | 4407 | { |
| 4408 | // Remember how many sc_list are in the list before we search in case |
| 4409 | // we are appending the results to a variable list. |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4410 | uint32_t original_size = types.GetSize(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4411 | |
| 4412 | const uint32_t num_die_offsets = die_offsets.size(); |
| 4413 | // Parse all of the types we found from the pubtypes matches |
| 4414 | uint32_t i; |
| 4415 | uint32_t num_matches = 0; |
| 4416 | for (i = 0; i < num_die_offsets; ++i) |
| 4417 | { |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4418 | Type *matching_type = ResolveTypeUID (die_offsets[i]); |
| 4419 | if (matching_type) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4420 | { |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4421 | // 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] | 4422 | types.InsertUnique (matching_type->shared_from_this()); |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4423 | ++num_matches; |
| 4424 | if (num_matches >= max_matches) |
| 4425 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4426 | } |
| 4427 | } |
| 4428 | |
| 4429 | // Return the number of variable that were appended to the list |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4430 | return types.GetSize() - original_size; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4431 | } |
| 4432 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4433 | |
| 4434 | size_t |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4435 | SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc, |
| 4436 | clang::DeclContext *containing_decl_ctx, |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4437 | DWARFCompileUnit* dwarf_cu, |
| 4438 | const DWARFDebugInfoEntry *parent_die, |
| 4439 | bool skip_artificial, |
| 4440 | bool &is_static, |
| Greg Clayton | 0396975 | 2014-02-24 18:53:11 +0000 | [diff] [blame] | 4441 | bool &is_variadic, |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 4442 | std::vector<ClangASTType>& function_param_types, |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4443 | std::vector<clang::ParmVarDecl*>& function_param_decls, |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 4444 | unsigned &type_quals) // , |
| 4445 | // ClangASTContext::TemplateParameterInfos &template_param_infos)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4446 | { |
| 4447 | if (parent_die == NULL) |
| 4448 | return 0; |
| 4449 | |
| Todd Fiala | ee8bfc6 | 2014-09-11 17:29:12 +0000 | [diff] [blame] | 4450 | 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] | 4451 | |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4452 | size_t arg_idx = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4453 | const DWARFDebugInfoEntry *die; |
| 4454 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 4455 | { |
| 4456 | dw_tag_t tag = die->Tag(); |
| 4457 | switch (tag) |
| 4458 | { |
| 4459 | case DW_TAG_formal_parameter: |
| 4460 | { |
| 4461 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4462 | 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] | 4463 | if (num_attributes > 0) |
| 4464 | { |
| 4465 | const char *name = NULL; |
| 4466 | Declaration decl; |
| 4467 | dw_offset_t param_type_die_offset = DW_INVALID_OFFSET; |
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 4468 | bool is_artificial = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4469 | // one of None, Auto, Register, Extern, Static, PrivateExtern |
| 4470 | |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 4471 | clang::StorageClass storage = clang::SC_None; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4472 | uint32_t i; |
| 4473 | for (i=0; i<num_attributes; ++i) |
| 4474 | { |
| 4475 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 4476 | DWARFFormValue form_value; |
| 4477 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 4478 | { |
| 4479 | switch (attr) |
| 4480 | { |
| 4481 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 4482 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 4483 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 4484 | 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] | 4485 | case DW_AT_type: param_type_die_offset = form_value.Reference(); break; |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 4486 | case DW_AT_artificial: is_artificial = form_value.Boolean(); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4487 | case DW_AT_location: |
| 4488 | // if (form_value.BlockData()) |
| 4489 | // { |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 4490 | // const DWARFDataExtractor& debug_info_data = debug_info(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4491 | // uint32_t block_length = form_value.Unsigned(); |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 4492 | // 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] | 4493 | // } |
| 4494 | // else |
| 4495 | // { |
| 4496 | // } |
| 4497 | // break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4498 | case DW_AT_const_value: |
| 4499 | case DW_AT_default_value: |
| 4500 | case DW_AT_description: |
| 4501 | case DW_AT_endianity: |
| 4502 | case DW_AT_is_optional: |
| 4503 | case DW_AT_segment: |
| 4504 | case DW_AT_variable_parameter: |
| 4505 | default: |
| 4506 | case DW_AT_abstract_origin: |
| 4507 | case DW_AT_sibling: |
| 4508 | break; |
| 4509 | } |
| 4510 | } |
| 4511 | } |
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 4512 | |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4513 | bool skip = false; |
| 4514 | if (skip_artificial) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4515 | { |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4516 | if (is_artificial) |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4517 | { |
| 4518 | // In order to determine if a C++ member function is |
| 4519 | // "const" we have to look at the const-ness of "this"... |
| 4520 | // Ugly, but that |
| 4521 | if (arg_idx == 0) |
| 4522 | { |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 4523 | if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind())) |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 4524 | { |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4525 | // Often times compilers omit the "this" name for the |
| 4526 | // specification DIEs, so we can't rely upon the name |
| 4527 | // being in the formal parameter DIE... |
| 4528 | if (name == NULL || ::strcmp(name, "this")==0) |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4529 | { |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4530 | Type *this_type = ResolveTypeUID (param_type_die_offset); |
| 4531 | if (this_type) |
| 4532 | { |
| 4533 | uint32_t encoding_mask = this_type->GetEncodingMask(); |
| 4534 | if (encoding_mask & Type::eEncodingIsPointerUID) |
| 4535 | { |
| 4536 | is_static = false; |
| 4537 | |
| 4538 | if (encoding_mask & (1u << Type::eEncodingIsConstUID)) |
| 4539 | type_quals |= clang::Qualifiers::Const; |
| 4540 | if (encoding_mask & (1u << Type::eEncodingIsVolatileUID)) |
| 4541 | type_quals |= clang::Qualifiers::Volatile; |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4542 | } |
| 4543 | } |
| 4544 | } |
| 4545 | } |
| 4546 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4547 | skip = true; |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4548 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4549 | else |
| 4550 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4551 | |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4552 | // HACK: Objective C formal parameters "self" and "_cmd" |
| 4553 | // are not marked as artificial in the DWARF... |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4554 | CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| 4555 | if (comp_unit) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4556 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4557 | switch (comp_unit->GetLanguage()) |
| 4558 | { |
| 4559 | case eLanguageTypeObjC: |
| 4560 | case eLanguageTypeObjC_plus_plus: |
| 4561 | if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0)) |
| 4562 | skip = true; |
| 4563 | break; |
| 4564 | default: |
| 4565 | break; |
| 4566 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4567 | } |
| 4568 | } |
| 4569 | } |
| 4570 | |
| 4571 | if (!skip) |
| 4572 | { |
| 4573 | Type *type = ResolveTypeUID(param_type_die_offset); |
| 4574 | if (type) |
| 4575 | { |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 4576 | function_param_types.push_back (type->GetClangForwardType()); |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4577 | |
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 4578 | clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name, |
| 4579 | type->GetClangForwardType(), |
| 4580 | storage); |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4581 | assert(param_var_decl); |
| 4582 | function_param_decls.push_back(param_var_decl); |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 4583 | |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 4584 | GetClangASTContext().SetMetadataAsUserID (param_var_decl, MakeUserID(die->GetOffset())); |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4585 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4586 | } |
| 4587 | } |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4588 | arg_idx++; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4589 | } |
| 4590 | break; |
| 4591 | |
| Greg Clayton | 0396975 | 2014-02-24 18:53:11 +0000 | [diff] [blame] | 4592 | case DW_TAG_unspecified_parameters: |
| 4593 | is_variadic = true; |
| 4594 | break; |
| 4595 | |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 4596 | case DW_TAG_template_type_parameter: |
| 4597 | case DW_TAG_template_value_parameter: |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 4598 | // The one caller of this was never using the template_param_infos, |
| 4599 | // and the local variable was taking up a large amount of stack space |
| 4600 | // in SymbolFileDWARF::ParseType() so this was removed. If we ever need |
| 4601 | // the template params back, we can add them back. |
| 4602 | // ParseTemplateDIE (dwarf_cu, die, template_param_infos); |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 4603 | break; |
| 4604 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4605 | default: |
| 4606 | break; |
| 4607 | } |
| 4608 | } |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4609 | return arg_idx; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4610 | } |
| 4611 | |
| 4612 | size_t |
| 4613 | SymbolFileDWARF::ParseChildEnumerators |
| 4614 | ( |
| 4615 | const SymbolContext& sc, |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 4616 | lldb_private::ClangASTType &clang_type, |
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 4617 | bool is_signed, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4618 | uint32_t enumerator_byte_size, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4619 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4620 | const DWARFDebugInfoEntry *parent_die |
| 4621 | ) |
| 4622 | { |
| 4623 | if (parent_die == NULL) |
| 4624 | return 0; |
| 4625 | |
| 4626 | size_t enumerators_added = 0; |
| 4627 | const DWARFDebugInfoEntry *die; |
| Todd Fiala | ee8bfc6 | 2014-09-11 17:29:12 +0000 | [diff] [blame] | 4628 | 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] | 4629 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4630 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 4631 | { |
| 4632 | const dw_tag_t tag = die->Tag(); |
| 4633 | if (tag == DW_TAG_enumerator) |
| 4634 | { |
| 4635 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4636 | 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] | 4637 | if (num_child_attributes > 0) |
| 4638 | { |
| 4639 | const char *name = NULL; |
| 4640 | bool got_value = false; |
| 4641 | int64_t enum_value = 0; |
| 4642 | Declaration decl; |
| 4643 | |
| 4644 | uint32_t i; |
| 4645 | for (i=0; i<num_child_attributes; ++i) |
| 4646 | { |
| 4647 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 4648 | DWARFFormValue form_value; |
| 4649 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 4650 | { |
| 4651 | switch (attr) |
| 4652 | { |
| 4653 | case DW_AT_const_value: |
| 4654 | got_value = true; |
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 4655 | if (is_signed) |
| 4656 | enum_value = form_value.Signed(); |
| 4657 | else |
| 4658 | enum_value = form_value.Unsigned(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4659 | break; |
| 4660 | |
| 4661 | case DW_AT_name: |
| 4662 | name = form_value.AsCString(&get_debug_str_data()); |
| 4663 | break; |
| 4664 | |
| 4665 | case DW_AT_description: |
| 4666 | default: |
| 4667 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 4668 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 4669 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 4670 | case DW_AT_sibling: |
| 4671 | break; |
| 4672 | } |
| 4673 | } |
| 4674 | } |
| 4675 | |
| 4676 | if (name && name[0] && got_value) |
| 4677 | { |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 4678 | clang_type.AddEnumerationValueToEnumerationType (clang_type.GetEnumerationIntegerType(), |
| 4679 | decl, |
| 4680 | name, |
| 4681 | enum_value, |
| 4682 | enumerator_byte_size * 8); |
| 4683 | ++enumerators_added; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4684 | } |
| 4685 | } |
| 4686 | } |
| 4687 | } |
| 4688 | return enumerators_added; |
| 4689 | } |
| 4690 | |
| 4691 | void |
| 4692 | SymbolFileDWARF::ParseChildArrayInfo |
| 4693 | ( |
| 4694 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4695 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4696 | const DWARFDebugInfoEntry *parent_die, |
| 4697 | int64_t& first_index, |
| 4698 | std::vector<uint64_t>& element_orders, |
| 4699 | uint32_t& byte_stride, |
| 4700 | uint32_t& bit_stride |
| 4701 | ) |
| 4702 | { |
| 4703 | if (parent_die == NULL) |
| 4704 | return; |
| 4705 | |
| 4706 | const DWARFDebugInfoEntry *die; |
| Todd Fiala | ee8bfc6 | 2014-09-11 17:29:12 +0000 | [diff] [blame] | 4707 | 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] | 4708 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 4709 | { |
| 4710 | const dw_tag_t tag = die->Tag(); |
| 4711 | switch (tag) |
| 4712 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4713 | case DW_TAG_subrange_type: |
| 4714 | { |
| 4715 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4716 | 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] | 4717 | if (num_child_attributes > 0) |
| 4718 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4719 | uint64_t num_elements = 0; |
| 4720 | uint64_t lower_bound = 0; |
| 4721 | uint64_t upper_bound = 0; |
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4722 | bool upper_bound_valid = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4723 | uint32_t i; |
| 4724 | for (i=0; i<num_child_attributes; ++i) |
| 4725 | { |
| 4726 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 4727 | DWARFFormValue form_value; |
| 4728 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 4729 | { |
| 4730 | switch (attr) |
| 4731 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4732 | case DW_AT_name: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4733 | break; |
| 4734 | |
| 4735 | case DW_AT_count: |
| 4736 | num_elements = form_value.Unsigned(); |
| 4737 | break; |
| 4738 | |
| 4739 | case DW_AT_bit_stride: |
| 4740 | bit_stride = form_value.Unsigned(); |
| 4741 | break; |
| 4742 | |
| 4743 | case DW_AT_byte_stride: |
| 4744 | byte_stride = form_value.Unsigned(); |
| 4745 | break; |
| 4746 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4747 | case DW_AT_lower_bound: |
| 4748 | lower_bound = form_value.Unsigned(); |
| 4749 | break; |
| 4750 | |
| 4751 | case DW_AT_upper_bound: |
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4752 | upper_bound_valid = true; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4753 | upper_bound = form_value.Unsigned(); |
| 4754 | break; |
| 4755 | |
| 4756 | default: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4757 | case DW_AT_abstract_origin: |
| 4758 | case DW_AT_accessibility: |
| 4759 | case DW_AT_allocated: |
| 4760 | case DW_AT_associated: |
| 4761 | case DW_AT_data_location: |
| 4762 | case DW_AT_declaration: |
| 4763 | case DW_AT_description: |
| 4764 | case DW_AT_sibling: |
| 4765 | case DW_AT_threads_scaled: |
| 4766 | case DW_AT_type: |
| 4767 | case DW_AT_visibility: |
| 4768 | break; |
| 4769 | } |
| 4770 | } |
| 4771 | } |
| 4772 | |
| Greg Clayton | e6a0779 | 2012-12-05 21:59:39 +0000 | [diff] [blame] | 4773 | if (num_elements == 0) |
| 4774 | { |
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4775 | if (upper_bound_valid && upper_bound >= lower_bound) |
| Greg Clayton | e6a0779 | 2012-12-05 21:59:39 +0000 | [diff] [blame] | 4776 | num_elements = upper_bound - lower_bound + 1; |
| 4777 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4778 | |
| Sean Callanan | ec979ba | 2012-10-22 23:56:48 +0000 | [diff] [blame] | 4779 | element_orders.push_back (num_elements); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4780 | } |
| 4781 | } |
| 4782 | break; |
| 4783 | } |
| 4784 | } |
| 4785 | } |
| 4786 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4787 | TypeSP |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4788 | SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4789 | { |
| 4790 | TypeSP type_sp; |
| 4791 | if (die != NULL) |
| 4792 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4793 | assert(dwarf_cu != NULL); |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4794 | Type *type_ptr = m_die_to_type.lookup (die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4795 | if (type_ptr == NULL) |
| 4796 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4797 | CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4798 | assert (lldb_cu); |
| 4799 | SymbolContext sc(lldb_cu); |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4800 | type_sp = ParseType(sc, dwarf_cu, die, NULL); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4801 | } |
| 4802 | else if (type_ptr != DIE_IS_BEING_PARSED) |
| 4803 | { |
| 4804 | // Grab the existing type from the master types lists |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 4805 | type_sp = type_ptr->shared_from_this(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4806 | } |
| 4807 | |
| 4808 | } |
| 4809 | return type_sp; |
| 4810 | } |
| 4811 | |
| 4812 | clang::DeclContext * |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4813 | SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4814 | { |
| 4815 | if (die_offset != DW_INVALID_OFFSET) |
| 4816 | { |
| 4817 | DWARFCompileUnitSP cu_sp; |
| 4818 | const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4819 | return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4820 | } |
| 4821 | return NULL; |
| 4822 | } |
| 4823 | |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4824 | clang::DeclContext * |
| 4825 | SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset) |
| 4826 | { |
| 4827 | if (die_offset != DW_INVALID_OFFSET) |
| 4828 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4829 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 4830 | if (debug_info) |
| 4831 | { |
| 4832 | DWARFCompileUnitSP cu_sp; |
| 4833 | const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp); |
| 4834 | if (die) |
| 4835 | return GetClangDeclContextForDIE (sc, cu_sp.get(), die); |
| 4836 | } |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4837 | } |
| 4838 | return NULL; |
| 4839 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4840 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4841 | clang::NamespaceDecl * |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4842 | SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4843 | { |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4844 | if (die && die->Tag() == DW_TAG_namespace) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4845 | { |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4846 | // See if we already parsed this namespace DIE and associated it with a |
| 4847 | // uniqued namespace declaration |
| 4848 | clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]); |
| 4849 | if (namespace_decl) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4850 | return namespace_decl; |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4851 | else |
| 4852 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4853 | const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL); |
| 4854 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL); |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4855 | namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx); |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4856 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4857 | if (log) |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4858 | { |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4859 | if (namespace_name) |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4860 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4861 | GetObjectFile()->GetModule()->LogMessage (log, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4862 | "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] | 4863 | static_cast<void*>(GetClangASTContext().getASTContext()), |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4864 | MakeUserID(die->GetOffset()), |
| 4865 | namespace_name, |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4866 | static_cast<void*>(namespace_decl), |
| 4867 | static_cast<void*>(namespace_decl->getOriginalNamespace())); |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4868 | } |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4869 | else |
| 4870 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4871 | GetObjectFile()->GetModule()->LogMessage (log, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4872 | "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] | 4873 | static_cast<void*>(GetClangASTContext().getASTContext()), |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4874 | MakeUserID(die->GetOffset()), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4875 | static_cast<void*>(namespace_decl), |
| 4876 | static_cast<void*>(namespace_decl->getOriginalNamespace())); |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4877 | } |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4878 | } |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4879 | |
| 4880 | if (namespace_decl) |
| 4881 | LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die); |
| 4882 | return namespace_decl; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4883 | } |
| 4884 | } |
| 4885 | return NULL; |
| 4886 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4887 | |
| 4888 | clang::DeclContext * |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4889 | SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4890 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4891 | clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die); |
| 4892 | if (clang_decl_ctx) |
| 4893 | return clang_decl_ctx; |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4894 | // If this DIE has a specification, or an abstract origin, then trace to those. |
| 4895 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4896 | 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] | 4897 | if (die_offset != DW_INVALID_OFFSET) |
| 4898 | return GetClangDeclContextForDIEOffset (sc, die_offset); |
| 4899 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4900 | 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] | 4901 | if (die_offset != DW_INVALID_OFFSET) |
| 4902 | return GetClangDeclContextForDIEOffset (sc, die_offset); |
| 4903 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4904 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 4905 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4906 | 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] | 4907 | // This is the DIE we want. Parse it, then query our map. |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4908 | bool assert_not_being_parsed = true; |
| 4909 | ResolveTypeUID (cu, die, assert_not_being_parsed); |
| 4910 | |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4911 | clang_decl_ctx = GetCachedClangDeclContextForDIE (die); |
| 4912 | |
| 4913 | return clang_decl_ctx; |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4914 | } |
| 4915 | |
| 4916 | clang::DeclContext * |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4917 | 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] | 4918 | { |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4919 | if (m_clang_tu_decl == NULL) |
| 4920 | m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4921 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4922 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4923 | |
| 4924 | if (decl_ctx_die_copy) |
| 4925 | *decl_ctx_die_copy = decl_ctx_die; |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4926 | |
| 4927 | if (decl_ctx_die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4928 | { |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4929 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4930 | DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die); |
| 4931 | if (pos != m_die_to_decl_ctx.end()) |
| 4932 | return pos->second; |
| 4933 | |
| 4934 | switch (decl_ctx_die->Tag()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4935 | { |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4936 | case DW_TAG_compile_unit: |
| 4937 | return m_clang_tu_decl; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4938 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4939 | case DW_TAG_namespace: |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4940 | return ResolveNamespaceDIE (cu, decl_ctx_die); |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4941 | break; |
| 4942 | |
| 4943 | case DW_TAG_structure_type: |
| 4944 | case DW_TAG_union_type: |
| 4945 | case DW_TAG_class_type: |
| 4946 | { |
| 4947 | Type* type = ResolveType (cu, decl_ctx_die); |
| 4948 | if (type) |
| 4949 | { |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 4950 | clang::DeclContext *decl_ctx = type->GetClangForwardType().GetDeclContextForType (); |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4951 | if (decl_ctx) |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4952 | { |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4953 | LinkDeclContextToDIE (decl_ctx, decl_ctx_die); |
| 4954 | if (decl_ctx) |
| 4955 | return decl_ctx; |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4956 | } |
| 4957 | } |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4958 | } |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4959 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4960 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4961 | default: |
| 4962 | break; |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4963 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4964 | } |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 4965 | return m_clang_tu_decl; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4966 | } |
| 4967 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4968 | |
| 4969 | const DWARFDebugInfoEntry * |
| 4970 | SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) |
| 4971 | { |
| 4972 | if (cu && die) |
| 4973 | { |
| 4974 | const DWARFDebugInfoEntry * const decl_die = die; |
| 4975 | |
| 4976 | while (die != NULL) |
| 4977 | { |
| 4978 | // If this is the original DIE that we are searching for a declaration |
| 4979 | // for, then don't look in the cache as we don't want our own decl |
| 4980 | // context to be our decl context... |
| 4981 | if (decl_die != die) |
| 4982 | { |
| 4983 | switch (die->Tag()) |
| 4984 | { |
| 4985 | case DW_TAG_compile_unit: |
| 4986 | case DW_TAG_namespace: |
| 4987 | case DW_TAG_structure_type: |
| 4988 | case DW_TAG_union_type: |
| 4989 | case DW_TAG_class_type: |
| 4990 | return die; |
| 4991 | |
| 4992 | default: |
| 4993 | break; |
| 4994 | } |
| 4995 | } |
| 4996 | |
| 4997 | dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET); |
| 4998 | if (die_offset != DW_INVALID_OFFSET) |
| 4999 | { |
| 5000 | DWARFCompileUnit *spec_cu = cu; |
| 5001 | const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu); |
| 5002 | const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die); |
| 5003 | if (spec_die_decl_ctx_die) |
| 5004 | return spec_die_decl_ctx_die; |
| 5005 | } |
| 5006 | |
| 5007 | die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET); |
| 5008 | if (die_offset != DW_INVALID_OFFSET) |
| 5009 | { |
| 5010 | DWARFCompileUnit *abs_cu = cu; |
| 5011 | const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu); |
| 5012 | const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die); |
| 5013 | if (abs_die_decl_ctx_die) |
| 5014 | return abs_die_decl_ctx_die; |
| 5015 | } |
| 5016 | |
| 5017 | die = die->GetParent(); |
| 5018 | } |
| 5019 | } |
| 5020 | return NULL; |
| 5021 | } |
| 5022 | |
| 5023 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5024 | Symbol * |
| 5025 | SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name) |
| 5026 | { |
| 5027 | Symbol *objc_class_symbol = NULL; |
| 5028 | if (m_obj_file) |
| 5029 | { |
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 5030 | Symtab *symtab = m_obj_file->GetSymtab (); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5031 | if (symtab) |
| 5032 | { |
| 5033 | objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name, |
| 5034 | eSymbolTypeObjCClass, |
| 5035 | Symtab::eDebugNo, |
| 5036 | Symtab::eVisibilityAny); |
| 5037 | } |
| 5038 | } |
| 5039 | return objc_class_symbol; |
| 5040 | } |
| 5041 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5042 | // Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't |
| 5043 | // then we can end up looking through all class types for a complete type and never find |
| 5044 | // the full definition. We need to know if this attribute is supported, so we determine |
| 5045 | // this here and cache th result. We also need to worry about the debug map DWARF file |
| 5046 | // if we are doing darwin DWARF in .o file debugging. |
| 5047 | bool |
| 5048 | SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu) |
| 5049 | { |
| 5050 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate) |
| 5051 | { |
| 5052 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo; |
| 5053 | if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type()) |
| 5054 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; |
| 5055 | else |
| 5056 | { |
| 5057 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 5058 | const uint32_t num_compile_units = GetNumCompileUnits(); |
| 5059 | for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) |
| 5060 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 5061 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); |
| 5062 | 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] | 5063 | { |
| 5064 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; |
| 5065 | break; |
| 5066 | } |
| 5067 | } |
| 5068 | } |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 5069 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ()) |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5070 | return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this); |
| 5071 | } |
| 5072 | return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes; |
| 5073 | } |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5074 | |
| 5075 | // This function can be used when a DIE is found that is a forward declaration |
| 5076 | // DIE and we want to try and find a type that has the complete definition. |
| 5077 | TypeSP |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5078 | SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die, |
| 5079 | const ConstString &type_name, |
| 5080 | bool must_be_implementation) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5081 | { |
| 5082 | |
| 5083 | TypeSP type_sp; |
| 5084 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5085 | if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name))) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5086 | return type_sp; |
| 5087 | |
| 5088 | DIEArray die_offsets; |
| 5089 | |
| 5090 | if (m_using_apple_tables) |
| 5091 | { |
| 5092 | if (m_apple_types_ap.get()) |
| 5093 | { |
| 5094 | const char *name_cstr = type_name.GetCString(); |
| Greg Clayton | 68221ec | 2012-01-18 20:58:12 +0000 | [diff] [blame] | 5095 | m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5096 | } |
| 5097 | } |
| 5098 | else |
| 5099 | { |
| 5100 | if (!m_indexed) |
| 5101 | Index (); |
| 5102 | |
| 5103 | m_type_index.Find (type_name, die_offsets); |
| 5104 | } |
| 5105 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5106 | const size_t num_matches = die_offsets.size(); |
| 5107 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5108 | DWARFCompileUnit* type_cu = NULL; |
| 5109 | const DWARFDebugInfoEntry* type_die = NULL; |
| 5110 | if (num_matches) |
| 5111 | { |
| 5112 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 5113 | for (size_t i=0; i<num_matches; ++i) |
| 5114 | { |
| 5115 | const dw_offset_t die_offset = die_offsets[i]; |
| 5116 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); |
| 5117 | |
| 5118 | if (type_die) |
| 5119 | { |
| 5120 | bool try_resolving_type = false; |
| 5121 | |
| 5122 | // Don't try and resolve the DIE we are looking for with the DIE itself! |
| 5123 | if (type_die != die) |
| 5124 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5125 | switch (type_die->Tag()) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5126 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5127 | case DW_TAG_class_type: |
| 5128 | case DW_TAG_structure_type: |
| 5129 | try_resolving_type = true; |
| 5130 | break; |
| 5131 | default: |
| 5132 | break; |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5133 | } |
| 5134 | } |
| 5135 | |
| 5136 | if (try_resolving_type) |
| 5137 | { |
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 5138 | if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type()) |
| 5139 | 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] | 5140 | |
| 5141 | if (try_resolving_type) |
| 5142 | { |
| 5143 | Type *resolved_type = ResolveType (type_cu, type_die, false); |
| 5144 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) |
| 5145 | { |
| Ed Maste | a0191d1 | 2013-10-17 20:42:56 +0000 | [diff] [blame] | 5146 | 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] | 5147 | MakeUserID(die->GetOffset()), |
| Jim Ingham | 4af5961 | 2014-12-19 19:20:44 +0000 | [diff] [blame] | 5148 | m_obj_file->GetFileSpec().GetFilename().AsCString("<Unknown>"), |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5149 | MakeUserID(type_die->GetOffset()), |
| 5150 | MakeUserID(type_cu->GetOffset())); |
| 5151 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5152 | if (die) |
| 5153 | m_die_to_type[die] = resolved_type; |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 5154 | type_sp = resolved_type->shared_from_this(); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5155 | break; |
| 5156 | } |
| 5157 | } |
| 5158 | } |
| 5159 | } |
| 5160 | else |
| 5161 | { |
| 5162 | if (m_using_apple_tables) |
| 5163 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5164 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 5165 | die_offset, type_name.GetCString()); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5166 | } |
| 5167 | } |
| 5168 | |
| 5169 | } |
| 5170 | } |
| 5171 | return type_sp; |
| 5172 | } |
| 5173 | |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5174 | |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5175 | //---------------------------------------------------------------------- |
| 5176 | // This function helps to ensure that the declaration contexts match for |
| 5177 | // two different DIEs. Often times debug information will refer to a |
| 5178 | // forward declaration of a type (the equivalent of "struct my_struct;". |
| 5179 | // There will often be a declaration of that type elsewhere that has the |
| 5180 | // full definition. When we go looking for the full type "my_struct", we |
| 5181 | // will find one or more matches in the accelerator tables and we will |
| 5182 | // then need to make sure the type was in the same declaration context |
| 5183 | // as the original DIE. This function can efficiently compare two DIEs |
| 5184 | // and will return true when the declaration context matches, and false |
| 5185 | // when they don't. |
| 5186 | //---------------------------------------------------------------------- |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5187 | bool |
| 5188 | SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1, |
| 5189 | DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2) |
| 5190 | { |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5191 | if (die1 == die2) |
| 5192 | return true; |
| 5193 | |
| 5194 | #if defined (LLDB_CONFIGURATION_DEBUG) |
| 5195 | // You can't and shouldn't call this function with a compile unit from |
| 5196 | // two different SymbolFileDWARF instances. |
| 5197 | assert (DebugInfo()->ContainsCompileUnit (cu1)); |
| 5198 | assert (DebugInfo()->ContainsCompileUnit (cu2)); |
| 5199 | #endif |
| 5200 | |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5201 | DWARFDIECollection decl_ctx_1; |
| 5202 | DWARFDIECollection decl_ctx_2; |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5203 | //The declaration DIE stack is a stack of the declaration context |
| 5204 | // DIEs all the way back to the compile unit. If a type "T" is |
| 5205 | // declared inside a class "B", and class "B" is declared inside |
| 5206 | // a class "A" and class "A" is in a namespace "lldb", and the |
| 5207 | // namespace is in a compile unit, there will be a stack of DIEs: |
| 5208 | // |
| 5209 | // [0] DW_TAG_class_type for "B" |
| 5210 | // [1] DW_TAG_class_type for "A" |
| 5211 | // [2] DW_TAG_namespace for "lldb" |
| 5212 | // [3] DW_TAG_compile_unit for the source file. |
| 5213 | // |
| 5214 | // We grab both contexts and make sure that everything matches |
| 5215 | // all the way back to the compiler unit. |
| 5216 | |
| 5217 | // First lets grab the decl contexts for both DIEs |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5218 | die1->GetDeclContextDIEs (this, cu1, decl_ctx_1); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5219 | die2->GetDeclContextDIEs (this, cu2, decl_ctx_2); |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5220 | // Make sure the context arrays have the same size, otherwise |
| 5221 | // we are done |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5222 | const size_t count1 = decl_ctx_1.Size(); |
| 5223 | const size_t count2 = decl_ctx_2.Size(); |
| 5224 | if (count1 != count2) |
| 5225 | return false; |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5226 | |
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 5227 | // 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] | 5228 | // compile unit. If they don't, then we are done. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5229 | const DWARFDebugInfoEntry *decl_ctx_die1; |
| 5230 | const DWARFDebugInfoEntry *decl_ctx_die2; |
| 5231 | size_t i; |
| 5232 | for (i=0; i<count1; i++) |
| 5233 | { |
| 5234 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); |
| 5235 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); |
| 5236 | if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag()) |
| 5237 | return false; |
| 5238 | } |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5239 | #if defined LLDB_CONFIGURATION_DEBUG |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5240 | |
| 5241 | // Make sure the top item in the decl context die array is always |
| 5242 | // DW_TAG_compile_unit. If it isn't then something went wrong in |
| 5243 | // the DWARFDebugInfoEntry::GetDeclContextDIEs() function... |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5244 | assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit); |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5245 | |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5246 | #endif |
| 5247 | // Always skip the compile unit when comparing by only iterating up to |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5248 | // "count - 1". Here we compare the names as we go. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5249 | for (i=0; i<count1 - 1; i++) |
| 5250 | { |
| 5251 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); |
| 5252 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); |
| 5253 | const char *name1 = decl_ctx_die1->GetName(this, cu1); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5254 | const char *name2 = decl_ctx_die2->GetName(this, cu2); |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5255 | // If the string was from a DW_FORM_strp, then the pointer will often |
| 5256 | // be the same! |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 5257 | if (name1 == name2) |
| 5258 | continue; |
| 5259 | |
| 5260 | // Name pointers are not equal, so only compare the strings |
| 5261 | // if both are not NULL. |
| 5262 | if (name1 && name2) |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5263 | { |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 5264 | // If the strings don't compare, we are done... |
| 5265 | if (strcmp(name1, name2) != 0) |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5266 | return false; |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 5267 | } |
| 5268 | else |
| 5269 | { |
| 5270 | // One name was NULL while the other wasn't |
| 5271 | return false; |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5272 | } |
| 5273 | } |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5274 | // We made it through all of the checks and the declaration contexts |
| 5275 | // are equal. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5276 | return true; |
| 5277 | } |
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 5278 | |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 5279 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5280 | TypeSP |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5281 | SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx) |
| 5282 | { |
| 5283 | TypeSP type_sp; |
| 5284 | |
| 5285 | const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize(); |
| 5286 | if (dwarf_decl_ctx_count > 0) |
| 5287 | { |
| 5288 | const ConstString type_name(dwarf_decl_ctx[0].name); |
| 5289 | const dw_tag_t tag = dwarf_decl_ctx[0].tag; |
| 5290 | |
| 5291 | if (type_name) |
| 5292 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5293 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS)); |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5294 | if (log) |
| 5295 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5296 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5297 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')", |
| 5298 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), |
| 5299 | dwarf_decl_ctx.GetQualifiedName()); |
| 5300 | } |
| 5301 | |
| 5302 | DIEArray die_offsets; |
| 5303 | |
| 5304 | if (m_using_apple_tables) |
| 5305 | { |
| 5306 | if (m_apple_types_ap.get()) |
| 5307 | { |
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 5308 | const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag); |
| 5309 | const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash); |
| 5310 | if (has_tag && has_qualified_name_hash) |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5311 | { |
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 5312 | const char *qualified_name = dwarf_decl_ctx.GetQualifiedName(); |
| 5313 | const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name); |
| 5314 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5315 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()"); |
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 5316 | m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets); |
| 5317 | } |
| 5318 | else if (has_tag) |
| 5319 | { |
| 5320 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5321 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()"); |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5322 | m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets); |
| 5323 | } |
| 5324 | else |
| 5325 | { |
| 5326 | m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets); |
| 5327 | } |
| 5328 | } |
| 5329 | } |
| 5330 | else |
| 5331 | { |
| 5332 | if (!m_indexed) |
| 5333 | Index (); |
| 5334 | |
| 5335 | m_type_index.Find (type_name, die_offsets); |
| 5336 | } |
| 5337 | |
| 5338 | const size_t num_matches = die_offsets.size(); |
| 5339 | |
| 5340 | |
| 5341 | DWARFCompileUnit* type_cu = NULL; |
| 5342 | const DWARFDebugInfoEntry* type_die = NULL; |
| 5343 | if (num_matches) |
| 5344 | { |
| 5345 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 5346 | for (size_t i=0; i<num_matches; ++i) |
| 5347 | { |
| 5348 | const dw_offset_t die_offset = die_offsets[i]; |
| 5349 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); |
| 5350 | |
| 5351 | if (type_die) |
| 5352 | { |
| 5353 | bool try_resolving_type = false; |
| 5354 | |
| 5355 | // Don't try and resolve the DIE we are looking for with the DIE itself! |
| 5356 | const dw_tag_t type_tag = type_die->Tag(); |
| 5357 | // Make sure the tags match |
| 5358 | if (type_tag == tag) |
| 5359 | { |
| 5360 | // The tags match, lets try resolving this type |
| 5361 | try_resolving_type = true; |
| 5362 | } |
| 5363 | else |
| 5364 | { |
| 5365 | // The tags don't match, but we need to watch our for a |
| 5366 | // forward declaration for a struct and ("struct foo") |
| 5367 | // ends up being a class ("class foo { ... };") or |
| 5368 | // vice versa. |
| 5369 | switch (type_tag) |
| 5370 | { |
| 5371 | case DW_TAG_class_type: |
| 5372 | // We had a "class foo", see if we ended up with a "struct foo { ... };" |
| 5373 | try_resolving_type = (tag == DW_TAG_structure_type); |
| 5374 | break; |
| 5375 | case DW_TAG_structure_type: |
| 5376 | // We had a "struct foo", see if we ended up with a "class foo { ... };" |
| 5377 | try_resolving_type = (tag == DW_TAG_class_type); |
| 5378 | break; |
| 5379 | default: |
| 5380 | // Tags don't match, don't event try to resolve |
| 5381 | // using this type whose name matches.... |
| 5382 | break; |
| 5383 | } |
| 5384 | } |
| 5385 | |
| 5386 | if (try_resolving_type) |
| 5387 | { |
| 5388 | DWARFDeclContext type_dwarf_decl_ctx; |
| 5389 | type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx); |
| 5390 | |
| 5391 | if (log) |
| 5392 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5393 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5394 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)", |
| 5395 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), |
| 5396 | dwarf_decl_ctx.GetQualifiedName(), |
| 5397 | type_die->GetOffset(), |
| 5398 | type_dwarf_decl_ctx.GetQualifiedName()); |
| 5399 | } |
| 5400 | |
| 5401 | // Make sure the decl contexts match all the way up |
| 5402 | if (dwarf_decl_ctx == type_dwarf_decl_ctx) |
| 5403 | { |
| 5404 | Type *resolved_type = ResolveType (type_cu, type_die, false); |
| 5405 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) |
| 5406 | { |
| 5407 | type_sp = resolved_type->shared_from_this(); |
| 5408 | break; |
| 5409 | } |
| 5410 | } |
| 5411 | } |
| 5412 | else |
| 5413 | { |
| 5414 | if (log) |
| 5415 | { |
| 5416 | std::string qualified_name; |
| 5417 | type_die->GetQualifiedName(this, type_cu, qualified_name); |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5418 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5419 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)", |
| 5420 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), |
| 5421 | dwarf_decl_ctx.GetQualifiedName(), |
| 5422 | type_die->GetOffset(), |
| 5423 | qualified_name.c_str()); |
| 5424 | } |
| 5425 | } |
| 5426 | } |
| 5427 | else |
| 5428 | { |
| 5429 | if (m_using_apple_tables) |
| 5430 | { |
| 5431 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 5432 | die_offset, type_name.GetCString()); |
| 5433 | } |
| 5434 | } |
| 5435 | |
| 5436 | } |
| 5437 | } |
| 5438 | } |
| 5439 | } |
| 5440 | return type_sp; |
| 5441 | } |
| 5442 | |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5443 | bool |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5444 | SymbolFileDWARF::CopyUniqueClassMethodTypes (SymbolFileDWARF *src_symfile, |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5445 | Type *class_type, |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5446 | DWARFCompileUnit* src_cu, |
| 5447 | const DWARFDebugInfoEntry *src_class_die, |
| 5448 | DWARFCompileUnit* dst_cu, |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5449 | const DWARFDebugInfoEntry *dst_class_die, |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 5450 | DWARFDIECollection &failures) |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5451 | { |
| 5452 | if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die) |
| 5453 | return false; |
| 5454 | if (src_class_die->Tag() != dst_class_die->Tag()) |
| 5455 | return false; |
| 5456 | |
| 5457 | // We need to complete the class type so we can get all of the method types |
| 5458 | // parsed so we can then unique those types to their equivalent counterparts |
| 5459 | // in "dst_cu" and "dst_class_die" |
| 5460 | class_type->GetClangFullType(); |
| 5461 | |
| 5462 | const DWARFDebugInfoEntry *src_die; |
| 5463 | const DWARFDebugInfoEntry *dst_die; |
| 5464 | UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die; |
| 5465 | UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die; |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5466 | UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die_artificial; |
| 5467 | UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die_artificial; |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5468 | for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling()) |
| 5469 | { |
| 5470 | if (src_die->Tag() == DW_TAG_subprogram) |
| 5471 | { |
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5472 | // Make sure this is a declaration and not a concrete instance by looking |
| 5473 | // for DW_AT_declaration set to 1. Sometimes concrete function instances |
| 5474 | // are placed inside the class definitions and shouldn't be included in |
| 5475 | // the list of things are are tracking here. |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5476 | 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] | 5477 | { |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5478 | const char *src_name = src_die->GetMangledName (src_symfile, src_cu); |
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5479 | if (src_name) |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5480 | { |
| 5481 | ConstString src_const_name(src_name); |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5482 | if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_artificial, 0)) |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5483 | src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die); |
| 5484 | else |
| 5485 | src_name_to_die.Append(src_const_name.GetCString(), src_die); |
| 5486 | } |
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5487 | } |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5488 | } |
| 5489 | } |
| 5490 | for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling()) |
| 5491 | { |
| 5492 | if (dst_die->Tag() == DW_TAG_subprogram) |
| 5493 | { |
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5494 | // Make sure this is a declaration and not a concrete instance by looking |
| 5495 | // for DW_AT_declaration set to 1. Sometimes concrete function instances |
| 5496 | // are placed inside the class definitions and shouldn't be included in |
| 5497 | // the list of things are are tracking here. |
| 5498 | if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_declaration, 0) == 1) |
| 5499 | { |
| 5500 | const char *dst_name = dst_die->GetMangledName (this, dst_cu); |
| 5501 | if (dst_name) |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5502 | { |
| 5503 | ConstString dst_const_name(dst_name); |
| 5504 | if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_artificial, 0)) |
| 5505 | dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die); |
| 5506 | else |
| 5507 | dst_name_to_die.Append(dst_const_name.GetCString(), dst_die); |
| 5508 | } |
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5509 | } |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5510 | } |
| 5511 | } |
| 5512 | const uint32_t src_size = src_name_to_die.GetSize (); |
| 5513 | const uint32_t dst_size = dst_name_to_die.GetSize (); |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5514 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION)); |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5515 | |
| 5516 | // Is everything kosher so we can go through the members at top speed? |
| 5517 | bool fast_path = true; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5518 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5519 | if (src_size != dst_size) |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5520 | { |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5521 | if (src_size != 0 && dst_size != 0) |
| 5522 | { |
| 5523 | if (log) |
| 5524 | 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)", |
| 5525 | src_class_die->GetOffset(), |
| 5526 | dst_class_die->GetOffset(), |
| 5527 | src_size, |
| 5528 | dst_size); |
| 5529 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5530 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5531 | fast_path = false; |
| 5532 | } |
| 5533 | |
| 5534 | uint32_t idx; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5535 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5536 | if (fast_path) |
| 5537 | { |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5538 | for (idx = 0; idx < src_size; ++idx) |
| 5539 | { |
| 5540 | src_die = src_name_to_die.GetValueAtIndexUnchecked (idx); |
| 5541 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx); |
| 5542 | |
| 5543 | if (src_die->Tag() != dst_die->Tag()) |
| 5544 | { |
| 5545 | if (log) |
| 5546 | 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)", |
| 5547 | src_class_die->GetOffset(), |
| 5548 | dst_class_die->GetOffset(), |
| 5549 | src_die->GetOffset(), |
| 5550 | DW_TAG_value_to_name(src_die->Tag()), |
| 5551 | dst_die->GetOffset(), |
| 5552 | DW_TAG_value_to_name(src_die->Tag())); |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5553 | fast_path = false; |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5554 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5555 | |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5556 | const char *src_name = src_die->GetMangledName (src_symfile, src_cu); |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5557 | const char *dst_name = dst_die->GetMangledName (this, dst_cu); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5558 | |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5559 | // Make sure the names match |
| 5560 | if (src_name == dst_name || (strcmp (src_name, dst_name) == 0)) |
| 5561 | continue; |
| 5562 | |
| 5563 | if (log) |
| 5564 | 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)", |
| 5565 | src_class_die->GetOffset(), |
| 5566 | dst_class_die->GetOffset(), |
| 5567 | src_die->GetOffset(), |
| 5568 | src_name, |
| 5569 | dst_die->GetOffset(), |
| 5570 | dst_name); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5571 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5572 | fast_path = false; |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5573 | } |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5574 | } |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5575 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5576 | // Now do the work of linking the DeclContexts and Types. |
| 5577 | if (fast_path) |
| 5578 | { |
| 5579 | // We can do this quickly. Just run across the tables index-for-index since |
| 5580 | // we know each node has matching names and tags. |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5581 | for (idx = 0; idx < src_size; ++idx) |
| 5582 | { |
| 5583 | src_die = src_name_to_die.GetValueAtIndexUnchecked (idx); |
| 5584 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5585 | |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5586 | 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] | 5587 | if (src_decl_ctx) |
| 5588 | { |
| 5589 | if (log) |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5590 | log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", |
| 5591 | static_cast<void*>(src_decl_ctx), |
| 5592 | src_die->GetOffset(), dst_die->GetOffset()); |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5593 | LinkDeclContextToDIE (src_decl_ctx, dst_die); |
| 5594 | } |
| 5595 | else |
| 5596 | { |
| 5597 | if (log) |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5598 | log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found", |
| 5599 | src_die->GetOffset(), dst_die->GetOffset()); |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5600 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5601 | |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5602 | Type *src_child_type = m_die_to_type[src_die]; |
| 5603 | if (src_child_type) |
| 5604 | { |
| 5605 | if (log) |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5606 | log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", |
| 5607 | static_cast<void*>(src_child_type), |
| 5608 | src_child_type->GetID(), |
| 5609 | src_die->GetOffset(), dst_die->GetOffset()); |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5610 | m_die_to_type[dst_die] = src_child_type; |
| 5611 | } |
| 5612 | else |
| 5613 | { |
| 5614 | if (log) |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5615 | 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()); |
| 5616 | } |
| 5617 | } |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5618 | } |
| 5619 | else |
| 5620 | { |
| 5621 | // We must do this slowly. For each member of the destination, look |
| 5622 | // up a member in the source with the same name, check its tag, and |
| 5623 | // unique them if everything matches up. Report failures. |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5624 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5625 | if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty()) |
| 5626 | { |
| 5627 | src_name_to_die.Sort(); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5628 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5629 | for (idx = 0; idx < dst_size; ++idx) |
| 5630 | { |
| 5631 | const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx); |
| 5632 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx); |
| 5633 | src_die = src_name_to_die.Find(dst_name, NULL); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5634 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5635 | if (src_die && (src_die->Tag() == dst_die->Tag())) |
| 5636 | { |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5637 | 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] | 5638 | if (src_decl_ctx) |
| 5639 | { |
| 5640 | if (log) |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5641 | log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", |
| 5642 | static_cast<void*>(src_decl_ctx), |
| 5643 | src_die->GetOffset(), |
| 5644 | dst_die->GetOffset()); |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5645 | LinkDeclContextToDIE (src_decl_ctx, dst_die); |
| 5646 | } |
| 5647 | else |
| 5648 | { |
| 5649 | if (log) |
| 5650 | 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()); |
| 5651 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5652 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5653 | Type *src_child_type = m_die_to_type[src_die]; |
| 5654 | if (src_child_type) |
| 5655 | { |
| 5656 | if (log) |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5657 | log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", |
| 5658 | static_cast<void*>(src_child_type), |
| 5659 | src_child_type->GetID(), |
| 5660 | src_die->GetOffset(), |
| 5661 | dst_die->GetOffset()); |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5662 | m_die_to_type[dst_die] = src_child_type; |
| 5663 | } |
| 5664 | else |
| 5665 | { |
| 5666 | if (log) |
| 5667 | 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()); |
| 5668 | } |
| 5669 | } |
| 5670 | else |
| 5671 | { |
| 5672 | if (log) |
| 5673 | 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] | 5674 | |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 5675 | failures.Append(dst_die); |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5676 | } |
| 5677 | } |
| 5678 | } |
| 5679 | } |
| 5680 | |
| 5681 | const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize (); |
| 5682 | const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize (); |
| 5683 | |
| 5684 | UniqueCStringMap<const DWARFDebugInfoEntry *> name_to_die_artificial_not_in_src; |
| 5685 | |
| 5686 | if (src_size_artificial && dst_size_artificial) |
| 5687 | { |
| 5688 | dst_name_to_die_artificial.Sort(); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5689 | |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5690 | for (idx = 0; idx < src_size_artificial; ++idx) |
| 5691 | { |
| 5692 | const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx); |
| 5693 | src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx); |
| 5694 | dst_die = dst_name_to_die_artificial.Find(src_name_artificial, NULL); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5695 | |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5696 | if (dst_die) |
| 5697 | { |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5698 | // Both classes have the artificial types, link them |
| 5699 | clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die]; |
| 5700 | if (src_decl_ctx) |
| 5701 | { |
| 5702 | if (log) |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5703 | log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", |
| 5704 | static_cast<void*>(src_decl_ctx), |
| 5705 | src_die->GetOffset(), dst_die->GetOffset()); |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5706 | LinkDeclContextToDIE (src_decl_ctx, dst_die); |
| 5707 | } |
| 5708 | else |
| 5709 | { |
| 5710 | if (log) |
| 5711 | 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()); |
| 5712 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5713 | |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5714 | Type *src_child_type = m_die_to_type[src_die]; |
| 5715 | if (src_child_type) |
| 5716 | { |
| 5717 | if (log) |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5718 | log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", |
| 5719 | static_cast<void*>(src_child_type), |
| 5720 | src_child_type->GetID(), |
| 5721 | src_die->GetOffset(), dst_die->GetOffset()); |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5722 | m_die_to_type[dst_die] = src_child_type; |
| 5723 | } |
| 5724 | else |
| 5725 | { |
| 5726 | if (log) |
| 5727 | 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()); |
| 5728 | } |
| 5729 | } |
| 5730 | } |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5731 | } |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5732 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5733 | if (dst_size_artificial) |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5734 | { |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5735 | for (idx = 0; idx < dst_size_artificial; ++idx) |
| 5736 | { |
| 5737 | const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx); |
| 5738 | dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx); |
| 5739 | if (log) |
| 5740 | log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die->GetOffset(), dst_name_artificial); |
| 5741 | |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 5742 | failures.Append(dst_die); |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5743 | } |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5744 | } |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5745 | |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 5746 | return (failures.Size() != 0); |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5747 | } |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5748 | |
| 5749 | TypeSP |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5750 | 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] | 5751 | { |
| 5752 | TypeSP type_sp; |
| 5753 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5754 | if (type_is_new_ptr) |
| 5755 | *type_is_new_ptr = false; |
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5756 | |
| Todd Fiala | 0a70a84 | 2014-05-28 16:43:26 +0000 | [diff] [blame] | 5757 | #if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE) |
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5758 | static DIEStack g_die_stack; |
| 5759 | DIEStack::ScopedPopper scoped_die_logger(g_die_stack); |
| 5760 | #endif |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5761 | |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 5762 | AccessType accessibility = eAccessNone; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5763 | if (die != NULL) |
| 5764 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5765 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5766 | if (log) |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5767 | { |
| 5768 | const DWARFDebugInfoEntry *context_die; |
| 5769 | clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5770 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5771 | 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] | 5772 | die->GetOffset(), |
| 5773 | static_cast<void*>(context), |
| 5774 | context_die->GetOffset(), |
| 5775 | DW_TAG_value_to_name(die->Tag()), |
| 5776 | die->GetName(this, dwarf_cu)); |
| 5777 | |
| Todd Fiala | 0a70a84 | 2014-05-28 16:43:26 +0000 | [diff] [blame] | 5778 | #if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE) |
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5779 | scoped_die_logger.Push (dwarf_cu, die); |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5780 | g_die_stack.LogDIEs(log, this); |
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5781 | #endif |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5782 | } |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5783 | // |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5784 | // Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5785 | // if (log && dwarf_cu) |
| 5786 | // { |
| 5787 | // StreamString s; |
| 5788 | // die->DumpLocation (this, dwarf_cu, s); |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5789 | // GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData()); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5790 | // |
| 5791 | // } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5792 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5793 | Type *type_ptr = m_die_to_type.lookup (die); |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5794 | TypeList* type_list = GetTypeList(); |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5795 | if (type_ptr == NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5796 | { |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5797 | ClangASTContext &ast = GetClangASTContext(); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5798 | if (type_is_new_ptr) |
| 5799 | *type_is_new_ptr = true; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5800 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5801 | const dw_tag_t tag = die->Tag(); |
| 5802 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5803 | bool is_forward_declaration = false; |
| 5804 | DWARFDebugInfoEntry::Attributes attributes; |
| 5805 | const char *type_name_cstr = NULL; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5806 | ConstString type_name_const_str; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5807 | Type::ResolveState resolve_state = Type::eResolveStateUnresolved; |
| Greg Clayton | faac111 | 2013-03-14 18:31:44 +0000 | [diff] [blame] | 5808 | uint64_t byte_size = 0; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5809 | Declaration decl; |
| 5810 | |
| Greg Clayton | 4957bf6 | 2010-09-30 21:49:03 +0000 | [diff] [blame] | 5811 | Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID; |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5812 | ClangASTType clang_type; |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 5813 | DWARFFormValue form_value; |
| 5814 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5815 | dw_attr_t attr; |
| 5816 | |
| 5817 | switch (tag) |
| 5818 | { |
| 5819 | case DW_TAG_base_type: |
| 5820 | case DW_TAG_pointer_type: |
| 5821 | case DW_TAG_reference_type: |
| Sean Callanan | ce8af86 | 2012-05-21 23:31:51 +0000 | [diff] [blame] | 5822 | case DW_TAG_rvalue_reference_type: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5823 | case DW_TAG_typedef: |
| 5824 | case DW_TAG_const_type: |
| 5825 | case DW_TAG_restrict_type: |
| 5826 | case DW_TAG_volatile_type: |
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5827 | case DW_TAG_unspecified_type: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5828 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5829 | // 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] | 5830 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5831 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5832 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5833 | uint32_t encoding = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5834 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; |
| 5835 | |
| 5836 | if (num_attributes > 0) |
| 5837 | { |
| 5838 | uint32_t i; |
| 5839 | for (i=0; i<num_attributes; ++i) |
| 5840 | { |
| 5841 | attr = attributes.AttributeAtIndex(i); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5842 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 5843 | { |
| 5844 | switch (attr) |
| 5845 | { |
| 5846 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 5847 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 5848 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 5849 | case DW_AT_name: |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5850 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5851 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Jim Ingham | 337030f | 2011-04-15 23:41:23 +0000 | [diff] [blame] | 5852 | // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't |
| 5853 | // include the "&"... |
| 5854 | if (tag == DW_TAG_reference_type) |
| 5855 | { |
| 5856 | if (strchr (type_name_cstr, '&') == NULL) |
| 5857 | type_name_cstr = NULL; |
| 5858 | } |
| 5859 | if (type_name_cstr) |
| 5860 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5861 | break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 5862 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5863 | case DW_AT_encoding: encoding = form_value.Unsigned(); break; |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 5864 | case DW_AT_type: encoding_uid = form_value.Reference(); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5865 | default: |
| 5866 | case DW_AT_sibling: |
| 5867 | break; |
| 5868 | } |
| 5869 | } |
| 5870 | } |
| 5871 | } |
| 5872 | |
| Ed Maste | a0191d1 | 2013-10-17 20:42:56 +0000 | [diff] [blame] | 5873 | 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] | 5874 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5875 | switch (tag) |
| 5876 | { |
| 5877 | default: |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5878 | break; |
| 5879 | |
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5880 | case DW_TAG_unspecified_type: |
| Greg Clayton | 7fba263 | 2013-07-01 21:01:52 +0000 | [diff] [blame] | 5881 | if (strcmp(type_name_cstr, "nullptr_t") == 0 || |
| 5882 | strcmp(type_name_cstr, "decltype(nullptr)") == 0 ) |
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5883 | { |
| 5884 | resolve_state = Type::eResolveStateFull; |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5885 | clang_type = ast.GetBasicType(eBasicTypeNullPtr); |
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5886 | break; |
| 5887 | } |
| 5888 | // Fall through to base type below in case we can handle the type there... |
| 5889 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5890 | case DW_TAG_base_type: |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5891 | resolve_state = Type::eResolveStateFull; |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5892 | clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr, |
| 5893 | encoding, |
| 5894 | byte_size * 8); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5895 | break; |
| 5896 | |
| Sean Callanan | ce8af86 | 2012-05-21 23:31:51 +0000 | [diff] [blame] | 5897 | case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break; |
| 5898 | case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break; |
| 5899 | case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break; |
| 5900 | case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break; |
| 5901 | case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break; |
| 5902 | case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break; |
| 5903 | case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5904 | } |
| 5905 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5906 | 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] | 5907 | { |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5908 | 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] | 5909 | |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5910 | if (translation_unit_is_objc) |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 5911 | { |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5912 | if (type_name_cstr != NULL) |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5913 | { |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5914 | static ConstString g_objc_type_name_id("id"); |
| 5915 | static ConstString g_objc_type_name_Class("Class"); |
| 5916 | static ConstString g_objc_type_name_selector("SEL"); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5917 | |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5918 | if (type_name_const_str == g_objc_type_name_id) |
| 5919 | { |
| 5920 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5921 | 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] | 5922 | die->GetOffset(), |
| 5923 | DW_TAG_value_to_name(die->Tag()), |
| 5924 | die->GetName(this, dwarf_cu)); |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5925 | clang_type = ast.GetBasicType(eBasicTypeObjCID); |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5926 | encoding_data_type = Type::eEncodingIsUID; |
| 5927 | encoding_uid = LLDB_INVALID_UID; |
| 5928 | resolve_state = Type::eResolveStateFull; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5929 | |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5930 | } |
| 5931 | else if (type_name_const_str == g_objc_type_name_Class) |
| 5932 | { |
| 5933 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5934 | 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] | 5935 | die->GetOffset(), |
| 5936 | DW_TAG_value_to_name(die->Tag()), |
| 5937 | die->GetName(this, dwarf_cu)); |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5938 | clang_type = ast.GetBasicType(eBasicTypeObjCClass); |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5939 | encoding_data_type = Type::eEncodingIsUID; |
| 5940 | encoding_uid = LLDB_INVALID_UID; |
| 5941 | resolve_state = Type::eResolveStateFull; |
| 5942 | } |
| 5943 | else if (type_name_const_str == g_objc_type_name_selector) |
| 5944 | { |
| 5945 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5946 | 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] | 5947 | die->GetOffset(), |
| 5948 | DW_TAG_value_to_name(die->Tag()), |
| 5949 | die->GetName(this, dwarf_cu)); |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5950 | clang_type = ast.GetBasicType(eBasicTypeObjCSel); |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5951 | encoding_data_type = Type::eEncodingIsUID; |
| 5952 | encoding_uid = LLDB_INVALID_UID; |
| 5953 | resolve_state = Type::eResolveStateFull; |
| 5954 | } |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5955 | } |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5956 | else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid != LLDB_INVALID_UID) |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5957 | { |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5958 | // 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] | 5959 | |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5960 | DWARFDebugInfoEntry* encoding_die = dwarf_cu->GetDIEPtr(encoding_uid); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5961 | |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5962 | if (encoding_die && encoding_die->Tag() == DW_TAG_structure_type) |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5963 | { |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5964 | if (const char *struct_name = encoding_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL)) |
| 5965 | { |
| 5966 | if (!strcmp(struct_name, "objc_object")) |
| 5967 | { |
| 5968 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5969 | 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] | 5970 | die->GetOffset(), |
| 5971 | DW_TAG_value_to_name(die->Tag()), |
| 5972 | die->GetName(this, dwarf_cu)); |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5973 | clang_type = ast.GetBasicType(eBasicTypeObjCID); |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5974 | encoding_data_type = Type::eEncodingIsUID; |
| 5975 | encoding_uid = LLDB_INVALID_UID; |
| 5976 | resolve_state = Type::eResolveStateFull; |
| 5977 | } |
| 5978 | } |
| 5979 | } |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5980 | } |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 5981 | } |
| 5982 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5983 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5984 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5985 | this, |
| 5986 | type_name_const_str, |
| 5987 | byte_size, |
| 5988 | NULL, |
| 5989 | encoding_uid, |
| 5990 | encoding_data_type, |
| 5991 | &decl, |
| 5992 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5993 | resolve_state)); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5994 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5995 | m_die_to_type[die] = type_sp.get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5996 | |
| 5997 | // Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false); |
| 5998 | // if (encoding_type != NULL) |
| 5999 | // { |
| 6000 | // if (encoding_type != DIE_IS_BEING_PARSED) |
| 6001 | // type_sp->SetEncodingType(encoding_type); |
| 6002 | // else |
| 6003 | // m_indirect_fixups.push_back(type_sp.get()); |
| 6004 | // } |
| 6005 | } |
| 6006 | break; |
| 6007 | |
| 6008 | case DW_TAG_structure_type: |
| 6009 | case DW_TAG_union_type: |
| 6010 | case DW_TAG_class_type: |
| 6011 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6012 | // 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] | 6013 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6014 | bool byte_size_valid = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6015 | |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 6016 | LanguageType class_language = eLanguageTypeUnknown; |
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 6017 | bool is_complete_objc_class = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6018 | //bool struct_is_class = false; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6019 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6020 | if (num_attributes > 0) |
| 6021 | { |
| 6022 | uint32_t i; |
| 6023 | for (i=0; i<num_attributes; ++i) |
| 6024 | { |
| 6025 | attr = attributes.AttributeAtIndex(i); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6026 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 6027 | { |
| 6028 | switch (attr) |
| 6029 | { |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 6030 | case DW_AT_decl_file: |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6031 | if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid()) |
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 6032 | { |
| 6033 | // llvm-gcc outputs invalid DW_AT_decl_file attributes that always |
| 6034 | // point to the compile unit file, so we clear this invalid value |
| 6035 | // so that we can still unique types efficiently. |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6036 | decl.SetFile(FileSpec ("<invalid>", false)); |
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 6037 | } |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6038 | else |
| 6039 | decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 6040 | break; |
| 6041 | |
| 6042 | case DW_AT_decl_line: |
| 6043 | decl.SetLine(form_value.Unsigned()); |
| 6044 | break; |
| 6045 | |
| 6046 | case DW_AT_decl_column: |
| 6047 | decl.SetColumn(form_value.Unsigned()); |
| 6048 | break; |
| 6049 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6050 | case DW_AT_name: |
| 6051 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6052 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6053 | break; |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 6054 | |
| 6055 | case DW_AT_byte_size: |
| 6056 | byte_size = form_value.Unsigned(); |
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 6057 | byte_size_valid = true; |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 6058 | break; |
| 6059 | |
| 6060 | case DW_AT_accessibility: |
| 6061 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); |
| 6062 | break; |
| 6063 | |
| 6064 | case DW_AT_declaration: |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 6065 | is_forward_declaration = form_value.Boolean(); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 6066 | break; |
| 6067 | |
| 6068 | case DW_AT_APPLE_runtime_class: |
| 6069 | class_language = (LanguageType)form_value.Signed(); |
| 6070 | break; |
| 6071 | |
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 6072 | case DW_AT_APPLE_objc_complete_type: |
| 6073 | is_complete_objc_class = form_value.Signed(); |
| 6074 | break; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6075 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6076 | case DW_AT_allocated: |
| 6077 | case DW_AT_associated: |
| 6078 | case DW_AT_data_location: |
| 6079 | case DW_AT_description: |
| 6080 | case DW_AT_start_scope: |
| 6081 | case DW_AT_visibility: |
| 6082 | default: |
| 6083 | case DW_AT_sibling: |
| 6084 | break; |
| 6085 | } |
| 6086 | } |
| 6087 | } |
| 6088 | } |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 6089 | |
| 6090 | // UniqueDWARFASTType is large, so don't create a local variables on the |
| 6091 | // stack, put it on the heap. This function is often called recursively |
| 6092 | // and clang isn't good and sharing the stack space for variables in different blocks. |
| 6093 | std::unique_ptr<UniqueDWARFASTType> unique_ast_entry_ap(new UniqueDWARFASTType()); |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 6094 | |
| Greg Clayton | 123edca | 2012-03-02 00:07:15 +0000 | [diff] [blame] | 6095 | // Only try and unique the type if it has a name. |
| 6096 | if (type_name_const_str && |
| 6097 | GetUniqueDWARFASTTypeMap().Find (type_name_const_str, |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 6098 | this, |
| 6099 | dwarf_cu, |
| 6100 | die, |
| 6101 | decl, |
| 6102 | byte_size_valid ? byte_size : -1, |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 6103 | *unique_ast_entry_ap)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6104 | { |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 6105 | // We have already parsed this type or from another |
| 6106 | // compile unit. GCC loves to use the "one definition |
| 6107 | // rule" which can result in multiple definitions |
| 6108 | // of the same class over and over in each compile |
| 6109 | // unit. |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 6110 | type_sp = unique_ast_entry_ap->m_type_sp; |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 6111 | if (type_sp) |
| Greg Clayton | c615ce4 | 2010-11-09 04:42:43 +0000 | [diff] [blame] | 6112 | { |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 6113 | m_die_to_type[die] = type_sp.get(); |
| 6114 | return type_sp; |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 6115 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6116 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6117 | |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6118 | 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] | 6119 | |
| 6120 | int tag_decl_kind = -1; |
| 6121 | AccessType default_accessibility = eAccessNone; |
| 6122 | if (tag == DW_TAG_structure_type) |
| 6123 | { |
| 6124 | tag_decl_kind = clang::TTK_Struct; |
| 6125 | default_accessibility = eAccessPublic; |
| 6126 | } |
| 6127 | else if (tag == DW_TAG_union_type) |
| 6128 | { |
| 6129 | tag_decl_kind = clang::TTK_Union; |
| 6130 | default_accessibility = eAccessPublic; |
| 6131 | } |
| 6132 | else if (tag == DW_TAG_class_type) |
| 6133 | { |
| 6134 | tag_decl_kind = clang::TTK_Class; |
| 6135 | default_accessibility = eAccessPrivate; |
| 6136 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6137 | |
| Greg Clayton | 3a5f29a | 2011-11-30 02:48:28 +0000 | [diff] [blame] | 6138 | if (byte_size_valid && byte_size == 0 && type_name_cstr && |
| 6139 | die->HasChildren() == false && |
| 6140 | sc.comp_unit->GetLanguage() == eLanguageTypeObjC) |
| 6141 | { |
| 6142 | // Work around an issue with clang at the moment where |
| 6143 | // forward declarations for objective C classes are emitted |
| 6144 | // as: |
| 6145 | // DW_TAG_structure_type [2] |
| 6146 | // DW_AT_name( "ForwardObjcClass" ) |
| 6147 | // DW_AT_byte_size( 0x00 ) |
| 6148 | // DW_AT_decl_file( "..." ) |
| 6149 | // DW_AT_decl_line( 1 ) |
| 6150 | // |
| 6151 | // Note that there is no DW_AT_declaration and there are |
| 6152 | // no children, and the byte size is zero. |
| 6153 | is_forward_declaration = true; |
| 6154 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6155 | |
| Sean Callanan | 7457f8d | 2012-04-25 01:03:57 +0000 | [diff] [blame] | 6156 | if (class_language == eLanguageTypeObjC || |
| 6157 | class_language == eLanguageTypeObjC_plus_plus) |
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 6158 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6159 | 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] | 6160 | { |
| 6161 | // We have a valid eSymbolTypeObjCClass class symbol whose |
| 6162 | // name matches the current objective C class that we |
| 6163 | // are trying to find and this DIE isn't the complete |
| 6164 | // definition (we checked is_complete_objc_class above and |
| 6165 | // know it is false), so the real definition is in here somewhere |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6166 | type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true); |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6167 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 6168 | if (!type_sp && GetDebugMapSymfile ()) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 6169 | { |
| 6170 | // We weren't able to find a full declaration in |
| 6171 | // this DWARF, see if we have a declaration anywhere |
| 6172 | // else... |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6173 | 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] | 6174 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6175 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 6176 | if (type_sp) |
| 6177 | { |
| 6178 | if (log) |
| 6179 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 6180 | GetObjectFile()->GetModule()->LogMessage (log, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6181 | "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] | 6182 | static_cast<void*>(this), |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6183 | die->GetOffset(), |
| 6184 | DW_TAG_value_to_name(tag), |
| 6185 | type_name_cstr, |
| 6186 | type_sp->GetID()); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 6187 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6188 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 6189 | // We found a real definition for this type elsewhere |
| 6190 | // so lets use it and cache the fact that we found |
| 6191 | // a complete type for this die |
| 6192 | m_die_to_type[die] = type_sp.get(); |
| 6193 | return type_sp; |
| 6194 | } |
| 6195 | } |
| 6196 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6197 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 6198 | |
| 6199 | if (is_forward_declaration) |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6200 | { |
| 6201 | // We have a forward declaration to a type and we need |
| 6202 | // to try and find a full declaration. We look in the |
| 6203 | // current type index just in case we have a forward |
| 6204 | // declaration followed by an actual declarations in the |
| 6205 | // DWARF. If this fails, we need to look elsewhere... |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 6206 | if (log) |
| 6207 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 6208 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6209 | "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] | 6210 | static_cast<void*>(this), |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6211 | die->GetOffset(), |
| 6212 | DW_TAG_value_to_name(tag), |
| 6213 | type_name_cstr); |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 6214 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6215 | |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 6216 | DWARFDeclContext die_decl_ctx; |
| 6217 | die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx); |
| 6218 | |
| 6219 | //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str); |
| 6220 | type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6221 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 6222 | if (!type_sp && GetDebugMapSymfile ()) |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 6223 | { |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6224 | // We weren't able to find a full declaration in |
| 6225 | // this DWARF, see if we have a declaration anywhere |
| 6226 | // else... |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 6227 | type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 6228 | } |
| 6229 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6230 | if (type_sp) |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 6231 | { |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 6232 | if (log) |
| 6233 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 6234 | GetObjectFile()->GetModule()->LogMessage (log, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6235 | "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] | 6236 | static_cast<void*>(this), |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6237 | die->GetOffset(), |
| 6238 | DW_TAG_value_to_name(tag), |
| 6239 | type_name_cstr, |
| 6240 | type_sp->GetID()); |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 6241 | } |
| 6242 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6243 | // We found a real definition for this type elsewhere |
| 6244 | // so lets use it and cache the fact that we found |
| 6245 | // a complete type for this die |
| 6246 | m_die_to_type[die] = type_sp.get(); |
| 6247 | return type_sp; |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 6248 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6249 | } |
| 6250 | assert (tag_decl_kind != -1); |
| 6251 | bool clang_type_was_created = false; |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 6252 | clang_type.SetClangType(ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die)); |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6253 | if (!clang_type) |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6254 | { |
| Sean Callanan | 4d04c6a | 2012-02-09 22:54:11 +0000 | [diff] [blame] | 6255 | const DWARFDebugInfoEntry *decl_ctx_die; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6256 | |
| Sean Callanan | 4d04c6a | 2012-02-09 22:54:11 +0000 | [diff] [blame] | 6257 | clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die); |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 6258 | if (accessibility == eAccessNone && decl_ctx) |
| 6259 | { |
| 6260 | // Check the decl context that contains this class/struct/union. |
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 6261 | // If it is a class we must give it an accessibility. |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 6262 | const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind(); |
| 6263 | if (DeclKindIsCXXClass (containing_decl_kind)) |
| 6264 | accessibility = default_accessibility; |
| 6265 | } |
| 6266 | |
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 6267 | ClangASTMetadata metadata; |
| 6268 | metadata.SetUserID(MakeUserID(die->GetOffset())); |
| 6269 | metadata.SetIsDynamicCXXType(ClassOrStructIsVirtual (dwarf_cu, die)); |
| 6270 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6271 | if (type_name_cstr && strchr (type_name_cstr, '<')) |
| 6272 | { |
| 6273 | ClangASTContext::TemplateParameterInfos template_param_infos; |
| 6274 | if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos)) |
| 6275 | { |
| 6276 | clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx, |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 6277 | accessibility, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6278 | type_name_cstr, |
| 6279 | tag_decl_kind, |
| 6280 | template_param_infos); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6281 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6282 | clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx, |
| 6283 | class_template_decl, |
| 6284 | tag_decl_kind, |
| 6285 | template_param_infos); |
| 6286 | clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl); |
| 6287 | clang_type_was_created = true; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6288 | |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6289 | GetClangASTContext().SetMetadata (class_template_decl, metadata); |
| 6290 | GetClangASTContext().SetMetadata (class_specialization_decl, metadata); |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6291 | } |
| 6292 | } |
| 6293 | |
| 6294 | if (!clang_type_was_created) |
| 6295 | { |
| 6296 | clang_type_was_created = true; |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 6297 | clang_type = ast.CreateRecordType (decl_ctx, |
| 6298 | accessibility, |
| 6299 | type_name_cstr, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6300 | tag_decl_kind, |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 6301 | class_language, |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6302 | &metadata); |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6303 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6304 | } |
| 6305 | |
| 6306 | // Store a forward declaration to this class type in case any |
| 6307 | // parameters in any class methods need it for the clang |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6308 | // types for function prototypes. |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 6309 | LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6310 | type_sp.reset (new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6311 | this, |
| 6312 | type_name_const_str, |
| 6313 | byte_size, |
| 6314 | NULL, |
| 6315 | LLDB_INVALID_UID, |
| 6316 | Type::eEncodingIsUID, |
| 6317 | &decl, |
| 6318 | clang_type, |
| 6319 | Type::eResolveStateForward)); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6320 | |
| Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 6321 | type_sp->SetIsCompleteObjCClass(is_complete_objc_class); |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6322 | |
| 6323 | |
| 6324 | // Add our type to the unique type map so we don't |
| 6325 | // end up creating many copies of the same type over |
| 6326 | // and over in the ASTContext for our module |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 6327 | unique_ast_entry_ap->m_type_sp = type_sp; |
| 6328 | unique_ast_entry_ap->m_symfile = this; |
| 6329 | unique_ast_entry_ap->m_cu = dwarf_cu; |
| 6330 | unique_ast_entry_ap->m_die = die; |
| 6331 | unique_ast_entry_ap->m_declaration = decl; |
| 6332 | unique_ast_entry_ap->m_byte_size = byte_size; |
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 6333 | GetUniqueDWARFASTTypeMap().Insert (type_name_const_str, |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 6334 | *unique_ast_entry_ap); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6335 | |
| Greg Clayton | 0ec71a0 | 2013-08-10 00:09:35 +0000 | [diff] [blame] | 6336 | if (is_forward_declaration && die->HasChildren()) |
| 6337 | { |
| 6338 | // Check to see if the DIE actually has a definition, some version of GCC will |
| 6339 | // emit DIEs with DW_AT_declaration set to true, but yet still have subprogram, |
| 6340 | // members, or inheritance, so we can't trust it |
| 6341 | const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); |
| 6342 | while (child_die) |
| 6343 | { |
| 6344 | switch (child_die->Tag()) |
| 6345 | { |
| 6346 | case DW_TAG_inheritance: |
| 6347 | case DW_TAG_subprogram: |
| 6348 | case DW_TAG_member: |
| 6349 | case DW_TAG_APPLE_property: |
| Greg Clayton | 4c484ec | 2014-02-07 19:21:56 +0000 | [diff] [blame] | 6350 | case DW_TAG_class_type: |
| 6351 | case DW_TAG_structure_type: |
| 6352 | case DW_TAG_enumeration_type: |
| 6353 | case DW_TAG_typedef: |
| 6354 | case DW_TAG_union_type: |
| Greg Clayton | 0ec71a0 | 2013-08-10 00:09:35 +0000 | [diff] [blame] | 6355 | child_die = NULL; |
| 6356 | is_forward_declaration = false; |
| 6357 | break; |
| 6358 | default: |
| 6359 | child_die = child_die->GetSibling(); |
| 6360 | break; |
| 6361 | } |
| 6362 | } |
| 6363 | } |
| 6364 | |
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6365 | if (!is_forward_declaration) |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 6366 | { |
| 6367 | // Always start the definition for a class type so that |
| 6368 | // if the class has child classes or types that require |
| 6369 | // the class to be created for use as their decl contexts |
| 6370 | // the class will be ready to accept these child definitions. |
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6371 | if (die->HasChildren() == false) |
| 6372 | { |
| 6373 | // No children for this struct/union/class, lets finish it |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 6374 | clang_type.StartTagDeclarationDefinition (); |
| 6375 | clang_type.CompleteTagDeclarationDefinition (); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6376 | |
| Sean Callanan | 433cd22 | 2012-10-19 01:37:25 +0000 | [diff] [blame] | 6377 | if (tag == DW_TAG_structure_type) // this only applies in C |
| 6378 | { |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 6379 | clang::RecordDecl *record_decl = clang_type.GetAsRecordDecl(); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6380 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6381 | if (record_decl) |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 6382 | 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] | 6383 | } |
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6384 | } |
| 6385 | else if (clang_type_was_created) |
| 6386 | { |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 6387 | // Start the definition if the class is not objective C since |
| 6388 | // the underlying decls respond to isCompleteDefinition(). Objective |
| Bruce Mitchener | aaa0ba3 | 2014-07-08 18:05:41 +0000 | [diff] [blame] | 6389 | // C decls don't respond to isCompleteDefinition() so we can't |
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 6390 | // start the declaration definition right away. For C++ class/union/structs |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 6391 | // we want to start the definition in case the class is needed as the |
| 6392 | // declaration context for a contained class or type without the need |
| 6393 | // to complete that type.. |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6394 | |
| Sean Callanan | 7457f8d | 2012-04-25 01:03:57 +0000 | [diff] [blame] | 6395 | if (class_language != eLanguageTypeObjC && |
| 6396 | class_language != eLanguageTypeObjC_plus_plus) |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 6397 | clang_type.StartTagDeclarationDefinition (); |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 6398 | |
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6399 | // Leave this as a forward declaration until we need |
| 6400 | // to know the details of the type. lldb_private::Type |
| 6401 | // will automatically call the SymbolFile virtual function |
| 6402 | // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)" |
| 6403 | // When the definition needs to be defined. |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6404 | m_forward_decl_die_to_clang_type[die] = clang_type.GetOpaqueQualType(); |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 6405 | m_forward_decl_clang_type_to_die[clang_type.RemoveFastQualifiers().GetOpaqueQualType()] = die; |
| 6406 | clang_type.SetHasExternalStorage (true); |
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6407 | } |
| Greg Clayton | c615ce4 | 2010-11-09 04:42:43 +0000 | [diff] [blame] | 6408 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6409 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6410 | } |
| 6411 | break; |
| 6412 | |
| 6413 | case DW_TAG_enumeration_type: |
| 6414 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6415 | // 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] | 6416 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6417 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6418 | lldb::user_id_t encoding_uid = DW_INVALID_OFFSET; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6419 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6420 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6421 | if (num_attributes > 0) |
| 6422 | { |
| 6423 | uint32_t i; |
| 6424 | |
| 6425 | for (i=0; i<num_attributes; ++i) |
| 6426 | { |
| 6427 | attr = attributes.AttributeAtIndex(i); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6428 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 6429 | { |
| 6430 | switch (attr) |
| 6431 | { |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 6432 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 6433 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 6434 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6435 | case DW_AT_name: |
| 6436 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6437 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6438 | break; |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 6439 | case DW_AT_type: encoding_uid = form_value.Reference(); break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6440 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; |
| 6441 | 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] | 6442 | case DW_AT_declaration: break; //is_forward_declaration = form_value.Boolean(); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6443 | case DW_AT_allocated: |
| 6444 | case DW_AT_associated: |
| 6445 | case DW_AT_bit_stride: |
| 6446 | case DW_AT_byte_stride: |
| 6447 | case DW_AT_data_location: |
| 6448 | case DW_AT_description: |
| 6449 | case DW_AT_start_scope: |
| 6450 | case DW_AT_visibility: |
| 6451 | case DW_AT_specification: |
| 6452 | case DW_AT_abstract_origin: |
| 6453 | case DW_AT_sibling: |
| 6454 | break; |
| 6455 | } |
| 6456 | } |
| 6457 | } |
| 6458 | |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6459 | 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] | 6460 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6461 | ClangASTType enumerator_clang_type; |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 6462 | clang_type.SetClangType (ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die)); |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6463 | if (!clang_type) |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6464 | { |
| Greg Clayton | 5d14fc0 | 2013-03-06 06:23:54 +0000 | [diff] [blame] | 6465 | if (encoding_uid != DW_INVALID_OFFSET) |
| 6466 | { |
| 6467 | Type *enumerator_type = ResolveTypeUID(encoding_uid); |
| 6468 | if (enumerator_type) |
| 6469 | enumerator_clang_type = enumerator_type->GetClangFullType(); |
| 6470 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6471 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6472 | if (!enumerator_clang_type) |
| Greg Clayton | 5d14fc0 | 2013-03-06 06:23:54 +0000 | [diff] [blame] | 6473 | enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL, |
| 6474 | DW_ATE_signed, |
| 6475 | byte_size * 8); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6476 | |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 6477 | clang_type = ast.CreateEnumerationType (type_name_cstr, |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6478 | GetClangDeclContextContainingDIE (dwarf_cu, die, NULL), |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 6479 | decl, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6480 | enumerator_clang_type); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6481 | } |
| 6482 | else |
| 6483 | { |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 6484 | enumerator_clang_type = clang_type.GetEnumerationIntegerType (); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6485 | } |
| 6486 | |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 6487 | LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6488 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6489 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6490 | this, |
| 6491 | type_name_const_str, |
| 6492 | byte_size, |
| 6493 | NULL, |
| 6494 | encoding_uid, |
| 6495 | Type::eEncodingIsUID, |
| 6496 | &decl, |
| 6497 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6498 | Type::eResolveStateForward)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6499 | |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 6500 | clang_type.StartTagDeclarationDefinition (); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 6501 | if (die->HasChildren()) |
| 6502 | { |
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 6503 | SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); |
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 6504 | bool is_signed = false; |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6505 | enumerator_clang_type.IsIntegerType(is_signed); |
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 6506 | 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] | 6507 | } |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 6508 | clang_type.CompleteTagDeclarationDefinition (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6509 | } |
| 6510 | } |
| 6511 | break; |
| 6512 | |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 6513 | case DW_TAG_inlined_subroutine: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6514 | case DW_TAG_subprogram: |
| 6515 | case DW_TAG_subroutine_type: |
| 6516 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6517 | // 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] | 6518 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6519 | |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6520 | //const char *mangled = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6521 | dw_offset_t type_die_offset = DW_INVALID_OFFSET; |
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 6522 | bool is_variadic = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6523 | bool is_inline = false; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6524 | bool is_static = false; |
| 6525 | bool is_virtual = false; |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6526 | bool is_explicit = false; |
| Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 6527 | bool is_artificial = false; |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6528 | dw_offset_t specification_die_offset = DW_INVALID_OFFSET; |
| 6529 | dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET; |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6530 | dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6531 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6532 | unsigned type_quals = 0; |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 6533 | clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6534 | |
| 6535 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6536 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6537 | if (num_attributes > 0) |
| 6538 | { |
| 6539 | uint32_t i; |
| 6540 | for (i=0; i<num_attributes; ++i) |
| 6541 | { |
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 6542 | attr = attributes.AttributeAtIndex(i); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6543 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 6544 | { |
| 6545 | switch (attr) |
| 6546 | { |
| 6547 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 6548 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 6549 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 6550 | case DW_AT_name: |
| 6551 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6552 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6553 | break; |
| 6554 | |
| Greg Clayton | 7141554 | 2012-12-08 00:24:40 +0000 | [diff] [blame] | 6555 | case DW_AT_linkage_name: |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6556 | 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] | 6557 | case DW_AT_type: type_die_offset = form_value.Reference(); break; |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 6558 | 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] | 6559 | case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break; |
| 6560 | case DW_AT_inline: is_inline = form_value.Boolean(); break; |
| 6561 | case DW_AT_virtuality: is_virtual = form_value.Boolean(); break; |
| 6562 | case DW_AT_explicit: is_explicit = form_value.Boolean(); break; |
| 6563 | case DW_AT_artificial: is_artificial = form_value.Boolean(); break; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6564 | |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6565 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6566 | case DW_AT_external: |
| 6567 | if (form_value.Unsigned()) |
| 6568 | { |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 6569 | if (storage == clang::SC_None) |
| 6570 | storage = clang::SC_Extern; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6571 | else |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 6572 | storage = clang::SC_PrivateExtern; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6573 | } |
| 6574 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6575 | |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6576 | case DW_AT_specification: |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 6577 | specification_die_offset = form_value.Reference(); |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6578 | break; |
| 6579 | |
| 6580 | case DW_AT_abstract_origin: |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 6581 | abstract_origin_die_offset = form_value.Reference(); |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6582 | break; |
| 6583 | |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6584 | case DW_AT_object_pointer: |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 6585 | object_pointer_die_offset = form_value.Reference(); |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6586 | break; |
| 6587 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6588 | case DW_AT_allocated: |
| 6589 | case DW_AT_associated: |
| 6590 | case DW_AT_address_class: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6591 | case DW_AT_calling_convention: |
| 6592 | case DW_AT_data_location: |
| 6593 | case DW_AT_elemental: |
| 6594 | case DW_AT_entry_pc: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6595 | case DW_AT_frame_base: |
| 6596 | case DW_AT_high_pc: |
| 6597 | case DW_AT_low_pc: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6598 | case DW_AT_prototyped: |
| 6599 | case DW_AT_pure: |
| 6600 | case DW_AT_ranges: |
| 6601 | case DW_AT_recursive: |
| 6602 | case DW_AT_return_addr: |
| 6603 | case DW_AT_segment: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6604 | case DW_AT_start_scope: |
| 6605 | case DW_AT_static_link: |
| 6606 | case DW_AT_trampoline: |
| 6607 | case DW_AT_visibility: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6608 | case DW_AT_vtable_elem_location: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6609 | case DW_AT_description: |
| 6610 | case DW_AT_sibling: |
| 6611 | break; |
| 6612 | } |
| 6613 | } |
| 6614 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6615 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6616 | |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6617 | std::string object_pointer_name; |
| 6618 | if (object_pointer_die_offset != DW_INVALID_OFFSET) |
| 6619 | { |
| 6620 | // Get the name from the object pointer die |
| 6621 | StreamString s; |
| 6622 | if (DWARFDebugInfoEntry::GetName (this, dwarf_cu, object_pointer_die_offset, s)) |
| 6623 | { |
| 6624 | object_pointer_name.assign(s.GetData()); |
| 6625 | } |
| 6626 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6627 | |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6628 | 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] | 6629 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6630 | ClangASTType return_clang_type; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6631 | Type *func_type = NULL; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6632 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6633 | if (type_die_offset != DW_INVALID_OFFSET) |
| 6634 | func_type = ResolveTypeUID(type_die_offset); |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6635 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6636 | if (func_type) |
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 6637 | return_clang_type = func_type->GetClangForwardType(); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6638 | else |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6639 | return_clang_type = ast.GetBasicType(eBasicTypeVoid); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6640 | |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6641 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6642 | std::vector<ClangASTType> function_param_types; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6643 | std::vector<clang::ParmVarDecl*> function_param_decls; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6644 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6645 | // Parse the function children for the parameters |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6646 | |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6647 | const DWARFDebugInfoEntry *decl_ctx_die = NULL; |
| 6648 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die); |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6649 | const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind(); |
| 6650 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6651 | const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind); |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6652 | // Start off static. This will be set to false in ParseChildParameters(...) |
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 6653 | // if we find a "this" parameters as the first parameter |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6654 | if (is_cxx_method) |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 6655 | is_static = true; |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 6656 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6657 | if (die->HasChildren()) |
| 6658 | { |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6659 | bool skip_artificial = true; |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6660 | ParseChildParameters (sc, |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6661 | containing_decl_ctx, |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6662 | dwarf_cu, |
| 6663 | die, |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 6664 | skip_artificial, |
| 6665 | is_static, |
| Greg Clayton | 0396975 | 2014-02-24 18:53:11 +0000 | [diff] [blame] | 6666 | is_variadic, |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6667 | function_param_types, |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 6668 | function_param_decls, |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 6669 | type_quals); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6670 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6671 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6672 | // clang_type will get the function prototype clang type after this call |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6673 | clang_type = ast.CreateFunctionType (return_clang_type, |
| Greg Clayton | 9cb25c4 | 2012-10-30 17:02:18 +0000 | [diff] [blame] | 6674 | function_param_types.data(), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6675 | function_param_types.size(), |
| 6676 | is_variadic, |
| 6677 | type_quals); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6678 | |
| Sean Callanan | de9ce87 | 2013-05-09 23:13:13 +0000 | [diff] [blame] | 6679 | bool ignore_containing_context = false; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6680 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6681 | if (type_name_cstr) |
| 6682 | { |
| 6683 | bool type_handled = false; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6684 | if (tag == DW_TAG_subprogram) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6685 | { |
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 6686 | ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true); |
| 6687 | if (objc_method.IsValid(true)) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6688 | { |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6689 | ClangASTType class_opaque_type; |
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 6690 | ConstString class_name(objc_method.GetClassName()); |
| Greg Clayton | 7c81042 | 2012-01-18 23:40:49 +0000 | [diff] [blame] | 6691 | if (class_name) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6692 | { |
| Greg Clayton | 278a16b | 2012-01-19 00:52:59 +0000 | [diff] [blame] | 6693 | TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false)); |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6694 | |
| 6695 | if (complete_objc_class_type_sp) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6696 | { |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6697 | ClangASTType type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType(); |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 6698 | if (type_clang_forward_type.IsObjCObjectOrInterfaceType ()) |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6699 | class_opaque_type = type_clang_forward_type; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6700 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6701 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6702 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6703 | if (class_opaque_type) |
| 6704 | { |
| 6705 | // If accessibility isn't set to anything valid, assume public for |
| 6706 | // now... |
| 6707 | if (accessibility == eAccessNone) |
| 6708 | accessibility = eAccessPublic; |
| 6709 | |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 6710 | clang::ObjCMethodDecl *objc_method_decl = class_opaque_type.AddMethodToObjCObjectType (type_name_cstr, |
| 6711 | clang_type, |
| 6712 | accessibility, |
| 6713 | is_artificial); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6714 | type_handled = objc_method_decl != NULL; |
| Sean Callanan | 464a5b5 | 2012-10-04 22:06:29 +0000 | [diff] [blame] | 6715 | if (type_handled) |
| 6716 | { |
| 6717 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die); |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6718 | GetClangASTContext().SetMetadataAsUserID (objc_method_decl, MakeUserID(die->GetOffset())); |
| Sean Callanan | 464a5b5 | 2012-10-04 22:06:29 +0000 | [diff] [blame] | 6719 | } |
| Sean Callanan | c3a1d56 | 2013-02-06 23:21:59 +0000 | [diff] [blame] | 6720 | else |
| 6721 | { |
| Jason Molenda | c1a6583 | 2013-03-07 22:44:42 +0000 | [diff] [blame] | 6722 | 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] | 6723 | die->GetOffset(), |
| 6724 | tag, |
| 6725 | DW_TAG_value_to_name(tag)); |
| 6726 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6727 | } |
| 6728 | } |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6729 | else if (is_cxx_method) |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6730 | { |
| 6731 | // Look at the parent of this DIE and see if is is |
| 6732 | // a class or struct and see if this is actually a |
| 6733 | // C++ method |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6734 | Type *class_type = ResolveType (dwarf_cu, decl_ctx_die); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6735 | if (class_type) |
| 6736 | { |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6737 | if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset())) |
| 6738 | { |
| 6739 | // We uniqued the parent class of this function to another class |
| 6740 | // so we now need to associate all dies under "decl_ctx_die" to |
| 6741 | // DIEs in the DIE for "class_type"... |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 6742 | SymbolFileDWARF *class_symfile = NULL; |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6743 | DWARFCompileUnitSP class_type_cu_sp; |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 6744 | const DWARFDebugInfoEntry *class_type_die = NULL; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6745 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6746 | SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile(); |
| 6747 | if (debug_map_symfile) |
| 6748 | { |
| 6749 | class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID())); |
| 6750 | class_type_die = class_symfile->DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp); |
| 6751 | } |
| 6752 | else |
| 6753 | { |
| 6754 | class_symfile = this; |
| 6755 | class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp); |
| 6756 | } |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6757 | if (class_type_die) |
| 6758 | { |
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 6759 | DWARFDIECollection failures; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6760 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6761 | CopyUniqueClassMethodTypes (class_symfile, |
| 6762 | class_type, |
| 6763 | class_type_cu_sp.get(), |
| 6764 | class_type_die, |
| 6765 | dwarf_cu, |
| 6766 | decl_ctx_die, |
| 6767 | failures); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6768 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6769 | // FIXME do something with these failures that's smarter than |
| 6770 | // just dropping them on the ground. Unfortunately classes don't |
| 6771 | // like having stuff added to them after their definitions are |
| 6772 | // complete... |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6773 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6774 | type_ptr = m_die_to_type[die]; |
| 6775 | if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6776 | { |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6777 | type_sp = type_ptr->shared_from_this(); |
| 6778 | break; |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6779 | } |
| 6780 | } |
| 6781 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6782 | |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6783 | if (specification_die_offset != DW_INVALID_OFFSET) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6784 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6785 | // We have a specification which we are going to base our function |
| 6786 | // prototype off of, so we need this type to be completed so that the |
| 6787 | // m_die_to_decl_ctx for the method in the specification has a valid |
| 6788 | // clang decl context. |
| Greg Clayton | 8eb732e | 2011-12-13 04:34:06 +0000 | [diff] [blame] | 6789 | class_type->GetClangForwardType(); |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6790 | // If we have a specification, then the function type should have been |
| 6791 | // made with the specification and not with this die. |
| 6792 | DWARFCompileUnitSP spec_cu_sp; |
| 6793 | const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp); |
| Eric Christopher | 6cc6e60 | 2012-03-25 19:37:33 +0000 | [diff] [blame] | 6794 | clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die); |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6795 | if (spec_clang_decl_ctx) |
| 6796 | { |
| 6797 | LinkDeclContextToDIE(spec_clang_decl_ctx, die); |
| 6798 | } |
| 6799 | else |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6800 | { |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6801 | 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] | 6802 | MakeUserID(die->GetOffset()), |
| 6803 | specification_die_offset); |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6804 | } |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6805 | type_handled = true; |
| 6806 | } |
| 6807 | else if (abstract_origin_die_offset != DW_INVALID_OFFSET) |
| 6808 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6809 | // We have a specification which we are going to base our function |
| 6810 | // prototype off of, so we need this type to be completed so that the |
| 6811 | // m_die_to_decl_ctx for the method in the abstract origin has a valid |
| 6812 | // clang decl context. |
| Greg Clayton | 8eb732e | 2011-12-13 04:34:06 +0000 | [diff] [blame] | 6813 | class_type->GetClangForwardType(); |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6814 | |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6815 | DWARFCompileUnitSP abs_cu_sp; |
| 6816 | 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] | 6817 | clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die); |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6818 | if (abs_clang_decl_ctx) |
| 6819 | { |
| 6820 | LinkDeclContextToDIE (abs_clang_decl_ctx, die); |
| 6821 | } |
| 6822 | else |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6823 | { |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6824 | 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] | 6825 | MakeUserID(die->GetOffset()), |
| 6826 | abstract_origin_die_offset); |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6827 | } |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6828 | type_handled = true; |
| 6829 | } |
| 6830 | else |
| 6831 | { |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6832 | ClangASTType class_opaque_type = class_type->GetClangForwardType(); |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 6833 | if (class_opaque_type.IsCXXClassType ()) |
| Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 6834 | { |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6835 | if (class_opaque_type.IsBeingDefined ()) |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6836 | { |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6837 | // Neither GCC 4.2 nor clang++ currently set a valid accessibility |
| 6838 | // in the DWARF for C++ methods... Default to public for now... |
| 6839 | if (accessibility == eAccessNone) |
| 6840 | accessibility = eAccessPublic; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6841 | |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6842 | if (!is_static && !die->HasChildren()) |
| 6843 | { |
| 6844 | // We have a C++ member function with no children (this pointer!) |
| 6845 | // and clang will get mad if we try and make a function that isn't |
| 6846 | // well formed in the DWARF, so we will just skip it... |
| 6847 | type_handled = true; |
| 6848 | } |
| 6849 | else |
| 6850 | { |
| 6851 | clang::CXXMethodDecl *cxx_method_decl; |
| 6852 | // REMOVE THE CRASH DESCRIPTION BELOW |
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 6853 | 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] | 6854 | type_name_cstr, |
| 6855 | class_type->GetName().GetCString(), |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6856 | MakeUserID(die->GetOffset()), |
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 6857 | m_obj_file->GetFileSpec().GetPath().c_str()); |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6858 | |
| Sean Callanan | c1b732d | 2011-11-01 18:07:13 +0000 | [diff] [blame] | 6859 | const bool is_attr_used = false; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6860 | |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 6861 | cxx_method_decl = class_opaque_type.AddMethodToCXXRecordType (type_name_cstr, |
| 6862 | clang_type, |
| 6863 | accessibility, |
| 6864 | is_virtual, |
| 6865 | is_static, |
| 6866 | is_inline, |
| 6867 | is_explicit, |
| 6868 | is_attr_used, |
| 6869 | is_artificial); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6870 | |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6871 | type_handled = cxx_method_decl != NULL; |
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6872 | |
| 6873 | if (type_handled) |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6874 | { |
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6875 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die); |
| 6876 | |
| 6877 | Host::SetCrashDescription (NULL); |
| 6878 | |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6879 | |
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6880 | ClangASTMetadata metadata; |
| 6881 | metadata.SetUserID(MakeUserID(die->GetOffset())); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6882 | |
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6883 | if (!object_pointer_name.empty()) |
| 6884 | { |
| 6885 | metadata.SetObjectPtrName(object_pointer_name.c_str()); |
| 6886 | if (log) |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6887 | log->Printf ("Setting object pointer name: %s on method object %p.\n", |
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6888 | object_pointer_name.c_str(), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6889 | static_cast<void*>(cxx_method_decl)); |
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6890 | } |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6891 | GetClangASTContext().SetMetadata (cxx_method_decl, metadata); |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6892 | } |
| Sean Callanan | b0640dc | 2013-04-09 23:22:08 +0000 | [diff] [blame] | 6893 | else |
| 6894 | { |
| Sean Callanan | de9ce87 | 2013-05-09 23:13:13 +0000 | [diff] [blame] | 6895 | ignore_containing_context = true; |
| Sean Callanan | b0640dc | 2013-04-09 23:22:08 +0000 | [diff] [blame] | 6896 | } |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6897 | } |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6898 | } |
| 6899 | else |
| 6900 | { |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6901 | // We were asked to parse the type for a method in a class, yet the |
| 6902 | // class hasn't been asked to complete itself through the |
| 6903 | // clang::ExternalASTSource protocol, so we need to just have the |
| 6904 | // class complete itself and do things the right way, then our |
| 6905 | // DIE should then have an entry in the m_die_to_type map. First |
| 6906 | // we need to modify the m_die_to_type so it doesn't think we are |
| 6907 | // trying to parse this DIE anymore... |
| 6908 | m_die_to_type[die] = NULL; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6909 | |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6910 | // Now we get the full type to force our class type to complete itself |
| 6911 | // using the clang::ExternalASTSource protocol which will parse all |
| 6912 | // base classes and all methods (including the method for this DIE). |
| 6913 | class_type->GetClangFullType(); |
| Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 6914 | |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6915 | // The type for this DIE should have been filled in the function call above |
| 6916 | type_ptr = m_die_to_type[die]; |
| Greg Clayton | e5476db | 2012-06-01 20:32:35 +0000 | [diff] [blame] | 6917 | if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6918 | { |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 6919 | type_sp = type_ptr->shared_from_this(); |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6920 | break; |
| 6921 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6922 | |
| Sean Callanan | 02eee4d | 2012-04-12 23:10:00 +0000 | [diff] [blame] | 6923 | // FIXME This is fixing some even uglier behavior but we really need to |
| 6924 | // uniq the methods of each class as well as the class itself. |
| 6925 | // <rdar://problem/11240464> |
| 6926 | type_handled = true; |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6927 | } |
| Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 6928 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6929 | } |
| 6930 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6931 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6932 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6933 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6934 | if (!type_handled) |
| 6935 | { |
| 6936 | // We just have a function that isn't part of a class |
| Sean Callanan | de9ce87 | 2013-05-09 23:13:13 +0000 | [diff] [blame] | 6937 | 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] | 6938 | type_name_cstr, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6939 | clang_type, |
| 6940 | storage, |
| 6941 | is_inline); |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 6942 | |
| 6943 | // if (template_param_infos.GetSize() > 0) |
| 6944 | // { |
| 6945 | // clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx, |
| 6946 | // function_decl, |
| 6947 | // type_name_cstr, |
| 6948 | // template_param_infos); |
| 6949 | // |
| 6950 | // ast.CreateFunctionTemplateSpecializationInfo (function_decl, |
| 6951 | // func_template_decl, |
| 6952 | // template_param_infos); |
| 6953 | // } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6954 | // Add the decl to our DIE to decl context map |
| 6955 | assert (function_decl); |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6956 | LinkDeclContextToDIE(function_decl, die); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6957 | if (!function_param_decls.empty()) |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6958 | ast.SetFunctionParameters (function_decl, |
| 6959 | &function_param_decls.front(), |
| 6960 | function_param_decls.size()); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6961 | |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6962 | ClangASTMetadata metadata; |
| 6963 | metadata.SetUserID(MakeUserID(die->GetOffset())); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6964 | |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6965 | if (!object_pointer_name.empty()) |
| 6966 | { |
| 6967 | metadata.SetObjectPtrName(object_pointer_name.c_str()); |
| Jim Ingham | 2cffda3f | 2012-10-30 23:34:07 +0000 | [diff] [blame] | 6968 | if (log) |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6969 | log->Printf ("Setting object pointer name: %s on function object %p.", |
| Jim Ingham | 2cffda3f | 2012-10-30 23:34:07 +0000 | [diff] [blame] | 6970 | object_pointer_name.c_str(), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6971 | static_cast<void*>(function_decl)); |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6972 | } |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6973 | GetClangASTContext().SetMetadata (function_decl, metadata); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6974 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6975 | } |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6976 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6977 | this, |
| 6978 | type_name_const_str, |
| 6979 | 0, |
| 6980 | NULL, |
| 6981 | LLDB_INVALID_UID, |
| 6982 | Type::eEncodingIsUID, |
| 6983 | &decl, |
| 6984 | clang_type, |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6985 | Type::eResolveStateFull)); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6986 | assert(type_sp.get()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6987 | } |
| 6988 | break; |
| 6989 | |
| 6990 | case DW_TAG_array_type: |
| 6991 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6992 | // 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] | 6993 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6994 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6995 | lldb::user_id_t type_die_offset = DW_INVALID_OFFSET; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6996 | int64_t first_index = 0; |
| 6997 | uint32_t byte_stride = 0; |
| 6998 | uint32_t bit_stride = 0; |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 6999 | bool is_vector = false; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 7000 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7001 | |
| 7002 | if (num_attributes > 0) |
| 7003 | { |
| 7004 | uint32_t i; |
| 7005 | for (i=0; i<num_attributes; ++i) |
| 7006 | { |
| 7007 | attr = attributes.AttributeAtIndex(i); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7008 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 7009 | { |
| 7010 | switch (attr) |
| 7011 | { |
| 7012 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 7013 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 7014 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 7015 | case DW_AT_name: |
| 7016 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 7017 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7018 | break; |
| 7019 | |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 7020 | case DW_AT_type: type_die_offset = form_value.Reference(); break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 7021 | case DW_AT_byte_size: break; // byte_size = form_value.Unsigned(); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7022 | case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break; |
| 7023 | case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break; |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 7024 | case DW_AT_GNU_vector: is_vector = form_value.Boolean(); break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 7025 | 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] | 7026 | case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7027 | case DW_AT_allocated: |
| 7028 | case DW_AT_associated: |
| 7029 | case DW_AT_data_location: |
| 7030 | case DW_AT_description: |
| 7031 | case DW_AT_ordering: |
| 7032 | case DW_AT_start_scope: |
| 7033 | case DW_AT_visibility: |
| 7034 | case DW_AT_specification: |
| 7035 | case DW_AT_abstract_origin: |
| 7036 | case DW_AT_sibling: |
| 7037 | break; |
| 7038 | } |
| 7039 | } |
| 7040 | } |
| 7041 | |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 7042 | 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] | 7043 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7044 | Type *element_type = ResolveTypeUID(type_die_offset); |
| 7045 | |
| 7046 | if (element_type) |
| 7047 | { |
| 7048 | std::vector<uint64_t> element_orders; |
| 7049 | ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride); |
| 7050 | if (byte_stride == 0 && bit_stride == 0) |
| 7051 | byte_stride = element_type->GetByteSize(); |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 7052 | ClangASTType array_element_type = element_type->GetClangForwardType(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7053 | uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride; |
| Siva Chandra | 89ce955 | 2015-01-05 23:06:14 +0000 | [diff] [blame] | 7054 | if (element_orders.size() > 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7055 | { |
| Siva Chandra | 89ce955 | 2015-01-05 23:06:14 +0000 | [diff] [blame] | 7056 | uint64_t num_elements = 0; |
| 7057 | std::vector<uint64_t>::const_reverse_iterator pos; |
| 7058 | std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend(); |
| 7059 | for (pos = element_orders.rbegin(); pos != end; ++pos) |
| 7060 | { |
| 7061 | num_elements = *pos; |
| 7062 | clang_type = ast.CreateArrayType (array_element_type, |
| 7063 | num_elements, |
| 7064 | is_vector); |
| 7065 | array_element_type = clang_type; |
| 7066 | array_element_bit_stride = num_elements ? |
| 7067 | array_element_bit_stride * num_elements : |
| 7068 | array_element_bit_stride; |
| 7069 | } |
| 7070 | } |
| 7071 | else |
| 7072 | { |
| 7073 | clang_type = ast.CreateArrayType (array_element_type, 0, is_vector); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7074 | } |
| 7075 | ConstString empty_name; |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7076 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 7077 | this, |
| 7078 | empty_name, |
| 7079 | array_element_bit_stride / 8, |
| 7080 | NULL, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 7081 | type_die_offset, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 7082 | Type::eEncodingIsUID, |
| 7083 | &decl, |
| 7084 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 7085 | Type::eResolveStateFull)); |
| 7086 | type_sp->SetEncodingType (element_type); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7087 | } |
| 7088 | } |
| 7089 | } |
| 7090 | break; |
| 7091 | |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 7092 | case DW_TAG_ptr_to_member_type: |
| 7093 | { |
| 7094 | dw_offset_t type_die_offset = DW_INVALID_OFFSET; |
| 7095 | dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET; |
| 7096 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 7097 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 7098 | |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 7099 | if (num_attributes > 0) { |
| 7100 | uint32_t i; |
| 7101 | for (i=0; i<num_attributes; ++i) |
| 7102 | { |
| 7103 | attr = attributes.AttributeAtIndex(i); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 7104 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 7105 | { |
| 7106 | switch (attr) |
| 7107 | { |
| 7108 | case DW_AT_type: |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 7109 | type_die_offset = form_value.Reference(); break; |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 7110 | case DW_AT_containing_type: |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 7111 | containing_type_die_offset = form_value.Reference(); break; |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 7112 | } |
| 7113 | } |
| 7114 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 7115 | |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 7116 | Type *pointee_type = ResolveTypeUID(type_die_offset); |
| 7117 | Type *class_type = ResolveTypeUID(containing_type_die_offset); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 7118 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 7119 | ClangASTType pointee_clang_type = pointee_type->GetClangForwardType(); |
| 7120 | ClangASTType class_clang_type = class_type->GetClangLayoutType(); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 7121 | |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 7122 | clang_type = pointee_clang_type.CreateMemberPointerType(class_clang_type); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 7123 | |
| Enrico Granata | 1cd5e92 | 2015-01-28 00:07:51 +0000 | [diff] [blame] | 7124 | byte_size = clang_type.GetByteSize(nullptr); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 7125 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7126 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 7127 | this, |
| 7128 | type_name_const_str, |
| 7129 | byte_size, |
| 7130 | NULL, |
| 7131 | LLDB_INVALID_UID, |
| 7132 | Type::eEncodingIsUID, |
| 7133 | NULL, |
| 7134 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 7135 | Type::eResolveStateForward)); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 7136 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 7137 | |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 7138 | break; |
| 7139 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7140 | default: |
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 7141 | 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", |
| 7142 | die->GetOffset(), |
| 7143 | tag, |
| 7144 | DW_TAG_value_to_name(tag)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7145 | break; |
| 7146 | } |
| 7147 | |
| 7148 | if (type_sp.get()) |
| 7149 | { |
| 7150 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); |
| 7151 | dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
| 7152 | |
| 7153 | SymbolContextScope * symbol_context_scope = NULL; |
| 7154 | if (sc_parent_tag == DW_TAG_compile_unit) |
| 7155 | { |
| 7156 | symbol_context_scope = sc.comp_unit; |
| 7157 | } |
| Jason Molenda | 60db6e4 | 2014-10-16 01:40:16 +0000 | [diff] [blame] | 7158 | else if (sc.function != NULL && sc_parent_die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7159 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7160 | 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] | 7161 | if (symbol_context_scope == NULL) |
| 7162 | symbol_context_scope = sc.function; |
| 7163 | } |
| 7164 | |
| 7165 | if (symbol_context_scope != NULL) |
| 7166 | { |
| 7167 | type_sp->SetSymbolContextScope(symbol_context_scope); |
| 7168 | } |
| 7169 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 7170 | // We are ready to put this type into the uniqued list up at the module level |
| 7171 | type_list->Insert (type_sp); |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 7172 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 7173 | m_die_to_type[die] = type_sp.get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7174 | } |
| 7175 | } |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 7176 | else if (type_ptr != DIE_IS_BEING_PARSED) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7177 | { |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 7178 | type_sp = type_ptr->shared_from_this(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7179 | } |
| 7180 | } |
| 7181 | return type_sp; |
| 7182 | } |
| 7183 | |
| 7184 | size_t |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 7185 | SymbolFileDWARF::ParseTypes |
| 7186 | ( |
| 7187 | const SymbolContext& sc, |
| 7188 | DWARFCompileUnit* dwarf_cu, |
| 7189 | const DWARFDebugInfoEntry *die, |
| 7190 | bool parse_siblings, |
| 7191 | bool parse_children |
| 7192 | ) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7193 | { |
| 7194 | size_t types_added = 0; |
| 7195 | while (die != NULL) |
| 7196 | { |
| 7197 | bool type_is_new = false; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 7198 | if (ParseType(sc, dwarf_cu, die, &type_is_new).get()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7199 | { |
| 7200 | if (type_is_new) |
| 7201 | ++types_added; |
| 7202 | } |
| 7203 | |
| 7204 | if (parse_children && die->HasChildren()) |
| 7205 | { |
| 7206 | if (die->Tag() == DW_TAG_subprogram) |
| 7207 | { |
| 7208 | SymbolContext child_sc(sc); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7209 | child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7210 | types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true); |
| 7211 | } |
| 7212 | else |
| 7213 | types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true); |
| 7214 | } |
| 7215 | |
| 7216 | if (parse_siblings) |
| 7217 | die = die->GetSibling(); |
| 7218 | else |
| 7219 | die = NULL; |
| 7220 | } |
| 7221 | return types_added; |
| 7222 | } |
| 7223 | |
| 7224 | |
| 7225 | size_t |
| 7226 | SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc) |
| 7227 | { |
| 7228 | assert(sc.comp_unit && sc.function); |
| 7229 | size_t functions_added = 0; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 7230 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7231 | if (dwarf_cu) |
| 7232 | { |
| 7233 | dw_offset_t function_die_offset = sc.function->GetID(); |
| 7234 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset); |
| 7235 | if (function_die) |
| 7236 | { |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 7237 | 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] | 7238 | } |
| 7239 | } |
| 7240 | |
| 7241 | return functions_added; |
| 7242 | } |
| 7243 | |
| 7244 | |
| 7245 | size_t |
| 7246 | SymbolFileDWARF::ParseTypes (const SymbolContext &sc) |
| 7247 | { |
| 7248 | // At least a compile unit must be valid |
| 7249 | assert(sc.comp_unit); |
| 7250 | size_t types_added = 0; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 7251 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7252 | if (dwarf_cu) |
| 7253 | { |
| 7254 | if (sc.function) |
| 7255 | { |
| 7256 | dw_offset_t function_die_offset = sc.function->GetID(); |
| 7257 | const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset); |
| 7258 | if (func_die && func_die->HasChildren()) |
| 7259 | { |
| 7260 | types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true); |
| 7261 | } |
| 7262 | } |
| 7263 | else |
| 7264 | { |
| 7265 | const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE(); |
| 7266 | if (dwarf_cu_die && dwarf_cu_die->HasChildren()) |
| 7267 | { |
| 7268 | types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true); |
| 7269 | } |
| 7270 | } |
| 7271 | } |
| 7272 | |
| 7273 | return types_added; |
| 7274 | } |
| 7275 | |
| 7276 | size_t |
| 7277 | SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc) |
| 7278 | { |
| 7279 | if (sc.comp_unit != NULL) |
| 7280 | { |
| Greg Clayton | 4b3dc10 | 2010-11-01 20:32:12 +0000 | [diff] [blame] | 7281 | DWARFDebugInfo* info = DebugInfo(); |
| 7282 | if (info == NULL) |
| 7283 | return 0; |
| 7284 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7285 | if (sc.function) |
| 7286 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7287 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnitContainingDIE(sc.function->GetID()).get(); |
| 7288 | |
| 7289 | if (dwarf_cu == NULL) |
| 7290 | return 0; |
| 7291 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7292 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID()); |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 7293 | |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 7294 | dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS); |
| 7295 | if (func_lo_pc != LLDB_INVALID_ADDRESS) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 7296 | { |
| 7297 | 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] | 7298 | |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 7299 | // Let all blocks know they have parse all their variables |
| 7300 | sc.function->GetBlock (false).SetDidParseVariables (true, true); |
| 7301 | return num_variables; |
| 7302 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7303 | } |
| 7304 | else if (sc.comp_unit) |
| 7305 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7306 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()).get(); |
| 7307 | |
| 7308 | if (dwarf_cu == NULL) |
| 7309 | return 0; |
| 7310 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7311 | uint32_t vars_added = 0; |
| 7312 | VariableListSP variables (sc.comp_unit->GetVariableList(false)); |
| 7313 | |
| 7314 | if (variables.get() == NULL) |
| 7315 | { |
| 7316 | variables.reset(new VariableList()); |
| 7317 | sc.comp_unit->SetVariableList(variables); |
| 7318 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7319 | DWARFCompileUnit* match_dwarf_cu = NULL; |
| 7320 | const DWARFDebugInfoEntry* die = NULL; |
| 7321 | DIEArray die_offsets; |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 7322 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7323 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 7324 | if (m_apple_names_ap.get()) |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7325 | { |
| 7326 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 7327 | if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(), |
| 7328 | dwarf_cu->GetNextCompileUnitOffset(), |
| 7329 | hash_data_array)) |
| 7330 | { |
| 7331 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| 7332 | } |
| 7333 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7334 | } |
| 7335 | else |
| 7336 | { |
| 7337 | // Index if we already haven't to make sure the compile units |
| 7338 | // get indexed and make their global DIE index list |
| 7339 | if (!m_indexed) |
| 7340 | Index (); |
| 7341 | |
| 7342 | m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(), |
| 7343 | dwarf_cu->GetNextCompileUnitOffset(), |
| 7344 | die_offsets); |
| 7345 | } |
| 7346 | |
| 7347 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7348 | if (num_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7349 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7350 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 7351 | for (size_t i=0; i<num_matches; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7352 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7353 | const dw_offset_t die_offset = die_offsets[i]; |
| 7354 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 7355 | if (die) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7356 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 7357 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS)); |
| 7358 | if (var_sp) |
| 7359 | { |
| 7360 | variables->AddVariableIfUnique (var_sp); |
| 7361 | ++vars_added; |
| 7362 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7363 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 7364 | else |
| 7365 | { |
| 7366 | if (m_using_apple_tables) |
| 7367 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 7368 | 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] | 7369 | } |
| 7370 | } |
| 7371 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7372 | } |
| 7373 | } |
| 7374 | } |
| 7375 | return vars_added; |
| 7376 | } |
| 7377 | } |
| 7378 | return 0; |
| 7379 | } |
| 7380 | |
| 7381 | |
| 7382 | VariableSP |
| 7383 | SymbolFileDWARF::ParseVariableDIE |
| 7384 | ( |
| 7385 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 7386 | DWARFCompileUnit* dwarf_cu, |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 7387 | const DWARFDebugInfoEntry *die, |
| 7388 | const lldb::addr_t func_low_pc |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7389 | ) |
| 7390 | { |
| Greg Clayton | 83c5cd9 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 7391 | VariableSP var_sp (m_die_to_variable_sp[die]); |
| 7392 | if (var_sp) |
| 7393 | return var_sp; // Already been parsed! |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7394 | |
| 7395 | const dw_tag_t tag = die->Tag(); |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 7396 | ModuleSP module = GetObjectFile()->GetModule(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7397 | |
| 7398 | if ((tag == DW_TAG_variable) || |
| 7399 | (tag == DW_TAG_constant) || |
| 7400 | (tag == DW_TAG_formal_parameter && sc.function)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7401 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7402 | DWARFDebugInfoEntry::Attributes attributes; |
| 7403 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| 7404 | if (num_attributes > 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7405 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7406 | const char *name = NULL; |
| 7407 | const char *mangled = NULL; |
| 7408 | Declaration decl; |
| 7409 | uint32_t i; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7410 | lldb::user_id_t type_uid = LLDB_INVALID_UID; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7411 | DWARFExpression location; |
| 7412 | bool is_external = false; |
| 7413 | bool is_artificial = false; |
| 7414 | bool location_is_const_value_data = false; |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7415 | bool has_explicit_location = false; |
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 7416 | DWARFFormValue const_value; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 7417 | //AccessType accessibility = eAccessNone; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7418 | |
| 7419 | for (i=0; i<num_attributes; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7420 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7421 | dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 7422 | DWARFFormValue form_value; |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 7423 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7424 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7425 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7426 | switch (attr) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7427 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7428 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 7429 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 7430 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 7431 | 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] | 7432 | case DW_AT_linkage_name: |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7433 | 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] | 7434 | case DW_AT_type: type_uid = form_value.Reference(); break; |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 7435 | case DW_AT_external: is_external = form_value.Boolean(); break; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7436 | case DW_AT_const_value: |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7437 | // If we have already found a DW_AT_location attribute, ignore this attribute. |
| 7438 | if (!has_explicit_location) |
| 7439 | { |
| 7440 | location_is_const_value_data = true; |
| 7441 | // 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] | 7442 | const DWARFDataExtractor& debug_info_data = get_debug_info_data(); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7443 | if (DWARFFormValue::IsBlockForm(form_value.Form())) |
| 7444 | { |
| 7445 | // Retrieve the value as a block expression. |
| 7446 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 7447 | uint32_t block_length = form_value.Unsigned(); |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 7448 | location.CopyOpcodeData(module, debug_info_data, block_offset, block_length); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7449 | } |
| 7450 | else if (DWARFFormValue::IsDataForm(form_value.Form())) |
| 7451 | { |
| 7452 | // Retrieve the value as a data expression. |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 7453 | 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] | 7454 | uint32_t data_offset = attributes.DIEOffsetAtIndex(i); |
| 7455 | uint32_t data_length = fixed_form_sizes[form_value.Form()]; |
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 7456 | if (data_length == 0) |
| 7457 | { |
| 7458 | const uint8_t *data_pointer = form_value.BlockData(); |
| 7459 | if (data_pointer) |
| 7460 | { |
| Jason Molenda | 18f5fd3 | 2014-10-16 07:52:17 +0000 | [diff] [blame] | 7461 | form_value.Unsigned(); |
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 7462 | } |
| 7463 | else if (DWARFFormValue::IsDataForm(form_value.Form())) |
| 7464 | { |
| 7465 | // we need to get the byte size of the type later after we create the variable |
| 7466 | const_value = form_value; |
| 7467 | } |
| 7468 | } |
| 7469 | else |
| 7470 | location.CopyOpcodeData(module, debug_info_data, data_offset, data_length); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7471 | } |
| 7472 | else |
| 7473 | { |
| 7474 | // Retrieve the value as a string expression. |
| 7475 | if (form_value.Form() == DW_FORM_strp) |
| 7476 | { |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 7477 | 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] | 7478 | uint32_t data_offset = attributes.DIEOffsetAtIndex(i); |
| 7479 | uint32_t data_length = fixed_form_sizes[form_value.Form()]; |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 7480 | location.CopyOpcodeData(module, debug_info_data, data_offset, data_length); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7481 | } |
| 7482 | else |
| 7483 | { |
| 7484 | const char *str = form_value.AsCString(&debug_info_data); |
| 7485 | uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart(); |
| 7486 | uint32_t string_length = strlen(str) + 1; |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 7487 | location.CopyOpcodeData(module, debug_info_data, string_offset, string_length); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7488 | } |
| 7489 | } |
| 7490 | } |
| 7491 | break; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7492 | case DW_AT_location: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7493 | { |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7494 | location_is_const_value_data = false; |
| 7495 | has_explicit_location = true; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7496 | if (form_value.BlockData()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7497 | { |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 7498 | const DWARFDataExtractor& debug_info_data = get_debug_info_data(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7499 | |
| 7500 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 7501 | uint32_t block_length = form_value.Unsigned(); |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 7502 | location.CopyOpcodeData(module, get_debug_info_data(), block_offset, block_length); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7503 | } |
| 7504 | else |
| 7505 | { |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 7506 | const DWARFDataExtractor& debug_loc_data = get_debug_loc_data(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7507 | const dw_offset_t debug_loc_offset = form_value.Unsigned(); |
| 7508 | |
| 7509 | size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset); |
| 7510 | if (loc_list_length > 0) |
| 7511 | { |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 7512 | location.CopyOpcodeData(module, debug_loc_data, debug_loc_offset, loc_list_length); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7513 | assert (func_low_pc != LLDB_INVALID_ADDRESS); |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 7514 | location.SetLocationListSlide (func_low_pc - attributes.CompileUnitAtIndex(i)->GetBaseAddress()); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7515 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7516 | } |
| 7517 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7518 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7519 | |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 7520 | case DW_AT_artificial: is_artificial = form_value.Boolean(); break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 7521 | 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] | 7522 | case DW_AT_declaration: |
| 7523 | case DW_AT_description: |
| 7524 | case DW_AT_endianity: |
| 7525 | case DW_AT_segment: |
| 7526 | case DW_AT_start_scope: |
| 7527 | case DW_AT_visibility: |
| 7528 | default: |
| 7529 | case DW_AT_abstract_origin: |
| 7530 | case DW_AT_sibling: |
| 7531 | case DW_AT_specification: |
| 7532 | break; |
| 7533 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7534 | } |
| 7535 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7536 | |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7537 | ValueType scope = eValueTypeInvalid; |
| 7538 | |
| 7539 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); |
| 7540 | dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
| 7541 | SymbolContextScope * symbol_context_scope = NULL; |
| 7542 | |
| Siva Chandra | 0783ab9 | 2015-03-24 18:32:27 +0000 | [diff] [blame] | 7543 | if (!mangled) |
| 7544 | { |
| 7545 | // LLDB relies on the mangled name (DW_TAG_linkage_name or DW_AT_MIPS_linkage_name) to |
| 7546 | // generate fully qualified names of global variables with commands like "frame var j". |
| 7547 | // For example, if j were an int variable holding a value 4 and declared in a namespace |
| 7548 | // B which in turn is contained in a namespace A, the command "frame var j" returns |
| 7549 | // "(int) A::B::j = 4". If the compiler does not emit a linkage name, we should be able |
| 7550 | // to generate a fully qualified name from the declaration context. |
| 7551 | if (die->GetParent()->Tag() == DW_TAG_compile_unit && |
| 7552 | LanguageRuntime::LanguageIsCPlusPlus(dwarf_cu->GetLanguageType())) |
| 7553 | { |
| 7554 | DWARFDeclContext decl_ctx; |
| 7555 | |
| 7556 | die->GetDWARFDeclContext(this, dwarf_cu, decl_ctx); |
| 7557 | mangled = decl_ctx.GetQualifiedNameAsConstString().GetCString(); |
| 7558 | } |
| 7559 | } |
| 7560 | |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7561 | // DWARF doesn't specify if a DW_TAG_variable is a local, global |
| 7562 | // or static variable, so we have to do a little digging by |
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 7563 | // looking at the location of a variable to see if it contains |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7564 | // a DW_OP_addr opcode _somewhere_ in the definition. I say |
| 7565 | // somewhere because clang likes to combine small global variables |
| 7566 | // into the same symbol and have locations like: |
| 7567 | // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus |
| 7568 | // So if we don't have a DW_TAG_formal_parameter, we can look at |
| 7569 | // the location to see if it contains a DW_OP_addr opcode, and |
| 7570 | // then we can correctly classify our variables. |
| 7571 | if (tag == DW_TAG_formal_parameter) |
| 7572 | scope = eValueTypeVariableArgument; |
| 7573 | else |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7574 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7575 | bool op_error = false; |
| 7576 | // Check if the location has a DW_OP_addr with any address value... |
| 7577 | lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS; |
| 7578 | if (!location_is_const_value_data) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7579 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7580 | location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error); |
| 7581 | if (op_error) |
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 7582 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7583 | StreamString strm; |
| 7584 | location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL); |
| 7585 | 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] | 7586 | } |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7587 | } |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7588 | |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7589 | if (location_DW_OP_addr != LLDB_INVALID_ADDRESS) |
| 7590 | { |
| 7591 | if (is_external) |
| 7592 | scope = eValueTypeVariableGlobal; |
| 7593 | else |
| 7594 | scope = eValueTypeVariableStatic; |
| 7595 | |
| 7596 | |
| 7597 | SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile (); |
| 7598 | |
| 7599 | if (debug_map_symfile) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7600 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7601 | // When leaving the DWARF in the .o files on darwin, |
| 7602 | // when we have a global variable that wasn't initialized, |
| 7603 | // the .o file might not have allocated a virtual |
| 7604 | // address for the global variable. In this case it will |
| 7605 | // have created a symbol for the global variable |
| 7606 | // that is undefined/data and external and the value will |
| 7607 | // be the byte size of the variable. When we do the |
| 7608 | // address map in SymbolFileDWARFDebugMap we rely on |
| 7609 | // having an address, we need to do some magic here |
| 7610 | // so we can get the correct address for our global |
| 7611 | // variable. The address for all of these entries |
| 7612 | // will be zero, and there will be an undefined symbol |
| 7613 | // in this object file, and the executable will have |
| 7614 | // a matching symbol with a good address. So here we |
| 7615 | // dig up the correct address and replace it in the |
| 7616 | // location for the variable, and set the variable's |
| 7617 | // symbol context scope to be that of the main executable |
| 7618 | // so the file address will resolve correctly. |
| 7619 | bool linked_oso_file_addr = false; |
| 7620 | if (is_external && location_DW_OP_addr == 0) |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7621 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7622 | // we have a possible uninitialized extern global |
| 7623 | ConstString const_name(mangled ? mangled : name); |
| 7624 | ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile(); |
| 7625 | if (debug_map_objfile) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7626 | { |
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 7627 | Symtab *debug_map_symtab = debug_map_objfile->GetSymtab(); |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7628 | if (debug_map_symtab) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7629 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7630 | Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name, |
| 7631 | eSymbolTypeData, |
| 7632 | Symtab::eDebugYes, |
| 7633 | Symtab::eVisibilityExtern); |
| 7634 | if (exe_symbol) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7635 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7636 | if (exe_symbol->ValueIsAddress()) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7637 | { |
| Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 7638 | const addr_t exe_file_addr = exe_symbol->GetAddressRef().GetFileAddress(); |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7639 | if (exe_file_addr != LLDB_INVALID_ADDRESS) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7640 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7641 | if (location.Update_DW_OP_addr (exe_file_addr)) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7642 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7643 | linked_oso_file_addr = true; |
| 7644 | symbol_context_scope = exe_symbol; |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7645 | } |
| 7646 | } |
| 7647 | } |
| 7648 | } |
| 7649 | } |
| 7650 | } |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7651 | } |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7652 | |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7653 | if (!linked_oso_file_addr) |
| 7654 | { |
| 7655 | // The DW_OP_addr is not zero, but it contains a .o file address which |
| 7656 | // needs to be linked up correctly. |
| 7657 | const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr); |
| 7658 | if (exe_file_addr != LLDB_INVALID_ADDRESS) |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7659 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7660 | // Update the file address for this variable |
| 7661 | location.Update_DW_OP_addr (exe_file_addr); |
| 7662 | } |
| 7663 | else |
| 7664 | { |
| 7665 | // Variable didn't make it into the final executable |
| 7666 | return var_sp; |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7667 | } |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7668 | } |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7669 | } |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 7670 | } |
| 7671 | else |
| 7672 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7673 | scope = eValueTypeVariableLocal; |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 7674 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7675 | } |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7676 | |
| 7677 | if (symbol_context_scope == NULL) |
| 7678 | { |
| 7679 | switch (parent_tag) |
| 7680 | { |
| 7681 | case DW_TAG_subprogram: |
| 7682 | case DW_TAG_inlined_subroutine: |
| 7683 | case DW_TAG_lexical_block: |
| 7684 | if (sc.function) |
| 7685 | { |
| 7686 | symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); |
| 7687 | if (symbol_context_scope == NULL) |
| 7688 | symbol_context_scope = sc.function; |
| 7689 | } |
| 7690 | break; |
| 7691 | |
| 7692 | default: |
| 7693 | symbol_context_scope = sc.comp_unit; |
| 7694 | break; |
| 7695 | } |
| 7696 | } |
| 7697 | |
| 7698 | if (symbol_context_scope) |
| 7699 | { |
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 7700 | SymbolFileTypeSP type_sp(new SymbolFileType(*this, type_uid)); |
| 7701 | |
| 7702 | if (const_value.Form() && type_sp && type_sp->GetType()) |
| 7703 | location.CopyOpcodeData(const_value.Unsigned(), type_sp->GetType()->GetByteSize(), dwarf_cu->GetAddressByteSize()); |
| 7704 | |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7705 | var_sp.reset (new Variable (MakeUserID(die->GetOffset()), |
| 7706 | name, |
| 7707 | mangled, |
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 7708 | type_sp, |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7709 | scope, |
| 7710 | symbol_context_scope, |
| 7711 | &decl, |
| 7712 | location, |
| 7713 | is_external, |
| 7714 | is_artificial)); |
| 7715 | |
| 7716 | var_sp->SetLocationIsConstantValueData (location_is_const_value_data); |
| 7717 | } |
| 7718 | else |
| 7719 | { |
| 7720 | // Not ready to parse this variable yet. It might be a global |
| 7721 | // or static variable that is in a function scope and the function |
| 7722 | // in the symbol context wasn't filled in yet |
| 7723 | return var_sp; |
| 7724 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7725 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7726 | // Cache var_sp even if NULL (the variable was just a specification or |
| 7727 | // was missing vital information to be able to be displayed in the debugger |
| 7728 | // (missing location due to optimization, etc)) so we don't re-parse |
| 7729 | // this DIE over and over later... |
| 7730 | m_die_to_variable_sp[die] = var_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7731 | } |
| 7732 | return var_sp; |
| 7733 | } |
| 7734 | |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7735 | |
| 7736 | const DWARFDebugInfoEntry * |
| 7737 | SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset, |
| 7738 | dw_offset_t spec_block_die_offset, |
| 7739 | DWARFCompileUnit **result_die_cu_handle) |
| 7740 | { |
| 7741 | // Give the concrete function die specified by "func_die_offset", find the |
| 7742 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points |
| 7743 | // to "spec_block_die_offset" |
| 7744 | DWARFDebugInfo* info = DebugInfo(); |
| 7745 | |
| 7746 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle); |
| 7747 | if (die) |
| 7748 | { |
| 7749 | assert (*result_die_cu_handle); |
| 7750 | return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle); |
| 7751 | } |
| 7752 | return NULL; |
| 7753 | } |
| 7754 | |
| 7755 | |
| 7756 | const DWARFDebugInfoEntry * |
| 7757 | SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu, |
| 7758 | const DWARFDebugInfoEntry *die, |
| 7759 | dw_offset_t spec_block_die_offset, |
| 7760 | DWARFCompileUnit **result_die_cu_handle) |
| 7761 | { |
| 7762 | if (die) |
| 7763 | { |
| 7764 | switch (die->Tag()) |
| 7765 | { |
| 7766 | case DW_TAG_subprogram: |
| 7767 | case DW_TAG_inlined_subroutine: |
| 7768 | case DW_TAG_lexical_block: |
| 7769 | { |
| 7770 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset) |
| 7771 | { |
| 7772 | *result_die_cu_handle = dwarf_cu; |
| 7773 | return die; |
| 7774 | } |
| 7775 | |
| 7776 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset) |
| 7777 | { |
| 7778 | *result_die_cu_handle = dwarf_cu; |
| 7779 | return die; |
| 7780 | } |
| 7781 | } |
| 7782 | break; |
| 7783 | } |
| 7784 | |
| 7785 | // Give the concrete function die specified by "func_die_offset", find the |
| 7786 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points |
| 7787 | // to "spec_block_die_offset" |
| 7788 | for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling()) |
| 7789 | { |
| 7790 | const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu, |
| 7791 | child_die, |
| 7792 | spec_block_die_offset, |
| 7793 | result_die_cu_handle); |
| 7794 | if (result_die) |
| 7795 | return result_die; |
| 7796 | } |
| 7797 | } |
| 7798 | |
| 7799 | *result_die_cu_handle = NULL; |
| 7800 | return NULL; |
| 7801 | } |
| 7802 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7803 | size_t |
| 7804 | SymbolFileDWARF::ParseVariables |
| 7805 | ( |
| 7806 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 7807 | DWARFCompileUnit* dwarf_cu, |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 7808 | const lldb::addr_t func_low_pc, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7809 | const DWARFDebugInfoEntry *orig_die, |
| 7810 | bool parse_siblings, |
| 7811 | bool parse_children, |
| 7812 | VariableList* cc_variable_list |
| 7813 | ) |
| 7814 | { |
| 7815 | if (orig_die == NULL) |
| 7816 | return 0; |
| 7817 | |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7818 | VariableListSP variable_list_sp; |
| 7819 | |
| 7820 | size_t vars_added = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7821 | const DWARFDebugInfoEntry *die = orig_die; |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7822 | while (die != NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7823 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7824 | dw_tag_t tag = die->Tag(); |
| 7825 | |
| 7826 | // Check to see if we have already parsed this variable or constant? |
| 7827 | if (m_die_to_variable_sp[die]) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7828 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7829 | if (cc_variable_list) |
| 7830 | cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7831 | } |
| 7832 | else |
| 7833 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7834 | // We haven't already parsed it, lets do that now. |
| 7835 | if ((tag == DW_TAG_variable) || |
| 7836 | (tag == DW_TAG_constant) || |
| 7837 | (tag == DW_TAG_formal_parameter && sc.function)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7838 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7839 | if (variable_list_sp.get() == NULL) |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7840 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7841 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die); |
| 7842 | dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
| 7843 | switch (parent_tag) |
| 7844 | { |
| 7845 | case DW_TAG_compile_unit: |
| 7846 | if (sc.comp_unit != NULL) |
| 7847 | { |
| 7848 | variable_list_sp = sc.comp_unit->GetVariableList(false); |
| 7849 | if (variable_list_sp.get() == NULL) |
| 7850 | { |
| 7851 | variable_list_sp.reset(new VariableList()); |
| 7852 | sc.comp_unit->SetVariableList(variable_list_sp); |
| 7853 | } |
| 7854 | } |
| 7855 | else |
| 7856 | { |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 7857 | 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] | 7858 | MakeUserID(sc_parent_die->GetOffset()), |
| 7859 | DW_TAG_value_to_name (parent_tag), |
| 7860 | MakeUserID(orig_die->GetOffset()), |
| 7861 | DW_TAG_value_to_name (orig_die->Tag())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7862 | } |
| 7863 | break; |
| 7864 | |
| 7865 | case DW_TAG_subprogram: |
| 7866 | case DW_TAG_inlined_subroutine: |
| 7867 | case DW_TAG_lexical_block: |
| 7868 | if (sc.function != NULL) |
| 7869 | { |
| 7870 | // Check to see if we already have parsed the variables for the given scope |
| 7871 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7872 | Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7873 | if (block == NULL) |
| 7874 | { |
| 7875 | // This must be a specification or abstract origin with |
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 7876 | // a concrete block counterpart in the current function. We need |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7877 | // to find the concrete block so we can correctly add the |
| 7878 | // variable to it |
| 7879 | DWARFCompileUnit *concrete_block_die_cu = dwarf_cu; |
| 7880 | const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(), |
| 7881 | sc_parent_die->GetOffset(), |
| 7882 | &concrete_block_die_cu); |
| 7883 | if (concrete_block_die) |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7884 | block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7885 | } |
| 7886 | |
| 7887 | if (block != NULL) |
| 7888 | { |
| 7889 | const bool can_create = false; |
| 7890 | variable_list_sp = block->GetBlockVariableList (can_create); |
| 7891 | if (variable_list_sp.get() == NULL) |
| 7892 | { |
| 7893 | variable_list_sp.reset(new VariableList()); |
| 7894 | block->SetVariableList(variable_list_sp); |
| 7895 | } |
| 7896 | } |
| 7897 | } |
| 7898 | break; |
| 7899 | |
| 7900 | default: |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 7901 | 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] | 7902 | MakeUserID(orig_die->GetOffset()), |
| 7903 | DW_TAG_value_to_name (orig_die->Tag())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7904 | break; |
| 7905 | } |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7906 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7907 | |
| 7908 | if (variable_list_sp) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7909 | { |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7910 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc)); |
| 7911 | if (var_sp) |
| 7912 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7913 | variable_list_sp->AddVariableIfUnique (var_sp); |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7914 | if (cc_variable_list) |
| 7915 | cc_variable_list->AddVariableIfUnique (var_sp); |
| 7916 | ++vars_added; |
| 7917 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7918 | } |
| 7919 | } |
| 7920 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7921 | |
| 7922 | bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram); |
| 7923 | |
| 7924 | if (!skip_children && parse_children && die->HasChildren()) |
| 7925 | { |
| 7926 | vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list); |
| 7927 | } |
| 7928 | |
| 7929 | if (parse_siblings) |
| 7930 | die = die->GetSibling(); |
| 7931 | else |
| 7932 | die = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7933 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7934 | return vars_added; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7935 | } |
| 7936 | |
| 7937 | //------------------------------------------------------------------ |
| 7938 | // PluginInterface protocol |
| 7939 | //------------------------------------------------------------------ |
| Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 7940 | ConstString |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7941 | SymbolFileDWARF::GetPluginName() |
| 7942 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7943 | return GetPluginNameStatic(); |
| 7944 | } |
| 7945 | |
| 7946 | uint32_t |
| 7947 | SymbolFileDWARF::GetPluginVersion() |
| 7948 | { |
| 7949 | return 1; |
| 7950 | } |
| 7951 | |
| 7952 | void |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 7953 | SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl) |
| 7954 | { |
| 7955 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 7956 | ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 7957 | if (clang_type) |
| 7958 | symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); |
| 7959 | } |
| 7960 | |
| 7961 | void |
| 7962 | SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl) |
| 7963 | { |
| 7964 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 7965 | ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 7966 | if (clang_type) |
| 7967 | symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); |
| 7968 | } |
| 7969 | |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7970 | void |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7971 | SymbolFileDWARF::DumpIndexes () |
| 7972 | { |
| 7973 | StreamFile s(stdout, false); |
| 7974 | |
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 7975 | s.Printf ("DWARF index for (%s) '%s':", |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7976 | GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(), |
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 7977 | GetObjectFile()->GetFileSpec().GetPath().c_str()); |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7978 | s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s); |
| 7979 | s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s); |
| 7980 | s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s); |
| 7981 | s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s); |
| 7982 | s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s); |
| 7983 | s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s); |
| 7984 | s.Printf("\nTypes:\n"); m_type_index.Dump (&s); |
| 7985 | s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s); |
| 7986 | } |
| 7987 | |
| 7988 | void |
| 7989 | SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context, |
| 7990 | const char *name, |
| 7991 | llvm::SmallVectorImpl <clang::NamedDecl *> *results) |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7992 | { |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7993 | DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context); |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7994 | |
| 7995 | if (iter == m_decl_ctx_to_die.end()) |
| 7996 | return; |
| 7997 | |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7998 | 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] | 7999 | { |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 8000 | const DWARFDebugInfoEntry *context_die = *pos; |
| 8001 | |
| 8002 | if (!results) |
| 8003 | return; |
| 8004 | |
| 8005 | DWARFDebugInfo* info = DebugInfo(); |
| 8006 | |
| 8007 | DIEArray die_offsets; |
| 8008 | |
| 8009 | DWARFCompileUnit* dwarf_cu = NULL; |
| 8010 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 8011 | |
| 8012 | if (m_using_apple_tables) |
| 8013 | { |
| 8014 | if (m_apple_types_ap.get()) |
| 8015 | m_apple_types_ap->FindByName (name, die_offsets); |
| 8016 | } |
| 8017 | else |
| 8018 | { |
| 8019 | if (!m_indexed) |
| 8020 | Index (); |
| 8021 | |
| 8022 | m_type_index.Find (ConstString(name), die_offsets); |
| 8023 | } |
| 8024 | |
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 8025 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 8026 | |
| 8027 | if (num_matches) |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 8028 | { |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 8029 | for (size_t i = 0; i < num_matches; ++i) |
| 8030 | { |
| 8031 | const dw_offset_t die_offset = die_offsets[i]; |
| 8032 | die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 8033 | |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 8034 | if (die->GetParent() != context_die) |
| 8035 | continue; |
| 8036 | |
| 8037 | Type *matching_type = ResolveType (dwarf_cu, die); |
| 8038 | |
| Pavel Labath | c7c30eb | 2015-06-08 23:38:06 +0000 | [diff] [blame] | 8039 | clang::QualType qual_type = matching_type->GetClangForwardType().GetQualType(); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 8040 | |
| 8041 | if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr())) |
| 8042 | { |
| 8043 | clang::TagDecl *tag_decl = tag_type->getDecl(); |
| 8044 | results->push_back(tag_decl); |
| 8045 | } |
| 8046 | else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr())) |
| 8047 | { |
| 8048 | clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl(); |
| 8049 | results->push_back(typedef_decl); |
| 8050 | } |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 8051 | } |
| 8052 | } |
| 8053 | } |
| 8054 | } |
| 8055 | |
| 8056 | void |
| 8057 | SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton, |
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 8058 | const clang::DeclContext *decl_context, |
| 8059 | clang::DeclarationName decl_name, |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 8060 | llvm::SmallVectorImpl <clang::NamedDecl *> *results) |
| 8061 | { |
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 8062 | |
| 8063 | switch (decl_context->getDeclKind()) |
| 8064 | { |
| 8065 | case clang::Decl::Namespace: |
| 8066 | case clang::Decl::TranslationUnit: |
| 8067 | { |
| 8068 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 8069 | symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results); |
| 8070 | } |
| 8071 | break; |
| 8072 | default: |
| 8073 | break; |
| 8074 | } |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 8075 | } |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 8076 | |
| Zachary Turner | 504f38d | 2015-03-24 16:24:50 +0000 | [diff] [blame] | 8077 | bool |
| 8078 | SymbolFileDWARF::LayoutRecordType(void *baton, const clang::RecordDecl *record_decl, uint64_t &size, |
| 8079 | uint64_t &alignment, |
| Zachary Turner | a98fac2 | 2015-03-24 18:56:08 +0000 | [diff] [blame] | 8080 | llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets, |
| 8081 | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, |
| 8082 | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 8083 | { |
| 8084 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 8085 | return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets); |
| 8086 | } |
| 8087 | |
| Zachary Turner | 504f38d | 2015-03-24 16:24:50 +0000 | [diff] [blame] | 8088 | bool |
| 8089 | SymbolFileDWARF::LayoutRecordType(const clang::RecordDecl *record_decl, uint64_t &bit_size, uint64_t &alignment, |
| Zachary Turner | a98fac2 | 2015-03-24 18:56:08 +0000 | [diff] [blame] | 8090 | llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets, |
| 8091 | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, |
| 8092 | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 8093 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 8094 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 8095 | RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl); |
| 8096 | bool success = false; |
| 8097 | base_offsets.clear(); |
| 8098 | vbase_offsets.clear(); |
| 8099 | if (pos != m_record_decl_to_layout_map.end()) |
| 8100 | { |
| 8101 | bit_size = pos->second.bit_size; |
| 8102 | alignment = pos->second.alignment; |
| 8103 | field_offsets.swap(pos->second.field_offsets); |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 8104 | base_offsets.swap (pos->second.base_offsets); |
| 8105 | vbase_offsets.swap (pos->second.vbase_offsets); |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 8106 | m_record_decl_to_layout_map.erase(pos); |
| 8107 | success = true; |
| 8108 | } |
| 8109 | else |
| 8110 | { |
| 8111 | bit_size = 0; |
| 8112 | alignment = 0; |
| 8113 | field_offsets.clear(); |
| 8114 | } |
| 8115 | |
| 8116 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 8117 | GetObjectFile()->GetModule()->LogMessage (log, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 8118 | "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] | 8119 | static_cast<const void*>(record_decl), |
| 8120 | bit_size, alignment, |
| 8121 | static_cast<uint32_t>(field_offsets.size()), |
| 8122 | static_cast<uint32_t>(base_offsets.size()), |
| 8123 | static_cast<uint32_t>(vbase_offsets.size()), |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 8124 | success); |
| 8125 | return success; |
| 8126 | } |
| 8127 | |
| 8128 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 8129 | SymbolFileDWARFDebugMap * |
| 8130 | SymbolFileDWARF::GetDebugMapSymfile () |
| 8131 | { |
| 8132 | if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired()) |
| 8133 | { |
| 8134 | lldb::ModuleSP module_sp (m_debug_map_module_wp.lock()); |
| 8135 | if (module_sp) |
| 8136 | { |
| 8137 | SymbolVendor *sym_vendor = module_sp->GetSymbolVendor(); |
| 8138 | if (sym_vendor) |
| 8139 | m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile(); |
| 8140 | } |
| 8141 | } |
| 8142 | return m_debug_map_symfile; |
| 8143 | } |
| 8144 | |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 8145 | |