| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- SymbolFileDWARF.cpp ------------------------------------*- C++ -*-===// | 
|  | 2 | // | 
|  | 3 | //                     The LLVM Compiler Infrastructure | 
|  | 4 | // | 
|  | 5 | // This file is distributed under the University of Illinois Open Source | 
|  | 6 | // License. See LICENSE.TXT for details. | 
|  | 7 | // | 
|  | 8 | //===----------------------------------------------------------------------===// | 
|  | 9 |  | 
|  | 10 | #include "SymbolFileDWARF.h" | 
|  | 11 |  | 
|  | 12 | // Other libraries and framework includes | 
|  | 13 | #include "clang/AST/ASTConsumer.h" | 
|  | 14 | #include "clang/AST/ASTContext.h" | 
|  | 15 | #include "clang/AST/Decl.h" | 
|  | 16 | #include "clang/AST/DeclGroup.h" | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclObjC.h" | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclTemplate.h" | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | #include "clang/Basic/Builtins.h" | 
|  | 20 | #include "clang/Basic/IdentifierTable.h" | 
|  | 21 | #include "clang/Basic/LangOptions.h" | 
|  | 22 | #include "clang/Basic/SourceManager.h" | 
|  | 23 | #include "clang/Basic/TargetInfo.h" | 
|  | 24 | #include "clang/Basic/Specifiers.h" | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 25 | #include "clang/Sema/DeclSpec.h" | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 26 |  | 
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 27 | #include "llvm/Support/Casting.h" | 
|  | 28 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | #include "lldb/Core/Module.h" | 
|  | 30 | #include "lldb/Core/PluginManager.h" | 
|  | 31 | #include "lldb/Core/RegularExpression.h" | 
|  | 32 | #include "lldb/Core/Scalar.h" | 
|  | 33 | #include "lldb/Core/Section.h" | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 34 | #include "lldb/Core/StreamFile.h" | 
| Jim Ingham | 318c9f2 | 2011-08-26 19:44:13 +0000 | [diff] [blame] | 35 | #include "lldb/Core/StreamString.h" | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 36 | #include "lldb/Core/Timer.h" | 
|  | 37 | #include "lldb/Core/Value.h" | 
|  | 38 |  | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 39 | #include "lldb/Host/Host.h" | 
|  | 40 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 41 | #include "lldb/Symbol/Block.h" | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 42 | #include "lldb/Symbol/ClangExternalASTSourceCallbacks.h" | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | #include "lldb/Symbol/CompileUnit.h" | 
|  | 44 | #include "lldb/Symbol/LineTable.h" | 
|  | 45 | #include "lldb/Symbol/ObjectFile.h" | 
|  | 46 | #include "lldb/Symbol/SymbolVendor.h" | 
|  | 47 | #include "lldb/Symbol/VariableList.h" | 
|  | 48 |  | 
| Jim Ingham | b7f6b2f | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 49 | #include "lldb/Target/ObjCLanguageRuntime.h" | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 50 | #include "lldb/Target/CPPLanguageRuntime.h" | 
| Jim Ingham | b7f6b2f | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 51 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 52 | #include "DWARFCompileUnit.h" | 
|  | 53 | #include "DWARFDebugAbbrev.h" | 
|  | 54 | #include "DWARFDebugAranges.h" | 
|  | 55 | #include "DWARFDebugInfo.h" | 
|  | 56 | #include "DWARFDebugInfoEntry.h" | 
|  | 57 | #include "DWARFDebugLine.h" | 
|  | 58 | #include "DWARFDebugPubnames.h" | 
|  | 59 | #include "DWARFDebugRanges.h" | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 60 | #include "DWARFDeclContext.h" | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 61 | #include "DWARFDIECollection.h" | 
|  | 62 | #include "DWARFFormValue.h" | 
|  | 63 | #include "DWARFLocationList.h" | 
|  | 64 | #include "LogChannelDWARF.h" | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 65 | #include "SymbolFileDWARFDebugMap.h" | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 66 |  | 
|  | 67 | #include <map> | 
|  | 68 |  | 
| Greg Clayton | 62742b1 | 2010-11-11 01:09:45 +0000 | [diff] [blame] | 69 | //#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 70 |  | 
|  | 71 | #ifdef ENABLE_DEBUG_PRINTF | 
|  | 72 | #include <stdio.h> | 
|  | 73 | #define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__) | 
|  | 74 | #else | 
|  | 75 | #define DEBUG_PRINTF(fmt, ...) | 
|  | 76 | #endif | 
|  | 77 |  | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 78 | #define DIE_IS_BEING_PARSED ((lldb_private::Type*)1) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 79 |  | 
|  | 80 | using namespace lldb; | 
|  | 81 | using namespace lldb_private; | 
|  | 82 |  | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 83 | //static inline bool | 
|  | 84 | //child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag) | 
|  | 85 | //{ | 
|  | 86 | //    switch (tag) | 
|  | 87 | //    { | 
|  | 88 | //    default: | 
|  | 89 | //        break; | 
|  | 90 | //    case DW_TAG_subprogram: | 
|  | 91 | //    case DW_TAG_inlined_subroutine: | 
|  | 92 | //    case DW_TAG_class_type: | 
|  | 93 | //    case DW_TAG_structure_type: | 
|  | 94 | //    case DW_TAG_union_type: | 
|  | 95 | //        return true; | 
|  | 96 | //    } | 
|  | 97 | //    return false; | 
|  | 98 | //} | 
|  | 99 | // | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 100 | static AccessType | 
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 101 | DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 102 | { | 
|  | 103 | switch (dwarf_accessibility) | 
|  | 104 | { | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 105 | case DW_ACCESS_public:      return eAccessPublic; | 
|  | 106 | case DW_ACCESS_private:     return eAccessPrivate; | 
|  | 107 | case DW_ACCESS_protected:   return eAccessProtected; | 
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 108 | default:                    break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 109 | } | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 110 | return eAccessNone; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 111 | } | 
|  | 112 |  | 
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 113 | #if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE) | 
|  | 114 |  | 
|  | 115 | class DIEStack | 
|  | 116 | { | 
|  | 117 | public: | 
|  | 118 |  | 
|  | 119 | void Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) | 
|  | 120 | { | 
|  | 121 | m_dies.push_back (DIEInfo(cu, die)); | 
|  | 122 | } | 
|  | 123 |  | 
|  | 124 |  | 
|  | 125 | void LogDIEs (Log *log, SymbolFileDWARF *dwarf) | 
|  | 126 | { | 
|  | 127 | StreamString log_strm; | 
|  | 128 | const size_t n = m_dies.size(); | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 129 | log_strm.Printf("DIEStack[%" PRIu64 "]:\n", (uint64_t)n); | 
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 130 | for (size_t i=0; i<n; i++) | 
|  | 131 | { | 
|  | 132 | DWARFCompileUnit *cu = m_dies[i].cu; | 
|  | 133 | const DWARFDebugInfoEntry *die = m_dies[i].die; | 
|  | 134 | std::string qualified_name; | 
|  | 135 | die->GetQualifiedName(dwarf, cu, qualified_name); | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 136 | log_strm.Printf ("[%" PRIu64 "] 0x%8.8x: %s name='%s'\n", | 
| Greg Clayton | 43e0af0 | 2012-09-18 18:04:04 +0000 | [diff] [blame] | 137 | (uint64_t)i, | 
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 138 | die->GetOffset(), | 
|  | 139 | DW_TAG_value_to_name(die->Tag()), | 
|  | 140 | qualified_name.c_str()); | 
|  | 141 | } | 
|  | 142 | log->PutCString(log_strm.GetData()); | 
|  | 143 | } | 
|  | 144 | void Pop () | 
|  | 145 | { | 
|  | 146 | m_dies.pop_back(); | 
|  | 147 | } | 
|  | 148 |  | 
|  | 149 | class ScopedPopper | 
|  | 150 | { | 
|  | 151 | public: | 
|  | 152 | ScopedPopper (DIEStack &die_stack) : | 
|  | 153 | m_die_stack (die_stack), | 
|  | 154 | m_valid (false) | 
|  | 155 | { | 
|  | 156 | } | 
|  | 157 |  | 
|  | 158 | void | 
|  | 159 | Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) | 
|  | 160 | { | 
|  | 161 | m_valid = true; | 
|  | 162 | m_die_stack.Push (cu, die); | 
|  | 163 | } | 
|  | 164 |  | 
|  | 165 | ~ScopedPopper () | 
|  | 166 | { | 
|  | 167 | if (m_valid) | 
|  | 168 | m_die_stack.Pop(); | 
|  | 169 | } | 
|  | 170 |  | 
|  | 171 |  | 
|  | 172 |  | 
|  | 173 | protected: | 
|  | 174 | DIEStack &m_die_stack; | 
|  | 175 | bool m_valid; | 
|  | 176 | }; | 
|  | 177 |  | 
|  | 178 | protected: | 
|  | 179 | struct DIEInfo { | 
|  | 180 | DIEInfo (DWARFCompileUnit *c, const DWARFDebugInfoEntry *d) : | 
|  | 181 | cu(c), | 
|  | 182 | die(d) | 
|  | 183 | { | 
|  | 184 | } | 
|  | 185 | DWARFCompileUnit *cu; | 
|  | 186 | const DWARFDebugInfoEntry *die; | 
|  | 187 | }; | 
|  | 188 | typedef std::vector<DIEInfo> Stack; | 
|  | 189 | Stack m_dies; | 
|  | 190 | }; | 
|  | 191 | #endif | 
|  | 192 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 193 | void | 
|  | 194 | SymbolFileDWARF::Initialize() | 
|  | 195 | { | 
|  | 196 | LogChannelDWARF::Initialize(); | 
|  | 197 | PluginManager::RegisterPlugin (GetPluginNameStatic(), | 
|  | 198 | GetPluginDescriptionStatic(), | 
|  | 199 | CreateInstance); | 
|  | 200 | } | 
|  | 201 |  | 
|  | 202 | void | 
|  | 203 | SymbolFileDWARF::Terminate() | 
|  | 204 | { | 
|  | 205 | PluginManager::UnregisterPlugin (CreateInstance); | 
|  | 206 | LogChannelDWARF::Initialize(); | 
|  | 207 | } | 
|  | 208 |  | 
|  | 209 |  | 
|  | 210 | const char * | 
|  | 211 | SymbolFileDWARF::GetPluginNameStatic() | 
|  | 212 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 213 | return "dwarf"; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 214 | } | 
|  | 215 |  | 
|  | 216 | const char * | 
|  | 217 | SymbolFileDWARF::GetPluginDescriptionStatic() | 
|  | 218 | { | 
|  | 219 | return "DWARF and DWARF3 debug symbol file reader."; | 
|  | 220 | } | 
|  | 221 |  | 
|  | 222 |  | 
|  | 223 | SymbolFile* | 
|  | 224 | SymbolFileDWARF::CreateInstance (ObjectFile* obj_file) | 
|  | 225 | { | 
|  | 226 | return new SymbolFileDWARF(obj_file); | 
|  | 227 | } | 
|  | 228 |  | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 229 | TypeList * | 
|  | 230 | SymbolFileDWARF::GetTypeList () | 
|  | 231 | { | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 232 | if (GetDebugMapSymfile ()) | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 233 | return m_debug_map_symfile->GetTypeList(); | 
|  | 234 | return m_obj_file->GetModule()->GetTypeList(); | 
|  | 235 |  | 
|  | 236 | } | 
|  | 237 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 238 | //---------------------------------------------------------------------- | 
|  | 239 | // Gets the first parent that is a lexical block, function or inlined | 
|  | 240 | // subroutine, or compile unit. | 
|  | 241 | //---------------------------------------------------------------------- | 
|  | 242 | static const DWARFDebugInfoEntry * | 
|  | 243 | GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die) | 
|  | 244 | { | 
|  | 245 | const DWARFDebugInfoEntry *die; | 
|  | 246 | for (die = child_die->GetParent(); die != NULL; die = die->GetParent()) | 
|  | 247 | { | 
|  | 248 | dw_tag_t tag = die->Tag(); | 
|  | 249 |  | 
|  | 250 | switch (tag) | 
|  | 251 | { | 
|  | 252 | case DW_TAG_compile_unit: | 
|  | 253 | case DW_TAG_subprogram: | 
|  | 254 | case DW_TAG_inlined_subroutine: | 
|  | 255 | case DW_TAG_lexical_block: | 
|  | 256 | return die; | 
|  | 257 | } | 
|  | 258 | } | 
|  | 259 | return NULL; | 
|  | 260 | } | 
|  | 261 |  | 
|  | 262 |  | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 263 | SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) : | 
|  | 264 | SymbolFile (objfile), | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 265 | 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] | 266 | m_debug_map_module_wp (), | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 267 | m_debug_map_symfile (NULL), | 
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 268 | m_clang_tu_decl (NULL), | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 269 | m_flags(), | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 270 | m_data_debug_abbrev (), | 
|  | 271 | m_data_debug_aranges (), | 
|  | 272 | m_data_debug_frame (), | 
|  | 273 | m_data_debug_info (), | 
|  | 274 | m_data_debug_line (), | 
|  | 275 | m_data_debug_loc (), | 
|  | 276 | m_data_debug_ranges (), | 
|  | 277 | m_data_debug_str (), | 
| Greg Clayton | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 278 | m_data_apple_names (), | 
|  | 279 | m_data_apple_types (), | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 280 | m_data_apple_namespaces (), | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 281 | m_abbr(), | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 282 | m_info(), | 
|  | 283 | m_line(), | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 284 | m_apple_names_ap (), | 
|  | 285 | m_apple_types_ap (), | 
|  | 286 | m_apple_namespaces_ap (), | 
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 287 | m_apple_objc_ap (), | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 288 | m_function_basename_index(), | 
|  | 289 | m_function_fullname_index(), | 
|  | 290 | m_function_method_index(), | 
|  | 291 | m_function_selector_index(), | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 292 | m_objc_class_selectors_index(), | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 293 | m_global_index(), | 
| Greg Clayton | 69b0488 | 2010-10-15 02:03:22 +0000 | [diff] [blame] | 294 | m_type_index(), | 
|  | 295 | m_namespace_index(), | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 296 | m_indexed (false), | 
|  | 297 | m_is_external_ast_source (false), | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 298 | m_using_apple_tables (false), | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 299 | m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate), | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 300 | m_ranges(), | 
|  | 301 | m_unique_ast_type_map () | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 302 | { | 
|  | 303 | } | 
|  | 304 |  | 
|  | 305 | SymbolFileDWARF::~SymbolFileDWARF() | 
|  | 306 | { | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 307 | if (m_is_external_ast_source) | 
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 308 | { | 
|  | 309 | ModuleSP module_sp (m_obj_file->GetModule()); | 
|  | 310 | if (module_sp) | 
|  | 311 | module_sp->GetClangASTContext().RemoveExternalSource (); | 
|  | 312 | } | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 313 | } | 
|  | 314 |  | 
|  | 315 | static const ConstString & | 
|  | 316 | GetDWARFMachOSegmentName () | 
|  | 317 | { | 
|  | 318 | static ConstString g_dwarf_section_name ("__DWARF"); | 
|  | 319 | return g_dwarf_section_name; | 
|  | 320 | } | 
|  | 321 |  | 
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 322 | UniqueDWARFASTTypeMap & | 
|  | 323 | SymbolFileDWARF::GetUniqueDWARFASTTypeMap () | 
|  | 324 | { | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 325 | if (GetDebugMapSymfile ()) | 
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 326 | return m_debug_map_symfile->GetUniqueDWARFASTTypeMap (); | 
|  | 327 | return m_unique_ast_type_map; | 
|  | 328 | } | 
|  | 329 |  | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 330 | ClangASTContext & | 
|  | 331 | SymbolFileDWARF::GetClangASTContext () | 
|  | 332 | { | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 333 | if (GetDebugMapSymfile ()) | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 334 | return m_debug_map_symfile->GetClangASTContext (); | 
|  | 335 |  | 
|  | 336 | ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext(); | 
|  | 337 | if (!m_is_external_ast_source) | 
|  | 338 | { | 
|  | 339 | m_is_external_ast_source = true; | 
|  | 340 | llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap ( | 
|  | 341 | new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl, | 
|  | 342 | SymbolFileDWARF::CompleteObjCInterfaceDecl, | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 343 | SymbolFileDWARF::FindExternalVisibleDeclsByName, | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 344 | SymbolFileDWARF::LayoutRecordType, | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 345 | this)); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 346 | ast.SetExternalSource (ast_source_ap); | 
|  | 347 | } | 
|  | 348 | return ast; | 
|  | 349 | } | 
|  | 350 |  | 
|  | 351 | void | 
|  | 352 | SymbolFileDWARF::InitializeObject() | 
|  | 353 | { | 
|  | 354 | // Install our external AST source callbacks so we can complete Clang types. | 
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 355 | ModuleSP module_sp (m_obj_file->GetModule()); | 
|  | 356 | if (module_sp) | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 357 | { | 
|  | 358 | const SectionList *section_list = m_obj_file->GetSectionList(); | 
|  | 359 |  | 
|  | 360 | const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get(); | 
|  | 361 |  | 
|  | 362 | // Memory map the DWARF mach-o segment so we have everything mmap'ed | 
|  | 363 | // to keep our heap memory usage down. | 
|  | 364 | if (section) | 
| Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 365 | m_obj_file->MemoryMapSectionData(section, m_dwarf_data); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 366 | } | 
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 367 | get_apple_names_data(); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 368 | if (m_data_apple_names.GetByteSize() > 0) | 
|  | 369 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 370 | m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names")); | 
|  | 371 | if (m_apple_names_ap->IsValid()) | 
|  | 372 | m_using_apple_tables = true; | 
|  | 373 | else | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 374 | m_apple_names_ap.reset(); | 
|  | 375 | } | 
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 376 | get_apple_types_data(); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 377 | if (m_data_apple_types.GetByteSize() > 0) | 
|  | 378 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 379 | m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types")); | 
|  | 380 | if (m_apple_types_ap->IsValid()) | 
|  | 381 | m_using_apple_tables = true; | 
|  | 382 | else | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 383 | m_apple_types_ap.reset(); | 
|  | 384 | } | 
|  | 385 |  | 
|  | 386 | get_apple_namespaces_data(); | 
|  | 387 | if (m_data_apple_namespaces.GetByteSize() > 0) | 
|  | 388 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 389 | m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces")); | 
|  | 390 | if (m_apple_namespaces_ap->IsValid()) | 
|  | 391 | m_using_apple_tables = true; | 
|  | 392 | else | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 393 | m_apple_namespaces_ap.reset(); | 
|  | 394 | } | 
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 395 |  | 
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 396 | get_apple_objc_data(); | 
|  | 397 | if (m_data_apple_objc.GetByteSize() > 0) | 
|  | 398 | { | 
|  | 399 | m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc")); | 
|  | 400 | if (m_apple_objc_ap->IsValid()) | 
|  | 401 | m_using_apple_tables = true; | 
|  | 402 | else | 
|  | 403 | m_apple_objc_ap.reset(); | 
|  | 404 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 405 | } | 
|  | 406 |  | 
|  | 407 | bool | 
|  | 408 | SymbolFileDWARF::SupportedVersion(uint16_t version) | 
|  | 409 | { | 
| Greg Clayton | abcbfe5 | 2013-04-04 00:00:36 +0000 | [diff] [blame] | 410 | return version == 2 || version == 3 || version == 4; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 411 | } | 
|  | 412 |  | 
|  | 413 | uint32_t | 
| Sean Callanan | bfaf54d | 2011-12-03 04:38:43 +0000 | [diff] [blame] | 414 | SymbolFileDWARF::CalculateAbilities () | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 415 | { | 
|  | 416 | uint32_t abilities = 0; | 
|  | 417 | if (m_obj_file != NULL) | 
|  | 418 | { | 
|  | 419 | const Section* section = NULL; | 
|  | 420 | const SectionList *section_list = m_obj_file->GetSectionList(); | 
|  | 421 | if (section_list == NULL) | 
|  | 422 | return 0; | 
|  | 423 |  | 
|  | 424 | uint64_t debug_abbrev_file_size = 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 425 | uint64_t debug_info_file_size = 0; | 
|  | 426 | uint64_t debug_line_file_size = 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 427 |  | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 428 | section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 429 |  | 
|  | 430 | if (section) | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 431 | section_list = §ion->GetChildren (); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 432 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 433 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 434 | if (section != NULL) | 
|  | 435 | { | 
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 436 | debug_info_file_size = section->GetFileSize(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 437 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 438 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 439 | if (section) | 
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 440 | debug_abbrev_file_size = section->GetFileSize(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 441 | else | 
|  | 442 | m_flags.Set (flagsGotDebugAbbrevData); | 
|  | 443 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 444 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get(); | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 445 | if (!section) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 446 | m_flags.Set (flagsGotDebugArangesData); | 
|  | 447 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 448 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get(); | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 449 | if (!section) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 450 | m_flags.Set (flagsGotDebugFrameData); | 
|  | 451 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 452 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 453 | if (section) | 
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 454 | debug_line_file_size = section->GetFileSize(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 455 | else | 
|  | 456 | m_flags.Set (flagsGotDebugLineData); | 
|  | 457 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 458 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get(); | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 459 | if (!section) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 460 | m_flags.Set (flagsGotDebugLocData); | 
|  | 461 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 462 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get(); | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 463 | if (!section) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 464 | m_flags.Set (flagsGotDebugMacInfoData); | 
|  | 465 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 466 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get(); | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 467 | if (!section) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 468 | m_flags.Set (flagsGotDebugPubNamesData); | 
|  | 469 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 470 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get(); | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 471 | if (!section) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 472 | m_flags.Set (flagsGotDebugPubTypesData); | 
|  | 473 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 474 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get(); | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 475 | if (!section) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 476 | m_flags.Set (flagsGotDebugRangesData); | 
|  | 477 |  | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 478 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get(); | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 479 | if (!section) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 480 | m_flags.Set (flagsGotDebugStrData); | 
|  | 481 | } | 
| Greg Clayton | 6c59661 | 2012-05-18 21:47:20 +0000 | [diff] [blame] | 482 | else | 
|  | 483 | { | 
|  | 484 | const char *symfile_dir_cstr = m_obj_file->GetFileSpec().GetDirectory().GetCString(); | 
|  | 485 | if (symfile_dir_cstr) | 
|  | 486 | { | 
|  | 487 | if (strcasestr(symfile_dir_cstr, ".dsym")) | 
|  | 488 | { | 
|  | 489 | if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo) | 
|  | 490 | { | 
|  | 491 | // We have a dSYM file that didn't have a any debug info. | 
|  | 492 | // If the string table has a size of 1, then it was made from | 
|  | 493 | // an executable with no debug info, or from an executable that | 
|  | 494 | // was stripped. | 
|  | 495 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get(); | 
|  | 496 | if (section && section->GetFileSize() == 1) | 
|  | 497 | { | 
|  | 498 | m_obj_file->GetModule()->ReportWarning ("empty dSYM file detected, dSYM was created with an executable with no debug info."); | 
|  | 499 | } | 
|  | 500 | } | 
|  | 501 | } | 
|  | 502 | } | 
|  | 503 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 504 |  | 
|  | 505 | if (debug_abbrev_file_size > 0 && debug_info_file_size > 0) | 
|  | 506 | abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes; | 
|  | 507 |  | 
|  | 508 | if (debug_line_file_size > 0) | 
|  | 509 | abilities |= LineTables; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 510 | } | 
|  | 511 | return abilities; | 
|  | 512 | } | 
|  | 513 |  | 
|  | 514 | const DataExtractor& | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 515 | SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 516 | { | 
|  | 517 | if (m_flags.IsClear (got_flag)) | 
|  | 518 | { | 
|  | 519 | m_flags.Set (got_flag); | 
|  | 520 | const SectionList *section_list = m_obj_file->GetSectionList(); | 
|  | 521 | if (section_list) | 
|  | 522 | { | 
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 523 | SectionSP section_sp (section_list->FindSectionByType(sect_type, true)); | 
|  | 524 | if (section_sp) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 525 | { | 
|  | 526 | // See if we memory mapped the DWARF segment? | 
|  | 527 | if (m_dwarf_data.GetByteSize()) | 
|  | 528 | { | 
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 529 | data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetFileSize()); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 530 | } | 
|  | 531 | else | 
|  | 532 | { | 
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 533 | if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 534 | data.Clear(); | 
|  | 535 | } | 
|  | 536 | } | 
|  | 537 | } | 
|  | 538 | } | 
|  | 539 | return data; | 
|  | 540 | } | 
|  | 541 |  | 
|  | 542 | const DataExtractor& | 
|  | 543 | SymbolFileDWARF::get_debug_abbrev_data() | 
|  | 544 | { | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 545 | return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 546 | } | 
|  | 547 |  | 
|  | 548 | const DataExtractor& | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 549 | SymbolFileDWARF::get_debug_aranges_data() | 
|  | 550 | { | 
|  | 551 | return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges); | 
|  | 552 | } | 
|  | 553 |  | 
|  | 554 | const DataExtractor& | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 555 | SymbolFileDWARF::get_debug_frame_data() | 
|  | 556 | { | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 557 | return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 558 | } | 
|  | 559 |  | 
|  | 560 | const DataExtractor& | 
|  | 561 | SymbolFileDWARF::get_debug_info_data() | 
|  | 562 | { | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 563 | return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 564 | } | 
|  | 565 |  | 
|  | 566 | const DataExtractor& | 
|  | 567 | SymbolFileDWARF::get_debug_line_data() | 
|  | 568 | { | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 569 | return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 570 | } | 
|  | 571 |  | 
|  | 572 | const DataExtractor& | 
|  | 573 | SymbolFileDWARF::get_debug_loc_data() | 
|  | 574 | { | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 575 | return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 576 | } | 
|  | 577 |  | 
|  | 578 | const DataExtractor& | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 579 | SymbolFileDWARF::get_debug_ranges_data() | 
|  | 580 | { | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 581 | return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 582 | } | 
|  | 583 |  | 
|  | 584 | const DataExtractor& | 
|  | 585 | SymbolFileDWARF::get_debug_str_data() | 
|  | 586 | { | 
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 587 | return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 588 | } | 
|  | 589 |  | 
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 590 | const DataExtractor& | 
| Greg Clayton | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 591 | SymbolFileDWARF::get_apple_names_data() | 
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 592 | { | 
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 593 | return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names); | 
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 594 | } | 
|  | 595 |  | 
|  | 596 | const DataExtractor& | 
| Greg Clayton | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 597 | SymbolFileDWARF::get_apple_types_data() | 
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 598 | { | 
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 599 | return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types); | 
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 600 | } | 
|  | 601 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 602 | const DataExtractor& | 
|  | 603 | SymbolFileDWARF::get_apple_namespaces_data() | 
|  | 604 | { | 
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 605 | return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces); | 
|  | 606 | } | 
|  | 607 |  | 
|  | 608 | const DataExtractor& | 
|  | 609 | SymbolFileDWARF::get_apple_objc_data() | 
|  | 610 | { | 
|  | 611 | return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 612 | } | 
|  | 613 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 614 |  | 
|  | 615 | DWARFDebugAbbrev* | 
|  | 616 | SymbolFileDWARF::DebugAbbrev() | 
|  | 617 | { | 
|  | 618 | if (m_abbr.get() == NULL) | 
|  | 619 | { | 
|  | 620 | const DataExtractor &debug_abbrev_data = get_debug_abbrev_data(); | 
|  | 621 | if (debug_abbrev_data.GetByteSize() > 0) | 
|  | 622 | { | 
|  | 623 | m_abbr.reset(new DWARFDebugAbbrev()); | 
|  | 624 | if (m_abbr.get()) | 
|  | 625 | m_abbr->Parse(debug_abbrev_data); | 
|  | 626 | } | 
|  | 627 | } | 
|  | 628 | return m_abbr.get(); | 
|  | 629 | } | 
|  | 630 |  | 
|  | 631 | const DWARFDebugAbbrev* | 
|  | 632 | SymbolFileDWARF::DebugAbbrev() const | 
|  | 633 | { | 
|  | 634 | return m_abbr.get(); | 
|  | 635 | } | 
|  | 636 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 637 |  | 
|  | 638 | DWARFDebugInfo* | 
|  | 639 | SymbolFileDWARF::DebugInfo() | 
|  | 640 | { | 
|  | 641 | if (m_info.get() == NULL) | 
|  | 642 | { | 
|  | 643 | Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this); | 
|  | 644 | if (get_debug_info_data().GetByteSize() > 0) | 
|  | 645 | { | 
|  | 646 | m_info.reset(new DWARFDebugInfo()); | 
|  | 647 | if (m_info.get()) | 
|  | 648 | { | 
|  | 649 | m_info->SetDwarfData(this); | 
|  | 650 | } | 
|  | 651 | } | 
|  | 652 | } | 
|  | 653 | return m_info.get(); | 
|  | 654 | } | 
|  | 655 |  | 
|  | 656 | const DWARFDebugInfo* | 
|  | 657 | SymbolFileDWARF::DebugInfo() const | 
|  | 658 | { | 
|  | 659 | return m_info.get(); | 
|  | 660 | } | 
|  | 661 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 662 | DWARFCompileUnit* | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 663 | SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 664 | { | 
|  | 665 | DWARFDebugInfo* info = DebugInfo(); | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 666 | if (info) | 
|  | 667 | { | 
|  | 668 | if (GetDebugMapSymfile ()) | 
|  | 669 | { | 
|  | 670 | // The debug map symbol file made the compile units for this DWARF | 
|  | 671 | // file which is .o file with DWARF in it, and we should have | 
|  | 672 | // only 1 compile unit which is at offset zero in the DWARF. | 
|  | 673 | // TODO: modify to support LTO .o files where each .o file might | 
|  | 674 | // have multiple DW_TAG_compile_unit tags. | 
|  | 675 | return info->GetCompileUnit(0).get(); | 
|  | 676 | } | 
|  | 677 | else | 
|  | 678 | { | 
|  | 679 | // Just a normal DWARF file whose user ID for the compile unit is | 
|  | 680 | // the DWARF offset itself | 
|  | 681 | return info->GetCompileUnit((dw_offset_t)comp_unit->GetID()).get(); | 
|  | 682 | } | 
|  | 683 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 684 | return NULL; | 
|  | 685 | } | 
|  | 686 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 687 |  | 
|  | 688 | DWARFDebugRanges* | 
|  | 689 | SymbolFileDWARF::DebugRanges() | 
|  | 690 | { | 
|  | 691 | if (m_ranges.get() == NULL) | 
|  | 692 | { | 
|  | 693 | Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this); | 
|  | 694 | if (get_debug_ranges_data().GetByteSize() > 0) | 
|  | 695 | { | 
|  | 696 | m_ranges.reset(new DWARFDebugRanges()); | 
|  | 697 | if (m_ranges.get()) | 
|  | 698 | m_ranges->Extract(this); | 
|  | 699 | } | 
|  | 700 | } | 
|  | 701 | return m_ranges.get(); | 
|  | 702 | } | 
|  | 703 |  | 
|  | 704 | const DWARFDebugRanges* | 
|  | 705 | SymbolFileDWARF::DebugRanges() const | 
|  | 706 | { | 
|  | 707 | return m_ranges.get(); | 
|  | 708 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 709 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 710 | lldb::CompUnitSP | 
|  | 711 | SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 712 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 713 | CompUnitSP cu_sp; | 
|  | 714 | if (dwarf_cu) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 715 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 716 | CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData(); | 
|  | 717 | if (comp_unit) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 718 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 719 | // We already parsed this compile unit, had out a shared pointer to it | 
|  | 720 | cu_sp = comp_unit->shared_from_this(); | 
|  | 721 | } | 
|  | 722 | else | 
|  | 723 | { | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 724 | if (GetDebugMapSymfile ()) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 725 | { | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 726 | // Let the debug map create the compile unit | 
|  | 727 | cu_sp = m_debug_map_symfile->GetCompileUnit(this); | 
|  | 728 | dwarf_cu->SetUserData(cu_sp.get()); | 
|  | 729 | } | 
|  | 730 | else | 
|  | 731 | { | 
|  | 732 | ModuleSP module_sp (m_obj_file->GetModule()); | 
|  | 733 | if (module_sp) | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 734 | { | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 735 | const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly (); | 
|  | 736 | if (cu_die) | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 737 | { | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 738 | const char * cu_die_name = cu_die->GetName(this, dwarf_cu); | 
|  | 739 | const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL); | 
|  | 740 | LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0); | 
|  | 741 | if (cu_die_name) | 
|  | 742 | { | 
|  | 743 | std::string ramapped_file; | 
|  | 744 | FileSpec cu_file_spec; | 
| Jim Ingham | 0909e5f | 2010-09-16 00:57:33 +0000 | [diff] [blame] | 745 |  | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 746 | 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] | 747 | { | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 748 | // If we have a full path to the compile unit, we don't need to resolve | 
|  | 749 | // the file.  This can be expensive e.g. when the source files are NFS mounted. | 
|  | 750 | if (module_sp->RemapSourceFile(cu_die_name, ramapped_file)) | 
|  | 751 | cu_file_spec.SetFile (ramapped_file.c_str(), false); | 
|  | 752 | else | 
|  | 753 | cu_file_spec.SetFile (cu_die_name, false); | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 754 | } | 
|  | 755 | else | 
|  | 756 | { | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 757 | std::string fullpath(cu_comp_dir); | 
|  | 758 | if (*fullpath.rbegin() != '/') | 
|  | 759 | fullpath += '/'; | 
|  | 760 | fullpath += cu_die_name; | 
|  | 761 | if (module_sp->RemapSourceFile (fullpath.c_str(), ramapped_file)) | 
|  | 762 | cu_file_spec.SetFile (ramapped_file.c_str(), false); | 
|  | 763 | else | 
|  | 764 | cu_file_spec.SetFile (fullpath.c_str(), false); | 
|  | 765 | } | 
|  | 766 |  | 
|  | 767 | cu_sp.reset(new CompileUnit (module_sp, | 
|  | 768 | dwarf_cu, | 
|  | 769 | cu_file_spec, | 
|  | 770 | MakeUserID(dwarf_cu->GetOffset()), | 
|  | 771 | cu_language)); | 
|  | 772 | if (cu_sp) | 
|  | 773 | { | 
|  | 774 | dwarf_cu->SetUserData(cu_sp.get()); | 
|  | 775 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 776 | // Figure out the compile unit index if we weren't given one | 
|  | 777 | if (cu_idx == UINT32_MAX) | 
|  | 778 | DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx); | 
|  | 779 |  | 
|  | 780 | m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp); | 
|  | 781 | } | 
|  | 782 | } | 
|  | 783 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 784 | } | 
|  | 785 | } | 
|  | 786 | } | 
|  | 787 | } | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 788 | return cu_sp; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 789 | } | 
|  | 790 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 791 | uint32_t | 
|  | 792 | SymbolFileDWARF::GetNumCompileUnits() | 
|  | 793 | { | 
|  | 794 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 795 | if (info) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 796 | return info->GetNumCompileUnits(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 797 | return 0; | 
|  | 798 | } | 
|  | 799 |  | 
|  | 800 | CompUnitSP | 
|  | 801 | SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx) | 
|  | 802 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 803 | CompUnitSP cu_sp; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 804 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 805 | if (info) | 
|  | 806 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 807 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx); | 
|  | 808 | if (dwarf_cu) | 
|  | 809 | cu_sp = ParseCompileUnit(dwarf_cu, cu_idx); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 810 | } | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 811 | return cu_sp; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 812 | } | 
|  | 813 |  | 
|  | 814 | static void | 
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 815 | AddRangesToBlock (Block& block, | 
|  | 816 | DWARFDebugRanges::RangeList& ranges, | 
|  | 817 | addr_t block_base_addr) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 818 | { | 
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 819 | const size_t num_ranges = ranges.GetSize(); | 
|  | 820 | for (size_t i = 0; i<num_ranges; ++i) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 821 | { | 
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 822 | const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i); | 
|  | 823 | const addr_t range_base = range.GetRangeBase(); | 
|  | 824 | assert (range_base >= block_base_addr); | 
|  | 825 | block.AddRange(Block::Range (range_base - block_base_addr, range.GetByteSize()));; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 826 | } | 
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 827 | block.FinalizeRanges (); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 828 | } | 
|  | 829 |  | 
|  | 830 |  | 
|  | 831 | Function * | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 832 | SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 833 | { | 
|  | 834 | DWARFDebugRanges::RangeList func_ranges; | 
|  | 835 | const char *name = NULL; | 
|  | 836 | const char *mangled = NULL; | 
|  | 837 | int decl_file = 0; | 
|  | 838 | int decl_line = 0; | 
|  | 839 | int decl_column = 0; | 
|  | 840 | int call_file = 0; | 
|  | 841 | int call_line = 0; | 
|  | 842 | int call_column = 0; | 
|  | 843 | DWARFExpression frame_base; | 
|  | 844 |  | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 845 | assert (die->Tag() == DW_TAG_subprogram); | 
|  | 846 |  | 
|  | 847 | if (die->Tag() != DW_TAG_subprogram) | 
|  | 848 | return NULL; | 
|  | 849 |  | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 850 | if (die->GetDIENamesAndRanges (this, | 
|  | 851 | dwarf_cu, | 
|  | 852 | name, | 
|  | 853 | mangled, | 
|  | 854 | func_ranges, | 
|  | 855 | decl_file, | 
|  | 856 | decl_line, | 
|  | 857 | decl_column, | 
|  | 858 | call_file, | 
|  | 859 | call_line, | 
|  | 860 | call_column, | 
|  | 861 | &frame_base)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 862 | { | 
|  | 863 | // Union of all ranges in the function DIE (if the function is discontiguous) | 
|  | 864 | AddressRange func_range; | 
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 865 | lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0); | 
|  | 866 | lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 867 | if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr) | 
|  | 868 | { | 
|  | 869 | func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList()); | 
|  | 870 | if (func_range.GetBaseAddress().IsValid()) | 
|  | 871 | func_range.SetByteSize(highest_func_addr - lowest_func_addr); | 
|  | 872 | } | 
|  | 873 |  | 
|  | 874 | if (func_range.GetBaseAddress().IsValid()) | 
|  | 875 | { | 
|  | 876 | Mangled func_name; | 
|  | 877 | if (mangled) | 
| Greg Clayton | 037520e | 2012-07-18 23:18:10 +0000 | [diff] [blame] | 878 | func_name.SetValue(ConstString(mangled), true); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 879 | else if (name) | 
| Greg Clayton | 037520e | 2012-07-18 23:18:10 +0000 | [diff] [blame] | 880 | func_name.SetValue(ConstString(name), false); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 881 |  | 
|  | 882 | FunctionSP func_sp; | 
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 883 | std::unique_ptr<Declaration> decl_ap; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 884 | if (decl_file != 0 || decl_line != 0 || decl_column != 0) | 
| Greg Clayton | d7e0546 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 885 | decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), | 
|  | 886 | decl_line, | 
|  | 887 | decl_column)); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 888 |  | 
| Greg Clayton | 0bd4e1b | 2011-09-30 20:52:25 +0000 | [diff] [blame] | 889 | // Supply the type _only_ if it has already been parsed | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 890 | Type *func_type = m_die_to_type.lookup (die); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 891 |  | 
|  | 892 | assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED); | 
|  | 893 |  | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 894 | if (FixupAddress (func_range.GetBaseAddress())) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 895 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 896 | const user_id_t func_user_id = MakeUserID(die->GetOffset()); | 
|  | 897 | func_sp.reset(new Function (sc.comp_unit, | 
|  | 898 | MakeUserID(func_user_id),       // UserID is the DIE offset | 
|  | 899 | MakeUserID(func_user_id), | 
|  | 900 | func_name, | 
|  | 901 | func_type, | 
|  | 902 | func_range));           // first address range | 
|  | 903 |  | 
|  | 904 | if (func_sp.get() != NULL) | 
|  | 905 | { | 
|  | 906 | if (frame_base.IsValid()) | 
|  | 907 | func_sp->GetFrameBaseExpression() = frame_base; | 
|  | 908 | sc.comp_unit->AddFunction(func_sp); | 
|  | 909 | return func_sp.get(); | 
|  | 910 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 911 | } | 
|  | 912 | } | 
|  | 913 | } | 
|  | 914 | return NULL; | 
|  | 915 | } | 
|  | 916 |  | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 917 | bool | 
|  | 918 | SymbolFileDWARF::FixupAddress (Address &addr) | 
|  | 919 | { | 
|  | 920 | SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile (); | 
|  | 921 | if (debug_map_symfile) | 
|  | 922 | { | 
|  | 923 | return debug_map_symfile->LinkOSOAddress(addr); | 
|  | 924 | } | 
|  | 925 | // This is a normal DWARF file, no address fixups need to happen | 
|  | 926 | return true; | 
|  | 927 | } | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 928 | lldb::LanguageType | 
|  | 929 | SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc) | 
|  | 930 | { | 
|  | 931 | assert (sc.comp_unit); | 
|  | 932 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); | 
|  | 933 | if (dwarf_cu) | 
|  | 934 | { | 
|  | 935 | const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly(); | 
| Jim Ingham | 28eb571 | 2012-10-12 17:34:26 +0000 | [diff] [blame] | 936 | if (die) | 
|  | 937 | { | 
|  | 938 | const uint32_t language = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0); | 
|  | 939 | if (language) | 
|  | 940 | return (lldb::LanguageType)language; | 
|  | 941 | } | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 942 | } | 
|  | 943 | return eLanguageTypeUnknown; | 
|  | 944 | } | 
|  | 945 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 946 | size_t | 
|  | 947 | SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc) | 
|  | 948 | { | 
|  | 949 | assert (sc.comp_unit); | 
|  | 950 | size_t functions_added = 0; | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 951 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 952 | if (dwarf_cu) | 
|  | 953 | { | 
|  | 954 | DWARFDIECollection function_dies; | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 955 | 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] | 956 | size_t func_idx; | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 957 | for (func_idx = 0; func_idx < num_functions; ++func_idx) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 958 | { | 
|  | 959 | const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx); | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 960 | if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 961 | { | 
|  | 962 | if (ParseCompileUnitFunction(sc, dwarf_cu, die)) | 
|  | 963 | ++functions_added; | 
|  | 964 | } | 
|  | 965 | } | 
|  | 966 | //FixupTypes(); | 
|  | 967 | } | 
|  | 968 | return functions_added; | 
|  | 969 | } | 
|  | 970 |  | 
|  | 971 | bool | 
|  | 972 | SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files) | 
|  | 973 | { | 
|  | 974 | assert (sc.comp_unit); | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 975 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); | 
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 976 | if (dwarf_cu) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 977 | { | 
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 978 | const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 979 |  | 
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 980 | if (cu_die) | 
|  | 981 | { | 
|  | 982 | const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL); | 
|  | 983 | 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] | 984 |  | 
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 985 | // All file indexes in DWARF are one based and a file of index zero is | 
|  | 986 | // supposed to be the compile unit itself. | 
|  | 987 | support_files.Append (*sc.comp_unit); | 
|  | 988 |  | 
|  | 989 | return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files); | 
|  | 990 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 991 | } | 
|  | 992 | return false; | 
|  | 993 | } | 
|  | 994 |  | 
|  | 995 | struct ParseDWARFLineTableCallbackInfo | 
|  | 996 | { | 
|  | 997 | LineTable* line_table; | 
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 998 | std::unique_ptr<LineSequence> sequence_ap; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 999 | }; | 
|  | 1000 |  | 
|  | 1001 | //---------------------------------------------------------------------- | 
|  | 1002 | // ParseStatementTableCallback | 
|  | 1003 | //---------------------------------------------------------------------- | 
|  | 1004 | static void | 
|  | 1005 | ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData) | 
|  | 1006 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1007 | if (state.row == DWARFDebugLine::State::StartParsingLineTable) | 
|  | 1008 | { | 
|  | 1009 | // Just started parsing the line table | 
|  | 1010 | } | 
|  | 1011 | else if (state.row == DWARFDebugLine::State::DoneParsingLineTable) | 
|  | 1012 | { | 
|  | 1013 | // Done parsing line table, nothing to do for the cleanup | 
|  | 1014 | } | 
|  | 1015 | else | 
|  | 1016 | { | 
|  | 1017 | ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData; | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1018 | LineTable* line_table = info->line_table; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1019 |  | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1020 | // If this is our first time here, we need to create a | 
|  | 1021 | // sequence container. | 
|  | 1022 | if (!info->sequence_ap.get()) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1023 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1024 | info->sequence_ap.reset(line_table->CreateLineSequenceContainer()); | 
|  | 1025 | assert(info->sequence_ap.get()); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1026 | } | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1027 | line_table->AppendLineEntryToSequence (info->sequence_ap.get(), | 
|  | 1028 | state.address, | 
|  | 1029 | state.line, | 
|  | 1030 | state.column, | 
|  | 1031 | state.file, | 
|  | 1032 | state.is_stmt, | 
|  | 1033 | state.basic_block, | 
|  | 1034 | state.prologue_end, | 
|  | 1035 | state.epilogue_begin, | 
|  | 1036 | state.end_sequence); | 
|  | 1037 | if (state.end_sequence) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1038 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1039 | // First, put the current sequence into the line table. | 
|  | 1040 | line_table->InsertSequence(info->sequence_ap.get()); | 
|  | 1041 | // Then, empty it to prepare for the next sequence. | 
|  | 1042 | info->sequence_ap->Clear(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1043 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1044 | } | 
|  | 1045 | } | 
|  | 1046 |  | 
|  | 1047 | bool | 
|  | 1048 | SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc) | 
|  | 1049 | { | 
|  | 1050 | assert (sc.comp_unit); | 
|  | 1051 | if (sc.comp_unit->GetLineTable() != NULL) | 
|  | 1052 | return true; | 
|  | 1053 |  | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1054 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1055 | if (dwarf_cu) | 
|  | 1056 | { | 
|  | 1057 | const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly(); | 
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1058 | if (dwarf_cu_die) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1059 | { | 
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1060 | const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET); | 
|  | 1061 | if (cu_line_offset != DW_INVALID_OFFSET) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1062 | { | 
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1063 | std::unique_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit)); | 
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1064 | if (line_table_ap.get()) | 
|  | 1065 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1066 | ParseDWARFLineTableCallbackInfo info; | 
|  | 1067 | info.line_table = line_table_ap.get(); | 
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1068 | lldb::offset_t offset = cu_line_offset; | 
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1069 | DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info); | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1070 | if (m_debug_map_symfile) | 
|  | 1071 | { | 
|  | 1072 | // We have an object file that has a line table with addresses | 
|  | 1073 | // that are not linked. We need to link the line table and convert | 
|  | 1074 | // the addresses that are relative to the .o file into addresses | 
|  | 1075 | // for the main executable. | 
|  | 1076 | sc.comp_unit->SetLineTable (m_debug_map_symfile->LinkOSOLineTable (this, line_table_ap.get())); | 
|  | 1077 | } | 
|  | 1078 | else | 
|  | 1079 | { | 
|  | 1080 | sc.comp_unit->SetLineTable(line_table_ap.release()); | 
|  | 1081 | return true; | 
|  | 1082 | } | 
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1083 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1084 | } | 
|  | 1085 | } | 
|  | 1086 | } | 
|  | 1087 | return false; | 
|  | 1088 | } | 
|  | 1089 |  | 
|  | 1090 | size_t | 
|  | 1091 | SymbolFileDWARF::ParseFunctionBlocks | 
|  | 1092 | ( | 
|  | 1093 | const SymbolContext& sc, | 
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1094 | Block *parent_block, | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1095 | DWARFCompileUnit* dwarf_cu, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1096 | const DWARFDebugInfoEntry *die, | 
|  | 1097 | addr_t subprogram_low_pc, | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1098 | uint32_t depth | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1099 | ) | 
|  | 1100 | { | 
|  | 1101 | size_t blocks_added = 0; | 
|  | 1102 | while (die != NULL) | 
|  | 1103 | { | 
|  | 1104 | dw_tag_t tag = die->Tag(); | 
|  | 1105 |  | 
|  | 1106 | switch (tag) | 
|  | 1107 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1108 | case DW_TAG_inlined_subroutine: | 
| Greg Clayton | b4d3733 | 2011-08-12 16:22:48 +0000 | [diff] [blame] | 1109 | case DW_TAG_subprogram: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1110 | case DW_TAG_lexical_block: | 
|  | 1111 | { | 
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1112 | Block *block = NULL; | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1113 | if (tag == DW_TAG_subprogram) | 
|  | 1114 | { | 
|  | 1115 | // Skip any DW_TAG_subprogram DIEs that are inside | 
|  | 1116 | // of a normal or inlined functions. These will be | 
|  | 1117 | // parsed on their own as separate entities. | 
|  | 1118 |  | 
|  | 1119 | if (depth > 0) | 
|  | 1120 | break; | 
|  | 1121 |  | 
|  | 1122 | block = parent_block; | 
|  | 1123 | } | 
|  | 1124 | else | 
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1125 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1126 | BlockSP block_sp(new Block (MakeUserID(die->GetOffset()))); | 
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1127 | parent_block->AddChild(block_sp); | 
|  | 1128 | block = block_sp.get(); | 
|  | 1129 | } | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1130 | DWARFDebugRanges::RangeList ranges; | 
|  | 1131 | const char *name = NULL; | 
|  | 1132 | const char *mangled_name = NULL; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1133 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1134 | int decl_file = 0; | 
|  | 1135 | int decl_line = 0; | 
|  | 1136 | int decl_column = 0; | 
|  | 1137 | int call_file = 0; | 
|  | 1138 | int call_line = 0; | 
|  | 1139 | int call_column = 0; | 
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1140 | if (die->GetDIENamesAndRanges (this, | 
|  | 1141 | dwarf_cu, | 
|  | 1142 | name, | 
|  | 1143 | mangled_name, | 
|  | 1144 | ranges, | 
|  | 1145 | decl_file, decl_line, decl_column, | 
|  | 1146 | call_file, call_line, call_column)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1147 | { | 
|  | 1148 | if (tag == DW_TAG_subprogram) | 
|  | 1149 | { | 
|  | 1150 | assert (subprogram_low_pc == LLDB_INVALID_ADDRESS); | 
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1151 | subprogram_low_pc = ranges.GetMinRangeBase(0); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1152 | } | 
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1153 | else if (tag == DW_TAG_inlined_subroutine) | 
|  | 1154 | { | 
|  | 1155 | // We get called here for inlined subroutines in two ways. | 
|  | 1156 | // The first time is when we are making the Function object | 
|  | 1157 | // for this inlined concrete instance.  Since we're creating a top level block at | 
|  | 1158 | // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS.  So we need to | 
|  | 1159 | // adjust the containing address. | 
|  | 1160 | // The second time is when we are parsing the blocks inside the function that contains | 
|  | 1161 | // the inlined concrete instance.  Since these will be blocks inside the containing "real" | 
|  | 1162 | // function the offset will be for that function. | 
|  | 1163 | if (subprogram_low_pc == LLDB_INVALID_ADDRESS) | 
|  | 1164 | { | 
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1165 | subprogram_low_pc = ranges.GetMinRangeBase(0); | 
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1166 | } | 
|  | 1167 | } | 
|  | 1168 |  | 
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1169 | AddRangesToBlock (*block, ranges, subprogram_low_pc); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1170 |  | 
|  | 1171 | if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL)) | 
|  | 1172 | { | 
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1173 | std::unique_ptr<Declaration> decl_ap; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1174 | if (decl_file != 0 || decl_line != 0 || decl_column != 0) | 
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1175 | decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), | 
|  | 1176 | decl_line, decl_column)); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1177 |  | 
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1178 | std::unique_ptr<Declaration> call_ap; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1179 | if (call_file != 0 || call_line != 0 || call_column != 0) | 
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1180 | call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file), | 
|  | 1181 | call_line, call_column)); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1182 |  | 
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1183 | block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get()); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1184 | } | 
|  | 1185 |  | 
|  | 1186 | ++blocks_added; | 
|  | 1187 |  | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1188 | if (die->HasChildren()) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1189 | { | 
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1190 | blocks_added += ParseFunctionBlocks (sc, | 
|  | 1191 | block, | 
|  | 1192 | dwarf_cu, | 
|  | 1193 | die->GetFirstChild(), | 
|  | 1194 | subprogram_low_pc, | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1195 | depth + 1); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1196 | } | 
|  | 1197 | } | 
|  | 1198 | } | 
|  | 1199 | break; | 
|  | 1200 | default: | 
|  | 1201 | break; | 
|  | 1202 | } | 
|  | 1203 |  | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1204 | // Only parse siblings of the block if we are not at depth zero. A depth | 
|  | 1205 | // of zero indicates we are currently parsing the top level | 
|  | 1206 | // DW_TAG_subprogram DIE | 
|  | 1207 |  | 
|  | 1208 | if (depth == 0) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1209 | die = NULL; | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1210 | else | 
|  | 1211 | die = die->GetSibling(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1212 | } | 
|  | 1213 | return blocks_added; | 
|  | 1214 | } | 
|  | 1215 |  | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1216 | bool | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1217 | SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu, | 
|  | 1218 | const DWARFDebugInfoEntry *die, | 
|  | 1219 | ClangASTContext::TemplateParameterInfos &template_param_infos) | 
|  | 1220 | { | 
|  | 1221 | const dw_tag_t tag = die->Tag(); | 
|  | 1222 |  | 
|  | 1223 | switch (tag) | 
|  | 1224 | { | 
|  | 1225 | case DW_TAG_template_type_parameter: | 
|  | 1226 | case DW_TAG_template_value_parameter: | 
|  | 1227 | { | 
|  | 1228 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); | 
|  | 1229 |  | 
|  | 1230 | DWARFDebugInfoEntry::Attributes attributes; | 
|  | 1231 | const size_t num_attributes = die->GetAttributes (this, | 
|  | 1232 | dwarf_cu, | 
|  | 1233 | fixed_form_sizes, | 
|  | 1234 | attributes); | 
|  | 1235 | const char *name = NULL; | 
|  | 1236 | Type *lldb_type = NULL; | 
|  | 1237 | clang_type_t clang_type = NULL; | 
|  | 1238 | uint64_t uval64 = 0; | 
|  | 1239 | bool uval64_valid = false; | 
|  | 1240 | if (num_attributes > 0) | 
|  | 1241 | { | 
|  | 1242 | DWARFFormValue form_value; | 
|  | 1243 | for (size_t i=0; i<num_attributes; ++i) | 
|  | 1244 | { | 
|  | 1245 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 1246 |  | 
|  | 1247 | switch (attr) | 
|  | 1248 | { | 
|  | 1249 | case DW_AT_name: | 
|  | 1250 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 1251 | name = form_value.AsCString(&get_debug_str_data()); | 
|  | 1252 | break; | 
|  | 1253 |  | 
|  | 1254 | case DW_AT_type: | 
|  | 1255 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 1256 | { | 
|  | 1257 | const dw_offset_t type_die_offset = form_value.Reference(dwarf_cu); | 
|  | 1258 | lldb_type = ResolveTypeUID(type_die_offset); | 
|  | 1259 | if (lldb_type) | 
|  | 1260 | clang_type = lldb_type->GetClangForwardType(); | 
|  | 1261 | } | 
|  | 1262 | break; | 
|  | 1263 |  | 
|  | 1264 | case DW_AT_const_value: | 
|  | 1265 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 1266 | { | 
|  | 1267 | uval64_valid = true; | 
|  | 1268 | uval64 = form_value.Unsigned(); | 
|  | 1269 | } | 
|  | 1270 | break; | 
|  | 1271 | default: | 
|  | 1272 | break; | 
|  | 1273 | } | 
|  | 1274 | } | 
|  | 1275 |  | 
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1276 | clang::ASTContext *ast = GetClangASTContext().getASTContext(); | 
|  | 1277 | if (!clang_type) | 
|  | 1278 | clang_type = ast->VoidTy.getAsOpaquePtr(); | 
|  | 1279 |  | 
|  | 1280 | if (clang_type) | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1281 | { | 
|  | 1282 | bool is_signed = false; | 
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1283 | if (name && name[0]) | 
|  | 1284 | template_param_infos.names.push_back(name); | 
|  | 1285 | else | 
|  | 1286 | template_param_infos.names.push_back(NULL); | 
|  | 1287 |  | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1288 | clang::QualType clang_qual_type (clang::QualType::getFromOpaquePtr (clang_type)); | 
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1289 | if (tag == DW_TAG_template_value_parameter && | 
|  | 1290 | lldb_type != NULL && | 
|  | 1291 | ClangASTContext::IsIntegerType (clang_type, is_signed) && | 
|  | 1292 | uval64_valid) | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1293 | { | 
|  | 1294 | llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed); | 
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1295 | template_param_infos.args.push_back (clang::TemplateArgument (*ast, | 
| Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1296 | llvm::APSInt(apint), | 
|  | 1297 | clang_qual_type)); | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1298 | } | 
|  | 1299 | else | 
|  | 1300 | { | 
|  | 1301 | template_param_infos.args.push_back (clang::TemplateArgument (clang_qual_type)); | 
|  | 1302 | } | 
|  | 1303 | } | 
|  | 1304 | else | 
|  | 1305 | { | 
|  | 1306 | return false; | 
|  | 1307 | } | 
|  | 1308 |  | 
|  | 1309 | } | 
|  | 1310 | } | 
|  | 1311 | return true; | 
|  | 1312 |  | 
|  | 1313 | default: | 
|  | 1314 | break; | 
|  | 1315 | } | 
|  | 1316 | return false; | 
|  | 1317 | } | 
|  | 1318 |  | 
|  | 1319 | bool | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1320 | SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu, | 
|  | 1321 | const DWARFDebugInfoEntry *parent_die, | 
|  | 1322 | ClangASTContext::TemplateParameterInfos &template_param_infos) | 
|  | 1323 | { | 
|  | 1324 |  | 
|  | 1325 | if (parent_die == NULL) | 
| Filipe Cabecinhas | 52008c6 | 2012-05-23 16:24:11 +0000 | [diff] [blame] | 1326 | return false; | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1327 |  | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1328 | Args template_parameter_names; | 
|  | 1329 | for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); | 
|  | 1330 | die != NULL; | 
|  | 1331 | die = die->GetSibling()) | 
|  | 1332 | { | 
|  | 1333 | const dw_tag_t tag = die->Tag(); | 
|  | 1334 |  | 
|  | 1335 | switch (tag) | 
|  | 1336 | { | 
|  | 1337 | case DW_TAG_template_type_parameter: | 
|  | 1338 | case DW_TAG_template_value_parameter: | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1339 | ParseTemplateDIE (dwarf_cu, die, template_param_infos); | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1340 | break; | 
|  | 1341 |  | 
|  | 1342 | default: | 
|  | 1343 | break; | 
|  | 1344 | } | 
|  | 1345 | } | 
|  | 1346 | if (template_param_infos.args.empty()) | 
|  | 1347 | return false; | 
|  | 1348 | return template_param_infos.args.size() == template_param_infos.names.size(); | 
|  | 1349 | } | 
|  | 1350 |  | 
|  | 1351 | clang::ClassTemplateDecl * | 
|  | 1352 | SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx, | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1353 | lldb::AccessType access_type, | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1354 | const char *parent_name, | 
|  | 1355 | int tag_decl_kind, | 
|  | 1356 | const ClangASTContext::TemplateParameterInfos &template_param_infos) | 
|  | 1357 | { | 
|  | 1358 | if (template_param_infos.IsValid()) | 
|  | 1359 | { | 
|  | 1360 | std::string template_basename(parent_name); | 
|  | 1361 | template_basename.erase (template_basename.find('<')); | 
|  | 1362 | ClangASTContext &ast = GetClangASTContext(); | 
|  | 1363 |  | 
|  | 1364 | return ast.CreateClassTemplateDecl (decl_ctx, | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1365 | access_type, | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1366 | template_basename.c_str(), | 
|  | 1367 | tag_decl_kind, | 
|  | 1368 | template_param_infos); | 
|  | 1369 | } | 
|  | 1370 | return NULL; | 
|  | 1371 | } | 
|  | 1372 |  | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1373 | class SymbolFileDWARF::DelayedAddObjCClassProperty | 
|  | 1374 | { | 
|  | 1375 | public: | 
|  | 1376 | DelayedAddObjCClassProperty | 
|  | 1377 | ( | 
|  | 1378 | clang::ASTContext      *ast, | 
|  | 1379 | lldb::clang_type_t      class_opaque_type, | 
|  | 1380 | const char             *property_name, | 
|  | 1381 | lldb::clang_type_t      property_opaque_type,  // The property type is only required if you don't have an ivar decl | 
|  | 1382 | clang::ObjCIvarDecl    *ivar_decl, | 
|  | 1383 | const char             *property_setter_name, | 
|  | 1384 | const char             *property_getter_name, | 
|  | 1385 | uint32_t                property_attributes, | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1386 | const ClangASTMetadata *metadata | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1387 | ) : | 
|  | 1388 | m_ast                   (ast), | 
|  | 1389 | m_class_opaque_type     (class_opaque_type), | 
|  | 1390 | m_property_name         (property_name), | 
|  | 1391 | m_property_opaque_type  (property_opaque_type), | 
|  | 1392 | m_ivar_decl             (ivar_decl), | 
|  | 1393 | m_property_setter_name  (property_setter_name), | 
|  | 1394 | m_property_getter_name  (property_getter_name), | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1395 | m_property_attributes   (property_attributes) | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1396 | { | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1397 | if (metadata != NULL) | 
|  | 1398 | { | 
|  | 1399 | m_metadata_ap.reset(new ClangASTMetadata()); | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1400 | *m_metadata_ap = *metadata; | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1401 | } | 
|  | 1402 | } | 
|  | 1403 |  | 
|  | 1404 | DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs) | 
|  | 1405 | { | 
| Daniel Malea | d4c5be6 | 2012-11-12 21:02:14 +0000 | [diff] [blame] | 1406 | *this = rhs; | 
|  | 1407 | } | 
|  | 1408 |  | 
|  | 1409 | DelayedAddObjCClassProperty& operator= (const DelayedAddObjCClassProperty &rhs) | 
|  | 1410 | { | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1411 | m_ast                  = rhs.m_ast; | 
|  | 1412 | m_class_opaque_type    = rhs.m_class_opaque_type; | 
|  | 1413 | m_property_name        = rhs.m_property_name; | 
|  | 1414 | m_property_opaque_type = rhs.m_property_opaque_type; | 
|  | 1415 | m_ivar_decl            = rhs.m_ivar_decl; | 
|  | 1416 | m_property_setter_name = rhs.m_property_setter_name; | 
|  | 1417 | m_property_getter_name = rhs.m_property_getter_name; | 
|  | 1418 | m_property_attributes  = rhs.m_property_attributes; | 
|  | 1419 |  | 
|  | 1420 | if (rhs.m_metadata_ap.get()) | 
|  | 1421 | { | 
|  | 1422 | m_metadata_ap.reset (new ClangASTMetadata()); | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1423 | *m_metadata_ap = *rhs.m_metadata_ap; | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1424 | } | 
| Daniel Malea | d4c5be6 | 2012-11-12 21:02:14 +0000 | [diff] [blame] | 1425 | return *this; | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1426 | } | 
|  | 1427 |  | 
|  | 1428 | bool Finalize() const | 
|  | 1429 | { | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1430 | return ClangASTContext::AddObjCClassProperty (m_ast, | 
|  | 1431 | m_class_opaque_type, | 
|  | 1432 | m_property_name, | 
|  | 1433 | m_property_opaque_type, | 
|  | 1434 | m_ivar_decl, | 
|  | 1435 | m_property_setter_name, | 
|  | 1436 | m_property_getter_name, | 
|  | 1437 | m_property_attributes, | 
|  | 1438 | m_metadata_ap.get()); | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1439 | } | 
|  | 1440 | private: | 
|  | 1441 | clang::ASTContext      *m_ast; | 
|  | 1442 | lldb::clang_type_t      m_class_opaque_type; | 
|  | 1443 | const char             *m_property_name; | 
|  | 1444 | lldb::clang_type_t      m_property_opaque_type; | 
|  | 1445 | clang::ObjCIvarDecl    *m_ivar_decl; | 
|  | 1446 | const char             *m_property_setter_name; | 
|  | 1447 | const char             *m_property_getter_name; | 
|  | 1448 | uint32_t                m_property_attributes; | 
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1449 | std::unique_ptr<ClangASTMetadata> m_metadata_ap; | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1450 | }; | 
|  | 1451 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1452 | struct BitfieldInfo | 
|  | 1453 | { | 
|  | 1454 | uint64_t bit_size; | 
|  | 1455 | uint64_t bit_offset; | 
|  | 1456 |  | 
|  | 1457 | BitfieldInfo () : | 
|  | 1458 | bit_size (LLDB_INVALID_ADDRESS), | 
|  | 1459 | bit_offset (LLDB_INVALID_ADDRESS) | 
|  | 1460 | { | 
|  | 1461 | } | 
|  | 1462 |  | 
|  | 1463 | bool IsValid () | 
|  | 1464 | { | 
|  | 1465 | return (bit_size != LLDB_INVALID_ADDRESS) && | 
|  | 1466 | (bit_offset != LLDB_INVALID_ADDRESS); | 
|  | 1467 | } | 
|  | 1468 | }; | 
|  | 1469 |  | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1470 |  | 
|  | 1471 | bool | 
|  | 1472 | SymbolFileDWARF::ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu, | 
|  | 1473 | const DWARFDebugInfoEntry *parent_die) | 
|  | 1474 | { | 
|  | 1475 | if (parent_die) | 
|  | 1476 | { | 
|  | 1477 | for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) | 
|  | 1478 | { | 
|  | 1479 | dw_tag_t tag = die->Tag(); | 
|  | 1480 | bool check_virtuality = false; | 
|  | 1481 | switch (tag) | 
|  | 1482 | { | 
|  | 1483 | case DW_TAG_inheritance: | 
|  | 1484 | case DW_TAG_subprogram: | 
|  | 1485 | check_virtuality = true; | 
|  | 1486 | break; | 
|  | 1487 | default: | 
|  | 1488 | break; | 
|  | 1489 | } | 
|  | 1490 | if (check_virtuality) | 
|  | 1491 | { | 
|  | 1492 | if (die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_virtuality, 0) != 0) | 
|  | 1493 | return true; | 
|  | 1494 | } | 
|  | 1495 | } | 
|  | 1496 | } | 
|  | 1497 | return false; | 
|  | 1498 | } | 
|  | 1499 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1500 | size_t | 
|  | 1501 | SymbolFileDWARF::ParseChildMembers | 
|  | 1502 | ( | 
|  | 1503 | const SymbolContext& sc, | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1504 | DWARFCompileUnit* dwarf_cu, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1505 | const DWARFDebugInfoEntry *parent_die, | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1506 | clang_type_t class_clang_type, | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1507 | const LanguageType class_language, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1508 | std::vector<clang::CXXBaseSpecifier *>& base_classes, | 
|  | 1509 | std::vector<int>& member_accessibilities, | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1510 | DWARFDIECollection& member_function_dies, | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1511 | DelayedPropertyList& delayed_properties, | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1512 | AccessType& default_accessibility, | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1513 | bool &is_a_class, | 
|  | 1514 | LayoutInfo &layout_info | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1515 | ) | 
|  | 1516 | { | 
|  | 1517 | if (parent_die == NULL) | 
|  | 1518 | return 0; | 
|  | 1519 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1520 | size_t count = 0; | 
|  | 1521 | const DWARFDebugInfoEntry *die; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 1522 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1523 | uint32_t member_idx = 0; | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1524 | BitfieldInfo last_field_info; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 1525 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1526 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) | 
|  | 1527 | { | 
|  | 1528 | dw_tag_t tag = die->Tag(); | 
|  | 1529 |  | 
|  | 1530 | switch (tag) | 
|  | 1531 | { | 
|  | 1532 | case DW_TAG_member: | 
| Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1533 | case DW_TAG_APPLE_property: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1534 | { | 
|  | 1535 | DWARFDebugInfoEntry::Attributes attributes; | 
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1536 | const size_t num_attributes = die->GetAttributes (this, | 
|  | 1537 | dwarf_cu, | 
|  | 1538 | fixed_form_sizes, | 
|  | 1539 | attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1540 | if (num_attributes > 0) | 
|  | 1541 | { | 
|  | 1542 | Declaration decl; | 
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1543 | //DWARFExpression location; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1544 | const char *name = NULL; | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1545 | const char *prop_name = NULL; | 
|  | 1546 | const char *prop_getter_name = NULL; | 
|  | 1547 | const char *prop_setter_name = NULL; | 
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1548 | uint32_t prop_attributes = 0; | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1549 |  | 
|  | 1550 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1551 | bool is_artificial = false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1552 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1553 | AccessType accessibility = eAccessNone; | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1554 | uint32_t member_byte_offset = UINT32_MAX; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1555 | size_t byte_size = 0; | 
|  | 1556 | size_t bit_offset = 0; | 
|  | 1557 | size_t bit_size = 0; | 
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1558 | 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] | 1559 | uint32_t i; | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1560 | for (i=0; i<num_attributes && !is_artificial; ++i) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1561 | { | 
|  | 1562 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 1563 | DWARFFormValue form_value; | 
|  | 1564 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 1565 | { | 
|  | 1566 | switch (attr) | 
|  | 1567 | { | 
|  | 1568 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 1569 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 1570 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 1571 | case DW_AT_name:        name = form_value.AsCString(&get_debug_str_data()); break; | 
|  | 1572 | case DW_AT_type:        encoding_uid = form_value.Reference(dwarf_cu); break; | 
|  | 1573 | case DW_AT_bit_offset:  bit_offset = form_value.Unsigned(); break; | 
|  | 1574 | case DW_AT_bit_size:    bit_size = form_value.Unsigned(); break; | 
|  | 1575 | case DW_AT_byte_size:   byte_size = form_value.Unsigned(); break; | 
|  | 1576 | case DW_AT_data_member_location: | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1577 | if (form_value.BlockData()) | 
|  | 1578 | { | 
|  | 1579 | Value initialValue(0); | 
|  | 1580 | Value memberOffset(0); | 
|  | 1581 | const DataExtractor& debug_info_data = get_debug_info_data(); | 
|  | 1582 | uint32_t block_length = form_value.Unsigned(); | 
|  | 1583 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); | 
|  | 1584 | if (DWARFExpression::Evaluate(NULL, // ExecutionContext * | 
|  | 1585 | NULL, // clang::ASTContext * | 
|  | 1586 | NULL, // ClangExpressionVariableList * | 
|  | 1587 | NULL, // ClangExpressionDeclMap * | 
|  | 1588 | NULL, // RegisterContext * | 
|  | 1589 | debug_info_data, | 
|  | 1590 | block_offset, | 
|  | 1591 | block_length, | 
|  | 1592 | eRegisterKindDWARF, | 
|  | 1593 | &initialValue, | 
|  | 1594 | memberOffset, | 
|  | 1595 | NULL)) | 
|  | 1596 | { | 
|  | 1597 | member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt(); | 
|  | 1598 | } | 
|  | 1599 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1600 | break; | 
|  | 1601 |  | 
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1602 | 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] | 1603 | case DW_AT_artificial: is_artificial = form_value.Boolean(); break; | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1604 | case DW_AT_APPLE_property_name:      prop_name = form_value.AsCString(&get_debug_str_data()); break; | 
|  | 1605 | case DW_AT_APPLE_property_getter:    prop_getter_name = form_value.AsCString(&get_debug_str_data()); break; | 
|  | 1606 | case DW_AT_APPLE_property_setter:    prop_setter_name = form_value.AsCString(&get_debug_str_data()); break; | 
|  | 1607 | case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break; | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 1608 | case DW_AT_external:                 is_external = form_value.Boolean(); break; | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1609 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1610 | default: | 
| Greg Clayton | 1b02c17 | 2012-03-14 21:00:47 +0000 | [diff] [blame] | 1611 | case DW_AT_declaration: | 
|  | 1612 | case DW_AT_description: | 
|  | 1613 | case DW_AT_mutable: | 
|  | 1614 | case DW_AT_visibility: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1615 | case DW_AT_sibling: | 
|  | 1616 | break; | 
|  | 1617 | } | 
|  | 1618 | } | 
|  | 1619 | } | 
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1620 |  | 
|  | 1621 | if (prop_name) | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1622 | { | 
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1623 | ConstString fixed_getter; | 
|  | 1624 | ConstString fixed_setter; | 
|  | 1625 |  | 
|  | 1626 | // Check if the property getter/setter were provided as full | 
|  | 1627 | // names.  We want basenames, so we extract them. | 
|  | 1628 |  | 
|  | 1629 | if (prop_getter_name && prop_getter_name[0] == '-') | 
|  | 1630 | { | 
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 1631 | ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true); | 
|  | 1632 | prop_getter_name = prop_getter_method.GetSelector().GetCString(); | 
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1633 | } | 
|  | 1634 |  | 
|  | 1635 | if (prop_setter_name && prop_setter_name[0] == '-') | 
|  | 1636 | { | 
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 1637 | ObjCLanguageRuntime::MethodName prop_setter_method(prop_setter_name, true); | 
|  | 1638 | prop_setter_name = prop_setter_method.GetSelector().GetCString(); | 
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1639 | } | 
|  | 1640 |  | 
|  | 1641 | // If the names haven't been provided, they need to be | 
|  | 1642 | // filled in. | 
|  | 1643 |  | 
|  | 1644 | if (!prop_getter_name) | 
|  | 1645 | { | 
|  | 1646 | prop_getter_name = prop_name; | 
|  | 1647 | } | 
|  | 1648 | if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly)) | 
|  | 1649 | { | 
|  | 1650 | StreamString ss; | 
|  | 1651 |  | 
|  | 1652 | ss.Printf("set%c%s:", | 
|  | 1653 | toupper(prop_name[0]), | 
|  | 1654 | &prop_name[1]); | 
|  | 1655 |  | 
|  | 1656 | fixed_setter.SetCString(ss.GetData()); | 
|  | 1657 | prop_setter_name = fixed_setter.GetCString(); | 
|  | 1658 | } | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1659 | } | 
|  | 1660 |  | 
|  | 1661 | // Clang has a DWARF generation bug where sometimes it | 
| Greg Clayton | 4495393 | 2011-10-25 01:25:35 +0000 | [diff] [blame] | 1662 | // represents fields that are references with bad byte size | 
|  | 1663 | // and bit size/offset information such as: | 
|  | 1664 | // | 
|  | 1665 | //  DW_AT_byte_size( 0x00 ) | 
|  | 1666 | //  DW_AT_bit_size( 0x40 ) | 
|  | 1667 | //  DW_AT_bit_offset( 0xffffffffffffffc0 ) | 
|  | 1668 | // | 
|  | 1669 | // So check the bit offset to make sure it is sane, and if | 
|  | 1670 | // the values are not sane, remove them. If we don't do this | 
|  | 1671 | // then we will end up with a crash if we try to use this | 
|  | 1672 | // type in an expression when clang becomes unhappy with its | 
|  | 1673 | // recycled debug info. | 
| Sean Callanan | 5a477cf | 2010-10-30 01:56:10 +0000 | [diff] [blame] | 1674 |  | 
| Greg Clayton | 4495393 | 2011-10-25 01:25:35 +0000 | [diff] [blame] | 1675 | if (bit_offset > 128) | 
|  | 1676 | { | 
|  | 1677 | bit_size = 0; | 
|  | 1678 | bit_offset = 0; | 
|  | 1679 | } | 
|  | 1680 |  | 
|  | 1681 | // FIXME: Make Clang ignore Objective-C accessibility for expressions | 
| Sean Callanan | 5a477cf | 2010-10-30 01:56:10 +0000 | [diff] [blame] | 1682 | if (class_language == eLanguageTypeObjC || | 
|  | 1683 | class_language == eLanguageTypeObjC_plus_plus) | 
|  | 1684 | accessibility = eAccessNone; | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1685 |  | 
|  | 1686 | if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name)) | 
|  | 1687 | { | 
|  | 1688 | // Not all compilers will mark the vtable pointer | 
|  | 1689 | // member as artificial (llvm-gcc). We can't have | 
|  | 1690 | // the virtual members in our classes otherwise it | 
|  | 1691 | // throws off all child offsets since we end up | 
|  | 1692 | // having and extra pointer sized member in our | 
|  | 1693 | // class layouts. | 
|  | 1694 | is_artificial = true; | 
|  | 1695 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1696 |  | 
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1697 | // Skip static members | 
|  | 1698 | if (is_external && member_byte_offset == UINT32_MAX) | 
| Greg Clayton | 973b6c9 | 2013-04-11 16:57:51 +0000 | [diff] [blame] | 1699 | { | 
|  | 1700 | Type *var_type = ResolveTypeUID(encoding_uid); | 
|  | 1701 |  | 
|  | 1702 | if (var_type) | 
|  | 1703 | { | 
|  | 1704 | GetClangASTContext().AddVariableToRecordType (class_clang_type, | 
|  | 1705 | name, | 
|  | 1706 | var_type->GetClangLayoutType(), | 
|  | 1707 | accessibility); | 
|  | 1708 | } | 
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1709 | break; | 
| Greg Clayton | 973b6c9 | 2013-04-11 16:57:51 +0000 | [diff] [blame] | 1710 | } | 
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1711 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1712 | if (is_artificial == false) | 
|  | 1713 | { | 
|  | 1714 | Type *member_type = ResolveTypeUID(encoding_uid); | 
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 1715 |  | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1716 | clang::FieldDecl *field_decl = NULL; | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1717 | if (tag == DW_TAG_member) | 
| Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1718 | { | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1719 | if (member_type) | 
|  | 1720 | { | 
|  | 1721 | if (accessibility == eAccessNone) | 
|  | 1722 | accessibility = default_accessibility; | 
|  | 1723 | member_accessibilities.push_back(accessibility); | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1724 |  | 
|  | 1725 | BitfieldInfo this_field_info; | 
|  | 1726 |  | 
|  | 1727 | this_field_info.bit_size = bit_size; | 
|  | 1728 |  | 
|  | 1729 | if (member_byte_offset != UINT32_MAX || bit_size != 0) | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1730 | { | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1731 | ///////////////////////////////////////////////////////////// | 
|  | 1732 | // How to locate a field given the DWARF debug information | 
|  | 1733 | // | 
|  | 1734 | // AT_byte_size indicates the size of the word in which the | 
|  | 1735 | // bit offset must be interpreted. | 
|  | 1736 | // | 
|  | 1737 | // AT_data_member_location indicates the byte offset of the | 
|  | 1738 | // word from the base address of the structure. | 
|  | 1739 | // | 
|  | 1740 | // AT_bit_offset indicates how many bits into the word | 
|  | 1741 | // (according to the host endianness) the low-order bit of | 
|  | 1742 | // the field starts.  AT_bit_offset can be negative. | 
|  | 1743 | // | 
|  | 1744 | // AT_bit_size indicates the size of the field in bits. | 
|  | 1745 | ///////////////////////////////////////////////////////////// | 
|  | 1746 |  | 
|  | 1747 | this_field_info.bit_offset = 0; | 
|  | 1748 |  | 
|  | 1749 | this_field_info.bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8)); | 
|  | 1750 |  | 
|  | 1751 | if (GetObjectFile()->GetByteOrder() == eByteOrderLittle) | 
|  | 1752 | { | 
|  | 1753 | this_field_info.bit_offset += byte_size * 8; | 
|  | 1754 | this_field_info.bit_offset -= (bit_offset + bit_size); | 
|  | 1755 | } | 
|  | 1756 | else | 
|  | 1757 | { | 
|  | 1758 | this_field_info.bit_offset += bit_offset; | 
|  | 1759 | } | 
|  | 1760 | } | 
|  | 1761 |  | 
|  | 1762 | // If the member to be emitted did not start on a character boundary and there is | 
|  | 1763 | // empty space between the last field and this one, then we need to emit an | 
|  | 1764 | // anonymous member filling up the space up to its start.  There are three cases | 
|  | 1765 | // here: | 
|  | 1766 | // | 
|  | 1767 | // 1 If the previous member ended on a character boundary, then we can emit an | 
|  | 1768 | //   anonymous member starting at the most recent character boundary. | 
|  | 1769 | // | 
|  | 1770 | // 2 If the previous member did not end on a character boundary and the distance | 
|  | 1771 | //   from the end of the previous member to the current member is less than a | 
|  | 1772 | //   word width, then we can emit an anonymous member starting right after the | 
|  | 1773 | //   previous member and right before this member. | 
|  | 1774 | // | 
|  | 1775 | // 3 If the previous member did not end on a character boundary and the distance | 
|  | 1776 | //   from the end of the previous member to the current member is greater than | 
|  | 1777 | //   or equal a word width, then we act as in Case 1. | 
|  | 1778 |  | 
|  | 1779 | const uint64_t character_width = 8; | 
|  | 1780 | const uint64_t word_width = 32; | 
|  | 1781 |  | 
|  | 1782 | if (this_field_info.IsValid()) | 
|  | 1783 | { | 
|  | 1784 | // Objective-C has invalid DW_AT_bit_offset values in older versions | 
|  | 1785 | // of clang, so we have to be careful and only insert unnammed bitfields | 
| Greg Clayton | 37c36e4 | 2012-11-27 00:59:26 +0000 | [diff] [blame] | 1786 | // if we have a new enough clang. | 
|  | 1787 | bool detect_unnamed_bitfields = true; | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1788 |  | 
| Greg Clayton | 37c36e4 | 2012-11-27 00:59:26 +0000 | [diff] [blame] | 1789 | if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus) | 
|  | 1790 | detect_unnamed_bitfields = dwarf_cu->Supports_unnamed_objc_bitfields (); | 
|  | 1791 |  | 
|  | 1792 | if (detect_unnamed_bitfields) | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1793 | { | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1794 | BitfieldInfo anon_field_info; | 
|  | 1795 |  | 
|  | 1796 | if ((this_field_info.bit_offset % character_width) != 0) // not char aligned | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1797 | { | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1798 | uint64_t last_field_end = 0; | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1799 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1800 | if (last_field_info.IsValid()) | 
|  | 1801 | 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] | 1802 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1803 | if (this_field_info.bit_offset != last_field_end) | 
|  | 1804 | { | 
|  | 1805 | if (((last_field_end % character_width) == 0) ||                    // case 1 | 
|  | 1806 | (this_field_info.bit_offset - last_field_end >= word_width))    // case 3 | 
|  | 1807 | { | 
|  | 1808 | anon_field_info.bit_size = this_field_info.bit_offset % character_width; | 
|  | 1809 | anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size; | 
|  | 1810 | } | 
|  | 1811 | else                                                                // case 2 | 
|  | 1812 | { | 
|  | 1813 | anon_field_info.bit_size = this_field_info.bit_offset - last_field_end; | 
|  | 1814 | anon_field_info.bit_offset = last_field_end; | 
|  | 1815 | } | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1816 | } | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1817 | } | 
|  | 1818 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1819 | if (anon_field_info.IsValid()) | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1820 | { | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1821 | clang::FieldDecl *unnamed_bitfield_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type, | 
|  | 1822 | NULL, | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1823 | GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width), | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1824 | accessibility, | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1825 | anon_field_info.bit_size); | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1826 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1827 | layout_info.field_offsets.insert(std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset)); | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1828 | } | 
|  | 1829 | } | 
|  | 1830 | } | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1831 |  | 
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 1832 | clang_type_t member_clang_type = member_type->GetClangLayoutType(); | 
|  | 1833 |  | 
|  | 1834 | { | 
|  | 1835 | // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>). | 
|  | 1836 | // If the current field is at the end of the structure, then there is definitely no room for extra | 
|  | 1837 | // elements and we override the type to array[0]. | 
|  | 1838 |  | 
|  | 1839 | clang_type_t member_array_element_type; | 
|  | 1840 | uint64_t member_array_size; | 
|  | 1841 | bool member_array_is_incomplete; | 
|  | 1842 |  | 
|  | 1843 | if (GetClangASTContext().IsArrayType(member_clang_type, | 
|  | 1844 | &member_array_element_type, | 
|  | 1845 | &member_array_size, | 
|  | 1846 | &member_array_is_incomplete) && | 
|  | 1847 | !member_array_is_incomplete) | 
|  | 1848 | { | 
|  | 1849 | uint64_t parent_byte_size = parent_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, UINT64_MAX); | 
|  | 1850 |  | 
|  | 1851 | if (member_byte_offset >= parent_byte_size) | 
|  | 1852 | { | 
|  | 1853 | if (member_array_size != 1) | 
|  | 1854 | { | 
|  | 1855 | 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, | 
|  | 1856 | MakeUserID(die->GetOffset()), | 
|  | 1857 | name, | 
|  | 1858 | encoding_uid, | 
|  | 1859 | MakeUserID(parent_die->GetOffset())); | 
|  | 1860 | } | 
|  | 1861 |  | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 1862 | member_clang_type = GetClangASTContext().CreateArrayType(member_array_element_type, 0, false); | 
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 1863 | } | 
|  | 1864 | } | 
|  | 1865 | } | 
|  | 1866 |  | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1867 | field_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type, | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1868 | name, | 
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 1869 | member_clang_type, | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1870 | accessibility, | 
|  | 1871 | bit_size); | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 1872 |  | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 1873 | GetClangASTContext().SetMetadataAsUserID (field_decl, MakeUserID(die->GetOffset())); | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1874 |  | 
|  | 1875 | if (this_field_info.IsValid()) | 
|  | 1876 | { | 
|  | 1877 | layout_info.field_offsets.insert(std::make_pair(field_decl, this_field_info.bit_offset)); | 
|  | 1878 | last_field_info = this_field_info; | 
|  | 1879 | } | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1880 | } | 
|  | 1881 | else | 
|  | 1882 | { | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1883 | if (name) | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1884 | 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] | 1885 | MakeUserID(die->GetOffset()), | 
|  | 1886 | name, | 
|  | 1887 | encoding_uid); | 
|  | 1888 | else | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1889 | 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] | 1890 | MakeUserID(die->GetOffset()), | 
|  | 1891 | encoding_uid); | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1892 | } | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1893 | } | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1894 |  | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1895 | if (prop_name != NULL) | 
|  | 1896 | { | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1897 | clang::ObjCIvarDecl *ivar_decl = NULL; | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1898 |  | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1899 | if (field_decl) | 
|  | 1900 | { | 
|  | 1901 | ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl); | 
|  | 1902 | assert (ivar_decl != NULL); | 
|  | 1903 | } | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1904 |  | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1905 | ClangASTMetadata metadata; | 
|  | 1906 | metadata.SetUserID (MakeUserID(die->GetOffset())); | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1907 | delayed_properties.push_back(DelayedAddObjCClassProperty(GetClangASTContext().getASTContext(), | 
|  | 1908 | class_clang_type, | 
|  | 1909 | prop_name, | 
|  | 1910 | member_type->GetClangLayoutType(), | 
|  | 1911 | ivar_decl, | 
|  | 1912 | prop_setter_name, | 
|  | 1913 | prop_getter_name, | 
|  | 1914 | prop_attributes, | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1915 | &metadata)); | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 1916 |  | 
| Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 1917 | if (ivar_decl) | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 1918 | GetClangASTContext().SetMetadataAsUserID (ivar_decl, MakeUserID(die->GetOffset())); | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1919 | } | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1920 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1921 | } | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1922 | ++member_idx; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1923 | } | 
|  | 1924 | break; | 
|  | 1925 |  | 
|  | 1926 | case DW_TAG_subprogram: | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1927 | // Let the type parsing code handle this one for us. | 
|  | 1928 | member_function_dies.Append (die); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1929 | break; | 
|  | 1930 |  | 
|  | 1931 | case DW_TAG_inheritance: | 
|  | 1932 | { | 
|  | 1933 | is_a_class = true; | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1934 | if (default_accessibility == eAccessNone) | 
|  | 1935 | default_accessibility = eAccessPrivate; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1936 | // TODO: implement DW_TAG_inheritance type parsing | 
|  | 1937 | DWARFDebugInfoEntry::Attributes attributes; | 
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1938 | const size_t num_attributes = die->GetAttributes (this, | 
|  | 1939 | dwarf_cu, | 
|  | 1940 | fixed_form_sizes, | 
|  | 1941 | attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1942 | if (num_attributes > 0) | 
|  | 1943 | { | 
|  | 1944 | Declaration decl; | 
|  | 1945 | DWARFExpression location; | 
|  | 1946 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1947 | AccessType accessibility = default_accessibility; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1948 | bool is_virtual = false; | 
|  | 1949 | bool is_base_of_class = true; | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 1950 | off_t member_byte_offset = 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1951 | uint32_t i; | 
|  | 1952 | for (i=0; i<num_attributes; ++i) | 
|  | 1953 | { | 
|  | 1954 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 1955 | DWARFFormValue form_value; | 
|  | 1956 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 1957 | { | 
|  | 1958 | switch (attr) | 
|  | 1959 | { | 
|  | 1960 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 1961 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 1962 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 1963 | case DW_AT_type:        encoding_uid = form_value.Reference(dwarf_cu); break; | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 1964 | case DW_AT_data_member_location: | 
|  | 1965 | if (form_value.BlockData()) | 
|  | 1966 | { | 
|  | 1967 | Value initialValue(0); | 
|  | 1968 | Value memberOffset(0); | 
|  | 1969 | const DataExtractor& debug_info_data = get_debug_info_data(); | 
|  | 1970 | uint32_t block_length = form_value.Unsigned(); | 
|  | 1971 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); | 
|  | 1972 | if (DWARFExpression::Evaluate (NULL, | 
|  | 1973 | NULL, | 
|  | 1974 | NULL, | 
|  | 1975 | NULL, | 
|  | 1976 | NULL, | 
|  | 1977 | debug_info_data, | 
|  | 1978 | block_offset, | 
|  | 1979 | block_length, | 
|  | 1980 | eRegisterKindDWARF, | 
|  | 1981 | &initialValue, | 
|  | 1982 | memberOffset, | 
|  | 1983 | NULL)) | 
|  | 1984 | { | 
|  | 1985 | member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt(); | 
|  | 1986 | } | 
|  | 1987 | } | 
|  | 1988 | break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1989 |  | 
|  | 1990 | case DW_AT_accessibility: | 
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1991 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1992 | break; | 
|  | 1993 |  | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 1994 | case DW_AT_virtuality: is_virtual = form_value.Boolean(); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1995 | default: | 
|  | 1996 | case DW_AT_sibling: | 
|  | 1997 | break; | 
|  | 1998 | } | 
|  | 1999 | } | 
|  | 2000 | } | 
|  | 2001 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 2002 | Type *base_class_type = ResolveTypeUID(encoding_uid); | 
|  | 2003 | assert(base_class_type); | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2004 |  | 
| Greg Clayton | f4ecaa5 | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 2005 | clang_type_t base_class_clang_type = base_class_type->GetClangFullType(); | 
|  | 2006 | assert (base_class_clang_type); | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2007 | if (class_language == eLanguageTypeObjC) | 
|  | 2008 | { | 
| Greg Clayton | f4ecaa5 | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 2009 | GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type); | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2010 | } | 
|  | 2011 | else | 
|  | 2012 | { | 
| Greg Clayton | f4ecaa5 | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 2013 | base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type, | 
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 2014 | accessibility, | 
|  | 2015 | is_virtual, | 
|  | 2016 | is_base_of_class)); | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2017 |  | 
|  | 2018 | if (is_virtual) | 
|  | 2019 | { | 
|  | 2020 | layout_info.vbase_offsets.insert(std::make_pair(ClangASTType::GetAsCXXRecordDecl(class_clang_type), | 
|  | 2021 | clang::CharUnits::fromQuantity(member_byte_offset))); | 
|  | 2022 | } | 
|  | 2023 | else | 
|  | 2024 | { | 
|  | 2025 | layout_info.base_offsets.insert(std::make_pair(ClangASTType::GetAsCXXRecordDecl(class_clang_type), | 
|  | 2026 | clang::CharUnits::fromQuantity(member_byte_offset))); | 
|  | 2027 | } | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2028 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2029 | } | 
|  | 2030 | } | 
|  | 2031 | break; | 
|  | 2032 |  | 
|  | 2033 | default: | 
|  | 2034 | break; | 
|  | 2035 | } | 
|  | 2036 | } | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2037 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2038 | return count; | 
|  | 2039 | } | 
|  | 2040 |  | 
|  | 2041 |  | 
|  | 2042 | clang::DeclContext* | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 2043 | SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2044 | { | 
|  | 2045 | DWARFDebugInfo* debug_info = DebugInfo(); | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2046 | if (debug_info && UserIDMatches(type_uid)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2047 | { | 
|  | 2048 | DWARFCompileUnitSP cu_sp; | 
|  | 2049 | const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp); | 
|  | 2050 | if (die) | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 2051 | return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL); | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 2052 | } | 
|  | 2053 | return NULL; | 
|  | 2054 | } | 
|  | 2055 |  | 
|  | 2056 | clang::DeclContext* | 
|  | 2057 | SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid) | 
|  | 2058 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2059 | if (UserIDMatches(type_uid)) | 
|  | 2060 | return GetClangDeclContextForDIEOffset (sc, type_uid); | 
|  | 2061 | return NULL; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2062 | } | 
|  | 2063 |  | 
|  | 2064 | Type* | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2065 | SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2066 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2067 | if (UserIDMatches(type_uid)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2068 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2069 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 2070 | if (debug_info) | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2071 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2072 | DWARFCompileUnitSP cu_sp; | 
|  | 2073 | const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp); | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2074 | const bool assert_not_being_parsed = true; | 
|  | 2075 | return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed); | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2076 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2077 | } | 
|  | 2078 | return NULL; | 
|  | 2079 | } | 
|  | 2080 |  | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2081 | Type* | 
|  | 2082 | SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed) | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2083 | { | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2084 | if (die != NULL) | 
|  | 2085 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2086 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2087 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2088 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2089 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'", | 
|  | 2090 | die->GetOffset(), | 
|  | 2091 | DW_TAG_value_to_name(die->Tag()), | 
|  | 2092 | die->GetName(this, cu)); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2093 |  | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2094 | // We might be coming in in the middle of a type tree (a class | 
|  | 2095 | // withing a class, an enum within a class), so parse any needed | 
|  | 2096 | // parent DIEs before we get to this one... | 
|  | 2097 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); | 
|  | 2098 | switch (decl_ctx_die->Tag()) | 
|  | 2099 | { | 
|  | 2100 | case DW_TAG_structure_type: | 
|  | 2101 | case DW_TAG_union_type: | 
|  | 2102 | case DW_TAG_class_type: | 
|  | 2103 | { | 
|  | 2104 | // Get the type, which could be a forward declaration | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2105 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2106 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2107 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x", | 
|  | 2108 | die->GetOffset(), | 
|  | 2109 | DW_TAG_value_to_name(die->Tag()), | 
|  | 2110 | die->GetName(this, cu), | 
|  | 2111 | decl_ctx_die->GetOffset()); | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2112 | // | 
|  | 2113 | //                Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed); | 
|  | 2114 | //                if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag())) | 
|  | 2115 | //                { | 
|  | 2116 | //                    if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2117 | //                        GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2118 | //                                                                  "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function", | 
|  | 2119 | //                                                                  die->GetOffset(), | 
|  | 2120 | //                                                                  DW_TAG_value_to_name(die->Tag()), | 
|  | 2121 | //                                                                  die->GetName(this, cu), | 
|  | 2122 | //                                                                  decl_ctx_die->GetOffset()); | 
|  | 2123 | //                    // Ask the type to complete itself if it already hasn't since if we | 
|  | 2124 | //                    // want a function (method or static) from a class, the class must | 
|  | 2125 | //                    // create itself and add it's own methods and class functions. | 
|  | 2126 | //                    if (parent_type) | 
|  | 2127 | //                        parent_type->GetClangFullType(); | 
|  | 2128 | //                } | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2129 | } | 
|  | 2130 | break; | 
|  | 2131 |  | 
|  | 2132 | default: | 
|  | 2133 | break; | 
|  | 2134 | } | 
|  | 2135 | return ResolveType (cu, die); | 
|  | 2136 | } | 
|  | 2137 | return NULL; | 
|  | 2138 | } | 
|  | 2139 |  | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2140 | // This function is used when SymbolFileDWARFDebugMap owns a bunch of | 
|  | 2141 | // SymbolFileDWARF objects to detect if this DWARF file is the one that | 
|  | 2142 | // can resolve a clang_type. | 
|  | 2143 | bool | 
|  | 2144 | SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type) | 
|  | 2145 | { | 
|  | 2146 | clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type); | 
|  | 2147 | const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers); | 
|  | 2148 | return die != NULL; | 
|  | 2149 | } | 
|  | 2150 |  | 
|  | 2151 |  | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2152 | lldb::clang_type_t | 
|  | 2153 | SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type) | 
|  | 2154 | { | 
|  | 2155 | // We have a struct/union/class/enum that needs to be fully resolved. | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2156 | clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type); | 
|  | 2157 | const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2158 | if (die == NULL) | 
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2159 | { | 
|  | 2160 | // We have already resolved this type... | 
|  | 2161 | return clang_type; | 
|  | 2162 | } | 
|  | 2163 | // Once we start resolving this type, remove it from the forward declaration | 
|  | 2164 | // map in case anyone child members or other types require this type to get resolved. | 
|  | 2165 | // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition | 
|  | 2166 | // are done. | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2167 | m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers); | 
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2168 |  | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2169 |  | 
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 2170 | // Disable external storage for this type so we don't get anymore | 
|  | 2171 | // clang::ExternalASTSource queries for this type. | 
|  | 2172 | ClangASTContext::SetHasExternalStorage (clang_type, false); | 
|  | 2173 |  | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2174 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 2175 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2176 | DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get(); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2177 | Type *type = m_die_to_type.lookup (die); | 
|  | 2178 |  | 
|  | 2179 | const dw_tag_t tag = die->Tag(); | 
|  | 2180 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2181 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION)); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2182 | if (log) | 
| Greg Clayton | baf95da | 2012-03-30 23:50:54 +0000 | [diff] [blame] | 2183 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2184 | GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2185 | "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...", | 
| Greg Clayton | d61c0fc | 2012-04-23 22:55:20 +0000 | [diff] [blame] | 2186 | MakeUserID(die->GetOffset()), | 
|  | 2187 | DW_TAG_value_to_name(tag), | 
|  | 2188 | type->GetName().AsCString()); | 
| Greg Clayton | baf95da | 2012-03-30 23:50:54 +0000 | [diff] [blame] | 2189 |  | 
| Greg Clayton | baf95da | 2012-03-30 23:50:54 +0000 | [diff] [blame] | 2190 | } | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2191 | assert (clang_type); | 
|  | 2192 | DWARFDebugInfoEntry::Attributes attributes; | 
|  | 2193 |  | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 2194 | ClangASTContext &ast = GetClangASTContext(); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2195 |  | 
|  | 2196 | switch (tag) | 
|  | 2197 | { | 
|  | 2198 | case DW_TAG_structure_type: | 
|  | 2199 | case DW_TAG_union_type: | 
|  | 2200 | case DW_TAG_class_type: | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2201 | { | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2202 | LayoutInfo layout_info; | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2203 |  | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2204 | { | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2205 | if (die->HasChildren()) | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2206 | { | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2207 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2208 | LanguageType class_language = eLanguageTypeUnknown; | 
|  | 2209 | bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type); | 
|  | 2210 | if (is_objc_class) | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2211 | { | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2212 | class_language = eLanguageTypeObjC; | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2213 | // For objective C we don't start the definition when | 
|  | 2214 | // the class is created. | 
|  | 2215 | ast.StartTagDeclarationDefinition (clang_type); | 
|  | 2216 | } | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2217 |  | 
|  | 2218 | int tag_decl_kind = -1; | 
|  | 2219 | AccessType default_accessibility = eAccessNone; | 
|  | 2220 | if (tag == DW_TAG_structure_type) | 
|  | 2221 | { | 
|  | 2222 | tag_decl_kind = clang::TTK_Struct; | 
|  | 2223 | default_accessibility = eAccessPublic; | 
|  | 2224 | } | 
|  | 2225 | else if (tag == DW_TAG_union_type) | 
|  | 2226 | { | 
|  | 2227 | tag_decl_kind = clang::TTK_Union; | 
|  | 2228 | default_accessibility = eAccessPublic; | 
|  | 2229 | } | 
|  | 2230 | else if (tag == DW_TAG_class_type) | 
|  | 2231 | { | 
|  | 2232 | tag_decl_kind = clang::TTK_Class; | 
|  | 2233 | default_accessibility = eAccessPrivate; | 
|  | 2234 | } | 
|  | 2235 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2236 | SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2237 | std::vector<clang::CXXBaseSpecifier *> base_classes; | 
|  | 2238 | std::vector<int> member_accessibilities; | 
|  | 2239 | bool is_a_class = false; | 
|  | 2240 | // Parse members and base classes first | 
|  | 2241 | DWARFDIECollection member_function_dies; | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2242 |  | 
|  | 2243 | DelayedPropertyList delayed_properties; | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2244 | ParseChildMembers (sc, | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2245 | dwarf_cu, | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2246 | die, | 
|  | 2247 | clang_type, | 
|  | 2248 | class_language, | 
|  | 2249 | base_classes, | 
|  | 2250 | member_accessibilities, | 
|  | 2251 | member_function_dies, | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2252 | delayed_properties, | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2253 | default_accessibility, | 
|  | 2254 | is_a_class, | 
|  | 2255 | layout_info); | 
|  | 2256 |  | 
|  | 2257 | // Now parse any methods if there were any... | 
|  | 2258 | size_t num_functions = member_function_dies.Size(); | 
|  | 2259 | if (num_functions > 0) | 
|  | 2260 | { | 
|  | 2261 | for (size_t i=0; i<num_functions; ++i) | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2262 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2263 | ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i)); | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2264 | } | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2265 | } | 
|  | 2266 |  | 
|  | 2267 | if (class_language == eLanguageTypeObjC) | 
|  | 2268 | { | 
| Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 2269 | std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(ast.getASTContext(), clang_type)); | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2270 | if (!class_str.empty()) | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2271 | { | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2272 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2273 | DIEArray method_die_offsets; | 
|  | 2274 | if (m_using_apple_tables) | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2275 | { | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2276 | if (m_apple_objc_ap.get()) | 
|  | 2277 | m_apple_objc_ap->FindByName(class_str.c_str(), method_die_offsets); | 
|  | 2278 | } | 
|  | 2279 | else | 
|  | 2280 | { | 
|  | 2281 | if (!m_indexed) | 
|  | 2282 | Index (); | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2283 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2284 | ConstString class_name (class_str.c_str()); | 
|  | 2285 | m_objc_class_selectors_index.Find (class_name, method_die_offsets); | 
|  | 2286 | } | 
|  | 2287 |  | 
|  | 2288 | if (!method_die_offsets.empty()) | 
|  | 2289 | { | 
|  | 2290 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 2291 |  | 
|  | 2292 | DWARFCompileUnit* method_cu = NULL; | 
|  | 2293 | const size_t num_matches = method_die_offsets.size(); | 
|  | 2294 | for (size_t i=0; i<num_matches; ++i) | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2295 | { | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2296 | const dw_offset_t die_offset = method_die_offsets[i]; | 
|  | 2297 | DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu); | 
|  | 2298 |  | 
|  | 2299 | if (method_die) | 
|  | 2300 | ResolveType (method_cu, method_die); | 
|  | 2301 | else | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2302 | { | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2303 | if (m_using_apple_tables) | 
|  | 2304 | { | 
|  | 2305 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n", | 
|  | 2306 | die_offset, class_str.c_str()); | 
|  | 2307 | } | 
|  | 2308 | } | 
|  | 2309 | } | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2310 | } | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2311 |  | 
|  | 2312 | for (DelayedPropertyList::const_iterator pi = delayed_properties.begin(), pe = delayed_properties.end(); | 
|  | 2313 | pi != pe; | 
|  | 2314 | ++pi) | 
|  | 2315 | pi->Finalize(); | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2316 | } | 
|  | 2317 | } | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2318 |  | 
|  | 2319 | // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we | 
|  | 2320 | // need to tell the clang type it is actually a class. | 
|  | 2321 | if (class_language != eLanguageTypeObjC) | 
|  | 2322 | { | 
|  | 2323 | if (is_a_class && tag_decl_kind != clang::TTK_Class) | 
|  | 2324 | ast.SetTagTypeKind (clang_type, clang::TTK_Class); | 
|  | 2325 | } | 
|  | 2326 |  | 
|  | 2327 | // Since DW_TAG_structure_type gets used for both classes | 
|  | 2328 | // and structures, we may need to set any DW_TAG_member | 
|  | 2329 | // fields to have a "private" access if none was specified. | 
|  | 2330 | // When we parsed the child members we tracked that actual | 
|  | 2331 | // accessibility value for each DW_TAG_member in the | 
|  | 2332 | // "member_accessibilities" array. If the value for the | 
|  | 2333 | // member is zero, then it was set to the "default_accessibility" | 
|  | 2334 | // which for structs was "public". Below we correct this | 
|  | 2335 | // by setting any fields to "private" that weren't correctly | 
|  | 2336 | // set. | 
|  | 2337 | if (is_a_class && !member_accessibilities.empty()) | 
|  | 2338 | { | 
|  | 2339 | // This is a class and all members that didn't have | 
|  | 2340 | // their access specified are private. | 
|  | 2341 | ast.SetDefaultAccessForRecordFields (clang_type, | 
|  | 2342 | eAccessPrivate, | 
|  | 2343 | &member_accessibilities.front(), | 
|  | 2344 | member_accessibilities.size()); | 
|  | 2345 | } | 
|  | 2346 |  | 
|  | 2347 | if (!base_classes.empty()) | 
|  | 2348 | { | 
|  | 2349 | ast.SetBaseClassesForClassType (clang_type, | 
|  | 2350 | &base_classes.front(), | 
|  | 2351 | base_classes.size()); | 
|  | 2352 |  | 
|  | 2353 | // Clang will copy each CXXBaseSpecifier in "base_classes" | 
|  | 2354 | // so we have to free them all. | 
|  | 2355 | ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(), | 
|  | 2356 | base_classes.size()); | 
|  | 2357 | } | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2358 | } | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2359 | } | 
| Sean Callanan | e8c0cfb | 2012-03-02 01:03:45 +0000 | [diff] [blame] | 2360 |  | 
|  | 2361 | ast.BuildIndirectFields (clang_type); | 
|  | 2362 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2363 | ast.CompleteTagDeclarationDefinition (clang_type); | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2364 |  | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2365 | if (!layout_info.field_offsets.empty() || | 
|  | 2366 | !layout_info.base_offsets.empty()  || | 
|  | 2367 | !layout_info.vbase_offsets.empty() ) | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2368 | { | 
|  | 2369 | if (type) | 
|  | 2370 | layout_info.bit_size = type->GetByteSize() * 8; | 
|  | 2371 | if (layout_info.bit_size == 0) | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2372 | layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8; | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2373 |  | 
|  | 2374 | clang::CXXRecordDecl *record_decl = ClangASTType::GetAsCXXRecordDecl(clang_type); | 
|  | 2375 | if (record_decl) | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2376 | { | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2377 | if (log) | 
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2378 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2379 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2380 | "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) caching layout info for record_decl = %p, bit_size = %" PRIu64 ", alignment = %" PRIu64 ", field_offsets[%u], base_offsets[%u], vbase_offsets[%u])", | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2381 | clang_type, | 
|  | 2382 | record_decl, | 
|  | 2383 | layout_info.bit_size, | 
|  | 2384 | layout_info.alignment, | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2385 | (uint32_t)layout_info.field_offsets.size(), | 
|  | 2386 | (uint32_t)layout_info.base_offsets.size(), | 
|  | 2387 | (uint32_t)layout_info.vbase_offsets.size()); | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2388 |  | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2389 | uint32_t idx; | 
|  | 2390 | { | 
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2391 | llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end(); | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2392 | for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx) | 
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2393 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2394 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2395 | "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = { bit_offset=%u, name='%s' }", | 
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2396 | clang_type, | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2397 | idx, | 
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2398 | (uint32_t)pos->second, | 
|  | 2399 | pos->first->getNameAsString().c_str()); | 
|  | 2400 | } | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2401 | } | 
|  | 2402 |  | 
|  | 2403 | { | 
|  | 2404 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos, base_end = layout_info.base_offsets.end(); | 
|  | 2405 | for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end; ++base_pos, ++idx) | 
|  | 2406 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2407 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2408 | "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] = { byte_offset=%u, name='%s' }", | 
|  | 2409 | clang_type, | 
|  | 2410 | idx, | 
|  | 2411 | (uint32_t)base_pos->second.getQuantity(), | 
|  | 2412 | base_pos->first->getNameAsString().c_str()); | 
|  | 2413 | } | 
|  | 2414 | } | 
|  | 2415 | { | 
|  | 2416 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos, vbase_end = layout_info.vbase_offsets.end(); | 
|  | 2417 | for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end; ++vbase_pos, ++idx) | 
|  | 2418 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2419 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2420 | "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) vbase[%u] = { byte_offset=%u, name='%s' }", | 
|  | 2421 | clang_type, | 
|  | 2422 | idx, | 
|  | 2423 | (uint32_t)vbase_pos->second.getQuantity(), | 
|  | 2424 | vbase_pos->first->getNameAsString().c_str()); | 
|  | 2425 | } | 
|  | 2426 | } | 
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2427 | } | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2428 | m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info)); | 
|  | 2429 | } | 
|  | 2430 | } | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2431 | } | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2432 |  | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2433 | return clang_type; | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2434 |  | 
|  | 2435 | case DW_TAG_enumeration_type: | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 2436 | ast.StartTagDeclarationDefinition (clang_type); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2437 | if (die->HasChildren()) | 
|  | 2438 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2439 | SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); | 
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 2440 | bool is_signed = false; | 
|  | 2441 | ast.IsIntegerType(clang_type, is_signed); | 
|  | 2442 | ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), dwarf_cu, die); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2443 | } | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 2444 | ast.CompleteTagDeclarationDefinition (clang_type); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2445 | return clang_type; | 
|  | 2446 |  | 
|  | 2447 | default: | 
|  | 2448 | assert(false && "not a forward clang type decl!"); | 
|  | 2449 | break; | 
|  | 2450 | } | 
|  | 2451 | return NULL; | 
|  | 2452 | } | 
|  | 2453 |  | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2454 | Type* | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2455 | 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] | 2456 | { | 
|  | 2457 | if (type_die != NULL) | 
|  | 2458 | { | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 2459 | Type *type = m_die_to_type.lookup (type_die); | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2460 |  | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2461 | if (type == NULL) | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2462 | type = GetTypeForDIE (dwarf_cu, type_die).get(); | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2463 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2464 | if (assert_not_being_parsed) | 
| Jim Ingham | c354928 | 2012-01-11 02:21:12 +0000 | [diff] [blame] | 2465 | { | 
|  | 2466 | if (type != DIE_IS_BEING_PARSED) | 
|  | 2467 | return type; | 
|  | 2468 |  | 
|  | 2469 | 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] | 2470 | type_die->GetOffset(), | 
|  | 2471 | DW_TAG_value_to_name(type_die->Tag()), | 
|  | 2472 | type_die->GetName(this, dwarf_cu)); | 
| Jim Ingham | c354928 | 2012-01-11 02:21:12 +0000 | [diff] [blame] | 2473 |  | 
|  | 2474 | } | 
|  | 2475 | else | 
|  | 2476 | return type; | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2477 | } | 
|  | 2478 | return NULL; | 
|  | 2479 | } | 
|  | 2480 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2481 | CompileUnit* | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2482 | SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2483 | { | 
|  | 2484 | // Check if the symbol vendor already knows about this compile unit? | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2485 | if (dwarf_cu->GetUserData() == NULL) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2486 | { | 
|  | 2487 | // The symbol vendor doesn't know about this compile unit, we | 
|  | 2488 | // need to parse and add it to the symbol vendor object. | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2489 | return ParseCompileUnit(dwarf_cu, cu_idx).get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2490 | } | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2491 | return (CompileUnit*)dwarf_cu->GetUserData(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2492 | } | 
|  | 2493 |  | 
|  | 2494 | bool | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2495 | SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2496 | { | 
| Greg Clayton | 7231035 | 2013-02-23 04:12:47 +0000 | [diff] [blame] | 2497 | sc.Clear(false); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2498 | // Check if the symbol vendor already knows about this compile unit? | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2499 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2500 |  | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2501 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2502 | if (sc.function == NULL) | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2503 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2504 |  | 
|  | 2505 | if (sc.function) | 
|  | 2506 | { | 
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 2507 | sc.module_sp = sc.function->CalculateSymbolContextModule(); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2508 | return true; | 
|  | 2509 | } | 
|  | 2510 |  | 
|  | 2511 | return false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2512 | } | 
|  | 2513 |  | 
|  | 2514 | uint32_t | 
|  | 2515 | SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) | 
|  | 2516 | { | 
|  | 2517 | Timer scoped_timer(__PRETTY_FUNCTION__, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2518 | "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%" PRIx64 " }, resolve_scope = 0x%8.8x)", | 
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 2519 | so_addr.GetSection().get(), | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2520 | so_addr.GetOffset(), | 
|  | 2521 | resolve_scope); | 
|  | 2522 | uint32_t resolved = 0; | 
|  | 2523 | if (resolve_scope & (   eSymbolContextCompUnit | | 
|  | 2524 | eSymbolContextFunction | | 
|  | 2525 | eSymbolContextBlock | | 
|  | 2526 | eSymbolContextLineEntry)) | 
|  | 2527 | { | 
|  | 2528 | lldb::addr_t file_vm_addr = so_addr.GetFileAddress(); | 
|  | 2529 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2530 | DWARFDebugInfo* debug_info = DebugInfo(); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2531 | if (debug_info) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2532 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2533 | const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2534 | if (cu_offset != DW_INVALID_OFFSET) | 
|  | 2535 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2536 | uint32_t cu_idx = DW_INVALID_INDEX; | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2537 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get(); | 
|  | 2538 | if (dwarf_cu) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2539 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2540 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2541 | if (sc.comp_unit) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2542 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2543 | resolved |= eSymbolContextCompUnit; | 
|  | 2544 |  | 
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2545 | bool force_check_line_table = false; | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2546 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) | 
|  | 2547 | { | 
|  | 2548 | DWARFDebugInfoEntry *function_die = NULL; | 
|  | 2549 | DWARFDebugInfoEntry *block_die = NULL; | 
|  | 2550 | if (resolve_scope & eSymbolContextBlock) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2551 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2552 | dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die); | 
|  | 2553 | } | 
|  | 2554 | else | 
|  | 2555 | { | 
|  | 2556 | dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL); | 
|  | 2557 | } | 
|  | 2558 |  | 
|  | 2559 | if (function_die != NULL) | 
|  | 2560 | { | 
|  | 2561 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); | 
|  | 2562 | if (sc.function == NULL) | 
|  | 2563 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die); | 
|  | 2564 | } | 
|  | 2565 | else | 
|  | 2566 | { | 
|  | 2567 | // We might have had a compile unit that had discontiguous | 
|  | 2568 | // address ranges where the gaps are symbols that don't have | 
|  | 2569 | // any debug info. Discontiguous compile unit address ranges | 
|  | 2570 | // should only happen when there aren't other functions from | 
|  | 2571 | // other compile units in these gaps. This helps keep the size | 
|  | 2572 | // of the aranges down. | 
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2573 | force_check_line_table = true; | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2574 | } | 
|  | 2575 |  | 
|  | 2576 | if (sc.function != NULL) | 
|  | 2577 | { | 
|  | 2578 | resolved |= eSymbolContextFunction; | 
|  | 2579 |  | 
|  | 2580 | if (resolve_scope & eSymbolContextBlock) | 
|  | 2581 | { | 
|  | 2582 | Block& block = sc.function->GetBlock (true); | 
|  | 2583 |  | 
|  | 2584 | if (block_die != NULL) | 
|  | 2585 | sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); | 
|  | 2586 | else | 
|  | 2587 | sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); | 
|  | 2588 | if (sc.block) | 
|  | 2589 | resolved |= eSymbolContextBlock; | 
|  | 2590 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2591 | } | 
|  | 2592 | } | 
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2593 |  | 
|  | 2594 | if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table) | 
|  | 2595 | { | 
|  | 2596 | LineTable *line_table = sc.comp_unit->GetLineTable(); | 
|  | 2597 | if (line_table != NULL) | 
|  | 2598 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 2599 | // And address that makes it into this function should be in terms | 
|  | 2600 | // of this debug file if there is no debug map, or it will be an | 
|  | 2601 | // address in the .o file which needs to be fixed up to be in terms | 
|  | 2602 | // of the debug map executable. Either way, calling FixupAddress() | 
|  | 2603 | // will work for us. | 
|  | 2604 | Address exe_so_addr (so_addr); | 
|  | 2605 | if (FixupAddress(exe_so_addr)) | 
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2606 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 2607 | if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry)) | 
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2608 | { | 
|  | 2609 | resolved |= eSymbolContextLineEntry; | 
|  | 2610 | } | 
|  | 2611 | } | 
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2612 | } | 
|  | 2613 | } | 
|  | 2614 |  | 
|  | 2615 | if (force_check_line_table && !(resolved & eSymbolContextLineEntry)) | 
|  | 2616 | { | 
|  | 2617 | // We might have had a compile unit that had discontiguous | 
|  | 2618 | // address ranges where the gaps are symbols that don't have | 
|  | 2619 | // any debug info. Discontiguous compile unit address ranges | 
|  | 2620 | // should only happen when there aren't other functions from | 
|  | 2621 | // other compile units in these gaps. This helps keep the size | 
|  | 2622 | // of the aranges down. | 
|  | 2623 | sc.comp_unit = NULL; | 
|  | 2624 | resolved &= ~eSymbolContextCompUnit; | 
|  | 2625 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2626 | } | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2627 | else | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2628 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2629 | GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.", | 
|  | 2630 | cu_offset, | 
|  | 2631 | cu_idx); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2632 | } | 
|  | 2633 | } | 
|  | 2634 | } | 
|  | 2635 | } | 
|  | 2636 | } | 
|  | 2637 | return resolved; | 
|  | 2638 | } | 
|  | 2639 |  | 
|  | 2640 |  | 
|  | 2641 |  | 
|  | 2642 | uint32_t | 
|  | 2643 | SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) | 
|  | 2644 | { | 
|  | 2645 | const uint32_t prev_size = sc_list.GetSize(); | 
|  | 2646 | if (resolve_scope & eSymbolContextCompUnit) | 
|  | 2647 | { | 
|  | 2648 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 2649 | if (debug_info) | 
|  | 2650 | { | 
|  | 2651 | uint32_t cu_idx; | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2652 | DWARFCompileUnit* dwarf_cu = NULL; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2653 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2654 | 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] | 2655 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2656 | CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 2657 | const bool full_match = file_spec.GetDirectory(); | 
|  | 2658 | 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] | 2659 | if (check_inlines || file_spec_matches_cu_file_spec) | 
|  | 2660 | { | 
|  | 2661 | SymbolContext sc (m_obj_file->GetModule()); | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2662 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2663 | if (sc.comp_unit) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2664 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2665 | uint32_t file_idx = UINT32_MAX; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2666 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2667 | // If we are looking for inline functions only and we don't | 
|  | 2668 | // find it in the support files, we are done. | 
|  | 2669 | if (check_inlines) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2670 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2671 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); | 
|  | 2672 | if (file_idx == UINT32_MAX) | 
|  | 2673 | continue; | 
|  | 2674 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2675 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2676 | if (line != 0) | 
|  | 2677 | { | 
|  | 2678 | LineTable *line_table = sc.comp_unit->GetLineTable(); | 
|  | 2679 |  | 
|  | 2680 | if (line_table != NULL && line != 0) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2681 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2682 | // We will have already looked up the file index if | 
|  | 2683 | // we are searching for inline entries. | 
|  | 2684 | if (!check_inlines) | 
|  | 2685 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2686 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2687 | if (file_idx != UINT32_MAX) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2688 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2689 | uint32_t found_line; | 
|  | 2690 | uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry); | 
|  | 2691 | found_line = sc.line_entry.line; | 
|  | 2692 |  | 
|  | 2693 | while (line_idx != UINT32_MAX) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2694 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2695 | sc.function = NULL; | 
|  | 2696 | sc.block = NULL; | 
|  | 2697 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2698 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2699 | const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress(); | 
|  | 2700 | if (file_vm_addr != LLDB_INVALID_ADDRESS) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2701 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2702 | DWARFDebugInfoEntry *function_die = NULL; | 
|  | 2703 | DWARFDebugInfoEntry *block_die = NULL; | 
|  | 2704 | 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] | 2705 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2706 | if (function_die != NULL) | 
|  | 2707 | { | 
|  | 2708 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); | 
|  | 2709 | if (sc.function == NULL) | 
|  | 2710 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die); | 
|  | 2711 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2712 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2713 | if (sc.function != NULL) | 
|  | 2714 | { | 
|  | 2715 | Block& block = sc.function->GetBlock (true); | 
|  | 2716 |  | 
|  | 2717 | if (block_die != NULL) | 
|  | 2718 | sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); | 
|  | 2719 | else | 
|  | 2720 | sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); | 
|  | 2721 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2722 | } | 
|  | 2723 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2724 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2725 | sc_list.Append(sc); | 
|  | 2726 | line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry); | 
|  | 2727 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2728 | } | 
|  | 2729 | } | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2730 | else if (file_spec_matches_cu_file_spec && !check_inlines) | 
|  | 2731 | { | 
|  | 2732 | // only append the context if we aren't looking for inline call sites | 
|  | 2733 | // by file and line and if the file spec matches that of the compile unit | 
|  | 2734 | sc_list.Append(sc); | 
|  | 2735 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2736 | } | 
|  | 2737 | else if (file_spec_matches_cu_file_spec && !check_inlines) | 
|  | 2738 | { | 
|  | 2739 | // only append the context if we aren't looking for inline call sites | 
|  | 2740 | // by file and line and if the file spec matches that of the compile unit | 
|  | 2741 | sc_list.Append(sc); | 
|  | 2742 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2743 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2744 | if (!check_inlines) | 
|  | 2745 | break; | 
|  | 2746 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2747 | } | 
|  | 2748 | } | 
|  | 2749 | } | 
|  | 2750 | } | 
|  | 2751 | return sc_list.GetSize() - prev_size; | 
|  | 2752 | } | 
|  | 2753 |  | 
|  | 2754 | void | 
|  | 2755 | SymbolFileDWARF::Index () | 
|  | 2756 | { | 
|  | 2757 | if (m_indexed) | 
|  | 2758 | return; | 
|  | 2759 | m_indexed = true; | 
|  | 2760 | Timer scoped_timer (__PRETTY_FUNCTION__, | 
|  | 2761 | "SymbolFileDWARF::Index (%s)", | 
|  | 2762 | GetObjectFile()->GetFileSpec().GetFilename().AsCString()); | 
|  | 2763 |  | 
|  | 2764 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 2765 | if (debug_info) | 
|  | 2766 | { | 
|  | 2767 | uint32_t cu_idx = 0; | 
|  | 2768 | const uint32_t num_compile_units = GetNumCompileUnits(); | 
|  | 2769 | for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) | 
|  | 2770 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2771 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2772 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2773 | bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2774 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2775 | dwarf_cu->Index (cu_idx, | 
|  | 2776 | m_function_basename_index, | 
|  | 2777 | m_function_fullname_index, | 
|  | 2778 | m_function_method_index, | 
|  | 2779 | m_function_selector_index, | 
|  | 2780 | m_objc_class_selectors_index, | 
|  | 2781 | m_global_index, | 
|  | 2782 | m_type_index, | 
|  | 2783 | m_namespace_index); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2784 |  | 
|  | 2785 | // Keep memory down by clearing DIEs if this generate function | 
|  | 2786 | // caused them to be parsed | 
|  | 2787 | if (clear_dies) | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2788 | dwarf_cu->ClearDIEs (true); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2789 | } | 
|  | 2790 |  | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2791 | m_function_basename_index.Finalize(); | 
|  | 2792 | m_function_fullname_index.Finalize(); | 
|  | 2793 | m_function_method_index.Finalize(); | 
|  | 2794 | m_function_selector_index.Finalize(); | 
|  | 2795 | m_objc_class_selectors_index.Finalize(); | 
|  | 2796 | m_global_index.Finalize(); | 
|  | 2797 | m_type_index.Finalize(); | 
|  | 2798 | m_namespace_index.Finalize(); | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2799 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2800 | #if defined (ENABLE_DEBUG_PRINTF) | 
| Greg Clayton | 7bd65b9 | 2011-02-09 23:39:34 +0000 | [diff] [blame] | 2801 | StreamFile s(stdout, false); | 
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 2802 | s.Printf ("DWARF index for '%s':", | 
|  | 2803 | GetObjectFile()->GetFileSpec().GetPath().c_str()); | 
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 2804 | s.Printf("\nFunction basenames:\n");    m_function_basename_index.Dump (&s); | 
|  | 2805 | s.Printf("\nFunction fullnames:\n");    m_function_fullname_index.Dump (&s); | 
|  | 2806 | s.Printf("\nFunction methods:\n");      m_function_method_index.Dump (&s); | 
|  | 2807 | s.Printf("\nFunction selectors:\n");    m_function_selector_index.Dump (&s); | 
|  | 2808 | s.Printf("\nObjective C class selectors:\n");    m_objc_class_selectors_index.Dump (&s); | 
|  | 2809 | s.Printf("\nGlobals and statics:\n");   m_global_index.Dump (&s); | 
| Greg Clayton | 69b0488 | 2010-10-15 02:03:22 +0000 | [diff] [blame] | 2810 | s.Printf("\nTypes:\n");                 m_type_index.Dump (&s); | 
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 2811 | s.Printf("\nNamepaces:\n");             m_namespace_index.Dump (&s); | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2812 | #endif | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2813 | } | 
|  | 2814 | } | 
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2815 |  | 
|  | 2816 | bool | 
|  | 2817 | SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl) | 
|  | 2818 | { | 
|  | 2819 | if (namespace_decl == NULL) | 
|  | 2820 | { | 
|  | 2821 | // Invalid namespace decl which means we aren't matching only things | 
|  | 2822 | // in this symbol file, so return true to indicate it matches this | 
|  | 2823 | // symbol file. | 
|  | 2824 | return true; | 
|  | 2825 | } | 
|  | 2826 |  | 
|  | 2827 | clang::ASTContext *namespace_ast = namespace_decl->GetASTContext(); | 
|  | 2828 |  | 
|  | 2829 | if (namespace_ast == NULL) | 
|  | 2830 | return true;    // No AST in the "namespace_decl", return true since it | 
|  | 2831 | // could then match any symbol file, including this one | 
|  | 2832 |  | 
|  | 2833 | if (namespace_ast == GetClangASTContext().getASTContext()) | 
|  | 2834 | return true;    // The ASTs match, return true | 
|  | 2835 |  | 
|  | 2836 | // The namespace AST was valid, and it does not match... | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2837 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Sean Callanan | c41e68b | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 2838 |  | 
|  | 2839 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2840 | GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file"); | 
| Sean Callanan | c41e68b | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 2841 |  | 
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2842 | return false; | 
|  | 2843 | } | 
|  | 2844 |  | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2845 | bool | 
|  | 2846 | SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl, | 
|  | 2847 | DWARFCompileUnit* cu, | 
|  | 2848 | const DWARFDebugInfoEntry* die) | 
|  | 2849 | { | 
|  | 2850 | // No namespace specified, so the answesr i | 
|  | 2851 | if (namespace_decl == NULL) | 
|  | 2852 | return true; | 
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2853 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2854 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2855 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2856 | const DWARFDebugInfoEntry *decl_ctx_die = NULL; | 
|  | 2857 | clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die); | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2858 | if (decl_ctx_die) | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2859 | { | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2860 | clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl(); | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2861 |  | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2862 | if (clang_namespace_decl) | 
|  | 2863 | { | 
|  | 2864 | if (decl_ctx_die->Tag() != DW_TAG_namespace) | 
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2865 | { | 
|  | 2866 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2867 | 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] | 2868 | return false; | 
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2869 | } | 
|  | 2870 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2871 | if (clang_namespace_decl == die_clang_decl_ctx) | 
|  | 2872 | return true; | 
|  | 2873 | else | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2874 | return false; | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2875 | } | 
|  | 2876 | else | 
|  | 2877 | { | 
|  | 2878 | // We have a namespace_decl that was not NULL but it contained | 
|  | 2879 | // a NULL "clang::NamespaceDecl", so this means the global namespace | 
|  | 2880 | // So as long the the contained decl context DIE isn't a namespace | 
|  | 2881 | // we should be ok. | 
|  | 2882 | if (decl_ctx_die->Tag() != DW_TAG_namespace) | 
|  | 2883 | return true; | 
|  | 2884 | } | 
|  | 2885 | } | 
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2886 |  | 
|  | 2887 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2888 | 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] | 2889 |  | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2890 | return false; | 
|  | 2891 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2892 | uint32_t | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2893 | 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] | 2894 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2895 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2896 |  | 
|  | 2897 | if (log) | 
|  | 2898 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2899 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2900 | "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)", | 
|  | 2901 | name.GetCString(), | 
|  | 2902 | namespace_decl, | 
|  | 2903 | append, | 
|  | 2904 | max_matches); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2905 | } | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2906 |  | 
|  | 2907 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) | 
|  | 2908 | return 0; | 
|  | 2909 |  | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2910 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 2911 | if (info == NULL) | 
|  | 2912 | return 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2913 |  | 
|  | 2914 | // If we aren't appending the results to this list, then clear the list | 
|  | 2915 | if (!append) | 
|  | 2916 | variables.Clear(); | 
|  | 2917 |  | 
|  | 2918 | // Remember how many variables are in the list before we search in case | 
|  | 2919 | // we are appending the results to a variable list. | 
|  | 2920 | const uint32_t original_size = variables.GetSize(); | 
|  | 2921 |  | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2922 | DIEArray die_offsets; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2923 |  | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2924 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2925 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2926 | if (m_apple_names_ap.get()) | 
|  | 2927 | { | 
|  | 2928 | const char *name_cstr = name.GetCString(); | 
|  | 2929 | const char *base_name_start; | 
|  | 2930 | const char *base_name_end = NULL; | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2931 |  | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2932 | if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end)) | 
|  | 2933 | base_name_start = name_cstr; | 
|  | 2934 |  | 
|  | 2935 | m_apple_names_ap->FindByName (base_name_start, die_offsets); | 
|  | 2936 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2937 | } | 
|  | 2938 | else | 
|  | 2939 | { | 
|  | 2940 | // Index the DWARF if we haven't already | 
|  | 2941 | if (!m_indexed) | 
|  | 2942 | Index (); | 
|  | 2943 |  | 
|  | 2944 | m_global_index.Find (name, die_offsets); | 
|  | 2945 | } | 
|  | 2946 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2947 | const size_t num_die_matches = die_offsets.size(); | 
|  | 2948 | if (num_die_matches) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2949 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2950 | SymbolContext sc; | 
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 2951 | sc.module_sp = m_obj_file->GetModule(); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2952 | assert (sc.module_sp); | 
|  | 2953 |  | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2954 | DWARFDebugInfo* debug_info = DebugInfo(); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2955 | DWARFCompileUnit* dwarf_cu = NULL; | 
|  | 2956 | const DWARFDebugInfoEntry* die = NULL; | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2957 | bool done = false; | 
|  | 2958 | for (size_t i=0; i<num_die_matches && !done; ++i) | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2959 | { | 
|  | 2960 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 2961 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2962 |  | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2963 | if (die) | 
|  | 2964 | { | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2965 | switch (die->Tag()) | 
|  | 2966 | { | 
|  | 2967 | default: | 
|  | 2968 | case DW_TAG_subprogram: | 
|  | 2969 | case DW_TAG_inlined_subroutine: | 
|  | 2970 | case DW_TAG_try_block: | 
|  | 2971 | case DW_TAG_catch_block: | 
|  | 2972 | break; | 
|  | 2973 |  | 
|  | 2974 | case DW_TAG_variable: | 
|  | 2975 | { | 
|  | 2976 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2977 |  | 
|  | 2978 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) | 
|  | 2979 | continue; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2980 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2981 | ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2982 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2983 | if (variables.GetSize() - original_size >= max_matches) | 
|  | 2984 | done = true; | 
|  | 2985 | } | 
|  | 2986 | break; | 
|  | 2987 | } | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2988 | } | 
|  | 2989 | else | 
|  | 2990 | { | 
|  | 2991 | if (m_using_apple_tables) | 
|  | 2992 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2993 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n", | 
|  | 2994 | die_offset, name.GetCString()); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2995 | } | 
|  | 2996 | } | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2997 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2998 | } | 
|  | 2999 |  | 
|  | 3000 | // Return the number of variable that were appended to the list | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3001 | const uint32_t num_matches = variables.GetSize() - original_size; | 
|  | 3002 | if (log && num_matches > 0) | 
|  | 3003 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3004 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3005 | "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u", | 
|  | 3006 | name.GetCString(), | 
|  | 3007 | namespace_decl, | 
|  | 3008 | append, | 
|  | 3009 | max_matches, | 
|  | 3010 | num_matches); | 
|  | 3011 | } | 
|  | 3012 | return num_matches; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3013 | } | 
|  | 3014 |  | 
|  | 3015 | uint32_t | 
|  | 3016 | SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables) | 
|  | 3017 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3018 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3019 |  | 
|  | 3020 | if (log) | 
|  | 3021 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3022 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3023 | "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)", | 
|  | 3024 | regex.GetText(), | 
|  | 3025 | append, | 
|  | 3026 | max_matches); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3027 | } | 
|  | 3028 |  | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3029 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 3030 | if (info == NULL) | 
|  | 3031 | return 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3032 |  | 
|  | 3033 | // If we aren't appending the results to this list, then clear the list | 
|  | 3034 | if (!append) | 
|  | 3035 | variables.Clear(); | 
|  | 3036 |  | 
|  | 3037 | // Remember how many variables are in the list before we search in case | 
|  | 3038 | // we are appending the results to a variable list. | 
|  | 3039 | const uint32_t original_size = variables.GetSize(); | 
|  | 3040 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3041 | DIEArray die_offsets; | 
|  | 3042 |  | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3043 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3044 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3045 | if (m_apple_names_ap.get()) | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3046 | { | 
|  | 3047 | DWARFMappedHash::DIEInfoArray hash_data_array; | 
|  | 3048 | if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) | 
|  | 3049 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); | 
|  | 3050 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3051 | } | 
|  | 3052 | else | 
|  | 3053 | { | 
|  | 3054 | // Index the DWARF if we haven't already | 
|  | 3055 | if (!m_indexed) | 
|  | 3056 | Index (); | 
|  | 3057 |  | 
|  | 3058 | m_global_index.Find (regex, die_offsets); | 
|  | 3059 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3060 |  | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3061 | SymbolContext sc; | 
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 3062 | sc.module_sp = m_obj_file->GetModule(); | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3063 | assert (sc.module_sp); | 
|  | 3064 |  | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3065 | DWARFCompileUnit* dwarf_cu = NULL; | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3066 | const DWARFDebugInfoEntry* die = NULL; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3067 | const size_t num_matches = die_offsets.size(); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3068 | if (num_matches) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3069 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3070 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 3071 | for (size_t i=0; i<num_matches; ++i) | 
|  | 3072 | { | 
|  | 3073 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 3074 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3075 |  | 
|  | 3076 | if (die) | 
|  | 3077 | { | 
|  | 3078 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3079 |  | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3080 | ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3081 |  | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3082 | if (variables.GetSize() - original_size >= max_matches) | 
|  | 3083 | break; | 
|  | 3084 | } | 
|  | 3085 | else | 
|  | 3086 | { | 
|  | 3087 | if (m_using_apple_tables) | 
|  | 3088 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3089 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n", | 
|  | 3090 | die_offset, regex.GetText()); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3091 | } | 
|  | 3092 | } | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3093 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3094 | } | 
|  | 3095 |  | 
|  | 3096 | // Return the number of variable that were appended to the list | 
|  | 3097 | return variables.GetSize() - original_size; | 
|  | 3098 | } | 
|  | 3099 |  | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3100 |  | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3101 | bool | 
|  | 3102 | SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset, | 
|  | 3103 | DWARFCompileUnit *&dwarf_cu, | 
|  | 3104 | SymbolContextList& sc_list) | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3105 | { | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3106 | const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
|  | 3107 | return ResolveFunction (dwarf_cu, die, sc_list); | 
|  | 3108 | } | 
|  | 3109 |  | 
|  | 3110 |  | 
|  | 3111 | bool | 
|  | 3112 | SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu, | 
|  | 3113 | const DWARFDebugInfoEntry *die, | 
|  | 3114 | SymbolContextList& sc_list) | 
|  | 3115 | { | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3116 | SymbolContext sc; | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3117 |  | 
|  | 3118 | if (die == NULL) | 
|  | 3119 | return false; | 
|  | 3120 |  | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3121 | // If we were passed a die that is not a function, just return false... | 
|  | 3122 | if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine) | 
|  | 3123 | return false; | 
|  | 3124 |  | 
|  | 3125 | const DWARFDebugInfoEntry* inlined_die = NULL; | 
|  | 3126 | if (die->Tag() == DW_TAG_inlined_subroutine) | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3127 | { | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3128 | inlined_die = die; | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3129 |  | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3130 | while ((die = die->GetParent()) != NULL) | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3131 | { | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3132 | if (die->Tag() == DW_TAG_subprogram) | 
|  | 3133 | break; | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3134 | } | 
|  | 3135 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3136 | assert (die->Tag() == DW_TAG_subprogram); | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3137 | if (GetFunction (cu, die, sc)) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3138 | { | 
|  | 3139 | Address addr; | 
|  | 3140 | // Parse all blocks if needed | 
|  | 3141 | if (inlined_die) | 
|  | 3142 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 3143 | sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset())); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3144 | assert (sc.block != NULL); | 
|  | 3145 | if (sc.block->GetStartAddress (addr) == false) | 
|  | 3146 | addr.Clear(); | 
|  | 3147 | } | 
|  | 3148 | else | 
|  | 3149 | { | 
|  | 3150 | sc.block = NULL; | 
|  | 3151 | addr = sc.function->GetAddressRange().GetBaseAddress(); | 
|  | 3152 | } | 
|  | 3153 |  | 
|  | 3154 | if (addr.IsValid()) | 
|  | 3155 | { | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3156 | sc_list.Append(sc); | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3157 | return true; | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3158 | } | 
|  | 3159 | } | 
|  | 3160 |  | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3161 | return false; | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3162 | } | 
|  | 3163 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3164 | void | 
|  | 3165 | SymbolFileDWARF::FindFunctions (const ConstString &name, | 
|  | 3166 | const NameToDIE &name_to_die, | 
|  | 3167 | SymbolContextList& sc_list) | 
|  | 3168 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3169 | DIEArray die_offsets; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3170 | if (name_to_die.Find (name, die_offsets)) | 
|  | 3171 | { | 
|  | 3172 | ParseFunctions (die_offsets, sc_list); | 
|  | 3173 | } | 
|  | 3174 | } | 
|  | 3175 |  | 
|  | 3176 |  | 
|  | 3177 | void | 
|  | 3178 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, | 
|  | 3179 | const NameToDIE &name_to_die, | 
|  | 3180 | SymbolContextList& sc_list) | 
|  | 3181 | { | 
|  | 3182 | DIEArray die_offsets; | 
|  | 3183 | if (name_to_die.Find (regex, die_offsets)) | 
|  | 3184 | { | 
|  | 3185 | ParseFunctions (die_offsets, sc_list); | 
|  | 3186 | } | 
|  | 3187 | } | 
|  | 3188 |  | 
|  | 3189 |  | 
|  | 3190 | void | 
|  | 3191 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, | 
|  | 3192 | const DWARFMappedHash::MemoryTable &memory_table, | 
|  | 3193 | SymbolContextList& sc_list) | 
|  | 3194 | { | 
|  | 3195 | DIEArray die_offsets; | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3196 | DWARFMappedHash::DIEInfoArray hash_data_array; | 
|  | 3197 | if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3198 | { | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3199 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3200 | ParseFunctions (die_offsets, sc_list); | 
|  | 3201 | } | 
|  | 3202 | } | 
|  | 3203 |  | 
|  | 3204 | void | 
|  | 3205 | SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets, | 
|  | 3206 | SymbolContextList& sc_list) | 
|  | 3207 | { | 
|  | 3208 | const size_t num_matches = die_offsets.size(); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3209 | if (num_matches) | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3210 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3211 | SymbolContext sc; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3212 |  | 
|  | 3213 | DWARFCompileUnit* dwarf_cu = NULL; | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3214 | for (size_t i=0; i<num_matches; ++i) | 
| Greg Clayton | d7e0546 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 3215 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3216 | const dw_offset_t die_offset = die_offsets[i]; | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3217 | ResolveFunction (die_offset, dwarf_cu, sc_list); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3218 | } | 
|  | 3219 | } | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3220 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3221 |  | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3222 | bool | 
|  | 3223 | SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die, | 
|  | 3224 | const DWARFCompileUnit *dwarf_cu, | 
|  | 3225 | uint32_t name_type_mask, | 
|  | 3226 | const char *partial_name, | 
|  | 3227 | const char *base_name_start, | 
|  | 3228 | const char *base_name_end) | 
|  | 3229 | { | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3230 | // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes: | 
|  | 3231 | if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3232 | { | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 3233 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset()); | 
|  | 3234 | if (!containing_decl_ctx) | 
|  | 3235 | return false; | 
|  | 3236 |  | 
|  | 3237 | bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()); | 
|  | 3238 |  | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3239 | if (name_type_mask == eFunctionNameTypeMethod) | 
|  | 3240 | { | 
|  | 3241 | if (is_cxx_method == false) | 
|  | 3242 | return false; | 
|  | 3243 | } | 
|  | 3244 |  | 
|  | 3245 | if (name_type_mask == eFunctionNameTypeBase) | 
|  | 3246 | { | 
|  | 3247 | if (is_cxx_method == true) | 
|  | 3248 | return false; | 
|  | 3249 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3250 | } | 
|  | 3251 |  | 
|  | 3252 | // Now we need to check whether the name we got back for this type matches the extra specifications | 
|  | 3253 | // that were in the name we're looking up: | 
|  | 3254 | if (base_name_start != partial_name || *base_name_end != '\0') | 
|  | 3255 | { | 
|  | 3256 | // First see if the stuff to the left matches the full name.  To do that let's see if | 
|  | 3257 | // we can pull out the mips linkage name attribute: | 
|  | 3258 |  | 
|  | 3259 | Mangled best_name; | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3260 | DWARFDebugInfoEntry::Attributes attributes; | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3261 | DWARFFormValue form_value; | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3262 | die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
|  | 3263 | uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name); | 
| Greg Clayton | 7141554 | 2012-12-08 00:24:40 +0000 | [diff] [blame] | 3264 | if (idx == UINT32_MAX) | 
|  | 3265 | idx = attributes.FindAttributeIndex(DW_AT_linkage_name); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3266 | if (idx != UINT32_MAX) | 
|  | 3267 | { | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3268 | if (attributes.ExtractFormValueAtIndex(this, idx, form_value)) | 
|  | 3269 | { | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3270 | const char *mangled_name = form_value.AsCString(&get_debug_str_data()); | 
|  | 3271 | if (mangled_name) | 
|  | 3272 | best_name.SetValue (ConstString(mangled_name), true); | 
|  | 3273 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3274 | } | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3275 |  | 
|  | 3276 | if (!best_name) | 
|  | 3277 | { | 
|  | 3278 | idx = attributes.FindAttributeIndex(DW_AT_name); | 
|  | 3279 | if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value)) | 
|  | 3280 | { | 
|  | 3281 | const char *name = form_value.AsCString(&get_debug_str_data()); | 
|  | 3282 | best_name.SetValue (ConstString(name), false); | 
|  | 3283 | } | 
|  | 3284 | } | 
|  | 3285 |  | 
|  | 3286 | if (best_name.GetDemangledName()) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3287 | { | 
|  | 3288 | const char *demangled = best_name.GetDemangledName().GetCString(); | 
|  | 3289 | if (demangled) | 
|  | 3290 | { | 
|  | 3291 | std::string name_no_parens(partial_name, base_name_end - partial_name); | 
| Jim Ingham | 85c13d7 | 2012-03-02 02:24:42 +0000 | [diff] [blame] | 3292 | const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str()); | 
|  | 3293 | if (partial_in_demangled == NULL) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3294 | return false; | 
| Jim Ingham | 85c13d7 | 2012-03-02 02:24:42 +0000 | [diff] [blame] | 3295 | else | 
|  | 3296 | { | 
|  | 3297 | // Sort out the case where our name is something like "Process::Destroy" and the match is | 
|  | 3298 | // "SBProcess::Destroy" - that shouldn't be a match.  We should really always match on | 
|  | 3299 | // namespace boundaries... | 
|  | 3300 |  | 
|  | 3301 | if (partial_name[0] == ':'  && partial_name[1] == ':') | 
|  | 3302 | { | 
|  | 3303 | // The partial name was already on a namespace boundary so all matches are good. | 
|  | 3304 | return true; | 
|  | 3305 | } | 
|  | 3306 | else if (partial_in_demangled == demangled) | 
|  | 3307 | { | 
|  | 3308 | // They both start the same, so this is an good match. | 
|  | 3309 | return true; | 
|  | 3310 | } | 
|  | 3311 | else | 
|  | 3312 | { | 
|  | 3313 | if (partial_in_demangled - demangled == 1) | 
|  | 3314 | { | 
|  | 3315 | // Only one character difference, can't be a namespace boundary... | 
|  | 3316 | return false; | 
|  | 3317 | } | 
|  | 3318 | else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':') | 
|  | 3319 | { | 
|  | 3320 | // We are on a namespace boundary, so this is also good. | 
|  | 3321 | return true; | 
|  | 3322 | } | 
|  | 3323 | else | 
|  | 3324 | return false; | 
|  | 3325 | } | 
|  | 3326 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3327 | } | 
|  | 3328 | } | 
|  | 3329 | } | 
|  | 3330 |  | 
|  | 3331 | return true; | 
|  | 3332 | } | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3333 |  | 
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3334 | uint32_t | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3335 | SymbolFileDWARF::FindFunctions (const ConstString &name, | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3336 | const lldb_private::ClangNamespaceDecl *namespace_decl, | 
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3337 | uint32_t name_type_mask, | 
|  | 3338 | bool include_inlines, | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3339 | bool append, | 
|  | 3340 | SymbolContextList& sc_list) | 
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3341 | { | 
|  | 3342 | Timer scoped_timer (__PRETTY_FUNCTION__, | 
|  | 3343 | "SymbolFileDWARF::FindFunctions (name = '%s')", | 
|  | 3344 | name.AsCString()); | 
|  | 3345 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3346 | // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup() | 
|  | 3347 | assert ((name_type_mask & eFunctionNameTypeAuto) == 0); | 
|  | 3348 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3349 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3350 |  | 
|  | 3351 | if (log) | 
|  | 3352 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3353 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3354 | "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)", | 
|  | 3355 | name.GetCString(), | 
|  | 3356 | name_type_mask, | 
|  | 3357 | append); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3358 | } | 
|  | 3359 |  | 
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3360 | // If we aren't appending the results to this list, then clear the list | 
|  | 3361 | if (!append) | 
|  | 3362 | sc_list.Clear(); | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3363 |  | 
|  | 3364 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) | 
|  | 3365 | return 0; | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3366 |  | 
|  | 3367 | // If name is empty then we won't find anything. | 
|  | 3368 | if (name.IsEmpty()) | 
|  | 3369 | return 0; | 
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3370 |  | 
|  | 3371 | // Remember how many sc_list are in the list before we search in case | 
|  | 3372 | // we are appending the results to a variable list. | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3373 |  | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3374 | const char *name_cstr = name.GetCString(); | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3375 |  | 
|  | 3376 | const uint32_t original_size = sc_list.GetSize(); | 
|  | 3377 |  | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3378 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 3379 | if (info == NULL) | 
|  | 3380 | return 0; | 
|  | 3381 |  | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3382 | DWARFCompileUnit *dwarf_cu = NULL; | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3383 | std::set<const DWARFDebugInfoEntry *> resolved_dies; | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3384 | if (m_using_apple_tables) | 
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 3385 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3386 | if (m_apple_names_ap.get()) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3387 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3388 |  | 
|  | 3389 | DIEArray die_offsets; | 
|  | 3390 |  | 
|  | 3391 | uint32_t num_matches = 0; | 
|  | 3392 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3393 | if (name_type_mask & eFunctionNameTypeFull) | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3394 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3395 | // If they asked for the full name, match what they typed.  At some point we may | 
|  | 3396 | // want to canonicalize this (strip double spaces, etc.  For now, we just add all the | 
|  | 3397 | // dies that we find by exact match. | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3398 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3399 | for (uint32_t i = 0; i < num_matches; i++) | 
|  | 3400 | { | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3401 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 3402 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3403 | if (die) | 
|  | 3404 | { | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3405 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) | 
|  | 3406 | continue; | 
|  | 3407 |  | 
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3408 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) | 
|  | 3409 | continue; | 
|  | 3410 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3411 | if (resolved_dies.find(die) == resolved_dies.end()) | 
|  | 3412 | { | 
|  | 3413 | if (ResolveFunction (dwarf_cu, die, sc_list)) | 
|  | 3414 | resolved_dies.insert(die); | 
|  | 3415 | } | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3416 | } | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3417 | else | 
|  | 3418 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3419 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", | 
|  | 3420 | die_offset, name_cstr); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3421 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3422 | } | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3423 | } | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3424 |  | 
|  | 3425 | if (name_type_mask & eFunctionNameTypeSelector) | 
|  | 3426 | { | 
|  | 3427 | if (namespace_decl && *namespace_decl) | 
|  | 3428 | return 0; // no selectors in namespaces | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3429 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3430 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); | 
|  | 3431 | // Now make sure these are actually ObjC methods.  In this case we can simply look up the name, | 
|  | 3432 | // and if it is an ObjC method name, we're good. | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3433 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3434 | for (uint32_t i = 0; i < num_matches; i++) | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3435 | { | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3436 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 3437 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
|  | 3438 | if (die) | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3439 | { | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3440 | const char *die_name = die->GetName(this, dwarf_cu); | 
|  | 3441 | if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name)) | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3442 | { | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3443 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) | 
|  | 3444 | continue; | 
|  | 3445 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3446 | if (resolved_dies.find(die) == resolved_dies.end()) | 
|  | 3447 | { | 
|  | 3448 | if (ResolveFunction (dwarf_cu, die, sc_list)) | 
|  | 3449 | resolved_dies.insert(die); | 
|  | 3450 | } | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3451 | } | 
|  | 3452 | } | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3453 | else | 
|  | 3454 | { | 
|  | 3455 | GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", | 
|  | 3456 | die_offset, name_cstr); | 
|  | 3457 | } | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3458 | } | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3459 | die_offsets.clear(); | 
|  | 3460 | } | 
|  | 3461 |  | 
|  | 3462 | if (((name_type_mask & eFunctionNameTypeMethod) && !namespace_decl) || name_type_mask & eFunctionNameTypeBase) | 
|  | 3463 | { | 
|  | 3464 | // The apple_names table stores just the "base name" of C++ methods in the table.  So we have to | 
|  | 3465 | // extract the base name, look that up, and if there is any other information in the name we were | 
|  | 3466 | // passed in we have to post-filter based on that. | 
|  | 3467 |  | 
|  | 3468 | // FIXME: Arrange the logic above so that we don't calculate the base name twice: | 
|  | 3469 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); | 
|  | 3470 |  | 
|  | 3471 | for (uint32_t i = 0; i < num_matches; i++) | 
|  | 3472 | { | 
|  | 3473 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 3474 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
|  | 3475 | if (die) | 
|  | 3476 | { | 
|  | 3477 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) | 
|  | 3478 | continue; | 
|  | 3479 |  | 
|  | 3480 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) | 
|  | 3481 | continue; | 
|  | 3482 |  | 
|  | 3483 | // If we get to here, the die is good, and we should add it: | 
|  | 3484 | if (resolved_dies.find(die) == resolved_dies.end()) | 
|  | 3485 | if (ResolveFunction (dwarf_cu, die, sc_list)) | 
|  | 3486 | { | 
|  | 3487 | bool keep_die = true; | 
|  | 3488 | if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod)) | 
|  | 3489 | { | 
|  | 3490 | // We are looking for either basenames or methods, so we need to | 
|  | 3491 | // trim out the ones we won't want by looking at the type | 
|  | 3492 | SymbolContext sc; | 
|  | 3493 | if (sc_list.GetLastContext(sc)) | 
|  | 3494 | { | 
|  | 3495 | if (sc.block) | 
|  | 3496 | { | 
|  | 3497 | // We have an inlined function | 
|  | 3498 | } | 
|  | 3499 | else if (sc.function) | 
|  | 3500 | { | 
|  | 3501 | Type *type = sc.function->GetType(); | 
|  | 3502 |  | 
|  | 3503 | clang::DeclContext* decl_ctx = GetClangDeclContextContainingTypeUID (type->GetID()); | 
|  | 3504 | if (decl_ctx->isRecord()) | 
|  | 3505 | { | 
|  | 3506 | if (name_type_mask & eFunctionNameTypeBase) | 
|  | 3507 | { | 
|  | 3508 | sc_list.RemoveContextAtIndex(sc_list.GetSize()-1); | 
|  | 3509 | keep_die = false; | 
|  | 3510 | } | 
|  | 3511 | } | 
|  | 3512 | else | 
|  | 3513 | { | 
|  | 3514 | if (name_type_mask & eFunctionNameTypeMethod) | 
|  | 3515 | { | 
|  | 3516 | sc_list.RemoveContextAtIndex(sc_list.GetSize()-1); | 
|  | 3517 | keep_die = false; | 
|  | 3518 | } | 
|  | 3519 | } | 
|  | 3520 | } | 
|  | 3521 | } | 
|  | 3522 | } | 
|  | 3523 | if (keep_die) | 
|  | 3524 | resolved_dies.insert(die); | 
|  | 3525 | } | 
|  | 3526 | } | 
|  | 3527 | else | 
|  | 3528 | { | 
|  | 3529 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", | 
|  | 3530 | die_offset, name_cstr); | 
|  | 3531 | } | 
|  | 3532 | } | 
|  | 3533 | die_offsets.clear(); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3534 | } | 
|  | 3535 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3536 | } | 
|  | 3537 | else | 
|  | 3538 | { | 
|  | 3539 |  | 
|  | 3540 | // Index the DWARF if we haven't already | 
|  | 3541 | if (!m_indexed) | 
|  | 3542 | Index (); | 
|  | 3543 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3544 | if (name_type_mask & eFunctionNameTypeFull) | 
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame^] | 3545 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3546 | FindFunctions (name, m_function_fullname_index, sc_list); | 
|  | 3547 |  | 
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame^] | 3548 | // Temporary workaround for global/anonymous namespace functions on linux | 
|  | 3549 | #if defined (__linux__) | 
|  | 3550 | // If we didn't find any functions in the global namespace try | 
|  | 3551 | // looking in the basename index but ignore any returned | 
|  | 3552 | // functions that have a namespace (ie. mangled names starting with | 
|  | 3553 | // '_ZN') but keep functions which have an anonymous namespace | 
|  | 3554 | if (sc_list.GetSize() == 0) | 
|  | 3555 | { | 
|  | 3556 | SymbolContextList temp_sc_list; | 
|  | 3557 | FindFunctions (name, m_function_basename_index, temp_sc_list); | 
|  | 3558 | if (!namespace_decl) | 
|  | 3559 | { | 
|  | 3560 | SymbolContext sc; | 
|  | 3561 | for (uint32_t i = 0; i < temp_sc_list.GetSize(); i++) | 
|  | 3562 | { | 
|  | 3563 | if (temp_sc_list.GetContextAtIndex(i, sc)) | 
|  | 3564 | { | 
|  | 3565 | ConstString func_name = sc.GetFunctionName(Mangled::ePreferDemangled); | 
|  | 3566 | if (!strncmp(name.GetCString(), "_ZN", 3) || | 
|  | 3567 | strncmp(name.GetCString(), "(anonymous namespace)", 21)) | 
|  | 3568 | { | 
|  | 3569 | sc_list.Append(sc); | 
|  | 3570 | } | 
|  | 3571 | } | 
|  | 3572 | } | 
|  | 3573 | } | 
|  | 3574 | } | 
|  | 3575 | #endif | 
|  | 3576 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3577 | DIEArray die_offsets; | 
|  | 3578 | DWARFCompileUnit *dwarf_cu = NULL; | 
|  | 3579 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3580 | if (name_type_mask & eFunctionNameTypeBase) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3581 | { | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3582 | uint32_t num_base = m_function_basename_index.Find(name, die_offsets); | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3583 | for (uint32_t i = 0; i < num_base; i++) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3584 | { | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3585 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); | 
|  | 3586 | if (die) | 
|  | 3587 | { | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3588 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) | 
|  | 3589 | continue; | 
|  | 3590 |  | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3591 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) | 
|  | 3592 | continue; | 
|  | 3593 |  | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3594 | // 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] | 3595 | if (resolved_dies.find(die) == resolved_dies.end()) | 
|  | 3596 | { | 
|  | 3597 | if (ResolveFunction (dwarf_cu, die, sc_list)) | 
|  | 3598 | resolved_dies.insert(die); | 
|  | 3599 | } | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3600 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3601 | } | 
|  | 3602 | die_offsets.clear(); | 
|  | 3603 | } | 
|  | 3604 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3605 | if (name_type_mask & eFunctionNameTypeMethod) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3606 | { | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3607 | if (namespace_decl && *namespace_decl) | 
|  | 3608 | return 0; // no methods in namespaces | 
|  | 3609 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3610 | uint32_t num_base = m_function_method_index.Find(name, die_offsets); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3611 | { | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3612 | for (uint32_t i = 0; i < num_base; i++) | 
|  | 3613 | { | 
|  | 3614 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); | 
|  | 3615 | if (die) | 
|  | 3616 | { | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3617 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) | 
|  | 3618 | continue; | 
|  | 3619 |  | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3620 | // 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] | 3621 | if (resolved_dies.find(die) == resolved_dies.end()) | 
|  | 3622 | { | 
|  | 3623 | if (ResolveFunction (dwarf_cu, die, sc_list)) | 
|  | 3624 | resolved_dies.insert(die); | 
|  | 3625 | } | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3626 | } | 
|  | 3627 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3628 | } | 
|  | 3629 | die_offsets.clear(); | 
|  | 3630 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3631 |  | 
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3632 | if ((name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl)) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3633 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3634 | FindFunctions (name, m_function_selector_index, sc_list); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3635 | } | 
|  | 3636 |  | 
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 3637 | } | 
|  | 3638 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3639 | // Return the number of variable that were appended to the list | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3640 | const uint32_t num_matches = sc_list.GetSize() - original_size; | 
|  | 3641 |  | 
|  | 3642 | if (log && num_matches > 0) | 
|  | 3643 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3644 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3645 | "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list) => %u", | 
|  | 3646 | name.GetCString(), | 
|  | 3647 | name_type_mask, | 
|  | 3648 | append, | 
|  | 3649 | num_matches); | 
|  | 3650 | } | 
|  | 3651 | return num_matches; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3652 | } | 
|  | 3653 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3654 | uint32_t | 
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3655 | 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] | 3656 | { | 
|  | 3657 | Timer scoped_timer (__PRETTY_FUNCTION__, | 
|  | 3658 | "SymbolFileDWARF::FindFunctions (regex = '%s')", | 
|  | 3659 | regex.GetText()); | 
|  | 3660 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3661 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3662 |  | 
|  | 3663 | if (log) | 
|  | 3664 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3665 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3666 | "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)", | 
|  | 3667 | regex.GetText(), | 
|  | 3668 | append); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3669 | } | 
|  | 3670 |  | 
|  | 3671 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3672 | // If we aren't appending the results to this list, then clear the list | 
|  | 3673 | if (!append) | 
|  | 3674 | sc_list.Clear(); | 
|  | 3675 |  | 
|  | 3676 | // Remember how many sc_list are in the list before we search in case | 
|  | 3677 | // we are appending the results to a variable list. | 
|  | 3678 | uint32_t original_size = sc_list.GetSize(); | 
|  | 3679 |  | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3680 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3681 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3682 | if (m_apple_names_ap.get()) | 
|  | 3683 | FindFunctions (regex, *m_apple_names_ap, sc_list); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3684 | } | 
|  | 3685 | else | 
|  | 3686 | { | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3687 | // Index the DWARF if we haven't already | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3688 | if (!m_indexed) | 
|  | 3689 | Index (); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3690 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3691 | FindFunctions (regex, m_function_basename_index, sc_list); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3692 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3693 | FindFunctions (regex, m_function_fullname_index, sc_list); | 
|  | 3694 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3695 |  | 
|  | 3696 | // Return the number of variable that were appended to the list | 
|  | 3697 | return sc_list.GetSize() - original_size; | 
|  | 3698 | } | 
| Jim Ingham | 318c9f2 | 2011-08-26 19:44:13 +0000 | [diff] [blame] | 3699 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3700 | uint32_t | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3701 | SymbolFileDWARF::FindTypes (const SymbolContext& sc, | 
|  | 3702 | const ConstString &name, | 
|  | 3703 | const lldb_private::ClangNamespaceDecl *namespace_decl, | 
|  | 3704 | bool append, | 
|  | 3705 | uint32_t max_matches, | 
|  | 3706 | TypeList& types) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3707 | { | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3708 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 3709 | if (info == NULL) | 
|  | 3710 | return 0; | 
|  | 3711 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3712 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3713 |  | 
|  | 3714 | if (log) | 
|  | 3715 | { | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3716 | if (namespace_decl) | 
|  | 3717 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3718 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3719 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)", | 
|  | 3720 | name.GetCString(), | 
|  | 3721 | namespace_decl->GetNamespaceDecl(), | 
|  | 3722 | namespace_decl->GetQualifiedName().c_str(), | 
|  | 3723 | append, | 
|  | 3724 | max_matches); | 
|  | 3725 | } | 
|  | 3726 | else | 
|  | 3727 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3728 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3729 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)", | 
|  | 3730 | name.GetCString(), | 
|  | 3731 | append, | 
|  | 3732 | max_matches); | 
|  | 3733 | } | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3734 | } | 
|  | 3735 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3736 | // If we aren't appending the results to this list, then clear the list | 
|  | 3737 | if (!append) | 
|  | 3738 | types.Clear(); | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3739 |  | 
|  | 3740 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) | 
|  | 3741 | return 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3742 |  | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3743 | DIEArray die_offsets; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3744 |  | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3745 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3746 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3747 | if (m_apple_types_ap.get()) | 
|  | 3748 | { | 
|  | 3749 | const char *name_cstr = name.GetCString(); | 
|  | 3750 | m_apple_types_ap->FindByName (name_cstr, die_offsets); | 
|  | 3751 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3752 | } | 
|  | 3753 | else | 
|  | 3754 | { | 
|  | 3755 | if (!m_indexed) | 
|  | 3756 | Index (); | 
|  | 3757 |  | 
|  | 3758 | m_type_index.Find (name, die_offsets); | 
|  | 3759 | } | 
|  | 3760 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3761 | const size_t num_die_matches = die_offsets.size(); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3762 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3763 | if (num_die_matches) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3764 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3765 | const uint32_t initial_types_size = types.GetSize(); | 
|  | 3766 | DWARFCompileUnit* dwarf_cu = NULL; | 
|  | 3767 | const DWARFDebugInfoEntry* die = NULL; | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3768 | DWARFDebugInfo* debug_info = DebugInfo(); | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3769 | for (size_t i=0; i<num_die_matches; ++i) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3770 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3771 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 3772 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
|  | 3773 |  | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3774 | if (die) | 
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 3775 | { | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3776 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) | 
|  | 3777 | continue; | 
|  | 3778 |  | 
|  | 3779 | Type *matching_type = ResolveType (dwarf_cu, die); | 
|  | 3780 | if (matching_type) | 
|  | 3781 | { | 
|  | 3782 | // 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] | 3783 | types.InsertUnique (matching_type->shared_from_this()); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3784 | if (types.GetSize() >= max_matches) | 
|  | 3785 | break; | 
|  | 3786 | } | 
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 3787 | } | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3788 | else | 
|  | 3789 | { | 
|  | 3790 | if (m_using_apple_tables) | 
|  | 3791 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3792 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", | 
|  | 3793 | die_offset, name.GetCString()); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3794 | } | 
|  | 3795 | } | 
|  | 3796 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3797 | } | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3798 | const uint32_t num_matches = types.GetSize() - initial_types_size; | 
|  | 3799 | if (log && num_matches) | 
|  | 3800 | { | 
|  | 3801 | if (namespace_decl) | 
|  | 3802 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3803 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3804 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u", | 
|  | 3805 | name.GetCString(), | 
|  | 3806 | namespace_decl->GetNamespaceDecl(), | 
|  | 3807 | namespace_decl->GetQualifiedName().c_str(), | 
|  | 3808 | append, | 
|  | 3809 | max_matches, | 
|  | 3810 | num_matches); | 
|  | 3811 | } | 
|  | 3812 | else | 
|  | 3813 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3814 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3815 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u", | 
|  | 3816 | name.GetCString(), | 
|  | 3817 | append, | 
|  | 3818 | max_matches, | 
|  | 3819 | num_matches); | 
|  | 3820 | } | 
|  | 3821 | } | 
|  | 3822 | return num_matches; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3823 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3824 | return 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3825 | } | 
|  | 3826 |  | 
|  | 3827 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3828 | ClangNamespaceDecl | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3829 | SymbolFileDWARF::FindNamespace (const SymbolContext& sc, | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3830 | const ConstString &name, | 
|  | 3831 | const lldb_private::ClangNamespaceDecl *parent_namespace_decl) | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3832 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3833 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3834 |  | 
|  | 3835 | if (log) | 
|  | 3836 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3837 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3838 | "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")", | 
|  | 3839 | name.GetCString()); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3840 | } | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3841 |  | 
|  | 3842 | if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl)) | 
|  | 3843 | return ClangNamespaceDecl(); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3844 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3845 | ClangNamespaceDecl namespace_decl; | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3846 | DWARFDebugInfo* info = DebugInfo(); | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3847 | if (info) | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3848 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3849 | DIEArray die_offsets; | 
|  | 3850 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3851 | // Index if we already haven't to make sure the compile units | 
|  | 3852 | // get indexed and make their global DIE index list | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3853 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3854 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3855 | if (m_apple_namespaces_ap.get()) | 
|  | 3856 | { | 
|  | 3857 | const char *name_cstr = name.GetCString(); | 
|  | 3858 | m_apple_namespaces_ap->FindByName (name_cstr, die_offsets); | 
|  | 3859 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3860 | } | 
|  | 3861 | else | 
|  | 3862 | { | 
|  | 3863 | if (!m_indexed) | 
|  | 3864 | Index (); | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3865 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3866 | m_namespace_index.Find (name, die_offsets); | 
|  | 3867 | } | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3868 |  | 
|  | 3869 | DWARFCompileUnit* dwarf_cu = NULL; | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3870 | const DWARFDebugInfoEntry* die = NULL; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3871 | const size_t num_matches = die_offsets.size(); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3872 | if (num_matches) | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3873 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3874 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 3875 | for (size_t i=0; i<num_matches; ++i) | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3876 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3877 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 3878 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3879 |  | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3880 | if (die) | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3881 | { | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3882 | if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die)) | 
|  | 3883 | continue; | 
|  | 3884 |  | 
|  | 3885 | clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die); | 
|  | 3886 | if (clang_namespace_decl) | 
|  | 3887 | { | 
|  | 3888 | namespace_decl.SetASTContext (GetClangASTContext().getASTContext()); | 
|  | 3889 | namespace_decl.SetNamespaceDecl (clang_namespace_decl); | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3890 | break; | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3891 | } | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3892 | } | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3893 | else | 
|  | 3894 | { | 
|  | 3895 | if (m_using_apple_tables) | 
|  | 3896 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3897 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n", | 
|  | 3898 | die_offset, name.GetCString()); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3899 | } | 
|  | 3900 | } | 
|  | 3901 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3902 | } | 
|  | 3903 | } | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3904 | } | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3905 | if (log && namespace_decl.GetNamespaceDecl()) | 
|  | 3906 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3907 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3908 | "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"", | 
|  | 3909 | name.GetCString(), | 
|  | 3910 | namespace_decl.GetNamespaceDecl(), | 
|  | 3911 | namespace_decl.GetQualifiedName().c_str()); | 
|  | 3912 | } | 
|  | 3913 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3914 | return namespace_decl; | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3915 | } | 
|  | 3916 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3917 | uint32_t | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3918 | 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] | 3919 | { | 
|  | 3920 | // Remember how many sc_list are in the list before we search in case | 
|  | 3921 | // we are appending the results to a variable list. | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3922 | uint32_t original_size = types.GetSize(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3923 |  | 
|  | 3924 | const uint32_t num_die_offsets = die_offsets.size(); | 
|  | 3925 | // Parse all of the types we found from the pubtypes matches | 
|  | 3926 | uint32_t i; | 
|  | 3927 | uint32_t num_matches = 0; | 
|  | 3928 | for (i = 0; i < num_die_offsets; ++i) | 
|  | 3929 | { | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3930 | Type *matching_type = ResolveTypeUID (die_offsets[i]); | 
|  | 3931 | if (matching_type) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3932 | { | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3933 | // 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] | 3934 | types.InsertUnique (matching_type->shared_from_this()); | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3935 | ++num_matches; | 
|  | 3936 | if (num_matches >= max_matches) | 
|  | 3937 | break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3938 | } | 
|  | 3939 | } | 
|  | 3940 |  | 
|  | 3941 | // Return the number of variable that were appended to the list | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3942 | return types.GetSize() - original_size; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3943 | } | 
|  | 3944 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3945 |  | 
|  | 3946 | size_t | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3947 | SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc, | 
|  | 3948 | clang::DeclContext *containing_decl_ctx, | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3949 | DWARFCompileUnit* dwarf_cu, | 
|  | 3950 | const DWARFDebugInfoEntry *parent_die, | 
|  | 3951 | bool skip_artificial, | 
|  | 3952 | bool &is_static, | 
|  | 3953 | TypeList* type_list, | 
|  | 3954 | std::vector<clang_type_t>& function_param_types, | 
|  | 3955 | std::vector<clang::ParmVarDecl*>& function_param_decls, | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 3956 | unsigned &type_quals, | 
|  | 3957 | ClangASTContext::TemplateParameterInfos &template_param_infos) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3958 | { | 
|  | 3959 | if (parent_die == NULL) | 
|  | 3960 | return 0; | 
|  | 3961 |  | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3962 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); | 
|  | 3963 |  | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3964 | size_t arg_idx = 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3965 | const DWARFDebugInfoEntry *die; | 
|  | 3966 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) | 
|  | 3967 | { | 
|  | 3968 | dw_tag_t tag = die->Tag(); | 
|  | 3969 | switch (tag) | 
|  | 3970 | { | 
|  | 3971 | case DW_TAG_formal_parameter: | 
|  | 3972 | { | 
|  | 3973 | DWARFDebugInfoEntry::Attributes attributes; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3974 | 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] | 3975 | if (num_attributes > 0) | 
|  | 3976 | { | 
|  | 3977 | const char *name = NULL; | 
|  | 3978 | Declaration decl; | 
|  | 3979 | dw_offset_t param_type_die_offset = DW_INVALID_OFFSET; | 
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 3980 | bool is_artificial = false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3981 | // one of None, Auto, Register, Extern, Static, PrivateExtern | 
|  | 3982 |  | 
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 3983 | clang::StorageClass storage = clang::SC_None; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3984 | uint32_t i; | 
|  | 3985 | for (i=0; i<num_attributes; ++i) | 
|  | 3986 | { | 
|  | 3987 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 3988 | DWARFFormValue form_value; | 
|  | 3989 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 3990 | { | 
|  | 3991 | switch (attr) | 
|  | 3992 | { | 
|  | 3993 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 3994 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 3995 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 3996 | case DW_AT_name:        name = form_value.AsCString(&get_debug_str_data()); break; | 
|  | 3997 | case DW_AT_type:        param_type_die_offset = form_value.Reference(dwarf_cu); break; | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 3998 | case DW_AT_artificial:  is_artificial = form_value.Boolean(); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3999 | case DW_AT_location: | 
|  | 4000 | //                          if (form_value.BlockData()) | 
|  | 4001 | //                          { | 
|  | 4002 | //                              const DataExtractor& debug_info_data = debug_info(); | 
|  | 4003 | //                              uint32_t block_length = form_value.Unsigned(); | 
|  | 4004 | //                              DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length); | 
|  | 4005 | //                          } | 
|  | 4006 | //                          else | 
|  | 4007 | //                          { | 
|  | 4008 | //                          } | 
|  | 4009 | //                          break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4010 | case DW_AT_const_value: | 
|  | 4011 | case DW_AT_default_value: | 
|  | 4012 | case DW_AT_description: | 
|  | 4013 | case DW_AT_endianity: | 
|  | 4014 | case DW_AT_is_optional: | 
|  | 4015 | case DW_AT_segment: | 
|  | 4016 | case DW_AT_variable_parameter: | 
|  | 4017 | default: | 
|  | 4018 | case DW_AT_abstract_origin: | 
|  | 4019 | case DW_AT_sibling: | 
|  | 4020 | break; | 
|  | 4021 | } | 
|  | 4022 | } | 
|  | 4023 | } | 
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 4024 |  | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4025 | bool skip = false; | 
|  | 4026 | if (skip_artificial) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4027 | { | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4028 | if (is_artificial) | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4029 | { | 
|  | 4030 | // In order to determine if a C++ member function is | 
|  | 4031 | // "const" we have to look at the const-ness of "this"... | 
|  | 4032 | // Ugly, but that | 
|  | 4033 | if (arg_idx == 0) | 
|  | 4034 | { | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 4035 | if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind())) | 
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 4036 | { | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4037 | // Often times compilers omit the "this" name for the | 
|  | 4038 | // specification DIEs, so we can't rely upon the name | 
|  | 4039 | // being in the formal parameter DIE... | 
|  | 4040 | if (name == NULL || ::strcmp(name, "this")==0) | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4041 | { | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4042 | Type *this_type = ResolveTypeUID (param_type_die_offset); | 
|  | 4043 | if (this_type) | 
|  | 4044 | { | 
|  | 4045 | uint32_t encoding_mask = this_type->GetEncodingMask(); | 
|  | 4046 | if (encoding_mask & Type::eEncodingIsPointerUID) | 
|  | 4047 | { | 
|  | 4048 | is_static = false; | 
|  | 4049 |  | 
|  | 4050 | if (encoding_mask & (1u << Type::eEncodingIsConstUID)) | 
|  | 4051 | type_quals |= clang::Qualifiers::Const; | 
|  | 4052 | if (encoding_mask & (1u << Type::eEncodingIsVolatileUID)) | 
|  | 4053 | type_quals |= clang::Qualifiers::Volatile; | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4054 | } | 
|  | 4055 | } | 
|  | 4056 | } | 
|  | 4057 | } | 
|  | 4058 | } | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4059 | skip = true; | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4060 | } | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4061 | else | 
|  | 4062 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4063 |  | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4064 | // HACK: Objective C formal parameters "self" and "_cmd" | 
|  | 4065 | // are not marked as artificial in the DWARF... | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4066 | CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); | 
|  | 4067 | if (comp_unit) | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4068 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4069 | switch (comp_unit->GetLanguage()) | 
|  | 4070 | { | 
|  | 4071 | case eLanguageTypeObjC: | 
|  | 4072 | case eLanguageTypeObjC_plus_plus: | 
|  | 4073 | if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0)) | 
|  | 4074 | skip = true; | 
|  | 4075 | break; | 
|  | 4076 | default: | 
|  | 4077 | break; | 
|  | 4078 | } | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4079 | } | 
|  | 4080 | } | 
|  | 4081 | } | 
|  | 4082 |  | 
|  | 4083 | if (!skip) | 
|  | 4084 | { | 
|  | 4085 | Type *type = ResolveTypeUID(param_type_die_offset); | 
|  | 4086 | if (type) | 
|  | 4087 | { | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 4088 | function_param_types.push_back (type->GetClangForwardType()); | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4089 |  | 
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 4090 | clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name, | 
|  | 4091 | type->GetClangForwardType(), | 
|  | 4092 | storage); | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4093 | assert(param_var_decl); | 
|  | 4094 | function_param_decls.push_back(param_var_decl); | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 4095 |  | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 4096 | GetClangASTContext().SetMetadataAsUserID (param_var_decl, MakeUserID(die->GetOffset())); | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4097 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4098 | } | 
|  | 4099 | } | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4100 | arg_idx++; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4101 | } | 
|  | 4102 | break; | 
|  | 4103 |  | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 4104 | case DW_TAG_template_type_parameter: | 
|  | 4105 | case DW_TAG_template_value_parameter: | 
|  | 4106 | ParseTemplateDIE (dwarf_cu, die,template_param_infos); | 
|  | 4107 | break; | 
|  | 4108 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4109 | default: | 
|  | 4110 | break; | 
|  | 4111 | } | 
|  | 4112 | } | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4113 | return arg_idx; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4114 | } | 
|  | 4115 |  | 
|  | 4116 | size_t | 
|  | 4117 | SymbolFileDWARF::ParseChildEnumerators | 
|  | 4118 | ( | 
|  | 4119 | const SymbolContext& sc, | 
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 4120 | clang_type_t enumerator_clang_type, | 
|  | 4121 | bool is_signed, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4122 | uint32_t enumerator_byte_size, | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4123 | DWARFCompileUnit* dwarf_cu, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4124 | const DWARFDebugInfoEntry *parent_die | 
|  | 4125 | ) | 
|  | 4126 | { | 
|  | 4127 | if (parent_die == NULL) | 
|  | 4128 | return 0; | 
|  | 4129 |  | 
|  | 4130 | size_t enumerators_added = 0; | 
|  | 4131 | const DWARFDebugInfoEntry *die; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4132 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); | 
|  | 4133 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4134 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) | 
|  | 4135 | { | 
|  | 4136 | const dw_tag_t tag = die->Tag(); | 
|  | 4137 | if (tag == DW_TAG_enumerator) | 
|  | 4138 | { | 
|  | 4139 | DWARFDebugInfoEntry::Attributes attributes; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4140 | 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] | 4141 | if (num_child_attributes > 0) | 
|  | 4142 | { | 
|  | 4143 | const char *name = NULL; | 
|  | 4144 | bool got_value = false; | 
|  | 4145 | int64_t enum_value = 0; | 
|  | 4146 | Declaration decl; | 
|  | 4147 |  | 
|  | 4148 | uint32_t i; | 
|  | 4149 | for (i=0; i<num_child_attributes; ++i) | 
|  | 4150 | { | 
|  | 4151 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 4152 | DWARFFormValue form_value; | 
|  | 4153 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 4154 | { | 
|  | 4155 | switch (attr) | 
|  | 4156 | { | 
|  | 4157 | case DW_AT_const_value: | 
|  | 4158 | got_value = true; | 
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 4159 | if (is_signed) | 
|  | 4160 | enum_value = form_value.Signed(); | 
|  | 4161 | else | 
|  | 4162 | enum_value = form_value.Unsigned(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4163 | break; | 
|  | 4164 |  | 
|  | 4165 | case DW_AT_name: | 
|  | 4166 | name = form_value.AsCString(&get_debug_str_data()); | 
|  | 4167 | break; | 
|  | 4168 |  | 
|  | 4169 | case DW_AT_description: | 
|  | 4170 | default: | 
|  | 4171 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 4172 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 4173 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 4174 | case DW_AT_sibling: | 
|  | 4175 | break; | 
|  | 4176 | } | 
|  | 4177 | } | 
|  | 4178 | } | 
|  | 4179 |  | 
|  | 4180 | if (name && name[0] && got_value) | 
|  | 4181 | { | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 4182 | GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type, | 
|  | 4183 | enumerator_clang_type, | 
|  | 4184 | decl, | 
|  | 4185 | name, | 
|  | 4186 | enum_value, | 
|  | 4187 | enumerator_byte_size * 8); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4188 | ++enumerators_added; | 
|  | 4189 | } | 
|  | 4190 | } | 
|  | 4191 | } | 
|  | 4192 | } | 
|  | 4193 | return enumerators_added; | 
|  | 4194 | } | 
|  | 4195 |  | 
|  | 4196 | void | 
|  | 4197 | SymbolFileDWARF::ParseChildArrayInfo | 
|  | 4198 | ( | 
|  | 4199 | const SymbolContext& sc, | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4200 | DWARFCompileUnit* dwarf_cu, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4201 | const DWARFDebugInfoEntry *parent_die, | 
|  | 4202 | int64_t& first_index, | 
|  | 4203 | std::vector<uint64_t>& element_orders, | 
|  | 4204 | uint32_t& byte_stride, | 
|  | 4205 | uint32_t& bit_stride | 
|  | 4206 | ) | 
|  | 4207 | { | 
|  | 4208 | if (parent_die == NULL) | 
|  | 4209 | return; | 
|  | 4210 |  | 
|  | 4211 | const DWARFDebugInfoEntry *die; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4212 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4213 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) | 
|  | 4214 | { | 
|  | 4215 | const dw_tag_t tag = die->Tag(); | 
|  | 4216 | switch (tag) | 
|  | 4217 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4218 | case DW_TAG_subrange_type: | 
|  | 4219 | { | 
|  | 4220 | DWARFDebugInfoEntry::Attributes attributes; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4221 | 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] | 4222 | if (num_child_attributes > 0) | 
|  | 4223 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4224 | uint64_t num_elements = 0; | 
|  | 4225 | uint64_t lower_bound = 0; | 
|  | 4226 | uint64_t upper_bound = 0; | 
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4227 | bool upper_bound_valid = false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4228 | uint32_t i; | 
|  | 4229 | for (i=0; i<num_child_attributes; ++i) | 
|  | 4230 | { | 
|  | 4231 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 4232 | DWARFFormValue form_value; | 
|  | 4233 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 4234 | { | 
|  | 4235 | switch (attr) | 
|  | 4236 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4237 | case DW_AT_name: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4238 | break; | 
|  | 4239 |  | 
|  | 4240 | case DW_AT_count: | 
|  | 4241 | num_elements = form_value.Unsigned(); | 
|  | 4242 | break; | 
|  | 4243 |  | 
|  | 4244 | case DW_AT_bit_stride: | 
|  | 4245 | bit_stride = form_value.Unsigned(); | 
|  | 4246 | break; | 
|  | 4247 |  | 
|  | 4248 | case DW_AT_byte_stride: | 
|  | 4249 | byte_stride = form_value.Unsigned(); | 
|  | 4250 | break; | 
|  | 4251 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4252 | case DW_AT_lower_bound: | 
|  | 4253 | lower_bound = form_value.Unsigned(); | 
|  | 4254 | break; | 
|  | 4255 |  | 
|  | 4256 | case DW_AT_upper_bound: | 
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4257 | upper_bound_valid = true; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4258 | upper_bound = form_value.Unsigned(); | 
|  | 4259 | break; | 
|  | 4260 |  | 
|  | 4261 | default: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4262 | case DW_AT_abstract_origin: | 
|  | 4263 | case DW_AT_accessibility: | 
|  | 4264 | case DW_AT_allocated: | 
|  | 4265 | case DW_AT_associated: | 
|  | 4266 | case DW_AT_data_location: | 
|  | 4267 | case DW_AT_declaration: | 
|  | 4268 | case DW_AT_description: | 
|  | 4269 | case DW_AT_sibling: | 
|  | 4270 | case DW_AT_threads_scaled: | 
|  | 4271 | case DW_AT_type: | 
|  | 4272 | case DW_AT_visibility: | 
|  | 4273 | break; | 
|  | 4274 | } | 
|  | 4275 | } | 
|  | 4276 | } | 
|  | 4277 |  | 
| Greg Clayton | e6a0779 | 2012-12-05 21:59:39 +0000 | [diff] [blame] | 4278 | if (num_elements == 0) | 
|  | 4279 | { | 
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4280 | if (upper_bound_valid && upper_bound >= lower_bound) | 
| Greg Clayton | e6a0779 | 2012-12-05 21:59:39 +0000 | [diff] [blame] | 4281 | num_elements = upper_bound - lower_bound + 1; | 
|  | 4282 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4283 |  | 
| Sean Callanan | ec979ba | 2012-10-22 23:56:48 +0000 | [diff] [blame] | 4284 | element_orders.push_back (num_elements); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4285 | } | 
|  | 4286 | } | 
|  | 4287 | break; | 
|  | 4288 | } | 
|  | 4289 | } | 
|  | 4290 | } | 
|  | 4291 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4292 | TypeSP | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4293 | SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4294 | { | 
|  | 4295 | TypeSP type_sp; | 
|  | 4296 | if (die != NULL) | 
|  | 4297 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4298 | assert(dwarf_cu != NULL); | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4299 | Type *type_ptr = m_die_to_type.lookup (die); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4300 | if (type_ptr == NULL) | 
|  | 4301 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4302 | CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu); | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4303 | assert (lldb_cu); | 
|  | 4304 | SymbolContext sc(lldb_cu); | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4305 | type_sp = ParseType(sc, dwarf_cu, die, NULL); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4306 | } | 
|  | 4307 | else if (type_ptr != DIE_IS_BEING_PARSED) | 
|  | 4308 | { | 
|  | 4309 | // Grab the existing type from the master types lists | 
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 4310 | type_sp = type_ptr->shared_from_this(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4311 | } | 
|  | 4312 |  | 
|  | 4313 | } | 
|  | 4314 | return type_sp; | 
|  | 4315 | } | 
|  | 4316 |  | 
|  | 4317 | clang::DeclContext * | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4318 | SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4319 | { | 
|  | 4320 | if (die_offset != DW_INVALID_OFFSET) | 
|  | 4321 | { | 
|  | 4322 | DWARFCompileUnitSP cu_sp; | 
|  | 4323 | const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp); | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4324 | return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4325 | } | 
|  | 4326 | return NULL; | 
|  | 4327 | } | 
|  | 4328 |  | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4329 | clang::DeclContext * | 
|  | 4330 | SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset) | 
|  | 4331 | { | 
|  | 4332 | if (die_offset != DW_INVALID_OFFSET) | 
|  | 4333 | { | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4334 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 4335 | if (debug_info) | 
|  | 4336 | { | 
|  | 4337 | DWARFCompileUnitSP cu_sp; | 
|  | 4338 | const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp); | 
|  | 4339 | if (die) | 
|  | 4340 | return GetClangDeclContextForDIE (sc, cu_sp.get(), die); | 
|  | 4341 | } | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4342 | } | 
|  | 4343 | return NULL; | 
|  | 4344 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4345 |  | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4346 | clang::NamespaceDecl * | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4347 | SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die) | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4348 | { | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4349 | if (die && die->Tag() == DW_TAG_namespace) | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4350 | { | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4351 | // See if we already parsed this namespace DIE and associated it with a | 
|  | 4352 | // uniqued namespace declaration | 
|  | 4353 | clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]); | 
|  | 4354 | if (namespace_decl) | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4355 | return namespace_decl; | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4356 | else | 
|  | 4357 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4358 | const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL); | 
|  | 4359 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL); | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4360 | namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4361 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4362 | if (log) | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4363 | { | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4364 | if (namespace_name) | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4365 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4366 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4367 | "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)", | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4368 | GetClangASTContext().getASTContext(), | 
|  | 4369 | MakeUserID(die->GetOffset()), | 
|  | 4370 | namespace_name, | 
|  | 4371 | namespace_decl, | 
|  | 4372 | namespace_decl->getOriginalNamespace()); | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4373 | } | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4374 | else | 
|  | 4375 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4376 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4377 | "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)", | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4378 | GetClangASTContext().getASTContext(), | 
|  | 4379 | MakeUserID(die->GetOffset()), | 
|  | 4380 | namespace_decl, | 
|  | 4381 | namespace_decl->getOriginalNamespace()); | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4382 | } | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4383 | } | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4384 |  | 
|  | 4385 | if (namespace_decl) | 
|  | 4386 | LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die); | 
|  | 4387 | return namespace_decl; | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4388 | } | 
|  | 4389 | } | 
|  | 4390 | return NULL; | 
|  | 4391 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4392 |  | 
|  | 4393 | clang::DeclContext * | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4394 | SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4395 | { | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4396 | clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die); | 
|  | 4397 | if (clang_decl_ctx) | 
|  | 4398 | return clang_decl_ctx; | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4399 | // If this DIE has a specification, or an abstract origin, then trace to those. | 
|  | 4400 |  | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4401 | 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] | 4402 | if (die_offset != DW_INVALID_OFFSET) | 
|  | 4403 | return GetClangDeclContextForDIEOffset (sc, die_offset); | 
|  | 4404 |  | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4405 | 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] | 4406 | if (die_offset != DW_INVALID_OFFSET) | 
|  | 4407 | return GetClangDeclContextForDIEOffset (sc, die_offset); | 
|  | 4408 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4409 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 4410 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4411 | 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] | 4412 | // This is the DIE we want.  Parse it, then query our map. | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4413 | bool assert_not_being_parsed = true; | 
|  | 4414 | ResolveTypeUID (cu, die, assert_not_being_parsed); | 
|  | 4415 |  | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4416 | clang_decl_ctx = GetCachedClangDeclContextForDIE (die); | 
|  | 4417 |  | 
|  | 4418 | return clang_decl_ctx; | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4419 | } | 
|  | 4420 |  | 
|  | 4421 | clang::DeclContext * | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4422 | 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] | 4423 | { | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4424 | if (m_clang_tu_decl == NULL) | 
|  | 4425 | m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4426 |  | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4427 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4428 |  | 
|  | 4429 | if (decl_ctx_die_copy) | 
|  | 4430 | *decl_ctx_die_copy = decl_ctx_die; | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4431 |  | 
|  | 4432 | if (decl_ctx_die) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4433 | { | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4434 |  | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4435 | DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die); | 
|  | 4436 | if (pos != m_die_to_decl_ctx.end()) | 
|  | 4437 | return pos->second; | 
|  | 4438 |  | 
|  | 4439 | switch (decl_ctx_die->Tag()) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4440 | { | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4441 | case DW_TAG_compile_unit: | 
|  | 4442 | return m_clang_tu_decl; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4443 |  | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4444 | case DW_TAG_namespace: | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4445 | return ResolveNamespaceDIE (cu, decl_ctx_die); | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4446 | break; | 
|  | 4447 |  | 
|  | 4448 | case DW_TAG_structure_type: | 
|  | 4449 | case DW_TAG_union_type: | 
|  | 4450 | case DW_TAG_class_type: | 
|  | 4451 | { | 
|  | 4452 | Type* type = ResolveType (cu, decl_ctx_die); | 
|  | 4453 | if (type) | 
|  | 4454 | { | 
|  | 4455 | clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ()); | 
|  | 4456 | if (decl_ctx) | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4457 | { | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4458 | LinkDeclContextToDIE (decl_ctx, decl_ctx_die); | 
|  | 4459 | if (decl_ctx) | 
|  | 4460 | return decl_ctx; | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4461 | } | 
|  | 4462 | } | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4463 | } | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4464 | break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4465 |  | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4466 | default: | 
|  | 4467 | break; | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4468 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4469 | } | 
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 4470 | return m_clang_tu_decl; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4471 | } | 
|  | 4472 |  | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4473 |  | 
|  | 4474 | const DWARFDebugInfoEntry * | 
|  | 4475 | SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) | 
|  | 4476 | { | 
|  | 4477 | if (cu && die) | 
|  | 4478 | { | 
|  | 4479 | const DWARFDebugInfoEntry * const decl_die = die; | 
|  | 4480 |  | 
|  | 4481 | while (die != NULL) | 
|  | 4482 | { | 
|  | 4483 | // If this is the original DIE that we are searching for a declaration | 
|  | 4484 | // for, then don't look in the cache as we don't want our own decl | 
|  | 4485 | // context to be our decl context... | 
|  | 4486 | if (decl_die != die) | 
|  | 4487 | { | 
|  | 4488 | switch (die->Tag()) | 
|  | 4489 | { | 
|  | 4490 | case DW_TAG_compile_unit: | 
|  | 4491 | case DW_TAG_namespace: | 
|  | 4492 | case DW_TAG_structure_type: | 
|  | 4493 | case DW_TAG_union_type: | 
|  | 4494 | case DW_TAG_class_type: | 
|  | 4495 | return die; | 
|  | 4496 |  | 
|  | 4497 | default: | 
|  | 4498 | break; | 
|  | 4499 | } | 
|  | 4500 | } | 
|  | 4501 |  | 
|  | 4502 | dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET); | 
|  | 4503 | if (die_offset != DW_INVALID_OFFSET) | 
|  | 4504 | { | 
|  | 4505 | DWARFCompileUnit *spec_cu = cu; | 
|  | 4506 | const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu); | 
|  | 4507 | const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die); | 
|  | 4508 | if (spec_die_decl_ctx_die) | 
|  | 4509 | return spec_die_decl_ctx_die; | 
|  | 4510 | } | 
|  | 4511 |  | 
|  | 4512 | die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET); | 
|  | 4513 | if (die_offset != DW_INVALID_OFFSET) | 
|  | 4514 | { | 
|  | 4515 | DWARFCompileUnit *abs_cu = cu; | 
|  | 4516 | const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu); | 
|  | 4517 | const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die); | 
|  | 4518 | if (abs_die_decl_ctx_die) | 
|  | 4519 | return abs_die_decl_ctx_die; | 
|  | 4520 | } | 
|  | 4521 |  | 
|  | 4522 | die = die->GetParent(); | 
|  | 4523 | } | 
|  | 4524 | } | 
|  | 4525 | return NULL; | 
|  | 4526 | } | 
|  | 4527 |  | 
|  | 4528 |  | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4529 | Symbol * | 
|  | 4530 | SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name) | 
|  | 4531 | { | 
|  | 4532 | Symbol *objc_class_symbol = NULL; | 
|  | 4533 | if (m_obj_file) | 
|  | 4534 | { | 
|  | 4535 | Symtab *symtab = m_obj_file->GetSymtab(); | 
|  | 4536 | if (symtab) | 
|  | 4537 | { | 
|  | 4538 | objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name, | 
|  | 4539 | eSymbolTypeObjCClass, | 
|  | 4540 | Symtab::eDebugNo, | 
|  | 4541 | Symtab::eVisibilityAny); | 
|  | 4542 | } | 
|  | 4543 | } | 
|  | 4544 | return objc_class_symbol; | 
|  | 4545 | } | 
|  | 4546 |  | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4547 | // Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't | 
|  | 4548 | // then we can end up looking through all class types for a complete type and never find | 
|  | 4549 | // the full definition. We need to know if this attribute is supported, so we determine | 
|  | 4550 | // this here and cache th result. We also need to worry about the debug map DWARF file | 
|  | 4551 | // if we are doing darwin DWARF in .o file debugging. | 
|  | 4552 | bool | 
|  | 4553 | SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu) | 
|  | 4554 | { | 
|  | 4555 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate) | 
|  | 4556 | { | 
|  | 4557 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo; | 
|  | 4558 | if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type()) | 
|  | 4559 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; | 
|  | 4560 | else | 
|  | 4561 | { | 
|  | 4562 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 4563 | const uint32_t num_compile_units = GetNumCompileUnits(); | 
|  | 4564 | for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) | 
|  | 4565 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4566 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); | 
|  | 4567 | 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] | 4568 | { | 
|  | 4569 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; | 
|  | 4570 | break; | 
|  | 4571 | } | 
|  | 4572 | } | 
|  | 4573 | } | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 4574 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ()) | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4575 | return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this); | 
|  | 4576 | } | 
|  | 4577 | return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes; | 
|  | 4578 | } | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4579 |  | 
|  | 4580 | // This function can be used when a DIE is found that is a forward declaration | 
|  | 4581 | // DIE and we want to try and find a type that has the complete definition. | 
|  | 4582 | TypeSP | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4583 | SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die, | 
|  | 4584 | const ConstString &type_name, | 
|  | 4585 | bool must_be_implementation) | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4586 | { | 
|  | 4587 |  | 
|  | 4588 | TypeSP type_sp; | 
|  | 4589 |  | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4590 | if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name))) | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4591 | return type_sp; | 
|  | 4592 |  | 
|  | 4593 | DIEArray die_offsets; | 
|  | 4594 |  | 
|  | 4595 | if (m_using_apple_tables) | 
|  | 4596 | { | 
|  | 4597 | if (m_apple_types_ap.get()) | 
|  | 4598 | { | 
|  | 4599 | const char *name_cstr = type_name.GetCString(); | 
| Greg Clayton | 68221ec | 2012-01-18 20:58:12 +0000 | [diff] [blame] | 4600 | m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation); | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4601 | } | 
|  | 4602 | } | 
|  | 4603 | else | 
|  | 4604 | { | 
|  | 4605 | if (!m_indexed) | 
|  | 4606 | Index (); | 
|  | 4607 |  | 
|  | 4608 | m_type_index.Find (type_name, die_offsets); | 
|  | 4609 | } | 
|  | 4610 |  | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4611 | const size_t num_matches = die_offsets.size(); | 
|  | 4612 |  | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4613 | DWARFCompileUnit* type_cu = NULL; | 
|  | 4614 | const DWARFDebugInfoEntry* type_die = NULL; | 
|  | 4615 | if (num_matches) | 
|  | 4616 | { | 
|  | 4617 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 4618 | for (size_t i=0; i<num_matches; ++i) | 
|  | 4619 | { | 
|  | 4620 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 4621 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); | 
|  | 4622 |  | 
|  | 4623 | if (type_die) | 
|  | 4624 | { | 
|  | 4625 | bool try_resolving_type = false; | 
|  | 4626 |  | 
|  | 4627 | // Don't try and resolve the DIE we are looking for with the DIE itself! | 
|  | 4628 | if (type_die != die) | 
|  | 4629 | { | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4630 | switch (type_die->Tag()) | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4631 | { | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4632 | case DW_TAG_class_type: | 
|  | 4633 | case DW_TAG_structure_type: | 
|  | 4634 | try_resolving_type = true; | 
|  | 4635 | break; | 
|  | 4636 | default: | 
|  | 4637 | break; | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4638 | } | 
|  | 4639 | } | 
|  | 4640 |  | 
|  | 4641 | if (try_resolving_type) | 
|  | 4642 | { | 
| Sean Callanan | a9bc065 | 2012-01-19 02:17:40 +0000 | [diff] [blame] | 4643 | if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type()) | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4644 | 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] | 4645 |  | 
|  | 4646 | if (try_resolving_type) | 
|  | 4647 | { | 
|  | 4648 | Type *resolved_type = ResolveType (type_cu, type_die, false); | 
|  | 4649 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) | 
|  | 4650 | { | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4651 | DEBUG_PRINTF ("resolved 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ") from %s to 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ")\n", | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4652 | MakeUserID(die->GetOffset()), | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4653 | MakeUserID(dwarf_cu->GetOffset()), | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4654 | m_obj_file->GetFileSpec().GetFilename().AsCString(), | 
|  | 4655 | MakeUserID(type_die->GetOffset()), | 
|  | 4656 | MakeUserID(type_cu->GetOffset())); | 
|  | 4657 |  | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4658 | if (die) | 
|  | 4659 | m_die_to_type[die] = resolved_type; | 
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 4660 | type_sp = resolved_type->shared_from_this(); | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4661 | break; | 
|  | 4662 | } | 
|  | 4663 | } | 
|  | 4664 | } | 
|  | 4665 | } | 
|  | 4666 | else | 
|  | 4667 | { | 
|  | 4668 | if (m_using_apple_tables) | 
|  | 4669 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4670 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", | 
|  | 4671 | die_offset, type_name.GetCString()); | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4672 | } | 
|  | 4673 | } | 
|  | 4674 |  | 
|  | 4675 | } | 
|  | 4676 | } | 
|  | 4677 | return type_sp; | 
|  | 4678 | } | 
|  | 4679 |  | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4680 |  | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4681 | //---------------------------------------------------------------------- | 
|  | 4682 | // This function helps to ensure that the declaration contexts match for | 
|  | 4683 | // two different DIEs. Often times debug information will refer to a | 
|  | 4684 | // forward declaration of a type (the equivalent of "struct my_struct;". | 
|  | 4685 | // There will often be a declaration of that type elsewhere that has the | 
|  | 4686 | // full definition. When we go looking for the full type "my_struct", we | 
|  | 4687 | // will find one or more matches in the accelerator tables and we will | 
|  | 4688 | // then need to make sure the type was in the same declaration context | 
|  | 4689 | // as the original DIE. This function can efficiently compare two DIEs | 
|  | 4690 | // and will return true when the declaration context matches, and false | 
|  | 4691 | // when they don't. | 
|  | 4692 | //---------------------------------------------------------------------- | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4693 | bool | 
|  | 4694 | SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1, | 
|  | 4695 | DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2) | 
|  | 4696 | { | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4697 | if (die1 == die2) | 
|  | 4698 | return true; | 
|  | 4699 |  | 
|  | 4700 | #if defined (LLDB_CONFIGURATION_DEBUG) | 
|  | 4701 | // You can't and shouldn't call this function with a compile unit from | 
|  | 4702 | // two different SymbolFileDWARF instances. | 
|  | 4703 | assert (DebugInfo()->ContainsCompileUnit (cu1)); | 
|  | 4704 | assert (DebugInfo()->ContainsCompileUnit (cu2)); | 
|  | 4705 | #endif | 
|  | 4706 |  | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4707 | DWARFDIECollection decl_ctx_1; | 
|  | 4708 | DWARFDIECollection decl_ctx_2; | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4709 | //The declaration DIE stack is a stack of the declaration context | 
|  | 4710 | // DIEs all the way back to the compile unit. If a type "T" is | 
|  | 4711 | // declared inside a class "B", and class "B" is declared inside | 
|  | 4712 | // a class "A" and class "A" is in a namespace "lldb", and the | 
|  | 4713 | // namespace is in a compile unit, there will be a stack of DIEs: | 
|  | 4714 | // | 
|  | 4715 | //   [0] DW_TAG_class_type for "B" | 
|  | 4716 | //   [1] DW_TAG_class_type for "A" | 
|  | 4717 | //   [2] DW_TAG_namespace  for "lldb" | 
|  | 4718 | //   [3] DW_TAG_compile_unit for the source file. | 
|  | 4719 | // | 
|  | 4720 | // We grab both contexts and make sure that everything matches | 
|  | 4721 | // all the way back to the compiler unit. | 
|  | 4722 |  | 
|  | 4723 | // First lets grab the decl contexts for both DIEs | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4724 | die1->GetDeclContextDIEs (this, cu1, decl_ctx_1); | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 4725 | die2->GetDeclContextDIEs (this, cu2, decl_ctx_2); | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4726 | // Make sure the context arrays have the same size, otherwise | 
|  | 4727 | // we are done | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4728 | const size_t count1 = decl_ctx_1.Size(); | 
|  | 4729 | const size_t count2 = decl_ctx_2.Size(); | 
|  | 4730 | if (count1 != count2) | 
|  | 4731 | return false; | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4732 |  | 
|  | 4733 | // Make sure the DW_TAG values match all the way back up the the | 
|  | 4734 | // compile unit. If they don't, then we are done. | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4735 | const DWARFDebugInfoEntry *decl_ctx_die1; | 
|  | 4736 | const DWARFDebugInfoEntry *decl_ctx_die2; | 
|  | 4737 | size_t i; | 
|  | 4738 | for (i=0; i<count1; i++) | 
|  | 4739 | { | 
|  | 4740 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); | 
|  | 4741 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); | 
|  | 4742 | if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag()) | 
|  | 4743 | return false; | 
|  | 4744 | } | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4745 | #if defined LLDB_CONFIGURATION_DEBUG | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4746 |  | 
|  | 4747 | // Make sure the top item in the decl context die array is always | 
|  | 4748 | // DW_TAG_compile_unit. If it isn't then something went wrong in | 
|  | 4749 | // the DWARFDebugInfoEntry::GetDeclContextDIEs() function... | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4750 | assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit); | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4751 |  | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4752 | #endif | 
|  | 4753 | // Always skip the compile unit when comparing by only iterating up to | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4754 | // "count - 1". Here we compare the names as we go. | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4755 | for (i=0; i<count1 - 1; i++) | 
|  | 4756 | { | 
|  | 4757 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); | 
|  | 4758 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); | 
|  | 4759 | const char *name1 = decl_ctx_die1->GetName(this, cu1); | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 4760 | const char *name2 = decl_ctx_die2->GetName(this, cu2); | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4761 | // If the string was from a DW_FORM_strp, then the pointer will often | 
|  | 4762 | // be the same! | 
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 4763 | if (name1 == name2) | 
|  | 4764 | continue; | 
|  | 4765 |  | 
|  | 4766 | // Name pointers are not equal, so only compare the strings | 
|  | 4767 | // if both are not NULL. | 
|  | 4768 | if (name1 && name2) | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4769 | { | 
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 4770 | // If the strings don't compare, we are done... | 
|  | 4771 | if (strcmp(name1, name2) != 0) | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4772 | return false; | 
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 4773 | } | 
|  | 4774 | else | 
|  | 4775 | { | 
|  | 4776 | // One name was NULL while the other wasn't | 
|  | 4777 | return false; | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4778 | } | 
|  | 4779 | } | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4780 | // We made it through all of the checks and the declaration contexts | 
|  | 4781 | // are equal. | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4782 | return true; | 
|  | 4783 | } | 
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 4784 |  | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4785 | // This function can be used when a DIE is found that is a forward declaration | 
|  | 4786 | // DIE and we want to try and find a type that has the complete definition. | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4787 | // "cu" and "die" must be from this SymbolFileDWARF | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4788 | TypeSP | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4789 | SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu, | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4790 | const DWARFDebugInfoEntry *die, | 
|  | 4791 | const ConstString &type_name) | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4792 | { | 
|  | 4793 | TypeSP type_sp; | 
|  | 4794 |  | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4795 | #if defined (LLDB_CONFIGURATION_DEBUG) | 
|  | 4796 | // You can't and shouldn't call this function with a compile unit from | 
|  | 4797 | // another SymbolFileDWARF instance. | 
|  | 4798 | assert (DebugInfo()->ContainsCompileUnit (cu)); | 
|  | 4799 | #endif | 
|  | 4800 |  | 
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 4801 | if (cu == NULL || die == NULL || !type_name) | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4802 | return type_sp; | 
|  | 4803 |  | 
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 4804 | std::string qualified_name; | 
|  | 4805 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4806 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4807 | if (log) | 
|  | 4808 | { | 
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4809 | die->GetQualifiedName(this, cu, qualified_name); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4810 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4811 | "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x (%s), name='%s')", | 
|  | 4812 | die->GetOffset(), | 
|  | 4813 | qualified_name.c_str(), | 
|  | 4814 | type_name.GetCString()); | 
|  | 4815 | } | 
|  | 4816 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4817 | DIEArray die_offsets; | 
|  | 4818 |  | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4819 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4820 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4821 | if (m_apple_types_ap.get()) | 
|  | 4822 | { | 
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 4823 | const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag); | 
|  | 4824 | const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash); | 
|  | 4825 | if (has_tag && has_qualified_name_hash) | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4826 | { | 
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 4827 | if (qualified_name.empty()) | 
|  | 4828 | die->GetQualifiedName(this, cu, qualified_name); | 
|  | 4829 |  | 
|  | 4830 | const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name.c_str()); | 
|  | 4831 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4832 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()"); | 
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 4833 | m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), die->Tag(), qualified_name_hash, die_offsets); | 
|  | 4834 | } | 
|  | 4835 | else if (has_tag > 1) | 
|  | 4836 | { | 
|  | 4837 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4838 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()"); | 
| Greg Clayton | ae920b6 | 2012-01-06 00:17:16 +0000 | [diff] [blame] | 4839 | m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets); | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4840 | } | 
|  | 4841 | else | 
|  | 4842 | { | 
|  | 4843 | m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets); | 
|  | 4844 | } | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4845 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4846 | } | 
|  | 4847 | else | 
|  | 4848 | { | 
|  | 4849 | if (!m_indexed) | 
|  | 4850 | Index (); | 
|  | 4851 |  | 
|  | 4852 | m_type_index.Find (type_name, die_offsets); | 
|  | 4853 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4854 |  | 
|  | 4855 | const size_t num_matches = die_offsets.size(); | 
| Greg Clayton | 6997489 | 2010-12-03 21:42:06 +0000 | [diff] [blame] | 4856 |  | 
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4857 | const dw_tag_t die_tag = die->Tag(); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4858 |  | 
|  | 4859 | DWARFCompileUnit* type_cu = NULL; | 
|  | 4860 | const DWARFDebugInfoEntry* type_die = NULL; | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4861 | if (num_matches) | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4862 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4863 | DWARFDebugInfo* debug_info = DebugInfo(); | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4864 | for (size_t i=0; i<num_matches; ++i) | 
|  | 4865 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4866 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 4867 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4868 |  | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4869 | if (type_die) | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4870 | { | 
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4871 | bool try_resolving_type = false; | 
|  | 4872 |  | 
|  | 4873 | // Don't try and resolve the DIE we are looking for with the DIE itself! | 
|  | 4874 | if (type_die != die) | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4875 | { | 
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4876 | const dw_tag_t type_die_tag = type_die->Tag(); | 
|  | 4877 | // Make sure the tags match | 
|  | 4878 | if (type_die_tag == die_tag) | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4879 | { | 
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4880 | // The tags match, lets try resolving this type | 
|  | 4881 | try_resolving_type = true; | 
|  | 4882 | } | 
|  | 4883 | else | 
|  | 4884 | { | 
|  | 4885 | // The tags don't match, but we need to watch our for a | 
|  | 4886 | // forward declaration for a struct and ("struct foo") | 
|  | 4887 | // ends up being a class ("class foo { ... };") or | 
|  | 4888 | // vice versa. | 
|  | 4889 | switch (type_die_tag) | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4890 | { | 
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4891 | case DW_TAG_class_type: | 
|  | 4892 | // We had a "class foo", see if we ended up with a "struct foo { ... };" | 
|  | 4893 | try_resolving_type = (die_tag == DW_TAG_structure_type); | 
|  | 4894 | break; | 
|  | 4895 | case DW_TAG_structure_type: | 
|  | 4896 | // We had a "struct foo", see if we ended up with a "class foo { ... };" | 
|  | 4897 | try_resolving_type = (die_tag == DW_TAG_class_type); | 
|  | 4898 | break; | 
|  | 4899 | default: | 
|  | 4900 | // Tags don't match, don't event try to resolve | 
|  | 4901 | // using this type whose name matches.... | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4902 | break; | 
|  | 4903 | } | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4904 | } | 
|  | 4905 | } | 
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4906 |  | 
|  | 4907 | if (try_resolving_type) | 
|  | 4908 | { | 
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4909 | if (log) | 
|  | 4910 | { | 
|  | 4911 | std::string qualified_name; | 
|  | 4912 | type_die->GetQualifiedName(this, cu, qualified_name); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4913 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4914 | "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') trying die=0x%8.8x (%s)", | 
|  | 4915 | die->GetOffset(), | 
|  | 4916 | type_name.GetCString(), | 
|  | 4917 | type_die->GetOffset(), | 
|  | 4918 | qualified_name.c_str()); | 
|  | 4919 | } | 
|  | 4920 |  | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4921 | // Make sure the decl contexts match all the way up | 
|  | 4922 | if (DIEDeclContextsMatch(cu, die, type_cu, type_die)) | 
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4923 | { | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4924 | Type *resolved_type = ResolveType (type_cu, type_die, false); | 
|  | 4925 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) | 
|  | 4926 | { | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4927 | DEBUG_PRINTF ("resolved 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ") from %s to 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ")\n", | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4928 | MakeUserID(die->GetOffset()), | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4929 | MakeUserID(dwarf_cu->GetOffset()), | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4930 | m_obj_file->GetFileSpec().GetFilename().AsCString(), | 
|  | 4931 | MakeUserID(type_die->GetOffset()), | 
|  | 4932 | MakeUserID(type_cu->GetOffset())); | 
|  | 4933 |  | 
|  | 4934 | m_die_to_type[die] = resolved_type; | 
| Greg Clayton | ff7692a | 2012-02-02 18:16:59 +0000 | [diff] [blame] | 4935 | type_sp = resolved_type->shared_from_this(); | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4936 | break; | 
|  | 4937 | } | 
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4938 | } | 
|  | 4939 | } | 
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4940 | else | 
|  | 4941 | { | 
|  | 4942 | if (log) | 
|  | 4943 | { | 
|  | 4944 | std::string qualified_name; | 
|  | 4945 | type_die->GetQualifiedName(this, cu, qualified_name); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4946 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4947 | "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') ignoring die=0x%8.8x (%s)", | 
|  | 4948 | die->GetOffset(), | 
|  | 4949 | type_name.GetCString(), | 
|  | 4950 | type_die->GetOffset(), | 
|  | 4951 | qualified_name.c_str()); | 
|  | 4952 | } | 
|  | 4953 | } | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4954 | } | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4955 | else | 
|  | 4956 | { | 
|  | 4957 | if (m_using_apple_tables) | 
|  | 4958 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4959 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", | 
|  | 4960 | die_offset, type_name.GetCString()); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4961 | } | 
|  | 4962 | } | 
|  | 4963 |  | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4964 | } | 
|  | 4965 | } | 
|  | 4966 | return type_sp; | 
|  | 4967 | } | 
|  | 4968 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4969 | TypeSP | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4970 | SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx) | 
|  | 4971 | { | 
|  | 4972 | TypeSP type_sp; | 
|  | 4973 |  | 
|  | 4974 | const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize(); | 
|  | 4975 | if (dwarf_decl_ctx_count > 0) | 
|  | 4976 | { | 
|  | 4977 | const ConstString type_name(dwarf_decl_ctx[0].name); | 
|  | 4978 | const dw_tag_t tag = dwarf_decl_ctx[0].tag; | 
|  | 4979 |  | 
|  | 4980 | if (type_name) | 
|  | 4981 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4982 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4983 | if (log) | 
|  | 4984 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4985 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4986 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')", | 
|  | 4987 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), | 
|  | 4988 | dwarf_decl_ctx.GetQualifiedName()); | 
|  | 4989 | } | 
|  | 4990 |  | 
|  | 4991 | DIEArray die_offsets; | 
|  | 4992 |  | 
|  | 4993 | if (m_using_apple_tables) | 
|  | 4994 | { | 
|  | 4995 | if (m_apple_types_ap.get()) | 
|  | 4996 | { | 
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 4997 | const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag); | 
|  | 4998 | const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash); | 
|  | 4999 | if (has_tag && has_qualified_name_hash) | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5000 | { | 
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 5001 | const char *qualified_name = dwarf_decl_ctx.GetQualifiedName(); | 
|  | 5002 | const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name); | 
|  | 5003 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5004 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()"); | 
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 5005 | m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets); | 
|  | 5006 | } | 
|  | 5007 | else if (has_tag) | 
|  | 5008 | { | 
|  | 5009 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5010 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()"); | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5011 | m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets); | 
|  | 5012 | } | 
|  | 5013 | else | 
|  | 5014 | { | 
|  | 5015 | m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets); | 
|  | 5016 | } | 
|  | 5017 | } | 
|  | 5018 | } | 
|  | 5019 | else | 
|  | 5020 | { | 
|  | 5021 | if (!m_indexed) | 
|  | 5022 | Index (); | 
|  | 5023 |  | 
|  | 5024 | m_type_index.Find (type_name, die_offsets); | 
|  | 5025 | } | 
|  | 5026 |  | 
|  | 5027 | const size_t num_matches = die_offsets.size(); | 
|  | 5028 |  | 
|  | 5029 |  | 
|  | 5030 | DWARFCompileUnit* type_cu = NULL; | 
|  | 5031 | const DWARFDebugInfoEntry* type_die = NULL; | 
|  | 5032 | if (num_matches) | 
|  | 5033 | { | 
|  | 5034 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 5035 | for (size_t i=0; i<num_matches; ++i) | 
|  | 5036 | { | 
|  | 5037 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 5038 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); | 
|  | 5039 |  | 
|  | 5040 | if (type_die) | 
|  | 5041 | { | 
|  | 5042 | bool try_resolving_type = false; | 
|  | 5043 |  | 
|  | 5044 | // Don't try and resolve the DIE we are looking for with the DIE itself! | 
|  | 5045 | const dw_tag_t type_tag = type_die->Tag(); | 
|  | 5046 | // Make sure the tags match | 
|  | 5047 | if (type_tag == tag) | 
|  | 5048 | { | 
|  | 5049 | // The tags match, lets try resolving this type | 
|  | 5050 | try_resolving_type = true; | 
|  | 5051 | } | 
|  | 5052 | else | 
|  | 5053 | { | 
|  | 5054 | // The tags don't match, but we need to watch our for a | 
|  | 5055 | // forward declaration for a struct and ("struct foo") | 
|  | 5056 | // ends up being a class ("class foo { ... };") or | 
|  | 5057 | // vice versa. | 
|  | 5058 | switch (type_tag) | 
|  | 5059 | { | 
|  | 5060 | case DW_TAG_class_type: | 
|  | 5061 | // We had a "class foo", see if we ended up with a "struct foo { ... };" | 
|  | 5062 | try_resolving_type = (tag == DW_TAG_structure_type); | 
|  | 5063 | break; | 
|  | 5064 | case DW_TAG_structure_type: | 
|  | 5065 | // We had a "struct foo", see if we ended up with a "class foo { ... };" | 
|  | 5066 | try_resolving_type = (tag == DW_TAG_class_type); | 
|  | 5067 | break; | 
|  | 5068 | default: | 
|  | 5069 | // Tags don't match, don't event try to resolve | 
|  | 5070 | // using this type whose name matches.... | 
|  | 5071 | break; | 
|  | 5072 | } | 
|  | 5073 | } | 
|  | 5074 |  | 
|  | 5075 | if (try_resolving_type) | 
|  | 5076 | { | 
|  | 5077 | DWARFDeclContext type_dwarf_decl_ctx; | 
|  | 5078 | type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx); | 
|  | 5079 |  | 
|  | 5080 | if (log) | 
|  | 5081 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5082 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5083 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)", | 
|  | 5084 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), | 
|  | 5085 | dwarf_decl_ctx.GetQualifiedName(), | 
|  | 5086 | type_die->GetOffset(), | 
|  | 5087 | type_dwarf_decl_ctx.GetQualifiedName()); | 
|  | 5088 | } | 
|  | 5089 |  | 
|  | 5090 | // Make sure the decl contexts match all the way up | 
|  | 5091 | if (dwarf_decl_ctx == type_dwarf_decl_ctx) | 
|  | 5092 | { | 
|  | 5093 | Type *resolved_type = ResolveType (type_cu, type_die, false); | 
|  | 5094 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) | 
|  | 5095 | { | 
|  | 5096 | type_sp = resolved_type->shared_from_this(); | 
|  | 5097 | break; | 
|  | 5098 | } | 
|  | 5099 | } | 
|  | 5100 | } | 
|  | 5101 | else | 
|  | 5102 | { | 
|  | 5103 | if (log) | 
|  | 5104 | { | 
|  | 5105 | std::string qualified_name; | 
|  | 5106 | type_die->GetQualifiedName(this, type_cu, qualified_name); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5107 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5108 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)", | 
|  | 5109 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), | 
|  | 5110 | dwarf_decl_ctx.GetQualifiedName(), | 
|  | 5111 | type_die->GetOffset(), | 
|  | 5112 | qualified_name.c_str()); | 
|  | 5113 | } | 
|  | 5114 | } | 
|  | 5115 | } | 
|  | 5116 | else | 
|  | 5117 | { | 
|  | 5118 | if (m_using_apple_tables) | 
|  | 5119 | { | 
|  | 5120 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", | 
|  | 5121 | die_offset, type_name.GetCString()); | 
|  | 5122 | } | 
|  | 5123 | } | 
|  | 5124 |  | 
|  | 5125 | } | 
|  | 5126 | } | 
|  | 5127 | } | 
|  | 5128 | } | 
|  | 5129 | return type_sp; | 
|  | 5130 | } | 
|  | 5131 |  | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5132 | bool | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5133 | SymbolFileDWARF::CopyUniqueClassMethodTypes (SymbolFileDWARF *src_symfile, | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5134 | Type *class_type, | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5135 | DWARFCompileUnit* src_cu, | 
|  | 5136 | const DWARFDebugInfoEntry *src_class_die, | 
|  | 5137 | DWARFCompileUnit* dst_cu, | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5138 | const DWARFDebugInfoEntry *dst_class_die, | 
|  | 5139 | llvm::SmallVectorImpl <const DWARFDebugInfoEntry *> &failures) | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5140 | { | 
|  | 5141 | if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die) | 
|  | 5142 | return false; | 
|  | 5143 | if (src_class_die->Tag() != dst_class_die->Tag()) | 
|  | 5144 | return false; | 
|  | 5145 |  | 
|  | 5146 | // We need to complete the class type so we can get all of the method types | 
|  | 5147 | // parsed so we can then unique those types to their equivalent counterparts | 
|  | 5148 | // in "dst_cu" and "dst_class_die" | 
|  | 5149 | class_type->GetClangFullType(); | 
|  | 5150 |  | 
|  | 5151 | const DWARFDebugInfoEntry *src_die; | 
|  | 5152 | const DWARFDebugInfoEntry *dst_die; | 
|  | 5153 | UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die; | 
|  | 5154 | UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die; | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5155 | UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die_artificial; | 
|  | 5156 | UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die_artificial; | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5157 | for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling()) | 
|  | 5158 | { | 
|  | 5159 | if (src_die->Tag() == DW_TAG_subprogram) | 
|  | 5160 | { | 
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5161 | // Make sure this is a declaration and not a concrete instance by looking | 
|  | 5162 | // for DW_AT_declaration set to 1. Sometimes concrete function instances | 
|  | 5163 | // are placed inside the class definitions and shouldn't be included in | 
|  | 5164 | // the list of things are are tracking here. | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5165 | 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] | 5166 | { | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5167 | const char *src_name = src_die->GetMangledName (src_symfile, src_cu); | 
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5168 | if (src_name) | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5169 | { | 
|  | 5170 | ConstString src_const_name(src_name); | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5171 | if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_artificial, 0)) | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5172 | src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die); | 
|  | 5173 | else | 
|  | 5174 | src_name_to_die.Append(src_const_name.GetCString(), src_die); | 
|  | 5175 | } | 
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5176 | } | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5177 | } | 
|  | 5178 | } | 
|  | 5179 | for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling()) | 
|  | 5180 | { | 
|  | 5181 | if (dst_die->Tag() == DW_TAG_subprogram) | 
|  | 5182 | { | 
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5183 | // Make sure this is a declaration and not a concrete instance by looking | 
|  | 5184 | // for DW_AT_declaration set to 1. Sometimes concrete function instances | 
|  | 5185 | // are placed inside the class definitions and shouldn't be included in | 
|  | 5186 | // the list of things are are tracking here. | 
|  | 5187 | if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_declaration, 0) == 1) | 
|  | 5188 | { | 
|  | 5189 | const char *dst_name = dst_die->GetMangledName (this, dst_cu); | 
|  | 5190 | if (dst_name) | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5191 | { | 
|  | 5192 | ConstString dst_const_name(dst_name); | 
|  | 5193 | if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_artificial, 0)) | 
|  | 5194 | dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die); | 
|  | 5195 | else | 
|  | 5196 | dst_name_to_die.Append(dst_const_name.GetCString(), dst_die); | 
|  | 5197 | } | 
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5198 | } | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5199 | } | 
|  | 5200 | } | 
|  | 5201 | const uint32_t src_size = src_name_to_die.GetSize (); | 
|  | 5202 | const uint32_t dst_size = dst_name_to_die.GetSize (); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5203 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION)); | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5204 |  | 
|  | 5205 | // Is everything kosher so we can go through the members at top speed? | 
|  | 5206 | bool fast_path = true; | 
|  | 5207 |  | 
|  | 5208 | if (src_size != dst_size) | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5209 | { | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5210 | if (src_size != 0 && dst_size != 0) | 
|  | 5211 | { | 
|  | 5212 | if (log) | 
|  | 5213 | 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)", | 
|  | 5214 | src_class_die->GetOffset(), | 
|  | 5215 | dst_class_die->GetOffset(), | 
|  | 5216 | src_size, | 
|  | 5217 | dst_size); | 
|  | 5218 | } | 
|  | 5219 |  | 
|  | 5220 | fast_path = false; | 
|  | 5221 | } | 
|  | 5222 |  | 
|  | 5223 | uint32_t idx; | 
|  | 5224 |  | 
|  | 5225 | if (fast_path) | 
|  | 5226 | { | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5227 | for (idx = 0; idx < src_size; ++idx) | 
|  | 5228 | { | 
|  | 5229 | src_die = src_name_to_die.GetValueAtIndexUnchecked (idx); | 
|  | 5230 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx); | 
|  | 5231 |  | 
|  | 5232 | if (src_die->Tag() != dst_die->Tag()) | 
|  | 5233 | { | 
|  | 5234 | if (log) | 
|  | 5235 | 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)", | 
|  | 5236 | src_class_die->GetOffset(), | 
|  | 5237 | dst_class_die->GetOffset(), | 
|  | 5238 | src_die->GetOffset(), | 
|  | 5239 | DW_TAG_value_to_name(src_die->Tag()), | 
|  | 5240 | dst_die->GetOffset(), | 
|  | 5241 | DW_TAG_value_to_name(src_die->Tag())); | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5242 | fast_path = false; | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5243 | } | 
|  | 5244 |  | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5245 | const char *src_name = src_die->GetMangledName (src_symfile, src_cu); | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5246 | const char *dst_name = dst_die->GetMangledName (this, dst_cu); | 
|  | 5247 |  | 
|  | 5248 | // Make sure the names match | 
|  | 5249 | if (src_name == dst_name || (strcmp (src_name, dst_name) == 0)) | 
|  | 5250 | continue; | 
|  | 5251 |  | 
|  | 5252 | if (log) | 
|  | 5253 | 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)", | 
|  | 5254 | src_class_die->GetOffset(), | 
|  | 5255 | dst_class_die->GetOffset(), | 
|  | 5256 | src_die->GetOffset(), | 
|  | 5257 | src_name, | 
|  | 5258 | dst_die->GetOffset(), | 
|  | 5259 | dst_name); | 
|  | 5260 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5261 | fast_path = false; | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5262 | } | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5263 | } | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5264 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5265 | // Now do the work of linking the DeclContexts and Types. | 
|  | 5266 | if (fast_path) | 
|  | 5267 | { | 
|  | 5268 | // We can do this quickly.  Just run across the tables index-for-index since | 
|  | 5269 | // we know each node has matching names and tags. | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5270 | for (idx = 0; idx < src_size; ++idx) | 
|  | 5271 | { | 
|  | 5272 | src_die = src_name_to_die.GetValueAtIndexUnchecked (idx); | 
|  | 5273 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx); | 
|  | 5274 |  | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5275 | 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] | 5276 | if (src_decl_ctx) | 
|  | 5277 | { | 
|  | 5278 | if (log) | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5279 | log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset()); | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5280 | LinkDeclContextToDIE (src_decl_ctx, dst_die); | 
|  | 5281 | } | 
|  | 5282 | else | 
|  | 5283 | { | 
|  | 5284 | if (log) | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5285 | log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found", src_die->GetOffset(), dst_die->GetOffset()); | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5286 | } | 
|  | 5287 |  | 
|  | 5288 | Type *src_child_type = m_die_to_type[src_die]; | 
|  | 5289 | if (src_child_type) | 
|  | 5290 | { | 
|  | 5291 | if (log) | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5292 | log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", src_child_type, src_child_type->GetID(), src_die->GetOffset(), dst_die->GetOffset()); | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5293 | m_die_to_type[dst_die] = src_child_type; | 
|  | 5294 | } | 
|  | 5295 | else | 
|  | 5296 | { | 
|  | 5297 | if (log) | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5298 | 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()); | 
|  | 5299 | } | 
|  | 5300 | } | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5301 | } | 
|  | 5302 | else | 
|  | 5303 | { | 
|  | 5304 | // We must do this slowly.  For each member of the destination, look | 
|  | 5305 | // up a member in the source with the same name, check its tag, and | 
|  | 5306 | // unique them if everything matches up.  Report failures. | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5307 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5308 | if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty()) | 
|  | 5309 | { | 
|  | 5310 | src_name_to_die.Sort(); | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5311 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5312 | for (idx = 0; idx < dst_size; ++idx) | 
|  | 5313 | { | 
|  | 5314 | const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx); | 
|  | 5315 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx); | 
|  | 5316 | src_die = src_name_to_die.Find(dst_name, NULL); | 
|  | 5317 |  | 
|  | 5318 | if (src_die && (src_die->Tag() == dst_die->Tag())) | 
|  | 5319 | { | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5320 | 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] | 5321 | if (src_decl_ctx) | 
|  | 5322 | { | 
|  | 5323 | if (log) | 
|  | 5324 | log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset()); | 
|  | 5325 | LinkDeclContextToDIE (src_decl_ctx, dst_die); | 
|  | 5326 | } | 
|  | 5327 | else | 
|  | 5328 | { | 
|  | 5329 | if (log) | 
|  | 5330 | 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()); | 
|  | 5331 | } | 
|  | 5332 |  | 
|  | 5333 | Type *src_child_type = m_die_to_type[src_die]; | 
|  | 5334 | if (src_child_type) | 
|  | 5335 | { | 
|  | 5336 | if (log) | 
|  | 5337 | log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", src_child_type, src_child_type->GetID(), src_die->GetOffset(), dst_die->GetOffset()); | 
|  | 5338 | m_die_to_type[dst_die] = src_child_type; | 
|  | 5339 | } | 
|  | 5340 | else | 
|  | 5341 | { | 
|  | 5342 | if (log) | 
|  | 5343 | 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()); | 
|  | 5344 | } | 
|  | 5345 | } | 
|  | 5346 | else | 
|  | 5347 | { | 
|  | 5348 | if (log) | 
|  | 5349 | 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] | 5350 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5351 | failures.push_back(dst_die); | 
|  | 5352 | } | 
|  | 5353 | } | 
|  | 5354 | } | 
|  | 5355 | } | 
|  | 5356 |  | 
|  | 5357 | const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize (); | 
|  | 5358 | const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize (); | 
|  | 5359 |  | 
|  | 5360 | UniqueCStringMap<const DWARFDebugInfoEntry *> name_to_die_artificial_not_in_src; | 
|  | 5361 |  | 
|  | 5362 | if (src_size_artificial && dst_size_artificial) | 
|  | 5363 | { | 
|  | 5364 | dst_name_to_die_artificial.Sort(); | 
|  | 5365 |  | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5366 | for (idx = 0; idx < src_size_artificial; ++idx) | 
|  | 5367 | { | 
|  | 5368 | const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx); | 
|  | 5369 | src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx); | 
|  | 5370 | dst_die = dst_name_to_die_artificial.Find(src_name_artificial, NULL); | 
|  | 5371 |  | 
|  | 5372 | if (dst_die) | 
|  | 5373 | { | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5374 | // Both classes have the artificial types, link them | 
|  | 5375 | clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die]; | 
|  | 5376 | if (src_decl_ctx) | 
|  | 5377 | { | 
|  | 5378 | if (log) | 
|  | 5379 | log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset()); | 
|  | 5380 | LinkDeclContextToDIE (src_decl_ctx, dst_die); | 
|  | 5381 | } | 
|  | 5382 | else | 
|  | 5383 | { | 
|  | 5384 | if (log) | 
|  | 5385 | 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()); | 
|  | 5386 | } | 
|  | 5387 |  | 
|  | 5388 | Type *src_child_type = m_die_to_type[src_die]; | 
|  | 5389 | if (src_child_type) | 
|  | 5390 | { | 
|  | 5391 | if (log) | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5392 | log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", src_child_type, src_child_type->GetID(), src_die->GetOffset(), dst_die->GetOffset()); | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5393 | m_die_to_type[dst_die] = src_child_type; | 
|  | 5394 | } | 
|  | 5395 | else | 
|  | 5396 | { | 
|  | 5397 | if (log) | 
|  | 5398 | 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()); | 
|  | 5399 | } | 
|  | 5400 | } | 
|  | 5401 | } | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5402 | } | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5403 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5404 | if (dst_size_artificial) | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5405 | { | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5406 | for (idx = 0; idx < dst_size_artificial; ++idx) | 
|  | 5407 | { | 
|  | 5408 | const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx); | 
|  | 5409 | dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx); | 
|  | 5410 | if (log) | 
|  | 5411 | log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die->GetOffset(), dst_name_artificial); | 
|  | 5412 |  | 
|  | 5413 | failures.push_back(dst_die); | 
|  | 5414 | } | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5415 | } | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5416 |  | 
|  | 5417 | return (failures.size() != 0); | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5418 | } | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5419 |  | 
|  | 5420 | TypeSP | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5421 | 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] | 5422 | { | 
|  | 5423 | TypeSP type_sp; | 
|  | 5424 |  | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5425 | if (type_is_new_ptr) | 
|  | 5426 | *type_is_new_ptr = false; | 
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5427 |  | 
|  | 5428 | #if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE) | 
|  | 5429 | static DIEStack g_die_stack; | 
|  | 5430 | DIEStack::ScopedPopper scoped_die_logger(g_die_stack); | 
|  | 5431 | #endif | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5432 |  | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 5433 | AccessType accessibility = eAccessNone; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5434 | if (die != NULL) | 
|  | 5435 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5436 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5437 | if (log) | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5438 | { | 
|  | 5439 | const DWARFDebugInfoEntry *context_die; | 
|  | 5440 | clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die); | 
|  | 5441 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5442 | GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x, decl_ctx = %p (die 0x%8.8x)) %s name = '%s')", | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5443 | die->GetOffset(), | 
|  | 5444 | context, | 
|  | 5445 | context_die->GetOffset(), | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5446 | DW_TAG_value_to_name(die->Tag()), | 
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5447 | die->GetName(this, dwarf_cu)); | 
|  | 5448 |  | 
|  | 5449 | #if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE) | 
|  | 5450 | scoped_die_logger.Push (dwarf_cu, die); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5451 | g_die_stack.LogDIEs(log, this); | 
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5452 | #endif | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5453 | } | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5454 | // | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5455 | //        Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5456 | //        if (log && dwarf_cu) | 
|  | 5457 | //        { | 
|  | 5458 | //            StreamString s; | 
|  | 5459 | //            die->DumpLocation (this, dwarf_cu, s); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5460 | //            GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData()); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5461 | // | 
|  | 5462 | //        } | 
| Jim Ingham | 16746d1 | 2011-08-25 23:21:43 +0000 | [diff] [blame] | 5463 |  | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5464 | Type *type_ptr = m_die_to_type.lookup (die); | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5465 | TypeList* type_list = GetTypeList(); | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5466 | if (type_ptr == NULL) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5467 | { | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5468 | ClangASTContext &ast = GetClangASTContext(); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5469 | if (type_is_new_ptr) | 
|  | 5470 | *type_is_new_ptr = true; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5471 |  | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5472 | const dw_tag_t tag = die->Tag(); | 
|  | 5473 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5474 | bool is_forward_declaration = false; | 
|  | 5475 | DWARFDebugInfoEntry::Attributes attributes; | 
|  | 5476 | const char *type_name_cstr = NULL; | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5477 | ConstString type_name_const_str; | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5478 | Type::ResolveState resolve_state = Type::eResolveStateUnresolved; | 
| Greg Clayton | faac111 | 2013-03-14 18:31:44 +0000 | [diff] [blame] | 5479 | uint64_t byte_size = 0; | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5480 | Declaration decl; | 
|  | 5481 |  | 
| Greg Clayton | 4957bf6 | 2010-09-30 21:49:03 +0000 | [diff] [blame] | 5482 | Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID; | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5483 | clang_type_t clang_type = NULL; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5484 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5485 | dw_attr_t attr; | 
|  | 5486 |  | 
|  | 5487 | switch (tag) | 
|  | 5488 | { | 
|  | 5489 | case DW_TAG_base_type: | 
|  | 5490 | case DW_TAG_pointer_type: | 
|  | 5491 | case DW_TAG_reference_type: | 
| Sean Callanan | ce8af86 | 2012-05-21 23:31:51 +0000 | [diff] [blame] | 5492 | case DW_TAG_rvalue_reference_type: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5493 | case DW_TAG_typedef: | 
|  | 5494 | case DW_TAG_const_type: | 
|  | 5495 | case DW_TAG_restrict_type: | 
|  | 5496 | case DW_TAG_volatile_type: | 
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5497 | case DW_TAG_unspecified_type: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5498 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5499 | // 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] | 5500 | m_die_to_type[die] = DIE_IS_BEING_PARSED; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5501 |  | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5502 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5503 | uint32_t encoding = 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5504 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; | 
|  | 5505 |  | 
|  | 5506 | if (num_attributes > 0) | 
|  | 5507 | { | 
|  | 5508 | uint32_t i; | 
|  | 5509 | for (i=0; i<num_attributes; ++i) | 
|  | 5510 | { | 
|  | 5511 | attr = attributes.AttributeAtIndex(i); | 
|  | 5512 | DWARFFormValue form_value; | 
|  | 5513 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 5514 | { | 
|  | 5515 | switch (attr) | 
|  | 5516 | { | 
|  | 5517 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 5518 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 5519 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 5520 | case DW_AT_name: | 
| Jim Ingham | 337030f | 2011-04-15 23:41:23 +0000 | [diff] [blame] | 5521 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5522 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); | 
| Jim Ingham | 337030f | 2011-04-15 23:41:23 +0000 | [diff] [blame] | 5523 | // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't | 
|  | 5524 | // include the "&"... | 
|  | 5525 | if (tag == DW_TAG_reference_type) | 
|  | 5526 | { | 
|  | 5527 | if (strchr (type_name_cstr, '&') == NULL) | 
|  | 5528 | type_name_cstr = NULL; | 
|  | 5529 | } | 
|  | 5530 | if (type_name_cstr) | 
|  | 5531 | type_name_const_str.SetCString(type_name_cstr); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5532 | break; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 5533 | case DW_AT_byte_size:   byte_size = form_value.Unsigned(); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5534 | case DW_AT_encoding:    encoding = form_value.Unsigned(); break; | 
|  | 5535 | case DW_AT_type:        encoding_uid = form_value.Reference(dwarf_cu); break; | 
|  | 5536 | default: | 
|  | 5537 | case DW_AT_sibling: | 
|  | 5538 | break; | 
|  | 5539 | } | 
|  | 5540 | } | 
|  | 5541 | } | 
|  | 5542 | } | 
|  | 5543 |  | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5544 | DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\") type => 0x%8.8x\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr, encoding_uid); | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 5545 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5546 | switch (tag) | 
|  | 5547 | { | 
|  | 5548 | default: | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5549 | break; | 
|  | 5550 |  | 
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5551 | case DW_TAG_unspecified_type: | 
|  | 5552 | if (strcmp(type_name_cstr, "nullptr_t") == 0) | 
|  | 5553 | { | 
|  | 5554 | resolve_state = Type::eResolveStateFull; | 
|  | 5555 | clang_type = ast.getASTContext()->NullPtrTy.getAsOpaquePtr(); | 
|  | 5556 | break; | 
|  | 5557 | } | 
|  | 5558 | // Fall through to base type below in case we can handle the type there... | 
|  | 5559 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5560 | case DW_TAG_base_type: | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5561 | resolve_state = Type::eResolveStateFull; | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5562 | clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr, | 
|  | 5563 | encoding, | 
|  | 5564 | byte_size * 8); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5565 | break; | 
|  | 5566 |  | 
| Sean Callanan | ce8af86 | 2012-05-21 23:31:51 +0000 | [diff] [blame] | 5567 | case DW_TAG_pointer_type:           encoding_data_type = Type::eEncodingIsPointerUID;           break; | 
|  | 5568 | case DW_TAG_reference_type:         encoding_data_type = Type::eEncodingIsLValueReferenceUID;   break; | 
|  | 5569 | case DW_TAG_rvalue_reference_type:  encoding_data_type = Type::eEncodingIsRValueReferenceUID;   break; | 
|  | 5570 | case DW_TAG_typedef:                encoding_data_type = Type::eEncodingIsTypedefUID;           break; | 
|  | 5571 | case DW_TAG_const_type:             encoding_data_type = Type::eEncodingIsConstUID;             break; | 
|  | 5572 | case DW_TAG_restrict_type:          encoding_data_type = Type::eEncodingIsRestrictUID;          break; | 
|  | 5573 | case DW_TAG_volatile_type:          encoding_data_type = Type::eEncodingIsVolatileUID;          break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5574 | } | 
|  | 5575 |  | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5576 | if (clang_type == NULL && (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] | 5577 | { | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5578 | bool translation_unit_is_objc = (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus); | 
|  | 5579 |  | 
|  | 5580 | if (translation_unit_is_objc) | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 5581 | { | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5582 | if (type_name_cstr != NULL) | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5583 | { | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5584 | static ConstString g_objc_type_name_id("id"); | 
|  | 5585 | static ConstString g_objc_type_name_Class("Class"); | 
|  | 5586 | static ConstString g_objc_type_name_selector("SEL"); | 
|  | 5587 |  | 
|  | 5588 | if (type_name_const_str == g_objc_type_name_id) | 
|  | 5589 | { | 
|  | 5590 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5591 | 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] | 5592 | die->GetOffset(), | 
|  | 5593 | DW_TAG_value_to_name(die->Tag()), | 
|  | 5594 | die->GetName(this, dwarf_cu)); | 
|  | 5595 | clang_type = ast.GetBuiltInType_objc_id(); | 
|  | 5596 | encoding_data_type = Type::eEncodingIsUID; | 
|  | 5597 | encoding_uid = LLDB_INVALID_UID; | 
|  | 5598 | resolve_state = Type::eResolveStateFull; | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5599 |  | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5600 | } | 
|  | 5601 | else if (type_name_const_str == g_objc_type_name_Class) | 
|  | 5602 | { | 
|  | 5603 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5604 | 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] | 5605 | die->GetOffset(), | 
|  | 5606 | DW_TAG_value_to_name(die->Tag()), | 
|  | 5607 | die->GetName(this, dwarf_cu)); | 
|  | 5608 | clang_type = ast.GetBuiltInType_objc_Class(); | 
|  | 5609 | encoding_data_type = Type::eEncodingIsUID; | 
|  | 5610 | encoding_uid = LLDB_INVALID_UID; | 
|  | 5611 | resolve_state = Type::eResolveStateFull; | 
|  | 5612 | } | 
|  | 5613 | else if (type_name_const_str == g_objc_type_name_selector) | 
|  | 5614 | { | 
|  | 5615 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5616 | 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] | 5617 | die->GetOffset(), | 
|  | 5618 | DW_TAG_value_to_name(die->Tag()), | 
|  | 5619 | die->GetName(this, dwarf_cu)); | 
|  | 5620 | clang_type = ast.GetBuiltInType_objc_selector(); | 
|  | 5621 | encoding_data_type = Type::eEncodingIsUID; | 
|  | 5622 | encoding_uid = LLDB_INVALID_UID; | 
|  | 5623 | resolve_state = Type::eResolveStateFull; | 
|  | 5624 | } | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5625 | } | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5626 | else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid != LLDB_INVALID_UID) | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5627 | { | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5628 | // Clang sometimes erroneously emits id as objc_object*.  In that case we fix up the type to "id". | 
|  | 5629 |  | 
|  | 5630 | DWARFDebugInfoEntry* encoding_die = dwarf_cu->GetDIEPtr(encoding_uid); | 
|  | 5631 |  | 
|  | 5632 | if (encoding_die && encoding_die->Tag() == DW_TAG_structure_type) | 
|  | 5633 | { | 
|  | 5634 | if (const char *struct_name = encoding_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL)) | 
|  | 5635 | { | 
|  | 5636 | if (!strcmp(struct_name, "objc_object")) | 
|  | 5637 | { | 
|  | 5638 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5639 | 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] | 5640 | die->GetOffset(), | 
|  | 5641 | DW_TAG_value_to_name(die->Tag()), | 
|  | 5642 | die->GetName(this, dwarf_cu)); | 
|  | 5643 | clang_type = ast.GetBuiltInType_objc_id(); | 
|  | 5644 | encoding_data_type = Type::eEncodingIsUID; | 
|  | 5645 | encoding_uid = LLDB_INVALID_UID; | 
|  | 5646 | resolve_state = Type::eResolveStateFull; | 
|  | 5647 | } | 
|  | 5648 | } | 
|  | 5649 | } | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5650 | } | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 5651 | } | 
|  | 5652 | } | 
|  | 5653 |  | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5654 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5655 | this, | 
|  | 5656 | type_name_const_str, | 
|  | 5657 | byte_size, | 
|  | 5658 | NULL, | 
|  | 5659 | encoding_uid, | 
|  | 5660 | encoding_data_type, | 
|  | 5661 | &decl, | 
|  | 5662 | clang_type, | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5663 | resolve_state)); | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5664 |  | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5665 | m_die_to_type[die] = type_sp.get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5666 |  | 
|  | 5667 | //                  Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false); | 
|  | 5668 | //                  if (encoding_type != NULL) | 
|  | 5669 | //                  { | 
|  | 5670 | //                      if (encoding_type != DIE_IS_BEING_PARSED) | 
|  | 5671 | //                          type_sp->SetEncodingType(encoding_type); | 
|  | 5672 | //                      else | 
|  | 5673 | //                          m_indirect_fixups.push_back(type_sp.get()); | 
|  | 5674 | //                  } | 
|  | 5675 | } | 
|  | 5676 | break; | 
|  | 5677 |  | 
|  | 5678 | case DW_TAG_structure_type: | 
|  | 5679 | case DW_TAG_union_type: | 
|  | 5680 | case DW_TAG_class_type: | 
|  | 5681 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5682 | // 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] | 5683 | m_die_to_type[die] = DIE_IS_BEING_PARSED; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 5684 | bool byte_size_valid = false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5685 |  | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5686 | LanguageType class_language = eLanguageTypeUnknown; | 
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 5687 | bool is_complete_objc_class = false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5688 | //bool struct_is_class = false; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5689 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5690 | if (num_attributes > 0) | 
|  | 5691 | { | 
|  | 5692 | uint32_t i; | 
|  | 5693 | for (i=0; i<num_attributes; ++i) | 
|  | 5694 | { | 
|  | 5695 | attr = attributes.AttributeAtIndex(i); | 
|  | 5696 | DWARFFormValue form_value; | 
|  | 5697 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 5698 | { | 
|  | 5699 | switch (attr) | 
|  | 5700 | { | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5701 | case DW_AT_decl_file: | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5702 | if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid()) | 
|  | 5703 | { | 
|  | 5704 | // llvm-gcc outputs invalid DW_AT_decl_file attributes that always | 
|  | 5705 | // point to the compile unit file, so we clear this invalid value | 
|  | 5706 | // so that we can still unique types efficiently. | 
|  | 5707 | decl.SetFile(FileSpec ("<invalid>", false)); | 
|  | 5708 | } | 
|  | 5709 | else | 
|  | 5710 | decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5711 | break; | 
|  | 5712 |  | 
|  | 5713 | case DW_AT_decl_line: | 
|  | 5714 | decl.SetLine(form_value.Unsigned()); | 
|  | 5715 | break; | 
|  | 5716 |  | 
|  | 5717 | case DW_AT_decl_column: | 
|  | 5718 | decl.SetColumn(form_value.Unsigned()); | 
|  | 5719 | break; | 
|  | 5720 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5721 | case DW_AT_name: | 
|  | 5722 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5723 | type_name_const_str.SetCString(type_name_cstr); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5724 | break; | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5725 |  | 
|  | 5726 | case DW_AT_byte_size: | 
|  | 5727 | byte_size = form_value.Unsigned(); | 
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 5728 | byte_size_valid = true; | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5729 | break; | 
|  | 5730 |  | 
|  | 5731 | case DW_AT_accessibility: | 
|  | 5732 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); | 
|  | 5733 | break; | 
|  | 5734 |  | 
|  | 5735 | case DW_AT_declaration: | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 5736 | is_forward_declaration = form_value.Boolean(); | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5737 | break; | 
|  | 5738 |  | 
|  | 5739 | case DW_AT_APPLE_runtime_class: | 
|  | 5740 | class_language = (LanguageType)form_value.Signed(); | 
|  | 5741 | break; | 
|  | 5742 |  | 
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 5743 | case DW_AT_APPLE_objc_complete_type: | 
|  | 5744 | is_complete_objc_class = form_value.Signed(); | 
|  | 5745 | break; | 
|  | 5746 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5747 | case DW_AT_allocated: | 
|  | 5748 | case DW_AT_associated: | 
|  | 5749 | case DW_AT_data_location: | 
|  | 5750 | case DW_AT_description: | 
|  | 5751 | case DW_AT_start_scope: | 
|  | 5752 | case DW_AT_visibility: | 
|  | 5753 | default: | 
|  | 5754 | case DW_AT_sibling: | 
|  | 5755 | break; | 
|  | 5756 | } | 
|  | 5757 | } | 
|  | 5758 | } | 
|  | 5759 | } | 
|  | 5760 |  | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5761 | UniqueDWARFASTType unique_ast_entry; | 
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5762 |  | 
| Greg Clayton | 123edca | 2012-03-02 00:07:15 +0000 | [diff] [blame] | 5763 | // Only try and unique the type if it has a name. | 
|  | 5764 | if (type_name_const_str && | 
|  | 5765 | GetUniqueDWARFASTTypeMap().Find (type_name_const_str, | 
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5766 | this, | 
|  | 5767 | dwarf_cu, | 
|  | 5768 | die, | 
|  | 5769 | decl, | 
|  | 5770 | byte_size_valid ? byte_size : -1, | 
|  | 5771 | unique_ast_entry)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5772 | { | 
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5773 | // We have already parsed this type or from another | 
|  | 5774 | // compile unit. GCC loves to use the "one definition | 
|  | 5775 | // rule" which can result in multiple definitions | 
|  | 5776 | // of the same class over and over in each compile | 
|  | 5777 | // unit. | 
|  | 5778 | type_sp = unique_ast_entry.m_type_sp; | 
|  | 5779 | if (type_sp) | 
| Greg Clayton | c615ce4 | 2010-11-09 04:42:43 +0000 | [diff] [blame] | 5780 | { | 
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5781 | m_die_to_type[die] = type_sp.get(); | 
|  | 5782 | return type_sp; | 
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5783 | } | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5784 | } | 
|  | 5785 |  | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5786 | 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] | 5787 |  | 
|  | 5788 | int tag_decl_kind = -1; | 
|  | 5789 | AccessType default_accessibility = eAccessNone; | 
|  | 5790 | if (tag == DW_TAG_structure_type) | 
|  | 5791 | { | 
|  | 5792 | tag_decl_kind = clang::TTK_Struct; | 
|  | 5793 | default_accessibility = eAccessPublic; | 
|  | 5794 | } | 
|  | 5795 | else if (tag == DW_TAG_union_type) | 
|  | 5796 | { | 
|  | 5797 | tag_decl_kind = clang::TTK_Union; | 
|  | 5798 | default_accessibility = eAccessPublic; | 
|  | 5799 | } | 
|  | 5800 | else if (tag == DW_TAG_class_type) | 
|  | 5801 | { | 
|  | 5802 | tag_decl_kind = clang::TTK_Class; | 
|  | 5803 | default_accessibility = eAccessPrivate; | 
|  | 5804 | } | 
| Greg Clayton | 3a5f29a | 2011-11-30 02:48:28 +0000 | [diff] [blame] | 5805 |  | 
|  | 5806 | if (byte_size_valid && byte_size == 0 && type_name_cstr && | 
|  | 5807 | die->HasChildren() == false && | 
|  | 5808 | sc.comp_unit->GetLanguage() == eLanguageTypeObjC) | 
|  | 5809 | { | 
|  | 5810 | // Work around an issue with clang at the moment where | 
|  | 5811 | // forward declarations for objective C classes are emitted | 
|  | 5812 | // as: | 
|  | 5813 | //  DW_TAG_structure_type [2] | 
|  | 5814 | //  DW_AT_name( "ForwardObjcClass" ) | 
|  | 5815 | //  DW_AT_byte_size( 0x00 ) | 
|  | 5816 | //  DW_AT_decl_file( "..." ) | 
|  | 5817 | //  DW_AT_decl_line( 1 ) | 
|  | 5818 | // | 
|  | 5819 | // Note that there is no DW_AT_declaration and there are | 
|  | 5820 | // no children, and the byte size is zero. | 
|  | 5821 | is_forward_declaration = true; | 
|  | 5822 | } | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5823 |  | 
| Sean Callanan | 7457f8d | 2012-04-25 01:03:57 +0000 | [diff] [blame] | 5824 | if (class_language == eLanguageTypeObjC || | 
|  | 5825 | class_language == eLanguageTypeObjC_plus_plus) | 
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 5826 | { | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5827 | 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] | 5828 | { | 
|  | 5829 | // We have a valid eSymbolTypeObjCClass class symbol whose | 
|  | 5830 | // name matches the current objective C class that we | 
|  | 5831 | // are trying to find and this DIE isn't the complete | 
|  | 5832 | // definition (we checked is_complete_objc_class above and | 
|  | 5833 | // know it is false), so the real definition is in here somewhere | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5834 | type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true); | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5835 |  | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 5836 | if (!type_sp && GetDebugMapSymfile ()) | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5837 | { | 
|  | 5838 | // We weren't able to find a full declaration in | 
|  | 5839 | // this DWARF, see if we have a declaration anywhere | 
|  | 5840 | // else... | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5841 | 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] | 5842 | } | 
|  | 5843 |  | 
|  | 5844 | if (type_sp) | 
|  | 5845 | { | 
|  | 5846 | if (log) | 
|  | 5847 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5848 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5849 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an incomplete objc type, complete type is 0x%8.8" PRIx64, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5850 | this, | 
|  | 5851 | die->GetOffset(), | 
|  | 5852 | DW_TAG_value_to_name(tag), | 
|  | 5853 | type_name_cstr, | 
|  | 5854 | type_sp->GetID()); | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5855 | } | 
|  | 5856 |  | 
|  | 5857 | // We found a real definition for this type elsewhere | 
|  | 5858 | // so lets use it and cache the fact that we found | 
|  | 5859 | // a complete type for this die | 
|  | 5860 | m_die_to_type[die] = type_sp.get(); | 
|  | 5861 | return type_sp; | 
|  | 5862 | } | 
|  | 5863 | } | 
|  | 5864 | } | 
|  | 5865 |  | 
|  | 5866 |  | 
|  | 5867 | if (is_forward_declaration) | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5868 | { | 
|  | 5869 | // We have a forward declaration to a type and we need | 
|  | 5870 | // to try and find a full declaration. We look in the | 
|  | 5871 | // current type index just in case we have a forward | 
|  | 5872 | // declaration followed by an actual declarations in the | 
|  | 5873 | // DWARF. If this fails, we need to look elsewhere... | 
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 5874 | if (log) | 
|  | 5875 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5876 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5877 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type", | 
|  | 5878 | this, | 
|  | 5879 | die->GetOffset(), | 
|  | 5880 | DW_TAG_value_to_name(tag), | 
|  | 5881 | type_name_cstr); | 
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 5882 | } | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5883 |  | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5884 | DWARFDeclContext die_decl_ctx; | 
|  | 5885 | die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx); | 
|  | 5886 |  | 
|  | 5887 | //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str); | 
|  | 5888 | type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5889 |  | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 5890 | if (!type_sp && GetDebugMapSymfile ()) | 
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5891 | { | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5892 | // We weren't able to find a full declaration in | 
|  | 5893 | // this DWARF, see if we have a declaration anywhere | 
|  | 5894 | // else... | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5895 | type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); | 
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5896 | } | 
|  | 5897 |  | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5898 | if (type_sp) | 
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5899 | { | 
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 5900 | if (log) | 
|  | 5901 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5902 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5903 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8" PRIx64, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5904 | this, | 
|  | 5905 | die->GetOffset(), | 
|  | 5906 | DW_TAG_value_to_name(tag), | 
|  | 5907 | type_name_cstr, | 
|  | 5908 | type_sp->GetID()); | 
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 5909 | } | 
|  | 5910 |  | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5911 | // We found a real definition for this type elsewhere | 
|  | 5912 | // so lets use it and cache the fact that we found | 
|  | 5913 | // a complete type for this die | 
|  | 5914 | m_die_to_type[die] = type_sp.get(); | 
|  | 5915 | return type_sp; | 
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5916 | } | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5917 | } | 
|  | 5918 | assert (tag_decl_kind != -1); | 
|  | 5919 | bool clang_type_was_created = false; | 
|  | 5920 | clang_type = m_forward_decl_die_to_clang_type.lookup (die); | 
|  | 5921 | if (clang_type == NULL) | 
|  | 5922 | { | 
| Sean Callanan | 4d04c6a | 2012-02-09 22:54:11 +0000 | [diff] [blame] | 5923 | const DWARFDebugInfoEntry *decl_ctx_die; | 
|  | 5924 |  | 
|  | 5925 | clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die); | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 5926 | if (accessibility == eAccessNone && decl_ctx) | 
|  | 5927 | { | 
|  | 5928 | // Check the decl context that contains this class/struct/union. | 
|  | 5929 | // If it is a class we must give it an accessability. | 
|  | 5930 | const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind(); | 
|  | 5931 | if (DeclKindIsCXXClass (containing_decl_kind)) | 
|  | 5932 | accessibility = default_accessibility; | 
|  | 5933 | } | 
|  | 5934 |  | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 5935 | ClangASTMetadata metadata; | 
|  | 5936 | metadata.SetUserID(MakeUserID(die->GetOffset())); | 
|  | 5937 | metadata.SetIsDynamicCXXType(ClassOrStructIsVirtual (dwarf_cu, die)); | 
|  | 5938 |  | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5939 | if (type_name_cstr && strchr (type_name_cstr, '<')) | 
|  | 5940 | { | 
|  | 5941 | ClangASTContext::TemplateParameterInfos template_param_infos; | 
|  | 5942 | if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos)) | 
|  | 5943 | { | 
|  | 5944 | clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx, | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 5945 | accessibility, | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5946 | type_name_cstr, | 
|  | 5947 | tag_decl_kind, | 
|  | 5948 | template_param_infos); | 
|  | 5949 |  | 
|  | 5950 | clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx, | 
|  | 5951 | class_template_decl, | 
|  | 5952 | tag_decl_kind, | 
|  | 5953 | template_param_infos); | 
|  | 5954 | clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl); | 
|  | 5955 | clang_type_was_created = true; | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 5956 |  | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 5957 | GetClangASTContext().SetMetadata (class_template_decl, metadata); | 
|  | 5958 | GetClangASTContext().SetMetadata (class_specialization_decl, metadata); | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5959 | } | 
|  | 5960 | } | 
|  | 5961 |  | 
|  | 5962 | if (!clang_type_was_created) | 
|  | 5963 | { | 
|  | 5964 | clang_type_was_created = true; | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 5965 | clang_type = ast.CreateRecordType (decl_ctx, | 
|  | 5966 | accessibility, | 
|  | 5967 | type_name_cstr, | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5968 | tag_decl_kind, | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 5969 | class_language, | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 5970 | &metadata); | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5971 | } | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5972 | } | 
|  | 5973 |  | 
|  | 5974 | // Store a forward declaration to this class type in case any | 
|  | 5975 | // parameters in any class methods need it for the clang | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 5976 | // types for function prototypes. | 
|  | 5977 | LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die); | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5978 | type_sp.reset (new Type (MakeUserID(die->GetOffset()), | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5979 | this, | 
|  | 5980 | type_name_const_str, | 
|  | 5981 | byte_size, | 
|  | 5982 | NULL, | 
|  | 5983 | LLDB_INVALID_UID, | 
|  | 5984 | Type::eEncodingIsUID, | 
|  | 5985 | &decl, | 
|  | 5986 | clang_type, | 
|  | 5987 | Type::eResolveStateForward)); | 
| Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 5988 |  | 
|  | 5989 | type_sp->SetIsCompleteObjCClass(is_complete_objc_class); | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5990 |  | 
|  | 5991 |  | 
|  | 5992 | // Add our type to the unique type map so we don't | 
|  | 5993 | // end up creating many copies of the same type over | 
|  | 5994 | // and over in the ASTContext for our module | 
|  | 5995 | unique_ast_entry.m_type_sp = type_sp; | 
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 5996 | unique_ast_entry.m_symfile = this; | 
|  | 5997 | unique_ast_entry.m_cu = dwarf_cu; | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5998 | unique_ast_entry.m_die = die; | 
|  | 5999 | unique_ast_entry.m_declaration = decl; | 
| Sean Callanan | 5970059 | 2012-02-13 22:30:16 +0000 | [diff] [blame] | 6000 | unique_ast_entry.m_byte_size = byte_size; | 
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 6001 | GetUniqueDWARFASTTypeMap().Insert (type_name_const_str, | 
|  | 6002 | unique_ast_entry); | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6003 |  | 
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6004 | if (!is_forward_declaration) | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 6005 | { | 
|  | 6006 | // Always start the definition for a class type so that | 
|  | 6007 | // if the class has child classes or types that require | 
|  | 6008 | // the class to be created for use as their decl contexts | 
|  | 6009 | // the class will be ready to accept these child definitions. | 
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6010 | if (die->HasChildren() == false) | 
|  | 6011 | { | 
|  | 6012 | // No children for this struct/union/class, lets finish it | 
|  | 6013 | ast.StartTagDeclarationDefinition (clang_type); | 
|  | 6014 | ast.CompleteTagDeclarationDefinition (clang_type); | 
| Sean Callanan | 433cd22 | 2012-10-19 01:37:25 +0000 | [diff] [blame] | 6015 |  | 
|  | 6016 | if (tag == DW_TAG_structure_type) // this only applies in C | 
|  | 6017 | { | 
|  | 6018 | clang::QualType qual_type = clang::QualType::getFromOpaquePtr (clang_type); | 
|  | 6019 | const clang::RecordType *record_type = qual_type->getAs<clang::RecordType> (); | 
|  | 6020 |  | 
|  | 6021 | if (record_type) | 
|  | 6022 | { | 
|  | 6023 | clang::RecordDecl *record_decl = record_type->getDecl(); | 
|  | 6024 |  | 
|  | 6025 | if (record_decl) | 
|  | 6026 | { | 
|  | 6027 | LayoutInfo layout_info; | 
|  | 6028 |  | 
|  | 6029 | layout_info.alignment = 0; | 
|  | 6030 | layout_info.bit_size = 0; | 
|  | 6031 |  | 
|  | 6032 | m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info)); | 
|  | 6033 | } | 
|  | 6034 | } | 
|  | 6035 | } | 
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6036 | } | 
|  | 6037 | else if (clang_type_was_created) | 
|  | 6038 | { | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 6039 | // Start the definition if the class is not objective C since | 
|  | 6040 | // the underlying decls respond to isCompleteDefinition(). Objective | 
|  | 6041 | // C decls dont' respond to isCompleteDefinition() so we can't | 
|  | 6042 | // start the declaration definition right away. For C++ classs/union/structs | 
|  | 6043 | // we want to start the definition in case the class is needed as the | 
|  | 6044 | // declaration context for a contained class or type without the need | 
|  | 6045 | // to complete that type.. | 
|  | 6046 |  | 
| Sean Callanan | 7457f8d | 2012-04-25 01:03:57 +0000 | [diff] [blame] | 6047 | if (class_language != eLanguageTypeObjC && | 
|  | 6048 | class_language != eLanguageTypeObjC_plus_plus) | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 6049 | ast.StartTagDeclarationDefinition (clang_type); | 
|  | 6050 |  | 
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6051 | // Leave this as a forward declaration until we need | 
|  | 6052 | // to know the details of the type. lldb_private::Type | 
|  | 6053 | // will automatically call the SymbolFile virtual function | 
|  | 6054 | // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)" | 
|  | 6055 | // When the definition needs to be defined. | 
|  | 6056 | m_forward_decl_die_to_clang_type[die] = clang_type; | 
|  | 6057 | m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die; | 
|  | 6058 | ClangASTContext::SetHasExternalStorage (clang_type, true); | 
|  | 6059 | } | 
| Greg Clayton | c615ce4 | 2010-11-09 04:42:43 +0000 | [diff] [blame] | 6060 | } | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 6061 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6062 | } | 
|  | 6063 | break; | 
|  | 6064 |  | 
|  | 6065 | case DW_TAG_enumeration_type: | 
|  | 6066 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6067 | // 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] | 6068 | m_die_to_type[die] = DIE_IS_BEING_PARSED; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6069 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6070 | lldb::user_id_t encoding_uid = DW_INVALID_OFFSET; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6071 |  | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6072 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6073 | if (num_attributes > 0) | 
|  | 6074 | { | 
|  | 6075 | uint32_t i; | 
|  | 6076 |  | 
|  | 6077 | for (i=0; i<num_attributes; ++i) | 
|  | 6078 | { | 
|  | 6079 | attr = attributes.AttributeAtIndex(i); | 
|  | 6080 | DWARFFormValue form_value; | 
|  | 6081 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 6082 | { | 
|  | 6083 | switch (attr) | 
|  | 6084 | { | 
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 6085 | case DW_AT_decl_file:       decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 6086 | case DW_AT_decl_line:       decl.SetLine(form_value.Unsigned()); break; | 
|  | 6087 | case DW_AT_decl_column:     decl.SetColumn(form_value.Unsigned()); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6088 | case DW_AT_name: | 
|  | 6089 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6090 | type_name_const_str.SetCString(type_name_cstr); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6091 | break; | 
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 6092 | case DW_AT_type:            encoding_uid = form_value.Reference(dwarf_cu); break; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6093 | case DW_AT_byte_size:       byte_size = form_value.Unsigned(); break; | 
|  | 6094 | 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] | 6095 | case DW_AT_declaration:     break; //is_forward_declaration = form_value.Boolean(); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6096 | case DW_AT_allocated: | 
|  | 6097 | case DW_AT_associated: | 
|  | 6098 | case DW_AT_bit_stride: | 
|  | 6099 | case DW_AT_byte_stride: | 
|  | 6100 | case DW_AT_data_location: | 
|  | 6101 | case DW_AT_description: | 
|  | 6102 | case DW_AT_start_scope: | 
|  | 6103 | case DW_AT_visibility: | 
|  | 6104 | case DW_AT_specification: | 
|  | 6105 | case DW_AT_abstract_origin: | 
|  | 6106 | case DW_AT_sibling: | 
|  | 6107 | break; | 
|  | 6108 | } | 
|  | 6109 | } | 
|  | 6110 | } | 
|  | 6111 |  | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6112 | 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] | 6113 |  | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6114 | clang_type_t enumerator_clang_type = NULL; | 
|  | 6115 | clang_type = m_forward_decl_die_to_clang_type.lookup (die); | 
|  | 6116 | if (clang_type == NULL) | 
|  | 6117 | { | 
| Greg Clayton | 5d14fc0 | 2013-03-06 06:23:54 +0000 | [diff] [blame] | 6118 | if (encoding_uid != DW_INVALID_OFFSET) | 
|  | 6119 | { | 
|  | 6120 | Type *enumerator_type = ResolveTypeUID(encoding_uid); | 
|  | 6121 | if (enumerator_type) | 
|  | 6122 | enumerator_clang_type = enumerator_type->GetClangFullType(); | 
|  | 6123 | } | 
|  | 6124 |  | 
|  | 6125 | if (enumerator_clang_type == NULL) | 
|  | 6126 | enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL, | 
|  | 6127 | DW_ATE_signed, | 
|  | 6128 | byte_size * 8); | 
|  | 6129 |  | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 6130 | clang_type = ast.CreateEnumerationType (type_name_cstr, | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6131 | GetClangDeclContextContainingDIE (dwarf_cu, die, NULL), | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 6132 | decl, | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6133 | enumerator_clang_type); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6134 | } | 
|  | 6135 | else | 
|  | 6136 | { | 
|  | 6137 | enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6138 | } | 
|  | 6139 |  | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6140 | LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die); | 
|  | 6141 |  | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6142 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6143 | this, | 
|  | 6144 | type_name_const_str, | 
|  | 6145 | byte_size, | 
|  | 6146 | NULL, | 
|  | 6147 | encoding_uid, | 
|  | 6148 | Type::eEncodingIsUID, | 
|  | 6149 | &decl, | 
|  | 6150 | clang_type, | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6151 | Type::eResolveStateForward)); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6152 |  | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 6153 | ast.StartTagDeclarationDefinition (clang_type); | 
|  | 6154 | if (die->HasChildren()) | 
|  | 6155 | { | 
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 6156 | SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); | 
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 6157 | bool is_signed = false; | 
| Greg Clayton | 5d14fc0 | 2013-03-06 06:23:54 +0000 | [diff] [blame] | 6158 | ast.IsIntegerType(enumerator_clang_type, is_signed); | 
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 6159 | 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] | 6160 | } | 
|  | 6161 | ast.CompleteTagDeclarationDefinition (clang_type); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6162 | } | 
|  | 6163 | } | 
|  | 6164 | break; | 
|  | 6165 |  | 
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 6166 | case DW_TAG_inlined_subroutine: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6167 | case DW_TAG_subprogram: | 
|  | 6168 | case DW_TAG_subroutine_type: | 
|  | 6169 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6170 | // 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] | 6171 | m_die_to_type[die] = DIE_IS_BEING_PARSED; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6172 |  | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6173 | //const char *mangled = NULL; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6174 | dw_offset_t type_die_offset = DW_INVALID_OFFSET; | 
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 6175 | bool is_variadic = false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6176 | bool is_inline = false; | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6177 | bool is_static = false; | 
|  | 6178 | bool is_virtual = false; | 
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6179 | bool is_explicit = false; | 
| Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 6180 | bool is_artificial = false; | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6181 | dw_offset_t specification_die_offset = DW_INVALID_OFFSET; | 
|  | 6182 | dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET; | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6183 | dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET; | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6184 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6185 | unsigned type_quals = 0; | 
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 6186 | clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6187 |  | 
|  | 6188 |  | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6189 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6190 | if (num_attributes > 0) | 
|  | 6191 | { | 
|  | 6192 | uint32_t i; | 
|  | 6193 | for (i=0; i<num_attributes; ++i) | 
|  | 6194 | { | 
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 6195 | attr = attributes.AttributeAtIndex(i); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6196 | DWARFFormValue form_value; | 
|  | 6197 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 6198 | { | 
|  | 6199 | switch (attr) | 
|  | 6200 | { | 
|  | 6201 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 6202 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 6203 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 6204 | case DW_AT_name: | 
|  | 6205 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6206 | type_name_const_str.SetCString(type_name_cstr); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6207 | break; | 
|  | 6208 |  | 
| Greg Clayton | 7141554 | 2012-12-08 00:24:40 +0000 | [diff] [blame] | 6209 | case DW_AT_linkage_name: | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6210 | case DW_AT_MIPS_linkage_name:   break; // mangled = form_value.AsCString(&get_debug_str_data()); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6211 | case DW_AT_type:                type_die_offset = form_value.Reference(dwarf_cu); break; | 
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 6212 | 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] | 6213 | case DW_AT_declaration:         break; // is_forward_declaration = form_value.Boolean(); break; | 
|  | 6214 | case DW_AT_inline:              is_inline = form_value.Boolean(); break; | 
|  | 6215 | case DW_AT_virtuality:          is_virtual = form_value.Boolean();  break; | 
|  | 6216 | case DW_AT_explicit:            is_explicit = form_value.Boolean();  break; | 
|  | 6217 | case DW_AT_artificial:          is_artificial = form_value.Boolean();  break; | 
| Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 6218 |  | 
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6219 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6220 | case DW_AT_external: | 
|  | 6221 | if (form_value.Unsigned()) | 
|  | 6222 | { | 
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 6223 | if (storage == clang::SC_None) | 
|  | 6224 | storage = clang::SC_Extern; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6225 | else | 
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 6226 | storage = clang::SC_PrivateExtern; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6227 | } | 
|  | 6228 | break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6229 |  | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6230 | case DW_AT_specification: | 
|  | 6231 | specification_die_offset = form_value.Reference(dwarf_cu); | 
|  | 6232 | break; | 
|  | 6233 |  | 
|  | 6234 | case DW_AT_abstract_origin: | 
|  | 6235 | abstract_origin_die_offset = form_value.Reference(dwarf_cu); | 
|  | 6236 | break; | 
|  | 6237 |  | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6238 | case DW_AT_object_pointer: | 
|  | 6239 | object_pointer_die_offset = form_value.Reference(dwarf_cu); | 
|  | 6240 | break; | 
|  | 6241 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6242 | case DW_AT_allocated: | 
|  | 6243 | case DW_AT_associated: | 
|  | 6244 | case DW_AT_address_class: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6245 | case DW_AT_calling_convention: | 
|  | 6246 | case DW_AT_data_location: | 
|  | 6247 | case DW_AT_elemental: | 
|  | 6248 | case DW_AT_entry_pc: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6249 | case DW_AT_frame_base: | 
|  | 6250 | case DW_AT_high_pc: | 
|  | 6251 | case DW_AT_low_pc: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6252 | case DW_AT_prototyped: | 
|  | 6253 | case DW_AT_pure: | 
|  | 6254 | case DW_AT_ranges: | 
|  | 6255 | case DW_AT_recursive: | 
|  | 6256 | case DW_AT_return_addr: | 
|  | 6257 | case DW_AT_segment: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6258 | case DW_AT_start_scope: | 
|  | 6259 | case DW_AT_static_link: | 
|  | 6260 | case DW_AT_trampoline: | 
|  | 6261 | case DW_AT_visibility: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6262 | case DW_AT_vtable_elem_location: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6263 | case DW_AT_description: | 
|  | 6264 | case DW_AT_sibling: | 
|  | 6265 | break; | 
|  | 6266 | } | 
|  | 6267 | } | 
|  | 6268 | } | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6269 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6270 |  | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6271 | std::string object_pointer_name; | 
|  | 6272 | if (object_pointer_die_offset != DW_INVALID_OFFSET) | 
|  | 6273 | { | 
|  | 6274 | // Get the name from the object pointer die | 
|  | 6275 | StreamString s; | 
|  | 6276 | if (DWARFDebugInfoEntry::GetName (this, dwarf_cu, object_pointer_die_offset, s)) | 
|  | 6277 | { | 
|  | 6278 | object_pointer_name.assign(s.GetData()); | 
|  | 6279 | } | 
|  | 6280 | } | 
|  | 6281 |  | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6282 | 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] | 6283 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6284 | clang_type_t return_clang_type = NULL; | 
|  | 6285 | Type *func_type = NULL; | 
|  | 6286 |  | 
|  | 6287 | if (type_die_offset != DW_INVALID_OFFSET) | 
|  | 6288 | func_type = ResolveTypeUID(type_die_offset); | 
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6289 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6290 | if (func_type) | 
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 6291 | return_clang_type = func_type->GetClangForwardType(); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6292 | else | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6293 | return_clang_type = ast.GetBuiltInType_void(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6294 |  | 
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6295 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6296 | std::vector<clang_type_t> function_param_types; | 
|  | 6297 | std::vector<clang::ParmVarDecl*> function_param_decls; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6298 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6299 | // Parse the function children for the parameters | 
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 6300 |  | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6301 | const DWARFDebugInfoEntry *decl_ctx_die = NULL; | 
|  | 6302 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die); | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6303 | const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind(); | 
|  | 6304 |  | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6305 | const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind); | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6306 | // Start off static. This will be set to false in ParseChildParameters(...) | 
|  | 6307 | // if we find a "this" paramters as the first parameter | 
|  | 6308 | if (is_cxx_method) | 
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 6309 | is_static = true; | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 6310 | ClangASTContext::TemplateParameterInfos template_param_infos; | 
|  | 6311 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6312 | if (die->HasChildren()) | 
|  | 6313 | { | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6314 | bool skip_artificial = true; | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6315 | ParseChildParameters (sc, | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6316 | containing_decl_ctx, | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6317 | dwarf_cu, | 
|  | 6318 | die, | 
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 6319 | skip_artificial, | 
|  | 6320 | is_static, | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6321 | type_list, | 
|  | 6322 | function_param_types, | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 6323 | function_param_decls, | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 6324 | type_quals, | 
|  | 6325 | template_param_infos); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6326 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6327 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6328 | // clang_type will get the function prototype clang type after this call | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6329 | clang_type = ast.CreateFunctionType (return_clang_type, | 
| Greg Clayton | 9cb25c4 | 2012-10-30 17:02:18 +0000 | [diff] [blame] | 6330 | function_param_types.data(), | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6331 | function_param_types.size(), | 
|  | 6332 | is_variadic, | 
|  | 6333 | type_quals); | 
|  | 6334 |  | 
| Sean Callanan | de9ce87 | 2013-05-09 23:13:13 +0000 | [diff] [blame] | 6335 | bool ignore_containing_context = false; | 
|  | 6336 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6337 | if (type_name_cstr) | 
|  | 6338 | { | 
|  | 6339 | bool type_handled = false; | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6340 | if (tag == DW_TAG_subprogram) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6341 | { | 
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 6342 | ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true); | 
|  | 6343 | if (objc_method.IsValid(true)) | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6344 | { | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6345 | SymbolContext empty_sc; | 
|  | 6346 | clang_type_t class_opaque_type = NULL; | 
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 6347 | ConstString class_name(objc_method.GetClassName()); | 
| Greg Clayton | 7c81042 | 2012-01-18 23:40:49 +0000 | [diff] [blame] | 6348 | if (class_name) | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6349 | { | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6350 | TypeList types; | 
| Greg Clayton | 278a16b | 2012-01-19 00:52:59 +0000 | [diff] [blame] | 6351 | TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false)); | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6352 |  | 
|  | 6353 | if (complete_objc_class_type_sp) | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6354 | { | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6355 | clang_type_t type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType(); | 
|  | 6356 | if (ClangASTContext::IsObjCClassType (type_clang_forward_type)) | 
|  | 6357 | class_opaque_type = type_clang_forward_type; | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6358 | } | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6359 | } | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6360 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6361 | if (class_opaque_type) | 
|  | 6362 | { | 
|  | 6363 | // If accessibility isn't set to anything valid, assume public for | 
|  | 6364 | // now... | 
|  | 6365 | if (accessibility == eAccessNone) | 
|  | 6366 | accessibility = eAccessPublic; | 
|  | 6367 |  | 
| Sean Callanan | 464a5b5 | 2012-10-04 22:06:29 +0000 | [diff] [blame] | 6368 | clang::ObjCMethodDecl *objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type, | 
|  | 6369 | type_name_cstr, | 
|  | 6370 | clang_type, | 
| Greg Clayton | 1bbcc03 | 2013-03-08 02:42:06 +0000 | [diff] [blame] | 6371 | accessibility, | 
|  | 6372 | is_artificial); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6373 | type_handled = objc_method_decl != NULL; | 
| Sean Callanan | 464a5b5 | 2012-10-04 22:06:29 +0000 | [diff] [blame] | 6374 | if (type_handled) | 
|  | 6375 | { | 
|  | 6376 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die); | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6377 | GetClangASTContext().SetMetadataAsUserID (objc_method_decl, MakeUserID(die->GetOffset())); | 
| Sean Callanan | 464a5b5 | 2012-10-04 22:06:29 +0000 | [diff] [blame] | 6378 | } | 
| Sean Callanan | c3a1d56 | 2013-02-06 23:21:59 +0000 | [diff] [blame] | 6379 | else | 
|  | 6380 | { | 
| Jason Molenda | c1a6583 | 2013-03-07 22:44:42 +0000 | [diff] [blame] | 6381 | 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] | 6382 | die->GetOffset(), | 
|  | 6383 | tag, | 
|  | 6384 | DW_TAG_value_to_name(tag)); | 
|  | 6385 | } | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6386 | } | 
|  | 6387 | } | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6388 | else if (is_cxx_method) | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6389 | { | 
|  | 6390 | // Look at the parent of this DIE and see if is is | 
|  | 6391 | // a class or struct and see if this is actually a | 
|  | 6392 | // C++ method | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6393 | Type *class_type = ResolveType (dwarf_cu, decl_ctx_die); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6394 | if (class_type) | 
|  | 6395 | { | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6396 | if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset())) | 
|  | 6397 | { | 
|  | 6398 | // We uniqued the parent class of this function to another class | 
|  | 6399 | // so we now need to associate all dies under "decl_ctx_die" to | 
|  | 6400 | // DIEs in the DIE for "class_type"... | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 6401 | SymbolFileDWARF *class_symfile = NULL; | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6402 | DWARFCompileUnitSP class_type_cu_sp; | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 6403 | const DWARFDebugInfoEntry *class_type_die = NULL; | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6404 |  | 
|  | 6405 | SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile(); | 
|  | 6406 | if (debug_map_symfile) | 
|  | 6407 | { | 
|  | 6408 | class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID())); | 
|  | 6409 | class_type_die = class_symfile->DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp); | 
|  | 6410 | } | 
|  | 6411 | else | 
|  | 6412 | { | 
|  | 6413 | class_symfile = this; | 
|  | 6414 | class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp); | 
|  | 6415 | } | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6416 | if (class_type_die) | 
|  | 6417 | { | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6418 | llvm::SmallVector<const DWARFDebugInfoEntry *, 0> failures; | 
|  | 6419 |  | 
|  | 6420 | CopyUniqueClassMethodTypes (class_symfile, | 
|  | 6421 | class_type, | 
|  | 6422 | class_type_cu_sp.get(), | 
|  | 6423 | class_type_die, | 
|  | 6424 | dwarf_cu, | 
|  | 6425 | decl_ctx_die, | 
|  | 6426 | failures); | 
|  | 6427 |  | 
|  | 6428 | // FIXME do something with these failures that's smarter than | 
|  | 6429 | // just dropping them on the ground.  Unfortunately classes don't | 
|  | 6430 | // like having stuff added to them after their definitions are | 
|  | 6431 | // complete... | 
|  | 6432 |  | 
|  | 6433 | type_ptr = m_die_to_type[die]; | 
|  | 6434 | if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6435 | { | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6436 | type_sp = type_ptr->shared_from_this(); | 
|  | 6437 | break; | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6438 | } | 
|  | 6439 | } | 
|  | 6440 | } | 
|  | 6441 |  | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6442 | if (specification_die_offset != DW_INVALID_OFFSET) | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6443 | { | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6444 | // We have a specification which we are going to base our function | 
|  | 6445 | // prototype off of, so we need this type to be completed so that the | 
|  | 6446 | // m_die_to_decl_ctx for the method in the specification has a valid | 
|  | 6447 | // clang decl context. | 
| Greg Clayton | 8eb732e | 2011-12-13 04:34:06 +0000 | [diff] [blame] | 6448 | class_type->GetClangForwardType(); | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6449 | // If we have a specification, then the function type should have been | 
|  | 6450 | // made with the specification and not with this die. | 
|  | 6451 | DWARFCompileUnitSP spec_cu_sp; | 
|  | 6452 | const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp); | 
| Eric Christopher | 6cc6e60 | 2012-03-25 19:37:33 +0000 | [diff] [blame] | 6453 | clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die); | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6454 | if (spec_clang_decl_ctx) | 
|  | 6455 | { | 
|  | 6456 | LinkDeclContextToDIE(spec_clang_decl_ctx, die); | 
|  | 6457 | } | 
|  | 6458 | else | 
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6459 | { | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6460 | 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] | 6461 | MakeUserID(die->GetOffset()), | 
|  | 6462 | specification_die_offset); | 
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6463 | } | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6464 | type_handled = true; | 
|  | 6465 | } | 
|  | 6466 | else if (abstract_origin_die_offset != DW_INVALID_OFFSET) | 
|  | 6467 | { | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6468 | // We have a specification which we are going to base our function | 
|  | 6469 | // prototype off of, so we need this type to be completed so that the | 
|  | 6470 | // m_die_to_decl_ctx for the method in the abstract origin has a valid | 
|  | 6471 | // clang decl context. | 
| Greg Clayton | 8eb732e | 2011-12-13 04:34:06 +0000 | [diff] [blame] | 6472 | class_type->GetClangForwardType(); | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6473 |  | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6474 | DWARFCompileUnitSP abs_cu_sp; | 
|  | 6475 | 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] | 6476 | clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die); | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6477 | if (abs_clang_decl_ctx) | 
|  | 6478 | { | 
|  | 6479 | LinkDeclContextToDIE (abs_clang_decl_ctx, die); | 
|  | 6480 | } | 
|  | 6481 | else | 
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6482 | { | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6483 | 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] | 6484 | MakeUserID(die->GetOffset()), | 
|  | 6485 | abstract_origin_die_offset); | 
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6486 | } | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6487 | type_handled = true; | 
|  | 6488 | } | 
|  | 6489 | else | 
|  | 6490 | { | 
|  | 6491 | clang_type_t class_opaque_type = class_type->GetClangForwardType(); | 
|  | 6492 | if (ClangASTContext::IsCXXClassType (class_opaque_type)) | 
| Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 6493 | { | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6494 | if (ClangASTContext::IsBeingDefined (class_opaque_type)) | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6495 | { | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6496 | // Neither GCC 4.2 nor clang++ currently set a valid accessibility | 
|  | 6497 | // in the DWARF for C++ methods... Default to public for now... | 
|  | 6498 | if (accessibility == eAccessNone) | 
|  | 6499 | accessibility = eAccessPublic; | 
|  | 6500 |  | 
|  | 6501 | if (!is_static && !die->HasChildren()) | 
|  | 6502 | { | 
|  | 6503 | // We have a C++ member function with no children (this pointer!) | 
|  | 6504 | // and clang will get mad if we try and make a function that isn't | 
|  | 6505 | // well formed in the DWARF, so we will just skip it... | 
|  | 6506 | type_handled = true; | 
|  | 6507 | } | 
|  | 6508 | else | 
|  | 6509 | { | 
|  | 6510 | clang::CXXMethodDecl *cxx_method_decl; | 
|  | 6511 | // REMOVE THE CRASH DESCRIPTION BELOW | 
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 6512 | 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] | 6513 | type_name_cstr, | 
|  | 6514 | class_type->GetName().GetCString(), | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6515 | MakeUserID(die->GetOffset()), | 
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 6516 | m_obj_file->GetFileSpec().GetPath().c_str()); | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6517 |  | 
| Sean Callanan | c1b732d | 2011-11-01 18:07:13 +0000 | [diff] [blame] | 6518 | const bool is_attr_used = false; | 
|  | 6519 |  | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6520 | cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type, | 
|  | 6521 | type_name_cstr, | 
|  | 6522 | clang_type, | 
|  | 6523 | accessibility, | 
|  | 6524 | is_virtual, | 
|  | 6525 | is_static, | 
|  | 6526 | is_inline, | 
| Sean Callanan | c1b732d | 2011-11-01 18:07:13 +0000 | [diff] [blame] | 6527 | is_explicit, | 
| Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 6528 | is_attr_used, | 
|  | 6529 | is_artificial); | 
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6530 |  | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6531 | type_handled = cxx_method_decl != NULL; | 
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6532 |  | 
|  | 6533 | if (type_handled) | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6534 | { | 
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6535 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die); | 
|  | 6536 |  | 
|  | 6537 | Host::SetCrashDescription (NULL); | 
|  | 6538 |  | 
|  | 6539 |  | 
|  | 6540 | ClangASTMetadata metadata; | 
|  | 6541 | metadata.SetUserID(MakeUserID(die->GetOffset())); | 
|  | 6542 |  | 
|  | 6543 | if (!object_pointer_name.empty()) | 
|  | 6544 | { | 
|  | 6545 | metadata.SetObjectPtrName(object_pointer_name.c_str()); | 
|  | 6546 | if (log) | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6547 | log->Printf ("Setting object pointer name: %s on method object %p.\n", | 
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6548 | object_pointer_name.c_str(), | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6549 | cxx_method_decl); | 
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6550 | } | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6551 | GetClangASTContext().SetMetadata (cxx_method_decl, metadata); | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6552 | } | 
| Sean Callanan | b0640dc | 2013-04-09 23:22:08 +0000 | [diff] [blame] | 6553 | else | 
|  | 6554 | { | 
| Sean Callanan | de9ce87 | 2013-05-09 23:13:13 +0000 | [diff] [blame] | 6555 | ignore_containing_context = true; | 
| Sean Callanan | b0640dc | 2013-04-09 23:22:08 +0000 | [diff] [blame] | 6556 | } | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6557 | } | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6558 | } | 
|  | 6559 | else | 
|  | 6560 | { | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6561 | // We were asked to parse the type for a method in a class, yet the | 
|  | 6562 | // class hasn't been asked to complete itself through the | 
|  | 6563 | // clang::ExternalASTSource protocol, so we need to just have the | 
|  | 6564 | // class complete itself and do things the right way, then our | 
|  | 6565 | // DIE should then have an entry in the m_die_to_type map. First | 
|  | 6566 | // we need to modify the m_die_to_type so it doesn't think we are | 
|  | 6567 | // trying to parse this DIE anymore... | 
|  | 6568 | m_die_to_type[die] = NULL; | 
|  | 6569 |  | 
|  | 6570 | // Now we get the full type to force our class type to complete itself | 
|  | 6571 | // using the clang::ExternalASTSource protocol which will parse all | 
|  | 6572 | // base classes and all methods (including the method for this DIE). | 
|  | 6573 | class_type->GetClangFullType(); | 
| Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 6574 |  | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6575 | // The type for this DIE should have been filled in the function call above | 
|  | 6576 | type_ptr = m_die_to_type[die]; | 
| Greg Clayton | e5476db | 2012-06-01 20:32:35 +0000 | [diff] [blame] | 6577 | if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6578 | { | 
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 6579 | type_sp = type_ptr->shared_from_this(); | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6580 | break; | 
|  | 6581 | } | 
| Sean Callanan | 02eee4d | 2012-04-12 23:10:00 +0000 | [diff] [blame] | 6582 |  | 
|  | 6583 | // FIXME This is fixing some even uglier behavior but we really need to | 
|  | 6584 | // uniq the methods of each class as well as the class itself. | 
|  | 6585 | // <rdar://problem/11240464> | 
|  | 6586 | type_handled = true; | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6587 | } | 
| Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 6588 | } | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6589 | } | 
|  | 6590 | } | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6591 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6592 | } | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6593 |  | 
|  | 6594 | if (!type_handled) | 
|  | 6595 | { | 
|  | 6596 | // We just have a function that isn't part of a class | 
| Sean Callanan | de9ce87 | 2013-05-09 23:13:13 +0000 | [diff] [blame] | 6597 | 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] | 6598 | type_name_cstr, | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6599 | clang_type, | 
|  | 6600 | storage, | 
|  | 6601 | is_inline); | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 6602 |  | 
|  | 6603 | //                            if (template_param_infos.GetSize() > 0) | 
|  | 6604 | //                            { | 
|  | 6605 | //                                clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx, | 
|  | 6606 | //                                                                                                                  function_decl, | 
|  | 6607 | //                                                                                                                  type_name_cstr, | 
|  | 6608 | //                                                                                                                  template_param_infos); | 
|  | 6609 | // | 
|  | 6610 | //                                ast.CreateFunctionTemplateSpecializationInfo (function_decl, | 
|  | 6611 | //                                                                              func_template_decl, | 
|  | 6612 | //                                                                              template_param_infos); | 
|  | 6613 | //                            } | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6614 | // Add the decl to our DIE to decl context map | 
|  | 6615 | assert (function_decl); | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6616 | LinkDeclContextToDIE(function_decl, die); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6617 | if (!function_param_decls.empty()) | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6618 | ast.SetFunctionParameters (function_decl, | 
|  | 6619 | &function_param_decls.front(), | 
|  | 6620 | function_param_decls.size()); | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 6621 |  | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6622 | ClangASTMetadata metadata; | 
|  | 6623 | metadata.SetUserID(MakeUserID(die->GetOffset())); | 
|  | 6624 |  | 
|  | 6625 | if (!object_pointer_name.empty()) | 
|  | 6626 | { | 
|  | 6627 | metadata.SetObjectPtrName(object_pointer_name.c_str()); | 
| Jim Ingham | 2cffda3f | 2012-10-30 23:34:07 +0000 | [diff] [blame] | 6628 | if (log) | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6629 | log->Printf ("Setting object pointer name: %s on function object %p.", | 
| Jim Ingham | 2cffda3f | 2012-10-30 23:34:07 +0000 | [diff] [blame] | 6630 | object_pointer_name.c_str(), | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6631 | function_decl); | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6632 | } | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6633 | GetClangASTContext().SetMetadata (function_decl, metadata); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6634 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6635 | } | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6636 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6637 | this, | 
|  | 6638 | type_name_const_str, | 
|  | 6639 | 0, | 
|  | 6640 | NULL, | 
|  | 6641 | LLDB_INVALID_UID, | 
|  | 6642 | Type::eEncodingIsUID, | 
|  | 6643 | &decl, | 
|  | 6644 | clang_type, | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6645 | Type::eResolveStateFull)); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6646 | assert(type_sp.get()); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6647 | } | 
|  | 6648 | break; | 
|  | 6649 |  | 
|  | 6650 | case DW_TAG_array_type: | 
|  | 6651 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6652 | // 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] | 6653 | m_die_to_type[die] = DIE_IS_BEING_PARSED; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6654 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6655 | lldb::user_id_t type_die_offset = DW_INVALID_OFFSET; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6656 | int64_t first_index = 0; | 
|  | 6657 | uint32_t byte_stride = 0; | 
|  | 6658 | uint32_t bit_stride = 0; | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 6659 | bool is_vector = false; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6660 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6661 |  | 
|  | 6662 | if (num_attributes > 0) | 
|  | 6663 | { | 
|  | 6664 | uint32_t i; | 
|  | 6665 | for (i=0; i<num_attributes; ++i) | 
|  | 6666 | { | 
|  | 6667 | attr = attributes.AttributeAtIndex(i); | 
|  | 6668 | DWARFFormValue form_value; | 
|  | 6669 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 6670 | { | 
|  | 6671 | switch (attr) | 
|  | 6672 | { | 
|  | 6673 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 6674 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 6675 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 6676 | case DW_AT_name: | 
|  | 6677 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6678 | type_name_const_str.SetCString(type_name_cstr); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6679 | break; | 
|  | 6680 |  | 
|  | 6681 | case DW_AT_type:            type_die_offset = form_value.Reference(dwarf_cu); break; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6682 | case DW_AT_byte_size:       break; // byte_size = form_value.Unsigned(); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6683 | case DW_AT_byte_stride:     byte_stride = form_value.Unsigned(); break; | 
|  | 6684 | case DW_AT_bit_stride:      bit_stride = form_value.Unsigned(); break; | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 6685 | case DW_AT_GNU_vector:      is_vector = form_value.Boolean(); break; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6686 | 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] | 6687 | case DW_AT_declaration:     break; // is_forward_declaration = form_value.Boolean(); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6688 | case DW_AT_allocated: | 
|  | 6689 | case DW_AT_associated: | 
|  | 6690 | case DW_AT_data_location: | 
|  | 6691 | case DW_AT_description: | 
|  | 6692 | case DW_AT_ordering: | 
|  | 6693 | case DW_AT_start_scope: | 
|  | 6694 | case DW_AT_visibility: | 
|  | 6695 | case DW_AT_specification: | 
|  | 6696 | case DW_AT_abstract_origin: | 
|  | 6697 | case DW_AT_sibling: | 
|  | 6698 | break; | 
|  | 6699 | } | 
|  | 6700 | } | 
|  | 6701 | } | 
|  | 6702 |  | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6703 | 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] | 6704 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6705 | Type *element_type = ResolveTypeUID(type_die_offset); | 
|  | 6706 |  | 
|  | 6707 | if (element_type) | 
|  | 6708 | { | 
|  | 6709 | std::vector<uint64_t> element_orders; | 
|  | 6710 | ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride); | 
|  | 6711 | if (byte_stride == 0 && bit_stride == 0) | 
|  | 6712 | byte_stride = element_type->GetByteSize(); | 
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 6713 | clang_type_t array_element_type = element_type->GetClangForwardType(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6714 | uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride; | 
|  | 6715 | uint64_t num_elements = 0; | 
|  | 6716 | std::vector<uint64_t>::const_reverse_iterator pos; | 
|  | 6717 | std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend(); | 
|  | 6718 | for (pos = element_orders.rbegin(); pos != end; ++pos) | 
|  | 6719 | { | 
|  | 6720 | num_elements = *pos; | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6721 | clang_type = ast.CreateArrayType (array_element_type, | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 6722 | num_elements, | 
|  | 6723 | is_vector); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6724 | array_element_type = clang_type; | 
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 6725 | array_element_bit_stride = num_elements ? array_element_bit_stride * num_elements : array_element_bit_stride; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6726 | } | 
|  | 6727 | ConstString empty_name; | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6728 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6729 | this, | 
|  | 6730 | empty_name, | 
|  | 6731 | array_element_bit_stride / 8, | 
|  | 6732 | NULL, | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6733 | type_die_offset, | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6734 | Type::eEncodingIsUID, | 
|  | 6735 | &decl, | 
|  | 6736 | clang_type, | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6737 | Type::eResolveStateFull)); | 
|  | 6738 | type_sp->SetEncodingType (element_type); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6739 | } | 
|  | 6740 | } | 
|  | 6741 | } | 
|  | 6742 | break; | 
|  | 6743 |  | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6744 | case DW_TAG_ptr_to_member_type: | 
|  | 6745 | { | 
|  | 6746 | dw_offset_t type_die_offset = DW_INVALID_OFFSET; | 
|  | 6747 | dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET; | 
|  | 6748 |  | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6749 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6750 |  | 
|  | 6751 | if (num_attributes > 0) { | 
|  | 6752 | uint32_t i; | 
|  | 6753 | for (i=0; i<num_attributes; ++i) | 
|  | 6754 | { | 
|  | 6755 | attr = attributes.AttributeAtIndex(i); | 
|  | 6756 | DWARFFormValue form_value; | 
|  | 6757 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 6758 | { | 
|  | 6759 | switch (attr) | 
|  | 6760 | { | 
|  | 6761 | case DW_AT_type: | 
|  | 6762 | type_die_offset = form_value.Reference(dwarf_cu); break; | 
|  | 6763 | case DW_AT_containing_type: | 
|  | 6764 | containing_type_die_offset = form_value.Reference(dwarf_cu); break; | 
|  | 6765 | } | 
|  | 6766 | } | 
|  | 6767 | } | 
|  | 6768 |  | 
|  | 6769 | Type *pointee_type = ResolveTypeUID(type_die_offset); | 
|  | 6770 | Type *class_type = ResolveTypeUID(containing_type_die_offset); | 
|  | 6771 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6772 | clang_type_t pointee_clang_type = pointee_type->GetClangForwardType(); | 
|  | 6773 | clang_type_t class_clang_type = class_type->GetClangLayoutType(); | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6774 |  | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6775 | clang_type = ast.CreateMemberPointerType(pointee_clang_type, | 
|  | 6776 | class_clang_type); | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6777 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6778 | byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(), | 
|  | 6779 | clang_type) / 8; | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6780 |  | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6781 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6782 | this, | 
|  | 6783 | type_name_const_str, | 
|  | 6784 | byte_size, | 
|  | 6785 | NULL, | 
|  | 6786 | LLDB_INVALID_UID, | 
|  | 6787 | Type::eEncodingIsUID, | 
|  | 6788 | NULL, | 
|  | 6789 | clang_type, | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6790 | Type::eResolveStateForward)); | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6791 | } | 
|  | 6792 |  | 
|  | 6793 | break; | 
|  | 6794 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6795 | default: | 
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 6796 | 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", | 
|  | 6797 | die->GetOffset(), | 
|  | 6798 | tag, | 
|  | 6799 | DW_TAG_value_to_name(tag)); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6800 | break; | 
|  | 6801 | } | 
|  | 6802 |  | 
|  | 6803 | if (type_sp.get()) | 
|  | 6804 | { | 
|  | 6805 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); | 
|  | 6806 | dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; | 
|  | 6807 |  | 
|  | 6808 | SymbolContextScope * symbol_context_scope = NULL; | 
|  | 6809 | if (sc_parent_tag == DW_TAG_compile_unit) | 
|  | 6810 | { | 
|  | 6811 | symbol_context_scope = sc.comp_unit; | 
|  | 6812 | } | 
|  | 6813 | else if (sc.function != NULL) | 
|  | 6814 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6815 | 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] | 6816 | if (symbol_context_scope == NULL) | 
|  | 6817 | symbol_context_scope = sc.function; | 
|  | 6818 | } | 
|  | 6819 |  | 
|  | 6820 | if (symbol_context_scope != NULL) | 
|  | 6821 | { | 
|  | 6822 | type_sp->SetSymbolContextScope(symbol_context_scope); | 
|  | 6823 | } | 
|  | 6824 |  | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6825 | // We are ready to put this type into the uniqued list up at the module level | 
|  | 6826 | type_list->Insert (type_sp); | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 6827 |  | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6828 | m_die_to_type[die] = type_sp.get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6829 | } | 
|  | 6830 | } | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 6831 | else if (type_ptr != DIE_IS_BEING_PARSED) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6832 | { | 
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 6833 | type_sp = type_ptr->shared_from_this(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6834 | } | 
|  | 6835 | } | 
|  | 6836 | return type_sp; | 
|  | 6837 | } | 
|  | 6838 |  | 
|  | 6839 | size_t | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6840 | SymbolFileDWARF::ParseTypes | 
|  | 6841 | ( | 
|  | 6842 | const SymbolContext& sc, | 
|  | 6843 | DWARFCompileUnit* dwarf_cu, | 
|  | 6844 | const DWARFDebugInfoEntry *die, | 
|  | 6845 | bool parse_siblings, | 
|  | 6846 | bool parse_children | 
|  | 6847 | ) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6848 | { | 
|  | 6849 | size_t types_added = 0; | 
|  | 6850 | while (die != NULL) | 
|  | 6851 | { | 
|  | 6852 | bool type_is_new = false; | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6853 | if (ParseType(sc, dwarf_cu, die, &type_is_new).get()) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6854 | { | 
|  | 6855 | if (type_is_new) | 
|  | 6856 | ++types_added; | 
|  | 6857 | } | 
|  | 6858 |  | 
|  | 6859 | if (parse_children && die->HasChildren()) | 
|  | 6860 | { | 
|  | 6861 | if (die->Tag() == DW_TAG_subprogram) | 
|  | 6862 | { | 
|  | 6863 | SymbolContext child_sc(sc); | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6864 | child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6865 | types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true); | 
|  | 6866 | } | 
|  | 6867 | else | 
|  | 6868 | types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true); | 
|  | 6869 | } | 
|  | 6870 |  | 
|  | 6871 | if (parse_siblings) | 
|  | 6872 | die = die->GetSibling(); | 
|  | 6873 | else | 
|  | 6874 | die = NULL; | 
|  | 6875 | } | 
|  | 6876 | return types_added; | 
|  | 6877 | } | 
|  | 6878 |  | 
|  | 6879 |  | 
|  | 6880 | size_t | 
|  | 6881 | SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc) | 
|  | 6882 | { | 
|  | 6883 | assert(sc.comp_unit && sc.function); | 
|  | 6884 | size_t functions_added = 0; | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 6885 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6886 | if (dwarf_cu) | 
|  | 6887 | { | 
|  | 6888 | dw_offset_t function_die_offset = sc.function->GetID(); | 
|  | 6889 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset); | 
|  | 6890 | if (function_die) | 
|  | 6891 | { | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 6892 | 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] | 6893 | } | 
|  | 6894 | } | 
|  | 6895 |  | 
|  | 6896 | return functions_added; | 
|  | 6897 | } | 
|  | 6898 |  | 
|  | 6899 |  | 
|  | 6900 | size_t | 
|  | 6901 | SymbolFileDWARF::ParseTypes (const SymbolContext &sc) | 
|  | 6902 | { | 
|  | 6903 | // At least a compile unit must be valid | 
|  | 6904 | assert(sc.comp_unit); | 
|  | 6905 | size_t types_added = 0; | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 6906 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6907 | if (dwarf_cu) | 
|  | 6908 | { | 
|  | 6909 | if (sc.function) | 
|  | 6910 | { | 
|  | 6911 | dw_offset_t function_die_offset = sc.function->GetID(); | 
|  | 6912 | const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset); | 
|  | 6913 | if (func_die && func_die->HasChildren()) | 
|  | 6914 | { | 
|  | 6915 | types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true); | 
|  | 6916 | } | 
|  | 6917 | } | 
|  | 6918 | else | 
|  | 6919 | { | 
|  | 6920 | const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE(); | 
|  | 6921 | if (dwarf_cu_die && dwarf_cu_die->HasChildren()) | 
|  | 6922 | { | 
|  | 6923 | types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true); | 
|  | 6924 | } | 
|  | 6925 | } | 
|  | 6926 | } | 
|  | 6927 |  | 
|  | 6928 | return types_added; | 
|  | 6929 | } | 
|  | 6930 |  | 
|  | 6931 | size_t | 
|  | 6932 | SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc) | 
|  | 6933 | { | 
|  | 6934 | if (sc.comp_unit != NULL) | 
|  | 6935 | { | 
| Greg Clayton | 4b3dc10 | 2010-11-01 20:32:12 +0000 | [diff] [blame] | 6936 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 6937 | if (info == NULL) | 
|  | 6938 | return 0; | 
|  | 6939 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6940 | if (sc.function) | 
|  | 6941 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 6942 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnitContainingDIE(sc.function->GetID()).get(); | 
|  | 6943 |  | 
|  | 6944 | if (dwarf_cu == NULL) | 
|  | 6945 | return 0; | 
|  | 6946 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6947 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID()); | 
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 6948 |  | 
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 6949 | dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS); | 
|  | 6950 | if (func_lo_pc != LLDB_INVALID_ADDRESS) | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6951 | { | 
|  | 6952 | 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] | 6953 |  | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6954 | // Let all blocks know they have parse all their variables | 
|  | 6955 | sc.function->GetBlock (false).SetDidParseVariables (true, true); | 
|  | 6956 | return num_variables; | 
|  | 6957 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6958 | } | 
|  | 6959 | else if (sc.comp_unit) | 
|  | 6960 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 6961 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()).get(); | 
|  | 6962 |  | 
|  | 6963 | if (dwarf_cu == NULL) | 
|  | 6964 | return 0; | 
|  | 6965 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6966 | uint32_t vars_added = 0; | 
|  | 6967 | VariableListSP variables (sc.comp_unit->GetVariableList(false)); | 
|  | 6968 |  | 
|  | 6969 | if (variables.get() == NULL) | 
|  | 6970 | { | 
|  | 6971 | variables.reset(new VariableList()); | 
|  | 6972 | sc.comp_unit->SetVariableList(variables); | 
|  | 6973 |  | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 6974 | DWARFCompileUnit* match_dwarf_cu = NULL; | 
|  | 6975 | const DWARFDebugInfoEntry* die = NULL; | 
|  | 6976 | DIEArray die_offsets; | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 6977 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6978 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 6979 | if (m_apple_names_ap.get()) | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6980 | { | 
|  | 6981 | DWARFMappedHash::DIEInfoArray hash_data_array; | 
|  | 6982 | if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(), | 
|  | 6983 | dwarf_cu->GetNextCompileUnitOffset(), | 
|  | 6984 | hash_data_array)) | 
|  | 6985 | { | 
|  | 6986 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); | 
|  | 6987 | } | 
|  | 6988 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6989 | } | 
|  | 6990 | else | 
|  | 6991 | { | 
|  | 6992 | // Index if we already haven't to make sure the compile units | 
|  | 6993 | // get indexed and make their global DIE index list | 
|  | 6994 | if (!m_indexed) | 
|  | 6995 | Index (); | 
|  | 6996 |  | 
|  | 6997 | m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(), | 
|  | 6998 | dwarf_cu->GetNextCompileUnitOffset(), | 
|  | 6999 | die_offsets); | 
|  | 7000 | } | 
|  | 7001 |  | 
|  | 7002 | const size_t num_matches = die_offsets.size(); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7003 | if (num_matches) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7004 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7005 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 7006 | for (size_t i=0; i<num_matches; ++i) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7007 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7008 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 7009 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 7010 | if (die) | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7011 | { | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 7012 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS)); | 
|  | 7013 | if (var_sp) | 
|  | 7014 | { | 
|  | 7015 | variables->AddVariableIfUnique (var_sp); | 
|  | 7016 | ++vars_added; | 
|  | 7017 | } | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7018 | } | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 7019 | else | 
|  | 7020 | { | 
|  | 7021 | if (m_using_apple_tables) | 
|  | 7022 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 7023 | 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] | 7024 | } | 
|  | 7025 | } | 
|  | 7026 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7027 | } | 
|  | 7028 | } | 
|  | 7029 | } | 
|  | 7030 | return vars_added; | 
|  | 7031 | } | 
|  | 7032 | } | 
|  | 7033 | return 0; | 
|  | 7034 | } | 
|  | 7035 |  | 
|  | 7036 |  | 
|  | 7037 | VariableSP | 
|  | 7038 | SymbolFileDWARF::ParseVariableDIE | 
|  | 7039 | ( | 
|  | 7040 | const SymbolContext& sc, | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 7041 | DWARFCompileUnit* dwarf_cu, | 
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 7042 | const DWARFDebugInfoEntry *die, | 
|  | 7043 | const lldb::addr_t func_low_pc | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7044 | ) | 
|  | 7045 | { | 
|  | 7046 |  | 
| Greg Clayton | 83c5cd9 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 7047 | VariableSP var_sp (m_die_to_variable_sp[die]); | 
|  | 7048 | if (var_sp) | 
|  | 7049 | return var_sp;  // Already been parsed! | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7050 |  | 
|  | 7051 | const dw_tag_t tag = die->Tag(); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7052 |  | 
|  | 7053 | if ((tag == DW_TAG_variable) || | 
|  | 7054 | (tag == DW_TAG_constant) || | 
|  | 7055 | (tag == DW_TAG_formal_parameter && sc.function)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7056 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7057 | DWARFDebugInfoEntry::Attributes attributes; | 
|  | 7058 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
|  | 7059 | if (num_attributes > 0) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7060 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7061 | const char *name = NULL; | 
|  | 7062 | const char *mangled = NULL; | 
|  | 7063 | Declaration decl; | 
|  | 7064 | uint32_t i; | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7065 | lldb::user_id_t type_uid = LLDB_INVALID_UID; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7066 | DWARFExpression location; | 
|  | 7067 | bool is_external = false; | 
|  | 7068 | bool is_artificial = false; | 
|  | 7069 | bool location_is_const_value_data = false; | 
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7070 | bool has_explicit_location = false; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 7071 | //AccessType accessibility = eAccessNone; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7072 |  | 
|  | 7073 | for (i=0; i<num_attributes; ++i) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7074 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7075 | dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 7076 | DWARFFormValue form_value; | 
|  | 7077 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7078 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7079 | switch (attr) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7080 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7081 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 7082 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 7083 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 7084 | 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] | 7085 | case DW_AT_linkage_name: | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7086 | case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break; | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7087 | case DW_AT_type:        type_uid = form_value.Reference(dwarf_cu); break; | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 7088 | case DW_AT_external:    is_external = form_value.Boolean(); break; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7089 | case DW_AT_const_value: | 
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7090 | // If we have already found a DW_AT_location attribute, ignore this attribute. | 
|  | 7091 | if (!has_explicit_location) | 
|  | 7092 | { | 
|  | 7093 | location_is_const_value_data = true; | 
|  | 7094 | // The constant value will be either a block, a data value or a string. | 
|  | 7095 | const DataExtractor& debug_info_data = get_debug_info_data(); | 
|  | 7096 | if (DWARFFormValue::IsBlockForm(form_value.Form())) | 
|  | 7097 | { | 
|  | 7098 | // Retrieve the value as a block expression. | 
|  | 7099 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); | 
|  | 7100 | uint32_t block_length = form_value.Unsigned(); | 
|  | 7101 | location.CopyOpcodeData(debug_info_data, block_offset, block_length); | 
|  | 7102 | } | 
|  | 7103 | else if (DWARFFormValue::IsDataForm(form_value.Form())) | 
|  | 7104 | { | 
|  | 7105 | // Retrieve the value as a data expression. | 
|  | 7106 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); | 
|  | 7107 | uint32_t data_offset = attributes.DIEOffsetAtIndex(i); | 
|  | 7108 | uint32_t data_length = fixed_form_sizes[form_value.Form()]; | 
|  | 7109 | location.CopyOpcodeData(debug_info_data, data_offset, data_length); | 
|  | 7110 | } | 
|  | 7111 | else | 
|  | 7112 | { | 
|  | 7113 | // Retrieve the value as a string expression. | 
|  | 7114 | if (form_value.Form() == DW_FORM_strp) | 
|  | 7115 | { | 
|  | 7116 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); | 
|  | 7117 | uint32_t data_offset = attributes.DIEOffsetAtIndex(i); | 
|  | 7118 | uint32_t data_length = fixed_form_sizes[form_value.Form()]; | 
|  | 7119 | location.CopyOpcodeData(debug_info_data, data_offset, data_length); | 
|  | 7120 | } | 
|  | 7121 | else | 
|  | 7122 | { | 
|  | 7123 | const char *str = form_value.AsCString(&debug_info_data); | 
|  | 7124 | uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart(); | 
|  | 7125 | uint32_t string_length = strlen(str) + 1; | 
|  | 7126 | location.CopyOpcodeData(debug_info_data, string_offset, string_length); | 
|  | 7127 | } | 
|  | 7128 | } | 
|  | 7129 | } | 
|  | 7130 | break; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7131 | case DW_AT_location: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7132 | { | 
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7133 | location_is_const_value_data = false; | 
|  | 7134 | has_explicit_location = true; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7135 | if (form_value.BlockData()) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7136 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7137 | const DataExtractor& debug_info_data = get_debug_info_data(); | 
|  | 7138 |  | 
|  | 7139 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); | 
|  | 7140 | uint32_t block_length = form_value.Unsigned(); | 
| Greg Clayton | 7f4c743 | 2012-08-11 00:49:14 +0000 | [diff] [blame] | 7141 | location.CopyOpcodeData(get_debug_info_data(), block_offset, block_length); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7142 | } | 
|  | 7143 | else | 
|  | 7144 | { | 
|  | 7145 | const DataExtractor&    debug_loc_data = get_debug_loc_data(); | 
|  | 7146 | const dw_offset_t debug_loc_offset = form_value.Unsigned(); | 
|  | 7147 |  | 
|  | 7148 | size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset); | 
|  | 7149 | if (loc_list_length > 0) | 
|  | 7150 | { | 
| Greg Clayton | 7f4c743 | 2012-08-11 00:49:14 +0000 | [diff] [blame] | 7151 | location.CopyOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7152 | assert (func_low_pc != LLDB_INVALID_ADDRESS); | 
|  | 7153 | location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress()); | 
|  | 7154 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7155 | } | 
|  | 7156 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7157 | break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7158 |  | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 7159 | case DW_AT_artificial:      is_artificial = form_value.Boolean(); break; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 7160 | 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] | 7161 | case DW_AT_declaration: | 
|  | 7162 | case DW_AT_description: | 
|  | 7163 | case DW_AT_endianity: | 
|  | 7164 | case DW_AT_segment: | 
|  | 7165 | case DW_AT_start_scope: | 
|  | 7166 | case DW_AT_visibility: | 
|  | 7167 | default: | 
|  | 7168 | case DW_AT_abstract_origin: | 
|  | 7169 | case DW_AT_sibling: | 
|  | 7170 | case DW_AT_specification: | 
|  | 7171 | break; | 
|  | 7172 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7173 | } | 
|  | 7174 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7175 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7176 | if (location.IsValid()) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7177 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7178 | ValueType scope = eValueTypeInvalid; | 
|  | 7179 |  | 
|  | 7180 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); | 
|  | 7181 | dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7182 | SymbolContextScope * symbol_context_scope = NULL; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7183 |  | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7184 | // DWARF doesn't specify if a DW_TAG_variable is a local, global | 
|  | 7185 | // or static variable, so we have to do a little digging by | 
|  | 7186 | // looking at the location of a varaible to see if it contains | 
|  | 7187 | // a DW_OP_addr opcode _somewhere_ in the definition. I say | 
|  | 7188 | // somewhere because clang likes to combine small global variables | 
|  | 7189 | // into the same symbol and have locations like: | 
|  | 7190 | // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus | 
|  | 7191 | // So if we don't have a DW_TAG_formal_parameter, we can look at | 
|  | 7192 | // the location to see if it contains a DW_OP_addr opcode, and | 
|  | 7193 | // then we can correctly classify  our variables. | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7194 | if (tag == DW_TAG_formal_parameter) | 
|  | 7195 | scope = eValueTypeVariableArgument; | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7196 | else | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7197 | { | 
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 7198 | bool op_error = false; | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7199 | // Check if the location has a DW_OP_addr with any address value... | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7200 | lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS; | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7201 | if (!location_is_const_value_data) | 
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 7202 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7203 | location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error); | 
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 7204 | if (op_error) | 
|  | 7205 | { | 
|  | 7206 | StreamString strm; | 
|  | 7207 | location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL); | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 7208 | 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] | 7209 | } | 
|  | 7210 | } | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7211 |  | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7212 | if (location_DW_OP_addr != LLDB_INVALID_ADDRESS) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7213 | { | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7214 | if (is_external) | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7215 | scope = eValueTypeVariableGlobal; | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7216 | else | 
|  | 7217 | scope = eValueTypeVariableStatic; | 
|  | 7218 |  | 
|  | 7219 |  | 
|  | 7220 | SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile (); | 
|  | 7221 |  | 
|  | 7222 | if (debug_map_symfile) | 
|  | 7223 | { | 
|  | 7224 | // When leaving the DWARF in the .o files on darwin, | 
|  | 7225 | // when we have a global variable that wasn't initialized, | 
|  | 7226 | // the .o file might not have allocated a virtual | 
|  | 7227 | // address for the global variable. In this case it will | 
|  | 7228 | // have created a symbol for the global variable | 
|  | 7229 | // that is undefined/data and external and the value will | 
|  | 7230 | // be the byte size of the variable. When we do the | 
|  | 7231 | // address map in SymbolFileDWARFDebugMap we rely on | 
|  | 7232 | // having an address, we need to do some magic here | 
|  | 7233 | // so we can get the correct address for our global | 
|  | 7234 | // variable. The address for all of these entries | 
|  | 7235 | // will be zero, and there will be an undefined symbol | 
|  | 7236 | // in this object file, and the executable will have | 
|  | 7237 | // a matching symbol with a good address. So here we | 
|  | 7238 | // dig up the correct address and replace it in the | 
|  | 7239 | // location for the variable, and set the variable's | 
|  | 7240 | // symbol context scope to be that of the main executable | 
|  | 7241 | // so the file address will resolve correctly. | 
|  | 7242 | bool linked_oso_file_addr = false; | 
|  | 7243 | if (is_external && location_DW_OP_addr == 0) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7244 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7245 |  | 
|  | 7246 | // we have a possible uninitialized extern global | 
|  | 7247 | ConstString const_name(mangled ? mangled : name); | 
|  | 7248 | ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile(); | 
|  | 7249 | if (debug_map_objfile) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7250 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7251 | Symtab *debug_map_symtab = debug_map_objfile->GetSymtab(); | 
|  | 7252 | if (debug_map_symtab) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7253 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7254 | Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name, | 
|  | 7255 | eSymbolTypeData, | 
|  | 7256 | Symtab::eDebugYes, | 
|  | 7257 | Symtab::eVisibilityExtern); | 
|  | 7258 | if (exe_symbol) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7259 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7260 | if (exe_symbol->ValueIsAddress()) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7261 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7262 | const addr_t exe_file_addr = exe_symbol->GetAddress().GetFileAddress(); | 
|  | 7263 | if (exe_file_addr != LLDB_INVALID_ADDRESS) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7264 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7265 | if (location.Update_DW_OP_addr (exe_file_addr)) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7266 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7267 | linked_oso_file_addr = true; | 
|  | 7268 | symbol_context_scope = exe_symbol; | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7269 | } | 
|  | 7270 | } | 
|  | 7271 | } | 
|  | 7272 | } | 
|  | 7273 | } | 
|  | 7274 | } | 
|  | 7275 | } | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7276 |  | 
|  | 7277 | if (!linked_oso_file_addr) | 
|  | 7278 | { | 
|  | 7279 | // The DW_OP_addr is not zero, but it contains a .o file address which | 
|  | 7280 | // needs to be linked up correctly. | 
|  | 7281 | const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr); | 
|  | 7282 | if (exe_file_addr != LLDB_INVALID_ADDRESS) | 
|  | 7283 | { | 
|  | 7284 | // Update the file address for this variable | 
|  | 7285 | location.Update_DW_OP_addr (exe_file_addr); | 
|  | 7286 | } | 
|  | 7287 | else | 
|  | 7288 | { | 
|  | 7289 | // Variable didn't make it into the final executable | 
|  | 7290 | return var_sp; | 
|  | 7291 | } | 
|  | 7292 | } | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7293 | } | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7294 | } | 
|  | 7295 | else | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7296 | { | 
|  | 7297 | scope = eValueTypeVariableLocal; | 
|  | 7298 | } | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7299 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7300 |  | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7301 | if (symbol_context_scope == NULL) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7302 | { | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7303 | switch (parent_tag) | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 7304 | { | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7305 | case DW_TAG_subprogram: | 
|  | 7306 | case DW_TAG_inlined_subroutine: | 
|  | 7307 | case DW_TAG_lexical_block: | 
|  | 7308 | if (sc.function) | 
|  | 7309 | { | 
|  | 7310 | symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); | 
|  | 7311 | if (symbol_context_scope == NULL) | 
|  | 7312 | symbol_context_scope = sc.function; | 
|  | 7313 | } | 
|  | 7314 | break; | 
|  | 7315 |  | 
|  | 7316 | default: | 
|  | 7317 | symbol_context_scope = sc.comp_unit; | 
|  | 7318 | break; | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 7319 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7320 | } | 
|  | 7321 |  | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 7322 | if (symbol_context_scope) | 
|  | 7323 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7324 | var_sp.reset (new Variable (MakeUserID(die->GetOffset()), | 
|  | 7325 | name, | 
|  | 7326 | mangled, | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7327 | SymbolFileTypeSP (new SymbolFileType(*this, type_uid)), | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7328 | scope, | 
|  | 7329 | symbol_context_scope, | 
|  | 7330 | &decl, | 
|  | 7331 | location, | 
|  | 7332 | is_external, | 
|  | 7333 | is_artificial)); | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 7334 |  | 
|  | 7335 | var_sp->SetLocationIsConstantValueData (location_is_const_value_data); | 
|  | 7336 | } | 
|  | 7337 | else | 
|  | 7338 | { | 
|  | 7339 | // Not ready to parse this variable yet. It might be a global | 
|  | 7340 | // or static variable that is in a function scope and the function | 
|  | 7341 | // in the symbol context wasn't filled in yet | 
|  | 7342 | return var_sp; | 
|  | 7343 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7344 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7345 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7346 | // Cache var_sp even if NULL (the variable was just a specification or | 
|  | 7347 | // was missing vital information to be able to be displayed in the debugger | 
|  | 7348 | // (missing location due to optimization, etc)) so we don't re-parse | 
|  | 7349 | // this DIE over and over later... | 
|  | 7350 | m_die_to_variable_sp[die] = var_sp; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7351 | } | 
|  | 7352 | return var_sp; | 
|  | 7353 | } | 
|  | 7354 |  | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7355 |  | 
|  | 7356 | const DWARFDebugInfoEntry * | 
|  | 7357 | SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset, | 
|  | 7358 | dw_offset_t spec_block_die_offset, | 
|  | 7359 | DWARFCompileUnit **result_die_cu_handle) | 
|  | 7360 | { | 
|  | 7361 | // Give the concrete function die specified by "func_die_offset", find the | 
|  | 7362 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points | 
|  | 7363 | // to "spec_block_die_offset" | 
|  | 7364 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 7365 |  | 
|  | 7366 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle); | 
|  | 7367 | if (die) | 
|  | 7368 | { | 
|  | 7369 | assert (*result_die_cu_handle); | 
|  | 7370 | return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle); | 
|  | 7371 | } | 
|  | 7372 | return NULL; | 
|  | 7373 | } | 
|  | 7374 |  | 
|  | 7375 |  | 
|  | 7376 | const DWARFDebugInfoEntry * | 
|  | 7377 | SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu, | 
|  | 7378 | const DWARFDebugInfoEntry *die, | 
|  | 7379 | dw_offset_t spec_block_die_offset, | 
|  | 7380 | DWARFCompileUnit **result_die_cu_handle) | 
|  | 7381 | { | 
|  | 7382 | if (die) | 
|  | 7383 | { | 
|  | 7384 | switch (die->Tag()) | 
|  | 7385 | { | 
|  | 7386 | case DW_TAG_subprogram: | 
|  | 7387 | case DW_TAG_inlined_subroutine: | 
|  | 7388 | case DW_TAG_lexical_block: | 
|  | 7389 | { | 
|  | 7390 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset) | 
|  | 7391 | { | 
|  | 7392 | *result_die_cu_handle = dwarf_cu; | 
|  | 7393 | return die; | 
|  | 7394 | } | 
|  | 7395 |  | 
|  | 7396 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset) | 
|  | 7397 | { | 
|  | 7398 | *result_die_cu_handle = dwarf_cu; | 
|  | 7399 | return die; | 
|  | 7400 | } | 
|  | 7401 | } | 
|  | 7402 | break; | 
|  | 7403 | } | 
|  | 7404 |  | 
|  | 7405 | // Give the concrete function die specified by "func_die_offset", find the | 
|  | 7406 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points | 
|  | 7407 | // to "spec_block_die_offset" | 
|  | 7408 | for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling()) | 
|  | 7409 | { | 
|  | 7410 | const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu, | 
|  | 7411 | child_die, | 
|  | 7412 | spec_block_die_offset, | 
|  | 7413 | result_die_cu_handle); | 
|  | 7414 | if (result_die) | 
|  | 7415 | return result_die; | 
|  | 7416 | } | 
|  | 7417 | } | 
|  | 7418 |  | 
|  | 7419 | *result_die_cu_handle = NULL; | 
|  | 7420 | return NULL; | 
|  | 7421 | } | 
|  | 7422 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7423 | size_t | 
|  | 7424 | SymbolFileDWARF::ParseVariables | 
|  | 7425 | ( | 
|  | 7426 | const SymbolContext& sc, | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 7427 | DWARFCompileUnit* dwarf_cu, | 
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 7428 | const lldb::addr_t func_low_pc, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7429 | const DWARFDebugInfoEntry *orig_die, | 
|  | 7430 | bool parse_siblings, | 
|  | 7431 | bool parse_children, | 
|  | 7432 | VariableList* cc_variable_list | 
|  | 7433 | ) | 
|  | 7434 | { | 
|  | 7435 | if (orig_die == NULL) | 
|  | 7436 | return 0; | 
|  | 7437 |  | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7438 | VariableListSP variable_list_sp; | 
|  | 7439 |  | 
|  | 7440 | size_t vars_added = 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7441 | const DWARFDebugInfoEntry *die = orig_die; | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7442 | while (die != NULL) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7443 | { | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7444 | dw_tag_t tag = die->Tag(); | 
|  | 7445 |  | 
|  | 7446 | // Check to see if we have already parsed this variable or constant? | 
|  | 7447 | if (m_die_to_variable_sp[die]) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7448 | { | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7449 | if (cc_variable_list) | 
|  | 7450 | cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7451 | } | 
|  | 7452 | else | 
|  | 7453 | { | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7454 | // We haven't already parsed it, lets do that now. | 
|  | 7455 | if ((tag == DW_TAG_variable) || | 
|  | 7456 | (tag == DW_TAG_constant) || | 
|  | 7457 | (tag == DW_TAG_formal_parameter && sc.function)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7458 | { | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7459 | if (variable_list_sp.get() == NULL) | 
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7460 | { | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7461 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die); | 
|  | 7462 | dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; | 
|  | 7463 | switch (parent_tag) | 
|  | 7464 | { | 
|  | 7465 | case DW_TAG_compile_unit: | 
|  | 7466 | if (sc.comp_unit != NULL) | 
|  | 7467 | { | 
|  | 7468 | variable_list_sp = sc.comp_unit->GetVariableList(false); | 
|  | 7469 | if (variable_list_sp.get() == NULL) | 
|  | 7470 | { | 
|  | 7471 | variable_list_sp.reset(new VariableList()); | 
|  | 7472 | sc.comp_unit->SetVariableList(variable_list_sp); | 
|  | 7473 | } | 
|  | 7474 | } | 
|  | 7475 | else | 
|  | 7476 | { | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 7477 | 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] | 7478 | MakeUserID(sc_parent_die->GetOffset()), | 
|  | 7479 | DW_TAG_value_to_name (parent_tag), | 
|  | 7480 | MakeUserID(orig_die->GetOffset()), | 
|  | 7481 | DW_TAG_value_to_name (orig_die->Tag())); | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7482 | } | 
|  | 7483 | break; | 
|  | 7484 |  | 
|  | 7485 | case DW_TAG_subprogram: | 
|  | 7486 | case DW_TAG_inlined_subroutine: | 
|  | 7487 | case DW_TAG_lexical_block: | 
|  | 7488 | if (sc.function != NULL) | 
|  | 7489 | { | 
|  | 7490 | // Check to see if we already have parsed the variables for the given scope | 
|  | 7491 |  | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7492 | Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7493 | if (block == NULL) | 
|  | 7494 | { | 
|  | 7495 | // This must be a specification or abstract origin with | 
|  | 7496 | // a concrete block couterpart in the current function. We need | 
|  | 7497 | // to find the concrete block so we can correctly add the | 
|  | 7498 | // variable to it | 
|  | 7499 | DWARFCompileUnit *concrete_block_die_cu = dwarf_cu; | 
|  | 7500 | const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(), | 
|  | 7501 | sc_parent_die->GetOffset(), | 
|  | 7502 | &concrete_block_die_cu); | 
|  | 7503 | if (concrete_block_die) | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7504 | block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset())); | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7505 | } | 
|  | 7506 |  | 
|  | 7507 | if (block != NULL) | 
|  | 7508 | { | 
|  | 7509 | const bool can_create = false; | 
|  | 7510 | variable_list_sp = block->GetBlockVariableList (can_create); | 
|  | 7511 | if (variable_list_sp.get() == NULL) | 
|  | 7512 | { | 
|  | 7513 | variable_list_sp.reset(new VariableList()); | 
|  | 7514 | block->SetVariableList(variable_list_sp); | 
|  | 7515 | } | 
|  | 7516 | } | 
|  | 7517 | } | 
|  | 7518 | break; | 
|  | 7519 |  | 
|  | 7520 | default: | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 7521 | 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] | 7522 | MakeUserID(orig_die->GetOffset()), | 
|  | 7523 | DW_TAG_value_to_name (orig_die->Tag())); | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7524 | break; | 
|  | 7525 | } | 
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7526 | } | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7527 |  | 
|  | 7528 | if (variable_list_sp) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7529 | { | 
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7530 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc)); | 
|  | 7531 | if (var_sp) | 
|  | 7532 | { | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7533 | variable_list_sp->AddVariableIfUnique (var_sp); | 
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7534 | if (cc_variable_list) | 
|  | 7535 | cc_variable_list->AddVariableIfUnique (var_sp); | 
|  | 7536 | ++vars_added; | 
|  | 7537 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7538 | } | 
|  | 7539 | } | 
|  | 7540 | } | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7541 |  | 
|  | 7542 | bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram); | 
|  | 7543 |  | 
|  | 7544 | if (!skip_children && parse_children && die->HasChildren()) | 
|  | 7545 | { | 
|  | 7546 | vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list); | 
|  | 7547 | } | 
|  | 7548 |  | 
|  | 7549 | if (parse_siblings) | 
|  | 7550 | die = die->GetSibling(); | 
|  | 7551 | else | 
|  | 7552 | die = NULL; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7553 | } | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7554 | return vars_added; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7555 | } | 
|  | 7556 |  | 
|  | 7557 | //------------------------------------------------------------------ | 
|  | 7558 | // PluginInterface protocol | 
|  | 7559 | //------------------------------------------------------------------ | 
|  | 7560 | const char * | 
|  | 7561 | SymbolFileDWARF::GetPluginName() | 
|  | 7562 | { | 
|  | 7563 | return "SymbolFileDWARF"; | 
|  | 7564 | } | 
|  | 7565 |  | 
|  | 7566 | const char * | 
|  | 7567 | SymbolFileDWARF::GetShortPluginName() | 
|  | 7568 | { | 
|  | 7569 | return GetPluginNameStatic(); | 
|  | 7570 | } | 
|  | 7571 |  | 
|  | 7572 | uint32_t | 
|  | 7573 | SymbolFileDWARF::GetPluginVersion() | 
|  | 7574 | { | 
|  | 7575 | return 1; | 
|  | 7576 | } | 
|  | 7577 |  | 
|  | 7578 | void | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 7579 | SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl) | 
|  | 7580 | { | 
|  | 7581 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; | 
|  | 7582 | clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); | 
|  | 7583 | if (clang_type) | 
|  | 7584 | symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); | 
|  | 7585 | } | 
|  | 7586 |  | 
|  | 7587 | void | 
|  | 7588 | SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl) | 
|  | 7589 | { | 
|  | 7590 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; | 
|  | 7591 | clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); | 
|  | 7592 | if (clang_type) | 
|  | 7593 | symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); | 
|  | 7594 | } | 
|  | 7595 |  | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7596 | void | 
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7597 | SymbolFileDWARF::DumpIndexes () | 
|  | 7598 | { | 
|  | 7599 | StreamFile s(stdout, false); | 
|  | 7600 |  | 
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 7601 | s.Printf ("DWARF index for (%s) '%s':", | 
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7602 | GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(), | 
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 7603 | GetObjectFile()->GetFileSpec().GetPath().c_str()); | 
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7604 | s.Printf("\nFunction basenames:\n");    m_function_basename_index.Dump (&s); | 
|  | 7605 | s.Printf("\nFunction fullnames:\n");    m_function_fullname_index.Dump (&s); | 
|  | 7606 | s.Printf("\nFunction methods:\n");      m_function_method_index.Dump (&s); | 
|  | 7607 | s.Printf("\nFunction selectors:\n");    m_function_selector_index.Dump (&s); | 
|  | 7608 | s.Printf("\nObjective C class selectors:\n");    m_objc_class_selectors_index.Dump (&s); | 
|  | 7609 | s.Printf("\nGlobals and statics:\n");   m_global_index.Dump (&s); | 
|  | 7610 | s.Printf("\nTypes:\n");                 m_type_index.Dump (&s); | 
|  | 7611 | s.Printf("\nNamepaces:\n");             m_namespace_index.Dump (&s); | 
|  | 7612 | } | 
|  | 7613 |  | 
|  | 7614 | void | 
|  | 7615 | SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context, | 
|  | 7616 | const char *name, | 
|  | 7617 | llvm::SmallVectorImpl <clang::NamedDecl *> *results) | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7618 | { | 
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7619 | DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context); | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7620 |  | 
|  | 7621 | if (iter == m_decl_ctx_to_die.end()) | 
|  | 7622 | return; | 
|  | 7623 |  | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7624 | 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] | 7625 | { | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7626 | const DWARFDebugInfoEntry *context_die = *pos; | 
|  | 7627 |  | 
|  | 7628 | if (!results) | 
|  | 7629 | return; | 
|  | 7630 |  | 
|  | 7631 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 7632 |  | 
|  | 7633 | DIEArray die_offsets; | 
|  | 7634 |  | 
|  | 7635 | DWARFCompileUnit* dwarf_cu = NULL; | 
|  | 7636 | const DWARFDebugInfoEntry* die = NULL; | 
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 7637 |  | 
|  | 7638 | if (m_using_apple_tables) | 
|  | 7639 | { | 
|  | 7640 | if (m_apple_types_ap.get()) | 
|  | 7641 | m_apple_types_ap->FindByName (name, die_offsets); | 
|  | 7642 | } | 
|  | 7643 | else | 
|  | 7644 | { | 
|  | 7645 | if (!m_indexed) | 
|  | 7646 | Index (); | 
|  | 7647 |  | 
|  | 7648 | m_type_index.Find (ConstString(name), die_offsets); | 
|  | 7649 | } | 
|  | 7650 |  | 
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 7651 | const size_t num_matches = die_offsets.size(); | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7652 |  | 
|  | 7653 | if (num_matches) | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7654 | { | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7655 | for (size_t i = 0; i < num_matches; ++i) | 
|  | 7656 | { | 
|  | 7657 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 7658 | die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7659 |  | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7660 | if (die->GetParent() != context_die) | 
|  | 7661 | continue; | 
|  | 7662 |  | 
|  | 7663 | Type *matching_type = ResolveType (dwarf_cu, die); | 
|  | 7664 |  | 
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 7665 | lldb::clang_type_t type = matching_type->GetClangForwardType(); | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7666 | clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type); | 
|  | 7667 |  | 
|  | 7668 | if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr())) | 
|  | 7669 | { | 
|  | 7670 | clang::TagDecl *tag_decl = tag_type->getDecl(); | 
|  | 7671 | results->push_back(tag_decl); | 
|  | 7672 | } | 
|  | 7673 | else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr())) | 
|  | 7674 | { | 
|  | 7675 | clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl(); | 
|  | 7676 | results->push_back(typedef_decl); | 
|  | 7677 | } | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7678 | } | 
|  | 7679 | } | 
|  | 7680 | } | 
|  | 7681 | } | 
|  | 7682 |  | 
|  | 7683 | void | 
|  | 7684 | SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton, | 
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 7685 | const clang::DeclContext *decl_context, | 
|  | 7686 | clang::DeclarationName decl_name, | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7687 | llvm::SmallVectorImpl <clang::NamedDecl *> *results) | 
|  | 7688 | { | 
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 7689 |  | 
|  | 7690 | switch (decl_context->getDeclKind()) | 
|  | 7691 | { | 
|  | 7692 | case clang::Decl::Namespace: | 
|  | 7693 | case clang::Decl::TranslationUnit: | 
|  | 7694 | { | 
|  | 7695 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; | 
|  | 7696 | symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results); | 
|  | 7697 | } | 
|  | 7698 | break; | 
|  | 7699 | default: | 
|  | 7700 | break; | 
|  | 7701 | } | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7702 | } | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7703 |  | 
|  | 7704 | bool | 
|  | 7705 | SymbolFileDWARF::LayoutRecordType (void *baton, | 
|  | 7706 | const clang::RecordDecl *record_decl, | 
|  | 7707 | uint64_t &size, | 
|  | 7708 | uint64_t &alignment, | 
|  | 7709 | llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, | 
|  | 7710 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, | 
|  | 7711 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) | 
|  | 7712 | { | 
|  | 7713 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; | 
|  | 7714 | return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets); | 
|  | 7715 | } | 
|  | 7716 |  | 
|  | 7717 |  | 
|  | 7718 | bool | 
|  | 7719 | SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl, | 
|  | 7720 | uint64_t &bit_size, | 
|  | 7721 | uint64_t &alignment, | 
|  | 7722 | llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, | 
|  | 7723 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, | 
|  | 7724 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) | 
|  | 7725 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 7726 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7727 | RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl); | 
|  | 7728 | bool success = false; | 
|  | 7729 | base_offsets.clear(); | 
|  | 7730 | vbase_offsets.clear(); | 
|  | 7731 | if (pos != m_record_decl_to_layout_map.end()) | 
|  | 7732 | { | 
|  | 7733 | bit_size = pos->second.bit_size; | 
|  | 7734 | alignment = pos->second.alignment; | 
|  | 7735 | field_offsets.swap(pos->second.field_offsets); | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 7736 | base_offsets.swap (pos->second.base_offsets); | 
|  | 7737 | vbase_offsets.swap (pos->second.vbase_offsets); | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7738 | m_record_decl_to_layout_map.erase(pos); | 
|  | 7739 | success = true; | 
|  | 7740 | } | 
|  | 7741 | else | 
|  | 7742 | { | 
|  | 7743 | bit_size = 0; | 
|  | 7744 | alignment = 0; | 
|  | 7745 | field_offsets.clear(); | 
|  | 7746 | } | 
|  | 7747 |  | 
|  | 7748 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 7749 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 7750 | "SymbolFileDWARF::LayoutRecordType (record_decl = %p, bit_size = %" PRIu64 ", alignment = %" PRIu64 ", field_offsets[%u],base_offsets[%u], vbase_offsets[%u]) success = %i", | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7751 | record_decl, | 
|  | 7752 | bit_size, | 
|  | 7753 | alignment, | 
|  | 7754 | (uint32_t)field_offsets.size(), | 
|  | 7755 | (uint32_t)base_offsets.size(), | 
|  | 7756 | (uint32_t)vbase_offsets.size(), | 
|  | 7757 | success); | 
|  | 7758 | return success; | 
|  | 7759 | } | 
|  | 7760 |  | 
|  | 7761 |  | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 7762 | SymbolFileDWARFDebugMap * | 
|  | 7763 | SymbolFileDWARF::GetDebugMapSymfile () | 
|  | 7764 | { | 
|  | 7765 | if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired()) | 
|  | 7766 | { | 
|  | 7767 | lldb::ModuleSP module_sp (m_debug_map_module_wp.lock()); | 
|  | 7768 | if (module_sp) | 
|  | 7769 | { | 
|  | 7770 | SymbolVendor *sym_vendor = module_sp->GetSymbolVendor(); | 
|  | 7771 | if (sym_vendor) | 
|  | 7772 | m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile(); | 
|  | 7773 | } | 
|  | 7774 | } | 
|  | 7775 | return m_debug_map_symfile; | 
|  | 7776 | } | 
|  | 7777 |  | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7778 |  |