| 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 | { | 
|  | 410 | return version == 2 || version == 3; | 
|  | 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; | 
|  | 883 | std::auto_ptr<Declaration> decl_ap; | 
|  | 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 | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 998 | std::auto_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 | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1063 | std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit)); | 
|  | 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 | { | 
|  | 1173 | std::auto_ptr<Declaration> decl_ap; | 
|  | 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 |  | 
|  | 1178 | std::auto_ptr<Declaration> call_ap; | 
|  | 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 |  | 
|  | 1276 | if (name && lldb_type && clang_type) | 
|  | 1277 | { | 
|  | 1278 | bool is_signed = false; | 
|  | 1279 | template_param_infos.names.push_back(name); | 
|  | 1280 | clang::QualType clang_qual_type (clang::QualType::getFromOpaquePtr (clang_type)); | 
|  | 1281 | if (tag == DW_TAG_template_value_parameter && ClangASTContext::IsIntegerType (clang_type, is_signed) && uval64_valid) | 
|  | 1282 | { | 
|  | 1283 | llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed); | 
| Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1284 | template_param_infos.args.push_back (clang::TemplateArgument (*GetClangASTContext().getASTContext(), | 
|  | 1285 | llvm::APSInt(apint), | 
|  | 1286 | clang_qual_type)); | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1287 | } | 
|  | 1288 | else | 
|  | 1289 | { | 
|  | 1290 | template_param_infos.args.push_back (clang::TemplateArgument (clang_qual_type)); | 
|  | 1291 | } | 
|  | 1292 | } | 
|  | 1293 | else | 
|  | 1294 | { | 
|  | 1295 | return false; | 
|  | 1296 | } | 
|  | 1297 |  | 
|  | 1298 | } | 
|  | 1299 | } | 
|  | 1300 | return true; | 
|  | 1301 |  | 
|  | 1302 | default: | 
|  | 1303 | break; | 
|  | 1304 | } | 
|  | 1305 | return false; | 
|  | 1306 | } | 
|  | 1307 |  | 
|  | 1308 | bool | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1309 | SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu, | 
|  | 1310 | const DWARFDebugInfoEntry *parent_die, | 
|  | 1311 | ClangASTContext::TemplateParameterInfos &template_param_infos) | 
|  | 1312 | { | 
|  | 1313 |  | 
|  | 1314 | if (parent_die == NULL) | 
| Filipe Cabecinhas | 52008c6 | 2012-05-23 16:24:11 +0000 | [diff] [blame] | 1315 | return false; | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1316 |  | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1317 | Args template_parameter_names; | 
|  | 1318 | for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); | 
|  | 1319 | die != NULL; | 
|  | 1320 | die = die->GetSibling()) | 
|  | 1321 | { | 
|  | 1322 | const dw_tag_t tag = die->Tag(); | 
|  | 1323 |  | 
|  | 1324 | switch (tag) | 
|  | 1325 | { | 
|  | 1326 | case DW_TAG_template_type_parameter: | 
|  | 1327 | case DW_TAG_template_value_parameter: | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1328 | ParseTemplateDIE (dwarf_cu, die, template_param_infos); | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1329 | break; | 
|  | 1330 |  | 
|  | 1331 | default: | 
|  | 1332 | break; | 
|  | 1333 | } | 
|  | 1334 | } | 
|  | 1335 | if (template_param_infos.args.empty()) | 
|  | 1336 | return false; | 
|  | 1337 | return template_param_infos.args.size() == template_param_infos.names.size(); | 
|  | 1338 | } | 
|  | 1339 |  | 
|  | 1340 | clang::ClassTemplateDecl * | 
|  | 1341 | SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx, | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1342 | lldb::AccessType access_type, | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1343 | const char *parent_name, | 
|  | 1344 | int tag_decl_kind, | 
|  | 1345 | const ClangASTContext::TemplateParameterInfos &template_param_infos) | 
|  | 1346 | { | 
|  | 1347 | if (template_param_infos.IsValid()) | 
|  | 1348 | { | 
|  | 1349 | std::string template_basename(parent_name); | 
|  | 1350 | template_basename.erase (template_basename.find('<')); | 
|  | 1351 | ClangASTContext &ast = GetClangASTContext(); | 
|  | 1352 |  | 
|  | 1353 | return ast.CreateClassTemplateDecl (decl_ctx, | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1354 | access_type, | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1355 | template_basename.c_str(), | 
|  | 1356 | tag_decl_kind, | 
|  | 1357 | template_param_infos); | 
|  | 1358 | } | 
|  | 1359 | return NULL; | 
|  | 1360 | } | 
|  | 1361 |  | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1362 | class SymbolFileDWARF::DelayedAddObjCClassProperty | 
|  | 1363 | { | 
|  | 1364 | public: | 
|  | 1365 | DelayedAddObjCClassProperty | 
|  | 1366 | ( | 
|  | 1367 | clang::ASTContext      *ast, | 
|  | 1368 | lldb::clang_type_t      class_opaque_type, | 
|  | 1369 | const char             *property_name, | 
|  | 1370 | lldb::clang_type_t      property_opaque_type,  // The property type is only required if you don't have an ivar decl | 
|  | 1371 | clang::ObjCIvarDecl    *ivar_decl, | 
|  | 1372 | const char             *property_setter_name, | 
|  | 1373 | const char             *property_getter_name, | 
|  | 1374 | uint32_t                property_attributes, | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1375 | const ClangASTMetadata *metadata | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1376 | ) : | 
|  | 1377 | m_ast                   (ast), | 
|  | 1378 | m_class_opaque_type     (class_opaque_type), | 
|  | 1379 | m_property_name         (property_name), | 
|  | 1380 | m_property_opaque_type  (property_opaque_type), | 
|  | 1381 | m_ivar_decl             (ivar_decl), | 
|  | 1382 | m_property_setter_name  (property_setter_name), | 
|  | 1383 | m_property_getter_name  (property_getter_name), | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1384 | m_property_attributes   (property_attributes) | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1385 | { | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1386 | if (metadata != NULL) | 
|  | 1387 | { | 
|  | 1388 | m_metadata_ap.reset(new ClangASTMetadata()); | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1389 | *m_metadata_ap = *metadata; | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1390 | } | 
|  | 1391 | } | 
|  | 1392 |  | 
|  | 1393 | DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs) | 
|  | 1394 | { | 
| Daniel Malea | d4c5be6 | 2012-11-12 21:02:14 +0000 | [diff] [blame] | 1395 | *this = rhs; | 
|  | 1396 | } | 
|  | 1397 |  | 
|  | 1398 | DelayedAddObjCClassProperty& operator= (const DelayedAddObjCClassProperty &rhs) | 
|  | 1399 | { | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1400 | m_ast                  = rhs.m_ast; | 
|  | 1401 | m_class_opaque_type    = rhs.m_class_opaque_type; | 
|  | 1402 | m_property_name        = rhs.m_property_name; | 
|  | 1403 | m_property_opaque_type = rhs.m_property_opaque_type; | 
|  | 1404 | m_ivar_decl            = rhs.m_ivar_decl; | 
|  | 1405 | m_property_setter_name = rhs.m_property_setter_name; | 
|  | 1406 | m_property_getter_name = rhs.m_property_getter_name; | 
|  | 1407 | m_property_attributes  = rhs.m_property_attributes; | 
|  | 1408 |  | 
|  | 1409 | if (rhs.m_metadata_ap.get()) | 
|  | 1410 | { | 
|  | 1411 | m_metadata_ap.reset (new ClangASTMetadata()); | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1412 | *m_metadata_ap = *rhs.m_metadata_ap; | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1413 | } | 
| Daniel Malea | d4c5be6 | 2012-11-12 21:02:14 +0000 | [diff] [blame] | 1414 | return *this; | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1415 | } | 
|  | 1416 |  | 
|  | 1417 | bool Finalize() const | 
|  | 1418 | { | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1419 | return ClangASTContext::AddObjCClassProperty (m_ast, | 
|  | 1420 | m_class_opaque_type, | 
|  | 1421 | m_property_name, | 
|  | 1422 | m_property_opaque_type, | 
|  | 1423 | m_ivar_decl, | 
|  | 1424 | m_property_setter_name, | 
|  | 1425 | m_property_getter_name, | 
|  | 1426 | m_property_attributes, | 
|  | 1427 | m_metadata_ap.get()); | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1428 | } | 
|  | 1429 | private: | 
|  | 1430 | clang::ASTContext      *m_ast; | 
|  | 1431 | lldb::clang_type_t      m_class_opaque_type; | 
|  | 1432 | const char             *m_property_name; | 
|  | 1433 | lldb::clang_type_t      m_property_opaque_type; | 
|  | 1434 | clang::ObjCIvarDecl    *m_ivar_decl; | 
|  | 1435 | const char             *m_property_setter_name; | 
|  | 1436 | const char             *m_property_getter_name; | 
|  | 1437 | uint32_t                m_property_attributes; | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1438 | std::auto_ptr<ClangASTMetadata> m_metadata_ap; | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1439 | }; | 
|  | 1440 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1441 | struct BitfieldInfo | 
|  | 1442 | { | 
|  | 1443 | uint64_t bit_size; | 
|  | 1444 | uint64_t bit_offset; | 
|  | 1445 |  | 
|  | 1446 | BitfieldInfo () : | 
|  | 1447 | bit_size (LLDB_INVALID_ADDRESS), | 
|  | 1448 | bit_offset (LLDB_INVALID_ADDRESS) | 
|  | 1449 | { | 
|  | 1450 | } | 
|  | 1451 |  | 
|  | 1452 | bool IsValid () | 
|  | 1453 | { | 
|  | 1454 | return (bit_size != LLDB_INVALID_ADDRESS) && | 
|  | 1455 | (bit_offset != LLDB_INVALID_ADDRESS); | 
|  | 1456 | } | 
|  | 1457 | }; | 
|  | 1458 |  | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1459 |  | 
|  | 1460 | bool | 
|  | 1461 | SymbolFileDWARF::ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu, | 
|  | 1462 | const DWARFDebugInfoEntry *parent_die) | 
|  | 1463 | { | 
|  | 1464 | if (parent_die) | 
|  | 1465 | { | 
|  | 1466 | for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) | 
|  | 1467 | { | 
|  | 1468 | dw_tag_t tag = die->Tag(); | 
|  | 1469 | bool check_virtuality = false; | 
|  | 1470 | switch (tag) | 
|  | 1471 | { | 
|  | 1472 | case DW_TAG_inheritance: | 
|  | 1473 | case DW_TAG_subprogram: | 
|  | 1474 | check_virtuality = true; | 
|  | 1475 | break; | 
|  | 1476 | default: | 
|  | 1477 | break; | 
|  | 1478 | } | 
|  | 1479 | if (check_virtuality) | 
|  | 1480 | { | 
|  | 1481 | if (die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_virtuality, 0) != 0) | 
|  | 1482 | return true; | 
|  | 1483 | } | 
|  | 1484 | } | 
|  | 1485 | } | 
|  | 1486 | return false; | 
|  | 1487 | } | 
|  | 1488 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1489 | size_t | 
|  | 1490 | SymbolFileDWARF::ParseChildMembers | 
|  | 1491 | ( | 
|  | 1492 | const SymbolContext& sc, | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1493 | DWARFCompileUnit* dwarf_cu, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1494 | const DWARFDebugInfoEntry *parent_die, | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1495 | clang_type_t class_clang_type, | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1496 | const LanguageType class_language, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1497 | std::vector<clang::CXXBaseSpecifier *>& base_classes, | 
|  | 1498 | std::vector<int>& member_accessibilities, | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1499 | DWARFDIECollection& member_function_dies, | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1500 | DelayedPropertyList& delayed_properties, | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1501 | AccessType& default_accessibility, | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1502 | bool &is_a_class, | 
|  | 1503 | LayoutInfo &layout_info | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1504 | ) | 
|  | 1505 | { | 
|  | 1506 | if (parent_die == NULL) | 
|  | 1507 | return 0; | 
|  | 1508 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1509 | size_t count = 0; | 
|  | 1510 | const DWARFDebugInfoEntry *die; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 1511 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1512 | uint32_t member_idx = 0; | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1513 | BitfieldInfo last_field_info; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 1514 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1515 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) | 
|  | 1516 | { | 
|  | 1517 | dw_tag_t tag = die->Tag(); | 
|  | 1518 |  | 
|  | 1519 | switch (tag) | 
|  | 1520 | { | 
|  | 1521 | case DW_TAG_member: | 
| Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1522 | case DW_TAG_APPLE_property: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1523 | { | 
|  | 1524 | DWARFDebugInfoEntry::Attributes attributes; | 
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1525 | const size_t num_attributes = die->GetAttributes (this, | 
|  | 1526 | dwarf_cu, | 
|  | 1527 | fixed_form_sizes, | 
|  | 1528 | attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1529 | if (num_attributes > 0) | 
|  | 1530 | { | 
|  | 1531 | Declaration decl; | 
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1532 | //DWARFExpression location; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1533 | const char *name = NULL; | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1534 | const char *prop_name = NULL; | 
|  | 1535 | const char *prop_getter_name = NULL; | 
|  | 1536 | const char *prop_setter_name = NULL; | 
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1537 | uint32_t prop_attributes = 0; | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1538 |  | 
|  | 1539 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1540 | bool is_artificial = false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1541 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1542 | AccessType accessibility = eAccessNone; | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1543 | uint32_t member_byte_offset = UINT32_MAX; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1544 | size_t byte_size = 0; | 
|  | 1545 | size_t bit_offset = 0; | 
|  | 1546 | size_t bit_size = 0; | 
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1547 | 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] | 1548 | uint32_t i; | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1549 | for (i=0; i<num_attributes && !is_artificial; ++i) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1550 | { | 
|  | 1551 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 1552 | DWARFFormValue form_value; | 
|  | 1553 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 1554 | { | 
|  | 1555 | switch (attr) | 
|  | 1556 | { | 
|  | 1557 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 1558 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 1559 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 1560 | case DW_AT_name:        name = form_value.AsCString(&get_debug_str_data()); break; | 
|  | 1561 | case DW_AT_type:        encoding_uid = form_value.Reference(dwarf_cu); break; | 
|  | 1562 | case DW_AT_bit_offset:  bit_offset = form_value.Unsigned(); break; | 
|  | 1563 | case DW_AT_bit_size:    bit_size = form_value.Unsigned(); break; | 
|  | 1564 | case DW_AT_byte_size:   byte_size = form_value.Unsigned(); break; | 
|  | 1565 | case DW_AT_data_member_location: | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1566 | if (form_value.BlockData()) | 
|  | 1567 | { | 
|  | 1568 | Value initialValue(0); | 
|  | 1569 | Value memberOffset(0); | 
|  | 1570 | const DataExtractor& debug_info_data = get_debug_info_data(); | 
|  | 1571 | uint32_t block_length = form_value.Unsigned(); | 
|  | 1572 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); | 
|  | 1573 | if (DWARFExpression::Evaluate(NULL, // ExecutionContext * | 
|  | 1574 | NULL, // clang::ASTContext * | 
|  | 1575 | NULL, // ClangExpressionVariableList * | 
|  | 1576 | NULL, // ClangExpressionDeclMap * | 
|  | 1577 | NULL, // RegisterContext * | 
|  | 1578 | debug_info_data, | 
|  | 1579 | block_offset, | 
|  | 1580 | block_length, | 
|  | 1581 | eRegisterKindDWARF, | 
|  | 1582 | &initialValue, | 
|  | 1583 | memberOffset, | 
|  | 1584 | NULL)) | 
|  | 1585 | { | 
|  | 1586 | member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt(); | 
|  | 1587 | } | 
|  | 1588 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1589 | break; | 
|  | 1590 |  | 
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1591 | case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break; | 
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1592 | case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break; | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1593 | case DW_AT_APPLE_property_name:      prop_name = form_value.AsCString(&get_debug_str_data()); break; | 
|  | 1594 | case DW_AT_APPLE_property_getter:    prop_getter_name = form_value.AsCString(&get_debug_str_data()); break; | 
|  | 1595 | case DW_AT_APPLE_property_setter:    prop_setter_name = form_value.AsCString(&get_debug_str_data()); break; | 
|  | 1596 | case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break; | 
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1597 | case DW_AT_external:                 is_external = form_value.Unsigned() != 0; break; | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1598 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1599 | default: | 
| Greg Clayton | 1b02c17 | 2012-03-14 21:00:47 +0000 | [diff] [blame] | 1600 | case DW_AT_declaration: | 
|  | 1601 | case DW_AT_description: | 
|  | 1602 | case DW_AT_mutable: | 
|  | 1603 | case DW_AT_visibility: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1604 | case DW_AT_sibling: | 
|  | 1605 | break; | 
|  | 1606 | } | 
|  | 1607 | } | 
|  | 1608 | } | 
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1609 |  | 
|  | 1610 | if (prop_name) | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1611 | { | 
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1612 | ConstString fixed_getter; | 
|  | 1613 | ConstString fixed_setter; | 
|  | 1614 |  | 
|  | 1615 | // Check if the property getter/setter were provided as full | 
|  | 1616 | // names.  We want basenames, so we extract them. | 
|  | 1617 |  | 
|  | 1618 | if (prop_getter_name && prop_getter_name[0] == '-') | 
|  | 1619 | { | 
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 1620 | ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true); | 
|  | 1621 | prop_getter_name = prop_getter_method.GetSelector().GetCString(); | 
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1622 | } | 
|  | 1623 |  | 
|  | 1624 | if (prop_setter_name && prop_setter_name[0] == '-') | 
|  | 1625 | { | 
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 1626 | ObjCLanguageRuntime::MethodName prop_setter_method(prop_setter_name, true); | 
|  | 1627 | prop_setter_name = prop_setter_method.GetSelector().GetCString(); | 
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1628 | } | 
|  | 1629 |  | 
|  | 1630 | // If the names haven't been provided, they need to be | 
|  | 1631 | // filled in. | 
|  | 1632 |  | 
|  | 1633 | if (!prop_getter_name) | 
|  | 1634 | { | 
|  | 1635 | prop_getter_name = prop_name; | 
|  | 1636 | } | 
|  | 1637 | if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly)) | 
|  | 1638 | { | 
|  | 1639 | StreamString ss; | 
|  | 1640 |  | 
|  | 1641 | ss.Printf("set%c%s:", | 
|  | 1642 | toupper(prop_name[0]), | 
|  | 1643 | &prop_name[1]); | 
|  | 1644 |  | 
|  | 1645 | fixed_setter.SetCString(ss.GetData()); | 
|  | 1646 | prop_setter_name = fixed_setter.GetCString(); | 
|  | 1647 | } | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1648 | } | 
|  | 1649 |  | 
|  | 1650 | // Clang has a DWARF generation bug where sometimes it | 
| Greg Clayton | 4495393 | 2011-10-25 01:25:35 +0000 | [diff] [blame] | 1651 | // represents fields that are references with bad byte size | 
|  | 1652 | // and bit size/offset information such as: | 
|  | 1653 | // | 
|  | 1654 | //  DW_AT_byte_size( 0x00 ) | 
|  | 1655 | //  DW_AT_bit_size( 0x40 ) | 
|  | 1656 | //  DW_AT_bit_offset( 0xffffffffffffffc0 ) | 
|  | 1657 | // | 
|  | 1658 | // So check the bit offset to make sure it is sane, and if | 
|  | 1659 | // the values are not sane, remove them. If we don't do this | 
|  | 1660 | // then we will end up with a crash if we try to use this | 
|  | 1661 | // type in an expression when clang becomes unhappy with its | 
|  | 1662 | // recycled debug info. | 
| Sean Callanan | 5a477cf | 2010-10-30 01:56:10 +0000 | [diff] [blame] | 1663 |  | 
| Greg Clayton | 4495393 | 2011-10-25 01:25:35 +0000 | [diff] [blame] | 1664 | if (bit_offset > 128) | 
|  | 1665 | { | 
|  | 1666 | bit_size = 0; | 
|  | 1667 | bit_offset = 0; | 
|  | 1668 | } | 
|  | 1669 |  | 
|  | 1670 | // FIXME: Make Clang ignore Objective-C accessibility for expressions | 
| Sean Callanan | 5a477cf | 2010-10-30 01:56:10 +0000 | [diff] [blame] | 1671 | if (class_language == eLanguageTypeObjC || | 
|  | 1672 | class_language == eLanguageTypeObjC_plus_plus) | 
|  | 1673 | accessibility = eAccessNone; | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1674 |  | 
|  | 1675 | if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name)) | 
|  | 1676 | { | 
|  | 1677 | // Not all compilers will mark the vtable pointer | 
|  | 1678 | // member as artificial (llvm-gcc). We can't have | 
|  | 1679 | // the virtual members in our classes otherwise it | 
|  | 1680 | // throws off all child offsets since we end up | 
|  | 1681 | // having and extra pointer sized member in our | 
|  | 1682 | // class layouts. | 
|  | 1683 | is_artificial = true; | 
|  | 1684 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1685 |  | 
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1686 | // Skip static members | 
|  | 1687 | if (is_external && member_byte_offset == UINT32_MAX) | 
|  | 1688 | break; | 
|  | 1689 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1690 | if (is_artificial == false) | 
|  | 1691 | { | 
|  | 1692 | Type *member_type = ResolveTypeUID(encoding_uid); | 
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 1693 |  | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1694 | clang::FieldDecl *field_decl = NULL; | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1695 | if (tag == DW_TAG_member) | 
| Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1696 | { | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1697 | if (member_type) | 
|  | 1698 | { | 
|  | 1699 | if (accessibility == eAccessNone) | 
|  | 1700 | accessibility = default_accessibility; | 
|  | 1701 | member_accessibilities.push_back(accessibility); | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1702 |  | 
|  | 1703 | BitfieldInfo this_field_info; | 
|  | 1704 |  | 
|  | 1705 | this_field_info.bit_size = bit_size; | 
|  | 1706 |  | 
|  | 1707 | if (member_byte_offset != UINT32_MAX || bit_size != 0) | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1708 | { | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1709 | ///////////////////////////////////////////////////////////// | 
|  | 1710 | // How to locate a field given the DWARF debug information | 
|  | 1711 | // | 
|  | 1712 | // AT_byte_size indicates the size of the word in which the | 
|  | 1713 | // bit offset must be interpreted. | 
|  | 1714 | // | 
|  | 1715 | // AT_data_member_location indicates the byte offset of the | 
|  | 1716 | // word from the base address of the structure. | 
|  | 1717 | // | 
|  | 1718 | // AT_bit_offset indicates how many bits into the word | 
|  | 1719 | // (according to the host endianness) the low-order bit of | 
|  | 1720 | // the field starts.  AT_bit_offset can be negative. | 
|  | 1721 | // | 
|  | 1722 | // AT_bit_size indicates the size of the field in bits. | 
|  | 1723 | ///////////////////////////////////////////////////////////// | 
|  | 1724 |  | 
|  | 1725 | this_field_info.bit_offset = 0; | 
|  | 1726 |  | 
|  | 1727 | this_field_info.bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8)); | 
|  | 1728 |  | 
|  | 1729 | if (GetObjectFile()->GetByteOrder() == eByteOrderLittle) | 
|  | 1730 | { | 
|  | 1731 | this_field_info.bit_offset += byte_size * 8; | 
|  | 1732 | this_field_info.bit_offset -= (bit_offset + bit_size); | 
|  | 1733 | } | 
|  | 1734 | else | 
|  | 1735 | { | 
|  | 1736 | this_field_info.bit_offset += bit_offset; | 
|  | 1737 | } | 
|  | 1738 | } | 
|  | 1739 |  | 
|  | 1740 | // If the member to be emitted did not start on a character boundary and there is | 
|  | 1741 | // empty space between the last field and this one, then we need to emit an | 
|  | 1742 | // anonymous member filling up the space up to its start.  There are three cases | 
|  | 1743 | // here: | 
|  | 1744 | // | 
|  | 1745 | // 1 If the previous member ended on a character boundary, then we can emit an | 
|  | 1746 | //   anonymous member starting at the most recent character boundary. | 
|  | 1747 | // | 
|  | 1748 | // 2 If the previous member did not end on a character boundary and the distance | 
|  | 1749 | //   from the end of the previous member to the current member is less than a | 
|  | 1750 | //   word width, then we can emit an anonymous member starting right after the | 
|  | 1751 | //   previous member and right before this member. | 
|  | 1752 | // | 
|  | 1753 | // 3 If the previous member did not end on a character boundary and the distance | 
|  | 1754 | //   from the end of the previous member to the current member is greater than | 
|  | 1755 | //   or equal a word width, then we act as in Case 1. | 
|  | 1756 |  | 
|  | 1757 | const uint64_t character_width = 8; | 
|  | 1758 | const uint64_t word_width = 32; | 
|  | 1759 |  | 
|  | 1760 | if (this_field_info.IsValid()) | 
|  | 1761 | { | 
|  | 1762 | // Objective-C has invalid DW_AT_bit_offset values in older versions | 
|  | 1763 | // 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] | 1764 | // if we have a new enough clang. | 
|  | 1765 | bool detect_unnamed_bitfields = true; | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1766 |  | 
| Greg Clayton | 37c36e4 | 2012-11-27 00:59:26 +0000 | [diff] [blame] | 1767 | if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus) | 
|  | 1768 | detect_unnamed_bitfields = dwarf_cu->Supports_unnamed_objc_bitfields (); | 
|  | 1769 |  | 
|  | 1770 | if (detect_unnamed_bitfields) | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1771 | { | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1772 | BitfieldInfo anon_field_info; | 
|  | 1773 |  | 
|  | 1774 | if ((this_field_info.bit_offset % character_width) != 0) // not char aligned | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1775 | { | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1776 | uint64_t last_field_end = 0; | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1777 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1778 | if (last_field_info.IsValid()) | 
|  | 1779 | 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] | 1780 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1781 | if (this_field_info.bit_offset != last_field_end) | 
|  | 1782 | { | 
|  | 1783 | if (((last_field_end % character_width) == 0) ||                    // case 1 | 
|  | 1784 | (this_field_info.bit_offset - last_field_end >= word_width))    // case 3 | 
|  | 1785 | { | 
|  | 1786 | anon_field_info.bit_size = this_field_info.bit_offset % character_width; | 
|  | 1787 | anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size; | 
|  | 1788 | } | 
|  | 1789 | else                                                                // case 2 | 
|  | 1790 | { | 
|  | 1791 | anon_field_info.bit_size = this_field_info.bit_offset - last_field_end; | 
|  | 1792 | anon_field_info.bit_offset = last_field_end; | 
|  | 1793 | } | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1794 | } | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1795 | } | 
|  | 1796 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1797 | if (anon_field_info.IsValid()) | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1798 | { | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1799 | clang::FieldDecl *unnamed_bitfield_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type, | 
|  | 1800 | NULL, | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1801 | GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width), | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1802 | accessibility, | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1803 | anon_field_info.bit_size); | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1804 |  | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1805 | 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] | 1806 | } | 
|  | 1807 | } | 
|  | 1808 | } | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1809 |  | 
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 1810 | clang_type_t member_clang_type = member_type->GetClangLayoutType(); | 
|  | 1811 |  | 
|  | 1812 | { | 
|  | 1813 | // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>). | 
|  | 1814 | // If the current field is at the end of the structure, then there is definitely no room for extra | 
|  | 1815 | // elements and we override the type to array[0]. | 
|  | 1816 |  | 
|  | 1817 | clang_type_t member_array_element_type; | 
|  | 1818 | uint64_t member_array_size; | 
|  | 1819 | bool member_array_is_incomplete; | 
|  | 1820 |  | 
|  | 1821 | if (GetClangASTContext().IsArrayType(member_clang_type, | 
|  | 1822 | &member_array_element_type, | 
|  | 1823 | &member_array_size, | 
|  | 1824 | &member_array_is_incomplete) && | 
|  | 1825 | !member_array_is_incomplete) | 
|  | 1826 | { | 
|  | 1827 | uint64_t parent_byte_size = parent_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, UINT64_MAX); | 
|  | 1828 |  | 
|  | 1829 | if (member_byte_offset >= parent_byte_size) | 
|  | 1830 | { | 
|  | 1831 | if (member_array_size != 1) | 
|  | 1832 | { | 
|  | 1833 | 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, | 
|  | 1834 | MakeUserID(die->GetOffset()), | 
|  | 1835 | name, | 
|  | 1836 | encoding_uid, | 
|  | 1837 | MakeUserID(parent_die->GetOffset())); | 
|  | 1838 | } | 
|  | 1839 |  | 
|  | 1840 | member_clang_type = GetClangASTContext().CreateArrayType(member_array_element_type, 0); | 
|  | 1841 | } | 
|  | 1842 | } | 
|  | 1843 | } | 
|  | 1844 |  | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1845 | field_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type, | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1846 | name, | 
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 1847 | member_clang_type, | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1848 | accessibility, | 
|  | 1849 | bit_size); | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 1850 |  | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 1851 | GetClangASTContext().SetMetadataAsUserID (field_decl, MakeUserID(die->GetOffset())); | 
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1852 |  | 
|  | 1853 | if (this_field_info.IsValid()) | 
|  | 1854 | { | 
|  | 1855 | layout_info.field_offsets.insert(std::make_pair(field_decl, this_field_info.bit_offset)); | 
|  | 1856 | last_field_info = this_field_info; | 
|  | 1857 | } | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1858 | } | 
|  | 1859 | else | 
|  | 1860 | { | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1861 | if (name) | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1862 | 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] | 1863 | MakeUserID(die->GetOffset()), | 
|  | 1864 | name, | 
|  | 1865 | encoding_uid); | 
|  | 1866 | else | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1867 | 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] | 1868 | MakeUserID(die->GetOffset()), | 
|  | 1869 | encoding_uid); | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1870 | } | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1871 | } | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1872 |  | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1873 | if (prop_name != NULL) | 
|  | 1874 | { | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1875 | clang::ObjCIvarDecl *ivar_decl = NULL; | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1876 |  | 
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1877 | if (field_decl) | 
|  | 1878 | { | 
|  | 1879 | ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl); | 
|  | 1880 | assert (ivar_decl != NULL); | 
|  | 1881 | } | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1882 |  | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1883 | ClangASTMetadata metadata; | 
|  | 1884 | metadata.SetUserID (MakeUserID(die->GetOffset())); | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1885 | delayed_properties.push_back(DelayedAddObjCClassProperty(GetClangASTContext().getASTContext(), | 
|  | 1886 | class_clang_type, | 
|  | 1887 | prop_name, | 
|  | 1888 | member_type->GetClangLayoutType(), | 
|  | 1889 | ivar_decl, | 
|  | 1890 | prop_setter_name, | 
|  | 1891 | prop_getter_name, | 
|  | 1892 | prop_attributes, | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1893 | &metadata)); | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 1894 |  | 
| Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 1895 | if (ivar_decl) | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 1896 | GetClangASTContext().SetMetadataAsUserID (ivar_decl, MakeUserID(die->GetOffset())); | 
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1897 | } | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1898 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1899 | } | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1900 | ++member_idx; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1901 | } | 
|  | 1902 | break; | 
|  | 1903 |  | 
|  | 1904 | case DW_TAG_subprogram: | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1905 | // Let the type parsing code handle this one for us. | 
|  | 1906 | member_function_dies.Append (die); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1907 | break; | 
|  | 1908 |  | 
|  | 1909 | case DW_TAG_inheritance: | 
|  | 1910 | { | 
|  | 1911 | is_a_class = true; | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1912 | if (default_accessibility == eAccessNone) | 
|  | 1913 | default_accessibility = eAccessPrivate; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1914 | // TODO: implement DW_TAG_inheritance type parsing | 
|  | 1915 | DWARFDebugInfoEntry::Attributes attributes; | 
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1916 | const size_t num_attributes = die->GetAttributes (this, | 
|  | 1917 | dwarf_cu, | 
|  | 1918 | fixed_form_sizes, | 
|  | 1919 | attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1920 | if (num_attributes > 0) | 
|  | 1921 | { | 
|  | 1922 | Declaration decl; | 
|  | 1923 | DWARFExpression location; | 
|  | 1924 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1925 | AccessType accessibility = default_accessibility; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1926 | bool is_virtual = false; | 
|  | 1927 | bool is_base_of_class = true; | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 1928 | off_t member_byte_offset = 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1929 | uint32_t i; | 
|  | 1930 | for (i=0; i<num_attributes; ++i) | 
|  | 1931 | { | 
|  | 1932 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 1933 | DWARFFormValue form_value; | 
|  | 1934 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 1935 | { | 
|  | 1936 | switch (attr) | 
|  | 1937 | { | 
|  | 1938 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 1939 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 1940 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 1941 | case DW_AT_type:        encoding_uid = form_value.Reference(dwarf_cu); break; | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 1942 | case DW_AT_data_member_location: | 
|  | 1943 | if (form_value.BlockData()) | 
|  | 1944 | { | 
|  | 1945 | Value initialValue(0); | 
|  | 1946 | Value memberOffset(0); | 
|  | 1947 | const DataExtractor& debug_info_data = get_debug_info_data(); | 
|  | 1948 | uint32_t block_length = form_value.Unsigned(); | 
|  | 1949 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); | 
|  | 1950 | if (DWARFExpression::Evaluate (NULL, | 
|  | 1951 | NULL, | 
|  | 1952 | NULL, | 
|  | 1953 | NULL, | 
|  | 1954 | NULL, | 
|  | 1955 | debug_info_data, | 
|  | 1956 | block_offset, | 
|  | 1957 | block_length, | 
|  | 1958 | eRegisterKindDWARF, | 
|  | 1959 | &initialValue, | 
|  | 1960 | memberOffset, | 
|  | 1961 | NULL)) | 
|  | 1962 | { | 
|  | 1963 | member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt(); | 
|  | 1964 | } | 
|  | 1965 | } | 
|  | 1966 | break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1967 |  | 
|  | 1968 | case DW_AT_accessibility: | 
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1969 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1970 | break; | 
|  | 1971 |  | 
|  | 1972 | case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break; | 
|  | 1973 | default: | 
|  | 1974 | case DW_AT_sibling: | 
|  | 1975 | break; | 
|  | 1976 | } | 
|  | 1977 | } | 
|  | 1978 | } | 
|  | 1979 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 1980 | Type *base_class_type = ResolveTypeUID(encoding_uid); | 
|  | 1981 | assert(base_class_type); | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1982 |  | 
| Greg Clayton | f4ecaa5 | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 1983 | clang_type_t base_class_clang_type = base_class_type->GetClangFullType(); | 
|  | 1984 | assert (base_class_clang_type); | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1985 | if (class_language == eLanguageTypeObjC) | 
|  | 1986 | { | 
| Greg Clayton | f4ecaa5 | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 1987 | GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type); | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1988 | } | 
|  | 1989 | else | 
|  | 1990 | { | 
| Greg Clayton | f4ecaa5 | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 1991 | base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type, | 
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1992 | accessibility, | 
|  | 1993 | is_virtual, | 
|  | 1994 | is_base_of_class)); | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 1995 |  | 
|  | 1996 | if (is_virtual) | 
|  | 1997 | { | 
|  | 1998 | layout_info.vbase_offsets.insert(std::make_pair(ClangASTType::GetAsCXXRecordDecl(class_clang_type), | 
|  | 1999 | clang::CharUnits::fromQuantity(member_byte_offset))); | 
|  | 2000 | } | 
|  | 2001 | else | 
|  | 2002 | { | 
|  | 2003 | layout_info.base_offsets.insert(std::make_pair(ClangASTType::GetAsCXXRecordDecl(class_clang_type), | 
|  | 2004 | clang::CharUnits::fromQuantity(member_byte_offset))); | 
|  | 2005 | } | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2006 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2007 | } | 
|  | 2008 | } | 
|  | 2009 | break; | 
|  | 2010 |  | 
|  | 2011 | default: | 
|  | 2012 | break; | 
|  | 2013 | } | 
|  | 2014 | } | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2015 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2016 | return count; | 
|  | 2017 | } | 
|  | 2018 |  | 
|  | 2019 |  | 
|  | 2020 | clang::DeclContext* | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 2021 | SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2022 | { | 
|  | 2023 | DWARFDebugInfo* debug_info = DebugInfo(); | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2024 | if (debug_info && UserIDMatches(type_uid)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2025 | { | 
|  | 2026 | DWARFCompileUnitSP cu_sp; | 
|  | 2027 | const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp); | 
|  | 2028 | if (die) | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 2029 | return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL); | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 2030 | } | 
|  | 2031 | return NULL; | 
|  | 2032 | } | 
|  | 2033 |  | 
|  | 2034 | clang::DeclContext* | 
|  | 2035 | SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid) | 
|  | 2036 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2037 | if (UserIDMatches(type_uid)) | 
|  | 2038 | return GetClangDeclContextForDIEOffset (sc, type_uid); | 
|  | 2039 | return NULL; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2040 | } | 
|  | 2041 |  | 
|  | 2042 | Type* | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2043 | SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2044 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2045 | if (UserIDMatches(type_uid)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2046 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2047 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 2048 | if (debug_info) | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2049 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2050 | DWARFCompileUnitSP cu_sp; | 
|  | 2051 | const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp); | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2052 | const bool assert_not_being_parsed = true; | 
|  | 2053 | return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed); | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2054 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2055 | } | 
|  | 2056 | return NULL; | 
|  | 2057 | } | 
|  | 2058 |  | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2059 | Type* | 
|  | 2060 | SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed) | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2061 | { | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2062 | if (die != NULL) | 
|  | 2063 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2064 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2065 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2066 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2067 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'", | 
|  | 2068 | die->GetOffset(), | 
|  | 2069 | DW_TAG_value_to_name(die->Tag()), | 
|  | 2070 | die->GetName(this, cu)); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2071 |  | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2072 | // We might be coming in in the middle of a type tree (a class | 
|  | 2073 | // withing a class, an enum within a class), so parse any needed | 
|  | 2074 | // parent DIEs before we get to this one... | 
|  | 2075 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); | 
|  | 2076 | switch (decl_ctx_die->Tag()) | 
|  | 2077 | { | 
|  | 2078 | case DW_TAG_structure_type: | 
|  | 2079 | case DW_TAG_union_type: | 
|  | 2080 | case DW_TAG_class_type: | 
|  | 2081 | { | 
|  | 2082 | // Get the type, which could be a forward declaration | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2083 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2084 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2085 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x", | 
|  | 2086 | die->GetOffset(), | 
|  | 2087 | DW_TAG_value_to_name(die->Tag()), | 
|  | 2088 | die->GetName(this, cu), | 
|  | 2089 | decl_ctx_die->GetOffset()); | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2090 | // | 
|  | 2091 | //                Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed); | 
|  | 2092 | //                if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag())) | 
|  | 2093 | //                { | 
|  | 2094 | //                    if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2095 | //                        GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2096 | //                                                                  "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function", | 
|  | 2097 | //                                                                  die->GetOffset(), | 
|  | 2098 | //                                                                  DW_TAG_value_to_name(die->Tag()), | 
|  | 2099 | //                                                                  die->GetName(this, cu), | 
|  | 2100 | //                                                                  decl_ctx_die->GetOffset()); | 
|  | 2101 | //                    // Ask the type to complete itself if it already hasn't since if we | 
|  | 2102 | //                    // want a function (method or static) from a class, the class must | 
|  | 2103 | //                    // create itself and add it's own methods and class functions. | 
|  | 2104 | //                    if (parent_type) | 
|  | 2105 | //                        parent_type->GetClangFullType(); | 
|  | 2106 | //                } | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2107 | } | 
|  | 2108 | break; | 
|  | 2109 |  | 
|  | 2110 | default: | 
|  | 2111 | break; | 
|  | 2112 | } | 
|  | 2113 | return ResolveType (cu, die); | 
|  | 2114 | } | 
|  | 2115 | return NULL; | 
|  | 2116 | } | 
|  | 2117 |  | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2118 | // This function is used when SymbolFileDWARFDebugMap owns a bunch of | 
|  | 2119 | // SymbolFileDWARF objects to detect if this DWARF file is the one that | 
|  | 2120 | // can resolve a clang_type. | 
|  | 2121 | bool | 
|  | 2122 | SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type) | 
|  | 2123 | { | 
|  | 2124 | clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type); | 
|  | 2125 | const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers); | 
|  | 2126 | return die != NULL; | 
|  | 2127 | } | 
|  | 2128 |  | 
|  | 2129 |  | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2130 | lldb::clang_type_t | 
|  | 2131 | SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type) | 
|  | 2132 | { | 
|  | 2133 | // 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] | 2134 | clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type); | 
|  | 2135 | 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] | 2136 | if (die == NULL) | 
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2137 | { | 
|  | 2138 | // We have already resolved this type... | 
|  | 2139 | return clang_type; | 
|  | 2140 | } | 
|  | 2141 | // Once we start resolving this type, remove it from the forward declaration | 
|  | 2142 | // map in case anyone child members or other types require this type to get resolved. | 
|  | 2143 | // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition | 
|  | 2144 | // are done. | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2145 | m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers); | 
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2146 |  | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2147 |  | 
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 2148 | // Disable external storage for this type so we don't get anymore | 
|  | 2149 | // clang::ExternalASTSource queries for this type. | 
|  | 2150 | ClangASTContext::SetHasExternalStorage (clang_type, false); | 
|  | 2151 |  | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2152 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 2153 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2154 | DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get(); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2155 | Type *type = m_die_to_type.lookup (die); | 
|  | 2156 |  | 
|  | 2157 | const dw_tag_t tag = die->Tag(); | 
|  | 2158 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2159 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION)); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2160 | if (log) | 
| Greg Clayton | baf95da | 2012-03-30 23:50:54 +0000 | [diff] [blame] | 2161 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2162 | GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2163 | "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...", | 
| Greg Clayton | d61c0fc | 2012-04-23 22:55:20 +0000 | [diff] [blame] | 2164 | MakeUserID(die->GetOffset()), | 
|  | 2165 | DW_TAG_value_to_name(tag), | 
|  | 2166 | type->GetName().AsCString()); | 
| Greg Clayton | baf95da | 2012-03-30 23:50:54 +0000 | [diff] [blame] | 2167 |  | 
| Greg Clayton | baf95da | 2012-03-30 23:50:54 +0000 | [diff] [blame] | 2168 | } | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2169 | assert (clang_type); | 
|  | 2170 | DWARFDebugInfoEntry::Attributes attributes; | 
|  | 2171 |  | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 2172 | ClangASTContext &ast = GetClangASTContext(); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2173 |  | 
|  | 2174 | switch (tag) | 
|  | 2175 | { | 
|  | 2176 | case DW_TAG_structure_type: | 
|  | 2177 | case DW_TAG_union_type: | 
|  | 2178 | case DW_TAG_class_type: | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2179 | { | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2180 | LayoutInfo layout_info; | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2181 |  | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2182 | { | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2183 | if (die->HasChildren()) | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2184 | { | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2185 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2186 | LanguageType class_language = eLanguageTypeUnknown; | 
|  | 2187 | bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type); | 
|  | 2188 | if (is_objc_class) | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2189 | { | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2190 | class_language = eLanguageTypeObjC; | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2191 | // For objective C we don't start the definition when | 
|  | 2192 | // the class is created. | 
|  | 2193 | ast.StartTagDeclarationDefinition (clang_type); | 
|  | 2194 | } | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2195 |  | 
|  | 2196 | int tag_decl_kind = -1; | 
|  | 2197 | AccessType default_accessibility = eAccessNone; | 
|  | 2198 | if (tag == DW_TAG_structure_type) | 
|  | 2199 | { | 
|  | 2200 | tag_decl_kind = clang::TTK_Struct; | 
|  | 2201 | default_accessibility = eAccessPublic; | 
|  | 2202 | } | 
|  | 2203 | else if (tag == DW_TAG_union_type) | 
|  | 2204 | { | 
|  | 2205 | tag_decl_kind = clang::TTK_Union; | 
|  | 2206 | default_accessibility = eAccessPublic; | 
|  | 2207 | } | 
|  | 2208 | else if (tag == DW_TAG_class_type) | 
|  | 2209 | { | 
|  | 2210 | tag_decl_kind = clang::TTK_Class; | 
|  | 2211 | default_accessibility = eAccessPrivate; | 
|  | 2212 | } | 
|  | 2213 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2214 | SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2215 | std::vector<clang::CXXBaseSpecifier *> base_classes; | 
|  | 2216 | std::vector<int> member_accessibilities; | 
|  | 2217 | bool is_a_class = false; | 
|  | 2218 | // Parse members and base classes first | 
|  | 2219 | DWARFDIECollection member_function_dies; | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2220 |  | 
|  | 2221 | DelayedPropertyList delayed_properties; | 
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2222 | ParseChildMembers (sc, | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2223 | dwarf_cu, | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2224 | die, | 
|  | 2225 | clang_type, | 
|  | 2226 | class_language, | 
|  | 2227 | base_classes, | 
|  | 2228 | member_accessibilities, | 
|  | 2229 | member_function_dies, | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2230 | delayed_properties, | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2231 | default_accessibility, | 
|  | 2232 | is_a_class, | 
|  | 2233 | layout_info); | 
|  | 2234 |  | 
|  | 2235 | // Now parse any methods if there were any... | 
|  | 2236 | size_t num_functions = member_function_dies.Size(); | 
|  | 2237 | if (num_functions > 0) | 
|  | 2238 | { | 
|  | 2239 | for (size_t i=0; i<num_functions; ++i) | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2240 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2241 | ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i)); | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2242 | } | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2243 | } | 
|  | 2244 |  | 
|  | 2245 | if (class_language == eLanguageTypeObjC) | 
|  | 2246 | { | 
| Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 2247 | std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(ast.getASTContext(), clang_type)); | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2248 | if (!class_str.empty()) | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2249 | { | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2250 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2251 | DIEArray method_die_offsets; | 
|  | 2252 | if (m_using_apple_tables) | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2253 | { | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2254 | if (m_apple_objc_ap.get()) | 
|  | 2255 | m_apple_objc_ap->FindByName(class_str.c_str(), method_die_offsets); | 
|  | 2256 | } | 
|  | 2257 | else | 
|  | 2258 | { | 
|  | 2259 | if (!m_indexed) | 
|  | 2260 | Index (); | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2261 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2262 | ConstString class_name (class_str.c_str()); | 
|  | 2263 | m_objc_class_selectors_index.Find (class_name, method_die_offsets); | 
|  | 2264 | } | 
|  | 2265 |  | 
|  | 2266 | if (!method_die_offsets.empty()) | 
|  | 2267 | { | 
|  | 2268 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 2269 |  | 
|  | 2270 | DWARFCompileUnit* method_cu = NULL; | 
|  | 2271 | const size_t num_matches = method_die_offsets.size(); | 
|  | 2272 | for (size_t i=0; i<num_matches; ++i) | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2273 | { | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2274 | const dw_offset_t die_offset = method_die_offsets[i]; | 
|  | 2275 | DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu); | 
|  | 2276 |  | 
|  | 2277 | if (method_die) | 
|  | 2278 | ResolveType (method_cu, method_die); | 
|  | 2279 | else | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2280 | { | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2281 | if (m_using_apple_tables) | 
|  | 2282 | { | 
|  | 2283 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n", | 
|  | 2284 | die_offset, class_str.c_str()); | 
|  | 2285 | } | 
|  | 2286 | } | 
|  | 2287 | } | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2288 | } | 
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2289 |  | 
|  | 2290 | for (DelayedPropertyList::const_iterator pi = delayed_properties.begin(), pe = delayed_properties.end(); | 
|  | 2291 | pi != pe; | 
|  | 2292 | ++pi) | 
|  | 2293 | pi->Finalize(); | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2294 | } | 
|  | 2295 | } | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2296 |  | 
|  | 2297 | // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we | 
|  | 2298 | // need to tell the clang type it is actually a class. | 
|  | 2299 | if (class_language != eLanguageTypeObjC) | 
|  | 2300 | { | 
|  | 2301 | if (is_a_class && tag_decl_kind != clang::TTK_Class) | 
|  | 2302 | ast.SetTagTypeKind (clang_type, clang::TTK_Class); | 
|  | 2303 | } | 
|  | 2304 |  | 
|  | 2305 | // Since DW_TAG_structure_type gets used for both classes | 
|  | 2306 | // and structures, we may need to set any DW_TAG_member | 
|  | 2307 | // fields to have a "private" access if none was specified. | 
|  | 2308 | // When we parsed the child members we tracked that actual | 
|  | 2309 | // accessibility value for each DW_TAG_member in the | 
|  | 2310 | // "member_accessibilities" array. If the value for the | 
|  | 2311 | // member is zero, then it was set to the "default_accessibility" | 
|  | 2312 | // which for structs was "public". Below we correct this | 
|  | 2313 | // by setting any fields to "private" that weren't correctly | 
|  | 2314 | // set. | 
|  | 2315 | if (is_a_class && !member_accessibilities.empty()) | 
|  | 2316 | { | 
|  | 2317 | // This is a class and all members that didn't have | 
|  | 2318 | // their access specified are private. | 
|  | 2319 | ast.SetDefaultAccessForRecordFields (clang_type, | 
|  | 2320 | eAccessPrivate, | 
|  | 2321 | &member_accessibilities.front(), | 
|  | 2322 | member_accessibilities.size()); | 
|  | 2323 | } | 
|  | 2324 |  | 
|  | 2325 | if (!base_classes.empty()) | 
|  | 2326 | { | 
|  | 2327 | ast.SetBaseClassesForClassType (clang_type, | 
|  | 2328 | &base_classes.front(), | 
|  | 2329 | base_classes.size()); | 
|  | 2330 |  | 
|  | 2331 | // Clang will copy each CXXBaseSpecifier in "base_classes" | 
|  | 2332 | // so we have to free them all. | 
|  | 2333 | ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(), | 
|  | 2334 | base_classes.size()); | 
|  | 2335 | } | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2336 | } | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2337 | } | 
| Sean Callanan | e8c0cfb | 2012-03-02 01:03:45 +0000 | [diff] [blame] | 2338 |  | 
|  | 2339 | ast.BuildIndirectFields (clang_type); | 
|  | 2340 |  | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2341 | ast.CompleteTagDeclarationDefinition (clang_type); | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2342 |  | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2343 | if (!layout_info.field_offsets.empty() || | 
|  | 2344 | !layout_info.base_offsets.empty()  || | 
|  | 2345 | !layout_info.vbase_offsets.empty() ) | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2346 | { | 
|  | 2347 | if (type) | 
|  | 2348 | layout_info.bit_size = type->GetByteSize() * 8; | 
|  | 2349 | if (layout_info.bit_size == 0) | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2350 | 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] | 2351 |  | 
|  | 2352 | clang::CXXRecordDecl *record_decl = ClangASTType::GetAsCXXRecordDecl(clang_type); | 
|  | 2353 | if (record_decl) | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2354 | { | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2355 | if (log) | 
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2356 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2357 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2358 | "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] | 2359 | clang_type, | 
|  | 2360 | record_decl, | 
|  | 2361 | layout_info.bit_size, | 
|  | 2362 | layout_info.alignment, | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2363 | (uint32_t)layout_info.field_offsets.size(), | 
|  | 2364 | (uint32_t)layout_info.base_offsets.size(), | 
|  | 2365 | (uint32_t)layout_info.vbase_offsets.size()); | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2366 |  | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2367 | uint32_t idx; | 
|  | 2368 | { | 
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2369 | 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] | 2370 | 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] | 2371 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2372 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2373 | "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = { bit_offset=%u, name='%s' }", | 
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2374 | clang_type, | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2375 | idx, | 
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2376 | (uint32_t)pos->second, | 
|  | 2377 | pos->first->getNameAsString().c_str()); | 
|  | 2378 | } | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2379 | } | 
|  | 2380 |  | 
|  | 2381 | { | 
|  | 2382 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos, base_end = layout_info.base_offsets.end(); | 
|  | 2383 | for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end; ++base_pos, ++idx) | 
|  | 2384 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2385 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2386 | "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] = { byte_offset=%u, name='%s' }", | 
|  | 2387 | clang_type, | 
|  | 2388 | idx, | 
|  | 2389 | (uint32_t)base_pos->second.getQuantity(), | 
|  | 2390 | base_pos->first->getNameAsString().c_str()); | 
|  | 2391 | } | 
|  | 2392 | } | 
|  | 2393 | { | 
|  | 2394 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos, vbase_end = layout_info.vbase_offsets.end(); | 
|  | 2395 | for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end; ++vbase_pos, ++idx) | 
|  | 2396 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2397 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2398 | "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) vbase[%u] = { byte_offset=%u, name='%s' }", | 
|  | 2399 | clang_type, | 
|  | 2400 | idx, | 
|  | 2401 | (uint32_t)vbase_pos->second.getQuantity(), | 
|  | 2402 | vbase_pos->first->getNameAsString().c_str()); | 
|  | 2403 | } | 
|  | 2404 | } | 
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2405 | } | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2406 | m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info)); | 
|  | 2407 | } | 
|  | 2408 | } | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2409 | } | 
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2410 |  | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2411 | return clang_type; | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2412 |  | 
|  | 2413 | case DW_TAG_enumeration_type: | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 2414 | ast.StartTagDeclarationDefinition (clang_type); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2415 | if (die->HasChildren()) | 
|  | 2416 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2417 | SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); | 
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 2418 | bool is_signed = false; | 
|  | 2419 | ast.IsIntegerType(clang_type, is_signed); | 
|  | 2420 | ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), dwarf_cu, die); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2421 | } | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 2422 | ast.CompleteTagDeclarationDefinition (clang_type); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2423 | return clang_type; | 
|  | 2424 |  | 
|  | 2425 | default: | 
|  | 2426 | assert(false && "not a forward clang type decl!"); | 
|  | 2427 | break; | 
|  | 2428 | } | 
|  | 2429 | return NULL; | 
|  | 2430 | } | 
|  | 2431 |  | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2432 | Type* | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2433 | 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] | 2434 | { | 
|  | 2435 | if (type_die != NULL) | 
|  | 2436 | { | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 2437 | Type *type = m_die_to_type.lookup (type_die); | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2438 |  | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2439 | if (type == NULL) | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2440 | type = GetTypeForDIE (dwarf_cu, type_die).get(); | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2441 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2442 | if (assert_not_being_parsed) | 
| Jim Ingham | c354928 | 2012-01-11 02:21:12 +0000 | [diff] [blame] | 2443 | { | 
|  | 2444 | if (type != DIE_IS_BEING_PARSED) | 
|  | 2445 | return type; | 
|  | 2446 |  | 
|  | 2447 | 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] | 2448 | type_die->GetOffset(), | 
|  | 2449 | DW_TAG_value_to_name(type_die->Tag()), | 
|  | 2450 | type_die->GetName(this, dwarf_cu)); | 
| Jim Ingham | c354928 | 2012-01-11 02:21:12 +0000 | [diff] [blame] | 2451 |  | 
|  | 2452 | } | 
|  | 2453 | else | 
|  | 2454 | return type; | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2455 | } | 
|  | 2456 | return NULL; | 
|  | 2457 | } | 
|  | 2458 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2459 | CompileUnit* | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2460 | SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2461 | { | 
|  | 2462 | // Check if the symbol vendor already knows about this compile unit? | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2463 | if (dwarf_cu->GetUserData() == NULL) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2464 | { | 
|  | 2465 | // The symbol vendor doesn't know about this compile unit, we | 
|  | 2466 | // need to parse and add it to the symbol vendor object. | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2467 | return ParseCompileUnit(dwarf_cu, cu_idx).get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2468 | } | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2469 | return (CompileUnit*)dwarf_cu->GetUserData(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2470 | } | 
|  | 2471 |  | 
|  | 2472 | bool | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2473 | SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2474 | { | 
| Greg Clayton | 7231035 | 2013-02-23 04:12:47 +0000 | [diff] [blame] | 2475 | sc.Clear(false); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2476 | // Check if the symbol vendor already knows about this compile unit? | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2477 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2478 |  | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2479 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2480 | if (sc.function == NULL) | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2481 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2482 |  | 
|  | 2483 | if (sc.function) | 
|  | 2484 | { | 
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 2485 | sc.module_sp = sc.function->CalculateSymbolContextModule(); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2486 | return true; | 
|  | 2487 | } | 
|  | 2488 |  | 
|  | 2489 | return false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2490 | } | 
|  | 2491 |  | 
|  | 2492 | uint32_t | 
|  | 2493 | SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) | 
|  | 2494 | { | 
|  | 2495 | Timer scoped_timer(__PRETTY_FUNCTION__, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2496 | "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] | 2497 | so_addr.GetSection().get(), | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2498 | so_addr.GetOffset(), | 
|  | 2499 | resolve_scope); | 
|  | 2500 | uint32_t resolved = 0; | 
|  | 2501 | if (resolve_scope & (   eSymbolContextCompUnit | | 
|  | 2502 | eSymbolContextFunction | | 
|  | 2503 | eSymbolContextBlock | | 
|  | 2504 | eSymbolContextLineEntry)) | 
|  | 2505 | { | 
|  | 2506 | lldb::addr_t file_vm_addr = so_addr.GetFileAddress(); | 
|  | 2507 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2508 | DWARFDebugInfo* debug_info = DebugInfo(); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2509 | if (debug_info) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2510 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2511 | 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] | 2512 | if (cu_offset != DW_INVALID_OFFSET) | 
|  | 2513 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2514 | uint32_t cu_idx = DW_INVALID_INDEX; | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2515 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get(); | 
|  | 2516 | if (dwarf_cu) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2517 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2518 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2519 | if (sc.comp_unit) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2520 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2521 | resolved |= eSymbolContextCompUnit; | 
|  | 2522 |  | 
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2523 | bool force_check_line_table = false; | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2524 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) | 
|  | 2525 | { | 
|  | 2526 | DWARFDebugInfoEntry *function_die = NULL; | 
|  | 2527 | DWARFDebugInfoEntry *block_die = NULL; | 
|  | 2528 | if (resolve_scope & eSymbolContextBlock) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2529 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2530 | dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die); | 
|  | 2531 | } | 
|  | 2532 | else | 
|  | 2533 | { | 
|  | 2534 | dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL); | 
|  | 2535 | } | 
|  | 2536 |  | 
|  | 2537 | if (function_die != NULL) | 
|  | 2538 | { | 
|  | 2539 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); | 
|  | 2540 | if (sc.function == NULL) | 
|  | 2541 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die); | 
|  | 2542 | } | 
|  | 2543 | else | 
|  | 2544 | { | 
|  | 2545 | // We might have had a compile unit that had discontiguous | 
|  | 2546 | // address ranges where the gaps are symbols that don't have | 
|  | 2547 | // any debug info. Discontiguous compile unit address ranges | 
|  | 2548 | // should only happen when there aren't other functions from | 
|  | 2549 | // other compile units in these gaps. This helps keep the size | 
|  | 2550 | // of the aranges down. | 
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2551 | force_check_line_table = true; | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2552 | } | 
|  | 2553 |  | 
|  | 2554 | if (sc.function != NULL) | 
|  | 2555 | { | 
|  | 2556 | resolved |= eSymbolContextFunction; | 
|  | 2557 |  | 
|  | 2558 | if (resolve_scope & eSymbolContextBlock) | 
|  | 2559 | { | 
|  | 2560 | Block& block = sc.function->GetBlock (true); | 
|  | 2561 |  | 
|  | 2562 | if (block_die != NULL) | 
|  | 2563 | sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); | 
|  | 2564 | else | 
|  | 2565 | sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); | 
|  | 2566 | if (sc.block) | 
|  | 2567 | resolved |= eSymbolContextBlock; | 
|  | 2568 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2569 | } | 
|  | 2570 | } | 
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2571 |  | 
|  | 2572 | if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table) | 
|  | 2573 | { | 
|  | 2574 | LineTable *line_table = sc.comp_unit->GetLineTable(); | 
|  | 2575 | if (line_table != NULL) | 
|  | 2576 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 2577 | // And address that makes it into this function should be in terms | 
|  | 2578 | // of this debug file if there is no debug map, or it will be an | 
|  | 2579 | // address in the .o file which needs to be fixed up to be in terms | 
|  | 2580 | // of the debug map executable. Either way, calling FixupAddress() | 
|  | 2581 | // will work for us. | 
|  | 2582 | Address exe_so_addr (so_addr); | 
|  | 2583 | if (FixupAddress(exe_so_addr)) | 
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2584 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 2585 | if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry)) | 
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2586 | { | 
|  | 2587 | resolved |= eSymbolContextLineEntry; | 
|  | 2588 | } | 
|  | 2589 | } | 
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2590 | } | 
|  | 2591 | } | 
|  | 2592 |  | 
|  | 2593 | if (force_check_line_table && !(resolved & eSymbolContextLineEntry)) | 
|  | 2594 | { | 
|  | 2595 | // We might have had a compile unit that had discontiguous | 
|  | 2596 | // address ranges where the gaps are symbols that don't have | 
|  | 2597 | // any debug info. Discontiguous compile unit address ranges | 
|  | 2598 | // should only happen when there aren't other functions from | 
|  | 2599 | // other compile units in these gaps. This helps keep the size | 
|  | 2600 | // of the aranges down. | 
|  | 2601 | sc.comp_unit = NULL; | 
|  | 2602 | resolved &= ~eSymbolContextCompUnit; | 
|  | 2603 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2604 | } | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2605 | else | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2606 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2607 | GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.", | 
|  | 2608 | cu_offset, | 
|  | 2609 | cu_idx); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2610 | } | 
|  | 2611 | } | 
|  | 2612 | } | 
|  | 2613 | } | 
|  | 2614 | } | 
|  | 2615 | return resolved; | 
|  | 2616 | } | 
|  | 2617 |  | 
|  | 2618 |  | 
|  | 2619 |  | 
|  | 2620 | uint32_t | 
|  | 2621 | SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) | 
|  | 2622 | { | 
|  | 2623 | const uint32_t prev_size = sc_list.GetSize(); | 
|  | 2624 | if (resolve_scope & eSymbolContextCompUnit) | 
|  | 2625 | { | 
|  | 2626 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 2627 | if (debug_info) | 
|  | 2628 | { | 
|  | 2629 | uint32_t cu_idx; | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2630 | DWARFCompileUnit* dwarf_cu = NULL; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2631 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2632 | 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] | 2633 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2634 | CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 2635 | const bool full_match = file_spec.GetDirectory(); | 
|  | 2636 | 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] | 2637 | if (check_inlines || file_spec_matches_cu_file_spec) | 
|  | 2638 | { | 
|  | 2639 | SymbolContext sc (m_obj_file->GetModule()); | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2640 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2641 | if (sc.comp_unit) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2642 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2643 | uint32_t file_idx = UINT32_MAX; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2644 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2645 | // If we are looking for inline functions only and we don't | 
|  | 2646 | // find it in the support files, we are done. | 
|  | 2647 | if (check_inlines) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2648 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2649 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); | 
|  | 2650 | if (file_idx == UINT32_MAX) | 
|  | 2651 | continue; | 
|  | 2652 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2653 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2654 | if (line != 0) | 
|  | 2655 | { | 
|  | 2656 | LineTable *line_table = sc.comp_unit->GetLineTable(); | 
|  | 2657 |  | 
|  | 2658 | if (line_table != NULL && line != 0) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2659 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2660 | // We will have already looked up the file index if | 
|  | 2661 | // we are searching for inline entries. | 
|  | 2662 | if (!check_inlines) | 
|  | 2663 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); | 
| 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 | if (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 | uint32_t found_line; | 
|  | 2668 | uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry); | 
|  | 2669 | found_line = sc.line_entry.line; | 
|  | 2670 |  | 
|  | 2671 | while (line_idx != UINT32_MAX) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2672 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2673 | sc.function = NULL; | 
|  | 2674 | sc.block = NULL; | 
|  | 2675 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2676 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2677 | const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress(); | 
|  | 2678 | if (file_vm_addr != LLDB_INVALID_ADDRESS) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2679 | { | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2680 | DWARFDebugInfoEntry *function_die = NULL; | 
|  | 2681 | DWARFDebugInfoEntry *block_die = NULL; | 
|  | 2682 | 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] | 2683 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2684 | if (function_die != NULL) | 
|  | 2685 | { | 
|  | 2686 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); | 
|  | 2687 | if (sc.function == NULL) | 
|  | 2688 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die); | 
|  | 2689 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2690 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2691 | if (sc.function != NULL) | 
|  | 2692 | { | 
|  | 2693 | Block& block = sc.function->GetBlock (true); | 
|  | 2694 |  | 
|  | 2695 | if (block_die != NULL) | 
|  | 2696 | sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); | 
|  | 2697 | else | 
|  | 2698 | sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); | 
|  | 2699 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2700 | } | 
|  | 2701 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2702 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2703 | sc_list.Append(sc); | 
|  | 2704 | line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry); | 
|  | 2705 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2706 | } | 
|  | 2707 | } | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2708 | else if (file_spec_matches_cu_file_spec && !check_inlines) | 
|  | 2709 | { | 
|  | 2710 | // only append the context if we aren't looking for inline call sites | 
|  | 2711 | // by file and line and if the file spec matches that of the compile unit | 
|  | 2712 | sc_list.Append(sc); | 
|  | 2713 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2714 | } | 
|  | 2715 | else if (file_spec_matches_cu_file_spec && !check_inlines) | 
|  | 2716 | { | 
|  | 2717 | // only append the context if we aren't looking for inline call sites | 
|  | 2718 | // by file and line and if the file spec matches that of the compile unit | 
|  | 2719 | sc_list.Append(sc); | 
|  | 2720 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2721 |  | 
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2722 | if (!check_inlines) | 
|  | 2723 | break; | 
|  | 2724 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2725 | } | 
|  | 2726 | } | 
|  | 2727 | } | 
|  | 2728 | } | 
|  | 2729 | return sc_list.GetSize() - prev_size; | 
|  | 2730 | } | 
|  | 2731 |  | 
|  | 2732 | void | 
|  | 2733 | SymbolFileDWARF::Index () | 
|  | 2734 | { | 
|  | 2735 | if (m_indexed) | 
|  | 2736 | return; | 
|  | 2737 | m_indexed = true; | 
|  | 2738 | Timer scoped_timer (__PRETTY_FUNCTION__, | 
|  | 2739 | "SymbolFileDWARF::Index (%s)", | 
|  | 2740 | GetObjectFile()->GetFileSpec().GetFilename().AsCString()); | 
|  | 2741 |  | 
|  | 2742 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 2743 | if (debug_info) | 
|  | 2744 | { | 
|  | 2745 | uint32_t cu_idx = 0; | 
|  | 2746 | const uint32_t num_compile_units = GetNumCompileUnits(); | 
|  | 2747 | for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) | 
|  | 2748 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2749 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2750 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2751 | bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2752 |  | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2753 | dwarf_cu->Index (cu_idx, | 
|  | 2754 | m_function_basename_index, | 
|  | 2755 | m_function_fullname_index, | 
|  | 2756 | m_function_method_index, | 
|  | 2757 | m_function_selector_index, | 
|  | 2758 | m_objc_class_selectors_index, | 
|  | 2759 | m_global_index, | 
|  | 2760 | m_type_index, | 
|  | 2761 | m_namespace_index); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2762 |  | 
|  | 2763 | // Keep memory down by clearing DIEs if this generate function | 
|  | 2764 | // caused them to be parsed | 
|  | 2765 | if (clear_dies) | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2766 | dwarf_cu->ClearDIEs (true); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2767 | } | 
|  | 2768 |  | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2769 | m_function_basename_index.Finalize(); | 
|  | 2770 | m_function_fullname_index.Finalize(); | 
|  | 2771 | m_function_method_index.Finalize(); | 
|  | 2772 | m_function_selector_index.Finalize(); | 
|  | 2773 | m_objc_class_selectors_index.Finalize(); | 
|  | 2774 | m_global_index.Finalize(); | 
|  | 2775 | m_type_index.Finalize(); | 
|  | 2776 | m_namespace_index.Finalize(); | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2777 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2778 | #if defined (ENABLE_DEBUG_PRINTF) | 
| Greg Clayton | 7bd65b9 | 2011-02-09 23:39:34 +0000 | [diff] [blame] | 2779 | StreamFile s(stdout, false); | 
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 2780 | s.Printf ("DWARF index for '%s/%s':", | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2781 | GetObjectFile()->GetFileSpec().GetDirectory().AsCString(), | 
|  | 2782 | GetObjectFile()->GetFileSpec().GetFilename().AsCString()); | 
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 2783 | s.Printf("\nFunction basenames:\n");    m_function_basename_index.Dump (&s); | 
|  | 2784 | s.Printf("\nFunction fullnames:\n");    m_function_fullname_index.Dump (&s); | 
|  | 2785 | s.Printf("\nFunction methods:\n");      m_function_method_index.Dump (&s); | 
|  | 2786 | s.Printf("\nFunction selectors:\n");    m_function_selector_index.Dump (&s); | 
|  | 2787 | s.Printf("\nObjective C class selectors:\n");    m_objc_class_selectors_index.Dump (&s); | 
|  | 2788 | s.Printf("\nGlobals and statics:\n");   m_global_index.Dump (&s); | 
| Greg Clayton | 69b0488 | 2010-10-15 02:03:22 +0000 | [diff] [blame] | 2789 | s.Printf("\nTypes:\n");                 m_type_index.Dump (&s); | 
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 2790 | s.Printf("\nNamepaces:\n");             m_namespace_index.Dump (&s); | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2791 | #endif | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2792 | } | 
|  | 2793 | } | 
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2794 |  | 
|  | 2795 | bool | 
|  | 2796 | SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl) | 
|  | 2797 | { | 
|  | 2798 | if (namespace_decl == NULL) | 
|  | 2799 | { | 
|  | 2800 | // Invalid namespace decl which means we aren't matching only things | 
|  | 2801 | // in this symbol file, so return true to indicate it matches this | 
|  | 2802 | // symbol file. | 
|  | 2803 | return true; | 
|  | 2804 | } | 
|  | 2805 |  | 
|  | 2806 | clang::ASTContext *namespace_ast = namespace_decl->GetASTContext(); | 
|  | 2807 |  | 
|  | 2808 | if (namespace_ast == NULL) | 
|  | 2809 | return true;    // No AST in the "namespace_decl", return true since it | 
|  | 2810 | // could then match any symbol file, including this one | 
|  | 2811 |  | 
|  | 2812 | if (namespace_ast == GetClangASTContext().getASTContext()) | 
|  | 2813 | return true;    // The ASTs match, return true | 
|  | 2814 |  | 
|  | 2815 | // The namespace AST was valid, and it does not match... | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2816 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Sean Callanan | c41e68b | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 2817 |  | 
|  | 2818 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2819 | GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file"); | 
| Sean Callanan | c41e68b | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 2820 |  | 
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2821 | return false; | 
|  | 2822 | } | 
|  | 2823 |  | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2824 | bool | 
|  | 2825 | SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl, | 
|  | 2826 | DWARFCompileUnit* cu, | 
|  | 2827 | const DWARFDebugInfoEntry* die) | 
|  | 2828 | { | 
|  | 2829 | // No namespace specified, so the answesr i | 
|  | 2830 | if (namespace_decl == NULL) | 
|  | 2831 | return true; | 
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2832 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2833 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2834 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2835 | const DWARFDebugInfoEntry *decl_ctx_die = NULL; | 
|  | 2836 | clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die); | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2837 | if (decl_ctx_die) | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2838 | { | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2839 | clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl(); | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2840 |  | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2841 | if (clang_namespace_decl) | 
|  | 2842 | { | 
|  | 2843 | if (decl_ctx_die->Tag() != DW_TAG_namespace) | 
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2844 | { | 
|  | 2845 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2846 | 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] | 2847 | return false; | 
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2848 | } | 
|  | 2849 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2850 | if (clang_namespace_decl == die_clang_decl_ctx) | 
|  | 2851 | return true; | 
|  | 2852 | else | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2853 | return false; | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2854 | } | 
|  | 2855 | else | 
|  | 2856 | { | 
|  | 2857 | // We have a namespace_decl that was not NULL but it contained | 
|  | 2858 | // a NULL "clang::NamespaceDecl", so this means the global namespace | 
|  | 2859 | // So as long the the contained decl context DIE isn't a namespace | 
|  | 2860 | // we should be ok. | 
|  | 2861 | if (decl_ctx_die->Tag() != DW_TAG_namespace) | 
|  | 2862 | return true; | 
|  | 2863 | } | 
|  | 2864 | } | 
| 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 doesn't exist"); | 
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2868 |  | 
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2869 | return false; | 
|  | 2870 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2871 | uint32_t | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2872 | 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] | 2873 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2874 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2875 |  | 
|  | 2876 | if (log) | 
|  | 2877 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2878 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2879 | "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)", | 
|  | 2880 | name.GetCString(), | 
|  | 2881 | namespace_decl, | 
|  | 2882 | append, | 
|  | 2883 | max_matches); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2884 | } | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2885 |  | 
|  | 2886 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) | 
|  | 2887 | return 0; | 
|  | 2888 |  | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2889 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 2890 | if (info == NULL) | 
|  | 2891 | return 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2892 |  | 
|  | 2893 | // If we aren't appending the results to this list, then clear the list | 
|  | 2894 | if (!append) | 
|  | 2895 | variables.Clear(); | 
|  | 2896 |  | 
|  | 2897 | // Remember how many variables are in the list before we search in case | 
|  | 2898 | // we are appending the results to a variable list. | 
|  | 2899 | const uint32_t original_size = variables.GetSize(); | 
|  | 2900 |  | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2901 | DIEArray die_offsets; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2902 |  | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2903 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2904 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2905 | if (m_apple_names_ap.get()) | 
|  | 2906 | { | 
|  | 2907 | const char *name_cstr = name.GetCString(); | 
|  | 2908 | const char *base_name_start; | 
|  | 2909 | const char *base_name_end = NULL; | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2910 |  | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2911 | if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end)) | 
|  | 2912 | base_name_start = name_cstr; | 
|  | 2913 |  | 
|  | 2914 | m_apple_names_ap->FindByName (base_name_start, die_offsets); | 
|  | 2915 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2916 | } | 
|  | 2917 | else | 
|  | 2918 | { | 
|  | 2919 | // Index the DWARF if we haven't already | 
|  | 2920 | if (!m_indexed) | 
|  | 2921 | Index (); | 
|  | 2922 |  | 
|  | 2923 | m_global_index.Find (name, die_offsets); | 
|  | 2924 | } | 
|  | 2925 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2926 | const size_t num_die_matches = die_offsets.size(); | 
|  | 2927 | if (num_die_matches) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2928 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2929 | SymbolContext sc; | 
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 2930 | sc.module_sp = m_obj_file->GetModule(); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2931 | assert (sc.module_sp); | 
|  | 2932 |  | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2933 | DWARFDebugInfo* debug_info = DebugInfo(); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2934 | DWARFCompileUnit* dwarf_cu = NULL; | 
|  | 2935 | const DWARFDebugInfoEntry* die = NULL; | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2936 | bool done = false; | 
|  | 2937 | for (size_t i=0; i<num_die_matches && !done; ++i) | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2938 | { | 
|  | 2939 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 2940 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2941 |  | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2942 | if (die) | 
|  | 2943 | { | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2944 | switch (die->Tag()) | 
|  | 2945 | { | 
|  | 2946 | default: | 
|  | 2947 | case DW_TAG_subprogram: | 
|  | 2948 | case DW_TAG_inlined_subroutine: | 
|  | 2949 | case DW_TAG_try_block: | 
|  | 2950 | case DW_TAG_catch_block: | 
|  | 2951 | break; | 
|  | 2952 |  | 
|  | 2953 | case DW_TAG_variable: | 
|  | 2954 | { | 
|  | 2955 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2956 |  | 
|  | 2957 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) | 
|  | 2958 | continue; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2959 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2960 | ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2961 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2962 | if (variables.GetSize() - original_size >= max_matches) | 
|  | 2963 | done = true; | 
|  | 2964 | } | 
|  | 2965 | break; | 
|  | 2966 | } | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2967 | } | 
|  | 2968 | else | 
|  | 2969 | { | 
|  | 2970 | if (m_using_apple_tables) | 
|  | 2971 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2972 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n", | 
|  | 2973 | die_offset, name.GetCString()); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2974 | } | 
|  | 2975 | } | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2976 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2977 | } | 
|  | 2978 |  | 
|  | 2979 | // Return the number of variable that were appended to the list | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2980 | const uint32_t num_matches = variables.GetSize() - original_size; | 
|  | 2981 | if (log && num_matches > 0) | 
|  | 2982 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2983 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2984 | "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u", | 
|  | 2985 | name.GetCString(), | 
|  | 2986 | namespace_decl, | 
|  | 2987 | append, | 
|  | 2988 | max_matches, | 
|  | 2989 | num_matches); | 
|  | 2990 | } | 
|  | 2991 | return num_matches; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2992 | } | 
|  | 2993 |  | 
|  | 2994 | uint32_t | 
|  | 2995 | SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables) | 
|  | 2996 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2997 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2998 |  | 
|  | 2999 | if (log) | 
|  | 3000 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3001 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3002 | "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)", | 
|  | 3003 | regex.GetText(), | 
|  | 3004 | append, | 
|  | 3005 | max_matches); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3006 | } | 
|  | 3007 |  | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3008 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 3009 | if (info == NULL) | 
|  | 3010 | return 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3011 |  | 
|  | 3012 | // If we aren't appending the results to this list, then clear the list | 
|  | 3013 | if (!append) | 
|  | 3014 | variables.Clear(); | 
|  | 3015 |  | 
|  | 3016 | // Remember how many variables are in the list before we search in case | 
|  | 3017 | // we are appending the results to a variable list. | 
|  | 3018 | const uint32_t original_size = variables.GetSize(); | 
|  | 3019 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3020 | DIEArray die_offsets; | 
|  | 3021 |  | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3022 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3023 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3024 | if (m_apple_names_ap.get()) | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3025 | { | 
|  | 3026 | DWARFMappedHash::DIEInfoArray hash_data_array; | 
|  | 3027 | if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) | 
|  | 3028 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); | 
|  | 3029 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3030 | } | 
|  | 3031 | else | 
|  | 3032 | { | 
|  | 3033 | // Index the DWARF if we haven't already | 
|  | 3034 | if (!m_indexed) | 
|  | 3035 | Index (); | 
|  | 3036 |  | 
|  | 3037 | m_global_index.Find (regex, die_offsets); | 
|  | 3038 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3039 |  | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3040 | SymbolContext sc; | 
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 3041 | sc.module_sp = m_obj_file->GetModule(); | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3042 | assert (sc.module_sp); | 
|  | 3043 |  | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3044 | DWARFCompileUnit* dwarf_cu = NULL; | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3045 | const DWARFDebugInfoEntry* die = NULL; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3046 | const size_t num_matches = die_offsets.size(); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3047 | if (num_matches) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3048 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3049 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 3050 | for (size_t i=0; i<num_matches; ++i) | 
|  | 3051 | { | 
|  | 3052 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 3053 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3054 |  | 
|  | 3055 | if (die) | 
|  | 3056 | { | 
|  | 3057 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3058 |  | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3059 | ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3060 |  | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3061 | if (variables.GetSize() - original_size >= max_matches) | 
|  | 3062 | break; | 
|  | 3063 | } | 
|  | 3064 | else | 
|  | 3065 | { | 
|  | 3066 | if (m_using_apple_tables) | 
|  | 3067 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3068 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n", | 
|  | 3069 | die_offset, regex.GetText()); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3070 | } | 
|  | 3071 | } | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3072 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3073 | } | 
|  | 3074 |  | 
|  | 3075 | // Return the number of variable that were appended to the list | 
|  | 3076 | return variables.GetSize() - original_size; | 
|  | 3077 | } | 
|  | 3078 |  | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3079 |  | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3080 | bool | 
|  | 3081 | SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset, | 
|  | 3082 | DWARFCompileUnit *&dwarf_cu, | 
|  | 3083 | SymbolContextList& sc_list) | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3084 | { | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3085 | const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
|  | 3086 | return ResolveFunction (dwarf_cu, die, sc_list); | 
|  | 3087 | } | 
|  | 3088 |  | 
|  | 3089 |  | 
|  | 3090 | bool | 
|  | 3091 | SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu, | 
|  | 3092 | const DWARFDebugInfoEntry *die, | 
|  | 3093 | SymbolContextList& sc_list) | 
|  | 3094 | { | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3095 | SymbolContext sc; | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3096 |  | 
|  | 3097 | if (die == NULL) | 
|  | 3098 | return false; | 
|  | 3099 |  | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3100 | // If we were passed a die that is not a function, just return false... | 
|  | 3101 | if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine) | 
|  | 3102 | return false; | 
|  | 3103 |  | 
|  | 3104 | const DWARFDebugInfoEntry* inlined_die = NULL; | 
|  | 3105 | if (die->Tag() == DW_TAG_inlined_subroutine) | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3106 | { | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3107 | inlined_die = die; | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3108 |  | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3109 | while ((die = die->GetParent()) != NULL) | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3110 | { | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3111 | if (die->Tag() == DW_TAG_subprogram) | 
|  | 3112 | break; | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3113 | } | 
|  | 3114 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3115 | assert (die->Tag() == DW_TAG_subprogram); | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3116 | if (GetFunction (cu, die, sc)) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3117 | { | 
|  | 3118 | Address addr; | 
|  | 3119 | // Parse all blocks if needed | 
|  | 3120 | if (inlined_die) | 
|  | 3121 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 3122 | sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset())); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3123 | assert (sc.block != NULL); | 
|  | 3124 | if (sc.block->GetStartAddress (addr) == false) | 
|  | 3125 | addr.Clear(); | 
|  | 3126 | } | 
|  | 3127 | else | 
|  | 3128 | { | 
|  | 3129 | sc.block = NULL; | 
|  | 3130 | addr = sc.function->GetAddressRange().GetBaseAddress(); | 
|  | 3131 | } | 
|  | 3132 |  | 
|  | 3133 | if (addr.IsValid()) | 
|  | 3134 | { | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3135 | sc_list.Append(sc); | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3136 | return true; | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3137 | } | 
|  | 3138 | } | 
|  | 3139 |  | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3140 | return false; | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3141 | } | 
|  | 3142 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3143 | void | 
|  | 3144 | SymbolFileDWARF::FindFunctions (const ConstString &name, | 
|  | 3145 | const NameToDIE &name_to_die, | 
|  | 3146 | SymbolContextList& sc_list) | 
|  | 3147 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3148 | DIEArray die_offsets; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3149 | if (name_to_die.Find (name, die_offsets)) | 
|  | 3150 | { | 
|  | 3151 | ParseFunctions (die_offsets, sc_list); | 
|  | 3152 | } | 
|  | 3153 | } | 
|  | 3154 |  | 
|  | 3155 |  | 
|  | 3156 | void | 
|  | 3157 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, | 
|  | 3158 | const NameToDIE &name_to_die, | 
|  | 3159 | SymbolContextList& sc_list) | 
|  | 3160 | { | 
|  | 3161 | DIEArray die_offsets; | 
|  | 3162 | if (name_to_die.Find (regex, die_offsets)) | 
|  | 3163 | { | 
|  | 3164 | ParseFunctions (die_offsets, sc_list); | 
|  | 3165 | } | 
|  | 3166 | } | 
|  | 3167 |  | 
|  | 3168 |  | 
|  | 3169 | void | 
|  | 3170 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, | 
|  | 3171 | const DWARFMappedHash::MemoryTable &memory_table, | 
|  | 3172 | SymbolContextList& sc_list) | 
|  | 3173 | { | 
|  | 3174 | DIEArray die_offsets; | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3175 | DWARFMappedHash::DIEInfoArray hash_data_array; | 
|  | 3176 | if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3177 | { | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3178 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3179 | ParseFunctions (die_offsets, sc_list); | 
|  | 3180 | } | 
|  | 3181 | } | 
|  | 3182 |  | 
|  | 3183 | void | 
|  | 3184 | SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets, | 
|  | 3185 | SymbolContextList& sc_list) | 
|  | 3186 | { | 
|  | 3187 | const size_t num_matches = die_offsets.size(); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3188 | if (num_matches) | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3189 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3190 | SymbolContext sc; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3191 |  | 
|  | 3192 | DWARFCompileUnit* dwarf_cu = NULL; | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3193 | for (size_t i=0; i<num_matches; ++i) | 
| Greg Clayton | d7e0546 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 3194 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3195 | const dw_offset_t die_offset = die_offsets[i]; | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3196 | ResolveFunction (die_offset, dwarf_cu, sc_list); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3197 | } | 
|  | 3198 | } | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3199 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3200 |  | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3201 | bool | 
|  | 3202 | SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die, | 
|  | 3203 | const DWARFCompileUnit *dwarf_cu, | 
|  | 3204 | uint32_t name_type_mask, | 
|  | 3205 | const char *partial_name, | 
|  | 3206 | const char *base_name_start, | 
|  | 3207 | const char *base_name_end) | 
|  | 3208 | { | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3209 | // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes: | 
|  | 3210 | if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3211 | { | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 3212 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset()); | 
|  | 3213 | if (!containing_decl_ctx) | 
|  | 3214 | return false; | 
|  | 3215 |  | 
|  | 3216 | bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()); | 
|  | 3217 |  | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3218 | if (name_type_mask == eFunctionNameTypeMethod) | 
|  | 3219 | { | 
|  | 3220 | if (is_cxx_method == false) | 
|  | 3221 | return false; | 
|  | 3222 | } | 
|  | 3223 |  | 
|  | 3224 | if (name_type_mask == eFunctionNameTypeBase) | 
|  | 3225 | { | 
|  | 3226 | if (is_cxx_method == true) | 
|  | 3227 | return false; | 
|  | 3228 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3229 | } | 
|  | 3230 |  | 
|  | 3231 | // Now we need to check whether the name we got back for this type matches the extra specifications | 
|  | 3232 | // that were in the name we're looking up: | 
|  | 3233 | if (base_name_start != partial_name || *base_name_end != '\0') | 
|  | 3234 | { | 
|  | 3235 | // First see if the stuff to the left matches the full name.  To do that let's see if | 
|  | 3236 | // we can pull out the mips linkage name attribute: | 
|  | 3237 |  | 
|  | 3238 | Mangled best_name; | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3239 | DWARFDebugInfoEntry::Attributes attributes; | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3240 | DWARFFormValue form_value; | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3241 | die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
|  | 3242 | uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name); | 
| Greg Clayton | 7141554 | 2012-12-08 00:24:40 +0000 | [diff] [blame] | 3243 | if (idx == UINT32_MAX) | 
|  | 3244 | idx = attributes.FindAttributeIndex(DW_AT_linkage_name); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3245 | if (idx != UINT32_MAX) | 
|  | 3246 | { | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3247 | if (attributes.ExtractFormValueAtIndex(this, idx, form_value)) | 
|  | 3248 | { | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3249 | const char *mangled_name = form_value.AsCString(&get_debug_str_data()); | 
|  | 3250 | if (mangled_name) | 
|  | 3251 | best_name.SetValue (ConstString(mangled_name), true); | 
|  | 3252 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3253 | } | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3254 |  | 
|  | 3255 | if (!best_name) | 
|  | 3256 | { | 
|  | 3257 | idx = attributes.FindAttributeIndex(DW_AT_name); | 
|  | 3258 | if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value)) | 
|  | 3259 | { | 
|  | 3260 | const char *name = form_value.AsCString(&get_debug_str_data()); | 
|  | 3261 | best_name.SetValue (ConstString(name), false); | 
|  | 3262 | } | 
|  | 3263 | } | 
|  | 3264 |  | 
|  | 3265 | if (best_name.GetDemangledName()) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3266 | { | 
|  | 3267 | const char *demangled = best_name.GetDemangledName().GetCString(); | 
|  | 3268 | if (demangled) | 
|  | 3269 | { | 
|  | 3270 | std::string name_no_parens(partial_name, base_name_end - partial_name); | 
| Jim Ingham | 85c13d7 | 2012-03-02 02:24:42 +0000 | [diff] [blame] | 3271 | const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str()); | 
|  | 3272 | if (partial_in_demangled == NULL) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3273 | return false; | 
| Jim Ingham | 85c13d7 | 2012-03-02 02:24:42 +0000 | [diff] [blame] | 3274 | else | 
|  | 3275 | { | 
|  | 3276 | // Sort out the case where our name is something like "Process::Destroy" and the match is | 
|  | 3277 | // "SBProcess::Destroy" - that shouldn't be a match.  We should really always match on | 
|  | 3278 | // namespace boundaries... | 
|  | 3279 |  | 
|  | 3280 | if (partial_name[0] == ':'  && partial_name[1] == ':') | 
|  | 3281 | { | 
|  | 3282 | // The partial name was already on a namespace boundary so all matches are good. | 
|  | 3283 | return true; | 
|  | 3284 | } | 
|  | 3285 | else if (partial_in_demangled == demangled) | 
|  | 3286 | { | 
|  | 3287 | // They both start the same, so this is an good match. | 
|  | 3288 | return true; | 
|  | 3289 | } | 
|  | 3290 | else | 
|  | 3291 | { | 
|  | 3292 | if (partial_in_demangled - demangled == 1) | 
|  | 3293 | { | 
|  | 3294 | // Only one character difference, can't be a namespace boundary... | 
|  | 3295 | return false; | 
|  | 3296 | } | 
|  | 3297 | else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':') | 
|  | 3298 | { | 
|  | 3299 | // We are on a namespace boundary, so this is also good. | 
|  | 3300 | return true; | 
|  | 3301 | } | 
|  | 3302 | else | 
|  | 3303 | return false; | 
|  | 3304 | } | 
|  | 3305 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3306 | } | 
|  | 3307 | } | 
|  | 3308 | } | 
|  | 3309 |  | 
|  | 3310 | return true; | 
|  | 3311 | } | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3312 |  | 
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3313 | uint32_t | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3314 | SymbolFileDWARF::FindFunctions (const ConstString &name, | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3315 | const lldb_private::ClangNamespaceDecl *namespace_decl, | 
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3316 | uint32_t name_type_mask, | 
|  | 3317 | bool include_inlines, | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3318 | bool append, | 
|  | 3319 | SymbolContextList& sc_list) | 
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3320 | { | 
|  | 3321 | Timer scoped_timer (__PRETTY_FUNCTION__, | 
|  | 3322 | "SymbolFileDWARF::FindFunctions (name = '%s')", | 
|  | 3323 | name.AsCString()); | 
|  | 3324 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3325 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3326 |  | 
|  | 3327 | if (log) | 
|  | 3328 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3329 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3330 | "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)", | 
|  | 3331 | name.GetCString(), | 
|  | 3332 | name_type_mask, | 
|  | 3333 | append); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3334 | } | 
|  | 3335 |  | 
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3336 | // If we aren't appending the results to this list, then clear the list | 
|  | 3337 | if (!append) | 
|  | 3338 | sc_list.Clear(); | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3339 |  | 
|  | 3340 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) | 
|  | 3341 | return 0; | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3342 |  | 
|  | 3343 | // If name is empty then we won't find anything. | 
|  | 3344 | if (name.IsEmpty()) | 
|  | 3345 | return 0; | 
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3346 |  | 
|  | 3347 | // Remember how many sc_list are in the list before we search in case | 
|  | 3348 | // we are appending the results to a variable list. | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3349 |  | 
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3350 | const uint32_t original_size = sc_list.GetSize(); | 
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3351 |  | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3352 | const char *name_cstr = name.GetCString(); | 
|  | 3353 | uint32_t effective_name_type_mask = eFunctionNameTypeNone; | 
|  | 3354 | const char *base_name_start = name_cstr; | 
|  | 3355 | const char *base_name_end = name_cstr + strlen(name_cstr); | 
|  | 3356 |  | 
|  | 3357 | if (name_type_mask & eFunctionNameTypeAuto) | 
|  | 3358 | { | 
|  | 3359 | if (CPPLanguageRuntime::IsCPPMangledName (name_cstr)) | 
|  | 3360 | effective_name_type_mask = eFunctionNameTypeFull; | 
|  | 3361 | else if (ObjCLanguageRuntime::IsPossibleObjCMethodName (name_cstr)) | 
|  | 3362 | effective_name_type_mask = eFunctionNameTypeFull; | 
|  | 3363 | else | 
|  | 3364 | { | 
|  | 3365 | if (ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr)) | 
|  | 3366 | effective_name_type_mask |= eFunctionNameTypeSelector; | 
|  | 3367 |  | 
|  | 3368 | if (CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end)) | 
|  | 3369 | effective_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase); | 
|  | 3370 | } | 
|  | 3371 | } | 
|  | 3372 | else | 
|  | 3373 | { | 
|  | 3374 | effective_name_type_mask = name_type_mask; | 
|  | 3375 | if (effective_name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase) | 
|  | 3376 | { | 
|  | 3377 | // If they've asked for a CPP method or function name and it can't be that, we don't | 
|  | 3378 | // even need to search for CPP methods or names. | 
|  | 3379 | if (!CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end)) | 
|  | 3380 | { | 
|  | 3381 | effective_name_type_mask &= ~(eFunctionNameTypeMethod | eFunctionNameTypeBase); | 
|  | 3382 | if (effective_name_type_mask == eFunctionNameTypeNone) | 
|  | 3383 | return 0; | 
|  | 3384 | } | 
|  | 3385 | } | 
|  | 3386 |  | 
|  | 3387 | if (effective_name_type_mask & eFunctionNameTypeSelector) | 
|  | 3388 | { | 
|  | 3389 | if (!ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr)) | 
|  | 3390 | { | 
|  | 3391 | effective_name_type_mask &= ~(eFunctionNameTypeSelector); | 
|  | 3392 | if (effective_name_type_mask == eFunctionNameTypeNone) | 
|  | 3393 | return 0; | 
|  | 3394 | } | 
|  | 3395 | } | 
|  | 3396 | } | 
|  | 3397 |  | 
|  | 3398 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 3399 | if (info == NULL) | 
|  | 3400 | return 0; | 
|  | 3401 |  | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3402 | DWARFCompileUnit *dwarf_cu = NULL; | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3403 | if (m_using_apple_tables) | 
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 3404 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3405 | if (m_apple_names_ap.get()) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3406 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3407 |  | 
|  | 3408 | DIEArray die_offsets; | 
|  | 3409 |  | 
|  | 3410 | uint32_t num_matches = 0; | 
|  | 3411 |  | 
|  | 3412 | if (effective_name_type_mask & eFunctionNameTypeFull) | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3413 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3414 | // If they asked for the full name, match what they typed.  At some point we may | 
|  | 3415 | // want to canonicalize this (strip double spaces, etc.  For now, we just add all the | 
|  | 3416 | // dies that we find by exact match. | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3417 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3418 | for (uint32_t i = 0; i < num_matches; i++) | 
|  | 3419 | { | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3420 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 3421 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3422 | if (die) | 
|  | 3423 | { | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3424 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) | 
|  | 3425 | continue; | 
|  | 3426 |  | 
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3427 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) | 
|  | 3428 | continue; | 
|  | 3429 |  | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3430 | ResolveFunction (dwarf_cu, die, sc_list); | 
|  | 3431 | } | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3432 | else | 
|  | 3433 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3434 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", | 
|  | 3435 | die_offset, name_cstr); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3436 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3437 | } | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3438 | } | 
|  | 3439 | else | 
|  | 3440 | { | 
|  | 3441 | if (effective_name_type_mask & eFunctionNameTypeSelector) | 
|  | 3442 | { | 
|  | 3443 | if (namespace_decl && *namespace_decl) | 
|  | 3444 | return 0; // no selectors in namespaces | 
|  | 3445 |  | 
|  | 3446 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); | 
|  | 3447 | // Now make sure these are actually ObjC methods.  In this case we can simply look up the name, | 
|  | 3448 | // and if it is an ObjC method name, we're good. | 
|  | 3449 |  | 
|  | 3450 | for (uint32_t i = 0; i < num_matches; i++) | 
|  | 3451 | { | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3452 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 3453 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3454 | if (die) | 
|  | 3455 | { | 
|  | 3456 | const char *die_name = die->GetName(this, dwarf_cu); | 
|  | 3457 | if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name)) | 
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3458 | { | 
|  | 3459 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) | 
|  | 3460 | continue; | 
|  | 3461 |  | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3462 | ResolveFunction (dwarf_cu, die, sc_list); | 
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3463 | } | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3464 | } | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3465 | else | 
|  | 3466 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3467 | GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", | 
|  | 3468 | die_offset, name_cstr); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3469 | } | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3470 | } | 
|  | 3471 | die_offsets.clear(); | 
|  | 3472 | } | 
|  | 3473 |  | 
|  | 3474 | if (effective_name_type_mask & eFunctionNameTypeMethod | 
|  | 3475 | || effective_name_type_mask & eFunctionNameTypeBase) | 
|  | 3476 | { | 
|  | 3477 | if ((effective_name_type_mask & eFunctionNameTypeMethod) && | 
|  | 3478 | (namespace_decl && *namespace_decl)) | 
|  | 3479 | return 0; // no methods in namespaces | 
|  | 3480 |  | 
|  | 3481 | // The apple_names table stores just the "base name" of C++ methods in the table.  So we have to | 
|  | 3482 | // extract the base name, look that up, and if there is any other information in the name we were | 
|  | 3483 | // passed in we have to post-filter based on that. | 
|  | 3484 |  | 
|  | 3485 | // FIXME: Arrange the logic above so that we don't calculate the base name twice: | 
|  | 3486 | std::string base_name(base_name_start, base_name_end - base_name_start); | 
|  | 3487 | num_matches = m_apple_names_ap->FindByName (base_name.c_str(), die_offsets); | 
|  | 3488 |  | 
|  | 3489 | for (uint32_t i = 0; i < num_matches; i++) | 
|  | 3490 | { | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3491 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 3492 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3493 | if (die) | 
|  | 3494 | { | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3495 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) | 
|  | 3496 | continue; | 
|  | 3497 |  | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3498 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) | 
|  | 3499 | continue; | 
|  | 3500 |  | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3501 | if (!FunctionDieMatchesPartialName(die, | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3502 | dwarf_cu, | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3503 | effective_name_type_mask, | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3504 | name_cstr, | 
|  | 3505 | base_name_start, | 
|  | 3506 | base_name_end)) | 
|  | 3507 | continue; | 
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3508 |  | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3509 | // If we get to here, the die is good, and we should add it: | 
|  | 3510 | ResolveFunction (dwarf_cu, die, sc_list); | 
|  | 3511 | } | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3512 | else | 
|  | 3513 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3514 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", | 
|  | 3515 | die_offset, name_cstr); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3516 | } | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3517 | } | 
|  | 3518 | die_offsets.clear(); | 
|  | 3519 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3520 | } | 
|  | 3521 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3522 | } | 
|  | 3523 | else | 
|  | 3524 | { | 
|  | 3525 |  | 
|  | 3526 | // Index the DWARF if we haven't already | 
|  | 3527 | if (!m_indexed) | 
|  | 3528 | Index (); | 
|  | 3529 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3530 | if (name_type_mask & eFunctionNameTypeFull) | 
|  | 3531 | FindFunctions (name, m_function_fullname_index, sc_list); | 
|  | 3532 |  | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3533 | std::string base_name(base_name_start, base_name_end - base_name_start); | 
|  | 3534 | ConstString base_name_const(base_name.c_str()); | 
|  | 3535 | DIEArray die_offsets; | 
|  | 3536 | DWARFCompileUnit *dwarf_cu = NULL; | 
|  | 3537 |  | 
|  | 3538 | if (effective_name_type_mask & eFunctionNameTypeBase) | 
|  | 3539 | { | 
|  | 3540 | uint32_t num_base = m_function_basename_index.Find(base_name_const, die_offsets); | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3541 | for (uint32_t i = 0; i < num_base; i++) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3542 | { | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3543 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); | 
|  | 3544 | if (die) | 
|  | 3545 | { | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3546 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) | 
|  | 3547 | continue; | 
|  | 3548 |  | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3549 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) | 
|  | 3550 | continue; | 
|  | 3551 |  | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3552 | if (!FunctionDieMatchesPartialName(die, | 
|  | 3553 | dwarf_cu, | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3554 | eFunctionNameTypeBase, | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3555 | name_cstr, | 
|  | 3556 | base_name_start, | 
|  | 3557 | base_name_end)) | 
|  | 3558 | continue; | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3559 |  | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3560 | // If we get to here, the die is good, and we should add it: | 
|  | 3561 | ResolveFunction (dwarf_cu, die, sc_list); | 
|  | 3562 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3563 | } | 
|  | 3564 | die_offsets.clear(); | 
|  | 3565 | } | 
|  | 3566 |  | 
| Jim Ingham | ea8005a | 2011-10-11 01:18:11 +0000 | [diff] [blame] | 3567 | if (effective_name_type_mask & eFunctionNameTypeMethod) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3568 | { | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3569 | if (namespace_decl && *namespace_decl) | 
|  | 3570 | return 0; // no methods in namespaces | 
|  | 3571 |  | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3572 | uint32_t num_base = m_function_method_index.Find(base_name_const, die_offsets); | 
|  | 3573 | { | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3574 | for (uint32_t i = 0; i < num_base; i++) | 
|  | 3575 | { | 
|  | 3576 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); | 
|  | 3577 | if (die) | 
|  | 3578 | { | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3579 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) | 
|  | 3580 | continue; | 
|  | 3581 |  | 
|  | 3582 | if (!FunctionDieMatchesPartialName(die, | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3583 | dwarf_cu, | 
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3584 | eFunctionNameTypeMethod, | 
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3585 | name_cstr, | 
|  | 3586 | base_name_start, | 
|  | 3587 | base_name_end)) | 
|  | 3588 | continue; | 
|  | 3589 |  | 
|  | 3590 | // If we get to here, the die is good, and we should add it: | 
|  | 3591 | ResolveFunction (dwarf_cu, die, sc_list); | 
|  | 3592 | } | 
|  | 3593 | } | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3594 | } | 
|  | 3595 | die_offsets.clear(); | 
|  | 3596 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3597 |  | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3598 | if ((effective_name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl)) | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3599 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3600 | FindFunctions (name, m_function_selector_index, sc_list); | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3601 | } | 
|  | 3602 |  | 
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 3603 | } | 
|  | 3604 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3605 | // Return the number of variable that were appended to the list | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3606 | const uint32_t num_matches = sc_list.GetSize() - original_size; | 
|  | 3607 |  | 
|  | 3608 | if (log && num_matches > 0) | 
|  | 3609 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3610 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3611 | "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list) => %u", | 
|  | 3612 | name.GetCString(), | 
|  | 3613 | name_type_mask, | 
|  | 3614 | append, | 
|  | 3615 | num_matches); | 
|  | 3616 | } | 
|  | 3617 | return num_matches; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3618 | } | 
|  | 3619 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3620 | uint32_t | 
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3621 | 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] | 3622 | { | 
|  | 3623 | Timer scoped_timer (__PRETTY_FUNCTION__, | 
|  | 3624 | "SymbolFileDWARF::FindFunctions (regex = '%s')", | 
|  | 3625 | regex.GetText()); | 
|  | 3626 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3627 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3628 |  | 
|  | 3629 | if (log) | 
|  | 3630 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3631 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3632 | "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)", | 
|  | 3633 | regex.GetText(), | 
|  | 3634 | append); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3635 | } | 
|  | 3636 |  | 
|  | 3637 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3638 | // If we aren't appending the results to this list, then clear the list | 
|  | 3639 | if (!append) | 
|  | 3640 | sc_list.Clear(); | 
|  | 3641 |  | 
|  | 3642 | // Remember how many sc_list are in the list before we search in case | 
|  | 3643 | // we are appending the results to a variable list. | 
|  | 3644 | uint32_t original_size = sc_list.GetSize(); | 
|  | 3645 |  | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3646 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3647 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3648 | if (m_apple_names_ap.get()) | 
|  | 3649 | FindFunctions (regex, *m_apple_names_ap, sc_list); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3650 | } | 
|  | 3651 | else | 
|  | 3652 | { | 
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3653 | // Index the DWARF if we haven't already | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3654 | if (!m_indexed) | 
|  | 3655 | Index (); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3656 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3657 | FindFunctions (regex, m_function_basename_index, sc_list); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3658 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3659 | FindFunctions (regex, m_function_fullname_index, sc_list); | 
|  | 3660 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3661 |  | 
|  | 3662 | // Return the number of variable that were appended to the list | 
|  | 3663 | return sc_list.GetSize() - original_size; | 
|  | 3664 | } | 
| Jim Ingham | 318c9f2 | 2011-08-26 19:44:13 +0000 | [diff] [blame] | 3665 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3666 | uint32_t | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3667 | SymbolFileDWARF::FindTypes (const SymbolContext& sc, | 
|  | 3668 | const ConstString &name, | 
|  | 3669 | const lldb_private::ClangNamespaceDecl *namespace_decl, | 
|  | 3670 | bool append, | 
|  | 3671 | uint32_t max_matches, | 
|  | 3672 | TypeList& types) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3673 | { | 
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3674 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 3675 | if (info == NULL) | 
|  | 3676 | return 0; | 
|  | 3677 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3678 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3679 |  | 
|  | 3680 | if (log) | 
|  | 3681 | { | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3682 | if (namespace_decl) | 
|  | 3683 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3684 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3685 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)", | 
|  | 3686 | name.GetCString(), | 
|  | 3687 | namespace_decl->GetNamespaceDecl(), | 
|  | 3688 | namespace_decl->GetQualifiedName().c_str(), | 
|  | 3689 | append, | 
|  | 3690 | max_matches); | 
|  | 3691 | } | 
|  | 3692 | else | 
|  | 3693 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3694 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3695 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)", | 
|  | 3696 | name.GetCString(), | 
|  | 3697 | append, | 
|  | 3698 | max_matches); | 
|  | 3699 | } | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3700 | } | 
|  | 3701 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3702 | // If we aren't appending the results to this list, then clear the list | 
|  | 3703 | if (!append) | 
|  | 3704 | types.Clear(); | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3705 |  | 
|  | 3706 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) | 
|  | 3707 | return 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3708 |  | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3709 | DIEArray die_offsets; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3710 |  | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3711 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3712 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3713 | if (m_apple_types_ap.get()) | 
|  | 3714 | { | 
|  | 3715 | const char *name_cstr = name.GetCString(); | 
|  | 3716 | m_apple_types_ap->FindByName (name_cstr, die_offsets); | 
|  | 3717 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3718 | } | 
|  | 3719 | else | 
|  | 3720 | { | 
|  | 3721 | if (!m_indexed) | 
|  | 3722 | Index (); | 
|  | 3723 |  | 
|  | 3724 | m_type_index.Find (name, die_offsets); | 
|  | 3725 | } | 
|  | 3726 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3727 | const size_t num_die_matches = die_offsets.size(); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3728 |  | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3729 | if (num_die_matches) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3730 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3731 | const uint32_t initial_types_size = types.GetSize(); | 
|  | 3732 | DWARFCompileUnit* dwarf_cu = NULL; | 
|  | 3733 | const DWARFDebugInfoEntry* die = NULL; | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3734 | DWARFDebugInfo* debug_info = DebugInfo(); | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3735 | for (size_t i=0; i<num_die_matches; ++i) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3736 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3737 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 3738 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
|  | 3739 |  | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3740 | if (die) | 
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 3741 | { | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3742 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) | 
|  | 3743 | continue; | 
|  | 3744 |  | 
|  | 3745 | Type *matching_type = ResolveType (dwarf_cu, die); | 
|  | 3746 | if (matching_type) | 
|  | 3747 | { | 
|  | 3748 | // 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] | 3749 | types.InsertUnique (matching_type->shared_from_this()); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3750 | if (types.GetSize() >= max_matches) | 
|  | 3751 | break; | 
|  | 3752 | } | 
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 3753 | } | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3754 | else | 
|  | 3755 | { | 
|  | 3756 | if (m_using_apple_tables) | 
|  | 3757 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3758 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", | 
|  | 3759 | die_offset, name.GetCString()); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3760 | } | 
|  | 3761 | } | 
|  | 3762 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3763 | } | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3764 | const uint32_t num_matches = types.GetSize() - initial_types_size; | 
|  | 3765 | if (log && num_matches) | 
|  | 3766 | { | 
|  | 3767 | if (namespace_decl) | 
|  | 3768 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3769 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3770 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u", | 
|  | 3771 | name.GetCString(), | 
|  | 3772 | namespace_decl->GetNamespaceDecl(), | 
|  | 3773 | namespace_decl->GetQualifiedName().c_str(), | 
|  | 3774 | append, | 
|  | 3775 | max_matches, | 
|  | 3776 | num_matches); | 
|  | 3777 | } | 
|  | 3778 | else | 
|  | 3779 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3780 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3781 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u", | 
|  | 3782 | name.GetCString(), | 
|  | 3783 | append, | 
|  | 3784 | max_matches, | 
|  | 3785 | num_matches); | 
|  | 3786 | } | 
|  | 3787 | } | 
|  | 3788 | return num_matches; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3789 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3790 | return 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3791 | } | 
|  | 3792 |  | 
|  | 3793 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3794 | ClangNamespaceDecl | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3795 | SymbolFileDWARF::FindNamespace (const SymbolContext& sc, | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3796 | const ConstString &name, | 
|  | 3797 | const lldb_private::ClangNamespaceDecl *parent_namespace_decl) | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3798 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3799 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3800 |  | 
|  | 3801 | if (log) | 
|  | 3802 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3803 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3804 | "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")", | 
|  | 3805 | name.GetCString()); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3806 | } | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3807 |  | 
|  | 3808 | if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl)) | 
|  | 3809 | return ClangNamespaceDecl(); | 
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3810 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3811 | ClangNamespaceDecl namespace_decl; | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3812 | DWARFDebugInfo* info = DebugInfo(); | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3813 | if (info) | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3814 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3815 | DIEArray die_offsets; | 
|  | 3816 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3817 | // Index if we already haven't to make sure the compile units | 
|  | 3818 | // get indexed and make their global DIE index list | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3819 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3820 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3821 | if (m_apple_namespaces_ap.get()) | 
|  | 3822 | { | 
|  | 3823 | const char *name_cstr = name.GetCString(); | 
|  | 3824 | m_apple_namespaces_ap->FindByName (name_cstr, die_offsets); | 
|  | 3825 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3826 | } | 
|  | 3827 | else | 
|  | 3828 | { | 
|  | 3829 | if (!m_indexed) | 
|  | 3830 | Index (); | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3831 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3832 | m_namespace_index.Find (name, die_offsets); | 
|  | 3833 | } | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3834 |  | 
|  | 3835 | DWARFCompileUnit* dwarf_cu = NULL; | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3836 | const DWARFDebugInfoEntry* die = NULL; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3837 | const size_t num_matches = die_offsets.size(); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3838 | if (num_matches) | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3839 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3840 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 3841 | for (size_t i=0; i<num_matches; ++i) | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3842 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3843 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 3844 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3845 |  | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3846 | if (die) | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3847 | { | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3848 | if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die)) | 
|  | 3849 | continue; | 
|  | 3850 |  | 
|  | 3851 | clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die); | 
|  | 3852 | if (clang_namespace_decl) | 
|  | 3853 | { | 
|  | 3854 | namespace_decl.SetASTContext (GetClangASTContext().getASTContext()); | 
|  | 3855 | namespace_decl.SetNamespaceDecl (clang_namespace_decl); | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3856 | break; | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3857 | } | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3858 | } | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3859 | else | 
|  | 3860 | { | 
|  | 3861 | if (m_using_apple_tables) | 
|  | 3862 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3863 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n", | 
|  | 3864 | die_offset, name.GetCString()); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3865 | } | 
|  | 3866 | } | 
|  | 3867 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3868 | } | 
|  | 3869 | } | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3870 | } | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3871 | if (log && namespace_decl.GetNamespaceDecl()) | 
|  | 3872 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3873 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3874 | "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"", | 
|  | 3875 | name.GetCString(), | 
|  | 3876 | namespace_decl.GetNamespaceDecl(), | 
|  | 3877 | namespace_decl.GetQualifiedName().c_str()); | 
|  | 3878 | } | 
|  | 3879 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3880 | return namespace_decl; | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3881 | } | 
|  | 3882 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3883 | uint32_t | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3884 | 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] | 3885 | { | 
|  | 3886 | // Remember how many sc_list are in the list before we search in case | 
|  | 3887 | // we are appending the results to a variable list. | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3888 | uint32_t original_size = types.GetSize(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3889 |  | 
|  | 3890 | const uint32_t num_die_offsets = die_offsets.size(); | 
|  | 3891 | // Parse all of the types we found from the pubtypes matches | 
|  | 3892 | uint32_t i; | 
|  | 3893 | uint32_t num_matches = 0; | 
|  | 3894 | for (i = 0; i < num_die_offsets; ++i) | 
|  | 3895 | { | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3896 | Type *matching_type = ResolveTypeUID (die_offsets[i]); | 
|  | 3897 | if (matching_type) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3898 | { | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3899 | // 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] | 3900 | types.InsertUnique (matching_type->shared_from_this()); | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3901 | ++num_matches; | 
|  | 3902 | if (num_matches >= max_matches) | 
|  | 3903 | break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3904 | } | 
|  | 3905 | } | 
|  | 3906 |  | 
|  | 3907 | // Return the number of variable that were appended to the list | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3908 | return types.GetSize() - original_size; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3909 | } | 
|  | 3910 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3911 |  | 
|  | 3912 | size_t | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3913 | SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc, | 
|  | 3914 | clang::DeclContext *containing_decl_ctx, | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3915 | DWARFCompileUnit* dwarf_cu, | 
|  | 3916 | const DWARFDebugInfoEntry *parent_die, | 
|  | 3917 | bool skip_artificial, | 
|  | 3918 | bool &is_static, | 
|  | 3919 | TypeList* type_list, | 
|  | 3920 | std::vector<clang_type_t>& function_param_types, | 
|  | 3921 | std::vector<clang::ParmVarDecl*>& function_param_decls, | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 3922 | unsigned &type_quals, | 
|  | 3923 | ClangASTContext::TemplateParameterInfos &template_param_infos) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3924 | { | 
|  | 3925 | if (parent_die == NULL) | 
|  | 3926 | return 0; | 
|  | 3927 |  | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3928 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); | 
|  | 3929 |  | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3930 | size_t arg_idx = 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3931 | const DWARFDebugInfoEntry *die; | 
|  | 3932 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) | 
|  | 3933 | { | 
|  | 3934 | dw_tag_t tag = die->Tag(); | 
|  | 3935 | switch (tag) | 
|  | 3936 | { | 
|  | 3937 | case DW_TAG_formal_parameter: | 
|  | 3938 | { | 
|  | 3939 | DWARFDebugInfoEntry::Attributes attributes; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3940 | 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] | 3941 | if (num_attributes > 0) | 
|  | 3942 | { | 
|  | 3943 | const char *name = NULL; | 
|  | 3944 | Declaration decl; | 
|  | 3945 | dw_offset_t param_type_die_offset = DW_INVALID_OFFSET; | 
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 3946 | bool is_artificial = false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3947 | // one of None, Auto, Register, Extern, Static, PrivateExtern | 
|  | 3948 |  | 
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 3949 | clang::StorageClass storage = clang::SC_None; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3950 | uint32_t i; | 
|  | 3951 | for (i=0; i<num_attributes; ++i) | 
|  | 3952 | { | 
|  | 3953 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 3954 | DWARFFormValue form_value; | 
|  | 3955 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 3956 | { | 
|  | 3957 | switch (attr) | 
|  | 3958 | { | 
|  | 3959 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 3960 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 3961 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 3962 | case DW_AT_name:        name = form_value.AsCString(&get_debug_str_data()); break; | 
|  | 3963 | case DW_AT_type:        param_type_die_offset = form_value.Reference(dwarf_cu); break; | 
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 3964 | case DW_AT_artificial:  is_artificial = form_value.Unsigned() != 0; break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3965 | case DW_AT_location: | 
|  | 3966 | //                          if (form_value.BlockData()) | 
|  | 3967 | //                          { | 
|  | 3968 | //                              const DataExtractor& debug_info_data = debug_info(); | 
|  | 3969 | //                              uint32_t block_length = form_value.Unsigned(); | 
|  | 3970 | //                              DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length); | 
|  | 3971 | //                          } | 
|  | 3972 | //                          else | 
|  | 3973 | //                          { | 
|  | 3974 | //                          } | 
|  | 3975 | //                          break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3976 | case DW_AT_const_value: | 
|  | 3977 | case DW_AT_default_value: | 
|  | 3978 | case DW_AT_description: | 
|  | 3979 | case DW_AT_endianity: | 
|  | 3980 | case DW_AT_is_optional: | 
|  | 3981 | case DW_AT_segment: | 
|  | 3982 | case DW_AT_variable_parameter: | 
|  | 3983 | default: | 
|  | 3984 | case DW_AT_abstract_origin: | 
|  | 3985 | case DW_AT_sibling: | 
|  | 3986 | break; | 
|  | 3987 | } | 
|  | 3988 | } | 
|  | 3989 | } | 
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 3990 |  | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3991 | bool skip = false; | 
|  | 3992 | if (skip_artificial) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3993 | { | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3994 | if (is_artificial) | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3995 | { | 
|  | 3996 | // In order to determine if a C++ member function is | 
|  | 3997 | // "const" we have to look at the const-ness of "this"... | 
|  | 3998 | // Ugly, but that | 
|  | 3999 | if (arg_idx == 0) | 
|  | 4000 | { | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 4001 | if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind())) | 
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 4002 | { | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4003 | // Often times compilers omit the "this" name for the | 
|  | 4004 | // specification DIEs, so we can't rely upon the name | 
|  | 4005 | // being in the formal parameter DIE... | 
|  | 4006 | if (name == NULL || ::strcmp(name, "this")==0) | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4007 | { | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4008 | Type *this_type = ResolveTypeUID (param_type_die_offset); | 
|  | 4009 | if (this_type) | 
|  | 4010 | { | 
|  | 4011 | uint32_t encoding_mask = this_type->GetEncodingMask(); | 
|  | 4012 | if (encoding_mask & Type::eEncodingIsPointerUID) | 
|  | 4013 | { | 
|  | 4014 | is_static = false; | 
|  | 4015 |  | 
|  | 4016 | if (encoding_mask & (1u << Type::eEncodingIsConstUID)) | 
|  | 4017 | type_quals |= clang::Qualifiers::Const; | 
|  | 4018 | if (encoding_mask & (1u << Type::eEncodingIsVolatileUID)) | 
|  | 4019 | type_quals |= clang::Qualifiers::Volatile; | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4020 | } | 
|  | 4021 | } | 
|  | 4022 | } | 
|  | 4023 | } | 
|  | 4024 | } | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4025 | skip = true; | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4026 | } | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4027 | else | 
|  | 4028 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4029 |  | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4030 | // HACK: Objective C formal parameters "self" and "_cmd" | 
|  | 4031 | // are not marked as artificial in the DWARF... | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4032 | CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); | 
|  | 4033 | if (comp_unit) | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4034 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4035 | switch (comp_unit->GetLanguage()) | 
|  | 4036 | { | 
|  | 4037 | case eLanguageTypeObjC: | 
|  | 4038 | case eLanguageTypeObjC_plus_plus: | 
|  | 4039 | if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0)) | 
|  | 4040 | skip = true; | 
|  | 4041 | break; | 
|  | 4042 | default: | 
|  | 4043 | break; | 
|  | 4044 | } | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4045 | } | 
|  | 4046 | } | 
|  | 4047 | } | 
|  | 4048 |  | 
|  | 4049 | if (!skip) | 
|  | 4050 | { | 
|  | 4051 | Type *type = ResolveTypeUID(param_type_die_offset); | 
|  | 4052 | if (type) | 
|  | 4053 | { | 
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 4054 | function_param_types.push_back (type->GetClangForwardType()); | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4055 |  | 
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 4056 | clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name, | 
|  | 4057 | type->GetClangForwardType(), | 
|  | 4058 | storage); | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4059 | assert(param_var_decl); | 
|  | 4060 | function_param_decls.push_back(param_var_decl); | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 4061 |  | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 4062 | GetClangASTContext().SetMetadataAsUserID (param_var_decl, MakeUserID(die->GetOffset())); | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4063 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4064 | } | 
|  | 4065 | } | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4066 | arg_idx++; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4067 | } | 
|  | 4068 | break; | 
|  | 4069 |  | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 4070 | case DW_TAG_template_type_parameter: | 
|  | 4071 | case DW_TAG_template_value_parameter: | 
|  | 4072 | ParseTemplateDIE (dwarf_cu, die,template_param_infos); | 
|  | 4073 | break; | 
|  | 4074 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4075 | default: | 
|  | 4076 | break; | 
|  | 4077 | } | 
|  | 4078 | } | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4079 | return arg_idx; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4080 | } | 
|  | 4081 |  | 
|  | 4082 | size_t | 
|  | 4083 | SymbolFileDWARF::ParseChildEnumerators | 
|  | 4084 | ( | 
|  | 4085 | const SymbolContext& sc, | 
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 4086 | clang_type_t enumerator_clang_type, | 
|  | 4087 | bool is_signed, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4088 | uint32_t enumerator_byte_size, | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4089 | DWARFCompileUnit* dwarf_cu, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4090 | const DWARFDebugInfoEntry *parent_die | 
|  | 4091 | ) | 
|  | 4092 | { | 
|  | 4093 | if (parent_die == NULL) | 
|  | 4094 | return 0; | 
|  | 4095 |  | 
|  | 4096 | size_t enumerators_added = 0; | 
|  | 4097 | const DWARFDebugInfoEntry *die; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4098 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); | 
|  | 4099 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4100 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) | 
|  | 4101 | { | 
|  | 4102 | const dw_tag_t tag = die->Tag(); | 
|  | 4103 | if (tag == DW_TAG_enumerator) | 
|  | 4104 | { | 
|  | 4105 | DWARFDebugInfoEntry::Attributes attributes; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4106 | 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] | 4107 | if (num_child_attributes > 0) | 
|  | 4108 | { | 
|  | 4109 | const char *name = NULL; | 
|  | 4110 | bool got_value = false; | 
|  | 4111 | int64_t enum_value = 0; | 
|  | 4112 | Declaration decl; | 
|  | 4113 |  | 
|  | 4114 | uint32_t i; | 
|  | 4115 | for (i=0; i<num_child_attributes; ++i) | 
|  | 4116 | { | 
|  | 4117 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 4118 | DWARFFormValue form_value; | 
|  | 4119 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 4120 | { | 
|  | 4121 | switch (attr) | 
|  | 4122 | { | 
|  | 4123 | case DW_AT_const_value: | 
|  | 4124 | got_value = true; | 
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 4125 | if (is_signed) | 
|  | 4126 | enum_value = form_value.Signed(); | 
|  | 4127 | else | 
|  | 4128 | enum_value = form_value.Unsigned(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4129 | break; | 
|  | 4130 |  | 
|  | 4131 | case DW_AT_name: | 
|  | 4132 | name = form_value.AsCString(&get_debug_str_data()); | 
|  | 4133 | break; | 
|  | 4134 |  | 
|  | 4135 | case DW_AT_description: | 
|  | 4136 | default: | 
|  | 4137 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 4138 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 4139 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 4140 | case DW_AT_sibling: | 
|  | 4141 | break; | 
|  | 4142 | } | 
|  | 4143 | } | 
|  | 4144 | } | 
|  | 4145 |  | 
|  | 4146 | if (name && name[0] && got_value) | 
|  | 4147 | { | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 4148 | GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type, | 
|  | 4149 | enumerator_clang_type, | 
|  | 4150 | decl, | 
|  | 4151 | name, | 
|  | 4152 | enum_value, | 
|  | 4153 | enumerator_byte_size * 8); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4154 | ++enumerators_added; | 
|  | 4155 | } | 
|  | 4156 | } | 
|  | 4157 | } | 
|  | 4158 | } | 
|  | 4159 | return enumerators_added; | 
|  | 4160 | } | 
|  | 4161 |  | 
|  | 4162 | void | 
|  | 4163 | SymbolFileDWARF::ParseChildArrayInfo | 
|  | 4164 | ( | 
|  | 4165 | const SymbolContext& sc, | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4166 | DWARFCompileUnit* dwarf_cu, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4167 | const DWARFDebugInfoEntry *parent_die, | 
|  | 4168 | int64_t& first_index, | 
|  | 4169 | std::vector<uint64_t>& element_orders, | 
|  | 4170 | uint32_t& byte_stride, | 
|  | 4171 | uint32_t& bit_stride | 
|  | 4172 | ) | 
|  | 4173 | { | 
|  | 4174 | if (parent_die == NULL) | 
|  | 4175 | return; | 
|  | 4176 |  | 
|  | 4177 | const DWARFDebugInfoEntry *die; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4178 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4179 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) | 
|  | 4180 | { | 
|  | 4181 | const dw_tag_t tag = die->Tag(); | 
|  | 4182 | switch (tag) | 
|  | 4183 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4184 | case DW_TAG_subrange_type: | 
|  | 4185 | { | 
|  | 4186 | DWARFDebugInfoEntry::Attributes attributes; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4187 | 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] | 4188 | if (num_child_attributes > 0) | 
|  | 4189 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4190 | uint64_t num_elements = 0; | 
|  | 4191 | uint64_t lower_bound = 0; | 
|  | 4192 | uint64_t upper_bound = 0; | 
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4193 | bool upper_bound_valid = false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4194 | uint32_t i; | 
|  | 4195 | for (i=0; i<num_child_attributes; ++i) | 
|  | 4196 | { | 
|  | 4197 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 4198 | DWARFFormValue form_value; | 
|  | 4199 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 4200 | { | 
|  | 4201 | switch (attr) | 
|  | 4202 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4203 | case DW_AT_name: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4204 | break; | 
|  | 4205 |  | 
|  | 4206 | case DW_AT_count: | 
|  | 4207 | num_elements = form_value.Unsigned(); | 
|  | 4208 | break; | 
|  | 4209 |  | 
|  | 4210 | case DW_AT_bit_stride: | 
|  | 4211 | bit_stride = form_value.Unsigned(); | 
|  | 4212 | break; | 
|  | 4213 |  | 
|  | 4214 | case DW_AT_byte_stride: | 
|  | 4215 | byte_stride = form_value.Unsigned(); | 
|  | 4216 | break; | 
|  | 4217 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4218 | case DW_AT_lower_bound: | 
|  | 4219 | lower_bound = form_value.Unsigned(); | 
|  | 4220 | break; | 
|  | 4221 |  | 
|  | 4222 | case DW_AT_upper_bound: | 
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4223 | upper_bound_valid = true; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4224 | upper_bound = form_value.Unsigned(); | 
|  | 4225 | break; | 
|  | 4226 |  | 
|  | 4227 | default: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4228 | case DW_AT_abstract_origin: | 
|  | 4229 | case DW_AT_accessibility: | 
|  | 4230 | case DW_AT_allocated: | 
|  | 4231 | case DW_AT_associated: | 
|  | 4232 | case DW_AT_data_location: | 
|  | 4233 | case DW_AT_declaration: | 
|  | 4234 | case DW_AT_description: | 
|  | 4235 | case DW_AT_sibling: | 
|  | 4236 | case DW_AT_threads_scaled: | 
|  | 4237 | case DW_AT_type: | 
|  | 4238 | case DW_AT_visibility: | 
|  | 4239 | break; | 
|  | 4240 | } | 
|  | 4241 | } | 
|  | 4242 | } | 
|  | 4243 |  | 
| Greg Clayton | e6a0779 | 2012-12-05 21:59:39 +0000 | [diff] [blame] | 4244 | if (num_elements == 0) | 
|  | 4245 | { | 
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4246 | if (upper_bound_valid && upper_bound >= lower_bound) | 
| Greg Clayton | e6a0779 | 2012-12-05 21:59:39 +0000 | [diff] [blame] | 4247 | num_elements = upper_bound - lower_bound + 1; | 
|  | 4248 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4249 |  | 
| Sean Callanan | ec979ba | 2012-10-22 23:56:48 +0000 | [diff] [blame] | 4250 | element_orders.push_back (num_elements); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4251 | } | 
|  | 4252 | } | 
|  | 4253 | break; | 
|  | 4254 | } | 
|  | 4255 | } | 
|  | 4256 | } | 
|  | 4257 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4258 | TypeSP | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4259 | SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4260 | { | 
|  | 4261 | TypeSP type_sp; | 
|  | 4262 | if (die != NULL) | 
|  | 4263 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4264 | assert(dwarf_cu != NULL); | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4265 | Type *type_ptr = m_die_to_type.lookup (die); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4266 | if (type_ptr == NULL) | 
|  | 4267 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4268 | CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu); | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4269 | assert (lldb_cu); | 
|  | 4270 | SymbolContext sc(lldb_cu); | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4271 | type_sp = ParseType(sc, dwarf_cu, die, NULL); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4272 | } | 
|  | 4273 | else if (type_ptr != DIE_IS_BEING_PARSED) | 
|  | 4274 | { | 
|  | 4275 | // Grab the existing type from the master types lists | 
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 4276 | type_sp = type_ptr->shared_from_this(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4277 | } | 
|  | 4278 |  | 
|  | 4279 | } | 
|  | 4280 | return type_sp; | 
|  | 4281 | } | 
|  | 4282 |  | 
|  | 4283 | clang::DeclContext * | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4284 | SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4285 | { | 
|  | 4286 | if (die_offset != DW_INVALID_OFFSET) | 
|  | 4287 | { | 
|  | 4288 | DWARFCompileUnitSP cu_sp; | 
|  | 4289 | const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp); | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4290 | return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4291 | } | 
|  | 4292 | return NULL; | 
|  | 4293 | } | 
|  | 4294 |  | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4295 | clang::DeclContext * | 
|  | 4296 | SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset) | 
|  | 4297 | { | 
|  | 4298 | if (die_offset != DW_INVALID_OFFSET) | 
|  | 4299 | { | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4300 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 4301 | if (debug_info) | 
|  | 4302 | { | 
|  | 4303 | DWARFCompileUnitSP cu_sp; | 
|  | 4304 | const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp); | 
|  | 4305 | if (die) | 
|  | 4306 | return GetClangDeclContextForDIE (sc, cu_sp.get(), die); | 
|  | 4307 | } | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4308 | } | 
|  | 4309 | return NULL; | 
|  | 4310 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4311 |  | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4312 | clang::NamespaceDecl * | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4313 | SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die) | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4314 | { | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4315 | if (die && die->Tag() == DW_TAG_namespace) | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4316 | { | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4317 | // See if we already parsed this namespace DIE and associated it with a | 
|  | 4318 | // uniqued namespace declaration | 
|  | 4319 | clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]); | 
|  | 4320 | if (namespace_decl) | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4321 | return namespace_decl; | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4322 | else | 
|  | 4323 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4324 | const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL); | 
|  | 4325 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL); | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4326 | namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4327 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4328 | if (log) | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4329 | { | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4330 | if (namespace_name) | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4331 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4332 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4333 | "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] | 4334 | GetClangASTContext().getASTContext(), | 
|  | 4335 | MakeUserID(die->GetOffset()), | 
|  | 4336 | namespace_name, | 
|  | 4337 | namespace_decl, | 
|  | 4338 | namespace_decl->getOriginalNamespace()); | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4339 | } | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4340 | else | 
|  | 4341 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4342 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4343 | "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] | 4344 | GetClangASTContext().getASTContext(), | 
|  | 4345 | MakeUserID(die->GetOffset()), | 
|  | 4346 | namespace_decl, | 
|  | 4347 | namespace_decl->getOriginalNamespace()); | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4348 | } | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4349 | } | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4350 |  | 
|  | 4351 | if (namespace_decl) | 
|  | 4352 | LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die); | 
|  | 4353 | return namespace_decl; | 
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4354 | } | 
|  | 4355 | } | 
|  | 4356 | return NULL; | 
|  | 4357 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4358 |  | 
|  | 4359 | clang::DeclContext * | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4360 | SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4361 | { | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4362 | clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die); | 
|  | 4363 | if (clang_decl_ctx) | 
|  | 4364 | return clang_decl_ctx; | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4365 | // If this DIE has a specification, or an abstract origin, then trace to those. | 
|  | 4366 |  | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4367 | 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] | 4368 | if (die_offset != DW_INVALID_OFFSET) | 
|  | 4369 | return GetClangDeclContextForDIEOffset (sc, die_offset); | 
|  | 4370 |  | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4371 | 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] | 4372 | if (die_offset != DW_INVALID_OFFSET) | 
|  | 4373 | return GetClangDeclContextForDIEOffset (sc, die_offset); | 
|  | 4374 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4375 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 4376 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4377 | 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] | 4378 | // This is the DIE we want.  Parse it, then query our map. | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4379 | bool assert_not_being_parsed = true; | 
|  | 4380 | ResolveTypeUID (cu, die, assert_not_being_parsed); | 
|  | 4381 |  | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4382 | clang_decl_ctx = GetCachedClangDeclContextForDIE (die); | 
|  | 4383 |  | 
|  | 4384 | return clang_decl_ctx; | 
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4385 | } | 
|  | 4386 |  | 
|  | 4387 | clang::DeclContext * | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4388 | 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] | 4389 | { | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4390 | if (m_clang_tu_decl == NULL) | 
|  | 4391 | m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4392 |  | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4393 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4394 |  | 
|  | 4395 | if (decl_ctx_die_copy) | 
|  | 4396 | *decl_ctx_die_copy = decl_ctx_die; | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4397 |  | 
|  | 4398 | if (decl_ctx_die) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4399 | { | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4400 |  | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4401 | DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die); | 
|  | 4402 | if (pos != m_die_to_decl_ctx.end()) | 
|  | 4403 | return pos->second; | 
|  | 4404 |  | 
|  | 4405 | switch (decl_ctx_die->Tag()) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4406 | { | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4407 | case DW_TAG_compile_unit: | 
|  | 4408 | return m_clang_tu_decl; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4409 |  | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4410 | case DW_TAG_namespace: | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4411 | return ResolveNamespaceDIE (cu, decl_ctx_die); | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4412 | break; | 
|  | 4413 |  | 
|  | 4414 | case DW_TAG_structure_type: | 
|  | 4415 | case DW_TAG_union_type: | 
|  | 4416 | case DW_TAG_class_type: | 
|  | 4417 | { | 
|  | 4418 | Type* type = ResolveType (cu, decl_ctx_die); | 
|  | 4419 | if (type) | 
|  | 4420 | { | 
|  | 4421 | clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ()); | 
|  | 4422 | if (decl_ctx) | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4423 | { | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4424 | LinkDeclContextToDIE (decl_ctx, decl_ctx_die); | 
|  | 4425 | if (decl_ctx) | 
|  | 4426 | return decl_ctx; | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4427 | } | 
|  | 4428 | } | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4429 | } | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4430 | break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4431 |  | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4432 | default: | 
|  | 4433 | break; | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4434 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4435 | } | 
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 4436 | return m_clang_tu_decl; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4437 | } | 
|  | 4438 |  | 
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4439 |  | 
|  | 4440 | const DWARFDebugInfoEntry * | 
|  | 4441 | SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) | 
|  | 4442 | { | 
|  | 4443 | if (cu && die) | 
|  | 4444 | { | 
|  | 4445 | const DWARFDebugInfoEntry * const decl_die = die; | 
|  | 4446 |  | 
|  | 4447 | while (die != NULL) | 
|  | 4448 | { | 
|  | 4449 | // If this is the original DIE that we are searching for a declaration | 
|  | 4450 | // for, then don't look in the cache as we don't want our own decl | 
|  | 4451 | // context to be our decl context... | 
|  | 4452 | if (decl_die != die) | 
|  | 4453 | { | 
|  | 4454 | switch (die->Tag()) | 
|  | 4455 | { | 
|  | 4456 | case DW_TAG_compile_unit: | 
|  | 4457 | case DW_TAG_namespace: | 
|  | 4458 | case DW_TAG_structure_type: | 
|  | 4459 | case DW_TAG_union_type: | 
|  | 4460 | case DW_TAG_class_type: | 
|  | 4461 | return die; | 
|  | 4462 |  | 
|  | 4463 | default: | 
|  | 4464 | break; | 
|  | 4465 | } | 
|  | 4466 | } | 
|  | 4467 |  | 
|  | 4468 | dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET); | 
|  | 4469 | if (die_offset != DW_INVALID_OFFSET) | 
|  | 4470 | { | 
|  | 4471 | DWARFCompileUnit *spec_cu = cu; | 
|  | 4472 | const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu); | 
|  | 4473 | const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die); | 
|  | 4474 | if (spec_die_decl_ctx_die) | 
|  | 4475 | return spec_die_decl_ctx_die; | 
|  | 4476 | } | 
|  | 4477 |  | 
|  | 4478 | die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET); | 
|  | 4479 | if (die_offset != DW_INVALID_OFFSET) | 
|  | 4480 | { | 
|  | 4481 | DWARFCompileUnit *abs_cu = cu; | 
|  | 4482 | const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu); | 
|  | 4483 | const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die); | 
|  | 4484 | if (abs_die_decl_ctx_die) | 
|  | 4485 | return abs_die_decl_ctx_die; | 
|  | 4486 | } | 
|  | 4487 |  | 
|  | 4488 | die = die->GetParent(); | 
|  | 4489 | } | 
|  | 4490 | } | 
|  | 4491 | return NULL; | 
|  | 4492 | } | 
|  | 4493 |  | 
|  | 4494 |  | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4495 | Symbol * | 
|  | 4496 | SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name) | 
|  | 4497 | { | 
|  | 4498 | Symbol *objc_class_symbol = NULL; | 
|  | 4499 | if (m_obj_file) | 
|  | 4500 | { | 
|  | 4501 | Symtab *symtab = m_obj_file->GetSymtab(); | 
|  | 4502 | if (symtab) | 
|  | 4503 | { | 
|  | 4504 | objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name, | 
|  | 4505 | eSymbolTypeObjCClass, | 
|  | 4506 | Symtab::eDebugNo, | 
|  | 4507 | Symtab::eVisibilityAny); | 
|  | 4508 | } | 
|  | 4509 | } | 
|  | 4510 | return objc_class_symbol; | 
|  | 4511 | } | 
|  | 4512 |  | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4513 | // Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't | 
|  | 4514 | // then we can end up looking through all class types for a complete type and never find | 
|  | 4515 | // the full definition. We need to know if this attribute is supported, so we determine | 
|  | 4516 | // this here and cache th result. We also need to worry about the debug map DWARF file | 
|  | 4517 | // if we are doing darwin DWARF in .o file debugging. | 
|  | 4518 | bool | 
|  | 4519 | SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu) | 
|  | 4520 | { | 
|  | 4521 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate) | 
|  | 4522 | { | 
|  | 4523 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo; | 
|  | 4524 | if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type()) | 
|  | 4525 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; | 
|  | 4526 | else | 
|  | 4527 | { | 
|  | 4528 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 4529 | const uint32_t num_compile_units = GetNumCompileUnits(); | 
|  | 4530 | for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) | 
|  | 4531 | { | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4532 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); | 
|  | 4533 | 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] | 4534 | { | 
|  | 4535 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; | 
|  | 4536 | break; | 
|  | 4537 | } | 
|  | 4538 | } | 
|  | 4539 | } | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 4540 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ()) | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4541 | return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this); | 
|  | 4542 | } | 
|  | 4543 | return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes; | 
|  | 4544 | } | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4545 |  | 
|  | 4546 | // This function can be used when a DIE is found that is a forward declaration | 
|  | 4547 | // DIE and we want to try and find a type that has the complete definition. | 
|  | 4548 | TypeSP | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4549 | SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die, | 
|  | 4550 | const ConstString &type_name, | 
|  | 4551 | bool must_be_implementation) | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4552 | { | 
|  | 4553 |  | 
|  | 4554 | TypeSP type_sp; | 
|  | 4555 |  | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4556 | if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name))) | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4557 | return type_sp; | 
|  | 4558 |  | 
|  | 4559 | DIEArray die_offsets; | 
|  | 4560 |  | 
|  | 4561 | if (m_using_apple_tables) | 
|  | 4562 | { | 
|  | 4563 | if (m_apple_types_ap.get()) | 
|  | 4564 | { | 
|  | 4565 | const char *name_cstr = type_name.GetCString(); | 
| Greg Clayton | 68221ec | 2012-01-18 20:58:12 +0000 | [diff] [blame] | 4566 | m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation); | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4567 | } | 
|  | 4568 | } | 
|  | 4569 | else | 
|  | 4570 | { | 
|  | 4571 | if (!m_indexed) | 
|  | 4572 | Index (); | 
|  | 4573 |  | 
|  | 4574 | m_type_index.Find (type_name, die_offsets); | 
|  | 4575 | } | 
|  | 4576 |  | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4577 | const size_t num_matches = die_offsets.size(); | 
|  | 4578 |  | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4579 | DWARFCompileUnit* type_cu = NULL; | 
|  | 4580 | const DWARFDebugInfoEntry* type_die = NULL; | 
|  | 4581 | if (num_matches) | 
|  | 4582 | { | 
|  | 4583 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 4584 | for (size_t i=0; i<num_matches; ++i) | 
|  | 4585 | { | 
|  | 4586 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 4587 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); | 
|  | 4588 |  | 
|  | 4589 | if (type_die) | 
|  | 4590 | { | 
|  | 4591 | bool try_resolving_type = false; | 
|  | 4592 |  | 
|  | 4593 | // Don't try and resolve the DIE we are looking for with the DIE itself! | 
|  | 4594 | if (type_die != die) | 
|  | 4595 | { | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4596 | switch (type_die->Tag()) | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4597 | { | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4598 | case DW_TAG_class_type: | 
|  | 4599 | case DW_TAG_structure_type: | 
|  | 4600 | try_resolving_type = true; | 
|  | 4601 | break; | 
|  | 4602 | default: | 
|  | 4603 | break; | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4604 | } | 
|  | 4605 | } | 
|  | 4606 |  | 
|  | 4607 | if (try_resolving_type) | 
|  | 4608 | { | 
| Sean Callanan | a9bc065 | 2012-01-19 02:17:40 +0000 | [diff] [blame] | 4609 | 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] | 4610 | 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] | 4611 |  | 
|  | 4612 | if (try_resolving_type) | 
|  | 4613 | { | 
|  | 4614 | Type *resolved_type = ResolveType (type_cu, type_die, false); | 
|  | 4615 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) | 
|  | 4616 | { | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4617 | 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] | 4618 | MakeUserID(die->GetOffset()), | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4619 | MakeUserID(dwarf_cu->GetOffset()), | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4620 | m_obj_file->GetFileSpec().GetFilename().AsCString(), | 
|  | 4621 | MakeUserID(type_die->GetOffset()), | 
|  | 4622 | MakeUserID(type_cu->GetOffset())); | 
|  | 4623 |  | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4624 | if (die) | 
|  | 4625 | m_die_to_type[die] = resolved_type; | 
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 4626 | type_sp = resolved_type->shared_from_this(); | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4627 | break; | 
|  | 4628 | } | 
|  | 4629 | } | 
|  | 4630 | } | 
|  | 4631 | } | 
|  | 4632 | else | 
|  | 4633 | { | 
|  | 4634 | if (m_using_apple_tables) | 
|  | 4635 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4636 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", | 
|  | 4637 | die_offset, type_name.GetCString()); | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4638 | } | 
|  | 4639 | } | 
|  | 4640 |  | 
|  | 4641 | } | 
|  | 4642 | } | 
|  | 4643 | return type_sp; | 
|  | 4644 | } | 
|  | 4645 |  | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4646 |  | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4647 | //---------------------------------------------------------------------- | 
|  | 4648 | // This function helps to ensure that the declaration contexts match for | 
|  | 4649 | // two different DIEs. Often times debug information will refer to a | 
|  | 4650 | // forward declaration of a type (the equivalent of "struct my_struct;". | 
|  | 4651 | // There will often be a declaration of that type elsewhere that has the | 
|  | 4652 | // full definition. When we go looking for the full type "my_struct", we | 
|  | 4653 | // will find one or more matches in the accelerator tables and we will | 
|  | 4654 | // then need to make sure the type was in the same declaration context | 
|  | 4655 | // as the original DIE. This function can efficiently compare two DIEs | 
|  | 4656 | // and will return true when the declaration context matches, and false | 
|  | 4657 | // when they don't. | 
|  | 4658 | //---------------------------------------------------------------------- | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4659 | bool | 
|  | 4660 | SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1, | 
|  | 4661 | DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2) | 
|  | 4662 | { | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4663 | if (die1 == die2) | 
|  | 4664 | return true; | 
|  | 4665 |  | 
|  | 4666 | #if defined (LLDB_CONFIGURATION_DEBUG) | 
|  | 4667 | // You can't and shouldn't call this function with a compile unit from | 
|  | 4668 | // two different SymbolFileDWARF instances. | 
|  | 4669 | assert (DebugInfo()->ContainsCompileUnit (cu1)); | 
|  | 4670 | assert (DebugInfo()->ContainsCompileUnit (cu2)); | 
|  | 4671 | #endif | 
|  | 4672 |  | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4673 | DWARFDIECollection decl_ctx_1; | 
|  | 4674 | DWARFDIECollection decl_ctx_2; | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4675 | //The declaration DIE stack is a stack of the declaration context | 
|  | 4676 | // DIEs all the way back to the compile unit. If a type "T" is | 
|  | 4677 | // declared inside a class "B", and class "B" is declared inside | 
|  | 4678 | // a class "A" and class "A" is in a namespace "lldb", and the | 
|  | 4679 | // namespace is in a compile unit, there will be a stack of DIEs: | 
|  | 4680 | // | 
|  | 4681 | //   [0] DW_TAG_class_type for "B" | 
|  | 4682 | //   [1] DW_TAG_class_type for "A" | 
|  | 4683 | //   [2] DW_TAG_namespace  for "lldb" | 
|  | 4684 | //   [3] DW_TAG_compile_unit for the source file. | 
|  | 4685 | // | 
|  | 4686 | // We grab both contexts and make sure that everything matches | 
|  | 4687 | // all the way back to the compiler unit. | 
|  | 4688 |  | 
|  | 4689 | // First lets grab the decl contexts for both DIEs | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4690 | die1->GetDeclContextDIEs (this, cu1, decl_ctx_1); | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 4691 | die2->GetDeclContextDIEs (this, cu2, decl_ctx_2); | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4692 | // Make sure the context arrays have the same size, otherwise | 
|  | 4693 | // we are done | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4694 | const size_t count1 = decl_ctx_1.Size(); | 
|  | 4695 | const size_t count2 = decl_ctx_2.Size(); | 
|  | 4696 | if (count1 != count2) | 
|  | 4697 | return false; | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4698 |  | 
|  | 4699 | // Make sure the DW_TAG values match all the way back up the the | 
|  | 4700 | // compile unit. If they don't, then we are done. | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4701 | const DWARFDebugInfoEntry *decl_ctx_die1; | 
|  | 4702 | const DWARFDebugInfoEntry *decl_ctx_die2; | 
|  | 4703 | size_t i; | 
|  | 4704 | for (i=0; i<count1; i++) | 
|  | 4705 | { | 
|  | 4706 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); | 
|  | 4707 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); | 
|  | 4708 | if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag()) | 
|  | 4709 | return false; | 
|  | 4710 | } | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4711 | #if defined LLDB_CONFIGURATION_DEBUG | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4712 |  | 
|  | 4713 | // Make sure the top item in the decl context die array is always | 
|  | 4714 | // DW_TAG_compile_unit. If it isn't then something went wrong in | 
|  | 4715 | // the DWARFDebugInfoEntry::GetDeclContextDIEs() function... | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4716 | assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit); | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4717 |  | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4718 | #endif | 
|  | 4719 | // Always skip the compile unit when comparing by only iterating up to | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4720 | // "count - 1". Here we compare the names as we go. | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4721 | for (i=0; i<count1 - 1; i++) | 
|  | 4722 | { | 
|  | 4723 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); | 
|  | 4724 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); | 
|  | 4725 | const char *name1 = decl_ctx_die1->GetName(this, cu1); | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 4726 | const char *name2 = decl_ctx_die2->GetName(this, cu2); | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4727 | // If the string was from a DW_FORM_strp, then the pointer will often | 
|  | 4728 | // be the same! | 
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 4729 | if (name1 == name2) | 
|  | 4730 | continue; | 
|  | 4731 |  | 
|  | 4732 | // Name pointers are not equal, so only compare the strings | 
|  | 4733 | // if both are not NULL. | 
|  | 4734 | if (name1 && name2) | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4735 | { | 
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 4736 | // If the strings don't compare, we are done... | 
|  | 4737 | if (strcmp(name1, name2) != 0) | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4738 | return false; | 
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 4739 | } | 
|  | 4740 | else | 
|  | 4741 | { | 
|  | 4742 | // One name was NULL while the other wasn't | 
|  | 4743 | return false; | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4744 | } | 
|  | 4745 | } | 
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4746 | // We made it through all of the checks and the declaration contexts | 
|  | 4747 | // are equal. | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4748 | return true; | 
|  | 4749 | } | 
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 4750 |  | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4751 | // This function can be used when a DIE is found that is a forward declaration | 
|  | 4752 | // 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] | 4753 | // "cu" and "die" must be from this SymbolFileDWARF | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4754 | TypeSP | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4755 | SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu, | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4756 | const DWARFDebugInfoEntry *die, | 
|  | 4757 | const ConstString &type_name) | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4758 | { | 
|  | 4759 | TypeSP type_sp; | 
|  | 4760 |  | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4761 | #if defined (LLDB_CONFIGURATION_DEBUG) | 
|  | 4762 | // You can't and shouldn't call this function with a compile unit from | 
|  | 4763 | // another SymbolFileDWARF instance. | 
|  | 4764 | assert (DebugInfo()->ContainsCompileUnit (cu)); | 
|  | 4765 | #endif | 
|  | 4766 |  | 
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 4767 | if (cu == NULL || die == NULL || !type_name) | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4768 | return type_sp; | 
|  | 4769 |  | 
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 4770 | std::string qualified_name; | 
|  | 4771 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4772 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4773 | if (log) | 
|  | 4774 | { | 
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4775 | die->GetQualifiedName(this, cu, qualified_name); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4776 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4777 | "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x (%s), name='%s')", | 
|  | 4778 | die->GetOffset(), | 
|  | 4779 | qualified_name.c_str(), | 
|  | 4780 | type_name.GetCString()); | 
|  | 4781 | } | 
|  | 4782 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4783 | DIEArray die_offsets; | 
|  | 4784 |  | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4785 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4786 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4787 | if (m_apple_types_ap.get()) | 
|  | 4788 | { | 
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 4789 | const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag); | 
|  | 4790 | const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash); | 
|  | 4791 | if (has_tag && has_qualified_name_hash) | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4792 | { | 
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 4793 | if (qualified_name.empty()) | 
|  | 4794 | die->GetQualifiedName(this, cu, qualified_name); | 
|  | 4795 |  | 
|  | 4796 | const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name.c_str()); | 
|  | 4797 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4798 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()"); | 
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 4799 | m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), die->Tag(), qualified_name_hash, die_offsets); | 
|  | 4800 | } | 
|  | 4801 | else if (has_tag > 1) | 
|  | 4802 | { | 
|  | 4803 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4804 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()"); | 
| Greg Clayton | ae920b6 | 2012-01-06 00:17:16 +0000 | [diff] [blame] | 4805 | m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets); | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4806 | } | 
|  | 4807 | else | 
|  | 4808 | { | 
|  | 4809 | m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets); | 
|  | 4810 | } | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4811 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4812 | } | 
|  | 4813 | else | 
|  | 4814 | { | 
|  | 4815 | if (!m_indexed) | 
|  | 4816 | Index (); | 
|  | 4817 |  | 
|  | 4818 | m_type_index.Find (type_name, die_offsets); | 
|  | 4819 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4820 |  | 
|  | 4821 | const size_t num_matches = die_offsets.size(); | 
| Greg Clayton | 6997489 | 2010-12-03 21:42:06 +0000 | [diff] [blame] | 4822 |  | 
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4823 | const dw_tag_t die_tag = die->Tag(); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4824 |  | 
|  | 4825 | DWARFCompileUnit* type_cu = NULL; | 
|  | 4826 | const DWARFDebugInfoEntry* type_die = NULL; | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4827 | if (num_matches) | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4828 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4829 | DWARFDebugInfo* debug_info = DebugInfo(); | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4830 | for (size_t i=0; i<num_matches; ++i) | 
|  | 4831 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4832 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 4833 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4834 |  | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4835 | if (type_die) | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4836 | { | 
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4837 | bool try_resolving_type = false; | 
|  | 4838 |  | 
|  | 4839 | // Don't try and resolve the DIE we are looking for with the DIE itself! | 
|  | 4840 | if (type_die != die) | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4841 | { | 
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4842 | const dw_tag_t type_die_tag = type_die->Tag(); | 
|  | 4843 | // Make sure the tags match | 
|  | 4844 | if (type_die_tag == die_tag) | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4845 | { | 
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4846 | // The tags match, lets try resolving this type | 
|  | 4847 | try_resolving_type = true; | 
|  | 4848 | } | 
|  | 4849 | else | 
|  | 4850 | { | 
|  | 4851 | // The tags don't match, but we need to watch our for a | 
|  | 4852 | // forward declaration for a struct and ("struct foo") | 
|  | 4853 | // ends up being a class ("class foo { ... };") or | 
|  | 4854 | // vice versa. | 
|  | 4855 | switch (type_die_tag) | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4856 | { | 
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4857 | case DW_TAG_class_type: | 
|  | 4858 | // We had a "class foo", see if we ended up with a "struct foo { ... };" | 
|  | 4859 | try_resolving_type = (die_tag == DW_TAG_structure_type); | 
|  | 4860 | break; | 
|  | 4861 | case DW_TAG_structure_type: | 
|  | 4862 | // We had a "struct foo", see if we ended up with a "class foo { ... };" | 
|  | 4863 | try_resolving_type = (die_tag == DW_TAG_class_type); | 
|  | 4864 | break; | 
|  | 4865 | default: | 
|  | 4866 | // Tags don't match, don't event try to resolve | 
|  | 4867 | // using this type whose name matches.... | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4868 | break; | 
|  | 4869 | } | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4870 | } | 
|  | 4871 | } | 
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4872 |  | 
|  | 4873 | if (try_resolving_type) | 
|  | 4874 | { | 
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4875 | if (log) | 
|  | 4876 | { | 
|  | 4877 | std::string qualified_name; | 
|  | 4878 | type_die->GetQualifiedName(this, cu, qualified_name); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4879 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4880 | "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') trying die=0x%8.8x (%s)", | 
|  | 4881 | die->GetOffset(), | 
|  | 4882 | type_name.GetCString(), | 
|  | 4883 | type_die->GetOffset(), | 
|  | 4884 | qualified_name.c_str()); | 
|  | 4885 | } | 
|  | 4886 |  | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4887 | // Make sure the decl contexts match all the way up | 
|  | 4888 | if (DIEDeclContextsMatch(cu, die, type_cu, type_die)) | 
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4889 | { | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4890 | Type *resolved_type = ResolveType (type_cu, type_die, false); | 
|  | 4891 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) | 
|  | 4892 | { | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4893 | 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] | 4894 | MakeUserID(die->GetOffset()), | 
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4895 | MakeUserID(dwarf_cu->GetOffset()), | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4896 | m_obj_file->GetFileSpec().GetFilename().AsCString(), | 
|  | 4897 | MakeUserID(type_die->GetOffset()), | 
|  | 4898 | MakeUserID(type_cu->GetOffset())); | 
|  | 4899 |  | 
|  | 4900 | m_die_to_type[die] = resolved_type; | 
| Greg Clayton | ff7692a | 2012-02-02 18:16:59 +0000 | [diff] [blame] | 4901 | type_sp = resolved_type->shared_from_this(); | 
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4902 | break; | 
|  | 4903 | } | 
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4904 | } | 
|  | 4905 | } | 
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4906 | else | 
|  | 4907 | { | 
|  | 4908 | if (log) | 
|  | 4909 | { | 
|  | 4910 | std::string qualified_name; | 
|  | 4911 | type_die->GetQualifiedName(this, cu, qualified_name); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4912 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4913 | "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') ignoring die=0x%8.8x (%s)", | 
|  | 4914 | die->GetOffset(), | 
|  | 4915 | type_name.GetCString(), | 
|  | 4916 | type_die->GetOffset(), | 
|  | 4917 | qualified_name.c_str()); | 
|  | 4918 | } | 
|  | 4919 | } | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4920 | } | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4921 | else | 
|  | 4922 | { | 
|  | 4923 | if (m_using_apple_tables) | 
|  | 4924 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4925 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", | 
|  | 4926 | die_offset, type_name.GetCString()); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4927 | } | 
|  | 4928 | } | 
|  | 4929 |  | 
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4930 | } | 
|  | 4931 | } | 
|  | 4932 | return type_sp; | 
|  | 4933 | } | 
|  | 4934 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4935 | TypeSP | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4936 | SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx) | 
|  | 4937 | { | 
|  | 4938 | TypeSP type_sp; | 
|  | 4939 |  | 
|  | 4940 | const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize(); | 
|  | 4941 | if (dwarf_decl_ctx_count > 0) | 
|  | 4942 | { | 
|  | 4943 | const ConstString type_name(dwarf_decl_ctx[0].name); | 
|  | 4944 | const dw_tag_t tag = dwarf_decl_ctx[0].tag; | 
|  | 4945 |  | 
|  | 4946 | if (type_name) | 
|  | 4947 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4948 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS)); | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4949 | if (log) | 
|  | 4950 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4951 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4952 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')", | 
|  | 4953 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), | 
|  | 4954 | dwarf_decl_ctx.GetQualifiedName()); | 
|  | 4955 | } | 
|  | 4956 |  | 
|  | 4957 | DIEArray die_offsets; | 
|  | 4958 |  | 
|  | 4959 | if (m_using_apple_tables) | 
|  | 4960 | { | 
|  | 4961 | if (m_apple_types_ap.get()) | 
|  | 4962 | { | 
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 4963 | const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag); | 
|  | 4964 | const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash); | 
|  | 4965 | if (has_tag && has_qualified_name_hash) | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4966 | { | 
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 4967 | const char *qualified_name = dwarf_decl_ctx.GetQualifiedName(); | 
|  | 4968 | const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name); | 
|  | 4969 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4970 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()"); | 
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 4971 | m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets); | 
|  | 4972 | } | 
|  | 4973 | else if (has_tag) | 
|  | 4974 | { | 
|  | 4975 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4976 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()"); | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4977 | m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets); | 
|  | 4978 | } | 
|  | 4979 | else | 
|  | 4980 | { | 
|  | 4981 | m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets); | 
|  | 4982 | } | 
|  | 4983 | } | 
|  | 4984 | } | 
|  | 4985 | else | 
|  | 4986 | { | 
|  | 4987 | if (!m_indexed) | 
|  | 4988 | Index (); | 
|  | 4989 |  | 
|  | 4990 | m_type_index.Find (type_name, die_offsets); | 
|  | 4991 | } | 
|  | 4992 |  | 
|  | 4993 | const size_t num_matches = die_offsets.size(); | 
|  | 4994 |  | 
|  | 4995 |  | 
|  | 4996 | DWARFCompileUnit* type_cu = NULL; | 
|  | 4997 | const DWARFDebugInfoEntry* type_die = NULL; | 
|  | 4998 | if (num_matches) | 
|  | 4999 | { | 
|  | 5000 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 5001 | for (size_t i=0; i<num_matches; ++i) | 
|  | 5002 | { | 
|  | 5003 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 5004 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); | 
|  | 5005 |  | 
|  | 5006 | if (type_die) | 
|  | 5007 | { | 
|  | 5008 | bool try_resolving_type = false; | 
|  | 5009 |  | 
|  | 5010 | // Don't try and resolve the DIE we are looking for with the DIE itself! | 
|  | 5011 | const dw_tag_t type_tag = type_die->Tag(); | 
|  | 5012 | // Make sure the tags match | 
|  | 5013 | if (type_tag == tag) | 
|  | 5014 | { | 
|  | 5015 | // The tags match, lets try resolving this type | 
|  | 5016 | try_resolving_type = true; | 
|  | 5017 | } | 
|  | 5018 | else | 
|  | 5019 | { | 
|  | 5020 | // The tags don't match, but we need to watch our for a | 
|  | 5021 | // forward declaration for a struct and ("struct foo") | 
|  | 5022 | // ends up being a class ("class foo { ... };") or | 
|  | 5023 | // vice versa. | 
|  | 5024 | switch (type_tag) | 
|  | 5025 | { | 
|  | 5026 | case DW_TAG_class_type: | 
|  | 5027 | // We had a "class foo", see if we ended up with a "struct foo { ... };" | 
|  | 5028 | try_resolving_type = (tag == DW_TAG_structure_type); | 
|  | 5029 | break; | 
|  | 5030 | case DW_TAG_structure_type: | 
|  | 5031 | // We had a "struct foo", see if we ended up with a "class foo { ... };" | 
|  | 5032 | try_resolving_type = (tag == DW_TAG_class_type); | 
|  | 5033 | break; | 
|  | 5034 | default: | 
|  | 5035 | // Tags don't match, don't event try to resolve | 
|  | 5036 | // using this type whose name matches.... | 
|  | 5037 | break; | 
|  | 5038 | } | 
|  | 5039 | } | 
|  | 5040 |  | 
|  | 5041 | if (try_resolving_type) | 
|  | 5042 | { | 
|  | 5043 | DWARFDeclContext type_dwarf_decl_ctx; | 
|  | 5044 | type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx); | 
|  | 5045 |  | 
|  | 5046 | if (log) | 
|  | 5047 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5048 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5049 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)", | 
|  | 5050 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), | 
|  | 5051 | dwarf_decl_ctx.GetQualifiedName(), | 
|  | 5052 | type_die->GetOffset(), | 
|  | 5053 | type_dwarf_decl_ctx.GetQualifiedName()); | 
|  | 5054 | } | 
|  | 5055 |  | 
|  | 5056 | // Make sure the decl contexts match all the way up | 
|  | 5057 | if (dwarf_decl_ctx == type_dwarf_decl_ctx) | 
|  | 5058 | { | 
|  | 5059 | Type *resolved_type = ResolveType (type_cu, type_die, false); | 
|  | 5060 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) | 
|  | 5061 | { | 
|  | 5062 | type_sp = resolved_type->shared_from_this(); | 
|  | 5063 | break; | 
|  | 5064 | } | 
|  | 5065 | } | 
|  | 5066 | } | 
|  | 5067 | else | 
|  | 5068 | { | 
|  | 5069 | if (log) | 
|  | 5070 | { | 
|  | 5071 | std::string qualified_name; | 
|  | 5072 | type_die->GetQualifiedName(this, type_cu, qualified_name); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5073 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5074 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)", | 
|  | 5075 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), | 
|  | 5076 | dwarf_decl_ctx.GetQualifiedName(), | 
|  | 5077 | type_die->GetOffset(), | 
|  | 5078 | qualified_name.c_str()); | 
|  | 5079 | } | 
|  | 5080 | } | 
|  | 5081 | } | 
|  | 5082 | else | 
|  | 5083 | { | 
|  | 5084 | if (m_using_apple_tables) | 
|  | 5085 | { | 
|  | 5086 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", | 
|  | 5087 | die_offset, type_name.GetCString()); | 
|  | 5088 | } | 
|  | 5089 | } | 
|  | 5090 |  | 
|  | 5091 | } | 
|  | 5092 | } | 
|  | 5093 | } | 
|  | 5094 | } | 
|  | 5095 | return type_sp; | 
|  | 5096 | } | 
|  | 5097 |  | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5098 | bool | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5099 | SymbolFileDWARF::CopyUniqueClassMethodTypes (SymbolFileDWARF *src_symfile, | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5100 | Type *class_type, | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5101 | DWARFCompileUnit* src_cu, | 
|  | 5102 | const DWARFDebugInfoEntry *src_class_die, | 
|  | 5103 | DWARFCompileUnit* dst_cu, | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5104 | const DWARFDebugInfoEntry *dst_class_die, | 
|  | 5105 | llvm::SmallVectorImpl <const DWARFDebugInfoEntry *> &failures) | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5106 | { | 
|  | 5107 | if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die) | 
|  | 5108 | return false; | 
|  | 5109 | if (src_class_die->Tag() != dst_class_die->Tag()) | 
|  | 5110 | return false; | 
|  | 5111 |  | 
|  | 5112 | // We need to complete the class type so we can get all of the method types | 
|  | 5113 | // parsed so we can then unique those types to their equivalent counterparts | 
|  | 5114 | // in "dst_cu" and "dst_class_die" | 
|  | 5115 | class_type->GetClangFullType(); | 
|  | 5116 |  | 
|  | 5117 | const DWARFDebugInfoEntry *src_die; | 
|  | 5118 | const DWARFDebugInfoEntry *dst_die; | 
|  | 5119 | UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die; | 
|  | 5120 | UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die; | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5121 | UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die_artificial; | 
|  | 5122 | UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die_artificial; | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5123 | for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling()) | 
|  | 5124 | { | 
|  | 5125 | if (src_die->Tag() == DW_TAG_subprogram) | 
|  | 5126 | { | 
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5127 | // Make sure this is a declaration and not a concrete instance by looking | 
|  | 5128 | // for DW_AT_declaration set to 1. Sometimes concrete function instances | 
|  | 5129 | // are placed inside the class definitions and shouldn't be included in | 
|  | 5130 | // the list of things are are tracking here. | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5131 | 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] | 5132 | { | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5133 | const char *src_name = src_die->GetMangledName (src_symfile, src_cu); | 
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5134 | if (src_name) | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5135 | { | 
|  | 5136 | ConstString src_const_name(src_name); | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5137 | if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_artificial, 0)) | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5138 | src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die); | 
|  | 5139 | else | 
|  | 5140 | src_name_to_die.Append(src_const_name.GetCString(), src_die); | 
|  | 5141 | } | 
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5142 | } | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5143 | } | 
|  | 5144 | } | 
|  | 5145 | for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling()) | 
|  | 5146 | { | 
|  | 5147 | if (dst_die->Tag() == DW_TAG_subprogram) | 
|  | 5148 | { | 
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5149 | // Make sure this is a declaration and not a concrete instance by looking | 
|  | 5150 | // for DW_AT_declaration set to 1. Sometimes concrete function instances | 
|  | 5151 | // are placed inside the class definitions and shouldn't be included in | 
|  | 5152 | // the list of things are are tracking here. | 
|  | 5153 | if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_declaration, 0) == 1) | 
|  | 5154 | { | 
|  | 5155 | const char *dst_name = dst_die->GetMangledName (this, dst_cu); | 
|  | 5156 | if (dst_name) | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5157 | { | 
|  | 5158 | ConstString dst_const_name(dst_name); | 
|  | 5159 | if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_artificial, 0)) | 
|  | 5160 | dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die); | 
|  | 5161 | else | 
|  | 5162 | dst_name_to_die.Append(dst_const_name.GetCString(), dst_die); | 
|  | 5163 | } | 
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5164 | } | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5165 | } | 
|  | 5166 | } | 
|  | 5167 | const uint32_t src_size = src_name_to_die.GetSize (); | 
|  | 5168 | const uint32_t dst_size = dst_name_to_die.GetSize (); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5169 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION)); | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5170 |  | 
|  | 5171 | // Is everything kosher so we can go through the members at top speed? | 
|  | 5172 | bool fast_path = true; | 
|  | 5173 |  | 
|  | 5174 | if (src_size != dst_size) | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5175 | { | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5176 | if (src_size != 0 && dst_size != 0) | 
|  | 5177 | { | 
|  | 5178 | if (log) | 
|  | 5179 | 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)", | 
|  | 5180 | src_class_die->GetOffset(), | 
|  | 5181 | dst_class_die->GetOffset(), | 
|  | 5182 | src_size, | 
|  | 5183 | dst_size); | 
|  | 5184 | } | 
|  | 5185 |  | 
|  | 5186 | fast_path = false; | 
|  | 5187 | } | 
|  | 5188 |  | 
|  | 5189 | uint32_t idx; | 
|  | 5190 |  | 
|  | 5191 | if (fast_path) | 
|  | 5192 | { | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5193 | for (idx = 0; idx < src_size; ++idx) | 
|  | 5194 | { | 
|  | 5195 | src_die = src_name_to_die.GetValueAtIndexUnchecked (idx); | 
|  | 5196 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx); | 
|  | 5197 |  | 
|  | 5198 | if (src_die->Tag() != dst_die->Tag()) | 
|  | 5199 | { | 
|  | 5200 | if (log) | 
|  | 5201 | 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)", | 
|  | 5202 | src_class_die->GetOffset(), | 
|  | 5203 | dst_class_die->GetOffset(), | 
|  | 5204 | src_die->GetOffset(), | 
|  | 5205 | DW_TAG_value_to_name(src_die->Tag()), | 
|  | 5206 | dst_die->GetOffset(), | 
|  | 5207 | DW_TAG_value_to_name(src_die->Tag())); | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5208 | fast_path = false; | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5209 | } | 
|  | 5210 |  | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5211 | const char *src_name = src_die->GetMangledName (src_symfile, src_cu); | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5212 | const char *dst_name = dst_die->GetMangledName (this, dst_cu); | 
|  | 5213 |  | 
|  | 5214 | // Make sure the names match | 
|  | 5215 | if (src_name == dst_name || (strcmp (src_name, dst_name) == 0)) | 
|  | 5216 | continue; | 
|  | 5217 |  | 
|  | 5218 | if (log) | 
|  | 5219 | 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)", | 
|  | 5220 | src_class_die->GetOffset(), | 
|  | 5221 | dst_class_die->GetOffset(), | 
|  | 5222 | src_die->GetOffset(), | 
|  | 5223 | src_name, | 
|  | 5224 | dst_die->GetOffset(), | 
|  | 5225 | dst_name); | 
|  | 5226 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5227 | fast_path = false; | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5228 | } | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5229 | } | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5230 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5231 | // Now do the work of linking the DeclContexts and Types. | 
|  | 5232 | if (fast_path) | 
|  | 5233 | { | 
|  | 5234 | // We can do this quickly.  Just run across the tables index-for-index since | 
|  | 5235 | // we know each node has matching names and tags. | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5236 | for (idx = 0; idx < src_size; ++idx) | 
|  | 5237 | { | 
|  | 5238 | src_die = src_name_to_die.GetValueAtIndexUnchecked (idx); | 
|  | 5239 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx); | 
|  | 5240 |  | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5241 | 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] | 5242 | if (src_decl_ctx) | 
|  | 5243 | { | 
|  | 5244 | if (log) | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5245 | 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] | 5246 | LinkDeclContextToDIE (src_decl_ctx, dst_die); | 
|  | 5247 | } | 
|  | 5248 | else | 
|  | 5249 | { | 
|  | 5250 | if (log) | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5251 | 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] | 5252 | } | 
|  | 5253 |  | 
|  | 5254 | Type *src_child_type = m_die_to_type[src_die]; | 
|  | 5255 | if (src_child_type) | 
|  | 5256 | { | 
|  | 5257 | if (log) | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5258 | 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] | 5259 | m_die_to_type[dst_die] = src_child_type; | 
|  | 5260 | } | 
|  | 5261 | else | 
|  | 5262 | { | 
|  | 5263 | if (log) | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5264 | 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()); | 
|  | 5265 | } | 
|  | 5266 | } | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5267 | } | 
|  | 5268 | else | 
|  | 5269 | { | 
|  | 5270 | // We must do this slowly.  For each member of the destination, look | 
|  | 5271 | // up a member in the source with the same name, check its tag, and | 
|  | 5272 | // unique them if everything matches up.  Report failures. | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5273 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5274 | if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty()) | 
|  | 5275 | { | 
|  | 5276 | src_name_to_die.Sort(); | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5277 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5278 | for (idx = 0; idx < dst_size; ++idx) | 
|  | 5279 | { | 
|  | 5280 | const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx); | 
|  | 5281 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx); | 
|  | 5282 | src_die = src_name_to_die.Find(dst_name, NULL); | 
|  | 5283 |  | 
|  | 5284 | if (src_die && (src_die->Tag() == dst_die->Tag())) | 
|  | 5285 | { | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5286 | 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] | 5287 | if (src_decl_ctx) | 
|  | 5288 | { | 
|  | 5289 | if (log) | 
|  | 5290 | log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset()); | 
|  | 5291 | LinkDeclContextToDIE (src_decl_ctx, dst_die); | 
|  | 5292 | } | 
|  | 5293 | else | 
|  | 5294 | { | 
|  | 5295 | if (log) | 
|  | 5296 | 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()); | 
|  | 5297 | } | 
|  | 5298 |  | 
|  | 5299 | Type *src_child_type = m_die_to_type[src_die]; | 
|  | 5300 | if (src_child_type) | 
|  | 5301 | { | 
|  | 5302 | if (log) | 
|  | 5303 | 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()); | 
|  | 5304 | m_die_to_type[dst_die] = src_child_type; | 
|  | 5305 | } | 
|  | 5306 | else | 
|  | 5307 | { | 
|  | 5308 | if (log) | 
|  | 5309 | 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()); | 
|  | 5310 | } | 
|  | 5311 | } | 
|  | 5312 | else | 
|  | 5313 | { | 
|  | 5314 | if (log) | 
|  | 5315 | 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] | 5316 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5317 | failures.push_back(dst_die); | 
|  | 5318 | } | 
|  | 5319 | } | 
|  | 5320 | } | 
|  | 5321 | } | 
|  | 5322 |  | 
|  | 5323 | const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize (); | 
|  | 5324 | const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize (); | 
|  | 5325 |  | 
|  | 5326 | UniqueCStringMap<const DWARFDebugInfoEntry *> name_to_die_artificial_not_in_src; | 
|  | 5327 |  | 
|  | 5328 | if (src_size_artificial && dst_size_artificial) | 
|  | 5329 | { | 
|  | 5330 | dst_name_to_die_artificial.Sort(); | 
|  | 5331 |  | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5332 | for (idx = 0; idx < src_size_artificial; ++idx) | 
|  | 5333 | { | 
|  | 5334 | const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx); | 
|  | 5335 | src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx); | 
|  | 5336 | dst_die = dst_name_to_die_artificial.Find(src_name_artificial, NULL); | 
|  | 5337 |  | 
|  | 5338 | if (dst_die) | 
|  | 5339 | { | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5340 | // Both classes have the artificial types, link them | 
|  | 5341 | clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die]; | 
|  | 5342 | if (src_decl_ctx) | 
|  | 5343 | { | 
|  | 5344 | if (log) | 
|  | 5345 | log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset()); | 
|  | 5346 | LinkDeclContextToDIE (src_decl_ctx, dst_die); | 
|  | 5347 | } | 
|  | 5348 | else | 
|  | 5349 | { | 
|  | 5350 | if (log) | 
|  | 5351 | 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()); | 
|  | 5352 | } | 
|  | 5353 |  | 
|  | 5354 | Type *src_child_type = m_die_to_type[src_die]; | 
|  | 5355 | if (src_child_type) | 
|  | 5356 | { | 
|  | 5357 | if (log) | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5358 | 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] | 5359 | m_die_to_type[dst_die] = src_child_type; | 
|  | 5360 | } | 
|  | 5361 | else | 
|  | 5362 | { | 
|  | 5363 | if (log) | 
|  | 5364 | 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()); | 
|  | 5365 | } | 
|  | 5366 | } | 
|  | 5367 | } | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5368 | } | 
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5369 |  | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5370 | if (dst_size_artificial) | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5371 | { | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5372 | for (idx = 0; idx < dst_size_artificial; ++idx) | 
|  | 5373 | { | 
|  | 5374 | const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx); | 
|  | 5375 | dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx); | 
|  | 5376 | if (log) | 
|  | 5377 | log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die->GetOffset(), dst_name_artificial); | 
|  | 5378 |  | 
|  | 5379 | failures.push_back(dst_die); | 
|  | 5380 | } | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5381 | } | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5382 |  | 
|  | 5383 | return (failures.size() != 0); | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5384 | } | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5385 |  | 
|  | 5386 | TypeSP | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5387 | 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] | 5388 | { | 
|  | 5389 | TypeSP type_sp; | 
|  | 5390 |  | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5391 | if (type_is_new_ptr) | 
|  | 5392 | *type_is_new_ptr = false; | 
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5393 |  | 
|  | 5394 | #if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE) | 
|  | 5395 | static DIEStack g_die_stack; | 
|  | 5396 | DIEStack::ScopedPopper scoped_die_logger(g_die_stack); | 
|  | 5397 | #endif | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5398 |  | 
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 5399 | AccessType accessibility = eAccessNone; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5400 | if (die != NULL) | 
|  | 5401 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5402 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5403 | if (log) | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5404 | { | 
|  | 5405 | const DWARFDebugInfoEntry *context_die; | 
|  | 5406 | clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die); | 
|  | 5407 |  | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5408 | 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] | 5409 | die->GetOffset(), | 
|  | 5410 | context, | 
|  | 5411 | context_die->GetOffset(), | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5412 | DW_TAG_value_to_name(die->Tag()), | 
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5413 | die->GetName(this, dwarf_cu)); | 
|  | 5414 |  | 
|  | 5415 | #if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE) | 
|  | 5416 | scoped_die_logger.Push (dwarf_cu, die); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5417 | g_die_stack.LogDIEs(log, this); | 
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5418 | #endif | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5419 | } | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5420 | // | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5421 | //        Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5422 | //        if (log && dwarf_cu) | 
|  | 5423 | //        { | 
|  | 5424 | //            StreamString s; | 
|  | 5425 | //            die->DumpLocation (this, dwarf_cu, s); | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5426 | //            GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData()); | 
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5427 | // | 
|  | 5428 | //        } | 
| Jim Ingham | 16746d1 | 2011-08-25 23:21:43 +0000 | [diff] [blame] | 5429 |  | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5430 | Type *type_ptr = m_die_to_type.lookup (die); | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5431 | TypeList* type_list = GetTypeList(); | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5432 | if (type_ptr == NULL) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5433 | { | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5434 | ClangASTContext &ast = GetClangASTContext(); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5435 | if (type_is_new_ptr) | 
|  | 5436 | *type_is_new_ptr = true; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5437 |  | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5438 | const dw_tag_t tag = die->Tag(); | 
|  | 5439 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5440 | bool is_forward_declaration = false; | 
|  | 5441 | DWARFDebugInfoEntry::Attributes attributes; | 
|  | 5442 | const char *type_name_cstr = NULL; | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5443 | ConstString type_name_const_str; | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5444 | Type::ResolveState resolve_state = Type::eResolveStateUnresolved; | 
| Greg Clayton | faac111 | 2013-03-14 18:31:44 +0000 | [diff] [blame] | 5445 | uint64_t byte_size = 0; | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5446 | Declaration decl; | 
|  | 5447 |  | 
| Greg Clayton | 4957bf6 | 2010-09-30 21:49:03 +0000 | [diff] [blame] | 5448 | Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID; | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5449 | clang_type_t clang_type = NULL; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5450 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5451 | dw_attr_t attr; | 
|  | 5452 |  | 
|  | 5453 | switch (tag) | 
|  | 5454 | { | 
|  | 5455 | case DW_TAG_base_type: | 
|  | 5456 | case DW_TAG_pointer_type: | 
|  | 5457 | case DW_TAG_reference_type: | 
| Sean Callanan | ce8af86 | 2012-05-21 23:31:51 +0000 | [diff] [blame] | 5458 | case DW_TAG_rvalue_reference_type: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5459 | case DW_TAG_typedef: | 
|  | 5460 | case DW_TAG_const_type: | 
|  | 5461 | case DW_TAG_restrict_type: | 
|  | 5462 | case DW_TAG_volatile_type: | 
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5463 | case DW_TAG_unspecified_type: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5464 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5465 | // 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] | 5466 | m_die_to_type[die] = DIE_IS_BEING_PARSED; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5467 |  | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5468 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5469 | uint32_t encoding = 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5470 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; | 
|  | 5471 |  | 
|  | 5472 | if (num_attributes > 0) | 
|  | 5473 | { | 
|  | 5474 | uint32_t i; | 
|  | 5475 | for (i=0; i<num_attributes; ++i) | 
|  | 5476 | { | 
|  | 5477 | attr = attributes.AttributeAtIndex(i); | 
|  | 5478 | DWARFFormValue form_value; | 
|  | 5479 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 5480 | { | 
|  | 5481 | switch (attr) | 
|  | 5482 | { | 
|  | 5483 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 5484 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 5485 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 5486 | case DW_AT_name: | 
| Jim Ingham | 337030f | 2011-04-15 23:41:23 +0000 | [diff] [blame] | 5487 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5488 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); | 
| Jim Ingham | 337030f | 2011-04-15 23:41:23 +0000 | [diff] [blame] | 5489 | // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't | 
|  | 5490 | // include the "&"... | 
|  | 5491 | if (tag == DW_TAG_reference_type) | 
|  | 5492 | { | 
|  | 5493 | if (strchr (type_name_cstr, '&') == NULL) | 
|  | 5494 | type_name_cstr = NULL; | 
|  | 5495 | } | 
|  | 5496 | if (type_name_cstr) | 
|  | 5497 | type_name_const_str.SetCString(type_name_cstr); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5498 | break; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 5499 | case DW_AT_byte_size:   byte_size = form_value.Unsigned(); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5500 | case DW_AT_encoding:    encoding = form_value.Unsigned(); break; | 
|  | 5501 | case DW_AT_type:        encoding_uid = form_value.Reference(dwarf_cu); break; | 
|  | 5502 | default: | 
|  | 5503 | case DW_AT_sibling: | 
|  | 5504 | break; | 
|  | 5505 | } | 
|  | 5506 | } | 
|  | 5507 | } | 
|  | 5508 | } | 
|  | 5509 |  | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5510 | 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] | 5511 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5512 | switch (tag) | 
|  | 5513 | { | 
|  | 5514 | default: | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5515 | break; | 
|  | 5516 |  | 
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5517 | case DW_TAG_unspecified_type: | 
|  | 5518 | if (strcmp(type_name_cstr, "nullptr_t") == 0) | 
|  | 5519 | { | 
|  | 5520 | resolve_state = Type::eResolveStateFull; | 
|  | 5521 | clang_type = ast.getASTContext()->NullPtrTy.getAsOpaquePtr(); | 
|  | 5522 | break; | 
|  | 5523 | } | 
|  | 5524 | // Fall through to base type below in case we can handle the type there... | 
|  | 5525 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5526 | case DW_TAG_base_type: | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5527 | resolve_state = Type::eResolveStateFull; | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5528 | clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr, | 
|  | 5529 | encoding, | 
|  | 5530 | byte_size * 8); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5531 | break; | 
|  | 5532 |  | 
| Sean Callanan | ce8af86 | 2012-05-21 23:31:51 +0000 | [diff] [blame] | 5533 | case DW_TAG_pointer_type:           encoding_data_type = Type::eEncodingIsPointerUID;           break; | 
|  | 5534 | case DW_TAG_reference_type:         encoding_data_type = Type::eEncodingIsLValueReferenceUID;   break; | 
|  | 5535 | case DW_TAG_rvalue_reference_type:  encoding_data_type = Type::eEncodingIsRValueReferenceUID;   break; | 
|  | 5536 | case DW_TAG_typedef:                encoding_data_type = Type::eEncodingIsTypedefUID;           break; | 
|  | 5537 | case DW_TAG_const_type:             encoding_data_type = Type::eEncodingIsConstUID;             break; | 
|  | 5538 | case DW_TAG_restrict_type:          encoding_data_type = Type::eEncodingIsRestrictUID;          break; | 
|  | 5539 | case DW_TAG_volatile_type:          encoding_data_type = Type::eEncodingIsVolatileUID;          break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5540 | } | 
|  | 5541 |  | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5542 | 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] | 5543 | { | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5544 | bool translation_unit_is_objc = (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus); | 
|  | 5545 |  | 
|  | 5546 | if (translation_unit_is_objc) | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 5547 | { | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5548 | if (type_name_cstr != NULL) | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5549 | { | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5550 | static ConstString g_objc_type_name_id("id"); | 
|  | 5551 | static ConstString g_objc_type_name_Class("Class"); | 
|  | 5552 | static ConstString g_objc_type_name_selector("SEL"); | 
|  | 5553 |  | 
|  | 5554 | if (type_name_const_str == g_objc_type_name_id) | 
|  | 5555 | { | 
|  | 5556 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5557 | 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] | 5558 | die->GetOffset(), | 
|  | 5559 | DW_TAG_value_to_name(die->Tag()), | 
|  | 5560 | die->GetName(this, dwarf_cu)); | 
|  | 5561 | clang_type = ast.GetBuiltInType_objc_id(); | 
|  | 5562 | encoding_data_type = Type::eEncodingIsUID; | 
|  | 5563 | encoding_uid = LLDB_INVALID_UID; | 
|  | 5564 | resolve_state = Type::eResolveStateFull; | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5565 |  | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5566 | } | 
|  | 5567 | else if (type_name_const_str == g_objc_type_name_Class) | 
|  | 5568 | { | 
|  | 5569 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5570 | 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] | 5571 | die->GetOffset(), | 
|  | 5572 | DW_TAG_value_to_name(die->Tag()), | 
|  | 5573 | die->GetName(this, dwarf_cu)); | 
|  | 5574 | clang_type = ast.GetBuiltInType_objc_Class(); | 
|  | 5575 | encoding_data_type = Type::eEncodingIsUID; | 
|  | 5576 | encoding_uid = LLDB_INVALID_UID; | 
|  | 5577 | resolve_state = Type::eResolveStateFull; | 
|  | 5578 | } | 
|  | 5579 | else if (type_name_const_str == g_objc_type_name_selector) | 
|  | 5580 | { | 
|  | 5581 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5582 | 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] | 5583 | die->GetOffset(), | 
|  | 5584 | DW_TAG_value_to_name(die->Tag()), | 
|  | 5585 | die->GetName(this, dwarf_cu)); | 
|  | 5586 | clang_type = ast.GetBuiltInType_objc_selector(); | 
|  | 5587 | encoding_data_type = Type::eEncodingIsUID; | 
|  | 5588 | encoding_uid = LLDB_INVALID_UID; | 
|  | 5589 | resolve_state = Type::eResolveStateFull; | 
|  | 5590 | } | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5591 | } | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5592 | else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid != LLDB_INVALID_UID) | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5593 | { | 
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5594 | // Clang sometimes erroneously emits id as objc_object*.  In that case we fix up the type to "id". | 
|  | 5595 |  | 
|  | 5596 | DWARFDebugInfoEntry* encoding_die = dwarf_cu->GetDIEPtr(encoding_uid); | 
|  | 5597 |  | 
|  | 5598 | if (encoding_die && encoding_die->Tag() == DW_TAG_structure_type) | 
|  | 5599 | { | 
|  | 5600 | if (const char *struct_name = encoding_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL)) | 
|  | 5601 | { | 
|  | 5602 | if (!strcmp(struct_name, "objc_object")) | 
|  | 5603 | { | 
|  | 5604 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5605 | 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] | 5606 | die->GetOffset(), | 
|  | 5607 | DW_TAG_value_to_name(die->Tag()), | 
|  | 5608 | die->GetName(this, dwarf_cu)); | 
|  | 5609 | clang_type = ast.GetBuiltInType_objc_id(); | 
|  | 5610 | encoding_data_type = Type::eEncodingIsUID; | 
|  | 5611 | encoding_uid = LLDB_INVALID_UID; | 
|  | 5612 | resolve_state = Type::eResolveStateFull; | 
|  | 5613 | } | 
|  | 5614 | } | 
|  | 5615 | } | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5616 | } | 
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 5617 | } | 
|  | 5618 | } | 
|  | 5619 |  | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5620 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5621 | this, | 
|  | 5622 | type_name_const_str, | 
|  | 5623 | byte_size, | 
|  | 5624 | NULL, | 
|  | 5625 | encoding_uid, | 
|  | 5626 | encoding_data_type, | 
|  | 5627 | &decl, | 
|  | 5628 | clang_type, | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5629 | resolve_state)); | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5630 |  | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5631 | m_die_to_type[die] = type_sp.get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5632 |  | 
|  | 5633 | //                  Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false); | 
|  | 5634 | //                  if (encoding_type != NULL) | 
|  | 5635 | //                  { | 
|  | 5636 | //                      if (encoding_type != DIE_IS_BEING_PARSED) | 
|  | 5637 | //                          type_sp->SetEncodingType(encoding_type); | 
|  | 5638 | //                      else | 
|  | 5639 | //                          m_indirect_fixups.push_back(type_sp.get()); | 
|  | 5640 | //                  } | 
|  | 5641 | } | 
|  | 5642 | break; | 
|  | 5643 |  | 
|  | 5644 | case DW_TAG_structure_type: | 
|  | 5645 | case DW_TAG_union_type: | 
|  | 5646 | case DW_TAG_class_type: | 
|  | 5647 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5648 | // 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] | 5649 | m_die_to_type[die] = DIE_IS_BEING_PARSED; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 5650 | bool byte_size_valid = false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5651 |  | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5652 | LanguageType class_language = eLanguageTypeUnknown; | 
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 5653 | bool is_complete_objc_class = false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5654 | //bool struct_is_class = false; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5655 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5656 | if (num_attributes > 0) | 
|  | 5657 | { | 
|  | 5658 | uint32_t i; | 
|  | 5659 | for (i=0; i<num_attributes; ++i) | 
|  | 5660 | { | 
|  | 5661 | attr = attributes.AttributeAtIndex(i); | 
|  | 5662 | DWARFFormValue form_value; | 
|  | 5663 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 5664 | { | 
|  | 5665 | switch (attr) | 
|  | 5666 | { | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5667 | case DW_AT_decl_file: | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5668 | if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid()) | 
|  | 5669 | { | 
|  | 5670 | // llvm-gcc outputs invalid DW_AT_decl_file attributes that always | 
|  | 5671 | // point to the compile unit file, so we clear this invalid value | 
|  | 5672 | // so that we can still unique types efficiently. | 
|  | 5673 | decl.SetFile(FileSpec ("<invalid>", false)); | 
|  | 5674 | } | 
|  | 5675 | else | 
|  | 5676 | decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5677 | break; | 
|  | 5678 |  | 
|  | 5679 | case DW_AT_decl_line: | 
|  | 5680 | decl.SetLine(form_value.Unsigned()); | 
|  | 5681 | break; | 
|  | 5682 |  | 
|  | 5683 | case DW_AT_decl_column: | 
|  | 5684 | decl.SetColumn(form_value.Unsigned()); | 
|  | 5685 | break; | 
|  | 5686 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5687 | case DW_AT_name: | 
|  | 5688 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5689 | type_name_const_str.SetCString(type_name_cstr); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5690 | break; | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5691 |  | 
|  | 5692 | case DW_AT_byte_size: | 
|  | 5693 | byte_size = form_value.Unsigned(); | 
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 5694 | byte_size_valid = true; | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5695 | break; | 
|  | 5696 |  | 
|  | 5697 | case DW_AT_accessibility: | 
|  | 5698 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); | 
|  | 5699 | break; | 
|  | 5700 |  | 
|  | 5701 | case DW_AT_declaration: | 
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 5702 | is_forward_declaration = form_value.Unsigned() != 0; | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5703 | break; | 
|  | 5704 |  | 
|  | 5705 | case DW_AT_APPLE_runtime_class: | 
|  | 5706 | class_language = (LanguageType)form_value.Signed(); | 
|  | 5707 | break; | 
|  | 5708 |  | 
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 5709 | case DW_AT_APPLE_objc_complete_type: | 
|  | 5710 | is_complete_objc_class = form_value.Signed(); | 
|  | 5711 | break; | 
|  | 5712 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5713 | case DW_AT_allocated: | 
|  | 5714 | case DW_AT_associated: | 
|  | 5715 | case DW_AT_data_location: | 
|  | 5716 | case DW_AT_description: | 
|  | 5717 | case DW_AT_start_scope: | 
|  | 5718 | case DW_AT_visibility: | 
|  | 5719 | default: | 
|  | 5720 | case DW_AT_sibling: | 
|  | 5721 | break; | 
|  | 5722 | } | 
|  | 5723 | } | 
|  | 5724 | } | 
|  | 5725 | } | 
|  | 5726 |  | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5727 | UniqueDWARFASTType unique_ast_entry; | 
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5728 |  | 
| Greg Clayton | 123edca | 2012-03-02 00:07:15 +0000 | [diff] [blame] | 5729 | // Only try and unique the type if it has a name. | 
|  | 5730 | if (type_name_const_str && | 
|  | 5731 | GetUniqueDWARFASTTypeMap().Find (type_name_const_str, | 
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5732 | this, | 
|  | 5733 | dwarf_cu, | 
|  | 5734 | die, | 
|  | 5735 | decl, | 
|  | 5736 | byte_size_valid ? byte_size : -1, | 
|  | 5737 | unique_ast_entry)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5738 | { | 
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5739 | // We have already parsed this type or from another | 
|  | 5740 | // compile unit. GCC loves to use the "one definition | 
|  | 5741 | // rule" which can result in multiple definitions | 
|  | 5742 | // of the same class over and over in each compile | 
|  | 5743 | // unit. | 
|  | 5744 | type_sp = unique_ast_entry.m_type_sp; | 
|  | 5745 | if (type_sp) | 
| Greg Clayton | c615ce4 | 2010-11-09 04:42:43 +0000 | [diff] [blame] | 5746 | { | 
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5747 | m_die_to_type[die] = type_sp.get(); | 
|  | 5748 | return type_sp; | 
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5749 | } | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5750 | } | 
|  | 5751 |  | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5752 | 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] | 5753 |  | 
|  | 5754 | int tag_decl_kind = -1; | 
|  | 5755 | AccessType default_accessibility = eAccessNone; | 
|  | 5756 | if (tag == DW_TAG_structure_type) | 
|  | 5757 | { | 
|  | 5758 | tag_decl_kind = clang::TTK_Struct; | 
|  | 5759 | default_accessibility = eAccessPublic; | 
|  | 5760 | } | 
|  | 5761 | else if (tag == DW_TAG_union_type) | 
|  | 5762 | { | 
|  | 5763 | tag_decl_kind = clang::TTK_Union; | 
|  | 5764 | default_accessibility = eAccessPublic; | 
|  | 5765 | } | 
|  | 5766 | else if (tag == DW_TAG_class_type) | 
|  | 5767 | { | 
|  | 5768 | tag_decl_kind = clang::TTK_Class; | 
|  | 5769 | default_accessibility = eAccessPrivate; | 
|  | 5770 | } | 
| Greg Clayton | 3a5f29a | 2011-11-30 02:48:28 +0000 | [diff] [blame] | 5771 |  | 
|  | 5772 | if (byte_size_valid && byte_size == 0 && type_name_cstr && | 
|  | 5773 | die->HasChildren() == false && | 
|  | 5774 | sc.comp_unit->GetLanguage() == eLanguageTypeObjC) | 
|  | 5775 | { | 
|  | 5776 | // Work around an issue with clang at the moment where | 
|  | 5777 | // forward declarations for objective C classes are emitted | 
|  | 5778 | // as: | 
|  | 5779 | //  DW_TAG_structure_type [2] | 
|  | 5780 | //  DW_AT_name( "ForwardObjcClass" ) | 
|  | 5781 | //  DW_AT_byte_size( 0x00 ) | 
|  | 5782 | //  DW_AT_decl_file( "..." ) | 
|  | 5783 | //  DW_AT_decl_line( 1 ) | 
|  | 5784 | // | 
|  | 5785 | // Note that there is no DW_AT_declaration and there are | 
|  | 5786 | // no children, and the byte size is zero. | 
|  | 5787 | is_forward_declaration = true; | 
|  | 5788 | } | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5789 |  | 
| Sean Callanan | 7457f8d | 2012-04-25 01:03:57 +0000 | [diff] [blame] | 5790 | if (class_language == eLanguageTypeObjC || | 
|  | 5791 | class_language == eLanguageTypeObjC_plus_plus) | 
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 5792 | { | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5793 | 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] | 5794 | { | 
|  | 5795 | // We have a valid eSymbolTypeObjCClass class symbol whose | 
|  | 5796 | // name matches the current objective C class that we | 
|  | 5797 | // are trying to find and this DIE isn't the complete | 
|  | 5798 | // definition (we checked is_complete_objc_class above and | 
|  | 5799 | // know it is false), so the real definition is in here somewhere | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5800 | type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true); | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5801 |  | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 5802 | if (!type_sp && GetDebugMapSymfile ()) | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5803 | { | 
|  | 5804 | // We weren't able to find a full declaration in | 
|  | 5805 | // this DWARF, see if we have a declaration anywhere | 
|  | 5806 | // else... | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5807 | 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] | 5808 | } | 
|  | 5809 |  | 
|  | 5810 | if (type_sp) | 
|  | 5811 | { | 
|  | 5812 | if (log) | 
|  | 5813 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5814 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5815 | "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] | 5816 | this, | 
|  | 5817 | die->GetOffset(), | 
|  | 5818 | DW_TAG_value_to_name(tag), | 
|  | 5819 | type_name_cstr, | 
|  | 5820 | type_sp->GetID()); | 
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5821 | } | 
|  | 5822 |  | 
|  | 5823 | // We found a real definition for this type elsewhere | 
|  | 5824 | // so lets use it and cache the fact that we found | 
|  | 5825 | // a complete type for this die | 
|  | 5826 | m_die_to_type[die] = type_sp.get(); | 
|  | 5827 | return type_sp; | 
|  | 5828 | } | 
|  | 5829 | } | 
|  | 5830 | } | 
|  | 5831 |  | 
|  | 5832 |  | 
|  | 5833 | if (is_forward_declaration) | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5834 | { | 
|  | 5835 | // We have a forward declaration to a type and we need | 
|  | 5836 | // to try and find a full declaration. We look in the | 
|  | 5837 | // current type index just in case we have a forward | 
|  | 5838 | // declaration followed by an actual declarations in the | 
|  | 5839 | // DWARF. If this fails, we need to look elsewhere... | 
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 5840 | if (log) | 
|  | 5841 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5842 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5843 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type", | 
|  | 5844 | this, | 
|  | 5845 | die->GetOffset(), | 
|  | 5846 | DW_TAG_value_to_name(tag), | 
|  | 5847 | type_name_cstr); | 
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 5848 | } | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5849 |  | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5850 | DWARFDeclContext die_decl_ctx; | 
|  | 5851 | die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx); | 
|  | 5852 |  | 
|  | 5853 | //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str); | 
|  | 5854 | type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5855 |  | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 5856 | if (!type_sp && GetDebugMapSymfile ()) | 
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5857 | { | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5858 | // We weren't able to find a full declaration in | 
|  | 5859 | // this DWARF, see if we have a declaration anywhere | 
|  | 5860 | // else... | 
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5861 | type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); | 
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5862 | } | 
|  | 5863 |  | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5864 | if (type_sp) | 
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5865 | { | 
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 5866 | if (log) | 
|  | 5867 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5868 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5869 | "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] | 5870 | this, | 
|  | 5871 | die->GetOffset(), | 
|  | 5872 | DW_TAG_value_to_name(tag), | 
|  | 5873 | type_name_cstr, | 
|  | 5874 | type_sp->GetID()); | 
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 5875 | } | 
|  | 5876 |  | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5877 | // We found a real definition for this type elsewhere | 
|  | 5878 | // so lets use it and cache the fact that we found | 
|  | 5879 | // a complete type for this die | 
|  | 5880 | m_die_to_type[die] = type_sp.get(); | 
|  | 5881 | return type_sp; | 
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5882 | } | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5883 | } | 
|  | 5884 | assert (tag_decl_kind != -1); | 
|  | 5885 | bool clang_type_was_created = false; | 
|  | 5886 | clang_type = m_forward_decl_die_to_clang_type.lookup (die); | 
|  | 5887 | if (clang_type == NULL) | 
|  | 5888 | { | 
| Sean Callanan | 4d04c6a | 2012-02-09 22:54:11 +0000 | [diff] [blame] | 5889 | const DWARFDebugInfoEntry *decl_ctx_die; | 
|  | 5890 |  | 
|  | 5891 | clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die); | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 5892 | if (accessibility == eAccessNone && decl_ctx) | 
|  | 5893 | { | 
|  | 5894 | // Check the decl context that contains this class/struct/union. | 
|  | 5895 | // If it is a class we must give it an accessability. | 
|  | 5896 | const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind(); | 
|  | 5897 | if (DeclKindIsCXXClass (containing_decl_kind)) | 
|  | 5898 | accessibility = default_accessibility; | 
|  | 5899 | } | 
|  | 5900 |  | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 5901 | ClangASTMetadata metadata; | 
|  | 5902 | metadata.SetUserID(MakeUserID(die->GetOffset())); | 
|  | 5903 | metadata.SetIsDynamicCXXType(ClassOrStructIsVirtual (dwarf_cu, die)); | 
|  | 5904 |  | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5905 | if (type_name_cstr && strchr (type_name_cstr, '<')) | 
|  | 5906 | { | 
|  | 5907 | ClangASTContext::TemplateParameterInfos template_param_infos; | 
|  | 5908 | if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos)) | 
|  | 5909 | { | 
|  | 5910 | clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx, | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 5911 | accessibility, | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5912 | type_name_cstr, | 
|  | 5913 | tag_decl_kind, | 
|  | 5914 | template_param_infos); | 
|  | 5915 |  | 
|  | 5916 | clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx, | 
|  | 5917 | class_template_decl, | 
|  | 5918 | tag_decl_kind, | 
|  | 5919 | template_param_infos); | 
|  | 5920 | clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl); | 
|  | 5921 | clang_type_was_created = true; | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 5922 |  | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 5923 | GetClangASTContext().SetMetadata (class_template_decl, metadata); | 
|  | 5924 | GetClangASTContext().SetMetadata (class_specialization_decl, metadata); | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5925 | } | 
|  | 5926 | } | 
|  | 5927 |  | 
|  | 5928 | if (!clang_type_was_created) | 
|  | 5929 | { | 
|  | 5930 | clang_type_was_created = true; | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 5931 | clang_type = ast.CreateRecordType (decl_ctx, | 
|  | 5932 | accessibility, | 
|  | 5933 | type_name_cstr, | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5934 | tag_decl_kind, | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 5935 | class_language, | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 5936 | &metadata); | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5937 | } | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5938 | } | 
|  | 5939 |  | 
|  | 5940 | // Store a forward declaration to this class type in case any | 
|  | 5941 | // parameters in any class methods need it for the clang | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 5942 | // types for function prototypes. | 
|  | 5943 | LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die); | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5944 | type_sp.reset (new Type (MakeUserID(die->GetOffset()), | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5945 | this, | 
|  | 5946 | type_name_const_str, | 
|  | 5947 | byte_size, | 
|  | 5948 | NULL, | 
|  | 5949 | LLDB_INVALID_UID, | 
|  | 5950 | Type::eEncodingIsUID, | 
|  | 5951 | &decl, | 
|  | 5952 | clang_type, | 
|  | 5953 | Type::eResolveStateForward)); | 
| Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 5954 |  | 
|  | 5955 | type_sp->SetIsCompleteObjCClass(is_complete_objc_class); | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5956 |  | 
|  | 5957 |  | 
|  | 5958 | // Add our type to the unique type map so we don't | 
|  | 5959 | // end up creating many copies of the same type over | 
|  | 5960 | // and over in the ASTContext for our module | 
|  | 5961 | unique_ast_entry.m_type_sp = type_sp; | 
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 5962 | unique_ast_entry.m_symfile = this; | 
|  | 5963 | unique_ast_entry.m_cu = dwarf_cu; | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5964 | unique_ast_entry.m_die = die; | 
|  | 5965 | unique_ast_entry.m_declaration = decl; | 
| Sean Callanan | 5970059 | 2012-02-13 22:30:16 +0000 | [diff] [blame] | 5966 | unique_ast_entry.m_byte_size = byte_size; | 
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 5967 | GetUniqueDWARFASTTypeMap().Insert (type_name_const_str, | 
|  | 5968 | unique_ast_entry); | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5969 |  | 
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 5970 | if (!is_forward_declaration) | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 5971 | { | 
|  | 5972 | // Always start the definition for a class type so that | 
|  | 5973 | // if the class has child classes or types that require | 
|  | 5974 | // the class to be created for use as their decl contexts | 
|  | 5975 | // the class will be ready to accept these child definitions. | 
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 5976 | if (die->HasChildren() == false) | 
|  | 5977 | { | 
|  | 5978 | // No children for this struct/union/class, lets finish it | 
|  | 5979 | ast.StartTagDeclarationDefinition (clang_type); | 
|  | 5980 | ast.CompleteTagDeclarationDefinition (clang_type); | 
| Sean Callanan | 433cd22 | 2012-10-19 01:37:25 +0000 | [diff] [blame] | 5981 |  | 
|  | 5982 | if (tag == DW_TAG_structure_type) // this only applies in C | 
|  | 5983 | { | 
|  | 5984 | clang::QualType qual_type = clang::QualType::getFromOpaquePtr (clang_type); | 
|  | 5985 | const clang::RecordType *record_type = qual_type->getAs<clang::RecordType> (); | 
|  | 5986 |  | 
|  | 5987 | if (record_type) | 
|  | 5988 | { | 
|  | 5989 | clang::RecordDecl *record_decl = record_type->getDecl(); | 
|  | 5990 |  | 
|  | 5991 | if (record_decl) | 
|  | 5992 | { | 
|  | 5993 | LayoutInfo layout_info; | 
|  | 5994 |  | 
|  | 5995 | layout_info.alignment = 0; | 
|  | 5996 | layout_info.bit_size = 0; | 
|  | 5997 |  | 
|  | 5998 | m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info)); | 
|  | 5999 | } | 
|  | 6000 | } | 
|  | 6001 | } | 
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6002 | } | 
|  | 6003 | else if (clang_type_was_created) | 
|  | 6004 | { | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 6005 | // Start the definition if the class is not objective C since | 
|  | 6006 | // the underlying decls respond to isCompleteDefinition(). Objective | 
|  | 6007 | // C decls dont' respond to isCompleteDefinition() so we can't | 
|  | 6008 | // start the declaration definition right away. For C++ classs/union/structs | 
|  | 6009 | // we want to start the definition in case the class is needed as the | 
|  | 6010 | // declaration context for a contained class or type without the need | 
|  | 6011 | // to complete that type.. | 
|  | 6012 |  | 
| Sean Callanan | 7457f8d | 2012-04-25 01:03:57 +0000 | [diff] [blame] | 6013 | if (class_language != eLanguageTypeObjC && | 
|  | 6014 | class_language != eLanguageTypeObjC_plus_plus) | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 6015 | ast.StartTagDeclarationDefinition (clang_type); | 
|  | 6016 |  | 
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6017 | // Leave this as a forward declaration until we need | 
|  | 6018 | // to know the details of the type. lldb_private::Type | 
|  | 6019 | // will automatically call the SymbolFile virtual function | 
|  | 6020 | // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)" | 
|  | 6021 | // When the definition needs to be defined. | 
|  | 6022 | m_forward_decl_die_to_clang_type[die] = clang_type; | 
|  | 6023 | m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die; | 
|  | 6024 | ClangASTContext::SetHasExternalStorage (clang_type, true); | 
|  | 6025 | } | 
| Greg Clayton | c615ce4 | 2010-11-09 04:42:43 +0000 | [diff] [blame] | 6026 | } | 
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 6027 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6028 | } | 
|  | 6029 | break; | 
|  | 6030 |  | 
|  | 6031 | case DW_TAG_enumeration_type: | 
|  | 6032 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6033 | // 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] | 6034 | m_die_to_type[die] = DIE_IS_BEING_PARSED; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6035 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6036 | lldb::user_id_t encoding_uid = DW_INVALID_OFFSET; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6037 |  | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6038 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6039 | if (num_attributes > 0) | 
|  | 6040 | { | 
|  | 6041 | uint32_t i; | 
|  | 6042 |  | 
|  | 6043 | for (i=0; i<num_attributes; ++i) | 
|  | 6044 | { | 
|  | 6045 | attr = attributes.AttributeAtIndex(i); | 
|  | 6046 | DWARFFormValue form_value; | 
|  | 6047 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 6048 | { | 
|  | 6049 | switch (attr) | 
|  | 6050 | { | 
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 6051 | case DW_AT_decl_file:       decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 6052 | case DW_AT_decl_line:       decl.SetLine(form_value.Unsigned()); break; | 
|  | 6053 | case DW_AT_decl_column:     decl.SetColumn(form_value.Unsigned()); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6054 | case DW_AT_name: | 
|  | 6055 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6056 | type_name_const_str.SetCString(type_name_cstr); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6057 | break; | 
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 6058 | case DW_AT_type:            encoding_uid = form_value.Reference(dwarf_cu); break; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6059 | case DW_AT_byte_size:       byte_size = form_value.Unsigned(); break; | 
|  | 6060 | case DW_AT_accessibility:   break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; | 
|  | 6061 | case DW_AT_declaration:     break; //is_forward_declaration = form_value.Unsigned() != 0; break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6062 | case DW_AT_allocated: | 
|  | 6063 | case DW_AT_associated: | 
|  | 6064 | case DW_AT_bit_stride: | 
|  | 6065 | case DW_AT_byte_stride: | 
|  | 6066 | case DW_AT_data_location: | 
|  | 6067 | case DW_AT_description: | 
|  | 6068 | case DW_AT_start_scope: | 
|  | 6069 | case DW_AT_visibility: | 
|  | 6070 | case DW_AT_specification: | 
|  | 6071 | case DW_AT_abstract_origin: | 
|  | 6072 | case DW_AT_sibling: | 
|  | 6073 | break; | 
|  | 6074 | } | 
|  | 6075 | } | 
|  | 6076 | } | 
|  | 6077 |  | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6078 | 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] | 6079 |  | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6080 | clang_type_t enumerator_clang_type = NULL; | 
|  | 6081 | clang_type = m_forward_decl_die_to_clang_type.lookup (die); | 
|  | 6082 | if (clang_type == NULL) | 
|  | 6083 | { | 
| Greg Clayton | 5d14fc0 | 2013-03-06 06:23:54 +0000 | [diff] [blame] | 6084 | if (encoding_uid != DW_INVALID_OFFSET) | 
|  | 6085 | { | 
|  | 6086 | Type *enumerator_type = ResolveTypeUID(encoding_uid); | 
|  | 6087 | if (enumerator_type) | 
|  | 6088 | enumerator_clang_type = enumerator_type->GetClangFullType(); | 
|  | 6089 | } | 
|  | 6090 |  | 
|  | 6091 | if (enumerator_clang_type == NULL) | 
|  | 6092 | enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL, | 
|  | 6093 | DW_ATE_signed, | 
|  | 6094 | byte_size * 8); | 
|  | 6095 |  | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 6096 | clang_type = ast.CreateEnumerationType (type_name_cstr, | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6097 | GetClangDeclContextContainingDIE (dwarf_cu, die, NULL), | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 6098 | decl, | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6099 | enumerator_clang_type); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6100 | } | 
|  | 6101 | else | 
|  | 6102 | { | 
|  | 6103 | enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type); | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6104 | } | 
|  | 6105 |  | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6106 | LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die); | 
|  | 6107 |  | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6108 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6109 | this, | 
|  | 6110 | type_name_const_str, | 
|  | 6111 | byte_size, | 
|  | 6112 | NULL, | 
|  | 6113 | encoding_uid, | 
|  | 6114 | Type::eEncodingIsUID, | 
|  | 6115 | &decl, | 
|  | 6116 | clang_type, | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6117 | Type::eResolveStateForward)); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6118 |  | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 6119 | ast.StartTagDeclarationDefinition (clang_type); | 
|  | 6120 | if (die->HasChildren()) | 
|  | 6121 | { | 
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 6122 | SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); | 
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 6123 | bool is_signed = false; | 
| Greg Clayton | 5d14fc0 | 2013-03-06 06:23:54 +0000 | [diff] [blame] | 6124 | ast.IsIntegerType(enumerator_clang_type, is_signed); | 
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 6125 | 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] | 6126 | } | 
|  | 6127 | ast.CompleteTagDeclarationDefinition (clang_type); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6128 | } | 
|  | 6129 | } | 
|  | 6130 | break; | 
|  | 6131 |  | 
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 6132 | case DW_TAG_inlined_subroutine: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6133 | case DW_TAG_subprogram: | 
|  | 6134 | case DW_TAG_subroutine_type: | 
|  | 6135 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6136 | // 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] | 6137 | m_die_to_type[die] = DIE_IS_BEING_PARSED; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6138 |  | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6139 | //const char *mangled = NULL; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6140 | dw_offset_t type_die_offset = DW_INVALID_OFFSET; | 
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 6141 | bool is_variadic = false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6142 | bool is_inline = false; | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6143 | bool is_static = false; | 
|  | 6144 | bool is_virtual = false; | 
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6145 | bool is_explicit = false; | 
| Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 6146 | bool is_artificial = false; | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6147 | dw_offset_t specification_die_offset = DW_INVALID_OFFSET; | 
|  | 6148 | dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET; | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6149 | dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET; | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6150 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6151 | unsigned type_quals = 0; | 
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 6152 | clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6153 |  | 
|  | 6154 |  | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6155 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6156 | if (num_attributes > 0) | 
|  | 6157 | { | 
|  | 6158 | uint32_t i; | 
|  | 6159 | for (i=0; i<num_attributes; ++i) | 
|  | 6160 | { | 
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 6161 | attr = attributes.AttributeAtIndex(i); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6162 | DWARFFormValue form_value; | 
|  | 6163 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 6164 | { | 
|  | 6165 | switch (attr) | 
|  | 6166 | { | 
|  | 6167 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 6168 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 6169 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 6170 | case DW_AT_name: | 
|  | 6171 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6172 | type_name_const_str.SetCString(type_name_cstr); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6173 | break; | 
|  | 6174 |  | 
| Greg Clayton | 7141554 | 2012-12-08 00:24:40 +0000 | [diff] [blame] | 6175 | case DW_AT_linkage_name: | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6176 | 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] | 6177 | 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] | 6178 | case DW_AT_accessibility:       accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6179 | case DW_AT_declaration:         break; // is_forward_declaration = form_value.Unsigned() != 0; break; | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6180 | case DW_AT_inline:              is_inline = form_value.Unsigned() != 0; break; | 
|  | 6181 | case DW_AT_virtuality:          is_virtual = form_value.Unsigned() != 0;  break; | 
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6182 | case DW_AT_explicit:            is_explicit = form_value.Unsigned() != 0;  break; | 
| Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 6183 | case DW_AT_artificial:          is_artificial = form_value.Unsigned() != 0;  break; | 
|  | 6184 |  | 
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6185 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6186 | case DW_AT_external: | 
|  | 6187 | if (form_value.Unsigned()) | 
|  | 6188 | { | 
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 6189 | if (storage == clang::SC_None) | 
|  | 6190 | storage = clang::SC_Extern; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6191 | else | 
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 6192 | storage = clang::SC_PrivateExtern; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6193 | } | 
|  | 6194 | break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6195 |  | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6196 | case DW_AT_specification: | 
|  | 6197 | specification_die_offset = form_value.Reference(dwarf_cu); | 
|  | 6198 | break; | 
|  | 6199 |  | 
|  | 6200 | case DW_AT_abstract_origin: | 
|  | 6201 | abstract_origin_die_offset = form_value.Reference(dwarf_cu); | 
|  | 6202 | break; | 
|  | 6203 |  | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6204 | case DW_AT_object_pointer: | 
|  | 6205 | object_pointer_die_offset = form_value.Reference(dwarf_cu); | 
|  | 6206 | break; | 
|  | 6207 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6208 | case DW_AT_allocated: | 
|  | 6209 | case DW_AT_associated: | 
|  | 6210 | case DW_AT_address_class: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6211 | case DW_AT_calling_convention: | 
|  | 6212 | case DW_AT_data_location: | 
|  | 6213 | case DW_AT_elemental: | 
|  | 6214 | case DW_AT_entry_pc: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6215 | case DW_AT_frame_base: | 
|  | 6216 | case DW_AT_high_pc: | 
|  | 6217 | case DW_AT_low_pc: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6218 | case DW_AT_prototyped: | 
|  | 6219 | case DW_AT_pure: | 
|  | 6220 | case DW_AT_ranges: | 
|  | 6221 | case DW_AT_recursive: | 
|  | 6222 | case DW_AT_return_addr: | 
|  | 6223 | case DW_AT_segment: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6224 | case DW_AT_start_scope: | 
|  | 6225 | case DW_AT_static_link: | 
|  | 6226 | case DW_AT_trampoline: | 
|  | 6227 | case DW_AT_visibility: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6228 | case DW_AT_vtable_elem_location: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6229 | case DW_AT_description: | 
|  | 6230 | case DW_AT_sibling: | 
|  | 6231 | break; | 
|  | 6232 | } | 
|  | 6233 | } | 
|  | 6234 | } | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6235 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6236 |  | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6237 | std::string object_pointer_name; | 
|  | 6238 | if (object_pointer_die_offset != DW_INVALID_OFFSET) | 
|  | 6239 | { | 
|  | 6240 | // Get the name from the object pointer die | 
|  | 6241 | StreamString s; | 
|  | 6242 | if (DWARFDebugInfoEntry::GetName (this, dwarf_cu, object_pointer_die_offset, s)) | 
|  | 6243 | { | 
|  | 6244 | object_pointer_name.assign(s.GetData()); | 
|  | 6245 | } | 
|  | 6246 | } | 
|  | 6247 |  | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6248 | 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] | 6249 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6250 | clang_type_t return_clang_type = NULL; | 
|  | 6251 | Type *func_type = NULL; | 
|  | 6252 |  | 
|  | 6253 | if (type_die_offset != DW_INVALID_OFFSET) | 
|  | 6254 | func_type = ResolveTypeUID(type_die_offset); | 
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6255 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6256 | if (func_type) | 
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 6257 | return_clang_type = func_type->GetClangForwardType(); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6258 | else | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6259 | return_clang_type = ast.GetBuiltInType_void(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6260 |  | 
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6261 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6262 | std::vector<clang_type_t> function_param_types; | 
|  | 6263 | std::vector<clang::ParmVarDecl*> function_param_decls; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6264 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6265 | // Parse the function children for the parameters | 
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 6266 |  | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6267 | const DWARFDebugInfoEntry *decl_ctx_die = NULL; | 
|  | 6268 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die); | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6269 | const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind(); | 
|  | 6270 |  | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6271 | const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind); | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6272 | // Start off static. This will be set to false in ParseChildParameters(...) | 
|  | 6273 | // if we find a "this" paramters as the first parameter | 
|  | 6274 | if (is_cxx_method) | 
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 6275 | is_static = true; | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 6276 | ClangASTContext::TemplateParameterInfos template_param_infos; | 
|  | 6277 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6278 | if (die->HasChildren()) | 
|  | 6279 | { | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6280 | bool skip_artificial = true; | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6281 | ParseChildParameters (sc, | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6282 | containing_decl_ctx, | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6283 | dwarf_cu, | 
|  | 6284 | die, | 
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 6285 | skip_artificial, | 
|  | 6286 | is_static, | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6287 | type_list, | 
|  | 6288 | function_param_types, | 
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 6289 | function_param_decls, | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 6290 | type_quals, | 
|  | 6291 | template_param_infos); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6292 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6293 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6294 | // clang_type will get the function prototype clang type after this call | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6295 | clang_type = ast.CreateFunctionType (return_clang_type, | 
| Greg Clayton | 9cb25c4 | 2012-10-30 17:02:18 +0000 | [diff] [blame] | 6296 | function_param_types.data(), | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6297 | function_param_types.size(), | 
|  | 6298 | is_variadic, | 
|  | 6299 | type_quals); | 
|  | 6300 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6301 | if (type_name_cstr) | 
|  | 6302 | { | 
|  | 6303 | bool type_handled = false; | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6304 | if (tag == DW_TAG_subprogram) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6305 | { | 
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 6306 | ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true); | 
|  | 6307 | if (objc_method.IsValid(true)) | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6308 | { | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6309 | SymbolContext empty_sc; | 
|  | 6310 | clang_type_t class_opaque_type = NULL; | 
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 6311 | ConstString class_name(objc_method.GetClassName()); | 
| Greg Clayton | 7c81042 | 2012-01-18 23:40:49 +0000 | [diff] [blame] | 6312 | if (class_name) | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6313 | { | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6314 | TypeList types; | 
| Greg Clayton | 278a16b | 2012-01-19 00:52:59 +0000 | [diff] [blame] | 6315 | TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false)); | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6316 |  | 
|  | 6317 | if (complete_objc_class_type_sp) | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6318 | { | 
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6319 | clang_type_t type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType(); | 
|  | 6320 | if (ClangASTContext::IsObjCClassType (type_clang_forward_type)) | 
|  | 6321 | class_opaque_type = type_clang_forward_type; | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6322 | } | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6323 | } | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6324 |  | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6325 | if (class_opaque_type) | 
|  | 6326 | { | 
|  | 6327 | // If accessibility isn't set to anything valid, assume public for | 
|  | 6328 | // now... | 
|  | 6329 | if (accessibility == eAccessNone) | 
|  | 6330 | accessibility = eAccessPublic; | 
|  | 6331 |  | 
| Sean Callanan | 464a5b5 | 2012-10-04 22:06:29 +0000 | [diff] [blame] | 6332 | clang::ObjCMethodDecl *objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type, | 
|  | 6333 | type_name_cstr, | 
|  | 6334 | clang_type, | 
| Greg Clayton | 1bbcc03 | 2013-03-08 02:42:06 +0000 | [diff] [blame] | 6335 | accessibility, | 
|  | 6336 | is_artificial); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6337 | type_handled = objc_method_decl != NULL; | 
| Sean Callanan | 464a5b5 | 2012-10-04 22:06:29 +0000 | [diff] [blame] | 6338 | if (type_handled) | 
|  | 6339 | { | 
|  | 6340 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die); | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6341 | GetClangASTContext().SetMetadataAsUserID (objc_method_decl, MakeUserID(die->GetOffset())); | 
| Sean Callanan | 464a5b5 | 2012-10-04 22:06:29 +0000 | [diff] [blame] | 6342 | } | 
| Sean Callanan | c3a1d56 | 2013-02-06 23:21:59 +0000 | [diff] [blame] | 6343 | else | 
|  | 6344 | { | 
| Jason Molenda | c1a6583 | 2013-03-07 22:44:42 +0000 | [diff] [blame] | 6345 | 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] | 6346 | die->GetOffset(), | 
|  | 6347 | tag, | 
|  | 6348 | DW_TAG_value_to_name(tag)); | 
|  | 6349 | } | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6350 | } | 
|  | 6351 | } | 
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6352 | else if (is_cxx_method) | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6353 | { | 
|  | 6354 | // Look at the parent of this DIE and see if is is | 
|  | 6355 | // a class or struct and see if this is actually a | 
|  | 6356 | // C++ method | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6357 | Type *class_type = ResolveType (dwarf_cu, decl_ctx_die); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6358 | if (class_type) | 
|  | 6359 | { | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6360 | if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset())) | 
|  | 6361 | { | 
|  | 6362 | // We uniqued the parent class of this function to another class | 
|  | 6363 | // so we now need to associate all dies under "decl_ctx_die" to | 
|  | 6364 | // DIEs in the DIE for "class_type"... | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 6365 | SymbolFileDWARF *class_symfile = NULL; | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6366 | DWARFCompileUnitSP class_type_cu_sp; | 
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 6367 | const DWARFDebugInfoEntry *class_type_die = NULL; | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6368 |  | 
|  | 6369 | SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile(); | 
|  | 6370 | if (debug_map_symfile) | 
|  | 6371 | { | 
|  | 6372 | class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID())); | 
|  | 6373 | class_type_die = class_symfile->DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp); | 
|  | 6374 | } | 
|  | 6375 | else | 
|  | 6376 | { | 
|  | 6377 | class_symfile = this; | 
|  | 6378 | class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp); | 
|  | 6379 | } | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6380 | if (class_type_die) | 
|  | 6381 | { | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6382 | llvm::SmallVector<const DWARFDebugInfoEntry *, 0> failures; | 
|  | 6383 |  | 
|  | 6384 | CopyUniqueClassMethodTypes (class_symfile, | 
|  | 6385 | class_type, | 
|  | 6386 | class_type_cu_sp.get(), | 
|  | 6387 | class_type_die, | 
|  | 6388 | dwarf_cu, | 
|  | 6389 | decl_ctx_die, | 
|  | 6390 | failures); | 
|  | 6391 |  | 
|  | 6392 | // FIXME do something with these failures that's smarter than | 
|  | 6393 | // just dropping them on the ground.  Unfortunately classes don't | 
|  | 6394 | // like having stuff added to them after their definitions are | 
|  | 6395 | // complete... | 
|  | 6396 |  | 
|  | 6397 | type_ptr = m_die_to_type[die]; | 
|  | 6398 | if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6399 | { | 
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6400 | type_sp = type_ptr->shared_from_this(); | 
|  | 6401 | break; | 
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6402 | } | 
|  | 6403 | } | 
|  | 6404 | } | 
|  | 6405 |  | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6406 | if (specification_die_offset != DW_INVALID_OFFSET) | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6407 | { | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6408 | // We have a specification which we are going to base our function | 
|  | 6409 | // prototype off of, so we need this type to be completed so that the | 
|  | 6410 | // m_die_to_decl_ctx for the method in the specification has a valid | 
|  | 6411 | // clang decl context. | 
| Greg Clayton | 8eb732e | 2011-12-13 04:34:06 +0000 | [diff] [blame] | 6412 | class_type->GetClangForwardType(); | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6413 | // If we have a specification, then the function type should have been | 
|  | 6414 | // made with the specification and not with this die. | 
|  | 6415 | DWARFCompileUnitSP spec_cu_sp; | 
|  | 6416 | const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp); | 
| Eric Christopher | 6cc6e60 | 2012-03-25 19:37:33 +0000 | [diff] [blame] | 6417 | clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die); | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6418 | if (spec_clang_decl_ctx) | 
|  | 6419 | { | 
|  | 6420 | LinkDeclContextToDIE(spec_clang_decl_ctx, die); | 
|  | 6421 | } | 
|  | 6422 | else | 
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6423 | { | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6424 | 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] | 6425 | MakeUserID(die->GetOffset()), | 
|  | 6426 | specification_die_offset); | 
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6427 | } | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6428 | type_handled = true; | 
|  | 6429 | } | 
|  | 6430 | else if (abstract_origin_die_offset != DW_INVALID_OFFSET) | 
|  | 6431 | { | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6432 | // We have a specification which we are going to base our function | 
|  | 6433 | // prototype off of, so we need this type to be completed so that the | 
|  | 6434 | // m_die_to_decl_ctx for the method in the abstract origin has a valid | 
|  | 6435 | // clang decl context. | 
| Greg Clayton | 8eb732e | 2011-12-13 04:34:06 +0000 | [diff] [blame] | 6436 | class_type->GetClangForwardType(); | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6437 |  | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6438 | DWARFCompileUnitSP abs_cu_sp; | 
|  | 6439 | 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] | 6440 | clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die); | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6441 | if (abs_clang_decl_ctx) | 
|  | 6442 | { | 
|  | 6443 | LinkDeclContextToDIE (abs_clang_decl_ctx, die); | 
|  | 6444 | } | 
|  | 6445 | else | 
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6446 | { | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6447 | 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] | 6448 | MakeUserID(die->GetOffset()), | 
|  | 6449 | abstract_origin_die_offset); | 
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6450 | } | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6451 | type_handled = true; | 
|  | 6452 | } | 
|  | 6453 | else | 
|  | 6454 | { | 
|  | 6455 | clang_type_t class_opaque_type = class_type->GetClangForwardType(); | 
|  | 6456 | if (ClangASTContext::IsCXXClassType (class_opaque_type)) | 
| Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 6457 | { | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6458 | if (ClangASTContext::IsBeingDefined (class_opaque_type)) | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6459 | { | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6460 | // Neither GCC 4.2 nor clang++ currently set a valid accessibility | 
|  | 6461 | // in the DWARF for C++ methods... Default to public for now... | 
|  | 6462 | if (accessibility == eAccessNone) | 
|  | 6463 | accessibility = eAccessPublic; | 
|  | 6464 |  | 
|  | 6465 | if (!is_static && !die->HasChildren()) | 
|  | 6466 | { | 
|  | 6467 | // We have a C++ member function with no children (this pointer!) | 
|  | 6468 | // and clang will get mad if we try and make a function that isn't | 
|  | 6469 | // well formed in the DWARF, so we will just skip it... | 
|  | 6470 | type_handled = true; | 
|  | 6471 | } | 
|  | 6472 | else | 
|  | 6473 | { | 
|  | 6474 | clang::CXXMethodDecl *cxx_method_decl; | 
|  | 6475 | // REMOVE THE CRASH DESCRIPTION BELOW | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6476 | Host::SetCrashDescriptionWithFormat ("SymbolFileDWARF::ParseType() is adding a method %s to class %s in DIE 0x%8.8" PRIx64 " from %s/%s", | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6477 | type_name_cstr, | 
|  | 6478 | class_type->GetName().GetCString(), | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6479 | MakeUserID(die->GetOffset()), | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6480 | m_obj_file->GetFileSpec().GetDirectory().GetCString(), | 
|  | 6481 | m_obj_file->GetFileSpec().GetFilename().GetCString()); | 
|  | 6482 |  | 
| Sean Callanan | c1b732d | 2011-11-01 18:07:13 +0000 | [diff] [blame] | 6483 | const bool is_attr_used = false; | 
|  | 6484 |  | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6485 | cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type, | 
|  | 6486 | type_name_cstr, | 
|  | 6487 | clang_type, | 
|  | 6488 | accessibility, | 
|  | 6489 | is_virtual, | 
|  | 6490 | is_static, | 
|  | 6491 | is_inline, | 
| Sean Callanan | c1b732d | 2011-11-01 18:07:13 +0000 | [diff] [blame] | 6492 | is_explicit, | 
| Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 6493 | is_attr_used, | 
|  | 6494 | is_artificial); | 
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6495 |  | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6496 | type_handled = cxx_method_decl != NULL; | 
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6497 |  | 
|  | 6498 | if (type_handled) | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6499 | { | 
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6500 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die); | 
|  | 6501 |  | 
|  | 6502 | Host::SetCrashDescription (NULL); | 
|  | 6503 |  | 
|  | 6504 |  | 
|  | 6505 | ClangASTMetadata metadata; | 
|  | 6506 | metadata.SetUserID(MakeUserID(die->GetOffset())); | 
|  | 6507 |  | 
|  | 6508 | if (!object_pointer_name.empty()) | 
|  | 6509 | { | 
|  | 6510 | metadata.SetObjectPtrName(object_pointer_name.c_str()); | 
|  | 6511 | if (log) | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6512 | log->Printf ("Setting object pointer name: %s on method object %p.\n", | 
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6513 | object_pointer_name.c_str(), | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6514 | cxx_method_decl); | 
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6515 | } | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6516 | GetClangASTContext().SetMetadata (cxx_method_decl, metadata); | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6517 | } | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6518 | } | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6519 | } | 
|  | 6520 | else | 
|  | 6521 | { | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6522 | // We were asked to parse the type for a method in a class, yet the | 
|  | 6523 | // class hasn't been asked to complete itself through the | 
|  | 6524 | // clang::ExternalASTSource protocol, so we need to just have the | 
|  | 6525 | // class complete itself and do things the right way, then our | 
|  | 6526 | // DIE should then have an entry in the m_die_to_type map. First | 
|  | 6527 | // we need to modify the m_die_to_type so it doesn't think we are | 
|  | 6528 | // trying to parse this DIE anymore... | 
|  | 6529 | m_die_to_type[die] = NULL; | 
|  | 6530 |  | 
|  | 6531 | // Now we get the full type to force our class type to complete itself | 
|  | 6532 | // using the clang::ExternalASTSource protocol which will parse all | 
|  | 6533 | // base classes and all methods (including the method for this DIE). | 
|  | 6534 | class_type->GetClangFullType(); | 
| Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 6535 |  | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6536 | // The type for this DIE should have been filled in the function call above | 
|  | 6537 | type_ptr = m_die_to_type[die]; | 
| Greg Clayton | e5476db | 2012-06-01 20:32:35 +0000 | [diff] [blame] | 6538 | if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6539 | { | 
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 6540 | type_sp = type_ptr->shared_from_this(); | 
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6541 | break; | 
|  | 6542 | } | 
| Sean Callanan | 02eee4d | 2012-04-12 23:10:00 +0000 | [diff] [blame] | 6543 |  | 
|  | 6544 | // FIXME This is fixing some even uglier behavior but we really need to | 
|  | 6545 | // uniq the methods of each class as well as the class itself. | 
|  | 6546 | // <rdar://problem/11240464> | 
|  | 6547 | type_handled = true; | 
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6548 | } | 
| Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 6549 | } | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6550 | } | 
|  | 6551 | } | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6552 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6553 | } | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6554 |  | 
|  | 6555 | if (!type_handled) | 
|  | 6556 | { | 
|  | 6557 | // We just have a function that isn't part of a class | 
| Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 6558 | clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (containing_decl_ctx, | 
|  | 6559 | type_name_cstr, | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6560 | clang_type, | 
|  | 6561 | storage, | 
|  | 6562 | is_inline); | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 6563 |  | 
|  | 6564 | //                            if (template_param_infos.GetSize() > 0) | 
|  | 6565 | //                            { | 
|  | 6566 | //                                clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx, | 
|  | 6567 | //                                                                                                                  function_decl, | 
|  | 6568 | //                                                                                                                  type_name_cstr, | 
|  | 6569 | //                                                                                                                  template_param_infos); | 
|  | 6570 | // | 
|  | 6571 | //                                ast.CreateFunctionTemplateSpecializationInfo (function_decl, | 
|  | 6572 | //                                                                              func_template_decl, | 
|  | 6573 | //                                                                              template_param_infos); | 
|  | 6574 | //                            } | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6575 | // Add the decl to our DIE to decl context map | 
|  | 6576 | assert (function_decl); | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6577 | LinkDeclContextToDIE(function_decl, die); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6578 | if (!function_param_decls.empty()) | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6579 | ast.SetFunctionParameters (function_decl, | 
|  | 6580 | &function_param_decls.front(), | 
|  | 6581 | function_param_decls.size()); | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 6582 |  | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6583 | ClangASTMetadata metadata; | 
|  | 6584 | metadata.SetUserID(MakeUserID(die->GetOffset())); | 
|  | 6585 |  | 
|  | 6586 | if (!object_pointer_name.empty()) | 
|  | 6587 | { | 
|  | 6588 | metadata.SetObjectPtrName(object_pointer_name.c_str()); | 
| Jim Ingham | 2cffda3f | 2012-10-30 23:34:07 +0000 | [diff] [blame] | 6589 | if (log) | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6590 | log->Printf ("Setting object pointer name: %s on function object %p.", | 
| Jim Ingham | 2cffda3f | 2012-10-30 23:34:07 +0000 | [diff] [blame] | 6591 | object_pointer_name.c_str(), | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6592 | function_decl); | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6593 | } | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6594 | GetClangASTContext().SetMetadata (function_decl, metadata); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6595 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6596 | } | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6597 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6598 | this, | 
|  | 6599 | type_name_const_str, | 
|  | 6600 | 0, | 
|  | 6601 | NULL, | 
|  | 6602 | LLDB_INVALID_UID, | 
|  | 6603 | Type::eEncodingIsUID, | 
|  | 6604 | &decl, | 
|  | 6605 | clang_type, | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6606 | Type::eResolveStateFull)); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6607 | assert(type_sp.get()); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6608 | } | 
|  | 6609 | break; | 
|  | 6610 |  | 
|  | 6611 | case DW_TAG_array_type: | 
|  | 6612 | { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6613 | // 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] | 6614 | m_die_to_type[die] = DIE_IS_BEING_PARSED; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6615 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6616 | lldb::user_id_t type_die_offset = DW_INVALID_OFFSET; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6617 | int64_t first_index = 0; | 
|  | 6618 | uint32_t byte_stride = 0; | 
|  | 6619 | uint32_t bit_stride = 0; | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6620 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6621 |  | 
|  | 6622 | if (num_attributes > 0) | 
|  | 6623 | { | 
|  | 6624 | uint32_t i; | 
|  | 6625 | for (i=0; i<num_attributes; ++i) | 
|  | 6626 | { | 
|  | 6627 | attr = attributes.AttributeAtIndex(i); | 
|  | 6628 | DWARFFormValue form_value; | 
|  | 6629 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 6630 | { | 
|  | 6631 | switch (attr) | 
|  | 6632 | { | 
|  | 6633 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 6634 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 6635 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 6636 | case DW_AT_name: | 
|  | 6637 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); | 
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6638 | type_name_const_str.SetCString(type_name_cstr); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6639 | break; | 
|  | 6640 |  | 
|  | 6641 | 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] | 6642 | case DW_AT_byte_size:       break; // byte_size = form_value.Unsigned(); break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6643 | case DW_AT_byte_stride:     byte_stride = form_value.Unsigned(); break; | 
|  | 6644 | case DW_AT_bit_stride:      bit_stride = form_value.Unsigned(); break; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6645 | case DW_AT_accessibility:   break; // accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; | 
|  | 6646 | case DW_AT_declaration:     break; // is_forward_declaration = form_value.Unsigned() != 0; break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6647 | case DW_AT_allocated: | 
|  | 6648 | case DW_AT_associated: | 
|  | 6649 | case DW_AT_data_location: | 
|  | 6650 | case DW_AT_description: | 
|  | 6651 | case DW_AT_ordering: | 
|  | 6652 | case DW_AT_start_scope: | 
|  | 6653 | case DW_AT_visibility: | 
|  | 6654 | case DW_AT_specification: | 
|  | 6655 | case DW_AT_abstract_origin: | 
|  | 6656 | case DW_AT_sibling: | 
|  | 6657 | break; | 
|  | 6658 | } | 
|  | 6659 | } | 
|  | 6660 | } | 
|  | 6661 |  | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6662 | 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] | 6663 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6664 | Type *element_type = ResolveTypeUID(type_die_offset); | 
|  | 6665 |  | 
|  | 6666 | if (element_type) | 
|  | 6667 | { | 
|  | 6668 | std::vector<uint64_t> element_orders; | 
|  | 6669 | ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride); | 
|  | 6670 | if (byte_stride == 0 && bit_stride == 0) | 
|  | 6671 | byte_stride = element_type->GetByteSize(); | 
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 6672 | clang_type_t array_element_type = element_type->GetClangForwardType(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6673 | uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride; | 
|  | 6674 | uint64_t num_elements = 0; | 
|  | 6675 | std::vector<uint64_t>::const_reverse_iterator pos; | 
|  | 6676 | std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend(); | 
|  | 6677 | for (pos = element_orders.rbegin(); pos != end; ++pos) | 
|  | 6678 | { | 
|  | 6679 | num_elements = *pos; | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6680 | clang_type = ast.CreateArrayType (array_element_type, | 
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 6681 | num_elements); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6682 | array_element_type = clang_type; | 
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 6683 | 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] | 6684 | } | 
|  | 6685 | ConstString empty_name; | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6686 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6687 | this, | 
|  | 6688 | empty_name, | 
|  | 6689 | array_element_bit_stride / 8, | 
|  | 6690 | NULL, | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6691 | type_die_offset, | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6692 | Type::eEncodingIsUID, | 
|  | 6693 | &decl, | 
|  | 6694 | clang_type, | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6695 | Type::eResolveStateFull)); | 
|  | 6696 | type_sp->SetEncodingType (element_type); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6697 | } | 
|  | 6698 | } | 
|  | 6699 | } | 
|  | 6700 | break; | 
|  | 6701 |  | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6702 | case DW_TAG_ptr_to_member_type: | 
|  | 6703 | { | 
|  | 6704 | dw_offset_t type_die_offset = DW_INVALID_OFFSET; | 
|  | 6705 | dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET; | 
|  | 6706 |  | 
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6707 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6708 |  | 
|  | 6709 | if (num_attributes > 0) { | 
|  | 6710 | uint32_t i; | 
|  | 6711 | for (i=0; i<num_attributes; ++i) | 
|  | 6712 | { | 
|  | 6713 | attr = attributes.AttributeAtIndex(i); | 
|  | 6714 | DWARFFormValue form_value; | 
|  | 6715 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
|  | 6716 | { | 
|  | 6717 | switch (attr) | 
|  | 6718 | { | 
|  | 6719 | case DW_AT_type: | 
|  | 6720 | type_die_offset = form_value.Reference(dwarf_cu); break; | 
|  | 6721 | case DW_AT_containing_type: | 
|  | 6722 | containing_type_die_offset = form_value.Reference(dwarf_cu); break; | 
|  | 6723 | } | 
|  | 6724 | } | 
|  | 6725 | } | 
|  | 6726 |  | 
|  | 6727 | Type *pointee_type = ResolveTypeUID(type_die_offset); | 
|  | 6728 | Type *class_type = ResolveTypeUID(containing_type_die_offset); | 
|  | 6729 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6730 | clang_type_t pointee_clang_type = pointee_type->GetClangForwardType(); | 
|  | 6731 | clang_type_t class_clang_type = class_type->GetClangLayoutType(); | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6732 |  | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6733 | clang_type = ast.CreateMemberPointerType(pointee_clang_type, | 
|  | 6734 | class_clang_type); | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6735 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6736 | byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(), | 
|  | 6737 | clang_type) / 8; | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6738 |  | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6739 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), | 
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6740 | this, | 
|  | 6741 | type_name_const_str, | 
|  | 6742 | byte_size, | 
|  | 6743 | NULL, | 
|  | 6744 | LLDB_INVALID_UID, | 
|  | 6745 | Type::eEncodingIsUID, | 
|  | 6746 | NULL, | 
|  | 6747 | clang_type, | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6748 | Type::eResolveStateForward)); | 
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6749 | } | 
|  | 6750 |  | 
|  | 6751 | break; | 
|  | 6752 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6753 | default: | 
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 6754 | 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", | 
|  | 6755 | die->GetOffset(), | 
|  | 6756 | tag, | 
|  | 6757 | DW_TAG_value_to_name(tag)); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6758 | break; | 
|  | 6759 | } | 
|  | 6760 |  | 
|  | 6761 | if (type_sp.get()) | 
|  | 6762 | { | 
|  | 6763 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); | 
|  | 6764 | dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; | 
|  | 6765 |  | 
|  | 6766 | SymbolContextScope * symbol_context_scope = NULL; | 
|  | 6767 | if (sc_parent_tag == DW_TAG_compile_unit) | 
|  | 6768 | { | 
|  | 6769 | symbol_context_scope = sc.comp_unit; | 
|  | 6770 | } | 
|  | 6771 | else if (sc.function != NULL) | 
|  | 6772 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6773 | 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] | 6774 | if (symbol_context_scope == NULL) | 
|  | 6775 | symbol_context_scope = sc.function; | 
|  | 6776 | } | 
|  | 6777 |  | 
|  | 6778 | if (symbol_context_scope != NULL) | 
|  | 6779 | { | 
|  | 6780 | type_sp->SetSymbolContextScope(symbol_context_scope); | 
|  | 6781 | } | 
|  | 6782 |  | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6783 | // We are ready to put this type into the uniqued list up at the module level | 
|  | 6784 | type_list->Insert (type_sp); | 
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 6785 |  | 
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6786 | m_die_to_type[die] = type_sp.get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6787 | } | 
|  | 6788 | } | 
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 6789 | else if (type_ptr != DIE_IS_BEING_PARSED) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6790 | { | 
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 6791 | type_sp = type_ptr->shared_from_this(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6792 | } | 
|  | 6793 | } | 
|  | 6794 | return type_sp; | 
|  | 6795 | } | 
|  | 6796 |  | 
|  | 6797 | size_t | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6798 | SymbolFileDWARF::ParseTypes | 
|  | 6799 | ( | 
|  | 6800 | const SymbolContext& sc, | 
|  | 6801 | DWARFCompileUnit* dwarf_cu, | 
|  | 6802 | const DWARFDebugInfoEntry *die, | 
|  | 6803 | bool parse_siblings, | 
|  | 6804 | bool parse_children | 
|  | 6805 | ) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6806 | { | 
|  | 6807 | size_t types_added = 0; | 
|  | 6808 | while (die != NULL) | 
|  | 6809 | { | 
|  | 6810 | bool type_is_new = false; | 
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6811 | if (ParseType(sc, dwarf_cu, die, &type_is_new).get()) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6812 | { | 
|  | 6813 | if (type_is_new) | 
|  | 6814 | ++types_added; | 
|  | 6815 | } | 
|  | 6816 |  | 
|  | 6817 | if (parse_children && die->HasChildren()) | 
|  | 6818 | { | 
|  | 6819 | if (die->Tag() == DW_TAG_subprogram) | 
|  | 6820 | { | 
|  | 6821 | SymbolContext child_sc(sc); | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6822 | child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6823 | types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true); | 
|  | 6824 | } | 
|  | 6825 | else | 
|  | 6826 | types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true); | 
|  | 6827 | } | 
|  | 6828 |  | 
|  | 6829 | if (parse_siblings) | 
|  | 6830 | die = die->GetSibling(); | 
|  | 6831 | else | 
|  | 6832 | die = NULL; | 
|  | 6833 | } | 
|  | 6834 | return types_added; | 
|  | 6835 | } | 
|  | 6836 |  | 
|  | 6837 |  | 
|  | 6838 | size_t | 
|  | 6839 | SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc) | 
|  | 6840 | { | 
|  | 6841 | assert(sc.comp_unit && sc.function); | 
|  | 6842 | size_t functions_added = 0; | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 6843 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6844 | if (dwarf_cu) | 
|  | 6845 | { | 
|  | 6846 | dw_offset_t function_die_offset = sc.function->GetID(); | 
|  | 6847 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset); | 
|  | 6848 | if (function_die) | 
|  | 6849 | { | 
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 6850 | 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] | 6851 | } | 
|  | 6852 | } | 
|  | 6853 |  | 
|  | 6854 | return functions_added; | 
|  | 6855 | } | 
|  | 6856 |  | 
|  | 6857 |  | 
|  | 6858 | size_t | 
|  | 6859 | SymbolFileDWARF::ParseTypes (const SymbolContext &sc) | 
|  | 6860 | { | 
|  | 6861 | // At least a compile unit must be valid | 
|  | 6862 | assert(sc.comp_unit); | 
|  | 6863 | size_t types_added = 0; | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 6864 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6865 | if (dwarf_cu) | 
|  | 6866 | { | 
|  | 6867 | if (sc.function) | 
|  | 6868 | { | 
|  | 6869 | dw_offset_t function_die_offset = sc.function->GetID(); | 
|  | 6870 | const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset); | 
|  | 6871 | if (func_die && func_die->HasChildren()) | 
|  | 6872 | { | 
|  | 6873 | types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true); | 
|  | 6874 | } | 
|  | 6875 | } | 
|  | 6876 | else | 
|  | 6877 | { | 
|  | 6878 | const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE(); | 
|  | 6879 | if (dwarf_cu_die && dwarf_cu_die->HasChildren()) | 
|  | 6880 | { | 
|  | 6881 | types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true); | 
|  | 6882 | } | 
|  | 6883 | } | 
|  | 6884 | } | 
|  | 6885 |  | 
|  | 6886 | return types_added; | 
|  | 6887 | } | 
|  | 6888 |  | 
|  | 6889 | size_t | 
|  | 6890 | SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc) | 
|  | 6891 | { | 
|  | 6892 | if (sc.comp_unit != NULL) | 
|  | 6893 | { | 
| Greg Clayton | 4b3dc10 | 2010-11-01 20:32:12 +0000 | [diff] [blame] | 6894 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 6895 | if (info == NULL) | 
|  | 6896 | return 0; | 
|  | 6897 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6898 | if (sc.function) | 
|  | 6899 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 6900 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnitContainingDIE(sc.function->GetID()).get(); | 
|  | 6901 |  | 
|  | 6902 | if (dwarf_cu == NULL) | 
|  | 6903 | return 0; | 
|  | 6904 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6905 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID()); | 
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 6906 |  | 
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 6907 | dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS); | 
|  | 6908 | if (func_lo_pc != LLDB_INVALID_ADDRESS) | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6909 | { | 
|  | 6910 | 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] | 6911 |  | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6912 | // Let all blocks know they have parse all their variables | 
|  | 6913 | sc.function->GetBlock (false).SetDidParseVariables (true, true); | 
|  | 6914 | return num_variables; | 
|  | 6915 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6916 | } | 
|  | 6917 | else if (sc.comp_unit) | 
|  | 6918 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 6919 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()).get(); | 
|  | 6920 |  | 
|  | 6921 | if (dwarf_cu == NULL) | 
|  | 6922 | return 0; | 
|  | 6923 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6924 | uint32_t vars_added = 0; | 
|  | 6925 | VariableListSP variables (sc.comp_unit->GetVariableList(false)); | 
|  | 6926 |  | 
|  | 6927 | if (variables.get() == NULL) | 
|  | 6928 | { | 
|  | 6929 | variables.reset(new VariableList()); | 
|  | 6930 | sc.comp_unit->SetVariableList(variables); | 
|  | 6931 |  | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 6932 | DWARFCompileUnit* match_dwarf_cu = NULL; | 
|  | 6933 | const DWARFDebugInfoEntry* die = NULL; | 
|  | 6934 | DIEArray die_offsets; | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 6935 | if (m_using_apple_tables) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6936 | { | 
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 6937 | if (m_apple_names_ap.get()) | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6938 | { | 
|  | 6939 | DWARFMappedHash::DIEInfoArray hash_data_array; | 
|  | 6940 | if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(), | 
|  | 6941 | dwarf_cu->GetNextCompileUnitOffset(), | 
|  | 6942 | hash_data_array)) | 
|  | 6943 | { | 
|  | 6944 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); | 
|  | 6945 | } | 
|  | 6946 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6947 | } | 
|  | 6948 | else | 
|  | 6949 | { | 
|  | 6950 | // Index if we already haven't to make sure the compile units | 
|  | 6951 | // get indexed and make their global DIE index list | 
|  | 6952 | if (!m_indexed) | 
|  | 6953 | Index (); | 
|  | 6954 |  | 
|  | 6955 | m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(), | 
|  | 6956 | dwarf_cu->GetNextCompileUnitOffset(), | 
|  | 6957 | die_offsets); | 
|  | 6958 | } | 
|  | 6959 |  | 
|  | 6960 | const size_t num_matches = die_offsets.size(); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 6961 | if (num_matches) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6962 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 6963 | DWARFDebugInfo* debug_info = DebugInfo(); | 
|  | 6964 | for (size_t i=0; i<num_matches; ++i) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6965 | { | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 6966 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 6967 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu); | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 6968 | if (die) | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 6969 | { | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 6970 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS)); | 
|  | 6971 | if (var_sp) | 
|  | 6972 | { | 
|  | 6973 | variables->AddVariableIfUnique (var_sp); | 
|  | 6974 | ++vars_added; | 
|  | 6975 | } | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 6976 | } | 
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 6977 | else | 
|  | 6978 | { | 
|  | 6979 | if (m_using_apple_tables) | 
|  | 6980 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6981 | 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] | 6982 | } | 
|  | 6983 | } | 
|  | 6984 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6985 | } | 
|  | 6986 | } | 
|  | 6987 | } | 
|  | 6988 | return vars_added; | 
|  | 6989 | } | 
|  | 6990 | } | 
|  | 6991 | return 0; | 
|  | 6992 | } | 
|  | 6993 |  | 
|  | 6994 |  | 
|  | 6995 | VariableSP | 
|  | 6996 | SymbolFileDWARF::ParseVariableDIE | 
|  | 6997 | ( | 
|  | 6998 | const SymbolContext& sc, | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6999 | DWARFCompileUnit* dwarf_cu, | 
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 7000 | const DWARFDebugInfoEntry *die, | 
|  | 7001 | const lldb::addr_t func_low_pc | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7002 | ) | 
|  | 7003 | { | 
|  | 7004 |  | 
| Greg Clayton | 83c5cd9 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 7005 | VariableSP var_sp (m_die_to_variable_sp[die]); | 
|  | 7006 | if (var_sp) | 
|  | 7007 | return var_sp;  // Already been parsed! | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7008 |  | 
|  | 7009 | const dw_tag_t tag = die->Tag(); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7010 |  | 
|  | 7011 | if ((tag == DW_TAG_variable) || | 
|  | 7012 | (tag == DW_TAG_constant) || | 
|  | 7013 | (tag == DW_TAG_formal_parameter && sc.function)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7014 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7015 | DWARFDebugInfoEntry::Attributes attributes; | 
|  | 7016 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); | 
|  | 7017 | if (num_attributes > 0) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7018 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7019 | const char *name = NULL; | 
|  | 7020 | const char *mangled = NULL; | 
|  | 7021 | Declaration decl; | 
|  | 7022 | uint32_t i; | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7023 | lldb::user_id_t type_uid = LLDB_INVALID_UID; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7024 | DWARFExpression location; | 
|  | 7025 | bool is_external = false; | 
|  | 7026 | bool is_artificial = false; | 
|  | 7027 | bool location_is_const_value_data = false; | 
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7028 | bool has_explicit_location = false; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 7029 | //AccessType accessibility = eAccessNone; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7030 |  | 
|  | 7031 | for (i=0; i<num_attributes; ++i) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7032 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7033 | dw_attr_t attr = attributes.AttributeAtIndex(i); | 
|  | 7034 | DWARFFormValue form_value; | 
|  | 7035 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7036 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7037 | switch (attr) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7038 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7039 | case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; | 
|  | 7040 | case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break; | 
|  | 7041 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; | 
|  | 7042 | 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] | 7043 | case DW_AT_linkage_name: | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7044 | 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] | 7045 | case DW_AT_type:        type_uid = form_value.Reference(dwarf_cu); break; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7046 | case DW_AT_external:    is_external = form_value.Unsigned() != 0; break; | 
|  | 7047 | case DW_AT_const_value: | 
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7048 | // If we have already found a DW_AT_location attribute, ignore this attribute. | 
|  | 7049 | if (!has_explicit_location) | 
|  | 7050 | { | 
|  | 7051 | location_is_const_value_data = true; | 
|  | 7052 | // The constant value will be either a block, a data value or a string. | 
|  | 7053 | const DataExtractor& debug_info_data = get_debug_info_data(); | 
|  | 7054 | if (DWARFFormValue::IsBlockForm(form_value.Form())) | 
|  | 7055 | { | 
|  | 7056 | // Retrieve the value as a block expression. | 
|  | 7057 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); | 
|  | 7058 | uint32_t block_length = form_value.Unsigned(); | 
|  | 7059 | location.CopyOpcodeData(debug_info_data, block_offset, block_length); | 
|  | 7060 | } | 
|  | 7061 | else if (DWARFFormValue::IsDataForm(form_value.Form())) | 
|  | 7062 | { | 
|  | 7063 | // Retrieve the value as a data expression. | 
|  | 7064 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); | 
|  | 7065 | uint32_t data_offset = attributes.DIEOffsetAtIndex(i); | 
|  | 7066 | uint32_t data_length = fixed_form_sizes[form_value.Form()]; | 
|  | 7067 | location.CopyOpcodeData(debug_info_data, data_offset, data_length); | 
|  | 7068 | } | 
|  | 7069 | else | 
|  | 7070 | { | 
|  | 7071 | // Retrieve the value as a string expression. | 
|  | 7072 | if (form_value.Form() == DW_FORM_strp) | 
|  | 7073 | { | 
|  | 7074 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); | 
|  | 7075 | uint32_t data_offset = attributes.DIEOffsetAtIndex(i); | 
|  | 7076 | uint32_t data_length = fixed_form_sizes[form_value.Form()]; | 
|  | 7077 | location.CopyOpcodeData(debug_info_data, data_offset, data_length); | 
|  | 7078 | } | 
|  | 7079 | else | 
|  | 7080 | { | 
|  | 7081 | const char *str = form_value.AsCString(&debug_info_data); | 
|  | 7082 | uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart(); | 
|  | 7083 | uint32_t string_length = strlen(str) + 1; | 
|  | 7084 | location.CopyOpcodeData(debug_info_data, string_offset, string_length); | 
|  | 7085 | } | 
|  | 7086 | } | 
|  | 7087 | } | 
|  | 7088 | break; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7089 | case DW_AT_location: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7090 | { | 
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7091 | location_is_const_value_data = false; | 
|  | 7092 | has_explicit_location = true; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7093 | if (form_value.BlockData()) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7094 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7095 | const DataExtractor& debug_info_data = get_debug_info_data(); | 
|  | 7096 |  | 
|  | 7097 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); | 
|  | 7098 | uint32_t block_length = form_value.Unsigned(); | 
| Greg Clayton | 7f4c743 | 2012-08-11 00:49:14 +0000 | [diff] [blame] | 7099 | location.CopyOpcodeData(get_debug_info_data(), block_offset, block_length); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7100 | } | 
|  | 7101 | else | 
|  | 7102 | { | 
|  | 7103 | const DataExtractor&    debug_loc_data = get_debug_loc_data(); | 
|  | 7104 | const dw_offset_t debug_loc_offset = form_value.Unsigned(); | 
|  | 7105 |  | 
|  | 7106 | size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset); | 
|  | 7107 | if (loc_list_length > 0) | 
|  | 7108 | { | 
| Greg Clayton | 7f4c743 | 2012-08-11 00:49:14 +0000 | [diff] [blame] | 7109 | location.CopyOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length); | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7110 | assert (func_low_pc != LLDB_INVALID_ADDRESS); | 
|  | 7111 | location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress()); | 
|  | 7112 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7113 | } | 
|  | 7114 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7115 | break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7116 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7117 | case DW_AT_artificial:      is_artificial = form_value.Unsigned() != 0; break; | 
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 7118 | 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] | 7119 | case DW_AT_declaration: | 
|  | 7120 | case DW_AT_description: | 
|  | 7121 | case DW_AT_endianity: | 
|  | 7122 | case DW_AT_segment: | 
|  | 7123 | case DW_AT_start_scope: | 
|  | 7124 | case DW_AT_visibility: | 
|  | 7125 | default: | 
|  | 7126 | case DW_AT_abstract_origin: | 
|  | 7127 | case DW_AT_sibling: | 
|  | 7128 | case DW_AT_specification: | 
|  | 7129 | break; | 
|  | 7130 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7131 | } | 
|  | 7132 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7133 |  | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7134 | if (location.IsValid()) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7135 | { | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7136 | ValueType scope = eValueTypeInvalid; | 
|  | 7137 |  | 
|  | 7138 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); | 
|  | 7139 | 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] | 7140 | SymbolContextScope * symbol_context_scope = NULL; | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7141 |  | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7142 | // DWARF doesn't specify if a DW_TAG_variable is a local, global | 
|  | 7143 | // or static variable, so we have to do a little digging by | 
|  | 7144 | // looking at the location of a varaible to see if it contains | 
|  | 7145 | // a DW_OP_addr opcode _somewhere_ in the definition. I say | 
|  | 7146 | // somewhere because clang likes to combine small global variables | 
|  | 7147 | // into the same symbol and have locations like: | 
|  | 7148 | // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus | 
|  | 7149 | // So if we don't have a DW_TAG_formal_parameter, we can look at | 
|  | 7150 | // the location to see if it contains a DW_OP_addr opcode, and | 
|  | 7151 | // then we can correctly classify  our variables. | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7152 | if (tag == DW_TAG_formal_parameter) | 
|  | 7153 | scope = eValueTypeVariableArgument; | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7154 | else | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7155 | { | 
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 7156 | bool op_error = false; | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7157 | // 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] | 7158 | lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS; | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7159 | if (!location_is_const_value_data) | 
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 7160 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7161 | location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error); | 
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 7162 | if (op_error) | 
|  | 7163 | { | 
|  | 7164 | StreamString strm; | 
|  | 7165 | location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL); | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 7166 | 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] | 7167 | } | 
|  | 7168 | } | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7169 |  | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7170 | if (location_DW_OP_addr != LLDB_INVALID_ADDRESS) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7171 | { | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7172 | if (is_external) | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7173 | scope = eValueTypeVariableGlobal; | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7174 | else | 
|  | 7175 | scope = eValueTypeVariableStatic; | 
|  | 7176 |  | 
|  | 7177 |  | 
|  | 7178 | SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile (); | 
|  | 7179 |  | 
|  | 7180 | if (debug_map_symfile) | 
|  | 7181 | { | 
|  | 7182 | // When leaving the DWARF in the .o files on darwin, | 
|  | 7183 | // when we have a global variable that wasn't initialized, | 
|  | 7184 | // the .o file might not have allocated a virtual | 
|  | 7185 | // address for the global variable. In this case it will | 
|  | 7186 | // have created a symbol for the global variable | 
|  | 7187 | // that is undefined/data and external and the value will | 
|  | 7188 | // be the byte size of the variable. When we do the | 
|  | 7189 | // address map in SymbolFileDWARFDebugMap we rely on | 
|  | 7190 | // having an address, we need to do some magic here | 
|  | 7191 | // so we can get the correct address for our global | 
|  | 7192 | // variable. The address for all of these entries | 
|  | 7193 | // will be zero, and there will be an undefined symbol | 
|  | 7194 | // in this object file, and the executable will have | 
|  | 7195 | // a matching symbol with a good address. So here we | 
|  | 7196 | // dig up the correct address and replace it in the | 
|  | 7197 | // location for the variable, and set the variable's | 
|  | 7198 | // symbol context scope to be that of the main executable | 
|  | 7199 | // so the file address will resolve correctly. | 
|  | 7200 | bool linked_oso_file_addr = false; | 
|  | 7201 | if (is_external && location_DW_OP_addr == 0) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7202 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7203 |  | 
|  | 7204 | // we have a possible uninitialized extern global | 
|  | 7205 | ConstString const_name(mangled ? mangled : name); | 
|  | 7206 | ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile(); | 
|  | 7207 | if (debug_map_objfile) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7208 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7209 | Symtab *debug_map_symtab = debug_map_objfile->GetSymtab(); | 
|  | 7210 | if (debug_map_symtab) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7211 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7212 | Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name, | 
|  | 7213 | eSymbolTypeData, | 
|  | 7214 | Symtab::eDebugYes, | 
|  | 7215 | Symtab::eVisibilityExtern); | 
|  | 7216 | if (exe_symbol) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7217 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7218 | if (exe_symbol->ValueIsAddress()) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7219 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7220 | const addr_t exe_file_addr = exe_symbol->GetAddress().GetFileAddress(); | 
|  | 7221 | if (exe_file_addr != LLDB_INVALID_ADDRESS) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7222 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7223 | if (location.Update_DW_OP_addr (exe_file_addr)) | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7224 | { | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7225 | linked_oso_file_addr = true; | 
|  | 7226 | symbol_context_scope = exe_symbol; | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7227 | } | 
|  | 7228 | } | 
|  | 7229 | } | 
|  | 7230 | } | 
|  | 7231 | } | 
|  | 7232 | } | 
|  | 7233 | } | 
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7234 |  | 
|  | 7235 | if (!linked_oso_file_addr) | 
|  | 7236 | { | 
|  | 7237 | // The DW_OP_addr is not zero, but it contains a .o file address which | 
|  | 7238 | // needs to be linked up correctly. | 
|  | 7239 | const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr); | 
|  | 7240 | if (exe_file_addr != LLDB_INVALID_ADDRESS) | 
|  | 7241 | { | 
|  | 7242 | // Update the file address for this variable | 
|  | 7243 | location.Update_DW_OP_addr (exe_file_addr); | 
|  | 7244 | } | 
|  | 7245 | else | 
|  | 7246 | { | 
|  | 7247 | // Variable didn't make it into the final executable | 
|  | 7248 | return var_sp; | 
|  | 7249 | } | 
|  | 7250 | } | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7251 | } | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7252 | } | 
|  | 7253 | else | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7254 | { | 
|  | 7255 | scope = eValueTypeVariableLocal; | 
|  | 7256 | } | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7257 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7258 |  | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7259 | if (symbol_context_scope == NULL) | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7260 | { | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7261 | switch (parent_tag) | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 7262 | { | 
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7263 | case DW_TAG_subprogram: | 
|  | 7264 | case DW_TAG_inlined_subroutine: | 
|  | 7265 | case DW_TAG_lexical_block: | 
|  | 7266 | if (sc.function) | 
|  | 7267 | { | 
|  | 7268 | symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); | 
|  | 7269 | if (symbol_context_scope == NULL) | 
|  | 7270 | symbol_context_scope = sc.function; | 
|  | 7271 | } | 
|  | 7272 | break; | 
|  | 7273 |  | 
|  | 7274 | default: | 
|  | 7275 | symbol_context_scope = sc.comp_unit; | 
|  | 7276 | break; | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 7277 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7278 | } | 
|  | 7279 |  | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 7280 | if (symbol_context_scope) | 
|  | 7281 | { | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7282 | var_sp.reset (new Variable (MakeUserID(die->GetOffset()), | 
|  | 7283 | name, | 
|  | 7284 | mangled, | 
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7285 | SymbolFileTypeSP (new SymbolFileType(*this, type_uid)), | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7286 | scope, | 
|  | 7287 | symbol_context_scope, | 
|  | 7288 | &decl, | 
|  | 7289 | location, | 
|  | 7290 | is_external, | 
|  | 7291 | is_artificial)); | 
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 7292 |  | 
|  | 7293 | var_sp->SetLocationIsConstantValueData (location_is_const_value_data); | 
|  | 7294 | } | 
|  | 7295 | else | 
|  | 7296 | { | 
|  | 7297 | // Not ready to parse this variable yet. It might be a global | 
|  | 7298 | // or static variable that is in a function scope and the function | 
|  | 7299 | // in the symbol context wasn't filled in yet | 
|  | 7300 | return var_sp; | 
|  | 7301 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7302 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7303 | } | 
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7304 | // Cache var_sp even if NULL (the variable was just a specification or | 
|  | 7305 | // was missing vital information to be able to be displayed in the debugger | 
|  | 7306 | // (missing location due to optimization, etc)) so we don't re-parse | 
|  | 7307 | // this DIE over and over later... | 
|  | 7308 | m_die_to_variable_sp[die] = var_sp; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7309 | } | 
|  | 7310 | return var_sp; | 
|  | 7311 | } | 
|  | 7312 |  | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7313 |  | 
|  | 7314 | const DWARFDebugInfoEntry * | 
|  | 7315 | SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset, | 
|  | 7316 | dw_offset_t spec_block_die_offset, | 
|  | 7317 | DWARFCompileUnit **result_die_cu_handle) | 
|  | 7318 | { | 
|  | 7319 | // Give the concrete function die specified by "func_die_offset", find the | 
|  | 7320 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points | 
|  | 7321 | // to "spec_block_die_offset" | 
|  | 7322 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 7323 |  | 
|  | 7324 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle); | 
|  | 7325 | if (die) | 
|  | 7326 | { | 
|  | 7327 | assert (*result_die_cu_handle); | 
|  | 7328 | return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle); | 
|  | 7329 | } | 
|  | 7330 | return NULL; | 
|  | 7331 | } | 
|  | 7332 |  | 
|  | 7333 |  | 
|  | 7334 | const DWARFDebugInfoEntry * | 
|  | 7335 | SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu, | 
|  | 7336 | const DWARFDebugInfoEntry *die, | 
|  | 7337 | dw_offset_t spec_block_die_offset, | 
|  | 7338 | DWARFCompileUnit **result_die_cu_handle) | 
|  | 7339 | { | 
|  | 7340 | if (die) | 
|  | 7341 | { | 
|  | 7342 | switch (die->Tag()) | 
|  | 7343 | { | 
|  | 7344 | case DW_TAG_subprogram: | 
|  | 7345 | case DW_TAG_inlined_subroutine: | 
|  | 7346 | case DW_TAG_lexical_block: | 
|  | 7347 | { | 
|  | 7348 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset) | 
|  | 7349 | { | 
|  | 7350 | *result_die_cu_handle = dwarf_cu; | 
|  | 7351 | return die; | 
|  | 7352 | } | 
|  | 7353 |  | 
|  | 7354 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset) | 
|  | 7355 | { | 
|  | 7356 | *result_die_cu_handle = dwarf_cu; | 
|  | 7357 | return die; | 
|  | 7358 | } | 
|  | 7359 | } | 
|  | 7360 | break; | 
|  | 7361 | } | 
|  | 7362 |  | 
|  | 7363 | // Give the concrete function die specified by "func_die_offset", find the | 
|  | 7364 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points | 
|  | 7365 | // to "spec_block_die_offset" | 
|  | 7366 | for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling()) | 
|  | 7367 | { | 
|  | 7368 | const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu, | 
|  | 7369 | child_die, | 
|  | 7370 | spec_block_die_offset, | 
|  | 7371 | result_die_cu_handle); | 
|  | 7372 | if (result_die) | 
|  | 7373 | return result_die; | 
|  | 7374 | } | 
|  | 7375 | } | 
|  | 7376 |  | 
|  | 7377 | *result_die_cu_handle = NULL; | 
|  | 7378 | return NULL; | 
|  | 7379 | } | 
|  | 7380 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7381 | size_t | 
|  | 7382 | SymbolFileDWARF::ParseVariables | 
|  | 7383 | ( | 
|  | 7384 | const SymbolContext& sc, | 
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 7385 | DWARFCompileUnit* dwarf_cu, | 
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 7386 | const lldb::addr_t func_low_pc, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7387 | const DWARFDebugInfoEntry *orig_die, | 
|  | 7388 | bool parse_siblings, | 
|  | 7389 | bool parse_children, | 
|  | 7390 | VariableList* cc_variable_list | 
|  | 7391 | ) | 
|  | 7392 | { | 
|  | 7393 | if (orig_die == NULL) | 
|  | 7394 | return 0; | 
|  | 7395 |  | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7396 | VariableListSP variable_list_sp; | 
|  | 7397 |  | 
|  | 7398 | size_t vars_added = 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7399 | const DWARFDebugInfoEntry *die = orig_die; | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7400 | while (die != NULL) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7401 | { | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7402 | dw_tag_t tag = die->Tag(); | 
|  | 7403 |  | 
|  | 7404 | // Check to see if we have already parsed this variable or constant? | 
|  | 7405 | if (m_die_to_variable_sp[die]) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7406 | { | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7407 | if (cc_variable_list) | 
|  | 7408 | cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7409 | } | 
|  | 7410 | else | 
|  | 7411 | { | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7412 | // We haven't already parsed it, lets do that now. | 
|  | 7413 | if ((tag == DW_TAG_variable) || | 
|  | 7414 | (tag == DW_TAG_constant) || | 
|  | 7415 | (tag == DW_TAG_formal_parameter && sc.function)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7416 | { | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7417 | if (variable_list_sp.get() == NULL) | 
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7418 | { | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7419 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die); | 
|  | 7420 | dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; | 
|  | 7421 | switch (parent_tag) | 
|  | 7422 | { | 
|  | 7423 | case DW_TAG_compile_unit: | 
|  | 7424 | if (sc.comp_unit != NULL) | 
|  | 7425 | { | 
|  | 7426 | variable_list_sp = sc.comp_unit->GetVariableList(false); | 
|  | 7427 | if (variable_list_sp.get() == NULL) | 
|  | 7428 | { | 
|  | 7429 | variable_list_sp.reset(new VariableList()); | 
|  | 7430 | sc.comp_unit->SetVariableList(variable_list_sp); | 
|  | 7431 | } | 
|  | 7432 | } | 
|  | 7433 | else | 
|  | 7434 | { | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 7435 | 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] | 7436 | MakeUserID(sc_parent_die->GetOffset()), | 
|  | 7437 | DW_TAG_value_to_name (parent_tag), | 
|  | 7438 | MakeUserID(orig_die->GetOffset()), | 
|  | 7439 | DW_TAG_value_to_name (orig_die->Tag())); | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7440 | } | 
|  | 7441 | break; | 
|  | 7442 |  | 
|  | 7443 | case DW_TAG_subprogram: | 
|  | 7444 | case DW_TAG_inlined_subroutine: | 
|  | 7445 | case DW_TAG_lexical_block: | 
|  | 7446 | if (sc.function != NULL) | 
|  | 7447 | { | 
|  | 7448 | // Check to see if we already have parsed the variables for the given scope | 
|  | 7449 |  | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7450 | Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7451 | if (block == NULL) | 
|  | 7452 | { | 
|  | 7453 | // This must be a specification or abstract origin with | 
|  | 7454 | // a concrete block couterpart in the current function. We need | 
|  | 7455 | // to find the concrete block so we can correctly add the | 
|  | 7456 | // variable to it | 
|  | 7457 | DWARFCompileUnit *concrete_block_die_cu = dwarf_cu; | 
|  | 7458 | const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(), | 
|  | 7459 | sc_parent_die->GetOffset(), | 
|  | 7460 | &concrete_block_die_cu); | 
|  | 7461 | if (concrete_block_die) | 
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7462 | block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset())); | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7463 | } | 
|  | 7464 |  | 
|  | 7465 | if (block != NULL) | 
|  | 7466 | { | 
|  | 7467 | const bool can_create = false; | 
|  | 7468 | variable_list_sp = block->GetBlockVariableList (can_create); | 
|  | 7469 | if (variable_list_sp.get() == NULL) | 
|  | 7470 | { | 
|  | 7471 | variable_list_sp.reset(new VariableList()); | 
|  | 7472 | block->SetVariableList(variable_list_sp); | 
|  | 7473 | } | 
|  | 7474 | } | 
|  | 7475 | } | 
|  | 7476 | break; | 
|  | 7477 |  | 
|  | 7478 | default: | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 7479 | 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] | 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 | break; | 
|  | 7483 | } | 
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7484 | } | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7485 |  | 
|  | 7486 | if (variable_list_sp) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7487 | { | 
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7488 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc)); | 
|  | 7489 | if (var_sp) | 
|  | 7490 | { | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7491 | variable_list_sp->AddVariableIfUnique (var_sp); | 
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7492 | if (cc_variable_list) | 
|  | 7493 | cc_variable_list->AddVariableIfUnique (var_sp); | 
|  | 7494 | ++vars_added; | 
|  | 7495 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7496 | } | 
|  | 7497 | } | 
|  | 7498 | } | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7499 |  | 
|  | 7500 | bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram); | 
|  | 7501 |  | 
|  | 7502 | if (!skip_children && parse_children && die->HasChildren()) | 
|  | 7503 | { | 
|  | 7504 | vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list); | 
|  | 7505 | } | 
|  | 7506 |  | 
|  | 7507 | if (parse_siblings) | 
|  | 7508 | die = die->GetSibling(); | 
|  | 7509 | else | 
|  | 7510 | die = NULL; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7511 | } | 
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7512 | return vars_added; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7513 | } | 
|  | 7514 |  | 
|  | 7515 | //------------------------------------------------------------------ | 
|  | 7516 | // PluginInterface protocol | 
|  | 7517 | //------------------------------------------------------------------ | 
|  | 7518 | const char * | 
|  | 7519 | SymbolFileDWARF::GetPluginName() | 
|  | 7520 | { | 
|  | 7521 | return "SymbolFileDWARF"; | 
|  | 7522 | } | 
|  | 7523 |  | 
|  | 7524 | const char * | 
|  | 7525 | SymbolFileDWARF::GetShortPluginName() | 
|  | 7526 | { | 
|  | 7527 | return GetPluginNameStatic(); | 
|  | 7528 | } | 
|  | 7529 |  | 
|  | 7530 | uint32_t | 
|  | 7531 | SymbolFileDWARF::GetPluginVersion() | 
|  | 7532 | { | 
|  | 7533 | return 1; | 
|  | 7534 | } | 
|  | 7535 |  | 
|  | 7536 | void | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 7537 | SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl) | 
|  | 7538 | { | 
|  | 7539 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; | 
|  | 7540 | clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); | 
|  | 7541 | if (clang_type) | 
|  | 7542 | symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); | 
|  | 7543 | } | 
|  | 7544 |  | 
|  | 7545 | void | 
|  | 7546 | SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl) | 
|  | 7547 | { | 
|  | 7548 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; | 
|  | 7549 | clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); | 
|  | 7550 | if (clang_type) | 
|  | 7551 | symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); | 
|  | 7552 | } | 
|  | 7553 |  | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7554 | void | 
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7555 | SymbolFileDWARF::DumpIndexes () | 
|  | 7556 | { | 
|  | 7557 | StreamFile s(stdout, false); | 
|  | 7558 |  | 
|  | 7559 | s.Printf ("DWARF index for (%s) '%s/%s':", | 
|  | 7560 | GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(), | 
|  | 7561 | GetObjectFile()->GetFileSpec().GetDirectory().AsCString(), | 
|  | 7562 | GetObjectFile()->GetFileSpec().GetFilename().AsCString()); | 
|  | 7563 | s.Printf("\nFunction basenames:\n");    m_function_basename_index.Dump (&s); | 
|  | 7564 | s.Printf("\nFunction fullnames:\n");    m_function_fullname_index.Dump (&s); | 
|  | 7565 | s.Printf("\nFunction methods:\n");      m_function_method_index.Dump (&s); | 
|  | 7566 | s.Printf("\nFunction selectors:\n");    m_function_selector_index.Dump (&s); | 
|  | 7567 | s.Printf("\nObjective C class selectors:\n");    m_objc_class_selectors_index.Dump (&s); | 
|  | 7568 | s.Printf("\nGlobals and statics:\n");   m_global_index.Dump (&s); | 
|  | 7569 | s.Printf("\nTypes:\n");                 m_type_index.Dump (&s); | 
|  | 7570 | s.Printf("\nNamepaces:\n");             m_namespace_index.Dump (&s); | 
|  | 7571 | } | 
|  | 7572 |  | 
|  | 7573 | void | 
|  | 7574 | SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context, | 
|  | 7575 | const char *name, | 
|  | 7576 | llvm::SmallVectorImpl <clang::NamedDecl *> *results) | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7577 | { | 
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7578 | DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context); | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7579 |  | 
|  | 7580 | if (iter == m_decl_ctx_to_die.end()) | 
|  | 7581 | return; | 
|  | 7582 |  | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7583 | 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] | 7584 | { | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7585 | const DWARFDebugInfoEntry *context_die = *pos; | 
|  | 7586 |  | 
|  | 7587 | if (!results) | 
|  | 7588 | return; | 
|  | 7589 |  | 
|  | 7590 | DWARFDebugInfo* info = DebugInfo(); | 
|  | 7591 |  | 
|  | 7592 | DIEArray die_offsets; | 
|  | 7593 |  | 
|  | 7594 | DWARFCompileUnit* dwarf_cu = NULL; | 
|  | 7595 | const DWARFDebugInfoEntry* die = NULL; | 
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 7596 |  | 
|  | 7597 | if (m_using_apple_tables) | 
|  | 7598 | { | 
|  | 7599 | if (m_apple_types_ap.get()) | 
|  | 7600 | m_apple_types_ap->FindByName (name, die_offsets); | 
|  | 7601 | } | 
|  | 7602 | else | 
|  | 7603 | { | 
|  | 7604 | if (!m_indexed) | 
|  | 7605 | Index (); | 
|  | 7606 |  | 
|  | 7607 | m_type_index.Find (ConstString(name), die_offsets); | 
|  | 7608 | } | 
|  | 7609 |  | 
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 7610 | const size_t num_matches = die_offsets.size(); | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7611 |  | 
|  | 7612 | if (num_matches) | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7613 | { | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7614 | for (size_t i = 0; i < num_matches; ++i) | 
|  | 7615 | { | 
|  | 7616 | const dw_offset_t die_offset = die_offsets[i]; | 
|  | 7617 | die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); | 
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7618 |  | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7619 | if (die->GetParent() != context_die) | 
|  | 7620 | continue; | 
|  | 7621 |  | 
|  | 7622 | Type *matching_type = ResolveType (dwarf_cu, die); | 
|  | 7623 |  | 
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 7624 | lldb::clang_type_t type = matching_type->GetClangForwardType(); | 
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7625 | clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type); | 
|  | 7626 |  | 
|  | 7627 | if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr())) | 
|  | 7628 | { | 
|  | 7629 | clang::TagDecl *tag_decl = tag_type->getDecl(); | 
|  | 7630 | results->push_back(tag_decl); | 
|  | 7631 | } | 
|  | 7632 | else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr())) | 
|  | 7633 | { | 
|  | 7634 | clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl(); | 
|  | 7635 | results->push_back(typedef_decl); | 
|  | 7636 | } | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7637 | } | 
|  | 7638 | } | 
|  | 7639 | } | 
|  | 7640 | } | 
|  | 7641 |  | 
|  | 7642 | void | 
|  | 7643 | SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton, | 
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 7644 | const clang::DeclContext *decl_context, | 
|  | 7645 | clang::DeclarationName decl_name, | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7646 | llvm::SmallVectorImpl <clang::NamedDecl *> *results) | 
|  | 7647 | { | 
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 7648 |  | 
|  | 7649 | switch (decl_context->getDeclKind()) | 
|  | 7650 | { | 
|  | 7651 | case clang::Decl::Namespace: | 
|  | 7652 | case clang::Decl::TranslationUnit: | 
|  | 7653 | { | 
|  | 7654 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; | 
|  | 7655 | symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results); | 
|  | 7656 | } | 
|  | 7657 | break; | 
|  | 7658 | default: | 
|  | 7659 | break; | 
|  | 7660 | } | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7661 | } | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7662 |  | 
|  | 7663 | bool | 
|  | 7664 | SymbolFileDWARF::LayoutRecordType (void *baton, | 
|  | 7665 | const clang::RecordDecl *record_decl, | 
|  | 7666 | uint64_t &size, | 
|  | 7667 | uint64_t &alignment, | 
|  | 7668 | llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, | 
|  | 7669 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, | 
|  | 7670 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) | 
|  | 7671 | { | 
|  | 7672 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; | 
|  | 7673 | return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets); | 
|  | 7674 | } | 
|  | 7675 |  | 
|  | 7676 |  | 
|  | 7677 | bool | 
|  | 7678 | SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl, | 
|  | 7679 | uint64_t &bit_size, | 
|  | 7680 | uint64_t &alignment, | 
|  | 7681 | llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, | 
|  | 7682 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, | 
|  | 7683 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) | 
|  | 7684 | { | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 7685 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7686 | RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl); | 
|  | 7687 | bool success = false; | 
|  | 7688 | base_offsets.clear(); | 
|  | 7689 | vbase_offsets.clear(); | 
|  | 7690 | if (pos != m_record_decl_to_layout_map.end()) | 
|  | 7691 | { | 
|  | 7692 | bit_size = pos->second.bit_size; | 
|  | 7693 | alignment = pos->second.alignment; | 
|  | 7694 | field_offsets.swap(pos->second.field_offsets); | 
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 7695 | base_offsets.swap (pos->second.base_offsets); | 
|  | 7696 | vbase_offsets.swap (pos->second.vbase_offsets); | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7697 | m_record_decl_to_layout_map.erase(pos); | 
|  | 7698 | success = true; | 
|  | 7699 | } | 
|  | 7700 | else | 
|  | 7701 | { | 
|  | 7702 | bit_size = 0; | 
|  | 7703 | alignment = 0; | 
|  | 7704 | field_offsets.clear(); | 
|  | 7705 | } | 
|  | 7706 |  | 
|  | 7707 | if (log) | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 7708 | GetObjectFile()->GetModule()->LogMessage (log, | 
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 7709 | "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] | 7710 | record_decl, | 
|  | 7711 | bit_size, | 
|  | 7712 | alignment, | 
|  | 7713 | (uint32_t)field_offsets.size(), | 
|  | 7714 | (uint32_t)base_offsets.size(), | 
|  | 7715 | (uint32_t)vbase_offsets.size(), | 
|  | 7716 | success); | 
|  | 7717 | return success; | 
|  | 7718 | } | 
|  | 7719 |  | 
|  | 7720 |  | 
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 7721 | SymbolFileDWARFDebugMap * | 
|  | 7722 | SymbolFileDWARF::GetDebugMapSymfile () | 
|  | 7723 | { | 
|  | 7724 | if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired()) | 
|  | 7725 | { | 
|  | 7726 | lldb::ModuleSP module_sp (m_debug_map_module_wp.lock()); | 
|  | 7727 | if (module_sp) | 
|  | 7728 | { | 
|  | 7729 | SymbolVendor *sym_vendor = module_sp->GetSymbolVendor(); | 
|  | 7730 | if (sym_vendor) | 
|  | 7731 | m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile(); | 
|  | 7732 | } | 
|  | 7733 | } | 
|  | 7734 | return m_debug_map_symfile; | 
|  | 7735 | } | 
|  | 7736 |  | 
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7737 |  |