| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- SymbolFileDWARF.cpp ------------------------------------*- C++ -*-===// | 
|  | 2 | // | 
|  | 3 | //                     The LLVM Compiler Infrastructure | 
|  | 4 | // | 
|  | 5 | // This file is distributed under the University of Illinois Open Source | 
|  | 6 | // License. See LICENSE.TXT for details. | 
|  | 7 | // | 
|  | 8 | //===----------------------------------------------------------------------===// | 
|  | 9 |  | 
|  | 10 | #include "SymbolFileDWARF.h" | 
|  | 11 |  | 
|  | 12 | // Other libraries and framework includes | 
|  | 13 | #include "clang/AST/ASTConsumer.h" | 
|  | 14 | #include "clang/AST/ASTContext.h" | 
|  | 15 | #include "clang/AST/Decl.h" | 
|  | 16 | #include "clang/AST/DeclGroup.h" | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclObjC.h" | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclTemplate.h" | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | #include "clang/Basic/Builtins.h" | 
|  | 20 | #include "clang/Basic/IdentifierTable.h" | 
|  | 21 | #include "clang/Basic/LangOptions.h" | 
|  | 22 | #include "clang/Basic/SourceManager.h" | 
|  | 23 | #include "clang/Basic/TargetInfo.h" | 
|  | 24 | #include "clang/Basic/Specifiers.h" | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 25 | #include "clang/Sema/DeclSpec.h" | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 26 |  | 
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 27 | #include "llvm/Support/Casting.h" | 
|  | 28 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | #include "lldb/Core/Module.h" | 
|  | 30 | #include "lldb/Core/PluginManager.h" | 
|  | 31 | #include "lldb/Core/RegularExpression.h" | 
|  | 32 | #include "lldb/Core/Scalar.h" | 
|  | 33 | #include "lldb/Core/Section.h" | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 34 | #include "lldb/Core/StreamFile.h" | 
| Jim Ingham | 318c9f2 | 2011-08-26 19:44:13 +0000 | [diff] [blame] | 35 | #include "lldb/Core/StreamString.h" | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 36 | #include "lldb/Core/Timer.h" | 
|  | 37 | #include "lldb/Core/Value.h" | 
|  | 38 |  | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 39 | #include "lldb/Host/Host.h" | 
|  | 40 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 41 | #include "lldb/Symbol/Block.h" | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 42 | #include "lldb/Symbol/ClangExternalASTSourceCallbacks.h" | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | #include "lldb/Symbol/CompileUnit.h" | 
|  | 44 | #include "lldb/Symbol/LineTable.h" | 
|  | 45 | #include "lldb/Symbol/ObjectFile.h" | 
|  | 46 | #include "lldb/Symbol/SymbolVendor.h" | 
|  | 47 | #include "lldb/Symbol/VariableList.h" | 
|  | 48 |  | 
| Jim Ingham | b7f6b2f | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 49 | #include "lldb/Target/ObjCLanguageRuntime.h" | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 50 | #include "lldb/Target/CPPLanguageRuntime.h" | 
| Jim Ingham | b7f6b2f | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 51 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 52 | #include "DWARFCompileUnit.h" | 
|  | 53 | #include "DWARFDebugAbbrev.h" | 
|  | 54 | #include "DWARFDebugAranges.h" | 
|  | 55 | #include "DWARFDebugInfo.h" | 
|  | 56 | #include "DWARFDebugInfoEntry.h" | 
|  | 57 | #include "DWARFDebugLine.h" | 
|  | 58 | #include "DWARFDebugPubnames.h" | 
|  | 59 | #include "DWARFDebugRanges.h" | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 60 | #include "DWARFDeclContext.h" | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 61 | #include "DWARFDIECollection.h" | 
|  | 62 | #include "DWARFFormValue.h" | 
|  | 63 | #include "DWARFLocationList.h" | 
|  | 64 | #include "LogChannelDWARF.h" | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 65 | #include "SymbolFileDWARFDebugMap.h" | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 66 |  | 
|  | 67 | #include <map> | 
|  | 68 |  | 
| Matthew Gardiner | e81df3b | 2014-08-26 06:57:23 +0000 | [diff] [blame] | 69 | #include <ctype.h> | 
|  | 70 | #include <string.h> | 
|  | 71 |  | 
| Greg Clayton | 62742b1 | 2010-11-11 01:09:45 +0000 | [diff] [blame] | 72 | //#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 73 |  | 
|  | 74 | #ifdef ENABLE_DEBUG_PRINTF | 
|  | 75 | #include <stdio.h> | 
| Ed Maste | a0191d1 | 2013-10-17 20:42:56 +0000 | [diff] [blame] | 76 | #define DEBUG_PRINTF(fmt, ...) printf(fmt, __VA_ARGS__) | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 77 | #else | 
|  | 78 | #define DEBUG_PRINTF(fmt, ...) | 
|  | 79 | #endif | 
|  | 80 |  | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 81 | #define DIE_IS_BEING_PARSED ((lldb_private::Type*)1) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 82 |  | 
|  | 83 | using namespace lldb; | 
|  | 84 | using namespace lldb_private; | 
|  | 85 |  | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 86 | //static inline bool | 
|  | 87 | //child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag) | 
|  | 88 | //{ | 
|  | 89 | //    switch (tag) | 
|  | 90 | //    { | 
|  | 91 | //    default: | 
|  | 92 | //        break; | 
|  | 93 | //    case DW_TAG_subprogram: | 
|  | 94 | //    case DW_TAG_inlined_subroutine: | 
|  | 95 | //    case DW_TAG_class_type: | 
|  | 96 | //    case DW_TAG_structure_type: | 
|  | 97 | //    case DW_TAG_union_type: | 
|  | 98 | //        return true; | 
|  | 99 | //    } | 
|  | 100 | //    return false; | 
|  | 101 | //} | 
|  | 102 | // | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 103 | static AccessType | 
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 104 | DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 105 | { | 
|  | 106 | switch (dwarf_accessibility) | 
|  | 107 | { | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 108 | case DW_ACCESS_public:      return eAccessPublic; | 
|  | 109 | case DW_ACCESS_private:     return eAccessPrivate; | 
|  | 110 | case DW_ACCESS_protected:   return eAccessProtected; | 
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 111 | default:                    break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 112 | } | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 113 | return eAccessNone; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 114 | } | 
|  | 115 |  | 
| Matthew Gardiner | e81df3b | 2014-08-26 06:57:23 +0000 | [diff] [blame] | 116 | static const char* | 
|  | 117 | removeHostnameFromPathname(const char* path_from_dwarf) | 
|  | 118 | { | 
|  | 119 | if (!path_from_dwarf || !path_from_dwarf[0]) | 
|  | 120 | { | 
|  | 121 | return path_from_dwarf; | 
|  | 122 | } | 
|  | 123 |  | 
|  | 124 | const char *colon_pos = strchr(path_from_dwarf, ':'); | 
|  | 125 | if (!colon_pos) | 
|  | 126 | { | 
|  | 127 | return path_from_dwarf; | 
|  | 128 | } | 
|  | 129 |  | 
|  | 130 | // check whether we have a windows path, and so the first character | 
|  | 131 | // is a drive-letter not a hostname. | 
|  | 132 | if ( | 
|  | 133 | colon_pos == path_from_dwarf + 1 && | 
|  | 134 | isalpha(*path_from_dwarf) && | 
|  | 135 | strlen(path_from_dwarf) > 2 && | 
|  | 136 | '\\' == path_from_dwarf[2]) | 
|  | 137 | { | 
|  | 138 | return path_from_dwarf; | 
|  | 139 | } | 
|  | 140 |  | 
|  | 141 | return colon_pos + 1; | 
|  | 142 | } | 
|  | 143 |  | 
| Todd Fiala | 0a70a84 | 2014-05-28 16:43:26 +0000 | [diff] [blame] | 144 | #if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE) | 
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 145 |  | 
|  | 146 | class DIEStack | 
|  | 147 | { | 
|  | 148 | public: | 
|  | 149 |  | 
|  | 150 | void Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) | 
|  | 151 | { | 
|  | 152 | m_dies.push_back (DIEInfo(cu, die)); | 
|  | 153 | } | 
|  | 154 |  | 
|  | 155 |  | 
|  | 156 | void LogDIEs (Log *log, SymbolFileDWARF *dwarf) | 
|  | 157 | { | 
|  | 158 | StreamString log_strm; | 
|  | 159 | const size_t n = m_dies.size(); | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 160 | log_strm.Printf("DIEStack[%" PRIu64 "]:\n", (uint64_t)n); | 
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 161 | for (size_t i=0; i<n; i++) | 
|  | 162 | { | 
|  | 163 | DWARFCompileUnit *cu = m_dies[i].cu; | 
|  | 164 | const DWARFDebugInfoEntry *die = m_dies[i].die; | 
|  | 165 | std::string qualified_name; | 
|  | 166 | die->GetQualifiedName(dwarf, cu, qualified_name); | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 167 | log_strm.Printf ("[%" PRIu64 "] 0x%8.8x: %s name='%s'\n", | 
| Greg Clayton | 43e0af0 | 2012-09-18 18:04:04 +0000 | [diff] [blame] | 168 | (uint64_t)i, | 
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 169 | die->GetOffset(), | 
|  | 170 | DW_TAG_value_to_name(die->Tag()), | 
|  | 171 | qualified_name.c_str()); | 
|  | 172 | } | 
|  | 173 | log->PutCString(log_strm.GetData()); | 
|  | 174 | } | 
|  | 175 | void Pop () | 
|  | 176 | { | 
|  | 177 | m_dies.pop_back(); | 
|  | 178 | } | 
|  | 179 |  | 
|  | 180 | class ScopedPopper | 
|  | 181 | { | 
|  | 182 | public: | 
|  | 183 | ScopedPopper (DIEStack &die_stack) : | 
|  | 184 | m_die_stack (die_stack), | 
|  | 185 | m_valid (false) | 
|  | 186 | { | 
|  | 187 | } | 
|  | 188 |  | 
|  | 189 | void | 
|  | 190 | Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) | 
|  | 191 | { | 
|  | 192 | m_valid = true; | 
|  | 193 | m_die_stack.Push (cu, die); | 
|  | 194 | } | 
|  | 195 |  | 
|  | 196 | ~ScopedPopper () | 
|  | 197 | { | 
|  | 198 | if (m_valid) | 
|  | 199 | m_die_stack.Pop(); | 
|  | 200 | } | 
|  | 201 |  | 
|  | 202 |  | 
|  | 203 |  | 
|  | 204 | protected: | 
|  | 205 | DIEStack &m_die_stack; | 
|  | 206 | bool m_valid; | 
|  | 207 | }; | 
|  | 208 |  | 
|  | 209 | protected: | 
|  | 210 | struct DIEInfo { | 
|  | 211 | DIEInfo (DWARFCompileUnit *c, const DWARFDebugInfoEntry *d) : | 
|  | 212 | cu(c), | 
|  | 213 | die(d) | 
|  | 214 | { | 
|  | 215 | } | 
|  | 216 | DWARFCompileUnit *cu; | 
|  | 217 | const DWARFDebugInfoEntry *die; | 
|  | 218 | }; | 
|  | 219 | typedef std::vector<DIEInfo> Stack; | 
|  | 220 | Stack m_dies; | 
|  | 221 | }; | 
|  | 222 | #endif | 
|  | 223 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 224 | void | 
|  | 225 | SymbolFileDWARF::Initialize() | 
|  | 226 | { | 
|  | 227 | LogChannelDWARF::Initialize(); | 
|  | 228 | PluginManager::RegisterPlugin (GetPluginNameStatic(), | 
|  | 229 | GetPluginDescriptionStatic(), | 
|  | 230 | CreateInstance); | 
|  | 231 | } | 
|  | 232 |  | 
|  | 233 | void | 
|  | 234 | SymbolFileDWARF::Terminate() | 
|  | 235 | { | 
|  | 236 | PluginManager::UnregisterPlugin (CreateInstance); | 
|  | 237 | LogChannelDWARF::Initialize(); | 
|  | 238 | } | 
|  | 239 |  | 
|  | 240 |  | 
| Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 241 | lldb_private::ConstString | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 242 | SymbolFileDWARF::GetPluginNameStatic() | 
|  | 243 | { | 
| Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 244 | static ConstString g_name("dwarf"); | 
|  | 245 | return g_name; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 246 | } | 
|  | 247 |  | 
|  | 248 | const char * | 
|  | 249 | SymbolFileDWARF::GetPluginDescriptionStatic() | 
|  | 250 | { | 
|  | 251 | return "DWARF and DWARF3 debug symbol file reader."; | 
|  | 252 | } | 
|  | 253 |  | 
|  | 254 |  | 
|  | 255 | SymbolFile* | 
|  | 256 | SymbolFileDWARF::CreateInstance (ObjectFile* obj_file) | 
|  | 257 | { | 
|  | 258 | return new SymbolFileDWARF(obj_file); | 
|  | 259 | } | 
|  | 260 |  | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 261 | TypeList * | 
|  | 262 | SymbolFileDWARF::GetTypeList () | 
|  | 263 | { | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 264 | if (GetDebugMapSymfile ()) | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 265 | return m_debug_map_symfile->GetTypeList(); | 
|  | 266 | return m_obj_file->GetModule()->GetTypeList(); | 
|  | 267 |  | 
|  | 268 | } | 
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 269 | void | 
|  | 270 | SymbolFileDWARF::GetTypes (DWARFCompileUnit* cu, | 
|  | 271 | const DWARFDebugInfoEntry *die, | 
|  | 272 | dw_offset_t min_die_offset, | 
|  | 273 | dw_offset_t max_die_offset, | 
|  | 274 | uint32_t type_mask, | 
|  | 275 | TypeSet &type_set) | 
|  | 276 | { | 
|  | 277 | if (cu) | 
|  | 278 | { | 
|  | 279 | if (die) | 
|  | 280 | { | 
|  | 281 | const dw_offset_t die_offset = die->GetOffset(); | 
|  | 282 |  | 
|  | 283 | if (die_offset >= max_die_offset) | 
|  | 284 | return; | 
|  | 285 |  | 
|  | 286 | if (die_offset >= min_die_offset) | 
|  | 287 | { | 
|  | 288 | const dw_tag_t tag = die->Tag(); | 
|  | 289 |  | 
|  | 290 | bool add_type = false; | 
|  | 291 |  | 
|  | 292 | switch (tag) | 
|  | 293 | { | 
|  | 294 | case DW_TAG_array_type:         add_type = (type_mask & eTypeClassArray         ) != 0; break; | 
|  | 295 | case DW_TAG_unspecified_type: | 
|  | 296 | case DW_TAG_base_type:          add_type = (type_mask & eTypeClassBuiltin       ) != 0; break; | 
|  | 297 | case DW_TAG_class_type:         add_type = (type_mask & eTypeClassClass         ) != 0; break; | 
|  | 298 | case DW_TAG_structure_type:     add_type = (type_mask & eTypeClassStruct        ) != 0; break; | 
|  | 299 | case DW_TAG_union_type:         add_type = (type_mask & eTypeClassUnion         ) != 0; break; | 
|  | 300 | case DW_TAG_enumeration_type:   add_type = (type_mask & eTypeClassEnumeration   ) != 0; break; | 
|  | 301 | case DW_TAG_subroutine_type: | 
|  | 302 | case DW_TAG_subprogram: | 
|  | 303 | case DW_TAG_inlined_subroutine: add_type = (type_mask & eTypeClassFunction      ) != 0; break; | 
|  | 304 | case DW_TAG_pointer_type:       add_type = (type_mask & eTypeClassPointer       ) != 0; break; | 
|  | 305 | case DW_TAG_rvalue_reference_type: | 
|  | 306 | case DW_TAG_reference_type:     add_type = (type_mask & eTypeClassReference     ) != 0; break; | 
|  | 307 | case DW_TAG_typedef:            add_type = (type_mask & eTypeClassTypedef       ) != 0; break; | 
|  | 308 | case DW_TAG_ptr_to_member_type: add_type = (type_mask & eTypeClassMemberPointer ) != 0; break; | 
|  | 309 | } | 
|  | 310 |  | 
|  | 311 | if (add_type) | 
|  | 312 | { | 
|  | 313 | const bool assert_not_being_parsed = true; | 
|  | 314 | Type *type = ResolveTypeUID (cu, die, assert_not_being_parsed); | 
|  | 315 | if (type) | 
|  | 316 | { | 
|  | 317 | if (type_set.find(type) == type_set.end()) | 
|  | 318 | type_set.insert(type); | 
|  | 319 | } | 
|  | 320 | } | 
|  | 321 | } | 
|  | 322 |  | 
|  | 323 | for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); | 
|  | 324 | child_die != NULL; | 
|  | 325 | child_die = child_die->GetSibling()) | 
|  | 326 | { | 
|  | 327 | GetTypes (cu, child_die, min_die_offset, max_die_offset, type_mask, type_set); | 
|  | 328 | } | 
|  | 329 | } | 
|  | 330 | } | 
|  | 331 | } | 
|  | 332 |  | 
|  | 333 | size_t | 
|  | 334 | SymbolFileDWARF::GetTypes (SymbolContextScope *sc_scope, | 
|  | 335 | uint32_t type_mask, | 
|  | 336 | TypeList &type_list) | 
|  | 337 |  | 
|  | 338 | { | 
|  | 339 | TypeSet type_set; | 
|  | 340 |  | 
|  | 341 | CompileUnit *comp_unit = NULL; | 
|  | 342 | DWARFCompileUnit* dwarf_cu = NULL; | 
|  | 343 | if (sc_scope) | 
|  | 344 | comp_unit = sc_scope->CalculateSymbolContextCompileUnit(); | 
|  | 345 |  | 
|  | 346 | if (comp_unit) | 
|  | 347 | { | 
|  | 348 | dwarf_cu = GetDWARFCompileUnit(comp_unit); | 
|  | 349 | if (dwarf_cu == 0) | 
|  | 350 | return 0; | 
|  | 351 | GetTypes (dwarf_cu, | 
|  | 352 | dwarf_cu->DIE(), | 
|  | 353 | dwarf_cu->GetOffset(), | 
|  | 354 | dwarf_cu->GetNextCompileUnitOffset(), | 
|  | 355 | type_mask, | 
|  | 356 | type_set); | 
|  | 357 | } | 
|  | 358 | else | 
|  | 359 | { | 
|  | 360 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 361 | if (info) | 
|  | 362 | { | 
|  | 363 | const size_t num_cus = info->GetNumCompileUnits(); | 
|  | 364 | for (size_t cu_idx=0; cu_idx<num_cus; ++cu_idx) | 
|  | 365 | { | 
|  | 366 | dwarf_cu = info->GetCompileUnitAtIndex(cu_idx); | 
|  | 367 | if (dwarf_cu) | 
|  | 368 | { | 
|  | 369 | GetTypes (dwarf_cu, | 
|  | 370 | dwarf_cu->DIE(), | 
|  | 371 | 0, | 
|  | 372 | UINT32_MAX, | 
|  | 373 | type_mask, | 
|  | 374 | type_set); | 
|  | 375 | } | 
|  | 376 | } | 
|  | 377 | } | 
|  | 378 | } | 
|  | 379 | //    if (m_using_apple_tables) | 
|  | 380 | //    { | 
|  | 381 | //        DWARFMappedHash::MemoryTable *apple_types = m_apple_types_ap.get(); | 
|  | 382 | //        if (apple_types) | 
|  | 383 | //        { | 
|  | 384 | //            apple_types->ForEach([this, &type_set, apple_types, type_mask](const DWARFMappedHash::DIEInfoArray &die_info_array) -> bool { | 
|  | 385 | // | 
|  | 386 | //                for (auto die_info: die_info_array) | 
|  | 387 | //                { | 
|  | 388 | //                    bool add_type = TagMatchesTypeMask (type_mask, 0); | 
|  | 389 | //                    if (!add_type) | 
|  | 390 | //                    { | 
|  | 391 | //                        dw_tag_t tag = die_info.tag; | 
|  | 392 | //                        if (tag == 0) | 
|  | 393 | //                        { | 
|  | 394 | //                            const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_info.offset, NULL); | 
|  | 395 | //                            tag = die->Tag(); | 
|  | 396 | //                        } | 
|  | 397 | //                        add_type = TagMatchesTypeMask (type_mask, tag); | 
|  | 398 | //                    } | 
|  | 399 | //                    if (add_type) | 
|  | 400 | //                    { | 
|  | 401 | //                        Type *type = ResolveTypeUID(die_info.offset); | 
|  | 402 | // | 
|  | 403 | //                        if (type_set.find(type) == type_set.end()) | 
|  | 404 | //                            type_set.insert(type); | 
|  | 405 | //                    } | 
|  | 406 | //                } | 
|  | 407 | //                return true; // Keep iterating | 
|  | 408 | //            }); | 
|  | 409 | //        } | 
|  | 410 | //    } | 
|  | 411 | //    else | 
|  | 412 | //    { | 
|  | 413 | //        if (!m_indexed) | 
|  | 414 | //            Index (); | 
|  | 415 | // | 
|  | 416 | //        m_type_index.ForEach([this, &type_set, type_mask](const char *name, uint32_t die_offset) -> bool { | 
|  | 417 | // | 
|  | 418 | //            bool add_type = TagMatchesTypeMask (type_mask, 0); | 
|  | 419 | // | 
|  | 420 | //            if (!add_type) | 
|  | 421 | //            { | 
|  | 422 | //                const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_offset, NULL); | 
|  | 423 | //                if (die) | 
|  | 424 | //                { | 
|  | 425 | //                    const dw_tag_t tag = die->Tag(); | 
|  | 426 | //                    add_type = TagMatchesTypeMask (type_mask, tag); | 
|  | 427 | //                } | 
|  | 428 | //            } | 
|  | 429 | // | 
|  | 430 | //            if (add_type) | 
|  | 431 | //            { | 
|  | 432 | //                Type *type = ResolveTypeUID(die_offset); | 
|  | 433 | // | 
|  | 434 | //                if (type_set.find(type) == type_set.end()) | 
|  | 435 | //                    type_set.insert(type); | 
|  | 436 | //            } | 
|  | 437 | //            return true; // Keep iterating | 
|  | 438 | //        }); | 
|  | 439 | //    } | 
|  | 440 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 441 | std::set<ClangASTType> clang_type_set; | 
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 442 | size_t num_types_added = 0; | 
|  | 443 | for (Type *type : type_set) | 
|  | 444 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 445 | ClangASTType clang_type = type->GetClangForwardType(); | 
| Greg Clayton | 0fc4f31 | 2013-06-20 01:23:18 +0000 | [diff] [blame] | 446 | if (clang_type_set.find(clang_type) == clang_type_set.end()) | 
|  | 447 | { | 
|  | 448 | clang_type_set.insert(clang_type); | 
|  | 449 | type_list.Insert (type->shared_from_this()); | 
|  | 450 | ++num_types_added; | 
|  | 451 | } | 
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 452 | } | 
|  | 453 | return num_types_added; | 
|  | 454 | } | 
|  | 455 |  | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 456 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 457 | //---------------------------------------------------------------------- | 
|  | 458 | // Gets the first parent that is a lexical block, function or inlined | 
|  | 459 | // subroutine, or compile unit. | 
|  | 460 | //---------------------------------------------------------------------- | 
|  | 461 | static const DWARFDebugInfoEntry * | 
|  | 462 | GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die) | 
|  | 463 | { | 
|  | 464 | const DWARFDebugInfoEntry *die; | 
|  | 465 | for (die = child_die->GetParent(); die != NULL; die = die->GetParent()) | 
|  | 466 | { | 
|  | 467 | dw_tag_t tag = die->Tag(); | 
|  | 468 |  | 
|  | 469 | switch (tag) | 
|  | 470 | { | 
|  | 471 | case DW_TAG_compile_unit: | 
|  | 472 | case DW_TAG_subprogram: | 
|  | 473 | case DW_TAG_inlined_subroutine: | 
|  | 474 | case DW_TAG_lexical_block: | 
|  | 475 | return die; | 
|  | 476 | } | 
|  | 477 | } | 
|  | 478 | return NULL; | 
|  | 479 | } | 
|  | 480 |  | 
|  | 481 |  | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 482 | SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) : | 
|  | 483 | SymbolFile (objfile), | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 484 | UserID (0),  // Used by SymbolFileDWARFDebugMap to when this class parses .o files to contain the .o file index/ID | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 485 | m_debug_map_module_wp (), | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 486 | m_debug_map_symfile (NULL), | 
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 487 | m_clang_tu_decl (NULL), | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 488 | m_flags(), | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 489 | m_data_debug_abbrev (), | 
|  | 490 | m_data_debug_aranges (), | 
|  | 491 | m_data_debug_frame (), | 
|  | 492 | m_data_debug_info (), | 
|  | 493 | m_data_debug_line (), | 
|  | 494 | m_data_debug_loc (), | 
|  | 495 | m_data_debug_ranges (), | 
|  | 496 | m_data_debug_str (), | 
| Greg Clayton | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 497 | m_data_apple_names (), | 
|  | 498 | m_data_apple_types (), | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 499 | m_data_apple_namespaces (), | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 500 | m_abbr(), | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 501 | m_info(), | 
|  | 502 | m_line(), | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 503 | m_apple_names_ap (), | 
|  | 504 | m_apple_types_ap (), | 
|  | 505 | m_apple_namespaces_ap (), | 
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 506 | m_apple_objc_ap (), | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 507 | m_function_basename_index(), | 
|  | 508 | m_function_fullname_index(), | 
|  | 509 | m_function_method_index(), | 
|  | 510 | m_function_selector_index(), | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 511 | m_objc_class_selectors_index(), | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 512 | m_global_index(), | 
| Greg Clayton | 69b0488 | 2010-10-15 02:03:22 +0000 | [diff] [blame] | 513 | m_type_index(), | 
|  | 514 | m_namespace_index(), | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 515 | m_indexed (false), | 
|  | 516 | m_is_external_ast_source (false), | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 517 | m_using_apple_tables (false), | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 518 | m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate), | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 519 | m_ranges(), | 
|  | 520 | m_unique_ast_type_map () | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 521 | { | 
|  | 522 | } | 
|  | 523 |  | 
|  | 524 | SymbolFileDWARF::~SymbolFileDWARF() | 
|  | 525 | { | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 526 | if (m_is_external_ast_source) | 
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 527 | { | 
|  | 528 | ModuleSP module_sp (m_obj_file->GetModule()); | 
|  | 529 | if (module_sp) | 
|  | 530 | module_sp->GetClangASTContext().RemoveExternalSource (); | 
|  | 531 | } | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 532 | } | 
|  | 533 |  | 
|  | 534 | static const ConstString & | 
|  | 535 | GetDWARFMachOSegmentName () | 
|  | 536 | { | 
|  | 537 | static ConstString g_dwarf_section_name ("__DWARF"); | 
|  | 538 | return g_dwarf_section_name; | 
|  | 539 | } | 
|  | 540 |  | 
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 541 | UniqueDWARFASTTypeMap & | 
|  | 542 | SymbolFileDWARF::GetUniqueDWARFASTTypeMap () | 
|  | 543 | { | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 544 | if (GetDebugMapSymfile ()) | 
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 545 | return m_debug_map_symfile->GetUniqueDWARFASTTypeMap (); | 
|  | 546 | return m_unique_ast_type_map; | 
|  | 547 | } | 
|  | 548 |  | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 549 | ClangASTContext & | 
|  | 550 | SymbolFileDWARF::GetClangASTContext () | 
|  | 551 | { | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 552 | if (GetDebugMapSymfile ()) | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 553 | return m_debug_map_symfile->GetClangASTContext (); | 
|  | 554 |  | 
|  | 555 | ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext(); | 
|  | 556 | if (!m_is_external_ast_source) | 
|  | 557 | { | 
|  | 558 | m_is_external_ast_source = true; | 
| Todd Fiala | 955fe6f | 2014-02-27 17:18:23 +0000 | [diff] [blame] | 559 | llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> ast_source_ap ( | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 560 | new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl, | 
|  | 561 | SymbolFileDWARF::CompleteObjCInterfaceDecl, | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 562 | SymbolFileDWARF::FindExternalVisibleDeclsByName, | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 563 | SymbolFileDWARF::LayoutRecordType, | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 564 | this)); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 565 | ast.SetExternalSource (ast_source_ap); | 
|  | 566 | } | 
|  | 567 | return ast; | 
|  | 568 | } | 
|  | 569 |  | 
|  | 570 | void | 
|  | 571 | SymbolFileDWARF::InitializeObject() | 
|  | 572 | { | 
|  | 573 | // Install our external AST source callbacks so we can complete Clang types. | 
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 574 | ModuleSP module_sp (m_obj_file->GetModule()); | 
|  | 575 | if (module_sp) | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 576 | { | 
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 577 | const SectionList *section_list = module_sp->GetSectionList(); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 578 |  | 
|  | 579 | const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get(); | 
|  | 580 |  | 
|  | 581 | // Memory map the DWARF mach-o segment so we have everything mmap'ed | 
|  | 582 | // to keep our heap memory usage down. | 
|  | 583 | if (section) | 
| Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 584 | m_obj_file->MemoryMapSectionData(section, m_dwarf_data); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 585 | } | 
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 586 | get_apple_names_data(); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 587 | if (m_data_apple_names.GetByteSize() > 0) | 
|  | 588 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 589 | m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names")); | 
|  | 590 | if (m_apple_names_ap->IsValid()) | 
|  | 591 | m_using_apple_tables = true; | 
|  | 592 | else | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 593 | m_apple_names_ap.reset(); | 
|  | 594 | } | 
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 595 | get_apple_types_data(); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 596 | if (m_data_apple_types.GetByteSize() > 0) | 
|  | 597 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 598 | m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types")); | 
|  | 599 | if (m_apple_types_ap->IsValid()) | 
|  | 600 | m_using_apple_tables = true; | 
|  | 601 | else | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 602 | m_apple_types_ap.reset(); | 
|  | 603 | } | 
|  | 604 |  | 
|  | 605 | get_apple_namespaces_data(); | 
|  | 606 | if (m_data_apple_namespaces.GetByteSize() > 0) | 
|  | 607 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 608 | m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces")); | 
|  | 609 | if (m_apple_namespaces_ap->IsValid()) | 
|  | 610 | m_using_apple_tables = true; | 
|  | 611 | else | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 612 | m_apple_namespaces_ap.reset(); | 
|  | 613 | } | 
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 614 |  | 
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 615 | get_apple_objc_data(); | 
|  | 616 | if (m_data_apple_objc.GetByteSize() > 0) | 
|  | 617 | { | 
|  | 618 | m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc")); | 
|  | 619 | if (m_apple_objc_ap->IsValid()) | 
|  | 620 | m_using_apple_tables = true; | 
|  | 621 | else | 
|  | 622 | m_apple_objc_ap.reset(); | 
|  | 623 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 624 | } | 
|  | 625 |  | 
|  | 626 | bool | 
|  | 627 | SymbolFileDWARF::SupportedVersion(uint16_t version) | 
|  | 628 | { | 
| Greg Clayton | abcbfe5 | 2013-04-04 00:00:36 +0000 | [diff] [blame] | 629 | return version == 2 || version == 3 || version == 4; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 630 | } | 
|  | 631 |  | 
|  | 632 | uint32_t | 
| Sean Callanan | bfaf54d | 2011-12-03 04:38:43 +0000 | [diff] [blame] | 633 | SymbolFileDWARF::CalculateAbilities () | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 634 | { | 
|  | 635 | uint32_t abilities = 0; | 
|  | 636 | if (m_obj_file != NULL) | 
|  | 637 | { | 
|  | 638 | const Section* section = NULL; | 
|  | 639 | const SectionList *section_list = m_obj_file->GetSectionList(); | 
|  | 640 | if (section_list == NULL) | 
|  | 641 | return 0; | 
|  | 642 |  | 
|  | 643 | uint64_t debug_abbrev_file_size = 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 644 | uint64_t debug_info_file_size = 0; | 
|  | 645 | uint64_t debug_line_file_size = 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 646 |  | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 647 | section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 648 |  | 
|  | 649 | if (section) | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 650 | section_list = §ion->GetChildren (); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 651 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 652 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 653 | if (section != NULL) | 
|  | 654 | { | 
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 655 | debug_info_file_size = section->GetFileSize(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 656 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 657 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 658 | if (section) | 
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 659 | debug_abbrev_file_size = section->GetFileSize(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 660 | else | 
|  | 661 | m_flags.Set (flagsGotDebugAbbrevData); | 
|  | 662 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 663 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get(); | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 664 | if (!section) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 665 | m_flags.Set (flagsGotDebugArangesData); | 
|  | 666 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 667 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get(); | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 668 | if (!section) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 669 | m_flags.Set (flagsGotDebugFrameData); | 
|  | 670 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 671 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 672 | if (section) | 
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 673 | debug_line_file_size = section->GetFileSize(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 674 | else | 
|  | 675 | m_flags.Set (flagsGotDebugLineData); | 
|  | 676 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 677 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get(); | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 678 | if (!section) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 679 | m_flags.Set (flagsGotDebugLocData); | 
|  | 680 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 681 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get(); | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 682 | if (!section) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 683 | m_flags.Set (flagsGotDebugMacInfoData); | 
|  | 684 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 685 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get(); | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 686 | if (!section) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 687 | m_flags.Set (flagsGotDebugPubNamesData); | 
|  | 688 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 689 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get(); | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 690 | if (!section) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 691 | m_flags.Set (flagsGotDebugPubTypesData); | 
|  | 692 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 693 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get(); | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 694 | if (!section) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 695 | m_flags.Set (flagsGotDebugRangesData); | 
|  | 696 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 697 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get(); | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 698 | if (!section) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 699 | m_flags.Set (flagsGotDebugStrData); | 
|  | 700 | } | 
| Greg Clayton | 6c59661 | 2012-05-18 21:47:20 +0000 | [diff] [blame] | 701 | else | 
|  | 702 | { | 
|  | 703 | const char *symfile_dir_cstr = m_obj_file->GetFileSpec().GetDirectory().GetCString(); | 
|  | 704 | if (symfile_dir_cstr) | 
|  | 705 | { | 
|  | 706 | if (strcasestr(symfile_dir_cstr, ".dsym")) | 
|  | 707 | { | 
|  | 708 | if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo) | 
|  | 709 | { | 
|  | 710 | // We have a dSYM file that didn't have a any debug info. | 
|  | 711 | // If the string table has a size of 1, then it was made from | 
|  | 712 | // an executable with no debug info, or from an executable that | 
|  | 713 | // was stripped. | 
|  | 714 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get(); | 
|  | 715 | if (section && section->GetFileSize() == 1) | 
|  | 716 | { | 
|  | 717 | m_obj_file->GetModule()->ReportWarning ("empty dSYM file detected, dSYM was created with an executable with no debug info."); | 
|  | 718 | } | 
|  | 719 | } | 
|  | 720 | } | 
|  | 721 | } | 
|  | 722 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 723 |  | 
|  | 724 | if (debug_abbrev_file_size > 0 && debug_info_file_size > 0) | 
|  | 725 | abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes; | 
|  | 726 |  | 
|  | 727 | if (debug_line_file_size > 0) | 
|  | 728 | abilities |= LineTables; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 729 | } | 
|  | 730 | return abilities; | 
|  | 731 | } | 
|  | 732 |  | 
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 733 | const DWARFDataExtractor& | 
|  | 734 | SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DWARFDataExtractor &data) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 735 | { | 
|  | 736 | if (m_flags.IsClear (got_flag)) | 
|  | 737 | { | 
| Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 738 | ModuleSP module_sp (m_obj_file->GetModule()); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 739 | m_flags.Set (got_flag); | 
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 740 | const SectionList *section_list = module_sp->GetSectionList(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 741 | if (section_list) | 
|  | 742 | { | 
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 743 | SectionSP section_sp (section_list->FindSectionByType(sect_type, true)); | 
|  | 744 | if (section_sp) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 745 | { | 
|  | 746 | // See if we memory mapped the DWARF segment? | 
|  | 747 | if (m_dwarf_data.GetByteSize()) | 
|  | 748 | { | 
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 749 | data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetFileSize()); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 750 | } | 
|  | 751 | else | 
|  | 752 | { | 
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 753 | if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 754 | data.Clear(); | 
|  | 755 | } | 
|  | 756 | } | 
|  | 757 | } | 
|  | 758 | } | 
|  | 759 | return data; | 
|  | 760 | } | 
|  | 761 |  | 
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 762 | const DWARFDataExtractor& | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 763 | SymbolFileDWARF::get_debug_abbrev_data() | 
|  | 764 | { | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 765 | return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 766 | } | 
|  | 767 |  | 
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 768 | const DWARFDataExtractor& | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 769 | SymbolFileDWARF::get_debug_aranges_data() | 
|  | 770 | { | 
|  | 771 | return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges); | 
|  | 772 | } | 
|  | 773 |  | 
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 774 | const DWARFDataExtractor& | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 775 | SymbolFileDWARF::get_debug_frame_data() | 
|  | 776 | { | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 777 | return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 778 | } | 
|  | 779 |  | 
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 780 | const DWARFDataExtractor& | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 781 | SymbolFileDWARF::get_debug_info_data() | 
|  | 782 | { | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 783 | return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 784 | } | 
|  | 785 |  | 
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 786 | const DWARFDataExtractor& | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 787 | SymbolFileDWARF::get_debug_line_data() | 
|  | 788 | { | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 789 | return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 790 | } | 
|  | 791 |  | 
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 792 | const DWARFDataExtractor& | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 793 | SymbolFileDWARF::get_debug_loc_data() | 
|  | 794 | { | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 795 | return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 796 | } | 
|  | 797 |  | 
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 798 | const DWARFDataExtractor& | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 799 | SymbolFileDWARF::get_debug_ranges_data() | 
|  | 800 | { | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 801 | return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 802 | } | 
|  | 803 |  | 
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 804 | const DWARFDataExtractor& | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 805 | SymbolFileDWARF::get_debug_str_data() | 
|  | 806 | { | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 807 | return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 808 | } | 
|  | 809 |  | 
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 810 | const DWARFDataExtractor& | 
| Greg Clayton | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 811 | SymbolFileDWARF::get_apple_names_data() | 
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 812 | { | 
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 813 | return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names); | 
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 814 | } | 
|  | 815 |  | 
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 816 | const DWARFDataExtractor& | 
| Greg Clayton | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 817 | SymbolFileDWARF::get_apple_types_data() | 
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 818 | { | 
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 819 | return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types); | 
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 820 | } | 
|  | 821 |  | 
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 822 | const DWARFDataExtractor& | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 823 | SymbolFileDWARF::get_apple_namespaces_data() | 
|  | 824 | { | 
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 825 | return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces); | 
|  | 826 | } | 
|  | 827 |  | 
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 828 | const DWARFDataExtractor& | 
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 829 | SymbolFileDWARF::get_apple_objc_data() | 
|  | 830 | { | 
|  | 831 | return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 832 | } | 
|  | 833 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 834 |  | 
|  | 835 | DWARFDebugAbbrev* | 
|  | 836 | SymbolFileDWARF::DebugAbbrev() | 
|  | 837 | { | 
|  | 838 | if (m_abbr.get() == NULL) | 
|  | 839 | { | 
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 840 | const DWARFDataExtractor &debug_abbrev_data = get_debug_abbrev_data(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 841 | if (debug_abbrev_data.GetByteSize() > 0) | 
|  | 842 | { | 
|  | 843 | m_abbr.reset(new DWARFDebugAbbrev()); | 
|  | 844 | if (m_abbr.get()) | 
|  | 845 | m_abbr->Parse(debug_abbrev_data); | 
|  | 846 | } | 
|  | 847 | } | 
|  | 848 | return m_abbr.get(); | 
|  | 849 | } | 
|  | 850 |  | 
|  | 851 | const DWARFDebugAbbrev* | 
|  | 852 | SymbolFileDWARF::DebugAbbrev() const | 
|  | 853 | { | 
|  | 854 | return m_abbr.get(); | 
|  | 855 | } | 
|  | 856 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 857 |  | 
|  | 858 | DWARFDebugInfo* | 
|  | 859 | SymbolFileDWARF::DebugInfo() | 
|  | 860 | { | 
|  | 861 | if (m_info.get() == NULL) | 
|  | 862 | { | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 863 | Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", | 
|  | 864 | __PRETTY_FUNCTION__, static_cast<void*>(this)); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 865 | if (get_debug_info_data().GetByteSize() > 0) | 
|  | 866 | { | 
|  | 867 | m_info.reset(new DWARFDebugInfo()); | 
|  | 868 | if (m_info.get()) | 
|  | 869 | { | 
|  | 870 | m_info->SetDwarfData(this); | 
|  | 871 | } | 
|  | 872 | } | 
|  | 873 | } | 
|  | 874 | return m_info.get(); | 
|  | 875 | } | 
|  | 876 |  | 
|  | 877 | const DWARFDebugInfo* | 
|  | 878 | SymbolFileDWARF::DebugInfo() const | 
|  | 879 | { | 
|  | 880 | return m_info.get(); | 
|  | 881 | } | 
|  | 882 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 883 | DWARFCompileUnit* | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 884 | SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 885 | { | 
|  | 886 | DWARFDebugInfo* info = DebugInfo(); | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 887 | if (info) | 
|  | 888 | { | 
|  | 889 | if (GetDebugMapSymfile ()) | 
|  | 890 | { | 
|  | 891 | // The debug map symbol file made the compile units for this DWARF | 
|  | 892 | // file which is .o file with DWARF in it, and we should have | 
|  | 893 | // only 1 compile unit which is at offset zero in the DWARF. | 
|  | 894 | // TODO: modify to support LTO .o files where each .o file might | 
|  | 895 | // have multiple DW_TAG_compile_unit tags. | 
|  | 896 | return info->GetCompileUnit(0).get(); | 
|  | 897 | } | 
|  | 898 | else | 
|  | 899 | { | 
|  | 900 | // Just a normal DWARF file whose user ID for the compile unit is | 
|  | 901 | // the DWARF offset itself | 
|  | 902 | return info->GetCompileUnit((dw_offset_t)comp_unit->GetID()).get(); | 
|  | 903 | } | 
|  | 904 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 905 | return NULL; | 
|  | 906 | } | 
|  | 907 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 908 |  | 
|  | 909 | DWARFDebugRanges* | 
|  | 910 | SymbolFileDWARF::DebugRanges() | 
|  | 911 | { | 
|  | 912 | if (m_ranges.get() == NULL) | 
|  | 913 | { | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 914 | Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", | 
|  | 915 | __PRETTY_FUNCTION__, static_cast<void*>(this)); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 916 | if (get_debug_ranges_data().GetByteSize() > 0) | 
|  | 917 | { | 
|  | 918 | m_ranges.reset(new DWARFDebugRanges()); | 
|  | 919 | if (m_ranges.get()) | 
|  | 920 | m_ranges->Extract(this); | 
|  | 921 | } | 
|  | 922 | } | 
|  | 923 | return m_ranges.get(); | 
|  | 924 | } | 
|  | 925 |  | 
|  | 926 | const DWARFDebugRanges* | 
|  | 927 | SymbolFileDWARF::DebugRanges() const | 
|  | 928 | { | 
|  | 929 | return m_ranges.get(); | 
|  | 930 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 931 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 932 | lldb::CompUnitSP | 
|  | 933 | SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 934 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 935 | CompUnitSP cu_sp; | 
|  | 936 | if (dwarf_cu) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 937 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 938 | CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData(); | 
|  | 939 | if (comp_unit) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 940 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 941 | // We already parsed this compile unit, had out a shared pointer to it | 
|  | 942 | cu_sp = comp_unit->shared_from_this(); | 
|  | 943 | } | 
|  | 944 | else | 
|  | 945 | { | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 946 | if (GetDebugMapSymfile ()) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 947 | { | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 948 | // Let the debug map create the compile unit | 
|  | 949 | cu_sp = m_debug_map_symfile->GetCompileUnit(this); | 
|  | 950 | dwarf_cu->SetUserData(cu_sp.get()); | 
|  | 951 | } | 
|  | 952 | else | 
|  | 953 | { | 
|  | 954 | ModuleSP module_sp (m_obj_file->GetModule()); | 
|  | 955 | if (module_sp) | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 956 | { | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 957 | const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly (); | 
|  | 958 | if (cu_die) | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 959 | { | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 960 | const char * cu_die_name = cu_die->GetName(this, dwarf_cu); | 
|  | 961 | const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL); | 
|  | 962 | LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0); | 
|  | 963 | if (cu_die_name) | 
|  | 964 | { | 
|  | 965 | std::string ramapped_file; | 
|  | 966 | FileSpec cu_file_spec; | 
| Jim Ingham | 0909e5f | 2010-09-16 00:57:33 +0000 | [diff] [blame] | 967 |  | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 968 | if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0') | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 969 | { | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 970 | // If we have a full path to the compile unit, we don't need to resolve | 
|  | 971 | // the file.  This can be expensive e.g. when the source files are NFS mounted. | 
|  | 972 | if (module_sp->RemapSourceFile(cu_die_name, ramapped_file)) | 
|  | 973 | cu_file_spec.SetFile (ramapped_file.c_str(), false); | 
|  | 974 | else | 
|  | 975 | cu_file_spec.SetFile (cu_die_name, false); | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 976 | } | 
|  | 977 | else | 
|  | 978 | { | 
| Matthew Gardiner | e81df3b | 2014-08-26 06:57:23 +0000 | [diff] [blame] | 979 | // DWARF2/3 suggests the form hostname:pathname for compilation directory. | 
|  | 980 | // Remove the host part if present. | 
|  | 981 | cu_comp_dir = removeHostnameFromPathname(cu_comp_dir); | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 982 | std::string fullpath(cu_comp_dir); | 
| Matthew Gardiner | e81df3b | 2014-08-26 06:57:23 +0000 | [diff] [blame] | 983 |  | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 984 | if (*fullpath.rbegin() != '/') | 
|  | 985 | fullpath += '/'; | 
|  | 986 | fullpath += cu_die_name; | 
|  | 987 | if (module_sp->RemapSourceFile (fullpath.c_str(), ramapped_file)) | 
|  | 988 | cu_file_spec.SetFile (ramapped_file.c_str(), false); | 
|  | 989 | else | 
|  | 990 | cu_file_spec.SetFile (fullpath.c_str(), false); | 
|  | 991 | } | 
|  | 992 |  | 
|  | 993 | cu_sp.reset(new CompileUnit (module_sp, | 
|  | 994 | dwarf_cu, | 
|  | 995 | cu_file_spec, | 
|  | 996 | MakeUserID(dwarf_cu->GetOffset()), | 
|  | 997 | cu_language)); | 
|  | 998 | if (cu_sp) | 
|  | 999 | { | 
|  | 1000 | dwarf_cu->SetUserData(cu_sp.get()); | 
|  | 1001 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1002 | // Figure out the compile unit index if we weren't given one | 
|  | 1003 | if (cu_idx == UINT32_MAX) | 
|  | 1004 | DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx); | 
|  | 1005 |  | 
|  | 1006 | m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp); | 
|  | 1007 | } | 
|  | 1008 | } | 
|  | 1009 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1010 | } | 
|  | 1011 | } | 
|  | 1012 | } | 
|  | 1013 | } | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1014 | return cu_sp; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1015 | } | 
|  | 1016 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1017 | uint32_t | 
|  | 1018 | SymbolFileDWARF::GetNumCompileUnits() | 
|  | 1019 | { | 
|  | 1020 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 1021 | if (info) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1022 | return info->GetNumCompileUnits(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1023 | return 0; | 
|  | 1024 | } | 
|  | 1025 |  | 
|  | 1026 | CompUnitSP | 
|  | 1027 | SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx) | 
|  | 1028 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1029 | CompUnitSP cu_sp; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1030 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 1031 | if (info) | 
|  | 1032 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1033 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx); | 
|  | 1034 | if (dwarf_cu) | 
|  | 1035 | cu_sp = ParseCompileUnit(dwarf_cu, cu_idx); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1036 | } | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1037 | return cu_sp; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1038 | } | 
|  | 1039 |  | 
|  | 1040 | static void | 
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1041 | AddRangesToBlock (Block& block, | 
|  | 1042 | DWARFDebugRanges::RangeList& ranges, | 
|  | 1043 | addr_t block_base_addr) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1044 | { | 
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1045 | const size_t num_ranges = ranges.GetSize(); | 
|  | 1046 | for (size_t i = 0; i<num_ranges; ++i) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1047 | { | 
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1048 | const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i); | 
|  | 1049 | const addr_t range_base = range.GetRangeBase(); | 
|  | 1050 | assert (range_base >= block_base_addr); | 
|  | 1051 | block.AddRange(Block::Range (range_base - block_base_addr, range.GetByteSize()));; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1052 | } | 
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1053 | block.FinalizeRanges (); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1054 | } | 
|  | 1055 |  | 
|  | 1056 |  | 
|  | 1057 | Function * | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1058 | SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1059 | { | 
|  | 1060 | DWARFDebugRanges::RangeList func_ranges; | 
|  | 1061 | const char *name = NULL; | 
|  | 1062 | const char *mangled = NULL; | 
|  | 1063 | int decl_file = 0; | 
|  | 1064 | int decl_line = 0; | 
|  | 1065 | int decl_column = 0; | 
|  | 1066 | int call_file = 0; | 
|  | 1067 | int call_line = 0; | 
|  | 1068 | int call_column = 0; | 
|  | 1069 | DWARFExpression frame_base; | 
|  | 1070 |  | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1071 | assert (die->Tag() == DW_TAG_subprogram); | 
|  | 1072 |  | 
|  | 1073 | if (die->Tag() != DW_TAG_subprogram) | 
|  | 1074 | return NULL; | 
|  | 1075 |  | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1076 | if (die->GetDIENamesAndRanges (this, | 
|  | 1077 | dwarf_cu, | 
|  | 1078 | name, | 
|  | 1079 | mangled, | 
|  | 1080 | func_ranges, | 
|  | 1081 | decl_file, | 
|  | 1082 | decl_line, | 
|  | 1083 | decl_column, | 
|  | 1084 | call_file, | 
|  | 1085 | call_line, | 
|  | 1086 | call_column, | 
|  | 1087 | &frame_base)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1088 | { | 
|  | 1089 | // Union of all ranges in the function DIE (if the function is discontiguous) | 
|  | 1090 | AddressRange func_range; | 
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1091 | lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0); | 
|  | 1092 | lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1093 | if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr) | 
|  | 1094 | { | 
| Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1095 | ModuleSP module_sp (m_obj_file->GetModule()); | 
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 1096 | func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, module_sp->GetSectionList()); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1097 | if (func_range.GetBaseAddress().IsValid()) | 
|  | 1098 | func_range.SetByteSize(highest_func_addr - lowest_func_addr); | 
|  | 1099 | } | 
|  | 1100 |  | 
|  | 1101 | if (func_range.GetBaseAddress().IsValid()) | 
|  | 1102 | { | 
|  | 1103 | Mangled func_name; | 
|  | 1104 | if (mangled) | 
| Greg Clayton | 037520e | 2012-07-18 23:18:10 +0000 | [diff] [blame] | 1105 | func_name.SetValue(ConstString(mangled), true); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1106 | else if (name) | 
| Greg Clayton | 037520e | 2012-07-18 23:18:10 +0000 | [diff] [blame] | 1107 | func_name.SetValue(ConstString(name), false); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1108 |  | 
|  | 1109 | FunctionSP func_sp; | 
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1110 | std::unique_ptr<Declaration> decl_ap; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1111 | if (decl_file != 0 || decl_line != 0 || decl_column != 0) | 
| Greg Clayton | d7e0546 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 1112 | decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), | 
|  | 1113 | decl_line, | 
|  | 1114 | decl_column)); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1115 |  | 
| Greg Clayton | 0bd4e1b | 2011-09-30 20:52:25 +0000 | [diff] [blame] | 1116 | // Supply the type _only_ if it has already been parsed | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 1117 | Type *func_type = m_die_to_type.lookup (die); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1118 |  | 
|  | 1119 | assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED); | 
|  | 1120 |  | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1121 | if (FixupAddress (func_range.GetBaseAddress())) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1122 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1123 | const user_id_t func_user_id = MakeUserID(die->GetOffset()); | 
|  | 1124 | func_sp.reset(new Function (sc.comp_unit, | 
|  | 1125 | MakeUserID(func_user_id),       // UserID is the DIE offset | 
|  | 1126 | MakeUserID(func_user_id), | 
|  | 1127 | func_name, | 
|  | 1128 | func_type, | 
|  | 1129 | func_range));           // first address range | 
|  | 1130 |  | 
|  | 1131 | if (func_sp.get() != NULL) | 
|  | 1132 | { | 
|  | 1133 | if (frame_base.IsValid()) | 
|  | 1134 | func_sp->GetFrameBaseExpression() = frame_base; | 
|  | 1135 | sc.comp_unit->AddFunction(func_sp); | 
|  | 1136 | return func_sp.get(); | 
|  | 1137 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1138 | } | 
|  | 1139 | } | 
|  | 1140 | } | 
|  | 1141 | return NULL; | 
|  | 1142 | } | 
|  | 1143 |  | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1144 | bool | 
|  | 1145 | SymbolFileDWARF::FixupAddress (Address &addr) | 
|  | 1146 | { | 
|  | 1147 | SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile (); | 
|  | 1148 | if (debug_map_symfile) | 
|  | 1149 | { | 
|  | 1150 | return debug_map_symfile->LinkOSOAddress(addr); | 
|  | 1151 | } | 
|  | 1152 | // This is a normal DWARF file, no address fixups need to happen | 
|  | 1153 | return true; | 
|  | 1154 | } | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1155 | lldb::LanguageType | 
|  | 1156 | SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc) | 
|  | 1157 | { | 
|  | 1158 | assert (sc.comp_unit); | 
|  | 1159 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); | 
|  | 1160 | if (dwarf_cu) | 
|  | 1161 | { | 
|  | 1162 | const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly(); | 
| Jim Ingham | 28eb571 | 2012-10-12 17:34:26 +0000 | [diff] [blame] | 1163 | if (die) | 
|  | 1164 | { | 
|  | 1165 | const uint32_t language = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0); | 
|  | 1166 | if (language) | 
|  | 1167 | return (lldb::LanguageType)language; | 
|  | 1168 | } | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1169 | } | 
|  | 1170 | return eLanguageTypeUnknown; | 
|  | 1171 | } | 
|  | 1172 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1173 | size_t | 
|  | 1174 | SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc) | 
|  | 1175 | { | 
|  | 1176 | assert (sc.comp_unit); | 
|  | 1177 | size_t functions_added = 0; | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1178 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1179 | if (dwarf_cu) | 
|  | 1180 | { | 
|  | 1181 | DWARFDIECollection function_dies; | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1182 | 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] | 1183 | size_t func_idx; | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1184 | for (func_idx = 0; func_idx < num_functions; ++func_idx) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1185 | { | 
|  | 1186 | const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx); | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1187 | if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1188 | { | 
|  | 1189 | if (ParseCompileUnitFunction(sc, dwarf_cu, die)) | 
|  | 1190 | ++functions_added; | 
|  | 1191 | } | 
|  | 1192 | } | 
|  | 1193 | //FixupTypes(); | 
|  | 1194 | } | 
|  | 1195 | return functions_added; | 
|  | 1196 | } | 
|  | 1197 |  | 
|  | 1198 | bool | 
|  | 1199 | SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files) | 
|  | 1200 | { | 
|  | 1201 | assert (sc.comp_unit); | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1202 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); | 
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1203 | if (dwarf_cu) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1204 | { | 
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1205 | const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1206 |  | 
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1207 | if (cu_die) | 
|  | 1208 | { | 
|  | 1209 | const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL); | 
| Matthew Gardiner | e81df3b | 2014-08-26 06:57:23 +0000 | [diff] [blame] | 1210 |  | 
|  | 1211 | // DWARF2/3 suggests the form hostname:pathname for compilation directory. | 
|  | 1212 | // Remove the host part if present. | 
|  | 1213 | cu_comp_dir = removeHostnameFromPathname(cu_comp_dir); | 
|  | 1214 |  | 
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1215 | 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] | 1216 |  | 
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1217 | // All file indexes in DWARF are one based and a file of index zero is | 
|  | 1218 | // supposed to be the compile unit itself. | 
|  | 1219 | support_files.Append (*sc.comp_unit); | 
|  | 1220 |  | 
|  | 1221 | return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files); | 
|  | 1222 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1223 | } | 
|  | 1224 | return false; | 
|  | 1225 | } | 
|  | 1226 |  | 
|  | 1227 | struct ParseDWARFLineTableCallbackInfo | 
|  | 1228 | { | 
|  | 1229 | LineTable* line_table; | 
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1230 | std::unique_ptr<LineSequence> sequence_ap; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1231 | }; | 
|  | 1232 |  | 
|  | 1233 | //---------------------------------------------------------------------- | 
|  | 1234 | // ParseStatementTableCallback | 
|  | 1235 | //---------------------------------------------------------------------- | 
|  | 1236 | static void | 
|  | 1237 | ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData) | 
|  | 1238 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1239 | if (state.row == DWARFDebugLine::State::StartParsingLineTable) | 
|  | 1240 | { | 
|  | 1241 | // Just started parsing the line table | 
|  | 1242 | } | 
|  | 1243 | else if (state.row == DWARFDebugLine::State::DoneParsingLineTable) | 
|  | 1244 | { | 
|  | 1245 | // Done parsing line table, nothing to do for the cleanup | 
|  | 1246 | } | 
|  | 1247 | else | 
|  | 1248 | { | 
|  | 1249 | ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData; | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1250 | LineTable* line_table = info->line_table; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1251 |  | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1252 | // If this is our first time here, we need to create a | 
|  | 1253 | // sequence container. | 
|  | 1254 | if (!info->sequence_ap.get()) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1255 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1256 | info->sequence_ap.reset(line_table->CreateLineSequenceContainer()); | 
|  | 1257 | assert(info->sequence_ap.get()); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1258 | } | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1259 | line_table->AppendLineEntryToSequence (info->sequence_ap.get(), | 
|  | 1260 | state.address, | 
|  | 1261 | state.line, | 
|  | 1262 | state.column, | 
|  | 1263 | state.file, | 
|  | 1264 | state.is_stmt, | 
|  | 1265 | state.basic_block, | 
|  | 1266 | state.prologue_end, | 
|  | 1267 | state.epilogue_begin, | 
|  | 1268 | state.end_sequence); | 
|  | 1269 | if (state.end_sequence) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1270 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1271 | // First, put the current sequence into the line table. | 
|  | 1272 | line_table->InsertSequence(info->sequence_ap.get()); | 
|  | 1273 | // Then, empty it to prepare for the next sequence. | 
|  | 1274 | info->sequence_ap->Clear(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1275 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1276 | } | 
|  | 1277 | } | 
|  | 1278 |  | 
|  | 1279 | bool | 
|  | 1280 | SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc) | 
|  | 1281 | { | 
|  | 1282 | assert (sc.comp_unit); | 
|  | 1283 | if (sc.comp_unit->GetLineTable() != NULL) | 
|  | 1284 | return true; | 
|  | 1285 |  | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1286 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1287 | if (dwarf_cu) | 
|  | 1288 | { | 
|  | 1289 | const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly(); | 
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1290 | if (dwarf_cu_die) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1291 | { | 
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1292 | const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET); | 
|  | 1293 | if (cu_line_offset != DW_INVALID_OFFSET) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1294 | { | 
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1295 | std::unique_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit)); | 
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1296 | if (line_table_ap.get()) | 
|  | 1297 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1298 | ParseDWARFLineTableCallbackInfo info; | 
|  | 1299 | info.line_table = line_table_ap.get(); | 
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1300 | lldb::offset_t offset = cu_line_offset; | 
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1301 | DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info); | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1302 | if (m_debug_map_symfile) | 
|  | 1303 | { | 
|  | 1304 | // We have an object file that has a line table with addresses | 
|  | 1305 | // that are not linked. We need to link the line table and convert | 
|  | 1306 | // the addresses that are relative to the .o file into addresses | 
|  | 1307 | // for the main executable. | 
|  | 1308 | sc.comp_unit->SetLineTable (m_debug_map_symfile->LinkOSOLineTable (this, line_table_ap.get())); | 
|  | 1309 | } | 
|  | 1310 | else | 
|  | 1311 | { | 
|  | 1312 | sc.comp_unit->SetLineTable(line_table_ap.release()); | 
|  | 1313 | return true; | 
|  | 1314 | } | 
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1315 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1316 | } | 
|  | 1317 | } | 
|  | 1318 | } | 
|  | 1319 | return false; | 
|  | 1320 | } | 
|  | 1321 |  | 
|  | 1322 | size_t | 
|  | 1323 | SymbolFileDWARF::ParseFunctionBlocks | 
|  | 1324 | ( | 
|  | 1325 | const SymbolContext& sc, | 
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1326 | Block *parent_block, | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1327 | DWARFCompileUnit* dwarf_cu, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1328 | const DWARFDebugInfoEntry *die, | 
|  | 1329 | addr_t subprogram_low_pc, | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1330 | uint32_t depth | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1331 | ) | 
|  | 1332 | { | 
|  | 1333 | size_t blocks_added = 0; | 
|  | 1334 | while (die != NULL) | 
|  | 1335 | { | 
|  | 1336 | dw_tag_t tag = die->Tag(); | 
|  | 1337 |  | 
|  | 1338 | switch (tag) | 
|  | 1339 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1340 | case DW_TAG_inlined_subroutine: | 
| Greg Clayton | b4d3733 | 2011-08-12 16:22:48 +0000 | [diff] [blame] | 1341 | case DW_TAG_subprogram: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1342 | case DW_TAG_lexical_block: | 
|  | 1343 | { | 
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1344 | Block *block = NULL; | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1345 | if (tag == DW_TAG_subprogram) | 
|  | 1346 | { | 
|  | 1347 | // Skip any DW_TAG_subprogram DIEs that are inside | 
|  | 1348 | // of a normal or inlined functions. These will be | 
|  | 1349 | // parsed on their own as separate entities. | 
|  | 1350 |  | 
|  | 1351 | if (depth > 0) | 
|  | 1352 | break; | 
|  | 1353 |  | 
|  | 1354 | block = parent_block; | 
|  | 1355 | } | 
|  | 1356 | else | 
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1357 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1358 | BlockSP block_sp(new Block (MakeUserID(die->GetOffset()))); | 
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1359 | parent_block->AddChild(block_sp); | 
|  | 1360 | block = block_sp.get(); | 
|  | 1361 | } | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1362 | DWARFDebugRanges::RangeList ranges; | 
|  | 1363 | const char *name = NULL; | 
|  | 1364 | const char *mangled_name = NULL; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1365 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1366 | int decl_file = 0; | 
|  | 1367 | int decl_line = 0; | 
|  | 1368 | int decl_column = 0; | 
|  | 1369 | int call_file = 0; | 
|  | 1370 | int call_line = 0; | 
|  | 1371 | int call_column = 0; | 
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1372 | if (die->GetDIENamesAndRanges (this, | 
|  | 1373 | dwarf_cu, | 
|  | 1374 | name, | 
|  | 1375 | mangled_name, | 
|  | 1376 | ranges, | 
|  | 1377 | decl_file, decl_line, decl_column, | 
|  | 1378 | call_file, call_line, call_column)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1379 | { | 
|  | 1380 | if (tag == DW_TAG_subprogram) | 
|  | 1381 | { | 
|  | 1382 | assert (subprogram_low_pc == LLDB_INVALID_ADDRESS); | 
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1383 | subprogram_low_pc = ranges.GetMinRangeBase(0); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1384 | } | 
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1385 | else if (tag == DW_TAG_inlined_subroutine) | 
|  | 1386 | { | 
|  | 1387 | // We get called here for inlined subroutines in two ways. | 
|  | 1388 | // The first time is when we are making the Function object | 
|  | 1389 | // for this inlined concrete instance.  Since we're creating a top level block at | 
|  | 1390 | // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS.  So we need to | 
|  | 1391 | // adjust the containing address. | 
|  | 1392 | // The second time is when we are parsing the blocks inside the function that contains | 
|  | 1393 | // the inlined concrete instance.  Since these will be blocks inside the containing "real" | 
|  | 1394 | // function the offset will be for that function. | 
|  | 1395 | if (subprogram_low_pc == LLDB_INVALID_ADDRESS) | 
|  | 1396 | { | 
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1397 | subprogram_low_pc = ranges.GetMinRangeBase(0); | 
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1398 | } | 
|  | 1399 | } | 
|  | 1400 |  | 
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1401 | AddRangesToBlock (*block, ranges, subprogram_low_pc); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1402 |  | 
|  | 1403 | if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL)) | 
|  | 1404 | { | 
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1405 | std::unique_ptr<Declaration> decl_ap; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1406 | if (decl_file != 0 || decl_line != 0 || decl_column != 0) | 
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1407 | decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), | 
|  | 1408 | decl_line, decl_column)); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1409 |  | 
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1410 | std::unique_ptr<Declaration> call_ap; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1411 | if (call_file != 0 || call_line != 0 || call_column != 0) | 
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1412 | call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file), | 
|  | 1413 | call_line, call_column)); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1414 |  | 
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1415 | block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get()); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1416 | } | 
|  | 1417 |  | 
|  | 1418 | ++blocks_added; | 
|  | 1419 |  | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1420 | if (die->HasChildren()) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1421 | { | 
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1422 | blocks_added += ParseFunctionBlocks (sc, | 
|  | 1423 | block, | 
|  | 1424 | dwarf_cu, | 
|  | 1425 | die->GetFirstChild(), | 
|  | 1426 | subprogram_low_pc, | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1427 | depth + 1); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1428 | } | 
|  | 1429 | } | 
|  | 1430 | } | 
|  | 1431 | break; | 
|  | 1432 | default: | 
|  | 1433 | break; | 
|  | 1434 | } | 
|  | 1435 |  | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1436 | // Only parse siblings of the block if we are not at depth zero. A depth | 
|  | 1437 | // of zero indicates we are currently parsing the top level | 
|  | 1438 | // DW_TAG_subprogram DIE | 
|  | 1439 |  | 
|  | 1440 | if (depth == 0) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1441 | die = NULL; | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1442 | else | 
|  | 1443 | die = die->GetSibling(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1444 | } | 
|  | 1445 | return blocks_added; | 
|  | 1446 | } | 
|  | 1447 |  | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1448 | bool | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1449 | SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu, | 
|  | 1450 | const DWARFDebugInfoEntry *die, | 
|  | 1451 | ClangASTContext::TemplateParameterInfos &template_param_infos) | 
|  | 1452 | { | 
|  | 1453 | const dw_tag_t tag = die->Tag(); | 
|  | 1454 |  | 
|  | 1455 | switch (tag) | 
|  | 1456 | { | 
|  | 1457 | case DW_TAG_template_type_parameter: | 
|  | 1458 | case DW_TAG_template_value_parameter: | 
|  | 1459 | { | 
| Todd Fiala | ee8bfc6 | 2014-09-11 17:29:12 +0000 | [diff] [blame] | 1460 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64()); | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1461 |  | 
|  | 1462 | DWARFDebugInfoEntry::Attributes attributes; | 
|  | 1463 | const size_t num_attributes = die->GetAttributes (this, | 
|  | 1464 | dwarf_cu, | 
|  | 1465 | fixed_form_sizes, | 
|  | 1466 | attributes); | 
|  | 1467 | const char *name = NULL; | 
|  | 1468 | Type *lldb_type = NULL; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1469 | ClangASTType clang_type; | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1470 | uint64_t uval64 = 0; | 
|  | 1471 | bool uval64_valid = false; | 
|  | 1472 | if (num_attributes > 0) | 
|  | 1473 | { | 
|  | 1474 | DWARFFormValue form_value; | 
|  | 1475 | for (size_t i=0; i<num_attributes; ++i) | 
|  | 1476 | { | 
|  | 1477 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 1478 |  | 
|  | 1479 | switch (attr) | 
|  | 1480 | { | 
|  | 1481 | case DW_AT_name: | 
|  | 1482 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 1483 | name = form_value.AsCString(&get_debug_str_data()); | 
|  | 1484 | break; | 
|  | 1485 |  | 
|  | 1486 | case DW_AT_type: | 
|  | 1487 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 1488 | { | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 1489 | const dw_offset_t type_die_offset = form_value.Reference(); | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1490 | lldb_type = ResolveTypeUID(type_die_offset); | 
|  | 1491 | if (lldb_type) | 
|  | 1492 | clang_type = lldb_type->GetClangForwardType(); | 
|  | 1493 | } | 
|  | 1494 | break; | 
|  | 1495 |  | 
|  | 1496 | case DW_AT_const_value: | 
|  | 1497 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 1498 | { | 
|  | 1499 | uval64_valid = true; | 
|  | 1500 | uval64 = form_value.Unsigned(); | 
|  | 1501 | } | 
|  | 1502 | break; | 
|  | 1503 | default: | 
|  | 1504 | break; | 
|  | 1505 | } | 
|  | 1506 | } | 
|  | 1507 |  | 
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1508 | clang::ASTContext *ast = GetClangASTContext().getASTContext(); | 
|  | 1509 | if (!clang_type) | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1510 | clang_type = GetClangASTContext().GetBasicType(eBasicTypeVoid); | 
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1511 |  | 
|  | 1512 | if (clang_type) | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1513 | { | 
|  | 1514 | bool is_signed = false; | 
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1515 | if (name && name[0]) | 
|  | 1516 | template_param_infos.names.push_back(name); | 
|  | 1517 | else | 
|  | 1518 | template_param_infos.names.push_back(NULL); | 
|  | 1519 |  | 
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1520 | if (tag == DW_TAG_template_value_parameter && | 
|  | 1521 | lldb_type != NULL && | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1522 | clang_type.IsIntegerType (is_signed) && | 
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1523 | uval64_valid) | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1524 | { | 
|  | 1525 | llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed); | 
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1526 | template_param_infos.args.push_back (clang::TemplateArgument (*ast, | 
| Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1527 | llvm::APSInt(apint), | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1528 | clang_type.GetQualType())); | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1529 | } | 
|  | 1530 | else | 
|  | 1531 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1532 | template_param_infos.args.push_back (clang::TemplateArgument (clang_type.GetQualType())); | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1533 | } | 
|  | 1534 | } | 
|  | 1535 | else | 
|  | 1536 | { | 
|  | 1537 | return false; | 
|  | 1538 | } | 
|  | 1539 |  | 
|  | 1540 | } | 
|  | 1541 | } | 
|  | 1542 | return true; | 
|  | 1543 |  | 
|  | 1544 | default: | 
|  | 1545 | break; | 
|  | 1546 | } | 
|  | 1547 | return false; | 
|  | 1548 | } | 
|  | 1549 |  | 
|  | 1550 | bool | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1551 | SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu, | 
|  | 1552 | const DWARFDebugInfoEntry *parent_die, | 
|  | 1553 | ClangASTContext::TemplateParameterInfos &template_param_infos) | 
|  | 1554 | { | 
|  | 1555 |  | 
|  | 1556 | if (parent_die == NULL) | 
| Filipe Cabecinhas | 52008c6 | 2012-05-23 16:24:11 +0000 | [diff] [blame] | 1557 | return false; | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1558 |  | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1559 | Args template_parameter_names; | 
|  | 1560 | for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); | 
|  | 1561 | die != NULL; | 
|  | 1562 | die = die->GetSibling()) | 
|  | 1563 | { | 
|  | 1564 | const dw_tag_t tag = die->Tag(); | 
|  | 1565 |  | 
|  | 1566 | switch (tag) | 
|  | 1567 | { | 
|  | 1568 | case DW_TAG_template_type_parameter: | 
|  | 1569 | case DW_TAG_template_value_parameter: | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1570 | ParseTemplateDIE (dwarf_cu, die, template_param_infos); | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1571 | break; | 
|  | 1572 |  | 
|  | 1573 | default: | 
|  | 1574 | break; | 
|  | 1575 | } | 
|  | 1576 | } | 
|  | 1577 | if (template_param_infos.args.empty()) | 
|  | 1578 | return false; | 
|  | 1579 | return template_param_infos.args.size() == template_param_infos.names.size(); | 
|  | 1580 | } | 
|  | 1581 |  | 
|  | 1582 | clang::ClassTemplateDecl * | 
|  | 1583 | SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx, | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1584 | lldb::AccessType access_type, | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1585 | const char *parent_name, | 
|  | 1586 | int tag_decl_kind, | 
|  | 1587 | const ClangASTContext::TemplateParameterInfos &template_param_infos) | 
|  | 1588 | { | 
|  | 1589 | if (template_param_infos.IsValid()) | 
|  | 1590 | { | 
|  | 1591 | std::string template_basename(parent_name); | 
|  | 1592 | template_basename.erase (template_basename.find('<')); | 
|  | 1593 | ClangASTContext &ast = GetClangASTContext(); | 
|  | 1594 |  | 
|  | 1595 | return ast.CreateClassTemplateDecl (decl_ctx, | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1596 | access_type, | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1597 | template_basename.c_str(), | 
|  | 1598 | tag_decl_kind, | 
|  | 1599 | template_param_infos); | 
|  | 1600 | } | 
|  | 1601 | return NULL; | 
|  | 1602 | } | 
|  | 1603 |  | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1604 | class SymbolFileDWARF::DelayedAddObjCClassProperty | 
|  | 1605 | { | 
|  | 1606 | public: | 
|  | 1607 | DelayedAddObjCClassProperty | 
|  | 1608 | ( | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1609 | const ClangASTType     &class_opaque_type, | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1610 | const char             *property_name, | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1611 | 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] | 1612 | clang::ObjCIvarDecl    *ivar_decl, | 
|  | 1613 | const char             *property_setter_name, | 
|  | 1614 | const char             *property_getter_name, | 
|  | 1615 | uint32_t                property_attributes, | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1616 | const ClangASTMetadata *metadata | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1617 | ) : | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1618 | m_class_opaque_type     (class_opaque_type), | 
|  | 1619 | m_property_name         (property_name), | 
|  | 1620 | m_property_opaque_type  (property_opaque_type), | 
|  | 1621 | m_ivar_decl             (ivar_decl), | 
|  | 1622 | m_property_setter_name  (property_setter_name), | 
|  | 1623 | m_property_getter_name  (property_getter_name), | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1624 | m_property_attributes   (property_attributes) | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1625 | { | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1626 | if (metadata != NULL) | 
|  | 1627 | { | 
|  | 1628 | m_metadata_ap.reset(new ClangASTMetadata()); | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1629 | *m_metadata_ap = *metadata; | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1630 | } | 
|  | 1631 | } | 
|  | 1632 |  | 
|  | 1633 | DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs) | 
|  | 1634 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1635 | *this = rhs; | 
| Daniel Malea | d4c5be6 | 2012-11-12 21:02:14 +0000 | [diff] [blame] | 1636 | } | 
|  | 1637 |  | 
|  | 1638 | DelayedAddObjCClassProperty& operator= (const DelayedAddObjCClassProperty &rhs) | 
|  | 1639 | { | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1640 | m_class_opaque_type    = rhs.m_class_opaque_type; | 
|  | 1641 | m_property_name        = rhs.m_property_name; | 
|  | 1642 | m_property_opaque_type = rhs.m_property_opaque_type; | 
|  | 1643 | m_ivar_decl            = rhs.m_ivar_decl; | 
|  | 1644 | m_property_setter_name = rhs.m_property_setter_name; | 
|  | 1645 | m_property_getter_name = rhs.m_property_getter_name; | 
|  | 1646 | m_property_attributes  = rhs.m_property_attributes; | 
|  | 1647 |  | 
|  | 1648 | if (rhs.m_metadata_ap.get()) | 
|  | 1649 | { | 
|  | 1650 | m_metadata_ap.reset (new ClangASTMetadata()); | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1651 | *m_metadata_ap = *rhs.m_metadata_ap; | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1652 | } | 
| Daniel Malea | d4c5be6 | 2012-11-12 21:02:14 +0000 | [diff] [blame] | 1653 | return *this; | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1654 | } | 
|  | 1655 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1656 | bool | 
|  | 1657 | Finalize() | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1658 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1659 | return m_class_opaque_type.AddObjCClassProperty (m_property_name, | 
|  | 1660 | m_property_opaque_type, | 
|  | 1661 | m_ivar_decl, | 
|  | 1662 | m_property_setter_name, | 
|  | 1663 | m_property_getter_name, | 
|  | 1664 | m_property_attributes, | 
|  | 1665 | m_metadata_ap.get()); | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1666 | } | 
|  | 1667 | private: | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1668 | ClangASTType            m_class_opaque_type; | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1669 | const char             *m_property_name; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1670 | ClangASTType            m_property_opaque_type; | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1671 | clang::ObjCIvarDecl    *m_ivar_decl; | 
|  | 1672 | const char             *m_property_setter_name; | 
|  | 1673 | const char             *m_property_getter_name; | 
|  | 1674 | uint32_t                m_property_attributes; | 
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1675 | std::unique_ptr<ClangASTMetadata> m_metadata_ap; | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1676 | }; | 
|  | 1677 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1678 | struct BitfieldInfo | 
|  | 1679 | { | 
|  | 1680 | uint64_t bit_size; | 
|  | 1681 | uint64_t bit_offset; | 
|  | 1682 |  | 
|  | 1683 | BitfieldInfo () : | 
|  | 1684 | bit_size (LLDB_INVALID_ADDRESS), | 
|  | 1685 | bit_offset (LLDB_INVALID_ADDRESS) | 
|  | 1686 | { | 
|  | 1687 | } | 
|  | 1688 |  | 
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 1689 | void | 
|  | 1690 | Clear() | 
|  | 1691 | { | 
|  | 1692 | bit_size = LLDB_INVALID_ADDRESS; | 
|  | 1693 | bit_offset = LLDB_INVALID_ADDRESS; | 
|  | 1694 | } | 
|  | 1695 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1696 | bool IsValid () | 
|  | 1697 | { | 
|  | 1698 | return (bit_size != LLDB_INVALID_ADDRESS) && | 
|  | 1699 | (bit_offset != LLDB_INVALID_ADDRESS); | 
|  | 1700 | } | 
|  | 1701 | }; | 
|  | 1702 |  | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1703 |  | 
|  | 1704 | bool | 
|  | 1705 | SymbolFileDWARF::ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu, | 
|  | 1706 | const DWARFDebugInfoEntry *parent_die) | 
|  | 1707 | { | 
|  | 1708 | if (parent_die) | 
|  | 1709 | { | 
|  | 1710 | for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) | 
|  | 1711 | { | 
|  | 1712 | dw_tag_t tag = die->Tag(); | 
|  | 1713 | bool check_virtuality = false; | 
|  | 1714 | switch (tag) | 
|  | 1715 | { | 
|  | 1716 | case DW_TAG_inheritance: | 
|  | 1717 | case DW_TAG_subprogram: | 
|  | 1718 | check_virtuality = true; | 
|  | 1719 | break; | 
|  | 1720 | default: | 
|  | 1721 | break; | 
|  | 1722 | } | 
|  | 1723 | if (check_virtuality) | 
|  | 1724 | { | 
|  | 1725 | if (die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_virtuality, 0) != 0) | 
|  | 1726 | return true; | 
|  | 1727 | } | 
|  | 1728 | } | 
|  | 1729 | } | 
|  | 1730 | return false; | 
|  | 1731 | } | 
|  | 1732 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1733 | size_t | 
|  | 1734 | SymbolFileDWARF::ParseChildMembers | 
|  | 1735 | ( | 
|  | 1736 | const SymbolContext& sc, | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1737 | DWARFCompileUnit* dwarf_cu, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1738 | const DWARFDebugInfoEntry *parent_die, | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1739 | ClangASTType &class_clang_type, | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1740 | const LanguageType class_language, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1741 | std::vector<clang::CXXBaseSpecifier *>& base_classes, | 
|  | 1742 | std::vector<int>& member_accessibilities, | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1743 | DWARFDIECollection& member_function_dies, | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1744 | DelayedPropertyList& delayed_properties, | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1745 | AccessType& default_accessibility, | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1746 | bool &is_a_class, | 
|  | 1747 | LayoutInfo &layout_info | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1748 | ) | 
|  | 1749 | { | 
|  | 1750 | if (parent_die == NULL) | 
|  | 1751 | return 0; | 
|  | 1752 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1753 | size_t count = 0; | 
|  | 1754 | const DWARFDebugInfoEntry *die; | 
| Todd Fiala | ee8bfc6 | 2014-09-11 17:29:12 +0000 | [diff] [blame] | 1755 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64()); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1756 | uint32_t member_idx = 0; | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1757 | BitfieldInfo last_field_info; | 
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 1758 | ModuleSP module = GetObjectFile()->GetModule(); | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 1759 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1760 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) | 
|  | 1761 | { | 
|  | 1762 | dw_tag_t tag = die->Tag(); | 
|  | 1763 |  | 
|  | 1764 | switch (tag) | 
|  | 1765 | { | 
|  | 1766 | case DW_TAG_member: | 
| Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1767 | case DW_TAG_APPLE_property: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1768 | { | 
|  | 1769 | DWARFDebugInfoEntry::Attributes attributes; | 
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1770 | const size_t num_attributes = die->GetAttributes (this, | 
|  | 1771 | dwarf_cu, | 
|  | 1772 | fixed_form_sizes, | 
|  | 1773 | attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1774 | if (num_attributes > 0) | 
|  | 1775 | { | 
|  | 1776 | Declaration decl; | 
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1777 | //DWARFExpression location; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1778 | const char *name = NULL; | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1779 | const char *prop_name = NULL; | 
|  | 1780 | const char *prop_getter_name = NULL; | 
|  | 1781 | const char *prop_setter_name = NULL; | 
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1782 | uint32_t prop_attributes = 0; | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1783 |  | 
|  | 1784 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1785 | bool is_artificial = false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1786 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1787 | AccessType accessibility = eAccessNone; | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1788 | uint32_t member_byte_offset = UINT32_MAX; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1789 | size_t byte_size = 0; | 
|  | 1790 | size_t bit_offset = 0; | 
|  | 1791 | size_t bit_size = 0; | 
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1792 | 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] | 1793 | uint32_t i; | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1794 | for (i=0; i<num_attributes && !is_artificial; ++i) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1795 | { | 
|  | 1796 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 1797 | DWARFFormValue form_value; | 
|  | 1798 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 1799 | { | 
|  | 1800 | switch (attr) | 
|  | 1801 | { | 
|  | 1802 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 1803 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 1804 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 1805 | case DW_AT_name:        name = form_value.AsCString(&get_debug_str_data()); break; | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 1806 | case DW_AT_type:        encoding_uid = form_value.Reference(); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1807 | case DW_AT_bit_offset:  bit_offset = form_value.Unsigned(); break; | 
|  | 1808 | case DW_AT_bit_size:    bit_size = form_value.Unsigned(); break; | 
|  | 1809 | case DW_AT_byte_size:   byte_size = form_value.Unsigned(); break; | 
|  | 1810 | case DW_AT_data_member_location: | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1811 | if (form_value.BlockData()) | 
|  | 1812 | { | 
|  | 1813 | Value initialValue(0); | 
|  | 1814 | Value memberOffset(0); | 
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 1815 | const DWARFDataExtractor& debug_info_data = get_debug_info_data(); | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1816 | uint32_t block_length = form_value.Unsigned(); | 
|  | 1817 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); | 
|  | 1818 | if (DWARFExpression::Evaluate(NULL, // ExecutionContext * | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1819 | NULL, // ClangExpressionVariableList * | 
|  | 1820 | NULL, // ClangExpressionDeclMap * | 
|  | 1821 | NULL, // RegisterContext * | 
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 1822 | module, | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1823 | debug_info_data, | 
|  | 1824 | block_offset, | 
|  | 1825 | block_length, | 
|  | 1826 | eRegisterKindDWARF, | 
|  | 1827 | &initialValue, | 
|  | 1828 | memberOffset, | 
|  | 1829 | NULL)) | 
|  | 1830 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1831 | member_byte_offset = memberOffset.ResolveValue(NULL).UInt(); | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1832 | } | 
|  | 1833 | } | 
| Ashok Thirumurthi | a4658a5 | 2013-07-30 14:58:39 +0000 | [diff] [blame] | 1834 | else | 
|  | 1835 | { | 
|  | 1836 | // With DWARF 3 and later, if the value is an integer constant, | 
|  | 1837 | // this form value is the offset in bytes from the beginning | 
|  | 1838 | // of the containing entity. | 
|  | 1839 | member_byte_offset = form_value.Unsigned(); | 
|  | 1840 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1841 | break; | 
|  | 1842 |  | 
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1843 | 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] | 1844 | case DW_AT_artificial: is_artificial = form_value.Boolean(); break; | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1845 | case DW_AT_APPLE_property_name:      prop_name = form_value.AsCString(&get_debug_str_data()); break; | 
|  | 1846 | case DW_AT_APPLE_property_getter:    prop_getter_name = form_value.AsCString(&get_debug_str_data()); break; | 
|  | 1847 | case DW_AT_APPLE_property_setter:    prop_setter_name = form_value.AsCString(&get_debug_str_data()); break; | 
|  | 1848 | case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break; | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 1849 | case DW_AT_external:                 is_external = form_value.Boolean(); break; | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1850 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1851 | default: | 
| Greg Clayton | 1b02c17 | 2012-03-14 21:00:47 +0000 | [diff] [blame] | 1852 | case DW_AT_declaration: | 
|  | 1853 | case DW_AT_description: | 
|  | 1854 | case DW_AT_mutable: | 
|  | 1855 | case DW_AT_visibility: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1856 | case DW_AT_sibling: | 
|  | 1857 | break; | 
|  | 1858 | } | 
|  | 1859 | } | 
|  | 1860 | } | 
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1861 |  | 
|  | 1862 | if (prop_name) | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1863 | { | 
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1864 | ConstString fixed_getter; | 
|  | 1865 | ConstString fixed_setter; | 
|  | 1866 |  | 
|  | 1867 | // Check if the property getter/setter were provided as full | 
|  | 1868 | // names.  We want basenames, so we extract them. | 
|  | 1869 |  | 
|  | 1870 | if (prop_getter_name && prop_getter_name[0] == '-') | 
|  | 1871 | { | 
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 1872 | ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true); | 
|  | 1873 | prop_getter_name = prop_getter_method.GetSelector().GetCString(); | 
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1874 | } | 
|  | 1875 |  | 
|  | 1876 | if (prop_setter_name && prop_setter_name[0] == '-') | 
|  | 1877 | { | 
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 1878 | ObjCLanguageRuntime::MethodName prop_setter_method(prop_setter_name, true); | 
|  | 1879 | prop_setter_name = prop_setter_method.GetSelector().GetCString(); | 
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1880 | } | 
|  | 1881 |  | 
|  | 1882 | // If the names haven't been provided, they need to be | 
|  | 1883 | // filled in. | 
|  | 1884 |  | 
|  | 1885 | if (!prop_getter_name) | 
|  | 1886 | { | 
|  | 1887 | prop_getter_name = prop_name; | 
|  | 1888 | } | 
|  | 1889 | if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly)) | 
|  | 1890 | { | 
|  | 1891 | StreamString ss; | 
|  | 1892 |  | 
|  | 1893 | ss.Printf("set%c%s:", | 
|  | 1894 | toupper(prop_name[0]), | 
|  | 1895 | &prop_name[1]); | 
|  | 1896 |  | 
|  | 1897 | fixed_setter.SetCString(ss.GetData()); | 
|  | 1898 | prop_setter_name = fixed_setter.GetCString(); | 
|  | 1899 | } | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1900 | } | 
|  | 1901 |  | 
|  | 1902 | // Clang has a DWARF generation bug where sometimes it | 
| Greg Clayton | 4495393 | 2011-10-25 01:25:35 +0000 | [diff] [blame] | 1903 | // represents fields that are references with bad byte size | 
|  | 1904 | // and bit size/offset information such as: | 
|  | 1905 | // | 
|  | 1906 | //  DW_AT_byte_size( 0x00 ) | 
|  | 1907 | //  DW_AT_bit_size( 0x40 ) | 
|  | 1908 | //  DW_AT_bit_offset( 0xffffffffffffffc0 ) | 
|  | 1909 | // | 
|  | 1910 | // So check the bit offset to make sure it is sane, and if | 
|  | 1911 | // the values are not sane, remove them. If we don't do this | 
|  | 1912 | // then we will end up with a crash if we try to use this | 
|  | 1913 | // type in an expression when clang becomes unhappy with its | 
|  | 1914 | // recycled debug info. | 
| Sean Callanan | 5a477cf | 2010-10-30 01:56:10 +0000 | [diff] [blame] | 1915 |  | 
| Greg Clayton | 4495393 | 2011-10-25 01:25:35 +0000 | [diff] [blame] | 1916 | if (bit_offset > 128) | 
|  | 1917 | { | 
|  | 1918 | bit_size = 0; | 
|  | 1919 | bit_offset = 0; | 
|  | 1920 | } | 
|  | 1921 |  | 
|  | 1922 | // FIXME: Make Clang ignore Objective-C accessibility for expressions | 
| Sean Callanan | 5a477cf | 2010-10-30 01:56:10 +0000 | [diff] [blame] | 1923 | if (class_language == eLanguageTypeObjC || | 
|  | 1924 | class_language == eLanguageTypeObjC_plus_plus) | 
|  | 1925 | accessibility = eAccessNone; | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1926 |  | 
|  | 1927 | if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name)) | 
|  | 1928 | { | 
|  | 1929 | // Not all compilers will mark the vtable pointer | 
|  | 1930 | // member as artificial (llvm-gcc). We can't have | 
|  | 1931 | // the virtual members in our classes otherwise it | 
|  | 1932 | // throws off all child offsets since we end up | 
|  | 1933 | // having and extra pointer sized member in our | 
|  | 1934 | // class layouts. | 
|  | 1935 | is_artificial = true; | 
|  | 1936 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1937 |  | 
| Greg Clayton | 2965971 | 2013-07-12 20:08:35 +0000 | [diff] [blame] | 1938 | // Handle static members | 
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1939 | if (is_external && member_byte_offset == UINT32_MAX) | 
| Greg Clayton | 973b6c9 | 2013-04-11 16:57:51 +0000 | [diff] [blame] | 1940 | { | 
|  | 1941 | Type *var_type = ResolveTypeUID(encoding_uid); | 
|  | 1942 |  | 
|  | 1943 | if (var_type) | 
|  | 1944 | { | 
| Greg Clayton | 2965971 | 2013-07-12 20:08:35 +0000 | [diff] [blame] | 1945 | if (accessibility == eAccessNone) | 
|  | 1946 | accessibility = eAccessPublic; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1947 | class_clang_type.AddVariableToRecordType (name, | 
|  | 1948 | var_type->GetClangLayoutType(), | 
|  | 1949 | accessibility); | 
| Greg Clayton | 973b6c9 | 2013-04-11 16:57:51 +0000 | [diff] [blame] | 1950 | } | 
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1951 | break; | 
| Greg Clayton | 973b6c9 | 2013-04-11 16:57:51 +0000 | [diff] [blame] | 1952 | } | 
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1953 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1954 | if (is_artificial == false) | 
|  | 1955 | { | 
|  | 1956 | Type *member_type = ResolveTypeUID(encoding_uid); | 
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 1957 |  | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1958 | clang::FieldDecl *field_decl = NULL; | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1959 | if (tag == DW_TAG_member) | 
| Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1960 | { | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1961 | if (member_type) | 
|  | 1962 | { | 
|  | 1963 | if (accessibility == eAccessNone) | 
|  | 1964 | accessibility = default_accessibility; | 
|  | 1965 | member_accessibilities.push_back(accessibility); | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1966 |  | 
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 1967 | uint64_t field_bit_offset = (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8)); | 
|  | 1968 | if (bit_size > 0) | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1969 | { | 
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 1970 |  | 
|  | 1971 | BitfieldInfo this_field_info; | 
|  | 1972 | this_field_info.bit_offset = field_bit_offset; | 
|  | 1973 | this_field_info.bit_size = bit_size; | 
|  | 1974 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1975 | ///////////////////////////////////////////////////////////// | 
|  | 1976 | // How to locate a field given the DWARF debug information | 
|  | 1977 | // | 
|  | 1978 | // AT_byte_size indicates the size of the word in which the | 
|  | 1979 | // bit offset must be interpreted. | 
|  | 1980 | // | 
|  | 1981 | // AT_data_member_location indicates the byte offset of the | 
|  | 1982 | // word from the base address of the structure. | 
|  | 1983 | // | 
|  | 1984 | // AT_bit_offset indicates how many bits into the word | 
|  | 1985 | // (according to the host endianness) the low-order bit of | 
|  | 1986 | // the field starts.  AT_bit_offset can be negative. | 
|  | 1987 | // | 
|  | 1988 | // AT_bit_size indicates the size of the field in bits. | 
|  | 1989 | ///////////////////////////////////////////////////////////// | 
|  | 1990 |  | 
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 1991 | if (byte_size == 0) | 
|  | 1992 | byte_size = member_type->GetByteSize(); | 
|  | 1993 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1994 | if (GetObjectFile()->GetByteOrder() == eByteOrderLittle) | 
|  | 1995 | { | 
|  | 1996 | this_field_info.bit_offset += byte_size * 8; | 
|  | 1997 | this_field_info.bit_offset -= (bit_offset + bit_size); | 
|  | 1998 | } | 
|  | 1999 | else | 
|  | 2000 | { | 
|  | 2001 | this_field_info.bit_offset += bit_offset; | 
|  | 2002 | } | 
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 2003 |  | 
|  | 2004 | // Update the field bit offset we will report for layout | 
|  | 2005 | field_bit_offset = this_field_info.bit_offset; | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2006 |  | 
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 2007 | // If the member to be emitted did not start on a character boundary and there is | 
|  | 2008 | // empty space between the last field and this one, then we need to emit an | 
|  | 2009 | // anonymous member filling up the space up to its start.  There are three cases | 
|  | 2010 | // here: | 
|  | 2011 | // | 
|  | 2012 | // 1 If the previous member ended on a character boundary, then we can emit an | 
|  | 2013 | //   anonymous member starting at the most recent character boundary. | 
|  | 2014 | // | 
|  | 2015 | // 2 If the previous member did not end on a character boundary and the distance | 
|  | 2016 | //   from the end of the previous member to the current member is less than a | 
|  | 2017 | //   word width, then we can emit an anonymous member starting right after the | 
|  | 2018 | //   previous member and right before this member. | 
|  | 2019 | // | 
|  | 2020 | // 3 If the previous member did not end on a character boundary and the distance | 
|  | 2021 | //   from the end of the previous member to the current member is greater than | 
|  | 2022 | //   or equal a word width, then we act as in Case 1. | 
|  | 2023 |  | 
|  | 2024 | const uint64_t character_width = 8; | 
|  | 2025 | const uint64_t word_width = 32; | 
|  | 2026 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2027 | // Objective-C has invalid DW_AT_bit_offset values in older versions | 
| Bruce Mitchener | aaa0ba3 | 2014-07-08 18:05:41 +0000 | [diff] [blame] | 2028 | // of clang, so we have to be careful and only insert unnamed bitfields | 
| Greg Clayton | 37c36e4 | 2012-11-27 00:59:26 +0000 | [diff] [blame] | 2029 | // if we have a new enough clang. | 
|  | 2030 | bool detect_unnamed_bitfields = true; | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2031 |  | 
| Greg Clayton | 37c36e4 | 2012-11-27 00:59:26 +0000 | [diff] [blame] | 2032 | if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus) | 
|  | 2033 | detect_unnamed_bitfields = dwarf_cu->Supports_unnamed_objc_bitfields (); | 
|  | 2034 |  | 
|  | 2035 | if (detect_unnamed_bitfields) | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2036 | { | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2037 | BitfieldInfo anon_field_info; | 
|  | 2038 |  | 
|  | 2039 | if ((this_field_info.bit_offset % character_width) != 0) // not char aligned | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2040 | { | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2041 | uint64_t last_field_end = 0; | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2042 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2043 | if (last_field_info.IsValid()) | 
|  | 2044 | 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] | 2045 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2046 | if (this_field_info.bit_offset != last_field_end) | 
|  | 2047 | { | 
|  | 2048 | if (((last_field_end % character_width) == 0) ||                    // case 1 | 
|  | 2049 | (this_field_info.bit_offset - last_field_end >= word_width))    // case 3 | 
|  | 2050 | { | 
|  | 2051 | anon_field_info.bit_size = this_field_info.bit_offset % character_width; | 
|  | 2052 | anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size; | 
|  | 2053 | } | 
|  | 2054 | else                                                                // case 2 | 
|  | 2055 | { | 
|  | 2056 | anon_field_info.bit_size = this_field_info.bit_offset - last_field_end; | 
|  | 2057 | anon_field_info.bit_offset = last_field_end; | 
|  | 2058 | } | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2059 | } | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2060 | } | 
|  | 2061 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2062 | if (anon_field_info.IsValid()) | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2063 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2064 | clang::FieldDecl *unnamed_bitfield_decl = class_clang_type.AddFieldToRecordType (NULL, | 
|  | 2065 | GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width), | 
|  | 2066 | accessibility, | 
|  | 2067 | anon_field_info.bit_size); | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2068 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2069 | 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] | 2070 | } | 
|  | 2071 | } | 
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 2072 | last_field_info = this_field_info; | 
|  | 2073 | } | 
|  | 2074 | else | 
|  | 2075 | { | 
|  | 2076 | last_field_info.Clear(); | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2077 | } | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2078 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2079 | ClangASTType member_clang_type = member_type->GetClangLayoutType(); | 
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 2080 |  | 
|  | 2081 | { | 
|  | 2082 | // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>). | 
|  | 2083 | // If the current field is at the end of the structure, then there is definitely no room for extra | 
|  | 2084 | // elements and we override the type to array[0]. | 
|  | 2085 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2086 | ClangASTType member_array_element_type; | 
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 2087 | uint64_t member_array_size; | 
|  | 2088 | bool member_array_is_incomplete; | 
|  | 2089 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2090 | if (member_clang_type.IsArrayType(&member_array_element_type, | 
|  | 2091 | &member_array_size, | 
|  | 2092 | &member_array_is_incomplete) && | 
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 2093 | !member_array_is_incomplete) | 
|  | 2094 | { | 
|  | 2095 | uint64_t parent_byte_size = parent_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, UINT64_MAX); | 
|  | 2096 |  | 
|  | 2097 | if (member_byte_offset >= parent_byte_size) | 
|  | 2098 | { | 
|  | 2099 | if (member_array_size != 1) | 
|  | 2100 | { | 
|  | 2101 | 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, | 
|  | 2102 | MakeUserID(die->GetOffset()), | 
|  | 2103 | name, | 
|  | 2104 | encoding_uid, | 
|  | 2105 | MakeUserID(parent_die->GetOffset())); | 
|  | 2106 | } | 
|  | 2107 |  | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 2108 | member_clang_type = GetClangASTContext().CreateArrayType(member_array_element_type, 0, false); | 
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 2109 | } | 
|  | 2110 | } | 
|  | 2111 | } | 
|  | 2112 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2113 | field_decl = class_clang_type.AddFieldToRecordType (name, | 
|  | 2114 | member_clang_type, | 
|  | 2115 | accessibility, | 
|  | 2116 | bit_size); | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2117 |  | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 2118 | GetClangASTContext().SetMetadataAsUserID (field_decl, MakeUserID(die->GetOffset())); | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2119 |  | 
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 2120 | layout_info.field_offsets.insert(std::make_pair(field_decl, field_bit_offset)); | 
|  | 2121 |  | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2122 | } | 
|  | 2123 | else | 
|  | 2124 | { | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 2125 | if (name) | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2126 | 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] | 2127 | MakeUserID(die->GetOffset()), | 
|  | 2128 | name, | 
|  | 2129 | encoding_uid); | 
|  | 2130 | else | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2131 | 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] | 2132 | MakeUserID(die->GetOffset()), | 
|  | 2133 | encoding_uid); | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2134 | } | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2135 | } | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 2136 |  | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2137 | if (prop_name != NULL) | 
|  | 2138 | { | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 2139 | clang::ObjCIvarDecl *ivar_decl = NULL; | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2140 |  | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 2141 | if (field_decl) | 
|  | 2142 | { | 
|  | 2143 | ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl); | 
|  | 2144 | assert (ivar_decl != NULL); | 
|  | 2145 | } | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2146 |  | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 2147 | ClangASTMetadata metadata; | 
|  | 2148 | metadata.SetUserID (MakeUserID(die->GetOffset())); | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2149 | delayed_properties.push_back(DelayedAddObjCClassProperty(class_clang_type, | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2150 | prop_name, | 
|  | 2151 | member_type->GetClangLayoutType(), | 
|  | 2152 | ivar_decl, | 
|  | 2153 | prop_setter_name, | 
|  | 2154 | prop_getter_name, | 
|  | 2155 | prop_attributes, | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 2156 | &metadata)); | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2157 |  | 
| Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 2158 | if (ivar_decl) | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 2159 | GetClangASTContext().SetMetadataAsUserID (ivar_decl, MakeUserID(die->GetOffset())); | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2160 | } | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2161 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2162 | } | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2163 | ++member_idx; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2164 | } | 
|  | 2165 | break; | 
|  | 2166 |  | 
|  | 2167 | case DW_TAG_subprogram: | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2168 | // Let the type parsing code handle this one for us. | 
|  | 2169 | member_function_dies.Append (die); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2170 | break; | 
|  | 2171 |  | 
|  | 2172 | case DW_TAG_inheritance: | 
|  | 2173 | { | 
|  | 2174 | is_a_class = true; | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 2175 | if (default_accessibility == eAccessNone) | 
|  | 2176 | default_accessibility = eAccessPrivate; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2177 | // TODO: implement DW_TAG_inheritance type parsing | 
|  | 2178 | DWARFDebugInfoEntry::Attributes attributes; | 
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 2179 | const size_t num_attributes = die->GetAttributes (this, | 
|  | 2180 | dwarf_cu, | 
|  | 2181 | fixed_form_sizes, | 
|  | 2182 | attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2183 | if (num_attributes > 0) | 
|  | 2184 | { | 
|  | 2185 | Declaration decl; | 
|  | 2186 | DWARFExpression location; | 
|  | 2187 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 2188 | AccessType accessibility = default_accessibility; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2189 | bool is_virtual = false; | 
|  | 2190 | bool is_base_of_class = true; | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2191 | off_t member_byte_offset = 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2192 | uint32_t i; | 
|  | 2193 | for (i=0; i<num_attributes; ++i) | 
|  | 2194 | { | 
|  | 2195 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 2196 | DWARFFormValue form_value; | 
|  | 2197 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 2198 | { | 
|  | 2199 | switch (attr) | 
|  | 2200 | { | 
|  | 2201 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 2202 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 2203 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 2204 | case DW_AT_type:        encoding_uid = form_value.Reference(); break; | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2205 | case DW_AT_data_member_location: | 
|  | 2206 | if (form_value.BlockData()) | 
|  | 2207 | { | 
|  | 2208 | Value initialValue(0); | 
|  | 2209 | Value memberOffset(0); | 
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 2210 | const DWARFDataExtractor& debug_info_data = get_debug_info_data(); | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2211 | uint32_t block_length = form_value.Unsigned(); | 
|  | 2212 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); | 
|  | 2213 | if (DWARFExpression::Evaluate (NULL, | 
|  | 2214 | NULL, | 
|  | 2215 | NULL, | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2216 | NULL, | 
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 2217 | module, | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2218 | debug_info_data, | 
|  | 2219 | block_offset, | 
|  | 2220 | block_length, | 
|  | 2221 | eRegisterKindDWARF, | 
|  | 2222 | &initialValue, | 
|  | 2223 | memberOffset, | 
|  | 2224 | NULL)) | 
|  | 2225 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2226 | member_byte_offset = memberOffset.ResolveValue(NULL).UInt(); | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2227 | } | 
|  | 2228 | } | 
| Ashok Thirumurthi | a4658a5 | 2013-07-30 14:58:39 +0000 | [diff] [blame] | 2229 | else | 
|  | 2230 | { | 
|  | 2231 | // With DWARF 3 and later, if the value is an integer constant, | 
|  | 2232 | // this form value is the offset in bytes from the beginning | 
|  | 2233 | // of the containing entity. | 
|  | 2234 | member_byte_offset = form_value.Unsigned(); | 
|  | 2235 | } | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2236 | break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2237 |  | 
|  | 2238 | case DW_AT_accessibility: | 
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 2239 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2240 | break; | 
|  | 2241 |  | 
| Ashok Thirumurthi | a4658a5 | 2013-07-30 14:58:39 +0000 | [diff] [blame] | 2242 | case DW_AT_virtuality: | 
|  | 2243 | is_virtual = form_value.Boolean(); | 
|  | 2244 | break; | 
|  | 2245 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2246 | case DW_AT_sibling: | 
|  | 2247 | break; | 
| Ashok Thirumurthi | a4658a5 | 2013-07-30 14:58:39 +0000 | [diff] [blame] | 2248 |  | 
|  | 2249 | default: | 
|  | 2250 | break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2251 | } | 
|  | 2252 | } | 
|  | 2253 | } | 
|  | 2254 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 2255 | Type *base_class_type = ResolveTypeUID(encoding_uid); | 
|  | 2256 | assert(base_class_type); | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2257 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2258 | ClangASTType base_class_clang_type = base_class_type->GetClangFullType(); | 
| Greg Clayton | f4ecaa5 | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 2259 | assert (base_class_clang_type); | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2260 | if (class_language == eLanguageTypeObjC) | 
|  | 2261 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2262 | class_clang_type.SetObjCSuperClass(base_class_clang_type); | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2263 | } | 
|  | 2264 | else | 
|  | 2265 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2266 | base_classes.push_back (base_class_clang_type.CreateBaseClassSpecifier (accessibility, | 
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 2267 | is_virtual, | 
|  | 2268 | is_base_of_class)); | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2269 |  | 
|  | 2270 | if (is_virtual) | 
|  | 2271 | { | 
| Greg Clayton | 52694e3 | 2013-09-16 21:57:07 +0000 | [diff] [blame] | 2272 | // Do not specify any offset for virtual inheritance. The DWARF produced by clang doesn't | 
|  | 2273 | // give us a constant offset, but gives us a DWARF expressions that requires an actual object | 
|  | 2274 | // in memory. the DW_AT_data_member_location for a virtual base class looks like: | 
|  | 2275 | //      DW_AT_data_member_location( DW_OP_dup, DW_OP_deref, DW_OP_constu(0x00000018), DW_OP_minus, DW_OP_deref, DW_OP_plus ) | 
|  | 2276 | // Given this, there is really no valid response we can give to clang for virtual base | 
|  | 2277 | // class offsets, and this should eventually be removed from LayoutRecordType() in the external | 
|  | 2278 | // AST source in clang. | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2279 | } | 
|  | 2280 | else | 
|  | 2281 | { | 
| Greg Clayton | 5764873 | 2013-09-12 17:22:32 +0000 | [diff] [blame] | 2282 | 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] | 2283 | clang::CharUnits::fromQuantity(member_byte_offset))); | 
|  | 2284 | } | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2285 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2286 | } | 
|  | 2287 | } | 
|  | 2288 | break; | 
|  | 2289 |  | 
|  | 2290 | default: | 
|  | 2291 | break; | 
|  | 2292 | } | 
|  | 2293 | } | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2294 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2295 | return count; | 
|  | 2296 | } | 
|  | 2297 |  | 
|  | 2298 |  | 
|  | 2299 | clang::DeclContext* | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 2300 | SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2301 | { | 
|  | 2302 | DWARFDebugInfo* debug_info = DebugInfo(); | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2303 | if (debug_info && UserIDMatches(type_uid)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2304 | { | 
|  | 2305 | DWARFCompileUnitSP cu_sp; | 
|  | 2306 | const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp); | 
|  | 2307 | if (die) | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 2308 | return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL); | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 2309 | } | 
|  | 2310 | return NULL; | 
|  | 2311 | } | 
|  | 2312 |  | 
|  | 2313 | clang::DeclContext* | 
|  | 2314 | SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid) | 
|  | 2315 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2316 | if (UserIDMatches(type_uid)) | 
|  | 2317 | return GetClangDeclContextForDIEOffset (sc, type_uid); | 
|  | 2318 | return NULL; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2319 | } | 
|  | 2320 |  | 
|  | 2321 | Type* | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2322 | SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2323 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2324 | if (UserIDMatches(type_uid)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2325 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2326 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 2327 | if (debug_info) | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2328 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2329 | DWARFCompileUnitSP cu_sp; | 
|  | 2330 | const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp); | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2331 | const bool assert_not_being_parsed = true; | 
|  | 2332 | return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed); | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2333 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2334 | } | 
|  | 2335 | return NULL; | 
|  | 2336 | } | 
|  | 2337 |  | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2338 | Type* | 
|  | 2339 | SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed) | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2340 | { | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2341 | if (die != NULL) | 
|  | 2342 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2343 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2344 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2345 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2346 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'", | 
|  | 2347 | die->GetOffset(), | 
|  | 2348 | DW_TAG_value_to_name(die->Tag()), | 
|  | 2349 | die->GetName(this, cu)); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2350 |  | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2351 | // We might be coming in in the middle of a type tree (a class | 
|  | 2352 | // withing a class, an enum within a class), so parse any needed | 
|  | 2353 | // parent DIEs before we get to this one... | 
|  | 2354 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); | 
|  | 2355 | switch (decl_ctx_die->Tag()) | 
|  | 2356 | { | 
|  | 2357 | case DW_TAG_structure_type: | 
|  | 2358 | case DW_TAG_union_type: | 
|  | 2359 | case DW_TAG_class_type: | 
|  | 2360 | { | 
|  | 2361 | // Get the type, which could be a forward declaration | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2362 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2363 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2364 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x", | 
|  | 2365 | die->GetOffset(), | 
|  | 2366 | DW_TAG_value_to_name(die->Tag()), | 
|  | 2367 | die->GetName(this, cu), | 
|  | 2368 | decl_ctx_die->GetOffset()); | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2369 | // | 
|  | 2370 | //                Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed); | 
|  | 2371 | //                if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag())) | 
|  | 2372 | //                { | 
|  | 2373 | //                    if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2374 | //                        GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2375 | //                                                                  "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function", | 
|  | 2376 | //                                                                  die->GetOffset(), | 
|  | 2377 | //                                                                  DW_TAG_value_to_name(die->Tag()), | 
|  | 2378 | //                                                                  die->GetName(this, cu), | 
|  | 2379 | //                                                                  decl_ctx_die->GetOffset()); | 
|  | 2380 | //                    // Ask the type to complete itself if it already hasn't since if we | 
|  | 2381 | //                    // want a function (method or static) from a class, the class must | 
|  | 2382 | //                    // create itself and add it's own methods and class functions. | 
|  | 2383 | //                    if (parent_type) | 
|  | 2384 | //                        parent_type->GetClangFullType(); | 
|  | 2385 | //                } | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2386 | } | 
|  | 2387 | break; | 
|  | 2388 |  | 
|  | 2389 | default: | 
|  | 2390 | break; | 
|  | 2391 | } | 
|  | 2392 | return ResolveType (cu, die); | 
|  | 2393 | } | 
|  | 2394 | return NULL; | 
|  | 2395 | } | 
|  | 2396 |  | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2397 | // This function is used when SymbolFileDWARFDebugMap owns a bunch of | 
|  | 2398 | // SymbolFileDWARF objects to detect if this DWARF file is the one that | 
|  | 2399 | // can resolve a clang_type. | 
|  | 2400 | bool | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2401 | SymbolFileDWARF::HasForwardDeclForClangType (const ClangASTType &clang_type) | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2402 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2403 | ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers(); | 
|  | 2404 | 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] | 2405 | return die != NULL; | 
|  | 2406 | } | 
|  | 2407 |  | 
|  | 2408 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2409 | bool | 
|  | 2410 | SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (ClangASTType &clang_type) | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2411 | { | 
|  | 2412 | // 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] | 2413 | ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers(); | 
|  | 2414 | 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] | 2415 | if (die == NULL) | 
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2416 | { | 
|  | 2417 | // We have already resolved this type... | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2418 | return true; | 
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2419 | } | 
|  | 2420 | // Once we start resolving this type, remove it from the forward declaration | 
|  | 2421 | // map in case anyone child members or other types require this type to get resolved. | 
|  | 2422 | // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition | 
|  | 2423 | // are done. | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2424 | m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers.GetOpaqueQualType()); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2425 |  | 
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 2426 | // Disable external storage for this type so we don't get anymore | 
|  | 2427 | // clang::ExternalASTSource queries for this type. | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2428 | clang_type.SetHasExternalStorage (false); | 
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 2429 |  | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2430 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 2431 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2432 | DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get(); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2433 | Type *type = m_die_to_type.lookup (die); | 
|  | 2434 |  | 
|  | 2435 | const dw_tag_t tag = die->Tag(); | 
|  | 2436 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2437 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION)); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2438 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2439 | GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2440 | "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...", | 
| Greg Clayton | d61c0fc | 2012-04-23 22:55:20 +0000 | [diff] [blame] | 2441 | MakeUserID(die->GetOffset()), | 
|  | 2442 | DW_TAG_value_to_name(tag), | 
|  | 2443 | type->GetName().AsCString()); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2444 | assert (clang_type); | 
|  | 2445 | DWARFDebugInfoEntry::Attributes attributes; | 
|  | 2446 |  | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2447 | switch (tag) | 
|  | 2448 | { | 
|  | 2449 | case DW_TAG_structure_type: | 
|  | 2450 | case DW_TAG_union_type: | 
|  | 2451 | case DW_TAG_class_type: | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2452 | { | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2453 | LayoutInfo layout_info; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2454 |  | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2455 | { | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2456 | if (die->HasChildren()) | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2457 | { | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2458 | LanguageType class_language = eLanguageTypeUnknown; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2459 | if (clang_type.IsObjCObjectOrInterfaceType()) | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2460 | { | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2461 | class_language = eLanguageTypeObjC; | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2462 | // For objective C we don't start the definition when | 
|  | 2463 | // the class is created. | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2464 | clang_type.StartTagDeclarationDefinition (); | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2465 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2466 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2467 | int tag_decl_kind = -1; | 
|  | 2468 | AccessType default_accessibility = eAccessNone; | 
|  | 2469 | if (tag == DW_TAG_structure_type) | 
|  | 2470 | { | 
|  | 2471 | tag_decl_kind = clang::TTK_Struct; | 
|  | 2472 | default_accessibility = eAccessPublic; | 
|  | 2473 | } | 
|  | 2474 | else if (tag == DW_TAG_union_type) | 
|  | 2475 | { | 
|  | 2476 | tag_decl_kind = clang::TTK_Union; | 
|  | 2477 | default_accessibility = eAccessPublic; | 
|  | 2478 | } | 
|  | 2479 | else if (tag == DW_TAG_class_type) | 
|  | 2480 | { | 
|  | 2481 | tag_decl_kind = clang::TTK_Class; | 
|  | 2482 | default_accessibility = eAccessPrivate; | 
|  | 2483 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2484 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2485 | SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2486 | std::vector<clang::CXXBaseSpecifier *> base_classes; | 
|  | 2487 | std::vector<int> member_accessibilities; | 
|  | 2488 | bool is_a_class = false; | 
|  | 2489 | // Parse members and base classes first | 
|  | 2490 | DWARFDIECollection member_function_dies; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2491 |  | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2492 | DelayedPropertyList delayed_properties; | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2493 | ParseChildMembers (sc, | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2494 | dwarf_cu, | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2495 | die, | 
|  | 2496 | clang_type, | 
|  | 2497 | class_language, | 
|  | 2498 | base_classes, | 
|  | 2499 | member_accessibilities, | 
|  | 2500 | member_function_dies, | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2501 | delayed_properties, | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2502 | default_accessibility, | 
|  | 2503 | is_a_class, | 
|  | 2504 | layout_info); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2505 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2506 | // Now parse any methods if there were any... | 
|  | 2507 | size_t num_functions = member_function_dies.Size(); | 
|  | 2508 | if (num_functions > 0) | 
|  | 2509 | { | 
|  | 2510 | for (size_t i=0; i<num_functions; ++i) | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2511 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2512 | ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i)); | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2513 | } | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2514 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2515 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2516 | if (class_language == eLanguageTypeObjC) | 
|  | 2517 | { | 
| Jim Ingham | fb6fc0d | 2013-09-27 20:59:37 +0000 | [diff] [blame] | 2518 | ConstString class_name (clang_type.GetTypeName()); | 
|  | 2519 | if (class_name) | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2520 | { | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2521 | DIEArray method_die_offsets; | 
|  | 2522 | if (m_using_apple_tables) | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2523 | { | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2524 | if (m_apple_objc_ap.get()) | 
| Jim Ingham | fb6fc0d | 2013-09-27 20:59:37 +0000 | [diff] [blame] | 2525 | m_apple_objc_ap->FindByName(class_name.GetCString(), method_die_offsets); | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2526 | } | 
|  | 2527 | else | 
|  | 2528 | { | 
|  | 2529 | if (!m_indexed) | 
|  | 2530 | Index (); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2531 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2532 | m_objc_class_selectors_index.Find (class_name, method_die_offsets); | 
|  | 2533 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2534 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2535 | if (!method_die_offsets.empty()) | 
|  | 2536 | { | 
|  | 2537 | DWARFDebugInfo* debug_info = DebugInfo(); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2538 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2539 | DWARFCompileUnit* method_cu = NULL; | 
|  | 2540 | const size_t num_matches = method_die_offsets.size(); | 
|  | 2541 | for (size_t i=0; i<num_matches; ++i) | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2542 | { | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2543 | const dw_offset_t die_offset = method_die_offsets[i]; | 
|  | 2544 | DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2545 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2546 | if (method_die) | 
|  | 2547 | ResolveType (method_cu, method_die); | 
|  | 2548 | else | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2549 | { | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2550 | if (m_using_apple_tables) | 
|  | 2551 | { | 
|  | 2552 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n", | 
| Jim Ingham | fb6fc0d | 2013-09-27 20:59:37 +0000 | [diff] [blame] | 2553 | die_offset, class_name.GetCString()); | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2554 | } | 
|  | 2555 | } | 
|  | 2556 | } | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2557 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2558 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2559 | for (DelayedPropertyList::iterator pi = delayed_properties.begin(), pe = delayed_properties.end(); | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2560 | pi != pe; | 
|  | 2561 | ++pi) | 
|  | 2562 | pi->Finalize(); | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2563 | } | 
|  | 2564 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2565 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2566 | // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we | 
|  | 2567 | // need to tell the clang type it is actually a class. | 
|  | 2568 | if (class_language != eLanguageTypeObjC) | 
|  | 2569 | { | 
|  | 2570 | if (is_a_class && tag_decl_kind != clang::TTK_Class) | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2571 | clang_type.SetTagTypeKind (clang::TTK_Class); | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2572 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2573 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2574 | // Since DW_TAG_structure_type gets used for both classes | 
|  | 2575 | // and structures, we may need to set any DW_TAG_member | 
|  | 2576 | // fields to have a "private" access if none was specified. | 
|  | 2577 | // When we parsed the child members we tracked that actual | 
|  | 2578 | // accessibility value for each DW_TAG_member in the | 
|  | 2579 | // "member_accessibilities" array. If the value for the | 
|  | 2580 | // member is zero, then it was set to the "default_accessibility" | 
|  | 2581 | // which for structs was "public". Below we correct this | 
|  | 2582 | // by setting any fields to "private" that weren't correctly | 
|  | 2583 | // set. | 
|  | 2584 | if (is_a_class && !member_accessibilities.empty()) | 
|  | 2585 | { | 
|  | 2586 | // This is a class and all members that didn't have | 
|  | 2587 | // their access specified are private. | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2588 | clang_type.SetDefaultAccessForRecordFields (eAccessPrivate, | 
|  | 2589 | &member_accessibilities.front(), | 
|  | 2590 | member_accessibilities.size()); | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2591 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2592 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2593 | if (!base_classes.empty()) | 
|  | 2594 | { | 
| Greg Clayton | 4705f8d | 2013-12-12 01:54:04 +0000 | [diff] [blame] | 2595 | // Make sure all base classes refer to complete types and not | 
|  | 2596 | // forward declarations. If we don't do this, clang will crash | 
|  | 2597 | // with an assertion in the call to clang_type.SetBaseClassesForClassType() | 
|  | 2598 | bool base_class_error = false; | 
|  | 2599 | for (auto &base_class : base_classes) | 
|  | 2600 | { | 
|  | 2601 | clang::TypeSourceInfo *type_source_info = base_class->getTypeSourceInfo(); | 
|  | 2602 | if (type_source_info) | 
|  | 2603 | { | 
|  | 2604 | ClangASTType base_class_type (GetClangASTContext().getASTContext(), type_source_info->getType()); | 
|  | 2605 | if (base_class_type.GetCompleteType() == false) | 
|  | 2606 | { | 
|  | 2607 | if (!base_class_error) | 
|  | 2608 | { | 
|  | 2609 | GetObjectFile()->GetModule()->ReportError ("DWARF DIE at 0x%8.8x for class '%s' has a base class '%s' that is a forward declaration, not a complete definition.\nPlease file a bug against the compiler and include the preprocessed output for %s", | 
|  | 2610 | die->GetOffset(), | 
|  | 2611 | die->GetName(this, dwarf_cu), | 
|  | 2612 | base_class_type.GetTypeName().GetCString(), | 
|  | 2613 | sc.comp_unit ? sc.comp_unit->GetPath().c_str() : "the source file"); | 
|  | 2614 | } | 
|  | 2615 | // We have no choice other than to pretend that the base class | 
|  | 2616 | // is complete. If we don't do this, clang will crash when we | 
|  | 2617 | // call setBases() inside of "clang_type.SetBaseClassesForClassType()" | 
|  | 2618 | // below. Since we provide layout assistance, all ivars in this | 
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 2619 | // class and other classes will be fine, this is the best we can do | 
| Greg Clayton | 4705f8d | 2013-12-12 01:54:04 +0000 | [diff] [blame] | 2620 | // short of crashing. | 
|  | 2621 | base_class_type.StartTagDeclarationDefinition (); | 
|  | 2622 | base_class_type.CompleteTagDeclarationDefinition (); | 
|  | 2623 | } | 
|  | 2624 | } | 
|  | 2625 | } | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2626 | clang_type.SetBaseClassesForClassType (&base_classes.front(), | 
|  | 2627 | base_classes.size()); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2628 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2629 | // Clang will copy each CXXBaseSpecifier in "base_classes" | 
|  | 2630 | // so we have to free them all. | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2631 | ClangASTType::DeleteBaseClassSpecifiers (&base_classes.front(), | 
|  | 2632 | base_classes.size()); | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2633 | } | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2634 | } | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2635 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2636 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2637 | clang_type.BuildIndirectFields (); | 
|  | 2638 | clang_type.CompleteTagDeclarationDefinition (); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2639 |  | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2640 | if (!layout_info.field_offsets.empty() || | 
|  | 2641 | !layout_info.base_offsets.empty()  || | 
|  | 2642 | !layout_info.vbase_offsets.empty() ) | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2643 | { | 
|  | 2644 | if (type) | 
|  | 2645 | layout_info.bit_size = type->GetByteSize() * 8; | 
|  | 2646 | if (layout_info.bit_size == 0) | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2647 | layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2648 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2649 | clang::CXXRecordDecl *record_decl = clang_type.GetAsCXXRecordDecl(); | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2650 | if (record_decl) | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2651 | { | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2652 | if (log) | 
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2653 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2654 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2655 | "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) caching layout info for record_decl = %p, bit_size = %" PRIu64 ", alignment = %" PRIu64 ", field_offsets[%u], base_offsets[%u], vbase_offsets[%u])", | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2656 | static_cast<void*>(clang_type.GetOpaqueQualType()), | 
|  | 2657 | static_cast<void*>(record_decl), | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2658 | layout_info.bit_size, | 
|  | 2659 | layout_info.alignment, | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2660 | static_cast<uint32_t>(layout_info.field_offsets.size()), | 
|  | 2661 | static_cast<uint32_t>(layout_info.base_offsets.size()), | 
|  | 2662 | static_cast<uint32_t>(layout_info.vbase_offsets.size())); | 
|  | 2663 |  | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2664 | uint32_t idx; | 
|  | 2665 | { | 
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2666 | 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] | 2667 | 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] | 2668 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2669 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2670 | "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = { bit_offset=%u, name='%s' }", | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2671 | static_cast<void*>(clang_type.GetOpaqueQualType()), | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2672 | idx, | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2673 | static_cast<uint32_t>(pos->second), | 
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2674 | pos->first->getNameAsString().c_str()); | 
|  | 2675 | } | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2676 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2677 |  | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2678 | { | 
|  | 2679 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos, base_end = layout_info.base_offsets.end(); | 
|  | 2680 | for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end; ++base_pos, ++idx) | 
|  | 2681 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2682 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2683 | "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] = { byte_offset=%u, name='%s' }", | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2684 | clang_type.GetOpaqueQualType(), | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2685 | idx, | 
|  | 2686 | (uint32_t)base_pos->second.getQuantity(), | 
|  | 2687 | base_pos->first->getNameAsString().c_str()); | 
|  | 2688 | } | 
|  | 2689 | } | 
|  | 2690 | { | 
|  | 2691 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos, vbase_end = layout_info.vbase_offsets.end(); | 
|  | 2692 | for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end; ++vbase_pos, ++idx) | 
|  | 2693 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2694 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2695 | "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) vbase[%u] = { byte_offset=%u, name='%s' }", | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2696 | static_cast<void*>(clang_type.GetOpaqueQualType()), | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2697 | idx, | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2698 | static_cast<uint32_t>(vbase_pos->second.getQuantity()), | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2699 | vbase_pos->first->getNameAsString().c_str()); | 
|  | 2700 | } | 
|  | 2701 | } | 
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2702 | } | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2703 | m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info)); | 
|  | 2704 | } | 
|  | 2705 | } | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2706 | } | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2707 |  | 
| Sean Callanan | 9076c0f | 2013-10-04 21:35:29 +0000 | [diff] [blame] | 2708 | return (bool)clang_type; | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2709 |  | 
|  | 2710 | case DW_TAG_enumeration_type: | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2711 | clang_type.StartTagDeclarationDefinition (); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2712 | if (die->HasChildren()) | 
|  | 2713 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2714 | SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); | 
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 2715 | bool is_signed = false; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2716 | clang_type.IsIntegerType(is_signed); | 
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 2717 | ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), dwarf_cu, die); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2718 | } | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2719 | clang_type.CompleteTagDeclarationDefinition (); | 
| Sean Callanan | 9076c0f | 2013-10-04 21:35:29 +0000 | [diff] [blame] | 2720 | return (bool)clang_type; | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2721 |  | 
|  | 2722 | default: | 
|  | 2723 | assert(false && "not a forward clang type decl!"); | 
|  | 2724 | break; | 
|  | 2725 | } | 
| Ashok Thirumurthi | a4658a5 | 2013-07-30 14:58:39 +0000 | [diff] [blame] | 2726 | return false; | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2727 | } | 
|  | 2728 |  | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2729 | Type* | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2730 | 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] | 2731 | { | 
|  | 2732 | if (type_die != NULL) | 
|  | 2733 | { | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 2734 | Type *type = m_die_to_type.lookup (type_die); | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2735 |  | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2736 | if (type == NULL) | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2737 | type = GetTypeForDIE (dwarf_cu, type_die).get(); | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2738 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2739 | if (assert_not_being_parsed) | 
| Jim Ingham | c354928 | 2012-01-11 02:21:12 +0000 | [diff] [blame] | 2740 | { | 
|  | 2741 | if (type != DIE_IS_BEING_PARSED) | 
|  | 2742 | return type; | 
|  | 2743 |  | 
|  | 2744 | 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] | 2745 | type_die->GetOffset(), | 
|  | 2746 | DW_TAG_value_to_name(type_die->Tag()), | 
|  | 2747 | type_die->GetName(this, dwarf_cu)); | 
| Jim Ingham | c354928 | 2012-01-11 02:21:12 +0000 | [diff] [blame] | 2748 |  | 
|  | 2749 | } | 
|  | 2750 | else | 
|  | 2751 | return type; | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2752 | } | 
|  | 2753 | return NULL; | 
|  | 2754 | } | 
|  | 2755 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2756 | CompileUnit* | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2757 | SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2758 | { | 
|  | 2759 | // Check if the symbol vendor already knows about this compile unit? | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2760 | if (dwarf_cu->GetUserData() == NULL) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2761 | { | 
|  | 2762 | // The symbol vendor doesn't know about this compile unit, we | 
|  | 2763 | // need to parse and add it to the symbol vendor object. | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2764 | return ParseCompileUnit(dwarf_cu, cu_idx).get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2765 | } | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2766 | return (CompileUnit*)dwarf_cu->GetUserData(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2767 | } | 
|  | 2768 |  | 
|  | 2769 | bool | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2770 | SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2771 | { | 
| Greg Clayton | 7231035 | 2013-02-23 04:12:47 +0000 | [diff] [blame] | 2772 | sc.Clear(false); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2773 | // Check if the symbol vendor already knows about this compile unit? | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2774 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2775 |  | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2776 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2777 | if (sc.function == NULL) | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2778 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2779 |  | 
|  | 2780 | if (sc.function) | 
|  | 2781 | { | 
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 2782 | sc.module_sp = sc.function->CalculateSymbolContextModule(); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2783 | return true; | 
|  | 2784 | } | 
|  | 2785 |  | 
|  | 2786 | return false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2787 | } | 
|  | 2788 |  | 
|  | 2789 | uint32_t | 
|  | 2790 | SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) | 
|  | 2791 | { | 
|  | 2792 | Timer scoped_timer(__PRETTY_FUNCTION__, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2793 | "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%" PRIx64 " }, resolve_scope = 0x%8.8x)", | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2794 | static_cast<void*>(so_addr.GetSection().get()), | 
|  | 2795 | so_addr.GetOffset(), resolve_scope); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2796 | uint32_t resolved = 0; | 
|  | 2797 | if (resolve_scope & (   eSymbolContextCompUnit | | 
|  | 2798 | eSymbolContextFunction | | 
|  | 2799 | eSymbolContextBlock | | 
|  | 2800 | eSymbolContextLineEntry)) | 
|  | 2801 | { | 
|  | 2802 | lldb::addr_t file_vm_addr = so_addr.GetFileAddress(); | 
|  | 2803 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2804 | DWARFDebugInfo* debug_info = DebugInfo(); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2805 | if (debug_info) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2806 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2807 | 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] | 2808 | if (cu_offset != DW_INVALID_OFFSET) | 
|  | 2809 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2810 | uint32_t cu_idx = DW_INVALID_INDEX; | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2811 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get(); | 
|  | 2812 | if (dwarf_cu) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2813 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2814 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2815 | if (sc.comp_unit) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2816 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2817 | resolved |= eSymbolContextCompUnit; | 
|  | 2818 |  | 
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2819 | bool force_check_line_table = false; | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2820 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) | 
|  | 2821 | { | 
|  | 2822 | DWARFDebugInfoEntry *function_die = NULL; | 
|  | 2823 | DWARFDebugInfoEntry *block_die = NULL; | 
|  | 2824 | if (resolve_scope & eSymbolContextBlock) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2825 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2826 | dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die); | 
|  | 2827 | } | 
|  | 2828 | else | 
|  | 2829 | { | 
|  | 2830 | dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL); | 
|  | 2831 | } | 
|  | 2832 |  | 
|  | 2833 | if (function_die != NULL) | 
|  | 2834 | { | 
|  | 2835 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); | 
|  | 2836 | if (sc.function == NULL) | 
|  | 2837 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die); | 
|  | 2838 | } | 
|  | 2839 | else | 
|  | 2840 | { | 
|  | 2841 | // We might have had a compile unit that had discontiguous | 
|  | 2842 | // address ranges where the gaps are symbols that don't have | 
|  | 2843 | // any debug info. Discontiguous compile unit address ranges | 
|  | 2844 | // should only happen when there aren't other functions from | 
|  | 2845 | // other compile units in these gaps. This helps keep the size | 
|  | 2846 | // of the aranges down. | 
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2847 | force_check_line_table = true; | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2848 | } | 
|  | 2849 |  | 
|  | 2850 | if (sc.function != NULL) | 
|  | 2851 | { | 
|  | 2852 | resolved |= eSymbolContextFunction; | 
|  | 2853 |  | 
|  | 2854 | if (resolve_scope & eSymbolContextBlock) | 
|  | 2855 | { | 
|  | 2856 | Block& block = sc.function->GetBlock (true); | 
|  | 2857 |  | 
|  | 2858 | if (block_die != NULL) | 
|  | 2859 | sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); | 
|  | 2860 | else | 
|  | 2861 | sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); | 
|  | 2862 | if (sc.block) | 
|  | 2863 | resolved |= eSymbolContextBlock; | 
|  | 2864 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2865 | } | 
|  | 2866 | } | 
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2867 |  | 
|  | 2868 | if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table) | 
|  | 2869 | { | 
|  | 2870 | LineTable *line_table = sc.comp_unit->GetLineTable(); | 
|  | 2871 | if (line_table != NULL) | 
|  | 2872 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 2873 | // And address that makes it into this function should be in terms | 
|  | 2874 | // of this debug file if there is no debug map, or it will be an | 
|  | 2875 | // address in the .o file which needs to be fixed up to be in terms | 
|  | 2876 | // of the debug map executable. Either way, calling FixupAddress() | 
|  | 2877 | // will work for us. | 
|  | 2878 | Address exe_so_addr (so_addr); | 
|  | 2879 | if (FixupAddress(exe_so_addr)) | 
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2880 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 2881 | if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry)) | 
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2882 | { | 
|  | 2883 | resolved |= eSymbolContextLineEntry; | 
|  | 2884 | } | 
|  | 2885 | } | 
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2886 | } | 
|  | 2887 | } | 
|  | 2888 |  | 
|  | 2889 | if (force_check_line_table && !(resolved & eSymbolContextLineEntry)) | 
|  | 2890 | { | 
|  | 2891 | // We might have had a compile unit that had discontiguous | 
|  | 2892 | // address ranges where the gaps are symbols that don't have | 
|  | 2893 | // any debug info. Discontiguous compile unit address ranges | 
|  | 2894 | // should only happen when there aren't other functions from | 
|  | 2895 | // other compile units in these gaps. This helps keep the size | 
|  | 2896 | // of the aranges down. | 
|  | 2897 | sc.comp_unit = NULL; | 
|  | 2898 | resolved &= ~eSymbolContextCompUnit; | 
|  | 2899 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2900 | } | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2901 | else | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2902 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2903 | GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.", | 
|  | 2904 | cu_offset, | 
|  | 2905 | cu_idx); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2906 | } | 
|  | 2907 | } | 
|  | 2908 | } | 
|  | 2909 | } | 
|  | 2910 | } | 
|  | 2911 | return resolved; | 
|  | 2912 | } | 
|  | 2913 |  | 
|  | 2914 |  | 
|  | 2915 |  | 
|  | 2916 | uint32_t | 
|  | 2917 | SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) | 
|  | 2918 | { | 
|  | 2919 | const uint32_t prev_size = sc_list.GetSize(); | 
|  | 2920 | if (resolve_scope & eSymbolContextCompUnit) | 
|  | 2921 | { | 
|  | 2922 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 2923 | if (debug_info) | 
|  | 2924 | { | 
|  | 2925 | uint32_t cu_idx; | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2926 | DWARFCompileUnit* dwarf_cu = NULL; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2927 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2928 | 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] | 2929 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2930 | CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); | 
| Sean Callanan | ddd7a2a | 2013-10-03 22:27:29 +0000 | [diff] [blame] | 2931 | const bool full_match = (bool)file_spec.GetDirectory(); | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 2932 | 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] | 2933 | if (check_inlines || file_spec_matches_cu_file_spec) | 
|  | 2934 | { | 
|  | 2935 | SymbolContext sc (m_obj_file->GetModule()); | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2936 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2937 | if (sc.comp_unit) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2938 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2939 | uint32_t file_idx = UINT32_MAX; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2940 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2941 | // If we are looking for inline functions only and we don't | 
|  | 2942 | // find it in the support files, we are done. | 
|  | 2943 | if (check_inlines) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2944 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2945 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); | 
|  | 2946 | if (file_idx == UINT32_MAX) | 
|  | 2947 | continue; | 
|  | 2948 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2949 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2950 | if (line != 0) | 
|  | 2951 | { | 
|  | 2952 | LineTable *line_table = sc.comp_unit->GetLineTable(); | 
|  | 2953 |  | 
|  | 2954 | if (line_table != NULL && line != 0) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2955 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2956 | // We will have already looked up the file index if | 
|  | 2957 | // we are searching for inline entries. | 
|  | 2958 | if (!check_inlines) | 
|  | 2959 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2960 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2961 | if (file_idx != UINT32_MAX) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2962 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2963 | uint32_t found_line; | 
|  | 2964 | uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry); | 
|  | 2965 | found_line = sc.line_entry.line; | 
|  | 2966 |  | 
|  | 2967 | while (line_idx != UINT32_MAX) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2968 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2969 | sc.function = NULL; | 
|  | 2970 | sc.block = NULL; | 
|  | 2971 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2972 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2973 | const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress(); | 
|  | 2974 | if (file_vm_addr != LLDB_INVALID_ADDRESS) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2975 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2976 | DWARFDebugInfoEntry *function_die = NULL; | 
|  | 2977 | DWARFDebugInfoEntry *block_die = NULL; | 
|  | 2978 | 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] | 2979 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2980 | if (function_die != NULL) | 
|  | 2981 | { | 
|  | 2982 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); | 
|  | 2983 | if (sc.function == NULL) | 
|  | 2984 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die); | 
|  | 2985 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2986 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2987 | if (sc.function != NULL) | 
|  | 2988 | { | 
|  | 2989 | Block& block = sc.function->GetBlock (true); | 
|  | 2990 |  | 
|  | 2991 | if (block_die != NULL) | 
|  | 2992 | sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); | 
| Jason Molenda | 60db6e4 | 2014-10-16 01:40:16 +0000 | [diff] [blame] | 2993 | else if (function_die != NULL) | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2994 | sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); | 
|  | 2995 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2996 | } | 
|  | 2997 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2998 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2999 | sc_list.Append(sc); | 
|  | 3000 | line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry); | 
|  | 3001 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3002 | } | 
|  | 3003 | } | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3004 | else if (file_spec_matches_cu_file_spec && !check_inlines) | 
|  | 3005 | { | 
|  | 3006 | // only append the context if we aren't looking for inline call sites | 
|  | 3007 | // by file and line and if the file spec matches that of the compile unit | 
|  | 3008 | sc_list.Append(sc); | 
|  | 3009 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3010 | } | 
|  | 3011 | else if (file_spec_matches_cu_file_spec && !check_inlines) | 
|  | 3012 | { | 
|  | 3013 | // only append the context if we aren't looking for inline call sites | 
|  | 3014 | // by file and line and if the file spec matches that of the compile unit | 
|  | 3015 | sc_list.Append(sc); | 
|  | 3016 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3017 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3018 | if (!check_inlines) | 
|  | 3019 | break; | 
|  | 3020 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3021 | } | 
|  | 3022 | } | 
|  | 3023 | } | 
|  | 3024 | } | 
|  | 3025 | return sc_list.GetSize() - prev_size; | 
|  | 3026 | } | 
|  | 3027 |  | 
|  | 3028 | void | 
|  | 3029 | SymbolFileDWARF::Index () | 
|  | 3030 | { | 
|  | 3031 | if (m_indexed) | 
|  | 3032 | return; | 
|  | 3033 | m_indexed = true; | 
|  | 3034 | Timer scoped_timer (__PRETTY_FUNCTION__, | 
|  | 3035 | "SymbolFileDWARF::Index (%s)", | 
| Jim Ingham | 4af5961 | 2014-12-19 19:20:44 +0000 | [diff] [blame^] | 3036 | GetObjectFile()->GetFileSpec().GetFilename().AsCString("<Unknown>")); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3037 |  | 
|  | 3038 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 3039 | if (debug_info) | 
|  | 3040 | { | 
|  | 3041 | uint32_t cu_idx = 0; | 
|  | 3042 | const uint32_t num_compile_units = GetNumCompileUnits(); | 
|  | 3043 | for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) | 
|  | 3044 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3045 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3046 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3047 | bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3048 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3049 | dwarf_cu->Index (cu_idx, | 
|  | 3050 | m_function_basename_index, | 
|  | 3051 | m_function_fullname_index, | 
|  | 3052 | m_function_method_index, | 
|  | 3053 | m_function_selector_index, | 
|  | 3054 | m_objc_class_selectors_index, | 
|  | 3055 | m_global_index, | 
|  | 3056 | m_type_index, | 
|  | 3057 | m_namespace_index); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3058 |  | 
|  | 3059 | // Keep memory down by clearing DIEs if this generate function | 
|  | 3060 | // caused them to be parsed | 
|  | 3061 | if (clear_dies) | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3062 | dwarf_cu->ClearDIEs (true); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3063 | } | 
|  | 3064 |  | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3065 | m_function_basename_index.Finalize(); | 
|  | 3066 | m_function_fullname_index.Finalize(); | 
|  | 3067 | m_function_method_index.Finalize(); | 
|  | 3068 | m_function_selector_index.Finalize(); | 
|  | 3069 | m_objc_class_selectors_index.Finalize(); | 
|  | 3070 | m_global_index.Finalize(); | 
|  | 3071 | m_type_index.Finalize(); | 
|  | 3072 | m_namespace_index.Finalize(); | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3073 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3074 | #if defined (ENABLE_DEBUG_PRINTF) | 
| Greg Clayton | 7bd65b9 | 2011-02-09 23:39:34 +0000 | [diff] [blame] | 3075 | StreamFile s(stdout, false); | 
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 3076 | s.Printf ("DWARF index for '%s':", | 
|  | 3077 | GetObjectFile()->GetFileSpec().GetPath().c_str()); | 
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 3078 | s.Printf("\nFunction basenames:\n");    m_function_basename_index.Dump (&s); | 
|  | 3079 | s.Printf("\nFunction fullnames:\n");    m_function_fullname_index.Dump (&s); | 
|  | 3080 | s.Printf("\nFunction methods:\n");      m_function_method_index.Dump (&s); | 
|  | 3081 | s.Printf("\nFunction selectors:\n");    m_function_selector_index.Dump (&s); | 
|  | 3082 | s.Printf("\nObjective C class selectors:\n");    m_objc_class_selectors_index.Dump (&s); | 
|  | 3083 | s.Printf("\nGlobals and statics:\n");   m_global_index.Dump (&s); | 
| Greg Clayton | 69b0488 | 2010-10-15 02:03:22 +0000 | [diff] [blame] | 3084 | s.Printf("\nTypes:\n");                 m_type_index.Dump (&s); | 
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 3085 | s.Printf("\nNamepaces:\n");             m_namespace_index.Dump (&s); | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3086 | #endif | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3087 | } | 
|  | 3088 | } | 
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 3089 |  | 
|  | 3090 | bool | 
|  | 3091 | SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl) | 
|  | 3092 | { | 
|  | 3093 | if (namespace_decl == NULL) | 
|  | 3094 | { | 
|  | 3095 | // Invalid namespace decl which means we aren't matching only things | 
|  | 3096 | // in this symbol file, so return true to indicate it matches this | 
|  | 3097 | // symbol file. | 
|  | 3098 | return true; | 
|  | 3099 | } | 
|  | 3100 |  | 
|  | 3101 | clang::ASTContext *namespace_ast = namespace_decl->GetASTContext(); | 
|  | 3102 |  | 
|  | 3103 | if (namespace_ast == NULL) | 
|  | 3104 | return true;    // No AST in the "namespace_decl", return true since it | 
|  | 3105 | // could then match any symbol file, including this one | 
|  | 3106 |  | 
|  | 3107 | if (namespace_ast == GetClangASTContext().getASTContext()) | 
|  | 3108 | return true;    // The ASTs match, return true | 
|  | 3109 |  | 
|  | 3110 | // The namespace AST was valid, and it does not match... | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3111 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Sean Callanan | c41e68b | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 3112 |  | 
|  | 3113 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3114 | GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file"); | 
| Sean Callanan | c41e68b | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 3115 |  | 
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 3116 | return false; | 
|  | 3117 | } | 
|  | 3118 |  | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3119 | bool | 
|  | 3120 | SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl, | 
|  | 3121 | DWARFCompileUnit* cu, | 
|  | 3122 | const DWARFDebugInfoEntry* die) | 
|  | 3123 | { | 
| Bruce Mitchener | aaa0ba3 | 2014-07-08 18:05:41 +0000 | [diff] [blame] | 3124 | // No namespace specified, so the answer is | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3125 | if (namespace_decl == NULL) | 
|  | 3126 | return true; | 
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 3127 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3128 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 3129 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3130 | const DWARFDebugInfoEntry *decl_ctx_die = NULL; | 
|  | 3131 | clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die); | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3132 | if (decl_ctx_die) | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3133 | { | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3134 | clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl(); | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3135 |  | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3136 | if (clang_namespace_decl) | 
|  | 3137 | { | 
|  | 3138 | if (decl_ctx_die->Tag() != DW_TAG_namespace) | 
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 3139 | { | 
|  | 3140 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3141 | 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] | 3142 | return false; | 
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 3143 | } | 
|  | 3144 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3145 | if (clang_namespace_decl == die_clang_decl_ctx) | 
|  | 3146 | return true; | 
|  | 3147 | else | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3148 | return false; | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3149 | } | 
|  | 3150 | else | 
|  | 3151 | { | 
|  | 3152 | // We have a namespace_decl that was not NULL but it contained | 
|  | 3153 | // a NULL "clang::NamespaceDecl", so this means the global namespace | 
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 3154 | // So as long the contained decl context DIE isn't a namespace | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3155 | // we should be ok. | 
|  | 3156 | if (decl_ctx_die->Tag() != DW_TAG_namespace) | 
|  | 3157 | return true; | 
|  | 3158 | } | 
|  | 3159 | } | 
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 3160 |  | 
|  | 3161 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3162 | 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] | 3163 |  | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3164 | return false; | 
|  | 3165 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3166 | uint32_t | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3167 | 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] | 3168 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3169 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3170 |  | 
|  | 3171 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3172 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3173 | "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)", | 
|  | 3174 | name.GetCString(), | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3175 | static_cast<const void*>(namespace_decl), | 
|  | 3176 | append, max_matches); | 
|  | 3177 |  | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3178 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) | 
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 3179 | return 0; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3180 |  | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3181 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 3182 | if (info == NULL) | 
|  | 3183 | return 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3184 |  | 
|  | 3185 | // If we aren't appending the results to this list, then clear the list | 
|  | 3186 | if (!append) | 
|  | 3187 | variables.Clear(); | 
|  | 3188 |  | 
|  | 3189 | // Remember how many variables are in the list before we search in case | 
|  | 3190 | // we are appending the results to a variable list. | 
|  | 3191 | const uint32_t original_size = variables.GetSize(); | 
|  | 3192 |  | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3193 | DIEArray die_offsets; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3194 |  | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3195 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3196 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3197 | if (m_apple_names_ap.get()) | 
|  | 3198 | { | 
|  | 3199 | const char *name_cstr = name.GetCString(); | 
| Jim Ingham | fa39bb4 | 2014-10-25 00:33:55 +0000 | [diff] [blame] | 3200 | llvm::StringRef basename; | 
|  | 3201 | llvm::StringRef context; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3202 |  | 
| Jim Ingham | fa39bb4 | 2014-10-25 00:33:55 +0000 | [diff] [blame] | 3203 | if (!CPPLanguageRuntime::ExtractContextAndIdentifier(name_cstr, context, basename)) | 
|  | 3204 | basename = name_cstr; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3205 |  | 
| Jim Ingham | fa39bb4 | 2014-10-25 00:33:55 +0000 | [diff] [blame] | 3206 | m_apple_names_ap->FindByName (basename.data(), die_offsets); | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3207 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3208 | } | 
|  | 3209 | else | 
|  | 3210 | { | 
|  | 3211 | // Index the DWARF if we haven't already | 
|  | 3212 | if (!m_indexed) | 
|  | 3213 | Index (); | 
|  | 3214 |  | 
|  | 3215 | m_global_index.Find (name, die_offsets); | 
|  | 3216 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3217 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3218 | const size_t num_die_matches = die_offsets.size(); | 
|  | 3219 | if (num_die_matches) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3220 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3221 | SymbolContext sc; | 
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 3222 | sc.module_sp = m_obj_file->GetModule(); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3223 | assert (sc.module_sp); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3224 |  | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3225 | DWARFDebugInfo* debug_info = DebugInfo(); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3226 | DWARFCompileUnit* dwarf_cu = NULL; | 
|  | 3227 | const DWARFDebugInfoEntry* die = NULL; | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3228 | bool done = false; | 
|  | 3229 | for (size_t i=0; i<num_die_matches && !done; ++i) | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3230 | { | 
|  | 3231 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 3232 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3233 |  | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3234 | if (die) | 
|  | 3235 | { | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3236 | switch (die->Tag()) | 
|  | 3237 | { | 
|  | 3238 | default: | 
|  | 3239 | case DW_TAG_subprogram: | 
|  | 3240 | case DW_TAG_inlined_subroutine: | 
|  | 3241 | case DW_TAG_try_block: | 
|  | 3242 | case DW_TAG_catch_block: | 
|  | 3243 | break; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3244 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3245 | case DW_TAG_variable: | 
|  | 3246 | { | 
|  | 3247 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3248 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3249 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) | 
|  | 3250 | continue; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3251 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3252 | ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3253 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3254 | if (variables.GetSize() - original_size >= max_matches) | 
|  | 3255 | done = true; | 
|  | 3256 | } | 
|  | 3257 | break; | 
|  | 3258 | } | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3259 | } | 
|  | 3260 | else | 
|  | 3261 | { | 
|  | 3262 | if (m_using_apple_tables) | 
|  | 3263 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3264 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n", | 
|  | 3265 | die_offset, name.GetCString()); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3266 | } | 
|  | 3267 | } | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3268 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3269 | } | 
|  | 3270 |  | 
|  | 3271 | // Return the number of variable that were appended to the list | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3272 | const uint32_t num_matches = variables.GetSize() - original_size; | 
|  | 3273 | if (log && num_matches > 0) | 
|  | 3274 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3275 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3276 | "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u", | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3277 | name.GetCString(), | 
|  | 3278 | static_cast<const void*>(namespace_decl), | 
|  | 3279 | append, max_matches, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3280 | num_matches); | 
|  | 3281 | } | 
|  | 3282 | return num_matches; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3283 | } | 
|  | 3284 |  | 
|  | 3285 | uint32_t | 
|  | 3286 | SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables) | 
|  | 3287 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3288 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3289 |  | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3290 | if (log) | 
|  | 3291 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3292 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3293 | "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)", | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3294 | regex.GetText(), append, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3295 | max_matches); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3296 | } | 
|  | 3297 |  | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3298 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 3299 | if (info == NULL) | 
|  | 3300 | return 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3301 |  | 
|  | 3302 | // If we aren't appending the results to this list, then clear the list | 
|  | 3303 | if (!append) | 
|  | 3304 | variables.Clear(); | 
|  | 3305 |  | 
|  | 3306 | // Remember how many variables are in the list before we search in case | 
|  | 3307 | // we are appending the results to a variable list. | 
|  | 3308 | const uint32_t original_size = variables.GetSize(); | 
|  | 3309 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3310 | DIEArray die_offsets; | 
|  | 3311 |  | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3312 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3313 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3314 | if (m_apple_names_ap.get()) | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3315 | { | 
|  | 3316 | DWARFMappedHash::DIEInfoArray hash_data_array; | 
|  | 3317 | if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) | 
|  | 3318 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); | 
|  | 3319 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3320 | } | 
|  | 3321 | else | 
|  | 3322 | { | 
|  | 3323 | // Index the DWARF if we haven't already | 
|  | 3324 | if (!m_indexed) | 
|  | 3325 | Index (); | 
|  | 3326 |  | 
|  | 3327 | m_global_index.Find (regex, die_offsets); | 
|  | 3328 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3329 |  | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3330 | SymbolContext sc; | 
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 3331 | sc.module_sp = m_obj_file->GetModule(); | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3332 | assert (sc.module_sp); | 
|  | 3333 |  | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3334 | DWARFCompileUnit* dwarf_cu = NULL; | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3335 | const DWARFDebugInfoEntry* die = NULL; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3336 | const size_t num_matches = die_offsets.size(); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3337 | if (num_matches) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3338 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3339 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 3340 | for (size_t i=0; i<num_matches; ++i) | 
|  | 3341 | { | 
|  | 3342 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 3343 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3344 |  | 
|  | 3345 | if (die) | 
|  | 3346 | { | 
|  | 3347 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3348 |  | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3349 | ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3350 |  | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3351 | if (variables.GetSize() - original_size >= max_matches) | 
|  | 3352 | break; | 
|  | 3353 | } | 
|  | 3354 | else | 
|  | 3355 | { | 
|  | 3356 | if (m_using_apple_tables) | 
|  | 3357 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3358 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n", | 
|  | 3359 | die_offset, regex.GetText()); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3360 | } | 
|  | 3361 | } | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3362 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3363 | } | 
|  | 3364 |  | 
|  | 3365 | // Return the number of variable that were appended to the list | 
|  | 3366 | return variables.GetSize() - original_size; | 
|  | 3367 | } | 
|  | 3368 |  | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3369 |  | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3370 | bool | 
|  | 3371 | SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset, | 
|  | 3372 | DWARFCompileUnit *&dwarf_cu, | 
|  | 3373 | SymbolContextList& sc_list) | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3374 | { | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3375 | const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
|  | 3376 | return ResolveFunction (dwarf_cu, die, sc_list); | 
|  | 3377 | } | 
|  | 3378 |  | 
|  | 3379 |  | 
|  | 3380 | bool | 
|  | 3381 | SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu, | 
|  | 3382 | const DWARFDebugInfoEntry *die, | 
|  | 3383 | SymbolContextList& sc_list) | 
|  | 3384 | { | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3385 | SymbolContext sc; | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3386 |  | 
|  | 3387 | if (die == NULL) | 
|  | 3388 | return false; | 
|  | 3389 |  | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3390 | // If we were passed a die that is not a function, just return false... | 
|  | 3391 | if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine) | 
|  | 3392 | return false; | 
|  | 3393 |  | 
|  | 3394 | const DWARFDebugInfoEntry* inlined_die = NULL; | 
|  | 3395 | if (die->Tag() == DW_TAG_inlined_subroutine) | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3396 | { | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3397 | inlined_die = die; | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3398 |  | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3399 | while ((die = die->GetParent()) != NULL) | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3400 | { | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3401 | if (die->Tag() == DW_TAG_subprogram) | 
|  | 3402 | break; | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3403 | } | 
|  | 3404 | } | 
| Jason Molenda | 60db6e4 | 2014-10-16 01:40:16 +0000 | [diff] [blame] | 3405 | assert (die && die->Tag() == DW_TAG_subprogram); | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3406 | if (GetFunction (cu, die, sc)) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3407 | { | 
|  | 3408 | Address addr; | 
|  | 3409 | // Parse all blocks if needed | 
|  | 3410 | if (inlined_die) | 
|  | 3411 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 3412 | sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset())); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3413 | assert (sc.block != NULL); | 
|  | 3414 | if (sc.block->GetStartAddress (addr) == false) | 
|  | 3415 | addr.Clear(); | 
|  | 3416 | } | 
|  | 3417 | else | 
|  | 3418 | { | 
|  | 3419 | sc.block = NULL; | 
|  | 3420 | addr = sc.function->GetAddressRange().GetBaseAddress(); | 
|  | 3421 | } | 
|  | 3422 |  | 
|  | 3423 | if (addr.IsValid()) | 
|  | 3424 | { | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3425 | sc_list.Append(sc); | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3426 | return true; | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3427 | } | 
|  | 3428 | } | 
|  | 3429 |  | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3430 | return false; | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3431 | } | 
|  | 3432 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3433 | void | 
|  | 3434 | SymbolFileDWARF::FindFunctions (const ConstString &name, | 
|  | 3435 | const NameToDIE &name_to_die, | 
|  | 3436 | SymbolContextList& sc_list) | 
|  | 3437 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3438 | DIEArray die_offsets; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3439 | if (name_to_die.Find (name, die_offsets)) | 
|  | 3440 | { | 
|  | 3441 | ParseFunctions (die_offsets, sc_list); | 
|  | 3442 | } | 
|  | 3443 | } | 
|  | 3444 |  | 
|  | 3445 |  | 
|  | 3446 | void | 
|  | 3447 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, | 
|  | 3448 | const NameToDIE &name_to_die, | 
|  | 3449 | SymbolContextList& sc_list) | 
|  | 3450 | { | 
|  | 3451 | DIEArray die_offsets; | 
|  | 3452 | if (name_to_die.Find (regex, die_offsets)) | 
|  | 3453 | { | 
|  | 3454 | ParseFunctions (die_offsets, sc_list); | 
|  | 3455 | } | 
|  | 3456 | } | 
|  | 3457 |  | 
|  | 3458 |  | 
|  | 3459 | void | 
|  | 3460 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, | 
|  | 3461 | const DWARFMappedHash::MemoryTable &memory_table, | 
|  | 3462 | SymbolContextList& sc_list) | 
|  | 3463 | { | 
|  | 3464 | DIEArray die_offsets; | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3465 | DWARFMappedHash::DIEInfoArray hash_data_array; | 
|  | 3466 | if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3467 | { | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3468 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3469 | ParseFunctions (die_offsets, sc_list); | 
|  | 3470 | } | 
|  | 3471 | } | 
|  | 3472 |  | 
|  | 3473 | void | 
|  | 3474 | SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets, | 
|  | 3475 | SymbolContextList& sc_list) | 
|  | 3476 | { | 
|  | 3477 | const size_t num_matches = die_offsets.size(); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3478 | if (num_matches) | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3479 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3480 | SymbolContext sc; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3481 |  | 
|  | 3482 | DWARFCompileUnit* dwarf_cu = NULL; | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3483 | for (size_t i=0; i<num_matches; ++i) | 
| Greg Clayton | d7e0546 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 3484 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3485 | const dw_offset_t die_offset = die_offsets[i]; | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3486 | ResolveFunction (die_offset, dwarf_cu, sc_list); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3487 | } | 
|  | 3488 | } | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3489 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3490 |  | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3491 | bool | 
|  | 3492 | SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die, | 
|  | 3493 | const DWARFCompileUnit *dwarf_cu, | 
|  | 3494 | uint32_t name_type_mask, | 
|  | 3495 | const char *partial_name, | 
|  | 3496 | const char *base_name_start, | 
|  | 3497 | const char *base_name_end) | 
|  | 3498 | { | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3499 | // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes: | 
|  | 3500 | if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3501 | { | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 3502 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset()); | 
|  | 3503 | if (!containing_decl_ctx) | 
|  | 3504 | return false; | 
|  | 3505 |  | 
|  | 3506 | bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()); | 
|  | 3507 |  | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3508 | if (name_type_mask == eFunctionNameTypeMethod) | 
|  | 3509 | { | 
|  | 3510 | if (is_cxx_method == false) | 
|  | 3511 | return false; | 
|  | 3512 | } | 
|  | 3513 |  | 
|  | 3514 | if (name_type_mask == eFunctionNameTypeBase) | 
|  | 3515 | { | 
|  | 3516 | if (is_cxx_method == true) | 
|  | 3517 | return false; | 
|  | 3518 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3519 | } | 
|  | 3520 |  | 
|  | 3521 | // Now we need to check whether the name we got back for this type matches the extra specifications | 
|  | 3522 | // that were in the name we're looking up: | 
|  | 3523 | if (base_name_start != partial_name || *base_name_end != '\0') | 
|  | 3524 | { | 
|  | 3525 | // First see if the stuff to the left matches the full name.  To do that let's see if | 
|  | 3526 | // we can pull out the mips linkage name attribute: | 
|  | 3527 |  | 
|  | 3528 | Mangled best_name; | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3529 | DWARFDebugInfoEntry::Attributes attributes; | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3530 | DWARFFormValue form_value; | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3531 | die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
|  | 3532 | uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name); | 
| Greg Clayton | 7141554 | 2012-12-08 00:24:40 +0000 | [diff] [blame] | 3533 | if (idx == UINT32_MAX) | 
|  | 3534 | idx = attributes.FindAttributeIndex(DW_AT_linkage_name); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3535 | if (idx != UINT32_MAX) | 
|  | 3536 | { | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3537 | if (attributes.ExtractFormValueAtIndex(this, idx, form_value)) | 
|  | 3538 | { | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3539 | const char *mangled_name = form_value.AsCString(&get_debug_str_data()); | 
|  | 3540 | if (mangled_name) | 
|  | 3541 | best_name.SetValue (ConstString(mangled_name), true); | 
|  | 3542 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3543 | } | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3544 |  | 
|  | 3545 | if (!best_name) | 
|  | 3546 | { | 
|  | 3547 | idx = attributes.FindAttributeIndex(DW_AT_name); | 
|  | 3548 | if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value)) | 
|  | 3549 | { | 
|  | 3550 | const char *name = form_value.AsCString(&get_debug_str_data()); | 
|  | 3551 | best_name.SetValue (ConstString(name), false); | 
|  | 3552 | } | 
|  | 3553 | } | 
|  | 3554 |  | 
|  | 3555 | if (best_name.GetDemangledName()) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3556 | { | 
|  | 3557 | const char *demangled = best_name.GetDemangledName().GetCString(); | 
|  | 3558 | if (demangled) | 
|  | 3559 | { | 
|  | 3560 | std::string name_no_parens(partial_name, base_name_end - partial_name); | 
| Jim Ingham | 85c13d7 | 2012-03-02 02:24:42 +0000 | [diff] [blame] | 3561 | const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str()); | 
|  | 3562 | if (partial_in_demangled == NULL) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3563 | return false; | 
| Jim Ingham | 85c13d7 | 2012-03-02 02:24:42 +0000 | [diff] [blame] | 3564 | else | 
|  | 3565 | { | 
|  | 3566 | // Sort out the case where our name is something like "Process::Destroy" and the match is | 
|  | 3567 | // "SBProcess::Destroy" - that shouldn't be a match.  We should really always match on | 
|  | 3568 | // namespace boundaries... | 
|  | 3569 |  | 
|  | 3570 | if (partial_name[0] == ':'  && partial_name[1] == ':') | 
|  | 3571 | { | 
|  | 3572 | // The partial name was already on a namespace boundary so all matches are good. | 
|  | 3573 | return true; | 
|  | 3574 | } | 
|  | 3575 | else if (partial_in_demangled == demangled) | 
|  | 3576 | { | 
|  | 3577 | // They both start the same, so this is an good match. | 
|  | 3578 | return true; | 
|  | 3579 | } | 
|  | 3580 | else | 
|  | 3581 | { | 
|  | 3582 | if (partial_in_demangled - demangled == 1) | 
|  | 3583 | { | 
|  | 3584 | // Only one character difference, can't be a namespace boundary... | 
|  | 3585 | return false; | 
|  | 3586 | } | 
|  | 3587 | else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':') | 
|  | 3588 | { | 
|  | 3589 | // We are on a namespace boundary, so this is also good. | 
|  | 3590 | return true; | 
|  | 3591 | } | 
|  | 3592 | else | 
|  | 3593 | return false; | 
|  | 3594 | } | 
|  | 3595 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3596 | } | 
|  | 3597 | } | 
|  | 3598 | } | 
|  | 3599 |  | 
|  | 3600 | return true; | 
|  | 3601 | } | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3602 |  | 
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3603 | uint32_t | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3604 | SymbolFileDWARF::FindFunctions (const ConstString &name, | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3605 | const lldb_private::ClangNamespaceDecl *namespace_decl, | 
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3606 | uint32_t name_type_mask, | 
|  | 3607 | bool include_inlines, | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3608 | bool append, | 
|  | 3609 | SymbolContextList& sc_list) | 
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3610 | { | 
|  | 3611 | Timer scoped_timer (__PRETTY_FUNCTION__, | 
|  | 3612 | "SymbolFileDWARF::FindFunctions (name = '%s')", | 
|  | 3613 | name.AsCString()); | 
|  | 3614 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3615 | // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup() | 
|  | 3616 | assert ((name_type_mask & eFunctionNameTypeAuto) == 0); | 
|  | 3617 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3618 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3619 |  | 
|  | 3620 | if (log) | 
|  | 3621 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3622 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3623 | "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)", | 
|  | 3624 | name.GetCString(), | 
|  | 3625 | name_type_mask, | 
|  | 3626 | append); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3627 | } | 
|  | 3628 |  | 
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3629 | // If we aren't appending the results to this list, then clear the list | 
|  | 3630 | if (!append) | 
|  | 3631 | sc_list.Clear(); | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3632 |  | 
|  | 3633 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) | 
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 3634 | return 0; | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3635 |  | 
|  | 3636 | // If name is empty then we won't find anything. | 
|  | 3637 | if (name.IsEmpty()) | 
|  | 3638 | return 0; | 
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3639 |  | 
|  | 3640 | // Remember how many sc_list are in the list before we search in case | 
|  | 3641 | // we are appending the results to a variable list. | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3642 |  | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3643 | const char *name_cstr = name.GetCString(); | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3644 |  | 
|  | 3645 | const uint32_t original_size = sc_list.GetSize(); | 
|  | 3646 |  | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3647 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 3648 | if (info == NULL) | 
|  | 3649 | return 0; | 
|  | 3650 |  | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3651 | DWARFCompileUnit *dwarf_cu = NULL; | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3652 | std::set<const DWARFDebugInfoEntry *> resolved_dies; | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3653 | if (m_using_apple_tables) | 
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 3654 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3655 | if (m_apple_names_ap.get()) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3656 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3657 |  | 
|  | 3658 | DIEArray die_offsets; | 
|  | 3659 |  | 
|  | 3660 | uint32_t num_matches = 0; | 
|  | 3661 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3662 | if (name_type_mask & eFunctionNameTypeFull) | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3663 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3664 | // If they asked for the full name, match what they typed.  At some point we may | 
|  | 3665 | // want to canonicalize this (strip double spaces, etc.  For now, we just add all the | 
|  | 3666 | // dies that we find by exact match. | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3667 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3668 | for (uint32_t i = 0; i < num_matches; i++) | 
|  | 3669 | { | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3670 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 3671 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3672 | if (die) | 
|  | 3673 | { | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3674 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) | 
|  | 3675 | continue; | 
|  | 3676 |  | 
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3677 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) | 
|  | 3678 | continue; | 
|  | 3679 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3680 | if (resolved_dies.find(die) == resolved_dies.end()) | 
|  | 3681 | { | 
|  | 3682 | if (ResolveFunction (dwarf_cu, die, sc_list)) | 
|  | 3683 | resolved_dies.insert(die); | 
|  | 3684 | } | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3685 | } | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3686 | else | 
|  | 3687 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3688 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", | 
|  | 3689 | die_offset, name_cstr); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3690 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3691 | } | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3692 | } | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3693 |  | 
|  | 3694 | if (name_type_mask & eFunctionNameTypeSelector) | 
|  | 3695 | { | 
|  | 3696 | if (namespace_decl && *namespace_decl) | 
|  | 3697 | return 0; // no selectors in namespaces | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3698 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3699 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); | 
|  | 3700 | // Now make sure these are actually ObjC methods.  In this case we can simply look up the name, | 
|  | 3701 | // and if it is an ObjC method name, we're good. | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3702 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3703 | for (uint32_t i = 0; i < num_matches; i++) | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3704 | { | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3705 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 3706 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
|  | 3707 | if (die) | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3708 | { | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3709 | const char *die_name = die->GetName(this, dwarf_cu); | 
|  | 3710 | if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name)) | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3711 | { | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3712 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) | 
|  | 3713 | continue; | 
|  | 3714 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3715 | if (resolved_dies.find(die) == resolved_dies.end()) | 
|  | 3716 | { | 
|  | 3717 | if (ResolveFunction (dwarf_cu, die, sc_list)) | 
|  | 3718 | resolved_dies.insert(die); | 
|  | 3719 | } | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3720 | } | 
|  | 3721 | } | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3722 | else | 
|  | 3723 | { | 
|  | 3724 | GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", | 
|  | 3725 | die_offset, name_cstr); | 
|  | 3726 | } | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3727 | } | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3728 | die_offsets.clear(); | 
|  | 3729 | } | 
|  | 3730 |  | 
|  | 3731 | if (((name_type_mask & eFunctionNameTypeMethod) && !namespace_decl) || name_type_mask & eFunctionNameTypeBase) | 
|  | 3732 | { | 
|  | 3733 | // The apple_names table stores just the "base name" of C++ methods in the table.  So we have to | 
|  | 3734 | // extract the base name, look that up, and if there is any other information in the name we were | 
|  | 3735 | // passed in we have to post-filter based on that. | 
|  | 3736 |  | 
|  | 3737 | // FIXME: Arrange the logic above so that we don't calculate the base name twice: | 
|  | 3738 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); | 
|  | 3739 |  | 
|  | 3740 | for (uint32_t i = 0; i < num_matches; i++) | 
|  | 3741 | { | 
|  | 3742 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 3743 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
|  | 3744 | if (die) | 
|  | 3745 | { | 
|  | 3746 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) | 
|  | 3747 | continue; | 
|  | 3748 |  | 
|  | 3749 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) | 
|  | 3750 | continue; | 
|  | 3751 |  | 
|  | 3752 | // If we get to here, the die is good, and we should add it: | 
|  | 3753 | if (resolved_dies.find(die) == resolved_dies.end()) | 
|  | 3754 | if (ResolveFunction (dwarf_cu, die, sc_list)) | 
|  | 3755 | { | 
|  | 3756 | bool keep_die = true; | 
|  | 3757 | if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod)) | 
|  | 3758 | { | 
|  | 3759 | // We are looking for either basenames or methods, so we need to | 
|  | 3760 | // trim out the ones we won't want by looking at the type | 
|  | 3761 | SymbolContext sc; | 
|  | 3762 | if (sc_list.GetLastContext(sc)) | 
|  | 3763 | { | 
|  | 3764 | if (sc.block) | 
|  | 3765 | { | 
|  | 3766 | // We have an inlined function | 
|  | 3767 | } | 
|  | 3768 | else if (sc.function) | 
|  | 3769 | { | 
|  | 3770 | Type *type = sc.function->GetType(); | 
|  | 3771 |  | 
| Sean Callanan | c370a8a | 2013-09-18 22:59:55 +0000 | [diff] [blame] | 3772 | if (type) | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3773 | { | 
| Sean Callanan | c370a8a | 2013-09-18 22:59:55 +0000 | [diff] [blame] | 3774 | clang::DeclContext* decl_ctx = GetClangDeclContextContainingTypeUID (type->GetID()); | 
|  | 3775 | if (decl_ctx->isRecord()) | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3776 | { | 
| Sean Callanan | c370a8a | 2013-09-18 22:59:55 +0000 | [diff] [blame] | 3777 | if (name_type_mask & eFunctionNameTypeBase) | 
|  | 3778 | { | 
|  | 3779 | sc_list.RemoveContextAtIndex(sc_list.GetSize()-1); | 
|  | 3780 | keep_die = false; | 
|  | 3781 | } | 
|  | 3782 | } | 
|  | 3783 | else | 
|  | 3784 | { | 
|  | 3785 | if (name_type_mask & eFunctionNameTypeMethod) | 
|  | 3786 | { | 
|  | 3787 | sc_list.RemoveContextAtIndex(sc_list.GetSize()-1); | 
|  | 3788 | keep_die = false; | 
|  | 3789 | } | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3790 | } | 
|  | 3791 | } | 
|  | 3792 | else | 
|  | 3793 | { | 
| Sean Callanan | c370a8a | 2013-09-18 22:59:55 +0000 | [diff] [blame] | 3794 | GetObjectFile()->GetModule()->ReportWarning ("function at die offset 0x%8.8x had no function type", | 
|  | 3795 | die_offset); | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3796 | } | 
|  | 3797 | } | 
|  | 3798 | } | 
|  | 3799 | } | 
|  | 3800 | if (keep_die) | 
|  | 3801 | resolved_dies.insert(die); | 
|  | 3802 | } | 
|  | 3803 | } | 
|  | 3804 | else | 
|  | 3805 | { | 
|  | 3806 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", | 
|  | 3807 | die_offset, name_cstr); | 
|  | 3808 | } | 
|  | 3809 | } | 
|  | 3810 | die_offsets.clear(); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3811 | } | 
|  | 3812 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3813 | } | 
|  | 3814 | else | 
|  | 3815 | { | 
|  | 3816 |  | 
|  | 3817 | // Index the DWARF if we haven't already | 
|  | 3818 | if (!m_indexed) | 
|  | 3819 | Index (); | 
|  | 3820 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3821 | if (name_type_mask & eFunctionNameTypeFull) | 
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 3822 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3823 | FindFunctions (name, m_function_fullname_index, sc_list); | 
|  | 3824 |  | 
| Ed Maste | fc7baa0 | 2013-09-09 18:00:45 +0000 | [diff] [blame] | 3825 | // FIXME Temporary workaround for global/anonymous namespace | 
|  | 3826 | // functions on FreeBSD and Linux | 
|  | 3827 | #if defined (__FreeBSD__) || defined (__linux__) | 
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 3828 | // If we didn't find any functions in the global namespace try | 
|  | 3829 | // looking in the basename index but ignore any returned | 
|  | 3830 | // functions that have a namespace (ie. mangled names starting with | 
|  | 3831 | // '_ZN') but keep functions which have an anonymous namespace | 
|  | 3832 | if (sc_list.GetSize() == 0) | 
|  | 3833 | { | 
|  | 3834 | SymbolContextList temp_sc_list; | 
|  | 3835 | FindFunctions (name, m_function_basename_index, temp_sc_list); | 
|  | 3836 | if (!namespace_decl) | 
|  | 3837 | { | 
|  | 3838 | SymbolContext sc; | 
|  | 3839 | for (uint32_t i = 0; i < temp_sc_list.GetSize(); i++) | 
|  | 3840 | { | 
|  | 3841 | if (temp_sc_list.GetContextAtIndex(i, sc)) | 
|  | 3842 | { | 
| Matt Kopec | a189d49 | 2013-05-10 22:55:24 +0000 | [diff] [blame] | 3843 | ConstString mangled_name = sc.GetFunctionName(Mangled::ePreferMangled); | 
|  | 3844 | ConstString demangled_name = sc.GetFunctionName(Mangled::ePreferDemangled); | 
| Matt Kopec | 04e5d58 | 2013-05-14 19:00:41 +0000 | [diff] [blame] | 3845 | if (strncmp(mangled_name.GetCString(), "_ZN", 3) || | 
|  | 3846 | !strncmp(demangled_name.GetCString(), "(anonymous namespace)", 21)) | 
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 3847 | { | 
|  | 3848 | sc_list.Append(sc); | 
|  | 3849 | } | 
|  | 3850 | } | 
|  | 3851 | } | 
|  | 3852 | } | 
|  | 3853 | } | 
|  | 3854 | #endif | 
|  | 3855 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3856 | DIEArray die_offsets; | 
|  | 3857 | DWARFCompileUnit *dwarf_cu = NULL; | 
|  | 3858 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3859 | if (name_type_mask & eFunctionNameTypeBase) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3860 | { | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3861 | uint32_t num_base = m_function_basename_index.Find(name, die_offsets); | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3862 | for (uint32_t i = 0; i < num_base; i++) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3863 | { | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3864 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); | 
|  | 3865 | if (die) | 
|  | 3866 | { | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3867 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) | 
|  | 3868 | continue; | 
|  | 3869 |  | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3870 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) | 
|  | 3871 | continue; | 
|  | 3872 |  | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3873 | // 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] | 3874 | if (resolved_dies.find(die) == resolved_dies.end()) | 
|  | 3875 | { | 
|  | 3876 | if (ResolveFunction (dwarf_cu, die, sc_list)) | 
|  | 3877 | resolved_dies.insert(die); | 
|  | 3878 | } | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3879 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3880 | } | 
|  | 3881 | die_offsets.clear(); | 
|  | 3882 | } | 
|  | 3883 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3884 | if (name_type_mask & eFunctionNameTypeMethod) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3885 | { | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3886 | if (namespace_decl && *namespace_decl) | 
|  | 3887 | return 0; // no methods in namespaces | 
|  | 3888 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3889 | uint32_t num_base = m_function_method_index.Find(name, die_offsets); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3890 | { | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3891 | for (uint32_t i = 0; i < num_base; i++) | 
|  | 3892 | { | 
|  | 3893 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); | 
|  | 3894 | if (die) | 
|  | 3895 | { | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3896 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) | 
|  | 3897 | continue; | 
|  | 3898 |  | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3899 | // 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] | 3900 | if (resolved_dies.find(die) == resolved_dies.end()) | 
|  | 3901 | { | 
|  | 3902 | if (ResolveFunction (dwarf_cu, die, sc_list)) | 
|  | 3903 | resolved_dies.insert(die); | 
|  | 3904 | } | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3905 | } | 
|  | 3906 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3907 | } | 
|  | 3908 | die_offsets.clear(); | 
|  | 3909 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3910 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3911 | if ((name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl)) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3912 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3913 | FindFunctions (name, m_function_selector_index, sc_list); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3914 | } | 
|  | 3915 |  | 
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 3916 | } | 
|  | 3917 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3918 | // Return the number of variable that were appended to the list | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3919 | const uint32_t num_matches = sc_list.GetSize() - original_size; | 
|  | 3920 |  | 
|  | 3921 | if (log && num_matches > 0) | 
|  | 3922 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3923 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3924 | "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list) => %u", | 
|  | 3925 | name.GetCString(), | 
|  | 3926 | name_type_mask, | 
|  | 3927 | append, | 
|  | 3928 | num_matches); | 
|  | 3929 | } | 
|  | 3930 | return num_matches; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3931 | } | 
|  | 3932 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3933 | uint32_t | 
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3934 | 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] | 3935 | { | 
|  | 3936 | Timer scoped_timer (__PRETTY_FUNCTION__, | 
|  | 3937 | "SymbolFileDWARF::FindFunctions (regex = '%s')", | 
|  | 3938 | regex.GetText()); | 
|  | 3939 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3940 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3941 |  | 
|  | 3942 | if (log) | 
|  | 3943 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3944 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3945 | "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)", | 
|  | 3946 | regex.GetText(), | 
|  | 3947 | append); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3948 | } | 
|  | 3949 |  | 
|  | 3950 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3951 | // If we aren't appending the results to this list, then clear the list | 
|  | 3952 | if (!append) | 
|  | 3953 | sc_list.Clear(); | 
|  | 3954 |  | 
|  | 3955 | // Remember how many sc_list are in the list before we search in case | 
|  | 3956 | // we are appending the results to a variable list. | 
|  | 3957 | uint32_t original_size = sc_list.GetSize(); | 
|  | 3958 |  | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3959 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3960 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3961 | if (m_apple_names_ap.get()) | 
|  | 3962 | FindFunctions (regex, *m_apple_names_ap, sc_list); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3963 | } | 
|  | 3964 | else | 
|  | 3965 | { | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3966 | // Index the DWARF if we haven't already | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3967 | if (!m_indexed) | 
|  | 3968 | Index (); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3969 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3970 | FindFunctions (regex, m_function_basename_index, sc_list); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3971 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3972 | FindFunctions (regex, m_function_fullname_index, sc_list); | 
|  | 3973 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3974 |  | 
|  | 3975 | // Return the number of variable that were appended to the list | 
|  | 3976 | return sc_list.GetSize() - original_size; | 
|  | 3977 | } | 
| Jim Ingham | 318c9f2 | 2011-08-26 19:44:13 +0000 | [diff] [blame] | 3978 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3979 | uint32_t | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3980 | SymbolFileDWARF::FindTypes (const SymbolContext& sc, | 
|  | 3981 | const ConstString &name, | 
|  | 3982 | const lldb_private::ClangNamespaceDecl *namespace_decl, | 
|  | 3983 | bool append, | 
|  | 3984 | uint32_t max_matches, | 
|  | 3985 | TypeList& types) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3986 | { | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3987 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 3988 | if (info == NULL) | 
|  | 3989 | return 0; | 
|  | 3990 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3991 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3992 |  | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3993 | if (log) | 
|  | 3994 | { | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3995 | if (namespace_decl) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3996 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3997 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)", | 
|  | 3998 | name.GetCString(), | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3999 | static_cast<void*>(namespace_decl->GetNamespaceDecl()), | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4000 | namespace_decl->GetQualifiedName().c_str(), | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4001 | append, max_matches); | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4002 | else | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4003 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4004 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)", | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4005 | name.GetCString(), append, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4006 | max_matches); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 4007 | } | 
|  | 4008 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4009 | // If we aren't appending the results to this list, then clear the list | 
|  | 4010 | if (!append) | 
|  | 4011 | types.Clear(); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4012 |  | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 4013 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) | 
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 4014 | return 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4015 |  | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4016 | DIEArray die_offsets; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4017 |  | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4018 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4019 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4020 | if (m_apple_types_ap.get()) | 
|  | 4021 | { | 
|  | 4022 | const char *name_cstr = name.GetCString(); | 
|  | 4023 | m_apple_types_ap->FindByName (name_cstr, die_offsets); | 
|  | 4024 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4025 | } | 
|  | 4026 | else | 
|  | 4027 | { | 
|  | 4028 | if (!m_indexed) | 
|  | 4029 | Index (); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4030 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4031 | m_type_index.Find (name, die_offsets); | 
|  | 4032 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4033 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4034 | const size_t num_die_matches = die_offsets.size(); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4035 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4036 | if (num_die_matches) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4037 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4038 | const uint32_t initial_types_size = types.GetSize(); | 
|  | 4039 | DWARFCompileUnit* dwarf_cu = NULL; | 
|  | 4040 | const DWARFDebugInfoEntry* die = NULL; | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4041 | DWARFDebugInfo* debug_info = DebugInfo(); | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4042 | for (size_t i=0; i<num_die_matches; ++i) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4043 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4044 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 4045 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
|  | 4046 |  | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4047 | if (die) | 
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 4048 | { | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4049 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) | 
|  | 4050 | continue; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4051 |  | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4052 | Type *matching_type = ResolveType (dwarf_cu, die); | 
|  | 4053 | if (matching_type) | 
|  | 4054 | { | 
|  | 4055 | // 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] | 4056 | types.InsertUnique (matching_type->shared_from_this()); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4057 | if (types.GetSize() >= max_matches) | 
|  | 4058 | break; | 
|  | 4059 | } | 
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 4060 | } | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4061 | else | 
|  | 4062 | { | 
|  | 4063 | if (m_using_apple_tables) | 
|  | 4064 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4065 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", | 
|  | 4066 | die_offset, name.GetCString()); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4067 | } | 
|  | 4068 | } | 
|  | 4069 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4070 | } | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4071 | const uint32_t num_matches = types.GetSize() - initial_types_size; | 
|  | 4072 | if (log && num_matches) | 
|  | 4073 | { | 
|  | 4074 | if (namespace_decl) | 
|  | 4075 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4076 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4077 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u", | 
|  | 4078 | name.GetCString(), | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4079 | static_cast<void*>(namespace_decl->GetNamespaceDecl()), | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4080 | namespace_decl->GetQualifiedName().c_str(), | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4081 | append, max_matches, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4082 | num_matches); | 
|  | 4083 | } | 
|  | 4084 | else | 
|  | 4085 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4086 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4087 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u", | 
|  | 4088 | name.GetCString(), | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4089 | append, max_matches, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4090 | num_matches); | 
|  | 4091 | } | 
|  | 4092 | } | 
|  | 4093 | return num_matches; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4094 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4095 | return 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4096 | } | 
|  | 4097 |  | 
|  | 4098 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4099 | ClangNamespaceDecl | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4100 | SymbolFileDWARF::FindNamespace (const SymbolContext& sc, | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 4101 | const ConstString &name, | 
|  | 4102 | const lldb_private::ClangNamespaceDecl *parent_namespace_decl) | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4103 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4104 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 4105 |  | 
|  | 4106 | if (log) | 
|  | 4107 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4108 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4109 | "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")", | 
|  | 4110 | name.GetCString()); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 4111 | } | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 4112 |  | 
|  | 4113 | if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl)) | 
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 4114 | return ClangNamespaceDecl(); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 4115 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4116 | ClangNamespaceDecl namespace_decl; | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4117 | DWARFDebugInfo* info = DebugInfo(); | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4118 | if (info) | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4119 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4120 | DIEArray die_offsets; | 
|  | 4121 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4122 | // Index if we already haven't to make sure the compile units | 
|  | 4123 | // get indexed and make their global DIE index list | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4124 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4125 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4126 | if (m_apple_namespaces_ap.get()) | 
|  | 4127 | { | 
|  | 4128 | const char *name_cstr = name.GetCString(); | 
|  | 4129 | m_apple_namespaces_ap->FindByName (name_cstr, die_offsets); | 
|  | 4130 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4131 | } | 
|  | 4132 | else | 
|  | 4133 | { | 
|  | 4134 | if (!m_indexed) | 
|  | 4135 | Index (); | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4136 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4137 | m_namespace_index.Find (name, die_offsets); | 
|  | 4138 | } | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4139 |  | 
|  | 4140 | DWARFCompileUnit* dwarf_cu = NULL; | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4141 | const DWARFDebugInfoEntry* die = NULL; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4142 | const size_t num_matches = die_offsets.size(); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4143 | if (num_matches) | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4144 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4145 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 4146 | for (size_t i=0; i<num_matches; ++i) | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4147 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4148 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 4149 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 4150 |  | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4151 | if (die) | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4152 | { | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4153 | if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die)) | 
|  | 4154 | continue; | 
|  | 4155 |  | 
|  | 4156 | clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die); | 
|  | 4157 | if (clang_namespace_decl) | 
|  | 4158 | { | 
|  | 4159 | namespace_decl.SetASTContext (GetClangASTContext().getASTContext()); | 
|  | 4160 | namespace_decl.SetNamespaceDecl (clang_namespace_decl); | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4161 | break; | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4162 | } | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4163 | } | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4164 | else | 
|  | 4165 | { | 
|  | 4166 | if (m_using_apple_tables) | 
|  | 4167 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4168 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n", | 
|  | 4169 | die_offset, name.GetCString()); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4170 | } | 
|  | 4171 | } | 
|  | 4172 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4173 | } | 
|  | 4174 | } | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4175 | } | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4176 | if (log && namespace_decl.GetNamespaceDecl()) | 
|  | 4177 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4178 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4179 | "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"", | 
|  | 4180 | name.GetCString(), | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4181 | static_cast<const void*>(namespace_decl.GetNamespaceDecl()), | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4182 | namespace_decl.GetQualifiedName().c_str()); | 
|  | 4183 | } | 
|  | 4184 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4185 | return namespace_decl; | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4186 | } | 
|  | 4187 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4188 | uint32_t | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4189 | 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] | 4190 | { | 
|  | 4191 | // Remember how many sc_list are in the list before we search in case | 
|  | 4192 | // we are appending the results to a variable list. | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4193 | uint32_t original_size = types.GetSize(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4194 |  | 
|  | 4195 | const uint32_t num_die_offsets = die_offsets.size(); | 
|  | 4196 | // Parse all of the types we found from the pubtypes matches | 
|  | 4197 | uint32_t i; | 
|  | 4198 | uint32_t num_matches = 0; | 
|  | 4199 | for (i = 0; i < num_die_offsets; ++i) | 
|  | 4200 | { | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4201 | Type *matching_type = ResolveTypeUID (die_offsets[i]); | 
|  | 4202 | if (matching_type) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4203 | { | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4204 | // 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] | 4205 | types.InsertUnique (matching_type->shared_from_this()); | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4206 | ++num_matches; | 
|  | 4207 | if (num_matches >= max_matches) | 
|  | 4208 | break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4209 | } | 
|  | 4210 | } | 
|  | 4211 |  | 
|  | 4212 | // Return the number of variable that were appended to the list | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4213 | return types.GetSize() - original_size; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4214 | } | 
|  | 4215 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4216 |  | 
|  | 4217 | size_t | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4218 | SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc, | 
|  | 4219 | clang::DeclContext *containing_decl_ctx, | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4220 | DWARFCompileUnit* dwarf_cu, | 
|  | 4221 | const DWARFDebugInfoEntry *parent_die, | 
|  | 4222 | bool skip_artificial, | 
|  | 4223 | bool &is_static, | 
| Greg Clayton | 0396975 | 2014-02-24 18:53:11 +0000 | [diff] [blame] | 4224 | bool &is_variadic, | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4225 | TypeList* type_list, | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 4226 | std::vector<ClangASTType>& function_param_types, | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4227 | std::vector<clang::ParmVarDecl*>& function_param_decls, | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 4228 | unsigned &type_quals) // , | 
|  | 4229 | // ClangASTContext::TemplateParameterInfos &template_param_infos)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4230 | { | 
|  | 4231 | if (parent_die == NULL) | 
|  | 4232 | return 0; | 
|  | 4233 |  | 
| Todd Fiala | ee8bfc6 | 2014-09-11 17:29:12 +0000 | [diff] [blame] | 4234 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64()); | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4235 |  | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4236 | size_t arg_idx = 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4237 | const DWARFDebugInfoEntry *die; | 
|  | 4238 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) | 
|  | 4239 | { | 
|  | 4240 | dw_tag_t tag = die->Tag(); | 
|  | 4241 | switch (tag) | 
|  | 4242 | { | 
|  | 4243 | case DW_TAG_formal_parameter: | 
|  | 4244 | { | 
|  | 4245 | DWARFDebugInfoEntry::Attributes attributes; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4246 | 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] | 4247 | if (num_attributes > 0) | 
|  | 4248 | { | 
|  | 4249 | const char *name = NULL; | 
|  | 4250 | Declaration decl; | 
|  | 4251 | dw_offset_t param_type_die_offset = DW_INVALID_OFFSET; | 
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 4252 | bool is_artificial = false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4253 | // one of None, Auto, Register, Extern, Static, PrivateExtern | 
|  | 4254 |  | 
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 4255 | clang::StorageClass storage = clang::SC_None; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4256 | uint32_t i; | 
|  | 4257 | for (i=0; i<num_attributes; ++i) | 
|  | 4258 | { | 
|  | 4259 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 4260 | DWARFFormValue form_value; | 
|  | 4261 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 4262 | { | 
|  | 4263 | switch (attr) | 
|  | 4264 | { | 
|  | 4265 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 4266 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 4267 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 4268 | case DW_AT_name:        name = form_value.AsCString(&get_debug_str_data()); break; | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 4269 | case DW_AT_type:        param_type_die_offset = form_value.Reference(); break; | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 4270 | case DW_AT_artificial:  is_artificial = form_value.Boolean(); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4271 | case DW_AT_location: | 
|  | 4272 | //                          if (form_value.BlockData()) | 
|  | 4273 | //                          { | 
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 4274 | //                              const DWARFDataExtractor& debug_info_data = debug_info(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4275 | //                              uint32_t block_length = form_value.Unsigned(); | 
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 4276 | //                              DWARFDataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4277 | //                          } | 
|  | 4278 | //                          else | 
|  | 4279 | //                          { | 
|  | 4280 | //                          } | 
|  | 4281 | //                          break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4282 | case DW_AT_const_value: | 
|  | 4283 | case DW_AT_default_value: | 
|  | 4284 | case DW_AT_description: | 
|  | 4285 | case DW_AT_endianity: | 
|  | 4286 | case DW_AT_is_optional: | 
|  | 4287 | case DW_AT_segment: | 
|  | 4288 | case DW_AT_variable_parameter: | 
|  | 4289 | default: | 
|  | 4290 | case DW_AT_abstract_origin: | 
|  | 4291 | case DW_AT_sibling: | 
|  | 4292 | break; | 
|  | 4293 | } | 
|  | 4294 | } | 
|  | 4295 | } | 
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 4296 |  | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4297 | bool skip = false; | 
|  | 4298 | if (skip_artificial) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4299 | { | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4300 | if (is_artificial) | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4301 | { | 
|  | 4302 | // In order to determine if a C++ member function is | 
|  | 4303 | // "const" we have to look at the const-ness of "this"... | 
|  | 4304 | // Ugly, but that | 
|  | 4305 | if (arg_idx == 0) | 
|  | 4306 | { | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 4307 | if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind())) | 
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 4308 | { | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4309 | // Often times compilers omit the "this" name for the | 
|  | 4310 | // specification DIEs, so we can't rely upon the name | 
|  | 4311 | // being in the formal parameter DIE... | 
|  | 4312 | if (name == NULL || ::strcmp(name, "this")==0) | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4313 | { | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4314 | Type *this_type = ResolveTypeUID (param_type_die_offset); | 
|  | 4315 | if (this_type) | 
|  | 4316 | { | 
|  | 4317 | uint32_t encoding_mask = this_type->GetEncodingMask(); | 
|  | 4318 | if (encoding_mask & Type::eEncodingIsPointerUID) | 
|  | 4319 | { | 
|  | 4320 | is_static = false; | 
|  | 4321 |  | 
|  | 4322 | if (encoding_mask & (1u << Type::eEncodingIsConstUID)) | 
|  | 4323 | type_quals |= clang::Qualifiers::Const; | 
|  | 4324 | if (encoding_mask & (1u << Type::eEncodingIsVolatileUID)) | 
|  | 4325 | type_quals |= clang::Qualifiers::Volatile; | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4326 | } | 
|  | 4327 | } | 
|  | 4328 | } | 
|  | 4329 | } | 
|  | 4330 | } | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4331 | skip = true; | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4332 | } | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4333 | else | 
|  | 4334 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4335 |  | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4336 | // HACK: Objective C formal parameters "self" and "_cmd" | 
|  | 4337 | // are not marked as artificial in the DWARF... | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4338 | CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); | 
|  | 4339 | if (comp_unit) | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4340 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4341 | switch (comp_unit->GetLanguage()) | 
|  | 4342 | { | 
|  | 4343 | case eLanguageTypeObjC: | 
|  | 4344 | case eLanguageTypeObjC_plus_plus: | 
|  | 4345 | if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0)) | 
|  | 4346 | skip = true; | 
|  | 4347 | break; | 
|  | 4348 | default: | 
|  | 4349 | break; | 
|  | 4350 | } | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4351 | } | 
|  | 4352 | } | 
|  | 4353 | } | 
|  | 4354 |  | 
|  | 4355 | if (!skip) | 
|  | 4356 | { | 
|  | 4357 | Type *type = ResolveTypeUID(param_type_die_offset); | 
|  | 4358 | if (type) | 
|  | 4359 | { | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 4360 | function_param_types.push_back (type->GetClangForwardType()); | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4361 |  | 
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 4362 | clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name, | 
|  | 4363 | type->GetClangForwardType(), | 
|  | 4364 | storage); | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4365 | assert(param_var_decl); | 
|  | 4366 | function_param_decls.push_back(param_var_decl); | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 4367 |  | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 4368 | GetClangASTContext().SetMetadataAsUserID (param_var_decl, MakeUserID(die->GetOffset())); | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4369 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4370 | } | 
|  | 4371 | } | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4372 | arg_idx++; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4373 | } | 
|  | 4374 | break; | 
|  | 4375 |  | 
| Greg Clayton | 0396975 | 2014-02-24 18:53:11 +0000 | [diff] [blame] | 4376 | case DW_TAG_unspecified_parameters: | 
|  | 4377 | is_variadic = true; | 
|  | 4378 | break; | 
|  | 4379 |  | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 4380 | case DW_TAG_template_type_parameter: | 
|  | 4381 | case DW_TAG_template_value_parameter: | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 4382 | // The one caller of this was never using the template_param_infos, | 
|  | 4383 | // and the local variable was taking up a large amount of stack space | 
|  | 4384 | // in SymbolFileDWARF::ParseType() so this was removed. If we ever need | 
|  | 4385 | // the template params back, we can add them back. | 
|  | 4386 | // ParseTemplateDIE (dwarf_cu, die, template_param_infos); | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 4387 | break; | 
|  | 4388 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4389 | default: | 
|  | 4390 | break; | 
|  | 4391 | } | 
|  | 4392 | } | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4393 | return arg_idx; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4394 | } | 
|  | 4395 |  | 
|  | 4396 | size_t | 
|  | 4397 | SymbolFileDWARF::ParseChildEnumerators | 
|  | 4398 | ( | 
|  | 4399 | const SymbolContext& sc, | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 4400 | lldb_private::ClangASTType &clang_type, | 
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 4401 | bool is_signed, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4402 | uint32_t enumerator_byte_size, | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4403 | DWARFCompileUnit* dwarf_cu, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4404 | const DWARFDebugInfoEntry *parent_die | 
|  | 4405 | ) | 
|  | 4406 | { | 
|  | 4407 | if (parent_die == NULL) | 
|  | 4408 | return 0; | 
|  | 4409 |  | 
|  | 4410 | size_t enumerators_added = 0; | 
|  | 4411 | const DWARFDebugInfoEntry *die; | 
| Todd Fiala | ee8bfc6 | 2014-09-11 17:29:12 +0000 | [diff] [blame] | 4412 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64()); | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4413 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4414 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) | 
|  | 4415 | { | 
|  | 4416 | const dw_tag_t tag = die->Tag(); | 
|  | 4417 | if (tag == DW_TAG_enumerator) | 
|  | 4418 | { | 
|  | 4419 | DWARFDebugInfoEntry::Attributes attributes; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4420 | 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] | 4421 | if (num_child_attributes > 0) | 
|  | 4422 | { | 
|  | 4423 | const char *name = NULL; | 
|  | 4424 | bool got_value = false; | 
|  | 4425 | int64_t enum_value = 0; | 
|  | 4426 | Declaration decl; | 
|  | 4427 |  | 
|  | 4428 | uint32_t i; | 
|  | 4429 | for (i=0; i<num_child_attributes; ++i) | 
|  | 4430 | { | 
|  | 4431 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 4432 | DWARFFormValue form_value; | 
|  | 4433 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 4434 | { | 
|  | 4435 | switch (attr) | 
|  | 4436 | { | 
|  | 4437 | case DW_AT_const_value: | 
|  | 4438 | got_value = true; | 
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 4439 | if (is_signed) | 
|  | 4440 | enum_value = form_value.Signed(); | 
|  | 4441 | else | 
|  | 4442 | enum_value = form_value.Unsigned(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4443 | break; | 
|  | 4444 |  | 
|  | 4445 | case DW_AT_name: | 
|  | 4446 | name = form_value.AsCString(&get_debug_str_data()); | 
|  | 4447 | break; | 
|  | 4448 |  | 
|  | 4449 | case DW_AT_description: | 
|  | 4450 | default: | 
|  | 4451 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 4452 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 4453 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 4454 | case DW_AT_sibling: | 
|  | 4455 | break; | 
|  | 4456 | } | 
|  | 4457 | } | 
|  | 4458 | } | 
|  | 4459 |  | 
|  | 4460 | if (name && name[0] && got_value) | 
|  | 4461 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 4462 | clang_type.AddEnumerationValueToEnumerationType (clang_type.GetEnumerationIntegerType(), | 
|  | 4463 | decl, | 
|  | 4464 | name, | 
|  | 4465 | enum_value, | 
|  | 4466 | enumerator_byte_size * 8); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4467 | ++enumerators_added; | 
|  | 4468 | } | 
|  | 4469 | } | 
|  | 4470 | } | 
|  | 4471 | } | 
|  | 4472 | return enumerators_added; | 
|  | 4473 | } | 
|  | 4474 |  | 
|  | 4475 | void | 
|  | 4476 | SymbolFileDWARF::ParseChildArrayInfo | 
|  | 4477 | ( | 
|  | 4478 | const SymbolContext& sc, | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4479 | DWARFCompileUnit* dwarf_cu, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4480 | const DWARFDebugInfoEntry *parent_die, | 
|  | 4481 | int64_t& first_index, | 
|  | 4482 | std::vector<uint64_t>& element_orders, | 
|  | 4483 | uint32_t& byte_stride, | 
|  | 4484 | uint32_t& bit_stride | 
|  | 4485 | ) | 
|  | 4486 | { | 
|  | 4487 | if (parent_die == NULL) | 
|  | 4488 | return; | 
|  | 4489 |  | 
|  | 4490 | const DWARFDebugInfoEntry *die; | 
| Todd Fiala | ee8bfc6 | 2014-09-11 17:29:12 +0000 | [diff] [blame] | 4491 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64()); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4492 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) | 
|  | 4493 | { | 
|  | 4494 | const dw_tag_t tag = die->Tag(); | 
|  | 4495 | switch (tag) | 
|  | 4496 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4497 | case DW_TAG_subrange_type: | 
|  | 4498 | { | 
|  | 4499 | DWARFDebugInfoEntry::Attributes attributes; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4500 | 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] | 4501 | if (num_child_attributes > 0) | 
|  | 4502 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4503 | uint64_t num_elements = 0; | 
|  | 4504 | uint64_t lower_bound = 0; | 
|  | 4505 | uint64_t upper_bound = 0; | 
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4506 | bool upper_bound_valid = false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4507 | uint32_t i; | 
|  | 4508 | for (i=0; i<num_child_attributes; ++i) | 
|  | 4509 | { | 
|  | 4510 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 4511 | DWARFFormValue form_value; | 
|  | 4512 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 4513 | { | 
|  | 4514 | switch (attr) | 
|  | 4515 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4516 | case DW_AT_name: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4517 | break; | 
|  | 4518 |  | 
|  | 4519 | case DW_AT_count: | 
|  | 4520 | num_elements = form_value.Unsigned(); | 
|  | 4521 | break; | 
|  | 4522 |  | 
|  | 4523 | case DW_AT_bit_stride: | 
|  | 4524 | bit_stride = form_value.Unsigned(); | 
|  | 4525 | break; | 
|  | 4526 |  | 
|  | 4527 | case DW_AT_byte_stride: | 
|  | 4528 | byte_stride = form_value.Unsigned(); | 
|  | 4529 | break; | 
|  | 4530 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4531 | case DW_AT_lower_bound: | 
|  | 4532 | lower_bound = form_value.Unsigned(); | 
|  | 4533 | break; | 
|  | 4534 |  | 
|  | 4535 | case DW_AT_upper_bound: | 
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4536 | upper_bound_valid = true; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4537 | upper_bound = form_value.Unsigned(); | 
|  | 4538 | break; | 
|  | 4539 |  | 
|  | 4540 | default: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4541 | case DW_AT_abstract_origin: | 
|  | 4542 | case DW_AT_accessibility: | 
|  | 4543 | case DW_AT_allocated: | 
|  | 4544 | case DW_AT_associated: | 
|  | 4545 | case DW_AT_data_location: | 
|  | 4546 | case DW_AT_declaration: | 
|  | 4547 | case DW_AT_description: | 
|  | 4548 | case DW_AT_sibling: | 
|  | 4549 | case DW_AT_threads_scaled: | 
|  | 4550 | case DW_AT_type: | 
|  | 4551 | case DW_AT_visibility: | 
|  | 4552 | break; | 
|  | 4553 | } | 
|  | 4554 | } | 
|  | 4555 | } | 
|  | 4556 |  | 
| Greg Clayton | e6a0779 | 2012-12-05 21:59:39 +0000 | [diff] [blame] | 4557 | if (num_elements == 0) | 
|  | 4558 | { | 
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4559 | if (upper_bound_valid && upper_bound >= lower_bound) | 
| Greg Clayton | e6a0779 | 2012-12-05 21:59:39 +0000 | [diff] [blame] | 4560 | num_elements = upper_bound - lower_bound + 1; | 
|  | 4561 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4562 |  | 
| Sean Callanan | ec979ba | 2012-10-22 23:56:48 +0000 | [diff] [blame] | 4563 | element_orders.push_back (num_elements); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4564 | } | 
|  | 4565 | } | 
|  | 4566 | break; | 
|  | 4567 | } | 
|  | 4568 | } | 
|  | 4569 | } | 
|  | 4570 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4571 | TypeSP | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4572 | SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4573 | { | 
|  | 4574 | TypeSP type_sp; | 
|  | 4575 | if (die != NULL) | 
|  | 4576 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4577 | assert(dwarf_cu != NULL); | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4578 | Type *type_ptr = m_die_to_type.lookup (die); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4579 | if (type_ptr == NULL) | 
|  | 4580 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4581 | CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu); | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4582 | assert (lldb_cu); | 
|  | 4583 | SymbolContext sc(lldb_cu); | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4584 | type_sp = ParseType(sc, dwarf_cu, die, NULL); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4585 | } | 
|  | 4586 | else if (type_ptr != DIE_IS_BEING_PARSED) | 
|  | 4587 | { | 
|  | 4588 | // Grab the existing type from the master types lists | 
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 4589 | type_sp = type_ptr->shared_from_this(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4590 | } | 
|  | 4591 |  | 
|  | 4592 | } | 
|  | 4593 | return type_sp; | 
|  | 4594 | } | 
|  | 4595 |  | 
|  | 4596 | clang::DeclContext * | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4597 | SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4598 | { | 
|  | 4599 | if (die_offset != DW_INVALID_OFFSET) | 
|  | 4600 | { | 
|  | 4601 | DWARFCompileUnitSP cu_sp; | 
|  | 4602 | const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp); | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4603 | return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4604 | } | 
|  | 4605 | return NULL; | 
|  | 4606 | } | 
|  | 4607 |  | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4608 | clang::DeclContext * | 
|  | 4609 | SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset) | 
|  | 4610 | { | 
|  | 4611 | if (die_offset != DW_INVALID_OFFSET) | 
|  | 4612 | { | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4613 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 4614 | if (debug_info) | 
|  | 4615 | { | 
|  | 4616 | DWARFCompileUnitSP cu_sp; | 
|  | 4617 | const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp); | 
|  | 4618 | if (die) | 
|  | 4619 | return GetClangDeclContextForDIE (sc, cu_sp.get(), die); | 
|  | 4620 | } | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4621 | } | 
|  | 4622 | return NULL; | 
|  | 4623 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4624 |  | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4625 | clang::NamespaceDecl * | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4626 | SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die) | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4627 | { | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4628 | if (die && die->Tag() == DW_TAG_namespace) | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4629 | { | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4630 | // See if we already parsed this namespace DIE and associated it with a | 
|  | 4631 | // uniqued namespace declaration | 
|  | 4632 | clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]); | 
|  | 4633 | if (namespace_decl) | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4634 | return namespace_decl; | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4635 | else | 
|  | 4636 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4637 | const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL); | 
|  | 4638 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL); | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4639 | namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4640 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4641 | if (log) | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4642 | { | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4643 | if (namespace_name) | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4644 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4645 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4646 | "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)", | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4647 | static_cast<void*>(GetClangASTContext().getASTContext()), | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4648 | MakeUserID(die->GetOffset()), | 
|  | 4649 | namespace_name, | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4650 | static_cast<void*>(namespace_decl), | 
|  | 4651 | static_cast<void*>(namespace_decl->getOriginalNamespace())); | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4652 | } | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4653 | else | 
|  | 4654 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4655 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4656 | "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)", | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4657 | static_cast<void*>(GetClangASTContext().getASTContext()), | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4658 | MakeUserID(die->GetOffset()), | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4659 | static_cast<void*>(namespace_decl), | 
|  | 4660 | static_cast<void*>(namespace_decl->getOriginalNamespace())); | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4661 | } | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4662 | } | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4663 |  | 
|  | 4664 | if (namespace_decl) | 
|  | 4665 | LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die); | 
|  | 4666 | return namespace_decl; | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4667 | } | 
|  | 4668 | } | 
|  | 4669 | return NULL; | 
|  | 4670 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4671 |  | 
|  | 4672 | clang::DeclContext * | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4673 | SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4674 | { | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4675 | clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die); | 
|  | 4676 | if (clang_decl_ctx) | 
|  | 4677 | return clang_decl_ctx; | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4678 | // If this DIE has a specification, or an abstract origin, then trace to those. | 
|  | 4679 |  | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4680 | 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] | 4681 | if (die_offset != DW_INVALID_OFFSET) | 
|  | 4682 | return GetClangDeclContextForDIEOffset (sc, die_offset); | 
|  | 4683 |  | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4684 | 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] | 4685 | if (die_offset != DW_INVALID_OFFSET) | 
|  | 4686 | return GetClangDeclContextForDIEOffset (sc, die_offset); | 
|  | 4687 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4688 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 4689 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4690 | 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] | 4691 | // This is the DIE we want.  Parse it, then query our map. | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4692 | bool assert_not_being_parsed = true; | 
|  | 4693 | ResolveTypeUID (cu, die, assert_not_being_parsed); | 
|  | 4694 |  | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4695 | clang_decl_ctx = GetCachedClangDeclContextForDIE (die); | 
|  | 4696 |  | 
|  | 4697 | return clang_decl_ctx; | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4698 | } | 
|  | 4699 |  | 
|  | 4700 | clang::DeclContext * | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4701 | 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] | 4702 | { | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4703 | if (m_clang_tu_decl == NULL) | 
|  | 4704 | m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4705 |  | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4706 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4707 |  | 
|  | 4708 | if (decl_ctx_die_copy) | 
|  | 4709 | *decl_ctx_die_copy = decl_ctx_die; | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4710 |  | 
|  | 4711 | if (decl_ctx_die) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4712 | { | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4713 |  | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4714 | DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die); | 
|  | 4715 | if (pos != m_die_to_decl_ctx.end()) | 
|  | 4716 | return pos->second; | 
|  | 4717 |  | 
|  | 4718 | switch (decl_ctx_die->Tag()) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4719 | { | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4720 | case DW_TAG_compile_unit: | 
|  | 4721 | return m_clang_tu_decl; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4722 |  | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4723 | case DW_TAG_namespace: | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4724 | return ResolveNamespaceDIE (cu, decl_ctx_die); | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4725 | break; | 
|  | 4726 |  | 
|  | 4727 | case DW_TAG_structure_type: | 
|  | 4728 | case DW_TAG_union_type: | 
|  | 4729 | case DW_TAG_class_type: | 
|  | 4730 | { | 
|  | 4731 | Type* type = ResolveType (cu, decl_ctx_die); | 
|  | 4732 | if (type) | 
|  | 4733 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 4734 | clang::DeclContext *decl_ctx = type->GetClangForwardType().GetDeclContextForType (); | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4735 | if (decl_ctx) | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4736 | { | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4737 | LinkDeclContextToDIE (decl_ctx, decl_ctx_die); | 
|  | 4738 | if (decl_ctx) | 
|  | 4739 | return decl_ctx; | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4740 | } | 
|  | 4741 | } | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4742 | } | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4743 | break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4744 |  | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4745 | default: | 
|  | 4746 | break; | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4747 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4748 | } | 
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 4749 | return m_clang_tu_decl; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4750 | } | 
|  | 4751 |  | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4752 |  | 
|  | 4753 | const DWARFDebugInfoEntry * | 
|  | 4754 | SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) | 
|  | 4755 | { | 
|  | 4756 | if (cu && die) | 
|  | 4757 | { | 
|  | 4758 | const DWARFDebugInfoEntry * const decl_die = die; | 
|  | 4759 |  | 
|  | 4760 | while (die != NULL) | 
|  | 4761 | { | 
|  | 4762 | // If this is the original DIE that we are searching for a declaration | 
|  | 4763 | // for, then don't look in the cache as we don't want our own decl | 
|  | 4764 | // context to be our decl context... | 
|  | 4765 | if (decl_die != die) | 
|  | 4766 | { | 
|  | 4767 | switch (die->Tag()) | 
|  | 4768 | { | 
|  | 4769 | case DW_TAG_compile_unit: | 
|  | 4770 | case DW_TAG_namespace: | 
|  | 4771 | case DW_TAG_structure_type: | 
|  | 4772 | case DW_TAG_union_type: | 
|  | 4773 | case DW_TAG_class_type: | 
|  | 4774 | return die; | 
|  | 4775 |  | 
|  | 4776 | default: | 
|  | 4777 | break; | 
|  | 4778 | } | 
|  | 4779 | } | 
|  | 4780 |  | 
|  | 4781 | dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET); | 
|  | 4782 | if (die_offset != DW_INVALID_OFFSET) | 
|  | 4783 | { | 
|  | 4784 | DWARFCompileUnit *spec_cu = cu; | 
|  | 4785 | const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu); | 
|  | 4786 | const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die); | 
|  | 4787 | if (spec_die_decl_ctx_die) | 
|  | 4788 | return spec_die_decl_ctx_die; | 
|  | 4789 | } | 
|  | 4790 |  | 
|  | 4791 | die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET); | 
|  | 4792 | if (die_offset != DW_INVALID_OFFSET) | 
|  | 4793 | { | 
|  | 4794 | DWARFCompileUnit *abs_cu = cu; | 
|  | 4795 | const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu); | 
|  | 4796 | const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die); | 
|  | 4797 | if (abs_die_decl_ctx_die) | 
|  | 4798 | return abs_die_decl_ctx_die; | 
|  | 4799 | } | 
|  | 4800 |  | 
|  | 4801 | die = die->GetParent(); | 
|  | 4802 | } | 
|  | 4803 | } | 
|  | 4804 | return NULL; | 
|  | 4805 | } | 
|  | 4806 |  | 
|  | 4807 |  | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4808 | Symbol * | 
|  | 4809 | SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name) | 
|  | 4810 | { | 
|  | 4811 | Symbol *objc_class_symbol = NULL; | 
|  | 4812 | if (m_obj_file) | 
|  | 4813 | { | 
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 4814 | Symtab *symtab = m_obj_file->GetSymtab (); | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4815 | if (symtab) | 
|  | 4816 | { | 
|  | 4817 | objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name, | 
|  | 4818 | eSymbolTypeObjCClass, | 
|  | 4819 | Symtab::eDebugNo, | 
|  | 4820 | Symtab::eVisibilityAny); | 
|  | 4821 | } | 
|  | 4822 | } | 
|  | 4823 | return objc_class_symbol; | 
|  | 4824 | } | 
|  | 4825 |  | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4826 | // Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't | 
|  | 4827 | // then we can end up looking through all class types for a complete type and never find | 
|  | 4828 | // the full definition. We need to know if this attribute is supported, so we determine | 
|  | 4829 | // this here and cache th result. We also need to worry about the debug map DWARF file | 
|  | 4830 | // if we are doing darwin DWARF in .o file debugging. | 
|  | 4831 | bool | 
|  | 4832 | SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu) | 
|  | 4833 | { | 
|  | 4834 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate) | 
|  | 4835 | { | 
|  | 4836 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo; | 
|  | 4837 | if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type()) | 
|  | 4838 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; | 
|  | 4839 | else | 
|  | 4840 | { | 
|  | 4841 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 4842 | const uint32_t num_compile_units = GetNumCompileUnits(); | 
|  | 4843 | for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) | 
|  | 4844 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4845 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); | 
|  | 4846 | 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] | 4847 | { | 
|  | 4848 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; | 
|  | 4849 | break; | 
|  | 4850 | } | 
|  | 4851 | } | 
|  | 4852 | } | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 4853 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ()) | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4854 | return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this); | 
|  | 4855 | } | 
|  | 4856 | return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes; | 
|  | 4857 | } | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4858 |  | 
|  | 4859 | // This function can be used when a DIE is found that is a forward declaration | 
|  | 4860 | // DIE and we want to try and find a type that has the complete definition. | 
|  | 4861 | TypeSP | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4862 | SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die, | 
|  | 4863 | const ConstString &type_name, | 
|  | 4864 | bool must_be_implementation) | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4865 | { | 
|  | 4866 |  | 
|  | 4867 | TypeSP type_sp; | 
|  | 4868 |  | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4869 | if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name))) | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4870 | return type_sp; | 
|  | 4871 |  | 
|  | 4872 | DIEArray die_offsets; | 
|  | 4873 |  | 
|  | 4874 | if (m_using_apple_tables) | 
|  | 4875 | { | 
|  | 4876 | if (m_apple_types_ap.get()) | 
|  | 4877 | { | 
|  | 4878 | const char *name_cstr = type_name.GetCString(); | 
| Greg Clayton | 68221ec | 2012-01-18 20:58:12 +0000 | [diff] [blame] | 4879 | m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation); | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4880 | } | 
|  | 4881 | } | 
|  | 4882 | else | 
|  | 4883 | { | 
|  | 4884 | if (!m_indexed) | 
|  | 4885 | Index (); | 
|  | 4886 |  | 
|  | 4887 | m_type_index.Find (type_name, die_offsets); | 
|  | 4888 | } | 
|  | 4889 |  | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4890 | const size_t num_matches = die_offsets.size(); | 
|  | 4891 |  | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4892 | DWARFCompileUnit* type_cu = NULL; | 
|  | 4893 | const DWARFDebugInfoEntry* type_die = NULL; | 
|  | 4894 | if (num_matches) | 
|  | 4895 | { | 
|  | 4896 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 4897 | for (size_t i=0; i<num_matches; ++i) | 
|  | 4898 | { | 
|  | 4899 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 4900 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); | 
|  | 4901 |  | 
|  | 4902 | if (type_die) | 
|  | 4903 | { | 
|  | 4904 | bool try_resolving_type = false; | 
|  | 4905 |  | 
|  | 4906 | // Don't try and resolve the DIE we are looking for with the DIE itself! | 
|  | 4907 | if (type_die != die) | 
|  | 4908 | { | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4909 | switch (type_die->Tag()) | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4910 | { | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4911 | case DW_TAG_class_type: | 
|  | 4912 | case DW_TAG_structure_type: | 
|  | 4913 | try_resolving_type = true; | 
|  | 4914 | break; | 
|  | 4915 | default: | 
|  | 4916 | break; | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4917 | } | 
|  | 4918 | } | 
|  | 4919 |  | 
|  | 4920 | if (try_resolving_type) | 
|  | 4921 | { | 
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 4922 | if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type()) | 
|  | 4923 | 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] | 4924 |  | 
|  | 4925 | if (try_resolving_type) | 
|  | 4926 | { | 
|  | 4927 | Type *resolved_type = ResolveType (type_cu, type_die, false); | 
|  | 4928 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) | 
|  | 4929 | { | 
| Ed Maste | a0191d1 | 2013-10-17 20:42:56 +0000 | [diff] [blame] | 4930 | DEBUG_PRINTF ("resolved 0x%8.8" PRIx64 " from %s to 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ")\n", | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4931 | MakeUserID(die->GetOffset()), | 
| Jim Ingham | 4af5961 | 2014-12-19 19:20:44 +0000 | [diff] [blame^] | 4932 | m_obj_file->GetFileSpec().GetFilename().AsCString("<Unknown>"), | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4933 | MakeUserID(type_die->GetOffset()), | 
|  | 4934 | MakeUserID(type_cu->GetOffset())); | 
|  | 4935 |  | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4936 | if (die) | 
|  | 4937 | m_die_to_type[die] = resolved_type; | 
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 4938 | type_sp = resolved_type->shared_from_this(); | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4939 | break; | 
|  | 4940 | } | 
|  | 4941 | } | 
|  | 4942 | } | 
|  | 4943 | } | 
|  | 4944 | else | 
|  | 4945 | { | 
|  | 4946 | if (m_using_apple_tables) | 
|  | 4947 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4948 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", | 
|  | 4949 | die_offset, type_name.GetCString()); | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4950 | } | 
|  | 4951 | } | 
|  | 4952 |  | 
|  | 4953 | } | 
|  | 4954 | } | 
|  | 4955 | return type_sp; | 
|  | 4956 | } | 
|  | 4957 |  | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4958 |  | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4959 | //---------------------------------------------------------------------- | 
|  | 4960 | // This function helps to ensure that the declaration contexts match for | 
|  | 4961 | // two different DIEs. Often times debug information will refer to a | 
|  | 4962 | // forward declaration of a type (the equivalent of "struct my_struct;". | 
|  | 4963 | // There will often be a declaration of that type elsewhere that has the | 
|  | 4964 | // full definition. When we go looking for the full type "my_struct", we | 
|  | 4965 | // will find one or more matches in the accelerator tables and we will | 
|  | 4966 | // then need to make sure the type was in the same declaration context | 
|  | 4967 | // as the original DIE. This function can efficiently compare two DIEs | 
|  | 4968 | // and will return true when the declaration context matches, and false | 
|  | 4969 | // when they don't. | 
|  | 4970 | //---------------------------------------------------------------------- | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4971 | bool | 
|  | 4972 | SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1, | 
|  | 4973 | DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2) | 
|  | 4974 | { | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4975 | if (die1 == die2) | 
|  | 4976 | return true; | 
|  | 4977 |  | 
|  | 4978 | #if defined (LLDB_CONFIGURATION_DEBUG) | 
|  | 4979 | // You can't and shouldn't call this function with a compile unit from | 
|  | 4980 | // two different SymbolFileDWARF instances. | 
|  | 4981 | assert (DebugInfo()->ContainsCompileUnit (cu1)); | 
|  | 4982 | assert (DebugInfo()->ContainsCompileUnit (cu2)); | 
|  | 4983 | #endif | 
|  | 4984 |  | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4985 | DWARFDIECollection decl_ctx_1; | 
|  | 4986 | DWARFDIECollection decl_ctx_2; | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4987 | //The declaration DIE stack is a stack of the declaration context | 
|  | 4988 | // DIEs all the way back to the compile unit. If a type "T" is | 
|  | 4989 | // declared inside a class "B", and class "B" is declared inside | 
|  | 4990 | // a class "A" and class "A" is in a namespace "lldb", and the | 
|  | 4991 | // namespace is in a compile unit, there will be a stack of DIEs: | 
|  | 4992 | // | 
|  | 4993 | //   [0] DW_TAG_class_type for "B" | 
|  | 4994 | //   [1] DW_TAG_class_type for "A" | 
|  | 4995 | //   [2] DW_TAG_namespace  for "lldb" | 
|  | 4996 | //   [3] DW_TAG_compile_unit for the source file. | 
|  | 4997 | // | 
|  | 4998 | // We grab both contexts and make sure that everything matches | 
|  | 4999 | // all the way back to the compiler unit. | 
|  | 5000 |  | 
|  | 5001 | // First lets grab the decl contexts for both DIEs | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5002 | die1->GetDeclContextDIEs (this, cu1, decl_ctx_1); | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5003 | die2->GetDeclContextDIEs (this, cu2, decl_ctx_2); | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5004 | // Make sure the context arrays have the same size, otherwise | 
|  | 5005 | // we are done | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5006 | const size_t count1 = decl_ctx_1.Size(); | 
|  | 5007 | const size_t count2 = decl_ctx_2.Size(); | 
|  | 5008 | if (count1 != count2) | 
|  | 5009 | return false; | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5010 |  | 
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 5011 | // Make sure the DW_TAG values match all the way back up the | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5012 | // compile unit. If they don't, then we are done. | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5013 | const DWARFDebugInfoEntry *decl_ctx_die1; | 
|  | 5014 | const DWARFDebugInfoEntry *decl_ctx_die2; | 
|  | 5015 | size_t i; | 
|  | 5016 | for (i=0; i<count1; i++) | 
|  | 5017 | { | 
|  | 5018 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); | 
|  | 5019 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); | 
|  | 5020 | if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag()) | 
|  | 5021 | return false; | 
|  | 5022 | } | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5023 | #if defined LLDB_CONFIGURATION_DEBUG | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5024 |  | 
|  | 5025 | // Make sure the top item in the decl context die array is always | 
|  | 5026 | // DW_TAG_compile_unit. If it isn't then something went wrong in | 
|  | 5027 | // the DWARFDebugInfoEntry::GetDeclContextDIEs() function... | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5028 | assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit); | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5029 |  | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5030 | #endif | 
|  | 5031 | // Always skip the compile unit when comparing by only iterating up to | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5032 | // "count - 1". Here we compare the names as we go. | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5033 | for (i=0; i<count1 - 1; i++) | 
|  | 5034 | { | 
|  | 5035 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); | 
|  | 5036 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); | 
|  | 5037 | const char *name1 = decl_ctx_die1->GetName(this, cu1); | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5038 | const char *name2 = decl_ctx_die2->GetName(this, cu2); | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5039 | // If the string was from a DW_FORM_strp, then the pointer will often | 
|  | 5040 | // be the same! | 
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 5041 | if (name1 == name2) | 
|  | 5042 | continue; | 
|  | 5043 |  | 
|  | 5044 | // Name pointers are not equal, so only compare the strings | 
|  | 5045 | // if both are not NULL. | 
|  | 5046 | if (name1 && name2) | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5047 | { | 
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 5048 | // If the strings don't compare, we are done... | 
|  | 5049 | if (strcmp(name1, name2) != 0) | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5050 | return false; | 
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 5051 | } | 
|  | 5052 | else | 
|  | 5053 | { | 
|  | 5054 | // One name was NULL while the other wasn't | 
|  | 5055 | return false; | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5056 | } | 
|  | 5057 | } | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5058 | // We made it through all of the checks and the declaration contexts | 
|  | 5059 | // are equal. | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5060 | return true; | 
|  | 5061 | } | 
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 5062 |  | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 5063 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5064 | TypeSP | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5065 | SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx) | 
|  | 5066 | { | 
|  | 5067 | TypeSP type_sp; | 
|  | 5068 |  | 
|  | 5069 | const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize(); | 
|  | 5070 | if (dwarf_decl_ctx_count > 0) | 
|  | 5071 | { | 
|  | 5072 | const ConstString type_name(dwarf_decl_ctx[0].name); | 
|  | 5073 | const dw_tag_t tag = dwarf_decl_ctx[0].tag; | 
|  | 5074 |  | 
|  | 5075 | if (type_name) | 
|  | 5076 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5077 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5078 | if (log) | 
|  | 5079 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5080 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5081 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')", | 
|  | 5082 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), | 
|  | 5083 | dwarf_decl_ctx.GetQualifiedName()); | 
|  | 5084 | } | 
|  | 5085 |  | 
|  | 5086 | DIEArray die_offsets; | 
|  | 5087 |  | 
|  | 5088 | if (m_using_apple_tables) | 
|  | 5089 | { | 
|  | 5090 | if (m_apple_types_ap.get()) | 
|  | 5091 | { | 
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 5092 | const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag); | 
|  | 5093 | const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash); | 
|  | 5094 | if (has_tag && has_qualified_name_hash) | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5095 | { | 
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 5096 | const char *qualified_name = dwarf_decl_ctx.GetQualifiedName(); | 
|  | 5097 | const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name); | 
|  | 5098 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5099 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()"); | 
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 5100 | m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets); | 
|  | 5101 | } | 
|  | 5102 | else if (has_tag) | 
|  | 5103 | { | 
|  | 5104 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5105 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()"); | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5106 | m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets); | 
|  | 5107 | } | 
|  | 5108 | else | 
|  | 5109 | { | 
|  | 5110 | m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets); | 
|  | 5111 | } | 
|  | 5112 | } | 
|  | 5113 | } | 
|  | 5114 | else | 
|  | 5115 | { | 
|  | 5116 | if (!m_indexed) | 
|  | 5117 | Index (); | 
|  | 5118 |  | 
|  | 5119 | m_type_index.Find (type_name, die_offsets); | 
|  | 5120 | } | 
|  | 5121 |  | 
|  | 5122 | const size_t num_matches = die_offsets.size(); | 
|  | 5123 |  | 
|  | 5124 |  | 
|  | 5125 | DWARFCompileUnit* type_cu = NULL; | 
|  | 5126 | const DWARFDebugInfoEntry* type_die = NULL; | 
|  | 5127 | if (num_matches) | 
|  | 5128 | { | 
|  | 5129 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 5130 | for (size_t i=0; i<num_matches; ++i) | 
|  | 5131 | { | 
|  | 5132 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 5133 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); | 
|  | 5134 |  | 
|  | 5135 | if (type_die) | 
|  | 5136 | { | 
|  | 5137 | bool try_resolving_type = false; | 
|  | 5138 |  | 
|  | 5139 | // Don't try and resolve the DIE we are looking for with the DIE itself! | 
|  | 5140 | const dw_tag_t type_tag = type_die->Tag(); | 
|  | 5141 | // Make sure the tags match | 
|  | 5142 | if (type_tag == tag) | 
|  | 5143 | { | 
|  | 5144 | // The tags match, lets try resolving this type | 
|  | 5145 | try_resolving_type = true; | 
|  | 5146 | } | 
|  | 5147 | else | 
|  | 5148 | { | 
|  | 5149 | // The tags don't match, but we need to watch our for a | 
|  | 5150 | // forward declaration for a struct and ("struct foo") | 
|  | 5151 | // ends up being a class ("class foo { ... };") or | 
|  | 5152 | // vice versa. | 
|  | 5153 | switch (type_tag) | 
|  | 5154 | { | 
|  | 5155 | case DW_TAG_class_type: | 
|  | 5156 | // We had a "class foo", see if we ended up with a "struct foo { ... };" | 
|  | 5157 | try_resolving_type = (tag == DW_TAG_structure_type); | 
|  | 5158 | break; | 
|  | 5159 | case DW_TAG_structure_type: | 
|  | 5160 | // We had a "struct foo", see if we ended up with a "class foo { ... };" | 
|  | 5161 | try_resolving_type = (tag == DW_TAG_class_type); | 
|  | 5162 | break; | 
|  | 5163 | default: | 
|  | 5164 | // Tags don't match, don't event try to resolve | 
|  | 5165 | // using this type whose name matches.... | 
|  | 5166 | break; | 
|  | 5167 | } | 
|  | 5168 | } | 
|  | 5169 |  | 
|  | 5170 | if (try_resolving_type) | 
|  | 5171 | { | 
|  | 5172 | DWARFDeclContext type_dwarf_decl_ctx; | 
|  | 5173 | type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx); | 
|  | 5174 |  | 
|  | 5175 | if (log) | 
|  | 5176 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5177 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5178 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)", | 
|  | 5179 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), | 
|  | 5180 | dwarf_decl_ctx.GetQualifiedName(), | 
|  | 5181 | type_die->GetOffset(), | 
|  | 5182 | type_dwarf_decl_ctx.GetQualifiedName()); | 
|  | 5183 | } | 
|  | 5184 |  | 
|  | 5185 | // Make sure the decl contexts match all the way up | 
|  | 5186 | if (dwarf_decl_ctx == type_dwarf_decl_ctx) | 
|  | 5187 | { | 
|  | 5188 | Type *resolved_type = ResolveType (type_cu, type_die, false); | 
|  | 5189 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) | 
|  | 5190 | { | 
|  | 5191 | type_sp = resolved_type->shared_from_this(); | 
|  | 5192 | break; | 
|  | 5193 | } | 
|  | 5194 | } | 
|  | 5195 | } | 
|  | 5196 | else | 
|  | 5197 | { | 
|  | 5198 | if (log) | 
|  | 5199 | { | 
|  | 5200 | std::string qualified_name; | 
|  | 5201 | type_die->GetQualifiedName(this, type_cu, qualified_name); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5202 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5203 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)", | 
|  | 5204 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), | 
|  | 5205 | dwarf_decl_ctx.GetQualifiedName(), | 
|  | 5206 | type_die->GetOffset(), | 
|  | 5207 | qualified_name.c_str()); | 
|  | 5208 | } | 
|  | 5209 | } | 
|  | 5210 | } | 
|  | 5211 | else | 
|  | 5212 | { | 
|  | 5213 | if (m_using_apple_tables) | 
|  | 5214 | { | 
|  | 5215 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", | 
|  | 5216 | die_offset, type_name.GetCString()); | 
|  | 5217 | } | 
|  | 5218 | } | 
|  | 5219 |  | 
|  | 5220 | } | 
|  | 5221 | } | 
|  | 5222 | } | 
|  | 5223 | } | 
|  | 5224 | return type_sp; | 
|  | 5225 | } | 
|  | 5226 |  | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5227 | bool | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5228 | SymbolFileDWARF::CopyUniqueClassMethodTypes (SymbolFileDWARF *src_symfile, | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5229 | Type *class_type, | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5230 | DWARFCompileUnit* src_cu, | 
|  | 5231 | const DWARFDebugInfoEntry *src_class_die, | 
|  | 5232 | DWARFCompileUnit* dst_cu, | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5233 | const DWARFDebugInfoEntry *dst_class_die, | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 5234 | DWARFDIECollection &failures) | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5235 | { | 
|  | 5236 | if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die) | 
|  | 5237 | return false; | 
|  | 5238 | if (src_class_die->Tag() != dst_class_die->Tag()) | 
|  | 5239 | return false; | 
|  | 5240 |  | 
|  | 5241 | // We need to complete the class type so we can get all of the method types | 
|  | 5242 | // parsed so we can then unique those types to their equivalent counterparts | 
|  | 5243 | // in "dst_cu" and "dst_class_die" | 
|  | 5244 | class_type->GetClangFullType(); | 
|  | 5245 |  | 
|  | 5246 | const DWARFDebugInfoEntry *src_die; | 
|  | 5247 | const DWARFDebugInfoEntry *dst_die; | 
|  | 5248 | UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die; | 
|  | 5249 | UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die; | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5250 | UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die_artificial; | 
|  | 5251 | UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die_artificial; | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5252 | for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling()) | 
|  | 5253 | { | 
|  | 5254 | if (src_die->Tag() == DW_TAG_subprogram) | 
|  | 5255 | { | 
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5256 | // Make sure this is a declaration and not a concrete instance by looking | 
|  | 5257 | // for DW_AT_declaration set to 1. Sometimes concrete function instances | 
|  | 5258 | // are placed inside the class definitions and shouldn't be included in | 
|  | 5259 | // the list of things are are tracking here. | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5260 | 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] | 5261 | { | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5262 | const char *src_name = src_die->GetMangledName (src_symfile, src_cu); | 
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5263 | if (src_name) | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5264 | { | 
|  | 5265 | ConstString src_const_name(src_name); | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5266 | if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_artificial, 0)) | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5267 | src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die); | 
|  | 5268 | else | 
|  | 5269 | src_name_to_die.Append(src_const_name.GetCString(), src_die); | 
|  | 5270 | } | 
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5271 | } | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5272 | } | 
|  | 5273 | } | 
|  | 5274 | for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling()) | 
|  | 5275 | { | 
|  | 5276 | if (dst_die->Tag() == DW_TAG_subprogram) | 
|  | 5277 | { | 
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5278 | // Make sure this is a declaration and not a concrete instance by looking | 
|  | 5279 | // for DW_AT_declaration set to 1. Sometimes concrete function instances | 
|  | 5280 | // are placed inside the class definitions and shouldn't be included in | 
|  | 5281 | // the list of things are are tracking here. | 
|  | 5282 | if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_declaration, 0) == 1) | 
|  | 5283 | { | 
|  | 5284 | const char *dst_name = dst_die->GetMangledName (this, dst_cu); | 
|  | 5285 | if (dst_name) | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5286 | { | 
|  | 5287 | ConstString dst_const_name(dst_name); | 
|  | 5288 | if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_artificial, 0)) | 
|  | 5289 | dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die); | 
|  | 5290 | else | 
|  | 5291 | dst_name_to_die.Append(dst_const_name.GetCString(), dst_die); | 
|  | 5292 | } | 
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5293 | } | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5294 | } | 
|  | 5295 | } | 
|  | 5296 | const uint32_t src_size = src_name_to_die.GetSize (); | 
|  | 5297 | const uint32_t dst_size = dst_name_to_die.GetSize (); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5298 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION)); | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5299 |  | 
|  | 5300 | // Is everything kosher so we can go through the members at top speed? | 
|  | 5301 | bool fast_path = true; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5302 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5303 | if (src_size != dst_size) | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5304 | { | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5305 | if (src_size != 0 && dst_size != 0) | 
|  | 5306 | { | 
|  | 5307 | if (log) | 
|  | 5308 | 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)", | 
|  | 5309 | src_class_die->GetOffset(), | 
|  | 5310 | dst_class_die->GetOffset(), | 
|  | 5311 | src_size, | 
|  | 5312 | dst_size); | 
|  | 5313 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5314 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5315 | fast_path = false; | 
|  | 5316 | } | 
|  | 5317 |  | 
|  | 5318 | uint32_t idx; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5319 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5320 | if (fast_path) | 
|  | 5321 | { | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5322 | for (idx = 0; idx < src_size; ++idx) | 
|  | 5323 | { | 
|  | 5324 | src_die = src_name_to_die.GetValueAtIndexUnchecked (idx); | 
|  | 5325 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx); | 
|  | 5326 |  | 
|  | 5327 | if (src_die->Tag() != dst_die->Tag()) | 
|  | 5328 | { | 
|  | 5329 | if (log) | 
|  | 5330 | 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)", | 
|  | 5331 | src_class_die->GetOffset(), | 
|  | 5332 | dst_class_die->GetOffset(), | 
|  | 5333 | src_die->GetOffset(), | 
|  | 5334 | DW_TAG_value_to_name(src_die->Tag()), | 
|  | 5335 | dst_die->GetOffset(), | 
|  | 5336 | DW_TAG_value_to_name(src_die->Tag())); | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5337 | fast_path = false; | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5338 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5339 |  | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5340 | const char *src_name = src_die->GetMangledName (src_symfile, src_cu); | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5341 | const char *dst_name = dst_die->GetMangledName (this, dst_cu); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5342 |  | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5343 | // Make sure the names match | 
|  | 5344 | if (src_name == dst_name || (strcmp (src_name, dst_name) == 0)) | 
|  | 5345 | continue; | 
|  | 5346 |  | 
|  | 5347 | if (log) | 
|  | 5348 | 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)", | 
|  | 5349 | src_class_die->GetOffset(), | 
|  | 5350 | dst_class_die->GetOffset(), | 
|  | 5351 | src_die->GetOffset(), | 
|  | 5352 | src_name, | 
|  | 5353 | dst_die->GetOffset(), | 
|  | 5354 | dst_name); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5355 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5356 | fast_path = false; | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5357 | } | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5358 | } | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5359 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5360 | // Now do the work of linking the DeclContexts and Types. | 
|  | 5361 | if (fast_path) | 
|  | 5362 | { | 
|  | 5363 | // We can do this quickly.  Just run across the tables index-for-index since | 
|  | 5364 | // we know each node has matching names and tags. | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5365 | for (idx = 0; idx < src_size; ++idx) | 
|  | 5366 | { | 
|  | 5367 | src_die = src_name_to_die.GetValueAtIndexUnchecked (idx); | 
|  | 5368 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5369 |  | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5370 | 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] | 5371 | if (src_decl_ctx) | 
|  | 5372 | { | 
|  | 5373 | if (log) | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5374 | log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", | 
|  | 5375 | static_cast<void*>(src_decl_ctx), | 
|  | 5376 | src_die->GetOffset(), dst_die->GetOffset()); | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5377 | LinkDeclContextToDIE (src_decl_ctx, dst_die); | 
|  | 5378 | } | 
|  | 5379 | else | 
|  | 5380 | { | 
|  | 5381 | if (log) | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5382 | log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found", | 
|  | 5383 | src_die->GetOffset(), dst_die->GetOffset()); | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5384 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5385 |  | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5386 | Type *src_child_type = m_die_to_type[src_die]; | 
|  | 5387 | if (src_child_type) | 
|  | 5388 | { | 
|  | 5389 | if (log) | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5390 | log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", | 
|  | 5391 | static_cast<void*>(src_child_type), | 
|  | 5392 | src_child_type->GetID(), | 
|  | 5393 | src_die->GetOffset(), dst_die->GetOffset()); | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5394 | m_die_to_type[dst_die] = src_child_type; | 
|  | 5395 | } | 
|  | 5396 | else | 
|  | 5397 | { | 
|  | 5398 | if (log) | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5399 | 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()); | 
|  | 5400 | } | 
|  | 5401 | } | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5402 | } | 
|  | 5403 | else | 
|  | 5404 | { | 
|  | 5405 | // We must do this slowly.  For each member of the destination, look | 
|  | 5406 | // up a member in the source with the same name, check its tag, and | 
|  | 5407 | // unique them if everything matches up.  Report failures. | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5408 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5409 | if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty()) | 
|  | 5410 | { | 
|  | 5411 | src_name_to_die.Sort(); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5412 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5413 | for (idx = 0; idx < dst_size; ++idx) | 
|  | 5414 | { | 
|  | 5415 | const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx); | 
|  | 5416 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx); | 
|  | 5417 | src_die = src_name_to_die.Find(dst_name, NULL); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5418 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5419 | if (src_die && (src_die->Tag() == dst_die->Tag())) | 
|  | 5420 | { | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5421 | 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] | 5422 | if (src_decl_ctx) | 
|  | 5423 | { | 
|  | 5424 | if (log) | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5425 | log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", | 
|  | 5426 | static_cast<void*>(src_decl_ctx), | 
|  | 5427 | src_die->GetOffset(), | 
|  | 5428 | dst_die->GetOffset()); | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5429 | LinkDeclContextToDIE (src_decl_ctx, dst_die); | 
|  | 5430 | } | 
|  | 5431 | else | 
|  | 5432 | { | 
|  | 5433 | if (log) | 
|  | 5434 | 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()); | 
|  | 5435 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5436 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5437 | Type *src_child_type = m_die_to_type[src_die]; | 
|  | 5438 | if (src_child_type) | 
|  | 5439 | { | 
|  | 5440 | if (log) | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5441 | log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", | 
|  | 5442 | static_cast<void*>(src_child_type), | 
|  | 5443 | src_child_type->GetID(), | 
|  | 5444 | src_die->GetOffset(), | 
|  | 5445 | dst_die->GetOffset()); | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5446 | m_die_to_type[dst_die] = src_child_type; | 
|  | 5447 | } | 
|  | 5448 | else | 
|  | 5449 | { | 
|  | 5450 | if (log) | 
|  | 5451 | 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()); | 
|  | 5452 | } | 
|  | 5453 | } | 
|  | 5454 | else | 
|  | 5455 | { | 
|  | 5456 | if (log) | 
|  | 5457 | 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] | 5458 |  | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 5459 | failures.Append(dst_die); | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5460 | } | 
|  | 5461 | } | 
|  | 5462 | } | 
|  | 5463 | } | 
|  | 5464 |  | 
|  | 5465 | const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize (); | 
|  | 5466 | const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize (); | 
|  | 5467 |  | 
|  | 5468 | UniqueCStringMap<const DWARFDebugInfoEntry *> name_to_die_artificial_not_in_src; | 
|  | 5469 |  | 
|  | 5470 | if (src_size_artificial && dst_size_artificial) | 
|  | 5471 | { | 
|  | 5472 | dst_name_to_die_artificial.Sort(); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5473 |  | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5474 | for (idx = 0; idx < src_size_artificial; ++idx) | 
|  | 5475 | { | 
|  | 5476 | const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx); | 
|  | 5477 | src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx); | 
|  | 5478 | dst_die = dst_name_to_die_artificial.Find(src_name_artificial, NULL); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5479 |  | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5480 | if (dst_die) | 
|  | 5481 | { | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5482 | // Both classes have the artificial types, link them | 
|  | 5483 | clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die]; | 
|  | 5484 | if (src_decl_ctx) | 
|  | 5485 | { | 
|  | 5486 | if (log) | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5487 | log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", | 
|  | 5488 | static_cast<void*>(src_decl_ctx), | 
|  | 5489 | src_die->GetOffset(), dst_die->GetOffset()); | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5490 | LinkDeclContextToDIE (src_decl_ctx, dst_die); | 
|  | 5491 | } | 
|  | 5492 | else | 
|  | 5493 | { | 
|  | 5494 | if (log) | 
|  | 5495 | 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()); | 
|  | 5496 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5497 |  | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5498 | Type *src_child_type = m_die_to_type[src_die]; | 
|  | 5499 | if (src_child_type) | 
|  | 5500 | { | 
|  | 5501 | if (log) | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5502 | log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", | 
|  | 5503 | static_cast<void*>(src_child_type), | 
|  | 5504 | src_child_type->GetID(), | 
|  | 5505 | src_die->GetOffset(), dst_die->GetOffset()); | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5506 | m_die_to_type[dst_die] = src_child_type; | 
|  | 5507 | } | 
|  | 5508 | else | 
|  | 5509 | { | 
|  | 5510 | if (log) | 
|  | 5511 | 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()); | 
|  | 5512 | } | 
|  | 5513 | } | 
|  | 5514 | } | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5515 | } | 
| 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 | if (dst_size_artificial) | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5518 | { | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5519 | for (idx = 0; idx < dst_size_artificial; ++idx) | 
|  | 5520 | { | 
|  | 5521 | const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx); | 
|  | 5522 | dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx); | 
|  | 5523 | if (log) | 
|  | 5524 | log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die->GetOffset(), dst_name_artificial); | 
|  | 5525 |  | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 5526 | failures.Append(dst_die); | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5527 | } | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5528 | } | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5529 |  | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 5530 | return (failures.Size() != 0); | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5531 | } | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5532 |  | 
|  | 5533 | TypeSP | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5534 | 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] | 5535 | { | 
|  | 5536 | TypeSP type_sp; | 
|  | 5537 |  | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5538 | if (type_is_new_ptr) | 
|  | 5539 | *type_is_new_ptr = false; | 
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5540 |  | 
| Todd Fiala | 0a70a84 | 2014-05-28 16:43:26 +0000 | [diff] [blame] | 5541 | #if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE) | 
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5542 | static DIEStack g_die_stack; | 
|  | 5543 | DIEStack::ScopedPopper scoped_die_logger(g_die_stack); | 
|  | 5544 | #endif | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5545 |  | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 5546 | AccessType accessibility = eAccessNone; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5547 | if (die != NULL) | 
|  | 5548 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5549 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5550 | if (log) | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5551 | { | 
|  | 5552 | const DWARFDebugInfoEntry *context_die; | 
|  | 5553 | clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5554 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5555 | GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x, decl_ctx = %p (die 0x%8.8x)) %s name = '%s')", | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5556 | die->GetOffset(), | 
|  | 5557 | static_cast<void*>(context), | 
|  | 5558 | context_die->GetOffset(), | 
|  | 5559 | DW_TAG_value_to_name(die->Tag()), | 
|  | 5560 | die->GetName(this, dwarf_cu)); | 
|  | 5561 |  | 
| Todd Fiala | 0a70a84 | 2014-05-28 16:43:26 +0000 | [diff] [blame] | 5562 | #if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE) | 
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5563 | scoped_die_logger.Push (dwarf_cu, die); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5564 | g_die_stack.LogDIEs(log, this); | 
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5565 | #endif | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5566 | } | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5567 | // | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5568 | //        Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5569 | //        if (log && dwarf_cu) | 
|  | 5570 | //        { | 
|  | 5571 | //            StreamString s; | 
|  | 5572 | //            die->DumpLocation (this, dwarf_cu, s); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5573 | //            GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData()); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5574 | // | 
|  | 5575 | //        } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5576 |  | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5577 | Type *type_ptr = m_die_to_type.lookup (die); | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5578 | TypeList* type_list = GetTypeList(); | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5579 | if (type_ptr == NULL) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5580 | { | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5581 | ClangASTContext &ast = GetClangASTContext(); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5582 | if (type_is_new_ptr) | 
|  | 5583 | *type_is_new_ptr = true; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5584 |  | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5585 | const dw_tag_t tag = die->Tag(); | 
|  | 5586 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5587 | bool is_forward_declaration = false; | 
|  | 5588 | DWARFDebugInfoEntry::Attributes attributes; | 
|  | 5589 | const char *type_name_cstr = NULL; | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5590 | ConstString type_name_const_str; | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5591 | Type::ResolveState resolve_state = Type::eResolveStateUnresolved; | 
| Greg Clayton | faac111 | 2013-03-14 18:31:44 +0000 | [diff] [blame] | 5592 | uint64_t byte_size = 0; | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5593 | Declaration decl; | 
|  | 5594 |  | 
| Greg Clayton | 4957bf6 | 2010-09-30 21:49:03 +0000 | [diff] [blame] | 5595 | Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5596 | ClangASTType clang_type; | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 5597 | DWARFFormValue form_value; | 
|  | 5598 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5599 | dw_attr_t attr; | 
|  | 5600 |  | 
|  | 5601 | switch (tag) | 
|  | 5602 | { | 
|  | 5603 | case DW_TAG_base_type: | 
|  | 5604 | case DW_TAG_pointer_type: | 
|  | 5605 | case DW_TAG_reference_type: | 
| Sean Callanan | ce8af86 | 2012-05-21 23:31:51 +0000 | [diff] [blame] | 5606 | case DW_TAG_rvalue_reference_type: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5607 | case DW_TAG_typedef: | 
|  | 5608 | case DW_TAG_const_type: | 
|  | 5609 | case DW_TAG_restrict_type: | 
|  | 5610 | case DW_TAG_volatile_type: | 
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5611 | case DW_TAG_unspecified_type: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5612 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5613 | // 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] | 5614 | m_die_to_type[die] = DIE_IS_BEING_PARSED; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5615 |  | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5616 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5617 | uint32_t encoding = 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5618 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; | 
|  | 5619 |  | 
|  | 5620 | if (num_attributes > 0) | 
|  | 5621 | { | 
|  | 5622 | uint32_t i; | 
|  | 5623 | for (i=0; i<num_attributes; ++i) | 
|  | 5624 | { | 
|  | 5625 | attr = attributes.AttributeAtIndex(i); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5626 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 5627 | { | 
|  | 5628 | switch (attr) | 
|  | 5629 | { | 
|  | 5630 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 5631 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 5632 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 5633 | case DW_AT_name: | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5634 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5635 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); | 
| Jim Ingham | 337030f | 2011-04-15 23:41:23 +0000 | [diff] [blame] | 5636 | // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't | 
|  | 5637 | // include the "&"... | 
|  | 5638 | if (tag == DW_TAG_reference_type) | 
|  | 5639 | { | 
|  | 5640 | if (strchr (type_name_cstr, '&') == NULL) | 
|  | 5641 | type_name_cstr = NULL; | 
|  | 5642 | } | 
|  | 5643 | if (type_name_cstr) | 
|  | 5644 | type_name_const_str.SetCString(type_name_cstr); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5645 | break; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 5646 | case DW_AT_byte_size:   byte_size = form_value.Unsigned(); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5647 | case DW_AT_encoding:    encoding = form_value.Unsigned(); break; | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 5648 | case DW_AT_type:        encoding_uid = form_value.Reference(); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5649 | default: | 
|  | 5650 | case DW_AT_sibling: | 
|  | 5651 | break; | 
|  | 5652 | } | 
|  | 5653 | } | 
|  | 5654 | } | 
|  | 5655 | } | 
|  | 5656 |  | 
| Ed Maste | a0191d1 | 2013-10-17 20:42:56 +0000 | [diff] [blame] | 5657 | DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\") type => 0x%8.8lx\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr, encoding_uid); | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 5658 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5659 | switch (tag) | 
|  | 5660 | { | 
|  | 5661 | default: | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5662 | break; | 
|  | 5663 |  | 
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5664 | case DW_TAG_unspecified_type: | 
| Greg Clayton | 7fba263 | 2013-07-01 21:01:52 +0000 | [diff] [blame] | 5665 | if (strcmp(type_name_cstr, "nullptr_t") == 0 || | 
|  | 5666 | strcmp(type_name_cstr, "decltype(nullptr)") == 0 ) | 
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5667 | { | 
|  | 5668 | resolve_state = Type::eResolveStateFull; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5669 | clang_type = ast.GetBasicType(eBasicTypeNullPtr); | 
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5670 | break; | 
|  | 5671 | } | 
|  | 5672 | // Fall through to base type below in case we can handle the type there... | 
|  | 5673 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5674 | case DW_TAG_base_type: | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5675 | resolve_state = Type::eResolveStateFull; | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5676 | clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr, | 
|  | 5677 | encoding, | 
|  | 5678 | byte_size * 8); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5679 | break; | 
|  | 5680 |  | 
| Sean Callanan | ce8af86 | 2012-05-21 23:31:51 +0000 | [diff] [blame] | 5681 | case DW_TAG_pointer_type:           encoding_data_type = Type::eEncodingIsPointerUID;           break; | 
|  | 5682 | case DW_TAG_reference_type:         encoding_data_type = Type::eEncodingIsLValueReferenceUID;   break; | 
|  | 5683 | case DW_TAG_rvalue_reference_type:  encoding_data_type = Type::eEncodingIsRValueReferenceUID;   break; | 
|  | 5684 | case DW_TAG_typedef:                encoding_data_type = Type::eEncodingIsTypedefUID;           break; | 
|  | 5685 | case DW_TAG_const_type:             encoding_data_type = Type::eEncodingIsConstUID;             break; | 
|  | 5686 | case DW_TAG_restrict_type:          encoding_data_type = Type::eEncodingIsRestrictUID;          break; | 
|  | 5687 | case DW_TAG_volatile_type:          encoding_data_type = Type::eEncodingIsVolatileUID;          break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5688 | } | 
|  | 5689 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5690 | 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] | 5691 | { | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5692 | bool translation_unit_is_objc = (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5693 |  | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5694 | if (translation_unit_is_objc) | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 5695 | { | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5696 | if (type_name_cstr != NULL) | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5697 | { | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5698 | static ConstString g_objc_type_name_id("id"); | 
|  | 5699 | static ConstString g_objc_type_name_Class("Class"); | 
|  | 5700 | static ConstString g_objc_type_name_selector("SEL"); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5701 |  | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5702 | if (type_name_const_str == g_objc_type_name_id) | 
|  | 5703 | { | 
|  | 5704 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5705 | 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] | 5706 | die->GetOffset(), | 
|  | 5707 | DW_TAG_value_to_name(die->Tag()), | 
|  | 5708 | die->GetName(this, dwarf_cu)); | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5709 | clang_type = ast.GetBasicType(eBasicTypeObjCID); | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5710 | encoding_data_type = Type::eEncodingIsUID; | 
|  | 5711 | encoding_uid = LLDB_INVALID_UID; | 
|  | 5712 | resolve_state = Type::eResolveStateFull; | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5713 |  | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5714 | } | 
|  | 5715 | else if (type_name_const_str == g_objc_type_name_Class) | 
|  | 5716 | { | 
|  | 5717 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5718 | 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] | 5719 | die->GetOffset(), | 
|  | 5720 | DW_TAG_value_to_name(die->Tag()), | 
|  | 5721 | die->GetName(this, dwarf_cu)); | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5722 | clang_type = ast.GetBasicType(eBasicTypeObjCClass); | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5723 | encoding_data_type = Type::eEncodingIsUID; | 
|  | 5724 | encoding_uid = LLDB_INVALID_UID; | 
|  | 5725 | resolve_state = Type::eResolveStateFull; | 
|  | 5726 | } | 
|  | 5727 | else if (type_name_const_str == g_objc_type_name_selector) | 
|  | 5728 | { | 
|  | 5729 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5730 | 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] | 5731 | die->GetOffset(), | 
|  | 5732 | DW_TAG_value_to_name(die->Tag()), | 
|  | 5733 | die->GetName(this, dwarf_cu)); | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5734 | clang_type = ast.GetBasicType(eBasicTypeObjCSel); | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5735 | encoding_data_type = Type::eEncodingIsUID; | 
|  | 5736 | encoding_uid = LLDB_INVALID_UID; | 
|  | 5737 | resolve_state = Type::eResolveStateFull; | 
|  | 5738 | } | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5739 | } | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5740 | else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid != LLDB_INVALID_UID) | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5741 | { | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5742 | // Clang sometimes erroneously emits id as objc_object*.  In that case we fix up the type to "id". | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5743 |  | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5744 | DWARFDebugInfoEntry* encoding_die = dwarf_cu->GetDIEPtr(encoding_uid); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5745 |  | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5746 | if (encoding_die && encoding_die->Tag() == DW_TAG_structure_type) | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5747 | { | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5748 | if (const char *struct_name = encoding_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL)) | 
|  | 5749 | { | 
|  | 5750 | if (!strcmp(struct_name, "objc_object")) | 
|  | 5751 | { | 
|  | 5752 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5753 | 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] | 5754 | die->GetOffset(), | 
|  | 5755 | DW_TAG_value_to_name(die->Tag()), | 
|  | 5756 | die->GetName(this, dwarf_cu)); | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5757 | clang_type = ast.GetBasicType(eBasicTypeObjCID); | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5758 | encoding_data_type = Type::eEncodingIsUID; | 
|  | 5759 | encoding_uid = LLDB_INVALID_UID; | 
|  | 5760 | resolve_state = Type::eResolveStateFull; | 
|  | 5761 | } | 
|  | 5762 | } | 
|  | 5763 | } | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5764 | } | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 5765 | } | 
|  | 5766 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5767 |  | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5768 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5769 | this, | 
|  | 5770 | type_name_const_str, | 
|  | 5771 | byte_size, | 
|  | 5772 | NULL, | 
|  | 5773 | encoding_uid, | 
|  | 5774 | encoding_data_type, | 
|  | 5775 | &decl, | 
|  | 5776 | clang_type, | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5777 | resolve_state)); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5778 |  | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5779 | m_die_to_type[die] = type_sp.get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5780 |  | 
|  | 5781 | //                  Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false); | 
|  | 5782 | //                  if (encoding_type != NULL) | 
|  | 5783 | //                  { | 
|  | 5784 | //                      if (encoding_type != DIE_IS_BEING_PARSED) | 
|  | 5785 | //                          type_sp->SetEncodingType(encoding_type); | 
|  | 5786 | //                      else | 
|  | 5787 | //                          m_indirect_fixups.push_back(type_sp.get()); | 
|  | 5788 | //                  } | 
|  | 5789 | } | 
|  | 5790 | break; | 
|  | 5791 |  | 
|  | 5792 | case DW_TAG_structure_type: | 
|  | 5793 | case DW_TAG_union_type: | 
|  | 5794 | case DW_TAG_class_type: | 
|  | 5795 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5796 | // 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] | 5797 | m_die_to_type[die] = DIE_IS_BEING_PARSED; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 5798 | bool byte_size_valid = false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5799 |  | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5800 | LanguageType class_language = eLanguageTypeUnknown; | 
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 5801 | bool is_complete_objc_class = false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5802 | //bool struct_is_class = false; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5803 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5804 | if (num_attributes > 0) | 
|  | 5805 | { | 
|  | 5806 | uint32_t i; | 
|  | 5807 | for (i=0; i<num_attributes; ++i) | 
|  | 5808 | { | 
|  | 5809 | attr = attributes.AttributeAtIndex(i); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5810 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 5811 | { | 
|  | 5812 | switch (attr) | 
|  | 5813 | { | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5814 | case DW_AT_decl_file: | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5815 | if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid()) | 
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 5816 | { | 
|  | 5817 | // llvm-gcc outputs invalid DW_AT_decl_file attributes that always | 
|  | 5818 | // point to the compile unit file, so we clear this invalid value | 
|  | 5819 | // so that we can still unique types efficiently. | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5820 | decl.SetFile(FileSpec ("<invalid>", false)); | 
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 5821 | } | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5822 | else | 
|  | 5823 | decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5824 | break; | 
|  | 5825 |  | 
|  | 5826 | case DW_AT_decl_line: | 
|  | 5827 | decl.SetLine(form_value.Unsigned()); | 
|  | 5828 | break; | 
|  | 5829 |  | 
|  | 5830 | case DW_AT_decl_column: | 
|  | 5831 | decl.SetColumn(form_value.Unsigned()); | 
|  | 5832 | break; | 
|  | 5833 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5834 | case DW_AT_name: | 
|  | 5835 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5836 | type_name_const_str.SetCString(type_name_cstr); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5837 | break; | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5838 |  | 
|  | 5839 | case DW_AT_byte_size: | 
|  | 5840 | byte_size = form_value.Unsigned(); | 
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 5841 | byte_size_valid = true; | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5842 | break; | 
|  | 5843 |  | 
|  | 5844 | case DW_AT_accessibility: | 
|  | 5845 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); | 
|  | 5846 | break; | 
|  | 5847 |  | 
|  | 5848 | case DW_AT_declaration: | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 5849 | is_forward_declaration = form_value.Boolean(); | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5850 | break; | 
|  | 5851 |  | 
|  | 5852 | case DW_AT_APPLE_runtime_class: | 
|  | 5853 | class_language = (LanguageType)form_value.Signed(); | 
|  | 5854 | break; | 
|  | 5855 |  | 
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 5856 | case DW_AT_APPLE_objc_complete_type: | 
|  | 5857 | is_complete_objc_class = form_value.Signed(); | 
|  | 5858 | break; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5859 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5860 | case DW_AT_allocated: | 
|  | 5861 | case DW_AT_associated: | 
|  | 5862 | case DW_AT_data_location: | 
|  | 5863 | case DW_AT_description: | 
|  | 5864 | case DW_AT_start_scope: | 
|  | 5865 | case DW_AT_visibility: | 
|  | 5866 | default: | 
|  | 5867 | case DW_AT_sibling: | 
|  | 5868 | break; | 
|  | 5869 | } | 
|  | 5870 | } | 
|  | 5871 | } | 
|  | 5872 | } | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 5873 |  | 
|  | 5874 | // UniqueDWARFASTType is large, so don't create a local variables on the | 
|  | 5875 | // stack, put it on the heap. This function is often called recursively | 
|  | 5876 | // and clang isn't good and sharing the stack space for variables in different blocks. | 
|  | 5877 | std::unique_ptr<UniqueDWARFASTType> unique_ast_entry_ap(new UniqueDWARFASTType()); | 
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5878 |  | 
| Greg Clayton | 123edca | 2012-03-02 00:07:15 +0000 | [diff] [blame] | 5879 | // Only try and unique the type if it has a name. | 
|  | 5880 | if (type_name_const_str && | 
|  | 5881 | GetUniqueDWARFASTTypeMap().Find (type_name_const_str, | 
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5882 | this, | 
|  | 5883 | dwarf_cu, | 
|  | 5884 | die, | 
|  | 5885 | decl, | 
|  | 5886 | byte_size_valid ? byte_size : -1, | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 5887 | *unique_ast_entry_ap)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5888 | { | 
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5889 | // We have already parsed this type or from another | 
|  | 5890 | // compile unit. GCC loves to use the "one definition | 
|  | 5891 | // rule" which can result in multiple definitions | 
|  | 5892 | // of the same class over and over in each compile | 
|  | 5893 | // unit. | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 5894 | type_sp = unique_ast_entry_ap->m_type_sp; | 
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5895 | if (type_sp) | 
| Greg Clayton | c615ce4 | 2010-11-09 04:42:43 +0000 | [diff] [blame] | 5896 | { | 
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5897 | m_die_to_type[die] = type_sp.get(); | 
|  | 5898 | return type_sp; | 
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5899 | } | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5900 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5901 |  | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5902 | 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] | 5903 |  | 
|  | 5904 | int tag_decl_kind = -1; | 
|  | 5905 | AccessType default_accessibility = eAccessNone; | 
|  | 5906 | if (tag == DW_TAG_structure_type) | 
|  | 5907 | { | 
|  | 5908 | tag_decl_kind = clang::TTK_Struct; | 
|  | 5909 | default_accessibility = eAccessPublic; | 
|  | 5910 | } | 
|  | 5911 | else if (tag == DW_TAG_union_type) | 
|  | 5912 | { | 
|  | 5913 | tag_decl_kind = clang::TTK_Union; | 
|  | 5914 | default_accessibility = eAccessPublic; | 
|  | 5915 | } | 
|  | 5916 | else if (tag == DW_TAG_class_type) | 
|  | 5917 | { | 
|  | 5918 | tag_decl_kind = clang::TTK_Class; | 
|  | 5919 | default_accessibility = eAccessPrivate; | 
|  | 5920 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5921 |  | 
| Greg Clayton | 3a5f29a | 2011-11-30 02:48:28 +0000 | [diff] [blame] | 5922 | if (byte_size_valid && byte_size == 0 && type_name_cstr && | 
|  | 5923 | die->HasChildren() == false && | 
|  | 5924 | sc.comp_unit->GetLanguage() == eLanguageTypeObjC) | 
|  | 5925 | { | 
|  | 5926 | // Work around an issue with clang at the moment where | 
|  | 5927 | // forward declarations for objective C classes are emitted | 
|  | 5928 | // as: | 
|  | 5929 | //  DW_TAG_structure_type [2] | 
|  | 5930 | //  DW_AT_name( "ForwardObjcClass" ) | 
|  | 5931 | //  DW_AT_byte_size( 0x00 ) | 
|  | 5932 | //  DW_AT_decl_file( "..." ) | 
|  | 5933 | //  DW_AT_decl_line( 1 ) | 
|  | 5934 | // | 
|  | 5935 | // Note that there is no DW_AT_declaration and there are | 
|  | 5936 | // no children, and the byte size is zero. | 
|  | 5937 | is_forward_declaration = true; | 
|  | 5938 | } | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5939 |  | 
| Sean Callanan | 7457f8d | 2012-04-25 01:03:57 +0000 | [diff] [blame] | 5940 | if (class_language == eLanguageTypeObjC || | 
|  | 5941 | class_language == eLanguageTypeObjC_plus_plus) | 
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 5942 | { | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5943 | 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] | 5944 | { | 
|  | 5945 | // We have a valid eSymbolTypeObjCClass class symbol whose | 
|  | 5946 | // name matches the current objective C class that we | 
|  | 5947 | // are trying to find and this DIE isn't the complete | 
|  | 5948 | // definition (we checked is_complete_objc_class above and | 
|  | 5949 | // know it is false), so the real definition is in here somewhere | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5950 | type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true); | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5951 |  | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 5952 | if (!type_sp && GetDebugMapSymfile ()) | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5953 | { | 
|  | 5954 | // We weren't able to find a full declaration in | 
|  | 5955 | // this DWARF, see if we have a declaration anywhere | 
|  | 5956 | // else... | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5957 | 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] | 5958 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5959 |  | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5960 | if (type_sp) | 
|  | 5961 | { | 
|  | 5962 | if (log) | 
|  | 5963 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5964 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5965 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an incomplete objc type, complete type is 0x%8.8" PRIx64, | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5966 | static_cast<void*>(this), | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5967 | die->GetOffset(), | 
|  | 5968 | DW_TAG_value_to_name(tag), | 
|  | 5969 | type_name_cstr, | 
|  | 5970 | type_sp->GetID()); | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5971 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5972 |  | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5973 | // We found a real definition for this type elsewhere | 
|  | 5974 | // so lets use it and cache the fact that we found | 
|  | 5975 | // a complete type for this die | 
|  | 5976 | m_die_to_type[die] = type_sp.get(); | 
|  | 5977 | return type_sp; | 
|  | 5978 | } | 
|  | 5979 | } | 
|  | 5980 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5981 |  | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5982 |  | 
|  | 5983 | if (is_forward_declaration) | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5984 | { | 
|  | 5985 | // We have a forward declaration to a type and we need | 
|  | 5986 | // to try and find a full declaration. We look in the | 
|  | 5987 | // current type index just in case we have a forward | 
|  | 5988 | // declaration followed by an actual declarations in the | 
|  | 5989 | // DWARF. If this fails, we need to look elsewhere... | 
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 5990 | if (log) | 
|  | 5991 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5992 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5993 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type", | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5994 | static_cast<void*>(this), | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5995 | die->GetOffset(), | 
|  | 5996 | DW_TAG_value_to_name(tag), | 
|  | 5997 | type_name_cstr); | 
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 5998 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5999 |  | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 6000 | DWARFDeclContext die_decl_ctx; | 
|  | 6001 | die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx); | 
|  | 6002 |  | 
|  | 6003 | //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str); | 
|  | 6004 | type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6005 |  | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 6006 | if (!type_sp && GetDebugMapSymfile ()) | 
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 6007 | { | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6008 | // We weren't able to find a full declaration in | 
|  | 6009 | // this DWARF, see if we have a declaration anywhere | 
|  | 6010 | // else... | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 6011 | type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); | 
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 6012 | } | 
|  | 6013 |  | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6014 | if (type_sp) | 
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 6015 | { | 
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 6016 | if (log) | 
|  | 6017 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 6018 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6019 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8" PRIx64, | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6020 | static_cast<void*>(this), | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6021 | die->GetOffset(), | 
|  | 6022 | DW_TAG_value_to_name(tag), | 
|  | 6023 | type_name_cstr, | 
|  | 6024 | type_sp->GetID()); | 
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 6025 | } | 
|  | 6026 |  | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6027 | // We found a real definition for this type elsewhere | 
|  | 6028 | // so lets use it and cache the fact that we found | 
|  | 6029 | // a complete type for this die | 
|  | 6030 | m_die_to_type[die] = type_sp.get(); | 
|  | 6031 | return type_sp; | 
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 6032 | } | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6033 | } | 
|  | 6034 | assert (tag_decl_kind != -1); | 
|  | 6035 | bool clang_type_was_created = false; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6036 | clang_type.SetClangType(ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die)); | 
|  | 6037 | if (!clang_type) | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6038 | { | 
| Sean Callanan | 4d04c6a | 2012-02-09 22:54:11 +0000 | [diff] [blame] | 6039 | const DWARFDebugInfoEntry *decl_ctx_die; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6040 |  | 
| Sean Callanan | 4d04c6a | 2012-02-09 22:54:11 +0000 | [diff] [blame] | 6041 | clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die); | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 6042 | if (accessibility == eAccessNone && decl_ctx) | 
|  | 6043 | { | 
|  | 6044 | // Check the decl context that contains this class/struct/union. | 
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 6045 | // If it is a class we must give it an accessibility. | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 6046 | const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind(); | 
|  | 6047 | if (DeclKindIsCXXClass (containing_decl_kind)) | 
|  | 6048 | accessibility = default_accessibility; | 
|  | 6049 | } | 
|  | 6050 |  | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 6051 | ClangASTMetadata metadata; | 
|  | 6052 | metadata.SetUserID(MakeUserID(die->GetOffset())); | 
|  | 6053 | metadata.SetIsDynamicCXXType(ClassOrStructIsVirtual (dwarf_cu, die)); | 
|  | 6054 |  | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6055 | if (type_name_cstr && strchr (type_name_cstr, '<')) | 
|  | 6056 | { | 
|  | 6057 | ClangASTContext::TemplateParameterInfos template_param_infos; | 
|  | 6058 | if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos)) | 
|  | 6059 | { | 
|  | 6060 | clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx, | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 6061 | accessibility, | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6062 | type_name_cstr, | 
|  | 6063 | tag_decl_kind, | 
|  | 6064 | template_param_infos); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6065 |  | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6066 | clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx, | 
|  | 6067 | class_template_decl, | 
|  | 6068 | tag_decl_kind, | 
|  | 6069 | template_param_infos); | 
|  | 6070 | clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl); | 
|  | 6071 | clang_type_was_created = true; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6072 |  | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6073 | GetClangASTContext().SetMetadata (class_template_decl, metadata); | 
|  | 6074 | GetClangASTContext().SetMetadata (class_specialization_decl, metadata); | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6075 | } | 
|  | 6076 | } | 
|  | 6077 |  | 
|  | 6078 | if (!clang_type_was_created) | 
|  | 6079 | { | 
|  | 6080 | clang_type_was_created = true; | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 6081 | clang_type = ast.CreateRecordType (decl_ctx, | 
|  | 6082 | accessibility, | 
|  | 6083 | type_name_cstr, | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6084 | tag_decl_kind, | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 6085 | class_language, | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6086 | &metadata); | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6087 | } | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6088 | } | 
|  | 6089 |  | 
|  | 6090 | // Store a forward declaration to this class type in case any | 
|  | 6091 | // parameters in any class methods need it for the clang | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6092 | // types for function prototypes. | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6093 | LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die); | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6094 | type_sp.reset (new Type (MakeUserID(die->GetOffset()), | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6095 | this, | 
|  | 6096 | type_name_const_str, | 
|  | 6097 | byte_size, | 
|  | 6098 | NULL, | 
|  | 6099 | LLDB_INVALID_UID, | 
|  | 6100 | Type::eEncodingIsUID, | 
|  | 6101 | &decl, | 
|  | 6102 | clang_type, | 
|  | 6103 | Type::eResolveStateForward)); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6104 |  | 
| Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 6105 | type_sp->SetIsCompleteObjCClass(is_complete_objc_class); | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6106 |  | 
|  | 6107 |  | 
|  | 6108 | // Add our type to the unique type map so we don't | 
|  | 6109 | // end up creating many copies of the same type over | 
|  | 6110 | // and over in the ASTContext for our module | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 6111 | unique_ast_entry_ap->m_type_sp = type_sp; | 
|  | 6112 | unique_ast_entry_ap->m_symfile = this; | 
|  | 6113 | unique_ast_entry_ap->m_cu = dwarf_cu; | 
|  | 6114 | unique_ast_entry_ap->m_die = die; | 
|  | 6115 | unique_ast_entry_ap->m_declaration = decl; | 
|  | 6116 | unique_ast_entry_ap->m_byte_size = byte_size; | 
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 6117 | GetUniqueDWARFASTTypeMap().Insert (type_name_const_str, | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 6118 | *unique_ast_entry_ap); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6119 |  | 
| Greg Clayton | 0ec71a0 | 2013-08-10 00:09:35 +0000 | [diff] [blame] | 6120 | if (is_forward_declaration && die->HasChildren()) | 
|  | 6121 | { | 
|  | 6122 | // Check to see if the DIE actually has a definition, some version of GCC will | 
|  | 6123 | // emit DIEs with DW_AT_declaration set to true, but yet still have subprogram, | 
|  | 6124 | // members, or inheritance, so we can't trust it | 
|  | 6125 | const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); | 
|  | 6126 | while (child_die) | 
|  | 6127 | { | 
|  | 6128 | switch (child_die->Tag()) | 
|  | 6129 | { | 
|  | 6130 | case DW_TAG_inheritance: | 
|  | 6131 | case DW_TAG_subprogram: | 
|  | 6132 | case DW_TAG_member: | 
|  | 6133 | case DW_TAG_APPLE_property: | 
| Greg Clayton | 4c484ec | 2014-02-07 19:21:56 +0000 | [diff] [blame] | 6134 | case DW_TAG_class_type: | 
|  | 6135 | case DW_TAG_structure_type: | 
|  | 6136 | case DW_TAG_enumeration_type: | 
|  | 6137 | case DW_TAG_typedef: | 
|  | 6138 | case DW_TAG_union_type: | 
| Greg Clayton | 0ec71a0 | 2013-08-10 00:09:35 +0000 | [diff] [blame] | 6139 | child_die = NULL; | 
|  | 6140 | is_forward_declaration = false; | 
|  | 6141 | break; | 
|  | 6142 | default: | 
|  | 6143 | child_die = child_die->GetSibling(); | 
|  | 6144 | break; | 
|  | 6145 | } | 
|  | 6146 | } | 
|  | 6147 | } | 
|  | 6148 |  | 
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6149 | if (!is_forward_declaration) | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 6150 | { | 
|  | 6151 | // Always start the definition for a class type so that | 
|  | 6152 | // if the class has child classes or types that require | 
|  | 6153 | // the class to be created for use as their decl contexts | 
|  | 6154 | // the class will be ready to accept these child definitions. | 
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6155 | if (die->HasChildren() == false) | 
|  | 6156 | { | 
|  | 6157 | // No children for this struct/union/class, lets finish it | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6158 | clang_type.StartTagDeclarationDefinition (); | 
|  | 6159 | clang_type.CompleteTagDeclarationDefinition (); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6160 |  | 
| Sean Callanan | 433cd22 | 2012-10-19 01:37:25 +0000 | [diff] [blame] | 6161 | if (tag == DW_TAG_structure_type) // this only applies in C | 
|  | 6162 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6163 | clang::RecordDecl *record_decl = clang_type.GetAsRecordDecl(); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6164 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6165 | if (record_decl) | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 6166 | m_record_decl_to_layout_map.insert(std::make_pair(record_decl, LayoutInfo())); | 
| Sean Callanan | 433cd22 | 2012-10-19 01:37:25 +0000 | [diff] [blame] | 6167 | } | 
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6168 | } | 
|  | 6169 | else if (clang_type_was_created) | 
|  | 6170 | { | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 6171 | // Start the definition if the class is not objective C since | 
|  | 6172 | // the underlying decls respond to isCompleteDefinition(). Objective | 
| Bruce Mitchener | aaa0ba3 | 2014-07-08 18:05:41 +0000 | [diff] [blame] | 6173 | // C decls don't respond to isCompleteDefinition() so we can't | 
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 6174 | // start the declaration definition right away. For C++ class/union/structs | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 6175 | // we want to start the definition in case the class is needed as the | 
|  | 6176 | // declaration context for a contained class or type without the need | 
|  | 6177 | // to complete that type.. | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6178 |  | 
| Sean Callanan | 7457f8d | 2012-04-25 01:03:57 +0000 | [diff] [blame] | 6179 | if (class_language != eLanguageTypeObjC && | 
|  | 6180 | class_language != eLanguageTypeObjC_plus_plus) | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6181 | clang_type.StartTagDeclarationDefinition (); | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 6182 |  | 
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6183 | // Leave this as a forward declaration until we need | 
|  | 6184 | // to know the details of the type. lldb_private::Type | 
|  | 6185 | // will automatically call the SymbolFile virtual function | 
|  | 6186 | // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)" | 
|  | 6187 | // When the definition needs to be defined. | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6188 | m_forward_decl_die_to_clang_type[die] = clang_type.GetOpaqueQualType(); | 
|  | 6189 | m_forward_decl_clang_type_to_die[clang_type.RemoveFastQualifiers().GetOpaqueQualType()] = die; | 
|  | 6190 | clang_type.SetHasExternalStorage (true); | 
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6191 | } | 
| Greg Clayton | c615ce4 | 2010-11-09 04:42:43 +0000 | [diff] [blame] | 6192 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6193 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6194 | } | 
|  | 6195 | break; | 
|  | 6196 |  | 
|  | 6197 | case DW_TAG_enumeration_type: | 
|  | 6198 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6199 | // 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] | 6200 | m_die_to_type[die] = DIE_IS_BEING_PARSED; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6201 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6202 | lldb::user_id_t encoding_uid = DW_INVALID_OFFSET; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6203 |  | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6204 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6205 | if (num_attributes > 0) | 
|  | 6206 | { | 
|  | 6207 | uint32_t i; | 
|  | 6208 |  | 
|  | 6209 | for (i=0; i<num_attributes; ++i) | 
|  | 6210 | { | 
|  | 6211 | attr = attributes.AttributeAtIndex(i); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6212 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 6213 | { | 
|  | 6214 | switch (attr) | 
|  | 6215 | { | 
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 6216 | case DW_AT_decl_file:       decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 6217 | case DW_AT_decl_line:       decl.SetLine(form_value.Unsigned()); break; | 
|  | 6218 | case DW_AT_decl_column:     decl.SetColumn(form_value.Unsigned()); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6219 | case DW_AT_name: | 
|  | 6220 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6221 | type_name_const_str.SetCString(type_name_cstr); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6222 | break; | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 6223 | case DW_AT_type:            encoding_uid = form_value.Reference(); break; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6224 | case DW_AT_byte_size:       byte_size = form_value.Unsigned(); break; | 
|  | 6225 | 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] | 6226 | case DW_AT_declaration:     break; //is_forward_declaration = form_value.Boolean(); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6227 | case DW_AT_allocated: | 
|  | 6228 | case DW_AT_associated: | 
|  | 6229 | case DW_AT_bit_stride: | 
|  | 6230 | case DW_AT_byte_stride: | 
|  | 6231 | case DW_AT_data_location: | 
|  | 6232 | case DW_AT_description: | 
|  | 6233 | case DW_AT_start_scope: | 
|  | 6234 | case DW_AT_visibility: | 
|  | 6235 | case DW_AT_specification: | 
|  | 6236 | case DW_AT_abstract_origin: | 
|  | 6237 | case DW_AT_sibling: | 
|  | 6238 | break; | 
|  | 6239 | } | 
|  | 6240 | } | 
|  | 6241 | } | 
|  | 6242 |  | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6243 | 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] | 6244 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6245 | ClangASTType enumerator_clang_type; | 
|  | 6246 | clang_type.SetClangType (ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die)); | 
|  | 6247 | if (!clang_type) | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6248 | { | 
| Greg Clayton | 5d14fc0 | 2013-03-06 06:23:54 +0000 | [diff] [blame] | 6249 | if (encoding_uid != DW_INVALID_OFFSET) | 
|  | 6250 | { | 
|  | 6251 | Type *enumerator_type = ResolveTypeUID(encoding_uid); | 
|  | 6252 | if (enumerator_type) | 
|  | 6253 | enumerator_clang_type = enumerator_type->GetClangFullType(); | 
|  | 6254 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6255 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6256 | if (!enumerator_clang_type) | 
| Greg Clayton | 5d14fc0 | 2013-03-06 06:23:54 +0000 | [diff] [blame] | 6257 | enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL, | 
|  | 6258 | DW_ATE_signed, | 
|  | 6259 | byte_size * 8); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6260 |  | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 6261 | clang_type = ast.CreateEnumerationType (type_name_cstr, | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6262 | GetClangDeclContextContainingDIE (dwarf_cu, die, NULL), | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 6263 | decl, | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6264 | enumerator_clang_type); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6265 | } | 
|  | 6266 | else | 
|  | 6267 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6268 | enumerator_clang_type = clang_type.GetEnumerationIntegerType (); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6269 | } | 
|  | 6270 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6271 | LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6272 |  | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6273 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6274 | this, | 
|  | 6275 | type_name_const_str, | 
|  | 6276 | byte_size, | 
|  | 6277 | NULL, | 
|  | 6278 | encoding_uid, | 
|  | 6279 | Type::eEncodingIsUID, | 
|  | 6280 | &decl, | 
|  | 6281 | clang_type, | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6282 | Type::eResolveStateForward)); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6283 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6284 | clang_type.StartTagDeclarationDefinition (); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 6285 | if (die->HasChildren()) | 
|  | 6286 | { | 
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 6287 | SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); | 
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 6288 | bool is_signed = false; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6289 | enumerator_clang_type.IsIntegerType(is_signed); | 
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 6290 | 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] | 6291 | } | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6292 | clang_type.CompleteTagDeclarationDefinition (); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6293 | } | 
|  | 6294 | } | 
|  | 6295 | break; | 
|  | 6296 |  | 
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 6297 | case DW_TAG_inlined_subroutine: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6298 | case DW_TAG_subprogram: | 
|  | 6299 | case DW_TAG_subroutine_type: | 
|  | 6300 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6301 | // 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] | 6302 | m_die_to_type[die] = DIE_IS_BEING_PARSED; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6303 |  | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6304 | //const char *mangled = NULL; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6305 | dw_offset_t type_die_offset = DW_INVALID_OFFSET; | 
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 6306 | bool is_variadic = false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6307 | bool is_inline = false; | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6308 | bool is_static = false; | 
|  | 6309 | bool is_virtual = false; | 
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6310 | bool is_explicit = false; | 
| Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 6311 | bool is_artificial = false; | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6312 | dw_offset_t specification_die_offset = DW_INVALID_OFFSET; | 
|  | 6313 | dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET; | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6314 | dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET; | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6315 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6316 | unsigned type_quals = 0; | 
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 6317 | clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6318 |  | 
|  | 6319 |  | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6320 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6321 | if (num_attributes > 0) | 
|  | 6322 | { | 
|  | 6323 | uint32_t i; | 
|  | 6324 | for (i=0; i<num_attributes; ++i) | 
|  | 6325 | { | 
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 6326 | attr = attributes.AttributeAtIndex(i); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6327 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 6328 | { | 
|  | 6329 | switch (attr) | 
|  | 6330 | { | 
|  | 6331 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 6332 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 6333 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 6334 | case DW_AT_name: | 
|  | 6335 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6336 | type_name_const_str.SetCString(type_name_cstr); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6337 | break; | 
|  | 6338 |  | 
| Greg Clayton | 7141554 | 2012-12-08 00:24:40 +0000 | [diff] [blame] | 6339 | case DW_AT_linkage_name: | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6340 | case DW_AT_MIPS_linkage_name:   break; // mangled = form_value.AsCString(&get_debug_str_data()); break; | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 6341 | case DW_AT_type:                type_die_offset = form_value.Reference(); break; | 
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 6342 | 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] | 6343 | case DW_AT_declaration:         break; // is_forward_declaration = form_value.Boolean(); break; | 
|  | 6344 | case DW_AT_inline:              is_inline = form_value.Boolean(); break; | 
|  | 6345 | case DW_AT_virtuality:          is_virtual = form_value.Boolean();  break; | 
|  | 6346 | case DW_AT_explicit:            is_explicit = form_value.Boolean();  break; | 
|  | 6347 | case DW_AT_artificial:          is_artificial = form_value.Boolean();  break; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6348 |  | 
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6349 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6350 | case DW_AT_external: | 
|  | 6351 | if (form_value.Unsigned()) | 
|  | 6352 | { | 
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 6353 | if (storage == clang::SC_None) | 
|  | 6354 | storage = clang::SC_Extern; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6355 | else | 
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 6356 | storage = clang::SC_PrivateExtern; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6357 | } | 
|  | 6358 | break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6359 |  | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6360 | case DW_AT_specification: | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 6361 | specification_die_offset = form_value.Reference(); | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6362 | break; | 
|  | 6363 |  | 
|  | 6364 | case DW_AT_abstract_origin: | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 6365 | abstract_origin_die_offset = form_value.Reference(); | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6366 | break; | 
|  | 6367 |  | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6368 | case DW_AT_object_pointer: | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 6369 | object_pointer_die_offset = form_value.Reference(); | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6370 | break; | 
|  | 6371 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6372 | case DW_AT_allocated: | 
|  | 6373 | case DW_AT_associated: | 
|  | 6374 | case DW_AT_address_class: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6375 | case DW_AT_calling_convention: | 
|  | 6376 | case DW_AT_data_location: | 
|  | 6377 | case DW_AT_elemental: | 
|  | 6378 | case DW_AT_entry_pc: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6379 | case DW_AT_frame_base: | 
|  | 6380 | case DW_AT_high_pc: | 
|  | 6381 | case DW_AT_low_pc: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6382 | case DW_AT_prototyped: | 
|  | 6383 | case DW_AT_pure: | 
|  | 6384 | case DW_AT_ranges: | 
|  | 6385 | case DW_AT_recursive: | 
|  | 6386 | case DW_AT_return_addr: | 
|  | 6387 | case DW_AT_segment: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6388 | case DW_AT_start_scope: | 
|  | 6389 | case DW_AT_static_link: | 
|  | 6390 | case DW_AT_trampoline: | 
|  | 6391 | case DW_AT_visibility: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6392 | case DW_AT_vtable_elem_location: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6393 | case DW_AT_description: | 
|  | 6394 | case DW_AT_sibling: | 
|  | 6395 | break; | 
|  | 6396 | } | 
|  | 6397 | } | 
|  | 6398 | } | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6399 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6400 |  | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6401 | std::string object_pointer_name; | 
|  | 6402 | if (object_pointer_die_offset != DW_INVALID_OFFSET) | 
|  | 6403 | { | 
|  | 6404 | // Get the name from the object pointer die | 
|  | 6405 | StreamString s; | 
|  | 6406 | if (DWARFDebugInfoEntry::GetName (this, dwarf_cu, object_pointer_die_offset, s)) | 
|  | 6407 | { | 
|  | 6408 | object_pointer_name.assign(s.GetData()); | 
|  | 6409 | } | 
|  | 6410 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6411 |  | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6412 | 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] | 6413 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6414 | ClangASTType return_clang_type; | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6415 | Type *func_type = NULL; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6416 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6417 | if (type_die_offset != DW_INVALID_OFFSET) | 
|  | 6418 | func_type = ResolveTypeUID(type_die_offset); | 
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6419 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6420 | if (func_type) | 
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 6421 | return_clang_type = func_type->GetClangForwardType(); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6422 | else | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6423 | return_clang_type = ast.GetBasicType(eBasicTypeVoid); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6424 |  | 
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6425 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6426 | std::vector<ClangASTType> function_param_types; | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6427 | std::vector<clang::ParmVarDecl*> function_param_decls; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6428 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6429 | // Parse the function children for the parameters | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6430 |  | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6431 | const DWARFDebugInfoEntry *decl_ctx_die = NULL; | 
|  | 6432 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die); | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6433 | const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind(); | 
|  | 6434 |  | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6435 | const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind); | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6436 | // Start off static. This will be set to false in ParseChildParameters(...) | 
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 6437 | // if we find a "this" parameters as the first parameter | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6438 | if (is_cxx_method) | 
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 6439 | is_static = true; | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 6440 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6441 | if (die->HasChildren()) | 
|  | 6442 | { | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6443 | bool skip_artificial = true; | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6444 | ParseChildParameters (sc, | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6445 | containing_decl_ctx, | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6446 | dwarf_cu, | 
|  | 6447 | die, | 
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 6448 | skip_artificial, | 
|  | 6449 | is_static, | 
| Greg Clayton | 0396975 | 2014-02-24 18:53:11 +0000 | [diff] [blame] | 6450 | is_variadic, | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6451 | type_list, | 
|  | 6452 | function_param_types, | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 6453 | function_param_decls, | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 6454 | type_quals); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6455 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6456 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6457 | // clang_type will get the function prototype clang type after this call | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6458 | clang_type = ast.CreateFunctionType (return_clang_type, | 
| Greg Clayton | 9cb25c4 | 2012-10-30 17:02:18 +0000 | [diff] [blame] | 6459 | function_param_types.data(), | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6460 | function_param_types.size(), | 
|  | 6461 | is_variadic, | 
|  | 6462 | type_quals); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6463 |  | 
| Sean Callanan | de9ce87 | 2013-05-09 23:13:13 +0000 | [diff] [blame] | 6464 | bool ignore_containing_context = false; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6465 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6466 | if (type_name_cstr) | 
|  | 6467 | { | 
|  | 6468 | bool type_handled = false; | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6469 | if (tag == DW_TAG_subprogram) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6470 | { | 
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 6471 | ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true); | 
|  | 6472 | if (objc_method.IsValid(true)) | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6473 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6474 | ClangASTType class_opaque_type; | 
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 6475 | ConstString class_name(objc_method.GetClassName()); | 
| Greg Clayton | 7c81042 | 2012-01-18 23:40:49 +0000 | [diff] [blame] | 6476 | if (class_name) | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6477 | { | 
| Greg Clayton | 278a16b | 2012-01-19 00:52:59 +0000 | [diff] [blame] | 6478 | TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false)); | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6479 |  | 
|  | 6480 | if (complete_objc_class_type_sp) | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6481 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6482 | ClangASTType type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType(); | 
|  | 6483 | if (type_clang_forward_type.IsObjCObjectOrInterfaceType ()) | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6484 | class_opaque_type = type_clang_forward_type; | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6485 | } | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6486 | } | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6487 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6488 | if (class_opaque_type) | 
|  | 6489 | { | 
|  | 6490 | // If accessibility isn't set to anything valid, assume public for | 
|  | 6491 | // now... | 
|  | 6492 | if (accessibility == eAccessNone) | 
|  | 6493 | accessibility = eAccessPublic; | 
|  | 6494 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6495 | clang::ObjCMethodDecl *objc_method_decl = class_opaque_type.AddMethodToObjCObjectType (type_name_cstr, | 
|  | 6496 | clang_type, | 
|  | 6497 | accessibility, | 
|  | 6498 | is_artificial); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6499 | type_handled = objc_method_decl != NULL; | 
| Sean Callanan | 464a5b5 | 2012-10-04 22:06:29 +0000 | [diff] [blame] | 6500 | if (type_handled) | 
|  | 6501 | { | 
|  | 6502 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die); | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6503 | GetClangASTContext().SetMetadataAsUserID (objc_method_decl, MakeUserID(die->GetOffset())); | 
| Sean Callanan | 464a5b5 | 2012-10-04 22:06:29 +0000 | [diff] [blame] | 6504 | } | 
| Sean Callanan | c3a1d56 | 2013-02-06 23:21:59 +0000 | [diff] [blame] | 6505 | else | 
|  | 6506 | { | 
| Jason Molenda | c1a6583 | 2013-03-07 22:44:42 +0000 | [diff] [blame] | 6507 | 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] | 6508 | die->GetOffset(), | 
|  | 6509 | tag, | 
|  | 6510 | DW_TAG_value_to_name(tag)); | 
|  | 6511 | } | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6512 | } | 
|  | 6513 | } | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6514 | else if (is_cxx_method) | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6515 | { | 
|  | 6516 | // Look at the parent of this DIE and see if is is | 
|  | 6517 | // a class or struct and see if this is actually a | 
|  | 6518 | // C++ method | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6519 | Type *class_type = ResolveType (dwarf_cu, decl_ctx_die); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6520 | if (class_type) | 
|  | 6521 | { | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6522 | if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset())) | 
|  | 6523 | { | 
|  | 6524 | // We uniqued the parent class of this function to another class | 
|  | 6525 | // so we now need to associate all dies under "decl_ctx_die" to | 
|  | 6526 | // DIEs in the DIE for "class_type"... | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 6527 | SymbolFileDWARF *class_symfile = NULL; | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6528 | DWARFCompileUnitSP class_type_cu_sp; | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 6529 | const DWARFDebugInfoEntry *class_type_die = NULL; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6530 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6531 | SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile(); | 
|  | 6532 | if (debug_map_symfile) | 
|  | 6533 | { | 
|  | 6534 | class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID())); | 
|  | 6535 | class_type_die = class_symfile->DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp); | 
|  | 6536 | } | 
|  | 6537 | else | 
|  | 6538 | { | 
|  | 6539 | class_symfile = this; | 
|  | 6540 | class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp); | 
|  | 6541 | } | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6542 | if (class_type_die) | 
|  | 6543 | { | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 6544 | DWARFDIECollection failures; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6545 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6546 | CopyUniqueClassMethodTypes (class_symfile, | 
|  | 6547 | class_type, | 
|  | 6548 | class_type_cu_sp.get(), | 
|  | 6549 | class_type_die, | 
|  | 6550 | dwarf_cu, | 
|  | 6551 | decl_ctx_die, | 
|  | 6552 | failures); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6553 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6554 | // FIXME do something with these failures that's smarter than | 
|  | 6555 | // just dropping them on the ground.  Unfortunately classes don't | 
|  | 6556 | // like having stuff added to them after their definitions are | 
|  | 6557 | // complete... | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6558 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6559 | type_ptr = m_die_to_type[die]; | 
|  | 6560 | if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6561 | { | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6562 | type_sp = type_ptr->shared_from_this(); | 
|  | 6563 | break; | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6564 | } | 
|  | 6565 | } | 
|  | 6566 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6567 |  | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6568 | if (specification_die_offset != DW_INVALID_OFFSET) | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6569 | { | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6570 | // We have a specification which we are going to base our function | 
|  | 6571 | // prototype off of, so we need this type to be completed so that the | 
|  | 6572 | // m_die_to_decl_ctx for the method in the specification has a valid | 
|  | 6573 | // clang decl context. | 
| Greg Clayton | 8eb732e | 2011-12-13 04:34:06 +0000 | [diff] [blame] | 6574 | class_type->GetClangForwardType(); | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6575 | // If we have a specification, then the function type should have been | 
|  | 6576 | // made with the specification and not with this die. | 
|  | 6577 | DWARFCompileUnitSP spec_cu_sp; | 
|  | 6578 | const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp); | 
| Eric Christopher | 6cc6e60 | 2012-03-25 19:37:33 +0000 | [diff] [blame] | 6579 | clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die); | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6580 | if (spec_clang_decl_ctx) | 
|  | 6581 | { | 
|  | 6582 | LinkDeclContextToDIE(spec_clang_decl_ctx, die); | 
|  | 6583 | } | 
|  | 6584 | else | 
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6585 | { | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6586 | 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] | 6587 | MakeUserID(die->GetOffset()), | 
|  | 6588 | specification_die_offset); | 
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6589 | } | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6590 | type_handled = true; | 
|  | 6591 | } | 
|  | 6592 | else if (abstract_origin_die_offset != DW_INVALID_OFFSET) | 
|  | 6593 | { | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6594 | // We have a specification which we are going to base our function | 
|  | 6595 | // prototype off of, so we need this type to be completed so that the | 
|  | 6596 | // m_die_to_decl_ctx for the method in the abstract origin has a valid | 
|  | 6597 | // clang decl context. | 
| Greg Clayton | 8eb732e | 2011-12-13 04:34:06 +0000 | [diff] [blame] | 6598 | class_type->GetClangForwardType(); | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6599 |  | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6600 | DWARFCompileUnitSP abs_cu_sp; | 
|  | 6601 | 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] | 6602 | clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die); | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6603 | if (abs_clang_decl_ctx) | 
|  | 6604 | { | 
|  | 6605 | LinkDeclContextToDIE (abs_clang_decl_ctx, die); | 
|  | 6606 | } | 
|  | 6607 | else | 
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6608 | { | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6609 | 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] | 6610 | MakeUserID(die->GetOffset()), | 
|  | 6611 | abstract_origin_die_offset); | 
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6612 | } | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6613 | type_handled = true; | 
|  | 6614 | } | 
|  | 6615 | else | 
|  | 6616 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6617 | ClangASTType class_opaque_type = class_type->GetClangForwardType(); | 
|  | 6618 | if (class_opaque_type.IsCXXClassType ()) | 
| Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 6619 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6620 | if (class_opaque_type.IsBeingDefined ()) | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6621 | { | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6622 | // Neither GCC 4.2 nor clang++ currently set a valid accessibility | 
|  | 6623 | // in the DWARF for C++ methods... Default to public for now... | 
|  | 6624 | if (accessibility == eAccessNone) | 
|  | 6625 | accessibility = eAccessPublic; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6626 |  | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6627 | if (!is_static && !die->HasChildren()) | 
|  | 6628 | { | 
|  | 6629 | // We have a C++ member function with no children (this pointer!) | 
|  | 6630 | // and clang will get mad if we try and make a function that isn't | 
|  | 6631 | // well formed in the DWARF, so we will just skip it... | 
|  | 6632 | type_handled = true; | 
|  | 6633 | } | 
|  | 6634 | else | 
|  | 6635 | { | 
|  | 6636 | clang::CXXMethodDecl *cxx_method_decl; | 
|  | 6637 | // REMOVE THE CRASH DESCRIPTION BELOW | 
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 6638 | 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] | 6639 | type_name_cstr, | 
|  | 6640 | class_type->GetName().GetCString(), | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6641 | MakeUserID(die->GetOffset()), | 
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 6642 | m_obj_file->GetFileSpec().GetPath().c_str()); | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6643 |  | 
| Sean Callanan | c1b732d | 2011-11-01 18:07:13 +0000 | [diff] [blame] | 6644 | const bool is_attr_used = false; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6645 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6646 | cxx_method_decl = class_opaque_type.AddMethodToCXXRecordType (type_name_cstr, | 
|  | 6647 | clang_type, | 
|  | 6648 | accessibility, | 
|  | 6649 | is_virtual, | 
|  | 6650 | is_static, | 
|  | 6651 | is_inline, | 
|  | 6652 | is_explicit, | 
|  | 6653 | is_attr_used, | 
|  | 6654 | is_artificial); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6655 |  | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6656 | type_handled = cxx_method_decl != NULL; | 
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6657 |  | 
|  | 6658 | if (type_handled) | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6659 | { | 
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6660 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die); | 
|  | 6661 |  | 
|  | 6662 | Host::SetCrashDescription (NULL); | 
|  | 6663 |  | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6664 |  | 
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6665 | ClangASTMetadata metadata; | 
|  | 6666 | metadata.SetUserID(MakeUserID(die->GetOffset())); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6667 |  | 
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6668 | if (!object_pointer_name.empty()) | 
|  | 6669 | { | 
|  | 6670 | metadata.SetObjectPtrName(object_pointer_name.c_str()); | 
|  | 6671 | if (log) | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6672 | log->Printf ("Setting object pointer name: %s on method object %p.\n", | 
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6673 | object_pointer_name.c_str(), | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6674 | static_cast<void*>(cxx_method_decl)); | 
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6675 | } | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6676 | GetClangASTContext().SetMetadata (cxx_method_decl, metadata); | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6677 | } | 
| Sean Callanan | b0640dc | 2013-04-09 23:22:08 +0000 | [diff] [blame] | 6678 | else | 
|  | 6679 | { | 
| Sean Callanan | de9ce87 | 2013-05-09 23:13:13 +0000 | [diff] [blame] | 6680 | ignore_containing_context = true; | 
| Sean Callanan | b0640dc | 2013-04-09 23:22:08 +0000 | [diff] [blame] | 6681 | } | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6682 | } | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6683 | } | 
|  | 6684 | else | 
|  | 6685 | { | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6686 | // We were asked to parse the type for a method in a class, yet the | 
|  | 6687 | // class hasn't been asked to complete itself through the | 
|  | 6688 | // clang::ExternalASTSource protocol, so we need to just have the | 
|  | 6689 | // class complete itself and do things the right way, then our | 
|  | 6690 | // DIE should then have an entry in the m_die_to_type map. First | 
|  | 6691 | // we need to modify the m_die_to_type so it doesn't think we are | 
|  | 6692 | // trying to parse this DIE anymore... | 
|  | 6693 | m_die_to_type[die] = NULL; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6694 |  | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6695 | // Now we get the full type to force our class type to complete itself | 
|  | 6696 | // using the clang::ExternalASTSource protocol which will parse all | 
|  | 6697 | // base classes and all methods (including the method for this DIE). | 
|  | 6698 | class_type->GetClangFullType(); | 
| Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 6699 |  | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6700 | // The type for this DIE should have been filled in the function call above | 
|  | 6701 | type_ptr = m_die_to_type[die]; | 
| Greg Clayton | e5476db | 2012-06-01 20:32:35 +0000 | [diff] [blame] | 6702 | if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6703 | { | 
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 6704 | type_sp = type_ptr->shared_from_this(); | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6705 | break; | 
|  | 6706 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6707 |  | 
| Sean Callanan | 02eee4d | 2012-04-12 23:10:00 +0000 | [diff] [blame] | 6708 | // FIXME This is fixing some even uglier behavior but we really need to | 
|  | 6709 | // uniq the methods of each class as well as the class itself. | 
|  | 6710 | // <rdar://problem/11240464> | 
|  | 6711 | type_handled = true; | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6712 | } | 
| Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 6713 | } | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6714 | } | 
|  | 6715 | } | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6716 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6717 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6718 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6719 | if (!type_handled) | 
|  | 6720 | { | 
|  | 6721 | // We just have a function that isn't part of a class | 
| Sean Callanan | de9ce87 | 2013-05-09 23:13:13 +0000 | [diff] [blame] | 6722 | 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] | 6723 | type_name_cstr, | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6724 | clang_type, | 
|  | 6725 | storage, | 
|  | 6726 | is_inline); | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 6727 |  | 
|  | 6728 | //                            if (template_param_infos.GetSize() > 0) | 
|  | 6729 | //                            { | 
|  | 6730 | //                                clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx, | 
|  | 6731 | //                                                                                                                  function_decl, | 
|  | 6732 | //                                                                                                                  type_name_cstr, | 
|  | 6733 | //                                                                                                                  template_param_infos); | 
|  | 6734 | // | 
|  | 6735 | //                                ast.CreateFunctionTemplateSpecializationInfo (function_decl, | 
|  | 6736 | //                                                                              func_template_decl, | 
|  | 6737 | //                                                                              template_param_infos); | 
|  | 6738 | //                            } | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6739 | // Add the decl to our DIE to decl context map | 
|  | 6740 | assert (function_decl); | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6741 | LinkDeclContextToDIE(function_decl, die); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6742 | if (!function_param_decls.empty()) | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6743 | ast.SetFunctionParameters (function_decl, | 
|  | 6744 | &function_param_decls.front(), | 
|  | 6745 | function_param_decls.size()); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6746 |  | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6747 | ClangASTMetadata metadata; | 
|  | 6748 | metadata.SetUserID(MakeUserID(die->GetOffset())); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6749 |  | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6750 | if (!object_pointer_name.empty()) | 
|  | 6751 | { | 
|  | 6752 | metadata.SetObjectPtrName(object_pointer_name.c_str()); | 
| Jim Ingham | 2cffda3f | 2012-10-30 23:34:07 +0000 | [diff] [blame] | 6753 | if (log) | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6754 | log->Printf ("Setting object pointer name: %s on function object %p.", | 
| Jim Ingham | 2cffda3f | 2012-10-30 23:34:07 +0000 | [diff] [blame] | 6755 | object_pointer_name.c_str(), | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6756 | static_cast<void*>(function_decl)); | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6757 | } | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6758 | GetClangASTContext().SetMetadata (function_decl, metadata); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6759 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6760 | } | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6761 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6762 | this, | 
|  | 6763 | type_name_const_str, | 
|  | 6764 | 0, | 
|  | 6765 | NULL, | 
|  | 6766 | LLDB_INVALID_UID, | 
|  | 6767 | Type::eEncodingIsUID, | 
|  | 6768 | &decl, | 
|  | 6769 | clang_type, | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6770 | Type::eResolveStateFull)); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6771 | assert(type_sp.get()); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6772 | } | 
|  | 6773 | break; | 
|  | 6774 |  | 
|  | 6775 | case DW_TAG_array_type: | 
|  | 6776 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6777 | // 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] | 6778 | m_die_to_type[die] = DIE_IS_BEING_PARSED; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6779 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6780 | lldb::user_id_t type_die_offset = DW_INVALID_OFFSET; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6781 | int64_t first_index = 0; | 
|  | 6782 | uint32_t byte_stride = 0; | 
|  | 6783 | uint32_t bit_stride = 0; | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 6784 | bool is_vector = false; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6785 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6786 |  | 
|  | 6787 | if (num_attributes > 0) | 
|  | 6788 | { | 
|  | 6789 | uint32_t i; | 
|  | 6790 | for (i=0; i<num_attributes; ++i) | 
|  | 6791 | { | 
|  | 6792 | attr = attributes.AttributeAtIndex(i); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6793 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 6794 | { | 
|  | 6795 | switch (attr) | 
|  | 6796 | { | 
|  | 6797 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 6798 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 6799 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 6800 | case DW_AT_name: | 
|  | 6801 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6802 | type_name_const_str.SetCString(type_name_cstr); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6803 | break; | 
|  | 6804 |  | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 6805 | case DW_AT_type:            type_die_offset = form_value.Reference(); break; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6806 | case DW_AT_byte_size:       break; // byte_size = form_value.Unsigned(); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6807 | case DW_AT_byte_stride:     byte_stride = form_value.Unsigned(); break; | 
|  | 6808 | case DW_AT_bit_stride:      bit_stride = form_value.Unsigned(); break; | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 6809 | case DW_AT_GNU_vector:      is_vector = form_value.Boolean(); break; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6810 | 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] | 6811 | case DW_AT_declaration:     break; // is_forward_declaration = form_value.Boolean(); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6812 | case DW_AT_allocated: | 
|  | 6813 | case DW_AT_associated: | 
|  | 6814 | case DW_AT_data_location: | 
|  | 6815 | case DW_AT_description: | 
|  | 6816 | case DW_AT_ordering: | 
|  | 6817 | case DW_AT_start_scope: | 
|  | 6818 | case DW_AT_visibility: | 
|  | 6819 | case DW_AT_specification: | 
|  | 6820 | case DW_AT_abstract_origin: | 
|  | 6821 | case DW_AT_sibling: | 
|  | 6822 | break; | 
|  | 6823 | } | 
|  | 6824 | } | 
|  | 6825 | } | 
|  | 6826 |  | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6827 | 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] | 6828 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6829 | Type *element_type = ResolveTypeUID(type_die_offset); | 
|  | 6830 |  | 
|  | 6831 | if (element_type) | 
|  | 6832 | { | 
|  | 6833 | std::vector<uint64_t> element_orders; | 
|  | 6834 | ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride); | 
|  | 6835 | if (byte_stride == 0 && bit_stride == 0) | 
|  | 6836 | byte_stride = element_type->GetByteSize(); | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6837 | ClangASTType array_element_type = element_type->GetClangForwardType(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6838 | uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride; | 
|  | 6839 | uint64_t num_elements = 0; | 
|  | 6840 | std::vector<uint64_t>::const_reverse_iterator pos; | 
|  | 6841 | std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend(); | 
|  | 6842 | for (pos = element_orders.rbegin(); pos != end; ++pos) | 
|  | 6843 | { | 
|  | 6844 | num_elements = *pos; | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6845 | clang_type = ast.CreateArrayType (array_element_type, | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 6846 | num_elements, | 
|  | 6847 | is_vector); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6848 | array_element_type = clang_type; | 
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 6849 | 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] | 6850 | } | 
|  | 6851 | ConstString empty_name; | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6852 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6853 | this, | 
|  | 6854 | empty_name, | 
|  | 6855 | array_element_bit_stride / 8, | 
|  | 6856 | NULL, | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6857 | type_die_offset, | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6858 | Type::eEncodingIsUID, | 
|  | 6859 | &decl, | 
|  | 6860 | clang_type, | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6861 | Type::eResolveStateFull)); | 
|  | 6862 | type_sp->SetEncodingType (element_type); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6863 | } | 
|  | 6864 | } | 
|  | 6865 | } | 
|  | 6866 | break; | 
|  | 6867 |  | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6868 | case DW_TAG_ptr_to_member_type: | 
|  | 6869 | { | 
|  | 6870 | dw_offset_t type_die_offset = DW_INVALID_OFFSET; | 
|  | 6871 | dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET; | 
|  | 6872 |  | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6873 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6874 |  | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6875 | if (num_attributes > 0) { | 
|  | 6876 | uint32_t i; | 
|  | 6877 | for (i=0; i<num_attributes; ++i) | 
|  | 6878 | { | 
|  | 6879 | attr = attributes.AttributeAtIndex(i); | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6880 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 6881 | { | 
|  | 6882 | switch (attr) | 
|  | 6883 | { | 
|  | 6884 | case DW_AT_type: | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 6885 | type_die_offset = form_value.Reference(); break; | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6886 | case DW_AT_containing_type: | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 6887 | containing_type_die_offset = form_value.Reference(); break; | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6888 | } | 
|  | 6889 | } | 
|  | 6890 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6891 |  | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6892 | Type *pointee_type = ResolveTypeUID(type_die_offset); | 
|  | 6893 | Type *class_type = ResolveTypeUID(containing_type_die_offset); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6894 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6895 | ClangASTType pointee_clang_type = pointee_type->GetClangForwardType(); | 
|  | 6896 | ClangASTType class_clang_type = class_type->GetClangLayoutType(); | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6897 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6898 | clang_type = pointee_clang_type.CreateMemberPointerType(class_clang_type); | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6899 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6900 | byte_size = clang_type.GetByteSize(); | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6901 |  | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6902 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6903 | this, | 
|  | 6904 | type_name_const_str, | 
|  | 6905 | byte_size, | 
|  | 6906 | NULL, | 
|  | 6907 | LLDB_INVALID_UID, | 
|  | 6908 | Type::eEncodingIsUID, | 
|  | 6909 | NULL, | 
|  | 6910 | clang_type, | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6911 | Type::eResolveStateForward)); | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6912 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6913 |  | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6914 | break; | 
|  | 6915 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6916 | default: | 
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 6917 | 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", | 
|  | 6918 | die->GetOffset(), | 
|  | 6919 | tag, | 
|  | 6920 | DW_TAG_value_to_name(tag)); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6921 | break; | 
|  | 6922 | } | 
|  | 6923 |  | 
|  | 6924 | if (type_sp.get()) | 
|  | 6925 | { | 
|  | 6926 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); | 
|  | 6927 | dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; | 
|  | 6928 |  | 
|  | 6929 | SymbolContextScope * symbol_context_scope = NULL; | 
|  | 6930 | if (sc_parent_tag == DW_TAG_compile_unit) | 
|  | 6931 | { | 
|  | 6932 | symbol_context_scope = sc.comp_unit; | 
|  | 6933 | } | 
| Jason Molenda | 60db6e4 | 2014-10-16 01:40:16 +0000 | [diff] [blame] | 6934 | else if (sc.function != NULL && sc_parent_die) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6935 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6936 | 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] | 6937 | if (symbol_context_scope == NULL) | 
|  | 6938 | symbol_context_scope = sc.function; | 
|  | 6939 | } | 
|  | 6940 |  | 
|  | 6941 | if (symbol_context_scope != NULL) | 
|  | 6942 | { | 
|  | 6943 | type_sp->SetSymbolContextScope(symbol_context_scope); | 
|  | 6944 | } | 
|  | 6945 |  | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6946 | // We are ready to put this type into the uniqued list up at the module level | 
|  | 6947 | type_list->Insert (type_sp); | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 6948 |  | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6949 | m_die_to_type[die] = type_sp.get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6950 | } | 
|  | 6951 | } | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 6952 | else if (type_ptr != DIE_IS_BEING_PARSED) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6953 | { | 
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 6954 | type_sp = type_ptr->shared_from_this(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6955 | } | 
|  | 6956 | } | 
|  | 6957 | return type_sp; | 
|  | 6958 | } | 
|  | 6959 |  | 
|  | 6960 | size_t | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6961 | SymbolFileDWARF::ParseTypes | 
|  | 6962 | ( | 
|  | 6963 | const SymbolContext& sc, | 
|  | 6964 | DWARFCompileUnit* dwarf_cu, | 
|  | 6965 | const DWARFDebugInfoEntry *die, | 
|  | 6966 | bool parse_siblings, | 
|  | 6967 | bool parse_children | 
|  | 6968 | ) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6969 | { | 
|  | 6970 | size_t types_added = 0; | 
|  | 6971 | while (die != NULL) | 
|  | 6972 | { | 
|  | 6973 | bool type_is_new = false; | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6974 | if (ParseType(sc, dwarf_cu, die, &type_is_new).get()) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6975 | { | 
|  | 6976 | if (type_is_new) | 
|  | 6977 | ++types_added; | 
|  | 6978 | } | 
|  | 6979 |  | 
|  | 6980 | if (parse_children && die->HasChildren()) | 
|  | 6981 | { | 
|  | 6982 | if (die->Tag() == DW_TAG_subprogram) | 
|  | 6983 | { | 
|  | 6984 | SymbolContext child_sc(sc); | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6985 | child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6986 | types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true); | 
|  | 6987 | } | 
|  | 6988 | else | 
|  | 6989 | types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true); | 
|  | 6990 | } | 
|  | 6991 |  | 
|  | 6992 | if (parse_siblings) | 
|  | 6993 | die = die->GetSibling(); | 
|  | 6994 | else | 
|  | 6995 | die = NULL; | 
|  | 6996 | } | 
|  | 6997 | return types_added; | 
|  | 6998 | } | 
|  | 6999 |  | 
|  | 7000 |  | 
|  | 7001 | size_t | 
|  | 7002 | SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc) | 
|  | 7003 | { | 
|  | 7004 | assert(sc.comp_unit && sc.function); | 
|  | 7005 | size_t functions_added = 0; | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 7006 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7007 | if (dwarf_cu) | 
|  | 7008 | { | 
|  | 7009 | dw_offset_t function_die_offset = sc.function->GetID(); | 
|  | 7010 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset); | 
|  | 7011 | if (function_die) | 
|  | 7012 | { | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 7013 | 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] | 7014 | } | 
|  | 7015 | } | 
|  | 7016 |  | 
|  | 7017 | return functions_added; | 
|  | 7018 | } | 
|  | 7019 |  | 
|  | 7020 |  | 
|  | 7021 | size_t | 
|  | 7022 | SymbolFileDWARF::ParseTypes (const SymbolContext &sc) | 
|  | 7023 | { | 
|  | 7024 | // At least a compile unit must be valid | 
|  | 7025 | assert(sc.comp_unit); | 
|  | 7026 | size_t types_added = 0; | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 7027 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7028 | if (dwarf_cu) | 
|  | 7029 | { | 
|  | 7030 | if (sc.function) | 
|  | 7031 | { | 
|  | 7032 | dw_offset_t function_die_offset = sc.function->GetID(); | 
|  | 7033 | const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset); | 
|  | 7034 | if (func_die && func_die->HasChildren()) | 
|  | 7035 | { | 
|  | 7036 | types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true); | 
|  | 7037 | } | 
|  | 7038 | } | 
|  | 7039 | else | 
|  | 7040 | { | 
|  | 7041 | const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE(); | 
|  | 7042 | if (dwarf_cu_die && dwarf_cu_die->HasChildren()) | 
|  | 7043 | { | 
|  | 7044 | types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true); | 
|  | 7045 | } | 
|  | 7046 | } | 
|  | 7047 | } | 
|  | 7048 |  | 
|  | 7049 | return types_added; | 
|  | 7050 | } | 
|  | 7051 |  | 
|  | 7052 | size_t | 
|  | 7053 | SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc) | 
|  | 7054 | { | 
|  | 7055 | if (sc.comp_unit != NULL) | 
|  | 7056 | { | 
| Greg Clayton | 4b3dc10 | 2010-11-01 20:32:12 +0000 | [diff] [blame] | 7057 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 7058 | if (info == NULL) | 
|  | 7059 | return 0; | 
|  | 7060 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7061 | if (sc.function) | 
|  | 7062 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7063 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnitContainingDIE(sc.function->GetID()).get(); | 
|  | 7064 |  | 
|  | 7065 | if (dwarf_cu == NULL) | 
|  | 7066 | return 0; | 
|  | 7067 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7068 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID()); | 
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 7069 |  | 
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 7070 | dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS); | 
|  | 7071 | if (func_lo_pc != LLDB_INVALID_ADDRESS) | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 7072 | { | 
|  | 7073 | 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] | 7074 |  | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 7075 | // Let all blocks know they have parse all their variables | 
|  | 7076 | sc.function->GetBlock (false).SetDidParseVariables (true, true); | 
|  | 7077 | return num_variables; | 
|  | 7078 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7079 | } | 
|  | 7080 | else if (sc.comp_unit) | 
|  | 7081 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7082 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()).get(); | 
|  | 7083 |  | 
|  | 7084 | if (dwarf_cu == NULL) | 
|  | 7085 | return 0; | 
|  | 7086 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7087 | uint32_t vars_added = 0; | 
|  | 7088 | VariableListSP variables (sc.comp_unit->GetVariableList(false)); | 
|  | 7089 |  | 
|  | 7090 | if (variables.get() == NULL) | 
|  | 7091 | { | 
|  | 7092 | variables.reset(new VariableList()); | 
|  | 7093 | sc.comp_unit->SetVariableList(variables); | 
|  | 7094 |  | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7095 | DWARFCompileUnit* match_dwarf_cu = NULL; | 
|  | 7096 | const DWARFDebugInfoEntry* die = NULL; | 
|  | 7097 | DIEArray die_offsets; | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 7098 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7099 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 7100 | if (m_apple_names_ap.get()) | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7101 | { | 
|  | 7102 | DWARFMappedHash::DIEInfoArray hash_data_array; | 
|  | 7103 | if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(), | 
|  | 7104 | dwarf_cu->GetNextCompileUnitOffset(), | 
|  | 7105 | hash_data_array)) | 
|  | 7106 | { | 
|  | 7107 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); | 
|  | 7108 | } | 
|  | 7109 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7110 | } | 
|  | 7111 | else | 
|  | 7112 | { | 
|  | 7113 | // Index if we already haven't to make sure the compile units | 
|  | 7114 | // get indexed and make their global DIE index list | 
|  | 7115 | if (!m_indexed) | 
|  | 7116 | Index (); | 
|  | 7117 |  | 
|  | 7118 | m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(), | 
|  | 7119 | dwarf_cu->GetNextCompileUnitOffset(), | 
|  | 7120 | die_offsets); | 
|  | 7121 | } | 
|  | 7122 |  | 
|  | 7123 | const size_t num_matches = die_offsets.size(); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7124 | if (num_matches) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7125 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7126 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 7127 | for (size_t i=0; i<num_matches; ++i) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7128 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7129 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 7130 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 7131 | if (die) | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7132 | { | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 7133 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS)); | 
|  | 7134 | if (var_sp) | 
|  | 7135 | { | 
|  | 7136 | variables->AddVariableIfUnique (var_sp); | 
|  | 7137 | ++vars_added; | 
|  | 7138 | } | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7139 | } | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 7140 | else | 
|  | 7141 | { | 
|  | 7142 | if (m_using_apple_tables) | 
|  | 7143 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 7144 | 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] | 7145 | } | 
|  | 7146 | } | 
|  | 7147 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7148 | } | 
|  | 7149 | } | 
|  | 7150 | } | 
|  | 7151 | return vars_added; | 
|  | 7152 | } | 
|  | 7153 | } | 
|  | 7154 | return 0; | 
|  | 7155 | } | 
|  | 7156 |  | 
|  | 7157 |  | 
|  | 7158 | VariableSP | 
|  | 7159 | SymbolFileDWARF::ParseVariableDIE | 
|  | 7160 | ( | 
|  | 7161 | const SymbolContext& sc, | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 7162 | DWARFCompileUnit* dwarf_cu, | 
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 7163 | const DWARFDebugInfoEntry *die, | 
|  | 7164 | const lldb::addr_t func_low_pc | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7165 | ) | 
|  | 7166 | { | 
| Greg Clayton | 83c5cd9 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 7167 | VariableSP var_sp (m_die_to_variable_sp[die]); | 
|  | 7168 | if (var_sp) | 
|  | 7169 | return var_sp;  // Already been parsed! | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7170 |  | 
|  | 7171 | const dw_tag_t tag = die->Tag(); | 
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 7172 | ModuleSP module = GetObjectFile()->GetModule(); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7173 |  | 
|  | 7174 | if ((tag == DW_TAG_variable) || | 
|  | 7175 | (tag == DW_TAG_constant) || | 
|  | 7176 | (tag == DW_TAG_formal_parameter && sc.function)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7177 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7178 | DWARFDebugInfoEntry::Attributes attributes; | 
|  | 7179 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
|  | 7180 | if (num_attributes > 0) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7181 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7182 | const char *name = NULL; | 
|  | 7183 | const char *mangled = NULL; | 
|  | 7184 | Declaration decl; | 
|  | 7185 | uint32_t i; | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7186 | lldb::user_id_t type_uid = LLDB_INVALID_UID; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7187 | DWARFExpression location; | 
|  | 7188 | bool is_external = false; | 
|  | 7189 | bool is_artificial = false; | 
|  | 7190 | bool location_is_const_value_data = false; | 
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7191 | bool has_explicit_location = false; | 
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 7192 | DWARFFormValue const_value; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 7193 | //AccessType accessibility = eAccessNone; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7194 |  | 
|  | 7195 | for (i=0; i<num_attributes; ++i) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7196 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7197 | dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 7198 | DWARFFormValue form_value; | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 7199 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7200 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7201 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7202 | switch (attr) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7203 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7204 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 7205 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 7206 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 7207 | 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] | 7208 | case DW_AT_linkage_name: | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7209 | case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break; | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 7210 | case DW_AT_type:        type_uid = form_value.Reference(); break; | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 7211 | case DW_AT_external:    is_external = form_value.Boolean(); break; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7212 | case DW_AT_const_value: | 
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7213 | // If we have already found a DW_AT_location attribute, ignore this attribute. | 
|  | 7214 | if (!has_explicit_location) | 
|  | 7215 | { | 
|  | 7216 | location_is_const_value_data = true; | 
|  | 7217 | // The constant value will be either a block, a data value or a string. | 
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 7218 | const DWARFDataExtractor& debug_info_data = get_debug_info_data(); | 
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7219 | if (DWARFFormValue::IsBlockForm(form_value.Form())) | 
|  | 7220 | { | 
|  | 7221 | // Retrieve the value as a block expression. | 
|  | 7222 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); | 
|  | 7223 | uint32_t block_length = form_value.Unsigned(); | 
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 7224 | location.CopyOpcodeData(module, debug_info_data, block_offset, block_length); | 
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7225 | } | 
|  | 7226 | else if (DWARFFormValue::IsDataForm(form_value.Form())) | 
|  | 7227 | { | 
|  | 7228 | // Retrieve the value as a data expression. | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 7229 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (attributes.CompileUnitAtIndex(i)->GetAddressByteSize(), attributes.CompileUnitAtIndex(i)->IsDWARF64()); | 
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7230 | uint32_t data_offset = attributes.DIEOffsetAtIndex(i); | 
|  | 7231 | uint32_t data_length = fixed_form_sizes[form_value.Form()]; | 
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 7232 | if (data_length == 0) | 
|  | 7233 | { | 
|  | 7234 | const uint8_t *data_pointer = form_value.BlockData(); | 
|  | 7235 | if (data_pointer) | 
|  | 7236 | { | 
| Jason Molenda | 18f5fd3 | 2014-10-16 07:52:17 +0000 | [diff] [blame] | 7237 | form_value.Unsigned(); | 
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 7238 | } | 
|  | 7239 | else if (DWARFFormValue::IsDataForm(form_value.Form())) | 
|  | 7240 | { | 
|  | 7241 | // we need to get the byte size of the type later after we create the variable | 
|  | 7242 | const_value = form_value; | 
|  | 7243 | } | 
|  | 7244 | } | 
|  | 7245 | else | 
|  | 7246 | location.CopyOpcodeData(module, debug_info_data, data_offset, data_length); | 
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7247 | } | 
|  | 7248 | else | 
|  | 7249 | { | 
|  | 7250 | // Retrieve the value as a string expression. | 
|  | 7251 | if (form_value.Form() == DW_FORM_strp) | 
|  | 7252 | { | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 7253 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (attributes.CompileUnitAtIndex(i)->GetAddressByteSize(), attributes.CompileUnitAtIndex(i)->IsDWARF64()); | 
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7254 | uint32_t data_offset = attributes.DIEOffsetAtIndex(i); | 
|  | 7255 | uint32_t data_length = fixed_form_sizes[form_value.Form()]; | 
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 7256 | location.CopyOpcodeData(module, debug_info_data, data_offset, data_length); | 
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7257 | } | 
|  | 7258 | else | 
|  | 7259 | { | 
|  | 7260 | const char *str = form_value.AsCString(&debug_info_data); | 
|  | 7261 | uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart(); | 
|  | 7262 | uint32_t string_length = strlen(str) + 1; | 
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 7263 | location.CopyOpcodeData(module, debug_info_data, string_offset, string_length); | 
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7264 | } | 
|  | 7265 | } | 
|  | 7266 | } | 
|  | 7267 | break; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7268 | case DW_AT_location: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7269 | { | 
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7270 | location_is_const_value_data = false; | 
|  | 7271 | has_explicit_location = true; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7272 | if (form_value.BlockData()) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7273 | { | 
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 7274 | const DWARFDataExtractor& debug_info_data = get_debug_info_data(); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7275 |  | 
|  | 7276 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); | 
|  | 7277 | uint32_t block_length = form_value.Unsigned(); | 
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 7278 | location.CopyOpcodeData(module, get_debug_info_data(), block_offset, block_length); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7279 | } | 
|  | 7280 | else | 
|  | 7281 | { | 
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 7282 | const DWARFDataExtractor&    debug_loc_data = get_debug_loc_data(); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7283 | const dw_offset_t debug_loc_offset = form_value.Unsigned(); | 
|  | 7284 |  | 
|  | 7285 | size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset); | 
|  | 7286 | if (loc_list_length > 0) | 
|  | 7287 | { | 
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 7288 | location.CopyOpcodeData(module, debug_loc_data, debug_loc_offset, loc_list_length); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7289 | assert (func_low_pc != LLDB_INVALID_ADDRESS); | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 7290 | location.SetLocationListSlide (func_low_pc - attributes.CompileUnitAtIndex(i)->GetBaseAddress()); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7291 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7292 | } | 
|  | 7293 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7294 | break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7295 |  | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 7296 | case DW_AT_artificial:      is_artificial = form_value.Boolean(); break; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 7297 | 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] | 7298 | case DW_AT_declaration: | 
|  | 7299 | case DW_AT_description: | 
|  | 7300 | case DW_AT_endianity: | 
|  | 7301 | case DW_AT_segment: | 
|  | 7302 | case DW_AT_start_scope: | 
|  | 7303 | case DW_AT_visibility: | 
|  | 7304 | default: | 
|  | 7305 | case DW_AT_abstract_origin: | 
|  | 7306 | case DW_AT_sibling: | 
|  | 7307 | case DW_AT_specification: | 
|  | 7308 | break; | 
|  | 7309 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7310 | } | 
|  | 7311 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7312 |  | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7313 | ValueType scope = eValueTypeInvalid; | 
|  | 7314 |  | 
|  | 7315 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); | 
|  | 7316 | dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; | 
|  | 7317 | SymbolContextScope * symbol_context_scope = NULL; | 
|  | 7318 |  | 
|  | 7319 | // DWARF doesn't specify if a DW_TAG_variable is a local, global | 
|  | 7320 | // or static variable, so we have to do a little digging by | 
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 7321 | // looking at the location of a variable to see if it contains | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7322 | // a DW_OP_addr opcode _somewhere_ in the definition. I say | 
|  | 7323 | // somewhere because clang likes to combine small global variables | 
|  | 7324 | // into the same symbol and have locations like: | 
|  | 7325 | // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus | 
|  | 7326 | // So if we don't have a DW_TAG_formal_parameter, we can look at | 
|  | 7327 | // the location to see if it contains a DW_OP_addr opcode, and | 
|  | 7328 | // then we can correctly classify  our variables. | 
|  | 7329 | if (tag == DW_TAG_formal_parameter) | 
|  | 7330 | scope = eValueTypeVariableArgument; | 
|  | 7331 | else | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7332 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7333 | bool op_error = false; | 
|  | 7334 | // Check if the location has a DW_OP_addr with any address value... | 
|  | 7335 | lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS; | 
|  | 7336 | if (!location_is_const_value_data) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7337 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7338 | location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error); | 
|  | 7339 | if (op_error) | 
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 7340 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7341 | StreamString strm; | 
|  | 7342 | location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL); | 
|  | 7343 | 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] | 7344 | } | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7345 | } | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7346 |  | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7347 | if (location_DW_OP_addr != LLDB_INVALID_ADDRESS) | 
|  | 7348 | { | 
|  | 7349 | if (is_external) | 
|  | 7350 | scope = eValueTypeVariableGlobal; | 
|  | 7351 | else | 
|  | 7352 | scope = eValueTypeVariableStatic; | 
|  | 7353 |  | 
|  | 7354 |  | 
|  | 7355 | SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile (); | 
|  | 7356 |  | 
|  | 7357 | if (debug_map_symfile) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7358 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7359 | // When leaving the DWARF in the .o files on darwin, | 
|  | 7360 | // when we have a global variable that wasn't initialized, | 
|  | 7361 | // the .o file might not have allocated a virtual | 
|  | 7362 | // address for the global variable. In this case it will | 
|  | 7363 | // have created a symbol for the global variable | 
|  | 7364 | // that is undefined/data and external and the value will | 
|  | 7365 | // be the byte size of the variable. When we do the | 
|  | 7366 | // address map in SymbolFileDWARFDebugMap we rely on | 
|  | 7367 | // having an address, we need to do some magic here | 
|  | 7368 | // so we can get the correct address for our global | 
|  | 7369 | // variable. The address for all of these entries | 
|  | 7370 | // will be zero, and there will be an undefined symbol | 
|  | 7371 | // in this object file, and the executable will have | 
|  | 7372 | // a matching symbol with a good address. So here we | 
|  | 7373 | // dig up the correct address and replace it in the | 
|  | 7374 | // location for the variable, and set the variable's | 
|  | 7375 | // symbol context scope to be that of the main executable | 
|  | 7376 | // so the file address will resolve correctly. | 
|  | 7377 | bool linked_oso_file_addr = false; | 
|  | 7378 | if (is_external && location_DW_OP_addr == 0) | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7379 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7380 | // we have a possible uninitialized extern global | 
|  | 7381 | ConstString const_name(mangled ? mangled : name); | 
|  | 7382 | ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile(); | 
|  | 7383 | if (debug_map_objfile) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7384 | { | 
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 7385 | Symtab *debug_map_symtab = debug_map_objfile->GetSymtab(); | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7386 | if (debug_map_symtab) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7387 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7388 | Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name, | 
|  | 7389 | eSymbolTypeData, | 
|  | 7390 | Symtab::eDebugYes, | 
|  | 7391 | Symtab::eVisibilityExtern); | 
|  | 7392 | if (exe_symbol) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7393 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7394 | if (exe_symbol->ValueIsAddress()) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7395 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7396 | const addr_t exe_file_addr = exe_symbol->GetAddress().GetFileAddress(); | 
|  | 7397 | if (exe_file_addr != LLDB_INVALID_ADDRESS) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7398 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7399 | if (location.Update_DW_OP_addr (exe_file_addr)) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7400 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7401 | linked_oso_file_addr = true; | 
|  | 7402 | symbol_context_scope = exe_symbol; | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7403 | } | 
|  | 7404 | } | 
|  | 7405 | } | 
|  | 7406 | } | 
|  | 7407 | } | 
|  | 7408 | } | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7409 | } | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7410 |  | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7411 | if (!linked_oso_file_addr) | 
|  | 7412 | { | 
|  | 7413 | // The DW_OP_addr is not zero, but it contains a .o file address which | 
|  | 7414 | // needs to be linked up correctly. | 
|  | 7415 | const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr); | 
|  | 7416 | if (exe_file_addr != LLDB_INVALID_ADDRESS) | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7417 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7418 | // Update the file address for this variable | 
|  | 7419 | location.Update_DW_OP_addr (exe_file_addr); | 
|  | 7420 | } | 
|  | 7421 | else | 
|  | 7422 | { | 
|  | 7423 | // Variable didn't make it into the final executable | 
|  | 7424 | return var_sp; | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7425 | } | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7426 | } | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7427 | } | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 7428 | } | 
|  | 7429 | else | 
|  | 7430 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7431 | scope = eValueTypeVariableLocal; | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 7432 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7433 | } | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7434 |  | 
|  | 7435 | if (symbol_context_scope == NULL) | 
|  | 7436 | { | 
|  | 7437 | switch (parent_tag) | 
|  | 7438 | { | 
|  | 7439 | case DW_TAG_subprogram: | 
|  | 7440 | case DW_TAG_inlined_subroutine: | 
|  | 7441 | case DW_TAG_lexical_block: | 
|  | 7442 | if (sc.function) | 
|  | 7443 | { | 
|  | 7444 | symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); | 
|  | 7445 | if (symbol_context_scope == NULL) | 
|  | 7446 | symbol_context_scope = sc.function; | 
|  | 7447 | } | 
|  | 7448 | break; | 
|  | 7449 |  | 
|  | 7450 | default: | 
|  | 7451 | symbol_context_scope = sc.comp_unit; | 
|  | 7452 | break; | 
|  | 7453 | } | 
|  | 7454 | } | 
|  | 7455 |  | 
|  | 7456 | if (symbol_context_scope) | 
|  | 7457 | { | 
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 7458 | SymbolFileTypeSP type_sp(new SymbolFileType(*this, type_uid)); | 
|  | 7459 |  | 
|  | 7460 | if (const_value.Form() && type_sp && type_sp->GetType()) | 
|  | 7461 | location.CopyOpcodeData(const_value.Unsigned(), type_sp->GetType()->GetByteSize(), dwarf_cu->GetAddressByteSize()); | 
|  | 7462 |  | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7463 | var_sp.reset (new Variable (MakeUserID(die->GetOffset()), | 
|  | 7464 | name, | 
|  | 7465 | mangled, | 
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 7466 | type_sp, | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7467 | scope, | 
|  | 7468 | symbol_context_scope, | 
|  | 7469 | &decl, | 
|  | 7470 | location, | 
|  | 7471 | is_external, | 
|  | 7472 | is_artificial)); | 
|  | 7473 |  | 
|  | 7474 | var_sp->SetLocationIsConstantValueData (location_is_const_value_data); | 
|  | 7475 | } | 
|  | 7476 | else | 
|  | 7477 | { | 
|  | 7478 | // Not ready to parse this variable yet. It might be a global | 
|  | 7479 | // or static variable that is in a function scope and the function | 
|  | 7480 | // in the symbol context wasn't filled in yet | 
|  | 7481 | return var_sp; | 
|  | 7482 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7483 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7484 | // Cache var_sp even if NULL (the variable was just a specification or | 
|  | 7485 | // was missing vital information to be able to be displayed in the debugger | 
|  | 7486 | // (missing location due to optimization, etc)) so we don't re-parse | 
|  | 7487 | // this DIE over and over later... | 
|  | 7488 | m_die_to_variable_sp[die] = var_sp; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7489 | } | 
|  | 7490 | return var_sp; | 
|  | 7491 | } | 
|  | 7492 |  | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7493 |  | 
|  | 7494 | const DWARFDebugInfoEntry * | 
|  | 7495 | SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset, | 
|  | 7496 | dw_offset_t spec_block_die_offset, | 
|  | 7497 | DWARFCompileUnit **result_die_cu_handle) | 
|  | 7498 | { | 
|  | 7499 | // Give the concrete function die specified by "func_die_offset", find the | 
|  | 7500 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points | 
|  | 7501 | // to "spec_block_die_offset" | 
|  | 7502 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 7503 |  | 
|  | 7504 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle); | 
|  | 7505 | if (die) | 
|  | 7506 | { | 
|  | 7507 | assert (*result_die_cu_handle); | 
|  | 7508 | return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle); | 
|  | 7509 | } | 
|  | 7510 | return NULL; | 
|  | 7511 | } | 
|  | 7512 |  | 
|  | 7513 |  | 
|  | 7514 | const DWARFDebugInfoEntry * | 
|  | 7515 | SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu, | 
|  | 7516 | const DWARFDebugInfoEntry *die, | 
|  | 7517 | dw_offset_t spec_block_die_offset, | 
|  | 7518 | DWARFCompileUnit **result_die_cu_handle) | 
|  | 7519 | { | 
|  | 7520 | if (die) | 
|  | 7521 | { | 
|  | 7522 | switch (die->Tag()) | 
|  | 7523 | { | 
|  | 7524 | case DW_TAG_subprogram: | 
|  | 7525 | case DW_TAG_inlined_subroutine: | 
|  | 7526 | case DW_TAG_lexical_block: | 
|  | 7527 | { | 
|  | 7528 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset) | 
|  | 7529 | { | 
|  | 7530 | *result_die_cu_handle = dwarf_cu; | 
|  | 7531 | return die; | 
|  | 7532 | } | 
|  | 7533 |  | 
|  | 7534 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset) | 
|  | 7535 | { | 
|  | 7536 | *result_die_cu_handle = dwarf_cu; | 
|  | 7537 | return die; | 
|  | 7538 | } | 
|  | 7539 | } | 
|  | 7540 | break; | 
|  | 7541 | } | 
|  | 7542 |  | 
|  | 7543 | // Give the concrete function die specified by "func_die_offset", find the | 
|  | 7544 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points | 
|  | 7545 | // to "spec_block_die_offset" | 
|  | 7546 | for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling()) | 
|  | 7547 | { | 
|  | 7548 | const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu, | 
|  | 7549 | child_die, | 
|  | 7550 | spec_block_die_offset, | 
|  | 7551 | result_die_cu_handle); | 
|  | 7552 | if (result_die) | 
|  | 7553 | return result_die; | 
|  | 7554 | } | 
|  | 7555 | } | 
|  | 7556 |  | 
|  | 7557 | *result_die_cu_handle = NULL; | 
|  | 7558 | return NULL; | 
|  | 7559 | } | 
|  | 7560 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7561 | size_t | 
|  | 7562 | SymbolFileDWARF::ParseVariables | 
|  | 7563 | ( | 
|  | 7564 | const SymbolContext& sc, | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 7565 | DWARFCompileUnit* dwarf_cu, | 
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 7566 | const lldb::addr_t func_low_pc, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7567 | const DWARFDebugInfoEntry *orig_die, | 
|  | 7568 | bool parse_siblings, | 
|  | 7569 | bool parse_children, | 
|  | 7570 | VariableList* cc_variable_list | 
|  | 7571 | ) | 
|  | 7572 | { | 
|  | 7573 | if (orig_die == NULL) | 
|  | 7574 | return 0; | 
|  | 7575 |  | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7576 | VariableListSP variable_list_sp; | 
|  | 7577 |  | 
|  | 7578 | size_t vars_added = 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7579 | const DWARFDebugInfoEntry *die = orig_die; | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7580 | while (die != NULL) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7581 | { | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7582 | dw_tag_t tag = die->Tag(); | 
|  | 7583 |  | 
|  | 7584 | // Check to see if we have already parsed this variable or constant? | 
|  | 7585 | if (m_die_to_variable_sp[die]) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7586 | { | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7587 | if (cc_variable_list) | 
|  | 7588 | cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7589 | } | 
|  | 7590 | else | 
|  | 7591 | { | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7592 | // We haven't already parsed it, lets do that now. | 
|  | 7593 | if ((tag == DW_TAG_variable) || | 
|  | 7594 | (tag == DW_TAG_constant) || | 
|  | 7595 | (tag == DW_TAG_formal_parameter && sc.function)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7596 | { | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7597 | if (variable_list_sp.get() == NULL) | 
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7598 | { | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7599 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die); | 
|  | 7600 | dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; | 
|  | 7601 | switch (parent_tag) | 
|  | 7602 | { | 
|  | 7603 | case DW_TAG_compile_unit: | 
|  | 7604 | if (sc.comp_unit != NULL) | 
|  | 7605 | { | 
|  | 7606 | variable_list_sp = sc.comp_unit->GetVariableList(false); | 
|  | 7607 | if (variable_list_sp.get() == NULL) | 
|  | 7608 | { | 
|  | 7609 | variable_list_sp.reset(new VariableList()); | 
|  | 7610 | sc.comp_unit->SetVariableList(variable_list_sp); | 
|  | 7611 | } | 
|  | 7612 | } | 
|  | 7613 | else | 
|  | 7614 | { | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 7615 | 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] | 7616 | MakeUserID(sc_parent_die->GetOffset()), | 
|  | 7617 | DW_TAG_value_to_name (parent_tag), | 
|  | 7618 | MakeUserID(orig_die->GetOffset()), | 
|  | 7619 | DW_TAG_value_to_name (orig_die->Tag())); | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7620 | } | 
|  | 7621 | break; | 
|  | 7622 |  | 
|  | 7623 | case DW_TAG_subprogram: | 
|  | 7624 | case DW_TAG_inlined_subroutine: | 
|  | 7625 | case DW_TAG_lexical_block: | 
|  | 7626 | if (sc.function != NULL) | 
|  | 7627 | { | 
|  | 7628 | // Check to see if we already have parsed the variables for the given scope | 
|  | 7629 |  | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7630 | Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7631 | if (block == NULL) | 
|  | 7632 | { | 
|  | 7633 | // This must be a specification or abstract origin with | 
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 7634 | // a concrete block counterpart in the current function. We need | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7635 | // to find the concrete block so we can correctly add the | 
|  | 7636 | // variable to it | 
|  | 7637 | DWARFCompileUnit *concrete_block_die_cu = dwarf_cu; | 
|  | 7638 | const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(), | 
|  | 7639 | sc_parent_die->GetOffset(), | 
|  | 7640 | &concrete_block_die_cu); | 
|  | 7641 | if (concrete_block_die) | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7642 | block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset())); | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7643 | } | 
|  | 7644 |  | 
|  | 7645 | if (block != NULL) | 
|  | 7646 | { | 
|  | 7647 | const bool can_create = false; | 
|  | 7648 | variable_list_sp = block->GetBlockVariableList (can_create); | 
|  | 7649 | if (variable_list_sp.get() == NULL) | 
|  | 7650 | { | 
|  | 7651 | variable_list_sp.reset(new VariableList()); | 
|  | 7652 | block->SetVariableList(variable_list_sp); | 
|  | 7653 | } | 
|  | 7654 | } | 
|  | 7655 | } | 
|  | 7656 | break; | 
|  | 7657 |  | 
|  | 7658 | default: | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 7659 | 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] | 7660 | MakeUserID(orig_die->GetOffset()), | 
|  | 7661 | DW_TAG_value_to_name (orig_die->Tag())); | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7662 | break; | 
|  | 7663 | } | 
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7664 | } | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7665 |  | 
|  | 7666 | if (variable_list_sp) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7667 | { | 
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7668 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc)); | 
|  | 7669 | if (var_sp) | 
|  | 7670 | { | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7671 | variable_list_sp->AddVariableIfUnique (var_sp); | 
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7672 | if (cc_variable_list) | 
|  | 7673 | cc_variable_list->AddVariableIfUnique (var_sp); | 
|  | 7674 | ++vars_added; | 
|  | 7675 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7676 | } | 
|  | 7677 | } | 
|  | 7678 | } | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7679 |  | 
|  | 7680 | bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram); | 
|  | 7681 |  | 
|  | 7682 | if (!skip_children && parse_children && die->HasChildren()) | 
|  | 7683 | { | 
|  | 7684 | vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list); | 
|  | 7685 | } | 
|  | 7686 |  | 
|  | 7687 | if (parse_siblings) | 
|  | 7688 | die = die->GetSibling(); | 
|  | 7689 | else | 
|  | 7690 | die = NULL; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7691 | } | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7692 | return vars_added; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7693 | } | 
|  | 7694 |  | 
|  | 7695 | //------------------------------------------------------------------ | 
|  | 7696 | // PluginInterface protocol | 
|  | 7697 | //------------------------------------------------------------------ | 
| Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 7698 | ConstString | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7699 | SymbolFileDWARF::GetPluginName() | 
|  | 7700 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7701 | return GetPluginNameStatic(); | 
|  | 7702 | } | 
|  | 7703 |  | 
|  | 7704 | uint32_t | 
|  | 7705 | SymbolFileDWARF::GetPluginVersion() | 
|  | 7706 | { | 
|  | 7707 | return 1; | 
|  | 7708 | } | 
|  | 7709 |  | 
|  | 7710 | void | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 7711 | SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl) | 
|  | 7712 | { | 
|  | 7713 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 7714 | ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 7715 | if (clang_type) | 
|  | 7716 | symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); | 
|  | 7717 | } | 
|  | 7718 |  | 
|  | 7719 | void | 
|  | 7720 | SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl) | 
|  | 7721 | { | 
|  | 7722 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 7723 | ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 7724 | if (clang_type) | 
|  | 7725 | symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); | 
|  | 7726 | } | 
|  | 7727 |  | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7728 | void | 
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7729 | SymbolFileDWARF::DumpIndexes () | 
|  | 7730 | { | 
|  | 7731 | StreamFile s(stdout, false); | 
|  | 7732 |  | 
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 7733 | s.Printf ("DWARF index for (%s) '%s':", | 
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7734 | GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(), | 
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 7735 | GetObjectFile()->GetFileSpec().GetPath().c_str()); | 
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7736 | s.Printf("\nFunction basenames:\n");    m_function_basename_index.Dump (&s); | 
|  | 7737 | s.Printf("\nFunction fullnames:\n");    m_function_fullname_index.Dump (&s); | 
|  | 7738 | s.Printf("\nFunction methods:\n");      m_function_method_index.Dump (&s); | 
|  | 7739 | s.Printf("\nFunction selectors:\n");    m_function_selector_index.Dump (&s); | 
|  | 7740 | s.Printf("\nObjective C class selectors:\n");    m_objc_class_selectors_index.Dump (&s); | 
|  | 7741 | s.Printf("\nGlobals and statics:\n");   m_global_index.Dump (&s); | 
|  | 7742 | s.Printf("\nTypes:\n");                 m_type_index.Dump (&s); | 
|  | 7743 | s.Printf("\nNamepaces:\n");             m_namespace_index.Dump (&s); | 
|  | 7744 | } | 
|  | 7745 |  | 
|  | 7746 | void | 
|  | 7747 | SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context, | 
|  | 7748 | const char *name, | 
|  | 7749 | llvm::SmallVectorImpl <clang::NamedDecl *> *results) | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7750 | { | 
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7751 | DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context); | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7752 |  | 
|  | 7753 | if (iter == m_decl_ctx_to_die.end()) | 
|  | 7754 | return; | 
|  | 7755 |  | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7756 | 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] | 7757 | { | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7758 | const DWARFDebugInfoEntry *context_die = *pos; | 
|  | 7759 |  | 
|  | 7760 | if (!results) | 
|  | 7761 | return; | 
|  | 7762 |  | 
|  | 7763 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 7764 |  | 
|  | 7765 | DIEArray die_offsets; | 
|  | 7766 |  | 
|  | 7767 | DWARFCompileUnit* dwarf_cu = NULL; | 
|  | 7768 | const DWARFDebugInfoEntry* die = NULL; | 
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 7769 |  | 
|  | 7770 | if (m_using_apple_tables) | 
|  | 7771 | { | 
|  | 7772 | if (m_apple_types_ap.get()) | 
|  | 7773 | m_apple_types_ap->FindByName (name, die_offsets); | 
|  | 7774 | } | 
|  | 7775 | else | 
|  | 7776 | { | 
|  | 7777 | if (!m_indexed) | 
|  | 7778 | Index (); | 
|  | 7779 |  | 
|  | 7780 | m_type_index.Find (ConstString(name), die_offsets); | 
|  | 7781 | } | 
|  | 7782 |  | 
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 7783 | const size_t num_matches = die_offsets.size(); | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7784 |  | 
|  | 7785 | if (num_matches) | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7786 | { | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7787 | for (size_t i = 0; i < num_matches; ++i) | 
|  | 7788 | { | 
|  | 7789 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 7790 | die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7791 |  | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7792 | if (die->GetParent() != context_die) | 
|  | 7793 | continue; | 
|  | 7794 |  | 
|  | 7795 | Type *matching_type = ResolveType (dwarf_cu, die); | 
|  | 7796 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 7797 | clang::QualType qual_type = matching_type->GetClangForwardType().GetQualType(); | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7798 |  | 
|  | 7799 | if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr())) | 
|  | 7800 | { | 
|  | 7801 | clang::TagDecl *tag_decl = tag_type->getDecl(); | 
|  | 7802 | results->push_back(tag_decl); | 
|  | 7803 | } | 
|  | 7804 | else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr())) | 
|  | 7805 | { | 
|  | 7806 | clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl(); | 
|  | 7807 | results->push_back(typedef_decl); | 
|  | 7808 | } | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7809 | } | 
|  | 7810 | } | 
|  | 7811 | } | 
|  | 7812 | } | 
|  | 7813 |  | 
|  | 7814 | void | 
|  | 7815 | SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton, | 
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 7816 | const clang::DeclContext *decl_context, | 
|  | 7817 | clang::DeclarationName decl_name, | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7818 | llvm::SmallVectorImpl <clang::NamedDecl *> *results) | 
|  | 7819 | { | 
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 7820 |  | 
|  | 7821 | switch (decl_context->getDeclKind()) | 
|  | 7822 | { | 
|  | 7823 | case clang::Decl::Namespace: | 
|  | 7824 | case clang::Decl::TranslationUnit: | 
|  | 7825 | { | 
|  | 7826 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; | 
|  | 7827 | symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results); | 
|  | 7828 | } | 
|  | 7829 | break; | 
|  | 7830 | default: | 
|  | 7831 | break; | 
|  | 7832 | } | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7833 | } | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7834 |  | 
|  | 7835 | bool | 
|  | 7836 | SymbolFileDWARF::LayoutRecordType (void *baton, | 
|  | 7837 | const clang::RecordDecl *record_decl, | 
|  | 7838 | uint64_t &size, | 
|  | 7839 | uint64_t &alignment, | 
|  | 7840 | llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, | 
|  | 7841 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, | 
|  | 7842 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) | 
|  | 7843 | { | 
|  | 7844 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; | 
|  | 7845 | return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets); | 
|  | 7846 | } | 
|  | 7847 |  | 
|  | 7848 |  | 
|  | 7849 | bool | 
|  | 7850 | SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl, | 
|  | 7851 | uint64_t &bit_size, | 
|  | 7852 | uint64_t &alignment, | 
|  | 7853 | llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, | 
|  | 7854 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, | 
|  | 7855 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) | 
|  | 7856 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 7857 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7858 | RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl); | 
|  | 7859 | bool success = false; | 
|  | 7860 | base_offsets.clear(); | 
|  | 7861 | vbase_offsets.clear(); | 
|  | 7862 | if (pos != m_record_decl_to_layout_map.end()) | 
|  | 7863 | { | 
|  | 7864 | bit_size = pos->second.bit_size; | 
|  | 7865 | alignment = pos->second.alignment; | 
|  | 7866 | field_offsets.swap(pos->second.field_offsets); | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 7867 | base_offsets.swap (pos->second.base_offsets); | 
|  | 7868 | vbase_offsets.swap (pos->second.vbase_offsets); | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7869 | m_record_decl_to_layout_map.erase(pos); | 
|  | 7870 | success = true; | 
|  | 7871 | } | 
|  | 7872 | else | 
|  | 7873 | { | 
|  | 7874 | bit_size = 0; | 
|  | 7875 | alignment = 0; | 
|  | 7876 | field_offsets.clear(); | 
|  | 7877 | } | 
|  | 7878 |  | 
|  | 7879 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 7880 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 7881 | "SymbolFileDWARF::LayoutRecordType (record_decl = %p, bit_size = %" PRIu64 ", alignment = %" PRIu64 ", field_offsets[%u],base_offsets[%u], vbase_offsets[%u]) success = %i", | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 7882 | static_cast<const void*>(record_decl), | 
|  | 7883 | bit_size, alignment, | 
|  | 7884 | static_cast<uint32_t>(field_offsets.size()), | 
|  | 7885 | static_cast<uint32_t>(base_offsets.size()), | 
|  | 7886 | static_cast<uint32_t>(vbase_offsets.size()), | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7887 | success); | 
|  | 7888 | return success; | 
|  | 7889 | } | 
|  | 7890 |  | 
|  | 7891 |  | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 7892 | SymbolFileDWARFDebugMap * | 
|  | 7893 | SymbolFileDWARF::GetDebugMapSymfile () | 
|  | 7894 | { | 
|  | 7895 | if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired()) | 
|  | 7896 | { | 
|  | 7897 | lldb::ModuleSP module_sp (m_debug_map_module_wp.lock()); | 
|  | 7898 | if (module_sp) | 
|  | 7899 | { | 
|  | 7900 | SymbolVendor *sym_vendor = module_sp->GetSymbolVendor(); | 
|  | 7901 | if (sym_vendor) | 
|  | 7902 | m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile(); | 
|  | 7903 | } | 
|  | 7904 | } | 
|  | 7905 | return m_debug_map_symfile; | 
|  | 7906 | } | 
|  | 7907 |  | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7908 |  |