| 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 | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame^] | 3325 | // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup() |
| 3326 | assert ((name_type_mask & eFunctionNameTypeAuto) == 0); |
| 3327 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3328 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3329 | |
| 3330 | if (log) |
| 3331 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3332 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3333 | "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)", |
| 3334 | name.GetCString(), |
| 3335 | name_type_mask, |
| 3336 | append); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3337 | } |
| 3338 | |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3339 | // If we aren't appending the results to this list, then clear the list |
| 3340 | if (!append) |
| 3341 | sc_list.Clear(); |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3342 | |
| 3343 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) |
| 3344 | return 0; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3345 | |
| 3346 | // If name is empty then we won't find anything. |
| 3347 | if (name.IsEmpty()) |
| 3348 | return 0; |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3349 | |
| 3350 | // Remember how many sc_list are in the list before we search in case |
| 3351 | // we are appending the results to a variable list. |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3352 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3353 | const char *name_cstr = name.GetCString(); |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame^] | 3354 | |
| 3355 | const uint32_t original_size = sc_list.GetSize(); |
| 3356 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3357 | DWARFDebugInfo* info = DebugInfo(); |
| 3358 | if (info == NULL) |
| 3359 | return 0; |
| 3360 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3361 | DWARFCompileUnit *dwarf_cu = NULL; |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame^] | 3362 | std::set<const DWARFDebugInfoEntry *> resolved_dies; |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3363 | if (m_using_apple_tables) |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 3364 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3365 | if (m_apple_names_ap.get()) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3366 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3367 | |
| 3368 | DIEArray die_offsets; |
| 3369 | |
| 3370 | uint32_t num_matches = 0; |
| 3371 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame^] | 3372 | if (name_type_mask & eFunctionNameTypeFull) |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3373 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3374 | // If they asked for the full name, match what they typed. At some point we may |
| 3375 | // want to canonicalize this (strip double spaces, etc. For now, we just add all the |
| 3376 | // dies that we find by exact match. |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3377 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3378 | for (uint32_t i = 0; i < num_matches; i++) |
| 3379 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3380 | const dw_offset_t die_offset = die_offsets[i]; |
| 3381 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3382 | if (die) |
| 3383 | { |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3384 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3385 | continue; |
| 3386 | |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3387 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) |
| 3388 | continue; |
| 3389 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame^] | 3390 | if (resolved_dies.find(die) == resolved_dies.end()) |
| 3391 | { |
| 3392 | if (ResolveFunction (dwarf_cu, die, sc_list)) |
| 3393 | resolved_dies.insert(die); |
| 3394 | } |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3395 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3396 | else |
| 3397 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3398 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 3399 | die_offset, name_cstr); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3400 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3401 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3402 | } |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame^] | 3403 | |
| 3404 | if (name_type_mask & eFunctionNameTypeSelector) |
| 3405 | { |
| 3406 | if (namespace_decl && *namespace_decl) |
| 3407 | return 0; // no selectors in namespaces |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3408 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame^] | 3409 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); |
| 3410 | // Now make sure these are actually ObjC methods. In this case we can simply look up the name, |
| 3411 | // and if it is an ObjC method name, we're good. |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3412 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame^] | 3413 | for (uint32_t i = 0; i < num_matches; i++) |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3414 | { |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame^] | 3415 | const dw_offset_t die_offset = die_offsets[i]; |
| 3416 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| 3417 | if (die) |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3418 | { |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame^] | 3419 | const char *die_name = die->GetName(this, dwarf_cu); |
| 3420 | if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name)) |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3421 | { |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3422 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) |
| 3423 | continue; |
| 3424 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame^] | 3425 | if (resolved_dies.find(die) == resolved_dies.end()) |
| 3426 | { |
| 3427 | if (ResolveFunction (dwarf_cu, die, sc_list)) |
| 3428 | resolved_dies.insert(die); |
| 3429 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3430 | } |
| 3431 | } |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame^] | 3432 | else |
| 3433 | { |
| 3434 | GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 3435 | die_offset, name_cstr); |
| 3436 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3437 | } |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame^] | 3438 | die_offsets.clear(); |
| 3439 | } |
| 3440 | |
| 3441 | if (((name_type_mask & eFunctionNameTypeMethod) && !namespace_decl) || name_type_mask & eFunctionNameTypeBase) |
| 3442 | { |
| 3443 | // The apple_names table stores just the "base name" of C++ methods in the table. So we have to |
| 3444 | // extract the base name, look that up, and if there is any other information in the name we were |
| 3445 | // passed in we have to post-filter based on that. |
| 3446 | |
| 3447 | // FIXME: Arrange the logic above so that we don't calculate the base name twice: |
| 3448 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); |
| 3449 | |
| 3450 | for (uint32_t i = 0; i < num_matches; i++) |
| 3451 | { |
| 3452 | const dw_offset_t die_offset = die_offsets[i]; |
| 3453 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| 3454 | if (die) |
| 3455 | { |
| 3456 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) |
| 3457 | continue; |
| 3458 | |
| 3459 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3460 | continue; |
| 3461 | |
| 3462 | // If we get to here, the die is good, and we should add it: |
| 3463 | if (resolved_dies.find(die) == resolved_dies.end()) |
| 3464 | if (ResolveFunction (dwarf_cu, die, sc_list)) |
| 3465 | { |
| 3466 | bool keep_die = true; |
| 3467 | if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod)) |
| 3468 | { |
| 3469 | // We are looking for either basenames or methods, so we need to |
| 3470 | // trim out the ones we won't want by looking at the type |
| 3471 | SymbolContext sc; |
| 3472 | if (sc_list.GetLastContext(sc)) |
| 3473 | { |
| 3474 | if (sc.block) |
| 3475 | { |
| 3476 | // We have an inlined function |
| 3477 | } |
| 3478 | else if (sc.function) |
| 3479 | { |
| 3480 | Type *type = sc.function->GetType(); |
| 3481 | |
| 3482 | clang::DeclContext* decl_ctx = GetClangDeclContextContainingTypeUID (type->GetID()); |
| 3483 | if (decl_ctx->isRecord()) |
| 3484 | { |
| 3485 | if (name_type_mask & eFunctionNameTypeBase) |
| 3486 | { |
| 3487 | sc_list.RemoveContextAtIndex(sc_list.GetSize()-1); |
| 3488 | keep_die = false; |
| 3489 | } |
| 3490 | } |
| 3491 | else |
| 3492 | { |
| 3493 | if (name_type_mask & eFunctionNameTypeMethod) |
| 3494 | { |
| 3495 | sc_list.RemoveContextAtIndex(sc_list.GetSize()-1); |
| 3496 | keep_die = false; |
| 3497 | } |
| 3498 | } |
| 3499 | } |
| 3500 | } |
| 3501 | } |
| 3502 | if (keep_die) |
| 3503 | resolved_dies.insert(die); |
| 3504 | } |
| 3505 | } |
| 3506 | else |
| 3507 | { |
| 3508 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 3509 | die_offset, name_cstr); |
| 3510 | } |
| 3511 | } |
| 3512 | die_offsets.clear(); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3513 | } |
| 3514 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3515 | } |
| 3516 | else |
| 3517 | { |
| 3518 | |
| 3519 | // Index the DWARF if we haven't already |
| 3520 | if (!m_indexed) |
| 3521 | Index (); |
| 3522 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3523 | if (name_type_mask & eFunctionNameTypeFull) |
| 3524 | FindFunctions (name, m_function_fullname_index, sc_list); |
| 3525 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3526 | DIEArray die_offsets; |
| 3527 | DWARFCompileUnit *dwarf_cu = NULL; |
| 3528 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame^] | 3529 | if (name_type_mask & eFunctionNameTypeBase) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3530 | { |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame^] | 3531 | uint32_t num_base = m_function_basename_index.Find(name, die_offsets); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3532 | for (uint32_t i = 0; i < num_base; i++) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3533 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3534 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); |
| 3535 | if (die) |
| 3536 | { |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3537 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) |
| 3538 | continue; |
| 3539 | |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3540 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3541 | continue; |
| 3542 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3543 | // If we get to here, the die is good, and we should add it: |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame^] | 3544 | if (resolved_dies.find(die) == resolved_dies.end()) |
| 3545 | { |
| 3546 | if (ResolveFunction (dwarf_cu, die, sc_list)) |
| 3547 | resolved_dies.insert(die); |
| 3548 | } |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3549 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3550 | } |
| 3551 | die_offsets.clear(); |
| 3552 | } |
| 3553 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame^] | 3554 | if (name_type_mask & eFunctionNameTypeMethod) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3555 | { |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3556 | if (namespace_decl && *namespace_decl) |
| 3557 | return 0; // no methods in namespaces |
| 3558 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame^] | 3559 | uint32_t num_base = m_function_method_index.Find(name, die_offsets); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3560 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3561 | for (uint32_t i = 0; i < num_base; i++) |
| 3562 | { |
| 3563 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); |
| 3564 | if (die) |
| 3565 | { |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3566 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) |
| 3567 | continue; |
| 3568 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3569 | // If we get to here, the die is good, and we should add it: |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame^] | 3570 | if (resolved_dies.find(die) == resolved_dies.end()) |
| 3571 | { |
| 3572 | if (ResolveFunction (dwarf_cu, die, sc_list)) |
| 3573 | resolved_dies.insert(die); |
| 3574 | } |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3575 | } |
| 3576 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3577 | } |
| 3578 | die_offsets.clear(); |
| 3579 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3580 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame^] | 3581 | if ((name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl)) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3582 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3583 | FindFunctions (name, m_function_selector_index, sc_list); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3584 | } |
| 3585 | |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 3586 | } |
| 3587 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3588 | // Return the number of variable that were appended to the list |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3589 | const uint32_t num_matches = sc_list.GetSize() - original_size; |
| 3590 | |
| 3591 | if (log && num_matches > 0) |
| 3592 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3593 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3594 | "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list) => %u", |
| 3595 | name.GetCString(), |
| 3596 | name_type_mask, |
| 3597 | append, |
| 3598 | num_matches); |
| 3599 | } |
| 3600 | return num_matches; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3601 | } |
| 3602 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3603 | uint32_t |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3604 | 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] | 3605 | { |
| 3606 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 3607 | "SymbolFileDWARF::FindFunctions (regex = '%s')", |
| 3608 | regex.GetText()); |
| 3609 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3610 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3611 | |
| 3612 | if (log) |
| 3613 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3614 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3615 | "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)", |
| 3616 | regex.GetText(), |
| 3617 | append); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3618 | } |
| 3619 | |
| 3620 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3621 | // If we aren't appending the results to this list, then clear the list |
| 3622 | if (!append) |
| 3623 | sc_list.Clear(); |
| 3624 | |
| 3625 | // Remember how many sc_list are in the list before we search in case |
| 3626 | // we are appending the results to a variable list. |
| 3627 | uint32_t original_size = sc_list.GetSize(); |
| 3628 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3629 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3630 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3631 | if (m_apple_names_ap.get()) |
| 3632 | FindFunctions (regex, *m_apple_names_ap, sc_list); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3633 | } |
| 3634 | else |
| 3635 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3636 | // Index the DWARF if we haven't already |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3637 | if (!m_indexed) |
| 3638 | Index (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3639 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3640 | FindFunctions (regex, m_function_basename_index, sc_list); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3641 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3642 | FindFunctions (regex, m_function_fullname_index, sc_list); |
| 3643 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3644 | |
| 3645 | // Return the number of variable that were appended to the list |
| 3646 | return sc_list.GetSize() - original_size; |
| 3647 | } |
| Jim Ingham | 318c9f2 | 2011-08-26 19:44:13 +0000 | [diff] [blame] | 3648 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3649 | uint32_t |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3650 | SymbolFileDWARF::FindTypes (const SymbolContext& sc, |
| 3651 | const ConstString &name, |
| 3652 | const lldb_private::ClangNamespaceDecl *namespace_decl, |
| 3653 | bool append, |
| 3654 | uint32_t max_matches, |
| 3655 | TypeList& types) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3656 | { |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3657 | DWARFDebugInfo* info = DebugInfo(); |
| 3658 | if (info == NULL) |
| 3659 | return 0; |
| 3660 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3661 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3662 | |
| 3663 | if (log) |
| 3664 | { |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3665 | if (namespace_decl) |
| 3666 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3667 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3668 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)", |
| 3669 | name.GetCString(), |
| 3670 | namespace_decl->GetNamespaceDecl(), |
| 3671 | namespace_decl->GetQualifiedName().c_str(), |
| 3672 | append, |
| 3673 | max_matches); |
| 3674 | } |
| 3675 | else |
| 3676 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3677 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3678 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)", |
| 3679 | name.GetCString(), |
| 3680 | append, |
| 3681 | max_matches); |
| 3682 | } |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3683 | } |
| 3684 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3685 | // If we aren't appending the results to this list, then clear the list |
| 3686 | if (!append) |
| 3687 | types.Clear(); |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3688 | |
| 3689 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) |
| 3690 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3691 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3692 | DIEArray die_offsets; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3693 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3694 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3695 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3696 | if (m_apple_types_ap.get()) |
| 3697 | { |
| 3698 | const char *name_cstr = name.GetCString(); |
| 3699 | m_apple_types_ap->FindByName (name_cstr, die_offsets); |
| 3700 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3701 | } |
| 3702 | else |
| 3703 | { |
| 3704 | if (!m_indexed) |
| 3705 | Index (); |
| 3706 | |
| 3707 | m_type_index.Find (name, die_offsets); |
| 3708 | } |
| 3709 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3710 | const size_t num_die_matches = die_offsets.size(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3711 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3712 | if (num_die_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3713 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3714 | const uint32_t initial_types_size = types.GetSize(); |
| 3715 | DWARFCompileUnit* dwarf_cu = NULL; |
| 3716 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3717 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3718 | for (size_t i=0; i<num_die_matches; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3719 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3720 | const dw_offset_t die_offset = die_offsets[i]; |
| 3721 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| 3722 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3723 | if (die) |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 3724 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3725 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3726 | continue; |
| 3727 | |
| 3728 | Type *matching_type = ResolveType (dwarf_cu, die); |
| 3729 | if (matching_type) |
| 3730 | { |
| 3731 | // 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] | 3732 | types.InsertUnique (matching_type->shared_from_this()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3733 | if (types.GetSize() >= max_matches) |
| 3734 | break; |
| 3735 | } |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 3736 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3737 | else |
| 3738 | { |
| 3739 | if (m_using_apple_tables) |
| 3740 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3741 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 3742 | die_offset, name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3743 | } |
| 3744 | } |
| 3745 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3746 | } |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3747 | const uint32_t num_matches = types.GetSize() - initial_types_size; |
| 3748 | if (log && num_matches) |
| 3749 | { |
| 3750 | if (namespace_decl) |
| 3751 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3752 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3753 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u", |
| 3754 | name.GetCString(), |
| 3755 | namespace_decl->GetNamespaceDecl(), |
| 3756 | namespace_decl->GetQualifiedName().c_str(), |
| 3757 | append, |
| 3758 | max_matches, |
| 3759 | num_matches); |
| 3760 | } |
| 3761 | else |
| 3762 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3763 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3764 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u", |
| 3765 | name.GetCString(), |
| 3766 | append, |
| 3767 | max_matches, |
| 3768 | num_matches); |
| 3769 | } |
| 3770 | } |
| 3771 | return num_matches; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3772 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3773 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3774 | } |
| 3775 | |
| 3776 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3777 | ClangNamespaceDecl |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3778 | SymbolFileDWARF::FindNamespace (const SymbolContext& sc, |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3779 | const ConstString &name, |
| 3780 | const lldb_private::ClangNamespaceDecl *parent_namespace_decl) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3781 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3782 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3783 | |
| 3784 | if (log) |
| 3785 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3786 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3787 | "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")", |
| 3788 | name.GetCString()); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3789 | } |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3790 | |
| 3791 | if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl)) |
| 3792 | return ClangNamespaceDecl(); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3793 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3794 | ClangNamespaceDecl namespace_decl; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3795 | DWARFDebugInfo* info = DebugInfo(); |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3796 | if (info) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3797 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3798 | DIEArray die_offsets; |
| 3799 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3800 | // Index if we already haven't to make sure the compile units |
| 3801 | // get indexed and make their global DIE index list |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3802 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3803 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3804 | if (m_apple_namespaces_ap.get()) |
| 3805 | { |
| 3806 | const char *name_cstr = name.GetCString(); |
| 3807 | m_apple_namespaces_ap->FindByName (name_cstr, die_offsets); |
| 3808 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3809 | } |
| 3810 | else |
| 3811 | { |
| 3812 | if (!m_indexed) |
| 3813 | Index (); |
| 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 | m_namespace_index.Find (name, die_offsets); |
| 3816 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3817 | |
| 3818 | DWARFCompileUnit* dwarf_cu = NULL; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3819 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3820 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3821 | if (num_matches) |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3822 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3823 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3824 | for (size_t i=0; i<num_matches; ++i) |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3825 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3826 | const dw_offset_t die_offset = die_offsets[i]; |
| 3827 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3828 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3829 | if (die) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3830 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3831 | if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die)) |
| 3832 | continue; |
| 3833 | |
| 3834 | clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die); |
| 3835 | if (clang_namespace_decl) |
| 3836 | { |
| 3837 | namespace_decl.SetASTContext (GetClangASTContext().getASTContext()); |
| 3838 | namespace_decl.SetNamespaceDecl (clang_namespace_decl); |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3839 | break; |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3840 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3841 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3842 | else |
| 3843 | { |
| 3844 | if (m_using_apple_tables) |
| 3845 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3846 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n", |
| 3847 | die_offset, name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3848 | } |
| 3849 | } |
| 3850 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3851 | } |
| 3852 | } |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3853 | } |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3854 | if (log && namespace_decl.GetNamespaceDecl()) |
| 3855 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3856 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3857 | "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"", |
| 3858 | name.GetCString(), |
| 3859 | namespace_decl.GetNamespaceDecl(), |
| 3860 | namespace_decl.GetQualifiedName().c_str()); |
| 3861 | } |
| 3862 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3863 | return namespace_decl; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3864 | } |
| 3865 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3866 | uint32_t |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3867 | 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] | 3868 | { |
| 3869 | // Remember how many sc_list are in the list before we search in case |
| 3870 | // we are appending the results to a variable list. |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3871 | uint32_t original_size = types.GetSize(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3872 | |
| 3873 | const uint32_t num_die_offsets = die_offsets.size(); |
| 3874 | // Parse all of the types we found from the pubtypes matches |
| 3875 | uint32_t i; |
| 3876 | uint32_t num_matches = 0; |
| 3877 | for (i = 0; i < num_die_offsets; ++i) |
| 3878 | { |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3879 | Type *matching_type = ResolveTypeUID (die_offsets[i]); |
| 3880 | if (matching_type) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3881 | { |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3882 | // 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] | 3883 | types.InsertUnique (matching_type->shared_from_this()); |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3884 | ++num_matches; |
| 3885 | if (num_matches >= max_matches) |
| 3886 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3887 | } |
| 3888 | } |
| 3889 | |
| 3890 | // Return the number of variable that were appended to the list |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3891 | return types.GetSize() - original_size; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3892 | } |
| 3893 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3894 | |
| 3895 | size_t |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3896 | SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc, |
| 3897 | clang::DeclContext *containing_decl_ctx, |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3898 | DWARFCompileUnit* dwarf_cu, |
| 3899 | const DWARFDebugInfoEntry *parent_die, |
| 3900 | bool skip_artificial, |
| 3901 | bool &is_static, |
| 3902 | TypeList* type_list, |
| 3903 | std::vector<clang_type_t>& function_param_types, |
| 3904 | std::vector<clang::ParmVarDecl*>& function_param_decls, |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 3905 | unsigned &type_quals, |
| 3906 | ClangASTContext::TemplateParameterInfos &template_param_infos) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3907 | { |
| 3908 | if (parent_die == NULL) |
| 3909 | return 0; |
| 3910 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3911 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| 3912 | |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3913 | size_t arg_idx = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3914 | const DWARFDebugInfoEntry *die; |
| 3915 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 3916 | { |
| 3917 | dw_tag_t tag = die->Tag(); |
| 3918 | switch (tag) |
| 3919 | { |
| 3920 | case DW_TAG_formal_parameter: |
| 3921 | { |
| 3922 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3923 | 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] | 3924 | if (num_attributes > 0) |
| 3925 | { |
| 3926 | const char *name = NULL; |
| 3927 | Declaration decl; |
| 3928 | dw_offset_t param_type_die_offset = DW_INVALID_OFFSET; |
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 3929 | bool is_artificial = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3930 | // one of None, Auto, Register, Extern, Static, PrivateExtern |
| 3931 | |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 3932 | clang::StorageClass storage = clang::SC_None; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3933 | uint32_t i; |
| 3934 | for (i=0; i<num_attributes; ++i) |
| 3935 | { |
| 3936 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 3937 | DWARFFormValue form_value; |
| 3938 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 3939 | { |
| 3940 | switch (attr) |
| 3941 | { |
| 3942 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 3943 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 3944 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 3945 | case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; |
| 3946 | 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] | 3947 | case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3948 | case DW_AT_location: |
| 3949 | // if (form_value.BlockData()) |
| 3950 | // { |
| 3951 | // const DataExtractor& debug_info_data = debug_info(); |
| 3952 | // uint32_t block_length = form_value.Unsigned(); |
| 3953 | // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length); |
| 3954 | // } |
| 3955 | // else |
| 3956 | // { |
| 3957 | // } |
| 3958 | // break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3959 | case DW_AT_const_value: |
| 3960 | case DW_AT_default_value: |
| 3961 | case DW_AT_description: |
| 3962 | case DW_AT_endianity: |
| 3963 | case DW_AT_is_optional: |
| 3964 | case DW_AT_segment: |
| 3965 | case DW_AT_variable_parameter: |
| 3966 | default: |
| 3967 | case DW_AT_abstract_origin: |
| 3968 | case DW_AT_sibling: |
| 3969 | break; |
| 3970 | } |
| 3971 | } |
| 3972 | } |
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 3973 | |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3974 | bool skip = false; |
| 3975 | if (skip_artificial) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3976 | { |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3977 | if (is_artificial) |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3978 | { |
| 3979 | // In order to determine if a C++ member function is |
| 3980 | // "const" we have to look at the const-ness of "this"... |
| 3981 | // Ugly, but that |
| 3982 | if (arg_idx == 0) |
| 3983 | { |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 3984 | if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind())) |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 3985 | { |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3986 | // Often times compilers omit the "this" name for the |
| 3987 | // specification DIEs, so we can't rely upon the name |
| 3988 | // being in the formal parameter DIE... |
| 3989 | if (name == NULL || ::strcmp(name, "this")==0) |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3990 | { |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3991 | Type *this_type = ResolveTypeUID (param_type_die_offset); |
| 3992 | if (this_type) |
| 3993 | { |
| 3994 | uint32_t encoding_mask = this_type->GetEncodingMask(); |
| 3995 | if (encoding_mask & Type::eEncodingIsPointerUID) |
| 3996 | { |
| 3997 | is_static = false; |
| 3998 | |
| 3999 | if (encoding_mask & (1u << Type::eEncodingIsConstUID)) |
| 4000 | type_quals |= clang::Qualifiers::Const; |
| 4001 | if (encoding_mask & (1u << Type::eEncodingIsVolatileUID)) |
| 4002 | type_quals |= clang::Qualifiers::Volatile; |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4003 | } |
| 4004 | } |
| 4005 | } |
| 4006 | } |
| 4007 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4008 | skip = true; |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4009 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4010 | else |
| 4011 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4012 | |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4013 | // HACK: Objective C formal parameters "self" and "_cmd" |
| 4014 | // are not marked as artificial in the DWARF... |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4015 | CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| 4016 | if (comp_unit) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4017 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4018 | switch (comp_unit->GetLanguage()) |
| 4019 | { |
| 4020 | case eLanguageTypeObjC: |
| 4021 | case eLanguageTypeObjC_plus_plus: |
| 4022 | if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0)) |
| 4023 | skip = true; |
| 4024 | break; |
| 4025 | default: |
| 4026 | break; |
| 4027 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4028 | } |
| 4029 | } |
| 4030 | } |
| 4031 | |
| 4032 | if (!skip) |
| 4033 | { |
| 4034 | Type *type = ResolveTypeUID(param_type_die_offset); |
| 4035 | if (type) |
| 4036 | { |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 4037 | function_param_types.push_back (type->GetClangForwardType()); |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4038 | |
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 4039 | clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name, |
| 4040 | type->GetClangForwardType(), |
| 4041 | storage); |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4042 | assert(param_var_decl); |
| 4043 | function_param_decls.push_back(param_var_decl); |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 4044 | |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 4045 | GetClangASTContext().SetMetadataAsUserID (param_var_decl, MakeUserID(die->GetOffset())); |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4046 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4047 | } |
| 4048 | } |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4049 | arg_idx++; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4050 | } |
| 4051 | break; |
| 4052 | |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 4053 | case DW_TAG_template_type_parameter: |
| 4054 | case DW_TAG_template_value_parameter: |
| 4055 | ParseTemplateDIE (dwarf_cu, die,template_param_infos); |
| 4056 | break; |
| 4057 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4058 | default: |
| 4059 | break; |
| 4060 | } |
| 4061 | } |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4062 | return arg_idx; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4063 | } |
| 4064 | |
| 4065 | size_t |
| 4066 | SymbolFileDWARF::ParseChildEnumerators |
| 4067 | ( |
| 4068 | const SymbolContext& sc, |
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 4069 | clang_type_t enumerator_clang_type, |
| 4070 | bool is_signed, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4071 | uint32_t enumerator_byte_size, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4072 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4073 | const DWARFDebugInfoEntry *parent_die |
| 4074 | ) |
| 4075 | { |
| 4076 | if (parent_die == NULL) |
| 4077 | return 0; |
| 4078 | |
| 4079 | size_t enumerators_added = 0; |
| 4080 | const DWARFDebugInfoEntry *die; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4081 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| 4082 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4083 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 4084 | { |
| 4085 | const dw_tag_t tag = die->Tag(); |
| 4086 | if (tag == DW_TAG_enumerator) |
| 4087 | { |
| 4088 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4089 | 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] | 4090 | if (num_child_attributes > 0) |
| 4091 | { |
| 4092 | const char *name = NULL; |
| 4093 | bool got_value = false; |
| 4094 | int64_t enum_value = 0; |
| 4095 | Declaration decl; |
| 4096 | |
| 4097 | uint32_t i; |
| 4098 | for (i=0; i<num_child_attributes; ++i) |
| 4099 | { |
| 4100 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 4101 | DWARFFormValue form_value; |
| 4102 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 4103 | { |
| 4104 | switch (attr) |
| 4105 | { |
| 4106 | case DW_AT_const_value: |
| 4107 | got_value = true; |
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 4108 | if (is_signed) |
| 4109 | enum_value = form_value.Signed(); |
| 4110 | else |
| 4111 | enum_value = form_value.Unsigned(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4112 | break; |
| 4113 | |
| 4114 | case DW_AT_name: |
| 4115 | name = form_value.AsCString(&get_debug_str_data()); |
| 4116 | break; |
| 4117 | |
| 4118 | case DW_AT_description: |
| 4119 | default: |
| 4120 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 4121 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 4122 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 4123 | case DW_AT_sibling: |
| 4124 | break; |
| 4125 | } |
| 4126 | } |
| 4127 | } |
| 4128 | |
| 4129 | if (name && name[0] && got_value) |
| 4130 | { |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 4131 | GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type, |
| 4132 | enumerator_clang_type, |
| 4133 | decl, |
| 4134 | name, |
| 4135 | enum_value, |
| 4136 | enumerator_byte_size * 8); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4137 | ++enumerators_added; |
| 4138 | } |
| 4139 | } |
| 4140 | } |
| 4141 | } |
| 4142 | return enumerators_added; |
| 4143 | } |
| 4144 | |
| 4145 | void |
| 4146 | SymbolFileDWARF::ParseChildArrayInfo |
| 4147 | ( |
| 4148 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4149 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4150 | const DWARFDebugInfoEntry *parent_die, |
| 4151 | int64_t& first_index, |
| 4152 | std::vector<uint64_t>& element_orders, |
| 4153 | uint32_t& byte_stride, |
| 4154 | uint32_t& bit_stride |
| 4155 | ) |
| 4156 | { |
| 4157 | if (parent_die == NULL) |
| 4158 | return; |
| 4159 | |
| 4160 | const DWARFDebugInfoEntry *die; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4161 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4162 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 4163 | { |
| 4164 | const dw_tag_t tag = die->Tag(); |
| 4165 | switch (tag) |
| 4166 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4167 | case DW_TAG_subrange_type: |
| 4168 | { |
| 4169 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4170 | 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] | 4171 | if (num_child_attributes > 0) |
| 4172 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4173 | uint64_t num_elements = 0; |
| 4174 | uint64_t lower_bound = 0; |
| 4175 | uint64_t upper_bound = 0; |
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4176 | bool upper_bound_valid = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4177 | uint32_t i; |
| 4178 | for (i=0; i<num_child_attributes; ++i) |
| 4179 | { |
| 4180 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 4181 | DWARFFormValue form_value; |
| 4182 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 4183 | { |
| 4184 | switch (attr) |
| 4185 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4186 | case DW_AT_name: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4187 | break; |
| 4188 | |
| 4189 | case DW_AT_count: |
| 4190 | num_elements = form_value.Unsigned(); |
| 4191 | break; |
| 4192 | |
| 4193 | case DW_AT_bit_stride: |
| 4194 | bit_stride = form_value.Unsigned(); |
| 4195 | break; |
| 4196 | |
| 4197 | case DW_AT_byte_stride: |
| 4198 | byte_stride = form_value.Unsigned(); |
| 4199 | break; |
| 4200 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4201 | case DW_AT_lower_bound: |
| 4202 | lower_bound = form_value.Unsigned(); |
| 4203 | break; |
| 4204 | |
| 4205 | case DW_AT_upper_bound: |
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4206 | upper_bound_valid = true; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4207 | upper_bound = form_value.Unsigned(); |
| 4208 | break; |
| 4209 | |
| 4210 | default: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4211 | case DW_AT_abstract_origin: |
| 4212 | case DW_AT_accessibility: |
| 4213 | case DW_AT_allocated: |
| 4214 | case DW_AT_associated: |
| 4215 | case DW_AT_data_location: |
| 4216 | case DW_AT_declaration: |
| 4217 | case DW_AT_description: |
| 4218 | case DW_AT_sibling: |
| 4219 | case DW_AT_threads_scaled: |
| 4220 | case DW_AT_type: |
| 4221 | case DW_AT_visibility: |
| 4222 | break; |
| 4223 | } |
| 4224 | } |
| 4225 | } |
| 4226 | |
| Greg Clayton | e6a0779 | 2012-12-05 21:59:39 +0000 | [diff] [blame] | 4227 | if (num_elements == 0) |
| 4228 | { |
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4229 | if (upper_bound_valid && upper_bound >= lower_bound) |
| Greg Clayton | e6a0779 | 2012-12-05 21:59:39 +0000 | [diff] [blame] | 4230 | num_elements = upper_bound - lower_bound + 1; |
| 4231 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4232 | |
| Sean Callanan | ec979ba | 2012-10-22 23:56:48 +0000 | [diff] [blame] | 4233 | element_orders.push_back (num_elements); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4234 | } |
| 4235 | } |
| 4236 | break; |
| 4237 | } |
| 4238 | } |
| 4239 | } |
| 4240 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4241 | TypeSP |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4242 | SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4243 | { |
| 4244 | TypeSP type_sp; |
| 4245 | if (die != NULL) |
| 4246 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4247 | assert(dwarf_cu != NULL); |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4248 | Type *type_ptr = m_die_to_type.lookup (die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4249 | if (type_ptr == NULL) |
| 4250 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4251 | CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4252 | assert (lldb_cu); |
| 4253 | SymbolContext sc(lldb_cu); |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4254 | type_sp = ParseType(sc, dwarf_cu, die, NULL); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4255 | } |
| 4256 | else if (type_ptr != DIE_IS_BEING_PARSED) |
| 4257 | { |
| 4258 | // Grab the existing type from the master types lists |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 4259 | type_sp = type_ptr->shared_from_this(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4260 | } |
| 4261 | |
| 4262 | } |
| 4263 | return type_sp; |
| 4264 | } |
| 4265 | |
| 4266 | clang::DeclContext * |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4267 | SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4268 | { |
| 4269 | if (die_offset != DW_INVALID_OFFSET) |
| 4270 | { |
| 4271 | DWARFCompileUnitSP cu_sp; |
| 4272 | const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4273 | return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4274 | } |
| 4275 | return NULL; |
| 4276 | } |
| 4277 | |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4278 | clang::DeclContext * |
| 4279 | SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset) |
| 4280 | { |
| 4281 | if (die_offset != DW_INVALID_OFFSET) |
| 4282 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4283 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 4284 | if (debug_info) |
| 4285 | { |
| 4286 | DWARFCompileUnitSP cu_sp; |
| 4287 | const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp); |
| 4288 | if (die) |
| 4289 | return GetClangDeclContextForDIE (sc, cu_sp.get(), die); |
| 4290 | } |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4291 | } |
| 4292 | return NULL; |
| 4293 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4294 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4295 | clang::NamespaceDecl * |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4296 | SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4297 | { |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4298 | if (die && die->Tag() == DW_TAG_namespace) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4299 | { |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4300 | // See if we already parsed this namespace DIE and associated it with a |
| 4301 | // uniqued namespace declaration |
| 4302 | clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]); |
| 4303 | if (namespace_decl) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4304 | return namespace_decl; |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4305 | else |
| 4306 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4307 | const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL); |
| 4308 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL); |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4309 | namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx); |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4310 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4311 | if (log) |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4312 | { |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4313 | if (namespace_name) |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4314 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4315 | GetObjectFile()->GetModule()->LogMessage (log, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4316 | "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] | 4317 | GetClangASTContext().getASTContext(), |
| 4318 | MakeUserID(die->GetOffset()), |
| 4319 | namespace_name, |
| 4320 | namespace_decl, |
| 4321 | namespace_decl->getOriginalNamespace()); |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4322 | } |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4323 | else |
| 4324 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4325 | GetObjectFile()->GetModule()->LogMessage (log, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4326 | "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] | 4327 | GetClangASTContext().getASTContext(), |
| 4328 | MakeUserID(die->GetOffset()), |
| 4329 | namespace_decl, |
| 4330 | namespace_decl->getOriginalNamespace()); |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4331 | } |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4332 | } |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4333 | |
| 4334 | if (namespace_decl) |
| 4335 | LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die); |
| 4336 | return namespace_decl; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4337 | } |
| 4338 | } |
| 4339 | return NULL; |
| 4340 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4341 | |
| 4342 | clang::DeclContext * |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4343 | SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4344 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4345 | clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die); |
| 4346 | if (clang_decl_ctx) |
| 4347 | return clang_decl_ctx; |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4348 | // If this DIE has a specification, or an abstract origin, then trace to those. |
| 4349 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4350 | 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] | 4351 | if (die_offset != DW_INVALID_OFFSET) |
| 4352 | return GetClangDeclContextForDIEOffset (sc, die_offset); |
| 4353 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4354 | 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] | 4355 | if (die_offset != DW_INVALID_OFFSET) |
| 4356 | return GetClangDeclContextForDIEOffset (sc, die_offset); |
| 4357 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4358 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 4359 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4360 | 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] | 4361 | // This is the DIE we want. Parse it, then query our map. |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4362 | bool assert_not_being_parsed = true; |
| 4363 | ResolveTypeUID (cu, die, assert_not_being_parsed); |
| 4364 | |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4365 | clang_decl_ctx = GetCachedClangDeclContextForDIE (die); |
| 4366 | |
| 4367 | return clang_decl_ctx; |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4368 | } |
| 4369 | |
| 4370 | clang::DeclContext * |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4371 | 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] | 4372 | { |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4373 | if (m_clang_tu_decl == NULL) |
| 4374 | m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4375 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4376 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4377 | |
| 4378 | if (decl_ctx_die_copy) |
| 4379 | *decl_ctx_die_copy = decl_ctx_die; |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4380 | |
| 4381 | if (decl_ctx_die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4382 | { |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4383 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4384 | DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die); |
| 4385 | if (pos != m_die_to_decl_ctx.end()) |
| 4386 | return pos->second; |
| 4387 | |
| 4388 | switch (decl_ctx_die->Tag()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4389 | { |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4390 | case DW_TAG_compile_unit: |
| 4391 | return m_clang_tu_decl; |
| 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 | case DW_TAG_namespace: |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4394 | return ResolveNamespaceDIE (cu, decl_ctx_die); |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4395 | break; |
| 4396 | |
| 4397 | case DW_TAG_structure_type: |
| 4398 | case DW_TAG_union_type: |
| 4399 | case DW_TAG_class_type: |
| 4400 | { |
| 4401 | Type* type = ResolveType (cu, decl_ctx_die); |
| 4402 | if (type) |
| 4403 | { |
| 4404 | clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ()); |
| 4405 | if (decl_ctx) |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4406 | { |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4407 | LinkDeclContextToDIE (decl_ctx, decl_ctx_die); |
| 4408 | if (decl_ctx) |
| 4409 | return decl_ctx; |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4410 | } |
| 4411 | } |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4412 | } |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4413 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4414 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4415 | default: |
| 4416 | break; |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4417 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4418 | } |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 4419 | return m_clang_tu_decl; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4420 | } |
| 4421 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4422 | |
| 4423 | const DWARFDebugInfoEntry * |
| 4424 | SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) |
| 4425 | { |
| 4426 | if (cu && die) |
| 4427 | { |
| 4428 | const DWARFDebugInfoEntry * const decl_die = die; |
| 4429 | |
| 4430 | while (die != NULL) |
| 4431 | { |
| 4432 | // If this is the original DIE that we are searching for a declaration |
| 4433 | // for, then don't look in the cache as we don't want our own decl |
| 4434 | // context to be our decl context... |
| 4435 | if (decl_die != die) |
| 4436 | { |
| 4437 | switch (die->Tag()) |
| 4438 | { |
| 4439 | case DW_TAG_compile_unit: |
| 4440 | case DW_TAG_namespace: |
| 4441 | case DW_TAG_structure_type: |
| 4442 | case DW_TAG_union_type: |
| 4443 | case DW_TAG_class_type: |
| 4444 | return die; |
| 4445 | |
| 4446 | default: |
| 4447 | break; |
| 4448 | } |
| 4449 | } |
| 4450 | |
| 4451 | dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET); |
| 4452 | if (die_offset != DW_INVALID_OFFSET) |
| 4453 | { |
| 4454 | DWARFCompileUnit *spec_cu = cu; |
| 4455 | const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu); |
| 4456 | const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die); |
| 4457 | if (spec_die_decl_ctx_die) |
| 4458 | return spec_die_decl_ctx_die; |
| 4459 | } |
| 4460 | |
| 4461 | die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET); |
| 4462 | if (die_offset != DW_INVALID_OFFSET) |
| 4463 | { |
| 4464 | DWARFCompileUnit *abs_cu = cu; |
| 4465 | const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu); |
| 4466 | const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die); |
| 4467 | if (abs_die_decl_ctx_die) |
| 4468 | return abs_die_decl_ctx_die; |
| 4469 | } |
| 4470 | |
| 4471 | die = die->GetParent(); |
| 4472 | } |
| 4473 | } |
| 4474 | return NULL; |
| 4475 | } |
| 4476 | |
| 4477 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4478 | Symbol * |
| 4479 | SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name) |
| 4480 | { |
| 4481 | Symbol *objc_class_symbol = NULL; |
| 4482 | if (m_obj_file) |
| 4483 | { |
| 4484 | Symtab *symtab = m_obj_file->GetSymtab(); |
| 4485 | if (symtab) |
| 4486 | { |
| 4487 | objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name, |
| 4488 | eSymbolTypeObjCClass, |
| 4489 | Symtab::eDebugNo, |
| 4490 | Symtab::eVisibilityAny); |
| 4491 | } |
| 4492 | } |
| 4493 | return objc_class_symbol; |
| 4494 | } |
| 4495 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4496 | // Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't |
| 4497 | // then we can end up looking through all class types for a complete type and never find |
| 4498 | // the full definition. We need to know if this attribute is supported, so we determine |
| 4499 | // this here and cache th result. We also need to worry about the debug map DWARF file |
| 4500 | // if we are doing darwin DWARF in .o file debugging. |
| 4501 | bool |
| 4502 | SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu) |
| 4503 | { |
| 4504 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate) |
| 4505 | { |
| 4506 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo; |
| 4507 | if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type()) |
| 4508 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; |
| 4509 | else |
| 4510 | { |
| 4511 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 4512 | const uint32_t num_compile_units = GetNumCompileUnits(); |
| 4513 | for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) |
| 4514 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4515 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); |
| 4516 | 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] | 4517 | { |
| 4518 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; |
| 4519 | break; |
| 4520 | } |
| 4521 | } |
| 4522 | } |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 4523 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ()) |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4524 | return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this); |
| 4525 | } |
| 4526 | return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes; |
| 4527 | } |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4528 | |
| 4529 | // This function can be used when a DIE is found that is a forward declaration |
| 4530 | // DIE and we want to try and find a type that has the complete definition. |
| 4531 | TypeSP |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4532 | SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die, |
| 4533 | const ConstString &type_name, |
| 4534 | bool must_be_implementation) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4535 | { |
| 4536 | |
| 4537 | TypeSP type_sp; |
| 4538 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4539 | if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name))) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4540 | return type_sp; |
| 4541 | |
| 4542 | DIEArray die_offsets; |
| 4543 | |
| 4544 | if (m_using_apple_tables) |
| 4545 | { |
| 4546 | if (m_apple_types_ap.get()) |
| 4547 | { |
| 4548 | const char *name_cstr = type_name.GetCString(); |
| Greg Clayton | 68221ec | 2012-01-18 20:58:12 +0000 | [diff] [blame] | 4549 | m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4550 | } |
| 4551 | } |
| 4552 | else |
| 4553 | { |
| 4554 | if (!m_indexed) |
| 4555 | Index (); |
| 4556 | |
| 4557 | m_type_index.Find (type_name, die_offsets); |
| 4558 | } |
| 4559 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4560 | const size_t num_matches = die_offsets.size(); |
| 4561 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4562 | DWARFCompileUnit* type_cu = NULL; |
| 4563 | const DWARFDebugInfoEntry* type_die = NULL; |
| 4564 | if (num_matches) |
| 4565 | { |
| 4566 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 4567 | for (size_t i=0; i<num_matches; ++i) |
| 4568 | { |
| 4569 | const dw_offset_t die_offset = die_offsets[i]; |
| 4570 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); |
| 4571 | |
| 4572 | if (type_die) |
| 4573 | { |
| 4574 | bool try_resolving_type = false; |
| 4575 | |
| 4576 | // Don't try and resolve the DIE we are looking for with the DIE itself! |
| 4577 | if (type_die != die) |
| 4578 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4579 | switch (type_die->Tag()) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4580 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4581 | case DW_TAG_class_type: |
| 4582 | case DW_TAG_structure_type: |
| 4583 | try_resolving_type = true; |
| 4584 | break; |
| 4585 | default: |
| 4586 | break; |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4587 | } |
| 4588 | } |
| 4589 | |
| 4590 | if (try_resolving_type) |
| 4591 | { |
| Sean Callanan | a9bc065 | 2012-01-19 02:17:40 +0000 | [diff] [blame] | 4592 | 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] | 4593 | 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] | 4594 | |
| 4595 | if (try_resolving_type) |
| 4596 | { |
| 4597 | Type *resolved_type = ResolveType (type_cu, type_die, false); |
| 4598 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) |
| 4599 | { |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4600 | 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] | 4601 | MakeUserID(die->GetOffset()), |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4602 | MakeUserID(dwarf_cu->GetOffset()), |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4603 | m_obj_file->GetFileSpec().GetFilename().AsCString(), |
| 4604 | MakeUserID(type_die->GetOffset()), |
| 4605 | MakeUserID(type_cu->GetOffset())); |
| 4606 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4607 | if (die) |
| 4608 | m_die_to_type[die] = resolved_type; |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 4609 | type_sp = resolved_type->shared_from_this(); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4610 | break; |
| 4611 | } |
| 4612 | } |
| 4613 | } |
| 4614 | } |
| 4615 | else |
| 4616 | { |
| 4617 | if (m_using_apple_tables) |
| 4618 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4619 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 4620 | die_offset, type_name.GetCString()); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4621 | } |
| 4622 | } |
| 4623 | |
| 4624 | } |
| 4625 | } |
| 4626 | return type_sp; |
| 4627 | } |
| 4628 | |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4629 | |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4630 | //---------------------------------------------------------------------- |
| 4631 | // This function helps to ensure that the declaration contexts match for |
| 4632 | // two different DIEs. Often times debug information will refer to a |
| 4633 | // forward declaration of a type (the equivalent of "struct my_struct;". |
| 4634 | // There will often be a declaration of that type elsewhere that has the |
| 4635 | // full definition. When we go looking for the full type "my_struct", we |
| 4636 | // will find one or more matches in the accelerator tables and we will |
| 4637 | // then need to make sure the type was in the same declaration context |
| 4638 | // as the original DIE. This function can efficiently compare two DIEs |
| 4639 | // and will return true when the declaration context matches, and false |
| 4640 | // when they don't. |
| 4641 | //---------------------------------------------------------------------- |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4642 | bool |
| 4643 | SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1, |
| 4644 | DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2) |
| 4645 | { |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4646 | if (die1 == die2) |
| 4647 | return true; |
| 4648 | |
| 4649 | #if defined (LLDB_CONFIGURATION_DEBUG) |
| 4650 | // You can't and shouldn't call this function with a compile unit from |
| 4651 | // two different SymbolFileDWARF instances. |
| 4652 | assert (DebugInfo()->ContainsCompileUnit (cu1)); |
| 4653 | assert (DebugInfo()->ContainsCompileUnit (cu2)); |
| 4654 | #endif |
| 4655 | |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4656 | DWARFDIECollection decl_ctx_1; |
| 4657 | DWARFDIECollection decl_ctx_2; |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4658 | //The declaration DIE stack is a stack of the declaration context |
| 4659 | // DIEs all the way back to the compile unit. If a type "T" is |
| 4660 | // declared inside a class "B", and class "B" is declared inside |
| 4661 | // a class "A" and class "A" is in a namespace "lldb", and the |
| 4662 | // namespace is in a compile unit, there will be a stack of DIEs: |
| 4663 | // |
| 4664 | // [0] DW_TAG_class_type for "B" |
| 4665 | // [1] DW_TAG_class_type for "A" |
| 4666 | // [2] DW_TAG_namespace for "lldb" |
| 4667 | // [3] DW_TAG_compile_unit for the source file. |
| 4668 | // |
| 4669 | // We grab both contexts and make sure that everything matches |
| 4670 | // all the way back to the compiler unit. |
| 4671 | |
| 4672 | // First lets grab the decl contexts for both DIEs |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4673 | die1->GetDeclContextDIEs (this, cu1, decl_ctx_1); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 4674 | die2->GetDeclContextDIEs (this, cu2, decl_ctx_2); |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4675 | // Make sure the context arrays have the same size, otherwise |
| 4676 | // we are done |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4677 | const size_t count1 = decl_ctx_1.Size(); |
| 4678 | const size_t count2 = decl_ctx_2.Size(); |
| 4679 | if (count1 != count2) |
| 4680 | return false; |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4681 | |
| 4682 | // Make sure the DW_TAG values match all the way back up the the |
| 4683 | // compile unit. If they don't, then we are done. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4684 | const DWARFDebugInfoEntry *decl_ctx_die1; |
| 4685 | const DWARFDebugInfoEntry *decl_ctx_die2; |
| 4686 | size_t i; |
| 4687 | for (i=0; i<count1; i++) |
| 4688 | { |
| 4689 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); |
| 4690 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); |
| 4691 | if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag()) |
| 4692 | return false; |
| 4693 | } |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4694 | #if defined LLDB_CONFIGURATION_DEBUG |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4695 | |
| 4696 | // Make sure the top item in the decl context die array is always |
| 4697 | // DW_TAG_compile_unit. If it isn't then something went wrong in |
| 4698 | // the DWARFDebugInfoEntry::GetDeclContextDIEs() function... |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4699 | assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit); |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4700 | |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4701 | #endif |
| 4702 | // Always skip the compile unit when comparing by only iterating up to |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4703 | // "count - 1". Here we compare the names as we go. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4704 | for (i=0; i<count1 - 1; i++) |
| 4705 | { |
| 4706 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); |
| 4707 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); |
| 4708 | const char *name1 = decl_ctx_die1->GetName(this, cu1); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 4709 | const char *name2 = decl_ctx_die2->GetName(this, cu2); |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4710 | // If the string was from a DW_FORM_strp, then the pointer will often |
| 4711 | // be the same! |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 4712 | if (name1 == name2) |
| 4713 | continue; |
| 4714 | |
| 4715 | // Name pointers are not equal, so only compare the strings |
| 4716 | // if both are not NULL. |
| 4717 | if (name1 && name2) |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4718 | { |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 4719 | // If the strings don't compare, we are done... |
| 4720 | if (strcmp(name1, name2) != 0) |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4721 | return false; |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 4722 | } |
| 4723 | else |
| 4724 | { |
| 4725 | // One name was NULL while the other wasn't |
| 4726 | return false; |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4727 | } |
| 4728 | } |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4729 | // We made it through all of the checks and the declaration contexts |
| 4730 | // are equal. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4731 | return true; |
| 4732 | } |
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 4733 | |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4734 | // This function can be used when a DIE is found that is a forward declaration |
| 4735 | // 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] | 4736 | // "cu" and "die" must be from this SymbolFileDWARF |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4737 | TypeSP |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4738 | SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu, |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4739 | const DWARFDebugInfoEntry *die, |
| 4740 | const ConstString &type_name) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4741 | { |
| 4742 | TypeSP type_sp; |
| 4743 | |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4744 | #if defined (LLDB_CONFIGURATION_DEBUG) |
| 4745 | // You can't and shouldn't call this function with a compile unit from |
| 4746 | // another SymbolFileDWARF instance. |
| 4747 | assert (DebugInfo()->ContainsCompileUnit (cu)); |
| 4748 | #endif |
| 4749 | |
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 4750 | if (cu == NULL || die == NULL || !type_name) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4751 | return type_sp; |
| 4752 | |
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 4753 | std::string qualified_name; |
| 4754 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4755 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4756 | if (log) |
| 4757 | { |
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4758 | die->GetQualifiedName(this, cu, qualified_name); |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4759 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4760 | "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x (%s), name='%s')", |
| 4761 | die->GetOffset(), |
| 4762 | qualified_name.c_str(), |
| 4763 | type_name.GetCString()); |
| 4764 | } |
| 4765 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4766 | DIEArray die_offsets; |
| 4767 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4768 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4769 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4770 | if (m_apple_types_ap.get()) |
| 4771 | { |
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 4772 | const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag); |
| 4773 | const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash); |
| 4774 | if (has_tag && has_qualified_name_hash) |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4775 | { |
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 4776 | if (qualified_name.empty()) |
| 4777 | die->GetQualifiedName(this, cu, qualified_name); |
| 4778 | |
| 4779 | const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name.c_str()); |
| 4780 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4781 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()"); |
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 4782 | m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), die->Tag(), qualified_name_hash, die_offsets); |
| 4783 | } |
| 4784 | else if (has_tag > 1) |
| 4785 | { |
| 4786 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4787 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()"); |
| Greg Clayton | ae920b6 | 2012-01-06 00:17:16 +0000 | [diff] [blame] | 4788 | m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets); |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4789 | } |
| 4790 | else |
| 4791 | { |
| 4792 | m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets); |
| 4793 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4794 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4795 | } |
| 4796 | else |
| 4797 | { |
| 4798 | if (!m_indexed) |
| 4799 | Index (); |
| 4800 | |
| 4801 | m_type_index.Find (type_name, die_offsets); |
| 4802 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4803 | |
| 4804 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | 6997489 | 2010-12-03 21:42:06 +0000 | [diff] [blame] | 4805 | |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4806 | const dw_tag_t die_tag = die->Tag(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4807 | |
| 4808 | DWARFCompileUnit* type_cu = NULL; |
| 4809 | const DWARFDebugInfoEntry* type_die = NULL; |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4810 | if (num_matches) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4811 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4812 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4813 | for (size_t i=0; i<num_matches; ++i) |
| 4814 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4815 | const dw_offset_t die_offset = die_offsets[i]; |
| 4816 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4817 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4818 | if (type_die) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4819 | { |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4820 | bool try_resolving_type = false; |
| 4821 | |
| 4822 | // Don't try and resolve the DIE we are looking for with the DIE itself! |
| 4823 | if (type_die != die) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4824 | { |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4825 | const dw_tag_t type_die_tag = type_die->Tag(); |
| 4826 | // Make sure the tags match |
| 4827 | if (type_die_tag == die_tag) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4828 | { |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4829 | // The tags match, lets try resolving this type |
| 4830 | try_resolving_type = true; |
| 4831 | } |
| 4832 | else |
| 4833 | { |
| 4834 | // The tags don't match, but we need to watch our for a |
| 4835 | // forward declaration for a struct and ("struct foo") |
| 4836 | // ends up being a class ("class foo { ... };") or |
| 4837 | // vice versa. |
| 4838 | switch (type_die_tag) |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4839 | { |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4840 | case DW_TAG_class_type: |
| 4841 | // We had a "class foo", see if we ended up with a "struct foo { ... };" |
| 4842 | try_resolving_type = (die_tag == DW_TAG_structure_type); |
| 4843 | break; |
| 4844 | case DW_TAG_structure_type: |
| 4845 | // We had a "struct foo", see if we ended up with a "class foo { ... };" |
| 4846 | try_resolving_type = (die_tag == DW_TAG_class_type); |
| 4847 | break; |
| 4848 | default: |
| 4849 | // Tags don't match, don't event try to resolve |
| 4850 | // using this type whose name matches.... |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4851 | break; |
| 4852 | } |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4853 | } |
| 4854 | } |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4855 | |
| 4856 | if (try_resolving_type) |
| 4857 | { |
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4858 | if (log) |
| 4859 | { |
| 4860 | std::string qualified_name; |
| 4861 | type_die->GetQualifiedName(this, cu, qualified_name); |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4862 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4863 | "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') trying die=0x%8.8x (%s)", |
| 4864 | die->GetOffset(), |
| 4865 | type_name.GetCString(), |
| 4866 | type_die->GetOffset(), |
| 4867 | qualified_name.c_str()); |
| 4868 | } |
| 4869 | |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4870 | // Make sure the decl contexts match all the way up |
| 4871 | if (DIEDeclContextsMatch(cu, die, type_cu, type_die)) |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4872 | { |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4873 | Type *resolved_type = ResolveType (type_cu, type_die, false); |
| 4874 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) |
| 4875 | { |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4876 | 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] | 4877 | MakeUserID(die->GetOffset()), |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4878 | MakeUserID(dwarf_cu->GetOffset()), |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4879 | m_obj_file->GetFileSpec().GetFilename().AsCString(), |
| 4880 | MakeUserID(type_die->GetOffset()), |
| 4881 | MakeUserID(type_cu->GetOffset())); |
| 4882 | |
| 4883 | m_die_to_type[die] = resolved_type; |
| Greg Clayton | ff7692a | 2012-02-02 18:16:59 +0000 | [diff] [blame] | 4884 | type_sp = resolved_type->shared_from_this(); |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4885 | break; |
| 4886 | } |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4887 | } |
| 4888 | } |
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4889 | else |
| 4890 | { |
| 4891 | if (log) |
| 4892 | { |
| 4893 | std::string qualified_name; |
| 4894 | type_die->GetQualifiedName(this, cu, qualified_name); |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4895 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4896 | "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') ignoring die=0x%8.8x (%s)", |
| 4897 | die->GetOffset(), |
| 4898 | type_name.GetCString(), |
| 4899 | type_die->GetOffset(), |
| 4900 | qualified_name.c_str()); |
| 4901 | } |
| 4902 | } |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4903 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4904 | else |
| 4905 | { |
| 4906 | if (m_using_apple_tables) |
| 4907 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4908 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 4909 | die_offset, type_name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4910 | } |
| 4911 | } |
| 4912 | |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4913 | } |
| 4914 | } |
| 4915 | return type_sp; |
| 4916 | } |
| 4917 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4918 | TypeSP |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4919 | SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx) |
| 4920 | { |
| 4921 | TypeSP type_sp; |
| 4922 | |
| 4923 | const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize(); |
| 4924 | if (dwarf_decl_ctx_count > 0) |
| 4925 | { |
| 4926 | const ConstString type_name(dwarf_decl_ctx[0].name); |
| 4927 | const dw_tag_t tag = dwarf_decl_ctx[0].tag; |
| 4928 | |
| 4929 | if (type_name) |
| 4930 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4931 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS)); |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4932 | if (log) |
| 4933 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4934 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4935 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')", |
| 4936 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), |
| 4937 | dwarf_decl_ctx.GetQualifiedName()); |
| 4938 | } |
| 4939 | |
| 4940 | DIEArray die_offsets; |
| 4941 | |
| 4942 | if (m_using_apple_tables) |
| 4943 | { |
| 4944 | if (m_apple_types_ap.get()) |
| 4945 | { |
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 4946 | const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag); |
| 4947 | const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash); |
| 4948 | if (has_tag && has_qualified_name_hash) |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4949 | { |
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 4950 | const char *qualified_name = dwarf_decl_ctx.GetQualifiedName(); |
| 4951 | const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name); |
| 4952 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4953 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()"); |
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 4954 | m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets); |
| 4955 | } |
| 4956 | else if (has_tag) |
| 4957 | { |
| 4958 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4959 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()"); |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4960 | m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets); |
| 4961 | } |
| 4962 | else |
| 4963 | { |
| 4964 | m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets); |
| 4965 | } |
| 4966 | } |
| 4967 | } |
| 4968 | else |
| 4969 | { |
| 4970 | if (!m_indexed) |
| 4971 | Index (); |
| 4972 | |
| 4973 | m_type_index.Find (type_name, die_offsets); |
| 4974 | } |
| 4975 | |
| 4976 | const size_t num_matches = die_offsets.size(); |
| 4977 | |
| 4978 | |
| 4979 | DWARFCompileUnit* type_cu = NULL; |
| 4980 | const DWARFDebugInfoEntry* type_die = NULL; |
| 4981 | if (num_matches) |
| 4982 | { |
| 4983 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 4984 | for (size_t i=0; i<num_matches; ++i) |
| 4985 | { |
| 4986 | const dw_offset_t die_offset = die_offsets[i]; |
| 4987 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); |
| 4988 | |
| 4989 | if (type_die) |
| 4990 | { |
| 4991 | bool try_resolving_type = false; |
| 4992 | |
| 4993 | // Don't try and resolve the DIE we are looking for with the DIE itself! |
| 4994 | const dw_tag_t type_tag = type_die->Tag(); |
| 4995 | // Make sure the tags match |
| 4996 | if (type_tag == tag) |
| 4997 | { |
| 4998 | // The tags match, lets try resolving this type |
| 4999 | try_resolving_type = true; |
| 5000 | } |
| 5001 | else |
| 5002 | { |
| 5003 | // The tags don't match, but we need to watch our for a |
| 5004 | // forward declaration for a struct and ("struct foo") |
| 5005 | // ends up being a class ("class foo { ... };") or |
| 5006 | // vice versa. |
| 5007 | switch (type_tag) |
| 5008 | { |
| 5009 | case DW_TAG_class_type: |
| 5010 | // We had a "class foo", see if we ended up with a "struct foo { ... };" |
| 5011 | try_resolving_type = (tag == DW_TAG_structure_type); |
| 5012 | break; |
| 5013 | case DW_TAG_structure_type: |
| 5014 | // We had a "struct foo", see if we ended up with a "class foo { ... };" |
| 5015 | try_resolving_type = (tag == DW_TAG_class_type); |
| 5016 | break; |
| 5017 | default: |
| 5018 | // Tags don't match, don't event try to resolve |
| 5019 | // using this type whose name matches.... |
| 5020 | break; |
| 5021 | } |
| 5022 | } |
| 5023 | |
| 5024 | if (try_resolving_type) |
| 5025 | { |
| 5026 | DWARFDeclContext type_dwarf_decl_ctx; |
| 5027 | type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx); |
| 5028 | |
| 5029 | if (log) |
| 5030 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5031 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5032 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)", |
| 5033 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), |
| 5034 | dwarf_decl_ctx.GetQualifiedName(), |
| 5035 | type_die->GetOffset(), |
| 5036 | type_dwarf_decl_ctx.GetQualifiedName()); |
| 5037 | } |
| 5038 | |
| 5039 | // Make sure the decl contexts match all the way up |
| 5040 | if (dwarf_decl_ctx == type_dwarf_decl_ctx) |
| 5041 | { |
| 5042 | Type *resolved_type = ResolveType (type_cu, type_die, false); |
| 5043 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) |
| 5044 | { |
| 5045 | type_sp = resolved_type->shared_from_this(); |
| 5046 | break; |
| 5047 | } |
| 5048 | } |
| 5049 | } |
| 5050 | else |
| 5051 | { |
| 5052 | if (log) |
| 5053 | { |
| 5054 | std::string qualified_name; |
| 5055 | type_die->GetQualifiedName(this, type_cu, qualified_name); |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5056 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5057 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)", |
| 5058 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), |
| 5059 | dwarf_decl_ctx.GetQualifiedName(), |
| 5060 | type_die->GetOffset(), |
| 5061 | qualified_name.c_str()); |
| 5062 | } |
| 5063 | } |
| 5064 | } |
| 5065 | else |
| 5066 | { |
| 5067 | if (m_using_apple_tables) |
| 5068 | { |
| 5069 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 5070 | die_offset, type_name.GetCString()); |
| 5071 | } |
| 5072 | } |
| 5073 | |
| 5074 | } |
| 5075 | } |
| 5076 | } |
| 5077 | } |
| 5078 | return type_sp; |
| 5079 | } |
| 5080 | |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5081 | bool |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5082 | SymbolFileDWARF::CopyUniqueClassMethodTypes (SymbolFileDWARF *src_symfile, |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5083 | Type *class_type, |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5084 | DWARFCompileUnit* src_cu, |
| 5085 | const DWARFDebugInfoEntry *src_class_die, |
| 5086 | DWARFCompileUnit* dst_cu, |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5087 | const DWARFDebugInfoEntry *dst_class_die, |
| 5088 | llvm::SmallVectorImpl <const DWARFDebugInfoEntry *> &failures) |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5089 | { |
| 5090 | if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die) |
| 5091 | return false; |
| 5092 | if (src_class_die->Tag() != dst_class_die->Tag()) |
| 5093 | return false; |
| 5094 | |
| 5095 | // We need to complete the class type so we can get all of the method types |
| 5096 | // parsed so we can then unique those types to their equivalent counterparts |
| 5097 | // in "dst_cu" and "dst_class_die" |
| 5098 | class_type->GetClangFullType(); |
| 5099 | |
| 5100 | const DWARFDebugInfoEntry *src_die; |
| 5101 | const DWARFDebugInfoEntry *dst_die; |
| 5102 | UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die; |
| 5103 | UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die; |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5104 | UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die_artificial; |
| 5105 | UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die_artificial; |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5106 | for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling()) |
| 5107 | { |
| 5108 | if (src_die->Tag() == DW_TAG_subprogram) |
| 5109 | { |
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5110 | // Make sure this is a declaration and not a concrete instance by looking |
| 5111 | // for DW_AT_declaration set to 1. Sometimes concrete function instances |
| 5112 | // are placed inside the class definitions and shouldn't be included in |
| 5113 | // the list of things are are tracking here. |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5114 | 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] | 5115 | { |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5116 | const char *src_name = src_die->GetMangledName (src_symfile, src_cu); |
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5117 | if (src_name) |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5118 | { |
| 5119 | ConstString src_const_name(src_name); |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5120 | if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_artificial, 0)) |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5121 | src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die); |
| 5122 | else |
| 5123 | src_name_to_die.Append(src_const_name.GetCString(), src_die); |
| 5124 | } |
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5125 | } |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5126 | } |
| 5127 | } |
| 5128 | for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling()) |
| 5129 | { |
| 5130 | if (dst_die->Tag() == DW_TAG_subprogram) |
| 5131 | { |
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5132 | // Make sure this is a declaration and not a concrete instance by looking |
| 5133 | // for DW_AT_declaration set to 1. Sometimes concrete function instances |
| 5134 | // are placed inside the class definitions and shouldn't be included in |
| 5135 | // the list of things are are tracking here. |
| 5136 | if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_declaration, 0) == 1) |
| 5137 | { |
| 5138 | const char *dst_name = dst_die->GetMangledName (this, dst_cu); |
| 5139 | if (dst_name) |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5140 | { |
| 5141 | ConstString dst_const_name(dst_name); |
| 5142 | if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_artificial, 0)) |
| 5143 | dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die); |
| 5144 | else |
| 5145 | dst_name_to_die.Append(dst_const_name.GetCString(), dst_die); |
| 5146 | } |
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5147 | } |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5148 | } |
| 5149 | } |
| 5150 | const uint32_t src_size = src_name_to_die.GetSize (); |
| 5151 | const uint32_t dst_size = dst_name_to_die.GetSize (); |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5152 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION)); |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5153 | |
| 5154 | // Is everything kosher so we can go through the members at top speed? |
| 5155 | bool fast_path = true; |
| 5156 | |
| 5157 | if (src_size != dst_size) |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5158 | { |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5159 | if (src_size != 0 && dst_size != 0) |
| 5160 | { |
| 5161 | if (log) |
| 5162 | 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)", |
| 5163 | src_class_die->GetOffset(), |
| 5164 | dst_class_die->GetOffset(), |
| 5165 | src_size, |
| 5166 | dst_size); |
| 5167 | } |
| 5168 | |
| 5169 | fast_path = false; |
| 5170 | } |
| 5171 | |
| 5172 | uint32_t idx; |
| 5173 | |
| 5174 | if (fast_path) |
| 5175 | { |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5176 | for (idx = 0; idx < src_size; ++idx) |
| 5177 | { |
| 5178 | src_die = src_name_to_die.GetValueAtIndexUnchecked (idx); |
| 5179 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx); |
| 5180 | |
| 5181 | if (src_die->Tag() != dst_die->Tag()) |
| 5182 | { |
| 5183 | if (log) |
| 5184 | 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)", |
| 5185 | src_class_die->GetOffset(), |
| 5186 | dst_class_die->GetOffset(), |
| 5187 | src_die->GetOffset(), |
| 5188 | DW_TAG_value_to_name(src_die->Tag()), |
| 5189 | dst_die->GetOffset(), |
| 5190 | DW_TAG_value_to_name(src_die->Tag())); |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5191 | fast_path = false; |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5192 | } |
| 5193 | |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5194 | const char *src_name = src_die->GetMangledName (src_symfile, src_cu); |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5195 | const char *dst_name = dst_die->GetMangledName (this, dst_cu); |
| 5196 | |
| 5197 | // Make sure the names match |
| 5198 | if (src_name == dst_name || (strcmp (src_name, dst_name) == 0)) |
| 5199 | continue; |
| 5200 | |
| 5201 | if (log) |
| 5202 | 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)", |
| 5203 | src_class_die->GetOffset(), |
| 5204 | dst_class_die->GetOffset(), |
| 5205 | src_die->GetOffset(), |
| 5206 | src_name, |
| 5207 | dst_die->GetOffset(), |
| 5208 | dst_name); |
| 5209 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5210 | fast_path = false; |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5211 | } |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5212 | } |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5213 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5214 | // Now do the work of linking the DeclContexts and Types. |
| 5215 | if (fast_path) |
| 5216 | { |
| 5217 | // We can do this quickly. Just run across the tables index-for-index since |
| 5218 | // we know each node has matching names and tags. |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5219 | for (idx = 0; idx < src_size; ++idx) |
| 5220 | { |
| 5221 | src_die = src_name_to_die.GetValueAtIndexUnchecked (idx); |
| 5222 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx); |
| 5223 | |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5224 | 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] | 5225 | if (src_decl_ctx) |
| 5226 | { |
| 5227 | if (log) |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5228 | 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] | 5229 | LinkDeclContextToDIE (src_decl_ctx, dst_die); |
| 5230 | } |
| 5231 | else |
| 5232 | { |
| 5233 | if (log) |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5234 | 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] | 5235 | } |
| 5236 | |
| 5237 | Type *src_child_type = m_die_to_type[src_die]; |
| 5238 | if (src_child_type) |
| 5239 | { |
| 5240 | if (log) |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5241 | 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] | 5242 | m_die_to_type[dst_die] = src_child_type; |
| 5243 | } |
| 5244 | else |
| 5245 | { |
| 5246 | if (log) |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5247 | 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()); |
| 5248 | } |
| 5249 | } |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5250 | } |
| 5251 | else |
| 5252 | { |
| 5253 | // We must do this slowly. For each member of the destination, look |
| 5254 | // up a member in the source with the same name, check its tag, and |
| 5255 | // unique them if everything matches up. Report failures. |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5256 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5257 | if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty()) |
| 5258 | { |
| 5259 | src_name_to_die.Sort(); |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5260 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5261 | for (idx = 0; idx < dst_size; ++idx) |
| 5262 | { |
| 5263 | const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx); |
| 5264 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx); |
| 5265 | src_die = src_name_to_die.Find(dst_name, NULL); |
| 5266 | |
| 5267 | if (src_die && (src_die->Tag() == dst_die->Tag())) |
| 5268 | { |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5269 | 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] | 5270 | if (src_decl_ctx) |
| 5271 | { |
| 5272 | if (log) |
| 5273 | log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset()); |
| 5274 | LinkDeclContextToDIE (src_decl_ctx, dst_die); |
| 5275 | } |
| 5276 | else |
| 5277 | { |
| 5278 | if (log) |
| 5279 | 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()); |
| 5280 | } |
| 5281 | |
| 5282 | Type *src_child_type = m_die_to_type[src_die]; |
| 5283 | if (src_child_type) |
| 5284 | { |
| 5285 | if (log) |
| 5286 | 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()); |
| 5287 | m_die_to_type[dst_die] = src_child_type; |
| 5288 | } |
| 5289 | else |
| 5290 | { |
| 5291 | if (log) |
| 5292 | 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()); |
| 5293 | } |
| 5294 | } |
| 5295 | else |
| 5296 | { |
| 5297 | if (log) |
| 5298 | 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] | 5299 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5300 | failures.push_back(dst_die); |
| 5301 | } |
| 5302 | } |
| 5303 | } |
| 5304 | } |
| 5305 | |
| 5306 | const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize (); |
| 5307 | const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize (); |
| 5308 | |
| 5309 | UniqueCStringMap<const DWARFDebugInfoEntry *> name_to_die_artificial_not_in_src; |
| 5310 | |
| 5311 | if (src_size_artificial && dst_size_artificial) |
| 5312 | { |
| 5313 | dst_name_to_die_artificial.Sort(); |
| 5314 | |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5315 | for (idx = 0; idx < src_size_artificial; ++idx) |
| 5316 | { |
| 5317 | const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx); |
| 5318 | src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx); |
| 5319 | dst_die = dst_name_to_die_artificial.Find(src_name_artificial, NULL); |
| 5320 | |
| 5321 | if (dst_die) |
| 5322 | { |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5323 | // Both classes have the artificial types, link them |
| 5324 | clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die]; |
| 5325 | if (src_decl_ctx) |
| 5326 | { |
| 5327 | if (log) |
| 5328 | log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset()); |
| 5329 | LinkDeclContextToDIE (src_decl_ctx, dst_die); |
| 5330 | } |
| 5331 | else |
| 5332 | { |
| 5333 | if (log) |
| 5334 | 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()); |
| 5335 | } |
| 5336 | |
| 5337 | Type *src_child_type = m_die_to_type[src_die]; |
| 5338 | if (src_child_type) |
| 5339 | { |
| 5340 | if (log) |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5341 | 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] | 5342 | m_die_to_type[dst_die] = src_child_type; |
| 5343 | } |
| 5344 | else |
| 5345 | { |
| 5346 | if (log) |
| 5347 | 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()); |
| 5348 | } |
| 5349 | } |
| 5350 | } |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5351 | } |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5352 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5353 | if (dst_size_artificial) |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5354 | { |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5355 | for (idx = 0; idx < dst_size_artificial; ++idx) |
| 5356 | { |
| 5357 | const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx); |
| 5358 | dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx); |
| 5359 | if (log) |
| 5360 | log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die->GetOffset(), dst_name_artificial); |
| 5361 | |
| 5362 | failures.push_back(dst_die); |
| 5363 | } |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5364 | } |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5365 | |
| 5366 | return (failures.size() != 0); |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5367 | } |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5368 | |
| 5369 | TypeSP |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5370 | 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] | 5371 | { |
| 5372 | TypeSP type_sp; |
| 5373 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5374 | if (type_is_new_ptr) |
| 5375 | *type_is_new_ptr = false; |
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5376 | |
| 5377 | #if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE) |
| 5378 | static DIEStack g_die_stack; |
| 5379 | DIEStack::ScopedPopper scoped_die_logger(g_die_stack); |
| 5380 | #endif |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5381 | |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 5382 | AccessType accessibility = eAccessNone; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5383 | if (die != NULL) |
| 5384 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5385 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5386 | if (log) |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5387 | { |
| 5388 | const DWARFDebugInfoEntry *context_die; |
| 5389 | clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die); |
| 5390 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5391 | 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] | 5392 | die->GetOffset(), |
| 5393 | context, |
| 5394 | context_die->GetOffset(), |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5395 | DW_TAG_value_to_name(die->Tag()), |
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5396 | die->GetName(this, dwarf_cu)); |
| 5397 | |
| 5398 | #if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE) |
| 5399 | scoped_die_logger.Push (dwarf_cu, die); |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5400 | g_die_stack.LogDIEs(log, this); |
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5401 | #endif |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5402 | } |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5403 | // |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5404 | // Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5405 | // if (log && dwarf_cu) |
| 5406 | // { |
| 5407 | // StreamString s; |
| 5408 | // die->DumpLocation (this, dwarf_cu, s); |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5409 | // GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData()); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5410 | // |
| 5411 | // } |
| Jim Ingham | 16746d1 | 2011-08-25 23:21:43 +0000 | [diff] [blame] | 5412 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5413 | Type *type_ptr = m_die_to_type.lookup (die); |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5414 | TypeList* type_list = GetTypeList(); |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5415 | if (type_ptr == NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5416 | { |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5417 | ClangASTContext &ast = GetClangASTContext(); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5418 | if (type_is_new_ptr) |
| 5419 | *type_is_new_ptr = true; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5420 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5421 | const dw_tag_t tag = die->Tag(); |
| 5422 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5423 | bool is_forward_declaration = false; |
| 5424 | DWARFDebugInfoEntry::Attributes attributes; |
| 5425 | const char *type_name_cstr = NULL; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5426 | ConstString type_name_const_str; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5427 | Type::ResolveState resolve_state = Type::eResolveStateUnresolved; |
| Greg Clayton | faac111 | 2013-03-14 18:31:44 +0000 | [diff] [blame] | 5428 | uint64_t byte_size = 0; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5429 | Declaration decl; |
| 5430 | |
| Greg Clayton | 4957bf6 | 2010-09-30 21:49:03 +0000 | [diff] [blame] | 5431 | Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5432 | clang_type_t clang_type = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5433 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5434 | dw_attr_t attr; |
| 5435 | |
| 5436 | switch (tag) |
| 5437 | { |
| 5438 | case DW_TAG_base_type: |
| 5439 | case DW_TAG_pointer_type: |
| 5440 | case DW_TAG_reference_type: |
| Sean Callanan | ce8af86 | 2012-05-21 23:31:51 +0000 | [diff] [blame] | 5441 | case DW_TAG_rvalue_reference_type: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5442 | case DW_TAG_typedef: |
| 5443 | case DW_TAG_const_type: |
| 5444 | case DW_TAG_restrict_type: |
| 5445 | case DW_TAG_volatile_type: |
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5446 | case DW_TAG_unspecified_type: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5447 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5448 | // 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] | 5449 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5450 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5451 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5452 | uint32_t encoding = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5453 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; |
| 5454 | |
| 5455 | if (num_attributes > 0) |
| 5456 | { |
| 5457 | uint32_t i; |
| 5458 | for (i=0; i<num_attributes; ++i) |
| 5459 | { |
| 5460 | attr = attributes.AttributeAtIndex(i); |
| 5461 | DWARFFormValue form_value; |
| 5462 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 5463 | { |
| 5464 | switch (attr) |
| 5465 | { |
| 5466 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 5467 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 5468 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 5469 | case DW_AT_name: |
| Jim Ingham | 337030f | 2011-04-15 23:41:23 +0000 | [diff] [blame] | 5470 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5471 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Jim Ingham | 337030f | 2011-04-15 23:41:23 +0000 | [diff] [blame] | 5472 | // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't |
| 5473 | // include the "&"... |
| 5474 | if (tag == DW_TAG_reference_type) |
| 5475 | { |
| 5476 | if (strchr (type_name_cstr, '&') == NULL) |
| 5477 | type_name_cstr = NULL; |
| 5478 | } |
| 5479 | if (type_name_cstr) |
| 5480 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5481 | break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 5482 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5483 | case DW_AT_encoding: encoding = form_value.Unsigned(); break; |
| 5484 | case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; |
| 5485 | default: |
| 5486 | case DW_AT_sibling: |
| 5487 | break; |
| 5488 | } |
| 5489 | } |
| 5490 | } |
| 5491 | } |
| 5492 | |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5493 | 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] | 5494 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5495 | switch (tag) |
| 5496 | { |
| 5497 | default: |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5498 | break; |
| 5499 | |
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5500 | case DW_TAG_unspecified_type: |
| 5501 | if (strcmp(type_name_cstr, "nullptr_t") == 0) |
| 5502 | { |
| 5503 | resolve_state = Type::eResolveStateFull; |
| 5504 | clang_type = ast.getASTContext()->NullPtrTy.getAsOpaquePtr(); |
| 5505 | break; |
| 5506 | } |
| 5507 | // Fall through to base type below in case we can handle the type there... |
| 5508 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5509 | case DW_TAG_base_type: |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5510 | resolve_state = Type::eResolveStateFull; |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5511 | clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr, |
| 5512 | encoding, |
| 5513 | byte_size * 8); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5514 | break; |
| 5515 | |
| Sean Callanan | ce8af86 | 2012-05-21 23:31:51 +0000 | [diff] [blame] | 5516 | case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break; |
| 5517 | case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break; |
| 5518 | case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break; |
| 5519 | case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break; |
| 5520 | case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break; |
| 5521 | case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break; |
| 5522 | case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5523 | } |
| 5524 | |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5525 | 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] | 5526 | { |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5527 | bool translation_unit_is_objc = (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus); |
| 5528 | |
| 5529 | if (translation_unit_is_objc) |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 5530 | { |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5531 | if (type_name_cstr != NULL) |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5532 | { |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5533 | static ConstString g_objc_type_name_id("id"); |
| 5534 | static ConstString g_objc_type_name_Class("Class"); |
| 5535 | static ConstString g_objc_type_name_selector("SEL"); |
| 5536 | |
| 5537 | if (type_name_const_str == g_objc_type_name_id) |
| 5538 | { |
| 5539 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5540 | 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] | 5541 | die->GetOffset(), |
| 5542 | DW_TAG_value_to_name(die->Tag()), |
| 5543 | die->GetName(this, dwarf_cu)); |
| 5544 | clang_type = ast.GetBuiltInType_objc_id(); |
| 5545 | encoding_data_type = Type::eEncodingIsUID; |
| 5546 | encoding_uid = LLDB_INVALID_UID; |
| 5547 | resolve_state = Type::eResolveStateFull; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5548 | |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5549 | } |
| 5550 | else if (type_name_const_str == g_objc_type_name_Class) |
| 5551 | { |
| 5552 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5553 | 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] | 5554 | die->GetOffset(), |
| 5555 | DW_TAG_value_to_name(die->Tag()), |
| 5556 | die->GetName(this, dwarf_cu)); |
| 5557 | clang_type = ast.GetBuiltInType_objc_Class(); |
| 5558 | encoding_data_type = Type::eEncodingIsUID; |
| 5559 | encoding_uid = LLDB_INVALID_UID; |
| 5560 | resolve_state = Type::eResolveStateFull; |
| 5561 | } |
| 5562 | else if (type_name_const_str == g_objc_type_name_selector) |
| 5563 | { |
| 5564 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5565 | 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] | 5566 | die->GetOffset(), |
| 5567 | DW_TAG_value_to_name(die->Tag()), |
| 5568 | die->GetName(this, dwarf_cu)); |
| 5569 | clang_type = ast.GetBuiltInType_objc_selector(); |
| 5570 | encoding_data_type = Type::eEncodingIsUID; |
| 5571 | encoding_uid = LLDB_INVALID_UID; |
| 5572 | resolve_state = Type::eResolveStateFull; |
| 5573 | } |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5574 | } |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5575 | else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid != LLDB_INVALID_UID) |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5576 | { |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5577 | // Clang sometimes erroneously emits id as objc_object*. In that case we fix up the type to "id". |
| 5578 | |
| 5579 | DWARFDebugInfoEntry* encoding_die = dwarf_cu->GetDIEPtr(encoding_uid); |
| 5580 | |
| 5581 | if (encoding_die && encoding_die->Tag() == DW_TAG_structure_type) |
| 5582 | { |
| 5583 | if (const char *struct_name = encoding_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL)) |
| 5584 | { |
| 5585 | if (!strcmp(struct_name, "objc_object")) |
| 5586 | { |
| 5587 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5588 | 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] | 5589 | die->GetOffset(), |
| 5590 | DW_TAG_value_to_name(die->Tag()), |
| 5591 | die->GetName(this, dwarf_cu)); |
| 5592 | clang_type = ast.GetBuiltInType_objc_id(); |
| 5593 | encoding_data_type = Type::eEncodingIsUID; |
| 5594 | encoding_uid = LLDB_INVALID_UID; |
| 5595 | resolve_state = Type::eResolveStateFull; |
| 5596 | } |
| 5597 | } |
| 5598 | } |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5599 | } |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 5600 | } |
| 5601 | } |
| 5602 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5603 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5604 | this, |
| 5605 | type_name_const_str, |
| 5606 | byte_size, |
| 5607 | NULL, |
| 5608 | encoding_uid, |
| 5609 | encoding_data_type, |
| 5610 | &decl, |
| 5611 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5612 | resolve_state)); |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5613 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5614 | m_die_to_type[die] = type_sp.get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5615 | |
| 5616 | // Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false); |
| 5617 | // if (encoding_type != NULL) |
| 5618 | // { |
| 5619 | // if (encoding_type != DIE_IS_BEING_PARSED) |
| 5620 | // type_sp->SetEncodingType(encoding_type); |
| 5621 | // else |
| 5622 | // m_indirect_fixups.push_back(type_sp.get()); |
| 5623 | // } |
| 5624 | } |
| 5625 | break; |
| 5626 | |
| 5627 | case DW_TAG_structure_type: |
| 5628 | case DW_TAG_union_type: |
| 5629 | case DW_TAG_class_type: |
| 5630 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5631 | // 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] | 5632 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 5633 | bool byte_size_valid = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5634 | |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5635 | LanguageType class_language = eLanguageTypeUnknown; |
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 5636 | bool is_complete_objc_class = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5637 | //bool struct_is_class = false; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5638 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5639 | if (num_attributes > 0) |
| 5640 | { |
| 5641 | uint32_t i; |
| 5642 | for (i=0; i<num_attributes; ++i) |
| 5643 | { |
| 5644 | attr = attributes.AttributeAtIndex(i); |
| 5645 | DWARFFormValue form_value; |
| 5646 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 5647 | { |
| 5648 | switch (attr) |
| 5649 | { |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5650 | case DW_AT_decl_file: |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5651 | if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid()) |
| 5652 | { |
| 5653 | // llvm-gcc outputs invalid DW_AT_decl_file attributes that always |
| 5654 | // point to the compile unit file, so we clear this invalid value |
| 5655 | // so that we can still unique types efficiently. |
| 5656 | decl.SetFile(FileSpec ("<invalid>", false)); |
| 5657 | } |
| 5658 | else |
| 5659 | decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5660 | break; |
| 5661 | |
| 5662 | case DW_AT_decl_line: |
| 5663 | decl.SetLine(form_value.Unsigned()); |
| 5664 | break; |
| 5665 | |
| 5666 | case DW_AT_decl_column: |
| 5667 | decl.SetColumn(form_value.Unsigned()); |
| 5668 | break; |
| 5669 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5670 | case DW_AT_name: |
| 5671 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5672 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5673 | break; |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5674 | |
| 5675 | case DW_AT_byte_size: |
| 5676 | byte_size = form_value.Unsigned(); |
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 5677 | byte_size_valid = true; |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5678 | break; |
| 5679 | |
| 5680 | case DW_AT_accessibility: |
| 5681 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); |
| 5682 | break; |
| 5683 | |
| 5684 | case DW_AT_declaration: |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 5685 | is_forward_declaration = form_value.Unsigned() != 0; |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5686 | break; |
| 5687 | |
| 5688 | case DW_AT_APPLE_runtime_class: |
| 5689 | class_language = (LanguageType)form_value.Signed(); |
| 5690 | break; |
| 5691 | |
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 5692 | case DW_AT_APPLE_objc_complete_type: |
| 5693 | is_complete_objc_class = form_value.Signed(); |
| 5694 | break; |
| 5695 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5696 | case DW_AT_allocated: |
| 5697 | case DW_AT_associated: |
| 5698 | case DW_AT_data_location: |
| 5699 | case DW_AT_description: |
| 5700 | case DW_AT_start_scope: |
| 5701 | case DW_AT_visibility: |
| 5702 | default: |
| 5703 | case DW_AT_sibling: |
| 5704 | break; |
| 5705 | } |
| 5706 | } |
| 5707 | } |
| 5708 | } |
| 5709 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5710 | UniqueDWARFASTType unique_ast_entry; |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5711 | |
| Greg Clayton | 123edca | 2012-03-02 00:07:15 +0000 | [diff] [blame] | 5712 | // Only try and unique the type if it has a name. |
| 5713 | if (type_name_const_str && |
| 5714 | GetUniqueDWARFASTTypeMap().Find (type_name_const_str, |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5715 | this, |
| 5716 | dwarf_cu, |
| 5717 | die, |
| 5718 | decl, |
| 5719 | byte_size_valid ? byte_size : -1, |
| 5720 | unique_ast_entry)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5721 | { |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5722 | // We have already parsed this type or from another |
| 5723 | // compile unit. GCC loves to use the "one definition |
| 5724 | // rule" which can result in multiple definitions |
| 5725 | // of the same class over and over in each compile |
| 5726 | // unit. |
| 5727 | type_sp = unique_ast_entry.m_type_sp; |
| 5728 | if (type_sp) |
| Greg Clayton | c615ce4 | 2010-11-09 04:42:43 +0000 | [diff] [blame] | 5729 | { |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5730 | m_die_to_type[die] = type_sp.get(); |
| 5731 | return type_sp; |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5732 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5733 | } |
| 5734 | |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5735 | 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] | 5736 | |
| 5737 | int tag_decl_kind = -1; |
| 5738 | AccessType default_accessibility = eAccessNone; |
| 5739 | if (tag == DW_TAG_structure_type) |
| 5740 | { |
| 5741 | tag_decl_kind = clang::TTK_Struct; |
| 5742 | default_accessibility = eAccessPublic; |
| 5743 | } |
| 5744 | else if (tag == DW_TAG_union_type) |
| 5745 | { |
| 5746 | tag_decl_kind = clang::TTK_Union; |
| 5747 | default_accessibility = eAccessPublic; |
| 5748 | } |
| 5749 | else if (tag == DW_TAG_class_type) |
| 5750 | { |
| 5751 | tag_decl_kind = clang::TTK_Class; |
| 5752 | default_accessibility = eAccessPrivate; |
| 5753 | } |
| Greg Clayton | 3a5f29a | 2011-11-30 02:48:28 +0000 | [diff] [blame] | 5754 | |
| 5755 | if (byte_size_valid && byte_size == 0 && type_name_cstr && |
| 5756 | die->HasChildren() == false && |
| 5757 | sc.comp_unit->GetLanguage() == eLanguageTypeObjC) |
| 5758 | { |
| 5759 | // Work around an issue with clang at the moment where |
| 5760 | // forward declarations for objective C classes are emitted |
| 5761 | // as: |
| 5762 | // DW_TAG_structure_type [2] |
| 5763 | // DW_AT_name( "ForwardObjcClass" ) |
| 5764 | // DW_AT_byte_size( 0x00 ) |
| 5765 | // DW_AT_decl_file( "..." ) |
| 5766 | // DW_AT_decl_line( 1 ) |
| 5767 | // |
| 5768 | // Note that there is no DW_AT_declaration and there are |
| 5769 | // no children, and the byte size is zero. |
| 5770 | is_forward_declaration = true; |
| 5771 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5772 | |
| Sean Callanan | 7457f8d | 2012-04-25 01:03:57 +0000 | [diff] [blame] | 5773 | if (class_language == eLanguageTypeObjC || |
| 5774 | class_language == eLanguageTypeObjC_plus_plus) |
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 5775 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5776 | 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] | 5777 | { |
| 5778 | // We have a valid eSymbolTypeObjCClass class symbol whose |
| 5779 | // name matches the current objective C class that we |
| 5780 | // are trying to find and this DIE isn't the complete |
| 5781 | // definition (we checked is_complete_objc_class above and |
| 5782 | // know it is false), so the real definition is in here somewhere |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5783 | type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true); |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5784 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 5785 | if (!type_sp && GetDebugMapSymfile ()) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5786 | { |
| 5787 | // We weren't able to find a full declaration in |
| 5788 | // this DWARF, see if we have a declaration anywhere |
| 5789 | // else... |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5790 | 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] | 5791 | } |
| 5792 | |
| 5793 | if (type_sp) |
| 5794 | { |
| 5795 | if (log) |
| 5796 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5797 | GetObjectFile()->GetModule()->LogMessage (log, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5798 | "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] | 5799 | this, |
| 5800 | die->GetOffset(), |
| 5801 | DW_TAG_value_to_name(tag), |
| 5802 | type_name_cstr, |
| 5803 | type_sp->GetID()); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5804 | } |
| 5805 | |
| 5806 | // We found a real definition for this type elsewhere |
| 5807 | // so lets use it and cache the fact that we found |
| 5808 | // a complete type for this die |
| 5809 | m_die_to_type[die] = type_sp.get(); |
| 5810 | return type_sp; |
| 5811 | } |
| 5812 | } |
| 5813 | } |
| 5814 | |
| 5815 | |
| 5816 | if (is_forward_declaration) |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5817 | { |
| 5818 | // We have a forward declaration to a type and we need |
| 5819 | // to try and find a full declaration. We look in the |
| 5820 | // current type index just in case we have a forward |
| 5821 | // declaration followed by an actual declarations in the |
| 5822 | // DWARF. If this fails, we need to look elsewhere... |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 5823 | if (log) |
| 5824 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5825 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5826 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type", |
| 5827 | this, |
| 5828 | die->GetOffset(), |
| 5829 | DW_TAG_value_to_name(tag), |
| 5830 | type_name_cstr); |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 5831 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5832 | |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5833 | DWARFDeclContext die_decl_ctx; |
| 5834 | die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx); |
| 5835 | |
| 5836 | //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str); |
| 5837 | type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5838 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 5839 | if (!type_sp && GetDebugMapSymfile ()) |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5840 | { |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5841 | // We weren't able to find a full declaration in |
| 5842 | // this DWARF, see if we have a declaration anywhere |
| 5843 | // else... |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5844 | type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5845 | } |
| 5846 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5847 | if (type_sp) |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5848 | { |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 5849 | if (log) |
| 5850 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5851 | GetObjectFile()->GetModule()->LogMessage (log, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5852 | "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] | 5853 | this, |
| 5854 | die->GetOffset(), |
| 5855 | DW_TAG_value_to_name(tag), |
| 5856 | type_name_cstr, |
| 5857 | type_sp->GetID()); |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 5858 | } |
| 5859 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5860 | // We found a real definition for this type elsewhere |
| 5861 | // so lets use it and cache the fact that we found |
| 5862 | // a complete type for this die |
| 5863 | m_die_to_type[die] = type_sp.get(); |
| 5864 | return type_sp; |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5865 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5866 | } |
| 5867 | assert (tag_decl_kind != -1); |
| 5868 | bool clang_type_was_created = false; |
| 5869 | clang_type = m_forward_decl_die_to_clang_type.lookup (die); |
| 5870 | if (clang_type == NULL) |
| 5871 | { |
| Sean Callanan | 4d04c6a | 2012-02-09 22:54:11 +0000 | [diff] [blame] | 5872 | const DWARFDebugInfoEntry *decl_ctx_die; |
| 5873 | |
| 5874 | clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die); |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 5875 | if (accessibility == eAccessNone && decl_ctx) |
| 5876 | { |
| 5877 | // Check the decl context that contains this class/struct/union. |
| 5878 | // If it is a class we must give it an accessability. |
| 5879 | const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind(); |
| 5880 | if (DeclKindIsCXXClass (containing_decl_kind)) |
| 5881 | accessibility = default_accessibility; |
| 5882 | } |
| 5883 | |
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 5884 | ClangASTMetadata metadata; |
| 5885 | metadata.SetUserID(MakeUserID(die->GetOffset())); |
| 5886 | metadata.SetIsDynamicCXXType(ClassOrStructIsVirtual (dwarf_cu, die)); |
| 5887 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5888 | if (type_name_cstr && strchr (type_name_cstr, '<')) |
| 5889 | { |
| 5890 | ClangASTContext::TemplateParameterInfos template_param_infos; |
| 5891 | if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos)) |
| 5892 | { |
| 5893 | clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx, |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 5894 | accessibility, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5895 | type_name_cstr, |
| 5896 | tag_decl_kind, |
| 5897 | template_param_infos); |
| 5898 | |
| 5899 | clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx, |
| 5900 | class_template_decl, |
| 5901 | tag_decl_kind, |
| 5902 | template_param_infos); |
| 5903 | clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl); |
| 5904 | clang_type_was_created = true; |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 5905 | |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 5906 | GetClangASTContext().SetMetadata (class_template_decl, metadata); |
| 5907 | GetClangASTContext().SetMetadata (class_specialization_decl, metadata); |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5908 | } |
| 5909 | } |
| 5910 | |
| 5911 | if (!clang_type_was_created) |
| 5912 | { |
| 5913 | clang_type_was_created = true; |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 5914 | clang_type = ast.CreateRecordType (decl_ctx, |
| 5915 | accessibility, |
| 5916 | type_name_cstr, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5917 | tag_decl_kind, |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 5918 | class_language, |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 5919 | &metadata); |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5920 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5921 | } |
| 5922 | |
| 5923 | // Store a forward declaration to this class type in case any |
| 5924 | // parameters in any class methods need it for the clang |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 5925 | // types for function prototypes. |
| 5926 | LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5927 | type_sp.reset (new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5928 | this, |
| 5929 | type_name_const_str, |
| 5930 | byte_size, |
| 5931 | NULL, |
| 5932 | LLDB_INVALID_UID, |
| 5933 | Type::eEncodingIsUID, |
| 5934 | &decl, |
| 5935 | clang_type, |
| 5936 | Type::eResolveStateForward)); |
| Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 5937 | |
| 5938 | type_sp->SetIsCompleteObjCClass(is_complete_objc_class); |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5939 | |
| 5940 | |
| 5941 | // Add our type to the unique type map so we don't |
| 5942 | // end up creating many copies of the same type over |
| 5943 | // and over in the ASTContext for our module |
| 5944 | unique_ast_entry.m_type_sp = type_sp; |
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 5945 | unique_ast_entry.m_symfile = this; |
| 5946 | unique_ast_entry.m_cu = dwarf_cu; |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5947 | unique_ast_entry.m_die = die; |
| 5948 | unique_ast_entry.m_declaration = decl; |
| Sean Callanan | 5970059 | 2012-02-13 22:30:16 +0000 | [diff] [blame] | 5949 | unique_ast_entry.m_byte_size = byte_size; |
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 5950 | GetUniqueDWARFASTTypeMap().Insert (type_name_const_str, |
| 5951 | unique_ast_entry); |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5952 | |
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 5953 | if (!is_forward_declaration) |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 5954 | { |
| 5955 | // Always start the definition for a class type so that |
| 5956 | // if the class has child classes or types that require |
| 5957 | // the class to be created for use as their decl contexts |
| 5958 | // the class will be ready to accept these child definitions. |
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 5959 | if (die->HasChildren() == false) |
| 5960 | { |
| 5961 | // No children for this struct/union/class, lets finish it |
| 5962 | ast.StartTagDeclarationDefinition (clang_type); |
| 5963 | ast.CompleteTagDeclarationDefinition (clang_type); |
| Sean Callanan | 433cd22 | 2012-10-19 01:37:25 +0000 | [diff] [blame] | 5964 | |
| 5965 | if (tag == DW_TAG_structure_type) // this only applies in C |
| 5966 | { |
| 5967 | clang::QualType qual_type = clang::QualType::getFromOpaquePtr (clang_type); |
| 5968 | const clang::RecordType *record_type = qual_type->getAs<clang::RecordType> (); |
| 5969 | |
| 5970 | if (record_type) |
| 5971 | { |
| 5972 | clang::RecordDecl *record_decl = record_type->getDecl(); |
| 5973 | |
| 5974 | if (record_decl) |
| 5975 | { |
| 5976 | LayoutInfo layout_info; |
| 5977 | |
| 5978 | layout_info.alignment = 0; |
| 5979 | layout_info.bit_size = 0; |
| 5980 | |
| 5981 | m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info)); |
| 5982 | } |
| 5983 | } |
| 5984 | } |
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 5985 | } |
| 5986 | else if (clang_type_was_created) |
| 5987 | { |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 5988 | // Start the definition if the class is not objective C since |
| 5989 | // the underlying decls respond to isCompleteDefinition(). Objective |
| 5990 | // C decls dont' respond to isCompleteDefinition() so we can't |
| 5991 | // start the declaration definition right away. For C++ classs/union/structs |
| 5992 | // we want to start the definition in case the class is needed as the |
| 5993 | // declaration context for a contained class or type without the need |
| 5994 | // to complete that type.. |
| 5995 | |
| Sean Callanan | 7457f8d | 2012-04-25 01:03:57 +0000 | [diff] [blame] | 5996 | if (class_language != eLanguageTypeObjC && |
| 5997 | class_language != eLanguageTypeObjC_plus_plus) |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 5998 | ast.StartTagDeclarationDefinition (clang_type); |
| 5999 | |
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6000 | // Leave this as a forward declaration until we need |
| 6001 | // to know the details of the type. lldb_private::Type |
| 6002 | // will automatically call the SymbolFile virtual function |
| 6003 | // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)" |
| 6004 | // When the definition needs to be defined. |
| 6005 | m_forward_decl_die_to_clang_type[die] = clang_type; |
| 6006 | m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die; |
| 6007 | ClangASTContext::SetHasExternalStorage (clang_type, true); |
| 6008 | } |
| Greg Clayton | c615ce4 | 2010-11-09 04:42:43 +0000 | [diff] [blame] | 6009 | } |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 6010 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6011 | } |
| 6012 | break; |
| 6013 | |
| 6014 | case DW_TAG_enumeration_type: |
| 6015 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6016 | // 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] | 6017 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6018 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6019 | lldb::user_id_t encoding_uid = DW_INVALID_OFFSET; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6020 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6021 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6022 | if (num_attributes > 0) |
| 6023 | { |
| 6024 | uint32_t i; |
| 6025 | |
| 6026 | for (i=0; i<num_attributes; ++i) |
| 6027 | { |
| 6028 | attr = attributes.AttributeAtIndex(i); |
| 6029 | DWARFFormValue form_value; |
| 6030 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 6031 | { |
| 6032 | switch (attr) |
| 6033 | { |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 6034 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 6035 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 6036 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6037 | case DW_AT_name: |
| 6038 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6039 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6040 | break; |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 6041 | case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6042 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; |
| 6043 | case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
| 6044 | 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] | 6045 | case DW_AT_allocated: |
| 6046 | case DW_AT_associated: |
| 6047 | case DW_AT_bit_stride: |
| 6048 | case DW_AT_byte_stride: |
| 6049 | case DW_AT_data_location: |
| 6050 | case DW_AT_description: |
| 6051 | case DW_AT_start_scope: |
| 6052 | case DW_AT_visibility: |
| 6053 | case DW_AT_specification: |
| 6054 | case DW_AT_abstract_origin: |
| 6055 | case DW_AT_sibling: |
| 6056 | break; |
| 6057 | } |
| 6058 | } |
| 6059 | } |
| 6060 | |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6061 | 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] | 6062 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6063 | clang_type_t enumerator_clang_type = NULL; |
| 6064 | clang_type = m_forward_decl_die_to_clang_type.lookup (die); |
| 6065 | if (clang_type == NULL) |
| 6066 | { |
| Greg Clayton | 5d14fc0 | 2013-03-06 06:23:54 +0000 | [diff] [blame] | 6067 | if (encoding_uid != DW_INVALID_OFFSET) |
| 6068 | { |
| 6069 | Type *enumerator_type = ResolveTypeUID(encoding_uid); |
| 6070 | if (enumerator_type) |
| 6071 | enumerator_clang_type = enumerator_type->GetClangFullType(); |
| 6072 | } |
| 6073 | |
| 6074 | if (enumerator_clang_type == NULL) |
| 6075 | enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL, |
| 6076 | DW_ATE_signed, |
| 6077 | byte_size * 8); |
| 6078 | |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 6079 | clang_type = ast.CreateEnumerationType (type_name_cstr, |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6080 | GetClangDeclContextContainingDIE (dwarf_cu, die, NULL), |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 6081 | decl, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6082 | enumerator_clang_type); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6083 | } |
| 6084 | else |
| 6085 | { |
| 6086 | enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6087 | } |
| 6088 | |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6089 | LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die); |
| 6090 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6091 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6092 | this, |
| 6093 | type_name_const_str, |
| 6094 | byte_size, |
| 6095 | NULL, |
| 6096 | encoding_uid, |
| 6097 | Type::eEncodingIsUID, |
| 6098 | &decl, |
| 6099 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6100 | Type::eResolveStateForward)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6101 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 6102 | ast.StartTagDeclarationDefinition (clang_type); |
| 6103 | if (die->HasChildren()) |
| 6104 | { |
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 6105 | SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); |
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 6106 | bool is_signed = false; |
| Greg Clayton | 5d14fc0 | 2013-03-06 06:23:54 +0000 | [diff] [blame] | 6107 | ast.IsIntegerType(enumerator_clang_type, is_signed); |
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 6108 | 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] | 6109 | } |
| 6110 | ast.CompleteTagDeclarationDefinition (clang_type); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6111 | } |
| 6112 | } |
| 6113 | break; |
| 6114 | |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 6115 | case DW_TAG_inlined_subroutine: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6116 | case DW_TAG_subprogram: |
| 6117 | case DW_TAG_subroutine_type: |
| 6118 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6119 | // 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] | 6120 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6121 | |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6122 | //const char *mangled = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6123 | dw_offset_t type_die_offset = DW_INVALID_OFFSET; |
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 6124 | bool is_variadic = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6125 | bool is_inline = false; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6126 | bool is_static = false; |
| 6127 | bool is_virtual = false; |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6128 | bool is_explicit = false; |
| Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 6129 | bool is_artificial = false; |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6130 | dw_offset_t specification_die_offset = DW_INVALID_OFFSET; |
| 6131 | dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET; |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6132 | dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6133 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6134 | unsigned type_quals = 0; |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 6135 | clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6136 | |
| 6137 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6138 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6139 | if (num_attributes > 0) |
| 6140 | { |
| 6141 | uint32_t i; |
| 6142 | for (i=0; i<num_attributes; ++i) |
| 6143 | { |
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 6144 | attr = attributes.AttributeAtIndex(i); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6145 | DWARFFormValue form_value; |
| 6146 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 6147 | { |
| 6148 | switch (attr) |
| 6149 | { |
| 6150 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 6151 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 6152 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 6153 | case DW_AT_name: |
| 6154 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6155 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6156 | break; |
| 6157 | |
| Greg Clayton | 7141554 | 2012-12-08 00:24:40 +0000 | [diff] [blame] | 6158 | case DW_AT_linkage_name: |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6159 | 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] | 6160 | 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] | 6161 | 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] | 6162 | 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] | 6163 | case DW_AT_inline: is_inline = form_value.Unsigned() != 0; break; |
| 6164 | case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break; |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6165 | case DW_AT_explicit: is_explicit = form_value.Unsigned() != 0; break; |
| Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 6166 | case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break; |
| 6167 | |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6168 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6169 | case DW_AT_external: |
| 6170 | if (form_value.Unsigned()) |
| 6171 | { |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 6172 | if (storage == clang::SC_None) |
| 6173 | storage = clang::SC_Extern; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6174 | else |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 6175 | storage = clang::SC_PrivateExtern; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6176 | } |
| 6177 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6178 | |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6179 | case DW_AT_specification: |
| 6180 | specification_die_offset = form_value.Reference(dwarf_cu); |
| 6181 | break; |
| 6182 | |
| 6183 | case DW_AT_abstract_origin: |
| 6184 | abstract_origin_die_offset = form_value.Reference(dwarf_cu); |
| 6185 | break; |
| 6186 | |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6187 | case DW_AT_object_pointer: |
| 6188 | object_pointer_die_offset = form_value.Reference(dwarf_cu); |
| 6189 | break; |
| 6190 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6191 | case DW_AT_allocated: |
| 6192 | case DW_AT_associated: |
| 6193 | case DW_AT_address_class: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6194 | case DW_AT_calling_convention: |
| 6195 | case DW_AT_data_location: |
| 6196 | case DW_AT_elemental: |
| 6197 | case DW_AT_entry_pc: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6198 | case DW_AT_frame_base: |
| 6199 | case DW_AT_high_pc: |
| 6200 | case DW_AT_low_pc: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6201 | case DW_AT_prototyped: |
| 6202 | case DW_AT_pure: |
| 6203 | case DW_AT_ranges: |
| 6204 | case DW_AT_recursive: |
| 6205 | case DW_AT_return_addr: |
| 6206 | case DW_AT_segment: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6207 | case DW_AT_start_scope: |
| 6208 | case DW_AT_static_link: |
| 6209 | case DW_AT_trampoline: |
| 6210 | case DW_AT_visibility: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6211 | case DW_AT_vtable_elem_location: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6212 | case DW_AT_description: |
| 6213 | case DW_AT_sibling: |
| 6214 | break; |
| 6215 | } |
| 6216 | } |
| 6217 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6218 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6219 | |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6220 | std::string object_pointer_name; |
| 6221 | if (object_pointer_die_offset != DW_INVALID_OFFSET) |
| 6222 | { |
| 6223 | // Get the name from the object pointer die |
| 6224 | StreamString s; |
| 6225 | if (DWARFDebugInfoEntry::GetName (this, dwarf_cu, object_pointer_die_offset, s)) |
| 6226 | { |
| 6227 | object_pointer_name.assign(s.GetData()); |
| 6228 | } |
| 6229 | } |
| 6230 | |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6231 | 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] | 6232 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6233 | clang_type_t return_clang_type = NULL; |
| 6234 | Type *func_type = NULL; |
| 6235 | |
| 6236 | if (type_die_offset != DW_INVALID_OFFSET) |
| 6237 | func_type = ResolveTypeUID(type_die_offset); |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6238 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6239 | if (func_type) |
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 6240 | return_clang_type = func_type->GetClangForwardType(); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6241 | else |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6242 | return_clang_type = ast.GetBuiltInType_void(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6243 | |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6244 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6245 | std::vector<clang_type_t> function_param_types; |
| 6246 | std::vector<clang::ParmVarDecl*> function_param_decls; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6247 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6248 | // Parse the function children for the parameters |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 6249 | |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6250 | const DWARFDebugInfoEntry *decl_ctx_die = NULL; |
| 6251 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die); |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6252 | const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind(); |
| 6253 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6254 | const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind); |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6255 | // Start off static. This will be set to false in ParseChildParameters(...) |
| 6256 | // if we find a "this" paramters as the first parameter |
| 6257 | if (is_cxx_method) |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 6258 | is_static = true; |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 6259 | ClangASTContext::TemplateParameterInfos template_param_infos; |
| 6260 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6261 | if (die->HasChildren()) |
| 6262 | { |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6263 | bool skip_artificial = true; |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6264 | ParseChildParameters (sc, |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6265 | containing_decl_ctx, |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6266 | dwarf_cu, |
| 6267 | die, |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 6268 | skip_artificial, |
| 6269 | is_static, |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6270 | type_list, |
| 6271 | function_param_types, |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 6272 | function_param_decls, |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 6273 | type_quals, |
| 6274 | template_param_infos); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6275 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6276 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6277 | // clang_type will get the function prototype clang type after this call |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6278 | clang_type = ast.CreateFunctionType (return_clang_type, |
| Greg Clayton | 9cb25c4 | 2012-10-30 17:02:18 +0000 | [diff] [blame] | 6279 | function_param_types.data(), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6280 | function_param_types.size(), |
| 6281 | is_variadic, |
| 6282 | type_quals); |
| 6283 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6284 | if (type_name_cstr) |
| 6285 | { |
| 6286 | bool type_handled = false; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6287 | if (tag == DW_TAG_subprogram) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6288 | { |
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 6289 | ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true); |
| 6290 | if (objc_method.IsValid(true)) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6291 | { |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6292 | SymbolContext empty_sc; |
| 6293 | clang_type_t class_opaque_type = NULL; |
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 6294 | ConstString class_name(objc_method.GetClassName()); |
| Greg Clayton | 7c81042 | 2012-01-18 23:40:49 +0000 | [diff] [blame] | 6295 | if (class_name) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6296 | { |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6297 | TypeList types; |
| Greg Clayton | 278a16b | 2012-01-19 00:52:59 +0000 | [diff] [blame] | 6298 | TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false)); |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6299 | |
| 6300 | if (complete_objc_class_type_sp) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6301 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6302 | clang_type_t type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType(); |
| 6303 | if (ClangASTContext::IsObjCClassType (type_clang_forward_type)) |
| 6304 | class_opaque_type = type_clang_forward_type; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6305 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6306 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6307 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6308 | if (class_opaque_type) |
| 6309 | { |
| 6310 | // If accessibility isn't set to anything valid, assume public for |
| 6311 | // now... |
| 6312 | if (accessibility == eAccessNone) |
| 6313 | accessibility = eAccessPublic; |
| 6314 | |
| Sean Callanan | 464a5b5 | 2012-10-04 22:06:29 +0000 | [diff] [blame] | 6315 | clang::ObjCMethodDecl *objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type, |
| 6316 | type_name_cstr, |
| 6317 | clang_type, |
| Greg Clayton | 1bbcc03 | 2013-03-08 02:42:06 +0000 | [diff] [blame] | 6318 | accessibility, |
| 6319 | is_artificial); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6320 | type_handled = objc_method_decl != NULL; |
| Sean Callanan | 464a5b5 | 2012-10-04 22:06:29 +0000 | [diff] [blame] | 6321 | if (type_handled) |
| 6322 | { |
| 6323 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die); |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6324 | GetClangASTContext().SetMetadataAsUserID (objc_method_decl, MakeUserID(die->GetOffset())); |
| Sean Callanan | 464a5b5 | 2012-10-04 22:06:29 +0000 | [diff] [blame] | 6325 | } |
| Sean Callanan | c3a1d56 | 2013-02-06 23:21:59 +0000 | [diff] [blame] | 6326 | else |
| 6327 | { |
| Jason Molenda | c1a6583 | 2013-03-07 22:44:42 +0000 | [diff] [blame] | 6328 | 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] | 6329 | die->GetOffset(), |
| 6330 | tag, |
| 6331 | DW_TAG_value_to_name(tag)); |
| 6332 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6333 | } |
| 6334 | } |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6335 | else if (is_cxx_method) |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6336 | { |
| 6337 | // Look at the parent of this DIE and see if is is |
| 6338 | // a class or struct and see if this is actually a |
| 6339 | // C++ method |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6340 | Type *class_type = ResolveType (dwarf_cu, decl_ctx_die); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6341 | if (class_type) |
| 6342 | { |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6343 | if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset())) |
| 6344 | { |
| 6345 | // We uniqued the parent class of this function to another class |
| 6346 | // so we now need to associate all dies under "decl_ctx_die" to |
| 6347 | // DIEs in the DIE for "class_type"... |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 6348 | SymbolFileDWARF *class_symfile = NULL; |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6349 | DWARFCompileUnitSP class_type_cu_sp; |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 6350 | const DWARFDebugInfoEntry *class_type_die = NULL; |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6351 | |
| 6352 | SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile(); |
| 6353 | if (debug_map_symfile) |
| 6354 | { |
| 6355 | class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID())); |
| 6356 | class_type_die = class_symfile->DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp); |
| 6357 | } |
| 6358 | else |
| 6359 | { |
| 6360 | class_symfile = this; |
| 6361 | class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp); |
| 6362 | } |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6363 | if (class_type_die) |
| 6364 | { |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6365 | llvm::SmallVector<const DWARFDebugInfoEntry *, 0> failures; |
| 6366 | |
| 6367 | CopyUniqueClassMethodTypes (class_symfile, |
| 6368 | class_type, |
| 6369 | class_type_cu_sp.get(), |
| 6370 | class_type_die, |
| 6371 | dwarf_cu, |
| 6372 | decl_ctx_die, |
| 6373 | failures); |
| 6374 | |
| 6375 | // FIXME do something with these failures that's smarter than |
| 6376 | // just dropping them on the ground. Unfortunately classes don't |
| 6377 | // like having stuff added to them after their definitions are |
| 6378 | // complete... |
| 6379 | |
| 6380 | type_ptr = m_die_to_type[die]; |
| 6381 | if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6382 | { |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6383 | type_sp = type_ptr->shared_from_this(); |
| 6384 | break; |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6385 | } |
| 6386 | } |
| 6387 | } |
| 6388 | |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6389 | if (specification_die_offset != DW_INVALID_OFFSET) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6390 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6391 | // We have a specification which we are going to base our function |
| 6392 | // prototype off of, so we need this type to be completed so that the |
| 6393 | // m_die_to_decl_ctx for the method in the specification has a valid |
| 6394 | // clang decl context. |
| Greg Clayton | 8eb732e | 2011-12-13 04:34:06 +0000 | [diff] [blame] | 6395 | class_type->GetClangForwardType(); |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6396 | // If we have a specification, then the function type should have been |
| 6397 | // made with the specification and not with this die. |
| 6398 | DWARFCompileUnitSP spec_cu_sp; |
| 6399 | const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp); |
| Eric Christopher | 6cc6e60 | 2012-03-25 19:37:33 +0000 | [diff] [blame] | 6400 | clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die); |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6401 | if (spec_clang_decl_ctx) |
| 6402 | { |
| 6403 | LinkDeclContextToDIE(spec_clang_decl_ctx, die); |
| 6404 | } |
| 6405 | else |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6406 | { |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6407 | 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] | 6408 | MakeUserID(die->GetOffset()), |
| 6409 | specification_die_offset); |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6410 | } |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6411 | type_handled = true; |
| 6412 | } |
| 6413 | else if (abstract_origin_die_offset != DW_INVALID_OFFSET) |
| 6414 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6415 | // We have a specification which we are going to base our function |
| 6416 | // prototype off of, so we need this type to be completed so that the |
| 6417 | // m_die_to_decl_ctx for the method in the abstract origin has a valid |
| 6418 | // clang decl context. |
| Greg Clayton | 8eb732e | 2011-12-13 04:34:06 +0000 | [diff] [blame] | 6419 | class_type->GetClangForwardType(); |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6420 | |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6421 | DWARFCompileUnitSP abs_cu_sp; |
| 6422 | 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] | 6423 | clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die); |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6424 | if (abs_clang_decl_ctx) |
| 6425 | { |
| 6426 | LinkDeclContextToDIE (abs_clang_decl_ctx, die); |
| 6427 | } |
| 6428 | else |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6429 | { |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6430 | 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] | 6431 | MakeUserID(die->GetOffset()), |
| 6432 | abstract_origin_die_offset); |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6433 | } |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6434 | type_handled = true; |
| 6435 | } |
| 6436 | else |
| 6437 | { |
| 6438 | clang_type_t class_opaque_type = class_type->GetClangForwardType(); |
| 6439 | if (ClangASTContext::IsCXXClassType (class_opaque_type)) |
| Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 6440 | { |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6441 | if (ClangASTContext::IsBeingDefined (class_opaque_type)) |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6442 | { |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6443 | // Neither GCC 4.2 nor clang++ currently set a valid accessibility |
| 6444 | // in the DWARF for C++ methods... Default to public for now... |
| 6445 | if (accessibility == eAccessNone) |
| 6446 | accessibility = eAccessPublic; |
| 6447 | |
| 6448 | if (!is_static && !die->HasChildren()) |
| 6449 | { |
| 6450 | // We have a C++ member function with no children (this pointer!) |
| 6451 | // and clang will get mad if we try and make a function that isn't |
| 6452 | // well formed in the DWARF, so we will just skip it... |
| 6453 | type_handled = true; |
| 6454 | } |
| 6455 | else |
| 6456 | { |
| 6457 | clang::CXXMethodDecl *cxx_method_decl; |
| 6458 | // REMOVE THE CRASH DESCRIPTION BELOW |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6459 | 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] | 6460 | type_name_cstr, |
| 6461 | class_type->GetName().GetCString(), |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6462 | MakeUserID(die->GetOffset()), |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6463 | m_obj_file->GetFileSpec().GetDirectory().GetCString(), |
| 6464 | m_obj_file->GetFileSpec().GetFilename().GetCString()); |
| 6465 | |
| Sean Callanan | c1b732d | 2011-11-01 18:07:13 +0000 | [diff] [blame] | 6466 | const bool is_attr_used = false; |
| 6467 | |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6468 | cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type, |
| 6469 | type_name_cstr, |
| 6470 | clang_type, |
| 6471 | accessibility, |
| 6472 | is_virtual, |
| 6473 | is_static, |
| 6474 | is_inline, |
| Sean Callanan | c1b732d | 2011-11-01 18:07:13 +0000 | [diff] [blame] | 6475 | is_explicit, |
| Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 6476 | is_attr_used, |
| 6477 | is_artificial); |
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6478 | |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6479 | type_handled = cxx_method_decl != NULL; |
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6480 | |
| 6481 | if (type_handled) |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6482 | { |
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6483 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die); |
| 6484 | |
| 6485 | Host::SetCrashDescription (NULL); |
| 6486 | |
| 6487 | |
| 6488 | ClangASTMetadata metadata; |
| 6489 | metadata.SetUserID(MakeUserID(die->GetOffset())); |
| 6490 | |
| 6491 | if (!object_pointer_name.empty()) |
| 6492 | { |
| 6493 | metadata.SetObjectPtrName(object_pointer_name.c_str()); |
| 6494 | if (log) |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6495 | log->Printf ("Setting object pointer name: %s on method object %p.\n", |
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6496 | object_pointer_name.c_str(), |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6497 | cxx_method_decl); |
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6498 | } |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6499 | GetClangASTContext().SetMetadata (cxx_method_decl, metadata); |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6500 | } |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6501 | } |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6502 | } |
| 6503 | else |
| 6504 | { |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6505 | // We were asked to parse the type for a method in a class, yet the |
| 6506 | // class hasn't been asked to complete itself through the |
| 6507 | // clang::ExternalASTSource protocol, so we need to just have the |
| 6508 | // class complete itself and do things the right way, then our |
| 6509 | // DIE should then have an entry in the m_die_to_type map. First |
| 6510 | // we need to modify the m_die_to_type so it doesn't think we are |
| 6511 | // trying to parse this DIE anymore... |
| 6512 | m_die_to_type[die] = NULL; |
| 6513 | |
| 6514 | // Now we get the full type to force our class type to complete itself |
| 6515 | // using the clang::ExternalASTSource protocol which will parse all |
| 6516 | // base classes and all methods (including the method for this DIE). |
| 6517 | class_type->GetClangFullType(); |
| Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 6518 | |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6519 | // The type for this DIE should have been filled in the function call above |
| 6520 | type_ptr = m_die_to_type[die]; |
| Greg Clayton | e5476db | 2012-06-01 20:32:35 +0000 | [diff] [blame] | 6521 | if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6522 | { |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 6523 | type_sp = type_ptr->shared_from_this(); |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6524 | break; |
| 6525 | } |
| Sean Callanan | 02eee4d | 2012-04-12 23:10:00 +0000 | [diff] [blame] | 6526 | |
| 6527 | // FIXME This is fixing some even uglier behavior but we really need to |
| 6528 | // uniq the methods of each class as well as the class itself. |
| 6529 | // <rdar://problem/11240464> |
| 6530 | type_handled = true; |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6531 | } |
| Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 6532 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6533 | } |
| 6534 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6535 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6536 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6537 | |
| 6538 | if (!type_handled) |
| 6539 | { |
| 6540 | // We just have a function that isn't part of a class |
| Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 6541 | clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (containing_decl_ctx, |
| 6542 | type_name_cstr, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6543 | clang_type, |
| 6544 | storage, |
| 6545 | is_inline); |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 6546 | |
| 6547 | // if (template_param_infos.GetSize() > 0) |
| 6548 | // { |
| 6549 | // clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx, |
| 6550 | // function_decl, |
| 6551 | // type_name_cstr, |
| 6552 | // template_param_infos); |
| 6553 | // |
| 6554 | // ast.CreateFunctionTemplateSpecializationInfo (function_decl, |
| 6555 | // func_template_decl, |
| 6556 | // template_param_infos); |
| 6557 | // } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6558 | // Add the decl to our DIE to decl context map |
| 6559 | assert (function_decl); |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6560 | LinkDeclContextToDIE(function_decl, die); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6561 | if (!function_param_decls.empty()) |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6562 | ast.SetFunctionParameters (function_decl, |
| 6563 | &function_param_decls.front(), |
| 6564 | function_param_decls.size()); |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 6565 | |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6566 | ClangASTMetadata metadata; |
| 6567 | metadata.SetUserID(MakeUserID(die->GetOffset())); |
| 6568 | |
| 6569 | if (!object_pointer_name.empty()) |
| 6570 | { |
| 6571 | metadata.SetObjectPtrName(object_pointer_name.c_str()); |
| Jim Ingham | 2cffda3f | 2012-10-30 23:34:07 +0000 | [diff] [blame] | 6572 | if (log) |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6573 | log->Printf ("Setting object pointer name: %s on function object %p.", |
| Jim Ingham | 2cffda3f | 2012-10-30 23:34:07 +0000 | [diff] [blame] | 6574 | object_pointer_name.c_str(), |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6575 | function_decl); |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6576 | } |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6577 | GetClangASTContext().SetMetadata (function_decl, metadata); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6578 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6579 | } |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6580 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6581 | this, |
| 6582 | type_name_const_str, |
| 6583 | 0, |
| 6584 | NULL, |
| 6585 | LLDB_INVALID_UID, |
| 6586 | Type::eEncodingIsUID, |
| 6587 | &decl, |
| 6588 | clang_type, |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6589 | Type::eResolveStateFull)); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6590 | assert(type_sp.get()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6591 | } |
| 6592 | break; |
| 6593 | |
| 6594 | case DW_TAG_array_type: |
| 6595 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6596 | // 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] | 6597 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6598 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6599 | lldb::user_id_t type_die_offset = DW_INVALID_OFFSET; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6600 | int64_t first_index = 0; |
| 6601 | uint32_t byte_stride = 0; |
| 6602 | uint32_t bit_stride = 0; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6603 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6604 | |
| 6605 | if (num_attributes > 0) |
| 6606 | { |
| 6607 | uint32_t i; |
| 6608 | for (i=0; i<num_attributes; ++i) |
| 6609 | { |
| 6610 | attr = attributes.AttributeAtIndex(i); |
| 6611 | DWARFFormValue form_value; |
| 6612 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 6613 | { |
| 6614 | switch (attr) |
| 6615 | { |
| 6616 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 6617 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 6618 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 6619 | case DW_AT_name: |
| 6620 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6621 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6622 | break; |
| 6623 | |
| 6624 | 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] | 6625 | case DW_AT_byte_size: break; // byte_size = form_value.Unsigned(); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6626 | case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break; |
| 6627 | case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6628 | case DW_AT_accessibility: break; // accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
| 6629 | 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] | 6630 | case DW_AT_allocated: |
| 6631 | case DW_AT_associated: |
| 6632 | case DW_AT_data_location: |
| 6633 | case DW_AT_description: |
| 6634 | case DW_AT_ordering: |
| 6635 | case DW_AT_start_scope: |
| 6636 | case DW_AT_visibility: |
| 6637 | case DW_AT_specification: |
| 6638 | case DW_AT_abstract_origin: |
| 6639 | case DW_AT_sibling: |
| 6640 | break; |
| 6641 | } |
| 6642 | } |
| 6643 | } |
| 6644 | |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6645 | 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] | 6646 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6647 | Type *element_type = ResolveTypeUID(type_die_offset); |
| 6648 | |
| 6649 | if (element_type) |
| 6650 | { |
| 6651 | std::vector<uint64_t> element_orders; |
| 6652 | ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride); |
| 6653 | if (byte_stride == 0 && bit_stride == 0) |
| 6654 | byte_stride = element_type->GetByteSize(); |
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 6655 | clang_type_t array_element_type = element_type->GetClangForwardType(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6656 | uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride; |
| 6657 | uint64_t num_elements = 0; |
| 6658 | std::vector<uint64_t>::const_reverse_iterator pos; |
| 6659 | std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend(); |
| 6660 | for (pos = element_orders.rbegin(); pos != end; ++pos) |
| 6661 | { |
| 6662 | num_elements = *pos; |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6663 | clang_type = ast.CreateArrayType (array_element_type, |
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 6664 | num_elements); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6665 | array_element_type = clang_type; |
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 6666 | 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] | 6667 | } |
| 6668 | ConstString empty_name; |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6669 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6670 | this, |
| 6671 | empty_name, |
| 6672 | array_element_bit_stride / 8, |
| 6673 | NULL, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6674 | type_die_offset, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6675 | Type::eEncodingIsUID, |
| 6676 | &decl, |
| 6677 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6678 | Type::eResolveStateFull)); |
| 6679 | type_sp->SetEncodingType (element_type); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6680 | } |
| 6681 | } |
| 6682 | } |
| 6683 | break; |
| 6684 | |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6685 | case DW_TAG_ptr_to_member_type: |
| 6686 | { |
| 6687 | dw_offset_t type_die_offset = DW_INVALID_OFFSET; |
| 6688 | dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET; |
| 6689 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6690 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6691 | |
| 6692 | if (num_attributes > 0) { |
| 6693 | uint32_t i; |
| 6694 | for (i=0; i<num_attributes; ++i) |
| 6695 | { |
| 6696 | attr = attributes.AttributeAtIndex(i); |
| 6697 | DWARFFormValue form_value; |
| 6698 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 6699 | { |
| 6700 | switch (attr) |
| 6701 | { |
| 6702 | case DW_AT_type: |
| 6703 | type_die_offset = form_value.Reference(dwarf_cu); break; |
| 6704 | case DW_AT_containing_type: |
| 6705 | containing_type_die_offset = form_value.Reference(dwarf_cu); break; |
| 6706 | } |
| 6707 | } |
| 6708 | } |
| 6709 | |
| 6710 | Type *pointee_type = ResolveTypeUID(type_die_offset); |
| 6711 | Type *class_type = ResolveTypeUID(containing_type_die_offset); |
| 6712 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6713 | clang_type_t pointee_clang_type = pointee_type->GetClangForwardType(); |
| 6714 | clang_type_t class_clang_type = class_type->GetClangLayoutType(); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6715 | |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6716 | clang_type = ast.CreateMemberPointerType(pointee_clang_type, |
| 6717 | class_clang_type); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6718 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6719 | byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(), |
| 6720 | clang_type) / 8; |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6721 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6722 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6723 | this, |
| 6724 | type_name_const_str, |
| 6725 | byte_size, |
| 6726 | NULL, |
| 6727 | LLDB_INVALID_UID, |
| 6728 | Type::eEncodingIsUID, |
| 6729 | NULL, |
| 6730 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6731 | Type::eResolveStateForward)); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6732 | } |
| 6733 | |
| 6734 | break; |
| 6735 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6736 | default: |
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 6737 | 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", |
| 6738 | die->GetOffset(), |
| 6739 | tag, |
| 6740 | DW_TAG_value_to_name(tag)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6741 | break; |
| 6742 | } |
| 6743 | |
| 6744 | if (type_sp.get()) |
| 6745 | { |
| 6746 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); |
| 6747 | dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
| 6748 | |
| 6749 | SymbolContextScope * symbol_context_scope = NULL; |
| 6750 | if (sc_parent_tag == DW_TAG_compile_unit) |
| 6751 | { |
| 6752 | symbol_context_scope = sc.comp_unit; |
| 6753 | } |
| 6754 | else if (sc.function != NULL) |
| 6755 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6756 | 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] | 6757 | if (symbol_context_scope == NULL) |
| 6758 | symbol_context_scope = sc.function; |
| 6759 | } |
| 6760 | |
| 6761 | if (symbol_context_scope != NULL) |
| 6762 | { |
| 6763 | type_sp->SetSymbolContextScope(symbol_context_scope); |
| 6764 | } |
| 6765 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6766 | // We are ready to put this type into the uniqued list up at the module level |
| 6767 | type_list->Insert (type_sp); |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 6768 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6769 | m_die_to_type[die] = type_sp.get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6770 | } |
| 6771 | } |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 6772 | else if (type_ptr != DIE_IS_BEING_PARSED) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6773 | { |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 6774 | type_sp = type_ptr->shared_from_this(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6775 | } |
| 6776 | } |
| 6777 | return type_sp; |
| 6778 | } |
| 6779 | |
| 6780 | size_t |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6781 | SymbolFileDWARF::ParseTypes |
| 6782 | ( |
| 6783 | const SymbolContext& sc, |
| 6784 | DWARFCompileUnit* dwarf_cu, |
| 6785 | const DWARFDebugInfoEntry *die, |
| 6786 | bool parse_siblings, |
| 6787 | bool parse_children |
| 6788 | ) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6789 | { |
| 6790 | size_t types_added = 0; |
| 6791 | while (die != NULL) |
| 6792 | { |
| 6793 | bool type_is_new = false; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6794 | if (ParseType(sc, dwarf_cu, die, &type_is_new).get()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6795 | { |
| 6796 | if (type_is_new) |
| 6797 | ++types_added; |
| 6798 | } |
| 6799 | |
| 6800 | if (parse_children && die->HasChildren()) |
| 6801 | { |
| 6802 | if (die->Tag() == DW_TAG_subprogram) |
| 6803 | { |
| 6804 | SymbolContext child_sc(sc); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6805 | child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6806 | types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true); |
| 6807 | } |
| 6808 | else |
| 6809 | types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true); |
| 6810 | } |
| 6811 | |
| 6812 | if (parse_siblings) |
| 6813 | die = die->GetSibling(); |
| 6814 | else |
| 6815 | die = NULL; |
| 6816 | } |
| 6817 | return types_added; |
| 6818 | } |
| 6819 | |
| 6820 | |
| 6821 | size_t |
| 6822 | SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc) |
| 6823 | { |
| 6824 | assert(sc.comp_unit && sc.function); |
| 6825 | size_t functions_added = 0; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 6826 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6827 | if (dwarf_cu) |
| 6828 | { |
| 6829 | dw_offset_t function_die_offset = sc.function->GetID(); |
| 6830 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset); |
| 6831 | if (function_die) |
| 6832 | { |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 6833 | 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] | 6834 | } |
| 6835 | } |
| 6836 | |
| 6837 | return functions_added; |
| 6838 | } |
| 6839 | |
| 6840 | |
| 6841 | size_t |
| 6842 | SymbolFileDWARF::ParseTypes (const SymbolContext &sc) |
| 6843 | { |
| 6844 | // At least a compile unit must be valid |
| 6845 | assert(sc.comp_unit); |
| 6846 | size_t types_added = 0; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 6847 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6848 | if (dwarf_cu) |
| 6849 | { |
| 6850 | if (sc.function) |
| 6851 | { |
| 6852 | dw_offset_t function_die_offset = sc.function->GetID(); |
| 6853 | const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset); |
| 6854 | if (func_die && func_die->HasChildren()) |
| 6855 | { |
| 6856 | types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true); |
| 6857 | } |
| 6858 | } |
| 6859 | else |
| 6860 | { |
| 6861 | const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE(); |
| 6862 | if (dwarf_cu_die && dwarf_cu_die->HasChildren()) |
| 6863 | { |
| 6864 | types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true); |
| 6865 | } |
| 6866 | } |
| 6867 | } |
| 6868 | |
| 6869 | return types_added; |
| 6870 | } |
| 6871 | |
| 6872 | size_t |
| 6873 | SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc) |
| 6874 | { |
| 6875 | if (sc.comp_unit != NULL) |
| 6876 | { |
| Greg Clayton | 4b3dc10 | 2010-11-01 20:32:12 +0000 | [diff] [blame] | 6877 | DWARFDebugInfo* info = DebugInfo(); |
| 6878 | if (info == NULL) |
| 6879 | return 0; |
| 6880 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6881 | if (sc.function) |
| 6882 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 6883 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnitContainingDIE(sc.function->GetID()).get(); |
| 6884 | |
| 6885 | if (dwarf_cu == NULL) |
| 6886 | return 0; |
| 6887 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6888 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID()); |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 6889 | |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 6890 | dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS); |
| 6891 | if (func_lo_pc != LLDB_INVALID_ADDRESS) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6892 | { |
| 6893 | 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] | 6894 | |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6895 | // Let all blocks know they have parse all their variables |
| 6896 | sc.function->GetBlock (false).SetDidParseVariables (true, true); |
| 6897 | return num_variables; |
| 6898 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6899 | } |
| 6900 | else if (sc.comp_unit) |
| 6901 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 6902 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()).get(); |
| 6903 | |
| 6904 | if (dwarf_cu == NULL) |
| 6905 | return 0; |
| 6906 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6907 | uint32_t vars_added = 0; |
| 6908 | VariableListSP variables (sc.comp_unit->GetVariableList(false)); |
| 6909 | |
| 6910 | if (variables.get() == NULL) |
| 6911 | { |
| 6912 | variables.reset(new VariableList()); |
| 6913 | sc.comp_unit->SetVariableList(variables); |
| 6914 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 6915 | DWARFCompileUnit* match_dwarf_cu = NULL; |
| 6916 | const DWARFDebugInfoEntry* die = NULL; |
| 6917 | DIEArray die_offsets; |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 6918 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6919 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 6920 | if (m_apple_names_ap.get()) |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6921 | { |
| 6922 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 6923 | if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(), |
| 6924 | dwarf_cu->GetNextCompileUnitOffset(), |
| 6925 | hash_data_array)) |
| 6926 | { |
| 6927 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| 6928 | } |
| 6929 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6930 | } |
| 6931 | else |
| 6932 | { |
| 6933 | // Index if we already haven't to make sure the compile units |
| 6934 | // get indexed and make their global DIE index list |
| 6935 | if (!m_indexed) |
| 6936 | Index (); |
| 6937 | |
| 6938 | m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(), |
| 6939 | dwarf_cu->GetNextCompileUnitOffset(), |
| 6940 | die_offsets); |
| 6941 | } |
| 6942 | |
| 6943 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 6944 | if (num_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6945 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 6946 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 6947 | for (size_t i=0; i<num_matches; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6948 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 6949 | const dw_offset_t die_offset = die_offsets[i]; |
| 6950 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 6951 | if (die) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 6952 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 6953 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS)); |
| 6954 | if (var_sp) |
| 6955 | { |
| 6956 | variables->AddVariableIfUnique (var_sp); |
| 6957 | ++vars_added; |
| 6958 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 6959 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 6960 | else |
| 6961 | { |
| 6962 | if (m_using_apple_tables) |
| 6963 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6964 | 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] | 6965 | } |
| 6966 | } |
| 6967 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6968 | } |
| 6969 | } |
| 6970 | } |
| 6971 | return vars_added; |
| 6972 | } |
| 6973 | } |
| 6974 | return 0; |
| 6975 | } |
| 6976 | |
| 6977 | |
| 6978 | VariableSP |
| 6979 | SymbolFileDWARF::ParseVariableDIE |
| 6980 | ( |
| 6981 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6982 | DWARFCompileUnit* dwarf_cu, |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 6983 | const DWARFDebugInfoEntry *die, |
| 6984 | const lldb::addr_t func_low_pc |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6985 | ) |
| 6986 | { |
| 6987 | |
| Greg Clayton | 83c5cd9 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 6988 | VariableSP var_sp (m_die_to_variable_sp[die]); |
| 6989 | if (var_sp) |
| 6990 | return var_sp; // Already been parsed! |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6991 | |
| 6992 | const dw_tag_t tag = die->Tag(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6993 | |
| 6994 | if ((tag == DW_TAG_variable) || |
| 6995 | (tag == DW_TAG_constant) || |
| 6996 | (tag == DW_TAG_formal_parameter && sc.function)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6997 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6998 | DWARFDebugInfoEntry::Attributes attributes; |
| 6999 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| 7000 | if (num_attributes > 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7001 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7002 | const char *name = NULL; |
| 7003 | const char *mangled = NULL; |
| 7004 | Declaration decl; |
| 7005 | uint32_t i; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7006 | lldb::user_id_t type_uid = LLDB_INVALID_UID; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7007 | DWARFExpression location; |
| 7008 | bool is_external = false; |
| 7009 | bool is_artificial = false; |
| 7010 | bool location_is_const_value_data = false; |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7011 | bool has_explicit_location = false; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 7012 | //AccessType accessibility = eAccessNone; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7013 | |
| 7014 | for (i=0; i<num_attributes; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7015 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7016 | dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 7017 | DWARFFormValue form_value; |
| 7018 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7019 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7020 | switch (attr) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7021 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7022 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 7023 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 7024 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 7025 | 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] | 7026 | case DW_AT_linkage_name: |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7027 | 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] | 7028 | case DW_AT_type: type_uid = form_value.Reference(dwarf_cu); break; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7029 | case DW_AT_external: is_external = form_value.Unsigned() != 0; break; |
| 7030 | case DW_AT_const_value: |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7031 | // If we have already found a DW_AT_location attribute, ignore this attribute. |
| 7032 | if (!has_explicit_location) |
| 7033 | { |
| 7034 | location_is_const_value_data = true; |
| 7035 | // The constant value will be either a block, a data value or a string. |
| 7036 | const DataExtractor& debug_info_data = get_debug_info_data(); |
| 7037 | if (DWARFFormValue::IsBlockForm(form_value.Form())) |
| 7038 | { |
| 7039 | // Retrieve the value as a block expression. |
| 7040 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 7041 | uint32_t block_length = form_value.Unsigned(); |
| 7042 | location.CopyOpcodeData(debug_info_data, block_offset, block_length); |
| 7043 | } |
| 7044 | else if (DWARFFormValue::IsDataForm(form_value.Form())) |
| 7045 | { |
| 7046 | // Retrieve the value as a data expression. |
| 7047 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| 7048 | uint32_t data_offset = attributes.DIEOffsetAtIndex(i); |
| 7049 | uint32_t data_length = fixed_form_sizes[form_value.Form()]; |
| 7050 | location.CopyOpcodeData(debug_info_data, data_offset, data_length); |
| 7051 | } |
| 7052 | else |
| 7053 | { |
| 7054 | // Retrieve the value as a string expression. |
| 7055 | if (form_value.Form() == DW_FORM_strp) |
| 7056 | { |
| 7057 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| 7058 | uint32_t data_offset = attributes.DIEOffsetAtIndex(i); |
| 7059 | uint32_t data_length = fixed_form_sizes[form_value.Form()]; |
| 7060 | location.CopyOpcodeData(debug_info_data, data_offset, data_length); |
| 7061 | } |
| 7062 | else |
| 7063 | { |
| 7064 | const char *str = form_value.AsCString(&debug_info_data); |
| 7065 | uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart(); |
| 7066 | uint32_t string_length = strlen(str) + 1; |
| 7067 | location.CopyOpcodeData(debug_info_data, string_offset, string_length); |
| 7068 | } |
| 7069 | } |
| 7070 | } |
| 7071 | break; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7072 | case DW_AT_location: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7073 | { |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7074 | location_is_const_value_data = false; |
| 7075 | has_explicit_location = true; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7076 | if (form_value.BlockData()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7077 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7078 | const DataExtractor& debug_info_data = get_debug_info_data(); |
| 7079 | |
| 7080 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 7081 | uint32_t block_length = form_value.Unsigned(); |
| Greg Clayton | 7f4c743 | 2012-08-11 00:49:14 +0000 | [diff] [blame] | 7082 | location.CopyOpcodeData(get_debug_info_data(), block_offset, block_length); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7083 | } |
| 7084 | else |
| 7085 | { |
| 7086 | const DataExtractor& debug_loc_data = get_debug_loc_data(); |
| 7087 | const dw_offset_t debug_loc_offset = form_value.Unsigned(); |
| 7088 | |
| 7089 | size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset); |
| 7090 | if (loc_list_length > 0) |
| 7091 | { |
| Greg Clayton | 7f4c743 | 2012-08-11 00:49:14 +0000 | [diff] [blame] | 7092 | location.CopyOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7093 | assert (func_low_pc != LLDB_INVALID_ADDRESS); |
| 7094 | location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress()); |
| 7095 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7096 | } |
| 7097 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7098 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7099 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7100 | case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 7101 | 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] | 7102 | case DW_AT_declaration: |
| 7103 | case DW_AT_description: |
| 7104 | case DW_AT_endianity: |
| 7105 | case DW_AT_segment: |
| 7106 | case DW_AT_start_scope: |
| 7107 | case DW_AT_visibility: |
| 7108 | default: |
| 7109 | case DW_AT_abstract_origin: |
| 7110 | case DW_AT_sibling: |
| 7111 | case DW_AT_specification: |
| 7112 | break; |
| 7113 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7114 | } |
| 7115 | } |
| 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 | if (location.IsValid()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7118 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7119 | ValueType scope = eValueTypeInvalid; |
| 7120 | |
| 7121 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); |
| 7122 | 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] | 7123 | SymbolContextScope * symbol_context_scope = NULL; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7124 | |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7125 | // DWARF doesn't specify if a DW_TAG_variable is a local, global |
| 7126 | // or static variable, so we have to do a little digging by |
| 7127 | // looking at the location of a varaible to see if it contains |
| 7128 | // a DW_OP_addr opcode _somewhere_ in the definition. I say |
| 7129 | // somewhere because clang likes to combine small global variables |
| 7130 | // into the same symbol and have locations like: |
| 7131 | // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus |
| 7132 | // So if we don't have a DW_TAG_formal_parameter, we can look at |
| 7133 | // the location to see if it contains a DW_OP_addr opcode, and |
| 7134 | // then we can correctly classify our variables. |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7135 | if (tag == DW_TAG_formal_parameter) |
| 7136 | scope = eValueTypeVariableArgument; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7137 | else |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7138 | { |
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 7139 | bool op_error = false; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7140 | // 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] | 7141 | lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7142 | if (!location_is_const_value_data) |
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 7143 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7144 | location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error); |
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 7145 | if (op_error) |
| 7146 | { |
| 7147 | StreamString strm; |
| 7148 | location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL); |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 7149 | 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] | 7150 | } |
| 7151 | } |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7152 | |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7153 | if (location_DW_OP_addr != LLDB_INVALID_ADDRESS) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7154 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7155 | if (is_external) |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7156 | scope = eValueTypeVariableGlobal; |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7157 | else |
| 7158 | scope = eValueTypeVariableStatic; |
| 7159 | |
| 7160 | |
| 7161 | SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile (); |
| 7162 | |
| 7163 | if (debug_map_symfile) |
| 7164 | { |
| 7165 | // When leaving the DWARF in the .o files on darwin, |
| 7166 | // when we have a global variable that wasn't initialized, |
| 7167 | // the .o file might not have allocated a virtual |
| 7168 | // address for the global variable. In this case it will |
| 7169 | // have created a symbol for the global variable |
| 7170 | // that is undefined/data and external and the value will |
| 7171 | // be the byte size of the variable. When we do the |
| 7172 | // address map in SymbolFileDWARFDebugMap we rely on |
| 7173 | // having an address, we need to do some magic here |
| 7174 | // so we can get the correct address for our global |
| 7175 | // variable. The address for all of these entries |
| 7176 | // will be zero, and there will be an undefined symbol |
| 7177 | // in this object file, and the executable will have |
| 7178 | // a matching symbol with a good address. So here we |
| 7179 | // dig up the correct address and replace it in the |
| 7180 | // location for the variable, and set the variable's |
| 7181 | // symbol context scope to be that of the main executable |
| 7182 | // so the file address will resolve correctly. |
| 7183 | bool linked_oso_file_addr = false; |
| 7184 | if (is_external && location_DW_OP_addr == 0) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7185 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7186 | |
| 7187 | // we have a possible uninitialized extern global |
| 7188 | ConstString const_name(mangled ? mangled : name); |
| 7189 | ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile(); |
| 7190 | if (debug_map_objfile) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7191 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7192 | Symtab *debug_map_symtab = debug_map_objfile->GetSymtab(); |
| 7193 | if (debug_map_symtab) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7194 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7195 | Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name, |
| 7196 | eSymbolTypeData, |
| 7197 | Symtab::eDebugYes, |
| 7198 | Symtab::eVisibilityExtern); |
| 7199 | if (exe_symbol) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7200 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7201 | if (exe_symbol->ValueIsAddress()) |
| 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 | const addr_t exe_file_addr = exe_symbol->GetAddress().GetFileAddress(); |
| 7204 | if (exe_file_addr != LLDB_INVALID_ADDRESS) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7205 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7206 | if (location.Update_DW_OP_addr (exe_file_addr)) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7207 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7208 | linked_oso_file_addr = true; |
| 7209 | symbol_context_scope = exe_symbol; |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7210 | } |
| 7211 | } |
| 7212 | } |
| 7213 | } |
| 7214 | } |
| 7215 | } |
| 7216 | } |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7217 | |
| 7218 | if (!linked_oso_file_addr) |
| 7219 | { |
| 7220 | // The DW_OP_addr is not zero, but it contains a .o file address which |
| 7221 | // needs to be linked up correctly. |
| 7222 | const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr); |
| 7223 | if (exe_file_addr != LLDB_INVALID_ADDRESS) |
| 7224 | { |
| 7225 | // Update the file address for this variable |
| 7226 | location.Update_DW_OP_addr (exe_file_addr); |
| 7227 | } |
| 7228 | else |
| 7229 | { |
| 7230 | // Variable didn't make it into the final executable |
| 7231 | return var_sp; |
| 7232 | } |
| 7233 | } |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7234 | } |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7235 | } |
| 7236 | else |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7237 | { |
| 7238 | scope = eValueTypeVariableLocal; |
| 7239 | } |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7240 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7241 | |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7242 | if (symbol_context_scope == NULL) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7243 | { |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7244 | switch (parent_tag) |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 7245 | { |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7246 | case DW_TAG_subprogram: |
| 7247 | case DW_TAG_inlined_subroutine: |
| 7248 | case DW_TAG_lexical_block: |
| 7249 | if (sc.function) |
| 7250 | { |
| 7251 | symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); |
| 7252 | if (symbol_context_scope == NULL) |
| 7253 | symbol_context_scope = sc.function; |
| 7254 | } |
| 7255 | break; |
| 7256 | |
| 7257 | default: |
| 7258 | symbol_context_scope = sc.comp_unit; |
| 7259 | break; |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 7260 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7261 | } |
| 7262 | |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 7263 | if (symbol_context_scope) |
| 7264 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7265 | var_sp.reset (new Variable (MakeUserID(die->GetOffset()), |
| 7266 | name, |
| 7267 | mangled, |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7268 | SymbolFileTypeSP (new SymbolFileType(*this, type_uid)), |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7269 | scope, |
| 7270 | symbol_context_scope, |
| 7271 | &decl, |
| 7272 | location, |
| 7273 | is_external, |
| 7274 | is_artificial)); |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 7275 | |
| 7276 | var_sp->SetLocationIsConstantValueData (location_is_const_value_data); |
| 7277 | } |
| 7278 | else |
| 7279 | { |
| 7280 | // Not ready to parse this variable yet. It might be a global |
| 7281 | // or static variable that is in a function scope and the function |
| 7282 | // in the symbol context wasn't filled in yet |
| 7283 | return var_sp; |
| 7284 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7285 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7286 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7287 | // Cache var_sp even if NULL (the variable was just a specification or |
| 7288 | // was missing vital information to be able to be displayed in the debugger |
| 7289 | // (missing location due to optimization, etc)) so we don't re-parse |
| 7290 | // this DIE over and over later... |
| 7291 | m_die_to_variable_sp[die] = var_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7292 | } |
| 7293 | return var_sp; |
| 7294 | } |
| 7295 | |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7296 | |
| 7297 | const DWARFDebugInfoEntry * |
| 7298 | SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset, |
| 7299 | dw_offset_t spec_block_die_offset, |
| 7300 | DWARFCompileUnit **result_die_cu_handle) |
| 7301 | { |
| 7302 | // Give the concrete function die specified by "func_die_offset", find the |
| 7303 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points |
| 7304 | // to "spec_block_die_offset" |
| 7305 | DWARFDebugInfo* info = DebugInfo(); |
| 7306 | |
| 7307 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle); |
| 7308 | if (die) |
| 7309 | { |
| 7310 | assert (*result_die_cu_handle); |
| 7311 | return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle); |
| 7312 | } |
| 7313 | return NULL; |
| 7314 | } |
| 7315 | |
| 7316 | |
| 7317 | const DWARFDebugInfoEntry * |
| 7318 | SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu, |
| 7319 | const DWARFDebugInfoEntry *die, |
| 7320 | dw_offset_t spec_block_die_offset, |
| 7321 | DWARFCompileUnit **result_die_cu_handle) |
| 7322 | { |
| 7323 | if (die) |
| 7324 | { |
| 7325 | switch (die->Tag()) |
| 7326 | { |
| 7327 | case DW_TAG_subprogram: |
| 7328 | case DW_TAG_inlined_subroutine: |
| 7329 | case DW_TAG_lexical_block: |
| 7330 | { |
| 7331 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset) |
| 7332 | { |
| 7333 | *result_die_cu_handle = dwarf_cu; |
| 7334 | return die; |
| 7335 | } |
| 7336 | |
| 7337 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset) |
| 7338 | { |
| 7339 | *result_die_cu_handle = dwarf_cu; |
| 7340 | return die; |
| 7341 | } |
| 7342 | } |
| 7343 | break; |
| 7344 | } |
| 7345 | |
| 7346 | // Give the concrete function die specified by "func_die_offset", find the |
| 7347 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points |
| 7348 | // to "spec_block_die_offset" |
| 7349 | for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling()) |
| 7350 | { |
| 7351 | const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu, |
| 7352 | child_die, |
| 7353 | spec_block_die_offset, |
| 7354 | result_die_cu_handle); |
| 7355 | if (result_die) |
| 7356 | return result_die; |
| 7357 | } |
| 7358 | } |
| 7359 | |
| 7360 | *result_die_cu_handle = NULL; |
| 7361 | return NULL; |
| 7362 | } |
| 7363 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7364 | size_t |
| 7365 | SymbolFileDWARF::ParseVariables |
| 7366 | ( |
| 7367 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 7368 | DWARFCompileUnit* dwarf_cu, |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 7369 | const lldb::addr_t func_low_pc, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7370 | const DWARFDebugInfoEntry *orig_die, |
| 7371 | bool parse_siblings, |
| 7372 | bool parse_children, |
| 7373 | VariableList* cc_variable_list |
| 7374 | ) |
| 7375 | { |
| 7376 | if (orig_die == NULL) |
| 7377 | return 0; |
| 7378 | |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7379 | VariableListSP variable_list_sp; |
| 7380 | |
| 7381 | size_t vars_added = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7382 | const DWARFDebugInfoEntry *die = orig_die; |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7383 | while (die != NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7384 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7385 | dw_tag_t tag = die->Tag(); |
| 7386 | |
| 7387 | // Check to see if we have already parsed this variable or constant? |
| 7388 | if (m_die_to_variable_sp[die]) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7389 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7390 | if (cc_variable_list) |
| 7391 | cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7392 | } |
| 7393 | else |
| 7394 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7395 | // We haven't already parsed it, lets do that now. |
| 7396 | if ((tag == DW_TAG_variable) || |
| 7397 | (tag == DW_TAG_constant) || |
| 7398 | (tag == DW_TAG_formal_parameter && sc.function)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7399 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7400 | if (variable_list_sp.get() == NULL) |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7401 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7402 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die); |
| 7403 | dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
| 7404 | switch (parent_tag) |
| 7405 | { |
| 7406 | case DW_TAG_compile_unit: |
| 7407 | if (sc.comp_unit != NULL) |
| 7408 | { |
| 7409 | variable_list_sp = sc.comp_unit->GetVariableList(false); |
| 7410 | if (variable_list_sp.get() == NULL) |
| 7411 | { |
| 7412 | variable_list_sp.reset(new VariableList()); |
| 7413 | sc.comp_unit->SetVariableList(variable_list_sp); |
| 7414 | } |
| 7415 | } |
| 7416 | else |
| 7417 | { |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 7418 | 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] | 7419 | MakeUserID(sc_parent_die->GetOffset()), |
| 7420 | DW_TAG_value_to_name (parent_tag), |
| 7421 | MakeUserID(orig_die->GetOffset()), |
| 7422 | DW_TAG_value_to_name (orig_die->Tag())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7423 | } |
| 7424 | break; |
| 7425 | |
| 7426 | case DW_TAG_subprogram: |
| 7427 | case DW_TAG_inlined_subroutine: |
| 7428 | case DW_TAG_lexical_block: |
| 7429 | if (sc.function != NULL) |
| 7430 | { |
| 7431 | // Check to see if we already have parsed the variables for the given scope |
| 7432 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7433 | Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7434 | if (block == NULL) |
| 7435 | { |
| 7436 | // This must be a specification or abstract origin with |
| 7437 | // a concrete block couterpart in the current function. We need |
| 7438 | // to find the concrete block so we can correctly add the |
| 7439 | // variable to it |
| 7440 | DWARFCompileUnit *concrete_block_die_cu = dwarf_cu; |
| 7441 | const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(), |
| 7442 | sc_parent_die->GetOffset(), |
| 7443 | &concrete_block_die_cu); |
| 7444 | if (concrete_block_die) |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7445 | block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7446 | } |
| 7447 | |
| 7448 | if (block != NULL) |
| 7449 | { |
| 7450 | const bool can_create = false; |
| 7451 | variable_list_sp = block->GetBlockVariableList (can_create); |
| 7452 | if (variable_list_sp.get() == NULL) |
| 7453 | { |
| 7454 | variable_list_sp.reset(new VariableList()); |
| 7455 | block->SetVariableList(variable_list_sp); |
| 7456 | } |
| 7457 | } |
| 7458 | } |
| 7459 | break; |
| 7460 | |
| 7461 | default: |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 7462 | 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] | 7463 | MakeUserID(orig_die->GetOffset()), |
| 7464 | DW_TAG_value_to_name (orig_die->Tag())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7465 | break; |
| 7466 | } |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7467 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7468 | |
| 7469 | if (variable_list_sp) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7470 | { |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7471 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc)); |
| 7472 | if (var_sp) |
| 7473 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7474 | variable_list_sp->AddVariableIfUnique (var_sp); |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7475 | if (cc_variable_list) |
| 7476 | cc_variable_list->AddVariableIfUnique (var_sp); |
| 7477 | ++vars_added; |
| 7478 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7479 | } |
| 7480 | } |
| 7481 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7482 | |
| 7483 | bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram); |
| 7484 | |
| 7485 | if (!skip_children && parse_children && die->HasChildren()) |
| 7486 | { |
| 7487 | vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list); |
| 7488 | } |
| 7489 | |
| 7490 | if (parse_siblings) |
| 7491 | die = die->GetSibling(); |
| 7492 | else |
| 7493 | die = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7494 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7495 | return vars_added; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7496 | } |
| 7497 | |
| 7498 | //------------------------------------------------------------------ |
| 7499 | // PluginInterface protocol |
| 7500 | //------------------------------------------------------------------ |
| 7501 | const char * |
| 7502 | SymbolFileDWARF::GetPluginName() |
| 7503 | { |
| 7504 | return "SymbolFileDWARF"; |
| 7505 | } |
| 7506 | |
| 7507 | const char * |
| 7508 | SymbolFileDWARF::GetShortPluginName() |
| 7509 | { |
| 7510 | return GetPluginNameStatic(); |
| 7511 | } |
| 7512 | |
| 7513 | uint32_t |
| 7514 | SymbolFileDWARF::GetPluginVersion() |
| 7515 | { |
| 7516 | return 1; |
| 7517 | } |
| 7518 | |
| 7519 | void |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 7520 | SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl) |
| 7521 | { |
| 7522 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 7523 | clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); |
| 7524 | if (clang_type) |
| 7525 | symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); |
| 7526 | } |
| 7527 | |
| 7528 | void |
| 7529 | SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl) |
| 7530 | { |
| 7531 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 7532 | clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); |
| 7533 | if (clang_type) |
| 7534 | symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); |
| 7535 | } |
| 7536 | |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7537 | void |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7538 | SymbolFileDWARF::DumpIndexes () |
| 7539 | { |
| 7540 | StreamFile s(stdout, false); |
| 7541 | |
| 7542 | s.Printf ("DWARF index for (%s) '%s/%s':", |
| 7543 | GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(), |
| 7544 | GetObjectFile()->GetFileSpec().GetDirectory().AsCString(), |
| 7545 | GetObjectFile()->GetFileSpec().GetFilename().AsCString()); |
| 7546 | s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s); |
| 7547 | s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s); |
| 7548 | s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s); |
| 7549 | s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s); |
| 7550 | s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s); |
| 7551 | s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s); |
| 7552 | s.Printf("\nTypes:\n"); m_type_index.Dump (&s); |
| 7553 | s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s); |
| 7554 | } |
| 7555 | |
| 7556 | void |
| 7557 | SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context, |
| 7558 | const char *name, |
| 7559 | llvm::SmallVectorImpl <clang::NamedDecl *> *results) |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7560 | { |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7561 | DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context); |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7562 | |
| 7563 | if (iter == m_decl_ctx_to_die.end()) |
| 7564 | return; |
| 7565 | |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7566 | 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] | 7567 | { |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7568 | const DWARFDebugInfoEntry *context_die = *pos; |
| 7569 | |
| 7570 | if (!results) |
| 7571 | return; |
| 7572 | |
| 7573 | DWARFDebugInfo* info = DebugInfo(); |
| 7574 | |
| 7575 | DIEArray die_offsets; |
| 7576 | |
| 7577 | DWARFCompileUnit* dwarf_cu = NULL; |
| 7578 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 7579 | |
| 7580 | if (m_using_apple_tables) |
| 7581 | { |
| 7582 | if (m_apple_types_ap.get()) |
| 7583 | m_apple_types_ap->FindByName (name, die_offsets); |
| 7584 | } |
| 7585 | else |
| 7586 | { |
| 7587 | if (!m_indexed) |
| 7588 | Index (); |
| 7589 | |
| 7590 | m_type_index.Find (ConstString(name), die_offsets); |
| 7591 | } |
| 7592 | |
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 7593 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7594 | |
| 7595 | if (num_matches) |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7596 | { |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7597 | for (size_t i = 0; i < num_matches; ++i) |
| 7598 | { |
| 7599 | const dw_offset_t die_offset = die_offsets[i]; |
| 7600 | die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7601 | |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7602 | if (die->GetParent() != context_die) |
| 7603 | continue; |
| 7604 | |
| 7605 | Type *matching_type = ResolveType (dwarf_cu, die); |
| 7606 | |
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 7607 | lldb::clang_type_t type = matching_type->GetClangForwardType(); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7608 | clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type); |
| 7609 | |
| 7610 | if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr())) |
| 7611 | { |
| 7612 | clang::TagDecl *tag_decl = tag_type->getDecl(); |
| 7613 | results->push_back(tag_decl); |
| 7614 | } |
| 7615 | else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr())) |
| 7616 | { |
| 7617 | clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl(); |
| 7618 | results->push_back(typedef_decl); |
| 7619 | } |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7620 | } |
| 7621 | } |
| 7622 | } |
| 7623 | } |
| 7624 | |
| 7625 | void |
| 7626 | SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton, |
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 7627 | const clang::DeclContext *decl_context, |
| 7628 | clang::DeclarationName decl_name, |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7629 | llvm::SmallVectorImpl <clang::NamedDecl *> *results) |
| 7630 | { |
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 7631 | |
| 7632 | switch (decl_context->getDeclKind()) |
| 7633 | { |
| 7634 | case clang::Decl::Namespace: |
| 7635 | case clang::Decl::TranslationUnit: |
| 7636 | { |
| 7637 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 7638 | symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results); |
| 7639 | } |
| 7640 | break; |
| 7641 | default: |
| 7642 | break; |
| 7643 | } |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7644 | } |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7645 | |
| 7646 | bool |
| 7647 | SymbolFileDWARF::LayoutRecordType (void *baton, |
| 7648 | const clang::RecordDecl *record_decl, |
| 7649 | uint64_t &size, |
| 7650 | uint64_t &alignment, |
| 7651 | llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, |
| 7652 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, |
| 7653 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) |
| 7654 | { |
| 7655 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 7656 | return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets); |
| 7657 | } |
| 7658 | |
| 7659 | |
| 7660 | bool |
| 7661 | SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl, |
| 7662 | uint64_t &bit_size, |
| 7663 | uint64_t &alignment, |
| 7664 | llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, |
| 7665 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, |
| 7666 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) |
| 7667 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 7668 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7669 | RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl); |
| 7670 | bool success = false; |
| 7671 | base_offsets.clear(); |
| 7672 | vbase_offsets.clear(); |
| 7673 | if (pos != m_record_decl_to_layout_map.end()) |
| 7674 | { |
| 7675 | bit_size = pos->second.bit_size; |
| 7676 | alignment = pos->second.alignment; |
| 7677 | field_offsets.swap(pos->second.field_offsets); |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 7678 | base_offsets.swap (pos->second.base_offsets); |
| 7679 | vbase_offsets.swap (pos->second.vbase_offsets); |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7680 | m_record_decl_to_layout_map.erase(pos); |
| 7681 | success = true; |
| 7682 | } |
| 7683 | else |
| 7684 | { |
| 7685 | bit_size = 0; |
| 7686 | alignment = 0; |
| 7687 | field_offsets.clear(); |
| 7688 | } |
| 7689 | |
| 7690 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 7691 | GetObjectFile()->GetModule()->LogMessage (log, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 7692 | "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] | 7693 | record_decl, |
| 7694 | bit_size, |
| 7695 | alignment, |
| 7696 | (uint32_t)field_offsets.size(), |
| 7697 | (uint32_t)base_offsets.size(), |
| 7698 | (uint32_t)vbase_offsets.size(), |
| 7699 | success); |
| 7700 | return success; |
| 7701 | } |
| 7702 | |
| 7703 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 7704 | SymbolFileDWARFDebugMap * |
| 7705 | SymbolFileDWARF::GetDebugMapSymfile () |
| 7706 | { |
| 7707 | if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired()) |
| 7708 | { |
| 7709 | lldb::ModuleSP module_sp (m_debug_map_module_wp.lock()); |
| 7710 | if (module_sp) |
| 7711 | { |
| 7712 | SymbolVendor *sym_vendor = module_sp->GetSymbolVendor(); |
| 7713 | if (sym_vendor) |
| 7714 | m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile(); |
| 7715 | } |
| 7716 | } |
| 7717 | return m_debug_map_symfile; |
| 7718 | } |
| 7719 | |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7720 | |