| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- SymbolFileDWARF.cpp ------------------------------------*- C++ -*-===// | 
|  | 2 | // | 
|  | 3 | //                     The LLVM Compiler Infrastructure | 
|  | 4 | // | 
|  | 5 | // This file is distributed under the University of Illinois Open Source | 
|  | 6 | // License. See LICENSE.TXT for details. | 
|  | 7 | // | 
|  | 8 | //===----------------------------------------------------------------------===// | 
|  | 9 |  | 
|  | 10 | #include "SymbolFileDWARF.h" | 
|  | 11 |  | 
|  | 12 | // Other libraries and framework includes | 
|  | 13 | #include "clang/AST/ASTConsumer.h" | 
|  | 14 | #include "clang/AST/ASTContext.h" | 
|  | 15 | #include "clang/AST/Decl.h" | 
|  | 16 | #include "clang/AST/DeclGroup.h" | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclObjC.h" | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclTemplate.h" | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | #include "clang/Basic/Builtins.h" | 
|  | 20 | #include "clang/Basic/IdentifierTable.h" | 
|  | 21 | #include "clang/Basic/LangOptions.h" | 
|  | 22 | #include "clang/Basic/SourceManager.h" | 
|  | 23 | #include "clang/Basic/TargetInfo.h" | 
|  | 24 | #include "clang/Basic/Specifiers.h" | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 25 | #include "clang/Sema/DeclSpec.h" | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 26 |  | 
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 27 | #include "llvm/Support/Casting.h" | 
|  | 28 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | #include "lldb/Core/Module.h" | 
|  | 30 | #include "lldb/Core/PluginManager.h" | 
|  | 31 | #include "lldb/Core/RegularExpression.h" | 
|  | 32 | #include "lldb/Core/Scalar.h" | 
|  | 33 | #include "lldb/Core/Section.h" | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 34 | #include "lldb/Core/StreamFile.h" | 
| Jim Ingham | 318c9f2 | 2011-08-26 19:44:13 +0000 | [diff] [blame] | 35 | #include "lldb/Core/StreamString.h" | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 36 | #include "lldb/Core/Timer.h" | 
|  | 37 | #include "lldb/Core/Value.h" | 
|  | 38 |  | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 39 | #include "lldb/Host/Host.h" | 
|  | 40 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 41 | #include "lldb/Symbol/Block.h" | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 42 | #include "lldb/Symbol/ClangExternalASTSourceCallbacks.h" | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | #include "lldb/Symbol/CompileUnit.h" | 
|  | 44 | #include "lldb/Symbol/LineTable.h" | 
|  | 45 | #include "lldb/Symbol/ObjectFile.h" | 
|  | 46 | #include "lldb/Symbol/SymbolVendor.h" | 
|  | 47 | #include "lldb/Symbol/VariableList.h" | 
|  | 48 |  | 
| Jim Ingham | b7f6b2f | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 49 | #include "lldb/Target/ObjCLanguageRuntime.h" | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 50 | #include "lldb/Target/CPPLanguageRuntime.h" | 
| Jim Ingham | b7f6b2f | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 51 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 52 | #include "DWARFCompileUnit.h" | 
|  | 53 | #include "DWARFDebugAbbrev.h" | 
|  | 54 | #include "DWARFDebugAranges.h" | 
|  | 55 | #include "DWARFDebugInfo.h" | 
|  | 56 | #include "DWARFDebugInfoEntry.h" | 
|  | 57 | #include "DWARFDebugLine.h" | 
|  | 58 | #include "DWARFDebugPubnames.h" | 
|  | 59 | #include "DWARFDebugRanges.h" | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 60 | #include "DWARFDeclContext.h" | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 61 | #include "DWARFDIECollection.h" | 
|  | 62 | #include "DWARFFormValue.h" | 
|  | 63 | #include "DWARFLocationList.h" | 
|  | 64 | #include "LogChannelDWARF.h" | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 65 | #include "SymbolFileDWARFDebugMap.h" | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 66 |  | 
|  | 67 | #include <map> | 
|  | 68 |  | 
| Greg Clayton | 62742b1 | 2010-11-11 01:09:45 +0000 | [diff] [blame] | 69 | //#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 70 |  | 
|  | 71 | #ifdef ENABLE_DEBUG_PRINTF | 
|  | 72 | #include <stdio.h> | 
|  | 73 | #define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__) | 
|  | 74 | #else | 
|  | 75 | #define DEBUG_PRINTF(fmt, ...) | 
|  | 76 | #endif | 
|  | 77 |  | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 78 | #define DIE_IS_BEING_PARSED ((lldb_private::Type*)1) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 79 |  | 
|  | 80 | using namespace lldb; | 
|  | 81 | using namespace lldb_private; | 
|  | 82 |  | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 83 | //static inline bool | 
|  | 84 | //child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag) | 
|  | 85 | //{ | 
|  | 86 | //    switch (tag) | 
|  | 87 | //    { | 
|  | 88 | //    default: | 
|  | 89 | //        break; | 
|  | 90 | //    case DW_TAG_subprogram: | 
|  | 91 | //    case DW_TAG_inlined_subroutine: | 
|  | 92 | //    case DW_TAG_class_type: | 
|  | 93 | //    case DW_TAG_structure_type: | 
|  | 94 | //    case DW_TAG_union_type: | 
|  | 95 | //        return true; | 
|  | 96 | //    } | 
|  | 97 | //    return false; | 
|  | 98 | //} | 
|  | 99 | // | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 100 | static AccessType | 
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 101 | DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 102 | { | 
|  | 103 | switch (dwarf_accessibility) | 
|  | 104 | { | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 105 | case DW_ACCESS_public:      return eAccessPublic; | 
|  | 106 | case DW_ACCESS_private:     return eAccessPrivate; | 
|  | 107 | case DW_ACCESS_protected:   return eAccessProtected; | 
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 108 | default:                    break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 109 | } | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 110 | return eAccessNone; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 111 | } | 
|  | 112 |  | 
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 113 | #if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE) | 
|  | 114 |  | 
|  | 115 | class DIEStack | 
|  | 116 | { | 
|  | 117 | public: | 
|  | 118 |  | 
|  | 119 | void Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) | 
|  | 120 | { | 
|  | 121 | m_dies.push_back (DIEInfo(cu, die)); | 
|  | 122 | } | 
|  | 123 |  | 
|  | 124 |  | 
|  | 125 | void LogDIEs (Log *log, SymbolFileDWARF *dwarf) | 
|  | 126 | { | 
|  | 127 | StreamString log_strm; | 
|  | 128 | const size_t n = m_dies.size(); | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 129 | log_strm.Printf("DIEStack[%" PRIu64 "]:\n", (uint64_t)n); | 
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 130 | for (size_t i=0; i<n; i++) | 
|  | 131 | { | 
|  | 132 | DWARFCompileUnit *cu = m_dies[i].cu; | 
|  | 133 | const DWARFDebugInfoEntry *die = m_dies[i].die; | 
|  | 134 | std::string qualified_name; | 
|  | 135 | die->GetQualifiedName(dwarf, cu, qualified_name); | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 136 | log_strm.Printf ("[%" PRIu64 "] 0x%8.8x: %s name='%s'\n", | 
| Greg Clayton | 43e0af0 | 2012-09-18 18:04:04 +0000 | [diff] [blame] | 137 | (uint64_t)i, | 
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 138 | die->GetOffset(), | 
|  | 139 | DW_TAG_value_to_name(die->Tag()), | 
|  | 140 | qualified_name.c_str()); | 
|  | 141 | } | 
|  | 142 | log->PutCString(log_strm.GetData()); | 
|  | 143 | } | 
|  | 144 | void Pop () | 
|  | 145 | { | 
|  | 146 | m_dies.pop_back(); | 
|  | 147 | } | 
|  | 148 |  | 
|  | 149 | class ScopedPopper | 
|  | 150 | { | 
|  | 151 | public: | 
|  | 152 | ScopedPopper (DIEStack &die_stack) : | 
|  | 153 | m_die_stack (die_stack), | 
|  | 154 | m_valid (false) | 
|  | 155 | { | 
|  | 156 | } | 
|  | 157 |  | 
|  | 158 | void | 
|  | 159 | Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) | 
|  | 160 | { | 
|  | 161 | m_valid = true; | 
|  | 162 | m_die_stack.Push (cu, die); | 
|  | 163 | } | 
|  | 164 |  | 
|  | 165 | ~ScopedPopper () | 
|  | 166 | { | 
|  | 167 | if (m_valid) | 
|  | 168 | m_die_stack.Pop(); | 
|  | 169 | } | 
|  | 170 |  | 
|  | 171 |  | 
|  | 172 |  | 
|  | 173 | protected: | 
|  | 174 | DIEStack &m_die_stack; | 
|  | 175 | bool m_valid; | 
|  | 176 | }; | 
|  | 177 |  | 
|  | 178 | protected: | 
|  | 179 | struct DIEInfo { | 
|  | 180 | DIEInfo (DWARFCompileUnit *c, const DWARFDebugInfoEntry *d) : | 
|  | 181 | cu(c), | 
|  | 182 | die(d) | 
|  | 183 | { | 
|  | 184 | } | 
|  | 185 | DWARFCompileUnit *cu; | 
|  | 186 | const DWARFDebugInfoEntry *die; | 
|  | 187 | }; | 
|  | 188 | typedef std::vector<DIEInfo> Stack; | 
|  | 189 | Stack m_dies; | 
|  | 190 | }; | 
|  | 191 | #endif | 
|  | 192 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 193 | void | 
|  | 194 | SymbolFileDWARF::Initialize() | 
|  | 195 | { | 
|  | 196 | LogChannelDWARF::Initialize(); | 
|  | 197 | PluginManager::RegisterPlugin (GetPluginNameStatic(), | 
|  | 198 | GetPluginDescriptionStatic(), | 
|  | 199 | CreateInstance); | 
|  | 200 | } | 
|  | 201 |  | 
|  | 202 | void | 
|  | 203 | SymbolFileDWARF::Terminate() | 
|  | 204 | { | 
|  | 205 | PluginManager::UnregisterPlugin (CreateInstance); | 
|  | 206 | LogChannelDWARF::Initialize(); | 
|  | 207 | } | 
|  | 208 |  | 
|  | 209 |  | 
| Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 210 | lldb_private::ConstString | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 211 | SymbolFileDWARF::GetPluginNameStatic() | 
|  | 212 | { | 
| Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 213 | static ConstString g_name("dwarf"); | 
|  | 214 | return g_name; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 215 | } | 
|  | 216 |  | 
|  | 217 | const char * | 
|  | 218 | SymbolFileDWARF::GetPluginDescriptionStatic() | 
|  | 219 | { | 
|  | 220 | return "DWARF and DWARF3 debug symbol file reader."; | 
|  | 221 | } | 
|  | 222 |  | 
|  | 223 |  | 
|  | 224 | SymbolFile* | 
|  | 225 | SymbolFileDWARF::CreateInstance (ObjectFile* obj_file) | 
|  | 226 | { | 
|  | 227 | return new SymbolFileDWARF(obj_file); | 
|  | 228 | } | 
|  | 229 |  | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 230 | TypeList * | 
|  | 231 | SymbolFileDWARF::GetTypeList () | 
|  | 232 | { | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 233 | if (GetDebugMapSymfile ()) | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 234 | return m_debug_map_symfile->GetTypeList(); | 
|  | 235 | return m_obj_file->GetModule()->GetTypeList(); | 
|  | 236 |  | 
|  | 237 | } | 
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 238 | void | 
|  | 239 | SymbolFileDWARF::GetTypes (DWARFCompileUnit* cu, | 
|  | 240 | const DWARFDebugInfoEntry *die, | 
|  | 241 | dw_offset_t min_die_offset, | 
|  | 242 | dw_offset_t max_die_offset, | 
|  | 243 | uint32_t type_mask, | 
|  | 244 | TypeSet &type_set) | 
|  | 245 | { | 
|  | 246 | if (cu) | 
|  | 247 | { | 
|  | 248 | if (die) | 
|  | 249 | { | 
|  | 250 | const dw_offset_t die_offset = die->GetOffset(); | 
|  | 251 |  | 
|  | 252 | if (die_offset >= max_die_offset) | 
|  | 253 | return; | 
|  | 254 |  | 
|  | 255 | if (die_offset >= min_die_offset) | 
|  | 256 | { | 
|  | 257 | const dw_tag_t tag = die->Tag(); | 
|  | 258 |  | 
|  | 259 | bool add_type = false; | 
|  | 260 |  | 
|  | 261 | switch (tag) | 
|  | 262 | { | 
|  | 263 | case DW_TAG_array_type:         add_type = (type_mask & eTypeClassArray         ) != 0; break; | 
|  | 264 | case DW_TAG_unspecified_type: | 
|  | 265 | case DW_TAG_base_type:          add_type = (type_mask & eTypeClassBuiltin       ) != 0; break; | 
|  | 266 | case DW_TAG_class_type:         add_type = (type_mask & eTypeClassClass         ) != 0; break; | 
|  | 267 | case DW_TAG_structure_type:     add_type = (type_mask & eTypeClassStruct        ) != 0; break; | 
|  | 268 | case DW_TAG_union_type:         add_type = (type_mask & eTypeClassUnion         ) != 0; break; | 
|  | 269 | case DW_TAG_enumeration_type:   add_type = (type_mask & eTypeClassEnumeration   ) != 0; break; | 
|  | 270 | case DW_TAG_subroutine_type: | 
|  | 271 | case DW_TAG_subprogram: | 
|  | 272 | case DW_TAG_inlined_subroutine: add_type = (type_mask & eTypeClassFunction      ) != 0; break; | 
|  | 273 | case DW_TAG_pointer_type:       add_type = (type_mask & eTypeClassPointer       ) != 0; break; | 
|  | 274 | case DW_TAG_rvalue_reference_type: | 
|  | 275 | case DW_TAG_reference_type:     add_type = (type_mask & eTypeClassReference     ) != 0; break; | 
|  | 276 | case DW_TAG_typedef:            add_type = (type_mask & eTypeClassTypedef       ) != 0; break; | 
|  | 277 | case DW_TAG_ptr_to_member_type: add_type = (type_mask & eTypeClassMemberPointer ) != 0; break; | 
|  | 278 | } | 
|  | 279 |  | 
|  | 280 | if (add_type) | 
|  | 281 | { | 
|  | 282 | const bool assert_not_being_parsed = true; | 
|  | 283 | Type *type = ResolveTypeUID (cu, die, assert_not_being_parsed); | 
|  | 284 | if (type) | 
|  | 285 | { | 
|  | 286 | if (type_set.find(type) == type_set.end()) | 
|  | 287 | type_set.insert(type); | 
|  | 288 | } | 
|  | 289 | } | 
|  | 290 | } | 
|  | 291 |  | 
|  | 292 | for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); | 
|  | 293 | child_die != NULL; | 
|  | 294 | child_die = child_die->GetSibling()) | 
|  | 295 | { | 
|  | 296 | GetTypes (cu, child_die, min_die_offset, max_die_offset, type_mask, type_set); | 
|  | 297 | } | 
|  | 298 | } | 
|  | 299 | } | 
|  | 300 | } | 
|  | 301 |  | 
|  | 302 | size_t | 
|  | 303 | SymbolFileDWARF::GetTypes (SymbolContextScope *sc_scope, | 
|  | 304 | uint32_t type_mask, | 
|  | 305 | TypeList &type_list) | 
|  | 306 |  | 
|  | 307 | { | 
|  | 308 | TypeSet type_set; | 
|  | 309 |  | 
|  | 310 | CompileUnit *comp_unit = NULL; | 
|  | 311 | DWARFCompileUnit* dwarf_cu = NULL; | 
|  | 312 | if (sc_scope) | 
|  | 313 | comp_unit = sc_scope->CalculateSymbolContextCompileUnit(); | 
|  | 314 |  | 
|  | 315 | if (comp_unit) | 
|  | 316 | { | 
|  | 317 | dwarf_cu = GetDWARFCompileUnit(comp_unit); | 
|  | 318 | if (dwarf_cu == 0) | 
|  | 319 | return 0; | 
|  | 320 | GetTypes (dwarf_cu, | 
|  | 321 | dwarf_cu->DIE(), | 
|  | 322 | dwarf_cu->GetOffset(), | 
|  | 323 | dwarf_cu->GetNextCompileUnitOffset(), | 
|  | 324 | type_mask, | 
|  | 325 | type_set); | 
|  | 326 | } | 
|  | 327 | else | 
|  | 328 | { | 
|  | 329 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 330 | if (info) | 
|  | 331 | { | 
|  | 332 | const size_t num_cus = info->GetNumCompileUnits(); | 
|  | 333 | for (size_t cu_idx=0; cu_idx<num_cus; ++cu_idx) | 
|  | 334 | { | 
|  | 335 | dwarf_cu = info->GetCompileUnitAtIndex(cu_idx); | 
|  | 336 | if (dwarf_cu) | 
|  | 337 | { | 
|  | 338 | GetTypes (dwarf_cu, | 
|  | 339 | dwarf_cu->DIE(), | 
|  | 340 | 0, | 
|  | 341 | UINT32_MAX, | 
|  | 342 | type_mask, | 
|  | 343 | type_set); | 
|  | 344 | } | 
|  | 345 | } | 
|  | 346 | } | 
|  | 347 | } | 
|  | 348 | //    if (m_using_apple_tables) | 
|  | 349 | //    { | 
|  | 350 | //        DWARFMappedHash::MemoryTable *apple_types = m_apple_types_ap.get(); | 
|  | 351 | //        if (apple_types) | 
|  | 352 | //        { | 
|  | 353 | //            apple_types->ForEach([this, &type_set, apple_types, type_mask](const DWARFMappedHash::DIEInfoArray &die_info_array) -> bool { | 
|  | 354 | // | 
|  | 355 | //                for (auto die_info: die_info_array) | 
|  | 356 | //                { | 
|  | 357 | //                    bool add_type = TagMatchesTypeMask (type_mask, 0); | 
|  | 358 | //                    if (!add_type) | 
|  | 359 | //                    { | 
|  | 360 | //                        dw_tag_t tag = die_info.tag; | 
|  | 361 | //                        if (tag == 0) | 
|  | 362 | //                        { | 
|  | 363 | //                            const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_info.offset, NULL); | 
|  | 364 | //                            tag = die->Tag(); | 
|  | 365 | //                        } | 
|  | 366 | //                        add_type = TagMatchesTypeMask (type_mask, tag); | 
|  | 367 | //                    } | 
|  | 368 | //                    if (add_type) | 
|  | 369 | //                    { | 
|  | 370 | //                        Type *type = ResolveTypeUID(die_info.offset); | 
|  | 371 | // | 
|  | 372 | //                        if (type_set.find(type) == type_set.end()) | 
|  | 373 | //                            type_set.insert(type); | 
|  | 374 | //                    } | 
|  | 375 | //                } | 
|  | 376 | //                return true; // Keep iterating | 
|  | 377 | //            }); | 
|  | 378 | //        } | 
|  | 379 | //    } | 
|  | 380 | //    else | 
|  | 381 | //    { | 
|  | 382 | //        if (!m_indexed) | 
|  | 383 | //            Index (); | 
|  | 384 | // | 
|  | 385 | //        m_type_index.ForEach([this, &type_set, type_mask](const char *name, uint32_t die_offset) -> bool { | 
|  | 386 | // | 
|  | 387 | //            bool add_type = TagMatchesTypeMask (type_mask, 0); | 
|  | 388 | // | 
|  | 389 | //            if (!add_type) | 
|  | 390 | //            { | 
|  | 391 | //                const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_offset, NULL); | 
|  | 392 | //                if (die) | 
|  | 393 | //                { | 
|  | 394 | //                    const dw_tag_t tag = die->Tag(); | 
|  | 395 | //                    add_type = TagMatchesTypeMask (type_mask, tag); | 
|  | 396 | //                } | 
|  | 397 | //            } | 
|  | 398 | // | 
|  | 399 | //            if (add_type) | 
|  | 400 | //            { | 
|  | 401 | //                Type *type = ResolveTypeUID(die_offset); | 
|  | 402 | // | 
|  | 403 | //                if (type_set.find(type) == type_set.end()) | 
|  | 404 | //                    type_set.insert(type); | 
|  | 405 | //            } | 
|  | 406 | //            return true; // Keep iterating | 
|  | 407 | //        }); | 
|  | 408 | //    } | 
|  | 409 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 410 | std::set<ClangASTType> clang_type_set; | 
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 411 | size_t num_types_added = 0; | 
|  | 412 | for (Type *type : type_set) | 
|  | 413 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 414 | ClangASTType clang_type = type->GetClangForwardType(); | 
| Greg Clayton | 0fc4f31 | 2013-06-20 01:23:18 +0000 | [diff] [blame] | 415 | if (clang_type_set.find(clang_type) == clang_type_set.end()) | 
|  | 416 | { | 
|  | 417 | clang_type_set.insert(clang_type); | 
|  | 418 | type_list.Insert (type->shared_from_this()); | 
|  | 419 | ++num_types_added; | 
|  | 420 | } | 
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 421 | } | 
|  | 422 | return num_types_added; | 
|  | 423 | } | 
|  | 424 |  | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 425 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 426 | //---------------------------------------------------------------------- | 
|  | 427 | // Gets the first parent that is a lexical block, function or inlined | 
|  | 428 | // subroutine, or compile unit. | 
|  | 429 | //---------------------------------------------------------------------- | 
|  | 430 | static const DWARFDebugInfoEntry * | 
|  | 431 | GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die) | 
|  | 432 | { | 
|  | 433 | const DWARFDebugInfoEntry *die; | 
|  | 434 | for (die = child_die->GetParent(); die != NULL; die = die->GetParent()) | 
|  | 435 | { | 
|  | 436 | dw_tag_t tag = die->Tag(); | 
|  | 437 |  | 
|  | 438 | switch (tag) | 
|  | 439 | { | 
|  | 440 | case DW_TAG_compile_unit: | 
|  | 441 | case DW_TAG_subprogram: | 
|  | 442 | case DW_TAG_inlined_subroutine: | 
|  | 443 | case DW_TAG_lexical_block: | 
|  | 444 | return die; | 
|  | 445 | } | 
|  | 446 | } | 
|  | 447 | return NULL; | 
|  | 448 | } | 
|  | 449 |  | 
|  | 450 |  | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 451 | SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) : | 
|  | 452 | SymbolFile (objfile), | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 453 | 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] | 454 | m_debug_map_module_wp (), | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 455 | m_debug_map_symfile (NULL), | 
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 456 | m_clang_tu_decl (NULL), | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 457 | m_flags(), | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 458 | m_data_debug_abbrev (), | 
|  | 459 | m_data_debug_aranges (), | 
|  | 460 | m_data_debug_frame (), | 
|  | 461 | m_data_debug_info (), | 
|  | 462 | m_data_debug_line (), | 
|  | 463 | m_data_debug_loc (), | 
|  | 464 | m_data_debug_ranges (), | 
|  | 465 | m_data_debug_str (), | 
| Greg Clayton | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 466 | m_data_apple_names (), | 
|  | 467 | m_data_apple_types (), | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 468 | m_data_apple_namespaces (), | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 469 | m_abbr(), | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 470 | m_info(), | 
|  | 471 | m_line(), | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 472 | m_apple_names_ap (), | 
|  | 473 | m_apple_types_ap (), | 
|  | 474 | m_apple_namespaces_ap (), | 
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 475 | m_apple_objc_ap (), | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 476 | m_function_basename_index(), | 
|  | 477 | m_function_fullname_index(), | 
|  | 478 | m_function_method_index(), | 
|  | 479 | m_function_selector_index(), | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 480 | m_objc_class_selectors_index(), | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 481 | m_global_index(), | 
| Greg Clayton | 69b0488 | 2010-10-15 02:03:22 +0000 | [diff] [blame] | 482 | m_type_index(), | 
|  | 483 | m_namespace_index(), | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 484 | m_indexed (false), | 
|  | 485 | m_is_external_ast_source (false), | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 486 | m_using_apple_tables (false), | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 487 | m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate), | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 488 | m_ranges(), | 
|  | 489 | m_unique_ast_type_map () | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 490 | { | 
|  | 491 | } | 
|  | 492 |  | 
|  | 493 | SymbolFileDWARF::~SymbolFileDWARF() | 
|  | 494 | { | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 495 | if (m_is_external_ast_source) | 
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 496 | { | 
|  | 497 | ModuleSP module_sp (m_obj_file->GetModule()); | 
|  | 498 | if (module_sp) | 
|  | 499 | module_sp->GetClangASTContext().RemoveExternalSource (); | 
|  | 500 | } | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 501 | } | 
|  | 502 |  | 
|  | 503 | static const ConstString & | 
|  | 504 | GetDWARFMachOSegmentName () | 
|  | 505 | { | 
|  | 506 | static ConstString g_dwarf_section_name ("__DWARF"); | 
|  | 507 | return g_dwarf_section_name; | 
|  | 508 | } | 
|  | 509 |  | 
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 510 | UniqueDWARFASTTypeMap & | 
|  | 511 | SymbolFileDWARF::GetUniqueDWARFASTTypeMap () | 
|  | 512 | { | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 513 | if (GetDebugMapSymfile ()) | 
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 514 | return m_debug_map_symfile->GetUniqueDWARFASTTypeMap (); | 
|  | 515 | return m_unique_ast_type_map; | 
|  | 516 | } | 
|  | 517 |  | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 518 | ClangASTContext & | 
|  | 519 | SymbolFileDWARF::GetClangASTContext () | 
|  | 520 | { | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 521 | if (GetDebugMapSymfile ()) | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 522 | return m_debug_map_symfile->GetClangASTContext (); | 
|  | 523 |  | 
|  | 524 | ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext(); | 
|  | 525 | if (!m_is_external_ast_source) | 
|  | 526 | { | 
|  | 527 | m_is_external_ast_source = true; | 
|  | 528 | llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap ( | 
|  | 529 | new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl, | 
|  | 530 | SymbolFileDWARF::CompleteObjCInterfaceDecl, | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 531 | SymbolFileDWARF::FindExternalVisibleDeclsByName, | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 532 | SymbolFileDWARF::LayoutRecordType, | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 533 | this)); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 534 | ast.SetExternalSource (ast_source_ap); | 
|  | 535 | } | 
|  | 536 | return ast; | 
|  | 537 | } | 
|  | 538 |  | 
|  | 539 | void | 
|  | 540 | SymbolFileDWARF::InitializeObject() | 
|  | 541 | { | 
|  | 542 | // Install our external AST source callbacks so we can complete Clang types. | 
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 543 | ModuleSP module_sp (m_obj_file->GetModule()); | 
|  | 544 | if (module_sp) | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 545 | { | 
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 546 | const SectionList *section_list = module_sp->GetSectionList(); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 547 |  | 
|  | 548 | const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get(); | 
|  | 549 |  | 
|  | 550 | // Memory map the DWARF mach-o segment so we have everything mmap'ed | 
|  | 551 | // to keep our heap memory usage down. | 
|  | 552 | if (section) | 
| Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 553 | m_obj_file->MemoryMapSectionData(section, m_dwarf_data); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 554 | } | 
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 555 | get_apple_names_data(); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 556 | if (m_data_apple_names.GetByteSize() > 0) | 
|  | 557 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 558 | m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names")); | 
|  | 559 | if (m_apple_names_ap->IsValid()) | 
|  | 560 | m_using_apple_tables = true; | 
|  | 561 | else | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 562 | m_apple_names_ap.reset(); | 
|  | 563 | } | 
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 564 | get_apple_types_data(); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 565 | if (m_data_apple_types.GetByteSize() > 0) | 
|  | 566 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 567 | m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types")); | 
|  | 568 | if (m_apple_types_ap->IsValid()) | 
|  | 569 | m_using_apple_tables = true; | 
|  | 570 | else | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 571 | m_apple_types_ap.reset(); | 
|  | 572 | } | 
|  | 573 |  | 
|  | 574 | get_apple_namespaces_data(); | 
|  | 575 | if (m_data_apple_namespaces.GetByteSize() > 0) | 
|  | 576 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 577 | m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces")); | 
|  | 578 | if (m_apple_namespaces_ap->IsValid()) | 
|  | 579 | m_using_apple_tables = true; | 
|  | 580 | else | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 581 | m_apple_namespaces_ap.reset(); | 
|  | 582 | } | 
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 583 |  | 
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 584 | get_apple_objc_data(); | 
|  | 585 | if (m_data_apple_objc.GetByteSize() > 0) | 
|  | 586 | { | 
|  | 587 | m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc")); | 
|  | 588 | if (m_apple_objc_ap->IsValid()) | 
|  | 589 | m_using_apple_tables = true; | 
|  | 590 | else | 
|  | 591 | m_apple_objc_ap.reset(); | 
|  | 592 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 593 | } | 
|  | 594 |  | 
|  | 595 | bool | 
|  | 596 | SymbolFileDWARF::SupportedVersion(uint16_t version) | 
|  | 597 | { | 
| Greg Clayton | abcbfe5 | 2013-04-04 00:00:36 +0000 | [diff] [blame] | 598 | return version == 2 || version == 3 || version == 4; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 599 | } | 
|  | 600 |  | 
|  | 601 | uint32_t | 
| Sean Callanan | bfaf54d | 2011-12-03 04:38:43 +0000 | [diff] [blame] | 602 | SymbolFileDWARF::CalculateAbilities () | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 603 | { | 
|  | 604 | uint32_t abilities = 0; | 
|  | 605 | if (m_obj_file != NULL) | 
|  | 606 | { | 
|  | 607 | const Section* section = NULL; | 
|  | 608 | const SectionList *section_list = m_obj_file->GetSectionList(); | 
|  | 609 | if (section_list == NULL) | 
|  | 610 | return 0; | 
|  | 611 |  | 
|  | 612 | uint64_t debug_abbrev_file_size = 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 613 | uint64_t debug_info_file_size = 0; | 
|  | 614 | uint64_t debug_line_file_size = 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 615 |  | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 616 | section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 617 |  | 
|  | 618 | if (section) | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 619 | section_list = §ion->GetChildren (); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 620 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 621 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 622 | if (section != NULL) | 
|  | 623 | { | 
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 624 | debug_info_file_size = section->GetFileSize(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 625 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 626 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 627 | if (section) | 
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 628 | debug_abbrev_file_size = section->GetFileSize(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 629 | else | 
|  | 630 | m_flags.Set (flagsGotDebugAbbrevData); | 
|  | 631 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 632 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get(); | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 633 | if (!section) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 634 | m_flags.Set (flagsGotDebugArangesData); | 
|  | 635 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 636 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get(); | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 637 | if (!section) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 638 | m_flags.Set (flagsGotDebugFrameData); | 
|  | 639 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 640 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 641 | if (section) | 
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 642 | debug_line_file_size = section->GetFileSize(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 643 | else | 
|  | 644 | m_flags.Set (flagsGotDebugLineData); | 
|  | 645 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 646 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get(); | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 647 | if (!section) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 648 | m_flags.Set (flagsGotDebugLocData); | 
|  | 649 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 650 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get(); | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 651 | if (!section) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 652 | m_flags.Set (flagsGotDebugMacInfoData); | 
|  | 653 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 654 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get(); | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 655 | if (!section) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 656 | m_flags.Set (flagsGotDebugPubNamesData); | 
|  | 657 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 658 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get(); | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 659 | if (!section) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 660 | m_flags.Set (flagsGotDebugPubTypesData); | 
|  | 661 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 662 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get(); | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 663 | if (!section) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 664 | m_flags.Set (flagsGotDebugRangesData); | 
|  | 665 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 666 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get(); | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 667 | if (!section) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 668 | m_flags.Set (flagsGotDebugStrData); | 
|  | 669 | } | 
| Greg Clayton | 6c59661 | 2012-05-18 21:47:20 +0000 | [diff] [blame] | 670 | else | 
|  | 671 | { | 
|  | 672 | const char *symfile_dir_cstr = m_obj_file->GetFileSpec().GetDirectory().GetCString(); | 
|  | 673 | if (symfile_dir_cstr) | 
|  | 674 | { | 
|  | 675 | if (strcasestr(symfile_dir_cstr, ".dsym")) | 
|  | 676 | { | 
|  | 677 | if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo) | 
|  | 678 | { | 
|  | 679 | // We have a dSYM file that didn't have a any debug info. | 
|  | 680 | // If the string table has a size of 1, then it was made from | 
|  | 681 | // an executable with no debug info, or from an executable that | 
|  | 682 | // was stripped. | 
|  | 683 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get(); | 
|  | 684 | if (section && section->GetFileSize() == 1) | 
|  | 685 | { | 
|  | 686 | m_obj_file->GetModule()->ReportWarning ("empty dSYM file detected, dSYM was created with an executable with no debug info."); | 
|  | 687 | } | 
|  | 688 | } | 
|  | 689 | } | 
|  | 690 | } | 
|  | 691 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 692 |  | 
|  | 693 | if (debug_abbrev_file_size > 0 && debug_info_file_size > 0) | 
|  | 694 | abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes; | 
|  | 695 |  | 
|  | 696 | if (debug_line_file_size > 0) | 
|  | 697 | abilities |= LineTables; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 698 | } | 
|  | 699 | return abilities; | 
|  | 700 | } | 
|  | 701 |  | 
|  | 702 | const DataExtractor& | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 703 | SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 704 | { | 
|  | 705 | if (m_flags.IsClear (got_flag)) | 
|  | 706 | { | 
| Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 707 | ModuleSP module_sp (m_obj_file->GetModule()); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 708 | m_flags.Set (got_flag); | 
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 709 | const SectionList *section_list = module_sp->GetSectionList(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 710 | if (section_list) | 
|  | 711 | { | 
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 712 | SectionSP section_sp (section_list->FindSectionByType(sect_type, true)); | 
|  | 713 | if (section_sp) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 714 | { | 
|  | 715 | // See if we memory mapped the DWARF segment? | 
|  | 716 | if (m_dwarf_data.GetByteSize()) | 
|  | 717 | { | 
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 718 | data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetFileSize()); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 719 | } | 
|  | 720 | else | 
|  | 721 | { | 
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 722 | if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 723 | data.Clear(); | 
|  | 724 | } | 
|  | 725 | } | 
|  | 726 | } | 
|  | 727 | } | 
|  | 728 | return data; | 
|  | 729 | } | 
|  | 730 |  | 
|  | 731 | const DataExtractor& | 
|  | 732 | SymbolFileDWARF::get_debug_abbrev_data() | 
|  | 733 | { | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 734 | return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 735 | } | 
|  | 736 |  | 
|  | 737 | const DataExtractor& | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 738 | SymbolFileDWARF::get_debug_aranges_data() | 
|  | 739 | { | 
|  | 740 | return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges); | 
|  | 741 | } | 
|  | 742 |  | 
|  | 743 | const DataExtractor& | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 744 | SymbolFileDWARF::get_debug_frame_data() | 
|  | 745 | { | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 746 | return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 747 | } | 
|  | 748 |  | 
|  | 749 | const DataExtractor& | 
|  | 750 | SymbolFileDWARF::get_debug_info_data() | 
|  | 751 | { | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 752 | return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 753 | } | 
|  | 754 |  | 
|  | 755 | const DataExtractor& | 
|  | 756 | SymbolFileDWARF::get_debug_line_data() | 
|  | 757 | { | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 758 | return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 759 | } | 
|  | 760 |  | 
|  | 761 | const DataExtractor& | 
|  | 762 | SymbolFileDWARF::get_debug_loc_data() | 
|  | 763 | { | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 764 | return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 765 | } | 
|  | 766 |  | 
|  | 767 | const DataExtractor& | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 768 | SymbolFileDWARF::get_debug_ranges_data() | 
|  | 769 | { | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 770 | return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 771 | } | 
|  | 772 |  | 
|  | 773 | const DataExtractor& | 
|  | 774 | SymbolFileDWARF::get_debug_str_data() | 
|  | 775 | { | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 776 | return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 777 | } | 
|  | 778 |  | 
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 779 | const DataExtractor& | 
| Greg Clayton | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 780 | SymbolFileDWARF::get_apple_names_data() | 
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 781 | { | 
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 782 | return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names); | 
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 783 | } | 
|  | 784 |  | 
|  | 785 | const DataExtractor& | 
| Greg Clayton | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 786 | SymbolFileDWARF::get_apple_types_data() | 
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 787 | { | 
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 788 | return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types); | 
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 789 | } | 
|  | 790 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 791 | const DataExtractor& | 
|  | 792 | SymbolFileDWARF::get_apple_namespaces_data() | 
|  | 793 | { | 
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 794 | return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces); | 
|  | 795 | } | 
|  | 796 |  | 
|  | 797 | const DataExtractor& | 
|  | 798 | SymbolFileDWARF::get_apple_objc_data() | 
|  | 799 | { | 
|  | 800 | return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 801 | } | 
|  | 802 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 803 |  | 
|  | 804 | DWARFDebugAbbrev* | 
|  | 805 | SymbolFileDWARF::DebugAbbrev() | 
|  | 806 | { | 
|  | 807 | if (m_abbr.get() == NULL) | 
|  | 808 | { | 
|  | 809 | const DataExtractor &debug_abbrev_data = get_debug_abbrev_data(); | 
|  | 810 | if (debug_abbrev_data.GetByteSize() > 0) | 
|  | 811 | { | 
|  | 812 | m_abbr.reset(new DWARFDebugAbbrev()); | 
|  | 813 | if (m_abbr.get()) | 
|  | 814 | m_abbr->Parse(debug_abbrev_data); | 
|  | 815 | } | 
|  | 816 | } | 
|  | 817 | return m_abbr.get(); | 
|  | 818 | } | 
|  | 819 |  | 
|  | 820 | const DWARFDebugAbbrev* | 
|  | 821 | SymbolFileDWARF::DebugAbbrev() const | 
|  | 822 | { | 
|  | 823 | return m_abbr.get(); | 
|  | 824 | } | 
|  | 825 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 826 |  | 
|  | 827 | DWARFDebugInfo* | 
|  | 828 | SymbolFileDWARF::DebugInfo() | 
|  | 829 | { | 
|  | 830 | if (m_info.get() == NULL) | 
|  | 831 | { | 
|  | 832 | Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this); | 
|  | 833 | if (get_debug_info_data().GetByteSize() > 0) | 
|  | 834 | { | 
|  | 835 | m_info.reset(new DWARFDebugInfo()); | 
|  | 836 | if (m_info.get()) | 
|  | 837 | { | 
|  | 838 | m_info->SetDwarfData(this); | 
|  | 839 | } | 
|  | 840 | } | 
|  | 841 | } | 
|  | 842 | return m_info.get(); | 
|  | 843 | } | 
|  | 844 |  | 
|  | 845 | const DWARFDebugInfo* | 
|  | 846 | SymbolFileDWARF::DebugInfo() const | 
|  | 847 | { | 
|  | 848 | return m_info.get(); | 
|  | 849 | } | 
|  | 850 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 851 | DWARFCompileUnit* | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 852 | SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 853 | { | 
|  | 854 | DWARFDebugInfo* info = DebugInfo(); | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 855 | if (info) | 
|  | 856 | { | 
|  | 857 | if (GetDebugMapSymfile ()) | 
|  | 858 | { | 
|  | 859 | // The debug map symbol file made the compile units for this DWARF | 
|  | 860 | // file which is .o file with DWARF in it, and we should have | 
|  | 861 | // only 1 compile unit which is at offset zero in the DWARF. | 
|  | 862 | // TODO: modify to support LTO .o files where each .o file might | 
|  | 863 | // have multiple DW_TAG_compile_unit tags. | 
|  | 864 | return info->GetCompileUnit(0).get(); | 
|  | 865 | } | 
|  | 866 | else | 
|  | 867 | { | 
|  | 868 | // Just a normal DWARF file whose user ID for the compile unit is | 
|  | 869 | // the DWARF offset itself | 
|  | 870 | return info->GetCompileUnit((dw_offset_t)comp_unit->GetID()).get(); | 
|  | 871 | } | 
|  | 872 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 873 | return NULL; | 
|  | 874 | } | 
|  | 875 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 876 |  | 
|  | 877 | DWARFDebugRanges* | 
|  | 878 | SymbolFileDWARF::DebugRanges() | 
|  | 879 | { | 
|  | 880 | if (m_ranges.get() == NULL) | 
|  | 881 | { | 
|  | 882 | Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this); | 
|  | 883 | if (get_debug_ranges_data().GetByteSize() > 0) | 
|  | 884 | { | 
|  | 885 | m_ranges.reset(new DWARFDebugRanges()); | 
|  | 886 | if (m_ranges.get()) | 
|  | 887 | m_ranges->Extract(this); | 
|  | 888 | } | 
|  | 889 | } | 
|  | 890 | return m_ranges.get(); | 
|  | 891 | } | 
|  | 892 |  | 
|  | 893 | const DWARFDebugRanges* | 
|  | 894 | SymbolFileDWARF::DebugRanges() const | 
|  | 895 | { | 
|  | 896 | return m_ranges.get(); | 
|  | 897 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 898 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 899 | lldb::CompUnitSP | 
|  | 900 | SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 901 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 902 | CompUnitSP cu_sp; | 
|  | 903 | if (dwarf_cu) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 904 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 905 | CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData(); | 
|  | 906 | if (comp_unit) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 907 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 908 | // We already parsed this compile unit, had out a shared pointer to it | 
|  | 909 | cu_sp = comp_unit->shared_from_this(); | 
|  | 910 | } | 
|  | 911 | else | 
|  | 912 | { | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 913 | if (GetDebugMapSymfile ()) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 914 | { | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 915 | // Let the debug map create the compile unit | 
|  | 916 | cu_sp = m_debug_map_symfile->GetCompileUnit(this); | 
|  | 917 | dwarf_cu->SetUserData(cu_sp.get()); | 
|  | 918 | } | 
|  | 919 | else | 
|  | 920 | { | 
|  | 921 | ModuleSP module_sp (m_obj_file->GetModule()); | 
|  | 922 | if (module_sp) | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 923 | { | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 924 | const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly (); | 
|  | 925 | if (cu_die) | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 926 | { | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 927 | const char * cu_die_name = cu_die->GetName(this, dwarf_cu); | 
|  | 928 | const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL); | 
|  | 929 | LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0); | 
|  | 930 | if (cu_die_name) | 
|  | 931 | { | 
|  | 932 | std::string ramapped_file; | 
|  | 933 | FileSpec cu_file_spec; | 
| Jim Ingham | 0909e5f | 2010-09-16 00:57:33 +0000 | [diff] [blame] | 934 |  | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 935 | if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0') | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 936 | { | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 937 | // If we have a full path to the compile unit, we don't need to resolve | 
|  | 938 | // the file.  This can be expensive e.g. when the source files are NFS mounted. | 
|  | 939 | if (module_sp->RemapSourceFile(cu_die_name, ramapped_file)) | 
|  | 940 | cu_file_spec.SetFile (ramapped_file.c_str(), false); | 
|  | 941 | else | 
|  | 942 | cu_file_spec.SetFile (cu_die_name, false); | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 943 | } | 
|  | 944 | else | 
|  | 945 | { | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 946 | std::string fullpath(cu_comp_dir); | 
|  | 947 | if (*fullpath.rbegin() != '/') | 
|  | 948 | fullpath += '/'; | 
|  | 949 | fullpath += cu_die_name; | 
|  | 950 | if (module_sp->RemapSourceFile (fullpath.c_str(), ramapped_file)) | 
|  | 951 | cu_file_spec.SetFile (ramapped_file.c_str(), false); | 
|  | 952 | else | 
|  | 953 | cu_file_spec.SetFile (fullpath.c_str(), false); | 
|  | 954 | } | 
|  | 955 |  | 
|  | 956 | cu_sp.reset(new CompileUnit (module_sp, | 
|  | 957 | dwarf_cu, | 
|  | 958 | cu_file_spec, | 
|  | 959 | MakeUserID(dwarf_cu->GetOffset()), | 
|  | 960 | cu_language)); | 
|  | 961 | if (cu_sp) | 
|  | 962 | { | 
|  | 963 | dwarf_cu->SetUserData(cu_sp.get()); | 
|  | 964 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 965 | // Figure out the compile unit index if we weren't given one | 
|  | 966 | if (cu_idx == UINT32_MAX) | 
|  | 967 | DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx); | 
|  | 968 |  | 
|  | 969 | m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp); | 
|  | 970 | } | 
|  | 971 | } | 
|  | 972 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 973 | } | 
|  | 974 | } | 
|  | 975 | } | 
|  | 976 | } | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 977 | return cu_sp; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 978 | } | 
|  | 979 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 980 | uint32_t | 
|  | 981 | SymbolFileDWARF::GetNumCompileUnits() | 
|  | 982 | { | 
|  | 983 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 984 | if (info) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 985 | return info->GetNumCompileUnits(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 986 | return 0; | 
|  | 987 | } | 
|  | 988 |  | 
|  | 989 | CompUnitSP | 
|  | 990 | SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx) | 
|  | 991 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 992 | CompUnitSP cu_sp; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 993 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 994 | if (info) | 
|  | 995 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 996 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx); | 
|  | 997 | if (dwarf_cu) | 
|  | 998 | cu_sp = ParseCompileUnit(dwarf_cu, cu_idx); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 999 | } | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1000 | return cu_sp; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1001 | } | 
|  | 1002 |  | 
|  | 1003 | static void | 
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1004 | AddRangesToBlock (Block& block, | 
|  | 1005 | DWARFDebugRanges::RangeList& ranges, | 
|  | 1006 | addr_t block_base_addr) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1007 | { | 
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1008 | const size_t num_ranges = ranges.GetSize(); | 
|  | 1009 | for (size_t i = 0; i<num_ranges; ++i) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1010 | { | 
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1011 | const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i); | 
|  | 1012 | const addr_t range_base = range.GetRangeBase(); | 
|  | 1013 | assert (range_base >= block_base_addr); | 
|  | 1014 | block.AddRange(Block::Range (range_base - block_base_addr, range.GetByteSize()));; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1015 | } | 
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1016 | block.FinalizeRanges (); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1017 | } | 
|  | 1018 |  | 
|  | 1019 |  | 
|  | 1020 | Function * | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1021 | SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1022 | { | 
|  | 1023 | DWARFDebugRanges::RangeList func_ranges; | 
|  | 1024 | const char *name = NULL; | 
|  | 1025 | const char *mangled = NULL; | 
|  | 1026 | int decl_file = 0; | 
|  | 1027 | int decl_line = 0; | 
|  | 1028 | int decl_column = 0; | 
|  | 1029 | int call_file = 0; | 
|  | 1030 | int call_line = 0; | 
|  | 1031 | int call_column = 0; | 
|  | 1032 | DWARFExpression frame_base; | 
|  | 1033 |  | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1034 | assert (die->Tag() == DW_TAG_subprogram); | 
|  | 1035 |  | 
|  | 1036 | if (die->Tag() != DW_TAG_subprogram) | 
|  | 1037 | return NULL; | 
|  | 1038 |  | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1039 | if (die->GetDIENamesAndRanges (this, | 
|  | 1040 | dwarf_cu, | 
|  | 1041 | name, | 
|  | 1042 | mangled, | 
|  | 1043 | func_ranges, | 
|  | 1044 | decl_file, | 
|  | 1045 | decl_line, | 
|  | 1046 | decl_column, | 
|  | 1047 | call_file, | 
|  | 1048 | call_line, | 
|  | 1049 | call_column, | 
|  | 1050 | &frame_base)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1051 | { | 
|  | 1052 | // Union of all ranges in the function DIE (if the function is discontiguous) | 
|  | 1053 | AddressRange func_range; | 
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1054 | lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0); | 
|  | 1055 | lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1056 | if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr) | 
|  | 1057 | { | 
| Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1058 | ModuleSP module_sp (m_obj_file->GetModule()); | 
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 1059 | func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, module_sp->GetSectionList()); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1060 | if (func_range.GetBaseAddress().IsValid()) | 
|  | 1061 | func_range.SetByteSize(highest_func_addr - lowest_func_addr); | 
|  | 1062 | } | 
|  | 1063 |  | 
|  | 1064 | if (func_range.GetBaseAddress().IsValid()) | 
|  | 1065 | { | 
|  | 1066 | Mangled func_name; | 
|  | 1067 | if (mangled) | 
| Greg Clayton | 037520e | 2012-07-18 23:18:10 +0000 | [diff] [blame] | 1068 | func_name.SetValue(ConstString(mangled), true); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1069 | else if (name) | 
| Greg Clayton | 037520e | 2012-07-18 23:18:10 +0000 | [diff] [blame] | 1070 | func_name.SetValue(ConstString(name), false); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1071 |  | 
|  | 1072 | FunctionSP func_sp; | 
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1073 | std::unique_ptr<Declaration> decl_ap; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1074 | if (decl_file != 0 || decl_line != 0 || decl_column != 0) | 
| Greg Clayton | d7e0546 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 1075 | decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), | 
|  | 1076 | decl_line, | 
|  | 1077 | decl_column)); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1078 |  | 
| Greg Clayton | 0bd4e1b | 2011-09-30 20:52:25 +0000 | [diff] [blame] | 1079 | // Supply the type _only_ if it has already been parsed | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 1080 | Type *func_type = m_die_to_type.lookup (die); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1081 |  | 
|  | 1082 | assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED); | 
|  | 1083 |  | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1084 | if (FixupAddress (func_range.GetBaseAddress())) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1085 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1086 | const user_id_t func_user_id = MakeUserID(die->GetOffset()); | 
|  | 1087 | func_sp.reset(new Function (sc.comp_unit, | 
|  | 1088 | MakeUserID(func_user_id),       // UserID is the DIE offset | 
|  | 1089 | MakeUserID(func_user_id), | 
|  | 1090 | func_name, | 
|  | 1091 | func_type, | 
|  | 1092 | func_range));           // first address range | 
|  | 1093 |  | 
|  | 1094 | if (func_sp.get() != NULL) | 
|  | 1095 | { | 
|  | 1096 | if (frame_base.IsValid()) | 
|  | 1097 | func_sp->GetFrameBaseExpression() = frame_base; | 
|  | 1098 | sc.comp_unit->AddFunction(func_sp); | 
|  | 1099 | return func_sp.get(); | 
|  | 1100 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1101 | } | 
|  | 1102 | } | 
|  | 1103 | } | 
|  | 1104 | return NULL; | 
|  | 1105 | } | 
|  | 1106 |  | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1107 | bool | 
|  | 1108 | SymbolFileDWARF::FixupAddress (Address &addr) | 
|  | 1109 | { | 
|  | 1110 | SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile (); | 
|  | 1111 | if (debug_map_symfile) | 
|  | 1112 | { | 
|  | 1113 | return debug_map_symfile->LinkOSOAddress(addr); | 
|  | 1114 | } | 
|  | 1115 | // This is a normal DWARF file, no address fixups need to happen | 
|  | 1116 | return true; | 
|  | 1117 | } | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1118 | lldb::LanguageType | 
|  | 1119 | SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc) | 
|  | 1120 | { | 
|  | 1121 | assert (sc.comp_unit); | 
|  | 1122 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); | 
|  | 1123 | if (dwarf_cu) | 
|  | 1124 | { | 
|  | 1125 | const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly(); | 
| Jim Ingham | 28eb571 | 2012-10-12 17:34:26 +0000 | [diff] [blame] | 1126 | if (die) | 
|  | 1127 | { | 
|  | 1128 | const uint32_t language = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0); | 
|  | 1129 | if (language) | 
|  | 1130 | return (lldb::LanguageType)language; | 
|  | 1131 | } | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1132 | } | 
|  | 1133 | return eLanguageTypeUnknown; | 
|  | 1134 | } | 
|  | 1135 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1136 | size_t | 
|  | 1137 | SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc) | 
|  | 1138 | { | 
|  | 1139 | assert (sc.comp_unit); | 
|  | 1140 | size_t functions_added = 0; | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1141 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1142 | if (dwarf_cu) | 
|  | 1143 | { | 
|  | 1144 | DWARFDIECollection function_dies; | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1145 | 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] | 1146 | size_t func_idx; | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1147 | for (func_idx = 0; func_idx < num_functions; ++func_idx) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1148 | { | 
|  | 1149 | const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx); | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1150 | if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1151 | { | 
|  | 1152 | if (ParseCompileUnitFunction(sc, dwarf_cu, die)) | 
|  | 1153 | ++functions_added; | 
|  | 1154 | } | 
|  | 1155 | } | 
|  | 1156 | //FixupTypes(); | 
|  | 1157 | } | 
|  | 1158 | return functions_added; | 
|  | 1159 | } | 
|  | 1160 |  | 
|  | 1161 | bool | 
|  | 1162 | SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files) | 
|  | 1163 | { | 
|  | 1164 | assert (sc.comp_unit); | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1165 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); | 
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1166 | if (dwarf_cu) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1167 | { | 
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1168 | const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1169 |  | 
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1170 | if (cu_die) | 
|  | 1171 | { | 
|  | 1172 | const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL); | 
|  | 1173 | 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] | 1174 |  | 
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1175 | // All file indexes in DWARF are one based and a file of index zero is | 
|  | 1176 | // supposed to be the compile unit itself. | 
|  | 1177 | support_files.Append (*sc.comp_unit); | 
|  | 1178 |  | 
|  | 1179 | return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files); | 
|  | 1180 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1181 | } | 
|  | 1182 | return false; | 
|  | 1183 | } | 
|  | 1184 |  | 
|  | 1185 | struct ParseDWARFLineTableCallbackInfo | 
|  | 1186 | { | 
|  | 1187 | LineTable* line_table; | 
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1188 | std::unique_ptr<LineSequence> sequence_ap; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1189 | }; | 
|  | 1190 |  | 
|  | 1191 | //---------------------------------------------------------------------- | 
|  | 1192 | // ParseStatementTableCallback | 
|  | 1193 | //---------------------------------------------------------------------- | 
|  | 1194 | static void | 
|  | 1195 | ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData) | 
|  | 1196 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1197 | if (state.row == DWARFDebugLine::State::StartParsingLineTable) | 
|  | 1198 | { | 
|  | 1199 | // Just started parsing the line table | 
|  | 1200 | } | 
|  | 1201 | else if (state.row == DWARFDebugLine::State::DoneParsingLineTable) | 
|  | 1202 | { | 
|  | 1203 | // Done parsing line table, nothing to do for the cleanup | 
|  | 1204 | } | 
|  | 1205 | else | 
|  | 1206 | { | 
|  | 1207 | ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData; | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1208 | LineTable* line_table = info->line_table; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1209 |  | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1210 | // If this is our first time here, we need to create a | 
|  | 1211 | // sequence container. | 
|  | 1212 | if (!info->sequence_ap.get()) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1213 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1214 | info->sequence_ap.reset(line_table->CreateLineSequenceContainer()); | 
|  | 1215 | assert(info->sequence_ap.get()); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1216 | } | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1217 | line_table->AppendLineEntryToSequence (info->sequence_ap.get(), | 
|  | 1218 | state.address, | 
|  | 1219 | state.line, | 
|  | 1220 | state.column, | 
|  | 1221 | state.file, | 
|  | 1222 | state.is_stmt, | 
|  | 1223 | state.basic_block, | 
|  | 1224 | state.prologue_end, | 
|  | 1225 | state.epilogue_begin, | 
|  | 1226 | state.end_sequence); | 
|  | 1227 | if (state.end_sequence) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1228 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1229 | // First, put the current sequence into the line table. | 
|  | 1230 | line_table->InsertSequence(info->sequence_ap.get()); | 
|  | 1231 | // Then, empty it to prepare for the next sequence. | 
|  | 1232 | info->sequence_ap->Clear(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1233 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1234 | } | 
|  | 1235 | } | 
|  | 1236 |  | 
|  | 1237 | bool | 
|  | 1238 | SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc) | 
|  | 1239 | { | 
|  | 1240 | assert (sc.comp_unit); | 
|  | 1241 | if (sc.comp_unit->GetLineTable() != NULL) | 
|  | 1242 | return true; | 
|  | 1243 |  | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1244 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1245 | if (dwarf_cu) | 
|  | 1246 | { | 
|  | 1247 | const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly(); | 
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1248 | if (dwarf_cu_die) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1249 | { | 
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1250 | const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET); | 
|  | 1251 | if (cu_line_offset != DW_INVALID_OFFSET) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1252 | { | 
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1253 | std::unique_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit)); | 
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1254 | if (line_table_ap.get()) | 
|  | 1255 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1256 | ParseDWARFLineTableCallbackInfo info; | 
|  | 1257 | info.line_table = line_table_ap.get(); | 
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1258 | lldb::offset_t offset = cu_line_offset; | 
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1259 | DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info); | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1260 | if (m_debug_map_symfile) | 
|  | 1261 | { | 
|  | 1262 | // We have an object file that has a line table with addresses | 
|  | 1263 | // that are not linked. We need to link the line table and convert | 
|  | 1264 | // the addresses that are relative to the .o file into addresses | 
|  | 1265 | // for the main executable. | 
|  | 1266 | sc.comp_unit->SetLineTable (m_debug_map_symfile->LinkOSOLineTable (this, line_table_ap.get())); | 
|  | 1267 | } | 
|  | 1268 | else | 
|  | 1269 | { | 
|  | 1270 | sc.comp_unit->SetLineTable(line_table_ap.release()); | 
|  | 1271 | return true; | 
|  | 1272 | } | 
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1273 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1274 | } | 
|  | 1275 | } | 
|  | 1276 | } | 
|  | 1277 | return false; | 
|  | 1278 | } | 
|  | 1279 |  | 
|  | 1280 | size_t | 
|  | 1281 | SymbolFileDWARF::ParseFunctionBlocks | 
|  | 1282 | ( | 
|  | 1283 | const SymbolContext& sc, | 
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1284 | Block *parent_block, | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1285 | DWARFCompileUnit* dwarf_cu, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1286 | const DWARFDebugInfoEntry *die, | 
|  | 1287 | addr_t subprogram_low_pc, | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1288 | uint32_t depth | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1289 | ) | 
|  | 1290 | { | 
|  | 1291 | size_t blocks_added = 0; | 
|  | 1292 | while (die != NULL) | 
|  | 1293 | { | 
|  | 1294 | dw_tag_t tag = die->Tag(); | 
|  | 1295 |  | 
|  | 1296 | switch (tag) | 
|  | 1297 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1298 | case DW_TAG_inlined_subroutine: | 
| Greg Clayton | b4d3733 | 2011-08-12 16:22:48 +0000 | [diff] [blame] | 1299 | case DW_TAG_subprogram: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1300 | case DW_TAG_lexical_block: | 
|  | 1301 | { | 
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1302 | Block *block = NULL; | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1303 | if (tag == DW_TAG_subprogram) | 
|  | 1304 | { | 
|  | 1305 | // Skip any DW_TAG_subprogram DIEs that are inside | 
|  | 1306 | // of a normal or inlined functions. These will be | 
|  | 1307 | // parsed on their own as separate entities. | 
|  | 1308 |  | 
|  | 1309 | if (depth > 0) | 
|  | 1310 | break; | 
|  | 1311 |  | 
|  | 1312 | block = parent_block; | 
|  | 1313 | } | 
|  | 1314 | else | 
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1315 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1316 | BlockSP block_sp(new Block (MakeUserID(die->GetOffset()))); | 
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1317 | parent_block->AddChild(block_sp); | 
|  | 1318 | block = block_sp.get(); | 
|  | 1319 | } | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1320 | DWARFDebugRanges::RangeList ranges; | 
|  | 1321 | const char *name = NULL; | 
|  | 1322 | const char *mangled_name = NULL; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1323 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1324 | int decl_file = 0; | 
|  | 1325 | int decl_line = 0; | 
|  | 1326 | int decl_column = 0; | 
|  | 1327 | int call_file = 0; | 
|  | 1328 | int call_line = 0; | 
|  | 1329 | int call_column = 0; | 
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1330 | if (die->GetDIENamesAndRanges (this, | 
|  | 1331 | dwarf_cu, | 
|  | 1332 | name, | 
|  | 1333 | mangled_name, | 
|  | 1334 | ranges, | 
|  | 1335 | decl_file, decl_line, decl_column, | 
|  | 1336 | call_file, call_line, call_column)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1337 | { | 
|  | 1338 | if (tag == DW_TAG_subprogram) | 
|  | 1339 | { | 
|  | 1340 | assert (subprogram_low_pc == LLDB_INVALID_ADDRESS); | 
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1341 | subprogram_low_pc = ranges.GetMinRangeBase(0); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1342 | } | 
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1343 | else if (tag == DW_TAG_inlined_subroutine) | 
|  | 1344 | { | 
|  | 1345 | // We get called here for inlined subroutines in two ways. | 
|  | 1346 | // The first time is when we are making the Function object | 
|  | 1347 | // for this inlined concrete instance.  Since we're creating a top level block at | 
|  | 1348 | // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS.  So we need to | 
|  | 1349 | // adjust the containing address. | 
|  | 1350 | // The second time is when we are parsing the blocks inside the function that contains | 
|  | 1351 | // the inlined concrete instance.  Since these will be blocks inside the containing "real" | 
|  | 1352 | // function the offset will be for that function. | 
|  | 1353 | if (subprogram_low_pc == LLDB_INVALID_ADDRESS) | 
|  | 1354 | { | 
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1355 | subprogram_low_pc = ranges.GetMinRangeBase(0); | 
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1356 | } | 
|  | 1357 | } | 
|  | 1358 |  | 
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1359 | AddRangesToBlock (*block, ranges, subprogram_low_pc); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1360 |  | 
|  | 1361 | if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL)) | 
|  | 1362 | { | 
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1363 | std::unique_ptr<Declaration> decl_ap; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1364 | if (decl_file != 0 || decl_line != 0 || decl_column != 0) | 
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1365 | decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), | 
|  | 1366 | decl_line, decl_column)); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1367 |  | 
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1368 | std::unique_ptr<Declaration> call_ap; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1369 | if (call_file != 0 || call_line != 0 || call_column != 0) | 
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1370 | call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file), | 
|  | 1371 | call_line, call_column)); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1372 |  | 
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1373 | block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get()); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1374 | } | 
|  | 1375 |  | 
|  | 1376 | ++blocks_added; | 
|  | 1377 |  | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1378 | if (die->HasChildren()) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1379 | { | 
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1380 | blocks_added += ParseFunctionBlocks (sc, | 
|  | 1381 | block, | 
|  | 1382 | dwarf_cu, | 
|  | 1383 | die->GetFirstChild(), | 
|  | 1384 | subprogram_low_pc, | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1385 | depth + 1); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1386 | } | 
|  | 1387 | } | 
|  | 1388 | } | 
|  | 1389 | break; | 
|  | 1390 | default: | 
|  | 1391 | break; | 
|  | 1392 | } | 
|  | 1393 |  | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1394 | // Only parse siblings of the block if we are not at depth zero. A depth | 
|  | 1395 | // of zero indicates we are currently parsing the top level | 
|  | 1396 | // DW_TAG_subprogram DIE | 
|  | 1397 |  | 
|  | 1398 | if (depth == 0) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1399 | die = NULL; | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1400 | else | 
|  | 1401 | die = die->GetSibling(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1402 | } | 
|  | 1403 | return blocks_added; | 
|  | 1404 | } | 
|  | 1405 |  | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1406 | bool | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1407 | SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu, | 
|  | 1408 | const DWARFDebugInfoEntry *die, | 
|  | 1409 | ClangASTContext::TemplateParameterInfos &template_param_infos) | 
|  | 1410 | { | 
|  | 1411 | const dw_tag_t tag = die->Tag(); | 
|  | 1412 |  | 
|  | 1413 | switch (tag) | 
|  | 1414 | { | 
|  | 1415 | case DW_TAG_template_type_parameter: | 
|  | 1416 | case DW_TAG_template_value_parameter: | 
|  | 1417 | { | 
|  | 1418 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); | 
|  | 1419 |  | 
|  | 1420 | DWARFDebugInfoEntry::Attributes attributes; | 
|  | 1421 | const size_t num_attributes = die->GetAttributes (this, | 
|  | 1422 | dwarf_cu, | 
|  | 1423 | fixed_form_sizes, | 
|  | 1424 | attributes); | 
|  | 1425 | const char *name = NULL; | 
|  | 1426 | Type *lldb_type = NULL; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1427 | ClangASTType clang_type; | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1428 | uint64_t uval64 = 0; | 
|  | 1429 | bool uval64_valid = false; | 
|  | 1430 | if (num_attributes > 0) | 
|  | 1431 | { | 
|  | 1432 | DWARFFormValue form_value; | 
|  | 1433 | for (size_t i=0; i<num_attributes; ++i) | 
|  | 1434 | { | 
|  | 1435 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 1436 |  | 
|  | 1437 | switch (attr) | 
|  | 1438 | { | 
|  | 1439 | case DW_AT_name: | 
|  | 1440 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 1441 | name = form_value.AsCString(&get_debug_str_data()); | 
|  | 1442 | break; | 
|  | 1443 |  | 
|  | 1444 | case DW_AT_type: | 
|  | 1445 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 1446 | { | 
|  | 1447 | const dw_offset_t type_die_offset = form_value.Reference(dwarf_cu); | 
|  | 1448 | lldb_type = ResolveTypeUID(type_die_offset); | 
|  | 1449 | if (lldb_type) | 
|  | 1450 | clang_type = lldb_type->GetClangForwardType(); | 
|  | 1451 | } | 
|  | 1452 | break; | 
|  | 1453 |  | 
|  | 1454 | case DW_AT_const_value: | 
|  | 1455 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 1456 | { | 
|  | 1457 | uval64_valid = true; | 
|  | 1458 | uval64 = form_value.Unsigned(); | 
|  | 1459 | } | 
|  | 1460 | break; | 
|  | 1461 | default: | 
|  | 1462 | break; | 
|  | 1463 | } | 
|  | 1464 | } | 
|  | 1465 |  | 
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1466 | clang::ASTContext *ast = GetClangASTContext().getASTContext(); | 
|  | 1467 | if (!clang_type) | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1468 | clang_type = GetClangASTContext().GetBasicType(eBasicTypeVoid); | 
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1469 |  | 
|  | 1470 | if (clang_type) | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1471 | { | 
|  | 1472 | bool is_signed = false; | 
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1473 | if (name && name[0]) | 
|  | 1474 | template_param_infos.names.push_back(name); | 
|  | 1475 | else | 
|  | 1476 | template_param_infos.names.push_back(NULL); | 
|  | 1477 |  | 
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1478 | if (tag == DW_TAG_template_value_parameter && | 
|  | 1479 | lldb_type != NULL && | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1480 | clang_type.IsIntegerType (is_signed) && | 
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1481 | uval64_valid) | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1482 | { | 
|  | 1483 | llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed); | 
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1484 | template_param_infos.args.push_back (clang::TemplateArgument (*ast, | 
| Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1485 | llvm::APSInt(apint), | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1486 | clang_type.GetQualType())); | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1487 | } | 
|  | 1488 | else | 
|  | 1489 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1490 | template_param_infos.args.push_back (clang::TemplateArgument (clang_type.GetQualType())); | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1491 | } | 
|  | 1492 | } | 
|  | 1493 | else | 
|  | 1494 | { | 
|  | 1495 | return false; | 
|  | 1496 | } | 
|  | 1497 |  | 
|  | 1498 | } | 
|  | 1499 | } | 
|  | 1500 | return true; | 
|  | 1501 |  | 
|  | 1502 | default: | 
|  | 1503 | break; | 
|  | 1504 | } | 
|  | 1505 | return false; | 
|  | 1506 | } | 
|  | 1507 |  | 
|  | 1508 | bool | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1509 | SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu, | 
|  | 1510 | const DWARFDebugInfoEntry *parent_die, | 
|  | 1511 | ClangASTContext::TemplateParameterInfos &template_param_infos) | 
|  | 1512 | { | 
|  | 1513 |  | 
|  | 1514 | if (parent_die == NULL) | 
| Filipe Cabecinhas | 52008c6 | 2012-05-23 16:24:11 +0000 | [diff] [blame] | 1515 | return false; | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1516 |  | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1517 | Args template_parameter_names; | 
|  | 1518 | for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); | 
|  | 1519 | die != NULL; | 
|  | 1520 | die = die->GetSibling()) | 
|  | 1521 | { | 
|  | 1522 | const dw_tag_t tag = die->Tag(); | 
|  | 1523 |  | 
|  | 1524 | switch (tag) | 
|  | 1525 | { | 
|  | 1526 | case DW_TAG_template_type_parameter: | 
|  | 1527 | case DW_TAG_template_value_parameter: | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1528 | ParseTemplateDIE (dwarf_cu, die, template_param_infos); | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1529 | break; | 
|  | 1530 |  | 
|  | 1531 | default: | 
|  | 1532 | break; | 
|  | 1533 | } | 
|  | 1534 | } | 
|  | 1535 | if (template_param_infos.args.empty()) | 
|  | 1536 | return false; | 
|  | 1537 | return template_param_infos.args.size() == template_param_infos.names.size(); | 
|  | 1538 | } | 
|  | 1539 |  | 
|  | 1540 | clang::ClassTemplateDecl * | 
|  | 1541 | SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx, | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1542 | lldb::AccessType access_type, | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1543 | const char *parent_name, | 
|  | 1544 | int tag_decl_kind, | 
|  | 1545 | const ClangASTContext::TemplateParameterInfos &template_param_infos) | 
|  | 1546 | { | 
|  | 1547 | if (template_param_infos.IsValid()) | 
|  | 1548 | { | 
|  | 1549 | std::string template_basename(parent_name); | 
|  | 1550 | template_basename.erase (template_basename.find('<')); | 
|  | 1551 | ClangASTContext &ast = GetClangASTContext(); | 
|  | 1552 |  | 
|  | 1553 | return ast.CreateClassTemplateDecl (decl_ctx, | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1554 | access_type, | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1555 | template_basename.c_str(), | 
|  | 1556 | tag_decl_kind, | 
|  | 1557 | template_param_infos); | 
|  | 1558 | } | 
|  | 1559 | return NULL; | 
|  | 1560 | } | 
|  | 1561 |  | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1562 | class SymbolFileDWARF::DelayedAddObjCClassProperty | 
|  | 1563 | { | 
|  | 1564 | public: | 
|  | 1565 | DelayedAddObjCClassProperty | 
|  | 1566 | ( | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1567 | const ClangASTType     &class_opaque_type, | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1568 | const char             *property_name, | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1569 | 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] | 1570 | clang::ObjCIvarDecl    *ivar_decl, | 
|  | 1571 | const char             *property_setter_name, | 
|  | 1572 | const char             *property_getter_name, | 
|  | 1573 | uint32_t                property_attributes, | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1574 | const ClangASTMetadata *metadata | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1575 | ) : | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1576 | m_class_opaque_type     (class_opaque_type), | 
|  | 1577 | m_property_name         (property_name), | 
|  | 1578 | m_property_opaque_type  (property_opaque_type), | 
|  | 1579 | m_ivar_decl             (ivar_decl), | 
|  | 1580 | m_property_setter_name  (property_setter_name), | 
|  | 1581 | m_property_getter_name  (property_getter_name), | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1582 | m_property_attributes   (property_attributes) | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1583 | { | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1584 | if (metadata != NULL) | 
|  | 1585 | { | 
|  | 1586 | m_metadata_ap.reset(new ClangASTMetadata()); | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1587 | *m_metadata_ap = *metadata; | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1588 | } | 
|  | 1589 | } | 
|  | 1590 |  | 
|  | 1591 | DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs) | 
|  | 1592 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1593 | *this = rhs; | 
| Daniel Malea | d4c5be6 | 2012-11-12 21:02:14 +0000 | [diff] [blame] | 1594 | } | 
|  | 1595 |  | 
|  | 1596 | DelayedAddObjCClassProperty& operator= (const DelayedAddObjCClassProperty &rhs) | 
|  | 1597 | { | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1598 | m_class_opaque_type    = rhs.m_class_opaque_type; | 
|  | 1599 | m_property_name        = rhs.m_property_name; | 
|  | 1600 | m_property_opaque_type = rhs.m_property_opaque_type; | 
|  | 1601 | m_ivar_decl            = rhs.m_ivar_decl; | 
|  | 1602 | m_property_setter_name = rhs.m_property_setter_name; | 
|  | 1603 | m_property_getter_name = rhs.m_property_getter_name; | 
|  | 1604 | m_property_attributes  = rhs.m_property_attributes; | 
|  | 1605 |  | 
|  | 1606 | if (rhs.m_metadata_ap.get()) | 
|  | 1607 | { | 
|  | 1608 | m_metadata_ap.reset (new ClangASTMetadata()); | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1609 | *m_metadata_ap = *rhs.m_metadata_ap; | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1610 | } | 
| Daniel Malea | d4c5be6 | 2012-11-12 21:02:14 +0000 | [diff] [blame] | 1611 | return *this; | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1612 | } | 
|  | 1613 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1614 | bool | 
|  | 1615 | Finalize() | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1616 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1617 | return m_class_opaque_type.AddObjCClassProperty (m_property_name, | 
|  | 1618 | m_property_opaque_type, | 
|  | 1619 | m_ivar_decl, | 
|  | 1620 | m_property_setter_name, | 
|  | 1621 | m_property_getter_name, | 
|  | 1622 | m_property_attributes, | 
|  | 1623 | m_metadata_ap.get()); | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1624 | } | 
|  | 1625 | private: | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1626 | ClangASTType            m_class_opaque_type; | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1627 | const char             *m_property_name; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1628 | ClangASTType            m_property_opaque_type; | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1629 | clang::ObjCIvarDecl    *m_ivar_decl; | 
|  | 1630 | const char             *m_property_setter_name; | 
|  | 1631 | const char             *m_property_getter_name; | 
|  | 1632 | uint32_t                m_property_attributes; | 
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1633 | std::unique_ptr<ClangASTMetadata> m_metadata_ap; | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1634 | }; | 
|  | 1635 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1636 | struct BitfieldInfo | 
|  | 1637 | { | 
|  | 1638 | uint64_t bit_size; | 
|  | 1639 | uint64_t bit_offset; | 
|  | 1640 |  | 
|  | 1641 | BitfieldInfo () : | 
|  | 1642 | bit_size (LLDB_INVALID_ADDRESS), | 
|  | 1643 | bit_offset (LLDB_INVALID_ADDRESS) | 
|  | 1644 | { | 
|  | 1645 | } | 
|  | 1646 |  | 
|  | 1647 | bool IsValid () | 
|  | 1648 | { | 
|  | 1649 | return (bit_size != LLDB_INVALID_ADDRESS) && | 
|  | 1650 | (bit_offset != LLDB_INVALID_ADDRESS); | 
|  | 1651 | } | 
|  | 1652 | }; | 
|  | 1653 |  | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1654 |  | 
|  | 1655 | bool | 
|  | 1656 | SymbolFileDWARF::ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu, | 
|  | 1657 | const DWARFDebugInfoEntry *parent_die) | 
|  | 1658 | { | 
|  | 1659 | if (parent_die) | 
|  | 1660 | { | 
|  | 1661 | for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) | 
|  | 1662 | { | 
|  | 1663 | dw_tag_t tag = die->Tag(); | 
|  | 1664 | bool check_virtuality = false; | 
|  | 1665 | switch (tag) | 
|  | 1666 | { | 
|  | 1667 | case DW_TAG_inheritance: | 
|  | 1668 | case DW_TAG_subprogram: | 
|  | 1669 | check_virtuality = true; | 
|  | 1670 | break; | 
|  | 1671 | default: | 
|  | 1672 | break; | 
|  | 1673 | } | 
|  | 1674 | if (check_virtuality) | 
|  | 1675 | { | 
|  | 1676 | if (die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_virtuality, 0) != 0) | 
|  | 1677 | return true; | 
|  | 1678 | } | 
|  | 1679 | } | 
|  | 1680 | } | 
|  | 1681 | return false; | 
|  | 1682 | } | 
|  | 1683 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1684 | size_t | 
|  | 1685 | SymbolFileDWARF::ParseChildMembers | 
|  | 1686 | ( | 
|  | 1687 | const SymbolContext& sc, | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1688 | DWARFCompileUnit* dwarf_cu, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1689 | const DWARFDebugInfoEntry *parent_die, | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1690 | ClangASTType &class_clang_type, | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1691 | const LanguageType class_language, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1692 | std::vector<clang::CXXBaseSpecifier *>& base_classes, | 
|  | 1693 | std::vector<int>& member_accessibilities, | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1694 | DWARFDIECollection& member_function_dies, | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1695 | DelayedPropertyList& delayed_properties, | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1696 | AccessType& default_accessibility, | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1697 | bool &is_a_class, | 
|  | 1698 | LayoutInfo &layout_info | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1699 | ) | 
|  | 1700 | { | 
|  | 1701 | if (parent_die == NULL) | 
|  | 1702 | return 0; | 
|  | 1703 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1704 | size_t count = 0; | 
|  | 1705 | const DWARFDebugInfoEntry *die; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 1706 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1707 | uint32_t member_idx = 0; | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1708 | BitfieldInfo last_field_info; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 1709 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1710 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) | 
|  | 1711 | { | 
|  | 1712 | dw_tag_t tag = die->Tag(); | 
|  | 1713 |  | 
|  | 1714 | switch (tag) | 
|  | 1715 | { | 
|  | 1716 | case DW_TAG_member: | 
| Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1717 | case DW_TAG_APPLE_property: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1718 | { | 
|  | 1719 | DWARFDebugInfoEntry::Attributes attributes; | 
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1720 | const size_t num_attributes = die->GetAttributes (this, | 
|  | 1721 | dwarf_cu, | 
|  | 1722 | fixed_form_sizes, | 
|  | 1723 | attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1724 | if (num_attributes > 0) | 
|  | 1725 | { | 
|  | 1726 | Declaration decl; | 
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1727 | //DWARFExpression location; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1728 | const char *name = NULL; | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1729 | const char *prop_name = NULL; | 
|  | 1730 | const char *prop_getter_name = NULL; | 
|  | 1731 | const char *prop_setter_name = NULL; | 
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1732 | uint32_t prop_attributes = 0; | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1733 |  | 
|  | 1734 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1735 | bool is_artificial = false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1736 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1737 | AccessType accessibility = eAccessNone; | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1738 | uint32_t member_byte_offset = UINT32_MAX; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1739 | size_t byte_size = 0; | 
|  | 1740 | size_t bit_offset = 0; | 
|  | 1741 | size_t bit_size = 0; | 
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1742 | 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] | 1743 | uint32_t i; | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1744 | for (i=0; i<num_attributes && !is_artificial; ++i) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1745 | { | 
|  | 1746 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 1747 | DWARFFormValue form_value; | 
|  | 1748 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 1749 | { | 
|  | 1750 | switch (attr) | 
|  | 1751 | { | 
|  | 1752 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 1753 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 1754 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 1755 | case DW_AT_name:        name = form_value.AsCString(&get_debug_str_data()); break; | 
|  | 1756 | case DW_AT_type:        encoding_uid = form_value.Reference(dwarf_cu); break; | 
|  | 1757 | case DW_AT_bit_offset:  bit_offset = form_value.Unsigned(); break; | 
|  | 1758 | case DW_AT_bit_size:    bit_size = form_value.Unsigned(); break; | 
|  | 1759 | case DW_AT_byte_size:   byte_size = form_value.Unsigned(); break; | 
|  | 1760 | case DW_AT_data_member_location: | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1761 | if (form_value.BlockData()) | 
|  | 1762 | { | 
|  | 1763 | Value initialValue(0); | 
|  | 1764 | Value memberOffset(0); | 
|  | 1765 | const DataExtractor& debug_info_data = get_debug_info_data(); | 
|  | 1766 | uint32_t block_length = form_value.Unsigned(); | 
|  | 1767 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); | 
|  | 1768 | if (DWARFExpression::Evaluate(NULL, // ExecutionContext * | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1769 | NULL, // ClangExpressionVariableList * | 
|  | 1770 | NULL, // ClangExpressionDeclMap * | 
|  | 1771 | NULL, // RegisterContext * | 
|  | 1772 | debug_info_data, | 
|  | 1773 | block_offset, | 
|  | 1774 | block_length, | 
|  | 1775 | eRegisterKindDWARF, | 
|  | 1776 | &initialValue, | 
|  | 1777 | memberOffset, | 
|  | 1778 | NULL)) | 
|  | 1779 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1780 | member_byte_offset = memberOffset.ResolveValue(NULL).UInt(); | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1781 | } | 
|  | 1782 | } | 
| Ashok Thirumurthi | a4658a5 | 2013-07-30 14:58:39 +0000 | [diff] [blame] | 1783 | else | 
|  | 1784 | { | 
|  | 1785 | // With DWARF 3 and later, if the value is an integer constant, | 
|  | 1786 | // this form value is the offset in bytes from the beginning | 
|  | 1787 | // of the containing entity. | 
|  | 1788 | member_byte_offset = form_value.Unsigned(); | 
|  | 1789 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1790 | break; | 
|  | 1791 |  | 
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1792 | 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] | 1793 | case DW_AT_artificial: is_artificial = form_value.Boolean(); break; | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1794 | case DW_AT_APPLE_property_name:      prop_name = form_value.AsCString(&get_debug_str_data()); break; | 
|  | 1795 | case DW_AT_APPLE_property_getter:    prop_getter_name = form_value.AsCString(&get_debug_str_data()); break; | 
|  | 1796 | case DW_AT_APPLE_property_setter:    prop_setter_name = form_value.AsCString(&get_debug_str_data()); break; | 
|  | 1797 | case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break; | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 1798 | case DW_AT_external:                 is_external = form_value.Boolean(); break; | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1799 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1800 | default: | 
| Greg Clayton | 1b02c17 | 2012-03-14 21:00:47 +0000 | [diff] [blame] | 1801 | case DW_AT_declaration: | 
|  | 1802 | case DW_AT_description: | 
|  | 1803 | case DW_AT_mutable: | 
|  | 1804 | case DW_AT_visibility: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1805 | case DW_AT_sibling: | 
|  | 1806 | break; | 
|  | 1807 | } | 
|  | 1808 | } | 
|  | 1809 | } | 
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1810 |  | 
|  | 1811 | if (prop_name) | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1812 | { | 
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1813 | ConstString fixed_getter; | 
|  | 1814 | ConstString fixed_setter; | 
|  | 1815 |  | 
|  | 1816 | // Check if the property getter/setter were provided as full | 
|  | 1817 | // names.  We want basenames, so we extract them. | 
|  | 1818 |  | 
|  | 1819 | if (prop_getter_name && prop_getter_name[0] == '-') | 
|  | 1820 | { | 
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 1821 | ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true); | 
|  | 1822 | prop_getter_name = prop_getter_method.GetSelector().GetCString(); | 
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1823 | } | 
|  | 1824 |  | 
|  | 1825 | if (prop_setter_name && prop_setter_name[0] == '-') | 
|  | 1826 | { | 
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 1827 | ObjCLanguageRuntime::MethodName prop_setter_method(prop_setter_name, true); | 
|  | 1828 | prop_setter_name = prop_setter_method.GetSelector().GetCString(); | 
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1829 | } | 
|  | 1830 |  | 
|  | 1831 | // If the names haven't been provided, they need to be | 
|  | 1832 | // filled in. | 
|  | 1833 |  | 
|  | 1834 | if (!prop_getter_name) | 
|  | 1835 | { | 
|  | 1836 | prop_getter_name = prop_name; | 
|  | 1837 | } | 
|  | 1838 | if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly)) | 
|  | 1839 | { | 
|  | 1840 | StreamString ss; | 
|  | 1841 |  | 
|  | 1842 | ss.Printf("set%c%s:", | 
|  | 1843 | toupper(prop_name[0]), | 
|  | 1844 | &prop_name[1]); | 
|  | 1845 |  | 
|  | 1846 | fixed_setter.SetCString(ss.GetData()); | 
|  | 1847 | prop_setter_name = fixed_setter.GetCString(); | 
|  | 1848 | } | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1849 | } | 
|  | 1850 |  | 
|  | 1851 | // Clang has a DWARF generation bug where sometimes it | 
| Greg Clayton | 4495393 | 2011-10-25 01:25:35 +0000 | [diff] [blame] | 1852 | // represents fields that are references with bad byte size | 
|  | 1853 | // and bit size/offset information such as: | 
|  | 1854 | // | 
|  | 1855 | //  DW_AT_byte_size( 0x00 ) | 
|  | 1856 | //  DW_AT_bit_size( 0x40 ) | 
|  | 1857 | //  DW_AT_bit_offset( 0xffffffffffffffc0 ) | 
|  | 1858 | // | 
|  | 1859 | // So check the bit offset to make sure it is sane, and if | 
|  | 1860 | // the values are not sane, remove them. If we don't do this | 
|  | 1861 | // then we will end up with a crash if we try to use this | 
|  | 1862 | // type in an expression when clang becomes unhappy with its | 
|  | 1863 | // recycled debug info. | 
| Sean Callanan | 5a477cf | 2010-10-30 01:56:10 +0000 | [diff] [blame] | 1864 |  | 
| Greg Clayton | 4495393 | 2011-10-25 01:25:35 +0000 | [diff] [blame] | 1865 | if (bit_offset > 128) | 
|  | 1866 | { | 
|  | 1867 | bit_size = 0; | 
|  | 1868 | bit_offset = 0; | 
|  | 1869 | } | 
|  | 1870 |  | 
|  | 1871 | // FIXME: Make Clang ignore Objective-C accessibility for expressions | 
| Sean Callanan | 5a477cf | 2010-10-30 01:56:10 +0000 | [diff] [blame] | 1872 | if (class_language == eLanguageTypeObjC || | 
|  | 1873 | class_language == eLanguageTypeObjC_plus_plus) | 
|  | 1874 | accessibility = eAccessNone; | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1875 |  | 
|  | 1876 | if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name)) | 
|  | 1877 | { | 
|  | 1878 | // Not all compilers will mark the vtable pointer | 
|  | 1879 | // member as artificial (llvm-gcc). We can't have | 
|  | 1880 | // the virtual members in our classes otherwise it | 
|  | 1881 | // throws off all child offsets since we end up | 
|  | 1882 | // having and extra pointer sized member in our | 
|  | 1883 | // class layouts. | 
|  | 1884 | is_artificial = true; | 
|  | 1885 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1886 |  | 
| Greg Clayton | 2965971 | 2013-07-12 20:08:35 +0000 | [diff] [blame] | 1887 | // Handle static members | 
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1888 | if (is_external && member_byte_offset == UINT32_MAX) | 
| Greg Clayton | 973b6c9 | 2013-04-11 16:57:51 +0000 | [diff] [blame] | 1889 | { | 
|  | 1890 | Type *var_type = ResolveTypeUID(encoding_uid); | 
|  | 1891 |  | 
|  | 1892 | if (var_type) | 
|  | 1893 | { | 
| Greg Clayton | 2965971 | 2013-07-12 20:08:35 +0000 | [diff] [blame] | 1894 | if (accessibility == eAccessNone) | 
|  | 1895 | accessibility = eAccessPublic; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1896 | class_clang_type.AddVariableToRecordType (name, | 
|  | 1897 | var_type->GetClangLayoutType(), | 
|  | 1898 | accessibility); | 
| Greg Clayton | 973b6c9 | 2013-04-11 16:57:51 +0000 | [diff] [blame] | 1899 | } | 
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1900 | break; | 
| Greg Clayton | 973b6c9 | 2013-04-11 16:57:51 +0000 | [diff] [blame] | 1901 | } | 
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1902 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1903 | if (is_artificial == false) | 
|  | 1904 | { | 
|  | 1905 | Type *member_type = ResolveTypeUID(encoding_uid); | 
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 1906 |  | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1907 | clang::FieldDecl *field_decl = NULL; | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1908 | if (tag == DW_TAG_member) | 
| Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1909 | { | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1910 | if (member_type) | 
|  | 1911 | { | 
|  | 1912 | if (accessibility == eAccessNone) | 
|  | 1913 | accessibility = default_accessibility; | 
|  | 1914 | member_accessibilities.push_back(accessibility); | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1915 |  | 
|  | 1916 | BitfieldInfo this_field_info; | 
|  | 1917 |  | 
|  | 1918 | this_field_info.bit_size = bit_size; | 
|  | 1919 |  | 
|  | 1920 | if (member_byte_offset != UINT32_MAX || bit_size != 0) | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1921 | { | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1922 | ///////////////////////////////////////////////////////////// | 
|  | 1923 | // How to locate a field given the DWARF debug information | 
|  | 1924 | // | 
|  | 1925 | // AT_byte_size indicates the size of the word in which the | 
|  | 1926 | // bit offset must be interpreted. | 
|  | 1927 | // | 
|  | 1928 | // AT_data_member_location indicates the byte offset of the | 
|  | 1929 | // word from the base address of the structure. | 
|  | 1930 | // | 
|  | 1931 | // AT_bit_offset indicates how many bits into the word | 
|  | 1932 | // (according to the host endianness) the low-order bit of | 
|  | 1933 | // the field starts.  AT_bit_offset can be negative. | 
|  | 1934 | // | 
|  | 1935 | // AT_bit_size indicates the size of the field in bits. | 
|  | 1936 | ///////////////////////////////////////////////////////////// | 
|  | 1937 |  | 
|  | 1938 | this_field_info.bit_offset = 0; | 
|  | 1939 |  | 
|  | 1940 | this_field_info.bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8)); | 
|  | 1941 |  | 
|  | 1942 | if (GetObjectFile()->GetByteOrder() == eByteOrderLittle) | 
|  | 1943 | { | 
|  | 1944 | this_field_info.bit_offset += byte_size * 8; | 
|  | 1945 | this_field_info.bit_offset -= (bit_offset + bit_size); | 
|  | 1946 | } | 
|  | 1947 | else | 
|  | 1948 | { | 
|  | 1949 | this_field_info.bit_offset += bit_offset; | 
|  | 1950 | } | 
|  | 1951 | } | 
|  | 1952 |  | 
|  | 1953 | // If the member to be emitted did not start on a character boundary and there is | 
|  | 1954 | // empty space between the last field and this one, then we need to emit an | 
|  | 1955 | // anonymous member filling up the space up to its start.  There are three cases | 
|  | 1956 | // here: | 
|  | 1957 | // | 
|  | 1958 | // 1 If the previous member ended on a character boundary, then we can emit an | 
|  | 1959 | //   anonymous member starting at the most recent character boundary. | 
|  | 1960 | // | 
|  | 1961 | // 2 If the previous member did not end on a character boundary and the distance | 
|  | 1962 | //   from the end of the previous member to the current member is less than a | 
|  | 1963 | //   word width, then we can emit an anonymous member starting right after the | 
|  | 1964 | //   previous member and right before this member. | 
|  | 1965 | // | 
|  | 1966 | // 3 If the previous member did not end on a character boundary and the distance | 
|  | 1967 | //   from the end of the previous member to the current member is greater than | 
|  | 1968 | //   or equal a word width, then we act as in Case 1. | 
|  | 1969 |  | 
|  | 1970 | const uint64_t character_width = 8; | 
|  | 1971 | const uint64_t word_width = 32; | 
|  | 1972 |  | 
|  | 1973 | if (this_field_info.IsValid()) | 
|  | 1974 | { | 
|  | 1975 | // Objective-C has invalid DW_AT_bit_offset values in older versions | 
|  | 1976 | // of clang, so we have to be careful and only insert unnammed bitfields | 
| Greg Clayton | 37c36e4 | 2012-11-27 00:59:26 +0000 | [diff] [blame] | 1977 | // if we have a new enough clang. | 
|  | 1978 | bool detect_unnamed_bitfields = true; | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1979 |  | 
| Greg Clayton | 37c36e4 | 2012-11-27 00:59:26 +0000 | [diff] [blame] | 1980 | if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus) | 
|  | 1981 | detect_unnamed_bitfields = dwarf_cu->Supports_unnamed_objc_bitfields (); | 
|  | 1982 |  | 
|  | 1983 | if (detect_unnamed_bitfields) | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1984 | { | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1985 | BitfieldInfo anon_field_info; | 
|  | 1986 |  | 
|  | 1987 | if ((this_field_info.bit_offset % character_width) != 0) // not char aligned | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1988 | { | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1989 | uint64_t last_field_end = 0; | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1990 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1991 | if (last_field_info.IsValid()) | 
|  | 1992 | 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] | 1993 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1994 | if (this_field_info.bit_offset != last_field_end) | 
|  | 1995 | { | 
|  | 1996 | if (((last_field_end % character_width) == 0) ||                    // case 1 | 
|  | 1997 | (this_field_info.bit_offset - last_field_end >= word_width))    // case 3 | 
|  | 1998 | { | 
|  | 1999 | anon_field_info.bit_size = this_field_info.bit_offset % character_width; | 
|  | 2000 | anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size; | 
|  | 2001 | } | 
|  | 2002 | else                                                                // case 2 | 
|  | 2003 | { | 
|  | 2004 | anon_field_info.bit_size = this_field_info.bit_offset - last_field_end; | 
|  | 2005 | anon_field_info.bit_offset = last_field_end; | 
|  | 2006 | } | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2007 | } | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2008 | } | 
|  | 2009 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2010 | if (anon_field_info.IsValid()) | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2011 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2012 | clang::FieldDecl *unnamed_bitfield_decl = class_clang_type.AddFieldToRecordType (NULL, | 
|  | 2013 | GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width), | 
|  | 2014 | accessibility, | 
|  | 2015 | anon_field_info.bit_size); | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2016 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2017 | layout_info.field_offsets.insert(std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset)); | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2018 | } | 
|  | 2019 | } | 
|  | 2020 | } | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2021 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2022 | ClangASTType member_clang_type = member_type->GetClangLayoutType(); | 
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 2023 |  | 
|  | 2024 | { | 
|  | 2025 | // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>). | 
|  | 2026 | // If the current field is at the end of the structure, then there is definitely no room for extra | 
|  | 2027 | // elements and we override the type to array[0]. | 
|  | 2028 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2029 | ClangASTType member_array_element_type; | 
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 2030 | uint64_t member_array_size; | 
|  | 2031 | bool member_array_is_incomplete; | 
|  | 2032 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2033 | if (member_clang_type.IsArrayType(&member_array_element_type, | 
|  | 2034 | &member_array_size, | 
|  | 2035 | &member_array_is_incomplete) && | 
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 2036 | !member_array_is_incomplete) | 
|  | 2037 | { | 
|  | 2038 | uint64_t parent_byte_size = parent_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, UINT64_MAX); | 
|  | 2039 |  | 
|  | 2040 | if (member_byte_offset >= parent_byte_size) | 
|  | 2041 | { | 
|  | 2042 | if (member_array_size != 1) | 
|  | 2043 | { | 
|  | 2044 | 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, | 
|  | 2045 | MakeUserID(die->GetOffset()), | 
|  | 2046 | name, | 
|  | 2047 | encoding_uid, | 
|  | 2048 | MakeUserID(parent_die->GetOffset())); | 
|  | 2049 | } | 
|  | 2050 |  | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 2051 | member_clang_type = GetClangASTContext().CreateArrayType(member_array_element_type, 0, false); | 
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 2052 | } | 
|  | 2053 | } | 
|  | 2054 | } | 
|  | 2055 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2056 | field_decl = class_clang_type.AddFieldToRecordType (name, | 
|  | 2057 | member_clang_type, | 
|  | 2058 | accessibility, | 
|  | 2059 | bit_size); | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2060 |  | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 2061 | GetClangASTContext().SetMetadataAsUserID (field_decl, MakeUserID(die->GetOffset())); | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2062 |  | 
|  | 2063 | if (this_field_info.IsValid()) | 
|  | 2064 | { | 
|  | 2065 | layout_info.field_offsets.insert(std::make_pair(field_decl, this_field_info.bit_offset)); | 
|  | 2066 | last_field_info = this_field_info; | 
|  | 2067 | } | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2068 | } | 
|  | 2069 | else | 
|  | 2070 | { | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 2071 | if (name) | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2072 | 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] | 2073 | MakeUserID(die->GetOffset()), | 
|  | 2074 | name, | 
|  | 2075 | encoding_uid); | 
|  | 2076 | else | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2077 | 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] | 2078 | MakeUserID(die->GetOffset()), | 
|  | 2079 | encoding_uid); | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2080 | } | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2081 | } | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 2082 |  | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2083 | if (prop_name != NULL) | 
|  | 2084 | { | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 2085 | clang::ObjCIvarDecl *ivar_decl = NULL; | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2086 |  | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 2087 | if (field_decl) | 
|  | 2088 | { | 
|  | 2089 | ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl); | 
|  | 2090 | assert (ivar_decl != NULL); | 
|  | 2091 | } | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2092 |  | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 2093 | ClangASTMetadata metadata; | 
|  | 2094 | metadata.SetUserID (MakeUserID(die->GetOffset())); | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2095 | delayed_properties.push_back(DelayedAddObjCClassProperty(class_clang_type, | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2096 | prop_name, | 
|  | 2097 | member_type->GetClangLayoutType(), | 
|  | 2098 | ivar_decl, | 
|  | 2099 | prop_setter_name, | 
|  | 2100 | prop_getter_name, | 
|  | 2101 | prop_attributes, | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 2102 | &metadata)); | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2103 |  | 
| Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 2104 | if (ivar_decl) | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 2105 | GetClangASTContext().SetMetadataAsUserID (ivar_decl, MakeUserID(die->GetOffset())); | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2106 | } | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2107 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2108 | } | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2109 | ++member_idx; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2110 | } | 
|  | 2111 | break; | 
|  | 2112 |  | 
|  | 2113 | case DW_TAG_subprogram: | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2114 | // Let the type parsing code handle this one for us. | 
|  | 2115 | member_function_dies.Append (die); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2116 | break; | 
|  | 2117 |  | 
|  | 2118 | case DW_TAG_inheritance: | 
|  | 2119 | { | 
|  | 2120 | is_a_class = true; | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 2121 | if (default_accessibility == eAccessNone) | 
|  | 2122 | default_accessibility = eAccessPrivate; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2123 | // TODO: implement DW_TAG_inheritance type parsing | 
|  | 2124 | DWARFDebugInfoEntry::Attributes attributes; | 
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 2125 | const size_t num_attributes = die->GetAttributes (this, | 
|  | 2126 | dwarf_cu, | 
|  | 2127 | fixed_form_sizes, | 
|  | 2128 | attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2129 | if (num_attributes > 0) | 
|  | 2130 | { | 
|  | 2131 | Declaration decl; | 
|  | 2132 | DWARFExpression location; | 
|  | 2133 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 2134 | AccessType accessibility = default_accessibility; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2135 | bool is_virtual = false; | 
|  | 2136 | bool is_base_of_class = true; | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2137 | off_t member_byte_offset = 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2138 | uint32_t i; | 
|  | 2139 | for (i=0; i<num_attributes; ++i) | 
|  | 2140 | { | 
|  | 2141 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 2142 | DWARFFormValue form_value; | 
|  | 2143 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 2144 | { | 
|  | 2145 | switch (attr) | 
|  | 2146 | { | 
|  | 2147 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 2148 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 2149 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 2150 | case DW_AT_type:        encoding_uid = form_value.Reference(dwarf_cu); break; | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2151 | case DW_AT_data_member_location: | 
|  | 2152 | if (form_value.BlockData()) | 
|  | 2153 | { | 
|  | 2154 | Value initialValue(0); | 
|  | 2155 | Value memberOffset(0); | 
|  | 2156 | const DataExtractor& debug_info_data = get_debug_info_data(); | 
|  | 2157 | uint32_t block_length = form_value.Unsigned(); | 
|  | 2158 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); | 
|  | 2159 | if (DWARFExpression::Evaluate (NULL, | 
|  | 2160 | NULL, | 
|  | 2161 | NULL, | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2162 | NULL, | 
|  | 2163 | debug_info_data, | 
|  | 2164 | block_offset, | 
|  | 2165 | block_length, | 
|  | 2166 | eRegisterKindDWARF, | 
|  | 2167 | &initialValue, | 
|  | 2168 | memberOffset, | 
|  | 2169 | NULL)) | 
|  | 2170 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2171 | member_byte_offset = memberOffset.ResolveValue(NULL).UInt(); | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2172 | } | 
|  | 2173 | } | 
| Ashok Thirumurthi | a4658a5 | 2013-07-30 14:58:39 +0000 | [diff] [blame] | 2174 | else | 
|  | 2175 | { | 
|  | 2176 | // With DWARF 3 and later, if the value is an integer constant, | 
|  | 2177 | // this form value is the offset in bytes from the beginning | 
|  | 2178 | // of the containing entity. | 
|  | 2179 | member_byte_offset = form_value.Unsigned(); | 
|  | 2180 | } | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2181 | break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2182 |  | 
|  | 2183 | case DW_AT_accessibility: | 
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 2184 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2185 | break; | 
|  | 2186 |  | 
| Ashok Thirumurthi | a4658a5 | 2013-07-30 14:58:39 +0000 | [diff] [blame] | 2187 | case DW_AT_virtuality: | 
|  | 2188 | is_virtual = form_value.Boolean(); | 
|  | 2189 | break; | 
|  | 2190 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2191 | case DW_AT_sibling: | 
|  | 2192 | break; | 
| Ashok Thirumurthi | a4658a5 | 2013-07-30 14:58:39 +0000 | [diff] [blame] | 2193 |  | 
|  | 2194 | default: | 
|  | 2195 | break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2196 | } | 
|  | 2197 | } | 
|  | 2198 | } | 
|  | 2199 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 2200 | Type *base_class_type = ResolveTypeUID(encoding_uid); | 
|  | 2201 | assert(base_class_type); | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2202 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2203 | ClangASTType base_class_clang_type = base_class_type->GetClangFullType(); | 
| Greg Clayton | f4ecaa5 | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 2204 | assert (base_class_clang_type); | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2205 | if (class_language == eLanguageTypeObjC) | 
|  | 2206 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2207 | class_clang_type.SetObjCSuperClass(base_class_clang_type); | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2208 | } | 
|  | 2209 | else | 
|  | 2210 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2211 | base_classes.push_back (base_class_clang_type.CreateBaseClassSpecifier (accessibility, | 
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 2212 | is_virtual, | 
|  | 2213 | is_base_of_class)); | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2214 |  | 
|  | 2215 | if (is_virtual) | 
|  | 2216 | { | 
| Greg Clayton | 52694e3 | 2013-09-16 21:57:07 +0000 | [diff] [blame] | 2217 | // Do not specify any offset for virtual inheritance. The DWARF produced by clang doesn't | 
|  | 2218 | // give us a constant offset, but gives us a DWARF expressions that requires an actual object | 
|  | 2219 | // in memory. the DW_AT_data_member_location for a virtual base class looks like: | 
|  | 2220 | //      DW_AT_data_member_location( DW_OP_dup, DW_OP_deref, DW_OP_constu(0x00000018), DW_OP_minus, DW_OP_deref, DW_OP_plus ) | 
|  | 2221 | // Given this, there is really no valid response we can give to clang for virtual base | 
|  | 2222 | // class offsets, and this should eventually be removed from LayoutRecordType() in the external | 
|  | 2223 | // AST source in clang. | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2224 | } | 
|  | 2225 | else | 
|  | 2226 | { | 
| Greg Clayton | 5764873 | 2013-09-12 17:22:32 +0000 | [diff] [blame] | 2227 | layout_info.base_offsets.insert(std::make_pair(base_class_clang_type.GetAsCXXRecordDecl(), | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2228 | clang::CharUnits::fromQuantity(member_byte_offset))); | 
|  | 2229 | } | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2230 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2231 | } | 
|  | 2232 | } | 
|  | 2233 | break; | 
|  | 2234 |  | 
|  | 2235 | default: | 
|  | 2236 | break; | 
|  | 2237 | } | 
|  | 2238 | } | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2239 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2240 | return count; | 
|  | 2241 | } | 
|  | 2242 |  | 
|  | 2243 |  | 
|  | 2244 | clang::DeclContext* | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 2245 | SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2246 | { | 
|  | 2247 | DWARFDebugInfo* debug_info = DebugInfo(); | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2248 | if (debug_info && UserIDMatches(type_uid)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2249 | { | 
|  | 2250 | DWARFCompileUnitSP cu_sp; | 
|  | 2251 | const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp); | 
|  | 2252 | if (die) | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 2253 | return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL); | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 2254 | } | 
|  | 2255 | return NULL; | 
|  | 2256 | } | 
|  | 2257 |  | 
|  | 2258 | clang::DeclContext* | 
|  | 2259 | SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid) | 
|  | 2260 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2261 | if (UserIDMatches(type_uid)) | 
|  | 2262 | return GetClangDeclContextForDIEOffset (sc, type_uid); | 
|  | 2263 | return NULL; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2264 | } | 
|  | 2265 |  | 
|  | 2266 | Type* | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2267 | SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2268 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2269 | if (UserIDMatches(type_uid)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2270 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2271 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 2272 | if (debug_info) | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2273 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2274 | DWARFCompileUnitSP cu_sp; | 
|  | 2275 | const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp); | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2276 | const bool assert_not_being_parsed = true; | 
|  | 2277 | return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed); | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2278 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2279 | } | 
|  | 2280 | return NULL; | 
|  | 2281 | } | 
|  | 2282 |  | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2283 | Type* | 
|  | 2284 | SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed) | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2285 | { | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2286 | if (die != NULL) | 
|  | 2287 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2288 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2289 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2290 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2291 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'", | 
|  | 2292 | die->GetOffset(), | 
|  | 2293 | DW_TAG_value_to_name(die->Tag()), | 
|  | 2294 | die->GetName(this, cu)); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2295 |  | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2296 | // We might be coming in in the middle of a type tree (a class | 
|  | 2297 | // withing a class, an enum within a class), so parse any needed | 
|  | 2298 | // parent DIEs before we get to this one... | 
|  | 2299 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); | 
|  | 2300 | switch (decl_ctx_die->Tag()) | 
|  | 2301 | { | 
|  | 2302 | case DW_TAG_structure_type: | 
|  | 2303 | case DW_TAG_union_type: | 
|  | 2304 | case DW_TAG_class_type: | 
|  | 2305 | { | 
|  | 2306 | // Get the type, which could be a forward declaration | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2307 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2308 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2309 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x", | 
|  | 2310 | die->GetOffset(), | 
|  | 2311 | DW_TAG_value_to_name(die->Tag()), | 
|  | 2312 | die->GetName(this, cu), | 
|  | 2313 | decl_ctx_die->GetOffset()); | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2314 | // | 
|  | 2315 | //                Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed); | 
|  | 2316 | //                if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag())) | 
|  | 2317 | //                { | 
|  | 2318 | //                    if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2319 | //                        GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2320 | //                                                                  "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function", | 
|  | 2321 | //                                                                  die->GetOffset(), | 
|  | 2322 | //                                                                  DW_TAG_value_to_name(die->Tag()), | 
|  | 2323 | //                                                                  die->GetName(this, cu), | 
|  | 2324 | //                                                                  decl_ctx_die->GetOffset()); | 
|  | 2325 | //                    // Ask the type to complete itself if it already hasn't since if we | 
|  | 2326 | //                    // want a function (method or static) from a class, the class must | 
|  | 2327 | //                    // create itself and add it's own methods and class functions. | 
|  | 2328 | //                    if (parent_type) | 
|  | 2329 | //                        parent_type->GetClangFullType(); | 
|  | 2330 | //                } | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2331 | } | 
|  | 2332 | break; | 
|  | 2333 |  | 
|  | 2334 | default: | 
|  | 2335 | break; | 
|  | 2336 | } | 
|  | 2337 | return ResolveType (cu, die); | 
|  | 2338 | } | 
|  | 2339 | return NULL; | 
|  | 2340 | } | 
|  | 2341 |  | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2342 | // This function is used when SymbolFileDWARFDebugMap owns a bunch of | 
|  | 2343 | // SymbolFileDWARF objects to detect if this DWARF file is the one that | 
|  | 2344 | // can resolve a clang_type. | 
|  | 2345 | bool | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2346 | SymbolFileDWARF::HasForwardDeclForClangType (const ClangASTType &clang_type) | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2347 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2348 | ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers(); | 
|  | 2349 | 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] | 2350 | return die != NULL; | 
|  | 2351 | } | 
|  | 2352 |  | 
|  | 2353 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2354 | bool | 
|  | 2355 | SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (ClangASTType &clang_type) | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2356 | { | 
|  | 2357 | // We have a struct/union/class/enum that needs to be fully resolved. | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2358 | ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers(); | 
|  | 2359 | 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] | 2360 | if (die == NULL) | 
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2361 | { | 
|  | 2362 | // We have already resolved this type... | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2363 | return true; | 
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2364 | } | 
|  | 2365 | // Once we start resolving this type, remove it from the forward declaration | 
|  | 2366 | // map in case anyone child members or other types require this type to get resolved. | 
|  | 2367 | // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition | 
|  | 2368 | // are done. | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2369 | m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers.GetOpaqueQualType()); | 
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2370 |  | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2371 |  | 
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 2372 | // Disable external storage for this type so we don't get anymore | 
|  | 2373 | // clang::ExternalASTSource queries for this type. | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2374 | clang_type.SetHasExternalStorage (false); | 
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 2375 |  | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2376 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 2377 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2378 | DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get(); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2379 | Type *type = m_die_to_type.lookup (die); | 
|  | 2380 |  | 
|  | 2381 | const dw_tag_t tag = die->Tag(); | 
|  | 2382 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2383 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION)); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2384 | if (log) | 
| Greg Clayton | baf95da | 2012-03-30 23:50:54 +0000 | [diff] [blame] | 2385 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2386 | GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2387 | "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...", | 
| Greg Clayton | d61c0fc | 2012-04-23 22:55:20 +0000 | [diff] [blame] | 2388 | MakeUserID(die->GetOffset()), | 
|  | 2389 | DW_TAG_value_to_name(tag), | 
|  | 2390 | type->GetName().AsCString()); | 
| Greg Clayton | baf95da | 2012-03-30 23:50:54 +0000 | [diff] [blame] | 2391 |  | 
| Greg Clayton | baf95da | 2012-03-30 23:50:54 +0000 | [diff] [blame] | 2392 | } | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2393 | assert (clang_type); | 
|  | 2394 | DWARFDebugInfoEntry::Attributes attributes; | 
|  | 2395 |  | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2396 | switch (tag) | 
|  | 2397 | { | 
|  | 2398 | case DW_TAG_structure_type: | 
|  | 2399 | case DW_TAG_union_type: | 
|  | 2400 | case DW_TAG_class_type: | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2401 | { | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2402 | LayoutInfo layout_info; | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2403 |  | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2404 | { | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2405 | if (die->HasChildren()) | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2406 | { | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2407 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2408 | LanguageType class_language = eLanguageTypeUnknown; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2409 | if (clang_type.IsObjCObjectOrInterfaceType()) | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2410 | { | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2411 | class_language = eLanguageTypeObjC; | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2412 | // For objective C we don't start the definition when | 
|  | 2413 | // the class is created. | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2414 | clang_type.StartTagDeclarationDefinition (); | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2415 | } | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2416 |  | 
|  | 2417 | int tag_decl_kind = -1; | 
|  | 2418 | AccessType default_accessibility = eAccessNone; | 
|  | 2419 | if (tag == DW_TAG_structure_type) | 
|  | 2420 | { | 
|  | 2421 | tag_decl_kind = clang::TTK_Struct; | 
|  | 2422 | default_accessibility = eAccessPublic; | 
|  | 2423 | } | 
|  | 2424 | else if (tag == DW_TAG_union_type) | 
|  | 2425 | { | 
|  | 2426 | tag_decl_kind = clang::TTK_Union; | 
|  | 2427 | default_accessibility = eAccessPublic; | 
|  | 2428 | } | 
|  | 2429 | else if (tag == DW_TAG_class_type) | 
|  | 2430 | { | 
|  | 2431 | tag_decl_kind = clang::TTK_Class; | 
|  | 2432 | default_accessibility = eAccessPrivate; | 
|  | 2433 | } | 
|  | 2434 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2435 | SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2436 | std::vector<clang::CXXBaseSpecifier *> base_classes; | 
|  | 2437 | std::vector<int> member_accessibilities; | 
|  | 2438 | bool is_a_class = false; | 
|  | 2439 | // Parse members and base classes first | 
|  | 2440 | DWARFDIECollection member_function_dies; | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2441 |  | 
|  | 2442 | DelayedPropertyList delayed_properties; | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2443 | ParseChildMembers (sc, | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2444 | dwarf_cu, | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2445 | die, | 
|  | 2446 | clang_type, | 
|  | 2447 | class_language, | 
|  | 2448 | base_classes, | 
|  | 2449 | member_accessibilities, | 
|  | 2450 | member_function_dies, | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2451 | delayed_properties, | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2452 | default_accessibility, | 
|  | 2453 | is_a_class, | 
|  | 2454 | layout_info); | 
|  | 2455 |  | 
|  | 2456 | // Now parse any methods if there were any... | 
|  | 2457 | size_t num_functions = member_function_dies.Size(); | 
|  | 2458 | if (num_functions > 0) | 
|  | 2459 | { | 
|  | 2460 | for (size_t i=0; i<num_functions; ++i) | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2461 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2462 | ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i)); | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2463 | } | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2464 | } | 
|  | 2465 |  | 
|  | 2466 | if (class_language == eLanguageTypeObjC) | 
|  | 2467 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2468 | std::string class_str (clang_type.GetTypeName()); | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2469 | if (!class_str.empty()) | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2470 | { | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2471 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2472 | DIEArray method_die_offsets; | 
|  | 2473 | if (m_using_apple_tables) | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2474 | { | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2475 | if (m_apple_objc_ap.get()) | 
|  | 2476 | m_apple_objc_ap->FindByName(class_str.c_str(), method_die_offsets); | 
|  | 2477 | } | 
|  | 2478 | else | 
|  | 2479 | { | 
|  | 2480 | if (!m_indexed) | 
|  | 2481 | Index (); | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2482 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2483 | ConstString class_name (class_str.c_str()); | 
|  | 2484 | m_objc_class_selectors_index.Find (class_name, method_die_offsets); | 
|  | 2485 | } | 
|  | 2486 |  | 
|  | 2487 | if (!method_die_offsets.empty()) | 
|  | 2488 | { | 
|  | 2489 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 2490 |  | 
|  | 2491 | DWARFCompileUnit* method_cu = NULL; | 
|  | 2492 | const size_t num_matches = method_die_offsets.size(); | 
|  | 2493 | for (size_t i=0; i<num_matches; ++i) | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2494 | { | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2495 | const dw_offset_t die_offset = method_die_offsets[i]; | 
|  | 2496 | DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu); | 
|  | 2497 |  | 
|  | 2498 | if (method_die) | 
|  | 2499 | ResolveType (method_cu, method_die); | 
|  | 2500 | else | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2501 | { | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2502 | if (m_using_apple_tables) | 
|  | 2503 | { | 
|  | 2504 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n", | 
|  | 2505 | die_offset, class_str.c_str()); | 
|  | 2506 | } | 
|  | 2507 | } | 
|  | 2508 | } | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2509 | } | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2510 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2511 | for (DelayedPropertyList::iterator pi = delayed_properties.begin(), pe = delayed_properties.end(); | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2512 | pi != pe; | 
|  | 2513 | ++pi) | 
|  | 2514 | pi->Finalize(); | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2515 | } | 
|  | 2516 | } | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2517 |  | 
|  | 2518 | // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we | 
|  | 2519 | // need to tell the clang type it is actually a class. | 
|  | 2520 | if (class_language != eLanguageTypeObjC) | 
|  | 2521 | { | 
|  | 2522 | if (is_a_class && tag_decl_kind != clang::TTK_Class) | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2523 | clang_type.SetTagTypeKind (clang::TTK_Class); | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2524 | } | 
|  | 2525 |  | 
|  | 2526 | // Since DW_TAG_structure_type gets used for both classes | 
|  | 2527 | // and structures, we may need to set any DW_TAG_member | 
|  | 2528 | // fields to have a "private" access if none was specified. | 
|  | 2529 | // When we parsed the child members we tracked that actual | 
|  | 2530 | // accessibility value for each DW_TAG_member in the | 
|  | 2531 | // "member_accessibilities" array. If the value for the | 
|  | 2532 | // member is zero, then it was set to the "default_accessibility" | 
|  | 2533 | // which for structs was "public". Below we correct this | 
|  | 2534 | // by setting any fields to "private" that weren't correctly | 
|  | 2535 | // set. | 
|  | 2536 | if (is_a_class && !member_accessibilities.empty()) | 
|  | 2537 | { | 
|  | 2538 | // This is a class and all members that didn't have | 
|  | 2539 | // their access specified are private. | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2540 | clang_type.SetDefaultAccessForRecordFields (eAccessPrivate, | 
|  | 2541 | &member_accessibilities.front(), | 
|  | 2542 | member_accessibilities.size()); | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2543 | } | 
|  | 2544 |  | 
|  | 2545 | if (!base_classes.empty()) | 
|  | 2546 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2547 | clang_type.SetBaseClassesForClassType (&base_classes.front(), | 
|  | 2548 | base_classes.size()); | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2549 |  | 
|  | 2550 | // Clang will copy each CXXBaseSpecifier in "base_classes" | 
|  | 2551 | // so we have to free them all. | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2552 | ClangASTType::DeleteBaseClassSpecifiers (&base_classes.front(), | 
|  | 2553 | base_classes.size()); | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2554 | } | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2555 | } | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2556 | } | 
| Sean Callanan | e8c0cfb | 2012-03-02 01:03:45 +0000 | [diff] [blame] | 2557 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2558 | clang_type.BuildIndirectFields (); | 
|  | 2559 | clang_type.CompleteTagDeclarationDefinition (); | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2560 |  | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2561 | if (!layout_info.field_offsets.empty() || | 
|  | 2562 | !layout_info.base_offsets.empty()  || | 
|  | 2563 | !layout_info.vbase_offsets.empty() ) | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2564 | { | 
|  | 2565 | if (type) | 
|  | 2566 | layout_info.bit_size = type->GetByteSize() * 8; | 
|  | 2567 | if (layout_info.bit_size == 0) | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2568 | layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8; | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2569 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2570 | clang::CXXRecordDecl *record_decl = clang_type.GetAsCXXRecordDecl(); | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2571 | if (record_decl) | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2572 | { | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2573 | if (log) | 
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2574 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2575 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2576 | "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])", | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2577 | clang_type.GetOpaqueQualType(), | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2578 | record_decl, | 
|  | 2579 | layout_info.bit_size, | 
|  | 2580 | layout_info.alignment, | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2581 | (uint32_t)layout_info.field_offsets.size(), | 
|  | 2582 | (uint32_t)layout_info.base_offsets.size(), | 
|  | 2583 | (uint32_t)layout_info.vbase_offsets.size()); | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2584 |  | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2585 | uint32_t idx; | 
|  | 2586 | { | 
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2587 | llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end(); | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2588 | for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx) | 
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2589 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2590 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2591 | "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = { bit_offset=%u, name='%s' }", | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2592 | clang_type.GetOpaqueQualType(), | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2593 | idx, | 
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2594 | (uint32_t)pos->second, | 
|  | 2595 | pos->first->getNameAsString().c_str()); | 
|  | 2596 | } | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2597 | } | 
|  | 2598 |  | 
|  | 2599 | { | 
|  | 2600 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos, base_end = layout_info.base_offsets.end(); | 
|  | 2601 | for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end; ++base_pos, ++idx) | 
|  | 2602 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2603 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2604 | "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] = { byte_offset=%u, name='%s' }", | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2605 | clang_type.GetOpaqueQualType(), | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2606 | idx, | 
|  | 2607 | (uint32_t)base_pos->second.getQuantity(), | 
|  | 2608 | base_pos->first->getNameAsString().c_str()); | 
|  | 2609 | } | 
|  | 2610 | } | 
|  | 2611 | { | 
|  | 2612 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos, vbase_end = layout_info.vbase_offsets.end(); | 
|  | 2613 | for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end; ++vbase_pos, ++idx) | 
|  | 2614 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2615 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2616 | "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) vbase[%u] = { byte_offset=%u, name='%s' }", | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2617 | clang_type.GetOpaqueQualType(), | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2618 | idx, | 
|  | 2619 | (uint32_t)vbase_pos->second.getQuantity(), | 
|  | 2620 | vbase_pos->first->getNameAsString().c_str()); | 
|  | 2621 | } | 
|  | 2622 | } | 
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2623 | } | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2624 | m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info)); | 
|  | 2625 | } | 
|  | 2626 | } | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2627 | } | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2628 |  | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2629 | return clang_type; | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2630 |  | 
|  | 2631 | case DW_TAG_enumeration_type: | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2632 | clang_type.StartTagDeclarationDefinition (); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2633 | if (die->HasChildren()) | 
|  | 2634 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2635 | SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); | 
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 2636 | bool is_signed = false; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2637 | clang_type.IsIntegerType(is_signed); | 
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 2638 | ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), dwarf_cu, die); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2639 | } | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2640 | clang_type.CompleteTagDeclarationDefinition (); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2641 | return clang_type; | 
|  | 2642 |  | 
|  | 2643 | default: | 
|  | 2644 | assert(false && "not a forward clang type decl!"); | 
|  | 2645 | break; | 
|  | 2646 | } | 
| Ashok Thirumurthi | a4658a5 | 2013-07-30 14:58:39 +0000 | [diff] [blame] | 2647 | return false; | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2648 | } | 
|  | 2649 |  | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2650 | Type* | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2651 | 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] | 2652 | { | 
|  | 2653 | if (type_die != NULL) | 
|  | 2654 | { | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 2655 | Type *type = m_die_to_type.lookup (type_die); | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2656 |  | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2657 | if (type == NULL) | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2658 | type = GetTypeForDIE (dwarf_cu, type_die).get(); | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2659 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2660 | if (assert_not_being_parsed) | 
| Jim Ingham | c354928 | 2012-01-11 02:21:12 +0000 | [diff] [blame] | 2661 | { | 
|  | 2662 | if (type != DIE_IS_BEING_PARSED) | 
|  | 2663 | return type; | 
|  | 2664 |  | 
|  | 2665 | 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] | 2666 | type_die->GetOffset(), | 
|  | 2667 | DW_TAG_value_to_name(type_die->Tag()), | 
|  | 2668 | type_die->GetName(this, dwarf_cu)); | 
| Jim Ingham | c354928 | 2012-01-11 02:21:12 +0000 | [diff] [blame] | 2669 |  | 
|  | 2670 | } | 
|  | 2671 | else | 
|  | 2672 | return type; | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2673 | } | 
|  | 2674 | return NULL; | 
|  | 2675 | } | 
|  | 2676 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2677 | CompileUnit* | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2678 | SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2679 | { | 
|  | 2680 | // Check if the symbol vendor already knows about this compile unit? | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2681 | if (dwarf_cu->GetUserData() == NULL) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2682 | { | 
|  | 2683 | // The symbol vendor doesn't know about this compile unit, we | 
|  | 2684 | // need to parse and add it to the symbol vendor object. | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2685 | return ParseCompileUnit(dwarf_cu, cu_idx).get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2686 | } | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2687 | return (CompileUnit*)dwarf_cu->GetUserData(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2688 | } | 
|  | 2689 |  | 
|  | 2690 | bool | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2691 | SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2692 | { | 
| Greg Clayton | 7231035 | 2013-02-23 04:12:47 +0000 | [diff] [blame] | 2693 | sc.Clear(false); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2694 | // Check if the symbol vendor already knows about this compile unit? | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2695 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2696 |  | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2697 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2698 | if (sc.function == NULL) | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2699 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2700 |  | 
|  | 2701 | if (sc.function) | 
|  | 2702 | { | 
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 2703 | sc.module_sp = sc.function->CalculateSymbolContextModule(); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2704 | return true; | 
|  | 2705 | } | 
|  | 2706 |  | 
|  | 2707 | return false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2708 | } | 
|  | 2709 |  | 
|  | 2710 | uint32_t | 
|  | 2711 | SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) | 
|  | 2712 | { | 
|  | 2713 | Timer scoped_timer(__PRETTY_FUNCTION__, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2714 | "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%" PRIx64 " }, resolve_scope = 0x%8.8x)", | 
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 2715 | so_addr.GetSection().get(), | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2716 | so_addr.GetOffset(), | 
|  | 2717 | resolve_scope); | 
|  | 2718 | uint32_t resolved = 0; | 
|  | 2719 | if (resolve_scope & (   eSymbolContextCompUnit | | 
|  | 2720 | eSymbolContextFunction | | 
|  | 2721 | eSymbolContextBlock | | 
|  | 2722 | eSymbolContextLineEntry)) | 
|  | 2723 | { | 
|  | 2724 | lldb::addr_t file_vm_addr = so_addr.GetFileAddress(); | 
|  | 2725 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2726 | DWARFDebugInfo* debug_info = DebugInfo(); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2727 | if (debug_info) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2728 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2729 | const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2730 | if (cu_offset != DW_INVALID_OFFSET) | 
|  | 2731 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2732 | uint32_t cu_idx = DW_INVALID_INDEX; | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2733 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get(); | 
|  | 2734 | if (dwarf_cu) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2735 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2736 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2737 | if (sc.comp_unit) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2738 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2739 | resolved |= eSymbolContextCompUnit; | 
|  | 2740 |  | 
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2741 | bool force_check_line_table = false; | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2742 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) | 
|  | 2743 | { | 
|  | 2744 | DWARFDebugInfoEntry *function_die = NULL; | 
|  | 2745 | DWARFDebugInfoEntry *block_die = NULL; | 
|  | 2746 | if (resolve_scope & eSymbolContextBlock) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2747 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2748 | dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die); | 
|  | 2749 | } | 
|  | 2750 | else | 
|  | 2751 | { | 
|  | 2752 | dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL); | 
|  | 2753 | } | 
|  | 2754 |  | 
|  | 2755 | if (function_die != NULL) | 
|  | 2756 | { | 
|  | 2757 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); | 
|  | 2758 | if (sc.function == NULL) | 
|  | 2759 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die); | 
|  | 2760 | } | 
|  | 2761 | else | 
|  | 2762 | { | 
|  | 2763 | // We might have had a compile unit that had discontiguous | 
|  | 2764 | // address ranges where the gaps are symbols that don't have | 
|  | 2765 | // any debug info. Discontiguous compile unit address ranges | 
|  | 2766 | // should only happen when there aren't other functions from | 
|  | 2767 | // other compile units in these gaps. This helps keep the size | 
|  | 2768 | // of the aranges down. | 
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2769 | force_check_line_table = true; | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2770 | } | 
|  | 2771 |  | 
|  | 2772 | if (sc.function != NULL) | 
|  | 2773 | { | 
|  | 2774 | resolved |= eSymbolContextFunction; | 
|  | 2775 |  | 
|  | 2776 | if (resolve_scope & eSymbolContextBlock) | 
|  | 2777 | { | 
|  | 2778 | Block& block = sc.function->GetBlock (true); | 
|  | 2779 |  | 
|  | 2780 | if (block_die != NULL) | 
|  | 2781 | sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); | 
|  | 2782 | else | 
|  | 2783 | sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); | 
|  | 2784 | if (sc.block) | 
|  | 2785 | resolved |= eSymbolContextBlock; | 
|  | 2786 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2787 | } | 
|  | 2788 | } | 
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2789 |  | 
|  | 2790 | if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table) | 
|  | 2791 | { | 
|  | 2792 | LineTable *line_table = sc.comp_unit->GetLineTable(); | 
|  | 2793 | if (line_table != NULL) | 
|  | 2794 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 2795 | // And address that makes it into this function should be in terms | 
|  | 2796 | // of this debug file if there is no debug map, or it will be an | 
|  | 2797 | // address in the .o file which needs to be fixed up to be in terms | 
|  | 2798 | // of the debug map executable. Either way, calling FixupAddress() | 
|  | 2799 | // will work for us. | 
|  | 2800 | Address exe_so_addr (so_addr); | 
|  | 2801 | if (FixupAddress(exe_so_addr)) | 
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2802 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 2803 | if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry)) | 
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2804 | { | 
|  | 2805 | resolved |= eSymbolContextLineEntry; | 
|  | 2806 | } | 
|  | 2807 | } | 
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2808 | } | 
|  | 2809 | } | 
|  | 2810 |  | 
|  | 2811 | if (force_check_line_table && !(resolved & eSymbolContextLineEntry)) | 
|  | 2812 | { | 
|  | 2813 | // We might have had a compile unit that had discontiguous | 
|  | 2814 | // address ranges where the gaps are symbols that don't have | 
|  | 2815 | // any debug info. Discontiguous compile unit address ranges | 
|  | 2816 | // should only happen when there aren't other functions from | 
|  | 2817 | // other compile units in these gaps. This helps keep the size | 
|  | 2818 | // of the aranges down. | 
|  | 2819 | sc.comp_unit = NULL; | 
|  | 2820 | resolved &= ~eSymbolContextCompUnit; | 
|  | 2821 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2822 | } | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2823 | else | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2824 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2825 | GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.", | 
|  | 2826 | cu_offset, | 
|  | 2827 | cu_idx); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2828 | } | 
|  | 2829 | } | 
|  | 2830 | } | 
|  | 2831 | } | 
|  | 2832 | } | 
|  | 2833 | return resolved; | 
|  | 2834 | } | 
|  | 2835 |  | 
|  | 2836 |  | 
|  | 2837 |  | 
|  | 2838 | uint32_t | 
|  | 2839 | SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) | 
|  | 2840 | { | 
|  | 2841 | const uint32_t prev_size = sc_list.GetSize(); | 
|  | 2842 | if (resolve_scope & eSymbolContextCompUnit) | 
|  | 2843 | { | 
|  | 2844 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 2845 | if (debug_info) | 
|  | 2846 | { | 
|  | 2847 | uint32_t cu_idx; | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2848 | DWARFCompileUnit* dwarf_cu = NULL; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2849 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2850 | 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] | 2851 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2852 | CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 2853 | const bool full_match = file_spec.GetDirectory(); | 
|  | 2854 | 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] | 2855 | if (check_inlines || file_spec_matches_cu_file_spec) | 
|  | 2856 | { | 
|  | 2857 | SymbolContext sc (m_obj_file->GetModule()); | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2858 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2859 | if (sc.comp_unit) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2860 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2861 | uint32_t file_idx = UINT32_MAX; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2862 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2863 | // If we are looking for inline functions only and we don't | 
|  | 2864 | // find it in the support files, we are done. | 
|  | 2865 | if (check_inlines) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2866 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2867 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); | 
|  | 2868 | if (file_idx == UINT32_MAX) | 
|  | 2869 | continue; | 
|  | 2870 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2871 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2872 | if (line != 0) | 
|  | 2873 | { | 
|  | 2874 | LineTable *line_table = sc.comp_unit->GetLineTable(); | 
|  | 2875 |  | 
|  | 2876 | if (line_table != NULL && line != 0) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2877 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2878 | // We will have already looked up the file index if | 
|  | 2879 | // we are searching for inline entries. | 
|  | 2880 | if (!check_inlines) | 
|  | 2881 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2882 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2883 | if (file_idx != UINT32_MAX) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2884 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2885 | uint32_t found_line; | 
|  | 2886 | uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry); | 
|  | 2887 | found_line = sc.line_entry.line; | 
|  | 2888 |  | 
|  | 2889 | while (line_idx != UINT32_MAX) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2890 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2891 | sc.function = NULL; | 
|  | 2892 | sc.block = NULL; | 
|  | 2893 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2894 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2895 | const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress(); | 
|  | 2896 | if (file_vm_addr != LLDB_INVALID_ADDRESS) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2897 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2898 | DWARFDebugInfoEntry *function_die = NULL; | 
|  | 2899 | DWARFDebugInfoEntry *block_die = NULL; | 
|  | 2900 | 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] | 2901 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2902 | if (function_die != NULL) | 
|  | 2903 | { | 
|  | 2904 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); | 
|  | 2905 | if (sc.function == NULL) | 
|  | 2906 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die); | 
|  | 2907 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2908 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2909 | if (sc.function != NULL) | 
|  | 2910 | { | 
|  | 2911 | Block& block = sc.function->GetBlock (true); | 
|  | 2912 |  | 
|  | 2913 | if (block_die != NULL) | 
|  | 2914 | sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); | 
|  | 2915 | else | 
|  | 2916 | sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); | 
|  | 2917 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2918 | } | 
|  | 2919 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2920 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2921 | sc_list.Append(sc); | 
|  | 2922 | line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry); | 
|  | 2923 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2924 | } | 
|  | 2925 | } | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2926 | else if (file_spec_matches_cu_file_spec && !check_inlines) | 
|  | 2927 | { | 
|  | 2928 | // only append the context if we aren't looking for inline call sites | 
|  | 2929 | // by file and line and if the file spec matches that of the compile unit | 
|  | 2930 | sc_list.Append(sc); | 
|  | 2931 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2932 | } | 
|  | 2933 | else if (file_spec_matches_cu_file_spec && !check_inlines) | 
|  | 2934 | { | 
|  | 2935 | // only append the context if we aren't looking for inline call sites | 
|  | 2936 | // by file and line and if the file spec matches that of the compile unit | 
|  | 2937 | sc_list.Append(sc); | 
|  | 2938 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2939 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2940 | if (!check_inlines) | 
|  | 2941 | break; | 
|  | 2942 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2943 | } | 
|  | 2944 | } | 
|  | 2945 | } | 
|  | 2946 | } | 
|  | 2947 | return sc_list.GetSize() - prev_size; | 
|  | 2948 | } | 
|  | 2949 |  | 
|  | 2950 | void | 
|  | 2951 | SymbolFileDWARF::Index () | 
|  | 2952 | { | 
|  | 2953 | if (m_indexed) | 
|  | 2954 | return; | 
|  | 2955 | m_indexed = true; | 
|  | 2956 | Timer scoped_timer (__PRETTY_FUNCTION__, | 
|  | 2957 | "SymbolFileDWARF::Index (%s)", | 
|  | 2958 | GetObjectFile()->GetFileSpec().GetFilename().AsCString()); | 
|  | 2959 |  | 
|  | 2960 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 2961 | if (debug_info) | 
|  | 2962 | { | 
|  | 2963 | uint32_t cu_idx = 0; | 
|  | 2964 | const uint32_t num_compile_units = GetNumCompileUnits(); | 
|  | 2965 | for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) | 
|  | 2966 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2967 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2968 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2969 | bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2970 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2971 | dwarf_cu->Index (cu_idx, | 
|  | 2972 | m_function_basename_index, | 
|  | 2973 | m_function_fullname_index, | 
|  | 2974 | m_function_method_index, | 
|  | 2975 | m_function_selector_index, | 
|  | 2976 | m_objc_class_selectors_index, | 
|  | 2977 | m_global_index, | 
|  | 2978 | m_type_index, | 
|  | 2979 | m_namespace_index); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2980 |  | 
|  | 2981 | // Keep memory down by clearing DIEs if this generate function | 
|  | 2982 | // caused them to be parsed | 
|  | 2983 | if (clear_dies) | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2984 | dwarf_cu->ClearDIEs (true); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2985 | } | 
|  | 2986 |  | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2987 | m_function_basename_index.Finalize(); | 
|  | 2988 | m_function_fullname_index.Finalize(); | 
|  | 2989 | m_function_method_index.Finalize(); | 
|  | 2990 | m_function_selector_index.Finalize(); | 
|  | 2991 | m_objc_class_selectors_index.Finalize(); | 
|  | 2992 | m_global_index.Finalize(); | 
|  | 2993 | m_type_index.Finalize(); | 
|  | 2994 | m_namespace_index.Finalize(); | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2995 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2996 | #if defined (ENABLE_DEBUG_PRINTF) | 
| Greg Clayton | 7bd65b9 | 2011-02-09 23:39:34 +0000 | [diff] [blame] | 2997 | StreamFile s(stdout, false); | 
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 2998 | s.Printf ("DWARF index for '%s':", | 
|  | 2999 | GetObjectFile()->GetFileSpec().GetPath().c_str()); | 
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 3000 | s.Printf("\nFunction basenames:\n");    m_function_basename_index.Dump (&s); | 
|  | 3001 | s.Printf("\nFunction fullnames:\n");    m_function_fullname_index.Dump (&s); | 
|  | 3002 | s.Printf("\nFunction methods:\n");      m_function_method_index.Dump (&s); | 
|  | 3003 | s.Printf("\nFunction selectors:\n");    m_function_selector_index.Dump (&s); | 
|  | 3004 | s.Printf("\nObjective C class selectors:\n");    m_objc_class_selectors_index.Dump (&s); | 
|  | 3005 | s.Printf("\nGlobals and statics:\n");   m_global_index.Dump (&s); | 
| Greg Clayton | 69b0488 | 2010-10-15 02:03:22 +0000 | [diff] [blame] | 3006 | s.Printf("\nTypes:\n");                 m_type_index.Dump (&s); | 
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 3007 | s.Printf("\nNamepaces:\n");             m_namespace_index.Dump (&s); | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3008 | #endif | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3009 | } | 
|  | 3010 | } | 
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 3011 |  | 
|  | 3012 | bool | 
|  | 3013 | SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl) | 
|  | 3014 | { | 
|  | 3015 | if (namespace_decl == NULL) | 
|  | 3016 | { | 
|  | 3017 | // Invalid namespace decl which means we aren't matching only things | 
|  | 3018 | // in this symbol file, so return true to indicate it matches this | 
|  | 3019 | // symbol file. | 
|  | 3020 | return true; | 
|  | 3021 | } | 
|  | 3022 |  | 
|  | 3023 | clang::ASTContext *namespace_ast = namespace_decl->GetASTContext(); | 
|  | 3024 |  | 
|  | 3025 | if (namespace_ast == NULL) | 
|  | 3026 | return true;    // No AST in the "namespace_decl", return true since it | 
|  | 3027 | // could then match any symbol file, including this one | 
|  | 3028 |  | 
|  | 3029 | if (namespace_ast == GetClangASTContext().getASTContext()) | 
|  | 3030 | return true;    // The ASTs match, return true | 
|  | 3031 |  | 
|  | 3032 | // The namespace AST was valid, and it does not match... | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3033 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Sean Callanan | c41e68b | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 3034 |  | 
|  | 3035 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3036 | GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file"); | 
| Sean Callanan | c41e68b | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 3037 |  | 
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 3038 | return false; | 
|  | 3039 | } | 
|  | 3040 |  | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3041 | bool | 
|  | 3042 | SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl, | 
|  | 3043 | DWARFCompileUnit* cu, | 
|  | 3044 | const DWARFDebugInfoEntry* die) | 
|  | 3045 | { | 
|  | 3046 | // No namespace specified, so the answesr i | 
|  | 3047 | if (namespace_decl == NULL) | 
|  | 3048 | return true; | 
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 3049 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3050 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 3051 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3052 | const DWARFDebugInfoEntry *decl_ctx_die = NULL; | 
|  | 3053 | clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die); | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3054 | if (decl_ctx_die) | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3055 | { | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3056 | clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl(); | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3057 |  | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3058 | if (clang_namespace_decl) | 
|  | 3059 | { | 
|  | 3060 | if (decl_ctx_die->Tag() != DW_TAG_namespace) | 
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 3061 | { | 
|  | 3062 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3063 | 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] | 3064 | return false; | 
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 3065 | } | 
|  | 3066 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3067 | if (clang_namespace_decl == die_clang_decl_ctx) | 
|  | 3068 | return true; | 
|  | 3069 | else | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3070 | return false; | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3071 | } | 
|  | 3072 | else | 
|  | 3073 | { | 
|  | 3074 | // We have a namespace_decl that was not NULL but it contained | 
|  | 3075 | // a NULL "clang::NamespaceDecl", so this means the global namespace | 
|  | 3076 | // So as long the the contained decl context DIE isn't a namespace | 
|  | 3077 | // we should be ok. | 
|  | 3078 | if (decl_ctx_die->Tag() != DW_TAG_namespace) | 
|  | 3079 | return true; | 
|  | 3080 | } | 
|  | 3081 | } | 
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 3082 |  | 
|  | 3083 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3084 | 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] | 3085 |  | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3086 | return false; | 
|  | 3087 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3088 | uint32_t | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3089 | 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] | 3090 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3091 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3092 |  | 
|  | 3093 | if (log) | 
|  | 3094 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3095 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3096 | "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)", | 
|  | 3097 | name.GetCString(), | 
|  | 3098 | namespace_decl, | 
|  | 3099 | append, | 
|  | 3100 | max_matches); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3101 | } | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3102 |  | 
|  | 3103 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) | 
|  | 3104 | return 0; | 
|  | 3105 |  | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3106 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 3107 | if (info == NULL) | 
|  | 3108 | return 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3109 |  | 
|  | 3110 | // If we aren't appending the results to this list, then clear the list | 
|  | 3111 | if (!append) | 
|  | 3112 | variables.Clear(); | 
|  | 3113 |  | 
|  | 3114 | // Remember how many variables are in the list before we search in case | 
|  | 3115 | // we are appending the results to a variable list. | 
|  | 3116 | const uint32_t original_size = variables.GetSize(); | 
|  | 3117 |  | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3118 | DIEArray die_offsets; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3119 |  | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3120 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3121 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3122 | if (m_apple_names_ap.get()) | 
|  | 3123 | { | 
|  | 3124 | const char *name_cstr = name.GetCString(); | 
|  | 3125 | const char *base_name_start; | 
|  | 3126 | const char *base_name_end = NULL; | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3127 |  | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3128 | if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end)) | 
|  | 3129 | base_name_start = name_cstr; | 
|  | 3130 |  | 
|  | 3131 | m_apple_names_ap->FindByName (base_name_start, die_offsets); | 
|  | 3132 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3133 | } | 
|  | 3134 | else | 
|  | 3135 | { | 
|  | 3136 | // Index the DWARF if we haven't already | 
|  | 3137 | if (!m_indexed) | 
|  | 3138 | Index (); | 
|  | 3139 |  | 
|  | 3140 | m_global_index.Find (name, die_offsets); | 
|  | 3141 | } | 
|  | 3142 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3143 | const size_t num_die_matches = die_offsets.size(); | 
|  | 3144 | if (num_die_matches) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3145 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3146 | SymbolContext sc; | 
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 3147 | sc.module_sp = m_obj_file->GetModule(); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3148 | assert (sc.module_sp); | 
|  | 3149 |  | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3150 | DWARFDebugInfo* debug_info = DebugInfo(); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3151 | DWARFCompileUnit* dwarf_cu = NULL; | 
|  | 3152 | const DWARFDebugInfoEntry* die = NULL; | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3153 | bool done = false; | 
|  | 3154 | for (size_t i=0; i<num_die_matches && !done; ++i) | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3155 | { | 
|  | 3156 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 3157 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3158 |  | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3159 | if (die) | 
|  | 3160 | { | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3161 | switch (die->Tag()) | 
|  | 3162 | { | 
|  | 3163 | default: | 
|  | 3164 | case DW_TAG_subprogram: | 
|  | 3165 | case DW_TAG_inlined_subroutine: | 
|  | 3166 | case DW_TAG_try_block: | 
|  | 3167 | case DW_TAG_catch_block: | 
|  | 3168 | break; | 
|  | 3169 |  | 
|  | 3170 | case DW_TAG_variable: | 
|  | 3171 | { | 
|  | 3172 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3173 |  | 
|  | 3174 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) | 
|  | 3175 | continue; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3176 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3177 | ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3178 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3179 | if (variables.GetSize() - original_size >= max_matches) | 
|  | 3180 | done = true; | 
|  | 3181 | } | 
|  | 3182 | break; | 
|  | 3183 | } | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3184 | } | 
|  | 3185 | else | 
|  | 3186 | { | 
|  | 3187 | if (m_using_apple_tables) | 
|  | 3188 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3189 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n", | 
|  | 3190 | die_offset, name.GetCString()); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3191 | } | 
|  | 3192 | } | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3193 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3194 | } | 
|  | 3195 |  | 
|  | 3196 | // Return the number of variable that were appended to the list | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3197 | const uint32_t num_matches = variables.GetSize() - original_size; | 
|  | 3198 | if (log && num_matches > 0) | 
|  | 3199 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3200 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3201 | "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u", | 
|  | 3202 | name.GetCString(), | 
|  | 3203 | namespace_decl, | 
|  | 3204 | append, | 
|  | 3205 | max_matches, | 
|  | 3206 | num_matches); | 
|  | 3207 | } | 
|  | 3208 | return num_matches; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3209 | } | 
|  | 3210 |  | 
|  | 3211 | uint32_t | 
|  | 3212 | SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables) | 
|  | 3213 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3214 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3215 |  | 
|  | 3216 | if (log) | 
|  | 3217 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3218 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3219 | "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)", | 
|  | 3220 | regex.GetText(), | 
|  | 3221 | append, | 
|  | 3222 | max_matches); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3223 | } | 
|  | 3224 |  | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3225 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 3226 | if (info == NULL) | 
|  | 3227 | return 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3228 |  | 
|  | 3229 | // If we aren't appending the results to this list, then clear the list | 
|  | 3230 | if (!append) | 
|  | 3231 | variables.Clear(); | 
|  | 3232 |  | 
|  | 3233 | // Remember how many variables are in the list before we search in case | 
|  | 3234 | // we are appending the results to a variable list. | 
|  | 3235 | const uint32_t original_size = variables.GetSize(); | 
|  | 3236 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3237 | DIEArray die_offsets; | 
|  | 3238 |  | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3239 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3240 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3241 | if (m_apple_names_ap.get()) | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3242 | { | 
|  | 3243 | DWARFMappedHash::DIEInfoArray hash_data_array; | 
|  | 3244 | if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) | 
|  | 3245 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); | 
|  | 3246 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3247 | } | 
|  | 3248 | else | 
|  | 3249 | { | 
|  | 3250 | // Index the DWARF if we haven't already | 
|  | 3251 | if (!m_indexed) | 
|  | 3252 | Index (); | 
|  | 3253 |  | 
|  | 3254 | m_global_index.Find (regex, die_offsets); | 
|  | 3255 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3256 |  | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3257 | SymbolContext sc; | 
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 3258 | sc.module_sp = m_obj_file->GetModule(); | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3259 | assert (sc.module_sp); | 
|  | 3260 |  | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3261 | DWARFCompileUnit* dwarf_cu = NULL; | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3262 | const DWARFDebugInfoEntry* die = NULL; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3263 | const size_t num_matches = die_offsets.size(); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3264 | if (num_matches) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3265 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3266 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 3267 | for (size_t i=0; i<num_matches; ++i) | 
|  | 3268 | { | 
|  | 3269 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 3270 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3271 |  | 
|  | 3272 | if (die) | 
|  | 3273 | { | 
|  | 3274 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3275 |  | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3276 | ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3277 |  | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3278 | if (variables.GetSize() - original_size >= max_matches) | 
|  | 3279 | break; | 
|  | 3280 | } | 
|  | 3281 | else | 
|  | 3282 | { | 
|  | 3283 | if (m_using_apple_tables) | 
|  | 3284 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3285 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n", | 
|  | 3286 | die_offset, regex.GetText()); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3287 | } | 
|  | 3288 | } | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3289 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3290 | } | 
|  | 3291 |  | 
|  | 3292 | // Return the number of variable that were appended to the list | 
|  | 3293 | return variables.GetSize() - original_size; | 
|  | 3294 | } | 
|  | 3295 |  | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3296 |  | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3297 | bool | 
|  | 3298 | SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset, | 
|  | 3299 | DWARFCompileUnit *&dwarf_cu, | 
|  | 3300 | SymbolContextList& sc_list) | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3301 | { | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3302 | const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
|  | 3303 | return ResolveFunction (dwarf_cu, die, sc_list); | 
|  | 3304 | } | 
|  | 3305 |  | 
|  | 3306 |  | 
|  | 3307 | bool | 
|  | 3308 | SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu, | 
|  | 3309 | const DWARFDebugInfoEntry *die, | 
|  | 3310 | SymbolContextList& sc_list) | 
|  | 3311 | { | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3312 | SymbolContext sc; | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3313 |  | 
|  | 3314 | if (die == NULL) | 
|  | 3315 | return false; | 
|  | 3316 |  | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3317 | // If we were passed a die that is not a function, just return false... | 
|  | 3318 | if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine) | 
|  | 3319 | return false; | 
|  | 3320 |  | 
|  | 3321 | const DWARFDebugInfoEntry* inlined_die = NULL; | 
|  | 3322 | if (die->Tag() == DW_TAG_inlined_subroutine) | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3323 | { | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3324 | inlined_die = die; | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3325 |  | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3326 | while ((die = die->GetParent()) != NULL) | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3327 | { | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3328 | if (die->Tag() == DW_TAG_subprogram) | 
|  | 3329 | break; | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3330 | } | 
|  | 3331 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3332 | assert (die->Tag() == DW_TAG_subprogram); | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3333 | if (GetFunction (cu, die, sc)) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3334 | { | 
|  | 3335 | Address addr; | 
|  | 3336 | // Parse all blocks if needed | 
|  | 3337 | if (inlined_die) | 
|  | 3338 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 3339 | sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset())); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3340 | assert (sc.block != NULL); | 
|  | 3341 | if (sc.block->GetStartAddress (addr) == false) | 
|  | 3342 | addr.Clear(); | 
|  | 3343 | } | 
|  | 3344 | else | 
|  | 3345 | { | 
|  | 3346 | sc.block = NULL; | 
|  | 3347 | addr = sc.function->GetAddressRange().GetBaseAddress(); | 
|  | 3348 | } | 
|  | 3349 |  | 
|  | 3350 | if (addr.IsValid()) | 
|  | 3351 | { | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3352 | sc_list.Append(sc); | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3353 | return true; | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3354 | } | 
|  | 3355 | } | 
|  | 3356 |  | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3357 | return false; | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3358 | } | 
|  | 3359 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3360 | void | 
|  | 3361 | SymbolFileDWARF::FindFunctions (const ConstString &name, | 
|  | 3362 | const NameToDIE &name_to_die, | 
|  | 3363 | SymbolContextList& sc_list) | 
|  | 3364 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3365 | DIEArray die_offsets; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3366 | if (name_to_die.Find (name, die_offsets)) | 
|  | 3367 | { | 
|  | 3368 | ParseFunctions (die_offsets, sc_list); | 
|  | 3369 | } | 
|  | 3370 | } | 
|  | 3371 |  | 
|  | 3372 |  | 
|  | 3373 | void | 
|  | 3374 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, | 
|  | 3375 | const NameToDIE &name_to_die, | 
|  | 3376 | SymbolContextList& sc_list) | 
|  | 3377 | { | 
|  | 3378 | DIEArray die_offsets; | 
|  | 3379 | if (name_to_die.Find (regex, die_offsets)) | 
|  | 3380 | { | 
|  | 3381 | ParseFunctions (die_offsets, sc_list); | 
|  | 3382 | } | 
|  | 3383 | } | 
|  | 3384 |  | 
|  | 3385 |  | 
|  | 3386 | void | 
|  | 3387 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, | 
|  | 3388 | const DWARFMappedHash::MemoryTable &memory_table, | 
|  | 3389 | SymbolContextList& sc_list) | 
|  | 3390 | { | 
|  | 3391 | DIEArray die_offsets; | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3392 | DWARFMappedHash::DIEInfoArray hash_data_array; | 
|  | 3393 | if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3394 | { | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3395 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3396 | ParseFunctions (die_offsets, sc_list); | 
|  | 3397 | } | 
|  | 3398 | } | 
|  | 3399 |  | 
|  | 3400 | void | 
|  | 3401 | SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets, | 
|  | 3402 | SymbolContextList& sc_list) | 
|  | 3403 | { | 
|  | 3404 | const size_t num_matches = die_offsets.size(); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3405 | if (num_matches) | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3406 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3407 | SymbolContext sc; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3408 |  | 
|  | 3409 | DWARFCompileUnit* dwarf_cu = NULL; | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3410 | for (size_t i=0; i<num_matches; ++i) | 
| Greg Clayton | d7e0546 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 3411 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3412 | const dw_offset_t die_offset = die_offsets[i]; | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3413 | ResolveFunction (die_offset, dwarf_cu, sc_list); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3414 | } | 
|  | 3415 | } | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3416 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3417 |  | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3418 | bool | 
|  | 3419 | SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die, | 
|  | 3420 | const DWARFCompileUnit *dwarf_cu, | 
|  | 3421 | uint32_t name_type_mask, | 
|  | 3422 | const char *partial_name, | 
|  | 3423 | const char *base_name_start, | 
|  | 3424 | const char *base_name_end) | 
|  | 3425 | { | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3426 | // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes: | 
|  | 3427 | if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3428 | { | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 3429 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset()); | 
|  | 3430 | if (!containing_decl_ctx) | 
|  | 3431 | return false; | 
|  | 3432 |  | 
|  | 3433 | bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()); | 
|  | 3434 |  | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3435 | if (name_type_mask == eFunctionNameTypeMethod) | 
|  | 3436 | { | 
|  | 3437 | if (is_cxx_method == false) | 
|  | 3438 | return false; | 
|  | 3439 | } | 
|  | 3440 |  | 
|  | 3441 | if (name_type_mask == eFunctionNameTypeBase) | 
|  | 3442 | { | 
|  | 3443 | if (is_cxx_method == true) | 
|  | 3444 | return false; | 
|  | 3445 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3446 | } | 
|  | 3447 |  | 
|  | 3448 | // Now we need to check whether the name we got back for this type matches the extra specifications | 
|  | 3449 | // that were in the name we're looking up: | 
|  | 3450 | if (base_name_start != partial_name || *base_name_end != '\0') | 
|  | 3451 | { | 
|  | 3452 | // First see if the stuff to the left matches the full name.  To do that let's see if | 
|  | 3453 | // we can pull out the mips linkage name attribute: | 
|  | 3454 |  | 
|  | 3455 | Mangled best_name; | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3456 | DWARFDebugInfoEntry::Attributes attributes; | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3457 | DWARFFormValue form_value; | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3458 | die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
|  | 3459 | uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name); | 
| Greg Clayton | 7141554 | 2012-12-08 00:24:40 +0000 | [diff] [blame] | 3460 | if (idx == UINT32_MAX) | 
|  | 3461 | idx = attributes.FindAttributeIndex(DW_AT_linkage_name); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3462 | if (idx != UINT32_MAX) | 
|  | 3463 | { | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3464 | if (attributes.ExtractFormValueAtIndex(this, idx, form_value)) | 
|  | 3465 | { | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3466 | const char *mangled_name = form_value.AsCString(&get_debug_str_data()); | 
|  | 3467 | if (mangled_name) | 
|  | 3468 | best_name.SetValue (ConstString(mangled_name), true); | 
|  | 3469 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3470 | } | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3471 |  | 
|  | 3472 | if (!best_name) | 
|  | 3473 | { | 
|  | 3474 | idx = attributes.FindAttributeIndex(DW_AT_name); | 
|  | 3475 | if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value)) | 
|  | 3476 | { | 
|  | 3477 | const char *name = form_value.AsCString(&get_debug_str_data()); | 
|  | 3478 | best_name.SetValue (ConstString(name), false); | 
|  | 3479 | } | 
|  | 3480 | } | 
|  | 3481 |  | 
|  | 3482 | if (best_name.GetDemangledName()) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3483 | { | 
|  | 3484 | const char *demangled = best_name.GetDemangledName().GetCString(); | 
|  | 3485 | if (demangled) | 
|  | 3486 | { | 
|  | 3487 | std::string name_no_parens(partial_name, base_name_end - partial_name); | 
| Jim Ingham | 85c13d7 | 2012-03-02 02:24:42 +0000 | [diff] [blame] | 3488 | const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str()); | 
|  | 3489 | if (partial_in_demangled == NULL) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3490 | return false; | 
| Jim Ingham | 85c13d7 | 2012-03-02 02:24:42 +0000 | [diff] [blame] | 3491 | else | 
|  | 3492 | { | 
|  | 3493 | // Sort out the case where our name is something like "Process::Destroy" and the match is | 
|  | 3494 | // "SBProcess::Destroy" - that shouldn't be a match.  We should really always match on | 
|  | 3495 | // namespace boundaries... | 
|  | 3496 |  | 
|  | 3497 | if (partial_name[0] == ':'  && partial_name[1] == ':') | 
|  | 3498 | { | 
|  | 3499 | // The partial name was already on a namespace boundary so all matches are good. | 
|  | 3500 | return true; | 
|  | 3501 | } | 
|  | 3502 | else if (partial_in_demangled == demangled) | 
|  | 3503 | { | 
|  | 3504 | // They both start the same, so this is an good match. | 
|  | 3505 | return true; | 
|  | 3506 | } | 
|  | 3507 | else | 
|  | 3508 | { | 
|  | 3509 | if (partial_in_demangled - demangled == 1) | 
|  | 3510 | { | 
|  | 3511 | // Only one character difference, can't be a namespace boundary... | 
|  | 3512 | return false; | 
|  | 3513 | } | 
|  | 3514 | else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':') | 
|  | 3515 | { | 
|  | 3516 | // We are on a namespace boundary, so this is also good. | 
|  | 3517 | return true; | 
|  | 3518 | } | 
|  | 3519 | else | 
|  | 3520 | return false; | 
|  | 3521 | } | 
|  | 3522 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3523 | } | 
|  | 3524 | } | 
|  | 3525 | } | 
|  | 3526 |  | 
|  | 3527 | return true; | 
|  | 3528 | } | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3529 |  | 
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3530 | uint32_t | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3531 | SymbolFileDWARF::FindFunctions (const ConstString &name, | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3532 | const lldb_private::ClangNamespaceDecl *namespace_decl, | 
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3533 | uint32_t name_type_mask, | 
|  | 3534 | bool include_inlines, | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3535 | bool append, | 
|  | 3536 | SymbolContextList& sc_list) | 
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3537 | { | 
|  | 3538 | Timer scoped_timer (__PRETTY_FUNCTION__, | 
|  | 3539 | "SymbolFileDWARF::FindFunctions (name = '%s')", | 
|  | 3540 | name.AsCString()); | 
|  | 3541 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3542 | // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup() | 
|  | 3543 | assert ((name_type_mask & eFunctionNameTypeAuto) == 0); | 
|  | 3544 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3545 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3546 |  | 
|  | 3547 | if (log) | 
|  | 3548 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3549 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3550 | "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)", | 
|  | 3551 | name.GetCString(), | 
|  | 3552 | name_type_mask, | 
|  | 3553 | append); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3554 | } | 
|  | 3555 |  | 
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3556 | // If we aren't appending the results to this list, then clear the list | 
|  | 3557 | if (!append) | 
|  | 3558 | sc_list.Clear(); | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3559 |  | 
|  | 3560 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) | 
|  | 3561 | return 0; | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3562 |  | 
|  | 3563 | // If name is empty then we won't find anything. | 
|  | 3564 | if (name.IsEmpty()) | 
|  | 3565 | return 0; | 
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3566 |  | 
|  | 3567 | // Remember how many sc_list are in the list before we search in case | 
|  | 3568 | // we are appending the results to a variable list. | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3569 |  | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3570 | const char *name_cstr = name.GetCString(); | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3571 |  | 
|  | 3572 | const uint32_t original_size = sc_list.GetSize(); | 
|  | 3573 |  | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3574 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 3575 | if (info == NULL) | 
|  | 3576 | return 0; | 
|  | 3577 |  | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3578 | DWARFCompileUnit *dwarf_cu = NULL; | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3579 | std::set<const DWARFDebugInfoEntry *> resolved_dies; | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3580 | if (m_using_apple_tables) | 
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 3581 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3582 | if (m_apple_names_ap.get()) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3583 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3584 |  | 
|  | 3585 | DIEArray die_offsets; | 
|  | 3586 |  | 
|  | 3587 | uint32_t num_matches = 0; | 
|  | 3588 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3589 | if (name_type_mask & eFunctionNameTypeFull) | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3590 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3591 | // If they asked for the full name, match what they typed.  At some point we may | 
|  | 3592 | // want to canonicalize this (strip double spaces, etc.  For now, we just add all the | 
|  | 3593 | // dies that we find by exact match. | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3594 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3595 | for (uint32_t i = 0; i < num_matches; i++) | 
|  | 3596 | { | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3597 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 3598 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3599 | if (die) | 
|  | 3600 | { | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3601 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) | 
|  | 3602 | continue; | 
|  | 3603 |  | 
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3604 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) | 
|  | 3605 | continue; | 
|  | 3606 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3607 | if (resolved_dies.find(die) == resolved_dies.end()) | 
|  | 3608 | { | 
|  | 3609 | if (ResolveFunction (dwarf_cu, die, sc_list)) | 
|  | 3610 | resolved_dies.insert(die); | 
|  | 3611 | } | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3612 | } | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3613 | else | 
|  | 3614 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3615 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", | 
|  | 3616 | die_offset, name_cstr); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3617 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3618 | } | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3619 | } | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3620 |  | 
|  | 3621 | if (name_type_mask & eFunctionNameTypeSelector) | 
|  | 3622 | { | 
|  | 3623 | if (namespace_decl && *namespace_decl) | 
|  | 3624 | return 0; // no selectors in namespaces | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3625 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3626 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); | 
|  | 3627 | // Now make sure these are actually ObjC methods.  In this case we can simply look up the name, | 
|  | 3628 | // and if it is an ObjC method name, we're good. | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3629 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3630 | for (uint32_t i = 0; i < num_matches; i++) | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3631 | { | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3632 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 3633 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
|  | 3634 | if (die) | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3635 | { | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3636 | const char *die_name = die->GetName(this, dwarf_cu); | 
|  | 3637 | if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name)) | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3638 | { | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3639 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) | 
|  | 3640 | continue; | 
|  | 3641 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3642 | if (resolved_dies.find(die) == resolved_dies.end()) | 
|  | 3643 | { | 
|  | 3644 | if (ResolveFunction (dwarf_cu, die, sc_list)) | 
|  | 3645 | resolved_dies.insert(die); | 
|  | 3646 | } | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3647 | } | 
|  | 3648 | } | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3649 | else | 
|  | 3650 | { | 
|  | 3651 | GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", | 
|  | 3652 | die_offset, name_cstr); | 
|  | 3653 | } | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3654 | } | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3655 | die_offsets.clear(); | 
|  | 3656 | } | 
|  | 3657 |  | 
|  | 3658 | if (((name_type_mask & eFunctionNameTypeMethod) && !namespace_decl) || name_type_mask & eFunctionNameTypeBase) | 
|  | 3659 | { | 
|  | 3660 | // The apple_names table stores just the "base name" of C++ methods in the table.  So we have to | 
|  | 3661 | // extract the base name, look that up, and if there is any other information in the name we were | 
|  | 3662 | // passed in we have to post-filter based on that. | 
|  | 3663 |  | 
|  | 3664 | // FIXME: Arrange the logic above so that we don't calculate the base name twice: | 
|  | 3665 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); | 
|  | 3666 |  | 
|  | 3667 | for (uint32_t i = 0; i < num_matches; i++) | 
|  | 3668 | { | 
|  | 3669 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 3670 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
|  | 3671 | if (die) | 
|  | 3672 | { | 
|  | 3673 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) | 
|  | 3674 | continue; | 
|  | 3675 |  | 
|  | 3676 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) | 
|  | 3677 | continue; | 
|  | 3678 |  | 
|  | 3679 | // If we get to here, the die is good, and we should add it: | 
|  | 3680 | if (resolved_dies.find(die) == resolved_dies.end()) | 
|  | 3681 | if (ResolveFunction (dwarf_cu, die, sc_list)) | 
|  | 3682 | { | 
|  | 3683 | bool keep_die = true; | 
|  | 3684 | if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod)) | 
|  | 3685 | { | 
|  | 3686 | // We are looking for either basenames or methods, so we need to | 
|  | 3687 | // trim out the ones we won't want by looking at the type | 
|  | 3688 | SymbolContext sc; | 
|  | 3689 | if (sc_list.GetLastContext(sc)) | 
|  | 3690 | { | 
|  | 3691 | if (sc.block) | 
|  | 3692 | { | 
|  | 3693 | // We have an inlined function | 
|  | 3694 | } | 
|  | 3695 | else if (sc.function) | 
|  | 3696 | { | 
|  | 3697 | Type *type = sc.function->GetType(); | 
|  | 3698 |  | 
| Sean Callanan | c370a8a | 2013-09-18 22:59:55 +0000 | [diff] [blame] | 3699 | if (type) | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3700 | { | 
| Sean Callanan | c370a8a | 2013-09-18 22:59:55 +0000 | [diff] [blame] | 3701 | clang::DeclContext* decl_ctx = GetClangDeclContextContainingTypeUID (type->GetID()); | 
|  | 3702 | if (decl_ctx->isRecord()) | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3703 | { | 
| Sean Callanan | c370a8a | 2013-09-18 22:59:55 +0000 | [diff] [blame] | 3704 | if (name_type_mask & eFunctionNameTypeBase) | 
|  | 3705 | { | 
|  | 3706 | sc_list.RemoveContextAtIndex(sc_list.GetSize()-1); | 
|  | 3707 | keep_die = false; | 
|  | 3708 | } | 
|  | 3709 | } | 
|  | 3710 | else | 
|  | 3711 | { | 
|  | 3712 | if (name_type_mask & eFunctionNameTypeMethod) | 
|  | 3713 | { | 
|  | 3714 | sc_list.RemoveContextAtIndex(sc_list.GetSize()-1); | 
|  | 3715 | keep_die = false; | 
|  | 3716 | } | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3717 | } | 
|  | 3718 | } | 
|  | 3719 | else | 
|  | 3720 | { | 
| Sean Callanan | c370a8a | 2013-09-18 22:59:55 +0000 | [diff] [blame] | 3721 | GetObjectFile()->GetModule()->ReportWarning ("function at die offset 0x%8.8x had no function type", | 
|  | 3722 | die_offset); | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3723 | } | 
|  | 3724 | } | 
|  | 3725 | } | 
|  | 3726 | } | 
|  | 3727 | if (keep_die) | 
|  | 3728 | resolved_dies.insert(die); | 
|  | 3729 | } | 
|  | 3730 | } | 
|  | 3731 | else | 
|  | 3732 | { | 
|  | 3733 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", | 
|  | 3734 | die_offset, name_cstr); | 
|  | 3735 | } | 
|  | 3736 | } | 
|  | 3737 | die_offsets.clear(); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3738 | } | 
|  | 3739 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3740 | } | 
|  | 3741 | else | 
|  | 3742 | { | 
|  | 3743 |  | 
|  | 3744 | // Index the DWARF if we haven't already | 
|  | 3745 | if (!m_indexed) | 
|  | 3746 | Index (); | 
|  | 3747 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3748 | if (name_type_mask & eFunctionNameTypeFull) | 
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 3749 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3750 | FindFunctions (name, m_function_fullname_index, sc_list); | 
|  | 3751 |  | 
| Ed Maste | fc7baa0 | 2013-09-09 18:00:45 +0000 | [diff] [blame] | 3752 | // FIXME Temporary workaround for global/anonymous namespace | 
|  | 3753 | // functions on FreeBSD and Linux | 
|  | 3754 | #if defined (__FreeBSD__) || defined (__linux__) | 
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 3755 | // If we didn't find any functions in the global namespace try | 
|  | 3756 | // looking in the basename index but ignore any returned | 
|  | 3757 | // functions that have a namespace (ie. mangled names starting with | 
|  | 3758 | // '_ZN') but keep functions which have an anonymous namespace | 
|  | 3759 | if (sc_list.GetSize() == 0) | 
|  | 3760 | { | 
|  | 3761 | SymbolContextList temp_sc_list; | 
|  | 3762 | FindFunctions (name, m_function_basename_index, temp_sc_list); | 
|  | 3763 | if (!namespace_decl) | 
|  | 3764 | { | 
|  | 3765 | SymbolContext sc; | 
|  | 3766 | for (uint32_t i = 0; i < temp_sc_list.GetSize(); i++) | 
|  | 3767 | { | 
|  | 3768 | if (temp_sc_list.GetContextAtIndex(i, sc)) | 
|  | 3769 | { | 
| Matt Kopec | a189d49 | 2013-05-10 22:55:24 +0000 | [diff] [blame] | 3770 | ConstString mangled_name = sc.GetFunctionName(Mangled::ePreferMangled); | 
|  | 3771 | ConstString demangled_name = sc.GetFunctionName(Mangled::ePreferDemangled); | 
| Matt Kopec | 04e5d58 | 2013-05-14 19:00:41 +0000 | [diff] [blame] | 3772 | if (strncmp(mangled_name.GetCString(), "_ZN", 3) || | 
|  | 3773 | !strncmp(demangled_name.GetCString(), "(anonymous namespace)", 21)) | 
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 3774 | { | 
|  | 3775 | sc_list.Append(sc); | 
|  | 3776 | } | 
|  | 3777 | } | 
|  | 3778 | } | 
|  | 3779 | } | 
|  | 3780 | } | 
|  | 3781 | #endif | 
|  | 3782 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3783 | DIEArray die_offsets; | 
|  | 3784 | DWARFCompileUnit *dwarf_cu = NULL; | 
|  | 3785 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3786 | if (name_type_mask & eFunctionNameTypeBase) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3787 | { | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3788 | uint32_t num_base = m_function_basename_index.Find(name, die_offsets); | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3789 | for (uint32_t i = 0; i < num_base; i++) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3790 | { | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3791 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); | 
|  | 3792 | if (die) | 
|  | 3793 | { | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3794 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) | 
|  | 3795 | continue; | 
|  | 3796 |  | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3797 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) | 
|  | 3798 | continue; | 
|  | 3799 |  | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3800 | // 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] | 3801 | if (resolved_dies.find(die) == resolved_dies.end()) | 
|  | 3802 | { | 
|  | 3803 | if (ResolveFunction (dwarf_cu, die, sc_list)) | 
|  | 3804 | resolved_dies.insert(die); | 
|  | 3805 | } | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3806 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3807 | } | 
|  | 3808 | die_offsets.clear(); | 
|  | 3809 | } | 
|  | 3810 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3811 | if (name_type_mask & eFunctionNameTypeMethod) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3812 | { | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3813 | if (namespace_decl && *namespace_decl) | 
|  | 3814 | return 0; // no methods in namespaces | 
|  | 3815 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3816 | uint32_t num_base = m_function_method_index.Find(name, die_offsets); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3817 | { | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3818 | for (uint32_t i = 0; i < num_base; i++) | 
|  | 3819 | { | 
|  | 3820 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); | 
|  | 3821 | if (die) | 
|  | 3822 | { | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3823 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) | 
|  | 3824 | continue; | 
|  | 3825 |  | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3826 | // 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] | 3827 | if (resolved_dies.find(die) == resolved_dies.end()) | 
|  | 3828 | { | 
|  | 3829 | if (ResolveFunction (dwarf_cu, die, sc_list)) | 
|  | 3830 | resolved_dies.insert(die); | 
|  | 3831 | } | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3832 | } | 
|  | 3833 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3834 | } | 
|  | 3835 | die_offsets.clear(); | 
|  | 3836 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3837 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3838 | if ((name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl)) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3839 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3840 | FindFunctions (name, m_function_selector_index, sc_list); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3841 | } | 
|  | 3842 |  | 
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 3843 | } | 
|  | 3844 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3845 | // Return the number of variable that were appended to the list | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3846 | const uint32_t num_matches = sc_list.GetSize() - original_size; | 
|  | 3847 |  | 
|  | 3848 | if (log && num_matches > 0) | 
|  | 3849 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3850 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3851 | "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list) => %u", | 
|  | 3852 | name.GetCString(), | 
|  | 3853 | name_type_mask, | 
|  | 3854 | append, | 
|  | 3855 | num_matches); | 
|  | 3856 | } | 
|  | 3857 | return num_matches; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3858 | } | 
|  | 3859 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3860 | uint32_t | 
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3861 | 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] | 3862 | { | 
|  | 3863 | Timer scoped_timer (__PRETTY_FUNCTION__, | 
|  | 3864 | "SymbolFileDWARF::FindFunctions (regex = '%s')", | 
|  | 3865 | regex.GetText()); | 
|  | 3866 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3867 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3868 |  | 
|  | 3869 | if (log) | 
|  | 3870 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3871 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3872 | "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)", | 
|  | 3873 | regex.GetText(), | 
|  | 3874 | append); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3875 | } | 
|  | 3876 |  | 
|  | 3877 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3878 | // If we aren't appending the results to this list, then clear the list | 
|  | 3879 | if (!append) | 
|  | 3880 | sc_list.Clear(); | 
|  | 3881 |  | 
|  | 3882 | // Remember how many sc_list are in the list before we search in case | 
|  | 3883 | // we are appending the results to a variable list. | 
|  | 3884 | uint32_t original_size = sc_list.GetSize(); | 
|  | 3885 |  | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3886 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3887 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3888 | if (m_apple_names_ap.get()) | 
|  | 3889 | FindFunctions (regex, *m_apple_names_ap, sc_list); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3890 | } | 
|  | 3891 | else | 
|  | 3892 | { | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3893 | // Index the DWARF if we haven't already | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3894 | if (!m_indexed) | 
|  | 3895 | Index (); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3896 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3897 | FindFunctions (regex, m_function_basename_index, sc_list); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3898 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3899 | FindFunctions (regex, m_function_fullname_index, sc_list); | 
|  | 3900 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3901 |  | 
|  | 3902 | // Return the number of variable that were appended to the list | 
|  | 3903 | return sc_list.GetSize() - original_size; | 
|  | 3904 | } | 
| Jim Ingham | 318c9f2 | 2011-08-26 19:44:13 +0000 | [diff] [blame] | 3905 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3906 | uint32_t | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3907 | SymbolFileDWARF::FindTypes (const SymbolContext& sc, | 
|  | 3908 | const ConstString &name, | 
|  | 3909 | const lldb_private::ClangNamespaceDecl *namespace_decl, | 
|  | 3910 | bool append, | 
|  | 3911 | uint32_t max_matches, | 
|  | 3912 | TypeList& types) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3913 | { | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3914 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 3915 | if (info == NULL) | 
|  | 3916 | return 0; | 
|  | 3917 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3918 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3919 |  | 
|  | 3920 | if (log) | 
|  | 3921 | { | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3922 | if (namespace_decl) | 
|  | 3923 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3924 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3925 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)", | 
|  | 3926 | name.GetCString(), | 
|  | 3927 | namespace_decl->GetNamespaceDecl(), | 
|  | 3928 | namespace_decl->GetQualifiedName().c_str(), | 
|  | 3929 | append, | 
|  | 3930 | max_matches); | 
|  | 3931 | } | 
|  | 3932 | else | 
|  | 3933 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3934 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3935 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)", | 
|  | 3936 | name.GetCString(), | 
|  | 3937 | append, | 
|  | 3938 | max_matches); | 
|  | 3939 | } | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3940 | } | 
|  | 3941 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3942 | // If we aren't appending the results to this list, then clear the list | 
|  | 3943 | if (!append) | 
|  | 3944 | types.Clear(); | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3945 |  | 
|  | 3946 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) | 
|  | 3947 | return 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3948 |  | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3949 | DIEArray die_offsets; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3950 |  | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3951 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3952 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3953 | if (m_apple_types_ap.get()) | 
|  | 3954 | { | 
|  | 3955 | const char *name_cstr = name.GetCString(); | 
|  | 3956 | m_apple_types_ap->FindByName (name_cstr, die_offsets); | 
|  | 3957 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3958 | } | 
|  | 3959 | else | 
|  | 3960 | { | 
|  | 3961 | if (!m_indexed) | 
|  | 3962 | Index (); | 
|  | 3963 |  | 
|  | 3964 | m_type_index.Find (name, die_offsets); | 
|  | 3965 | } | 
|  | 3966 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3967 | const size_t num_die_matches = die_offsets.size(); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3968 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3969 | if (num_die_matches) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3970 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3971 | const uint32_t initial_types_size = types.GetSize(); | 
|  | 3972 | DWARFCompileUnit* dwarf_cu = NULL; | 
|  | 3973 | const DWARFDebugInfoEntry* die = NULL; | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3974 | DWARFDebugInfo* debug_info = DebugInfo(); | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3975 | for (size_t i=0; i<num_die_matches; ++i) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3976 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3977 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 3978 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
|  | 3979 |  | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3980 | if (die) | 
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 3981 | { | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3982 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) | 
|  | 3983 | continue; | 
|  | 3984 |  | 
|  | 3985 | Type *matching_type = ResolveType (dwarf_cu, die); | 
|  | 3986 | if (matching_type) | 
|  | 3987 | { | 
|  | 3988 | // 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] | 3989 | types.InsertUnique (matching_type->shared_from_this()); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3990 | if (types.GetSize() >= max_matches) | 
|  | 3991 | break; | 
|  | 3992 | } | 
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 3993 | } | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3994 | else | 
|  | 3995 | { | 
|  | 3996 | if (m_using_apple_tables) | 
|  | 3997 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3998 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", | 
|  | 3999 | die_offset, name.GetCString()); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4000 | } | 
|  | 4001 | } | 
|  | 4002 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4003 | } | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4004 | const uint32_t num_matches = types.GetSize() - initial_types_size; | 
|  | 4005 | if (log && num_matches) | 
|  | 4006 | { | 
|  | 4007 | if (namespace_decl) | 
|  | 4008 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4009 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4010 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u", | 
|  | 4011 | name.GetCString(), | 
|  | 4012 | namespace_decl->GetNamespaceDecl(), | 
|  | 4013 | namespace_decl->GetQualifiedName().c_str(), | 
|  | 4014 | append, | 
|  | 4015 | max_matches, | 
|  | 4016 | num_matches); | 
|  | 4017 | } | 
|  | 4018 | else | 
|  | 4019 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4020 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4021 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u", | 
|  | 4022 | name.GetCString(), | 
|  | 4023 | append, | 
|  | 4024 | max_matches, | 
|  | 4025 | num_matches); | 
|  | 4026 | } | 
|  | 4027 | } | 
|  | 4028 | return num_matches; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4029 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4030 | return 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4031 | } | 
|  | 4032 |  | 
|  | 4033 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4034 | ClangNamespaceDecl | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4035 | SymbolFileDWARF::FindNamespace (const SymbolContext& sc, | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 4036 | const ConstString &name, | 
|  | 4037 | const lldb_private::ClangNamespaceDecl *parent_namespace_decl) | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4038 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4039 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 4040 |  | 
|  | 4041 | if (log) | 
|  | 4042 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4043 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4044 | "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")", | 
|  | 4045 | name.GetCString()); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 4046 | } | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 4047 |  | 
|  | 4048 | if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl)) | 
|  | 4049 | return ClangNamespaceDecl(); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 4050 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4051 | ClangNamespaceDecl namespace_decl; | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4052 | DWARFDebugInfo* info = DebugInfo(); | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4053 | if (info) | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4054 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4055 | DIEArray die_offsets; | 
|  | 4056 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4057 | // Index if we already haven't to make sure the compile units | 
|  | 4058 | // get indexed and make their global DIE index list | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4059 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4060 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4061 | if (m_apple_namespaces_ap.get()) | 
|  | 4062 | { | 
|  | 4063 | const char *name_cstr = name.GetCString(); | 
|  | 4064 | m_apple_namespaces_ap->FindByName (name_cstr, die_offsets); | 
|  | 4065 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4066 | } | 
|  | 4067 | else | 
|  | 4068 | { | 
|  | 4069 | if (!m_indexed) | 
|  | 4070 | Index (); | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4071 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4072 | m_namespace_index.Find (name, die_offsets); | 
|  | 4073 | } | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4074 |  | 
|  | 4075 | DWARFCompileUnit* dwarf_cu = NULL; | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4076 | const DWARFDebugInfoEntry* die = NULL; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4077 | const size_t num_matches = die_offsets.size(); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4078 | if (num_matches) | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4079 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4080 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 4081 | for (size_t i=0; i<num_matches; ++i) | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4082 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4083 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 4084 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 4085 |  | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4086 | if (die) | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4087 | { | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4088 | if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die)) | 
|  | 4089 | continue; | 
|  | 4090 |  | 
|  | 4091 | clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die); | 
|  | 4092 | if (clang_namespace_decl) | 
|  | 4093 | { | 
|  | 4094 | namespace_decl.SetASTContext (GetClangASTContext().getASTContext()); | 
|  | 4095 | namespace_decl.SetNamespaceDecl (clang_namespace_decl); | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4096 | break; | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4097 | } | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4098 | } | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4099 | else | 
|  | 4100 | { | 
|  | 4101 | if (m_using_apple_tables) | 
|  | 4102 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4103 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n", | 
|  | 4104 | die_offset, name.GetCString()); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4105 | } | 
|  | 4106 | } | 
|  | 4107 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4108 | } | 
|  | 4109 | } | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4110 | } | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4111 | if (log && namespace_decl.GetNamespaceDecl()) | 
|  | 4112 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4113 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4114 | "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"", | 
|  | 4115 | name.GetCString(), | 
|  | 4116 | namespace_decl.GetNamespaceDecl(), | 
|  | 4117 | namespace_decl.GetQualifiedName().c_str()); | 
|  | 4118 | } | 
|  | 4119 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4120 | return namespace_decl; | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4121 | } | 
|  | 4122 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4123 | uint32_t | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4124 | 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] | 4125 | { | 
|  | 4126 | // Remember how many sc_list are in the list before we search in case | 
|  | 4127 | // we are appending the results to a variable list. | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4128 | uint32_t original_size = types.GetSize(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4129 |  | 
|  | 4130 | const uint32_t num_die_offsets = die_offsets.size(); | 
|  | 4131 | // Parse all of the types we found from the pubtypes matches | 
|  | 4132 | uint32_t i; | 
|  | 4133 | uint32_t num_matches = 0; | 
|  | 4134 | for (i = 0; i < num_die_offsets; ++i) | 
|  | 4135 | { | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4136 | Type *matching_type = ResolveTypeUID (die_offsets[i]); | 
|  | 4137 | if (matching_type) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4138 | { | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4139 | // 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] | 4140 | types.InsertUnique (matching_type->shared_from_this()); | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4141 | ++num_matches; | 
|  | 4142 | if (num_matches >= max_matches) | 
|  | 4143 | break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4144 | } | 
|  | 4145 | } | 
|  | 4146 |  | 
|  | 4147 | // Return the number of variable that were appended to the list | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4148 | return types.GetSize() - original_size; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4149 | } | 
|  | 4150 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4151 |  | 
|  | 4152 | size_t | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4153 | SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc, | 
|  | 4154 | clang::DeclContext *containing_decl_ctx, | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4155 | DWARFCompileUnit* dwarf_cu, | 
|  | 4156 | const DWARFDebugInfoEntry *parent_die, | 
|  | 4157 | bool skip_artificial, | 
|  | 4158 | bool &is_static, | 
|  | 4159 | TypeList* type_list, | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 4160 | std::vector<ClangASTType>& function_param_types, | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4161 | std::vector<clang::ParmVarDecl*>& function_param_decls, | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 4162 | unsigned &type_quals, | 
|  | 4163 | ClangASTContext::TemplateParameterInfos &template_param_infos) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4164 | { | 
|  | 4165 | if (parent_die == NULL) | 
|  | 4166 | return 0; | 
|  | 4167 |  | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4168 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); | 
|  | 4169 |  | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4170 | size_t arg_idx = 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4171 | const DWARFDebugInfoEntry *die; | 
|  | 4172 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) | 
|  | 4173 | { | 
|  | 4174 | dw_tag_t tag = die->Tag(); | 
|  | 4175 | switch (tag) | 
|  | 4176 | { | 
|  | 4177 | case DW_TAG_formal_parameter: | 
|  | 4178 | { | 
|  | 4179 | DWARFDebugInfoEntry::Attributes attributes; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4180 | 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] | 4181 | if (num_attributes > 0) | 
|  | 4182 | { | 
|  | 4183 | const char *name = NULL; | 
|  | 4184 | Declaration decl; | 
|  | 4185 | dw_offset_t param_type_die_offset = DW_INVALID_OFFSET; | 
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 4186 | bool is_artificial = false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4187 | // one of None, Auto, Register, Extern, Static, PrivateExtern | 
|  | 4188 |  | 
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 4189 | clang::StorageClass storage = clang::SC_None; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4190 | uint32_t i; | 
|  | 4191 | for (i=0; i<num_attributes; ++i) | 
|  | 4192 | { | 
|  | 4193 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 4194 | DWARFFormValue form_value; | 
|  | 4195 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 4196 | { | 
|  | 4197 | switch (attr) | 
|  | 4198 | { | 
|  | 4199 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 4200 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 4201 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 4202 | case DW_AT_name:        name = form_value.AsCString(&get_debug_str_data()); break; | 
|  | 4203 | case DW_AT_type:        param_type_die_offset = form_value.Reference(dwarf_cu); break; | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 4204 | case DW_AT_artificial:  is_artificial = form_value.Boolean(); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4205 | case DW_AT_location: | 
|  | 4206 | //                          if (form_value.BlockData()) | 
|  | 4207 | //                          { | 
|  | 4208 | //                              const DataExtractor& debug_info_data = debug_info(); | 
|  | 4209 | //                              uint32_t block_length = form_value.Unsigned(); | 
|  | 4210 | //                              DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length); | 
|  | 4211 | //                          } | 
|  | 4212 | //                          else | 
|  | 4213 | //                          { | 
|  | 4214 | //                          } | 
|  | 4215 | //                          break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4216 | case DW_AT_const_value: | 
|  | 4217 | case DW_AT_default_value: | 
|  | 4218 | case DW_AT_description: | 
|  | 4219 | case DW_AT_endianity: | 
|  | 4220 | case DW_AT_is_optional: | 
|  | 4221 | case DW_AT_segment: | 
|  | 4222 | case DW_AT_variable_parameter: | 
|  | 4223 | default: | 
|  | 4224 | case DW_AT_abstract_origin: | 
|  | 4225 | case DW_AT_sibling: | 
|  | 4226 | break; | 
|  | 4227 | } | 
|  | 4228 | } | 
|  | 4229 | } | 
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 4230 |  | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4231 | bool skip = false; | 
|  | 4232 | if (skip_artificial) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4233 | { | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4234 | if (is_artificial) | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4235 | { | 
|  | 4236 | // In order to determine if a C++ member function is | 
|  | 4237 | // "const" we have to look at the const-ness of "this"... | 
|  | 4238 | // Ugly, but that | 
|  | 4239 | if (arg_idx == 0) | 
|  | 4240 | { | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 4241 | if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind())) | 
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 4242 | { | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4243 | // Often times compilers omit the "this" name for the | 
|  | 4244 | // specification DIEs, so we can't rely upon the name | 
|  | 4245 | // being in the formal parameter DIE... | 
|  | 4246 | if (name == NULL || ::strcmp(name, "this")==0) | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4247 | { | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4248 | Type *this_type = ResolveTypeUID (param_type_die_offset); | 
|  | 4249 | if (this_type) | 
|  | 4250 | { | 
|  | 4251 | uint32_t encoding_mask = this_type->GetEncodingMask(); | 
|  | 4252 | if (encoding_mask & Type::eEncodingIsPointerUID) | 
|  | 4253 | { | 
|  | 4254 | is_static = false; | 
|  | 4255 |  | 
|  | 4256 | if (encoding_mask & (1u << Type::eEncodingIsConstUID)) | 
|  | 4257 | type_quals |= clang::Qualifiers::Const; | 
|  | 4258 | if (encoding_mask & (1u << Type::eEncodingIsVolatileUID)) | 
|  | 4259 | type_quals |= clang::Qualifiers::Volatile; | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4260 | } | 
|  | 4261 | } | 
|  | 4262 | } | 
|  | 4263 | } | 
|  | 4264 | } | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4265 | skip = true; | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4266 | } | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4267 | else | 
|  | 4268 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4269 |  | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4270 | // HACK: Objective C formal parameters "self" and "_cmd" | 
|  | 4271 | // are not marked as artificial in the DWARF... | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4272 | CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); | 
|  | 4273 | if (comp_unit) | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4274 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4275 | switch (comp_unit->GetLanguage()) | 
|  | 4276 | { | 
|  | 4277 | case eLanguageTypeObjC: | 
|  | 4278 | case eLanguageTypeObjC_plus_plus: | 
|  | 4279 | if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0)) | 
|  | 4280 | skip = true; | 
|  | 4281 | break; | 
|  | 4282 | default: | 
|  | 4283 | break; | 
|  | 4284 | } | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4285 | } | 
|  | 4286 | } | 
|  | 4287 | } | 
|  | 4288 |  | 
|  | 4289 | if (!skip) | 
|  | 4290 | { | 
|  | 4291 | Type *type = ResolveTypeUID(param_type_die_offset); | 
|  | 4292 | if (type) | 
|  | 4293 | { | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 4294 | function_param_types.push_back (type->GetClangForwardType()); | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4295 |  | 
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 4296 | clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name, | 
|  | 4297 | type->GetClangForwardType(), | 
|  | 4298 | storage); | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4299 | assert(param_var_decl); | 
|  | 4300 | function_param_decls.push_back(param_var_decl); | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 4301 |  | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 4302 | GetClangASTContext().SetMetadataAsUserID (param_var_decl, MakeUserID(die->GetOffset())); | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4303 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4304 | } | 
|  | 4305 | } | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4306 | arg_idx++; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4307 | } | 
|  | 4308 | break; | 
|  | 4309 |  | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 4310 | case DW_TAG_template_type_parameter: | 
|  | 4311 | case DW_TAG_template_value_parameter: | 
|  | 4312 | ParseTemplateDIE (dwarf_cu, die,template_param_infos); | 
|  | 4313 | break; | 
|  | 4314 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4315 | default: | 
|  | 4316 | break; | 
|  | 4317 | } | 
|  | 4318 | } | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4319 | return arg_idx; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4320 | } | 
|  | 4321 |  | 
|  | 4322 | size_t | 
|  | 4323 | SymbolFileDWARF::ParseChildEnumerators | 
|  | 4324 | ( | 
|  | 4325 | const SymbolContext& sc, | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 4326 | lldb_private::ClangASTType &clang_type, | 
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 4327 | bool is_signed, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4328 | uint32_t enumerator_byte_size, | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4329 | DWARFCompileUnit* dwarf_cu, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4330 | const DWARFDebugInfoEntry *parent_die | 
|  | 4331 | ) | 
|  | 4332 | { | 
|  | 4333 | if (parent_die == NULL) | 
|  | 4334 | return 0; | 
|  | 4335 |  | 
|  | 4336 | size_t enumerators_added = 0; | 
|  | 4337 | const DWARFDebugInfoEntry *die; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4338 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); | 
|  | 4339 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4340 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) | 
|  | 4341 | { | 
|  | 4342 | const dw_tag_t tag = die->Tag(); | 
|  | 4343 | if (tag == DW_TAG_enumerator) | 
|  | 4344 | { | 
|  | 4345 | DWARFDebugInfoEntry::Attributes attributes; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4346 | 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] | 4347 | if (num_child_attributes > 0) | 
|  | 4348 | { | 
|  | 4349 | const char *name = NULL; | 
|  | 4350 | bool got_value = false; | 
|  | 4351 | int64_t enum_value = 0; | 
|  | 4352 | Declaration decl; | 
|  | 4353 |  | 
|  | 4354 | uint32_t i; | 
|  | 4355 | for (i=0; i<num_child_attributes; ++i) | 
|  | 4356 | { | 
|  | 4357 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 4358 | DWARFFormValue form_value; | 
|  | 4359 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 4360 | { | 
|  | 4361 | switch (attr) | 
|  | 4362 | { | 
|  | 4363 | case DW_AT_const_value: | 
|  | 4364 | got_value = true; | 
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 4365 | if (is_signed) | 
|  | 4366 | enum_value = form_value.Signed(); | 
|  | 4367 | else | 
|  | 4368 | enum_value = form_value.Unsigned(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4369 | break; | 
|  | 4370 |  | 
|  | 4371 | case DW_AT_name: | 
|  | 4372 | name = form_value.AsCString(&get_debug_str_data()); | 
|  | 4373 | break; | 
|  | 4374 |  | 
|  | 4375 | case DW_AT_description: | 
|  | 4376 | default: | 
|  | 4377 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 4378 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 4379 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 4380 | case DW_AT_sibling: | 
|  | 4381 | break; | 
|  | 4382 | } | 
|  | 4383 | } | 
|  | 4384 | } | 
|  | 4385 |  | 
|  | 4386 | if (name && name[0] && got_value) | 
|  | 4387 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 4388 | clang_type.AddEnumerationValueToEnumerationType (clang_type.GetEnumerationIntegerType(), | 
|  | 4389 | decl, | 
|  | 4390 | name, | 
|  | 4391 | enum_value, | 
|  | 4392 | enumerator_byte_size * 8); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4393 | ++enumerators_added; | 
|  | 4394 | } | 
|  | 4395 | } | 
|  | 4396 | } | 
|  | 4397 | } | 
|  | 4398 | return enumerators_added; | 
|  | 4399 | } | 
|  | 4400 |  | 
|  | 4401 | void | 
|  | 4402 | SymbolFileDWARF::ParseChildArrayInfo | 
|  | 4403 | ( | 
|  | 4404 | const SymbolContext& sc, | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4405 | DWARFCompileUnit* dwarf_cu, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4406 | const DWARFDebugInfoEntry *parent_die, | 
|  | 4407 | int64_t& first_index, | 
|  | 4408 | std::vector<uint64_t>& element_orders, | 
|  | 4409 | uint32_t& byte_stride, | 
|  | 4410 | uint32_t& bit_stride | 
|  | 4411 | ) | 
|  | 4412 | { | 
|  | 4413 | if (parent_die == NULL) | 
|  | 4414 | return; | 
|  | 4415 |  | 
|  | 4416 | const DWARFDebugInfoEntry *die; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4417 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4418 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) | 
|  | 4419 | { | 
|  | 4420 | const dw_tag_t tag = die->Tag(); | 
|  | 4421 | switch (tag) | 
|  | 4422 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4423 | case DW_TAG_subrange_type: | 
|  | 4424 | { | 
|  | 4425 | DWARFDebugInfoEntry::Attributes attributes; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4426 | 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] | 4427 | if (num_child_attributes > 0) | 
|  | 4428 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4429 | uint64_t num_elements = 0; | 
|  | 4430 | uint64_t lower_bound = 0; | 
|  | 4431 | uint64_t upper_bound = 0; | 
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4432 | bool upper_bound_valid = false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4433 | uint32_t i; | 
|  | 4434 | for (i=0; i<num_child_attributes; ++i) | 
|  | 4435 | { | 
|  | 4436 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 4437 | DWARFFormValue form_value; | 
|  | 4438 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 4439 | { | 
|  | 4440 | switch (attr) | 
|  | 4441 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4442 | case DW_AT_name: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4443 | break; | 
|  | 4444 |  | 
|  | 4445 | case DW_AT_count: | 
|  | 4446 | num_elements = form_value.Unsigned(); | 
|  | 4447 | break; | 
|  | 4448 |  | 
|  | 4449 | case DW_AT_bit_stride: | 
|  | 4450 | bit_stride = form_value.Unsigned(); | 
|  | 4451 | break; | 
|  | 4452 |  | 
|  | 4453 | case DW_AT_byte_stride: | 
|  | 4454 | byte_stride = form_value.Unsigned(); | 
|  | 4455 | break; | 
|  | 4456 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4457 | case DW_AT_lower_bound: | 
|  | 4458 | lower_bound = form_value.Unsigned(); | 
|  | 4459 | break; | 
|  | 4460 |  | 
|  | 4461 | case DW_AT_upper_bound: | 
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4462 | upper_bound_valid = true; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4463 | upper_bound = form_value.Unsigned(); | 
|  | 4464 | break; | 
|  | 4465 |  | 
|  | 4466 | default: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4467 | case DW_AT_abstract_origin: | 
|  | 4468 | case DW_AT_accessibility: | 
|  | 4469 | case DW_AT_allocated: | 
|  | 4470 | case DW_AT_associated: | 
|  | 4471 | case DW_AT_data_location: | 
|  | 4472 | case DW_AT_declaration: | 
|  | 4473 | case DW_AT_description: | 
|  | 4474 | case DW_AT_sibling: | 
|  | 4475 | case DW_AT_threads_scaled: | 
|  | 4476 | case DW_AT_type: | 
|  | 4477 | case DW_AT_visibility: | 
|  | 4478 | break; | 
|  | 4479 | } | 
|  | 4480 | } | 
|  | 4481 | } | 
|  | 4482 |  | 
| Greg Clayton | e6a0779 | 2012-12-05 21:59:39 +0000 | [diff] [blame] | 4483 | if (num_elements == 0) | 
|  | 4484 | { | 
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4485 | if (upper_bound_valid && upper_bound >= lower_bound) | 
| Greg Clayton | e6a0779 | 2012-12-05 21:59:39 +0000 | [diff] [blame] | 4486 | num_elements = upper_bound - lower_bound + 1; | 
|  | 4487 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4488 |  | 
| Sean Callanan | ec979ba | 2012-10-22 23:56:48 +0000 | [diff] [blame] | 4489 | element_orders.push_back (num_elements); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4490 | } | 
|  | 4491 | } | 
|  | 4492 | break; | 
|  | 4493 | } | 
|  | 4494 | } | 
|  | 4495 | } | 
|  | 4496 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4497 | TypeSP | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4498 | SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4499 | { | 
|  | 4500 | TypeSP type_sp; | 
|  | 4501 | if (die != NULL) | 
|  | 4502 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4503 | assert(dwarf_cu != NULL); | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4504 | Type *type_ptr = m_die_to_type.lookup (die); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4505 | if (type_ptr == NULL) | 
|  | 4506 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4507 | CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu); | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4508 | assert (lldb_cu); | 
|  | 4509 | SymbolContext sc(lldb_cu); | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4510 | type_sp = ParseType(sc, dwarf_cu, die, NULL); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4511 | } | 
|  | 4512 | else if (type_ptr != DIE_IS_BEING_PARSED) | 
|  | 4513 | { | 
|  | 4514 | // Grab the existing type from the master types lists | 
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 4515 | type_sp = type_ptr->shared_from_this(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4516 | } | 
|  | 4517 |  | 
|  | 4518 | } | 
|  | 4519 | return type_sp; | 
|  | 4520 | } | 
|  | 4521 |  | 
|  | 4522 | clang::DeclContext * | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4523 | SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4524 | { | 
|  | 4525 | if (die_offset != DW_INVALID_OFFSET) | 
|  | 4526 | { | 
|  | 4527 | DWARFCompileUnitSP cu_sp; | 
|  | 4528 | const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp); | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4529 | return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4530 | } | 
|  | 4531 | return NULL; | 
|  | 4532 | } | 
|  | 4533 |  | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4534 | clang::DeclContext * | 
|  | 4535 | SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset) | 
|  | 4536 | { | 
|  | 4537 | if (die_offset != DW_INVALID_OFFSET) | 
|  | 4538 | { | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4539 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 4540 | if (debug_info) | 
|  | 4541 | { | 
|  | 4542 | DWARFCompileUnitSP cu_sp; | 
|  | 4543 | const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp); | 
|  | 4544 | if (die) | 
|  | 4545 | return GetClangDeclContextForDIE (sc, cu_sp.get(), die); | 
|  | 4546 | } | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4547 | } | 
|  | 4548 | return NULL; | 
|  | 4549 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4550 |  | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4551 | clang::NamespaceDecl * | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4552 | SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die) | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4553 | { | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4554 | if (die && die->Tag() == DW_TAG_namespace) | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4555 | { | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4556 | // See if we already parsed this namespace DIE and associated it with a | 
|  | 4557 | // uniqued namespace declaration | 
|  | 4558 | clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]); | 
|  | 4559 | if (namespace_decl) | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4560 | return namespace_decl; | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4561 | else | 
|  | 4562 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4563 | const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL); | 
|  | 4564 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL); | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4565 | namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4566 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4567 | if (log) | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4568 | { | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4569 | if (namespace_name) | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4570 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4571 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4572 | "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)", | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4573 | GetClangASTContext().getASTContext(), | 
|  | 4574 | MakeUserID(die->GetOffset()), | 
|  | 4575 | namespace_name, | 
|  | 4576 | namespace_decl, | 
|  | 4577 | namespace_decl->getOriginalNamespace()); | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4578 | } | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4579 | else | 
|  | 4580 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4581 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4582 | "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)", | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4583 | GetClangASTContext().getASTContext(), | 
|  | 4584 | MakeUserID(die->GetOffset()), | 
|  | 4585 | namespace_decl, | 
|  | 4586 | namespace_decl->getOriginalNamespace()); | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4587 | } | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4588 | } | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4589 |  | 
|  | 4590 | if (namespace_decl) | 
|  | 4591 | LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die); | 
|  | 4592 | return namespace_decl; | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4593 | } | 
|  | 4594 | } | 
|  | 4595 | return NULL; | 
|  | 4596 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4597 |  | 
|  | 4598 | clang::DeclContext * | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4599 | SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4600 | { | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4601 | clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die); | 
|  | 4602 | if (clang_decl_ctx) | 
|  | 4603 | return clang_decl_ctx; | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4604 | // If this DIE has a specification, or an abstract origin, then trace to those. | 
|  | 4605 |  | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4606 | 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] | 4607 | if (die_offset != DW_INVALID_OFFSET) | 
|  | 4608 | return GetClangDeclContextForDIEOffset (sc, die_offset); | 
|  | 4609 |  | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4610 | 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] | 4611 | if (die_offset != DW_INVALID_OFFSET) | 
|  | 4612 | return GetClangDeclContextForDIEOffset (sc, die_offset); | 
|  | 4613 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4614 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 4615 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4616 | 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] | 4617 | // This is the DIE we want.  Parse it, then query our map. | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4618 | bool assert_not_being_parsed = true; | 
|  | 4619 | ResolveTypeUID (cu, die, assert_not_being_parsed); | 
|  | 4620 |  | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4621 | clang_decl_ctx = GetCachedClangDeclContextForDIE (die); | 
|  | 4622 |  | 
|  | 4623 | return clang_decl_ctx; | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4624 | } | 
|  | 4625 |  | 
|  | 4626 | clang::DeclContext * | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4627 | 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] | 4628 | { | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4629 | if (m_clang_tu_decl == NULL) | 
|  | 4630 | m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4631 |  | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4632 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4633 |  | 
|  | 4634 | if (decl_ctx_die_copy) | 
|  | 4635 | *decl_ctx_die_copy = decl_ctx_die; | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4636 |  | 
|  | 4637 | if (decl_ctx_die) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4638 | { | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4639 |  | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4640 | DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die); | 
|  | 4641 | if (pos != m_die_to_decl_ctx.end()) | 
|  | 4642 | return pos->second; | 
|  | 4643 |  | 
|  | 4644 | switch (decl_ctx_die->Tag()) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4645 | { | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4646 | case DW_TAG_compile_unit: | 
|  | 4647 | return m_clang_tu_decl; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4648 |  | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4649 | case DW_TAG_namespace: | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4650 | return ResolveNamespaceDIE (cu, decl_ctx_die); | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4651 | break; | 
|  | 4652 |  | 
|  | 4653 | case DW_TAG_structure_type: | 
|  | 4654 | case DW_TAG_union_type: | 
|  | 4655 | case DW_TAG_class_type: | 
|  | 4656 | { | 
|  | 4657 | Type* type = ResolveType (cu, decl_ctx_die); | 
|  | 4658 | if (type) | 
|  | 4659 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 4660 | clang::DeclContext *decl_ctx = type->GetClangForwardType().GetDeclContextForType (); | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4661 | if (decl_ctx) | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4662 | { | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4663 | LinkDeclContextToDIE (decl_ctx, decl_ctx_die); | 
|  | 4664 | if (decl_ctx) | 
|  | 4665 | return decl_ctx; | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4666 | } | 
|  | 4667 | } | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4668 | } | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4669 | break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4670 |  | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4671 | default: | 
|  | 4672 | break; | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4673 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4674 | } | 
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 4675 | return m_clang_tu_decl; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4676 | } | 
|  | 4677 |  | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4678 |  | 
|  | 4679 | const DWARFDebugInfoEntry * | 
|  | 4680 | SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) | 
|  | 4681 | { | 
|  | 4682 | if (cu && die) | 
|  | 4683 | { | 
|  | 4684 | const DWARFDebugInfoEntry * const decl_die = die; | 
|  | 4685 |  | 
|  | 4686 | while (die != NULL) | 
|  | 4687 | { | 
|  | 4688 | // If this is the original DIE that we are searching for a declaration | 
|  | 4689 | // for, then don't look in the cache as we don't want our own decl | 
|  | 4690 | // context to be our decl context... | 
|  | 4691 | if (decl_die != die) | 
|  | 4692 | { | 
|  | 4693 | switch (die->Tag()) | 
|  | 4694 | { | 
|  | 4695 | case DW_TAG_compile_unit: | 
|  | 4696 | case DW_TAG_namespace: | 
|  | 4697 | case DW_TAG_structure_type: | 
|  | 4698 | case DW_TAG_union_type: | 
|  | 4699 | case DW_TAG_class_type: | 
|  | 4700 | return die; | 
|  | 4701 |  | 
|  | 4702 | default: | 
|  | 4703 | break; | 
|  | 4704 | } | 
|  | 4705 | } | 
|  | 4706 |  | 
|  | 4707 | dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET); | 
|  | 4708 | if (die_offset != DW_INVALID_OFFSET) | 
|  | 4709 | { | 
|  | 4710 | DWARFCompileUnit *spec_cu = cu; | 
|  | 4711 | const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu); | 
|  | 4712 | const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die); | 
|  | 4713 | if (spec_die_decl_ctx_die) | 
|  | 4714 | return spec_die_decl_ctx_die; | 
|  | 4715 | } | 
|  | 4716 |  | 
|  | 4717 | die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET); | 
|  | 4718 | if (die_offset != DW_INVALID_OFFSET) | 
|  | 4719 | { | 
|  | 4720 | DWARFCompileUnit *abs_cu = cu; | 
|  | 4721 | const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu); | 
|  | 4722 | const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die); | 
|  | 4723 | if (abs_die_decl_ctx_die) | 
|  | 4724 | return abs_die_decl_ctx_die; | 
|  | 4725 | } | 
|  | 4726 |  | 
|  | 4727 | die = die->GetParent(); | 
|  | 4728 | } | 
|  | 4729 | } | 
|  | 4730 | return NULL; | 
|  | 4731 | } | 
|  | 4732 |  | 
|  | 4733 |  | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4734 | Symbol * | 
|  | 4735 | SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name) | 
|  | 4736 | { | 
|  | 4737 | Symbol *objc_class_symbol = NULL; | 
|  | 4738 | if (m_obj_file) | 
|  | 4739 | { | 
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 4740 | Symtab *symtab = m_obj_file->GetSymtab (); | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4741 | if (symtab) | 
|  | 4742 | { | 
|  | 4743 | objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name, | 
|  | 4744 | eSymbolTypeObjCClass, | 
|  | 4745 | Symtab::eDebugNo, | 
|  | 4746 | Symtab::eVisibilityAny); | 
|  | 4747 | } | 
|  | 4748 | } | 
|  | 4749 | return objc_class_symbol; | 
|  | 4750 | } | 
|  | 4751 |  | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4752 | // Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't | 
|  | 4753 | // then we can end up looking through all class types for a complete type and never find | 
|  | 4754 | // the full definition. We need to know if this attribute is supported, so we determine | 
|  | 4755 | // this here and cache th result. We also need to worry about the debug map DWARF file | 
|  | 4756 | // if we are doing darwin DWARF in .o file debugging. | 
|  | 4757 | bool | 
|  | 4758 | SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu) | 
|  | 4759 | { | 
|  | 4760 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate) | 
|  | 4761 | { | 
|  | 4762 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo; | 
|  | 4763 | if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type()) | 
|  | 4764 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; | 
|  | 4765 | else | 
|  | 4766 | { | 
|  | 4767 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 4768 | const uint32_t num_compile_units = GetNumCompileUnits(); | 
|  | 4769 | for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) | 
|  | 4770 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4771 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); | 
|  | 4772 | 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] | 4773 | { | 
|  | 4774 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; | 
|  | 4775 | break; | 
|  | 4776 | } | 
|  | 4777 | } | 
|  | 4778 | } | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 4779 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ()) | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4780 | return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this); | 
|  | 4781 | } | 
|  | 4782 | return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes; | 
|  | 4783 | } | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4784 |  | 
|  | 4785 | // This function can be used when a DIE is found that is a forward declaration | 
|  | 4786 | // DIE and we want to try and find a type that has the complete definition. | 
|  | 4787 | TypeSP | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4788 | SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die, | 
|  | 4789 | const ConstString &type_name, | 
|  | 4790 | bool must_be_implementation) | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4791 | { | 
|  | 4792 |  | 
|  | 4793 | TypeSP type_sp; | 
|  | 4794 |  | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4795 | if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name))) | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4796 | return type_sp; | 
|  | 4797 |  | 
|  | 4798 | DIEArray die_offsets; | 
|  | 4799 |  | 
|  | 4800 | if (m_using_apple_tables) | 
|  | 4801 | { | 
|  | 4802 | if (m_apple_types_ap.get()) | 
|  | 4803 | { | 
|  | 4804 | const char *name_cstr = type_name.GetCString(); | 
| Greg Clayton | 68221ec | 2012-01-18 20:58:12 +0000 | [diff] [blame] | 4805 | m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation); | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4806 | } | 
|  | 4807 | } | 
|  | 4808 | else | 
|  | 4809 | { | 
|  | 4810 | if (!m_indexed) | 
|  | 4811 | Index (); | 
|  | 4812 |  | 
|  | 4813 | m_type_index.Find (type_name, die_offsets); | 
|  | 4814 | } | 
|  | 4815 |  | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4816 | const size_t num_matches = die_offsets.size(); | 
|  | 4817 |  | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4818 | DWARFCompileUnit* type_cu = NULL; | 
|  | 4819 | const DWARFDebugInfoEntry* type_die = NULL; | 
|  | 4820 | if (num_matches) | 
|  | 4821 | { | 
|  | 4822 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 4823 | for (size_t i=0; i<num_matches; ++i) | 
|  | 4824 | { | 
|  | 4825 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 4826 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); | 
|  | 4827 |  | 
|  | 4828 | if (type_die) | 
|  | 4829 | { | 
|  | 4830 | bool try_resolving_type = false; | 
|  | 4831 |  | 
|  | 4832 | // Don't try and resolve the DIE we are looking for with the DIE itself! | 
|  | 4833 | if (type_die != die) | 
|  | 4834 | { | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4835 | switch (type_die->Tag()) | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4836 | { | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4837 | case DW_TAG_class_type: | 
|  | 4838 | case DW_TAG_structure_type: | 
|  | 4839 | try_resolving_type = true; | 
|  | 4840 | break; | 
|  | 4841 | default: | 
|  | 4842 | break; | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4843 | } | 
|  | 4844 | } | 
|  | 4845 |  | 
|  | 4846 | if (try_resolving_type) | 
|  | 4847 | { | 
| Sean Callanan | a9bc065 | 2012-01-19 02:17:40 +0000 | [diff] [blame] | 4848 | if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type()) | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4849 | 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] | 4850 |  | 
|  | 4851 | if (try_resolving_type) | 
|  | 4852 | { | 
|  | 4853 | Type *resolved_type = ResolveType (type_cu, type_die, false); | 
|  | 4854 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) | 
|  | 4855 | { | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4856 | DEBUG_PRINTF ("resolved 0x%8.8" PRIx64 " (cu 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] | 4857 | MakeUserID(die->GetOffset()), | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4858 | MakeUserID(dwarf_cu->GetOffset()), | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4859 | m_obj_file->GetFileSpec().GetFilename().AsCString(), | 
|  | 4860 | MakeUserID(type_die->GetOffset()), | 
|  | 4861 | MakeUserID(type_cu->GetOffset())); | 
|  | 4862 |  | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4863 | if (die) | 
|  | 4864 | m_die_to_type[die] = resolved_type; | 
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 4865 | type_sp = resolved_type->shared_from_this(); | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4866 | break; | 
|  | 4867 | } | 
|  | 4868 | } | 
|  | 4869 | } | 
|  | 4870 | } | 
|  | 4871 | else | 
|  | 4872 | { | 
|  | 4873 | if (m_using_apple_tables) | 
|  | 4874 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4875 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", | 
|  | 4876 | die_offset, type_name.GetCString()); | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4877 | } | 
|  | 4878 | } | 
|  | 4879 |  | 
|  | 4880 | } | 
|  | 4881 | } | 
|  | 4882 | return type_sp; | 
|  | 4883 | } | 
|  | 4884 |  | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4885 |  | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4886 | //---------------------------------------------------------------------- | 
|  | 4887 | // This function helps to ensure that the declaration contexts match for | 
|  | 4888 | // two different DIEs. Often times debug information will refer to a | 
|  | 4889 | // forward declaration of a type (the equivalent of "struct my_struct;". | 
|  | 4890 | // There will often be a declaration of that type elsewhere that has the | 
|  | 4891 | // full definition. When we go looking for the full type "my_struct", we | 
|  | 4892 | // will find one or more matches in the accelerator tables and we will | 
|  | 4893 | // then need to make sure the type was in the same declaration context | 
|  | 4894 | // as the original DIE. This function can efficiently compare two DIEs | 
|  | 4895 | // and will return true when the declaration context matches, and false | 
|  | 4896 | // when they don't. | 
|  | 4897 | //---------------------------------------------------------------------- | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4898 | bool | 
|  | 4899 | SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1, | 
|  | 4900 | DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2) | 
|  | 4901 | { | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4902 | if (die1 == die2) | 
|  | 4903 | return true; | 
|  | 4904 |  | 
|  | 4905 | #if defined (LLDB_CONFIGURATION_DEBUG) | 
|  | 4906 | // You can't and shouldn't call this function with a compile unit from | 
|  | 4907 | // two different SymbolFileDWARF instances. | 
|  | 4908 | assert (DebugInfo()->ContainsCompileUnit (cu1)); | 
|  | 4909 | assert (DebugInfo()->ContainsCompileUnit (cu2)); | 
|  | 4910 | #endif | 
|  | 4911 |  | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4912 | DWARFDIECollection decl_ctx_1; | 
|  | 4913 | DWARFDIECollection decl_ctx_2; | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4914 | //The declaration DIE stack is a stack of the declaration context | 
|  | 4915 | // DIEs all the way back to the compile unit. If a type "T" is | 
|  | 4916 | // declared inside a class "B", and class "B" is declared inside | 
|  | 4917 | // a class "A" and class "A" is in a namespace "lldb", and the | 
|  | 4918 | // namespace is in a compile unit, there will be a stack of DIEs: | 
|  | 4919 | // | 
|  | 4920 | //   [0] DW_TAG_class_type for "B" | 
|  | 4921 | //   [1] DW_TAG_class_type for "A" | 
|  | 4922 | //   [2] DW_TAG_namespace  for "lldb" | 
|  | 4923 | //   [3] DW_TAG_compile_unit for the source file. | 
|  | 4924 | // | 
|  | 4925 | // We grab both contexts and make sure that everything matches | 
|  | 4926 | // all the way back to the compiler unit. | 
|  | 4927 |  | 
|  | 4928 | // First lets grab the decl contexts for both DIEs | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4929 | die1->GetDeclContextDIEs (this, cu1, decl_ctx_1); | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 4930 | die2->GetDeclContextDIEs (this, cu2, decl_ctx_2); | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4931 | // Make sure the context arrays have the same size, otherwise | 
|  | 4932 | // we are done | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4933 | const size_t count1 = decl_ctx_1.Size(); | 
|  | 4934 | const size_t count2 = decl_ctx_2.Size(); | 
|  | 4935 | if (count1 != count2) | 
|  | 4936 | return false; | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4937 |  | 
|  | 4938 | // Make sure the DW_TAG values match all the way back up the the | 
|  | 4939 | // compile unit. If they don't, then we are done. | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4940 | const DWARFDebugInfoEntry *decl_ctx_die1; | 
|  | 4941 | const DWARFDebugInfoEntry *decl_ctx_die2; | 
|  | 4942 | size_t i; | 
|  | 4943 | for (i=0; i<count1; i++) | 
|  | 4944 | { | 
|  | 4945 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); | 
|  | 4946 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); | 
|  | 4947 | if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag()) | 
|  | 4948 | return false; | 
|  | 4949 | } | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4950 | #if defined LLDB_CONFIGURATION_DEBUG | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4951 |  | 
|  | 4952 | // Make sure the top item in the decl context die array is always | 
|  | 4953 | // DW_TAG_compile_unit. If it isn't then something went wrong in | 
|  | 4954 | // the DWARFDebugInfoEntry::GetDeclContextDIEs() function... | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4955 | assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit); | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4956 |  | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4957 | #endif | 
|  | 4958 | // Always skip the compile unit when comparing by only iterating up to | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4959 | // "count - 1". Here we compare the names as we go. | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4960 | for (i=0; i<count1 - 1; i++) | 
|  | 4961 | { | 
|  | 4962 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); | 
|  | 4963 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); | 
|  | 4964 | const char *name1 = decl_ctx_die1->GetName(this, cu1); | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 4965 | const char *name2 = decl_ctx_die2->GetName(this, cu2); | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4966 | // If the string was from a DW_FORM_strp, then the pointer will often | 
|  | 4967 | // be the same! | 
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 4968 | if (name1 == name2) | 
|  | 4969 | continue; | 
|  | 4970 |  | 
|  | 4971 | // Name pointers are not equal, so only compare the strings | 
|  | 4972 | // if both are not NULL. | 
|  | 4973 | if (name1 && name2) | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4974 | { | 
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 4975 | // If the strings don't compare, we are done... | 
|  | 4976 | if (strcmp(name1, name2) != 0) | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4977 | return false; | 
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 4978 | } | 
|  | 4979 | else | 
|  | 4980 | { | 
|  | 4981 | // One name was NULL while the other wasn't | 
|  | 4982 | return false; | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4983 | } | 
|  | 4984 | } | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4985 | // We made it through all of the checks and the declaration contexts | 
|  | 4986 | // are equal. | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4987 | return true; | 
|  | 4988 | } | 
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 4989 |  | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4990 | // This function can be used when a DIE is found that is a forward declaration | 
|  | 4991 | // DIE and we want to try and find a type that has the complete definition. | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4992 | // "cu" and "die" must be from this SymbolFileDWARF | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4993 | TypeSP | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4994 | SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu, | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4995 | const DWARFDebugInfoEntry *die, | 
|  | 4996 | const ConstString &type_name) | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4997 | { | 
|  | 4998 | TypeSP type_sp; | 
|  | 4999 |  | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5000 | #if defined (LLDB_CONFIGURATION_DEBUG) | 
|  | 5001 | // You can't and shouldn't call this function with a compile unit from | 
|  | 5002 | // another SymbolFileDWARF instance. | 
|  | 5003 | assert (DebugInfo()->ContainsCompileUnit (cu)); | 
|  | 5004 | #endif | 
|  | 5005 |  | 
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 5006 | if (cu == NULL || die == NULL || !type_name) | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 5007 | return type_sp; | 
|  | 5008 |  | 
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 5009 | std::string qualified_name; | 
|  | 5010 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5011 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 5012 | if (log) | 
|  | 5013 | { | 
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 5014 | die->GetQualifiedName(this, cu, qualified_name); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5015 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 5016 | "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x (%s), name='%s')", | 
|  | 5017 | die->GetOffset(), | 
|  | 5018 | qualified_name.c_str(), | 
|  | 5019 | type_name.GetCString()); | 
|  | 5020 | } | 
|  | 5021 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5022 | DIEArray die_offsets; | 
|  | 5023 |  | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 5024 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5025 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 5026 | if (m_apple_types_ap.get()) | 
|  | 5027 | { | 
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 5028 | const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag); | 
|  | 5029 | const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash); | 
|  | 5030 | if (has_tag && has_qualified_name_hash) | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5031 | { | 
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 5032 | if (qualified_name.empty()) | 
|  | 5033 | die->GetQualifiedName(this, cu, qualified_name); | 
|  | 5034 |  | 
|  | 5035 | const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name.c_str()); | 
|  | 5036 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5037 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()"); | 
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 5038 | m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), die->Tag(), qualified_name_hash, die_offsets); | 
|  | 5039 | } | 
|  | 5040 | else if (has_tag > 1) | 
|  | 5041 | { | 
|  | 5042 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5043 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()"); | 
| Greg Clayton | ae920b6 | 2012-01-06 00:17:16 +0000 | [diff] [blame] | 5044 | m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets); | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 5045 | } | 
|  | 5046 | else | 
|  | 5047 | { | 
|  | 5048 | m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets); | 
|  | 5049 | } | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 5050 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5051 | } | 
|  | 5052 | else | 
|  | 5053 | { | 
|  | 5054 | if (!m_indexed) | 
|  | 5055 | Index (); | 
|  | 5056 |  | 
|  | 5057 | m_type_index.Find (type_name, die_offsets); | 
|  | 5058 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 5059 |  | 
|  | 5060 | const size_t num_matches = die_offsets.size(); | 
| Greg Clayton | 6997489 | 2010-12-03 21:42:06 +0000 | [diff] [blame] | 5061 |  | 
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 5062 | const dw_tag_t die_tag = die->Tag(); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 5063 |  | 
|  | 5064 | DWARFCompileUnit* type_cu = NULL; | 
|  | 5065 | const DWARFDebugInfoEntry* type_die = NULL; | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 5066 | if (num_matches) | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 5067 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 5068 | DWARFDebugInfo* debug_info = DebugInfo(); | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 5069 | for (size_t i=0; i<num_matches; ++i) | 
|  | 5070 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 5071 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 5072 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 5073 |  | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 5074 | if (type_die) | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 5075 | { | 
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 5076 | bool try_resolving_type = false; | 
|  | 5077 |  | 
|  | 5078 | // Don't try and resolve the DIE we are looking for with the DIE itself! | 
|  | 5079 | if (type_die != die) | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 5080 | { | 
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 5081 | const dw_tag_t type_die_tag = type_die->Tag(); | 
|  | 5082 | // Make sure the tags match | 
|  | 5083 | if (type_die_tag == die_tag) | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 5084 | { | 
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 5085 | // The tags match, lets try resolving this type | 
|  | 5086 | try_resolving_type = true; | 
|  | 5087 | } | 
|  | 5088 | else | 
|  | 5089 | { | 
|  | 5090 | // The tags don't match, but we need to watch our for a | 
|  | 5091 | // forward declaration for a struct and ("struct foo") | 
|  | 5092 | // ends up being a class ("class foo { ... };") or | 
|  | 5093 | // vice versa. | 
|  | 5094 | switch (type_die_tag) | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 5095 | { | 
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 5096 | case DW_TAG_class_type: | 
|  | 5097 | // We had a "class foo", see if we ended up with a "struct foo { ... };" | 
|  | 5098 | try_resolving_type = (die_tag == DW_TAG_structure_type); | 
|  | 5099 | break; | 
|  | 5100 | case DW_TAG_structure_type: | 
|  | 5101 | // We had a "struct foo", see if we ended up with a "class foo { ... };" | 
|  | 5102 | try_resolving_type = (die_tag == DW_TAG_class_type); | 
|  | 5103 | break; | 
|  | 5104 | default: | 
|  | 5105 | // Tags don't match, don't event try to resolve | 
|  | 5106 | // using this type whose name matches.... | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 5107 | break; | 
|  | 5108 | } | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 5109 | } | 
|  | 5110 | } | 
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 5111 |  | 
|  | 5112 | if (try_resolving_type) | 
|  | 5113 | { | 
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 5114 | if (log) | 
|  | 5115 | { | 
|  | 5116 | std::string qualified_name; | 
|  | 5117 | type_die->GetQualifiedName(this, cu, qualified_name); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5118 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 5119 | "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') trying die=0x%8.8x (%s)", | 
|  | 5120 | die->GetOffset(), | 
|  | 5121 | type_name.GetCString(), | 
|  | 5122 | type_die->GetOffset(), | 
|  | 5123 | qualified_name.c_str()); | 
|  | 5124 | } | 
|  | 5125 |  | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5126 | // Make sure the decl contexts match all the way up | 
|  | 5127 | if (DIEDeclContextsMatch(cu, die, type_cu, type_die)) | 
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 5128 | { | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5129 | Type *resolved_type = ResolveType (type_cu, type_die, false); | 
|  | 5130 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) | 
|  | 5131 | { | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5132 | DEBUG_PRINTF ("resolved 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ") from %s to 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ")\n", | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5133 | MakeUserID(die->GetOffset()), | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 5134 | MakeUserID(dwarf_cu->GetOffset()), | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5135 | m_obj_file->GetFileSpec().GetFilename().AsCString(), | 
|  | 5136 | MakeUserID(type_die->GetOffset()), | 
|  | 5137 | MakeUserID(type_cu->GetOffset())); | 
|  | 5138 |  | 
|  | 5139 | m_die_to_type[die] = resolved_type; | 
| Greg Clayton | ff7692a | 2012-02-02 18:16:59 +0000 | [diff] [blame] | 5140 | type_sp = resolved_type->shared_from_this(); | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5141 | break; | 
|  | 5142 | } | 
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 5143 | } | 
|  | 5144 | } | 
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 5145 | else | 
|  | 5146 | { | 
|  | 5147 | if (log) | 
|  | 5148 | { | 
|  | 5149 | std::string qualified_name; | 
|  | 5150 | type_die->GetQualifiedName(this, cu, qualified_name); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5151 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 5152 | "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') ignoring die=0x%8.8x (%s)", | 
|  | 5153 | die->GetOffset(), | 
|  | 5154 | type_name.GetCString(), | 
|  | 5155 | type_die->GetOffset(), | 
|  | 5156 | qualified_name.c_str()); | 
|  | 5157 | } | 
|  | 5158 | } | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 5159 | } | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 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 | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 5166 | } | 
|  | 5167 | } | 
|  | 5168 |  | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 5169 | } | 
|  | 5170 | } | 
|  | 5171 | return type_sp; | 
|  | 5172 | } | 
|  | 5173 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5174 | TypeSP | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5175 | SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx) | 
|  | 5176 | { | 
|  | 5177 | TypeSP type_sp; | 
|  | 5178 |  | 
|  | 5179 | const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize(); | 
|  | 5180 | if (dwarf_decl_ctx_count > 0) | 
|  | 5181 | { | 
|  | 5182 | const ConstString type_name(dwarf_decl_ctx[0].name); | 
|  | 5183 | const dw_tag_t tag = dwarf_decl_ctx[0].tag; | 
|  | 5184 |  | 
|  | 5185 | if (type_name) | 
|  | 5186 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5187 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5188 | if (log) | 
|  | 5189 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5190 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5191 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')", | 
|  | 5192 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), | 
|  | 5193 | dwarf_decl_ctx.GetQualifiedName()); | 
|  | 5194 | } | 
|  | 5195 |  | 
|  | 5196 | DIEArray die_offsets; | 
|  | 5197 |  | 
|  | 5198 | if (m_using_apple_tables) | 
|  | 5199 | { | 
|  | 5200 | if (m_apple_types_ap.get()) | 
|  | 5201 | { | 
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 5202 | const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag); | 
|  | 5203 | const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash); | 
|  | 5204 | if (has_tag && has_qualified_name_hash) | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5205 | { | 
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 5206 | const char *qualified_name = dwarf_decl_ctx.GetQualifiedName(); | 
|  | 5207 | const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name); | 
|  | 5208 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5209 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()"); | 
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 5210 | m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets); | 
|  | 5211 | } | 
|  | 5212 | else if (has_tag) | 
|  | 5213 | { | 
|  | 5214 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5215 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()"); | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5216 | m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets); | 
|  | 5217 | } | 
|  | 5218 | else | 
|  | 5219 | { | 
|  | 5220 | m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets); | 
|  | 5221 | } | 
|  | 5222 | } | 
|  | 5223 | } | 
|  | 5224 | else | 
|  | 5225 | { | 
|  | 5226 | if (!m_indexed) | 
|  | 5227 | Index (); | 
|  | 5228 |  | 
|  | 5229 | m_type_index.Find (type_name, die_offsets); | 
|  | 5230 | } | 
|  | 5231 |  | 
|  | 5232 | const size_t num_matches = die_offsets.size(); | 
|  | 5233 |  | 
|  | 5234 |  | 
|  | 5235 | DWARFCompileUnit* type_cu = NULL; | 
|  | 5236 | const DWARFDebugInfoEntry* type_die = NULL; | 
|  | 5237 | if (num_matches) | 
|  | 5238 | { | 
|  | 5239 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 5240 | for (size_t i=0; i<num_matches; ++i) | 
|  | 5241 | { | 
|  | 5242 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 5243 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); | 
|  | 5244 |  | 
|  | 5245 | if (type_die) | 
|  | 5246 | { | 
|  | 5247 | bool try_resolving_type = false; | 
|  | 5248 |  | 
|  | 5249 | // Don't try and resolve the DIE we are looking for with the DIE itself! | 
|  | 5250 | const dw_tag_t type_tag = type_die->Tag(); | 
|  | 5251 | // Make sure the tags match | 
|  | 5252 | if (type_tag == tag) | 
|  | 5253 | { | 
|  | 5254 | // The tags match, lets try resolving this type | 
|  | 5255 | try_resolving_type = true; | 
|  | 5256 | } | 
|  | 5257 | else | 
|  | 5258 | { | 
|  | 5259 | // The tags don't match, but we need to watch our for a | 
|  | 5260 | // forward declaration for a struct and ("struct foo") | 
|  | 5261 | // ends up being a class ("class foo { ... };") or | 
|  | 5262 | // vice versa. | 
|  | 5263 | switch (type_tag) | 
|  | 5264 | { | 
|  | 5265 | case DW_TAG_class_type: | 
|  | 5266 | // We had a "class foo", see if we ended up with a "struct foo { ... };" | 
|  | 5267 | try_resolving_type = (tag == DW_TAG_structure_type); | 
|  | 5268 | break; | 
|  | 5269 | case DW_TAG_structure_type: | 
|  | 5270 | // We had a "struct foo", see if we ended up with a "class foo { ... };" | 
|  | 5271 | try_resolving_type = (tag == DW_TAG_class_type); | 
|  | 5272 | break; | 
|  | 5273 | default: | 
|  | 5274 | // Tags don't match, don't event try to resolve | 
|  | 5275 | // using this type whose name matches.... | 
|  | 5276 | break; | 
|  | 5277 | } | 
|  | 5278 | } | 
|  | 5279 |  | 
|  | 5280 | if (try_resolving_type) | 
|  | 5281 | { | 
|  | 5282 | DWARFDeclContext type_dwarf_decl_ctx; | 
|  | 5283 | type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx); | 
|  | 5284 |  | 
|  | 5285 | if (log) | 
|  | 5286 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5287 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5288 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)", | 
|  | 5289 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), | 
|  | 5290 | dwarf_decl_ctx.GetQualifiedName(), | 
|  | 5291 | type_die->GetOffset(), | 
|  | 5292 | type_dwarf_decl_ctx.GetQualifiedName()); | 
|  | 5293 | } | 
|  | 5294 |  | 
|  | 5295 | // Make sure the decl contexts match all the way up | 
|  | 5296 | if (dwarf_decl_ctx == type_dwarf_decl_ctx) | 
|  | 5297 | { | 
|  | 5298 | Type *resolved_type = ResolveType (type_cu, type_die, false); | 
|  | 5299 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) | 
|  | 5300 | { | 
|  | 5301 | type_sp = resolved_type->shared_from_this(); | 
|  | 5302 | break; | 
|  | 5303 | } | 
|  | 5304 | } | 
|  | 5305 | } | 
|  | 5306 | else | 
|  | 5307 | { | 
|  | 5308 | if (log) | 
|  | 5309 | { | 
|  | 5310 | std::string qualified_name; | 
|  | 5311 | type_die->GetQualifiedName(this, type_cu, qualified_name); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5312 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5313 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)", | 
|  | 5314 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), | 
|  | 5315 | dwarf_decl_ctx.GetQualifiedName(), | 
|  | 5316 | type_die->GetOffset(), | 
|  | 5317 | qualified_name.c_str()); | 
|  | 5318 | } | 
|  | 5319 | } | 
|  | 5320 | } | 
|  | 5321 | else | 
|  | 5322 | { | 
|  | 5323 | if (m_using_apple_tables) | 
|  | 5324 | { | 
|  | 5325 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", | 
|  | 5326 | die_offset, type_name.GetCString()); | 
|  | 5327 | } | 
|  | 5328 | } | 
|  | 5329 |  | 
|  | 5330 | } | 
|  | 5331 | } | 
|  | 5332 | } | 
|  | 5333 | } | 
|  | 5334 | return type_sp; | 
|  | 5335 | } | 
|  | 5336 |  | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5337 | bool | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5338 | SymbolFileDWARF::CopyUniqueClassMethodTypes (SymbolFileDWARF *src_symfile, | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5339 | Type *class_type, | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5340 | DWARFCompileUnit* src_cu, | 
|  | 5341 | const DWARFDebugInfoEntry *src_class_die, | 
|  | 5342 | DWARFCompileUnit* dst_cu, | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5343 | const DWARFDebugInfoEntry *dst_class_die, | 
|  | 5344 | llvm::SmallVectorImpl <const DWARFDebugInfoEntry *> &failures) | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5345 | { | 
|  | 5346 | if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die) | 
|  | 5347 | return false; | 
|  | 5348 | if (src_class_die->Tag() != dst_class_die->Tag()) | 
|  | 5349 | return false; | 
|  | 5350 |  | 
|  | 5351 | // We need to complete the class type so we can get all of the method types | 
|  | 5352 | // parsed so we can then unique those types to their equivalent counterparts | 
|  | 5353 | // in "dst_cu" and "dst_class_die" | 
|  | 5354 | class_type->GetClangFullType(); | 
|  | 5355 |  | 
|  | 5356 | const DWARFDebugInfoEntry *src_die; | 
|  | 5357 | const DWARFDebugInfoEntry *dst_die; | 
|  | 5358 | UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die; | 
|  | 5359 | UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die; | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5360 | UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die_artificial; | 
|  | 5361 | UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die_artificial; | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5362 | for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling()) | 
|  | 5363 | { | 
|  | 5364 | if (src_die->Tag() == DW_TAG_subprogram) | 
|  | 5365 | { | 
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5366 | // Make sure this is a declaration and not a concrete instance by looking | 
|  | 5367 | // for DW_AT_declaration set to 1. Sometimes concrete function instances | 
|  | 5368 | // are placed inside the class definitions and shouldn't be included in | 
|  | 5369 | // the list of things are are tracking here. | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5370 | 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] | 5371 | { | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5372 | const char *src_name = src_die->GetMangledName (src_symfile, src_cu); | 
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5373 | if (src_name) | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5374 | { | 
|  | 5375 | ConstString src_const_name(src_name); | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5376 | if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_artificial, 0)) | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5377 | src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die); | 
|  | 5378 | else | 
|  | 5379 | src_name_to_die.Append(src_const_name.GetCString(), src_die); | 
|  | 5380 | } | 
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5381 | } | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5382 | } | 
|  | 5383 | } | 
|  | 5384 | for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling()) | 
|  | 5385 | { | 
|  | 5386 | if (dst_die->Tag() == DW_TAG_subprogram) | 
|  | 5387 | { | 
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5388 | // Make sure this is a declaration and not a concrete instance by looking | 
|  | 5389 | // for DW_AT_declaration set to 1. Sometimes concrete function instances | 
|  | 5390 | // are placed inside the class definitions and shouldn't be included in | 
|  | 5391 | // the list of things are are tracking here. | 
|  | 5392 | if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_declaration, 0) == 1) | 
|  | 5393 | { | 
|  | 5394 | const char *dst_name = dst_die->GetMangledName (this, dst_cu); | 
|  | 5395 | if (dst_name) | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5396 | { | 
|  | 5397 | ConstString dst_const_name(dst_name); | 
|  | 5398 | if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_artificial, 0)) | 
|  | 5399 | dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die); | 
|  | 5400 | else | 
|  | 5401 | dst_name_to_die.Append(dst_const_name.GetCString(), dst_die); | 
|  | 5402 | } | 
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5403 | } | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5404 | } | 
|  | 5405 | } | 
|  | 5406 | const uint32_t src_size = src_name_to_die.GetSize (); | 
|  | 5407 | const uint32_t dst_size = dst_name_to_die.GetSize (); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5408 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION)); | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5409 |  | 
|  | 5410 | // Is everything kosher so we can go through the members at top speed? | 
|  | 5411 | bool fast_path = true; | 
|  | 5412 |  | 
|  | 5413 | if (src_size != dst_size) | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5414 | { | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5415 | if (src_size != 0 && dst_size != 0) | 
|  | 5416 | { | 
|  | 5417 | if (log) | 
|  | 5418 | 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)", | 
|  | 5419 | src_class_die->GetOffset(), | 
|  | 5420 | dst_class_die->GetOffset(), | 
|  | 5421 | src_size, | 
|  | 5422 | dst_size); | 
|  | 5423 | } | 
|  | 5424 |  | 
|  | 5425 | fast_path = false; | 
|  | 5426 | } | 
|  | 5427 |  | 
|  | 5428 | uint32_t idx; | 
|  | 5429 |  | 
|  | 5430 | if (fast_path) | 
|  | 5431 | { | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5432 | for (idx = 0; idx < src_size; ++idx) | 
|  | 5433 | { | 
|  | 5434 | src_die = src_name_to_die.GetValueAtIndexUnchecked (idx); | 
|  | 5435 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx); | 
|  | 5436 |  | 
|  | 5437 | if (src_die->Tag() != dst_die->Tag()) | 
|  | 5438 | { | 
|  | 5439 | if (log) | 
|  | 5440 | 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)", | 
|  | 5441 | src_class_die->GetOffset(), | 
|  | 5442 | dst_class_die->GetOffset(), | 
|  | 5443 | src_die->GetOffset(), | 
|  | 5444 | DW_TAG_value_to_name(src_die->Tag()), | 
|  | 5445 | dst_die->GetOffset(), | 
|  | 5446 | DW_TAG_value_to_name(src_die->Tag())); | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5447 | fast_path = false; | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5448 | } | 
|  | 5449 |  | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5450 | const char *src_name = src_die->GetMangledName (src_symfile, src_cu); | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5451 | const char *dst_name = dst_die->GetMangledName (this, dst_cu); | 
|  | 5452 |  | 
|  | 5453 | // Make sure the names match | 
|  | 5454 | if (src_name == dst_name || (strcmp (src_name, dst_name) == 0)) | 
|  | 5455 | continue; | 
|  | 5456 |  | 
|  | 5457 | if (log) | 
|  | 5458 | 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)", | 
|  | 5459 | src_class_die->GetOffset(), | 
|  | 5460 | dst_class_die->GetOffset(), | 
|  | 5461 | src_die->GetOffset(), | 
|  | 5462 | src_name, | 
|  | 5463 | dst_die->GetOffset(), | 
|  | 5464 | dst_name); | 
|  | 5465 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5466 | fast_path = false; | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5467 | } | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5468 | } | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5469 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5470 | // Now do the work of linking the DeclContexts and Types. | 
|  | 5471 | if (fast_path) | 
|  | 5472 | { | 
|  | 5473 | // We can do this quickly.  Just run across the tables index-for-index since | 
|  | 5474 | // we know each node has matching names and tags. | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5475 | for (idx = 0; idx < src_size; ++idx) | 
|  | 5476 | { | 
|  | 5477 | src_die = src_name_to_die.GetValueAtIndexUnchecked (idx); | 
|  | 5478 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx); | 
|  | 5479 |  | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5480 | 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] | 5481 | if (src_decl_ctx) | 
|  | 5482 | { | 
|  | 5483 | if (log) | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5484 | log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset()); | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5485 | LinkDeclContextToDIE (src_decl_ctx, dst_die); | 
|  | 5486 | } | 
|  | 5487 | else | 
|  | 5488 | { | 
|  | 5489 | if (log) | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5490 | 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()); | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5491 | } | 
|  | 5492 |  | 
|  | 5493 | Type *src_child_type = m_die_to_type[src_die]; | 
|  | 5494 | if (src_child_type) | 
|  | 5495 | { | 
|  | 5496 | if (log) | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5497 | log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", src_child_type, src_child_type->GetID(), src_die->GetOffset(), dst_die->GetOffset()); | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5498 | m_die_to_type[dst_die] = src_child_type; | 
|  | 5499 | } | 
|  | 5500 | else | 
|  | 5501 | { | 
|  | 5502 | if (log) | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5503 | 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()); | 
|  | 5504 | } | 
|  | 5505 | } | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5506 | } | 
|  | 5507 | else | 
|  | 5508 | { | 
|  | 5509 | // We must do this slowly.  For each member of the destination, look | 
|  | 5510 | // up a member in the source with the same name, check its tag, and | 
|  | 5511 | // unique them if everything matches up.  Report failures. | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5512 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5513 | if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty()) | 
|  | 5514 | { | 
|  | 5515 | src_name_to_die.Sort(); | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5516 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5517 | for (idx = 0; idx < dst_size; ++idx) | 
|  | 5518 | { | 
|  | 5519 | const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx); | 
|  | 5520 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx); | 
|  | 5521 | src_die = src_name_to_die.Find(dst_name, NULL); | 
|  | 5522 |  | 
|  | 5523 | if (src_die && (src_die->Tag() == dst_die->Tag())) | 
|  | 5524 | { | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5525 | 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] | 5526 | if (src_decl_ctx) | 
|  | 5527 | { | 
|  | 5528 | if (log) | 
|  | 5529 | log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset()); | 
|  | 5530 | LinkDeclContextToDIE (src_decl_ctx, dst_die); | 
|  | 5531 | } | 
|  | 5532 | else | 
|  | 5533 | { | 
|  | 5534 | if (log) | 
|  | 5535 | 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()); | 
|  | 5536 | } | 
|  | 5537 |  | 
|  | 5538 | Type *src_child_type = m_die_to_type[src_die]; | 
|  | 5539 | if (src_child_type) | 
|  | 5540 | { | 
|  | 5541 | if (log) | 
|  | 5542 | log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", src_child_type, src_child_type->GetID(), src_die->GetOffset(), dst_die->GetOffset()); | 
|  | 5543 | m_die_to_type[dst_die] = src_child_type; | 
|  | 5544 | } | 
|  | 5545 | else | 
|  | 5546 | { | 
|  | 5547 | if (log) | 
|  | 5548 | 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()); | 
|  | 5549 | } | 
|  | 5550 | } | 
|  | 5551 | else | 
|  | 5552 | { | 
|  | 5553 | if (log) | 
|  | 5554 | 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] | 5555 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5556 | failures.push_back(dst_die); | 
|  | 5557 | } | 
|  | 5558 | } | 
|  | 5559 | } | 
|  | 5560 | } | 
|  | 5561 |  | 
|  | 5562 | const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize (); | 
|  | 5563 | const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize (); | 
|  | 5564 |  | 
|  | 5565 | UniqueCStringMap<const DWARFDebugInfoEntry *> name_to_die_artificial_not_in_src; | 
|  | 5566 |  | 
|  | 5567 | if (src_size_artificial && dst_size_artificial) | 
|  | 5568 | { | 
|  | 5569 | dst_name_to_die_artificial.Sort(); | 
|  | 5570 |  | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5571 | for (idx = 0; idx < src_size_artificial; ++idx) | 
|  | 5572 | { | 
|  | 5573 | const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx); | 
|  | 5574 | src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx); | 
|  | 5575 | dst_die = dst_name_to_die_artificial.Find(src_name_artificial, NULL); | 
|  | 5576 |  | 
|  | 5577 | if (dst_die) | 
|  | 5578 | { | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5579 | // Both classes have the artificial types, link them | 
|  | 5580 | clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die]; | 
|  | 5581 | if (src_decl_ctx) | 
|  | 5582 | { | 
|  | 5583 | if (log) | 
|  | 5584 | log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset()); | 
|  | 5585 | LinkDeclContextToDIE (src_decl_ctx, dst_die); | 
|  | 5586 | } | 
|  | 5587 | else | 
|  | 5588 | { | 
|  | 5589 | if (log) | 
|  | 5590 | 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()); | 
|  | 5591 | } | 
|  | 5592 |  | 
|  | 5593 | Type *src_child_type = m_die_to_type[src_die]; | 
|  | 5594 | if (src_child_type) | 
|  | 5595 | { | 
|  | 5596 | if (log) | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5597 | log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", src_child_type, src_child_type->GetID(), src_die->GetOffset(), dst_die->GetOffset()); | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5598 | m_die_to_type[dst_die] = src_child_type; | 
|  | 5599 | } | 
|  | 5600 | else | 
|  | 5601 | { | 
|  | 5602 | if (log) | 
|  | 5603 | 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()); | 
|  | 5604 | } | 
|  | 5605 | } | 
|  | 5606 | } | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5607 | } | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5608 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5609 | if (dst_size_artificial) | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5610 | { | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5611 | for (idx = 0; idx < dst_size_artificial; ++idx) | 
|  | 5612 | { | 
|  | 5613 | const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx); | 
|  | 5614 | dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx); | 
|  | 5615 | if (log) | 
|  | 5616 | log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die->GetOffset(), dst_name_artificial); | 
|  | 5617 |  | 
|  | 5618 | failures.push_back(dst_die); | 
|  | 5619 | } | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5620 | } | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5621 |  | 
|  | 5622 | return (failures.size() != 0); | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5623 | } | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5624 |  | 
|  | 5625 | TypeSP | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5626 | 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] | 5627 | { | 
|  | 5628 | TypeSP type_sp; | 
|  | 5629 |  | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5630 | if (type_is_new_ptr) | 
|  | 5631 | *type_is_new_ptr = false; | 
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5632 |  | 
|  | 5633 | #if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE) | 
|  | 5634 | static DIEStack g_die_stack; | 
|  | 5635 | DIEStack::ScopedPopper scoped_die_logger(g_die_stack); | 
|  | 5636 | #endif | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5637 |  | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 5638 | AccessType accessibility = eAccessNone; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5639 | if (die != NULL) | 
|  | 5640 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5641 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5642 | if (log) | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5643 | { | 
|  | 5644 | const DWARFDebugInfoEntry *context_die; | 
|  | 5645 | clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die); | 
|  | 5646 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5647 | GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x, decl_ctx = %p (die 0x%8.8x)) %s name = '%s')", | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5648 | die->GetOffset(), | 
|  | 5649 | context, | 
|  | 5650 | context_die->GetOffset(), | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5651 | DW_TAG_value_to_name(die->Tag()), | 
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5652 | die->GetName(this, dwarf_cu)); | 
|  | 5653 |  | 
|  | 5654 | #if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE) | 
|  | 5655 | scoped_die_logger.Push (dwarf_cu, die); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5656 | g_die_stack.LogDIEs(log, this); | 
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5657 | #endif | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5658 | } | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5659 | // | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5660 | //        Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5661 | //        if (log && dwarf_cu) | 
|  | 5662 | //        { | 
|  | 5663 | //            StreamString s; | 
|  | 5664 | //            die->DumpLocation (this, dwarf_cu, s); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5665 | //            GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData()); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5666 | // | 
|  | 5667 | //        } | 
| Jim Ingham | 16746d1 | 2011-08-25 23:21:43 +0000 | [diff] [blame] | 5668 |  | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5669 | Type *type_ptr = m_die_to_type.lookup (die); | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5670 | TypeList* type_list = GetTypeList(); | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5671 | if (type_ptr == NULL) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5672 | { | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5673 | ClangASTContext &ast = GetClangASTContext(); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5674 | if (type_is_new_ptr) | 
|  | 5675 | *type_is_new_ptr = true; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5676 |  | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5677 | const dw_tag_t tag = die->Tag(); | 
|  | 5678 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5679 | bool is_forward_declaration = false; | 
|  | 5680 | DWARFDebugInfoEntry::Attributes attributes; | 
|  | 5681 | const char *type_name_cstr = NULL; | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5682 | ConstString type_name_const_str; | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5683 | Type::ResolveState resolve_state = Type::eResolveStateUnresolved; | 
| Greg Clayton | faac111 | 2013-03-14 18:31:44 +0000 | [diff] [blame] | 5684 | uint64_t byte_size = 0; | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5685 | Declaration decl; | 
|  | 5686 |  | 
| Greg Clayton | 4957bf6 | 2010-09-30 21:49:03 +0000 | [diff] [blame] | 5687 | Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5688 | ClangASTType clang_type; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5689 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5690 | dw_attr_t attr; | 
|  | 5691 |  | 
|  | 5692 | switch (tag) | 
|  | 5693 | { | 
|  | 5694 | case DW_TAG_base_type: | 
|  | 5695 | case DW_TAG_pointer_type: | 
|  | 5696 | case DW_TAG_reference_type: | 
| Sean Callanan | ce8af86 | 2012-05-21 23:31:51 +0000 | [diff] [blame] | 5697 | case DW_TAG_rvalue_reference_type: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5698 | case DW_TAG_typedef: | 
|  | 5699 | case DW_TAG_const_type: | 
|  | 5700 | case DW_TAG_restrict_type: | 
|  | 5701 | case DW_TAG_volatile_type: | 
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5702 | case DW_TAG_unspecified_type: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5703 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5704 | // 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] | 5705 | m_die_to_type[die] = DIE_IS_BEING_PARSED; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5706 |  | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5707 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5708 | uint32_t encoding = 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5709 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; | 
|  | 5710 |  | 
|  | 5711 | if (num_attributes > 0) | 
|  | 5712 | { | 
|  | 5713 | uint32_t i; | 
|  | 5714 | for (i=0; i<num_attributes; ++i) | 
|  | 5715 | { | 
|  | 5716 | attr = attributes.AttributeAtIndex(i); | 
|  | 5717 | DWARFFormValue form_value; | 
|  | 5718 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 5719 | { | 
|  | 5720 | switch (attr) | 
|  | 5721 | { | 
|  | 5722 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 5723 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 5724 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 5725 | case DW_AT_name: | 
| Jim Ingham | 337030f | 2011-04-15 23:41:23 +0000 | [diff] [blame] | 5726 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5727 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); | 
| Jim Ingham | 337030f | 2011-04-15 23:41:23 +0000 | [diff] [blame] | 5728 | // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't | 
|  | 5729 | // include the "&"... | 
|  | 5730 | if (tag == DW_TAG_reference_type) | 
|  | 5731 | { | 
|  | 5732 | if (strchr (type_name_cstr, '&') == NULL) | 
|  | 5733 | type_name_cstr = NULL; | 
|  | 5734 | } | 
|  | 5735 | if (type_name_cstr) | 
|  | 5736 | type_name_const_str.SetCString(type_name_cstr); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5737 | break; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 5738 | case DW_AT_byte_size:   byte_size = form_value.Unsigned(); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5739 | case DW_AT_encoding:    encoding = form_value.Unsigned(); break; | 
|  | 5740 | case DW_AT_type:        encoding_uid = form_value.Reference(dwarf_cu); break; | 
|  | 5741 | default: | 
|  | 5742 | case DW_AT_sibling: | 
|  | 5743 | break; | 
|  | 5744 | } | 
|  | 5745 | } | 
|  | 5746 | } | 
|  | 5747 | } | 
|  | 5748 |  | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5749 | DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\") type => 0x%8.8x\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr, encoding_uid); | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 5750 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5751 | switch (tag) | 
|  | 5752 | { | 
|  | 5753 | default: | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5754 | break; | 
|  | 5755 |  | 
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5756 | case DW_TAG_unspecified_type: | 
| Greg Clayton | 7fba263 | 2013-07-01 21:01:52 +0000 | [diff] [blame] | 5757 | if (strcmp(type_name_cstr, "nullptr_t") == 0 || | 
|  | 5758 | strcmp(type_name_cstr, "decltype(nullptr)") == 0 ) | 
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5759 | { | 
|  | 5760 | resolve_state = Type::eResolveStateFull; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5761 | clang_type = ast.GetBasicType(eBasicTypeNullPtr); | 
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5762 | break; | 
|  | 5763 | } | 
|  | 5764 | // Fall through to base type below in case we can handle the type there... | 
|  | 5765 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5766 | case DW_TAG_base_type: | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5767 | resolve_state = Type::eResolveStateFull; | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5768 | clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr, | 
|  | 5769 | encoding, | 
|  | 5770 | byte_size * 8); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5771 | break; | 
|  | 5772 |  | 
| Sean Callanan | ce8af86 | 2012-05-21 23:31:51 +0000 | [diff] [blame] | 5773 | case DW_TAG_pointer_type:           encoding_data_type = Type::eEncodingIsPointerUID;           break; | 
|  | 5774 | case DW_TAG_reference_type:         encoding_data_type = Type::eEncodingIsLValueReferenceUID;   break; | 
|  | 5775 | case DW_TAG_rvalue_reference_type:  encoding_data_type = Type::eEncodingIsRValueReferenceUID;   break; | 
|  | 5776 | case DW_TAG_typedef:                encoding_data_type = Type::eEncodingIsTypedefUID;           break; | 
|  | 5777 | case DW_TAG_const_type:             encoding_data_type = Type::eEncodingIsConstUID;             break; | 
|  | 5778 | case DW_TAG_restrict_type:          encoding_data_type = Type::eEncodingIsRestrictUID;          break; | 
|  | 5779 | case DW_TAG_volatile_type:          encoding_data_type = Type::eEncodingIsVolatileUID;          break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5780 | } | 
|  | 5781 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5782 | 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] | 5783 | { | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5784 | bool translation_unit_is_objc = (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus); | 
|  | 5785 |  | 
|  | 5786 | if (translation_unit_is_objc) | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 5787 | { | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5788 | if (type_name_cstr != NULL) | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5789 | { | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5790 | static ConstString g_objc_type_name_id("id"); | 
|  | 5791 | static ConstString g_objc_type_name_Class("Class"); | 
|  | 5792 | static ConstString g_objc_type_name_selector("SEL"); | 
|  | 5793 |  | 
|  | 5794 | if (type_name_const_str == g_objc_type_name_id) | 
|  | 5795 | { | 
|  | 5796 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5797 | 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] | 5798 | die->GetOffset(), | 
|  | 5799 | DW_TAG_value_to_name(die->Tag()), | 
|  | 5800 | die->GetName(this, dwarf_cu)); | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5801 | clang_type = ast.GetBasicType(eBasicTypeObjCID); | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5802 | encoding_data_type = Type::eEncodingIsUID; | 
|  | 5803 | encoding_uid = LLDB_INVALID_UID; | 
|  | 5804 | resolve_state = Type::eResolveStateFull; | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5805 |  | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5806 | } | 
|  | 5807 | else if (type_name_const_str == g_objc_type_name_Class) | 
|  | 5808 | { | 
|  | 5809 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5810 | 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] | 5811 | die->GetOffset(), | 
|  | 5812 | DW_TAG_value_to_name(die->Tag()), | 
|  | 5813 | die->GetName(this, dwarf_cu)); | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5814 | clang_type = ast.GetBasicType(eBasicTypeObjCClass); | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5815 | encoding_data_type = Type::eEncodingIsUID; | 
|  | 5816 | encoding_uid = LLDB_INVALID_UID; | 
|  | 5817 | resolve_state = Type::eResolveStateFull; | 
|  | 5818 | } | 
|  | 5819 | else if (type_name_const_str == g_objc_type_name_selector) | 
|  | 5820 | { | 
|  | 5821 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5822 | 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] | 5823 | die->GetOffset(), | 
|  | 5824 | DW_TAG_value_to_name(die->Tag()), | 
|  | 5825 | die->GetName(this, dwarf_cu)); | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5826 | clang_type = ast.GetBasicType(eBasicTypeObjCSel); | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5827 | encoding_data_type = Type::eEncodingIsUID; | 
|  | 5828 | encoding_uid = LLDB_INVALID_UID; | 
|  | 5829 | resolve_state = Type::eResolveStateFull; | 
|  | 5830 | } | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5831 | } | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5832 | else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid != LLDB_INVALID_UID) | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5833 | { | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5834 | // Clang sometimes erroneously emits id as objc_object*.  In that case we fix up the type to "id". | 
|  | 5835 |  | 
|  | 5836 | DWARFDebugInfoEntry* encoding_die = dwarf_cu->GetDIEPtr(encoding_uid); | 
|  | 5837 |  | 
|  | 5838 | if (encoding_die && encoding_die->Tag() == DW_TAG_structure_type) | 
|  | 5839 | { | 
|  | 5840 | if (const char *struct_name = encoding_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL)) | 
|  | 5841 | { | 
|  | 5842 | if (!strcmp(struct_name, "objc_object")) | 
|  | 5843 | { | 
|  | 5844 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5845 | 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] | 5846 | die->GetOffset(), | 
|  | 5847 | DW_TAG_value_to_name(die->Tag()), | 
|  | 5848 | die->GetName(this, dwarf_cu)); | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5849 | clang_type = ast.GetBasicType(eBasicTypeObjCID); | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5850 | encoding_data_type = Type::eEncodingIsUID; | 
|  | 5851 | encoding_uid = LLDB_INVALID_UID; | 
|  | 5852 | resolve_state = Type::eResolveStateFull; | 
|  | 5853 | } | 
|  | 5854 | } | 
|  | 5855 | } | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5856 | } | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 5857 | } | 
|  | 5858 | } | 
|  | 5859 |  | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5860 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5861 | this, | 
|  | 5862 | type_name_const_str, | 
|  | 5863 | byte_size, | 
|  | 5864 | NULL, | 
|  | 5865 | encoding_uid, | 
|  | 5866 | encoding_data_type, | 
|  | 5867 | &decl, | 
|  | 5868 | clang_type, | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5869 | resolve_state)); | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5870 |  | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5871 | m_die_to_type[die] = type_sp.get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5872 |  | 
|  | 5873 | //                  Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false); | 
|  | 5874 | //                  if (encoding_type != NULL) | 
|  | 5875 | //                  { | 
|  | 5876 | //                      if (encoding_type != DIE_IS_BEING_PARSED) | 
|  | 5877 | //                          type_sp->SetEncodingType(encoding_type); | 
|  | 5878 | //                      else | 
|  | 5879 | //                          m_indirect_fixups.push_back(type_sp.get()); | 
|  | 5880 | //                  } | 
|  | 5881 | } | 
|  | 5882 | break; | 
|  | 5883 |  | 
|  | 5884 | case DW_TAG_structure_type: | 
|  | 5885 | case DW_TAG_union_type: | 
|  | 5886 | case DW_TAG_class_type: | 
|  | 5887 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5888 | // 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] | 5889 | m_die_to_type[die] = DIE_IS_BEING_PARSED; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 5890 | bool byte_size_valid = false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5891 |  | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5892 | LanguageType class_language = eLanguageTypeUnknown; | 
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 5893 | bool is_complete_objc_class = false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5894 | //bool struct_is_class = false; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5895 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5896 | if (num_attributes > 0) | 
|  | 5897 | { | 
|  | 5898 | uint32_t i; | 
|  | 5899 | for (i=0; i<num_attributes; ++i) | 
|  | 5900 | { | 
|  | 5901 | attr = attributes.AttributeAtIndex(i); | 
|  | 5902 | DWARFFormValue form_value; | 
|  | 5903 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 5904 | { | 
|  | 5905 | switch (attr) | 
|  | 5906 | { | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5907 | case DW_AT_decl_file: | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5908 | if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid()) | 
|  | 5909 | { | 
|  | 5910 | // llvm-gcc outputs invalid DW_AT_decl_file attributes that always | 
|  | 5911 | // point to the compile unit file, so we clear this invalid value | 
|  | 5912 | // so that we can still unique types efficiently. | 
|  | 5913 | decl.SetFile(FileSpec ("<invalid>", false)); | 
|  | 5914 | } | 
|  | 5915 | else | 
|  | 5916 | decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5917 | break; | 
|  | 5918 |  | 
|  | 5919 | case DW_AT_decl_line: | 
|  | 5920 | decl.SetLine(form_value.Unsigned()); | 
|  | 5921 | break; | 
|  | 5922 |  | 
|  | 5923 | case DW_AT_decl_column: | 
|  | 5924 | decl.SetColumn(form_value.Unsigned()); | 
|  | 5925 | break; | 
|  | 5926 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5927 | case DW_AT_name: | 
|  | 5928 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5929 | type_name_const_str.SetCString(type_name_cstr); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5930 | break; | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5931 |  | 
|  | 5932 | case DW_AT_byte_size: | 
|  | 5933 | byte_size = form_value.Unsigned(); | 
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 5934 | byte_size_valid = true; | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5935 | break; | 
|  | 5936 |  | 
|  | 5937 | case DW_AT_accessibility: | 
|  | 5938 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); | 
|  | 5939 | break; | 
|  | 5940 |  | 
|  | 5941 | case DW_AT_declaration: | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 5942 | is_forward_declaration = form_value.Boolean(); | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5943 | break; | 
|  | 5944 |  | 
|  | 5945 | case DW_AT_APPLE_runtime_class: | 
|  | 5946 | class_language = (LanguageType)form_value.Signed(); | 
|  | 5947 | break; | 
|  | 5948 |  | 
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 5949 | case DW_AT_APPLE_objc_complete_type: | 
|  | 5950 | is_complete_objc_class = form_value.Signed(); | 
|  | 5951 | break; | 
|  | 5952 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5953 | case DW_AT_allocated: | 
|  | 5954 | case DW_AT_associated: | 
|  | 5955 | case DW_AT_data_location: | 
|  | 5956 | case DW_AT_description: | 
|  | 5957 | case DW_AT_start_scope: | 
|  | 5958 | case DW_AT_visibility: | 
|  | 5959 | default: | 
|  | 5960 | case DW_AT_sibling: | 
|  | 5961 | break; | 
|  | 5962 | } | 
|  | 5963 | } | 
|  | 5964 | } | 
|  | 5965 | } | 
|  | 5966 |  | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5967 | UniqueDWARFASTType unique_ast_entry; | 
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5968 |  | 
| Greg Clayton | 123edca | 2012-03-02 00:07:15 +0000 | [diff] [blame] | 5969 | // Only try and unique the type if it has a name. | 
|  | 5970 | if (type_name_const_str && | 
|  | 5971 | GetUniqueDWARFASTTypeMap().Find (type_name_const_str, | 
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5972 | this, | 
|  | 5973 | dwarf_cu, | 
|  | 5974 | die, | 
|  | 5975 | decl, | 
|  | 5976 | byte_size_valid ? byte_size : -1, | 
|  | 5977 | unique_ast_entry)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5978 | { | 
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5979 | // We have already parsed this type or from another | 
|  | 5980 | // compile unit. GCC loves to use the "one definition | 
|  | 5981 | // rule" which can result in multiple definitions | 
|  | 5982 | // of the same class over and over in each compile | 
|  | 5983 | // unit. | 
|  | 5984 | type_sp = unique_ast_entry.m_type_sp; | 
|  | 5985 | if (type_sp) | 
| Greg Clayton | c615ce4 | 2010-11-09 04:42:43 +0000 | [diff] [blame] | 5986 | { | 
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5987 | m_die_to_type[die] = type_sp.get(); | 
|  | 5988 | return type_sp; | 
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5989 | } | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5990 | } | 
|  | 5991 |  | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5992 | 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] | 5993 |  | 
|  | 5994 | int tag_decl_kind = -1; | 
|  | 5995 | AccessType default_accessibility = eAccessNone; | 
|  | 5996 | if (tag == DW_TAG_structure_type) | 
|  | 5997 | { | 
|  | 5998 | tag_decl_kind = clang::TTK_Struct; | 
|  | 5999 | default_accessibility = eAccessPublic; | 
|  | 6000 | } | 
|  | 6001 | else if (tag == DW_TAG_union_type) | 
|  | 6002 | { | 
|  | 6003 | tag_decl_kind = clang::TTK_Union; | 
|  | 6004 | default_accessibility = eAccessPublic; | 
|  | 6005 | } | 
|  | 6006 | else if (tag == DW_TAG_class_type) | 
|  | 6007 | { | 
|  | 6008 | tag_decl_kind = clang::TTK_Class; | 
|  | 6009 | default_accessibility = eAccessPrivate; | 
|  | 6010 | } | 
| Greg Clayton | 3a5f29a | 2011-11-30 02:48:28 +0000 | [diff] [blame] | 6011 |  | 
|  | 6012 | if (byte_size_valid && byte_size == 0 && type_name_cstr && | 
|  | 6013 | die->HasChildren() == false && | 
|  | 6014 | sc.comp_unit->GetLanguage() == eLanguageTypeObjC) | 
|  | 6015 | { | 
|  | 6016 | // Work around an issue with clang at the moment where | 
|  | 6017 | // forward declarations for objective C classes are emitted | 
|  | 6018 | // as: | 
|  | 6019 | //  DW_TAG_structure_type [2] | 
|  | 6020 | //  DW_AT_name( "ForwardObjcClass" ) | 
|  | 6021 | //  DW_AT_byte_size( 0x00 ) | 
|  | 6022 | //  DW_AT_decl_file( "..." ) | 
|  | 6023 | //  DW_AT_decl_line( 1 ) | 
|  | 6024 | // | 
|  | 6025 | // Note that there is no DW_AT_declaration and there are | 
|  | 6026 | // no children, and the byte size is zero. | 
|  | 6027 | is_forward_declaration = true; | 
|  | 6028 | } | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6029 |  | 
| Sean Callanan | 7457f8d | 2012-04-25 01:03:57 +0000 | [diff] [blame] | 6030 | if (class_language == eLanguageTypeObjC || | 
|  | 6031 | class_language == eLanguageTypeObjC_plus_plus) | 
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 6032 | { | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6033 | 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] | 6034 | { | 
|  | 6035 | // We have a valid eSymbolTypeObjCClass class symbol whose | 
|  | 6036 | // name matches the current objective C class that we | 
|  | 6037 | // are trying to find and this DIE isn't the complete | 
|  | 6038 | // definition (we checked is_complete_objc_class above and | 
|  | 6039 | // know it is false), so the real definition is in here somewhere | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6040 | type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true); | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6041 |  | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 6042 | if (!type_sp && GetDebugMapSymfile ()) | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 6043 | { | 
|  | 6044 | // We weren't able to find a full declaration in | 
|  | 6045 | // this DWARF, see if we have a declaration anywhere | 
|  | 6046 | // else... | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6047 | 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] | 6048 | } | 
|  | 6049 |  | 
|  | 6050 | if (type_sp) | 
|  | 6051 | { | 
|  | 6052 | if (log) | 
|  | 6053 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 6054 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6055 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an incomplete objc type, complete type is 0x%8.8" PRIx64, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6056 | this, | 
|  | 6057 | die->GetOffset(), | 
|  | 6058 | DW_TAG_value_to_name(tag), | 
|  | 6059 | type_name_cstr, | 
|  | 6060 | type_sp->GetID()); | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 6061 | } | 
|  | 6062 |  | 
|  | 6063 | // We found a real definition for this type elsewhere | 
|  | 6064 | // so lets use it and cache the fact that we found | 
|  | 6065 | // a complete type for this die | 
|  | 6066 | m_die_to_type[die] = type_sp.get(); | 
|  | 6067 | return type_sp; | 
|  | 6068 | } | 
|  | 6069 | } | 
|  | 6070 | } | 
|  | 6071 |  | 
|  | 6072 |  | 
|  | 6073 | if (is_forward_declaration) | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6074 | { | 
|  | 6075 | // We have a forward declaration to a type and we need | 
|  | 6076 | // to try and find a full declaration. We look in the | 
|  | 6077 | // current type index just in case we have a forward | 
|  | 6078 | // declaration followed by an actual declarations in the | 
|  | 6079 | // DWARF. If this fails, we need to look elsewhere... | 
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 6080 | if (log) | 
|  | 6081 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 6082 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6083 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type", | 
|  | 6084 | this, | 
|  | 6085 | die->GetOffset(), | 
|  | 6086 | DW_TAG_value_to_name(tag), | 
|  | 6087 | type_name_cstr); | 
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 6088 | } | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6089 |  | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 6090 | DWARFDeclContext die_decl_ctx; | 
|  | 6091 | die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx); | 
|  | 6092 |  | 
|  | 6093 | //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str); | 
|  | 6094 | type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6095 |  | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 6096 | if (!type_sp && GetDebugMapSymfile ()) | 
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 6097 | { | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6098 | // We weren't able to find a full declaration in | 
|  | 6099 | // this DWARF, see if we have a declaration anywhere | 
|  | 6100 | // else... | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 6101 | type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); | 
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 6102 | } | 
|  | 6103 |  | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6104 | if (type_sp) | 
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 6105 | { | 
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 6106 | if (log) | 
|  | 6107 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 6108 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6109 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8" PRIx64, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6110 | this, | 
|  | 6111 | die->GetOffset(), | 
|  | 6112 | DW_TAG_value_to_name(tag), | 
|  | 6113 | type_name_cstr, | 
|  | 6114 | type_sp->GetID()); | 
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 6115 | } | 
|  | 6116 |  | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6117 | // We found a real definition for this type elsewhere | 
|  | 6118 | // so lets use it and cache the fact that we found | 
|  | 6119 | // a complete type for this die | 
|  | 6120 | m_die_to_type[die] = type_sp.get(); | 
|  | 6121 | return type_sp; | 
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 6122 | } | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6123 | } | 
|  | 6124 | assert (tag_decl_kind != -1); | 
|  | 6125 | bool clang_type_was_created = false; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6126 | clang_type.SetClangType(ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die)); | 
|  | 6127 | if (!clang_type) | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6128 | { | 
| Sean Callanan | 4d04c6a | 2012-02-09 22:54:11 +0000 | [diff] [blame] | 6129 | const DWARFDebugInfoEntry *decl_ctx_die; | 
|  | 6130 |  | 
|  | 6131 | clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die); | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 6132 | if (accessibility == eAccessNone && decl_ctx) | 
|  | 6133 | { | 
|  | 6134 | // Check the decl context that contains this class/struct/union. | 
|  | 6135 | // If it is a class we must give it an accessability. | 
|  | 6136 | const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind(); | 
|  | 6137 | if (DeclKindIsCXXClass (containing_decl_kind)) | 
|  | 6138 | accessibility = default_accessibility; | 
|  | 6139 | } | 
|  | 6140 |  | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 6141 | ClangASTMetadata metadata; | 
|  | 6142 | metadata.SetUserID(MakeUserID(die->GetOffset())); | 
|  | 6143 | metadata.SetIsDynamicCXXType(ClassOrStructIsVirtual (dwarf_cu, die)); | 
|  | 6144 |  | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6145 | if (type_name_cstr && strchr (type_name_cstr, '<')) | 
|  | 6146 | { | 
|  | 6147 | ClangASTContext::TemplateParameterInfos template_param_infos; | 
|  | 6148 | if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos)) | 
|  | 6149 | { | 
|  | 6150 | clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx, | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 6151 | accessibility, | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6152 | type_name_cstr, | 
|  | 6153 | tag_decl_kind, | 
|  | 6154 | template_param_infos); | 
|  | 6155 |  | 
|  | 6156 | clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx, | 
|  | 6157 | class_template_decl, | 
|  | 6158 | tag_decl_kind, | 
|  | 6159 | template_param_infos); | 
|  | 6160 | clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl); | 
|  | 6161 | clang_type_was_created = true; | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 6162 |  | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6163 | GetClangASTContext().SetMetadata (class_template_decl, metadata); | 
|  | 6164 | GetClangASTContext().SetMetadata (class_specialization_decl, metadata); | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6165 | } | 
|  | 6166 | } | 
|  | 6167 |  | 
|  | 6168 | if (!clang_type_was_created) | 
|  | 6169 | { | 
|  | 6170 | clang_type_was_created = true; | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 6171 | clang_type = ast.CreateRecordType (decl_ctx, | 
|  | 6172 | accessibility, | 
|  | 6173 | type_name_cstr, | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6174 | tag_decl_kind, | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 6175 | class_language, | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6176 | &metadata); | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6177 | } | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6178 | } | 
|  | 6179 |  | 
|  | 6180 | // Store a forward declaration to this class type in case any | 
|  | 6181 | // parameters in any class methods need it for the clang | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6182 | // types for function prototypes. | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6183 | LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die); | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6184 | type_sp.reset (new Type (MakeUserID(die->GetOffset()), | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6185 | this, | 
|  | 6186 | type_name_const_str, | 
|  | 6187 | byte_size, | 
|  | 6188 | NULL, | 
|  | 6189 | LLDB_INVALID_UID, | 
|  | 6190 | Type::eEncodingIsUID, | 
|  | 6191 | &decl, | 
|  | 6192 | clang_type, | 
|  | 6193 | Type::eResolveStateForward)); | 
| Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 6194 |  | 
|  | 6195 | type_sp->SetIsCompleteObjCClass(is_complete_objc_class); | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6196 |  | 
|  | 6197 |  | 
|  | 6198 | // Add our type to the unique type map so we don't | 
|  | 6199 | // end up creating many copies of the same type over | 
|  | 6200 | // and over in the ASTContext for our module | 
|  | 6201 | unique_ast_entry.m_type_sp = type_sp; | 
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 6202 | unique_ast_entry.m_symfile = this; | 
|  | 6203 | unique_ast_entry.m_cu = dwarf_cu; | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6204 | unique_ast_entry.m_die = die; | 
|  | 6205 | unique_ast_entry.m_declaration = decl; | 
| Sean Callanan | 5970059 | 2012-02-13 22:30:16 +0000 | [diff] [blame] | 6206 | unique_ast_entry.m_byte_size = byte_size; | 
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 6207 | GetUniqueDWARFASTTypeMap().Insert (type_name_const_str, | 
|  | 6208 | unique_ast_entry); | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6209 |  | 
| Greg Clayton | 0ec71a0 | 2013-08-10 00:09:35 +0000 | [diff] [blame] | 6210 | if (is_forward_declaration && die->HasChildren()) | 
|  | 6211 | { | 
|  | 6212 | // Check to see if the DIE actually has a definition, some version of GCC will | 
|  | 6213 | // emit DIEs with DW_AT_declaration set to true, but yet still have subprogram, | 
|  | 6214 | // members, or inheritance, so we can't trust it | 
|  | 6215 | const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); | 
|  | 6216 | while (child_die) | 
|  | 6217 | { | 
|  | 6218 | switch (child_die->Tag()) | 
|  | 6219 | { | 
|  | 6220 | case DW_TAG_inheritance: | 
|  | 6221 | case DW_TAG_subprogram: | 
|  | 6222 | case DW_TAG_member: | 
|  | 6223 | case DW_TAG_APPLE_property: | 
|  | 6224 | child_die = NULL; | 
|  | 6225 | is_forward_declaration = false; | 
|  | 6226 | break; | 
|  | 6227 | default: | 
|  | 6228 | child_die = child_die->GetSibling(); | 
|  | 6229 | break; | 
|  | 6230 | } | 
|  | 6231 | } | 
|  | 6232 | } | 
|  | 6233 |  | 
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6234 | if (!is_forward_declaration) | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 6235 | { | 
|  | 6236 | // Always start the definition for a class type so that | 
|  | 6237 | // if the class has child classes or types that require | 
|  | 6238 | // the class to be created for use as their decl contexts | 
|  | 6239 | // the class will be ready to accept these child definitions. | 
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6240 | if (die->HasChildren() == false) | 
|  | 6241 | { | 
|  | 6242 | // No children for this struct/union/class, lets finish it | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6243 | clang_type.StartTagDeclarationDefinition (); | 
|  | 6244 | clang_type.CompleteTagDeclarationDefinition (); | 
| Sean Callanan | 433cd22 | 2012-10-19 01:37:25 +0000 | [diff] [blame] | 6245 |  | 
|  | 6246 | if (tag == DW_TAG_structure_type) // this only applies in C | 
|  | 6247 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6248 | clang::RecordDecl *record_decl = clang_type.GetAsRecordDecl(); | 
| Sean Callanan | 433cd22 | 2012-10-19 01:37:25 +0000 | [diff] [blame] | 6249 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6250 | if (record_decl) | 
| Sean Callanan | 433cd22 | 2012-10-19 01:37:25 +0000 | [diff] [blame] | 6251 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6252 | LayoutInfo layout_info; | 
| Sean Callanan | 433cd22 | 2012-10-19 01:37:25 +0000 | [diff] [blame] | 6253 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6254 | layout_info.alignment = 0; | 
|  | 6255 | layout_info.bit_size = 0; | 
|  | 6256 |  | 
|  | 6257 | m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info)); | 
| Sean Callanan | 433cd22 | 2012-10-19 01:37:25 +0000 | [diff] [blame] | 6258 | } | 
|  | 6259 | } | 
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6260 | } | 
|  | 6261 | else if (clang_type_was_created) | 
|  | 6262 | { | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 6263 | // Start the definition if the class is not objective C since | 
|  | 6264 | // the underlying decls respond to isCompleteDefinition(). Objective | 
|  | 6265 | // C decls dont' respond to isCompleteDefinition() so we can't | 
|  | 6266 | // start the declaration definition right away. For C++ classs/union/structs | 
|  | 6267 | // we want to start the definition in case the class is needed as the | 
|  | 6268 | // declaration context for a contained class or type without the need | 
|  | 6269 | // to complete that type.. | 
|  | 6270 |  | 
| Sean Callanan | 7457f8d | 2012-04-25 01:03:57 +0000 | [diff] [blame] | 6271 | if (class_language != eLanguageTypeObjC && | 
|  | 6272 | class_language != eLanguageTypeObjC_plus_plus) | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6273 | clang_type.StartTagDeclarationDefinition (); | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 6274 |  | 
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6275 | // Leave this as a forward declaration until we need | 
|  | 6276 | // to know the details of the type. lldb_private::Type | 
|  | 6277 | // will automatically call the SymbolFile virtual function | 
|  | 6278 | // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)" | 
|  | 6279 | // When the definition needs to be defined. | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6280 | m_forward_decl_die_to_clang_type[die] = clang_type.GetOpaqueQualType(); | 
|  | 6281 | m_forward_decl_clang_type_to_die[clang_type.RemoveFastQualifiers().GetOpaqueQualType()] = die; | 
|  | 6282 | clang_type.SetHasExternalStorage (true); | 
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6283 | } | 
| Greg Clayton | c615ce4 | 2010-11-09 04:42:43 +0000 | [diff] [blame] | 6284 | } | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 6285 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6286 | } | 
|  | 6287 | break; | 
|  | 6288 |  | 
|  | 6289 | case DW_TAG_enumeration_type: | 
|  | 6290 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6291 | // 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] | 6292 | m_die_to_type[die] = DIE_IS_BEING_PARSED; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6293 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6294 | lldb::user_id_t encoding_uid = DW_INVALID_OFFSET; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6295 |  | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6296 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6297 | if (num_attributes > 0) | 
|  | 6298 | { | 
|  | 6299 | uint32_t i; | 
|  | 6300 |  | 
|  | 6301 | for (i=0; i<num_attributes; ++i) | 
|  | 6302 | { | 
|  | 6303 | attr = attributes.AttributeAtIndex(i); | 
|  | 6304 | DWARFFormValue form_value; | 
|  | 6305 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 6306 | { | 
|  | 6307 | switch (attr) | 
|  | 6308 | { | 
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 6309 | case DW_AT_decl_file:       decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 6310 | case DW_AT_decl_line:       decl.SetLine(form_value.Unsigned()); break; | 
|  | 6311 | case DW_AT_decl_column:     decl.SetColumn(form_value.Unsigned()); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6312 | case DW_AT_name: | 
|  | 6313 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6314 | type_name_const_str.SetCString(type_name_cstr); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6315 | break; | 
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 6316 | case DW_AT_type:            encoding_uid = form_value.Reference(dwarf_cu); break; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6317 | case DW_AT_byte_size:       byte_size = form_value.Unsigned(); break; | 
|  | 6318 | 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] | 6319 | case DW_AT_declaration:     break; //is_forward_declaration = form_value.Boolean(); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6320 | case DW_AT_allocated: | 
|  | 6321 | case DW_AT_associated: | 
|  | 6322 | case DW_AT_bit_stride: | 
|  | 6323 | case DW_AT_byte_stride: | 
|  | 6324 | case DW_AT_data_location: | 
|  | 6325 | case DW_AT_description: | 
|  | 6326 | case DW_AT_start_scope: | 
|  | 6327 | case DW_AT_visibility: | 
|  | 6328 | case DW_AT_specification: | 
|  | 6329 | case DW_AT_abstract_origin: | 
|  | 6330 | case DW_AT_sibling: | 
|  | 6331 | break; | 
|  | 6332 | } | 
|  | 6333 | } | 
|  | 6334 | } | 
|  | 6335 |  | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6336 | 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] | 6337 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6338 | ClangASTType enumerator_clang_type; | 
|  | 6339 | clang_type.SetClangType (ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die)); | 
|  | 6340 | if (!clang_type) | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6341 | { | 
| Greg Clayton | 5d14fc0 | 2013-03-06 06:23:54 +0000 | [diff] [blame] | 6342 | if (encoding_uid != DW_INVALID_OFFSET) | 
|  | 6343 | { | 
|  | 6344 | Type *enumerator_type = ResolveTypeUID(encoding_uid); | 
|  | 6345 | if (enumerator_type) | 
|  | 6346 | enumerator_clang_type = enumerator_type->GetClangFullType(); | 
|  | 6347 | } | 
|  | 6348 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6349 | if (!enumerator_clang_type) | 
| Greg Clayton | 5d14fc0 | 2013-03-06 06:23:54 +0000 | [diff] [blame] | 6350 | enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL, | 
|  | 6351 | DW_ATE_signed, | 
|  | 6352 | byte_size * 8); | 
|  | 6353 |  | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 6354 | clang_type = ast.CreateEnumerationType (type_name_cstr, | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6355 | GetClangDeclContextContainingDIE (dwarf_cu, die, NULL), | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 6356 | decl, | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6357 | enumerator_clang_type); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6358 | } | 
|  | 6359 | else | 
|  | 6360 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6361 | enumerator_clang_type = clang_type.GetEnumerationIntegerType (); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6362 | } | 
|  | 6363 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6364 | LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die); | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6365 |  | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6366 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6367 | this, | 
|  | 6368 | type_name_const_str, | 
|  | 6369 | byte_size, | 
|  | 6370 | NULL, | 
|  | 6371 | encoding_uid, | 
|  | 6372 | Type::eEncodingIsUID, | 
|  | 6373 | &decl, | 
|  | 6374 | clang_type, | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6375 | Type::eResolveStateForward)); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6376 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6377 | clang_type.StartTagDeclarationDefinition (); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 6378 | if (die->HasChildren()) | 
|  | 6379 | { | 
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 6380 | SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); | 
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 6381 | bool is_signed = false; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6382 | enumerator_clang_type.IsIntegerType(is_signed); | 
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 6383 | 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] | 6384 | } | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6385 | clang_type.CompleteTagDeclarationDefinition (); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6386 | } | 
|  | 6387 | } | 
|  | 6388 | break; | 
|  | 6389 |  | 
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 6390 | case DW_TAG_inlined_subroutine: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6391 | case DW_TAG_subprogram: | 
|  | 6392 | case DW_TAG_subroutine_type: | 
|  | 6393 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6394 | // 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] | 6395 | m_die_to_type[die] = DIE_IS_BEING_PARSED; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6396 |  | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6397 | //const char *mangled = NULL; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6398 | dw_offset_t type_die_offset = DW_INVALID_OFFSET; | 
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 6399 | bool is_variadic = false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6400 | bool is_inline = false; | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6401 | bool is_static = false; | 
|  | 6402 | bool is_virtual = false; | 
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6403 | bool is_explicit = false; | 
| Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 6404 | bool is_artificial = false; | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6405 | dw_offset_t specification_die_offset = DW_INVALID_OFFSET; | 
|  | 6406 | dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET; | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6407 | dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET; | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6408 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6409 | unsigned type_quals = 0; | 
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 6410 | clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6411 |  | 
|  | 6412 |  | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6413 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6414 | if (num_attributes > 0) | 
|  | 6415 | { | 
|  | 6416 | uint32_t i; | 
|  | 6417 | for (i=0; i<num_attributes; ++i) | 
|  | 6418 | { | 
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 6419 | attr = attributes.AttributeAtIndex(i); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6420 | DWARFFormValue form_value; | 
|  | 6421 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 6422 | { | 
|  | 6423 | switch (attr) | 
|  | 6424 | { | 
|  | 6425 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 6426 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 6427 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 6428 | case DW_AT_name: | 
|  | 6429 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6430 | type_name_const_str.SetCString(type_name_cstr); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6431 | break; | 
|  | 6432 |  | 
| Greg Clayton | 7141554 | 2012-12-08 00:24:40 +0000 | [diff] [blame] | 6433 | case DW_AT_linkage_name: | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6434 | case DW_AT_MIPS_linkage_name:   break; // mangled = form_value.AsCString(&get_debug_str_data()); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6435 | case DW_AT_type:                type_die_offset = form_value.Reference(dwarf_cu); break; | 
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 6436 | 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] | 6437 | case DW_AT_declaration:         break; // is_forward_declaration = form_value.Boolean(); break; | 
|  | 6438 | case DW_AT_inline:              is_inline = form_value.Boolean(); break; | 
|  | 6439 | case DW_AT_virtuality:          is_virtual = form_value.Boolean();  break; | 
|  | 6440 | case DW_AT_explicit:            is_explicit = form_value.Boolean();  break; | 
|  | 6441 | case DW_AT_artificial:          is_artificial = form_value.Boolean();  break; | 
| Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 6442 |  | 
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6443 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6444 | case DW_AT_external: | 
|  | 6445 | if (form_value.Unsigned()) | 
|  | 6446 | { | 
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 6447 | if (storage == clang::SC_None) | 
|  | 6448 | storage = clang::SC_Extern; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6449 | else | 
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 6450 | storage = clang::SC_PrivateExtern; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6451 | } | 
|  | 6452 | break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6453 |  | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6454 | case DW_AT_specification: | 
|  | 6455 | specification_die_offset = form_value.Reference(dwarf_cu); | 
|  | 6456 | break; | 
|  | 6457 |  | 
|  | 6458 | case DW_AT_abstract_origin: | 
|  | 6459 | abstract_origin_die_offset = form_value.Reference(dwarf_cu); | 
|  | 6460 | break; | 
|  | 6461 |  | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6462 | case DW_AT_object_pointer: | 
|  | 6463 | object_pointer_die_offset = form_value.Reference(dwarf_cu); | 
|  | 6464 | break; | 
|  | 6465 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6466 | case DW_AT_allocated: | 
|  | 6467 | case DW_AT_associated: | 
|  | 6468 | case DW_AT_address_class: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6469 | case DW_AT_calling_convention: | 
|  | 6470 | case DW_AT_data_location: | 
|  | 6471 | case DW_AT_elemental: | 
|  | 6472 | case DW_AT_entry_pc: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6473 | case DW_AT_frame_base: | 
|  | 6474 | case DW_AT_high_pc: | 
|  | 6475 | case DW_AT_low_pc: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6476 | case DW_AT_prototyped: | 
|  | 6477 | case DW_AT_pure: | 
|  | 6478 | case DW_AT_ranges: | 
|  | 6479 | case DW_AT_recursive: | 
|  | 6480 | case DW_AT_return_addr: | 
|  | 6481 | case DW_AT_segment: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6482 | case DW_AT_start_scope: | 
|  | 6483 | case DW_AT_static_link: | 
|  | 6484 | case DW_AT_trampoline: | 
|  | 6485 | case DW_AT_visibility: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6486 | case DW_AT_vtable_elem_location: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6487 | case DW_AT_description: | 
|  | 6488 | case DW_AT_sibling: | 
|  | 6489 | break; | 
|  | 6490 | } | 
|  | 6491 | } | 
|  | 6492 | } | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6493 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6494 |  | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6495 | std::string object_pointer_name; | 
|  | 6496 | if (object_pointer_die_offset != DW_INVALID_OFFSET) | 
|  | 6497 | { | 
|  | 6498 | // Get the name from the object pointer die | 
|  | 6499 | StreamString s; | 
|  | 6500 | if (DWARFDebugInfoEntry::GetName (this, dwarf_cu, object_pointer_die_offset, s)) | 
|  | 6501 | { | 
|  | 6502 | object_pointer_name.assign(s.GetData()); | 
|  | 6503 | } | 
|  | 6504 | } | 
|  | 6505 |  | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6506 | 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] | 6507 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6508 | ClangASTType return_clang_type; | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6509 | Type *func_type = NULL; | 
|  | 6510 |  | 
|  | 6511 | if (type_die_offset != DW_INVALID_OFFSET) | 
|  | 6512 | func_type = ResolveTypeUID(type_die_offset); | 
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6513 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6514 | if (func_type) | 
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 6515 | return_clang_type = func_type->GetClangForwardType(); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6516 | else | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6517 | return_clang_type = ast.GetBasicType(eBasicTypeVoid); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6518 |  | 
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6519 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6520 | std::vector<ClangASTType> function_param_types; | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6521 | std::vector<clang::ParmVarDecl*> function_param_decls; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6522 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6523 | // Parse the function children for the parameters | 
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 6524 |  | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6525 | const DWARFDebugInfoEntry *decl_ctx_die = NULL; | 
|  | 6526 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die); | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6527 | const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind(); | 
|  | 6528 |  | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6529 | const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind); | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6530 | // Start off static. This will be set to false in ParseChildParameters(...) | 
|  | 6531 | // if we find a "this" paramters as the first parameter | 
|  | 6532 | if (is_cxx_method) | 
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 6533 | is_static = true; | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 6534 | ClangASTContext::TemplateParameterInfos template_param_infos; | 
|  | 6535 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6536 | if (die->HasChildren()) | 
|  | 6537 | { | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6538 | bool skip_artificial = true; | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6539 | ParseChildParameters (sc, | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6540 | containing_decl_ctx, | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6541 | dwarf_cu, | 
|  | 6542 | die, | 
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 6543 | skip_artificial, | 
|  | 6544 | is_static, | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6545 | type_list, | 
|  | 6546 | function_param_types, | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 6547 | function_param_decls, | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 6548 | type_quals, | 
|  | 6549 | template_param_infos); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6550 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6551 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6552 | // clang_type will get the function prototype clang type after this call | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6553 | clang_type = ast.CreateFunctionType (return_clang_type, | 
| Greg Clayton | 9cb25c4 | 2012-10-30 17:02:18 +0000 | [diff] [blame] | 6554 | function_param_types.data(), | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6555 | function_param_types.size(), | 
|  | 6556 | is_variadic, | 
|  | 6557 | type_quals); | 
|  | 6558 |  | 
| Sean Callanan | de9ce87 | 2013-05-09 23:13:13 +0000 | [diff] [blame] | 6559 | bool ignore_containing_context = false; | 
|  | 6560 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6561 | if (type_name_cstr) | 
|  | 6562 | { | 
|  | 6563 | bool type_handled = false; | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6564 | if (tag == DW_TAG_subprogram) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6565 | { | 
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 6566 | ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true); | 
|  | 6567 | if (objc_method.IsValid(true)) | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6568 | { | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6569 | SymbolContext empty_sc; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6570 | ClangASTType class_opaque_type; | 
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 6571 | ConstString class_name(objc_method.GetClassName()); | 
| Greg Clayton | 7c81042 | 2012-01-18 23:40:49 +0000 | [diff] [blame] | 6572 | if (class_name) | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6573 | { | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6574 | TypeList types; | 
| Greg Clayton | 278a16b | 2012-01-19 00:52:59 +0000 | [diff] [blame] | 6575 | TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false)); | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6576 |  | 
|  | 6577 | if (complete_objc_class_type_sp) | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6578 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6579 | ClangASTType type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType(); | 
|  | 6580 | if (type_clang_forward_type.IsObjCObjectOrInterfaceType ()) | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6581 | class_opaque_type = type_clang_forward_type; | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6582 | } | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6583 | } | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6584 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6585 | if (class_opaque_type) | 
|  | 6586 | { | 
|  | 6587 | // If accessibility isn't set to anything valid, assume public for | 
|  | 6588 | // now... | 
|  | 6589 | if (accessibility == eAccessNone) | 
|  | 6590 | accessibility = eAccessPublic; | 
|  | 6591 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6592 | clang::ObjCMethodDecl *objc_method_decl = class_opaque_type.AddMethodToObjCObjectType (type_name_cstr, | 
|  | 6593 | clang_type, | 
|  | 6594 | accessibility, | 
|  | 6595 | is_artificial); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6596 | type_handled = objc_method_decl != NULL; | 
| Sean Callanan | 464a5b5 | 2012-10-04 22:06:29 +0000 | [diff] [blame] | 6597 | if (type_handled) | 
|  | 6598 | { | 
|  | 6599 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die); | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6600 | GetClangASTContext().SetMetadataAsUserID (objc_method_decl, MakeUserID(die->GetOffset())); | 
| Sean Callanan | 464a5b5 | 2012-10-04 22:06:29 +0000 | [diff] [blame] | 6601 | } | 
| Sean Callanan | c3a1d56 | 2013-02-06 23:21:59 +0000 | [diff] [blame] | 6602 | else | 
|  | 6603 | { | 
| Jason Molenda | c1a6583 | 2013-03-07 22:44:42 +0000 | [diff] [blame] | 6604 | 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] | 6605 | die->GetOffset(), | 
|  | 6606 | tag, | 
|  | 6607 | DW_TAG_value_to_name(tag)); | 
|  | 6608 | } | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6609 | } | 
|  | 6610 | } | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6611 | else if (is_cxx_method) | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6612 | { | 
|  | 6613 | // Look at the parent of this DIE and see if is is | 
|  | 6614 | // a class or struct and see if this is actually a | 
|  | 6615 | // C++ method | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6616 | Type *class_type = ResolveType (dwarf_cu, decl_ctx_die); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6617 | if (class_type) | 
|  | 6618 | { | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6619 | if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset())) | 
|  | 6620 | { | 
|  | 6621 | // We uniqued the parent class of this function to another class | 
|  | 6622 | // so we now need to associate all dies under "decl_ctx_die" to | 
|  | 6623 | // DIEs in the DIE for "class_type"... | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 6624 | SymbolFileDWARF *class_symfile = NULL; | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6625 | DWARFCompileUnitSP class_type_cu_sp; | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 6626 | const DWARFDebugInfoEntry *class_type_die = NULL; | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6627 |  | 
|  | 6628 | SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile(); | 
|  | 6629 | if (debug_map_symfile) | 
|  | 6630 | { | 
|  | 6631 | class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID())); | 
|  | 6632 | class_type_die = class_symfile->DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp); | 
|  | 6633 | } | 
|  | 6634 | else | 
|  | 6635 | { | 
|  | 6636 | class_symfile = this; | 
|  | 6637 | class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp); | 
|  | 6638 | } | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6639 | if (class_type_die) | 
|  | 6640 | { | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6641 | llvm::SmallVector<const DWARFDebugInfoEntry *, 0> failures; | 
|  | 6642 |  | 
|  | 6643 | CopyUniqueClassMethodTypes (class_symfile, | 
|  | 6644 | class_type, | 
|  | 6645 | class_type_cu_sp.get(), | 
|  | 6646 | class_type_die, | 
|  | 6647 | dwarf_cu, | 
|  | 6648 | decl_ctx_die, | 
|  | 6649 | failures); | 
|  | 6650 |  | 
|  | 6651 | // FIXME do something with these failures that's smarter than | 
|  | 6652 | // just dropping them on the ground.  Unfortunately classes don't | 
|  | 6653 | // like having stuff added to them after their definitions are | 
|  | 6654 | // complete... | 
|  | 6655 |  | 
|  | 6656 | type_ptr = m_die_to_type[die]; | 
|  | 6657 | if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6658 | { | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6659 | type_sp = type_ptr->shared_from_this(); | 
|  | 6660 | break; | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6661 | } | 
|  | 6662 | } | 
|  | 6663 | } | 
|  | 6664 |  | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6665 | if (specification_die_offset != DW_INVALID_OFFSET) | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6666 | { | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6667 | // We have a specification which we are going to base our function | 
|  | 6668 | // prototype off of, so we need this type to be completed so that the | 
|  | 6669 | // m_die_to_decl_ctx for the method in the specification has a valid | 
|  | 6670 | // clang decl context. | 
| Greg Clayton | 8eb732e | 2011-12-13 04:34:06 +0000 | [diff] [blame] | 6671 | class_type->GetClangForwardType(); | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6672 | // If we have a specification, then the function type should have been | 
|  | 6673 | // made with the specification and not with this die. | 
|  | 6674 | DWARFCompileUnitSP spec_cu_sp; | 
|  | 6675 | const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp); | 
| Eric Christopher | 6cc6e60 | 2012-03-25 19:37:33 +0000 | [diff] [blame] | 6676 | clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die); | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6677 | if (spec_clang_decl_ctx) | 
|  | 6678 | { | 
|  | 6679 | LinkDeclContextToDIE(spec_clang_decl_ctx, die); | 
|  | 6680 | } | 
|  | 6681 | else | 
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6682 | { | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6683 | 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] | 6684 | MakeUserID(die->GetOffset()), | 
|  | 6685 | specification_die_offset); | 
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6686 | } | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6687 | type_handled = true; | 
|  | 6688 | } | 
|  | 6689 | else if (abstract_origin_die_offset != DW_INVALID_OFFSET) | 
|  | 6690 | { | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6691 | // We have a specification which we are going to base our function | 
|  | 6692 | // prototype off of, so we need this type to be completed so that the | 
|  | 6693 | // m_die_to_decl_ctx for the method in the abstract origin has a valid | 
|  | 6694 | // clang decl context. | 
| Greg Clayton | 8eb732e | 2011-12-13 04:34:06 +0000 | [diff] [blame] | 6695 | class_type->GetClangForwardType(); | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6696 |  | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6697 | DWARFCompileUnitSP abs_cu_sp; | 
|  | 6698 | 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] | 6699 | clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die); | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6700 | if (abs_clang_decl_ctx) | 
|  | 6701 | { | 
|  | 6702 | LinkDeclContextToDIE (abs_clang_decl_ctx, die); | 
|  | 6703 | } | 
|  | 6704 | else | 
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6705 | { | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6706 | 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] | 6707 | MakeUserID(die->GetOffset()), | 
|  | 6708 | abstract_origin_die_offset); | 
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6709 | } | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6710 | type_handled = true; | 
|  | 6711 | } | 
|  | 6712 | else | 
|  | 6713 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6714 | ClangASTType class_opaque_type = class_type->GetClangForwardType(); | 
|  | 6715 | if (class_opaque_type.IsCXXClassType ()) | 
| Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 6716 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6717 | if (class_opaque_type.IsBeingDefined ()) | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6718 | { | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6719 | // Neither GCC 4.2 nor clang++ currently set a valid accessibility | 
|  | 6720 | // in the DWARF for C++ methods... Default to public for now... | 
|  | 6721 | if (accessibility == eAccessNone) | 
|  | 6722 | accessibility = eAccessPublic; | 
|  | 6723 |  | 
|  | 6724 | if (!is_static && !die->HasChildren()) | 
|  | 6725 | { | 
|  | 6726 | // We have a C++ member function with no children (this pointer!) | 
|  | 6727 | // and clang will get mad if we try and make a function that isn't | 
|  | 6728 | // well formed in the DWARF, so we will just skip it... | 
|  | 6729 | type_handled = true; | 
|  | 6730 | } | 
|  | 6731 | else | 
|  | 6732 | { | 
|  | 6733 | clang::CXXMethodDecl *cxx_method_decl; | 
|  | 6734 | // REMOVE THE CRASH DESCRIPTION BELOW | 
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 6735 | 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] | 6736 | type_name_cstr, | 
|  | 6737 | class_type->GetName().GetCString(), | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6738 | MakeUserID(die->GetOffset()), | 
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 6739 | m_obj_file->GetFileSpec().GetPath().c_str()); | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6740 |  | 
| Sean Callanan | c1b732d | 2011-11-01 18:07:13 +0000 | [diff] [blame] | 6741 | const bool is_attr_used = false; | 
|  | 6742 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6743 | cxx_method_decl = class_opaque_type.AddMethodToCXXRecordType (type_name_cstr, | 
|  | 6744 | clang_type, | 
|  | 6745 | accessibility, | 
|  | 6746 | is_virtual, | 
|  | 6747 | is_static, | 
|  | 6748 | is_inline, | 
|  | 6749 | is_explicit, | 
|  | 6750 | is_attr_used, | 
|  | 6751 | is_artificial); | 
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6752 |  | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6753 | type_handled = cxx_method_decl != NULL; | 
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6754 |  | 
|  | 6755 | if (type_handled) | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6756 | { | 
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6757 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die); | 
|  | 6758 |  | 
|  | 6759 | Host::SetCrashDescription (NULL); | 
|  | 6760 |  | 
|  | 6761 |  | 
|  | 6762 | ClangASTMetadata metadata; | 
|  | 6763 | metadata.SetUserID(MakeUserID(die->GetOffset())); | 
|  | 6764 |  | 
|  | 6765 | if (!object_pointer_name.empty()) | 
|  | 6766 | { | 
|  | 6767 | metadata.SetObjectPtrName(object_pointer_name.c_str()); | 
|  | 6768 | if (log) | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6769 | log->Printf ("Setting object pointer name: %s on method object %p.\n", | 
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6770 | object_pointer_name.c_str(), | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6771 | cxx_method_decl); | 
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6772 | } | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6773 | GetClangASTContext().SetMetadata (cxx_method_decl, metadata); | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6774 | } | 
| Sean Callanan | b0640dc | 2013-04-09 23:22:08 +0000 | [diff] [blame] | 6775 | else | 
|  | 6776 | { | 
| Sean Callanan | de9ce87 | 2013-05-09 23:13:13 +0000 | [diff] [blame] | 6777 | ignore_containing_context = true; | 
| Sean Callanan | b0640dc | 2013-04-09 23:22:08 +0000 | [diff] [blame] | 6778 | } | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6779 | } | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6780 | } | 
|  | 6781 | else | 
|  | 6782 | { | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6783 | // We were asked to parse the type for a method in a class, yet the | 
|  | 6784 | // class hasn't been asked to complete itself through the | 
|  | 6785 | // clang::ExternalASTSource protocol, so we need to just have the | 
|  | 6786 | // class complete itself and do things the right way, then our | 
|  | 6787 | // DIE should then have an entry in the m_die_to_type map. First | 
|  | 6788 | // we need to modify the m_die_to_type so it doesn't think we are | 
|  | 6789 | // trying to parse this DIE anymore... | 
|  | 6790 | m_die_to_type[die] = NULL; | 
|  | 6791 |  | 
|  | 6792 | // Now we get the full type to force our class type to complete itself | 
|  | 6793 | // using the clang::ExternalASTSource protocol which will parse all | 
|  | 6794 | // base classes and all methods (including the method for this DIE). | 
|  | 6795 | class_type->GetClangFullType(); | 
| Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 6796 |  | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6797 | // The type for this DIE should have been filled in the function call above | 
|  | 6798 | type_ptr = m_die_to_type[die]; | 
| Greg Clayton | e5476db | 2012-06-01 20:32:35 +0000 | [diff] [blame] | 6799 | if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6800 | { | 
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 6801 | type_sp = type_ptr->shared_from_this(); | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6802 | break; | 
|  | 6803 | } | 
| Sean Callanan | 02eee4d | 2012-04-12 23:10:00 +0000 | [diff] [blame] | 6804 |  | 
|  | 6805 | // FIXME This is fixing some even uglier behavior but we really need to | 
|  | 6806 | // uniq the methods of each class as well as the class itself. | 
|  | 6807 | // <rdar://problem/11240464> | 
|  | 6808 | type_handled = true; | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6809 | } | 
| Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 6810 | } | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6811 | } | 
|  | 6812 | } | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6813 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6814 | } | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6815 |  | 
|  | 6816 | if (!type_handled) | 
|  | 6817 | { | 
|  | 6818 | // We just have a function that isn't part of a class | 
| Sean Callanan | de9ce87 | 2013-05-09 23:13:13 +0000 | [diff] [blame] | 6819 | 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] | 6820 | type_name_cstr, | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6821 | clang_type, | 
|  | 6822 | storage, | 
|  | 6823 | is_inline); | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 6824 |  | 
|  | 6825 | //                            if (template_param_infos.GetSize() > 0) | 
|  | 6826 | //                            { | 
|  | 6827 | //                                clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx, | 
|  | 6828 | //                                                                                                                  function_decl, | 
|  | 6829 | //                                                                                                                  type_name_cstr, | 
|  | 6830 | //                                                                                                                  template_param_infos); | 
|  | 6831 | // | 
|  | 6832 | //                                ast.CreateFunctionTemplateSpecializationInfo (function_decl, | 
|  | 6833 | //                                                                              func_template_decl, | 
|  | 6834 | //                                                                              template_param_infos); | 
|  | 6835 | //                            } | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6836 | // Add the decl to our DIE to decl context map | 
|  | 6837 | assert (function_decl); | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6838 | LinkDeclContextToDIE(function_decl, die); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6839 | if (!function_param_decls.empty()) | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6840 | ast.SetFunctionParameters (function_decl, | 
|  | 6841 | &function_param_decls.front(), | 
|  | 6842 | function_param_decls.size()); | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 6843 |  | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6844 | ClangASTMetadata metadata; | 
|  | 6845 | metadata.SetUserID(MakeUserID(die->GetOffset())); | 
|  | 6846 |  | 
|  | 6847 | if (!object_pointer_name.empty()) | 
|  | 6848 | { | 
|  | 6849 | metadata.SetObjectPtrName(object_pointer_name.c_str()); | 
| Jim Ingham | 2cffda3f | 2012-10-30 23:34:07 +0000 | [diff] [blame] | 6850 | if (log) | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6851 | log->Printf ("Setting object pointer name: %s on function object %p.", | 
| Jim Ingham | 2cffda3f | 2012-10-30 23:34:07 +0000 | [diff] [blame] | 6852 | object_pointer_name.c_str(), | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6853 | function_decl); | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6854 | } | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6855 | GetClangASTContext().SetMetadata (function_decl, metadata); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6856 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6857 | } | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6858 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6859 | this, | 
|  | 6860 | type_name_const_str, | 
|  | 6861 | 0, | 
|  | 6862 | NULL, | 
|  | 6863 | LLDB_INVALID_UID, | 
|  | 6864 | Type::eEncodingIsUID, | 
|  | 6865 | &decl, | 
|  | 6866 | clang_type, | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6867 | Type::eResolveStateFull)); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6868 | assert(type_sp.get()); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6869 | } | 
|  | 6870 | break; | 
|  | 6871 |  | 
|  | 6872 | case DW_TAG_array_type: | 
|  | 6873 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6874 | // 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] | 6875 | m_die_to_type[die] = DIE_IS_BEING_PARSED; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6876 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6877 | lldb::user_id_t type_die_offset = DW_INVALID_OFFSET; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6878 | int64_t first_index = 0; | 
|  | 6879 | uint32_t byte_stride = 0; | 
|  | 6880 | uint32_t bit_stride = 0; | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 6881 | bool is_vector = false; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6882 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6883 |  | 
|  | 6884 | if (num_attributes > 0) | 
|  | 6885 | { | 
|  | 6886 | uint32_t i; | 
|  | 6887 | for (i=0; i<num_attributes; ++i) | 
|  | 6888 | { | 
|  | 6889 | attr = attributes.AttributeAtIndex(i); | 
|  | 6890 | DWARFFormValue form_value; | 
|  | 6891 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 6892 | { | 
|  | 6893 | switch (attr) | 
|  | 6894 | { | 
|  | 6895 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 6896 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 6897 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 6898 | case DW_AT_name: | 
|  | 6899 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6900 | type_name_const_str.SetCString(type_name_cstr); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6901 | break; | 
|  | 6902 |  | 
|  | 6903 | case DW_AT_type:            type_die_offset = form_value.Reference(dwarf_cu); break; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6904 | case DW_AT_byte_size:       break; // byte_size = form_value.Unsigned(); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6905 | case DW_AT_byte_stride:     byte_stride = form_value.Unsigned(); break; | 
|  | 6906 | case DW_AT_bit_stride:      bit_stride = form_value.Unsigned(); break; | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 6907 | case DW_AT_GNU_vector:      is_vector = form_value.Boolean(); break; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6908 | 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] | 6909 | case DW_AT_declaration:     break; // is_forward_declaration = form_value.Boolean(); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6910 | case DW_AT_allocated: | 
|  | 6911 | case DW_AT_associated: | 
|  | 6912 | case DW_AT_data_location: | 
|  | 6913 | case DW_AT_description: | 
|  | 6914 | case DW_AT_ordering: | 
|  | 6915 | case DW_AT_start_scope: | 
|  | 6916 | case DW_AT_visibility: | 
|  | 6917 | case DW_AT_specification: | 
|  | 6918 | case DW_AT_abstract_origin: | 
|  | 6919 | case DW_AT_sibling: | 
|  | 6920 | break; | 
|  | 6921 | } | 
|  | 6922 | } | 
|  | 6923 | } | 
|  | 6924 |  | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6925 | 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] | 6926 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6927 | Type *element_type = ResolveTypeUID(type_die_offset); | 
|  | 6928 |  | 
|  | 6929 | if (element_type) | 
|  | 6930 | { | 
|  | 6931 | std::vector<uint64_t> element_orders; | 
|  | 6932 | ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride); | 
|  | 6933 | if (byte_stride == 0 && bit_stride == 0) | 
|  | 6934 | byte_stride = element_type->GetByteSize(); | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6935 | ClangASTType array_element_type = element_type->GetClangForwardType(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6936 | uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride; | 
|  | 6937 | uint64_t num_elements = 0; | 
|  | 6938 | std::vector<uint64_t>::const_reverse_iterator pos; | 
|  | 6939 | std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend(); | 
|  | 6940 | for (pos = element_orders.rbegin(); pos != end; ++pos) | 
|  | 6941 | { | 
|  | 6942 | num_elements = *pos; | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6943 | clang_type = ast.CreateArrayType (array_element_type, | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 6944 | num_elements, | 
|  | 6945 | is_vector); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6946 | array_element_type = clang_type; | 
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 6947 | array_element_bit_stride = num_elements ? array_element_bit_stride * num_elements : array_element_bit_stride; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6948 | } | 
|  | 6949 | ConstString empty_name; | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6950 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6951 | this, | 
|  | 6952 | empty_name, | 
|  | 6953 | array_element_bit_stride / 8, | 
|  | 6954 | NULL, | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6955 | type_die_offset, | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6956 | Type::eEncodingIsUID, | 
|  | 6957 | &decl, | 
|  | 6958 | clang_type, | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6959 | Type::eResolveStateFull)); | 
|  | 6960 | type_sp->SetEncodingType (element_type); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6961 | } | 
|  | 6962 | } | 
|  | 6963 | } | 
|  | 6964 | break; | 
|  | 6965 |  | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6966 | case DW_TAG_ptr_to_member_type: | 
|  | 6967 | { | 
|  | 6968 | dw_offset_t type_die_offset = DW_INVALID_OFFSET; | 
|  | 6969 | dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET; | 
|  | 6970 |  | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6971 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6972 |  | 
|  | 6973 | if (num_attributes > 0) { | 
|  | 6974 | uint32_t i; | 
|  | 6975 | for (i=0; i<num_attributes; ++i) | 
|  | 6976 | { | 
|  | 6977 | attr = attributes.AttributeAtIndex(i); | 
|  | 6978 | DWARFFormValue form_value; | 
|  | 6979 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 6980 | { | 
|  | 6981 | switch (attr) | 
|  | 6982 | { | 
|  | 6983 | case DW_AT_type: | 
|  | 6984 | type_die_offset = form_value.Reference(dwarf_cu); break; | 
|  | 6985 | case DW_AT_containing_type: | 
|  | 6986 | containing_type_die_offset = form_value.Reference(dwarf_cu); break; | 
|  | 6987 | } | 
|  | 6988 | } | 
|  | 6989 | } | 
|  | 6990 |  | 
|  | 6991 | Type *pointee_type = ResolveTypeUID(type_die_offset); | 
|  | 6992 | Type *class_type = ResolveTypeUID(containing_type_die_offset); | 
|  | 6993 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6994 | ClangASTType pointee_clang_type = pointee_type->GetClangForwardType(); | 
|  | 6995 | ClangASTType class_clang_type = class_type->GetClangLayoutType(); | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6996 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6997 | clang_type = pointee_clang_type.CreateMemberPointerType(class_clang_type); | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6998 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6999 | byte_size = clang_type.GetByteSize(); | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 7000 |  | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7001 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 7002 | this, | 
|  | 7003 | type_name_const_str, | 
|  | 7004 | byte_size, | 
|  | 7005 | NULL, | 
|  | 7006 | LLDB_INVALID_UID, | 
|  | 7007 | Type::eEncodingIsUID, | 
|  | 7008 | NULL, | 
|  | 7009 | clang_type, | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 7010 | Type::eResolveStateForward)); | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 7011 | } | 
|  | 7012 |  | 
|  | 7013 | break; | 
|  | 7014 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7015 | default: | 
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 7016 | 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", | 
|  | 7017 | die->GetOffset(), | 
|  | 7018 | tag, | 
|  | 7019 | DW_TAG_value_to_name(tag)); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7020 | break; | 
|  | 7021 | } | 
|  | 7022 |  | 
|  | 7023 | if (type_sp.get()) | 
|  | 7024 | { | 
|  | 7025 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); | 
|  | 7026 | dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; | 
|  | 7027 |  | 
|  | 7028 | SymbolContextScope * symbol_context_scope = NULL; | 
|  | 7029 | if (sc_parent_tag == DW_TAG_compile_unit) | 
|  | 7030 | { | 
|  | 7031 | symbol_context_scope = sc.comp_unit; | 
|  | 7032 | } | 
|  | 7033 | else if (sc.function != NULL) | 
|  | 7034 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7035 | 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] | 7036 | if (symbol_context_scope == NULL) | 
|  | 7037 | symbol_context_scope = sc.function; | 
|  | 7038 | } | 
|  | 7039 |  | 
|  | 7040 | if (symbol_context_scope != NULL) | 
|  | 7041 | { | 
|  | 7042 | type_sp->SetSymbolContextScope(symbol_context_scope); | 
|  | 7043 | } | 
|  | 7044 |  | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 7045 | // We are ready to put this type into the uniqued list up at the module level | 
|  | 7046 | type_list->Insert (type_sp); | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 7047 |  | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 7048 | m_die_to_type[die] = type_sp.get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7049 | } | 
|  | 7050 | } | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 7051 | else if (type_ptr != DIE_IS_BEING_PARSED) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7052 | { | 
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 7053 | type_sp = type_ptr->shared_from_this(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7054 | } | 
|  | 7055 | } | 
|  | 7056 | return type_sp; | 
|  | 7057 | } | 
|  | 7058 |  | 
|  | 7059 | size_t | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 7060 | SymbolFileDWARF::ParseTypes | 
|  | 7061 | ( | 
|  | 7062 | const SymbolContext& sc, | 
|  | 7063 | DWARFCompileUnit* dwarf_cu, | 
|  | 7064 | const DWARFDebugInfoEntry *die, | 
|  | 7065 | bool parse_siblings, | 
|  | 7066 | bool parse_children | 
|  | 7067 | ) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7068 | { | 
|  | 7069 | size_t types_added = 0; | 
|  | 7070 | while (die != NULL) | 
|  | 7071 | { | 
|  | 7072 | bool type_is_new = false; | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 7073 | if (ParseType(sc, dwarf_cu, die, &type_is_new).get()) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7074 | { | 
|  | 7075 | if (type_is_new) | 
|  | 7076 | ++types_added; | 
|  | 7077 | } | 
|  | 7078 |  | 
|  | 7079 | if (parse_children && die->HasChildren()) | 
|  | 7080 | { | 
|  | 7081 | if (die->Tag() == DW_TAG_subprogram) | 
|  | 7082 | { | 
|  | 7083 | SymbolContext child_sc(sc); | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7084 | child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7085 | types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true); | 
|  | 7086 | } | 
|  | 7087 | else | 
|  | 7088 | types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true); | 
|  | 7089 | } | 
|  | 7090 |  | 
|  | 7091 | if (parse_siblings) | 
|  | 7092 | die = die->GetSibling(); | 
|  | 7093 | else | 
|  | 7094 | die = NULL; | 
|  | 7095 | } | 
|  | 7096 | return types_added; | 
|  | 7097 | } | 
|  | 7098 |  | 
|  | 7099 |  | 
|  | 7100 | size_t | 
|  | 7101 | SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc) | 
|  | 7102 | { | 
|  | 7103 | assert(sc.comp_unit && sc.function); | 
|  | 7104 | size_t functions_added = 0; | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 7105 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7106 | if (dwarf_cu) | 
|  | 7107 | { | 
|  | 7108 | dw_offset_t function_die_offset = sc.function->GetID(); | 
|  | 7109 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset); | 
|  | 7110 | if (function_die) | 
|  | 7111 | { | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 7112 | 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] | 7113 | } | 
|  | 7114 | } | 
|  | 7115 |  | 
|  | 7116 | return functions_added; | 
|  | 7117 | } | 
|  | 7118 |  | 
|  | 7119 |  | 
|  | 7120 | size_t | 
|  | 7121 | SymbolFileDWARF::ParseTypes (const SymbolContext &sc) | 
|  | 7122 | { | 
|  | 7123 | // At least a compile unit must be valid | 
|  | 7124 | assert(sc.comp_unit); | 
|  | 7125 | size_t types_added = 0; | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 7126 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7127 | if (dwarf_cu) | 
|  | 7128 | { | 
|  | 7129 | if (sc.function) | 
|  | 7130 | { | 
|  | 7131 | dw_offset_t function_die_offset = sc.function->GetID(); | 
|  | 7132 | const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset); | 
|  | 7133 | if (func_die && func_die->HasChildren()) | 
|  | 7134 | { | 
|  | 7135 | types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true); | 
|  | 7136 | } | 
|  | 7137 | } | 
|  | 7138 | else | 
|  | 7139 | { | 
|  | 7140 | const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE(); | 
|  | 7141 | if (dwarf_cu_die && dwarf_cu_die->HasChildren()) | 
|  | 7142 | { | 
|  | 7143 | types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true); | 
|  | 7144 | } | 
|  | 7145 | } | 
|  | 7146 | } | 
|  | 7147 |  | 
|  | 7148 | return types_added; | 
|  | 7149 | } | 
|  | 7150 |  | 
|  | 7151 | size_t | 
|  | 7152 | SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc) | 
|  | 7153 | { | 
|  | 7154 | if (sc.comp_unit != NULL) | 
|  | 7155 | { | 
| Greg Clayton | 4b3dc10 | 2010-11-01 20:32:12 +0000 | [diff] [blame] | 7156 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 7157 | if (info == NULL) | 
|  | 7158 | return 0; | 
|  | 7159 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7160 | if (sc.function) | 
|  | 7161 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7162 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnitContainingDIE(sc.function->GetID()).get(); | 
|  | 7163 |  | 
|  | 7164 | if (dwarf_cu == NULL) | 
|  | 7165 | return 0; | 
|  | 7166 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7167 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID()); | 
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 7168 |  | 
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 7169 | dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS); | 
|  | 7170 | if (func_lo_pc != LLDB_INVALID_ADDRESS) | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 7171 | { | 
|  | 7172 | 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] | 7173 |  | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 7174 | // Let all blocks know they have parse all their variables | 
|  | 7175 | sc.function->GetBlock (false).SetDidParseVariables (true, true); | 
|  | 7176 | return num_variables; | 
|  | 7177 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7178 | } | 
|  | 7179 | else if (sc.comp_unit) | 
|  | 7180 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7181 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()).get(); | 
|  | 7182 |  | 
|  | 7183 | if (dwarf_cu == NULL) | 
|  | 7184 | return 0; | 
|  | 7185 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7186 | uint32_t vars_added = 0; | 
|  | 7187 | VariableListSP variables (sc.comp_unit->GetVariableList(false)); | 
|  | 7188 |  | 
|  | 7189 | if (variables.get() == NULL) | 
|  | 7190 | { | 
|  | 7191 | variables.reset(new VariableList()); | 
|  | 7192 | sc.comp_unit->SetVariableList(variables); | 
|  | 7193 |  | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7194 | DWARFCompileUnit* match_dwarf_cu = NULL; | 
|  | 7195 | const DWARFDebugInfoEntry* die = NULL; | 
|  | 7196 | DIEArray die_offsets; | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 7197 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7198 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 7199 | if (m_apple_names_ap.get()) | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7200 | { | 
|  | 7201 | DWARFMappedHash::DIEInfoArray hash_data_array; | 
|  | 7202 | if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(), | 
|  | 7203 | dwarf_cu->GetNextCompileUnitOffset(), | 
|  | 7204 | hash_data_array)) | 
|  | 7205 | { | 
|  | 7206 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); | 
|  | 7207 | } | 
|  | 7208 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7209 | } | 
|  | 7210 | else | 
|  | 7211 | { | 
|  | 7212 | // Index if we already haven't to make sure the compile units | 
|  | 7213 | // get indexed and make their global DIE index list | 
|  | 7214 | if (!m_indexed) | 
|  | 7215 | Index (); | 
|  | 7216 |  | 
|  | 7217 | m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(), | 
|  | 7218 | dwarf_cu->GetNextCompileUnitOffset(), | 
|  | 7219 | die_offsets); | 
|  | 7220 | } | 
|  | 7221 |  | 
|  | 7222 | const size_t num_matches = die_offsets.size(); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7223 | if (num_matches) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7224 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7225 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 7226 | for (size_t i=0; i<num_matches; ++i) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7227 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7228 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 7229 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 7230 | if (die) | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7231 | { | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 7232 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS)); | 
|  | 7233 | if (var_sp) | 
|  | 7234 | { | 
|  | 7235 | variables->AddVariableIfUnique (var_sp); | 
|  | 7236 | ++vars_added; | 
|  | 7237 | } | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7238 | } | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 7239 | else | 
|  | 7240 | { | 
|  | 7241 | if (m_using_apple_tables) | 
|  | 7242 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 7243 | 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] | 7244 | } | 
|  | 7245 | } | 
|  | 7246 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7247 | } | 
|  | 7248 | } | 
|  | 7249 | } | 
|  | 7250 | return vars_added; | 
|  | 7251 | } | 
|  | 7252 | } | 
|  | 7253 | return 0; | 
|  | 7254 | } | 
|  | 7255 |  | 
|  | 7256 |  | 
|  | 7257 | VariableSP | 
|  | 7258 | SymbolFileDWARF::ParseVariableDIE | 
|  | 7259 | ( | 
|  | 7260 | const SymbolContext& sc, | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 7261 | DWARFCompileUnit* dwarf_cu, | 
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 7262 | const DWARFDebugInfoEntry *die, | 
|  | 7263 | const lldb::addr_t func_low_pc | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7264 | ) | 
|  | 7265 | { | 
|  | 7266 |  | 
| Greg Clayton | 83c5cd9 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 7267 | VariableSP var_sp (m_die_to_variable_sp[die]); | 
|  | 7268 | if (var_sp) | 
|  | 7269 | return var_sp;  // Already been parsed! | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7270 |  | 
|  | 7271 | const dw_tag_t tag = die->Tag(); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7272 |  | 
|  | 7273 | if ((tag == DW_TAG_variable) || | 
|  | 7274 | (tag == DW_TAG_constant) || | 
|  | 7275 | (tag == DW_TAG_formal_parameter && sc.function)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7276 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7277 | DWARFDebugInfoEntry::Attributes attributes; | 
|  | 7278 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
|  | 7279 | if (num_attributes > 0) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7280 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7281 | const char *name = NULL; | 
|  | 7282 | const char *mangled = NULL; | 
|  | 7283 | Declaration decl; | 
|  | 7284 | uint32_t i; | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7285 | lldb::user_id_t type_uid = LLDB_INVALID_UID; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7286 | DWARFExpression location; | 
|  | 7287 | bool is_external = false; | 
|  | 7288 | bool is_artificial = false; | 
|  | 7289 | bool location_is_const_value_data = false; | 
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7290 | bool has_explicit_location = false; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 7291 | //AccessType accessibility = eAccessNone; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7292 |  | 
|  | 7293 | for (i=0; i<num_attributes; ++i) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7294 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7295 | dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 7296 | DWARFFormValue form_value; | 
|  | 7297 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7298 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7299 | switch (attr) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7300 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7301 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 7302 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 7303 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 7304 | 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] | 7305 | case DW_AT_linkage_name: | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7306 | case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break; | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7307 | case DW_AT_type:        type_uid = form_value.Reference(dwarf_cu); break; | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 7308 | case DW_AT_external:    is_external = form_value.Boolean(); break; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7309 | case DW_AT_const_value: | 
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7310 | // If we have already found a DW_AT_location attribute, ignore this attribute. | 
|  | 7311 | if (!has_explicit_location) | 
|  | 7312 | { | 
|  | 7313 | location_is_const_value_data = true; | 
|  | 7314 | // The constant value will be either a block, a data value or a string. | 
|  | 7315 | const DataExtractor& debug_info_data = get_debug_info_data(); | 
|  | 7316 | if (DWARFFormValue::IsBlockForm(form_value.Form())) | 
|  | 7317 | { | 
|  | 7318 | // Retrieve the value as a block expression. | 
|  | 7319 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); | 
|  | 7320 | uint32_t block_length = form_value.Unsigned(); | 
|  | 7321 | location.CopyOpcodeData(debug_info_data, block_offset, block_length); | 
|  | 7322 | } | 
|  | 7323 | else if (DWARFFormValue::IsDataForm(form_value.Form())) | 
|  | 7324 | { | 
|  | 7325 | // Retrieve the value as a data expression. | 
|  | 7326 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); | 
|  | 7327 | uint32_t data_offset = attributes.DIEOffsetAtIndex(i); | 
|  | 7328 | uint32_t data_length = fixed_form_sizes[form_value.Form()]; | 
|  | 7329 | location.CopyOpcodeData(debug_info_data, data_offset, data_length); | 
|  | 7330 | } | 
|  | 7331 | else | 
|  | 7332 | { | 
|  | 7333 | // Retrieve the value as a string expression. | 
|  | 7334 | if (form_value.Form() == DW_FORM_strp) | 
|  | 7335 | { | 
|  | 7336 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); | 
|  | 7337 | uint32_t data_offset = attributes.DIEOffsetAtIndex(i); | 
|  | 7338 | uint32_t data_length = fixed_form_sizes[form_value.Form()]; | 
|  | 7339 | location.CopyOpcodeData(debug_info_data, data_offset, data_length); | 
|  | 7340 | } | 
|  | 7341 | else | 
|  | 7342 | { | 
|  | 7343 | const char *str = form_value.AsCString(&debug_info_data); | 
|  | 7344 | uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart(); | 
|  | 7345 | uint32_t string_length = strlen(str) + 1; | 
|  | 7346 | location.CopyOpcodeData(debug_info_data, string_offset, string_length); | 
|  | 7347 | } | 
|  | 7348 | } | 
|  | 7349 | } | 
|  | 7350 | break; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7351 | case DW_AT_location: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7352 | { | 
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7353 | location_is_const_value_data = false; | 
|  | 7354 | has_explicit_location = true; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7355 | if (form_value.BlockData()) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7356 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7357 | const DataExtractor& debug_info_data = get_debug_info_data(); | 
|  | 7358 |  | 
|  | 7359 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); | 
|  | 7360 | uint32_t block_length = form_value.Unsigned(); | 
| Greg Clayton | 7f4c743 | 2012-08-11 00:49:14 +0000 | [diff] [blame] | 7361 | location.CopyOpcodeData(get_debug_info_data(), block_offset, block_length); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7362 | } | 
|  | 7363 | else | 
|  | 7364 | { | 
|  | 7365 | const DataExtractor&    debug_loc_data = get_debug_loc_data(); | 
|  | 7366 | const dw_offset_t debug_loc_offset = form_value.Unsigned(); | 
|  | 7367 |  | 
|  | 7368 | size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset); | 
|  | 7369 | if (loc_list_length > 0) | 
|  | 7370 | { | 
| Greg Clayton | 7f4c743 | 2012-08-11 00:49:14 +0000 | [diff] [blame] | 7371 | location.CopyOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7372 | assert (func_low_pc != LLDB_INVALID_ADDRESS); | 
|  | 7373 | location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress()); | 
|  | 7374 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7375 | } | 
|  | 7376 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7377 | break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7378 |  | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 7379 | case DW_AT_artificial:      is_artificial = form_value.Boolean(); break; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 7380 | 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] | 7381 | case DW_AT_declaration: | 
|  | 7382 | case DW_AT_description: | 
|  | 7383 | case DW_AT_endianity: | 
|  | 7384 | case DW_AT_segment: | 
|  | 7385 | case DW_AT_start_scope: | 
|  | 7386 | case DW_AT_visibility: | 
|  | 7387 | default: | 
|  | 7388 | case DW_AT_abstract_origin: | 
|  | 7389 | case DW_AT_sibling: | 
|  | 7390 | case DW_AT_specification: | 
|  | 7391 | break; | 
|  | 7392 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7393 | } | 
|  | 7394 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7395 |  | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7396 | ValueType scope = eValueTypeInvalid; | 
|  | 7397 |  | 
|  | 7398 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); | 
|  | 7399 | dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; | 
|  | 7400 | SymbolContextScope * symbol_context_scope = NULL; | 
|  | 7401 |  | 
|  | 7402 | // DWARF doesn't specify if a DW_TAG_variable is a local, global | 
|  | 7403 | // or static variable, so we have to do a little digging by | 
|  | 7404 | // looking at the location of a varaible to see if it contains | 
|  | 7405 | // a DW_OP_addr opcode _somewhere_ in the definition. I say | 
|  | 7406 | // somewhere because clang likes to combine small global variables | 
|  | 7407 | // into the same symbol and have locations like: | 
|  | 7408 | // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus | 
|  | 7409 | // So if we don't have a DW_TAG_formal_parameter, we can look at | 
|  | 7410 | // the location to see if it contains a DW_OP_addr opcode, and | 
|  | 7411 | // then we can correctly classify  our variables. | 
|  | 7412 | if (tag == DW_TAG_formal_parameter) | 
|  | 7413 | scope = eValueTypeVariableArgument; | 
|  | 7414 | else | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7415 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7416 | bool op_error = false; | 
|  | 7417 | // Check if the location has a DW_OP_addr with any address value... | 
|  | 7418 | lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS; | 
|  | 7419 | if (!location_is_const_value_data) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7420 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7421 | location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error); | 
|  | 7422 | if (op_error) | 
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 7423 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7424 | StreamString strm; | 
|  | 7425 | location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL); | 
|  | 7426 | 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] | 7427 | } | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7428 | } | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7429 |  | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7430 | if (location_DW_OP_addr != LLDB_INVALID_ADDRESS) | 
|  | 7431 | { | 
|  | 7432 | if (is_external) | 
|  | 7433 | scope = eValueTypeVariableGlobal; | 
|  | 7434 | else | 
|  | 7435 | scope = eValueTypeVariableStatic; | 
|  | 7436 |  | 
|  | 7437 |  | 
|  | 7438 | SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile (); | 
|  | 7439 |  | 
|  | 7440 | if (debug_map_symfile) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7441 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7442 | // When leaving the DWARF in the .o files on darwin, | 
|  | 7443 | // when we have a global variable that wasn't initialized, | 
|  | 7444 | // the .o file might not have allocated a virtual | 
|  | 7445 | // address for the global variable. In this case it will | 
|  | 7446 | // have created a symbol for the global variable | 
|  | 7447 | // that is undefined/data and external and the value will | 
|  | 7448 | // be the byte size of the variable. When we do the | 
|  | 7449 | // address map in SymbolFileDWARFDebugMap we rely on | 
|  | 7450 | // having an address, we need to do some magic here | 
|  | 7451 | // so we can get the correct address for our global | 
|  | 7452 | // variable. The address for all of these entries | 
|  | 7453 | // will be zero, and there will be an undefined symbol | 
|  | 7454 | // in this object file, and the executable will have | 
|  | 7455 | // a matching symbol with a good address. So here we | 
|  | 7456 | // dig up the correct address and replace it in the | 
|  | 7457 | // location for the variable, and set the variable's | 
|  | 7458 | // symbol context scope to be that of the main executable | 
|  | 7459 | // so the file address will resolve correctly. | 
|  | 7460 | bool linked_oso_file_addr = false; | 
|  | 7461 | if (is_external && location_DW_OP_addr == 0) | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7462 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7463 | // we have a possible uninitialized extern global | 
|  | 7464 | ConstString const_name(mangled ? mangled : name); | 
|  | 7465 | ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile(); | 
|  | 7466 | if (debug_map_objfile) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7467 | { | 
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 7468 | Symtab *debug_map_symtab = debug_map_objfile->GetSymtab(); | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7469 | if (debug_map_symtab) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7470 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7471 | Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name, | 
|  | 7472 | eSymbolTypeData, | 
|  | 7473 | Symtab::eDebugYes, | 
|  | 7474 | Symtab::eVisibilityExtern); | 
|  | 7475 | if (exe_symbol) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7476 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7477 | if (exe_symbol->ValueIsAddress()) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7478 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7479 | const addr_t exe_file_addr = exe_symbol->GetAddress().GetFileAddress(); | 
|  | 7480 | if (exe_file_addr != LLDB_INVALID_ADDRESS) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7481 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7482 | if (location.Update_DW_OP_addr (exe_file_addr)) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7483 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7484 | linked_oso_file_addr = true; | 
|  | 7485 | symbol_context_scope = exe_symbol; | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7486 | } | 
|  | 7487 | } | 
|  | 7488 | } | 
|  | 7489 | } | 
|  | 7490 | } | 
|  | 7491 | } | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7492 | } | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7493 |  | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7494 | if (!linked_oso_file_addr) | 
|  | 7495 | { | 
|  | 7496 | // The DW_OP_addr is not zero, but it contains a .o file address which | 
|  | 7497 | // needs to be linked up correctly. | 
|  | 7498 | const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr); | 
|  | 7499 | if (exe_file_addr != LLDB_INVALID_ADDRESS) | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7500 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7501 | // Update the file address for this variable | 
|  | 7502 | location.Update_DW_OP_addr (exe_file_addr); | 
|  | 7503 | } | 
|  | 7504 | else | 
|  | 7505 | { | 
|  | 7506 | // Variable didn't make it into the final executable | 
|  | 7507 | return var_sp; | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7508 | } | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7509 | } | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7510 | } | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 7511 | } | 
|  | 7512 | else | 
|  | 7513 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7514 | scope = eValueTypeVariableLocal; | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 7515 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7516 | } | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7517 |  | 
|  | 7518 | if (symbol_context_scope == NULL) | 
|  | 7519 | { | 
|  | 7520 | switch (parent_tag) | 
|  | 7521 | { | 
|  | 7522 | case DW_TAG_subprogram: | 
|  | 7523 | case DW_TAG_inlined_subroutine: | 
|  | 7524 | case DW_TAG_lexical_block: | 
|  | 7525 | if (sc.function) | 
|  | 7526 | { | 
|  | 7527 | symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); | 
|  | 7528 | if (symbol_context_scope == NULL) | 
|  | 7529 | symbol_context_scope = sc.function; | 
|  | 7530 | } | 
|  | 7531 | break; | 
|  | 7532 |  | 
|  | 7533 | default: | 
|  | 7534 | symbol_context_scope = sc.comp_unit; | 
|  | 7535 | break; | 
|  | 7536 | } | 
|  | 7537 | } | 
|  | 7538 |  | 
|  | 7539 | if (symbol_context_scope) | 
|  | 7540 | { | 
|  | 7541 | var_sp.reset (new Variable (MakeUserID(die->GetOffset()), | 
|  | 7542 | name, | 
|  | 7543 | mangled, | 
|  | 7544 | SymbolFileTypeSP (new SymbolFileType(*this, type_uid)), | 
|  | 7545 | scope, | 
|  | 7546 | symbol_context_scope, | 
|  | 7547 | &decl, | 
|  | 7548 | location, | 
|  | 7549 | is_external, | 
|  | 7550 | is_artificial)); | 
|  | 7551 |  | 
|  | 7552 | var_sp->SetLocationIsConstantValueData (location_is_const_value_data); | 
|  | 7553 | } | 
|  | 7554 | else | 
|  | 7555 | { | 
|  | 7556 | // Not ready to parse this variable yet. It might be a global | 
|  | 7557 | // or static variable that is in a function scope and the function | 
|  | 7558 | // in the symbol context wasn't filled in yet | 
|  | 7559 | return var_sp; | 
|  | 7560 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7561 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7562 | // Cache var_sp even if NULL (the variable was just a specification or | 
|  | 7563 | // was missing vital information to be able to be displayed in the debugger | 
|  | 7564 | // (missing location due to optimization, etc)) so we don't re-parse | 
|  | 7565 | // this DIE over and over later... | 
|  | 7566 | m_die_to_variable_sp[die] = var_sp; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7567 | } | 
|  | 7568 | return var_sp; | 
|  | 7569 | } | 
|  | 7570 |  | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7571 |  | 
|  | 7572 | const DWARFDebugInfoEntry * | 
|  | 7573 | SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset, | 
|  | 7574 | dw_offset_t spec_block_die_offset, | 
|  | 7575 | DWARFCompileUnit **result_die_cu_handle) | 
|  | 7576 | { | 
|  | 7577 | // Give the concrete function die specified by "func_die_offset", find the | 
|  | 7578 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points | 
|  | 7579 | // to "spec_block_die_offset" | 
|  | 7580 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 7581 |  | 
|  | 7582 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle); | 
|  | 7583 | if (die) | 
|  | 7584 | { | 
|  | 7585 | assert (*result_die_cu_handle); | 
|  | 7586 | return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle); | 
|  | 7587 | } | 
|  | 7588 | return NULL; | 
|  | 7589 | } | 
|  | 7590 |  | 
|  | 7591 |  | 
|  | 7592 | const DWARFDebugInfoEntry * | 
|  | 7593 | SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu, | 
|  | 7594 | const DWARFDebugInfoEntry *die, | 
|  | 7595 | dw_offset_t spec_block_die_offset, | 
|  | 7596 | DWARFCompileUnit **result_die_cu_handle) | 
|  | 7597 | { | 
|  | 7598 | if (die) | 
|  | 7599 | { | 
|  | 7600 | switch (die->Tag()) | 
|  | 7601 | { | 
|  | 7602 | case DW_TAG_subprogram: | 
|  | 7603 | case DW_TAG_inlined_subroutine: | 
|  | 7604 | case DW_TAG_lexical_block: | 
|  | 7605 | { | 
|  | 7606 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset) | 
|  | 7607 | { | 
|  | 7608 | *result_die_cu_handle = dwarf_cu; | 
|  | 7609 | return die; | 
|  | 7610 | } | 
|  | 7611 |  | 
|  | 7612 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset) | 
|  | 7613 | { | 
|  | 7614 | *result_die_cu_handle = dwarf_cu; | 
|  | 7615 | return die; | 
|  | 7616 | } | 
|  | 7617 | } | 
|  | 7618 | break; | 
|  | 7619 | } | 
|  | 7620 |  | 
|  | 7621 | // Give the concrete function die specified by "func_die_offset", find the | 
|  | 7622 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points | 
|  | 7623 | // to "spec_block_die_offset" | 
|  | 7624 | for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling()) | 
|  | 7625 | { | 
|  | 7626 | const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu, | 
|  | 7627 | child_die, | 
|  | 7628 | spec_block_die_offset, | 
|  | 7629 | result_die_cu_handle); | 
|  | 7630 | if (result_die) | 
|  | 7631 | return result_die; | 
|  | 7632 | } | 
|  | 7633 | } | 
|  | 7634 |  | 
|  | 7635 | *result_die_cu_handle = NULL; | 
|  | 7636 | return NULL; | 
|  | 7637 | } | 
|  | 7638 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7639 | size_t | 
|  | 7640 | SymbolFileDWARF::ParseVariables | 
|  | 7641 | ( | 
|  | 7642 | const SymbolContext& sc, | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 7643 | DWARFCompileUnit* dwarf_cu, | 
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 7644 | const lldb::addr_t func_low_pc, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7645 | const DWARFDebugInfoEntry *orig_die, | 
|  | 7646 | bool parse_siblings, | 
|  | 7647 | bool parse_children, | 
|  | 7648 | VariableList* cc_variable_list | 
|  | 7649 | ) | 
|  | 7650 | { | 
|  | 7651 | if (orig_die == NULL) | 
|  | 7652 | return 0; | 
|  | 7653 |  | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7654 | VariableListSP variable_list_sp; | 
|  | 7655 |  | 
|  | 7656 | size_t vars_added = 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7657 | const DWARFDebugInfoEntry *die = orig_die; | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7658 | while (die != NULL) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7659 | { | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7660 | dw_tag_t tag = die->Tag(); | 
|  | 7661 |  | 
|  | 7662 | // Check to see if we have already parsed this variable or constant? | 
|  | 7663 | if (m_die_to_variable_sp[die]) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7664 | { | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7665 | if (cc_variable_list) | 
|  | 7666 | cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7667 | } | 
|  | 7668 | else | 
|  | 7669 | { | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7670 | // We haven't already parsed it, lets do that now. | 
|  | 7671 | if ((tag == DW_TAG_variable) || | 
|  | 7672 | (tag == DW_TAG_constant) || | 
|  | 7673 | (tag == DW_TAG_formal_parameter && sc.function)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7674 | { | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7675 | if (variable_list_sp.get() == NULL) | 
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7676 | { | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7677 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die); | 
|  | 7678 | dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; | 
|  | 7679 | switch (parent_tag) | 
|  | 7680 | { | 
|  | 7681 | case DW_TAG_compile_unit: | 
|  | 7682 | if (sc.comp_unit != NULL) | 
|  | 7683 | { | 
|  | 7684 | variable_list_sp = sc.comp_unit->GetVariableList(false); | 
|  | 7685 | if (variable_list_sp.get() == NULL) | 
|  | 7686 | { | 
|  | 7687 | variable_list_sp.reset(new VariableList()); | 
|  | 7688 | sc.comp_unit->SetVariableList(variable_list_sp); | 
|  | 7689 | } | 
|  | 7690 | } | 
|  | 7691 | else | 
|  | 7692 | { | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 7693 | 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] | 7694 | MakeUserID(sc_parent_die->GetOffset()), | 
|  | 7695 | DW_TAG_value_to_name (parent_tag), | 
|  | 7696 | MakeUserID(orig_die->GetOffset()), | 
|  | 7697 | DW_TAG_value_to_name (orig_die->Tag())); | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7698 | } | 
|  | 7699 | break; | 
|  | 7700 |  | 
|  | 7701 | case DW_TAG_subprogram: | 
|  | 7702 | case DW_TAG_inlined_subroutine: | 
|  | 7703 | case DW_TAG_lexical_block: | 
|  | 7704 | if (sc.function != NULL) | 
|  | 7705 | { | 
|  | 7706 | // Check to see if we already have parsed the variables for the given scope | 
|  | 7707 |  | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7708 | Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7709 | if (block == NULL) | 
|  | 7710 | { | 
|  | 7711 | // This must be a specification or abstract origin with | 
|  | 7712 | // a concrete block couterpart in the current function. We need | 
|  | 7713 | // to find the concrete block so we can correctly add the | 
|  | 7714 | // variable to it | 
|  | 7715 | DWARFCompileUnit *concrete_block_die_cu = dwarf_cu; | 
|  | 7716 | const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(), | 
|  | 7717 | sc_parent_die->GetOffset(), | 
|  | 7718 | &concrete_block_die_cu); | 
|  | 7719 | if (concrete_block_die) | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7720 | block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset())); | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7721 | } | 
|  | 7722 |  | 
|  | 7723 | if (block != NULL) | 
|  | 7724 | { | 
|  | 7725 | const bool can_create = false; | 
|  | 7726 | variable_list_sp = block->GetBlockVariableList (can_create); | 
|  | 7727 | if (variable_list_sp.get() == NULL) | 
|  | 7728 | { | 
|  | 7729 | variable_list_sp.reset(new VariableList()); | 
|  | 7730 | block->SetVariableList(variable_list_sp); | 
|  | 7731 | } | 
|  | 7732 | } | 
|  | 7733 | } | 
|  | 7734 | break; | 
|  | 7735 |  | 
|  | 7736 | default: | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 7737 | 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] | 7738 | MakeUserID(orig_die->GetOffset()), | 
|  | 7739 | DW_TAG_value_to_name (orig_die->Tag())); | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7740 | break; | 
|  | 7741 | } | 
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7742 | } | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7743 |  | 
|  | 7744 | if (variable_list_sp) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7745 | { | 
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7746 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc)); | 
|  | 7747 | if (var_sp) | 
|  | 7748 | { | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7749 | variable_list_sp->AddVariableIfUnique (var_sp); | 
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7750 | if (cc_variable_list) | 
|  | 7751 | cc_variable_list->AddVariableIfUnique (var_sp); | 
|  | 7752 | ++vars_added; | 
|  | 7753 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7754 | } | 
|  | 7755 | } | 
|  | 7756 | } | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7757 |  | 
|  | 7758 | bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram); | 
|  | 7759 |  | 
|  | 7760 | if (!skip_children && parse_children && die->HasChildren()) | 
|  | 7761 | { | 
|  | 7762 | vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list); | 
|  | 7763 | } | 
|  | 7764 |  | 
|  | 7765 | if (parse_siblings) | 
|  | 7766 | die = die->GetSibling(); | 
|  | 7767 | else | 
|  | 7768 | die = NULL; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7769 | } | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7770 | return vars_added; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7771 | } | 
|  | 7772 |  | 
|  | 7773 | //------------------------------------------------------------------ | 
|  | 7774 | // PluginInterface protocol | 
|  | 7775 | //------------------------------------------------------------------ | 
| Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 7776 | ConstString | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7777 | SymbolFileDWARF::GetPluginName() | 
|  | 7778 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7779 | return GetPluginNameStatic(); | 
|  | 7780 | } | 
|  | 7781 |  | 
|  | 7782 | uint32_t | 
|  | 7783 | SymbolFileDWARF::GetPluginVersion() | 
|  | 7784 | { | 
|  | 7785 | return 1; | 
|  | 7786 | } | 
|  | 7787 |  | 
|  | 7788 | void | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 7789 | SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl) | 
|  | 7790 | { | 
|  | 7791 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 7792 | ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 7793 | if (clang_type) | 
|  | 7794 | symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); | 
|  | 7795 | } | 
|  | 7796 |  | 
|  | 7797 | void | 
|  | 7798 | SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl) | 
|  | 7799 | { | 
|  | 7800 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 7801 | ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 7802 | if (clang_type) | 
|  | 7803 | symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); | 
|  | 7804 | } | 
|  | 7805 |  | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7806 | void | 
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7807 | SymbolFileDWARF::DumpIndexes () | 
|  | 7808 | { | 
|  | 7809 | StreamFile s(stdout, false); | 
|  | 7810 |  | 
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 7811 | s.Printf ("DWARF index for (%s) '%s':", | 
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7812 | GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(), | 
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 7813 | GetObjectFile()->GetFileSpec().GetPath().c_str()); | 
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7814 | s.Printf("\nFunction basenames:\n");    m_function_basename_index.Dump (&s); | 
|  | 7815 | s.Printf("\nFunction fullnames:\n");    m_function_fullname_index.Dump (&s); | 
|  | 7816 | s.Printf("\nFunction methods:\n");      m_function_method_index.Dump (&s); | 
|  | 7817 | s.Printf("\nFunction selectors:\n");    m_function_selector_index.Dump (&s); | 
|  | 7818 | s.Printf("\nObjective C class selectors:\n");    m_objc_class_selectors_index.Dump (&s); | 
|  | 7819 | s.Printf("\nGlobals and statics:\n");   m_global_index.Dump (&s); | 
|  | 7820 | s.Printf("\nTypes:\n");                 m_type_index.Dump (&s); | 
|  | 7821 | s.Printf("\nNamepaces:\n");             m_namespace_index.Dump (&s); | 
|  | 7822 | } | 
|  | 7823 |  | 
|  | 7824 | void | 
|  | 7825 | SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context, | 
|  | 7826 | const char *name, | 
|  | 7827 | llvm::SmallVectorImpl <clang::NamedDecl *> *results) | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7828 | { | 
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7829 | DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context); | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7830 |  | 
|  | 7831 | if (iter == m_decl_ctx_to_die.end()) | 
|  | 7832 | return; | 
|  | 7833 |  | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7834 | 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] | 7835 | { | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7836 | const DWARFDebugInfoEntry *context_die = *pos; | 
|  | 7837 |  | 
|  | 7838 | if (!results) | 
|  | 7839 | return; | 
|  | 7840 |  | 
|  | 7841 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 7842 |  | 
|  | 7843 | DIEArray die_offsets; | 
|  | 7844 |  | 
|  | 7845 | DWARFCompileUnit* dwarf_cu = NULL; | 
|  | 7846 | const DWARFDebugInfoEntry* die = NULL; | 
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 7847 |  | 
|  | 7848 | if (m_using_apple_tables) | 
|  | 7849 | { | 
|  | 7850 | if (m_apple_types_ap.get()) | 
|  | 7851 | m_apple_types_ap->FindByName (name, die_offsets); | 
|  | 7852 | } | 
|  | 7853 | else | 
|  | 7854 | { | 
|  | 7855 | if (!m_indexed) | 
|  | 7856 | Index (); | 
|  | 7857 |  | 
|  | 7858 | m_type_index.Find (ConstString(name), die_offsets); | 
|  | 7859 | } | 
|  | 7860 |  | 
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 7861 | const size_t num_matches = die_offsets.size(); | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7862 |  | 
|  | 7863 | if (num_matches) | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7864 | { | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7865 | for (size_t i = 0; i < num_matches; ++i) | 
|  | 7866 | { | 
|  | 7867 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 7868 | die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7869 |  | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7870 | if (die->GetParent() != context_die) | 
|  | 7871 | continue; | 
|  | 7872 |  | 
|  | 7873 | Type *matching_type = ResolveType (dwarf_cu, die); | 
|  | 7874 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 7875 | clang::QualType qual_type = matching_type->GetClangForwardType().GetQualType(); | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7876 |  | 
|  | 7877 | if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr())) | 
|  | 7878 | { | 
|  | 7879 | clang::TagDecl *tag_decl = tag_type->getDecl(); | 
|  | 7880 | results->push_back(tag_decl); | 
|  | 7881 | } | 
|  | 7882 | else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr())) | 
|  | 7883 | { | 
|  | 7884 | clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl(); | 
|  | 7885 | results->push_back(typedef_decl); | 
|  | 7886 | } | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7887 | } | 
|  | 7888 | } | 
|  | 7889 | } | 
|  | 7890 | } | 
|  | 7891 |  | 
|  | 7892 | void | 
|  | 7893 | SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton, | 
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 7894 | const clang::DeclContext *decl_context, | 
|  | 7895 | clang::DeclarationName decl_name, | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7896 | llvm::SmallVectorImpl <clang::NamedDecl *> *results) | 
|  | 7897 | { | 
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 7898 |  | 
|  | 7899 | switch (decl_context->getDeclKind()) | 
|  | 7900 | { | 
|  | 7901 | case clang::Decl::Namespace: | 
|  | 7902 | case clang::Decl::TranslationUnit: | 
|  | 7903 | { | 
|  | 7904 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; | 
|  | 7905 | symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results); | 
|  | 7906 | } | 
|  | 7907 | break; | 
|  | 7908 | default: | 
|  | 7909 | break; | 
|  | 7910 | } | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7911 | } | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7912 |  | 
|  | 7913 | bool | 
|  | 7914 | SymbolFileDWARF::LayoutRecordType (void *baton, | 
|  | 7915 | const clang::RecordDecl *record_decl, | 
|  | 7916 | uint64_t &size, | 
|  | 7917 | uint64_t &alignment, | 
|  | 7918 | llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, | 
|  | 7919 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, | 
|  | 7920 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) | 
|  | 7921 | { | 
|  | 7922 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; | 
|  | 7923 | return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets); | 
|  | 7924 | } | 
|  | 7925 |  | 
|  | 7926 |  | 
|  | 7927 | bool | 
|  | 7928 | SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl, | 
|  | 7929 | uint64_t &bit_size, | 
|  | 7930 | uint64_t &alignment, | 
|  | 7931 | llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, | 
|  | 7932 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, | 
|  | 7933 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) | 
|  | 7934 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 7935 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7936 | RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl); | 
|  | 7937 | bool success = false; | 
|  | 7938 | base_offsets.clear(); | 
|  | 7939 | vbase_offsets.clear(); | 
|  | 7940 | if (pos != m_record_decl_to_layout_map.end()) | 
|  | 7941 | { | 
|  | 7942 | bit_size = pos->second.bit_size; | 
|  | 7943 | alignment = pos->second.alignment; | 
|  | 7944 | field_offsets.swap(pos->second.field_offsets); | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 7945 | base_offsets.swap (pos->second.base_offsets); | 
|  | 7946 | vbase_offsets.swap (pos->second.vbase_offsets); | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7947 | m_record_decl_to_layout_map.erase(pos); | 
|  | 7948 | success = true; | 
|  | 7949 | } | 
|  | 7950 | else | 
|  | 7951 | { | 
|  | 7952 | bit_size = 0; | 
|  | 7953 | alignment = 0; | 
|  | 7954 | field_offsets.clear(); | 
|  | 7955 | } | 
|  | 7956 |  | 
|  | 7957 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 7958 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 7959 | "SymbolFileDWARF::LayoutRecordType (record_decl = %p, bit_size = %" PRIu64 ", alignment = %" PRIu64 ", field_offsets[%u],base_offsets[%u], vbase_offsets[%u]) success = %i", | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7960 | record_decl, | 
|  | 7961 | bit_size, | 
|  | 7962 | alignment, | 
|  | 7963 | (uint32_t)field_offsets.size(), | 
|  | 7964 | (uint32_t)base_offsets.size(), | 
|  | 7965 | (uint32_t)vbase_offsets.size(), | 
|  | 7966 | success); | 
|  | 7967 | return success; | 
|  | 7968 | } | 
|  | 7969 |  | 
|  | 7970 |  | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 7971 | SymbolFileDWARFDebugMap * | 
|  | 7972 | SymbolFileDWARF::GetDebugMapSymfile () | 
|  | 7973 | { | 
|  | 7974 | if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired()) | 
|  | 7975 | { | 
|  | 7976 | lldb::ModuleSP module_sp (m_debug_map_module_wp.lock()); | 
|  | 7977 | if (module_sp) | 
|  | 7978 | { | 
|  | 7979 | SymbolVendor *sym_vendor = module_sp->GetSymbolVendor(); | 
|  | 7980 | if (sym_vendor) | 
|  | 7981 | m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile(); | 
|  | 7982 | } | 
|  | 7983 | } | 
|  | 7984 | return m_debug_map_symfile; | 
|  | 7985 | } | 
|  | 7986 |  | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7987 |  |