| 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. | 
| Greg Clayton | 68c00bd | 2015-02-05 02:10:29 +0000 | [diff] [blame] | 896 |  | 
|  | 897 | DWARFCompileUnit *dwarf_cu = info->GetCompileUnit(0).get(); | 
|  | 898 | if (dwarf_cu && dwarf_cu->GetUserData() == NULL) | 
|  | 899 | dwarf_cu->SetUserData(comp_unit); | 
|  | 900 | return dwarf_cu; | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 901 | } | 
|  | 902 | else | 
|  | 903 | { | 
|  | 904 | // Just a normal DWARF file whose user ID for the compile unit is | 
|  | 905 | // the DWARF offset itself | 
| Greg Clayton | 68c00bd | 2015-02-05 02:10:29 +0000 | [diff] [blame] | 906 |  | 
|  | 907 | DWARFCompileUnit *dwarf_cu = info->GetCompileUnit((dw_offset_t)comp_unit->GetID()).get(); | 
|  | 908 | if (dwarf_cu && dwarf_cu->GetUserData() == NULL) | 
|  | 909 | dwarf_cu->SetUserData(comp_unit); | 
|  | 910 | return dwarf_cu; | 
|  | 911 |  | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 912 | } | 
|  | 913 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 914 | return NULL; | 
|  | 915 | } | 
|  | 916 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 917 |  | 
|  | 918 | DWARFDebugRanges* | 
|  | 919 | SymbolFileDWARF::DebugRanges() | 
|  | 920 | { | 
|  | 921 | if (m_ranges.get() == NULL) | 
|  | 922 | { | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 923 | Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", | 
|  | 924 | __PRETTY_FUNCTION__, static_cast<void*>(this)); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 925 | if (get_debug_ranges_data().GetByteSize() > 0) | 
|  | 926 | { | 
|  | 927 | m_ranges.reset(new DWARFDebugRanges()); | 
|  | 928 | if (m_ranges.get()) | 
|  | 929 | m_ranges->Extract(this); | 
|  | 930 | } | 
|  | 931 | } | 
|  | 932 | return m_ranges.get(); | 
|  | 933 | } | 
|  | 934 |  | 
|  | 935 | const DWARFDebugRanges* | 
|  | 936 | SymbolFileDWARF::DebugRanges() const | 
|  | 937 | { | 
|  | 938 | return m_ranges.get(); | 
|  | 939 | } | 
| 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 | lldb::CompUnitSP | 
|  | 942 | SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 943 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 944 | CompUnitSP cu_sp; | 
|  | 945 | if (dwarf_cu) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 946 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 947 | CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData(); | 
|  | 948 | if (comp_unit) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 949 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 950 | // We already parsed this compile unit, had out a shared pointer to it | 
|  | 951 | cu_sp = comp_unit->shared_from_this(); | 
|  | 952 | } | 
|  | 953 | else | 
|  | 954 | { | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 955 | if (GetDebugMapSymfile ()) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 956 | { | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 957 | // Let the debug map create the compile unit | 
|  | 958 | cu_sp = m_debug_map_symfile->GetCompileUnit(this); | 
|  | 959 | dwarf_cu->SetUserData(cu_sp.get()); | 
|  | 960 | } | 
|  | 961 | else | 
|  | 962 | { | 
|  | 963 | ModuleSP module_sp (m_obj_file->GetModule()); | 
|  | 964 | if (module_sp) | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 965 | { | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 966 | const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly (); | 
|  | 967 | if (cu_die) | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 968 | { | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 969 | const char * cu_die_name = cu_die->GetName(this, dwarf_cu); | 
|  | 970 | const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL); | 
|  | 971 | LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0); | 
|  | 972 | if (cu_die_name) | 
|  | 973 | { | 
|  | 974 | std::string ramapped_file; | 
|  | 975 | FileSpec cu_file_spec; | 
| Jim Ingham | 0909e5f | 2010-09-16 00:57:33 +0000 | [diff] [blame] | 976 |  | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 977 | 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] | 978 | { | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 979 | // If we have a full path to the compile unit, we don't need to resolve | 
|  | 980 | // the file.  This can be expensive e.g. when the source files are NFS mounted. | 
|  | 981 | if (module_sp->RemapSourceFile(cu_die_name, ramapped_file)) | 
|  | 982 | cu_file_spec.SetFile (ramapped_file.c_str(), false); | 
|  | 983 | else | 
|  | 984 | cu_file_spec.SetFile (cu_die_name, false); | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 985 | } | 
|  | 986 | else | 
|  | 987 | { | 
| Matthew Gardiner | e81df3b | 2014-08-26 06:57:23 +0000 | [diff] [blame] | 988 | // DWARF2/3 suggests the form hostname:pathname for compilation directory. | 
|  | 989 | // Remove the host part if present. | 
|  | 990 | cu_comp_dir = removeHostnameFromPathname(cu_comp_dir); | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 991 | std::string fullpath(cu_comp_dir); | 
| Matthew Gardiner | e81df3b | 2014-08-26 06:57:23 +0000 | [diff] [blame] | 992 |  | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 993 | if (*fullpath.rbegin() != '/') | 
|  | 994 | fullpath += '/'; | 
|  | 995 | fullpath += cu_die_name; | 
|  | 996 | if (module_sp->RemapSourceFile (fullpath.c_str(), ramapped_file)) | 
|  | 997 | cu_file_spec.SetFile (ramapped_file.c_str(), false); | 
|  | 998 | else | 
|  | 999 | cu_file_spec.SetFile (fullpath.c_str(), false); | 
|  | 1000 | } | 
|  | 1001 |  | 
|  | 1002 | cu_sp.reset(new CompileUnit (module_sp, | 
|  | 1003 | dwarf_cu, | 
|  | 1004 | cu_file_spec, | 
|  | 1005 | MakeUserID(dwarf_cu->GetOffset()), | 
|  | 1006 | cu_language)); | 
|  | 1007 | if (cu_sp) | 
|  | 1008 | { | 
|  | 1009 | dwarf_cu->SetUserData(cu_sp.get()); | 
|  | 1010 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1011 | // Figure out the compile unit index if we weren't given one | 
|  | 1012 | if (cu_idx == UINT32_MAX) | 
|  | 1013 | DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx); | 
|  | 1014 |  | 
|  | 1015 | m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp); | 
|  | 1016 | } | 
|  | 1017 | } | 
|  | 1018 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1019 | } | 
|  | 1020 | } | 
|  | 1021 | } | 
|  | 1022 | } | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1023 | return cu_sp; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1024 | } | 
|  | 1025 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1026 | uint32_t | 
|  | 1027 | SymbolFileDWARF::GetNumCompileUnits() | 
|  | 1028 | { | 
|  | 1029 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 1030 | if (info) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1031 | return info->GetNumCompileUnits(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1032 | return 0; | 
|  | 1033 | } | 
|  | 1034 |  | 
|  | 1035 | CompUnitSP | 
|  | 1036 | SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx) | 
|  | 1037 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1038 | CompUnitSP cu_sp; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1039 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 1040 | if (info) | 
|  | 1041 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1042 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx); | 
|  | 1043 | if (dwarf_cu) | 
|  | 1044 | cu_sp = ParseCompileUnit(dwarf_cu, cu_idx); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1045 | } | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1046 | return cu_sp; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1047 | } | 
|  | 1048 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1049 | Function * | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1050 | SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1051 | { | 
|  | 1052 | DWARFDebugRanges::RangeList func_ranges; | 
|  | 1053 | const char *name = NULL; | 
|  | 1054 | const char *mangled = NULL; | 
|  | 1055 | int decl_file = 0; | 
|  | 1056 | int decl_line = 0; | 
|  | 1057 | int decl_column = 0; | 
|  | 1058 | int call_file = 0; | 
|  | 1059 | int call_line = 0; | 
|  | 1060 | int call_column = 0; | 
|  | 1061 | DWARFExpression frame_base; | 
|  | 1062 |  | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1063 | assert (die->Tag() == DW_TAG_subprogram); | 
|  | 1064 |  | 
|  | 1065 | if (die->Tag() != DW_TAG_subprogram) | 
|  | 1066 | return NULL; | 
|  | 1067 |  | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1068 | if (die->GetDIENamesAndRanges (this, | 
|  | 1069 | dwarf_cu, | 
|  | 1070 | name, | 
|  | 1071 | mangled, | 
|  | 1072 | func_ranges, | 
|  | 1073 | decl_file, | 
|  | 1074 | decl_line, | 
|  | 1075 | decl_column, | 
|  | 1076 | call_file, | 
|  | 1077 | call_line, | 
|  | 1078 | call_column, | 
|  | 1079 | &frame_base)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1080 | { | 
|  | 1081 | // Union of all ranges in the function DIE (if the function is discontiguous) | 
|  | 1082 | AddressRange func_range; | 
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1083 | lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0); | 
|  | 1084 | lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1085 | if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr) | 
|  | 1086 | { | 
| Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1087 | ModuleSP module_sp (m_obj_file->GetModule()); | 
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 1088 | func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, module_sp->GetSectionList()); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1089 | if (func_range.GetBaseAddress().IsValid()) | 
|  | 1090 | func_range.SetByteSize(highest_func_addr - lowest_func_addr); | 
|  | 1091 | } | 
|  | 1092 |  | 
|  | 1093 | if (func_range.GetBaseAddress().IsValid()) | 
|  | 1094 | { | 
|  | 1095 | Mangled func_name; | 
|  | 1096 | if (mangled) | 
| Greg Clayton | 037520e | 2012-07-18 23:18:10 +0000 | [diff] [blame] | 1097 | func_name.SetValue(ConstString(mangled), true); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1098 | else if (name) | 
| Greg Clayton | 037520e | 2012-07-18 23:18:10 +0000 | [diff] [blame] | 1099 | func_name.SetValue(ConstString(name), false); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1100 |  | 
|  | 1101 | FunctionSP func_sp; | 
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1102 | std::unique_ptr<Declaration> decl_ap; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1103 | if (decl_file != 0 || decl_line != 0 || decl_column != 0) | 
| Greg Clayton | d7e0546 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 1104 | decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), | 
|  | 1105 | decl_line, | 
|  | 1106 | decl_column)); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1107 |  | 
| Greg Clayton | 0bd4e1b | 2011-09-30 20:52:25 +0000 | [diff] [blame] | 1108 | // Supply the type _only_ if it has already been parsed | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 1109 | Type *func_type = m_die_to_type.lookup (die); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1110 |  | 
|  | 1111 | assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED); | 
|  | 1112 |  | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1113 | if (FixupAddress (func_range.GetBaseAddress())) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1114 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1115 | const user_id_t func_user_id = MakeUserID(die->GetOffset()); | 
|  | 1116 | func_sp.reset(new Function (sc.comp_unit, | 
|  | 1117 | MakeUserID(func_user_id),       // UserID is the DIE offset | 
|  | 1118 | MakeUserID(func_user_id), | 
|  | 1119 | func_name, | 
|  | 1120 | func_type, | 
|  | 1121 | func_range));           // first address range | 
|  | 1122 |  | 
|  | 1123 | if (func_sp.get() != NULL) | 
|  | 1124 | { | 
|  | 1125 | if (frame_base.IsValid()) | 
|  | 1126 | func_sp->GetFrameBaseExpression() = frame_base; | 
|  | 1127 | sc.comp_unit->AddFunction(func_sp); | 
|  | 1128 | return func_sp.get(); | 
|  | 1129 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1130 | } | 
|  | 1131 | } | 
|  | 1132 | } | 
|  | 1133 | return NULL; | 
|  | 1134 | } | 
|  | 1135 |  | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1136 | bool | 
|  | 1137 | SymbolFileDWARF::FixupAddress (Address &addr) | 
|  | 1138 | { | 
|  | 1139 | SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile (); | 
|  | 1140 | if (debug_map_symfile) | 
|  | 1141 | { | 
|  | 1142 | return debug_map_symfile->LinkOSOAddress(addr); | 
|  | 1143 | } | 
|  | 1144 | // This is a normal DWARF file, no address fixups need to happen | 
|  | 1145 | return true; | 
|  | 1146 | } | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1147 | lldb::LanguageType | 
|  | 1148 | SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc) | 
|  | 1149 | { | 
|  | 1150 | assert (sc.comp_unit); | 
|  | 1151 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); | 
|  | 1152 | if (dwarf_cu) | 
|  | 1153 | { | 
|  | 1154 | const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly(); | 
| Jim Ingham | 28eb571 | 2012-10-12 17:34:26 +0000 | [diff] [blame] | 1155 | if (die) | 
|  | 1156 | { | 
|  | 1157 | const uint32_t language = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0); | 
|  | 1158 | if (language) | 
|  | 1159 | return (lldb::LanguageType)language; | 
|  | 1160 | } | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1161 | } | 
|  | 1162 | return eLanguageTypeUnknown; | 
|  | 1163 | } | 
|  | 1164 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1165 | size_t | 
|  | 1166 | SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc) | 
|  | 1167 | { | 
|  | 1168 | assert (sc.comp_unit); | 
|  | 1169 | size_t functions_added = 0; | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1170 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1171 | if (dwarf_cu) | 
|  | 1172 | { | 
|  | 1173 | DWARFDIECollection function_dies; | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1174 | 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] | 1175 | size_t func_idx; | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1176 | for (func_idx = 0; func_idx < num_functions; ++func_idx) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1177 | { | 
|  | 1178 | const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx); | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1179 | if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1180 | { | 
|  | 1181 | if (ParseCompileUnitFunction(sc, dwarf_cu, die)) | 
|  | 1182 | ++functions_added; | 
|  | 1183 | } | 
|  | 1184 | } | 
|  | 1185 | //FixupTypes(); | 
|  | 1186 | } | 
|  | 1187 | return functions_added; | 
|  | 1188 | } | 
|  | 1189 |  | 
|  | 1190 | bool | 
|  | 1191 | SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files) | 
|  | 1192 | { | 
|  | 1193 | assert (sc.comp_unit); | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1194 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); | 
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1195 | if (dwarf_cu) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1196 | { | 
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1197 | const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1198 |  | 
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1199 | if (cu_die) | 
|  | 1200 | { | 
|  | 1201 | 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] | 1202 |  | 
|  | 1203 | // DWARF2/3 suggests the form hostname:pathname for compilation directory. | 
|  | 1204 | // Remove the host part if present. | 
|  | 1205 | cu_comp_dir = removeHostnameFromPathname(cu_comp_dir); | 
|  | 1206 |  | 
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1207 | 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] | 1208 |  | 
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1209 | // All file indexes in DWARF are one based and a file of index zero is | 
|  | 1210 | // supposed to be the compile unit itself. | 
|  | 1211 | support_files.Append (*sc.comp_unit); | 
|  | 1212 |  | 
|  | 1213 | return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files); | 
|  | 1214 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1215 | } | 
|  | 1216 | return false; | 
|  | 1217 | } | 
|  | 1218 |  | 
|  | 1219 | struct ParseDWARFLineTableCallbackInfo | 
|  | 1220 | { | 
|  | 1221 | LineTable* line_table; | 
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1222 | std::unique_ptr<LineSequence> sequence_ap; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1223 | }; | 
|  | 1224 |  | 
|  | 1225 | //---------------------------------------------------------------------- | 
|  | 1226 | // ParseStatementTableCallback | 
|  | 1227 | //---------------------------------------------------------------------- | 
|  | 1228 | static void | 
|  | 1229 | ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData) | 
|  | 1230 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1231 | if (state.row == DWARFDebugLine::State::StartParsingLineTable) | 
|  | 1232 | { | 
|  | 1233 | // Just started parsing the line table | 
|  | 1234 | } | 
|  | 1235 | else if (state.row == DWARFDebugLine::State::DoneParsingLineTable) | 
|  | 1236 | { | 
|  | 1237 | // Done parsing line table, nothing to do for the cleanup | 
|  | 1238 | } | 
|  | 1239 | else | 
|  | 1240 | { | 
|  | 1241 | ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData; | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1242 | LineTable* line_table = info->line_table; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1243 |  | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1244 | // If this is our first time here, we need to create a | 
|  | 1245 | // sequence container. | 
|  | 1246 | if (!info->sequence_ap.get()) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1247 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1248 | info->sequence_ap.reset(line_table->CreateLineSequenceContainer()); | 
|  | 1249 | assert(info->sequence_ap.get()); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1250 | } | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1251 | line_table->AppendLineEntryToSequence (info->sequence_ap.get(), | 
|  | 1252 | state.address, | 
|  | 1253 | state.line, | 
|  | 1254 | state.column, | 
|  | 1255 | state.file, | 
|  | 1256 | state.is_stmt, | 
|  | 1257 | state.basic_block, | 
|  | 1258 | state.prologue_end, | 
|  | 1259 | state.epilogue_begin, | 
|  | 1260 | state.end_sequence); | 
|  | 1261 | if (state.end_sequence) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1262 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1263 | // First, put the current sequence into the line table. | 
|  | 1264 | line_table->InsertSequence(info->sequence_ap.get()); | 
|  | 1265 | // Then, empty it to prepare for the next sequence. | 
|  | 1266 | info->sequence_ap->Clear(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1267 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1268 | } | 
|  | 1269 | } | 
|  | 1270 |  | 
|  | 1271 | bool | 
|  | 1272 | SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc) | 
|  | 1273 | { | 
|  | 1274 | assert (sc.comp_unit); | 
|  | 1275 | if (sc.comp_unit->GetLineTable() != NULL) | 
|  | 1276 | return true; | 
|  | 1277 |  | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1278 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1279 | if (dwarf_cu) | 
|  | 1280 | { | 
|  | 1281 | const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly(); | 
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1282 | if (dwarf_cu_die) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1283 | { | 
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1284 | const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET); | 
|  | 1285 | if (cu_line_offset != DW_INVALID_OFFSET) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1286 | { | 
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1287 | std::unique_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit)); | 
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1288 | if (line_table_ap.get()) | 
|  | 1289 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1290 | ParseDWARFLineTableCallbackInfo info; | 
|  | 1291 | info.line_table = line_table_ap.get(); | 
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1292 | lldb::offset_t offset = cu_line_offset; | 
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1293 | DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info); | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1294 | if (m_debug_map_symfile) | 
|  | 1295 | { | 
|  | 1296 | // We have an object file that has a line table with addresses | 
|  | 1297 | // that are not linked. We need to link the line table and convert | 
|  | 1298 | // the addresses that are relative to the .o file into addresses | 
|  | 1299 | // for the main executable. | 
|  | 1300 | sc.comp_unit->SetLineTable (m_debug_map_symfile->LinkOSOLineTable (this, line_table_ap.get())); | 
|  | 1301 | } | 
|  | 1302 | else | 
|  | 1303 | { | 
|  | 1304 | sc.comp_unit->SetLineTable(line_table_ap.release()); | 
|  | 1305 | return true; | 
|  | 1306 | } | 
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1307 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1308 | } | 
|  | 1309 | } | 
|  | 1310 | } | 
|  | 1311 | return false; | 
|  | 1312 | } | 
|  | 1313 |  | 
|  | 1314 | size_t | 
|  | 1315 | SymbolFileDWARF::ParseFunctionBlocks | 
|  | 1316 | ( | 
|  | 1317 | const SymbolContext& sc, | 
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1318 | Block *parent_block, | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1319 | DWARFCompileUnit* dwarf_cu, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1320 | const DWARFDebugInfoEntry *die, | 
|  | 1321 | addr_t subprogram_low_pc, | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1322 | uint32_t depth | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1323 | ) | 
|  | 1324 | { | 
|  | 1325 | size_t blocks_added = 0; | 
|  | 1326 | while (die != NULL) | 
|  | 1327 | { | 
|  | 1328 | dw_tag_t tag = die->Tag(); | 
|  | 1329 |  | 
|  | 1330 | switch (tag) | 
|  | 1331 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1332 | case DW_TAG_inlined_subroutine: | 
| Greg Clayton | b4d3733 | 2011-08-12 16:22:48 +0000 | [diff] [blame] | 1333 | case DW_TAG_subprogram: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1334 | case DW_TAG_lexical_block: | 
|  | 1335 | { | 
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1336 | Block *block = NULL; | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1337 | if (tag == DW_TAG_subprogram) | 
|  | 1338 | { | 
|  | 1339 | // Skip any DW_TAG_subprogram DIEs that are inside | 
|  | 1340 | // of a normal or inlined functions. These will be | 
|  | 1341 | // parsed on their own as separate entities. | 
|  | 1342 |  | 
|  | 1343 | if (depth > 0) | 
|  | 1344 | break; | 
|  | 1345 |  | 
|  | 1346 | block = parent_block; | 
|  | 1347 | } | 
|  | 1348 | else | 
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1349 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1350 | BlockSP block_sp(new Block (MakeUserID(die->GetOffset()))); | 
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1351 | parent_block->AddChild(block_sp); | 
|  | 1352 | block = block_sp.get(); | 
|  | 1353 | } | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1354 | DWARFDebugRanges::RangeList ranges; | 
|  | 1355 | const char *name = NULL; | 
|  | 1356 | const char *mangled_name = NULL; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1357 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1358 | int decl_file = 0; | 
|  | 1359 | int decl_line = 0; | 
|  | 1360 | int decl_column = 0; | 
|  | 1361 | int call_file = 0; | 
|  | 1362 | int call_line = 0; | 
|  | 1363 | int call_column = 0; | 
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1364 | if (die->GetDIENamesAndRanges (this, | 
|  | 1365 | dwarf_cu, | 
|  | 1366 | name, | 
|  | 1367 | mangled_name, | 
|  | 1368 | ranges, | 
|  | 1369 | decl_file, decl_line, decl_column, | 
|  | 1370 | call_file, call_line, call_column)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1371 | { | 
|  | 1372 | if (tag == DW_TAG_subprogram) | 
|  | 1373 | { | 
|  | 1374 | assert (subprogram_low_pc == LLDB_INVALID_ADDRESS); | 
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1375 | subprogram_low_pc = ranges.GetMinRangeBase(0); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1376 | } | 
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1377 | else if (tag == DW_TAG_inlined_subroutine) | 
|  | 1378 | { | 
|  | 1379 | // We get called here for inlined subroutines in two ways. | 
|  | 1380 | // The first time is when we are making the Function object | 
|  | 1381 | // for this inlined concrete instance.  Since we're creating a top level block at | 
|  | 1382 | // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS.  So we need to | 
|  | 1383 | // adjust the containing address. | 
|  | 1384 | // The second time is when we are parsing the blocks inside the function that contains | 
|  | 1385 | // the inlined concrete instance.  Since these will be blocks inside the containing "real" | 
|  | 1386 | // function the offset will be for that function. | 
|  | 1387 | if (subprogram_low_pc == LLDB_INVALID_ADDRESS) | 
|  | 1388 | { | 
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1389 | subprogram_low_pc = ranges.GetMinRangeBase(0); | 
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1390 | } | 
|  | 1391 | } | 
| Greg Clayton | 103f309 | 2015-01-15 03:04:37 +0000 | [diff] [blame] | 1392 |  | 
|  | 1393 | const size_t num_ranges = ranges.GetSize(); | 
|  | 1394 | for (size_t i = 0; i<num_ranges; ++i) | 
|  | 1395 | { | 
|  | 1396 | const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i); | 
|  | 1397 | const addr_t range_base = range.GetRangeBase(); | 
|  | 1398 | if (range_base >= subprogram_low_pc) | 
|  | 1399 | block->AddRange(Block::Range (range_base - subprogram_low_pc, range.GetByteSize())); | 
|  | 1400 | else | 
|  | 1401 | { | 
|  | 1402 | GetObjectFile()->GetModule()->ReportError ("0x%8.8" PRIx64 ": adding range [0x%" PRIx64 "-0x%" PRIx64 ") which has a base that is less than the function's low PC 0x%" PRIx64 ". Please file a bug and attach the file at the start of this error message", | 
|  | 1403 | block->GetID(), | 
|  | 1404 | range_base, | 
|  | 1405 | range.GetRangeEnd(), | 
|  | 1406 | subprogram_low_pc); | 
|  | 1407 | } | 
|  | 1408 | } | 
|  | 1409 | block->FinalizeRanges (); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1410 |  | 
|  | 1411 | if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL)) | 
|  | 1412 | { | 
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1413 | std::unique_ptr<Declaration> decl_ap; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1414 | if (decl_file != 0 || decl_line != 0 || decl_column != 0) | 
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1415 | decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), | 
|  | 1416 | decl_line, decl_column)); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1417 |  | 
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1418 | std::unique_ptr<Declaration> call_ap; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1419 | if (call_file != 0 || call_line != 0 || call_column != 0) | 
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1420 | call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file), | 
|  | 1421 | call_line, call_column)); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1422 |  | 
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1423 | block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get()); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1424 | } | 
|  | 1425 |  | 
|  | 1426 | ++blocks_added; | 
|  | 1427 |  | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1428 | if (die->HasChildren()) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1429 | { | 
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1430 | blocks_added += ParseFunctionBlocks (sc, | 
|  | 1431 | block, | 
|  | 1432 | dwarf_cu, | 
|  | 1433 | die->GetFirstChild(), | 
|  | 1434 | subprogram_low_pc, | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1435 | depth + 1); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1436 | } | 
|  | 1437 | } | 
|  | 1438 | } | 
|  | 1439 | break; | 
|  | 1440 | default: | 
|  | 1441 | break; | 
|  | 1442 | } | 
|  | 1443 |  | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1444 | // Only parse siblings of the block if we are not at depth zero. A depth | 
|  | 1445 | // of zero indicates we are currently parsing the top level | 
|  | 1446 | // DW_TAG_subprogram DIE | 
|  | 1447 |  | 
|  | 1448 | if (depth == 0) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1449 | die = NULL; | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1450 | else | 
|  | 1451 | die = die->GetSibling(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1452 | } | 
|  | 1453 | return blocks_added; | 
|  | 1454 | } | 
|  | 1455 |  | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1456 | bool | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1457 | SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu, | 
|  | 1458 | const DWARFDebugInfoEntry *die, | 
|  | 1459 | ClangASTContext::TemplateParameterInfos &template_param_infos) | 
|  | 1460 | { | 
|  | 1461 | const dw_tag_t tag = die->Tag(); | 
|  | 1462 |  | 
|  | 1463 | switch (tag) | 
|  | 1464 | { | 
|  | 1465 | case DW_TAG_template_type_parameter: | 
|  | 1466 | case DW_TAG_template_value_parameter: | 
|  | 1467 | { | 
| Todd Fiala | ee8bfc6 | 2014-09-11 17:29:12 +0000 | [diff] [blame] | 1468 | 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] | 1469 |  | 
|  | 1470 | DWARFDebugInfoEntry::Attributes attributes; | 
|  | 1471 | const size_t num_attributes = die->GetAttributes (this, | 
|  | 1472 | dwarf_cu, | 
|  | 1473 | fixed_form_sizes, | 
|  | 1474 | attributes); | 
|  | 1475 | const char *name = NULL; | 
|  | 1476 | Type *lldb_type = NULL; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1477 | ClangASTType clang_type; | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1478 | uint64_t uval64 = 0; | 
|  | 1479 | bool uval64_valid = false; | 
|  | 1480 | if (num_attributes > 0) | 
|  | 1481 | { | 
|  | 1482 | DWARFFormValue form_value; | 
|  | 1483 | for (size_t i=0; i<num_attributes; ++i) | 
|  | 1484 | { | 
|  | 1485 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 1486 |  | 
|  | 1487 | switch (attr) | 
|  | 1488 | { | 
|  | 1489 | case DW_AT_name: | 
|  | 1490 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 1491 | name = form_value.AsCString(&get_debug_str_data()); | 
|  | 1492 | break; | 
|  | 1493 |  | 
|  | 1494 | case DW_AT_type: | 
|  | 1495 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 1496 | { | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 1497 | const dw_offset_t type_die_offset = form_value.Reference(); | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1498 | lldb_type = ResolveTypeUID(type_die_offset); | 
|  | 1499 | if (lldb_type) | 
|  | 1500 | clang_type = lldb_type->GetClangForwardType(); | 
|  | 1501 | } | 
|  | 1502 | break; | 
|  | 1503 |  | 
|  | 1504 | case DW_AT_const_value: | 
|  | 1505 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 1506 | { | 
|  | 1507 | uval64_valid = true; | 
|  | 1508 | uval64 = form_value.Unsigned(); | 
|  | 1509 | } | 
|  | 1510 | break; | 
|  | 1511 | default: | 
|  | 1512 | break; | 
|  | 1513 | } | 
|  | 1514 | } | 
|  | 1515 |  | 
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1516 | clang::ASTContext *ast = GetClangASTContext().getASTContext(); | 
|  | 1517 | if (!clang_type) | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1518 | clang_type = GetClangASTContext().GetBasicType(eBasicTypeVoid); | 
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1519 |  | 
|  | 1520 | if (clang_type) | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1521 | { | 
|  | 1522 | bool is_signed = false; | 
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1523 | if (name && name[0]) | 
|  | 1524 | template_param_infos.names.push_back(name); | 
|  | 1525 | else | 
|  | 1526 | template_param_infos.names.push_back(NULL); | 
|  | 1527 |  | 
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1528 | if (tag == DW_TAG_template_value_parameter && | 
|  | 1529 | lldb_type != NULL && | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1530 | clang_type.IsIntegerType (is_signed) && | 
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1531 | uval64_valid) | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1532 | { | 
|  | 1533 | llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed); | 
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1534 | template_param_infos.args.push_back (clang::TemplateArgument (*ast, | 
| Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1535 | llvm::APSInt(apint), | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1536 | clang_type.GetQualType())); | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1537 | } | 
|  | 1538 | else | 
|  | 1539 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1540 | template_param_infos.args.push_back (clang::TemplateArgument (clang_type.GetQualType())); | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1541 | } | 
|  | 1542 | } | 
|  | 1543 | else | 
|  | 1544 | { | 
|  | 1545 | return false; | 
|  | 1546 | } | 
|  | 1547 |  | 
|  | 1548 | } | 
|  | 1549 | } | 
|  | 1550 | return true; | 
|  | 1551 |  | 
|  | 1552 | default: | 
|  | 1553 | break; | 
|  | 1554 | } | 
|  | 1555 | return false; | 
|  | 1556 | } | 
|  | 1557 |  | 
|  | 1558 | bool | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1559 | SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu, | 
|  | 1560 | const DWARFDebugInfoEntry *parent_die, | 
|  | 1561 | ClangASTContext::TemplateParameterInfos &template_param_infos) | 
|  | 1562 | { | 
|  | 1563 |  | 
|  | 1564 | if (parent_die == NULL) | 
| Filipe Cabecinhas | 52008c6 | 2012-05-23 16:24:11 +0000 | [diff] [blame] | 1565 | return false; | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1566 |  | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1567 | Args template_parameter_names; | 
|  | 1568 | for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); | 
|  | 1569 | die != NULL; | 
|  | 1570 | die = die->GetSibling()) | 
|  | 1571 | { | 
|  | 1572 | const dw_tag_t tag = die->Tag(); | 
|  | 1573 |  | 
|  | 1574 | switch (tag) | 
|  | 1575 | { | 
|  | 1576 | case DW_TAG_template_type_parameter: | 
|  | 1577 | case DW_TAG_template_value_parameter: | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1578 | ParseTemplateDIE (dwarf_cu, die, template_param_infos); | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1579 | break; | 
|  | 1580 |  | 
|  | 1581 | default: | 
|  | 1582 | break; | 
|  | 1583 | } | 
|  | 1584 | } | 
|  | 1585 | if (template_param_infos.args.empty()) | 
|  | 1586 | return false; | 
|  | 1587 | return template_param_infos.args.size() == template_param_infos.names.size(); | 
|  | 1588 | } | 
|  | 1589 |  | 
|  | 1590 | clang::ClassTemplateDecl * | 
|  | 1591 | SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx, | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1592 | lldb::AccessType access_type, | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1593 | const char *parent_name, | 
|  | 1594 | int tag_decl_kind, | 
|  | 1595 | const ClangASTContext::TemplateParameterInfos &template_param_infos) | 
|  | 1596 | { | 
|  | 1597 | if (template_param_infos.IsValid()) | 
|  | 1598 | { | 
|  | 1599 | std::string template_basename(parent_name); | 
|  | 1600 | template_basename.erase (template_basename.find('<')); | 
|  | 1601 | ClangASTContext &ast = GetClangASTContext(); | 
|  | 1602 |  | 
|  | 1603 | return ast.CreateClassTemplateDecl (decl_ctx, | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1604 | access_type, | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1605 | template_basename.c_str(), | 
|  | 1606 | tag_decl_kind, | 
|  | 1607 | template_param_infos); | 
|  | 1608 | } | 
|  | 1609 | return NULL; | 
|  | 1610 | } | 
|  | 1611 |  | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1612 | class SymbolFileDWARF::DelayedAddObjCClassProperty | 
|  | 1613 | { | 
|  | 1614 | public: | 
|  | 1615 | DelayedAddObjCClassProperty | 
|  | 1616 | ( | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1617 | const ClangASTType     &class_opaque_type, | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1618 | const char             *property_name, | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1619 | 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] | 1620 | clang::ObjCIvarDecl    *ivar_decl, | 
|  | 1621 | const char             *property_setter_name, | 
|  | 1622 | const char             *property_getter_name, | 
|  | 1623 | uint32_t                property_attributes, | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1624 | const ClangASTMetadata *metadata | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1625 | ) : | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1626 | m_class_opaque_type     (class_opaque_type), | 
|  | 1627 | m_property_name         (property_name), | 
|  | 1628 | m_property_opaque_type  (property_opaque_type), | 
|  | 1629 | m_ivar_decl             (ivar_decl), | 
|  | 1630 | m_property_setter_name  (property_setter_name), | 
|  | 1631 | m_property_getter_name  (property_getter_name), | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1632 | m_property_attributes   (property_attributes) | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1633 | { | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1634 | if (metadata != NULL) | 
|  | 1635 | { | 
|  | 1636 | m_metadata_ap.reset(new ClangASTMetadata()); | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1637 | *m_metadata_ap = *metadata; | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1638 | } | 
|  | 1639 | } | 
|  | 1640 |  | 
|  | 1641 | DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs) | 
|  | 1642 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1643 | *this = rhs; | 
| Daniel Malea | d4c5be6 | 2012-11-12 21:02:14 +0000 | [diff] [blame] | 1644 | } | 
|  | 1645 |  | 
|  | 1646 | DelayedAddObjCClassProperty& operator= (const DelayedAddObjCClassProperty &rhs) | 
|  | 1647 | { | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1648 | m_class_opaque_type    = rhs.m_class_opaque_type; | 
|  | 1649 | m_property_name        = rhs.m_property_name; | 
|  | 1650 | m_property_opaque_type = rhs.m_property_opaque_type; | 
|  | 1651 | m_ivar_decl            = rhs.m_ivar_decl; | 
|  | 1652 | m_property_setter_name = rhs.m_property_setter_name; | 
|  | 1653 | m_property_getter_name = rhs.m_property_getter_name; | 
|  | 1654 | m_property_attributes  = rhs.m_property_attributes; | 
|  | 1655 |  | 
|  | 1656 | if (rhs.m_metadata_ap.get()) | 
|  | 1657 | { | 
|  | 1658 | m_metadata_ap.reset (new ClangASTMetadata()); | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1659 | *m_metadata_ap = *rhs.m_metadata_ap; | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1660 | } | 
| Daniel Malea | d4c5be6 | 2012-11-12 21:02:14 +0000 | [diff] [blame] | 1661 | return *this; | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1662 | } | 
|  | 1663 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1664 | bool | 
|  | 1665 | Finalize() | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1666 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1667 | return m_class_opaque_type.AddObjCClassProperty (m_property_name, | 
|  | 1668 | m_property_opaque_type, | 
|  | 1669 | m_ivar_decl, | 
|  | 1670 | m_property_setter_name, | 
|  | 1671 | m_property_getter_name, | 
|  | 1672 | m_property_attributes, | 
|  | 1673 | m_metadata_ap.get()); | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1674 | } | 
|  | 1675 | private: | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1676 | ClangASTType            m_class_opaque_type; | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1677 | const char             *m_property_name; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1678 | ClangASTType            m_property_opaque_type; | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1679 | clang::ObjCIvarDecl    *m_ivar_decl; | 
|  | 1680 | const char             *m_property_setter_name; | 
|  | 1681 | const char             *m_property_getter_name; | 
|  | 1682 | uint32_t                m_property_attributes; | 
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1683 | std::unique_ptr<ClangASTMetadata> m_metadata_ap; | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1684 | }; | 
|  | 1685 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1686 | struct BitfieldInfo | 
|  | 1687 | { | 
|  | 1688 | uint64_t bit_size; | 
|  | 1689 | uint64_t bit_offset; | 
|  | 1690 |  | 
|  | 1691 | BitfieldInfo () : | 
|  | 1692 | bit_size (LLDB_INVALID_ADDRESS), | 
|  | 1693 | bit_offset (LLDB_INVALID_ADDRESS) | 
|  | 1694 | { | 
|  | 1695 | } | 
|  | 1696 |  | 
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 1697 | void | 
|  | 1698 | Clear() | 
|  | 1699 | { | 
|  | 1700 | bit_size = LLDB_INVALID_ADDRESS; | 
|  | 1701 | bit_offset = LLDB_INVALID_ADDRESS; | 
|  | 1702 | } | 
|  | 1703 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1704 | bool IsValid () | 
|  | 1705 | { | 
|  | 1706 | return (bit_size != LLDB_INVALID_ADDRESS) && | 
|  | 1707 | (bit_offset != LLDB_INVALID_ADDRESS); | 
|  | 1708 | } | 
|  | 1709 | }; | 
|  | 1710 |  | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1711 |  | 
|  | 1712 | bool | 
|  | 1713 | SymbolFileDWARF::ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu, | 
|  | 1714 | const DWARFDebugInfoEntry *parent_die) | 
|  | 1715 | { | 
|  | 1716 | if (parent_die) | 
|  | 1717 | { | 
|  | 1718 | for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) | 
|  | 1719 | { | 
|  | 1720 | dw_tag_t tag = die->Tag(); | 
|  | 1721 | bool check_virtuality = false; | 
|  | 1722 | switch (tag) | 
|  | 1723 | { | 
|  | 1724 | case DW_TAG_inheritance: | 
|  | 1725 | case DW_TAG_subprogram: | 
|  | 1726 | check_virtuality = true; | 
|  | 1727 | break; | 
|  | 1728 | default: | 
|  | 1729 | break; | 
|  | 1730 | } | 
|  | 1731 | if (check_virtuality) | 
|  | 1732 | { | 
|  | 1733 | if (die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_virtuality, 0) != 0) | 
|  | 1734 | return true; | 
|  | 1735 | } | 
|  | 1736 | } | 
|  | 1737 | } | 
|  | 1738 | return false; | 
|  | 1739 | } | 
|  | 1740 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1741 | size_t | 
|  | 1742 | SymbolFileDWARF::ParseChildMembers | 
|  | 1743 | ( | 
|  | 1744 | const SymbolContext& sc, | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1745 | DWARFCompileUnit* dwarf_cu, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1746 | const DWARFDebugInfoEntry *parent_die, | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1747 | ClangASTType &class_clang_type, | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1748 | const LanguageType class_language, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1749 | std::vector<clang::CXXBaseSpecifier *>& base_classes, | 
|  | 1750 | std::vector<int>& member_accessibilities, | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1751 | DWARFDIECollection& member_function_dies, | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1752 | DelayedPropertyList& delayed_properties, | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1753 | AccessType& default_accessibility, | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1754 | bool &is_a_class, | 
|  | 1755 | LayoutInfo &layout_info | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1756 | ) | 
|  | 1757 | { | 
|  | 1758 | if (parent_die == NULL) | 
|  | 1759 | return 0; | 
|  | 1760 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1761 | size_t count = 0; | 
|  | 1762 | const DWARFDebugInfoEntry *die; | 
| Todd Fiala | ee8bfc6 | 2014-09-11 17:29:12 +0000 | [diff] [blame] | 1763 | 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] | 1764 | uint32_t member_idx = 0; | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1765 | BitfieldInfo last_field_info; | 
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 1766 | ModuleSP module = GetObjectFile()->GetModule(); | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 1767 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1768 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) | 
|  | 1769 | { | 
|  | 1770 | dw_tag_t tag = die->Tag(); | 
|  | 1771 |  | 
|  | 1772 | switch (tag) | 
|  | 1773 | { | 
|  | 1774 | case DW_TAG_member: | 
| Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1775 | case DW_TAG_APPLE_property: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1776 | { | 
|  | 1777 | DWARFDebugInfoEntry::Attributes attributes; | 
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1778 | const size_t num_attributes = die->GetAttributes (this, | 
|  | 1779 | dwarf_cu, | 
|  | 1780 | fixed_form_sizes, | 
|  | 1781 | attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1782 | if (num_attributes > 0) | 
|  | 1783 | { | 
|  | 1784 | Declaration decl; | 
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1785 | //DWARFExpression location; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1786 | const char *name = NULL; | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1787 | const char *prop_name = NULL; | 
|  | 1788 | const char *prop_getter_name = NULL; | 
|  | 1789 | const char *prop_setter_name = NULL; | 
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1790 | uint32_t prop_attributes = 0; | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1791 |  | 
|  | 1792 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1793 | bool is_artificial = false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1794 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1795 | AccessType accessibility = eAccessNone; | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1796 | uint32_t member_byte_offset = UINT32_MAX; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1797 | size_t byte_size = 0; | 
|  | 1798 | size_t bit_offset = 0; | 
|  | 1799 | size_t bit_size = 0; | 
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1800 | 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] | 1801 | uint32_t i; | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1802 | for (i=0; i<num_attributes && !is_artificial; ++i) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1803 | { | 
|  | 1804 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 1805 | DWARFFormValue form_value; | 
|  | 1806 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 1807 | { | 
|  | 1808 | switch (attr) | 
|  | 1809 | { | 
|  | 1810 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 1811 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 1812 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 1813 | 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] | 1814 | case DW_AT_type:        encoding_uid = form_value.Reference(); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1815 | case DW_AT_bit_offset:  bit_offset = form_value.Unsigned(); break; | 
|  | 1816 | case DW_AT_bit_size:    bit_size = form_value.Unsigned(); break; | 
|  | 1817 | case DW_AT_byte_size:   byte_size = form_value.Unsigned(); break; | 
|  | 1818 | case DW_AT_data_member_location: | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1819 | if (form_value.BlockData()) | 
|  | 1820 | { | 
|  | 1821 | Value initialValue(0); | 
|  | 1822 | Value memberOffset(0); | 
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 1823 | const DWARFDataExtractor& debug_info_data = get_debug_info_data(); | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1824 | uint32_t block_length = form_value.Unsigned(); | 
|  | 1825 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); | 
|  | 1826 | if (DWARFExpression::Evaluate(NULL, // ExecutionContext * | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1827 | NULL, // ClangExpressionVariableList * | 
|  | 1828 | NULL, // ClangExpressionDeclMap * | 
|  | 1829 | NULL, // RegisterContext * | 
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 1830 | module, | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1831 | debug_info_data, | 
|  | 1832 | block_offset, | 
|  | 1833 | block_length, | 
|  | 1834 | eRegisterKindDWARF, | 
|  | 1835 | &initialValue, | 
|  | 1836 | memberOffset, | 
|  | 1837 | NULL)) | 
|  | 1838 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1839 | member_byte_offset = memberOffset.ResolveValue(NULL).UInt(); | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1840 | } | 
|  | 1841 | } | 
| Ashok Thirumurthi | a4658a5 | 2013-07-30 14:58:39 +0000 | [diff] [blame] | 1842 | else | 
|  | 1843 | { | 
|  | 1844 | // With DWARF 3 and later, if the value is an integer constant, | 
|  | 1845 | // this form value is the offset in bytes from the beginning | 
|  | 1846 | // of the containing entity. | 
|  | 1847 | member_byte_offset = form_value.Unsigned(); | 
|  | 1848 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1849 | break; | 
|  | 1850 |  | 
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1851 | 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] | 1852 | case DW_AT_artificial: is_artificial = form_value.Boolean(); break; | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1853 | case DW_AT_APPLE_property_name:      prop_name = form_value.AsCString(&get_debug_str_data()); break; | 
|  | 1854 | case DW_AT_APPLE_property_getter:    prop_getter_name = form_value.AsCString(&get_debug_str_data()); break; | 
|  | 1855 | case DW_AT_APPLE_property_setter:    prop_setter_name = form_value.AsCString(&get_debug_str_data()); break; | 
|  | 1856 | case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break; | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 1857 | case DW_AT_external:                 is_external = form_value.Boolean(); break; | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1858 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1859 | default: | 
| Greg Clayton | 1b02c17 | 2012-03-14 21:00:47 +0000 | [diff] [blame] | 1860 | case DW_AT_declaration: | 
|  | 1861 | case DW_AT_description: | 
|  | 1862 | case DW_AT_mutable: | 
|  | 1863 | case DW_AT_visibility: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1864 | case DW_AT_sibling: | 
|  | 1865 | break; | 
|  | 1866 | } | 
|  | 1867 | } | 
|  | 1868 | } | 
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1869 |  | 
|  | 1870 | if (prop_name) | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1871 | { | 
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1872 | ConstString fixed_getter; | 
|  | 1873 | ConstString fixed_setter; | 
|  | 1874 |  | 
|  | 1875 | // Check if the property getter/setter were provided as full | 
|  | 1876 | // names.  We want basenames, so we extract them. | 
|  | 1877 |  | 
|  | 1878 | if (prop_getter_name && prop_getter_name[0] == '-') | 
|  | 1879 | { | 
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 1880 | ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true); | 
|  | 1881 | prop_getter_name = prop_getter_method.GetSelector().GetCString(); | 
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1882 | } | 
|  | 1883 |  | 
|  | 1884 | if (prop_setter_name && prop_setter_name[0] == '-') | 
|  | 1885 | { | 
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 1886 | ObjCLanguageRuntime::MethodName prop_setter_method(prop_setter_name, true); | 
|  | 1887 | prop_setter_name = prop_setter_method.GetSelector().GetCString(); | 
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1888 | } | 
|  | 1889 |  | 
|  | 1890 | // If the names haven't been provided, they need to be | 
|  | 1891 | // filled in. | 
|  | 1892 |  | 
|  | 1893 | if (!prop_getter_name) | 
|  | 1894 | { | 
|  | 1895 | prop_getter_name = prop_name; | 
|  | 1896 | } | 
|  | 1897 | if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly)) | 
|  | 1898 | { | 
|  | 1899 | StreamString ss; | 
|  | 1900 |  | 
|  | 1901 | ss.Printf("set%c%s:", | 
|  | 1902 | toupper(prop_name[0]), | 
|  | 1903 | &prop_name[1]); | 
|  | 1904 |  | 
|  | 1905 | fixed_setter.SetCString(ss.GetData()); | 
|  | 1906 | prop_setter_name = fixed_setter.GetCString(); | 
|  | 1907 | } | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1908 | } | 
|  | 1909 |  | 
|  | 1910 | // Clang has a DWARF generation bug where sometimes it | 
| Greg Clayton | 4495393 | 2011-10-25 01:25:35 +0000 | [diff] [blame] | 1911 | // represents fields that are references with bad byte size | 
|  | 1912 | // and bit size/offset information such as: | 
|  | 1913 | // | 
|  | 1914 | //  DW_AT_byte_size( 0x00 ) | 
|  | 1915 | //  DW_AT_bit_size( 0x40 ) | 
|  | 1916 | //  DW_AT_bit_offset( 0xffffffffffffffc0 ) | 
|  | 1917 | // | 
|  | 1918 | // So check the bit offset to make sure it is sane, and if | 
|  | 1919 | // the values are not sane, remove them. If we don't do this | 
|  | 1920 | // then we will end up with a crash if we try to use this | 
|  | 1921 | // type in an expression when clang becomes unhappy with its | 
|  | 1922 | // recycled debug info. | 
| Sean Callanan | 5a477cf | 2010-10-30 01:56:10 +0000 | [diff] [blame] | 1923 |  | 
| Greg Clayton | 4495393 | 2011-10-25 01:25:35 +0000 | [diff] [blame] | 1924 | if (bit_offset > 128) | 
|  | 1925 | { | 
|  | 1926 | bit_size = 0; | 
|  | 1927 | bit_offset = 0; | 
|  | 1928 | } | 
|  | 1929 |  | 
|  | 1930 | // FIXME: Make Clang ignore Objective-C accessibility for expressions | 
| Sean Callanan | 5a477cf | 2010-10-30 01:56:10 +0000 | [diff] [blame] | 1931 | if (class_language == eLanguageTypeObjC || | 
|  | 1932 | class_language == eLanguageTypeObjC_plus_plus) | 
|  | 1933 | accessibility = eAccessNone; | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1934 |  | 
|  | 1935 | if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name)) | 
|  | 1936 | { | 
|  | 1937 | // Not all compilers will mark the vtable pointer | 
|  | 1938 | // member as artificial (llvm-gcc). We can't have | 
|  | 1939 | // the virtual members in our classes otherwise it | 
|  | 1940 | // throws off all child offsets since we end up | 
|  | 1941 | // having and extra pointer sized member in our | 
|  | 1942 | // class layouts. | 
|  | 1943 | is_artificial = true; | 
|  | 1944 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1945 |  | 
| Greg Clayton | 2965971 | 2013-07-12 20:08:35 +0000 | [diff] [blame] | 1946 | // Handle static members | 
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1947 | if (is_external && member_byte_offset == UINT32_MAX) | 
| Greg Clayton | 973b6c9 | 2013-04-11 16:57:51 +0000 | [diff] [blame] | 1948 | { | 
|  | 1949 | Type *var_type = ResolveTypeUID(encoding_uid); | 
|  | 1950 |  | 
|  | 1951 | if (var_type) | 
|  | 1952 | { | 
| Greg Clayton | 2965971 | 2013-07-12 20:08:35 +0000 | [diff] [blame] | 1953 | if (accessibility == eAccessNone) | 
|  | 1954 | accessibility = eAccessPublic; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1955 | class_clang_type.AddVariableToRecordType (name, | 
|  | 1956 | var_type->GetClangLayoutType(), | 
|  | 1957 | accessibility); | 
| Greg Clayton | 973b6c9 | 2013-04-11 16:57:51 +0000 | [diff] [blame] | 1958 | } | 
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1959 | break; | 
| Greg Clayton | 973b6c9 | 2013-04-11 16:57:51 +0000 | [diff] [blame] | 1960 | } | 
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1961 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1962 | if (is_artificial == false) | 
|  | 1963 | { | 
|  | 1964 | Type *member_type = ResolveTypeUID(encoding_uid); | 
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 1965 |  | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1966 | clang::FieldDecl *field_decl = NULL; | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1967 | if (tag == DW_TAG_member) | 
| Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1968 | { | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1969 | if (member_type) | 
|  | 1970 | { | 
|  | 1971 | if (accessibility == eAccessNone) | 
|  | 1972 | accessibility = default_accessibility; | 
|  | 1973 | member_accessibilities.push_back(accessibility); | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1974 |  | 
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 1975 | uint64_t field_bit_offset = (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8)); | 
|  | 1976 | if (bit_size > 0) | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1977 | { | 
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 1978 |  | 
|  | 1979 | BitfieldInfo this_field_info; | 
|  | 1980 | this_field_info.bit_offset = field_bit_offset; | 
|  | 1981 | this_field_info.bit_size = bit_size; | 
|  | 1982 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1983 | ///////////////////////////////////////////////////////////// | 
|  | 1984 | // How to locate a field given the DWARF debug information | 
|  | 1985 | // | 
|  | 1986 | // AT_byte_size indicates the size of the word in which the | 
|  | 1987 | // bit offset must be interpreted. | 
|  | 1988 | // | 
|  | 1989 | // AT_data_member_location indicates the byte offset of the | 
|  | 1990 | // word from the base address of the structure. | 
|  | 1991 | // | 
|  | 1992 | // AT_bit_offset indicates how many bits into the word | 
|  | 1993 | // (according to the host endianness) the low-order bit of | 
|  | 1994 | // the field starts.  AT_bit_offset can be negative. | 
|  | 1995 | // | 
|  | 1996 | // AT_bit_size indicates the size of the field in bits. | 
|  | 1997 | ///////////////////////////////////////////////////////////// | 
|  | 1998 |  | 
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 1999 | if (byte_size == 0) | 
|  | 2000 | byte_size = member_type->GetByteSize(); | 
|  | 2001 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2002 | if (GetObjectFile()->GetByteOrder() == eByteOrderLittle) | 
|  | 2003 | { | 
|  | 2004 | this_field_info.bit_offset += byte_size * 8; | 
|  | 2005 | this_field_info.bit_offset -= (bit_offset + bit_size); | 
|  | 2006 | } | 
|  | 2007 | else | 
|  | 2008 | { | 
|  | 2009 | this_field_info.bit_offset += bit_offset; | 
|  | 2010 | } | 
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 2011 |  | 
|  | 2012 | // Update the field bit offset we will report for layout | 
|  | 2013 | field_bit_offset = this_field_info.bit_offset; | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2014 |  | 
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 2015 | // If the member to be emitted did not start on a character boundary and there is | 
|  | 2016 | // empty space between the last field and this one, then we need to emit an | 
|  | 2017 | // anonymous member filling up the space up to its start.  There are three cases | 
|  | 2018 | // here: | 
|  | 2019 | // | 
|  | 2020 | // 1 If the previous member ended on a character boundary, then we can emit an | 
|  | 2021 | //   anonymous member starting at the most recent character boundary. | 
|  | 2022 | // | 
|  | 2023 | // 2 If the previous member did not end on a character boundary and the distance | 
|  | 2024 | //   from the end of the previous member to the current member is less than a | 
|  | 2025 | //   word width, then we can emit an anonymous member starting right after the | 
|  | 2026 | //   previous member and right before this member. | 
|  | 2027 | // | 
|  | 2028 | // 3 If the previous member did not end on a character boundary and the distance | 
|  | 2029 | //   from the end of the previous member to the current member is greater than | 
|  | 2030 | //   or equal a word width, then we act as in Case 1. | 
|  | 2031 |  | 
|  | 2032 | const uint64_t character_width = 8; | 
|  | 2033 | const uint64_t word_width = 32; | 
|  | 2034 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2035 | // Objective-C has invalid DW_AT_bit_offset values in older versions | 
| Bruce Mitchener | aaa0ba3 | 2014-07-08 18:05:41 +0000 | [diff] [blame] | 2036 | // 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] | 2037 | // if we have a new enough clang. | 
|  | 2038 | bool detect_unnamed_bitfields = true; | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2039 |  | 
| Greg Clayton | 37c36e4 | 2012-11-27 00:59:26 +0000 | [diff] [blame] | 2040 | if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus) | 
|  | 2041 | detect_unnamed_bitfields = dwarf_cu->Supports_unnamed_objc_bitfields (); | 
|  | 2042 |  | 
|  | 2043 | if (detect_unnamed_bitfields) | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2044 | { | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2045 | BitfieldInfo anon_field_info; | 
|  | 2046 |  | 
|  | 2047 | if ((this_field_info.bit_offset % character_width) != 0) // not char aligned | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2048 | { | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2049 | uint64_t last_field_end = 0; | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2050 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2051 | if (last_field_info.IsValid()) | 
|  | 2052 | 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] | 2053 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2054 | if (this_field_info.bit_offset != last_field_end) | 
|  | 2055 | { | 
|  | 2056 | if (((last_field_end % character_width) == 0) ||                    // case 1 | 
|  | 2057 | (this_field_info.bit_offset - last_field_end >= word_width))    // case 3 | 
|  | 2058 | { | 
|  | 2059 | anon_field_info.bit_size = this_field_info.bit_offset % character_width; | 
|  | 2060 | anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size; | 
|  | 2061 | } | 
|  | 2062 | else                                                                // case 2 | 
|  | 2063 | { | 
|  | 2064 | anon_field_info.bit_size = this_field_info.bit_offset - last_field_end; | 
|  | 2065 | anon_field_info.bit_offset = last_field_end; | 
|  | 2066 | } | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2067 | } | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2068 | } | 
|  | 2069 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2070 | if (anon_field_info.IsValid()) | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2071 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2072 | clang::FieldDecl *unnamed_bitfield_decl = class_clang_type.AddFieldToRecordType (NULL, | 
|  | 2073 | GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width), | 
|  | 2074 | accessibility, | 
|  | 2075 | anon_field_info.bit_size); | 
| Zachary Turner | 504f38d | 2015-03-24 16:24:50 +0000 | [diff] [blame] | 2076 |  | 
| Zachary Turner | a98fac2 | 2015-03-24 18:56:08 +0000 | [diff] [blame] | 2077 | layout_info.field_offsets.insert( | 
| Zachary Turner | 504f38d | 2015-03-24 16:24:50 +0000 | [diff] [blame] | 2078 | std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset)); | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2079 | } | 
|  | 2080 | } | 
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 2081 | last_field_info = this_field_info; | 
|  | 2082 | } | 
|  | 2083 | else | 
|  | 2084 | { | 
|  | 2085 | last_field_info.Clear(); | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2086 | } | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 2087 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2088 | ClangASTType member_clang_type = member_type->GetClangLayoutType(); | 
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 2089 |  | 
|  | 2090 | { | 
|  | 2091 | // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>). | 
|  | 2092 | // If the current field is at the end of the structure, then there is definitely no room for extra | 
|  | 2093 | // elements and we override the type to array[0]. | 
|  | 2094 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2095 | ClangASTType member_array_element_type; | 
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 2096 | uint64_t member_array_size; | 
|  | 2097 | bool member_array_is_incomplete; | 
|  | 2098 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2099 | if (member_clang_type.IsArrayType(&member_array_element_type, | 
|  | 2100 | &member_array_size, | 
|  | 2101 | &member_array_is_incomplete) && | 
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 2102 | !member_array_is_incomplete) | 
|  | 2103 | { | 
|  | 2104 | uint64_t parent_byte_size = parent_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, UINT64_MAX); | 
|  | 2105 |  | 
|  | 2106 | if (member_byte_offset >= parent_byte_size) | 
|  | 2107 | { | 
|  | 2108 | if (member_array_size != 1) | 
|  | 2109 | { | 
|  | 2110 | 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, | 
|  | 2111 | MakeUserID(die->GetOffset()), | 
|  | 2112 | name, | 
|  | 2113 | encoding_uid, | 
|  | 2114 | MakeUserID(parent_die->GetOffset())); | 
|  | 2115 | } | 
|  | 2116 |  | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 2117 | member_clang_type = GetClangASTContext().CreateArrayType(member_array_element_type, 0, false); | 
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 2118 | } | 
|  | 2119 | } | 
|  | 2120 | } | 
|  | 2121 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2122 | field_decl = class_clang_type.AddFieldToRecordType (name, | 
|  | 2123 | member_clang_type, | 
|  | 2124 | accessibility, | 
|  | 2125 | bit_size); | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2126 |  | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 2127 | GetClangASTContext().SetMetadataAsUserID (field_decl, MakeUserID(die->GetOffset())); | 
| Greg Clayton | 78f4d95 | 2013-12-11 23:10:39 +0000 | [diff] [blame] | 2128 |  | 
| Zachary Turner | a98fac2 | 2015-03-24 18:56:08 +0000 | [diff] [blame] | 2129 | layout_info.field_offsets.insert(std::make_pair(field_decl, field_bit_offset)); | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2130 | } | 
|  | 2131 | else | 
|  | 2132 | { | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 2133 | if (name) | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2134 | 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] | 2135 | MakeUserID(die->GetOffset()), | 
|  | 2136 | name, | 
|  | 2137 | encoding_uid); | 
|  | 2138 | else | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2139 | 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] | 2140 | MakeUserID(die->GetOffset()), | 
|  | 2141 | encoding_uid); | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2142 | } | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2143 | } | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 2144 |  | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2145 | if (prop_name != NULL) | 
|  | 2146 | { | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 2147 | clang::ObjCIvarDecl *ivar_decl = NULL; | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2148 |  | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 2149 | if (field_decl) | 
|  | 2150 | { | 
|  | 2151 | ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl); | 
|  | 2152 | assert (ivar_decl != NULL); | 
|  | 2153 | } | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2154 |  | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 2155 | ClangASTMetadata metadata; | 
|  | 2156 | metadata.SetUserID (MakeUserID(die->GetOffset())); | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2157 | delayed_properties.push_back(DelayedAddObjCClassProperty(class_clang_type, | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2158 | prop_name, | 
|  | 2159 | member_type->GetClangLayoutType(), | 
|  | 2160 | ivar_decl, | 
|  | 2161 | prop_setter_name, | 
|  | 2162 | prop_getter_name, | 
|  | 2163 | prop_attributes, | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 2164 | &metadata)); | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2165 |  | 
| Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 2166 | if (ivar_decl) | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 2167 | GetClangASTContext().SetMetadataAsUserID (ivar_decl, MakeUserID(die->GetOffset())); | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2168 | } | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2169 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2170 | } | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2171 | ++member_idx; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2172 | } | 
|  | 2173 | break; | 
|  | 2174 |  | 
|  | 2175 | case DW_TAG_subprogram: | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2176 | // Let the type parsing code handle this one for us. | 
|  | 2177 | member_function_dies.Append (die); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2178 | break; | 
|  | 2179 |  | 
|  | 2180 | case DW_TAG_inheritance: | 
|  | 2181 | { | 
|  | 2182 | is_a_class = true; | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 2183 | if (default_accessibility == eAccessNone) | 
|  | 2184 | default_accessibility = eAccessPrivate; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2185 | // TODO: implement DW_TAG_inheritance type parsing | 
|  | 2186 | DWARFDebugInfoEntry::Attributes attributes; | 
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 2187 | const size_t num_attributes = die->GetAttributes (this, | 
|  | 2188 | dwarf_cu, | 
|  | 2189 | fixed_form_sizes, | 
|  | 2190 | attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2191 | if (num_attributes > 0) | 
|  | 2192 | { | 
|  | 2193 | Declaration decl; | 
|  | 2194 | DWARFExpression location; | 
|  | 2195 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 2196 | AccessType accessibility = default_accessibility; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2197 | bool is_virtual = false; | 
|  | 2198 | bool is_base_of_class = true; | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2199 | off_t member_byte_offset = 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2200 | uint32_t i; | 
|  | 2201 | for (i=0; i<num_attributes; ++i) | 
|  | 2202 | { | 
|  | 2203 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 2204 | DWARFFormValue form_value; | 
|  | 2205 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 2206 | { | 
|  | 2207 | switch (attr) | 
|  | 2208 | { | 
|  | 2209 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 2210 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 2211 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 2212 | case DW_AT_type:        encoding_uid = form_value.Reference(); break; | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2213 | case DW_AT_data_member_location: | 
|  | 2214 | if (form_value.BlockData()) | 
|  | 2215 | { | 
|  | 2216 | Value initialValue(0); | 
|  | 2217 | Value memberOffset(0); | 
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 2218 | const DWARFDataExtractor& debug_info_data = get_debug_info_data(); | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2219 | uint32_t block_length = form_value.Unsigned(); | 
|  | 2220 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); | 
|  | 2221 | if (DWARFExpression::Evaluate (NULL, | 
|  | 2222 | NULL, | 
|  | 2223 | NULL, | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2224 | NULL, | 
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 2225 | module, | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2226 | debug_info_data, | 
|  | 2227 | block_offset, | 
|  | 2228 | block_length, | 
|  | 2229 | eRegisterKindDWARF, | 
|  | 2230 | &initialValue, | 
|  | 2231 | memberOffset, | 
|  | 2232 | NULL)) | 
|  | 2233 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2234 | member_byte_offset = memberOffset.ResolveValue(NULL).UInt(); | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2235 | } | 
|  | 2236 | } | 
| Ashok Thirumurthi | a4658a5 | 2013-07-30 14:58:39 +0000 | [diff] [blame] | 2237 | else | 
|  | 2238 | { | 
|  | 2239 | // With DWARF 3 and later, if the value is an integer constant, | 
|  | 2240 | // this form value is the offset in bytes from the beginning | 
|  | 2241 | // of the containing entity. | 
|  | 2242 | member_byte_offset = form_value.Unsigned(); | 
|  | 2243 | } | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2244 | break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2245 |  | 
|  | 2246 | case DW_AT_accessibility: | 
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 2247 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2248 | break; | 
|  | 2249 |  | 
| Ashok Thirumurthi | a4658a5 | 2013-07-30 14:58:39 +0000 | [diff] [blame] | 2250 | case DW_AT_virtuality: | 
|  | 2251 | is_virtual = form_value.Boolean(); | 
|  | 2252 | break; | 
|  | 2253 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2254 | case DW_AT_sibling: | 
|  | 2255 | break; | 
| Ashok Thirumurthi | a4658a5 | 2013-07-30 14:58:39 +0000 | [diff] [blame] | 2256 |  | 
|  | 2257 | default: | 
|  | 2258 | break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2259 | } | 
|  | 2260 | } | 
|  | 2261 | } | 
|  | 2262 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 2263 | Type *base_class_type = ResolveTypeUID(encoding_uid); | 
|  | 2264 | assert(base_class_type); | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2265 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2266 | ClangASTType base_class_clang_type = base_class_type->GetClangFullType(); | 
| Greg Clayton | f4ecaa5 | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 2267 | assert (base_class_clang_type); | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2268 | if (class_language == eLanguageTypeObjC) | 
|  | 2269 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2270 | class_clang_type.SetObjCSuperClass(base_class_clang_type); | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2271 | } | 
|  | 2272 | else | 
|  | 2273 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2274 | base_classes.push_back (base_class_clang_type.CreateBaseClassSpecifier (accessibility, | 
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 2275 | is_virtual, | 
|  | 2276 | is_base_of_class)); | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2277 |  | 
|  | 2278 | if (is_virtual) | 
|  | 2279 | { | 
| Greg Clayton | 52694e3 | 2013-09-16 21:57:07 +0000 | [diff] [blame] | 2280 | // Do not specify any offset for virtual inheritance. The DWARF produced by clang doesn't | 
|  | 2281 | // give us a constant offset, but gives us a DWARF expressions that requires an actual object | 
|  | 2282 | // in memory. the DW_AT_data_member_location for a virtual base class looks like: | 
|  | 2283 | //      DW_AT_data_member_location( DW_OP_dup, DW_OP_deref, DW_OP_constu(0x00000018), DW_OP_minus, DW_OP_deref, DW_OP_plus ) | 
|  | 2284 | // Given this, there is really no valid response we can give to clang for virtual base | 
|  | 2285 | // class offsets, and this should eventually be removed from LayoutRecordType() in the external | 
|  | 2286 | // AST source in clang. | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2287 | } | 
|  | 2288 | else | 
|  | 2289 | { | 
| Zachary Turner | a98fac2 | 2015-03-24 18:56:08 +0000 | [diff] [blame] | 2290 | layout_info.base_offsets.insert( | 
| Zachary Turner | 504f38d | 2015-03-24 16:24:50 +0000 | [diff] [blame] | 2291 | std::make_pair(base_class_clang_type.GetAsCXXRecordDecl(), | 
|  | 2292 | clang::CharUnits::fromQuantity(member_byte_offset))); | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2293 | } | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2294 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2295 | } | 
|  | 2296 | } | 
|  | 2297 | break; | 
|  | 2298 |  | 
|  | 2299 | default: | 
|  | 2300 | break; | 
|  | 2301 | } | 
|  | 2302 | } | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2303 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2304 | return count; | 
|  | 2305 | } | 
|  | 2306 |  | 
|  | 2307 |  | 
|  | 2308 | clang::DeclContext* | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 2309 | SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2310 | { | 
|  | 2311 | DWARFDebugInfo* debug_info = DebugInfo(); | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2312 | if (debug_info && UserIDMatches(type_uid)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2313 | { | 
|  | 2314 | DWARFCompileUnitSP cu_sp; | 
|  | 2315 | const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp); | 
|  | 2316 | if (die) | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 2317 | return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL); | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 2318 | } | 
|  | 2319 | return NULL; | 
|  | 2320 | } | 
|  | 2321 |  | 
|  | 2322 | clang::DeclContext* | 
|  | 2323 | SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid) | 
|  | 2324 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2325 | if (UserIDMatches(type_uid)) | 
|  | 2326 | return GetClangDeclContextForDIEOffset (sc, type_uid); | 
|  | 2327 | return NULL; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2328 | } | 
|  | 2329 |  | 
|  | 2330 | Type* | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2331 | SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2332 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2333 | if (UserIDMatches(type_uid)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2334 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2335 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 2336 | if (debug_info) | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2337 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2338 | DWARFCompileUnitSP cu_sp; | 
|  | 2339 | const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp); | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2340 | const bool assert_not_being_parsed = true; | 
|  | 2341 | return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed); | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2342 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2343 | } | 
|  | 2344 | return NULL; | 
|  | 2345 | } | 
|  | 2346 |  | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2347 | Type* | 
|  | 2348 | SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed) | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2349 | { | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2350 | if (die != NULL) | 
|  | 2351 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2352 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2353 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2354 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2355 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'", | 
|  | 2356 | die->GetOffset(), | 
|  | 2357 | DW_TAG_value_to_name(die->Tag()), | 
|  | 2358 | die->GetName(this, cu)); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2359 |  | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2360 | // We might be coming in in the middle of a type tree (a class | 
|  | 2361 | // withing a class, an enum within a class), so parse any needed | 
|  | 2362 | // parent DIEs before we get to this one... | 
|  | 2363 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); | 
|  | 2364 | switch (decl_ctx_die->Tag()) | 
|  | 2365 | { | 
|  | 2366 | case DW_TAG_structure_type: | 
|  | 2367 | case DW_TAG_union_type: | 
|  | 2368 | case DW_TAG_class_type: | 
|  | 2369 | { | 
|  | 2370 | // Get the type, which could be a forward declaration | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2371 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2372 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2373 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x", | 
|  | 2374 | die->GetOffset(), | 
|  | 2375 | DW_TAG_value_to_name(die->Tag()), | 
|  | 2376 | die->GetName(this, cu), | 
|  | 2377 | decl_ctx_die->GetOffset()); | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2378 | // | 
|  | 2379 | //                Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed); | 
|  | 2380 | //                if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag())) | 
|  | 2381 | //                { | 
|  | 2382 | //                    if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2383 | //                        GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2384 | //                                                                  "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function", | 
|  | 2385 | //                                                                  die->GetOffset(), | 
|  | 2386 | //                                                                  DW_TAG_value_to_name(die->Tag()), | 
|  | 2387 | //                                                                  die->GetName(this, cu), | 
|  | 2388 | //                                                                  decl_ctx_die->GetOffset()); | 
|  | 2389 | //                    // Ask the type to complete itself if it already hasn't since if we | 
|  | 2390 | //                    // want a function (method or static) from a class, the class must | 
|  | 2391 | //                    // create itself and add it's own methods and class functions. | 
|  | 2392 | //                    if (parent_type) | 
|  | 2393 | //                        parent_type->GetClangFullType(); | 
|  | 2394 | //                } | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2395 | } | 
|  | 2396 | break; | 
|  | 2397 |  | 
|  | 2398 | default: | 
|  | 2399 | break; | 
|  | 2400 | } | 
|  | 2401 | return ResolveType (cu, die); | 
|  | 2402 | } | 
|  | 2403 | return NULL; | 
|  | 2404 | } | 
|  | 2405 |  | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2406 | // This function is used when SymbolFileDWARFDebugMap owns a bunch of | 
|  | 2407 | // SymbolFileDWARF objects to detect if this DWARF file is the one that | 
|  | 2408 | // can resolve a clang_type. | 
|  | 2409 | bool | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2410 | SymbolFileDWARF::HasForwardDeclForClangType (const ClangASTType &clang_type) | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2411 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2412 | ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers(); | 
|  | 2413 | const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType()); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2414 | return die != NULL; | 
|  | 2415 | } | 
|  | 2416 |  | 
|  | 2417 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2418 | bool | 
|  | 2419 | SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (ClangASTType &clang_type) | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2420 | { | 
|  | 2421 | // 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] | 2422 | ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers(); | 
|  | 2423 | 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] | 2424 | if (die == NULL) | 
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2425 | { | 
|  | 2426 | // We have already resolved this type... | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2427 | return true; | 
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2428 | } | 
|  | 2429 | // Once we start resolving this type, remove it from the forward declaration | 
|  | 2430 | // map in case anyone child members or other types require this type to get resolved. | 
|  | 2431 | // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition | 
|  | 2432 | // are done. | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2433 | 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] | 2434 |  | 
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 2435 | // Disable external storage for this type so we don't get anymore | 
|  | 2436 | // clang::ExternalASTSource queries for this type. | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2437 | clang_type.SetHasExternalStorage (false); | 
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 2438 |  | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2439 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 2440 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2441 | DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get(); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2442 | Type *type = m_die_to_type.lookup (die); | 
|  | 2443 |  | 
|  | 2444 | const dw_tag_t tag = die->Tag(); | 
|  | 2445 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2446 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION)); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2447 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2448 | GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2449 | "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...", | 
| Greg Clayton | d61c0fc | 2012-04-23 22:55:20 +0000 | [diff] [blame] | 2450 | MakeUserID(die->GetOffset()), | 
|  | 2451 | DW_TAG_value_to_name(tag), | 
|  | 2452 | type->GetName().AsCString()); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2453 | assert (clang_type); | 
|  | 2454 | DWARFDebugInfoEntry::Attributes attributes; | 
|  | 2455 |  | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2456 | switch (tag) | 
|  | 2457 | { | 
|  | 2458 | case DW_TAG_structure_type: | 
|  | 2459 | case DW_TAG_union_type: | 
|  | 2460 | case DW_TAG_class_type: | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2461 | { | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2462 | LayoutInfo layout_info; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2463 |  | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2464 | { | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2465 | if (die->HasChildren()) | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2466 | { | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2467 | LanguageType class_language = eLanguageTypeUnknown; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2468 | if (clang_type.IsObjCObjectOrInterfaceType()) | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2469 | { | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2470 | class_language = eLanguageTypeObjC; | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2471 | // For objective C we don't start the definition when | 
|  | 2472 | // the class is created. | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2473 | clang_type.StartTagDeclarationDefinition (); | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2474 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2475 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2476 | int tag_decl_kind = -1; | 
|  | 2477 | AccessType default_accessibility = eAccessNone; | 
|  | 2478 | if (tag == DW_TAG_structure_type) | 
|  | 2479 | { | 
|  | 2480 | tag_decl_kind = clang::TTK_Struct; | 
|  | 2481 | default_accessibility = eAccessPublic; | 
|  | 2482 | } | 
|  | 2483 | else if (tag == DW_TAG_union_type) | 
|  | 2484 | { | 
|  | 2485 | tag_decl_kind = clang::TTK_Union; | 
|  | 2486 | default_accessibility = eAccessPublic; | 
|  | 2487 | } | 
|  | 2488 | else if (tag == DW_TAG_class_type) | 
|  | 2489 | { | 
|  | 2490 | tag_decl_kind = clang::TTK_Class; | 
|  | 2491 | default_accessibility = eAccessPrivate; | 
|  | 2492 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2493 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2494 | SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2495 | std::vector<clang::CXXBaseSpecifier *> base_classes; | 
|  | 2496 | std::vector<int> member_accessibilities; | 
|  | 2497 | bool is_a_class = false; | 
|  | 2498 | // Parse members and base classes first | 
|  | 2499 | DWARFDIECollection member_function_dies; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2500 |  | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2501 | DelayedPropertyList delayed_properties; | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2502 | ParseChildMembers (sc, | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2503 | dwarf_cu, | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2504 | die, | 
|  | 2505 | clang_type, | 
|  | 2506 | class_language, | 
|  | 2507 | base_classes, | 
|  | 2508 | member_accessibilities, | 
|  | 2509 | member_function_dies, | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2510 | delayed_properties, | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2511 | default_accessibility, | 
|  | 2512 | is_a_class, | 
|  | 2513 | layout_info); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2514 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2515 | // Now parse any methods if there were any... | 
|  | 2516 | size_t num_functions = member_function_dies.Size(); | 
|  | 2517 | if (num_functions > 0) | 
|  | 2518 | { | 
|  | 2519 | for (size_t i=0; i<num_functions; ++i) | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2520 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2521 | ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i)); | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2522 | } | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2523 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2524 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2525 | if (class_language == eLanguageTypeObjC) | 
|  | 2526 | { | 
| Jim Ingham | fb6fc0d | 2013-09-27 20:59:37 +0000 | [diff] [blame] | 2527 | ConstString class_name (clang_type.GetTypeName()); | 
|  | 2528 | if (class_name) | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2529 | { | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2530 | DIEArray method_die_offsets; | 
|  | 2531 | if (m_using_apple_tables) | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2532 | { | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2533 | if (m_apple_objc_ap.get()) | 
| Jim Ingham | fb6fc0d | 2013-09-27 20:59:37 +0000 | [diff] [blame] | 2534 | m_apple_objc_ap->FindByName(class_name.GetCString(), method_die_offsets); | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2535 | } | 
|  | 2536 | else | 
|  | 2537 | { | 
|  | 2538 | if (!m_indexed) | 
|  | 2539 | Index (); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2540 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2541 | m_objc_class_selectors_index.Find (class_name, method_die_offsets); | 
|  | 2542 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2543 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2544 | if (!method_die_offsets.empty()) | 
|  | 2545 | { | 
|  | 2546 | DWARFDebugInfo* debug_info = DebugInfo(); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2547 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2548 | DWARFCompileUnit* method_cu = NULL; | 
|  | 2549 | const size_t num_matches = method_die_offsets.size(); | 
|  | 2550 | for (size_t i=0; i<num_matches; ++i) | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2551 | { | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2552 | const dw_offset_t die_offset = method_die_offsets[i]; | 
|  | 2553 | DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2554 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2555 | if (method_die) | 
|  | 2556 | ResolveType (method_cu, method_die); | 
|  | 2557 | else | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2558 | { | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2559 | if (m_using_apple_tables) | 
|  | 2560 | { | 
|  | 2561 | 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] | 2562 | die_offset, class_name.GetCString()); | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2563 | } | 
|  | 2564 | } | 
|  | 2565 | } | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2566 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2567 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2568 | for (DelayedPropertyList::iterator pi = delayed_properties.begin(), pe = delayed_properties.end(); | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2569 | pi != pe; | 
|  | 2570 | ++pi) | 
|  | 2571 | pi->Finalize(); | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2572 | } | 
|  | 2573 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2574 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2575 | // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we | 
|  | 2576 | // need to tell the clang type it is actually a class. | 
|  | 2577 | if (class_language != eLanguageTypeObjC) | 
|  | 2578 | { | 
|  | 2579 | if (is_a_class && tag_decl_kind != clang::TTK_Class) | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2580 | clang_type.SetTagTypeKind (clang::TTK_Class); | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2581 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2582 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2583 | // Since DW_TAG_structure_type gets used for both classes | 
|  | 2584 | // and structures, we may need to set any DW_TAG_member | 
|  | 2585 | // fields to have a "private" access if none was specified. | 
|  | 2586 | // When we parsed the child members we tracked that actual | 
|  | 2587 | // accessibility value for each DW_TAG_member in the | 
|  | 2588 | // "member_accessibilities" array. If the value for the | 
|  | 2589 | // member is zero, then it was set to the "default_accessibility" | 
|  | 2590 | // which for structs was "public". Below we correct this | 
|  | 2591 | // by setting any fields to "private" that weren't correctly | 
|  | 2592 | // set. | 
|  | 2593 | if (is_a_class && !member_accessibilities.empty()) | 
|  | 2594 | { | 
|  | 2595 | // This is a class and all members that didn't have | 
|  | 2596 | // their access specified are private. | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2597 | clang_type.SetDefaultAccessForRecordFields (eAccessPrivate, | 
|  | 2598 | &member_accessibilities.front(), | 
|  | 2599 | member_accessibilities.size()); | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2600 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2601 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2602 | if (!base_classes.empty()) | 
|  | 2603 | { | 
| Greg Clayton | 4705f8d | 2013-12-12 01:54:04 +0000 | [diff] [blame] | 2604 | // Make sure all base classes refer to complete types and not | 
|  | 2605 | // forward declarations. If we don't do this, clang will crash | 
|  | 2606 | // with an assertion in the call to clang_type.SetBaseClassesForClassType() | 
|  | 2607 | bool base_class_error = false; | 
|  | 2608 | for (auto &base_class : base_classes) | 
|  | 2609 | { | 
|  | 2610 | clang::TypeSourceInfo *type_source_info = base_class->getTypeSourceInfo(); | 
|  | 2611 | if (type_source_info) | 
|  | 2612 | { | 
|  | 2613 | ClangASTType base_class_type (GetClangASTContext().getASTContext(), type_source_info->getType()); | 
|  | 2614 | if (base_class_type.GetCompleteType() == false) | 
|  | 2615 | { | 
|  | 2616 | if (!base_class_error) | 
|  | 2617 | { | 
|  | 2618 | 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", | 
|  | 2619 | die->GetOffset(), | 
|  | 2620 | die->GetName(this, dwarf_cu), | 
|  | 2621 | base_class_type.GetTypeName().GetCString(), | 
|  | 2622 | sc.comp_unit ? sc.comp_unit->GetPath().c_str() : "the source file"); | 
|  | 2623 | } | 
|  | 2624 | // We have no choice other than to pretend that the base class | 
|  | 2625 | // is complete. If we don't do this, clang will crash when we | 
|  | 2626 | // call setBases() inside of "clang_type.SetBaseClassesForClassType()" | 
|  | 2627 | // below. Since we provide layout assistance, all ivars in this | 
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 2628 | // 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] | 2629 | // short of crashing. | 
|  | 2630 | base_class_type.StartTagDeclarationDefinition (); | 
|  | 2631 | base_class_type.CompleteTagDeclarationDefinition (); | 
|  | 2632 | } | 
|  | 2633 | } | 
|  | 2634 | } | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2635 | clang_type.SetBaseClassesForClassType (&base_classes.front(), | 
|  | 2636 | base_classes.size()); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2637 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2638 | // Clang will copy each CXXBaseSpecifier in "base_classes" | 
|  | 2639 | // so we have to free them all. | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2640 | ClangASTType::DeleteBaseClassSpecifiers (&base_classes.front(), | 
|  | 2641 | base_classes.size()); | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2642 | } | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2643 | } | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2644 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2645 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2646 | clang_type.BuildIndirectFields (); | 
|  | 2647 | clang_type.CompleteTagDeclarationDefinition (); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2648 |  | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2649 | if (!layout_info.field_offsets.empty() || | 
|  | 2650 | !layout_info.base_offsets.empty()  || | 
|  | 2651 | !layout_info.vbase_offsets.empty() ) | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2652 | { | 
|  | 2653 | if (type) | 
|  | 2654 | layout_info.bit_size = type->GetByteSize() * 8; | 
|  | 2655 | if (layout_info.bit_size == 0) | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2656 | 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] | 2657 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2658 | clang::CXXRecordDecl *record_decl = clang_type.GetAsCXXRecordDecl(); | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2659 | if (record_decl) | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2660 | { | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2661 | if (log) | 
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2662 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2663 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2664 | "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] | 2665 | static_cast<void*>(clang_type.GetOpaqueQualType()), | 
|  | 2666 | static_cast<void*>(record_decl), | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2667 | layout_info.bit_size, | 
|  | 2668 | layout_info.alignment, | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2669 | static_cast<uint32_t>(layout_info.field_offsets.size()), | 
|  | 2670 | static_cast<uint32_t>(layout_info.base_offsets.size()), | 
|  | 2671 | static_cast<uint32_t>(layout_info.vbase_offsets.size())); | 
|  | 2672 |  | 
| Zachary Turner | a98fac2 | 2015-03-24 18:56:08 +0000 | [diff] [blame] | 2673 | uint32_t idx; | 
|  | 2674 | { | 
|  | 2675 | llvm::DenseMap<const clang::FieldDecl *, uint64_t>::const_iterator pos, | 
|  | 2676 | end = layout_info.field_offsets.end(); | 
|  | 2677 | for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx) | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2678 | { | 
| Zachary Turner | 504f38d | 2015-03-24 16:24:50 +0000 | [diff] [blame] | 2679 | GetObjectFile()->GetModule()->LogMessage( | 
|  | 2680 | log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = " | 
|  | 2681 | "{ bit_offset=%u, name='%s' }", | 
| Zachary Turner | 504f38d | 2015-03-24 16:24:50 +0000 | [diff] [blame] | 2682 | static_cast<void *>(clang_type.GetOpaqueQualType()), idx, | 
| Zachary Turner | a98fac2 | 2015-03-24 18:56:08 +0000 | [diff] [blame] | 2683 | static_cast<uint32_t>(pos->second), pos->first->getNameAsString().c_str()); | 
|  | 2684 | } | 
|  | 2685 | } | 
|  | 2686 |  | 
|  | 2687 | { | 
|  | 2688 | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos, | 
|  | 2689 | base_end = layout_info.base_offsets.end(); | 
|  | 2690 | for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end; | 
|  | 2691 | ++base_pos, ++idx) | 
|  | 2692 | { | 
|  | 2693 | GetObjectFile()->GetModule()->LogMessage( | 
|  | 2694 | log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] " | 
|  | 2695 | "= { byte_offset=%u, name='%s' }", | 
|  | 2696 | clang_type.GetOpaqueQualType(), idx, (uint32_t)base_pos->second.getQuantity(), | 
|  | 2697 | base_pos->first->getNameAsString().c_str()); | 
|  | 2698 | } | 
|  | 2699 | } | 
|  | 2700 | { | 
|  | 2701 | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos, | 
|  | 2702 | vbase_end = layout_info.vbase_offsets.end(); | 
|  | 2703 | for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end; | 
|  | 2704 | ++vbase_pos, ++idx) | 
|  | 2705 | { | 
|  | 2706 | GetObjectFile()->GetModule()->LogMessage( | 
|  | 2707 | log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) " | 
|  | 2708 | "vbase[%u] = { byte_offset=%u, name='%s' }", | 
|  | 2709 | static_cast<void *>(clang_type.GetOpaqueQualType()), idx, | 
|  | 2710 | static_cast<uint32_t>(vbase_pos->second.getQuantity()), | 
|  | 2711 | vbase_pos->first->getNameAsString().c_str()); | 
|  | 2712 | } | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2713 | } | 
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2714 | } | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2715 | m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info)); | 
|  | 2716 | } | 
|  | 2717 | } | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2718 | } | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2719 |  | 
| 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 | case DW_TAG_enumeration_type: | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2723 | clang_type.StartTagDeclarationDefinition (); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2724 | if (die->HasChildren()) | 
|  | 2725 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2726 | SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); | 
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 2727 | bool is_signed = false; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2728 | clang_type.IsIntegerType(is_signed); | 
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 2729 | ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), dwarf_cu, die); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2730 | } | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2731 | clang_type.CompleteTagDeclarationDefinition (); | 
| Sean Callanan | 9076c0f | 2013-10-04 21:35:29 +0000 | [diff] [blame] | 2732 | return (bool)clang_type; | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2733 |  | 
|  | 2734 | default: | 
|  | 2735 | assert(false && "not a forward clang type decl!"); | 
|  | 2736 | break; | 
|  | 2737 | } | 
| Ashok Thirumurthi | a4658a5 | 2013-07-30 14:58:39 +0000 | [diff] [blame] | 2738 | return false; | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2739 | } | 
|  | 2740 |  | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2741 | Type* | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2742 | 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] | 2743 | { | 
|  | 2744 | if (type_die != NULL) | 
|  | 2745 | { | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 2746 | Type *type = m_die_to_type.lookup (type_die); | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2747 |  | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2748 | if (type == NULL) | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2749 | type = GetTypeForDIE (dwarf_cu, type_die).get(); | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2750 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2751 | if (assert_not_being_parsed) | 
| Jim Ingham | c354928 | 2012-01-11 02:21:12 +0000 | [diff] [blame] | 2752 | { | 
|  | 2753 | if (type != DIE_IS_BEING_PARSED) | 
|  | 2754 | return type; | 
|  | 2755 |  | 
|  | 2756 | 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] | 2757 | type_die->GetOffset(), | 
|  | 2758 | DW_TAG_value_to_name(type_die->Tag()), | 
|  | 2759 | type_die->GetName(this, dwarf_cu)); | 
| Jim Ingham | c354928 | 2012-01-11 02:21:12 +0000 | [diff] [blame] | 2760 |  | 
|  | 2761 | } | 
|  | 2762 | else | 
|  | 2763 | return type; | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2764 | } | 
|  | 2765 | return NULL; | 
|  | 2766 | } | 
|  | 2767 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2768 | CompileUnit* | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2769 | SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2770 | { | 
|  | 2771 | // Check if the symbol vendor already knows about this compile unit? | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2772 | if (dwarf_cu->GetUserData() == NULL) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2773 | { | 
|  | 2774 | // The symbol vendor doesn't know about this compile unit, we | 
|  | 2775 | // need to parse and add it to the symbol vendor object. | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2776 | return ParseCompileUnit(dwarf_cu, cu_idx).get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2777 | } | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2778 | return (CompileUnit*)dwarf_cu->GetUserData(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2779 | } | 
|  | 2780 |  | 
|  | 2781 | bool | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2782 | SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2783 | { | 
| Greg Clayton | 7231035 | 2013-02-23 04:12:47 +0000 | [diff] [blame] | 2784 | sc.Clear(false); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2785 | // Check if the symbol vendor already knows about this compile unit? | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2786 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2787 |  | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2788 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2789 | if (sc.function == NULL) | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2790 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2791 |  | 
|  | 2792 | if (sc.function) | 
|  | 2793 | { | 
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 2794 | sc.module_sp = sc.function->CalculateSymbolContextModule(); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2795 | return true; | 
|  | 2796 | } | 
|  | 2797 |  | 
|  | 2798 | return false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2799 | } | 
|  | 2800 |  | 
| Greg Clayton | 2501e5e | 2015-01-15 02:59:20 +0000 | [diff] [blame] | 2801 |  | 
|  | 2802 |  | 
|  | 2803 | SymbolFileDWARF::GlobalVariableMap & | 
|  | 2804 | SymbolFileDWARF::GetGlobalAranges() | 
|  | 2805 | { | 
|  | 2806 | if (!m_global_aranges_ap) | 
|  | 2807 | { | 
|  | 2808 | m_global_aranges_ap.reset (new GlobalVariableMap()); | 
|  | 2809 |  | 
|  | 2810 | ModuleSP module_sp = GetObjectFile()->GetModule(); | 
|  | 2811 | if (module_sp) | 
|  | 2812 | { | 
|  | 2813 | const size_t num_cus = module_sp->GetNumCompileUnits(); | 
|  | 2814 | for (size_t i = 0; i < num_cus; ++i) | 
|  | 2815 | { | 
|  | 2816 | CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(i); | 
|  | 2817 | if (cu_sp) | 
|  | 2818 | { | 
|  | 2819 | VariableListSP globals_sp = cu_sp->GetVariableList(true); | 
|  | 2820 | if (globals_sp) | 
|  | 2821 | { | 
|  | 2822 | const size_t num_globals = globals_sp->GetSize(); | 
|  | 2823 | for (size_t g = 0; g < num_globals; ++g) | 
|  | 2824 | { | 
|  | 2825 | VariableSP var_sp = globals_sp->GetVariableAtIndex(g); | 
|  | 2826 | if (var_sp && !var_sp->GetLocationIsConstantValueData()) | 
|  | 2827 | { | 
|  | 2828 | const DWARFExpression &location = var_sp->LocationExpression(); | 
|  | 2829 | Value location_result; | 
|  | 2830 | Error error; | 
|  | 2831 | if (location.Evaluate(NULL, NULL, NULL, LLDB_INVALID_ADDRESS, NULL, location_result, &error)) | 
|  | 2832 | { | 
|  | 2833 | if (location_result.GetValueType() == Value::eValueTypeFileAddress) | 
|  | 2834 | { | 
|  | 2835 | lldb::addr_t file_addr = location_result.GetScalar().ULongLong(); | 
|  | 2836 | lldb::addr_t byte_size = 1; | 
|  | 2837 | if (var_sp->GetType()) | 
|  | 2838 | byte_size = var_sp->GetType()->GetByteSize(); | 
|  | 2839 | m_global_aranges_ap->Append(GlobalVariableMap::Entry(file_addr, byte_size, var_sp.get())); | 
|  | 2840 | } | 
|  | 2841 | } | 
|  | 2842 | } | 
|  | 2843 | } | 
|  | 2844 | } | 
|  | 2845 | } | 
|  | 2846 | } | 
|  | 2847 | } | 
|  | 2848 | m_global_aranges_ap->Sort(); | 
|  | 2849 | } | 
|  | 2850 | return *m_global_aranges_ap; | 
|  | 2851 | } | 
|  | 2852 |  | 
|  | 2853 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2854 | uint32_t | 
|  | 2855 | SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) | 
|  | 2856 | { | 
|  | 2857 | Timer scoped_timer(__PRETTY_FUNCTION__, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2858 | "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] | 2859 | static_cast<void*>(so_addr.GetSection().get()), | 
|  | 2860 | so_addr.GetOffset(), resolve_scope); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2861 | uint32_t resolved = 0; | 
| Greg Clayton | 2501e5e | 2015-01-15 02:59:20 +0000 | [diff] [blame] | 2862 | if (resolve_scope & (   eSymbolContextCompUnit  | | 
|  | 2863 | eSymbolContextFunction  | | 
|  | 2864 | eSymbolContextBlock     | | 
|  | 2865 | eSymbolContextLineEntry | | 
|  | 2866 | eSymbolContextVariable  )) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2867 | { | 
|  | 2868 | lldb::addr_t file_vm_addr = so_addr.GetFileAddress(); | 
|  | 2869 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2870 | DWARFDebugInfo* debug_info = DebugInfo(); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2871 | if (debug_info) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2872 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2873 | const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr); | 
| Greg Clayton | 2501e5e | 2015-01-15 02:59:20 +0000 | [diff] [blame] | 2874 | if (cu_offset == DW_INVALID_OFFSET) | 
|  | 2875 | { | 
|  | 2876 | // Global variables are not in the compile unit address ranges. The only way to | 
|  | 2877 | // currently find global variables is to iterate over the .debug_pubnames or the | 
|  | 2878 | // __apple_names table and find all items in there that point to DW_TAG_variable | 
|  | 2879 | // DIEs and then find the address that matches. | 
|  | 2880 | if (resolve_scope & eSymbolContextVariable) | 
|  | 2881 | { | 
|  | 2882 | GlobalVariableMap &map = GetGlobalAranges(); | 
|  | 2883 | const GlobalVariableMap::Entry *entry = map.FindEntryThatContains(file_vm_addr); | 
|  | 2884 | if (entry && entry->data) | 
|  | 2885 | { | 
|  | 2886 | Variable *variable = entry->data; | 
|  | 2887 | SymbolContextScope *scc = variable->GetSymbolContextScope(); | 
|  | 2888 | if (scc) | 
|  | 2889 | { | 
|  | 2890 | scc->CalculateSymbolContext(&sc); | 
|  | 2891 | sc.variable = variable; | 
|  | 2892 | } | 
|  | 2893 | return sc.GetResolvedMask(); | 
|  | 2894 | } | 
|  | 2895 | } | 
|  | 2896 | } | 
|  | 2897 | else | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2898 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2899 | uint32_t cu_idx = DW_INVALID_INDEX; | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2900 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get(); | 
|  | 2901 | if (dwarf_cu) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2902 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2903 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2904 | if (sc.comp_unit) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2905 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2906 | resolved |= eSymbolContextCompUnit; | 
|  | 2907 |  | 
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2908 | bool force_check_line_table = false; | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2909 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) | 
|  | 2910 | { | 
|  | 2911 | DWARFDebugInfoEntry *function_die = NULL; | 
|  | 2912 | DWARFDebugInfoEntry *block_die = NULL; | 
|  | 2913 | if (resolve_scope & eSymbolContextBlock) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2914 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2915 | dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die); | 
|  | 2916 | } | 
|  | 2917 | else | 
|  | 2918 | { | 
|  | 2919 | dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL); | 
|  | 2920 | } | 
|  | 2921 |  | 
|  | 2922 | if (function_die != NULL) | 
|  | 2923 | { | 
|  | 2924 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); | 
|  | 2925 | if (sc.function == NULL) | 
|  | 2926 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die); | 
|  | 2927 | } | 
|  | 2928 | else | 
|  | 2929 | { | 
|  | 2930 | // We might have had a compile unit that had discontiguous | 
|  | 2931 | // address ranges where the gaps are symbols that don't have | 
|  | 2932 | // any debug info. Discontiguous compile unit address ranges | 
|  | 2933 | // should only happen when there aren't other functions from | 
|  | 2934 | // other compile units in these gaps. This helps keep the size | 
|  | 2935 | // of the aranges down. | 
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2936 | force_check_line_table = true; | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2937 | } | 
|  | 2938 |  | 
|  | 2939 | if (sc.function != NULL) | 
|  | 2940 | { | 
|  | 2941 | resolved |= eSymbolContextFunction; | 
|  | 2942 |  | 
|  | 2943 | if (resolve_scope & eSymbolContextBlock) | 
|  | 2944 | { | 
|  | 2945 | Block& block = sc.function->GetBlock (true); | 
|  | 2946 |  | 
|  | 2947 | if (block_die != NULL) | 
|  | 2948 | sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); | 
|  | 2949 | else | 
|  | 2950 | sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); | 
|  | 2951 | if (sc.block) | 
|  | 2952 | resolved |= eSymbolContextBlock; | 
|  | 2953 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2954 | } | 
|  | 2955 | } | 
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2956 |  | 
|  | 2957 | if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table) | 
|  | 2958 | { | 
|  | 2959 | LineTable *line_table = sc.comp_unit->GetLineTable(); | 
|  | 2960 | if (line_table != NULL) | 
|  | 2961 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 2962 | // And address that makes it into this function should be in terms | 
|  | 2963 | // of this debug file if there is no debug map, or it will be an | 
|  | 2964 | // address in the .o file which needs to be fixed up to be in terms | 
|  | 2965 | // of the debug map executable. Either way, calling FixupAddress() | 
|  | 2966 | // will work for us. | 
|  | 2967 | Address exe_so_addr (so_addr); | 
|  | 2968 | if (FixupAddress(exe_so_addr)) | 
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2969 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 2970 | if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry)) | 
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2971 | { | 
|  | 2972 | resolved |= eSymbolContextLineEntry; | 
|  | 2973 | } | 
|  | 2974 | } | 
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2975 | } | 
|  | 2976 | } | 
|  | 2977 |  | 
|  | 2978 | if (force_check_line_table && !(resolved & eSymbolContextLineEntry)) | 
|  | 2979 | { | 
|  | 2980 | // We might have had a compile unit that had discontiguous | 
|  | 2981 | // address ranges where the gaps are symbols that don't have | 
|  | 2982 | // any debug info. Discontiguous compile unit address ranges | 
|  | 2983 | // should only happen when there aren't other functions from | 
|  | 2984 | // other compile units in these gaps. This helps keep the size | 
|  | 2985 | // of the aranges down. | 
|  | 2986 | sc.comp_unit = NULL; | 
|  | 2987 | resolved &= ~eSymbolContextCompUnit; | 
|  | 2988 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2989 | } | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2990 | else | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2991 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2992 | GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.", | 
|  | 2993 | cu_offset, | 
|  | 2994 | cu_idx); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2995 | } | 
|  | 2996 | } | 
|  | 2997 | } | 
|  | 2998 | } | 
|  | 2999 | } | 
|  | 3000 | return resolved; | 
|  | 3001 | } | 
|  | 3002 |  | 
|  | 3003 |  | 
|  | 3004 |  | 
|  | 3005 | uint32_t | 
|  | 3006 | SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) | 
|  | 3007 | { | 
|  | 3008 | const uint32_t prev_size = sc_list.GetSize(); | 
|  | 3009 | if (resolve_scope & eSymbolContextCompUnit) | 
|  | 3010 | { | 
|  | 3011 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 3012 | if (debug_info) | 
|  | 3013 | { | 
|  | 3014 | uint32_t cu_idx; | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3015 | DWARFCompileUnit* dwarf_cu = NULL; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3016 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3017 | 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] | 3018 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3019 | CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); | 
| Sean Callanan | ddd7a2a | 2013-10-03 22:27:29 +0000 | [diff] [blame] | 3020 | const bool full_match = (bool)file_spec.GetDirectory(); | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 3021 | 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] | 3022 | if (check_inlines || file_spec_matches_cu_file_spec) | 
|  | 3023 | { | 
|  | 3024 | SymbolContext sc (m_obj_file->GetModule()); | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3025 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3026 | if (sc.comp_unit) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3027 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3028 | uint32_t file_idx = UINT32_MAX; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3029 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3030 | // If we are looking for inline functions only and we don't | 
|  | 3031 | // find it in the support files, we are done. | 
|  | 3032 | if (check_inlines) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3033 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3034 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); | 
|  | 3035 | if (file_idx == UINT32_MAX) | 
|  | 3036 | continue; | 
|  | 3037 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3038 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3039 | if (line != 0) | 
|  | 3040 | { | 
|  | 3041 | LineTable *line_table = sc.comp_unit->GetLineTable(); | 
|  | 3042 |  | 
|  | 3043 | if (line_table != NULL && line != 0) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3044 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3045 | // We will have already looked up the file index if | 
|  | 3046 | // we are searching for inline entries. | 
|  | 3047 | if (!check_inlines) | 
|  | 3048 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3049 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3050 | if (file_idx != UINT32_MAX) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3051 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3052 | uint32_t found_line; | 
|  | 3053 | uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry); | 
|  | 3054 | found_line = sc.line_entry.line; | 
|  | 3055 |  | 
|  | 3056 | while (line_idx != UINT32_MAX) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3057 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3058 | sc.function = NULL; | 
|  | 3059 | sc.block = NULL; | 
|  | 3060 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3061 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3062 | const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress(); | 
|  | 3063 | if (file_vm_addr != LLDB_INVALID_ADDRESS) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3064 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3065 | DWARFDebugInfoEntry *function_die = NULL; | 
|  | 3066 | DWARFDebugInfoEntry *block_die = NULL; | 
|  | 3067 | 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] | 3068 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3069 | if (function_die != NULL) | 
|  | 3070 | { | 
|  | 3071 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); | 
|  | 3072 | if (sc.function == NULL) | 
|  | 3073 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die); | 
|  | 3074 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3075 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3076 | if (sc.function != NULL) | 
|  | 3077 | { | 
|  | 3078 | Block& block = sc.function->GetBlock (true); | 
|  | 3079 |  | 
|  | 3080 | if (block_die != NULL) | 
|  | 3081 | sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); | 
| Jason Molenda | 60db6e4 | 2014-10-16 01:40:16 +0000 | [diff] [blame] | 3082 | else if (function_die != NULL) | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3083 | sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); | 
|  | 3084 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3085 | } | 
|  | 3086 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3087 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3088 | sc_list.Append(sc); | 
|  | 3089 | line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry); | 
|  | 3090 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3091 | } | 
|  | 3092 | } | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3093 | else if (file_spec_matches_cu_file_spec && !check_inlines) | 
|  | 3094 | { | 
|  | 3095 | // only append the context if we aren't looking for inline call sites | 
|  | 3096 | // by file and line and if the file spec matches that of the compile unit | 
|  | 3097 | sc_list.Append(sc); | 
|  | 3098 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3099 | } | 
|  | 3100 | else if (file_spec_matches_cu_file_spec && !check_inlines) | 
|  | 3101 | { | 
|  | 3102 | // only append the context if we aren't looking for inline call sites | 
|  | 3103 | // by file and line and if the file spec matches that of the compile unit | 
|  | 3104 | sc_list.Append(sc); | 
|  | 3105 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3106 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 3107 | if (!check_inlines) | 
|  | 3108 | break; | 
|  | 3109 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3110 | } | 
|  | 3111 | } | 
|  | 3112 | } | 
|  | 3113 | } | 
|  | 3114 | return sc_list.GetSize() - prev_size; | 
|  | 3115 | } | 
|  | 3116 |  | 
|  | 3117 | void | 
|  | 3118 | SymbolFileDWARF::Index () | 
|  | 3119 | { | 
|  | 3120 | if (m_indexed) | 
|  | 3121 | return; | 
|  | 3122 | m_indexed = true; | 
|  | 3123 | Timer scoped_timer (__PRETTY_FUNCTION__, | 
|  | 3124 | "SymbolFileDWARF::Index (%s)", | 
| Jim Ingham | 4af5961 | 2014-12-19 19:20:44 +0000 | [diff] [blame] | 3125 | GetObjectFile()->GetFileSpec().GetFilename().AsCString("<Unknown>")); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3126 |  | 
|  | 3127 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 3128 | if (debug_info) | 
|  | 3129 | { | 
|  | 3130 | uint32_t cu_idx = 0; | 
|  | 3131 | const uint32_t num_compile_units = GetNumCompileUnits(); | 
|  | 3132 | for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) | 
|  | 3133 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3134 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3135 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3136 | bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3137 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3138 | dwarf_cu->Index (cu_idx, | 
|  | 3139 | m_function_basename_index, | 
|  | 3140 | m_function_fullname_index, | 
|  | 3141 | m_function_method_index, | 
|  | 3142 | m_function_selector_index, | 
|  | 3143 | m_objc_class_selectors_index, | 
|  | 3144 | m_global_index, | 
|  | 3145 | m_type_index, | 
|  | 3146 | m_namespace_index); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3147 |  | 
|  | 3148 | // Keep memory down by clearing DIEs if this generate function | 
|  | 3149 | // caused them to be parsed | 
|  | 3150 | if (clear_dies) | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3151 | dwarf_cu->ClearDIEs (true); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3152 | } | 
|  | 3153 |  | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3154 | m_function_basename_index.Finalize(); | 
|  | 3155 | m_function_fullname_index.Finalize(); | 
|  | 3156 | m_function_method_index.Finalize(); | 
|  | 3157 | m_function_selector_index.Finalize(); | 
|  | 3158 | m_objc_class_selectors_index.Finalize(); | 
|  | 3159 | m_global_index.Finalize(); | 
|  | 3160 | m_type_index.Finalize(); | 
|  | 3161 | m_namespace_index.Finalize(); | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3162 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 3163 | #if defined (ENABLE_DEBUG_PRINTF) | 
| Greg Clayton | 7bd65b9 | 2011-02-09 23:39:34 +0000 | [diff] [blame] | 3164 | StreamFile s(stdout, false); | 
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 3165 | s.Printf ("DWARF index for '%s':", | 
|  | 3166 | GetObjectFile()->GetFileSpec().GetPath().c_str()); | 
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 3167 | s.Printf("\nFunction basenames:\n");    m_function_basename_index.Dump (&s); | 
|  | 3168 | s.Printf("\nFunction fullnames:\n");    m_function_fullname_index.Dump (&s); | 
|  | 3169 | s.Printf("\nFunction methods:\n");      m_function_method_index.Dump (&s); | 
|  | 3170 | s.Printf("\nFunction selectors:\n");    m_function_selector_index.Dump (&s); | 
|  | 3171 | s.Printf("\nObjective C class selectors:\n");    m_objc_class_selectors_index.Dump (&s); | 
|  | 3172 | s.Printf("\nGlobals and statics:\n");   m_global_index.Dump (&s); | 
| Greg Clayton | 69b0488 | 2010-10-15 02:03:22 +0000 | [diff] [blame] | 3173 | s.Printf("\nTypes:\n");                 m_type_index.Dump (&s); | 
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 3174 | s.Printf("\nNamepaces:\n");             m_namespace_index.Dump (&s); | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3175 | #endif | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3176 | } | 
|  | 3177 | } | 
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 3178 |  | 
|  | 3179 | bool | 
|  | 3180 | SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl) | 
|  | 3181 | { | 
|  | 3182 | if (namespace_decl == NULL) | 
|  | 3183 | { | 
|  | 3184 | // Invalid namespace decl which means we aren't matching only things | 
|  | 3185 | // in this symbol file, so return true to indicate it matches this | 
|  | 3186 | // symbol file. | 
|  | 3187 | return true; | 
|  | 3188 | } | 
|  | 3189 |  | 
|  | 3190 | clang::ASTContext *namespace_ast = namespace_decl->GetASTContext(); | 
|  | 3191 |  | 
|  | 3192 | if (namespace_ast == NULL) | 
|  | 3193 | return true;    // No AST in the "namespace_decl", return true since it | 
|  | 3194 | // could then match any symbol file, including this one | 
|  | 3195 |  | 
|  | 3196 | if (namespace_ast == GetClangASTContext().getASTContext()) | 
|  | 3197 | return true;    // The ASTs match, return true | 
|  | 3198 |  | 
|  | 3199 | // The namespace AST was valid, and it does not match... | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3200 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Sean Callanan | c41e68b | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 3201 |  | 
|  | 3202 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3203 | GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file"); | 
| Sean Callanan | c41e68b | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 3204 |  | 
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 3205 | return false; | 
|  | 3206 | } | 
|  | 3207 |  | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3208 | bool | 
|  | 3209 | SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl, | 
|  | 3210 | DWARFCompileUnit* cu, | 
|  | 3211 | const DWARFDebugInfoEntry* die) | 
|  | 3212 | { | 
| Bruce Mitchener | aaa0ba3 | 2014-07-08 18:05:41 +0000 | [diff] [blame] | 3213 | // No namespace specified, so the answer is | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3214 | if (namespace_decl == NULL) | 
|  | 3215 | return true; | 
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 3216 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3217 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 3218 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3219 | const DWARFDebugInfoEntry *decl_ctx_die = NULL; | 
|  | 3220 | clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die); | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3221 | if (decl_ctx_die) | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3222 | { | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3223 | clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl(); | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3224 |  | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3225 | if (clang_namespace_decl) | 
|  | 3226 | { | 
|  | 3227 | if (decl_ctx_die->Tag() != DW_TAG_namespace) | 
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 3228 | { | 
|  | 3229 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3230 | 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] | 3231 | return false; | 
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 3232 | } | 
|  | 3233 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3234 | if (clang_namespace_decl == die_clang_decl_ctx) | 
|  | 3235 | return true; | 
|  | 3236 | else | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3237 | return false; | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3238 | } | 
|  | 3239 | else | 
|  | 3240 | { | 
|  | 3241 | // We have a namespace_decl that was not NULL but it contained | 
|  | 3242 | // a NULL "clang::NamespaceDecl", so this means the global namespace | 
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 3243 | // So as long the contained decl context DIE isn't a namespace | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3244 | // we should be ok. | 
|  | 3245 | if (decl_ctx_die->Tag() != DW_TAG_namespace) | 
|  | 3246 | return true; | 
|  | 3247 | } | 
|  | 3248 | } | 
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 3249 |  | 
|  | 3250 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3251 | 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] | 3252 |  | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 3253 | return false; | 
|  | 3254 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3255 | uint32_t | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3256 | 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] | 3257 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3258 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3259 |  | 
|  | 3260 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3261 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3262 | "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)", | 
|  | 3263 | name.GetCString(), | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3264 | static_cast<const void*>(namespace_decl), | 
|  | 3265 | append, max_matches); | 
|  | 3266 |  | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3267 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) | 
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 3268 | return 0; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3269 |  | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3270 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 3271 | if (info == NULL) | 
|  | 3272 | return 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3273 |  | 
|  | 3274 | // If we aren't appending the results to this list, then clear the list | 
|  | 3275 | if (!append) | 
|  | 3276 | variables.Clear(); | 
|  | 3277 |  | 
|  | 3278 | // Remember how many variables are in the list before we search in case | 
|  | 3279 | // we are appending the results to a variable list. | 
|  | 3280 | const uint32_t original_size = variables.GetSize(); | 
|  | 3281 |  | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3282 | DIEArray die_offsets; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3283 |  | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3284 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3285 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3286 | if (m_apple_names_ap.get()) | 
|  | 3287 | { | 
|  | 3288 | const char *name_cstr = name.GetCString(); | 
| Jim Ingham | fa39bb4 | 2014-10-25 00:33:55 +0000 | [diff] [blame] | 3289 | llvm::StringRef basename; | 
|  | 3290 | llvm::StringRef context; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3291 |  | 
| Jim Ingham | fa39bb4 | 2014-10-25 00:33:55 +0000 | [diff] [blame] | 3292 | if (!CPPLanguageRuntime::ExtractContextAndIdentifier(name_cstr, context, basename)) | 
|  | 3293 | basename = name_cstr; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3294 |  | 
| Jim Ingham | fa39bb4 | 2014-10-25 00:33:55 +0000 | [diff] [blame] | 3295 | m_apple_names_ap->FindByName (basename.data(), die_offsets); | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3296 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3297 | } | 
|  | 3298 | else | 
|  | 3299 | { | 
|  | 3300 | // Index the DWARF if we haven't already | 
|  | 3301 | if (!m_indexed) | 
|  | 3302 | Index (); | 
|  | 3303 |  | 
|  | 3304 | m_global_index.Find (name, die_offsets); | 
|  | 3305 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3306 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3307 | const size_t num_die_matches = die_offsets.size(); | 
|  | 3308 | if (num_die_matches) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3309 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3310 | SymbolContext sc; | 
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 3311 | sc.module_sp = m_obj_file->GetModule(); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3312 | assert (sc.module_sp); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3313 |  | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3314 | DWARFDebugInfo* debug_info = DebugInfo(); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3315 | DWARFCompileUnit* dwarf_cu = NULL; | 
|  | 3316 | const DWARFDebugInfoEntry* die = NULL; | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3317 | bool done = false; | 
|  | 3318 | for (size_t i=0; i<num_die_matches && !done; ++i) | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3319 | { | 
|  | 3320 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 3321 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3322 |  | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3323 | if (die) | 
|  | 3324 | { | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3325 | switch (die->Tag()) | 
|  | 3326 | { | 
|  | 3327 | default: | 
|  | 3328 | case DW_TAG_subprogram: | 
|  | 3329 | case DW_TAG_inlined_subroutine: | 
|  | 3330 | case DW_TAG_try_block: | 
|  | 3331 | case DW_TAG_catch_block: | 
|  | 3332 | break; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3333 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3334 | case DW_TAG_variable: | 
|  | 3335 | { | 
|  | 3336 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3337 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3338 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) | 
|  | 3339 | continue; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3340 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3341 | ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3342 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3343 | if (variables.GetSize() - original_size >= max_matches) | 
|  | 3344 | done = true; | 
|  | 3345 | } | 
|  | 3346 | break; | 
|  | 3347 | } | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3348 | } | 
|  | 3349 | else | 
|  | 3350 | { | 
|  | 3351 | if (m_using_apple_tables) | 
|  | 3352 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3353 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n", | 
|  | 3354 | die_offset, name.GetCString()); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3355 | } | 
|  | 3356 | } | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3357 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3358 | } | 
|  | 3359 |  | 
|  | 3360 | // Return the number of variable that were appended to the list | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3361 | const uint32_t num_matches = variables.GetSize() - original_size; | 
|  | 3362 | if (log && num_matches > 0) | 
|  | 3363 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3364 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3365 | "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] | 3366 | name.GetCString(), | 
|  | 3367 | static_cast<const void*>(namespace_decl), | 
|  | 3368 | append, max_matches, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3369 | num_matches); | 
|  | 3370 | } | 
|  | 3371 | return num_matches; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3372 | } | 
|  | 3373 |  | 
|  | 3374 | uint32_t | 
|  | 3375 | SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables) | 
|  | 3376 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3377 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3378 |  | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3379 | if (log) | 
|  | 3380 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3381 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3382 | "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)", | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3383 | regex.GetText(), append, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3384 | max_matches); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3385 | } | 
|  | 3386 |  | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3387 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 3388 | if (info == NULL) | 
|  | 3389 | return 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3390 |  | 
|  | 3391 | // If we aren't appending the results to this list, then clear the list | 
|  | 3392 | if (!append) | 
|  | 3393 | variables.Clear(); | 
|  | 3394 |  | 
|  | 3395 | // Remember how many variables are in the list before we search in case | 
|  | 3396 | // we are appending the results to a variable list. | 
|  | 3397 | const uint32_t original_size = variables.GetSize(); | 
|  | 3398 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3399 | DIEArray die_offsets; | 
|  | 3400 |  | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3401 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3402 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3403 | if (m_apple_names_ap.get()) | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3404 | { | 
|  | 3405 | DWARFMappedHash::DIEInfoArray hash_data_array; | 
|  | 3406 | if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) | 
|  | 3407 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); | 
|  | 3408 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3409 | } | 
|  | 3410 | else | 
|  | 3411 | { | 
|  | 3412 | // Index the DWARF if we haven't already | 
|  | 3413 | if (!m_indexed) | 
|  | 3414 | Index (); | 
|  | 3415 |  | 
|  | 3416 | m_global_index.Find (regex, die_offsets); | 
|  | 3417 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3418 |  | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3419 | SymbolContext sc; | 
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 3420 | sc.module_sp = m_obj_file->GetModule(); | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3421 | assert (sc.module_sp); | 
|  | 3422 |  | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3423 | DWARFCompileUnit* dwarf_cu = NULL; | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3424 | const DWARFDebugInfoEntry* die = NULL; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3425 | const size_t num_matches = die_offsets.size(); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3426 | if (num_matches) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3427 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3428 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 3429 | for (size_t i=0; i<num_matches; ++i) | 
|  | 3430 | { | 
|  | 3431 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 3432 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3433 |  | 
|  | 3434 | if (die) | 
|  | 3435 | { | 
|  | 3436 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3437 |  | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3438 | ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3439 |  | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3440 | if (variables.GetSize() - original_size >= max_matches) | 
|  | 3441 | break; | 
|  | 3442 | } | 
|  | 3443 | else | 
|  | 3444 | { | 
|  | 3445 | if (m_using_apple_tables) | 
|  | 3446 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3447 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n", | 
|  | 3448 | die_offset, regex.GetText()); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3449 | } | 
|  | 3450 | } | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3451 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3452 | } | 
|  | 3453 |  | 
|  | 3454 | // Return the number of variable that were appended to the list | 
|  | 3455 | return variables.GetSize() - original_size; | 
|  | 3456 | } | 
|  | 3457 |  | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3458 |  | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3459 | bool | 
|  | 3460 | SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset, | 
|  | 3461 | DWARFCompileUnit *&dwarf_cu, | 
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3462 | bool include_inlines, | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3463 | SymbolContextList& sc_list) | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3464 | { | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3465 | const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3466 | return ResolveFunction (dwarf_cu, die, include_inlines, sc_list); | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3467 | } | 
|  | 3468 |  | 
|  | 3469 |  | 
|  | 3470 | bool | 
|  | 3471 | SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu, | 
|  | 3472 | const DWARFDebugInfoEntry *die, | 
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3473 | bool include_inlines, | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3474 | SymbolContextList& sc_list) | 
|  | 3475 | { | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3476 | SymbolContext sc; | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3477 |  | 
|  | 3478 | if (die == NULL) | 
|  | 3479 | return false; | 
|  | 3480 |  | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3481 | // If we were passed a die that is not a function, just return false... | 
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3482 | if (! (die->Tag() == DW_TAG_subprogram || (include_inlines && die->Tag() == DW_TAG_inlined_subroutine))) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3483 | return false; | 
|  | 3484 |  | 
|  | 3485 | const DWARFDebugInfoEntry* inlined_die = NULL; | 
|  | 3486 | if (die->Tag() == DW_TAG_inlined_subroutine) | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3487 | { | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3488 | inlined_die = die; | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3489 |  | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3490 | while ((die = die->GetParent()) != NULL) | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3491 | { | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3492 | if (die->Tag() == DW_TAG_subprogram) | 
|  | 3493 | break; | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3494 | } | 
|  | 3495 | } | 
| Jason Molenda | 60db6e4 | 2014-10-16 01:40:16 +0000 | [diff] [blame] | 3496 | assert (die && die->Tag() == DW_TAG_subprogram); | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3497 | if (GetFunction (cu, die, sc)) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3498 | { | 
|  | 3499 | Address addr; | 
|  | 3500 | // Parse all blocks if needed | 
|  | 3501 | if (inlined_die) | 
|  | 3502 | { | 
| Greg Clayton | f7bb1fb | 2015-01-15 03:13:44 +0000 | [diff] [blame] | 3503 | Block &function_block = sc.function->GetBlock (true); | 
|  | 3504 | sc.block = function_block.FindBlockByID (MakeUserID(inlined_die->GetOffset())); | 
|  | 3505 | if (sc.block == NULL) | 
|  | 3506 | sc.block = function_block.FindBlockByID (inlined_die->GetOffset()); | 
|  | 3507 | if (sc.block == NULL || sc.block->GetStartAddress (addr) == false) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3508 | addr.Clear(); | 
|  | 3509 | } | 
|  | 3510 | else | 
|  | 3511 | { | 
|  | 3512 | sc.block = NULL; | 
|  | 3513 | addr = sc.function->GetAddressRange().GetBaseAddress(); | 
|  | 3514 | } | 
|  | 3515 |  | 
|  | 3516 | if (addr.IsValid()) | 
|  | 3517 | { | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3518 | sc_list.Append(sc); | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3519 | return true; | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3520 | } | 
|  | 3521 | } | 
|  | 3522 |  | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3523 | return false; | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3524 | } | 
|  | 3525 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3526 | void | 
|  | 3527 | SymbolFileDWARF::FindFunctions (const ConstString &name, | 
|  | 3528 | const NameToDIE &name_to_die, | 
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3529 | bool include_inlines, | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3530 | SymbolContextList& sc_list) | 
|  | 3531 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3532 | DIEArray die_offsets; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3533 | if (name_to_die.Find (name, die_offsets)) | 
|  | 3534 | { | 
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3535 | ParseFunctions (die_offsets, include_inlines, sc_list); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3536 | } | 
|  | 3537 | } | 
|  | 3538 |  | 
|  | 3539 |  | 
|  | 3540 | void | 
|  | 3541 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, | 
|  | 3542 | const NameToDIE &name_to_die, | 
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3543 | bool include_inlines, | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3544 | SymbolContextList& sc_list) | 
|  | 3545 | { | 
|  | 3546 | DIEArray die_offsets; | 
|  | 3547 | if (name_to_die.Find (regex, die_offsets)) | 
|  | 3548 | { | 
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3549 | ParseFunctions (die_offsets, include_inlines, sc_list); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3550 | } | 
|  | 3551 | } | 
|  | 3552 |  | 
|  | 3553 |  | 
|  | 3554 | void | 
|  | 3555 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, | 
|  | 3556 | const DWARFMappedHash::MemoryTable &memory_table, | 
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3557 | bool include_inlines, | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3558 | SymbolContextList& sc_list) | 
|  | 3559 | { | 
|  | 3560 | DIEArray die_offsets; | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3561 | DWARFMappedHash::DIEInfoArray hash_data_array; | 
|  | 3562 | if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3563 | { | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3564 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); | 
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3565 | ParseFunctions (die_offsets, include_inlines, sc_list); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3566 | } | 
|  | 3567 | } | 
|  | 3568 |  | 
|  | 3569 | void | 
|  | 3570 | SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets, | 
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3571 | bool include_inlines, | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3572 | SymbolContextList& sc_list) | 
|  | 3573 | { | 
|  | 3574 | const size_t num_matches = die_offsets.size(); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3575 | if (num_matches) | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3576 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3577 | DWARFCompileUnit* dwarf_cu = NULL; | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3578 | for (size_t i=0; i<num_matches; ++i) | 
| Greg Clayton | d7e0546 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 3579 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3580 | const dw_offset_t die_offset = die_offsets[i]; | 
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3581 | ResolveFunction (die_offset, dwarf_cu, include_inlines, sc_list); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3582 | } | 
|  | 3583 | } | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3584 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3585 |  | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3586 | bool | 
|  | 3587 | SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die, | 
|  | 3588 | const DWARFCompileUnit *dwarf_cu, | 
|  | 3589 | uint32_t name_type_mask, | 
|  | 3590 | const char *partial_name, | 
|  | 3591 | const char *base_name_start, | 
|  | 3592 | const char *base_name_end) | 
|  | 3593 | { | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3594 | // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes: | 
|  | 3595 | if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3596 | { | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 3597 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset()); | 
|  | 3598 | if (!containing_decl_ctx) | 
|  | 3599 | return false; | 
|  | 3600 |  | 
|  | 3601 | bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()); | 
|  | 3602 |  | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3603 | if (name_type_mask == eFunctionNameTypeMethod) | 
|  | 3604 | { | 
|  | 3605 | if (is_cxx_method == false) | 
|  | 3606 | return false; | 
|  | 3607 | } | 
|  | 3608 |  | 
|  | 3609 | if (name_type_mask == eFunctionNameTypeBase) | 
|  | 3610 | { | 
|  | 3611 | if (is_cxx_method == true) | 
|  | 3612 | return false; | 
|  | 3613 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3614 | } | 
|  | 3615 |  | 
|  | 3616 | // Now we need to check whether the name we got back for this type matches the extra specifications | 
|  | 3617 | // that were in the name we're looking up: | 
|  | 3618 | if (base_name_start != partial_name || *base_name_end != '\0') | 
|  | 3619 | { | 
|  | 3620 | // First see if the stuff to the left matches the full name.  To do that let's see if | 
|  | 3621 | // we can pull out the mips linkage name attribute: | 
|  | 3622 |  | 
|  | 3623 | Mangled best_name; | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3624 | DWARFDebugInfoEntry::Attributes attributes; | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3625 | DWARFFormValue form_value; | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3626 | die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
|  | 3627 | uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name); | 
| Greg Clayton | 7141554 | 2012-12-08 00:24:40 +0000 | [diff] [blame] | 3628 | if (idx == UINT32_MAX) | 
|  | 3629 | idx = attributes.FindAttributeIndex(DW_AT_linkage_name); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3630 | if (idx != UINT32_MAX) | 
|  | 3631 | { | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3632 | if (attributes.ExtractFormValueAtIndex(this, idx, form_value)) | 
|  | 3633 | { | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3634 | const char *mangled_name = form_value.AsCString(&get_debug_str_data()); | 
|  | 3635 | if (mangled_name) | 
|  | 3636 | best_name.SetValue (ConstString(mangled_name), true); | 
|  | 3637 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3638 | } | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3639 |  | 
|  | 3640 | if (!best_name) | 
|  | 3641 | { | 
|  | 3642 | idx = attributes.FindAttributeIndex(DW_AT_name); | 
|  | 3643 | if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value)) | 
|  | 3644 | { | 
|  | 3645 | const char *name = form_value.AsCString(&get_debug_str_data()); | 
|  | 3646 | best_name.SetValue (ConstString(name), false); | 
|  | 3647 | } | 
|  | 3648 | } | 
|  | 3649 |  | 
|  | 3650 | if (best_name.GetDemangledName()) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3651 | { | 
|  | 3652 | const char *demangled = best_name.GetDemangledName().GetCString(); | 
|  | 3653 | if (demangled) | 
|  | 3654 | { | 
|  | 3655 | std::string name_no_parens(partial_name, base_name_end - partial_name); | 
| Jim Ingham | 85c13d7 | 2012-03-02 02:24:42 +0000 | [diff] [blame] | 3656 | const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str()); | 
|  | 3657 | if (partial_in_demangled == NULL) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3658 | return false; | 
| Jim Ingham | 85c13d7 | 2012-03-02 02:24:42 +0000 | [diff] [blame] | 3659 | else | 
|  | 3660 | { | 
|  | 3661 | // Sort out the case where our name is something like "Process::Destroy" and the match is | 
|  | 3662 | // "SBProcess::Destroy" - that shouldn't be a match.  We should really always match on | 
|  | 3663 | // namespace boundaries... | 
|  | 3664 |  | 
|  | 3665 | if (partial_name[0] == ':'  && partial_name[1] == ':') | 
|  | 3666 | { | 
|  | 3667 | // The partial name was already on a namespace boundary so all matches are good. | 
|  | 3668 | return true; | 
|  | 3669 | } | 
|  | 3670 | else if (partial_in_demangled == demangled) | 
|  | 3671 | { | 
|  | 3672 | // They both start the same, so this is an good match. | 
|  | 3673 | return true; | 
|  | 3674 | } | 
|  | 3675 | else | 
|  | 3676 | { | 
|  | 3677 | if (partial_in_demangled - demangled == 1) | 
|  | 3678 | { | 
|  | 3679 | // Only one character difference, can't be a namespace boundary... | 
|  | 3680 | return false; | 
|  | 3681 | } | 
|  | 3682 | else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':') | 
|  | 3683 | { | 
|  | 3684 | // We are on a namespace boundary, so this is also good. | 
|  | 3685 | return true; | 
|  | 3686 | } | 
|  | 3687 | else | 
|  | 3688 | return false; | 
|  | 3689 | } | 
|  | 3690 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3691 | } | 
|  | 3692 | } | 
|  | 3693 | } | 
|  | 3694 |  | 
|  | 3695 | return true; | 
|  | 3696 | } | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3697 |  | 
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3698 | uint32_t | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3699 | SymbolFileDWARF::FindFunctions (const ConstString &name, | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3700 | const lldb_private::ClangNamespaceDecl *namespace_decl, | 
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3701 | uint32_t name_type_mask, | 
|  | 3702 | bool include_inlines, | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3703 | bool append, | 
|  | 3704 | SymbolContextList& sc_list) | 
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3705 | { | 
|  | 3706 | Timer scoped_timer (__PRETTY_FUNCTION__, | 
|  | 3707 | "SymbolFileDWARF::FindFunctions (name = '%s')", | 
|  | 3708 | name.AsCString()); | 
|  | 3709 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3710 | // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup() | 
|  | 3711 | assert ((name_type_mask & eFunctionNameTypeAuto) == 0); | 
|  | 3712 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3713 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3714 |  | 
|  | 3715 | if (log) | 
|  | 3716 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3717 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3718 | "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)", | 
|  | 3719 | name.GetCString(), | 
|  | 3720 | name_type_mask, | 
|  | 3721 | append); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3722 | } | 
|  | 3723 |  | 
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3724 | // If we aren't appending the results to this list, then clear the list | 
|  | 3725 | if (!append) | 
|  | 3726 | sc_list.Clear(); | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3727 |  | 
|  | 3728 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) | 
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 3729 | return 0; | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3730 |  | 
|  | 3731 | // If name is empty then we won't find anything. | 
|  | 3732 | if (name.IsEmpty()) | 
|  | 3733 | return 0; | 
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3734 |  | 
|  | 3735 | // Remember how many sc_list are in the list before we search in case | 
|  | 3736 | // we are appending the results to a variable list. | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3737 |  | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3738 | const char *name_cstr = name.GetCString(); | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3739 |  | 
|  | 3740 | const uint32_t original_size = sc_list.GetSize(); | 
|  | 3741 |  | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3742 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 3743 | if (info == NULL) | 
|  | 3744 | return 0; | 
|  | 3745 |  | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3746 | DWARFCompileUnit *dwarf_cu = NULL; | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3747 | std::set<const DWARFDebugInfoEntry *> resolved_dies; | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3748 | if (m_using_apple_tables) | 
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 3749 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3750 | if (m_apple_names_ap.get()) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3751 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3752 |  | 
|  | 3753 | DIEArray die_offsets; | 
|  | 3754 |  | 
|  | 3755 | uint32_t num_matches = 0; | 
|  | 3756 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3757 | if (name_type_mask & eFunctionNameTypeFull) | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3758 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3759 | // If they asked for the full name, match what they typed.  At some point we may | 
|  | 3760 | // want to canonicalize this (strip double spaces, etc.  For now, we just add all the | 
|  | 3761 | // dies that we find by exact match. | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3762 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3763 | for (uint32_t i = 0; i < num_matches; i++) | 
|  | 3764 | { | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3765 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 3766 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3767 | if (die) | 
|  | 3768 | { | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3769 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) | 
|  | 3770 | continue; | 
|  | 3771 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3772 | if (resolved_dies.find(die) == resolved_dies.end()) | 
|  | 3773 | { | 
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3774 | if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list)) | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3775 | resolved_dies.insert(die); | 
|  | 3776 | } | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3777 | } | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3778 | else | 
|  | 3779 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3780 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", | 
|  | 3781 | die_offset, name_cstr); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3782 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3783 | } | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3784 | } | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3785 |  | 
|  | 3786 | if (name_type_mask & eFunctionNameTypeSelector) | 
|  | 3787 | { | 
|  | 3788 | if (namespace_decl && *namespace_decl) | 
|  | 3789 | return 0; // no selectors in namespaces | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3790 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3791 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); | 
|  | 3792 | // Now make sure these are actually ObjC methods.  In this case we can simply look up the name, | 
|  | 3793 | // and if it is an ObjC method name, we're good. | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3794 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3795 | for (uint32_t i = 0; i < num_matches; i++) | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3796 | { | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3797 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 3798 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
|  | 3799 | if (die) | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3800 | { | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3801 | const char *die_name = die->GetName(this, dwarf_cu); | 
|  | 3802 | if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name)) | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3803 | { | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3804 | if (resolved_dies.find(die) == resolved_dies.end()) | 
|  | 3805 | { | 
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3806 | if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list)) | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3807 | resolved_dies.insert(die); | 
|  | 3808 | } | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3809 | } | 
|  | 3810 | } | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3811 | else | 
|  | 3812 | { | 
|  | 3813 | GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", | 
|  | 3814 | die_offset, name_cstr); | 
|  | 3815 | } | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3816 | } | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3817 | die_offsets.clear(); | 
|  | 3818 | } | 
|  | 3819 |  | 
|  | 3820 | if (((name_type_mask & eFunctionNameTypeMethod) && !namespace_decl) || name_type_mask & eFunctionNameTypeBase) | 
|  | 3821 | { | 
|  | 3822 | // The apple_names table stores just the "base name" of C++ methods in the table.  So we have to | 
|  | 3823 | // extract the base name, look that up, and if there is any other information in the name we were | 
|  | 3824 | // passed in we have to post-filter based on that. | 
|  | 3825 |  | 
|  | 3826 | // FIXME: Arrange the logic above so that we don't calculate the base name twice: | 
|  | 3827 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); | 
|  | 3828 |  | 
|  | 3829 | for (uint32_t i = 0; i < num_matches; i++) | 
|  | 3830 | { | 
|  | 3831 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 3832 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
|  | 3833 | if (die) | 
|  | 3834 | { | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3835 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) | 
|  | 3836 | continue; | 
|  | 3837 |  | 
|  | 3838 | // If we get to here, the die is good, and we should add it: | 
|  | 3839 | if (resolved_dies.find(die) == resolved_dies.end()) | 
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3840 | if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list)) | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3841 | { | 
|  | 3842 | bool keep_die = true; | 
|  | 3843 | if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod)) | 
|  | 3844 | { | 
|  | 3845 | // We are looking for either basenames or methods, so we need to | 
|  | 3846 | // trim out the ones we won't want by looking at the type | 
|  | 3847 | SymbolContext sc; | 
|  | 3848 | if (sc_list.GetLastContext(sc)) | 
|  | 3849 | { | 
|  | 3850 | if (sc.block) | 
|  | 3851 | { | 
|  | 3852 | // We have an inlined function | 
|  | 3853 | } | 
|  | 3854 | else if (sc.function) | 
|  | 3855 | { | 
|  | 3856 | Type *type = sc.function->GetType(); | 
|  | 3857 |  | 
| Sean Callanan | c370a8a | 2013-09-18 22:59:55 +0000 | [diff] [blame] | 3858 | if (type) | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3859 | { | 
| Sean Callanan | c370a8a | 2013-09-18 22:59:55 +0000 | [diff] [blame] | 3860 | clang::DeclContext* decl_ctx = GetClangDeclContextContainingTypeUID (type->GetID()); | 
|  | 3861 | if (decl_ctx->isRecord()) | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3862 | { | 
| Sean Callanan | c370a8a | 2013-09-18 22:59:55 +0000 | [diff] [blame] | 3863 | if (name_type_mask & eFunctionNameTypeBase) | 
|  | 3864 | { | 
|  | 3865 | sc_list.RemoveContextAtIndex(sc_list.GetSize()-1); | 
|  | 3866 | keep_die = false; | 
|  | 3867 | } | 
|  | 3868 | } | 
|  | 3869 | else | 
|  | 3870 | { | 
|  | 3871 | if (name_type_mask & eFunctionNameTypeMethod) | 
|  | 3872 | { | 
|  | 3873 | sc_list.RemoveContextAtIndex(sc_list.GetSize()-1); | 
|  | 3874 | keep_die = false; | 
|  | 3875 | } | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3876 | } | 
|  | 3877 | } | 
|  | 3878 | else | 
|  | 3879 | { | 
| Sean Callanan | c370a8a | 2013-09-18 22:59:55 +0000 | [diff] [blame] | 3880 | GetObjectFile()->GetModule()->ReportWarning ("function at die offset 0x%8.8x had no function type", | 
|  | 3881 | die_offset); | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3882 | } | 
|  | 3883 | } | 
|  | 3884 | } | 
|  | 3885 | } | 
|  | 3886 | if (keep_die) | 
|  | 3887 | resolved_dies.insert(die); | 
|  | 3888 | } | 
|  | 3889 | } | 
|  | 3890 | else | 
|  | 3891 | { | 
|  | 3892 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", | 
|  | 3893 | die_offset, name_cstr); | 
|  | 3894 | } | 
|  | 3895 | } | 
|  | 3896 | die_offsets.clear(); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3897 | } | 
|  | 3898 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3899 | } | 
|  | 3900 | else | 
|  | 3901 | { | 
|  | 3902 |  | 
|  | 3903 | // Index the DWARF if we haven't already | 
|  | 3904 | if (!m_indexed) | 
|  | 3905 | Index (); | 
|  | 3906 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3907 | if (name_type_mask & eFunctionNameTypeFull) | 
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 3908 | { | 
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3909 | FindFunctions (name, m_function_fullname_index, include_inlines, sc_list); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3910 |  | 
| Ed Maste | fc7baa0 | 2013-09-09 18:00:45 +0000 | [diff] [blame] | 3911 | // FIXME Temporary workaround for global/anonymous namespace | 
|  | 3912 | // functions on FreeBSD and Linux | 
|  | 3913 | #if defined (__FreeBSD__) || defined (__linux__) | 
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 3914 | // If we didn't find any functions in the global namespace try | 
|  | 3915 | // looking in the basename index but ignore any returned | 
|  | 3916 | // functions that have a namespace (ie. mangled names starting with | 
|  | 3917 | // '_ZN') but keep functions which have an anonymous namespace | 
|  | 3918 | if (sc_list.GetSize() == 0) | 
|  | 3919 | { | 
|  | 3920 | SymbolContextList temp_sc_list; | 
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3921 | FindFunctions (name, m_function_basename_index, include_inlines, temp_sc_list); | 
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 3922 | if (!namespace_decl) | 
|  | 3923 | { | 
|  | 3924 | SymbolContext sc; | 
|  | 3925 | for (uint32_t i = 0; i < temp_sc_list.GetSize(); i++) | 
|  | 3926 | { | 
|  | 3927 | if (temp_sc_list.GetContextAtIndex(i, sc)) | 
|  | 3928 | { | 
| Matt Kopec | a189d49 | 2013-05-10 22:55:24 +0000 | [diff] [blame] | 3929 | ConstString mangled_name = sc.GetFunctionName(Mangled::ePreferMangled); | 
|  | 3930 | ConstString demangled_name = sc.GetFunctionName(Mangled::ePreferDemangled); | 
| Matt Kopec | 04e5d58 | 2013-05-14 19:00:41 +0000 | [diff] [blame] | 3931 | if (strncmp(mangled_name.GetCString(), "_ZN", 3) || | 
|  | 3932 | !strncmp(demangled_name.GetCString(), "(anonymous namespace)", 21)) | 
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 3933 | { | 
|  | 3934 | sc_list.Append(sc); | 
|  | 3935 | } | 
|  | 3936 | } | 
|  | 3937 | } | 
|  | 3938 | } | 
|  | 3939 | } | 
|  | 3940 | #endif | 
|  | 3941 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3942 | DIEArray die_offsets; | 
|  | 3943 | DWARFCompileUnit *dwarf_cu = NULL; | 
|  | 3944 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3945 | if (name_type_mask & eFunctionNameTypeBase) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3946 | { | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3947 | uint32_t num_base = m_function_basename_index.Find(name, die_offsets); | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3948 | for (uint32_t i = 0; i < num_base; i++) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3949 | { | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3950 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); | 
|  | 3951 | if (die) | 
|  | 3952 | { | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3953 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) | 
|  | 3954 | continue; | 
|  | 3955 |  | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3956 | // 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] | 3957 | if (resolved_dies.find(die) == resolved_dies.end()) | 
|  | 3958 | { | 
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3959 | if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list)) | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3960 | resolved_dies.insert(die); | 
|  | 3961 | } | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3962 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3963 | } | 
|  | 3964 | die_offsets.clear(); | 
|  | 3965 | } | 
|  | 3966 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3967 | if (name_type_mask & eFunctionNameTypeMethod) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3968 | { | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3969 | if (namespace_decl && *namespace_decl) | 
|  | 3970 | return 0; // no methods in namespaces | 
|  | 3971 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3972 | uint32_t num_base = m_function_method_index.Find(name, die_offsets); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3973 | { | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3974 | for (uint32_t i = 0; i < num_base; i++) | 
|  | 3975 | { | 
|  | 3976 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); | 
|  | 3977 | if (die) | 
|  | 3978 | { | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3979 | // 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] | 3980 | if (resolved_dies.find(die) == resolved_dies.end()) | 
|  | 3981 | { | 
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3982 | if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list)) | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3983 | resolved_dies.insert(die); | 
|  | 3984 | } | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3985 | } | 
|  | 3986 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3987 | } | 
|  | 3988 | die_offsets.clear(); | 
|  | 3989 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3990 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3991 | if ((name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl)) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3992 | { | 
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3993 | FindFunctions (name, m_function_selector_index, include_inlines, sc_list); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3994 | } | 
|  | 3995 |  | 
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 3996 | } | 
|  | 3997 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3998 | // Return the number of variable that were appended to the list | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3999 | const uint32_t num_matches = sc_list.GetSize() - original_size; | 
|  | 4000 |  | 
|  | 4001 | if (log && num_matches > 0) | 
|  | 4002 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4003 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 4004 | "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, include_inlines=%d, append=%u, sc_list) => %u", | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4005 | name.GetCString(), | 
|  | 4006 | name_type_mask, | 
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 4007 | include_inlines, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4008 | append, | 
|  | 4009 | num_matches); | 
|  | 4010 | } | 
|  | 4011 | return num_matches; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4012 | } | 
|  | 4013 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4014 | uint32_t | 
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 4015 | 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] | 4016 | { | 
|  | 4017 | Timer scoped_timer (__PRETTY_FUNCTION__, | 
|  | 4018 | "SymbolFileDWARF::FindFunctions (regex = '%s')", | 
|  | 4019 | regex.GetText()); | 
|  | 4020 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4021 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 4022 |  | 
|  | 4023 | if (log) | 
|  | 4024 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4025 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4026 | "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)", | 
|  | 4027 | regex.GetText(), | 
|  | 4028 | append); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 4029 | } | 
|  | 4030 |  | 
|  | 4031 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4032 | // If we aren't appending the results to this list, then clear the list | 
|  | 4033 | if (!append) | 
|  | 4034 | sc_list.Clear(); | 
|  | 4035 |  | 
|  | 4036 | // Remember how many sc_list are in the list before we search in case | 
|  | 4037 | // we are appending the results to a variable list. | 
|  | 4038 | uint32_t original_size = sc_list.GetSize(); | 
|  | 4039 |  | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4040 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4041 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4042 | if (m_apple_names_ap.get()) | 
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 4043 | FindFunctions (regex, *m_apple_names_ap, include_inlines, sc_list); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4044 | } | 
|  | 4045 | else | 
|  | 4046 | { | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 4047 | // Index the DWARF if we haven't already | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4048 | if (!m_indexed) | 
|  | 4049 | Index (); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4050 |  | 
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 4051 | FindFunctions (regex, m_function_basename_index, include_inlines, sc_list); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4052 |  | 
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 4053 | FindFunctions (regex, m_function_fullname_index, include_inlines, sc_list); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4054 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4055 |  | 
|  | 4056 | // Return the number of variable that were appended to the list | 
|  | 4057 | return sc_list.GetSize() - original_size; | 
|  | 4058 | } | 
| Jim Ingham | 318c9f2 | 2011-08-26 19:44:13 +0000 | [diff] [blame] | 4059 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4060 | uint32_t | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4061 | SymbolFileDWARF::FindTypes (const SymbolContext& sc, | 
|  | 4062 | const ConstString &name, | 
|  | 4063 | const lldb_private::ClangNamespaceDecl *namespace_decl, | 
|  | 4064 | bool append, | 
|  | 4065 | uint32_t max_matches, | 
|  | 4066 | TypeList& types) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4067 | { | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 4068 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 4069 | if (info == NULL) | 
|  | 4070 | return 0; | 
|  | 4071 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4072 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4073 |  | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 4074 | if (log) | 
|  | 4075 | { | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4076 | if (namespace_decl) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4077 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4078 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)", | 
|  | 4079 | name.GetCString(), | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4080 | static_cast<void*>(namespace_decl->GetNamespaceDecl()), | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4081 | namespace_decl->GetQualifiedName().c_str(), | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4082 | append, max_matches); | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4083 | else | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4084 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4085 | "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] | 4086 | name.GetCString(), append, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4087 | max_matches); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 4088 | } | 
|  | 4089 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4090 | // If we aren't appending the results to this list, then clear the list | 
|  | 4091 | if (!append) | 
|  | 4092 | types.Clear(); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4093 |  | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 4094 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) | 
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 4095 | return 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4096 |  | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4097 | DIEArray die_offsets; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4098 |  | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4099 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4100 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4101 | if (m_apple_types_ap.get()) | 
|  | 4102 | { | 
|  | 4103 | const char *name_cstr = name.GetCString(); | 
|  | 4104 | m_apple_types_ap->FindByName (name_cstr, die_offsets); | 
|  | 4105 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4106 | } | 
|  | 4107 | else | 
|  | 4108 | { | 
|  | 4109 | if (!m_indexed) | 
|  | 4110 | Index (); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4111 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4112 | m_type_index.Find (name, die_offsets); | 
|  | 4113 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4114 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4115 | const size_t num_die_matches = die_offsets.size(); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4116 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4117 | if (num_die_matches) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4118 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4119 | const uint32_t initial_types_size = types.GetSize(); | 
|  | 4120 | DWARFCompileUnit* dwarf_cu = NULL; | 
|  | 4121 | const DWARFDebugInfoEntry* die = NULL; | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4122 | DWARFDebugInfo* debug_info = DebugInfo(); | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4123 | for (size_t i=0; i<num_die_matches; ++i) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4124 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4125 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 4126 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
|  | 4127 |  | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4128 | if (die) | 
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 4129 | { | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4130 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) | 
|  | 4131 | continue; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4132 |  | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4133 | Type *matching_type = ResolveType (dwarf_cu, die); | 
|  | 4134 | if (matching_type) | 
|  | 4135 | { | 
|  | 4136 | // 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] | 4137 | types.InsertUnique (matching_type->shared_from_this()); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4138 | if (types.GetSize() >= max_matches) | 
|  | 4139 | break; | 
|  | 4140 | } | 
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 4141 | } | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4142 | else | 
|  | 4143 | { | 
|  | 4144 | if (m_using_apple_tables) | 
|  | 4145 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4146 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", | 
|  | 4147 | die_offset, name.GetCString()); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4148 | } | 
|  | 4149 | } | 
|  | 4150 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4151 | } | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4152 | const uint32_t num_matches = types.GetSize() - initial_types_size; | 
|  | 4153 | if (log && num_matches) | 
|  | 4154 | { | 
|  | 4155 | if (namespace_decl) | 
|  | 4156 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4157 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4158 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u", | 
|  | 4159 | name.GetCString(), | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4160 | static_cast<void*>(namespace_decl->GetNamespaceDecl()), | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4161 | namespace_decl->GetQualifiedName().c_str(), | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4162 | append, max_matches, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4163 | num_matches); | 
|  | 4164 | } | 
|  | 4165 | else | 
|  | 4166 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4167 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4168 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u", | 
|  | 4169 | name.GetCString(), | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4170 | append, max_matches, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4171 | num_matches); | 
|  | 4172 | } | 
|  | 4173 | } | 
|  | 4174 | return num_matches; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4175 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4176 | return 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4177 | } | 
|  | 4178 |  | 
|  | 4179 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4180 | ClangNamespaceDecl | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4181 | SymbolFileDWARF::FindNamespace (const SymbolContext& sc, | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 4182 | const ConstString &name, | 
|  | 4183 | const lldb_private::ClangNamespaceDecl *parent_namespace_decl) | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4184 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4185 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 4186 |  | 
|  | 4187 | if (log) | 
|  | 4188 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4189 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4190 | "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")", | 
|  | 4191 | name.GetCString()); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 4192 | } | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 4193 |  | 
|  | 4194 | if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl)) | 
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 4195 | return ClangNamespaceDecl(); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 4196 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4197 | ClangNamespaceDecl namespace_decl; | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4198 | DWARFDebugInfo* info = DebugInfo(); | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4199 | if (info) | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4200 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4201 | DIEArray die_offsets; | 
|  | 4202 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4203 | // Index if we already haven't to make sure the compile units | 
|  | 4204 | // get indexed and make their global DIE index list | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4205 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4206 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4207 | if (m_apple_namespaces_ap.get()) | 
|  | 4208 | { | 
|  | 4209 | const char *name_cstr = name.GetCString(); | 
|  | 4210 | m_apple_namespaces_ap->FindByName (name_cstr, die_offsets); | 
|  | 4211 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4212 | } | 
|  | 4213 | else | 
|  | 4214 | { | 
|  | 4215 | if (!m_indexed) | 
|  | 4216 | Index (); | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4217 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4218 | m_namespace_index.Find (name, die_offsets); | 
|  | 4219 | } | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4220 |  | 
|  | 4221 | DWARFCompileUnit* dwarf_cu = NULL; | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4222 | const DWARFDebugInfoEntry* die = NULL; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4223 | const size_t num_matches = die_offsets.size(); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4224 | if (num_matches) | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4225 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4226 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 4227 | for (size_t i=0; i<num_matches; ++i) | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4228 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4229 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 4230 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 4231 |  | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4232 | if (die) | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4233 | { | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4234 | if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die)) | 
|  | 4235 | continue; | 
|  | 4236 |  | 
|  | 4237 | clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die); | 
|  | 4238 | if (clang_namespace_decl) | 
|  | 4239 | { | 
|  | 4240 | namespace_decl.SetASTContext (GetClangASTContext().getASTContext()); | 
|  | 4241 | namespace_decl.SetNamespaceDecl (clang_namespace_decl); | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4242 | break; | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4243 | } | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4244 | } | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4245 | else | 
|  | 4246 | { | 
|  | 4247 | if (m_using_apple_tables) | 
|  | 4248 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4249 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n", | 
|  | 4250 | die_offset, name.GetCString()); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4251 | } | 
|  | 4252 | } | 
|  | 4253 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4254 | } | 
|  | 4255 | } | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4256 | } | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4257 | if (log && namespace_decl.GetNamespaceDecl()) | 
|  | 4258 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4259 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4260 | "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"", | 
|  | 4261 | name.GetCString(), | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4262 | static_cast<const void*>(namespace_decl.GetNamespaceDecl()), | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 4263 | namespace_decl.GetQualifiedName().c_str()); | 
|  | 4264 | } | 
|  | 4265 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 4266 | return namespace_decl; | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4267 | } | 
|  | 4268 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4269 | uint32_t | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4270 | 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] | 4271 | { | 
|  | 4272 | // Remember how many sc_list are in the list before we search in case | 
|  | 4273 | // we are appending the results to a variable list. | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4274 | uint32_t original_size = types.GetSize(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4275 |  | 
|  | 4276 | const uint32_t num_die_offsets = die_offsets.size(); | 
|  | 4277 | // Parse all of the types we found from the pubtypes matches | 
|  | 4278 | uint32_t i; | 
|  | 4279 | uint32_t num_matches = 0; | 
|  | 4280 | for (i = 0; i < num_die_offsets; ++i) | 
|  | 4281 | { | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4282 | Type *matching_type = ResolveTypeUID (die_offsets[i]); | 
|  | 4283 | if (matching_type) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4284 | { | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4285 | // 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] | 4286 | types.InsertUnique (matching_type->shared_from_this()); | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4287 | ++num_matches; | 
|  | 4288 | if (num_matches >= max_matches) | 
|  | 4289 | break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4290 | } | 
|  | 4291 | } | 
|  | 4292 |  | 
|  | 4293 | // Return the number of variable that were appended to the list | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4294 | return types.GetSize() - original_size; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4295 | } | 
|  | 4296 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4297 |  | 
|  | 4298 | size_t | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4299 | SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc, | 
|  | 4300 | clang::DeclContext *containing_decl_ctx, | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4301 | DWARFCompileUnit* dwarf_cu, | 
|  | 4302 | const DWARFDebugInfoEntry *parent_die, | 
|  | 4303 | bool skip_artificial, | 
|  | 4304 | bool &is_static, | 
| Greg Clayton | 0396975 | 2014-02-24 18:53:11 +0000 | [diff] [blame] | 4305 | bool &is_variadic, | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 4306 | std::vector<ClangASTType>& function_param_types, | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4307 | std::vector<clang::ParmVarDecl*>& function_param_decls, | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 4308 | unsigned &type_quals) // , | 
|  | 4309 | // ClangASTContext::TemplateParameterInfos &template_param_infos)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4310 | { | 
|  | 4311 | if (parent_die == NULL) | 
|  | 4312 | return 0; | 
|  | 4313 |  | 
| Todd Fiala | ee8bfc6 | 2014-09-11 17:29:12 +0000 | [diff] [blame] | 4314 | 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] | 4315 |  | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4316 | size_t arg_idx = 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4317 | const DWARFDebugInfoEntry *die; | 
|  | 4318 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) | 
|  | 4319 | { | 
|  | 4320 | dw_tag_t tag = die->Tag(); | 
|  | 4321 | switch (tag) | 
|  | 4322 | { | 
|  | 4323 | case DW_TAG_formal_parameter: | 
|  | 4324 | { | 
|  | 4325 | DWARFDebugInfoEntry::Attributes attributes; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4326 | 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] | 4327 | if (num_attributes > 0) | 
|  | 4328 | { | 
|  | 4329 | const char *name = NULL; | 
|  | 4330 | Declaration decl; | 
|  | 4331 | dw_offset_t param_type_die_offset = DW_INVALID_OFFSET; | 
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 4332 | bool is_artificial = false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4333 | // one of None, Auto, Register, Extern, Static, PrivateExtern | 
|  | 4334 |  | 
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 4335 | clang::StorageClass storage = clang::SC_None; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4336 | uint32_t i; | 
|  | 4337 | for (i=0; i<num_attributes; ++i) | 
|  | 4338 | { | 
|  | 4339 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 4340 | DWARFFormValue form_value; | 
|  | 4341 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 4342 | { | 
|  | 4343 | switch (attr) | 
|  | 4344 | { | 
|  | 4345 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 4346 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 4347 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 4348 | 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] | 4349 | case DW_AT_type:        param_type_die_offset = form_value.Reference(); break; | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 4350 | case DW_AT_artificial:  is_artificial = form_value.Boolean(); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4351 | case DW_AT_location: | 
|  | 4352 | //                          if (form_value.BlockData()) | 
|  | 4353 | //                          { | 
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 4354 | //                              const DWARFDataExtractor& debug_info_data = debug_info(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4355 | //                              uint32_t block_length = form_value.Unsigned(); | 
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 4356 | //                              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] | 4357 | //                          } | 
|  | 4358 | //                          else | 
|  | 4359 | //                          { | 
|  | 4360 | //                          } | 
|  | 4361 | //                          break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4362 | case DW_AT_const_value: | 
|  | 4363 | case DW_AT_default_value: | 
|  | 4364 | case DW_AT_description: | 
|  | 4365 | case DW_AT_endianity: | 
|  | 4366 | case DW_AT_is_optional: | 
|  | 4367 | case DW_AT_segment: | 
|  | 4368 | case DW_AT_variable_parameter: | 
|  | 4369 | default: | 
|  | 4370 | case DW_AT_abstract_origin: | 
|  | 4371 | case DW_AT_sibling: | 
|  | 4372 | break; | 
|  | 4373 | } | 
|  | 4374 | } | 
|  | 4375 | } | 
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 4376 |  | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4377 | bool skip = false; | 
|  | 4378 | if (skip_artificial) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4379 | { | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4380 | if (is_artificial) | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4381 | { | 
|  | 4382 | // In order to determine if a C++ member function is | 
|  | 4383 | // "const" we have to look at the const-ness of "this"... | 
|  | 4384 | // Ugly, but that | 
|  | 4385 | if (arg_idx == 0) | 
|  | 4386 | { | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 4387 | if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind())) | 
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 4388 | { | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4389 | // Often times compilers omit the "this" name for the | 
|  | 4390 | // specification DIEs, so we can't rely upon the name | 
|  | 4391 | // being in the formal parameter DIE... | 
|  | 4392 | if (name == NULL || ::strcmp(name, "this")==0) | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4393 | { | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4394 | Type *this_type = ResolveTypeUID (param_type_die_offset); | 
|  | 4395 | if (this_type) | 
|  | 4396 | { | 
|  | 4397 | uint32_t encoding_mask = this_type->GetEncodingMask(); | 
|  | 4398 | if (encoding_mask & Type::eEncodingIsPointerUID) | 
|  | 4399 | { | 
|  | 4400 | is_static = false; | 
|  | 4401 |  | 
|  | 4402 | if (encoding_mask & (1u << Type::eEncodingIsConstUID)) | 
|  | 4403 | type_quals |= clang::Qualifiers::Const; | 
|  | 4404 | if (encoding_mask & (1u << Type::eEncodingIsVolatileUID)) | 
|  | 4405 | type_quals |= clang::Qualifiers::Volatile; | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4406 | } | 
|  | 4407 | } | 
|  | 4408 | } | 
|  | 4409 | } | 
|  | 4410 | } | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4411 | skip = true; | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4412 | } | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4413 | else | 
|  | 4414 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4415 |  | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4416 | // HACK: Objective C formal parameters "self" and "_cmd" | 
|  | 4417 | // are not marked as artificial in the DWARF... | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4418 | CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); | 
|  | 4419 | if (comp_unit) | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4420 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4421 | switch (comp_unit->GetLanguage()) | 
|  | 4422 | { | 
|  | 4423 | case eLanguageTypeObjC: | 
|  | 4424 | case eLanguageTypeObjC_plus_plus: | 
|  | 4425 | if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0)) | 
|  | 4426 | skip = true; | 
|  | 4427 | break; | 
|  | 4428 | default: | 
|  | 4429 | break; | 
|  | 4430 | } | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4431 | } | 
|  | 4432 | } | 
|  | 4433 | } | 
|  | 4434 |  | 
|  | 4435 | if (!skip) | 
|  | 4436 | { | 
|  | 4437 | Type *type = ResolveTypeUID(param_type_die_offset); | 
|  | 4438 | if (type) | 
|  | 4439 | { | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 4440 | function_param_types.push_back (type->GetClangForwardType()); | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4441 |  | 
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 4442 | clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name, | 
|  | 4443 | type->GetClangForwardType(), | 
|  | 4444 | storage); | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4445 | assert(param_var_decl); | 
|  | 4446 | function_param_decls.push_back(param_var_decl); | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 4447 |  | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 4448 | GetClangASTContext().SetMetadataAsUserID (param_var_decl, MakeUserID(die->GetOffset())); | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4449 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4450 | } | 
|  | 4451 | } | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4452 | arg_idx++; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4453 | } | 
|  | 4454 | break; | 
|  | 4455 |  | 
| Greg Clayton | 0396975 | 2014-02-24 18:53:11 +0000 | [diff] [blame] | 4456 | case DW_TAG_unspecified_parameters: | 
|  | 4457 | is_variadic = true; | 
|  | 4458 | break; | 
|  | 4459 |  | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 4460 | case DW_TAG_template_type_parameter: | 
|  | 4461 | case DW_TAG_template_value_parameter: | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 4462 | // The one caller of this was never using the template_param_infos, | 
|  | 4463 | // and the local variable was taking up a large amount of stack space | 
|  | 4464 | // in SymbolFileDWARF::ParseType() so this was removed. If we ever need | 
|  | 4465 | // the template params back, we can add them back. | 
|  | 4466 | // ParseTemplateDIE (dwarf_cu, die, template_param_infos); | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 4467 | break; | 
|  | 4468 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4469 | default: | 
|  | 4470 | break; | 
|  | 4471 | } | 
|  | 4472 | } | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4473 | return arg_idx; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4474 | } | 
|  | 4475 |  | 
|  | 4476 | size_t | 
|  | 4477 | SymbolFileDWARF::ParseChildEnumerators | 
|  | 4478 | ( | 
|  | 4479 | const SymbolContext& sc, | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 4480 | lldb_private::ClangASTType &clang_type, | 
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 4481 | bool is_signed, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4482 | uint32_t enumerator_byte_size, | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4483 | DWARFCompileUnit* dwarf_cu, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4484 | const DWARFDebugInfoEntry *parent_die | 
|  | 4485 | ) | 
|  | 4486 | { | 
|  | 4487 | if (parent_die == NULL) | 
|  | 4488 | return 0; | 
|  | 4489 |  | 
|  | 4490 | size_t enumerators_added = 0; | 
|  | 4491 | const DWARFDebugInfoEntry *die; | 
| Todd Fiala | ee8bfc6 | 2014-09-11 17:29:12 +0000 | [diff] [blame] | 4492 | 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] | 4493 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4494 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) | 
|  | 4495 | { | 
|  | 4496 | const dw_tag_t tag = die->Tag(); | 
|  | 4497 | if (tag == DW_TAG_enumerator) | 
|  | 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 | { | 
|  | 4503 | const char *name = NULL; | 
|  | 4504 | bool got_value = false; | 
|  | 4505 | int64_t enum_value = 0; | 
|  | 4506 | Declaration decl; | 
|  | 4507 |  | 
|  | 4508 | uint32_t i; | 
|  | 4509 | for (i=0; i<num_child_attributes; ++i) | 
|  | 4510 | { | 
|  | 4511 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 4512 | DWARFFormValue form_value; | 
|  | 4513 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 4514 | { | 
|  | 4515 | switch (attr) | 
|  | 4516 | { | 
|  | 4517 | case DW_AT_const_value: | 
|  | 4518 | got_value = true; | 
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 4519 | if (is_signed) | 
|  | 4520 | enum_value = form_value.Signed(); | 
|  | 4521 | else | 
|  | 4522 | enum_value = form_value.Unsigned(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4523 | break; | 
|  | 4524 |  | 
|  | 4525 | case DW_AT_name: | 
|  | 4526 | name = form_value.AsCString(&get_debug_str_data()); | 
|  | 4527 | break; | 
|  | 4528 |  | 
|  | 4529 | case DW_AT_description: | 
|  | 4530 | default: | 
|  | 4531 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 4532 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 4533 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 4534 | case DW_AT_sibling: | 
|  | 4535 | break; | 
|  | 4536 | } | 
|  | 4537 | } | 
|  | 4538 | } | 
|  | 4539 |  | 
|  | 4540 | if (name && name[0] && got_value) | 
|  | 4541 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 4542 | clang_type.AddEnumerationValueToEnumerationType (clang_type.GetEnumerationIntegerType(), | 
|  | 4543 | decl, | 
|  | 4544 | name, | 
|  | 4545 | enum_value, | 
|  | 4546 | enumerator_byte_size * 8); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4547 | ++enumerators_added; | 
|  | 4548 | } | 
|  | 4549 | } | 
|  | 4550 | } | 
|  | 4551 | } | 
|  | 4552 | return enumerators_added; | 
|  | 4553 | } | 
|  | 4554 |  | 
|  | 4555 | void | 
|  | 4556 | SymbolFileDWARF::ParseChildArrayInfo | 
|  | 4557 | ( | 
|  | 4558 | const SymbolContext& sc, | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4559 | DWARFCompileUnit* dwarf_cu, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4560 | const DWARFDebugInfoEntry *parent_die, | 
|  | 4561 | int64_t& first_index, | 
|  | 4562 | std::vector<uint64_t>& element_orders, | 
|  | 4563 | uint32_t& byte_stride, | 
|  | 4564 | uint32_t& bit_stride | 
|  | 4565 | ) | 
|  | 4566 | { | 
|  | 4567 | if (parent_die == NULL) | 
|  | 4568 | return; | 
|  | 4569 |  | 
|  | 4570 | const DWARFDebugInfoEntry *die; | 
| Todd Fiala | ee8bfc6 | 2014-09-11 17:29:12 +0000 | [diff] [blame] | 4571 | 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] | 4572 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) | 
|  | 4573 | { | 
|  | 4574 | const dw_tag_t tag = die->Tag(); | 
|  | 4575 | switch (tag) | 
|  | 4576 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4577 | case DW_TAG_subrange_type: | 
|  | 4578 | { | 
|  | 4579 | DWARFDebugInfoEntry::Attributes attributes; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4580 | 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] | 4581 | if (num_child_attributes > 0) | 
|  | 4582 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4583 | uint64_t num_elements = 0; | 
|  | 4584 | uint64_t lower_bound = 0; | 
|  | 4585 | uint64_t upper_bound = 0; | 
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4586 | bool upper_bound_valid = false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4587 | uint32_t i; | 
|  | 4588 | for (i=0; i<num_child_attributes; ++i) | 
|  | 4589 | { | 
|  | 4590 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 4591 | DWARFFormValue form_value; | 
|  | 4592 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 4593 | { | 
|  | 4594 | switch (attr) | 
|  | 4595 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4596 | case DW_AT_name: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4597 | break; | 
|  | 4598 |  | 
|  | 4599 | case DW_AT_count: | 
|  | 4600 | num_elements = form_value.Unsigned(); | 
|  | 4601 | break; | 
|  | 4602 |  | 
|  | 4603 | case DW_AT_bit_stride: | 
|  | 4604 | bit_stride = form_value.Unsigned(); | 
|  | 4605 | break; | 
|  | 4606 |  | 
|  | 4607 | case DW_AT_byte_stride: | 
|  | 4608 | byte_stride = form_value.Unsigned(); | 
|  | 4609 | break; | 
|  | 4610 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4611 | case DW_AT_lower_bound: | 
|  | 4612 | lower_bound = form_value.Unsigned(); | 
|  | 4613 | break; | 
|  | 4614 |  | 
|  | 4615 | case DW_AT_upper_bound: | 
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4616 | upper_bound_valid = true; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4617 | upper_bound = form_value.Unsigned(); | 
|  | 4618 | break; | 
|  | 4619 |  | 
|  | 4620 | default: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4621 | case DW_AT_abstract_origin: | 
|  | 4622 | case DW_AT_accessibility: | 
|  | 4623 | case DW_AT_allocated: | 
|  | 4624 | case DW_AT_associated: | 
|  | 4625 | case DW_AT_data_location: | 
|  | 4626 | case DW_AT_declaration: | 
|  | 4627 | case DW_AT_description: | 
|  | 4628 | case DW_AT_sibling: | 
|  | 4629 | case DW_AT_threads_scaled: | 
|  | 4630 | case DW_AT_type: | 
|  | 4631 | case DW_AT_visibility: | 
|  | 4632 | break; | 
|  | 4633 | } | 
|  | 4634 | } | 
|  | 4635 | } | 
|  | 4636 |  | 
| Greg Clayton | e6a0779 | 2012-12-05 21:59:39 +0000 | [diff] [blame] | 4637 | if (num_elements == 0) | 
|  | 4638 | { | 
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4639 | if (upper_bound_valid && upper_bound >= lower_bound) | 
| Greg Clayton | e6a0779 | 2012-12-05 21:59:39 +0000 | [diff] [blame] | 4640 | num_elements = upper_bound - lower_bound + 1; | 
|  | 4641 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4642 |  | 
| Sean Callanan | ec979ba | 2012-10-22 23:56:48 +0000 | [diff] [blame] | 4643 | element_orders.push_back (num_elements); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4644 | } | 
|  | 4645 | } | 
|  | 4646 | break; | 
|  | 4647 | } | 
|  | 4648 | } | 
|  | 4649 | } | 
|  | 4650 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4651 | TypeSP | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4652 | SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4653 | { | 
|  | 4654 | TypeSP type_sp; | 
|  | 4655 | if (die != NULL) | 
|  | 4656 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4657 | assert(dwarf_cu != NULL); | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4658 | Type *type_ptr = m_die_to_type.lookup (die); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4659 | if (type_ptr == NULL) | 
|  | 4660 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4661 | CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu); | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4662 | assert (lldb_cu); | 
|  | 4663 | SymbolContext sc(lldb_cu); | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4664 | type_sp = ParseType(sc, dwarf_cu, die, NULL); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4665 | } | 
|  | 4666 | else if (type_ptr != DIE_IS_BEING_PARSED) | 
|  | 4667 | { | 
|  | 4668 | // Grab the existing type from the master types lists | 
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 4669 | type_sp = type_ptr->shared_from_this(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4670 | } | 
|  | 4671 |  | 
|  | 4672 | } | 
|  | 4673 | return type_sp; | 
|  | 4674 | } | 
|  | 4675 |  | 
|  | 4676 | clang::DeclContext * | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4677 | SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4678 | { | 
|  | 4679 | if (die_offset != DW_INVALID_OFFSET) | 
|  | 4680 | { | 
|  | 4681 | DWARFCompileUnitSP cu_sp; | 
|  | 4682 | const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp); | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4683 | return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4684 | } | 
|  | 4685 | return NULL; | 
|  | 4686 | } | 
|  | 4687 |  | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4688 | clang::DeclContext * | 
|  | 4689 | SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset) | 
|  | 4690 | { | 
|  | 4691 | if (die_offset != DW_INVALID_OFFSET) | 
|  | 4692 | { | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4693 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 4694 | if (debug_info) | 
|  | 4695 | { | 
|  | 4696 | DWARFCompileUnitSP cu_sp; | 
|  | 4697 | const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp); | 
|  | 4698 | if (die) | 
|  | 4699 | return GetClangDeclContextForDIE (sc, cu_sp.get(), die); | 
|  | 4700 | } | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4701 | } | 
|  | 4702 | return NULL; | 
|  | 4703 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4704 |  | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4705 | clang::NamespaceDecl * | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4706 | SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die) | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4707 | { | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4708 | if (die && die->Tag() == DW_TAG_namespace) | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4709 | { | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4710 | // See if we already parsed this namespace DIE and associated it with a | 
|  | 4711 | // uniqued namespace declaration | 
|  | 4712 | clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]); | 
|  | 4713 | if (namespace_decl) | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4714 | return namespace_decl; | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4715 | else | 
|  | 4716 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4717 | const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL); | 
|  | 4718 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL); | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4719 | namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4720 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4721 | if (log) | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4722 | { | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4723 | if (namespace_name) | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4724 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4725 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4726 | "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] | 4727 | static_cast<void*>(GetClangASTContext().getASTContext()), | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4728 | MakeUserID(die->GetOffset()), | 
|  | 4729 | namespace_name, | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4730 | static_cast<void*>(namespace_decl), | 
|  | 4731 | static_cast<void*>(namespace_decl->getOriginalNamespace())); | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4732 | } | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4733 | else | 
|  | 4734 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4735 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4736 | "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] | 4737 | static_cast<void*>(GetClangASTContext().getASTContext()), | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4738 | MakeUserID(die->GetOffset()), | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4739 | static_cast<void*>(namespace_decl), | 
|  | 4740 | static_cast<void*>(namespace_decl->getOriginalNamespace())); | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4741 | } | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4742 | } | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4743 |  | 
|  | 4744 | if (namespace_decl) | 
|  | 4745 | LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die); | 
|  | 4746 | return namespace_decl; | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4747 | } | 
|  | 4748 | } | 
|  | 4749 | return NULL; | 
|  | 4750 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4751 |  | 
|  | 4752 | clang::DeclContext * | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4753 | SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4754 | { | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4755 | clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die); | 
|  | 4756 | if (clang_decl_ctx) | 
|  | 4757 | return clang_decl_ctx; | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4758 | // If this DIE has a specification, or an abstract origin, then trace to those. | 
|  | 4759 |  | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4760 | 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] | 4761 | if (die_offset != DW_INVALID_OFFSET) | 
|  | 4762 | return GetClangDeclContextForDIEOffset (sc, die_offset); | 
|  | 4763 |  | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4764 | 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] | 4765 | if (die_offset != DW_INVALID_OFFSET) | 
|  | 4766 | return GetClangDeclContextForDIEOffset (sc, die_offset); | 
|  | 4767 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4768 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 4769 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4770 | 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] | 4771 | // This is the DIE we want.  Parse it, then query our map. | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4772 | bool assert_not_being_parsed = true; | 
|  | 4773 | ResolveTypeUID (cu, die, assert_not_being_parsed); | 
|  | 4774 |  | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4775 | clang_decl_ctx = GetCachedClangDeclContextForDIE (die); | 
|  | 4776 |  | 
|  | 4777 | return clang_decl_ctx; | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4778 | } | 
|  | 4779 |  | 
|  | 4780 | clang::DeclContext * | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4781 | 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] | 4782 | { | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4783 | if (m_clang_tu_decl == NULL) | 
|  | 4784 | m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4785 |  | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4786 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4787 |  | 
|  | 4788 | if (decl_ctx_die_copy) | 
|  | 4789 | *decl_ctx_die_copy = decl_ctx_die; | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4790 |  | 
|  | 4791 | if (decl_ctx_die) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4792 | { | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4793 |  | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4794 | DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die); | 
|  | 4795 | if (pos != m_die_to_decl_ctx.end()) | 
|  | 4796 | return pos->second; | 
|  | 4797 |  | 
|  | 4798 | switch (decl_ctx_die->Tag()) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4799 | { | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4800 | case DW_TAG_compile_unit: | 
|  | 4801 | return m_clang_tu_decl; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4802 |  | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4803 | case DW_TAG_namespace: | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4804 | return ResolveNamespaceDIE (cu, decl_ctx_die); | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4805 | break; | 
|  | 4806 |  | 
|  | 4807 | case DW_TAG_structure_type: | 
|  | 4808 | case DW_TAG_union_type: | 
|  | 4809 | case DW_TAG_class_type: | 
|  | 4810 | { | 
|  | 4811 | Type* type = ResolveType (cu, decl_ctx_die); | 
|  | 4812 | if (type) | 
|  | 4813 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 4814 | clang::DeclContext *decl_ctx = type->GetClangForwardType().GetDeclContextForType (); | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4815 | if (decl_ctx) | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4816 | { | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4817 | LinkDeclContextToDIE (decl_ctx, decl_ctx_die); | 
|  | 4818 | if (decl_ctx) | 
|  | 4819 | return decl_ctx; | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4820 | } | 
|  | 4821 | } | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4822 | } | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4823 | break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4824 |  | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4825 | default: | 
|  | 4826 | break; | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4827 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4828 | } | 
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 4829 | return m_clang_tu_decl; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4830 | } | 
|  | 4831 |  | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4832 |  | 
|  | 4833 | const DWARFDebugInfoEntry * | 
|  | 4834 | SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) | 
|  | 4835 | { | 
|  | 4836 | if (cu && die) | 
|  | 4837 | { | 
|  | 4838 | const DWARFDebugInfoEntry * const decl_die = die; | 
|  | 4839 |  | 
|  | 4840 | while (die != NULL) | 
|  | 4841 | { | 
|  | 4842 | // If this is the original DIE that we are searching for a declaration | 
|  | 4843 | // for, then don't look in the cache as we don't want our own decl | 
|  | 4844 | // context to be our decl context... | 
|  | 4845 | if (decl_die != die) | 
|  | 4846 | { | 
|  | 4847 | switch (die->Tag()) | 
|  | 4848 | { | 
|  | 4849 | case DW_TAG_compile_unit: | 
|  | 4850 | case DW_TAG_namespace: | 
|  | 4851 | case DW_TAG_structure_type: | 
|  | 4852 | case DW_TAG_union_type: | 
|  | 4853 | case DW_TAG_class_type: | 
|  | 4854 | return die; | 
|  | 4855 |  | 
|  | 4856 | default: | 
|  | 4857 | break; | 
|  | 4858 | } | 
|  | 4859 | } | 
|  | 4860 |  | 
|  | 4861 | dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET); | 
|  | 4862 | if (die_offset != DW_INVALID_OFFSET) | 
|  | 4863 | { | 
|  | 4864 | DWARFCompileUnit *spec_cu = cu; | 
|  | 4865 | const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu); | 
|  | 4866 | const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die); | 
|  | 4867 | if (spec_die_decl_ctx_die) | 
|  | 4868 | return spec_die_decl_ctx_die; | 
|  | 4869 | } | 
|  | 4870 |  | 
|  | 4871 | die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET); | 
|  | 4872 | if (die_offset != DW_INVALID_OFFSET) | 
|  | 4873 | { | 
|  | 4874 | DWARFCompileUnit *abs_cu = cu; | 
|  | 4875 | const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu); | 
|  | 4876 | const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die); | 
|  | 4877 | if (abs_die_decl_ctx_die) | 
|  | 4878 | return abs_die_decl_ctx_die; | 
|  | 4879 | } | 
|  | 4880 |  | 
|  | 4881 | die = die->GetParent(); | 
|  | 4882 | } | 
|  | 4883 | } | 
|  | 4884 | return NULL; | 
|  | 4885 | } | 
|  | 4886 |  | 
|  | 4887 |  | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4888 | Symbol * | 
|  | 4889 | SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name) | 
|  | 4890 | { | 
|  | 4891 | Symbol *objc_class_symbol = NULL; | 
|  | 4892 | if (m_obj_file) | 
|  | 4893 | { | 
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 4894 | Symtab *symtab = m_obj_file->GetSymtab (); | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4895 | if (symtab) | 
|  | 4896 | { | 
|  | 4897 | objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name, | 
|  | 4898 | eSymbolTypeObjCClass, | 
|  | 4899 | Symtab::eDebugNo, | 
|  | 4900 | Symtab::eVisibilityAny); | 
|  | 4901 | } | 
|  | 4902 | } | 
|  | 4903 | return objc_class_symbol; | 
|  | 4904 | } | 
|  | 4905 |  | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4906 | // Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't | 
|  | 4907 | // then we can end up looking through all class types for a complete type and never find | 
|  | 4908 | // the full definition. We need to know if this attribute is supported, so we determine | 
|  | 4909 | // this here and cache th result. We also need to worry about the debug map DWARF file | 
|  | 4910 | // if we are doing darwin DWARF in .o file debugging. | 
|  | 4911 | bool | 
|  | 4912 | SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu) | 
|  | 4913 | { | 
|  | 4914 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate) | 
|  | 4915 | { | 
|  | 4916 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo; | 
|  | 4917 | if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type()) | 
|  | 4918 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; | 
|  | 4919 | else | 
|  | 4920 | { | 
|  | 4921 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 4922 | const uint32_t num_compile_units = GetNumCompileUnits(); | 
|  | 4923 | for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) | 
|  | 4924 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4925 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); | 
|  | 4926 | 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] | 4927 | { | 
|  | 4928 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; | 
|  | 4929 | break; | 
|  | 4930 | } | 
|  | 4931 | } | 
|  | 4932 | } | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 4933 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ()) | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4934 | return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this); | 
|  | 4935 | } | 
|  | 4936 | return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes; | 
|  | 4937 | } | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4938 |  | 
|  | 4939 | // This function can be used when a DIE is found that is a forward declaration | 
|  | 4940 | // DIE and we want to try and find a type that has the complete definition. | 
|  | 4941 | TypeSP | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4942 | SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die, | 
|  | 4943 | const ConstString &type_name, | 
|  | 4944 | bool must_be_implementation) | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4945 | { | 
|  | 4946 |  | 
|  | 4947 | TypeSP type_sp; | 
|  | 4948 |  | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4949 | if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name))) | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4950 | return type_sp; | 
|  | 4951 |  | 
|  | 4952 | DIEArray die_offsets; | 
|  | 4953 |  | 
|  | 4954 | if (m_using_apple_tables) | 
|  | 4955 | { | 
|  | 4956 | if (m_apple_types_ap.get()) | 
|  | 4957 | { | 
|  | 4958 | const char *name_cstr = type_name.GetCString(); | 
| Greg Clayton | 68221ec | 2012-01-18 20:58:12 +0000 | [diff] [blame] | 4959 | m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation); | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4960 | } | 
|  | 4961 | } | 
|  | 4962 | else | 
|  | 4963 | { | 
|  | 4964 | if (!m_indexed) | 
|  | 4965 | Index (); | 
|  | 4966 |  | 
|  | 4967 | m_type_index.Find (type_name, die_offsets); | 
|  | 4968 | } | 
|  | 4969 |  | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4970 | const size_t num_matches = die_offsets.size(); | 
|  | 4971 |  | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4972 | DWARFCompileUnit* type_cu = NULL; | 
|  | 4973 | const DWARFDebugInfoEntry* type_die = NULL; | 
|  | 4974 | if (num_matches) | 
|  | 4975 | { | 
|  | 4976 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 4977 | for (size_t i=0; i<num_matches; ++i) | 
|  | 4978 | { | 
|  | 4979 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 4980 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); | 
|  | 4981 |  | 
|  | 4982 | if (type_die) | 
|  | 4983 | { | 
|  | 4984 | bool try_resolving_type = false; | 
|  | 4985 |  | 
|  | 4986 | // Don't try and resolve the DIE we are looking for with the DIE itself! | 
|  | 4987 | if (type_die != die) | 
|  | 4988 | { | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4989 | switch (type_die->Tag()) | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4990 | { | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4991 | case DW_TAG_class_type: | 
|  | 4992 | case DW_TAG_structure_type: | 
|  | 4993 | try_resolving_type = true; | 
|  | 4994 | break; | 
|  | 4995 | default: | 
|  | 4996 | break; | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4997 | } | 
|  | 4998 | } | 
|  | 4999 |  | 
|  | 5000 | if (try_resolving_type) | 
|  | 5001 | { | 
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 5002 | if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type()) | 
|  | 5003 | 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] | 5004 |  | 
|  | 5005 | if (try_resolving_type) | 
|  | 5006 | { | 
|  | 5007 | Type *resolved_type = ResolveType (type_cu, type_die, false); | 
|  | 5008 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) | 
|  | 5009 | { | 
| Ed Maste | a0191d1 | 2013-10-17 20:42:56 +0000 | [diff] [blame] | 5010 | 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] | 5011 | MakeUserID(die->GetOffset()), | 
| Jim Ingham | 4af5961 | 2014-12-19 19:20:44 +0000 | [diff] [blame] | 5012 | m_obj_file->GetFileSpec().GetFilename().AsCString("<Unknown>"), | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5013 | MakeUserID(type_die->GetOffset()), | 
|  | 5014 | MakeUserID(type_cu->GetOffset())); | 
|  | 5015 |  | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5016 | if (die) | 
|  | 5017 | m_die_to_type[die] = resolved_type; | 
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 5018 | type_sp = resolved_type->shared_from_this(); | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5019 | break; | 
|  | 5020 | } | 
|  | 5021 | } | 
|  | 5022 | } | 
|  | 5023 | } | 
|  | 5024 | else | 
|  | 5025 | { | 
|  | 5026 | if (m_using_apple_tables) | 
|  | 5027 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5028 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", | 
|  | 5029 | die_offset, type_name.GetCString()); | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5030 | } | 
|  | 5031 | } | 
|  | 5032 |  | 
|  | 5033 | } | 
|  | 5034 | } | 
|  | 5035 | return type_sp; | 
|  | 5036 | } | 
|  | 5037 |  | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5038 |  | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5039 | //---------------------------------------------------------------------- | 
|  | 5040 | // This function helps to ensure that the declaration contexts match for | 
|  | 5041 | // two different DIEs. Often times debug information will refer to a | 
|  | 5042 | // forward declaration of a type (the equivalent of "struct my_struct;". | 
|  | 5043 | // There will often be a declaration of that type elsewhere that has the | 
|  | 5044 | // full definition. When we go looking for the full type "my_struct", we | 
|  | 5045 | // will find one or more matches in the accelerator tables and we will | 
|  | 5046 | // then need to make sure the type was in the same declaration context | 
|  | 5047 | // as the original DIE. This function can efficiently compare two DIEs | 
|  | 5048 | // and will return true when the declaration context matches, and false | 
|  | 5049 | // when they don't. | 
|  | 5050 | //---------------------------------------------------------------------- | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5051 | bool | 
|  | 5052 | SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1, | 
|  | 5053 | DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2) | 
|  | 5054 | { | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5055 | if (die1 == die2) | 
|  | 5056 | return true; | 
|  | 5057 |  | 
|  | 5058 | #if defined (LLDB_CONFIGURATION_DEBUG) | 
|  | 5059 | // You can't and shouldn't call this function with a compile unit from | 
|  | 5060 | // two different SymbolFileDWARF instances. | 
|  | 5061 | assert (DebugInfo()->ContainsCompileUnit (cu1)); | 
|  | 5062 | assert (DebugInfo()->ContainsCompileUnit (cu2)); | 
|  | 5063 | #endif | 
|  | 5064 |  | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5065 | DWARFDIECollection decl_ctx_1; | 
|  | 5066 | DWARFDIECollection decl_ctx_2; | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5067 | //The declaration DIE stack is a stack of the declaration context | 
|  | 5068 | // DIEs all the way back to the compile unit. If a type "T" is | 
|  | 5069 | // declared inside a class "B", and class "B" is declared inside | 
|  | 5070 | // a class "A" and class "A" is in a namespace "lldb", and the | 
|  | 5071 | // namespace is in a compile unit, there will be a stack of DIEs: | 
|  | 5072 | // | 
|  | 5073 | //   [0] DW_TAG_class_type for "B" | 
|  | 5074 | //   [1] DW_TAG_class_type for "A" | 
|  | 5075 | //   [2] DW_TAG_namespace  for "lldb" | 
|  | 5076 | //   [3] DW_TAG_compile_unit for the source file. | 
|  | 5077 | // | 
|  | 5078 | // We grab both contexts and make sure that everything matches | 
|  | 5079 | // all the way back to the compiler unit. | 
|  | 5080 |  | 
|  | 5081 | // First lets grab the decl contexts for both DIEs | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5082 | die1->GetDeclContextDIEs (this, cu1, decl_ctx_1); | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5083 | die2->GetDeclContextDIEs (this, cu2, decl_ctx_2); | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5084 | // Make sure the context arrays have the same size, otherwise | 
|  | 5085 | // we are done | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5086 | const size_t count1 = decl_ctx_1.Size(); | 
|  | 5087 | const size_t count2 = decl_ctx_2.Size(); | 
|  | 5088 | if (count1 != count2) | 
|  | 5089 | return false; | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5090 |  | 
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 5091 | // 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] | 5092 | // compile unit. If they don't, then we are done. | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5093 | const DWARFDebugInfoEntry *decl_ctx_die1; | 
|  | 5094 | const DWARFDebugInfoEntry *decl_ctx_die2; | 
|  | 5095 | size_t i; | 
|  | 5096 | for (i=0; i<count1; i++) | 
|  | 5097 | { | 
|  | 5098 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); | 
|  | 5099 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); | 
|  | 5100 | if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag()) | 
|  | 5101 | return false; | 
|  | 5102 | } | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5103 | #if defined LLDB_CONFIGURATION_DEBUG | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5104 |  | 
|  | 5105 | // Make sure the top item in the decl context die array is always | 
|  | 5106 | // DW_TAG_compile_unit. If it isn't then something went wrong in | 
|  | 5107 | // the DWARFDebugInfoEntry::GetDeclContextDIEs() function... | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5108 | assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit); | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5109 |  | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5110 | #endif | 
|  | 5111 | // Always skip the compile unit when comparing by only iterating up to | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5112 | // "count - 1". Here we compare the names as we go. | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5113 | for (i=0; i<count1 - 1; i++) | 
|  | 5114 | { | 
|  | 5115 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); | 
|  | 5116 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); | 
|  | 5117 | const char *name1 = decl_ctx_die1->GetName(this, cu1); | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5118 | const char *name2 = decl_ctx_die2->GetName(this, cu2); | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5119 | // If the string was from a DW_FORM_strp, then the pointer will often | 
|  | 5120 | // be the same! | 
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 5121 | if (name1 == name2) | 
|  | 5122 | continue; | 
|  | 5123 |  | 
|  | 5124 | // Name pointers are not equal, so only compare the strings | 
|  | 5125 | // if both are not NULL. | 
|  | 5126 | if (name1 && name2) | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5127 | { | 
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 5128 | // If the strings don't compare, we are done... | 
|  | 5129 | if (strcmp(name1, name2) != 0) | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5130 | return false; | 
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 5131 | } | 
|  | 5132 | else | 
|  | 5133 | { | 
|  | 5134 | // One name was NULL while the other wasn't | 
|  | 5135 | return false; | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5136 | } | 
|  | 5137 | } | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 5138 | // We made it through all of the checks and the declaration contexts | 
|  | 5139 | // are equal. | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 5140 | return true; | 
|  | 5141 | } | 
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 5142 |  | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 5143 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5144 | TypeSP | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5145 | SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx) | 
|  | 5146 | { | 
|  | 5147 | TypeSP type_sp; | 
|  | 5148 |  | 
|  | 5149 | const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize(); | 
|  | 5150 | if (dwarf_decl_ctx_count > 0) | 
|  | 5151 | { | 
|  | 5152 | const ConstString type_name(dwarf_decl_ctx[0].name); | 
|  | 5153 | const dw_tag_t tag = dwarf_decl_ctx[0].tag; | 
|  | 5154 |  | 
|  | 5155 | if (type_name) | 
|  | 5156 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5157 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5158 | if (log) | 
|  | 5159 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5160 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5161 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')", | 
|  | 5162 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), | 
|  | 5163 | dwarf_decl_ctx.GetQualifiedName()); | 
|  | 5164 | } | 
|  | 5165 |  | 
|  | 5166 | DIEArray die_offsets; | 
|  | 5167 |  | 
|  | 5168 | if (m_using_apple_tables) | 
|  | 5169 | { | 
|  | 5170 | if (m_apple_types_ap.get()) | 
|  | 5171 | { | 
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 5172 | const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag); | 
|  | 5173 | const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash); | 
|  | 5174 | if (has_tag && has_qualified_name_hash) | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5175 | { | 
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 5176 | const char *qualified_name = dwarf_decl_ctx.GetQualifiedName(); | 
|  | 5177 | const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name); | 
|  | 5178 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5179 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()"); | 
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 5180 | m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets); | 
|  | 5181 | } | 
|  | 5182 | else if (has_tag) | 
|  | 5183 | { | 
|  | 5184 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5185 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()"); | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5186 | m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets); | 
|  | 5187 | } | 
|  | 5188 | else | 
|  | 5189 | { | 
|  | 5190 | m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets); | 
|  | 5191 | } | 
|  | 5192 | } | 
|  | 5193 | } | 
|  | 5194 | else | 
|  | 5195 | { | 
|  | 5196 | if (!m_indexed) | 
|  | 5197 | Index (); | 
|  | 5198 |  | 
|  | 5199 | m_type_index.Find (type_name, die_offsets); | 
|  | 5200 | } | 
|  | 5201 |  | 
|  | 5202 | const size_t num_matches = die_offsets.size(); | 
|  | 5203 |  | 
|  | 5204 |  | 
|  | 5205 | DWARFCompileUnit* type_cu = NULL; | 
|  | 5206 | const DWARFDebugInfoEntry* type_die = NULL; | 
|  | 5207 | if (num_matches) | 
|  | 5208 | { | 
|  | 5209 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 5210 | for (size_t i=0; i<num_matches; ++i) | 
|  | 5211 | { | 
|  | 5212 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 5213 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); | 
|  | 5214 |  | 
|  | 5215 | if (type_die) | 
|  | 5216 | { | 
|  | 5217 | bool try_resolving_type = false; | 
|  | 5218 |  | 
|  | 5219 | // Don't try and resolve the DIE we are looking for with the DIE itself! | 
|  | 5220 | const dw_tag_t type_tag = type_die->Tag(); | 
|  | 5221 | // Make sure the tags match | 
|  | 5222 | if (type_tag == tag) | 
|  | 5223 | { | 
|  | 5224 | // The tags match, lets try resolving this type | 
|  | 5225 | try_resolving_type = true; | 
|  | 5226 | } | 
|  | 5227 | else | 
|  | 5228 | { | 
|  | 5229 | // The tags don't match, but we need to watch our for a | 
|  | 5230 | // forward declaration for a struct and ("struct foo") | 
|  | 5231 | // ends up being a class ("class foo { ... };") or | 
|  | 5232 | // vice versa. | 
|  | 5233 | switch (type_tag) | 
|  | 5234 | { | 
|  | 5235 | case DW_TAG_class_type: | 
|  | 5236 | // We had a "class foo", see if we ended up with a "struct foo { ... };" | 
|  | 5237 | try_resolving_type = (tag == DW_TAG_structure_type); | 
|  | 5238 | break; | 
|  | 5239 | case DW_TAG_structure_type: | 
|  | 5240 | // We had a "struct foo", see if we ended up with a "class foo { ... };" | 
|  | 5241 | try_resolving_type = (tag == DW_TAG_class_type); | 
|  | 5242 | break; | 
|  | 5243 | default: | 
|  | 5244 | // Tags don't match, don't event try to resolve | 
|  | 5245 | // using this type whose name matches.... | 
|  | 5246 | break; | 
|  | 5247 | } | 
|  | 5248 | } | 
|  | 5249 |  | 
|  | 5250 | if (try_resolving_type) | 
|  | 5251 | { | 
|  | 5252 | DWARFDeclContext type_dwarf_decl_ctx; | 
|  | 5253 | type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx); | 
|  | 5254 |  | 
|  | 5255 | if (log) | 
|  | 5256 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5257 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5258 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)", | 
|  | 5259 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), | 
|  | 5260 | dwarf_decl_ctx.GetQualifiedName(), | 
|  | 5261 | type_die->GetOffset(), | 
|  | 5262 | type_dwarf_decl_ctx.GetQualifiedName()); | 
|  | 5263 | } | 
|  | 5264 |  | 
|  | 5265 | // Make sure the decl contexts match all the way up | 
|  | 5266 | if (dwarf_decl_ctx == type_dwarf_decl_ctx) | 
|  | 5267 | { | 
|  | 5268 | Type *resolved_type = ResolveType (type_cu, type_die, false); | 
|  | 5269 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) | 
|  | 5270 | { | 
|  | 5271 | type_sp = resolved_type->shared_from_this(); | 
|  | 5272 | break; | 
|  | 5273 | } | 
|  | 5274 | } | 
|  | 5275 | } | 
|  | 5276 | else | 
|  | 5277 | { | 
|  | 5278 | if (log) | 
|  | 5279 | { | 
|  | 5280 | std::string qualified_name; | 
|  | 5281 | type_die->GetQualifiedName(this, type_cu, qualified_name); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5282 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5283 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)", | 
|  | 5284 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), | 
|  | 5285 | dwarf_decl_ctx.GetQualifiedName(), | 
|  | 5286 | type_die->GetOffset(), | 
|  | 5287 | qualified_name.c_str()); | 
|  | 5288 | } | 
|  | 5289 | } | 
|  | 5290 | } | 
|  | 5291 | else | 
|  | 5292 | { | 
|  | 5293 | if (m_using_apple_tables) | 
|  | 5294 | { | 
|  | 5295 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", | 
|  | 5296 | die_offset, type_name.GetCString()); | 
|  | 5297 | } | 
|  | 5298 | } | 
|  | 5299 |  | 
|  | 5300 | } | 
|  | 5301 | } | 
|  | 5302 | } | 
|  | 5303 | } | 
|  | 5304 | return type_sp; | 
|  | 5305 | } | 
|  | 5306 |  | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5307 | bool | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5308 | SymbolFileDWARF::CopyUniqueClassMethodTypes (SymbolFileDWARF *src_symfile, | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5309 | Type *class_type, | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5310 | DWARFCompileUnit* src_cu, | 
|  | 5311 | const DWARFDebugInfoEntry *src_class_die, | 
|  | 5312 | DWARFCompileUnit* dst_cu, | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5313 | const DWARFDebugInfoEntry *dst_class_die, | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 5314 | DWARFDIECollection &failures) | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5315 | { | 
|  | 5316 | if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die) | 
|  | 5317 | return false; | 
|  | 5318 | if (src_class_die->Tag() != dst_class_die->Tag()) | 
|  | 5319 | return false; | 
|  | 5320 |  | 
|  | 5321 | // We need to complete the class type so we can get all of the method types | 
|  | 5322 | // parsed so we can then unique those types to their equivalent counterparts | 
|  | 5323 | // in "dst_cu" and "dst_class_die" | 
|  | 5324 | class_type->GetClangFullType(); | 
|  | 5325 |  | 
|  | 5326 | const DWARFDebugInfoEntry *src_die; | 
|  | 5327 | const DWARFDebugInfoEntry *dst_die; | 
|  | 5328 | UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die; | 
|  | 5329 | UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die; | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5330 | UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die_artificial; | 
|  | 5331 | UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die_artificial; | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5332 | for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling()) | 
|  | 5333 | { | 
|  | 5334 | if (src_die->Tag() == DW_TAG_subprogram) | 
|  | 5335 | { | 
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5336 | // Make sure this is a declaration and not a concrete instance by looking | 
|  | 5337 | // for DW_AT_declaration set to 1. Sometimes concrete function instances | 
|  | 5338 | // are placed inside the class definitions and shouldn't be included in | 
|  | 5339 | // the list of things are are tracking here. | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5340 | 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] | 5341 | { | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5342 | const char *src_name = src_die->GetMangledName (src_symfile, src_cu); | 
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5343 | if (src_name) | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5344 | { | 
|  | 5345 | ConstString src_const_name(src_name); | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5346 | if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_artificial, 0)) | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5347 | src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die); | 
|  | 5348 | else | 
|  | 5349 | src_name_to_die.Append(src_const_name.GetCString(), src_die); | 
|  | 5350 | } | 
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5351 | } | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5352 | } | 
|  | 5353 | } | 
|  | 5354 | for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling()) | 
|  | 5355 | { | 
|  | 5356 | if (dst_die->Tag() == DW_TAG_subprogram) | 
|  | 5357 | { | 
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5358 | // Make sure this is a declaration and not a concrete instance by looking | 
|  | 5359 | // for DW_AT_declaration set to 1. Sometimes concrete function instances | 
|  | 5360 | // are placed inside the class definitions and shouldn't be included in | 
|  | 5361 | // the list of things are are tracking here. | 
|  | 5362 | if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_declaration, 0) == 1) | 
|  | 5363 | { | 
|  | 5364 | const char *dst_name = dst_die->GetMangledName (this, dst_cu); | 
|  | 5365 | if (dst_name) | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5366 | { | 
|  | 5367 | ConstString dst_const_name(dst_name); | 
|  | 5368 | if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_artificial, 0)) | 
|  | 5369 | dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die); | 
|  | 5370 | else | 
|  | 5371 | dst_name_to_die.Append(dst_const_name.GetCString(), dst_die); | 
|  | 5372 | } | 
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5373 | } | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5374 | } | 
|  | 5375 | } | 
|  | 5376 | const uint32_t src_size = src_name_to_die.GetSize (); | 
|  | 5377 | const uint32_t dst_size = dst_name_to_die.GetSize (); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5378 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION)); | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5379 |  | 
|  | 5380 | // Is everything kosher so we can go through the members at top speed? | 
|  | 5381 | bool fast_path = true; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5382 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5383 | if (src_size != dst_size) | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5384 | { | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5385 | if (src_size != 0 && dst_size != 0) | 
|  | 5386 | { | 
|  | 5387 | if (log) | 
|  | 5388 | 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)", | 
|  | 5389 | src_class_die->GetOffset(), | 
|  | 5390 | dst_class_die->GetOffset(), | 
|  | 5391 | src_size, | 
|  | 5392 | dst_size); | 
|  | 5393 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5394 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5395 | fast_path = false; | 
|  | 5396 | } | 
|  | 5397 |  | 
|  | 5398 | uint32_t idx; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5399 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5400 | if (fast_path) | 
|  | 5401 | { | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5402 | for (idx = 0; idx < src_size; ++idx) | 
|  | 5403 | { | 
|  | 5404 | src_die = src_name_to_die.GetValueAtIndexUnchecked (idx); | 
|  | 5405 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx); | 
|  | 5406 |  | 
|  | 5407 | if (src_die->Tag() != dst_die->Tag()) | 
|  | 5408 | { | 
|  | 5409 | if (log) | 
|  | 5410 | 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)", | 
|  | 5411 | src_class_die->GetOffset(), | 
|  | 5412 | dst_class_die->GetOffset(), | 
|  | 5413 | src_die->GetOffset(), | 
|  | 5414 | DW_TAG_value_to_name(src_die->Tag()), | 
|  | 5415 | dst_die->GetOffset(), | 
|  | 5416 | DW_TAG_value_to_name(src_die->Tag())); | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5417 | fast_path = false; | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5418 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5419 |  | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5420 | const char *src_name = src_die->GetMangledName (src_symfile, src_cu); | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5421 | const char *dst_name = dst_die->GetMangledName (this, dst_cu); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5422 |  | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5423 | // Make sure the names match | 
|  | 5424 | if (src_name == dst_name || (strcmp (src_name, dst_name) == 0)) | 
|  | 5425 | continue; | 
|  | 5426 |  | 
|  | 5427 | if (log) | 
|  | 5428 | 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)", | 
|  | 5429 | src_class_die->GetOffset(), | 
|  | 5430 | dst_class_die->GetOffset(), | 
|  | 5431 | src_die->GetOffset(), | 
|  | 5432 | src_name, | 
|  | 5433 | dst_die->GetOffset(), | 
|  | 5434 | dst_name); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5435 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5436 | fast_path = false; | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5437 | } | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5438 | } | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5439 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5440 | // Now do the work of linking the DeclContexts and Types. | 
|  | 5441 | if (fast_path) | 
|  | 5442 | { | 
|  | 5443 | // We can do this quickly.  Just run across the tables index-for-index since | 
|  | 5444 | // we know each node has matching names and tags. | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5445 | for (idx = 0; idx < src_size; ++idx) | 
|  | 5446 | { | 
|  | 5447 | src_die = src_name_to_die.GetValueAtIndexUnchecked (idx); | 
|  | 5448 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5449 |  | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5450 | 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] | 5451 | if (src_decl_ctx) | 
|  | 5452 | { | 
|  | 5453 | if (log) | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5454 | log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", | 
|  | 5455 | static_cast<void*>(src_decl_ctx), | 
|  | 5456 | src_die->GetOffset(), dst_die->GetOffset()); | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5457 | LinkDeclContextToDIE (src_decl_ctx, dst_die); | 
|  | 5458 | } | 
|  | 5459 | else | 
|  | 5460 | { | 
|  | 5461 | if (log) | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5462 | log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found", | 
|  | 5463 | src_die->GetOffset(), dst_die->GetOffset()); | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5464 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5465 |  | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5466 | Type *src_child_type = m_die_to_type[src_die]; | 
|  | 5467 | if (src_child_type) | 
|  | 5468 | { | 
|  | 5469 | if (log) | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5470 | log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", | 
|  | 5471 | static_cast<void*>(src_child_type), | 
|  | 5472 | src_child_type->GetID(), | 
|  | 5473 | src_die->GetOffset(), dst_die->GetOffset()); | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5474 | m_die_to_type[dst_die] = src_child_type; | 
|  | 5475 | } | 
|  | 5476 | else | 
|  | 5477 | { | 
|  | 5478 | if (log) | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5479 | 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()); | 
|  | 5480 | } | 
|  | 5481 | } | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5482 | } | 
|  | 5483 | else | 
|  | 5484 | { | 
|  | 5485 | // We must do this slowly.  For each member of the destination, look | 
|  | 5486 | // up a member in the source with the same name, check its tag, and | 
|  | 5487 | // unique them if everything matches up.  Report failures. | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5488 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5489 | if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty()) | 
|  | 5490 | { | 
|  | 5491 | src_name_to_die.Sort(); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5492 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5493 | for (idx = 0; idx < dst_size; ++idx) | 
|  | 5494 | { | 
|  | 5495 | const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx); | 
|  | 5496 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx); | 
|  | 5497 | src_die = src_name_to_die.Find(dst_name, NULL); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5498 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5499 | if (src_die && (src_die->Tag() == dst_die->Tag())) | 
|  | 5500 | { | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5501 | 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] | 5502 | if (src_decl_ctx) | 
|  | 5503 | { | 
|  | 5504 | if (log) | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5505 | log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", | 
|  | 5506 | static_cast<void*>(src_decl_ctx), | 
|  | 5507 | src_die->GetOffset(), | 
|  | 5508 | dst_die->GetOffset()); | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5509 | LinkDeclContextToDIE (src_decl_ctx, dst_die); | 
|  | 5510 | } | 
|  | 5511 | else | 
|  | 5512 | { | 
|  | 5513 | if (log) | 
|  | 5514 | 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()); | 
|  | 5515 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5516 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5517 | Type *src_child_type = m_die_to_type[src_die]; | 
|  | 5518 | if (src_child_type) | 
|  | 5519 | { | 
|  | 5520 | if (log) | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5521 | log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", | 
|  | 5522 | static_cast<void*>(src_child_type), | 
|  | 5523 | src_child_type->GetID(), | 
|  | 5524 | src_die->GetOffset(), | 
|  | 5525 | dst_die->GetOffset()); | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5526 | m_die_to_type[dst_die] = src_child_type; | 
|  | 5527 | } | 
|  | 5528 | else | 
|  | 5529 | { | 
|  | 5530 | if (log) | 
|  | 5531 | 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()); | 
|  | 5532 | } | 
|  | 5533 | } | 
|  | 5534 | else | 
|  | 5535 | { | 
|  | 5536 | if (log) | 
|  | 5537 | 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] | 5538 |  | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 5539 | failures.Append(dst_die); | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5540 | } | 
|  | 5541 | } | 
|  | 5542 | } | 
|  | 5543 | } | 
|  | 5544 |  | 
|  | 5545 | const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize (); | 
|  | 5546 | const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize (); | 
|  | 5547 |  | 
|  | 5548 | UniqueCStringMap<const DWARFDebugInfoEntry *> name_to_die_artificial_not_in_src; | 
|  | 5549 |  | 
|  | 5550 | if (src_size_artificial && dst_size_artificial) | 
|  | 5551 | { | 
|  | 5552 | dst_name_to_die_artificial.Sort(); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5553 |  | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5554 | for (idx = 0; idx < src_size_artificial; ++idx) | 
|  | 5555 | { | 
|  | 5556 | const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx); | 
|  | 5557 | src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx); | 
|  | 5558 | dst_die = dst_name_to_die_artificial.Find(src_name_artificial, NULL); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5559 |  | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5560 | if (dst_die) | 
|  | 5561 | { | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5562 | // Both classes have the artificial types, link them | 
|  | 5563 | clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die]; | 
|  | 5564 | if (src_decl_ctx) | 
|  | 5565 | { | 
|  | 5566 | if (log) | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5567 | log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", | 
|  | 5568 | static_cast<void*>(src_decl_ctx), | 
|  | 5569 | src_die->GetOffset(), dst_die->GetOffset()); | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5570 | LinkDeclContextToDIE (src_decl_ctx, dst_die); | 
|  | 5571 | } | 
|  | 5572 | else | 
|  | 5573 | { | 
|  | 5574 | if (log) | 
|  | 5575 | 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()); | 
|  | 5576 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5577 |  | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5578 | Type *src_child_type = m_die_to_type[src_die]; | 
|  | 5579 | if (src_child_type) | 
|  | 5580 | { | 
|  | 5581 | if (log) | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5582 | log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", | 
|  | 5583 | static_cast<void*>(src_child_type), | 
|  | 5584 | src_child_type->GetID(), | 
|  | 5585 | src_die->GetOffset(), dst_die->GetOffset()); | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5586 | m_die_to_type[dst_die] = src_child_type; | 
|  | 5587 | } | 
|  | 5588 | else | 
|  | 5589 | { | 
|  | 5590 | if (log) | 
|  | 5591 | 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()); | 
|  | 5592 | } | 
|  | 5593 | } | 
|  | 5594 | } | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5595 | } | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5596 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5597 | if (dst_size_artificial) | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5598 | { | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5599 | for (idx = 0; idx < dst_size_artificial; ++idx) | 
|  | 5600 | { | 
|  | 5601 | const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx); | 
|  | 5602 | dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx); | 
|  | 5603 | if (log) | 
|  | 5604 | log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die->GetOffset(), dst_name_artificial); | 
|  | 5605 |  | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 5606 | failures.Append(dst_die); | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5607 | } | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5608 | } | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5609 |  | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 5610 | return (failures.Size() != 0); | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5611 | } | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5612 |  | 
|  | 5613 | TypeSP | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5614 | 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] | 5615 | { | 
|  | 5616 | TypeSP type_sp; | 
|  | 5617 |  | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5618 | if (type_is_new_ptr) | 
|  | 5619 | *type_is_new_ptr = false; | 
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5620 |  | 
| Todd Fiala | 0a70a84 | 2014-05-28 16:43:26 +0000 | [diff] [blame] | 5621 | #if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE) | 
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5622 | static DIEStack g_die_stack; | 
|  | 5623 | DIEStack::ScopedPopper scoped_die_logger(g_die_stack); | 
|  | 5624 | #endif | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5625 |  | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 5626 | AccessType accessibility = eAccessNone; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5627 | if (die != NULL) | 
|  | 5628 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5629 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5630 | if (log) | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5631 | { | 
|  | 5632 | const DWARFDebugInfoEntry *context_die; | 
|  | 5633 | clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5634 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5635 | 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] | 5636 | die->GetOffset(), | 
|  | 5637 | static_cast<void*>(context), | 
|  | 5638 | context_die->GetOffset(), | 
|  | 5639 | DW_TAG_value_to_name(die->Tag()), | 
|  | 5640 | die->GetName(this, dwarf_cu)); | 
|  | 5641 |  | 
| Todd Fiala | 0a70a84 | 2014-05-28 16:43:26 +0000 | [diff] [blame] | 5642 | #if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE) | 
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5643 | scoped_die_logger.Push (dwarf_cu, die); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5644 | g_die_stack.LogDIEs(log, this); | 
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5645 | #endif | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5646 | } | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5647 | // | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5648 | //        Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5649 | //        if (log && dwarf_cu) | 
|  | 5650 | //        { | 
|  | 5651 | //            StreamString s; | 
|  | 5652 | //            die->DumpLocation (this, dwarf_cu, s); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5653 | //            GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData()); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5654 | // | 
|  | 5655 | //        } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5656 |  | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5657 | Type *type_ptr = m_die_to_type.lookup (die); | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5658 | TypeList* type_list = GetTypeList(); | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5659 | if (type_ptr == NULL) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5660 | { | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5661 | ClangASTContext &ast = GetClangASTContext(); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5662 | if (type_is_new_ptr) | 
|  | 5663 | *type_is_new_ptr = true; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5664 |  | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5665 | const dw_tag_t tag = die->Tag(); | 
|  | 5666 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5667 | bool is_forward_declaration = false; | 
|  | 5668 | DWARFDebugInfoEntry::Attributes attributes; | 
|  | 5669 | const char *type_name_cstr = NULL; | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5670 | ConstString type_name_const_str; | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5671 | Type::ResolveState resolve_state = Type::eResolveStateUnresolved; | 
| Greg Clayton | faac111 | 2013-03-14 18:31:44 +0000 | [diff] [blame] | 5672 | uint64_t byte_size = 0; | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5673 | Declaration decl; | 
|  | 5674 |  | 
| Greg Clayton | 4957bf6 | 2010-09-30 21:49:03 +0000 | [diff] [blame] | 5675 | Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5676 | ClangASTType clang_type; | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 5677 | DWARFFormValue form_value; | 
|  | 5678 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5679 | dw_attr_t attr; | 
|  | 5680 |  | 
|  | 5681 | switch (tag) | 
|  | 5682 | { | 
|  | 5683 | case DW_TAG_base_type: | 
|  | 5684 | case DW_TAG_pointer_type: | 
|  | 5685 | case DW_TAG_reference_type: | 
| Sean Callanan | ce8af86 | 2012-05-21 23:31:51 +0000 | [diff] [blame] | 5686 | case DW_TAG_rvalue_reference_type: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5687 | case DW_TAG_typedef: | 
|  | 5688 | case DW_TAG_const_type: | 
|  | 5689 | case DW_TAG_restrict_type: | 
|  | 5690 | case DW_TAG_volatile_type: | 
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5691 | case DW_TAG_unspecified_type: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5692 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5693 | // 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] | 5694 | m_die_to_type[die] = DIE_IS_BEING_PARSED; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5695 |  | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5696 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5697 | uint32_t encoding = 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5698 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; | 
|  | 5699 |  | 
|  | 5700 | if (num_attributes > 0) | 
|  | 5701 | { | 
|  | 5702 | uint32_t i; | 
|  | 5703 | for (i=0; i<num_attributes; ++i) | 
|  | 5704 | { | 
|  | 5705 | attr = attributes.AttributeAtIndex(i); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5706 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 5707 | { | 
|  | 5708 | switch (attr) | 
|  | 5709 | { | 
|  | 5710 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 5711 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 5712 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 5713 | case DW_AT_name: | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5714 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5715 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); | 
| Jim Ingham | 337030f | 2011-04-15 23:41:23 +0000 | [diff] [blame] | 5716 | // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't | 
|  | 5717 | // include the "&"... | 
|  | 5718 | if (tag == DW_TAG_reference_type) | 
|  | 5719 | { | 
|  | 5720 | if (strchr (type_name_cstr, '&') == NULL) | 
|  | 5721 | type_name_cstr = NULL; | 
|  | 5722 | } | 
|  | 5723 | if (type_name_cstr) | 
|  | 5724 | type_name_const_str.SetCString(type_name_cstr); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5725 | break; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 5726 | case DW_AT_byte_size:   byte_size = form_value.Unsigned(); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5727 | case DW_AT_encoding:    encoding = form_value.Unsigned(); break; | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 5728 | case DW_AT_type:        encoding_uid = form_value.Reference(); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5729 | default: | 
|  | 5730 | case DW_AT_sibling: | 
|  | 5731 | break; | 
|  | 5732 | } | 
|  | 5733 | } | 
|  | 5734 | } | 
|  | 5735 | } | 
|  | 5736 |  | 
| Ed Maste | a0191d1 | 2013-10-17 20:42:56 +0000 | [diff] [blame] | 5737 | 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] | 5738 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5739 | switch (tag) | 
|  | 5740 | { | 
|  | 5741 | default: | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5742 | break; | 
|  | 5743 |  | 
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5744 | case DW_TAG_unspecified_type: | 
| Greg Clayton | 7fba263 | 2013-07-01 21:01:52 +0000 | [diff] [blame] | 5745 | if (strcmp(type_name_cstr, "nullptr_t") == 0 || | 
|  | 5746 | strcmp(type_name_cstr, "decltype(nullptr)") == 0 ) | 
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5747 | { | 
|  | 5748 | resolve_state = Type::eResolveStateFull; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5749 | clang_type = ast.GetBasicType(eBasicTypeNullPtr); | 
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5750 | break; | 
|  | 5751 | } | 
|  | 5752 | // Fall through to base type below in case we can handle the type there... | 
|  | 5753 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5754 | case DW_TAG_base_type: | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5755 | resolve_state = Type::eResolveStateFull; | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5756 | clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr, | 
|  | 5757 | encoding, | 
|  | 5758 | byte_size * 8); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5759 | break; | 
|  | 5760 |  | 
| Sean Callanan | ce8af86 | 2012-05-21 23:31:51 +0000 | [diff] [blame] | 5761 | case DW_TAG_pointer_type:           encoding_data_type = Type::eEncodingIsPointerUID;           break; | 
|  | 5762 | case DW_TAG_reference_type:         encoding_data_type = Type::eEncodingIsLValueReferenceUID;   break; | 
|  | 5763 | case DW_TAG_rvalue_reference_type:  encoding_data_type = Type::eEncodingIsRValueReferenceUID;   break; | 
|  | 5764 | case DW_TAG_typedef:                encoding_data_type = Type::eEncodingIsTypedefUID;           break; | 
|  | 5765 | case DW_TAG_const_type:             encoding_data_type = Type::eEncodingIsConstUID;             break; | 
|  | 5766 | case DW_TAG_restrict_type:          encoding_data_type = Type::eEncodingIsRestrictUID;          break; | 
|  | 5767 | case DW_TAG_volatile_type:          encoding_data_type = Type::eEncodingIsVolatileUID;          break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5768 | } | 
|  | 5769 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5770 | 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] | 5771 | { | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5772 | 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] | 5773 |  | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5774 | if (translation_unit_is_objc) | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 5775 | { | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5776 | if (type_name_cstr != NULL) | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5777 | { | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5778 | static ConstString g_objc_type_name_id("id"); | 
|  | 5779 | static ConstString g_objc_type_name_Class("Class"); | 
|  | 5780 | static ConstString g_objc_type_name_selector("SEL"); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5781 |  | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5782 | if (type_name_const_str == g_objc_type_name_id) | 
|  | 5783 | { | 
|  | 5784 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5785 | 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] | 5786 | die->GetOffset(), | 
|  | 5787 | DW_TAG_value_to_name(die->Tag()), | 
|  | 5788 | die->GetName(this, dwarf_cu)); | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5789 | clang_type = ast.GetBasicType(eBasicTypeObjCID); | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5790 | encoding_data_type = Type::eEncodingIsUID; | 
|  | 5791 | encoding_uid = LLDB_INVALID_UID; | 
|  | 5792 | resolve_state = Type::eResolveStateFull; | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5793 |  | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5794 | } | 
|  | 5795 | else if (type_name_const_str == g_objc_type_name_Class) | 
|  | 5796 | { | 
|  | 5797 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5798 | 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] | 5799 | die->GetOffset(), | 
|  | 5800 | DW_TAG_value_to_name(die->Tag()), | 
|  | 5801 | die->GetName(this, dwarf_cu)); | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5802 | clang_type = ast.GetBasicType(eBasicTypeObjCClass); | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5803 | encoding_data_type = Type::eEncodingIsUID; | 
|  | 5804 | encoding_uid = LLDB_INVALID_UID; | 
|  | 5805 | resolve_state = Type::eResolveStateFull; | 
|  | 5806 | } | 
|  | 5807 | else if (type_name_const_str == g_objc_type_name_selector) | 
|  | 5808 | { | 
|  | 5809 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5810 | GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'selector' built-in type.", | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5811 | die->GetOffset(), | 
|  | 5812 | DW_TAG_value_to_name(die->Tag()), | 
|  | 5813 | die->GetName(this, dwarf_cu)); | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5814 | clang_type = ast.GetBasicType(eBasicTypeObjCSel); | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5815 | encoding_data_type = Type::eEncodingIsUID; | 
|  | 5816 | encoding_uid = LLDB_INVALID_UID; | 
|  | 5817 | resolve_state = Type::eResolveStateFull; | 
|  | 5818 | } | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5819 | } | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5820 | else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid != LLDB_INVALID_UID) | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5821 | { | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5822 | // 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] | 5823 |  | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5824 | DWARFDebugInfoEntry* encoding_die = dwarf_cu->GetDIEPtr(encoding_uid); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5825 |  | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5826 | if (encoding_die && encoding_die->Tag() == DW_TAG_structure_type) | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5827 | { | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5828 | if (const char *struct_name = encoding_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL)) | 
|  | 5829 | { | 
|  | 5830 | if (!strcmp(struct_name, "objc_object")) | 
|  | 5831 | { | 
|  | 5832 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5833 | 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] | 5834 | die->GetOffset(), | 
|  | 5835 | DW_TAG_value_to_name(die->Tag()), | 
|  | 5836 | die->GetName(this, dwarf_cu)); | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 5837 | clang_type = ast.GetBasicType(eBasicTypeObjCID); | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5838 | encoding_data_type = Type::eEncodingIsUID; | 
|  | 5839 | encoding_uid = LLDB_INVALID_UID; | 
|  | 5840 | resolve_state = Type::eResolveStateFull; | 
|  | 5841 | } | 
|  | 5842 | } | 
|  | 5843 | } | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5844 | } | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 5845 | } | 
|  | 5846 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5847 |  | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5848 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5849 | this, | 
|  | 5850 | type_name_const_str, | 
|  | 5851 | byte_size, | 
|  | 5852 | NULL, | 
|  | 5853 | encoding_uid, | 
|  | 5854 | encoding_data_type, | 
|  | 5855 | &decl, | 
|  | 5856 | clang_type, | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5857 | resolve_state)); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5858 |  | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5859 | m_die_to_type[die] = type_sp.get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5860 |  | 
|  | 5861 | //                  Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false); | 
|  | 5862 | //                  if (encoding_type != NULL) | 
|  | 5863 | //                  { | 
|  | 5864 | //                      if (encoding_type != DIE_IS_BEING_PARSED) | 
|  | 5865 | //                          type_sp->SetEncodingType(encoding_type); | 
|  | 5866 | //                      else | 
|  | 5867 | //                          m_indirect_fixups.push_back(type_sp.get()); | 
|  | 5868 | //                  } | 
|  | 5869 | } | 
|  | 5870 | break; | 
|  | 5871 |  | 
|  | 5872 | case DW_TAG_structure_type: | 
|  | 5873 | case DW_TAG_union_type: | 
|  | 5874 | case DW_TAG_class_type: | 
|  | 5875 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5876 | // 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] | 5877 | m_die_to_type[die] = DIE_IS_BEING_PARSED; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 5878 | bool byte_size_valid = false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5879 |  | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5880 | LanguageType class_language = eLanguageTypeUnknown; | 
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 5881 | bool is_complete_objc_class = false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5882 | //bool struct_is_class = false; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5883 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5884 | if (num_attributes > 0) | 
|  | 5885 | { | 
|  | 5886 | uint32_t i; | 
|  | 5887 | for (i=0; i<num_attributes; ++i) | 
|  | 5888 | { | 
|  | 5889 | attr = attributes.AttributeAtIndex(i); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5890 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 5891 | { | 
|  | 5892 | switch (attr) | 
|  | 5893 | { | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5894 | case DW_AT_decl_file: | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5895 | if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid()) | 
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 5896 | { | 
|  | 5897 | // llvm-gcc outputs invalid DW_AT_decl_file attributes that always | 
|  | 5898 | // point to the compile unit file, so we clear this invalid value | 
|  | 5899 | // so that we can still unique types efficiently. | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5900 | decl.SetFile(FileSpec ("<invalid>", false)); | 
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 5901 | } | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5902 | else | 
|  | 5903 | decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5904 | break; | 
|  | 5905 |  | 
|  | 5906 | case DW_AT_decl_line: | 
|  | 5907 | decl.SetLine(form_value.Unsigned()); | 
|  | 5908 | break; | 
|  | 5909 |  | 
|  | 5910 | case DW_AT_decl_column: | 
|  | 5911 | decl.SetColumn(form_value.Unsigned()); | 
|  | 5912 | break; | 
|  | 5913 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5914 | case DW_AT_name: | 
|  | 5915 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5916 | type_name_const_str.SetCString(type_name_cstr); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5917 | break; | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5918 |  | 
|  | 5919 | case DW_AT_byte_size: | 
|  | 5920 | byte_size = form_value.Unsigned(); | 
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 5921 | byte_size_valid = true; | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5922 | break; | 
|  | 5923 |  | 
|  | 5924 | case DW_AT_accessibility: | 
|  | 5925 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); | 
|  | 5926 | break; | 
|  | 5927 |  | 
|  | 5928 | case DW_AT_declaration: | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 5929 | is_forward_declaration = form_value.Boolean(); | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5930 | break; | 
|  | 5931 |  | 
|  | 5932 | case DW_AT_APPLE_runtime_class: | 
|  | 5933 | class_language = (LanguageType)form_value.Signed(); | 
|  | 5934 | break; | 
|  | 5935 |  | 
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 5936 | case DW_AT_APPLE_objc_complete_type: | 
|  | 5937 | is_complete_objc_class = form_value.Signed(); | 
|  | 5938 | break; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5939 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5940 | case DW_AT_allocated: | 
|  | 5941 | case DW_AT_associated: | 
|  | 5942 | case DW_AT_data_location: | 
|  | 5943 | case DW_AT_description: | 
|  | 5944 | case DW_AT_start_scope: | 
|  | 5945 | case DW_AT_visibility: | 
|  | 5946 | default: | 
|  | 5947 | case DW_AT_sibling: | 
|  | 5948 | break; | 
|  | 5949 | } | 
|  | 5950 | } | 
|  | 5951 | } | 
|  | 5952 | } | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 5953 |  | 
|  | 5954 | // UniqueDWARFASTType is large, so don't create a local variables on the | 
|  | 5955 | // stack, put it on the heap. This function is often called recursively | 
|  | 5956 | // and clang isn't good and sharing the stack space for variables in different blocks. | 
|  | 5957 | std::unique_ptr<UniqueDWARFASTType> unique_ast_entry_ap(new UniqueDWARFASTType()); | 
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5958 |  | 
| Greg Clayton | 123edca | 2012-03-02 00:07:15 +0000 | [diff] [blame] | 5959 | // Only try and unique the type if it has a name. | 
|  | 5960 | if (type_name_const_str && | 
|  | 5961 | GetUniqueDWARFASTTypeMap().Find (type_name_const_str, | 
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5962 | this, | 
|  | 5963 | dwarf_cu, | 
|  | 5964 | die, | 
|  | 5965 | decl, | 
|  | 5966 | byte_size_valid ? byte_size : -1, | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 5967 | *unique_ast_entry_ap)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5968 | { | 
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5969 | // We have already parsed this type or from another | 
|  | 5970 | // compile unit. GCC loves to use the "one definition | 
|  | 5971 | // rule" which can result in multiple definitions | 
|  | 5972 | // of the same class over and over in each compile | 
|  | 5973 | // unit. | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 5974 | type_sp = unique_ast_entry_ap->m_type_sp; | 
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5975 | if (type_sp) | 
| Greg Clayton | c615ce4 | 2010-11-09 04:42:43 +0000 | [diff] [blame] | 5976 | { | 
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5977 | m_die_to_type[die] = type_sp.get(); | 
|  | 5978 | return type_sp; | 
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5979 | } | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5980 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5981 |  | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5982 | 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] | 5983 |  | 
|  | 5984 | int tag_decl_kind = -1; | 
|  | 5985 | AccessType default_accessibility = eAccessNone; | 
|  | 5986 | if (tag == DW_TAG_structure_type) | 
|  | 5987 | { | 
|  | 5988 | tag_decl_kind = clang::TTK_Struct; | 
|  | 5989 | default_accessibility = eAccessPublic; | 
|  | 5990 | } | 
|  | 5991 | else if (tag == DW_TAG_union_type) | 
|  | 5992 | { | 
|  | 5993 | tag_decl_kind = clang::TTK_Union; | 
|  | 5994 | default_accessibility = eAccessPublic; | 
|  | 5995 | } | 
|  | 5996 | else if (tag == DW_TAG_class_type) | 
|  | 5997 | { | 
|  | 5998 | tag_decl_kind = clang::TTK_Class; | 
|  | 5999 | default_accessibility = eAccessPrivate; | 
|  | 6000 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6001 |  | 
| Greg Clayton | 3a5f29a | 2011-11-30 02:48:28 +0000 | [diff] [blame] | 6002 | if (byte_size_valid && byte_size == 0 && type_name_cstr && | 
|  | 6003 | die->HasChildren() == false && | 
|  | 6004 | sc.comp_unit->GetLanguage() == eLanguageTypeObjC) | 
|  | 6005 | { | 
|  | 6006 | // Work around an issue with clang at the moment where | 
|  | 6007 | // forward declarations for objective C classes are emitted | 
|  | 6008 | // as: | 
|  | 6009 | //  DW_TAG_structure_type [2] | 
|  | 6010 | //  DW_AT_name( "ForwardObjcClass" ) | 
|  | 6011 | //  DW_AT_byte_size( 0x00 ) | 
|  | 6012 | //  DW_AT_decl_file( "..." ) | 
|  | 6013 | //  DW_AT_decl_line( 1 ) | 
|  | 6014 | // | 
|  | 6015 | // Note that there is no DW_AT_declaration and there are | 
|  | 6016 | // no children, and the byte size is zero. | 
|  | 6017 | is_forward_declaration = true; | 
|  | 6018 | } | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6019 |  | 
| Sean Callanan | 7457f8d | 2012-04-25 01:03:57 +0000 | [diff] [blame] | 6020 | if (class_language == eLanguageTypeObjC || | 
|  | 6021 | class_language == eLanguageTypeObjC_plus_plus) | 
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 6022 | { | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6023 | 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] | 6024 | { | 
|  | 6025 | // We have a valid eSymbolTypeObjCClass class symbol whose | 
|  | 6026 | // name matches the current objective C class that we | 
|  | 6027 | // are trying to find and this DIE isn't the complete | 
|  | 6028 | // definition (we checked is_complete_objc_class above and | 
|  | 6029 | // know it is false), so the real definition is in here somewhere | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6030 | type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true); | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6031 |  | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 6032 | if (!type_sp && GetDebugMapSymfile ()) | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 6033 | { | 
|  | 6034 | // We weren't able to find a full declaration in | 
|  | 6035 | // this DWARF, see if we have a declaration anywhere | 
|  | 6036 | // else... | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6037 | 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] | 6038 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6039 |  | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 6040 | if (type_sp) | 
|  | 6041 | { | 
|  | 6042 | if (log) | 
|  | 6043 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 6044 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6045 | "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] | 6046 | static_cast<void*>(this), | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6047 | die->GetOffset(), | 
|  | 6048 | DW_TAG_value_to_name(tag), | 
|  | 6049 | type_name_cstr, | 
|  | 6050 | type_sp->GetID()); | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 6051 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6052 |  | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 6053 | // We found a real definition for this type elsewhere | 
|  | 6054 | // so lets use it and cache the fact that we found | 
|  | 6055 | // a complete type for this die | 
|  | 6056 | m_die_to_type[die] = type_sp.get(); | 
|  | 6057 | return type_sp; | 
|  | 6058 | } | 
|  | 6059 | } | 
|  | 6060 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6061 |  | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 6062 |  | 
|  | 6063 | if (is_forward_declaration) | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6064 | { | 
|  | 6065 | // We have a forward declaration to a type and we need | 
|  | 6066 | // to try and find a full declaration. We look in the | 
|  | 6067 | // current type index just in case we have a forward | 
|  | 6068 | // declaration followed by an actual declarations in the | 
|  | 6069 | // DWARF. If this fails, we need to look elsewhere... | 
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 6070 | if (log) | 
|  | 6071 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 6072 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6073 | "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] | 6074 | static_cast<void*>(this), | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6075 | die->GetOffset(), | 
|  | 6076 | DW_TAG_value_to_name(tag), | 
|  | 6077 | type_name_cstr); | 
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 6078 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6079 |  | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 6080 | DWARFDeclContext die_decl_ctx; | 
|  | 6081 | die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx); | 
|  | 6082 |  | 
|  | 6083 | //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str); | 
|  | 6084 | type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6085 |  | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 6086 | if (!type_sp && GetDebugMapSymfile ()) | 
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 6087 | { | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6088 | // We weren't able to find a full declaration in | 
|  | 6089 | // this DWARF, see if we have a declaration anywhere | 
|  | 6090 | // else... | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 6091 | type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); | 
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 6092 | } | 
|  | 6093 |  | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6094 | if (type_sp) | 
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 6095 | { | 
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 6096 | if (log) | 
|  | 6097 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 6098 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6099 | "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] | 6100 | static_cast<void*>(this), | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6101 | die->GetOffset(), | 
|  | 6102 | DW_TAG_value_to_name(tag), | 
|  | 6103 | type_name_cstr, | 
|  | 6104 | type_sp->GetID()); | 
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 6105 | } | 
|  | 6106 |  | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6107 | // We found a real definition for this type elsewhere | 
|  | 6108 | // so lets use it and cache the fact that we found | 
|  | 6109 | // a complete type for this die | 
|  | 6110 | m_die_to_type[die] = type_sp.get(); | 
|  | 6111 | return type_sp; | 
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 6112 | } | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6113 | } | 
|  | 6114 | assert (tag_decl_kind != -1); | 
|  | 6115 | bool clang_type_was_created = false; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6116 | clang_type.SetClangType(ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die)); | 
|  | 6117 | if (!clang_type) | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6118 | { | 
| Sean Callanan | 4d04c6a | 2012-02-09 22:54:11 +0000 | [diff] [blame] | 6119 | const DWARFDebugInfoEntry *decl_ctx_die; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6120 |  | 
| Sean Callanan | 4d04c6a | 2012-02-09 22:54:11 +0000 | [diff] [blame] | 6121 | clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die); | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 6122 | if (accessibility == eAccessNone && decl_ctx) | 
|  | 6123 | { | 
|  | 6124 | // Check the decl context that contains this class/struct/union. | 
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 6125 | // If it is a class we must give it an accessibility. | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 6126 | const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind(); | 
|  | 6127 | if (DeclKindIsCXXClass (containing_decl_kind)) | 
|  | 6128 | accessibility = default_accessibility; | 
|  | 6129 | } | 
|  | 6130 |  | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 6131 | ClangASTMetadata metadata; | 
|  | 6132 | metadata.SetUserID(MakeUserID(die->GetOffset())); | 
|  | 6133 | metadata.SetIsDynamicCXXType(ClassOrStructIsVirtual (dwarf_cu, die)); | 
|  | 6134 |  | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6135 | if (type_name_cstr && strchr (type_name_cstr, '<')) | 
|  | 6136 | { | 
|  | 6137 | ClangASTContext::TemplateParameterInfos template_param_infos; | 
|  | 6138 | if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos)) | 
|  | 6139 | { | 
|  | 6140 | clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx, | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 6141 | accessibility, | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6142 | type_name_cstr, | 
|  | 6143 | tag_decl_kind, | 
|  | 6144 | template_param_infos); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6145 |  | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6146 | clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx, | 
|  | 6147 | class_template_decl, | 
|  | 6148 | tag_decl_kind, | 
|  | 6149 | template_param_infos); | 
|  | 6150 | clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl); | 
|  | 6151 | clang_type_was_created = true; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6152 |  | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6153 | GetClangASTContext().SetMetadata (class_template_decl, metadata); | 
|  | 6154 | GetClangASTContext().SetMetadata (class_specialization_decl, metadata); | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6155 | } | 
|  | 6156 | } | 
|  | 6157 |  | 
|  | 6158 | if (!clang_type_was_created) | 
|  | 6159 | { | 
|  | 6160 | clang_type_was_created = true; | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 6161 | clang_type = ast.CreateRecordType (decl_ctx, | 
|  | 6162 | accessibility, | 
|  | 6163 | type_name_cstr, | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6164 | tag_decl_kind, | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 6165 | class_language, | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6166 | &metadata); | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6167 | } | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6168 | } | 
|  | 6169 |  | 
|  | 6170 | // Store a forward declaration to this class type in case any | 
|  | 6171 | // parameters in any class methods need it for the clang | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6172 | // types for function prototypes. | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6173 | LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die); | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6174 | type_sp.reset (new Type (MakeUserID(die->GetOffset()), | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6175 | this, | 
|  | 6176 | type_name_const_str, | 
|  | 6177 | byte_size, | 
|  | 6178 | NULL, | 
|  | 6179 | LLDB_INVALID_UID, | 
|  | 6180 | Type::eEncodingIsUID, | 
|  | 6181 | &decl, | 
|  | 6182 | clang_type, | 
|  | 6183 | Type::eResolveStateForward)); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6184 |  | 
| Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 6185 | type_sp->SetIsCompleteObjCClass(is_complete_objc_class); | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6186 |  | 
|  | 6187 |  | 
|  | 6188 | // Add our type to the unique type map so we don't | 
|  | 6189 | // end up creating many copies of the same type over | 
|  | 6190 | // and over in the ASTContext for our module | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 6191 | unique_ast_entry_ap->m_type_sp = type_sp; | 
|  | 6192 | unique_ast_entry_ap->m_symfile = this; | 
|  | 6193 | unique_ast_entry_ap->m_cu = dwarf_cu; | 
|  | 6194 | unique_ast_entry_ap->m_die = die; | 
|  | 6195 | unique_ast_entry_ap->m_declaration = decl; | 
|  | 6196 | unique_ast_entry_ap->m_byte_size = byte_size; | 
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 6197 | GetUniqueDWARFASTTypeMap().Insert (type_name_const_str, | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 6198 | *unique_ast_entry_ap); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6199 |  | 
| Greg Clayton | 0ec71a0 | 2013-08-10 00:09:35 +0000 | [diff] [blame] | 6200 | if (is_forward_declaration && die->HasChildren()) | 
|  | 6201 | { | 
|  | 6202 | // Check to see if the DIE actually has a definition, some version of GCC will | 
|  | 6203 | // emit DIEs with DW_AT_declaration set to true, but yet still have subprogram, | 
|  | 6204 | // members, or inheritance, so we can't trust it | 
|  | 6205 | const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); | 
|  | 6206 | while (child_die) | 
|  | 6207 | { | 
|  | 6208 | switch (child_die->Tag()) | 
|  | 6209 | { | 
|  | 6210 | case DW_TAG_inheritance: | 
|  | 6211 | case DW_TAG_subprogram: | 
|  | 6212 | case DW_TAG_member: | 
|  | 6213 | case DW_TAG_APPLE_property: | 
| Greg Clayton | 4c484ec | 2014-02-07 19:21:56 +0000 | [diff] [blame] | 6214 | case DW_TAG_class_type: | 
|  | 6215 | case DW_TAG_structure_type: | 
|  | 6216 | case DW_TAG_enumeration_type: | 
|  | 6217 | case DW_TAG_typedef: | 
|  | 6218 | case DW_TAG_union_type: | 
| Greg Clayton | 0ec71a0 | 2013-08-10 00:09:35 +0000 | [diff] [blame] | 6219 | child_die = NULL; | 
|  | 6220 | is_forward_declaration = false; | 
|  | 6221 | break; | 
|  | 6222 | default: | 
|  | 6223 | child_die = child_die->GetSibling(); | 
|  | 6224 | break; | 
|  | 6225 | } | 
|  | 6226 | } | 
|  | 6227 | } | 
|  | 6228 |  | 
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6229 | if (!is_forward_declaration) | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 6230 | { | 
|  | 6231 | // Always start the definition for a class type so that | 
|  | 6232 | // if the class has child classes or types that require | 
|  | 6233 | // the class to be created for use as their decl contexts | 
|  | 6234 | // the class will be ready to accept these child definitions. | 
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6235 | if (die->HasChildren() == false) | 
|  | 6236 | { | 
|  | 6237 | // No children for this struct/union/class, lets finish it | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6238 | clang_type.StartTagDeclarationDefinition (); | 
|  | 6239 | clang_type.CompleteTagDeclarationDefinition (); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6240 |  | 
| Sean Callanan | 433cd22 | 2012-10-19 01:37:25 +0000 | [diff] [blame] | 6241 | if (tag == DW_TAG_structure_type) // this only applies in C | 
|  | 6242 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6243 | clang::RecordDecl *record_decl = clang_type.GetAsRecordDecl(); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6244 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6245 | if (record_decl) | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 6246 | 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] | 6247 | } | 
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6248 | } | 
|  | 6249 | else if (clang_type_was_created) | 
|  | 6250 | { | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 6251 | // Start the definition if the class is not objective C since | 
|  | 6252 | // the underlying decls respond to isCompleteDefinition(). Objective | 
| Bruce Mitchener | aaa0ba3 | 2014-07-08 18:05:41 +0000 | [diff] [blame] | 6253 | // C decls don't respond to isCompleteDefinition() so we can't | 
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 6254 | // start the declaration definition right away. For C++ class/union/structs | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 6255 | // we want to start the definition in case the class is needed as the | 
|  | 6256 | // declaration context for a contained class or type without the need | 
|  | 6257 | // to complete that type.. | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6258 |  | 
| Sean Callanan | 7457f8d | 2012-04-25 01:03:57 +0000 | [diff] [blame] | 6259 | if (class_language != eLanguageTypeObjC && | 
|  | 6260 | class_language != eLanguageTypeObjC_plus_plus) | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6261 | clang_type.StartTagDeclarationDefinition (); | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 6262 |  | 
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6263 | // Leave this as a forward declaration until we need | 
|  | 6264 | // to know the details of the type. lldb_private::Type | 
|  | 6265 | // will automatically call the SymbolFile virtual function | 
|  | 6266 | // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)" | 
|  | 6267 | // When the definition needs to be defined. | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6268 | m_forward_decl_die_to_clang_type[die] = clang_type.GetOpaqueQualType(); | 
|  | 6269 | m_forward_decl_clang_type_to_die[clang_type.RemoveFastQualifiers().GetOpaqueQualType()] = die; | 
|  | 6270 | clang_type.SetHasExternalStorage (true); | 
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6271 | } | 
| Greg Clayton | c615ce4 | 2010-11-09 04:42:43 +0000 | [diff] [blame] | 6272 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6273 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6274 | } | 
|  | 6275 | break; | 
|  | 6276 |  | 
|  | 6277 | case DW_TAG_enumeration_type: | 
|  | 6278 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6279 | // 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] | 6280 | m_die_to_type[die] = DIE_IS_BEING_PARSED; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6281 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6282 | lldb::user_id_t encoding_uid = DW_INVALID_OFFSET; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6283 |  | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6284 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6285 | if (num_attributes > 0) | 
|  | 6286 | { | 
|  | 6287 | uint32_t i; | 
|  | 6288 |  | 
|  | 6289 | for (i=0; i<num_attributes; ++i) | 
|  | 6290 | { | 
|  | 6291 | attr = attributes.AttributeAtIndex(i); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6292 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 6293 | { | 
|  | 6294 | switch (attr) | 
|  | 6295 | { | 
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 6296 | case DW_AT_decl_file:       decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 6297 | case DW_AT_decl_line:       decl.SetLine(form_value.Unsigned()); break; | 
|  | 6298 | case DW_AT_decl_column:     decl.SetColumn(form_value.Unsigned()); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6299 | case DW_AT_name: | 
|  | 6300 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6301 | type_name_const_str.SetCString(type_name_cstr); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6302 | break; | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 6303 | case DW_AT_type:            encoding_uid = form_value.Reference(); break; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6304 | case DW_AT_byte_size:       byte_size = form_value.Unsigned(); break; | 
|  | 6305 | 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] | 6306 | case DW_AT_declaration:     break; //is_forward_declaration = form_value.Boolean(); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6307 | case DW_AT_allocated: | 
|  | 6308 | case DW_AT_associated: | 
|  | 6309 | case DW_AT_bit_stride: | 
|  | 6310 | case DW_AT_byte_stride: | 
|  | 6311 | case DW_AT_data_location: | 
|  | 6312 | case DW_AT_description: | 
|  | 6313 | case DW_AT_start_scope: | 
|  | 6314 | case DW_AT_visibility: | 
|  | 6315 | case DW_AT_specification: | 
|  | 6316 | case DW_AT_abstract_origin: | 
|  | 6317 | case DW_AT_sibling: | 
|  | 6318 | break; | 
|  | 6319 | } | 
|  | 6320 | } | 
|  | 6321 | } | 
|  | 6322 |  | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6323 | 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] | 6324 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6325 | ClangASTType enumerator_clang_type; | 
|  | 6326 | clang_type.SetClangType (ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die)); | 
|  | 6327 | if (!clang_type) | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6328 | { | 
| Greg Clayton | 5d14fc0 | 2013-03-06 06:23:54 +0000 | [diff] [blame] | 6329 | if (encoding_uid != DW_INVALID_OFFSET) | 
|  | 6330 | { | 
|  | 6331 | Type *enumerator_type = ResolveTypeUID(encoding_uid); | 
|  | 6332 | if (enumerator_type) | 
|  | 6333 | enumerator_clang_type = enumerator_type->GetClangFullType(); | 
|  | 6334 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6335 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6336 | if (!enumerator_clang_type) | 
| Greg Clayton | 5d14fc0 | 2013-03-06 06:23:54 +0000 | [diff] [blame] | 6337 | enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL, | 
|  | 6338 | DW_ATE_signed, | 
|  | 6339 | byte_size * 8); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6340 |  | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 6341 | clang_type = ast.CreateEnumerationType (type_name_cstr, | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6342 | GetClangDeclContextContainingDIE (dwarf_cu, die, NULL), | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 6343 | decl, | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6344 | enumerator_clang_type); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6345 | } | 
|  | 6346 | else | 
|  | 6347 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6348 | enumerator_clang_type = clang_type.GetEnumerationIntegerType (); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6349 | } | 
|  | 6350 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6351 | LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6352 |  | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6353 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6354 | this, | 
|  | 6355 | type_name_const_str, | 
|  | 6356 | byte_size, | 
|  | 6357 | NULL, | 
|  | 6358 | encoding_uid, | 
|  | 6359 | Type::eEncodingIsUID, | 
|  | 6360 | &decl, | 
|  | 6361 | clang_type, | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6362 | Type::eResolveStateForward)); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6363 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6364 | clang_type.StartTagDeclarationDefinition (); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 6365 | if (die->HasChildren()) | 
|  | 6366 | { | 
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 6367 | SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); | 
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 6368 | bool is_signed = false; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6369 | enumerator_clang_type.IsIntegerType(is_signed); | 
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 6370 | 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] | 6371 | } | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6372 | clang_type.CompleteTagDeclarationDefinition (); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6373 | } | 
|  | 6374 | } | 
|  | 6375 | break; | 
|  | 6376 |  | 
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 6377 | case DW_TAG_inlined_subroutine: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6378 | case DW_TAG_subprogram: | 
|  | 6379 | case DW_TAG_subroutine_type: | 
|  | 6380 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6381 | // 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] | 6382 | m_die_to_type[die] = DIE_IS_BEING_PARSED; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6383 |  | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6384 | //const char *mangled = NULL; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6385 | dw_offset_t type_die_offset = DW_INVALID_OFFSET; | 
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 6386 | bool is_variadic = false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6387 | bool is_inline = false; | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6388 | bool is_static = false; | 
|  | 6389 | bool is_virtual = false; | 
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6390 | bool is_explicit = false; | 
| Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 6391 | bool is_artificial = false; | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6392 | dw_offset_t specification_die_offset = DW_INVALID_OFFSET; | 
|  | 6393 | dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET; | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6394 | dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET; | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6395 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6396 | unsigned type_quals = 0; | 
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 6397 | clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6398 |  | 
|  | 6399 |  | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6400 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6401 | if (num_attributes > 0) | 
|  | 6402 | { | 
|  | 6403 | uint32_t i; | 
|  | 6404 | for (i=0; i<num_attributes; ++i) | 
|  | 6405 | { | 
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 6406 | attr = attributes.AttributeAtIndex(i); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6407 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 6408 | { | 
|  | 6409 | switch (attr) | 
|  | 6410 | { | 
|  | 6411 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 6412 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 6413 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 6414 | case DW_AT_name: | 
|  | 6415 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6416 | type_name_const_str.SetCString(type_name_cstr); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6417 | break; | 
|  | 6418 |  | 
| Greg Clayton | 7141554 | 2012-12-08 00:24:40 +0000 | [diff] [blame] | 6419 | case DW_AT_linkage_name: | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6420 | 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] | 6421 | case DW_AT_type:                type_die_offset = form_value.Reference(); break; | 
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 6422 | 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] | 6423 | case DW_AT_declaration:         break; // is_forward_declaration = form_value.Boolean(); break; | 
|  | 6424 | case DW_AT_inline:              is_inline = form_value.Boolean(); break; | 
|  | 6425 | case DW_AT_virtuality:          is_virtual = form_value.Boolean();  break; | 
|  | 6426 | case DW_AT_explicit:            is_explicit = form_value.Boolean();  break; | 
|  | 6427 | case DW_AT_artificial:          is_artificial = form_value.Boolean();  break; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6428 |  | 
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6429 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6430 | case DW_AT_external: | 
|  | 6431 | if (form_value.Unsigned()) | 
|  | 6432 | { | 
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 6433 | if (storage == clang::SC_None) | 
|  | 6434 | storage = clang::SC_Extern; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6435 | else | 
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 6436 | storage = clang::SC_PrivateExtern; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6437 | } | 
|  | 6438 | break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6439 |  | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6440 | case DW_AT_specification: | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 6441 | specification_die_offset = form_value.Reference(); | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6442 | break; | 
|  | 6443 |  | 
|  | 6444 | case DW_AT_abstract_origin: | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 6445 | abstract_origin_die_offset = form_value.Reference(); | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6446 | break; | 
|  | 6447 |  | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6448 | case DW_AT_object_pointer: | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 6449 | object_pointer_die_offset = form_value.Reference(); | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6450 | break; | 
|  | 6451 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6452 | case DW_AT_allocated: | 
|  | 6453 | case DW_AT_associated: | 
|  | 6454 | case DW_AT_address_class: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6455 | case DW_AT_calling_convention: | 
|  | 6456 | case DW_AT_data_location: | 
|  | 6457 | case DW_AT_elemental: | 
|  | 6458 | case DW_AT_entry_pc: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6459 | case DW_AT_frame_base: | 
|  | 6460 | case DW_AT_high_pc: | 
|  | 6461 | case DW_AT_low_pc: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6462 | case DW_AT_prototyped: | 
|  | 6463 | case DW_AT_pure: | 
|  | 6464 | case DW_AT_ranges: | 
|  | 6465 | case DW_AT_recursive: | 
|  | 6466 | case DW_AT_return_addr: | 
|  | 6467 | case DW_AT_segment: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6468 | case DW_AT_start_scope: | 
|  | 6469 | case DW_AT_static_link: | 
|  | 6470 | case DW_AT_trampoline: | 
|  | 6471 | case DW_AT_visibility: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6472 | case DW_AT_vtable_elem_location: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6473 | case DW_AT_description: | 
|  | 6474 | case DW_AT_sibling: | 
|  | 6475 | break; | 
|  | 6476 | } | 
|  | 6477 | } | 
|  | 6478 | } | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6479 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6480 |  | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6481 | std::string object_pointer_name; | 
|  | 6482 | if (object_pointer_die_offset != DW_INVALID_OFFSET) | 
|  | 6483 | { | 
|  | 6484 | // Get the name from the object pointer die | 
|  | 6485 | StreamString s; | 
|  | 6486 | if (DWARFDebugInfoEntry::GetName (this, dwarf_cu, object_pointer_die_offset, s)) | 
|  | 6487 | { | 
|  | 6488 | object_pointer_name.assign(s.GetData()); | 
|  | 6489 | } | 
|  | 6490 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6491 |  | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6492 | 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] | 6493 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6494 | ClangASTType return_clang_type; | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6495 | Type *func_type = NULL; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6496 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6497 | if (type_die_offset != DW_INVALID_OFFSET) | 
|  | 6498 | func_type = ResolveTypeUID(type_die_offset); | 
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6499 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6500 | if (func_type) | 
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 6501 | return_clang_type = func_type->GetClangForwardType(); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6502 | else | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6503 | return_clang_type = ast.GetBasicType(eBasicTypeVoid); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6504 |  | 
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6505 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6506 | std::vector<ClangASTType> function_param_types; | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6507 | std::vector<clang::ParmVarDecl*> function_param_decls; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6508 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6509 | // Parse the function children for the parameters | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6510 |  | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6511 | const DWARFDebugInfoEntry *decl_ctx_die = NULL; | 
|  | 6512 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die); | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6513 | const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind(); | 
|  | 6514 |  | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6515 | const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind); | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6516 | // Start off static. This will be set to false in ParseChildParameters(...) | 
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 6517 | // if we find a "this" parameters as the first parameter | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6518 | if (is_cxx_method) | 
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 6519 | is_static = true; | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 6520 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6521 | if (die->HasChildren()) | 
|  | 6522 | { | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6523 | bool skip_artificial = true; | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6524 | ParseChildParameters (sc, | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6525 | containing_decl_ctx, | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6526 | dwarf_cu, | 
|  | 6527 | die, | 
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 6528 | skip_artificial, | 
|  | 6529 | is_static, | 
| Greg Clayton | 0396975 | 2014-02-24 18:53:11 +0000 | [diff] [blame] | 6530 | is_variadic, | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6531 | function_param_types, | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 6532 | function_param_decls, | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 6533 | type_quals); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6534 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6535 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6536 | // clang_type will get the function prototype clang type after this call | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6537 | clang_type = ast.CreateFunctionType (return_clang_type, | 
| Greg Clayton | 9cb25c4 | 2012-10-30 17:02:18 +0000 | [diff] [blame] | 6538 | function_param_types.data(), | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6539 | function_param_types.size(), | 
|  | 6540 | is_variadic, | 
|  | 6541 | type_quals); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6542 |  | 
| Sean Callanan | de9ce87 | 2013-05-09 23:13:13 +0000 | [diff] [blame] | 6543 | bool ignore_containing_context = false; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6544 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6545 | if (type_name_cstr) | 
|  | 6546 | { | 
|  | 6547 | bool type_handled = false; | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6548 | if (tag == DW_TAG_subprogram) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6549 | { | 
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 6550 | ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true); | 
|  | 6551 | if (objc_method.IsValid(true)) | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6552 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6553 | ClangASTType class_opaque_type; | 
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 6554 | ConstString class_name(objc_method.GetClassName()); | 
| Greg Clayton | 7c81042 | 2012-01-18 23:40:49 +0000 | [diff] [blame] | 6555 | if (class_name) | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6556 | { | 
| Greg Clayton | 278a16b | 2012-01-19 00:52:59 +0000 | [diff] [blame] | 6557 | TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false)); | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6558 |  | 
|  | 6559 | if (complete_objc_class_type_sp) | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6560 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6561 | ClangASTType type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType(); | 
|  | 6562 | if (type_clang_forward_type.IsObjCObjectOrInterfaceType ()) | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6563 | class_opaque_type = type_clang_forward_type; | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6564 | } | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6565 | } | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6566 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6567 | if (class_opaque_type) | 
|  | 6568 | { | 
|  | 6569 | // If accessibility isn't set to anything valid, assume public for | 
|  | 6570 | // now... | 
|  | 6571 | if (accessibility == eAccessNone) | 
|  | 6572 | accessibility = eAccessPublic; | 
|  | 6573 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6574 | clang::ObjCMethodDecl *objc_method_decl = class_opaque_type.AddMethodToObjCObjectType (type_name_cstr, | 
|  | 6575 | clang_type, | 
|  | 6576 | accessibility, | 
|  | 6577 | is_artificial); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6578 | type_handled = objc_method_decl != NULL; | 
| Sean Callanan | 464a5b5 | 2012-10-04 22:06:29 +0000 | [diff] [blame] | 6579 | if (type_handled) | 
|  | 6580 | { | 
|  | 6581 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die); | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6582 | GetClangASTContext().SetMetadataAsUserID (objc_method_decl, MakeUserID(die->GetOffset())); | 
| Sean Callanan | 464a5b5 | 2012-10-04 22:06:29 +0000 | [diff] [blame] | 6583 | } | 
| Sean Callanan | c3a1d56 | 2013-02-06 23:21:59 +0000 | [diff] [blame] | 6584 | else | 
|  | 6585 | { | 
| Jason Molenda | c1a6583 | 2013-03-07 22:44:42 +0000 | [diff] [blame] | 6586 | 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] | 6587 | die->GetOffset(), | 
|  | 6588 | tag, | 
|  | 6589 | DW_TAG_value_to_name(tag)); | 
|  | 6590 | } | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6591 | } | 
|  | 6592 | } | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6593 | else if (is_cxx_method) | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6594 | { | 
|  | 6595 | // Look at the parent of this DIE and see if is is | 
|  | 6596 | // a class or struct and see if this is actually a | 
|  | 6597 | // C++ method | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6598 | Type *class_type = ResolveType (dwarf_cu, decl_ctx_die); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6599 | if (class_type) | 
|  | 6600 | { | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6601 | if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset())) | 
|  | 6602 | { | 
|  | 6603 | // We uniqued the parent class of this function to another class | 
|  | 6604 | // so we now need to associate all dies under "decl_ctx_die" to | 
|  | 6605 | // DIEs in the DIE for "class_type"... | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 6606 | SymbolFileDWARF *class_symfile = NULL; | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6607 | DWARFCompileUnitSP class_type_cu_sp; | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 6608 | const DWARFDebugInfoEntry *class_type_die = NULL; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6609 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6610 | SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile(); | 
|  | 6611 | if (debug_map_symfile) | 
|  | 6612 | { | 
|  | 6613 | class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID())); | 
|  | 6614 | class_type_die = class_symfile->DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp); | 
|  | 6615 | } | 
|  | 6616 | else | 
|  | 6617 | { | 
|  | 6618 | class_symfile = this; | 
|  | 6619 | class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp); | 
|  | 6620 | } | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6621 | if (class_type_die) | 
|  | 6622 | { | 
| Greg Clayton | d20deac | 2014-04-04 18:15:18 +0000 | [diff] [blame] | 6623 | DWARFDIECollection failures; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6624 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6625 | CopyUniqueClassMethodTypes (class_symfile, | 
|  | 6626 | class_type, | 
|  | 6627 | class_type_cu_sp.get(), | 
|  | 6628 | class_type_die, | 
|  | 6629 | dwarf_cu, | 
|  | 6630 | decl_ctx_die, | 
|  | 6631 | failures); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6632 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6633 | // FIXME do something with these failures that's smarter than | 
|  | 6634 | // just dropping them on the ground.  Unfortunately classes don't | 
|  | 6635 | // like having stuff added to them after their definitions are | 
|  | 6636 | // complete... | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6637 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6638 | type_ptr = m_die_to_type[die]; | 
|  | 6639 | if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6640 | { | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6641 | type_sp = type_ptr->shared_from_this(); | 
|  | 6642 | break; | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6643 | } | 
|  | 6644 | } | 
|  | 6645 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6646 |  | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6647 | if (specification_die_offset != DW_INVALID_OFFSET) | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6648 | { | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6649 | // We have a specification which we are going to base our function | 
|  | 6650 | // prototype off of, so we need this type to be completed so that the | 
|  | 6651 | // m_die_to_decl_ctx for the method in the specification has a valid | 
|  | 6652 | // clang decl context. | 
| Greg Clayton | 8eb732e | 2011-12-13 04:34:06 +0000 | [diff] [blame] | 6653 | class_type->GetClangForwardType(); | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6654 | // If we have a specification, then the function type should have been | 
|  | 6655 | // made with the specification and not with this die. | 
|  | 6656 | DWARFCompileUnitSP spec_cu_sp; | 
|  | 6657 | const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp); | 
| Eric Christopher | 6cc6e60 | 2012-03-25 19:37:33 +0000 | [diff] [blame] | 6658 | clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die); | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6659 | if (spec_clang_decl_ctx) | 
|  | 6660 | { | 
|  | 6661 | LinkDeclContextToDIE(spec_clang_decl_ctx, die); | 
|  | 6662 | } | 
|  | 6663 | else | 
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6664 | { | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6665 | 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] | 6666 | MakeUserID(die->GetOffset()), | 
|  | 6667 | specification_die_offset); | 
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6668 | } | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6669 | type_handled = true; | 
|  | 6670 | } | 
|  | 6671 | else if (abstract_origin_die_offset != DW_INVALID_OFFSET) | 
|  | 6672 | { | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6673 | // We have a specification which we are going to base our function | 
|  | 6674 | // prototype off of, so we need this type to be completed so that the | 
|  | 6675 | // m_die_to_decl_ctx for the method in the abstract origin has a valid | 
|  | 6676 | // clang decl context. | 
| Greg Clayton | 8eb732e | 2011-12-13 04:34:06 +0000 | [diff] [blame] | 6677 | class_type->GetClangForwardType(); | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6678 |  | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6679 | DWARFCompileUnitSP abs_cu_sp; | 
|  | 6680 | 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] | 6681 | clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die); | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6682 | if (abs_clang_decl_ctx) | 
|  | 6683 | { | 
|  | 6684 | LinkDeclContextToDIE (abs_clang_decl_ctx, die); | 
|  | 6685 | } | 
|  | 6686 | else | 
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6687 | { | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6688 | 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] | 6689 | MakeUserID(die->GetOffset()), | 
|  | 6690 | abstract_origin_die_offset); | 
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6691 | } | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6692 | type_handled = true; | 
|  | 6693 | } | 
|  | 6694 | else | 
|  | 6695 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6696 | ClangASTType class_opaque_type = class_type->GetClangForwardType(); | 
|  | 6697 | if (class_opaque_type.IsCXXClassType ()) | 
| Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 6698 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6699 | if (class_opaque_type.IsBeingDefined ()) | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6700 | { | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6701 | // Neither GCC 4.2 nor clang++ currently set a valid accessibility | 
|  | 6702 | // in the DWARF for C++ methods... Default to public for now... | 
|  | 6703 | if (accessibility == eAccessNone) | 
|  | 6704 | accessibility = eAccessPublic; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6705 |  | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6706 | if (!is_static && !die->HasChildren()) | 
|  | 6707 | { | 
|  | 6708 | // We have a C++ member function with no children (this pointer!) | 
|  | 6709 | // and clang will get mad if we try and make a function that isn't | 
|  | 6710 | // well formed in the DWARF, so we will just skip it... | 
|  | 6711 | type_handled = true; | 
|  | 6712 | } | 
|  | 6713 | else | 
|  | 6714 | { | 
|  | 6715 | clang::CXXMethodDecl *cxx_method_decl; | 
|  | 6716 | // REMOVE THE CRASH DESCRIPTION BELOW | 
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 6717 | 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] | 6718 | type_name_cstr, | 
|  | 6719 | class_type->GetName().GetCString(), | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6720 | MakeUserID(die->GetOffset()), | 
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 6721 | m_obj_file->GetFileSpec().GetPath().c_str()); | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6722 |  | 
| Sean Callanan | c1b732d | 2011-11-01 18:07:13 +0000 | [diff] [blame] | 6723 | const bool is_attr_used = false; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6724 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6725 | cxx_method_decl = class_opaque_type.AddMethodToCXXRecordType (type_name_cstr, | 
|  | 6726 | clang_type, | 
|  | 6727 | accessibility, | 
|  | 6728 | is_virtual, | 
|  | 6729 | is_static, | 
|  | 6730 | is_inline, | 
|  | 6731 | is_explicit, | 
|  | 6732 | is_attr_used, | 
|  | 6733 | is_artificial); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6734 |  | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6735 | type_handled = cxx_method_decl != NULL; | 
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6736 |  | 
|  | 6737 | if (type_handled) | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6738 | { | 
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6739 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die); | 
|  | 6740 |  | 
|  | 6741 | Host::SetCrashDescription (NULL); | 
|  | 6742 |  | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6743 |  | 
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6744 | ClangASTMetadata metadata; | 
|  | 6745 | metadata.SetUserID(MakeUserID(die->GetOffset())); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6746 |  | 
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6747 | if (!object_pointer_name.empty()) | 
|  | 6748 | { | 
|  | 6749 | metadata.SetObjectPtrName(object_pointer_name.c_str()); | 
|  | 6750 | if (log) | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6751 | log->Printf ("Setting object pointer name: %s on method object %p.\n", | 
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6752 | object_pointer_name.c_str(), | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6753 | static_cast<void*>(cxx_method_decl)); | 
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6754 | } | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6755 | GetClangASTContext().SetMetadata (cxx_method_decl, metadata); | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6756 | } | 
| Sean Callanan | b0640dc | 2013-04-09 23:22:08 +0000 | [diff] [blame] | 6757 | else | 
|  | 6758 | { | 
| Sean Callanan | de9ce87 | 2013-05-09 23:13:13 +0000 | [diff] [blame] | 6759 | ignore_containing_context = true; | 
| Sean Callanan | b0640dc | 2013-04-09 23:22:08 +0000 | [diff] [blame] | 6760 | } | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6761 | } | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6762 | } | 
|  | 6763 | else | 
|  | 6764 | { | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6765 | // We were asked to parse the type for a method in a class, yet the | 
|  | 6766 | // class hasn't been asked to complete itself through the | 
|  | 6767 | // clang::ExternalASTSource protocol, so we need to just have the | 
|  | 6768 | // class complete itself and do things the right way, then our | 
|  | 6769 | // DIE should then have an entry in the m_die_to_type map. First | 
|  | 6770 | // we need to modify the m_die_to_type so it doesn't think we are | 
|  | 6771 | // trying to parse this DIE anymore... | 
|  | 6772 | m_die_to_type[die] = NULL; | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6773 |  | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6774 | // Now we get the full type to force our class type to complete itself | 
|  | 6775 | // using the clang::ExternalASTSource protocol which will parse all | 
|  | 6776 | // base classes and all methods (including the method for this DIE). | 
|  | 6777 | class_type->GetClangFullType(); | 
| Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 6778 |  | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6779 | // The type for this DIE should have been filled in the function call above | 
|  | 6780 | type_ptr = m_die_to_type[die]; | 
| Greg Clayton | e5476db | 2012-06-01 20:32:35 +0000 | [diff] [blame] | 6781 | if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6782 | { | 
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 6783 | type_sp = type_ptr->shared_from_this(); | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6784 | break; | 
|  | 6785 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6786 |  | 
| Sean Callanan | 02eee4d | 2012-04-12 23:10:00 +0000 | [diff] [blame] | 6787 | // FIXME This is fixing some even uglier behavior but we really need to | 
|  | 6788 | // uniq the methods of each class as well as the class itself. | 
|  | 6789 | // <rdar://problem/11240464> | 
|  | 6790 | type_handled = true; | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6791 | } | 
| Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 6792 | } | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6793 | } | 
|  | 6794 | } | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6795 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6796 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6797 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6798 | if (!type_handled) | 
|  | 6799 | { | 
|  | 6800 | // We just have a function that isn't part of a class | 
| Sean Callanan | de9ce87 | 2013-05-09 23:13:13 +0000 | [diff] [blame] | 6801 | 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] | 6802 | type_name_cstr, | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6803 | clang_type, | 
|  | 6804 | storage, | 
|  | 6805 | is_inline); | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 6806 |  | 
|  | 6807 | //                            if (template_param_infos.GetSize() > 0) | 
|  | 6808 | //                            { | 
|  | 6809 | //                                clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx, | 
|  | 6810 | //                                                                                                                  function_decl, | 
|  | 6811 | //                                                                                                                  type_name_cstr, | 
|  | 6812 | //                                                                                                                  template_param_infos); | 
|  | 6813 | // | 
|  | 6814 | //                                ast.CreateFunctionTemplateSpecializationInfo (function_decl, | 
|  | 6815 | //                                                                              func_template_decl, | 
|  | 6816 | //                                                                              template_param_infos); | 
|  | 6817 | //                            } | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6818 | // Add the decl to our DIE to decl context map | 
|  | 6819 | assert (function_decl); | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6820 | LinkDeclContextToDIE(function_decl, die); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6821 | if (!function_param_decls.empty()) | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6822 | ast.SetFunctionParameters (function_decl, | 
|  | 6823 | &function_param_decls.front(), | 
|  | 6824 | function_param_decls.size()); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6825 |  | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6826 | ClangASTMetadata metadata; | 
|  | 6827 | metadata.SetUserID(MakeUserID(die->GetOffset())); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6828 |  | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6829 | if (!object_pointer_name.empty()) | 
|  | 6830 | { | 
|  | 6831 | metadata.SetObjectPtrName(object_pointer_name.c_str()); | 
| Jim Ingham | 2cffda3f | 2012-10-30 23:34:07 +0000 | [diff] [blame] | 6832 | if (log) | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6833 | log->Printf ("Setting object pointer name: %s on function object %p.", | 
| Jim Ingham | 2cffda3f | 2012-10-30 23:34:07 +0000 | [diff] [blame] | 6834 | object_pointer_name.c_str(), | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6835 | static_cast<void*>(function_decl)); | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6836 | } | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6837 | GetClangASTContext().SetMetadata (function_decl, metadata); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6838 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6839 | } | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6840 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6841 | this, | 
|  | 6842 | type_name_const_str, | 
|  | 6843 | 0, | 
|  | 6844 | NULL, | 
|  | 6845 | LLDB_INVALID_UID, | 
|  | 6846 | Type::eEncodingIsUID, | 
|  | 6847 | &decl, | 
|  | 6848 | clang_type, | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6849 | Type::eResolveStateFull)); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6850 | assert(type_sp.get()); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6851 | } | 
|  | 6852 | break; | 
|  | 6853 |  | 
|  | 6854 | case DW_TAG_array_type: | 
|  | 6855 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6856 | // 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] | 6857 | m_die_to_type[die] = DIE_IS_BEING_PARSED; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6858 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6859 | lldb::user_id_t type_die_offset = DW_INVALID_OFFSET; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6860 | int64_t first_index = 0; | 
|  | 6861 | uint32_t byte_stride = 0; | 
|  | 6862 | uint32_t bit_stride = 0; | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 6863 | bool is_vector = false; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6864 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6865 |  | 
|  | 6866 | if (num_attributes > 0) | 
|  | 6867 | { | 
|  | 6868 | uint32_t i; | 
|  | 6869 | for (i=0; i<num_attributes; ++i) | 
|  | 6870 | { | 
|  | 6871 | attr = attributes.AttributeAtIndex(i); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6872 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 6873 | { | 
|  | 6874 | switch (attr) | 
|  | 6875 | { | 
|  | 6876 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 6877 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 6878 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 6879 | case DW_AT_name: | 
|  | 6880 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6881 | type_name_const_str.SetCString(type_name_cstr); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6882 | break; | 
|  | 6883 |  | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 6884 | case DW_AT_type:            type_die_offset = form_value.Reference(); break; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6885 | case DW_AT_byte_size:       break; // byte_size = form_value.Unsigned(); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6886 | case DW_AT_byte_stride:     byte_stride = form_value.Unsigned(); break; | 
|  | 6887 | case DW_AT_bit_stride:      bit_stride = form_value.Unsigned(); break; | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 6888 | case DW_AT_GNU_vector:      is_vector = form_value.Boolean(); break; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6889 | 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] | 6890 | case DW_AT_declaration:     break; // is_forward_declaration = form_value.Boolean(); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6891 | case DW_AT_allocated: | 
|  | 6892 | case DW_AT_associated: | 
|  | 6893 | case DW_AT_data_location: | 
|  | 6894 | case DW_AT_description: | 
|  | 6895 | case DW_AT_ordering: | 
|  | 6896 | case DW_AT_start_scope: | 
|  | 6897 | case DW_AT_visibility: | 
|  | 6898 | case DW_AT_specification: | 
|  | 6899 | case DW_AT_abstract_origin: | 
|  | 6900 | case DW_AT_sibling: | 
|  | 6901 | break; | 
|  | 6902 | } | 
|  | 6903 | } | 
|  | 6904 | } | 
|  | 6905 |  | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6906 | 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] | 6907 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6908 | Type *element_type = ResolveTypeUID(type_die_offset); | 
|  | 6909 |  | 
|  | 6910 | if (element_type) | 
|  | 6911 | { | 
|  | 6912 | std::vector<uint64_t> element_orders; | 
|  | 6913 | ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride); | 
|  | 6914 | if (byte_stride == 0 && bit_stride == 0) | 
|  | 6915 | byte_stride = element_type->GetByteSize(); | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6916 | ClangASTType array_element_type = element_type->GetClangForwardType(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6917 | uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride; | 
| Siva Chandra | 89ce955 | 2015-01-05 23:06:14 +0000 | [diff] [blame] | 6918 | if (element_orders.size() > 0) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6919 | { | 
| Siva Chandra | 89ce955 | 2015-01-05 23:06:14 +0000 | [diff] [blame] | 6920 | uint64_t num_elements = 0; | 
|  | 6921 | std::vector<uint64_t>::const_reverse_iterator pos; | 
|  | 6922 | std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend(); | 
|  | 6923 | for (pos = element_orders.rbegin(); pos != end; ++pos) | 
|  | 6924 | { | 
|  | 6925 | num_elements = *pos; | 
|  | 6926 | clang_type = ast.CreateArrayType (array_element_type, | 
|  | 6927 | num_elements, | 
|  | 6928 | is_vector); | 
|  | 6929 | array_element_type = clang_type; | 
|  | 6930 | array_element_bit_stride = num_elements ? | 
|  | 6931 | array_element_bit_stride * num_elements : | 
|  | 6932 | array_element_bit_stride; | 
|  | 6933 | } | 
|  | 6934 | } | 
|  | 6935 | else | 
|  | 6936 | { | 
|  | 6937 | clang_type = ast.CreateArrayType (array_element_type, 0, is_vector); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6938 | } | 
|  | 6939 | ConstString empty_name; | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6940 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6941 | this, | 
|  | 6942 | empty_name, | 
|  | 6943 | array_element_bit_stride / 8, | 
|  | 6944 | NULL, | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6945 | type_die_offset, | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6946 | Type::eEncodingIsUID, | 
|  | 6947 | &decl, | 
|  | 6948 | clang_type, | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6949 | Type::eResolveStateFull)); | 
|  | 6950 | type_sp->SetEncodingType (element_type); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6951 | } | 
|  | 6952 | } | 
|  | 6953 | } | 
|  | 6954 | break; | 
|  | 6955 |  | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6956 | case DW_TAG_ptr_to_member_type: | 
|  | 6957 | { | 
|  | 6958 | dw_offset_t type_die_offset = DW_INVALID_OFFSET; | 
|  | 6959 | dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET; | 
|  | 6960 |  | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6961 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6962 |  | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6963 | if (num_attributes > 0) { | 
|  | 6964 | uint32_t i; | 
|  | 6965 | for (i=0; i<num_attributes; ++i) | 
|  | 6966 | { | 
|  | 6967 | attr = attributes.AttributeAtIndex(i); | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6968 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 6969 | { | 
|  | 6970 | switch (attr) | 
|  | 6971 | { | 
|  | 6972 | case DW_AT_type: | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 6973 | type_die_offset = form_value.Reference(); break; | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6974 | case DW_AT_containing_type: | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 6975 | containing_type_die_offset = form_value.Reference(); break; | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6976 | } | 
|  | 6977 | } | 
|  | 6978 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6979 |  | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6980 | Type *pointee_type = ResolveTypeUID(type_die_offset); | 
|  | 6981 | Type *class_type = ResolveTypeUID(containing_type_die_offset); | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6982 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6983 | ClangASTType pointee_clang_type = pointee_type->GetClangForwardType(); | 
|  | 6984 | ClangASTType class_clang_type = class_type->GetClangLayoutType(); | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6985 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 6986 | clang_type = pointee_clang_type.CreateMemberPointerType(class_clang_type); | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6987 |  | 
| Enrico Granata | 1cd5e92 | 2015-01-28 00:07:51 +0000 | [diff] [blame] | 6988 | byte_size = clang_type.GetByteSize(nullptr); | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6989 |  | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6990 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6991 | this, | 
|  | 6992 | type_name_const_str, | 
|  | 6993 | byte_size, | 
|  | 6994 | NULL, | 
|  | 6995 | LLDB_INVALID_UID, | 
|  | 6996 | Type::eEncodingIsUID, | 
|  | 6997 | NULL, | 
|  | 6998 | clang_type, | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6999 | Type::eResolveStateForward)); | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 7000 | } | 
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 7001 |  | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 7002 | break; | 
|  | 7003 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7004 | default: | 
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 7005 | 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", | 
|  | 7006 | die->GetOffset(), | 
|  | 7007 | tag, | 
|  | 7008 | DW_TAG_value_to_name(tag)); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7009 | break; | 
|  | 7010 | } | 
|  | 7011 |  | 
|  | 7012 | if (type_sp.get()) | 
|  | 7013 | { | 
|  | 7014 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); | 
|  | 7015 | dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; | 
|  | 7016 |  | 
|  | 7017 | SymbolContextScope * symbol_context_scope = NULL; | 
|  | 7018 | if (sc_parent_tag == DW_TAG_compile_unit) | 
|  | 7019 | { | 
|  | 7020 | symbol_context_scope = sc.comp_unit; | 
|  | 7021 | } | 
| Jason Molenda | 60db6e4 | 2014-10-16 01:40:16 +0000 | [diff] [blame] | 7022 | else if (sc.function != NULL && sc_parent_die) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7023 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7024 | 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] | 7025 | if (symbol_context_scope == NULL) | 
|  | 7026 | symbol_context_scope = sc.function; | 
|  | 7027 | } | 
|  | 7028 |  | 
|  | 7029 | if (symbol_context_scope != NULL) | 
|  | 7030 | { | 
|  | 7031 | type_sp->SetSymbolContextScope(symbol_context_scope); | 
|  | 7032 | } | 
|  | 7033 |  | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 7034 | // We are ready to put this type into the uniqued list up at the module level | 
|  | 7035 | type_list->Insert (type_sp); | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 7036 |  | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 7037 | m_die_to_type[die] = type_sp.get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7038 | } | 
|  | 7039 | } | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 7040 | else if (type_ptr != DIE_IS_BEING_PARSED) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7041 | { | 
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 7042 | type_sp = type_ptr->shared_from_this(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7043 | } | 
|  | 7044 | } | 
|  | 7045 | return type_sp; | 
|  | 7046 | } | 
|  | 7047 |  | 
|  | 7048 | size_t | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 7049 | SymbolFileDWARF::ParseTypes | 
|  | 7050 | ( | 
|  | 7051 | const SymbolContext& sc, | 
|  | 7052 | DWARFCompileUnit* dwarf_cu, | 
|  | 7053 | const DWARFDebugInfoEntry *die, | 
|  | 7054 | bool parse_siblings, | 
|  | 7055 | bool parse_children | 
|  | 7056 | ) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7057 | { | 
|  | 7058 | size_t types_added = 0; | 
|  | 7059 | while (die != NULL) | 
|  | 7060 | { | 
|  | 7061 | bool type_is_new = false; | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 7062 | if (ParseType(sc, dwarf_cu, die, &type_is_new).get()) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7063 | { | 
|  | 7064 | if (type_is_new) | 
|  | 7065 | ++types_added; | 
|  | 7066 | } | 
|  | 7067 |  | 
|  | 7068 | if (parse_children && die->HasChildren()) | 
|  | 7069 | { | 
|  | 7070 | if (die->Tag() == DW_TAG_subprogram) | 
|  | 7071 | { | 
|  | 7072 | SymbolContext child_sc(sc); | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7073 | child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7074 | types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true); | 
|  | 7075 | } | 
|  | 7076 | else | 
|  | 7077 | types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true); | 
|  | 7078 | } | 
|  | 7079 |  | 
|  | 7080 | if (parse_siblings) | 
|  | 7081 | die = die->GetSibling(); | 
|  | 7082 | else | 
|  | 7083 | die = NULL; | 
|  | 7084 | } | 
|  | 7085 | return types_added; | 
|  | 7086 | } | 
|  | 7087 |  | 
|  | 7088 |  | 
|  | 7089 | size_t | 
|  | 7090 | SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc) | 
|  | 7091 | { | 
|  | 7092 | assert(sc.comp_unit && sc.function); | 
|  | 7093 | size_t functions_added = 0; | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 7094 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7095 | if (dwarf_cu) | 
|  | 7096 | { | 
|  | 7097 | dw_offset_t function_die_offset = sc.function->GetID(); | 
|  | 7098 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset); | 
|  | 7099 | if (function_die) | 
|  | 7100 | { | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 7101 | 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] | 7102 | } | 
|  | 7103 | } | 
|  | 7104 |  | 
|  | 7105 | return functions_added; | 
|  | 7106 | } | 
|  | 7107 |  | 
|  | 7108 |  | 
|  | 7109 | size_t | 
|  | 7110 | SymbolFileDWARF::ParseTypes (const SymbolContext &sc) | 
|  | 7111 | { | 
|  | 7112 | // At least a compile unit must be valid | 
|  | 7113 | assert(sc.comp_unit); | 
|  | 7114 | size_t types_added = 0; | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 7115 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7116 | if (dwarf_cu) | 
|  | 7117 | { | 
|  | 7118 | if (sc.function) | 
|  | 7119 | { | 
|  | 7120 | dw_offset_t function_die_offset = sc.function->GetID(); | 
|  | 7121 | const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset); | 
|  | 7122 | if (func_die && func_die->HasChildren()) | 
|  | 7123 | { | 
|  | 7124 | types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true); | 
|  | 7125 | } | 
|  | 7126 | } | 
|  | 7127 | else | 
|  | 7128 | { | 
|  | 7129 | const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE(); | 
|  | 7130 | if (dwarf_cu_die && dwarf_cu_die->HasChildren()) | 
|  | 7131 | { | 
|  | 7132 | types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true); | 
|  | 7133 | } | 
|  | 7134 | } | 
|  | 7135 | } | 
|  | 7136 |  | 
|  | 7137 | return types_added; | 
|  | 7138 | } | 
|  | 7139 |  | 
|  | 7140 | size_t | 
|  | 7141 | SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc) | 
|  | 7142 | { | 
|  | 7143 | if (sc.comp_unit != NULL) | 
|  | 7144 | { | 
| Greg Clayton | 4b3dc10 | 2010-11-01 20:32:12 +0000 | [diff] [blame] | 7145 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 7146 | if (info == NULL) | 
|  | 7147 | return 0; | 
|  | 7148 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7149 | if (sc.function) | 
|  | 7150 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7151 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnitContainingDIE(sc.function->GetID()).get(); | 
|  | 7152 |  | 
|  | 7153 | if (dwarf_cu == NULL) | 
|  | 7154 | return 0; | 
|  | 7155 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7156 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID()); | 
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 7157 |  | 
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 7158 | dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS); | 
|  | 7159 | if (func_lo_pc != LLDB_INVALID_ADDRESS) | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 7160 | { | 
|  | 7161 | 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] | 7162 |  | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 7163 | // Let all blocks know they have parse all their variables | 
|  | 7164 | sc.function->GetBlock (false).SetDidParseVariables (true, true); | 
|  | 7165 | return num_variables; | 
|  | 7166 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7167 | } | 
|  | 7168 | else if (sc.comp_unit) | 
|  | 7169 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7170 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()).get(); | 
|  | 7171 |  | 
|  | 7172 | if (dwarf_cu == NULL) | 
|  | 7173 | return 0; | 
|  | 7174 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7175 | uint32_t vars_added = 0; | 
|  | 7176 | VariableListSP variables (sc.comp_unit->GetVariableList(false)); | 
|  | 7177 |  | 
|  | 7178 | if (variables.get() == NULL) | 
|  | 7179 | { | 
|  | 7180 | variables.reset(new VariableList()); | 
|  | 7181 | sc.comp_unit->SetVariableList(variables); | 
|  | 7182 |  | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7183 | DWARFCompileUnit* match_dwarf_cu = NULL; | 
|  | 7184 | const DWARFDebugInfoEntry* die = NULL; | 
|  | 7185 | DIEArray die_offsets; | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 7186 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7187 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 7188 | if (m_apple_names_ap.get()) | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7189 | { | 
|  | 7190 | DWARFMappedHash::DIEInfoArray hash_data_array; | 
|  | 7191 | if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(), | 
|  | 7192 | dwarf_cu->GetNextCompileUnitOffset(), | 
|  | 7193 | hash_data_array)) | 
|  | 7194 | { | 
|  | 7195 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); | 
|  | 7196 | } | 
|  | 7197 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7198 | } | 
|  | 7199 | else | 
|  | 7200 | { | 
|  | 7201 | // Index if we already haven't to make sure the compile units | 
|  | 7202 | // get indexed and make their global DIE index list | 
|  | 7203 | if (!m_indexed) | 
|  | 7204 | Index (); | 
|  | 7205 |  | 
|  | 7206 | m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(), | 
|  | 7207 | dwarf_cu->GetNextCompileUnitOffset(), | 
|  | 7208 | die_offsets); | 
|  | 7209 | } | 
|  | 7210 |  | 
|  | 7211 | const size_t num_matches = die_offsets.size(); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7212 | if (num_matches) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7213 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7214 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 7215 | for (size_t i=0; i<num_matches; ++i) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7216 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7217 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 7218 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 7219 | if (die) | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7220 | { | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 7221 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS)); | 
|  | 7222 | if (var_sp) | 
|  | 7223 | { | 
|  | 7224 | variables->AddVariableIfUnique (var_sp); | 
|  | 7225 | ++vars_added; | 
|  | 7226 | } | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7227 | } | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 7228 | else | 
|  | 7229 | { | 
|  | 7230 | if (m_using_apple_tables) | 
|  | 7231 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 7232 | 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] | 7233 | } | 
|  | 7234 | } | 
|  | 7235 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7236 | } | 
|  | 7237 | } | 
|  | 7238 | } | 
|  | 7239 | return vars_added; | 
|  | 7240 | } | 
|  | 7241 | } | 
|  | 7242 | return 0; | 
|  | 7243 | } | 
|  | 7244 |  | 
|  | 7245 |  | 
|  | 7246 | VariableSP | 
|  | 7247 | SymbolFileDWARF::ParseVariableDIE | 
|  | 7248 | ( | 
|  | 7249 | const SymbolContext& sc, | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 7250 | DWARFCompileUnit* dwarf_cu, | 
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 7251 | const DWARFDebugInfoEntry *die, | 
|  | 7252 | const lldb::addr_t func_low_pc | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7253 | ) | 
|  | 7254 | { | 
| Greg Clayton | 83c5cd9 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 7255 | VariableSP var_sp (m_die_to_variable_sp[die]); | 
|  | 7256 | if (var_sp) | 
|  | 7257 | return var_sp;  // Already been parsed! | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7258 |  | 
|  | 7259 | const dw_tag_t tag = die->Tag(); | 
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 7260 | ModuleSP module = GetObjectFile()->GetModule(); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7261 |  | 
|  | 7262 | if ((tag == DW_TAG_variable) || | 
|  | 7263 | (tag == DW_TAG_constant) || | 
|  | 7264 | (tag == DW_TAG_formal_parameter && sc.function)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7265 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7266 | DWARFDebugInfoEntry::Attributes attributes; | 
|  | 7267 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
|  | 7268 | if (num_attributes > 0) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7269 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7270 | const char *name = NULL; | 
|  | 7271 | const char *mangled = NULL; | 
|  | 7272 | Declaration decl; | 
|  | 7273 | uint32_t i; | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7274 | lldb::user_id_t type_uid = LLDB_INVALID_UID; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7275 | DWARFExpression location; | 
|  | 7276 | bool is_external = false; | 
|  | 7277 | bool is_artificial = false; | 
|  | 7278 | bool location_is_const_value_data = false; | 
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7279 | bool has_explicit_location = false; | 
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 7280 | DWARFFormValue const_value; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 7281 | //AccessType accessibility = eAccessNone; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7282 |  | 
|  | 7283 | for (i=0; i<num_attributes; ++i) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7284 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7285 | dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 7286 | DWARFFormValue form_value; | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 7287 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7288 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7289 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7290 | switch (attr) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7291 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7292 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 7293 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 7294 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 7295 | 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] | 7296 | case DW_AT_linkage_name: | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7297 | 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] | 7298 | case DW_AT_type:        type_uid = form_value.Reference(); break; | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 7299 | case DW_AT_external:    is_external = form_value.Boolean(); break; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7300 | case DW_AT_const_value: | 
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7301 | // If we have already found a DW_AT_location attribute, ignore this attribute. | 
|  | 7302 | if (!has_explicit_location) | 
|  | 7303 | { | 
|  | 7304 | location_is_const_value_data = true; | 
|  | 7305 | // 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] | 7306 | const DWARFDataExtractor& debug_info_data = get_debug_info_data(); | 
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7307 | if (DWARFFormValue::IsBlockForm(form_value.Form())) | 
|  | 7308 | { | 
|  | 7309 | // Retrieve the value as a block expression. | 
|  | 7310 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); | 
|  | 7311 | uint32_t block_length = form_value.Unsigned(); | 
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 7312 | location.CopyOpcodeData(module, debug_info_data, block_offset, block_length); | 
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7313 | } | 
|  | 7314 | else if (DWARFFormValue::IsDataForm(form_value.Form())) | 
|  | 7315 | { | 
|  | 7316 | // Retrieve the value as a data expression. | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 7317 | 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] | 7318 | uint32_t data_offset = attributes.DIEOffsetAtIndex(i); | 
|  | 7319 | uint32_t data_length = fixed_form_sizes[form_value.Form()]; | 
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 7320 | if (data_length == 0) | 
|  | 7321 | { | 
|  | 7322 | const uint8_t *data_pointer = form_value.BlockData(); | 
|  | 7323 | if (data_pointer) | 
|  | 7324 | { | 
| Jason Molenda | 18f5fd3 | 2014-10-16 07:52:17 +0000 | [diff] [blame] | 7325 | form_value.Unsigned(); | 
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 7326 | } | 
|  | 7327 | else if (DWARFFormValue::IsDataForm(form_value.Form())) | 
|  | 7328 | { | 
|  | 7329 | // we need to get the byte size of the type later after we create the variable | 
|  | 7330 | const_value = form_value; | 
|  | 7331 | } | 
|  | 7332 | } | 
|  | 7333 | else | 
|  | 7334 | location.CopyOpcodeData(module, debug_info_data, data_offset, data_length); | 
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7335 | } | 
|  | 7336 | else | 
|  | 7337 | { | 
|  | 7338 | // Retrieve the value as a string expression. | 
|  | 7339 | if (form_value.Form() == DW_FORM_strp) | 
|  | 7340 | { | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 7341 | 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] | 7342 | uint32_t data_offset = attributes.DIEOffsetAtIndex(i); | 
|  | 7343 | uint32_t data_length = fixed_form_sizes[form_value.Form()]; | 
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 7344 | location.CopyOpcodeData(module, debug_info_data, data_offset, data_length); | 
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7345 | } | 
|  | 7346 | else | 
|  | 7347 | { | 
|  | 7348 | const char *str = form_value.AsCString(&debug_info_data); | 
|  | 7349 | uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart(); | 
|  | 7350 | uint32_t string_length = strlen(str) + 1; | 
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 7351 | location.CopyOpcodeData(module, debug_info_data, string_offset, string_length); | 
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7352 | } | 
|  | 7353 | } | 
|  | 7354 | } | 
|  | 7355 | break; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7356 | case DW_AT_location: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7357 | { | 
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7358 | location_is_const_value_data = false; | 
|  | 7359 | has_explicit_location = true; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7360 | if (form_value.BlockData()) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7361 | { | 
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 7362 | const DWARFDataExtractor& debug_info_data = get_debug_info_data(); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7363 |  | 
|  | 7364 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); | 
|  | 7365 | uint32_t block_length = form_value.Unsigned(); | 
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 7366 | location.CopyOpcodeData(module, get_debug_info_data(), block_offset, block_length); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7367 | } | 
|  | 7368 | else | 
|  | 7369 | { | 
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 7370 | const DWARFDataExtractor&    debug_loc_data = get_debug_loc_data(); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7371 | const dw_offset_t debug_loc_offset = form_value.Unsigned(); | 
|  | 7372 |  | 
|  | 7373 | size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset); | 
|  | 7374 | if (loc_list_length > 0) | 
|  | 7375 | { | 
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 7376 | location.CopyOpcodeData(module, debug_loc_data, debug_loc_offset, loc_list_length); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7377 | assert (func_low_pc != LLDB_INVALID_ADDRESS); | 
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 7378 | location.SetLocationListSlide (func_low_pc - attributes.CompileUnitAtIndex(i)->GetBaseAddress()); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7379 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7380 | } | 
|  | 7381 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7382 | break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7383 |  | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 7384 | case DW_AT_artificial:      is_artificial = form_value.Boolean(); break; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 7385 | 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] | 7386 | case DW_AT_declaration: | 
|  | 7387 | case DW_AT_description: | 
|  | 7388 | case DW_AT_endianity: | 
|  | 7389 | case DW_AT_segment: | 
|  | 7390 | case DW_AT_start_scope: | 
|  | 7391 | case DW_AT_visibility: | 
|  | 7392 | default: | 
|  | 7393 | case DW_AT_abstract_origin: | 
|  | 7394 | case DW_AT_sibling: | 
|  | 7395 | case DW_AT_specification: | 
|  | 7396 | break; | 
|  | 7397 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7398 | } | 
|  | 7399 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7400 |  | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7401 | ValueType scope = eValueTypeInvalid; | 
|  | 7402 |  | 
|  | 7403 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); | 
|  | 7404 | dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; | 
|  | 7405 | SymbolContextScope * symbol_context_scope = NULL; | 
|  | 7406 |  | 
| Siva Chandra | 0783ab9 | 2015-03-24 18:32:27 +0000 | [diff] [blame] | 7407 | if (!mangled) | 
|  | 7408 | { | 
|  | 7409 | // LLDB relies on the mangled name (DW_TAG_linkage_name or DW_AT_MIPS_linkage_name) to | 
|  | 7410 | // generate fully qualified names of global variables with commands like "frame var j". | 
|  | 7411 | // For example, if j were an int variable holding a value 4 and declared in a namespace | 
|  | 7412 | // B which in turn is contained in a namespace A, the command "frame var j" returns | 
|  | 7413 | // "(int) A::B::j = 4". If the compiler does not emit a linkage name, we should be able | 
|  | 7414 | // to generate a fully qualified name from the declaration context. | 
|  | 7415 | if (die->GetParent()->Tag() == DW_TAG_compile_unit && | 
|  | 7416 | LanguageRuntime::LanguageIsCPlusPlus(dwarf_cu->GetLanguageType())) | 
|  | 7417 | { | 
|  | 7418 | DWARFDeclContext decl_ctx; | 
|  | 7419 |  | 
|  | 7420 | die->GetDWARFDeclContext(this, dwarf_cu, decl_ctx); | 
|  | 7421 | mangled = decl_ctx.GetQualifiedNameAsConstString().GetCString(); | 
|  | 7422 | } | 
|  | 7423 | } | 
|  | 7424 |  | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7425 | // DWARF doesn't specify if a DW_TAG_variable is a local, global | 
|  | 7426 | // or static variable, so we have to do a little digging by | 
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 7427 | // looking at the location of a variable to see if it contains | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7428 | // a DW_OP_addr opcode _somewhere_ in the definition. I say | 
|  | 7429 | // somewhere because clang likes to combine small global variables | 
|  | 7430 | // into the same symbol and have locations like: | 
|  | 7431 | // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus | 
|  | 7432 | // So if we don't have a DW_TAG_formal_parameter, we can look at | 
|  | 7433 | // the location to see if it contains a DW_OP_addr opcode, and | 
|  | 7434 | // then we can correctly classify  our variables. | 
|  | 7435 | if (tag == DW_TAG_formal_parameter) | 
|  | 7436 | scope = eValueTypeVariableArgument; | 
|  | 7437 | else | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7438 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7439 | bool op_error = false; | 
|  | 7440 | // Check if the location has a DW_OP_addr with any address value... | 
|  | 7441 | lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS; | 
|  | 7442 | if (!location_is_const_value_data) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7443 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7444 | location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error); | 
|  | 7445 | if (op_error) | 
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 7446 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7447 | StreamString strm; | 
|  | 7448 | location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL); | 
|  | 7449 | 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] | 7450 | } | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7451 | } | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7452 |  | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7453 | if (location_DW_OP_addr != LLDB_INVALID_ADDRESS) | 
|  | 7454 | { | 
|  | 7455 | if (is_external) | 
|  | 7456 | scope = eValueTypeVariableGlobal; | 
|  | 7457 | else | 
|  | 7458 | scope = eValueTypeVariableStatic; | 
|  | 7459 |  | 
|  | 7460 |  | 
|  | 7461 | SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile (); | 
|  | 7462 |  | 
|  | 7463 | if (debug_map_symfile) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7464 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7465 | // When leaving the DWARF in the .o files on darwin, | 
|  | 7466 | // when we have a global variable that wasn't initialized, | 
|  | 7467 | // the .o file might not have allocated a virtual | 
|  | 7468 | // address for the global variable. In this case it will | 
|  | 7469 | // have created a symbol for the global variable | 
|  | 7470 | // that is undefined/data and external and the value will | 
|  | 7471 | // be the byte size of the variable. When we do the | 
|  | 7472 | // address map in SymbolFileDWARFDebugMap we rely on | 
|  | 7473 | // having an address, we need to do some magic here | 
|  | 7474 | // so we can get the correct address for our global | 
|  | 7475 | // variable. The address for all of these entries | 
|  | 7476 | // will be zero, and there will be an undefined symbol | 
|  | 7477 | // in this object file, and the executable will have | 
|  | 7478 | // a matching symbol with a good address. So here we | 
|  | 7479 | // dig up the correct address and replace it in the | 
|  | 7480 | // location for the variable, and set the variable's | 
|  | 7481 | // symbol context scope to be that of the main executable | 
|  | 7482 | // so the file address will resolve correctly. | 
|  | 7483 | bool linked_oso_file_addr = false; | 
|  | 7484 | if (is_external && location_DW_OP_addr == 0) | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7485 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7486 | // we have a possible uninitialized extern global | 
|  | 7487 | ConstString const_name(mangled ? mangled : name); | 
|  | 7488 | ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile(); | 
|  | 7489 | if (debug_map_objfile) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7490 | { | 
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 7491 | Symtab *debug_map_symtab = debug_map_objfile->GetSymtab(); | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7492 | if (debug_map_symtab) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7493 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7494 | Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name, | 
|  | 7495 | eSymbolTypeData, | 
|  | 7496 | Symtab::eDebugYes, | 
|  | 7497 | Symtab::eVisibilityExtern); | 
|  | 7498 | if (exe_symbol) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7499 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7500 | if (exe_symbol->ValueIsAddress()) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7501 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7502 | const addr_t exe_file_addr = exe_symbol->GetAddress().GetFileAddress(); | 
|  | 7503 | if (exe_file_addr != LLDB_INVALID_ADDRESS) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7504 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7505 | if (location.Update_DW_OP_addr (exe_file_addr)) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7506 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7507 | linked_oso_file_addr = true; | 
|  | 7508 | symbol_context_scope = exe_symbol; | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7509 | } | 
|  | 7510 | } | 
|  | 7511 | } | 
|  | 7512 | } | 
|  | 7513 | } | 
|  | 7514 | } | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7515 | } | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7516 |  | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7517 | if (!linked_oso_file_addr) | 
|  | 7518 | { | 
|  | 7519 | // The DW_OP_addr is not zero, but it contains a .o file address which | 
|  | 7520 | // needs to be linked up correctly. | 
|  | 7521 | const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr); | 
|  | 7522 | if (exe_file_addr != LLDB_INVALID_ADDRESS) | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7523 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7524 | // Update the file address for this variable | 
|  | 7525 | location.Update_DW_OP_addr (exe_file_addr); | 
|  | 7526 | } | 
|  | 7527 | else | 
|  | 7528 | { | 
|  | 7529 | // Variable didn't make it into the final executable | 
|  | 7530 | return var_sp; | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7531 | } | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7532 | } | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7533 | } | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 7534 | } | 
|  | 7535 | else | 
|  | 7536 | { | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7537 | scope = eValueTypeVariableLocal; | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 7538 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7539 | } | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7540 |  | 
|  | 7541 | if (symbol_context_scope == NULL) | 
|  | 7542 | { | 
|  | 7543 | switch (parent_tag) | 
|  | 7544 | { | 
|  | 7545 | case DW_TAG_subprogram: | 
|  | 7546 | case DW_TAG_inlined_subroutine: | 
|  | 7547 | case DW_TAG_lexical_block: | 
|  | 7548 | if (sc.function) | 
|  | 7549 | { | 
|  | 7550 | symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); | 
|  | 7551 | if (symbol_context_scope == NULL) | 
|  | 7552 | symbol_context_scope = sc.function; | 
|  | 7553 | } | 
|  | 7554 | break; | 
|  | 7555 |  | 
|  | 7556 | default: | 
|  | 7557 | symbol_context_scope = sc.comp_unit; | 
|  | 7558 | break; | 
|  | 7559 | } | 
|  | 7560 | } | 
|  | 7561 |  | 
|  | 7562 | if (symbol_context_scope) | 
|  | 7563 | { | 
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 7564 | SymbolFileTypeSP type_sp(new SymbolFileType(*this, type_uid)); | 
|  | 7565 |  | 
|  | 7566 | if (const_value.Form() && type_sp && type_sp->GetType()) | 
|  | 7567 | location.CopyOpcodeData(const_value.Unsigned(), type_sp->GetType()->GetByteSize(), dwarf_cu->GetAddressByteSize()); | 
|  | 7568 |  | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7569 | var_sp.reset (new Variable (MakeUserID(die->GetOffset()), | 
|  | 7570 | name, | 
|  | 7571 | mangled, | 
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 7572 | type_sp, | 
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 7573 | scope, | 
|  | 7574 | symbol_context_scope, | 
|  | 7575 | &decl, | 
|  | 7576 | location, | 
|  | 7577 | is_external, | 
|  | 7578 | is_artificial)); | 
|  | 7579 |  | 
|  | 7580 | var_sp->SetLocationIsConstantValueData (location_is_const_value_data); | 
|  | 7581 | } | 
|  | 7582 | else | 
|  | 7583 | { | 
|  | 7584 | // Not ready to parse this variable yet. It might be a global | 
|  | 7585 | // or static variable that is in a function scope and the function | 
|  | 7586 | // in the symbol context wasn't filled in yet | 
|  | 7587 | return var_sp; | 
|  | 7588 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7589 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7590 | // Cache var_sp even if NULL (the variable was just a specification or | 
|  | 7591 | // was missing vital information to be able to be displayed in the debugger | 
|  | 7592 | // (missing location due to optimization, etc)) so we don't re-parse | 
|  | 7593 | // this DIE over and over later... | 
|  | 7594 | m_die_to_variable_sp[die] = var_sp; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7595 | } | 
|  | 7596 | return var_sp; | 
|  | 7597 | } | 
|  | 7598 |  | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7599 |  | 
|  | 7600 | const DWARFDebugInfoEntry * | 
|  | 7601 | SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset, | 
|  | 7602 | dw_offset_t spec_block_die_offset, | 
|  | 7603 | DWARFCompileUnit **result_die_cu_handle) | 
|  | 7604 | { | 
|  | 7605 | // Give the concrete function die specified by "func_die_offset", find the | 
|  | 7606 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points | 
|  | 7607 | // to "spec_block_die_offset" | 
|  | 7608 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 7609 |  | 
|  | 7610 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle); | 
|  | 7611 | if (die) | 
|  | 7612 | { | 
|  | 7613 | assert (*result_die_cu_handle); | 
|  | 7614 | return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle); | 
|  | 7615 | } | 
|  | 7616 | return NULL; | 
|  | 7617 | } | 
|  | 7618 |  | 
|  | 7619 |  | 
|  | 7620 | const DWARFDebugInfoEntry * | 
|  | 7621 | SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu, | 
|  | 7622 | const DWARFDebugInfoEntry *die, | 
|  | 7623 | dw_offset_t spec_block_die_offset, | 
|  | 7624 | DWARFCompileUnit **result_die_cu_handle) | 
|  | 7625 | { | 
|  | 7626 | if (die) | 
|  | 7627 | { | 
|  | 7628 | switch (die->Tag()) | 
|  | 7629 | { | 
|  | 7630 | case DW_TAG_subprogram: | 
|  | 7631 | case DW_TAG_inlined_subroutine: | 
|  | 7632 | case DW_TAG_lexical_block: | 
|  | 7633 | { | 
|  | 7634 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset) | 
|  | 7635 | { | 
|  | 7636 | *result_die_cu_handle = dwarf_cu; | 
|  | 7637 | return die; | 
|  | 7638 | } | 
|  | 7639 |  | 
|  | 7640 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset) | 
|  | 7641 | { | 
|  | 7642 | *result_die_cu_handle = dwarf_cu; | 
|  | 7643 | return die; | 
|  | 7644 | } | 
|  | 7645 | } | 
|  | 7646 | break; | 
|  | 7647 | } | 
|  | 7648 |  | 
|  | 7649 | // Give the concrete function die specified by "func_die_offset", find the | 
|  | 7650 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points | 
|  | 7651 | // to "spec_block_die_offset" | 
|  | 7652 | for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling()) | 
|  | 7653 | { | 
|  | 7654 | const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu, | 
|  | 7655 | child_die, | 
|  | 7656 | spec_block_die_offset, | 
|  | 7657 | result_die_cu_handle); | 
|  | 7658 | if (result_die) | 
|  | 7659 | return result_die; | 
|  | 7660 | } | 
|  | 7661 | } | 
|  | 7662 |  | 
|  | 7663 | *result_die_cu_handle = NULL; | 
|  | 7664 | return NULL; | 
|  | 7665 | } | 
|  | 7666 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7667 | size_t | 
|  | 7668 | SymbolFileDWARF::ParseVariables | 
|  | 7669 | ( | 
|  | 7670 | const SymbolContext& sc, | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 7671 | DWARFCompileUnit* dwarf_cu, | 
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 7672 | const lldb::addr_t func_low_pc, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7673 | const DWARFDebugInfoEntry *orig_die, | 
|  | 7674 | bool parse_siblings, | 
|  | 7675 | bool parse_children, | 
|  | 7676 | VariableList* cc_variable_list | 
|  | 7677 | ) | 
|  | 7678 | { | 
|  | 7679 | if (orig_die == NULL) | 
|  | 7680 | return 0; | 
|  | 7681 |  | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7682 | VariableListSP variable_list_sp; | 
|  | 7683 |  | 
|  | 7684 | size_t vars_added = 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7685 | const DWARFDebugInfoEntry *die = orig_die; | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7686 | while (die != NULL) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7687 | { | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7688 | dw_tag_t tag = die->Tag(); | 
|  | 7689 |  | 
|  | 7690 | // Check to see if we have already parsed this variable or constant? | 
|  | 7691 | if (m_die_to_variable_sp[die]) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7692 | { | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7693 | if (cc_variable_list) | 
|  | 7694 | cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7695 | } | 
|  | 7696 | else | 
|  | 7697 | { | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7698 | // We haven't already parsed it, lets do that now. | 
|  | 7699 | if ((tag == DW_TAG_variable) || | 
|  | 7700 | (tag == DW_TAG_constant) || | 
|  | 7701 | (tag == DW_TAG_formal_parameter && sc.function)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7702 | { | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7703 | if (variable_list_sp.get() == NULL) | 
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7704 | { | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7705 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die); | 
|  | 7706 | dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; | 
|  | 7707 | switch (parent_tag) | 
|  | 7708 | { | 
|  | 7709 | case DW_TAG_compile_unit: | 
|  | 7710 | if (sc.comp_unit != NULL) | 
|  | 7711 | { | 
|  | 7712 | variable_list_sp = sc.comp_unit->GetVariableList(false); | 
|  | 7713 | if (variable_list_sp.get() == NULL) | 
|  | 7714 | { | 
|  | 7715 | variable_list_sp.reset(new VariableList()); | 
|  | 7716 | sc.comp_unit->SetVariableList(variable_list_sp); | 
|  | 7717 | } | 
|  | 7718 | } | 
|  | 7719 | else | 
|  | 7720 | { | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 7721 | 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] | 7722 | MakeUserID(sc_parent_die->GetOffset()), | 
|  | 7723 | DW_TAG_value_to_name (parent_tag), | 
|  | 7724 | MakeUserID(orig_die->GetOffset()), | 
|  | 7725 | DW_TAG_value_to_name (orig_die->Tag())); | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7726 | } | 
|  | 7727 | break; | 
|  | 7728 |  | 
|  | 7729 | case DW_TAG_subprogram: | 
|  | 7730 | case DW_TAG_inlined_subroutine: | 
|  | 7731 | case DW_TAG_lexical_block: | 
|  | 7732 | if (sc.function != NULL) | 
|  | 7733 | { | 
|  | 7734 | // Check to see if we already have parsed the variables for the given scope | 
|  | 7735 |  | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7736 | Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7737 | if (block == NULL) | 
|  | 7738 | { | 
|  | 7739 | // This must be a specification or abstract origin with | 
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 7740 | // a concrete block counterpart in the current function. We need | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7741 | // to find the concrete block so we can correctly add the | 
|  | 7742 | // variable to it | 
|  | 7743 | DWARFCompileUnit *concrete_block_die_cu = dwarf_cu; | 
|  | 7744 | const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(), | 
|  | 7745 | sc_parent_die->GetOffset(), | 
|  | 7746 | &concrete_block_die_cu); | 
|  | 7747 | if (concrete_block_die) | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7748 | block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset())); | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7749 | } | 
|  | 7750 |  | 
|  | 7751 | if (block != NULL) | 
|  | 7752 | { | 
|  | 7753 | const bool can_create = false; | 
|  | 7754 | variable_list_sp = block->GetBlockVariableList (can_create); | 
|  | 7755 | if (variable_list_sp.get() == NULL) | 
|  | 7756 | { | 
|  | 7757 | variable_list_sp.reset(new VariableList()); | 
|  | 7758 | block->SetVariableList(variable_list_sp); | 
|  | 7759 | } | 
|  | 7760 | } | 
|  | 7761 | } | 
|  | 7762 | break; | 
|  | 7763 |  | 
|  | 7764 | default: | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 7765 | 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] | 7766 | MakeUserID(orig_die->GetOffset()), | 
|  | 7767 | DW_TAG_value_to_name (orig_die->Tag())); | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7768 | break; | 
|  | 7769 | } | 
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7770 | } | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7771 |  | 
|  | 7772 | if (variable_list_sp) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7773 | { | 
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7774 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc)); | 
|  | 7775 | if (var_sp) | 
|  | 7776 | { | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7777 | variable_list_sp->AddVariableIfUnique (var_sp); | 
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7778 | if (cc_variable_list) | 
|  | 7779 | cc_variable_list->AddVariableIfUnique (var_sp); | 
|  | 7780 | ++vars_added; | 
|  | 7781 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7782 | } | 
|  | 7783 | } | 
|  | 7784 | } | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7785 |  | 
|  | 7786 | bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram); | 
|  | 7787 |  | 
|  | 7788 | if (!skip_children && parse_children && die->HasChildren()) | 
|  | 7789 | { | 
|  | 7790 | vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list); | 
|  | 7791 | } | 
|  | 7792 |  | 
|  | 7793 | if (parse_siblings) | 
|  | 7794 | die = die->GetSibling(); | 
|  | 7795 | else | 
|  | 7796 | die = NULL; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7797 | } | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7798 | return vars_added; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7799 | } | 
|  | 7800 |  | 
|  | 7801 | //------------------------------------------------------------------ | 
|  | 7802 | // PluginInterface protocol | 
|  | 7803 | //------------------------------------------------------------------ | 
| Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 7804 | ConstString | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7805 | SymbolFileDWARF::GetPluginName() | 
|  | 7806 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7807 | return GetPluginNameStatic(); | 
|  | 7808 | } | 
|  | 7809 |  | 
|  | 7810 | uint32_t | 
|  | 7811 | SymbolFileDWARF::GetPluginVersion() | 
|  | 7812 | { | 
|  | 7813 | return 1; | 
|  | 7814 | } | 
|  | 7815 |  | 
|  | 7816 | void | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 7817 | SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl) | 
|  | 7818 | { | 
|  | 7819 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 7820 | ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 7821 | if (clang_type) | 
|  | 7822 | symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); | 
|  | 7823 | } | 
|  | 7824 |  | 
|  | 7825 | void | 
|  | 7826 | SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl) | 
|  | 7827 | { | 
|  | 7828 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 7829 | ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 7830 | if (clang_type) | 
|  | 7831 | symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); | 
|  | 7832 | } | 
|  | 7833 |  | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7834 | void | 
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7835 | SymbolFileDWARF::DumpIndexes () | 
|  | 7836 | { | 
|  | 7837 | StreamFile s(stdout, false); | 
|  | 7838 |  | 
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 7839 | s.Printf ("DWARF index for (%s) '%s':", | 
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7840 | GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(), | 
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 7841 | GetObjectFile()->GetFileSpec().GetPath().c_str()); | 
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7842 | s.Printf("\nFunction basenames:\n");    m_function_basename_index.Dump (&s); | 
|  | 7843 | s.Printf("\nFunction fullnames:\n");    m_function_fullname_index.Dump (&s); | 
|  | 7844 | s.Printf("\nFunction methods:\n");      m_function_method_index.Dump (&s); | 
|  | 7845 | s.Printf("\nFunction selectors:\n");    m_function_selector_index.Dump (&s); | 
|  | 7846 | s.Printf("\nObjective C class selectors:\n");    m_objc_class_selectors_index.Dump (&s); | 
|  | 7847 | s.Printf("\nGlobals and statics:\n");   m_global_index.Dump (&s); | 
|  | 7848 | s.Printf("\nTypes:\n");                 m_type_index.Dump (&s); | 
|  | 7849 | s.Printf("\nNamepaces:\n");             m_namespace_index.Dump (&s); | 
|  | 7850 | } | 
|  | 7851 |  | 
|  | 7852 | void | 
|  | 7853 | SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context, | 
|  | 7854 | const char *name, | 
|  | 7855 | llvm::SmallVectorImpl <clang::NamedDecl *> *results) | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7856 | { | 
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7857 | DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context); | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7858 |  | 
|  | 7859 | if (iter == m_decl_ctx_to_die.end()) | 
|  | 7860 | return; | 
|  | 7861 |  | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7862 | 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] | 7863 | { | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7864 | const DWARFDebugInfoEntry *context_die = *pos; | 
|  | 7865 |  | 
|  | 7866 | if (!results) | 
|  | 7867 | return; | 
|  | 7868 |  | 
|  | 7869 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 7870 |  | 
|  | 7871 | DIEArray die_offsets; | 
|  | 7872 |  | 
|  | 7873 | DWARFCompileUnit* dwarf_cu = NULL; | 
|  | 7874 | const DWARFDebugInfoEntry* die = NULL; | 
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 7875 |  | 
|  | 7876 | if (m_using_apple_tables) | 
|  | 7877 | { | 
|  | 7878 | if (m_apple_types_ap.get()) | 
|  | 7879 | m_apple_types_ap->FindByName (name, die_offsets); | 
|  | 7880 | } | 
|  | 7881 | else | 
|  | 7882 | { | 
|  | 7883 | if (!m_indexed) | 
|  | 7884 | Index (); | 
|  | 7885 |  | 
|  | 7886 | m_type_index.Find (ConstString(name), die_offsets); | 
|  | 7887 | } | 
|  | 7888 |  | 
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 7889 | const size_t num_matches = die_offsets.size(); | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7890 |  | 
|  | 7891 | if (num_matches) | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7892 | { | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7893 | for (size_t i = 0; i < num_matches; ++i) | 
|  | 7894 | { | 
|  | 7895 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 7896 | die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7897 |  | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7898 | if (die->GetParent() != context_die) | 
|  | 7899 | continue; | 
|  | 7900 |  | 
|  | 7901 | Type *matching_type = ResolveType (dwarf_cu, die); | 
|  | 7902 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 7903 | clang::QualType qual_type = matching_type->GetClangForwardType().GetQualType(); | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7904 |  | 
|  | 7905 | if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr())) | 
|  | 7906 | { | 
|  | 7907 | clang::TagDecl *tag_decl = tag_type->getDecl(); | 
|  | 7908 | results->push_back(tag_decl); | 
|  | 7909 | } | 
|  | 7910 | else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr())) | 
|  | 7911 | { | 
|  | 7912 | clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl(); | 
|  | 7913 | results->push_back(typedef_decl); | 
|  | 7914 | } | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7915 | } | 
|  | 7916 | } | 
|  | 7917 | } | 
|  | 7918 | } | 
|  | 7919 |  | 
|  | 7920 | void | 
|  | 7921 | SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton, | 
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 7922 | const clang::DeclContext *decl_context, | 
|  | 7923 | clang::DeclarationName decl_name, | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7924 | llvm::SmallVectorImpl <clang::NamedDecl *> *results) | 
|  | 7925 | { | 
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 7926 |  | 
|  | 7927 | switch (decl_context->getDeclKind()) | 
|  | 7928 | { | 
|  | 7929 | case clang::Decl::Namespace: | 
|  | 7930 | case clang::Decl::TranslationUnit: | 
|  | 7931 | { | 
|  | 7932 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; | 
|  | 7933 | symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results); | 
|  | 7934 | } | 
|  | 7935 | break; | 
|  | 7936 | default: | 
|  | 7937 | break; | 
|  | 7938 | } | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7939 | } | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7940 |  | 
| Zachary Turner | 504f38d | 2015-03-24 16:24:50 +0000 | [diff] [blame] | 7941 | bool | 
|  | 7942 | SymbolFileDWARF::LayoutRecordType(void *baton, const clang::RecordDecl *record_decl, uint64_t &size, | 
|  | 7943 | uint64_t &alignment, | 
| Zachary Turner | a98fac2 | 2015-03-24 18:56:08 +0000 | [diff] [blame] | 7944 | llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets, | 
|  | 7945 | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, | 
|  | 7946 | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7947 | { | 
|  | 7948 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; | 
|  | 7949 | return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets); | 
|  | 7950 | } | 
|  | 7951 |  | 
| Zachary Turner | 504f38d | 2015-03-24 16:24:50 +0000 | [diff] [blame] | 7952 | bool | 
|  | 7953 | SymbolFileDWARF::LayoutRecordType(const clang::RecordDecl *record_decl, uint64_t &bit_size, uint64_t &alignment, | 
| Zachary Turner | a98fac2 | 2015-03-24 18:56:08 +0000 | [diff] [blame] | 7954 | llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets, | 
|  | 7955 | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, | 
|  | 7956 | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7957 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 7958 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7959 | RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl); | 
|  | 7960 | bool success = false; | 
|  | 7961 | base_offsets.clear(); | 
|  | 7962 | vbase_offsets.clear(); | 
|  | 7963 | if (pos != m_record_decl_to_layout_map.end()) | 
|  | 7964 | { | 
|  | 7965 | bit_size = pos->second.bit_size; | 
|  | 7966 | alignment = pos->second.alignment; | 
|  | 7967 | field_offsets.swap(pos->second.field_offsets); | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 7968 | base_offsets.swap (pos->second.base_offsets); | 
|  | 7969 | vbase_offsets.swap (pos->second.vbase_offsets); | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7970 | m_record_decl_to_layout_map.erase(pos); | 
|  | 7971 | success = true; | 
|  | 7972 | } | 
|  | 7973 | else | 
|  | 7974 | { | 
|  | 7975 | bit_size = 0; | 
|  | 7976 | alignment = 0; | 
|  | 7977 | field_offsets.clear(); | 
|  | 7978 | } | 
|  | 7979 |  | 
|  | 7980 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 7981 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 7982 | "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] | 7983 | static_cast<const void*>(record_decl), | 
|  | 7984 | bit_size, alignment, | 
|  | 7985 | static_cast<uint32_t>(field_offsets.size()), | 
|  | 7986 | static_cast<uint32_t>(base_offsets.size()), | 
|  | 7987 | static_cast<uint32_t>(vbase_offsets.size()), | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7988 | success); | 
|  | 7989 | return success; | 
|  | 7990 | } | 
|  | 7991 |  | 
|  | 7992 |  | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 7993 | SymbolFileDWARFDebugMap * | 
|  | 7994 | SymbolFileDWARF::GetDebugMapSymfile () | 
|  | 7995 | { | 
|  | 7996 | if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired()) | 
|  | 7997 | { | 
|  | 7998 | lldb::ModuleSP module_sp (m_debug_map_module_wp.lock()); | 
|  | 7999 | if (module_sp) | 
|  | 8000 | { | 
|  | 8001 | SymbolVendor *sym_vendor = module_sp->GetSymbolVendor(); | 
|  | 8002 | if (sym_vendor) | 
|  | 8003 | m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile(); | 
|  | 8004 | } | 
|  | 8005 | } | 
|  | 8006 | return m_debug_map_symfile; | 
|  | 8007 | } | 
|  | 8008 |  | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 8009 |  |