| 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 | |
| Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 210 | lldb_private::ConstString |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 211 | SymbolFileDWARF::GetPluginNameStatic() |
| 212 | { |
| Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 213 | static ConstString g_name("dwarf"); |
| 214 | return g_name; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | const char * |
| 218 | SymbolFileDWARF::GetPluginDescriptionStatic() |
| 219 | { |
| 220 | return "DWARF and DWARF3 debug symbol file reader."; |
| 221 | } |
| 222 | |
| 223 | |
| 224 | SymbolFile* |
| 225 | SymbolFileDWARF::CreateInstance (ObjectFile* obj_file) |
| 226 | { |
| 227 | return new SymbolFileDWARF(obj_file); |
| 228 | } |
| 229 | |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 230 | TypeList * |
| 231 | SymbolFileDWARF::GetTypeList () |
| 232 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 233 | if (GetDebugMapSymfile ()) |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 234 | return m_debug_map_symfile->GetTypeList(); |
| 235 | return m_obj_file->GetModule()->GetTypeList(); |
| 236 | |
| 237 | } |
| 238 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 239 | //---------------------------------------------------------------------- |
| 240 | // Gets the first parent that is a lexical block, function or inlined |
| 241 | // subroutine, or compile unit. |
| 242 | //---------------------------------------------------------------------- |
| 243 | static const DWARFDebugInfoEntry * |
| 244 | GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die) |
| 245 | { |
| 246 | const DWARFDebugInfoEntry *die; |
| 247 | for (die = child_die->GetParent(); die != NULL; die = die->GetParent()) |
| 248 | { |
| 249 | dw_tag_t tag = die->Tag(); |
| 250 | |
| 251 | switch (tag) |
| 252 | { |
| 253 | case DW_TAG_compile_unit: |
| 254 | case DW_TAG_subprogram: |
| 255 | case DW_TAG_inlined_subroutine: |
| 256 | case DW_TAG_lexical_block: |
| 257 | return die; |
| 258 | } |
| 259 | } |
| 260 | return NULL; |
| 261 | } |
| 262 | |
| 263 | |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 264 | SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) : |
| 265 | SymbolFile (objfile), |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 266 | 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] | 267 | m_debug_map_module_wp (), |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 268 | m_debug_map_symfile (NULL), |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 269 | m_clang_tu_decl (NULL), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 270 | m_flags(), |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 271 | m_data_debug_abbrev (), |
| 272 | m_data_debug_aranges (), |
| 273 | m_data_debug_frame (), |
| 274 | m_data_debug_info (), |
| 275 | m_data_debug_line (), |
| 276 | m_data_debug_loc (), |
| 277 | m_data_debug_ranges (), |
| 278 | m_data_debug_str (), |
| Greg Clayton | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 279 | m_data_apple_names (), |
| 280 | m_data_apple_types (), |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 281 | m_data_apple_namespaces (), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 282 | m_abbr(), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 283 | m_info(), |
| 284 | m_line(), |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 285 | m_apple_names_ap (), |
| 286 | m_apple_types_ap (), |
| 287 | m_apple_namespaces_ap (), |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 288 | m_apple_objc_ap (), |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 289 | m_function_basename_index(), |
| 290 | m_function_fullname_index(), |
| 291 | m_function_method_index(), |
| 292 | m_function_selector_index(), |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 293 | m_objc_class_selectors_index(), |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 294 | m_global_index(), |
| Greg Clayton | 69b0488 | 2010-10-15 02:03:22 +0000 | [diff] [blame] | 295 | m_type_index(), |
| 296 | m_namespace_index(), |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 297 | m_indexed (false), |
| 298 | m_is_external_ast_source (false), |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 299 | m_using_apple_tables (false), |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 300 | m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate), |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 301 | m_ranges(), |
| 302 | m_unique_ast_type_map () |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 303 | { |
| 304 | } |
| 305 | |
| 306 | SymbolFileDWARF::~SymbolFileDWARF() |
| 307 | { |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 308 | if (m_is_external_ast_source) |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 309 | { |
| 310 | ModuleSP module_sp (m_obj_file->GetModule()); |
| 311 | if (module_sp) |
| 312 | module_sp->GetClangASTContext().RemoveExternalSource (); |
| 313 | } |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | static const ConstString & |
| 317 | GetDWARFMachOSegmentName () |
| 318 | { |
| 319 | static ConstString g_dwarf_section_name ("__DWARF"); |
| 320 | return g_dwarf_section_name; |
| 321 | } |
| 322 | |
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 323 | UniqueDWARFASTTypeMap & |
| 324 | SymbolFileDWARF::GetUniqueDWARFASTTypeMap () |
| 325 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 326 | if (GetDebugMapSymfile ()) |
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 327 | return m_debug_map_symfile->GetUniqueDWARFASTTypeMap (); |
| 328 | return m_unique_ast_type_map; |
| 329 | } |
| 330 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 331 | ClangASTContext & |
| 332 | SymbolFileDWARF::GetClangASTContext () |
| 333 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 334 | if (GetDebugMapSymfile ()) |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 335 | return m_debug_map_symfile->GetClangASTContext (); |
| 336 | |
| 337 | ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext(); |
| 338 | if (!m_is_external_ast_source) |
| 339 | { |
| 340 | m_is_external_ast_source = true; |
| 341 | llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap ( |
| 342 | new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl, |
| 343 | SymbolFileDWARF::CompleteObjCInterfaceDecl, |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 344 | SymbolFileDWARF::FindExternalVisibleDeclsByName, |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 345 | SymbolFileDWARF::LayoutRecordType, |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 346 | this)); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 347 | ast.SetExternalSource (ast_source_ap); |
| 348 | } |
| 349 | return ast; |
| 350 | } |
| 351 | |
| 352 | void |
| 353 | SymbolFileDWARF::InitializeObject() |
| 354 | { |
| 355 | // Install our external AST source callbacks so we can complete Clang types. |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 356 | ModuleSP module_sp (m_obj_file->GetModule()); |
| 357 | if (module_sp) |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 358 | { |
| 359 | const SectionList *section_list = m_obj_file->GetSectionList(); |
| 360 | |
| 361 | const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get(); |
| 362 | |
| 363 | // Memory map the DWARF mach-o segment so we have everything mmap'ed |
| 364 | // to keep our heap memory usage down. |
| 365 | if (section) |
| Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 366 | m_obj_file->MemoryMapSectionData(section, m_dwarf_data); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 367 | } |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 368 | get_apple_names_data(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 369 | if (m_data_apple_names.GetByteSize() > 0) |
| 370 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 371 | m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names")); |
| 372 | if (m_apple_names_ap->IsValid()) |
| 373 | m_using_apple_tables = true; |
| 374 | else |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 375 | m_apple_names_ap.reset(); |
| 376 | } |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 377 | get_apple_types_data(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 378 | if (m_data_apple_types.GetByteSize() > 0) |
| 379 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 380 | m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types")); |
| 381 | if (m_apple_types_ap->IsValid()) |
| 382 | m_using_apple_tables = true; |
| 383 | else |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 384 | m_apple_types_ap.reset(); |
| 385 | } |
| 386 | |
| 387 | get_apple_namespaces_data(); |
| 388 | if (m_data_apple_namespaces.GetByteSize() > 0) |
| 389 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 390 | m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces")); |
| 391 | if (m_apple_namespaces_ap->IsValid()) |
| 392 | m_using_apple_tables = true; |
| 393 | else |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 394 | m_apple_namespaces_ap.reset(); |
| 395 | } |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 396 | |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 397 | get_apple_objc_data(); |
| 398 | if (m_data_apple_objc.GetByteSize() > 0) |
| 399 | { |
| 400 | m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc")); |
| 401 | if (m_apple_objc_ap->IsValid()) |
| 402 | m_using_apple_tables = true; |
| 403 | else |
| 404 | m_apple_objc_ap.reset(); |
| 405 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | bool |
| 409 | SymbolFileDWARF::SupportedVersion(uint16_t version) |
| 410 | { |
| Greg Clayton | abcbfe5 | 2013-04-04 00:00:36 +0000 | [diff] [blame] | 411 | return version == 2 || version == 3 || version == 4; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | uint32_t |
| Sean Callanan | bfaf54d | 2011-12-03 04:38:43 +0000 | [diff] [blame] | 415 | SymbolFileDWARF::CalculateAbilities () |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 416 | { |
| 417 | uint32_t abilities = 0; |
| 418 | if (m_obj_file != NULL) |
| 419 | { |
| 420 | const Section* section = NULL; |
| 421 | const SectionList *section_list = m_obj_file->GetSectionList(); |
| 422 | if (section_list == NULL) |
| 423 | return 0; |
| 424 | |
| 425 | uint64_t debug_abbrev_file_size = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 426 | uint64_t debug_info_file_size = 0; |
| 427 | uint64_t debug_line_file_size = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 428 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 429 | section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 430 | |
| 431 | if (section) |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 432 | section_list = §ion->GetChildren (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 433 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 434 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 435 | if (section != NULL) |
| 436 | { |
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 437 | debug_info_file_size = section->GetFileSize(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 438 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 439 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 440 | if (section) |
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 441 | debug_abbrev_file_size = section->GetFileSize(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 442 | else |
| 443 | m_flags.Set (flagsGotDebugAbbrevData); |
| 444 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 445 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 446 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 447 | m_flags.Set (flagsGotDebugArangesData); |
| 448 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 449 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 450 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 451 | m_flags.Set (flagsGotDebugFrameData); |
| 452 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 453 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 454 | if (section) |
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 455 | debug_line_file_size = section->GetFileSize(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 456 | else |
| 457 | m_flags.Set (flagsGotDebugLineData); |
| 458 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 459 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 460 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 461 | m_flags.Set (flagsGotDebugLocData); |
| 462 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 463 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 464 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 465 | m_flags.Set (flagsGotDebugMacInfoData); |
| 466 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 467 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 468 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 469 | m_flags.Set (flagsGotDebugPubNamesData); |
| 470 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 471 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 472 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 473 | m_flags.Set (flagsGotDebugPubTypesData); |
| 474 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 475 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 476 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 477 | m_flags.Set (flagsGotDebugRangesData); |
| 478 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 479 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 480 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 481 | m_flags.Set (flagsGotDebugStrData); |
| 482 | } |
| Greg Clayton | 6c59661 | 2012-05-18 21:47:20 +0000 | [diff] [blame] | 483 | else |
| 484 | { |
| 485 | const char *symfile_dir_cstr = m_obj_file->GetFileSpec().GetDirectory().GetCString(); |
| 486 | if (symfile_dir_cstr) |
| 487 | { |
| 488 | if (strcasestr(symfile_dir_cstr, ".dsym")) |
| 489 | { |
| 490 | if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo) |
| 491 | { |
| 492 | // We have a dSYM file that didn't have a any debug info. |
| 493 | // If the string table has a size of 1, then it was made from |
| 494 | // an executable with no debug info, or from an executable that |
| 495 | // was stripped. |
| 496 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get(); |
| 497 | if (section && section->GetFileSize() == 1) |
| 498 | { |
| 499 | m_obj_file->GetModule()->ReportWarning ("empty dSYM file detected, dSYM was created with an executable with no debug info."); |
| 500 | } |
| 501 | } |
| 502 | } |
| 503 | } |
| 504 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 505 | |
| 506 | if (debug_abbrev_file_size > 0 && debug_info_file_size > 0) |
| 507 | abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes; |
| 508 | |
| 509 | if (debug_line_file_size > 0) |
| 510 | abilities |= LineTables; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 511 | } |
| 512 | return abilities; |
| 513 | } |
| 514 | |
| 515 | const DataExtractor& |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 516 | SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 517 | { |
| 518 | if (m_flags.IsClear (got_flag)) |
| 519 | { |
| 520 | m_flags.Set (got_flag); |
| 521 | const SectionList *section_list = m_obj_file->GetSectionList(); |
| 522 | if (section_list) |
| 523 | { |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 524 | SectionSP section_sp (section_list->FindSectionByType(sect_type, true)); |
| 525 | if (section_sp) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 526 | { |
| 527 | // See if we memory mapped the DWARF segment? |
| 528 | if (m_dwarf_data.GetByteSize()) |
| 529 | { |
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 530 | data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetFileSize()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 531 | } |
| 532 | else |
| 533 | { |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 534 | if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 535 | data.Clear(); |
| 536 | } |
| 537 | } |
| 538 | } |
| 539 | } |
| 540 | return data; |
| 541 | } |
| 542 | |
| 543 | const DataExtractor& |
| 544 | SymbolFileDWARF::get_debug_abbrev_data() |
| 545 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 546 | return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | const DataExtractor& |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 550 | SymbolFileDWARF::get_debug_aranges_data() |
| 551 | { |
| 552 | return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges); |
| 553 | } |
| 554 | |
| 555 | const DataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 556 | SymbolFileDWARF::get_debug_frame_data() |
| 557 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 558 | return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | const DataExtractor& |
| 562 | SymbolFileDWARF::get_debug_info_data() |
| 563 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 564 | return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | const DataExtractor& |
| 568 | SymbolFileDWARF::get_debug_line_data() |
| 569 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 570 | return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | const DataExtractor& |
| 574 | SymbolFileDWARF::get_debug_loc_data() |
| 575 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 576 | return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | const DataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 580 | SymbolFileDWARF::get_debug_ranges_data() |
| 581 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 582 | return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | const DataExtractor& |
| 586 | SymbolFileDWARF::get_debug_str_data() |
| 587 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 588 | return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 589 | } |
| 590 | |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 591 | const DataExtractor& |
| Greg Clayton | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 592 | SymbolFileDWARF::get_apple_names_data() |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 593 | { |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 594 | return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names); |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | const DataExtractor& |
| Greg Clayton | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 598 | SymbolFileDWARF::get_apple_types_data() |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 599 | { |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 600 | return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types); |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 601 | } |
| 602 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 603 | const DataExtractor& |
| 604 | SymbolFileDWARF::get_apple_namespaces_data() |
| 605 | { |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 606 | return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces); |
| 607 | } |
| 608 | |
| 609 | const DataExtractor& |
| 610 | SymbolFileDWARF::get_apple_objc_data() |
| 611 | { |
| 612 | return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 613 | } |
| 614 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 615 | |
| 616 | DWARFDebugAbbrev* |
| 617 | SymbolFileDWARF::DebugAbbrev() |
| 618 | { |
| 619 | if (m_abbr.get() == NULL) |
| 620 | { |
| 621 | const DataExtractor &debug_abbrev_data = get_debug_abbrev_data(); |
| 622 | if (debug_abbrev_data.GetByteSize() > 0) |
| 623 | { |
| 624 | m_abbr.reset(new DWARFDebugAbbrev()); |
| 625 | if (m_abbr.get()) |
| 626 | m_abbr->Parse(debug_abbrev_data); |
| 627 | } |
| 628 | } |
| 629 | return m_abbr.get(); |
| 630 | } |
| 631 | |
| 632 | const DWARFDebugAbbrev* |
| 633 | SymbolFileDWARF::DebugAbbrev() const |
| 634 | { |
| 635 | return m_abbr.get(); |
| 636 | } |
| 637 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 638 | |
| 639 | DWARFDebugInfo* |
| 640 | SymbolFileDWARF::DebugInfo() |
| 641 | { |
| 642 | if (m_info.get() == NULL) |
| 643 | { |
| 644 | Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this); |
| 645 | if (get_debug_info_data().GetByteSize() > 0) |
| 646 | { |
| 647 | m_info.reset(new DWARFDebugInfo()); |
| 648 | if (m_info.get()) |
| 649 | { |
| 650 | m_info->SetDwarfData(this); |
| 651 | } |
| 652 | } |
| 653 | } |
| 654 | return m_info.get(); |
| 655 | } |
| 656 | |
| 657 | const DWARFDebugInfo* |
| 658 | SymbolFileDWARF::DebugInfo() const |
| 659 | { |
| 660 | return m_info.get(); |
| 661 | } |
| 662 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 663 | DWARFCompileUnit* |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 664 | SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 665 | { |
| 666 | DWARFDebugInfo* info = DebugInfo(); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 667 | if (info) |
| 668 | { |
| 669 | if (GetDebugMapSymfile ()) |
| 670 | { |
| 671 | // The debug map symbol file made the compile units for this DWARF |
| 672 | // file which is .o file with DWARF in it, and we should have |
| 673 | // only 1 compile unit which is at offset zero in the DWARF. |
| 674 | // TODO: modify to support LTO .o files where each .o file might |
| 675 | // have multiple DW_TAG_compile_unit tags. |
| 676 | return info->GetCompileUnit(0).get(); |
| 677 | } |
| 678 | else |
| 679 | { |
| 680 | // Just a normal DWARF file whose user ID for the compile unit is |
| 681 | // the DWARF offset itself |
| 682 | return info->GetCompileUnit((dw_offset_t)comp_unit->GetID()).get(); |
| 683 | } |
| 684 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 685 | return NULL; |
| 686 | } |
| 687 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 688 | |
| 689 | DWARFDebugRanges* |
| 690 | SymbolFileDWARF::DebugRanges() |
| 691 | { |
| 692 | if (m_ranges.get() == NULL) |
| 693 | { |
| 694 | Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this); |
| 695 | if (get_debug_ranges_data().GetByteSize() > 0) |
| 696 | { |
| 697 | m_ranges.reset(new DWARFDebugRanges()); |
| 698 | if (m_ranges.get()) |
| 699 | m_ranges->Extract(this); |
| 700 | } |
| 701 | } |
| 702 | return m_ranges.get(); |
| 703 | } |
| 704 | |
| 705 | const DWARFDebugRanges* |
| 706 | SymbolFileDWARF::DebugRanges() const |
| 707 | { |
| 708 | return m_ranges.get(); |
| 709 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 710 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 711 | lldb::CompUnitSP |
| 712 | SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 713 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 714 | CompUnitSP cu_sp; |
| 715 | if (dwarf_cu) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 716 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 717 | CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData(); |
| 718 | if (comp_unit) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 719 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 720 | // We already parsed this compile unit, had out a shared pointer to it |
| 721 | cu_sp = comp_unit->shared_from_this(); |
| 722 | } |
| 723 | else |
| 724 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 725 | if (GetDebugMapSymfile ()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 726 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 727 | // Let the debug map create the compile unit |
| 728 | cu_sp = m_debug_map_symfile->GetCompileUnit(this); |
| 729 | dwarf_cu->SetUserData(cu_sp.get()); |
| 730 | } |
| 731 | else |
| 732 | { |
| 733 | ModuleSP module_sp (m_obj_file->GetModule()); |
| 734 | if (module_sp) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 735 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 736 | const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly (); |
| 737 | if (cu_die) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 738 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 739 | const char * cu_die_name = cu_die->GetName(this, dwarf_cu); |
| 740 | const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL); |
| 741 | LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0); |
| 742 | if (cu_die_name) |
| 743 | { |
| 744 | std::string ramapped_file; |
| 745 | FileSpec cu_file_spec; |
| Jim Ingham | 0909e5f | 2010-09-16 00:57:33 +0000 | [diff] [blame] | 746 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 747 | 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] | 748 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 749 | // If we have a full path to the compile unit, we don't need to resolve |
| 750 | // the file. This can be expensive e.g. when the source files are NFS mounted. |
| 751 | if (module_sp->RemapSourceFile(cu_die_name, ramapped_file)) |
| 752 | cu_file_spec.SetFile (ramapped_file.c_str(), false); |
| 753 | else |
| 754 | cu_file_spec.SetFile (cu_die_name, false); |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 755 | } |
| 756 | else |
| 757 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 758 | std::string fullpath(cu_comp_dir); |
| 759 | if (*fullpath.rbegin() != '/') |
| 760 | fullpath += '/'; |
| 761 | fullpath += cu_die_name; |
| 762 | if (module_sp->RemapSourceFile (fullpath.c_str(), ramapped_file)) |
| 763 | cu_file_spec.SetFile (ramapped_file.c_str(), false); |
| 764 | else |
| 765 | cu_file_spec.SetFile (fullpath.c_str(), false); |
| 766 | } |
| 767 | |
| 768 | cu_sp.reset(new CompileUnit (module_sp, |
| 769 | dwarf_cu, |
| 770 | cu_file_spec, |
| 771 | MakeUserID(dwarf_cu->GetOffset()), |
| 772 | cu_language)); |
| 773 | if (cu_sp) |
| 774 | { |
| 775 | dwarf_cu->SetUserData(cu_sp.get()); |
| 776 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 777 | // Figure out the compile unit index if we weren't given one |
| 778 | if (cu_idx == UINT32_MAX) |
| 779 | DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx); |
| 780 | |
| 781 | m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp); |
| 782 | } |
| 783 | } |
| 784 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 785 | } |
| 786 | } |
| 787 | } |
| 788 | } |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 789 | return cu_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 790 | } |
| 791 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 792 | uint32_t |
| 793 | SymbolFileDWARF::GetNumCompileUnits() |
| 794 | { |
| 795 | DWARFDebugInfo* info = DebugInfo(); |
| 796 | if (info) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 797 | return info->GetNumCompileUnits(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 798 | return 0; |
| 799 | } |
| 800 | |
| 801 | CompUnitSP |
| 802 | SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx) |
| 803 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 804 | CompUnitSP cu_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 805 | DWARFDebugInfo* info = DebugInfo(); |
| 806 | if (info) |
| 807 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 808 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx); |
| 809 | if (dwarf_cu) |
| 810 | cu_sp = ParseCompileUnit(dwarf_cu, cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 811 | } |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 812 | return cu_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | static void |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 816 | AddRangesToBlock (Block& block, |
| 817 | DWARFDebugRanges::RangeList& ranges, |
| 818 | addr_t block_base_addr) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 819 | { |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 820 | const size_t num_ranges = ranges.GetSize(); |
| 821 | for (size_t i = 0; i<num_ranges; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 822 | { |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 823 | const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i); |
| 824 | const addr_t range_base = range.GetRangeBase(); |
| 825 | assert (range_base >= block_base_addr); |
| 826 | block.AddRange(Block::Range (range_base - block_base_addr, range.GetByteSize()));; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 827 | } |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 828 | block.FinalizeRanges (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | |
| 832 | Function * |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 833 | SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 834 | { |
| 835 | DWARFDebugRanges::RangeList func_ranges; |
| 836 | const char *name = NULL; |
| 837 | const char *mangled = NULL; |
| 838 | int decl_file = 0; |
| 839 | int decl_line = 0; |
| 840 | int decl_column = 0; |
| 841 | int call_file = 0; |
| 842 | int call_line = 0; |
| 843 | int call_column = 0; |
| 844 | DWARFExpression frame_base; |
| 845 | |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 846 | assert (die->Tag() == DW_TAG_subprogram); |
| 847 | |
| 848 | if (die->Tag() != DW_TAG_subprogram) |
| 849 | return NULL; |
| 850 | |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 851 | if (die->GetDIENamesAndRanges (this, |
| 852 | dwarf_cu, |
| 853 | name, |
| 854 | mangled, |
| 855 | func_ranges, |
| 856 | decl_file, |
| 857 | decl_line, |
| 858 | decl_column, |
| 859 | call_file, |
| 860 | call_line, |
| 861 | call_column, |
| 862 | &frame_base)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 863 | { |
| 864 | // Union of all ranges in the function DIE (if the function is discontiguous) |
| 865 | AddressRange func_range; |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 866 | lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0); |
| 867 | lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 868 | if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr) |
| 869 | { |
| 870 | func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList()); |
| 871 | if (func_range.GetBaseAddress().IsValid()) |
| 872 | func_range.SetByteSize(highest_func_addr - lowest_func_addr); |
| 873 | } |
| 874 | |
| 875 | if (func_range.GetBaseAddress().IsValid()) |
| 876 | { |
| 877 | Mangled func_name; |
| 878 | if (mangled) |
| Greg Clayton | 037520e | 2012-07-18 23:18:10 +0000 | [diff] [blame] | 879 | func_name.SetValue(ConstString(mangled), true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 880 | else if (name) |
| Greg Clayton | 037520e | 2012-07-18 23:18:10 +0000 | [diff] [blame] | 881 | func_name.SetValue(ConstString(name), false); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 882 | |
| 883 | FunctionSP func_sp; |
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 884 | std::unique_ptr<Declaration> decl_ap; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 885 | if (decl_file != 0 || decl_line != 0 || decl_column != 0) |
| Greg Clayton | d7e0546 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 886 | decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), |
| 887 | decl_line, |
| 888 | decl_column)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 889 | |
| Greg Clayton | 0bd4e1b | 2011-09-30 20:52:25 +0000 | [diff] [blame] | 890 | // Supply the type _only_ if it has already been parsed |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 891 | Type *func_type = m_die_to_type.lookup (die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 892 | |
| 893 | assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED); |
| 894 | |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 895 | if (FixupAddress (func_range.GetBaseAddress())) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 896 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 897 | const user_id_t func_user_id = MakeUserID(die->GetOffset()); |
| 898 | func_sp.reset(new Function (sc.comp_unit, |
| 899 | MakeUserID(func_user_id), // UserID is the DIE offset |
| 900 | MakeUserID(func_user_id), |
| 901 | func_name, |
| 902 | func_type, |
| 903 | func_range)); // first address range |
| 904 | |
| 905 | if (func_sp.get() != NULL) |
| 906 | { |
| 907 | if (frame_base.IsValid()) |
| 908 | func_sp->GetFrameBaseExpression() = frame_base; |
| 909 | sc.comp_unit->AddFunction(func_sp); |
| 910 | return func_sp.get(); |
| 911 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 912 | } |
| 913 | } |
| 914 | } |
| 915 | return NULL; |
| 916 | } |
| 917 | |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 918 | bool |
| 919 | SymbolFileDWARF::FixupAddress (Address &addr) |
| 920 | { |
| 921 | SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile (); |
| 922 | if (debug_map_symfile) |
| 923 | { |
| 924 | return debug_map_symfile->LinkOSOAddress(addr); |
| 925 | } |
| 926 | // This is a normal DWARF file, no address fixups need to happen |
| 927 | return true; |
| 928 | } |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 929 | lldb::LanguageType |
| 930 | SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc) |
| 931 | { |
| 932 | assert (sc.comp_unit); |
| 933 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| 934 | if (dwarf_cu) |
| 935 | { |
| 936 | const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly(); |
| Jim Ingham | 28eb571 | 2012-10-12 17:34:26 +0000 | [diff] [blame] | 937 | if (die) |
| 938 | { |
| 939 | const uint32_t language = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0); |
| 940 | if (language) |
| 941 | return (lldb::LanguageType)language; |
| 942 | } |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 943 | } |
| 944 | return eLanguageTypeUnknown; |
| 945 | } |
| 946 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 947 | size_t |
| 948 | SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc) |
| 949 | { |
| 950 | assert (sc.comp_unit); |
| 951 | size_t functions_added = 0; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 952 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 953 | if (dwarf_cu) |
| 954 | { |
| 955 | DWARFDIECollection function_dies; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 956 | 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] | 957 | size_t func_idx; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 958 | for (func_idx = 0; func_idx < num_functions; ++func_idx) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 959 | { |
| 960 | const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 961 | if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 962 | { |
| 963 | if (ParseCompileUnitFunction(sc, dwarf_cu, die)) |
| 964 | ++functions_added; |
| 965 | } |
| 966 | } |
| 967 | //FixupTypes(); |
| 968 | } |
| 969 | return functions_added; |
| 970 | } |
| 971 | |
| 972 | bool |
| 973 | SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files) |
| 974 | { |
| 975 | assert (sc.comp_unit); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 976 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 977 | if (dwarf_cu) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 978 | { |
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 979 | const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 980 | |
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 981 | if (cu_die) |
| 982 | { |
| 983 | const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL); |
| 984 | 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] | 985 | |
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 986 | // All file indexes in DWARF are one based and a file of index zero is |
| 987 | // supposed to be the compile unit itself. |
| 988 | support_files.Append (*sc.comp_unit); |
| 989 | |
| 990 | return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files); |
| 991 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 992 | } |
| 993 | return false; |
| 994 | } |
| 995 | |
| 996 | struct ParseDWARFLineTableCallbackInfo |
| 997 | { |
| 998 | LineTable* line_table; |
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 999 | std::unique_ptr<LineSequence> sequence_ap; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1000 | }; |
| 1001 | |
| 1002 | //---------------------------------------------------------------------- |
| 1003 | // ParseStatementTableCallback |
| 1004 | //---------------------------------------------------------------------- |
| 1005 | static void |
| 1006 | ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData) |
| 1007 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1008 | if (state.row == DWARFDebugLine::State::StartParsingLineTable) |
| 1009 | { |
| 1010 | // Just started parsing the line table |
| 1011 | } |
| 1012 | else if (state.row == DWARFDebugLine::State::DoneParsingLineTable) |
| 1013 | { |
| 1014 | // Done parsing line table, nothing to do for the cleanup |
| 1015 | } |
| 1016 | else |
| 1017 | { |
| 1018 | ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData; |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1019 | LineTable* line_table = info->line_table; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1020 | |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1021 | // If this is our first time here, we need to create a |
| 1022 | // sequence container. |
| 1023 | if (!info->sequence_ap.get()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1024 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1025 | info->sequence_ap.reset(line_table->CreateLineSequenceContainer()); |
| 1026 | assert(info->sequence_ap.get()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1027 | } |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1028 | line_table->AppendLineEntryToSequence (info->sequence_ap.get(), |
| 1029 | state.address, |
| 1030 | state.line, |
| 1031 | state.column, |
| 1032 | state.file, |
| 1033 | state.is_stmt, |
| 1034 | state.basic_block, |
| 1035 | state.prologue_end, |
| 1036 | state.epilogue_begin, |
| 1037 | state.end_sequence); |
| 1038 | if (state.end_sequence) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1039 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1040 | // First, put the current sequence into the line table. |
| 1041 | line_table->InsertSequence(info->sequence_ap.get()); |
| 1042 | // Then, empty it to prepare for the next sequence. |
| 1043 | info->sequence_ap->Clear(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1044 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1045 | } |
| 1046 | } |
| 1047 | |
| 1048 | bool |
| 1049 | SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc) |
| 1050 | { |
| 1051 | assert (sc.comp_unit); |
| 1052 | if (sc.comp_unit->GetLineTable() != NULL) |
| 1053 | return true; |
| 1054 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1055 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1056 | if (dwarf_cu) |
| 1057 | { |
| 1058 | const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly(); |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1059 | if (dwarf_cu_die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1060 | { |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1061 | const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET); |
| 1062 | if (cu_line_offset != DW_INVALID_OFFSET) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1063 | { |
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1064 | std::unique_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit)); |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1065 | if (line_table_ap.get()) |
| 1066 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1067 | ParseDWARFLineTableCallbackInfo info; |
| 1068 | info.line_table = line_table_ap.get(); |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1069 | lldb::offset_t offset = cu_line_offset; |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1070 | DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info); |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1071 | if (m_debug_map_symfile) |
| 1072 | { |
| 1073 | // We have an object file that has a line table with addresses |
| 1074 | // that are not linked. We need to link the line table and convert |
| 1075 | // the addresses that are relative to the .o file into addresses |
| 1076 | // for the main executable. |
| 1077 | sc.comp_unit->SetLineTable (m_debug_map_symfile->LinkOSOLineTable (this, line_table_ap.get())); |
| 1078 | } |
| 1079 | else |
| 1080 | { |
| 1081 | sc.comp_unit->SetLineTable(line_table_ap.release()); |
| 1082 | return true; |
| 1083 | } |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1084 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1085 | } |
| 1086 | } |
| 1087 | } |
| 1088 | return false; |
| 1089 | } |
| 1090 | |
| 1091 | size_t |
| 1092 | SymbolFileDWARF::ParseFunctionBlocks |
| 1093 | ( |
| 1094 | const SymbolContext& sc, |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1095 | Block *parent_block, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1096 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1097 | const DWARFDebugInfoEntry *die, |
| 1098 | addr_t subprogram_low_pc, |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1099 | uint32_t depth |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1100 | ) |
| 1101 | { |
| 1102 | size_t blocks_added = 0; |
| 1103 | while (die != NULL) |
| 1104 | { |
| 1105 | dw_tag_t tag = die->Tag(); |
| 1106 | |
| 1107 | switch (tag) |
| 1108 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1109 | case DW_TAG_inlined_subroutine: |
| Greg Clayton | b4d3733 | 2011-08-12 16:22:48 +0000 | [diff] [blame] | 1110 | case DW_TAG_subprogram: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1111 | case DW_TAG_lexical_block: |
| 1112 | { |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1113 | Block *block = NULL; |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1114 | if (tag == DW_TAG_subprogram) |
| 1115 | { |
| 1116 | // Skip any DW_TAG_subprogram DIEs that are inside |
| 1117 | // of a normal or inlined functions. These will be |
| 1118 | // parsed on their own as separate entities. |
| 1119 | |
| 1120 | if (depth > 0) |
| 1121 | break; |
| 1122 | |
| 1123 | block = parent_block; |
| 1124 | } |
| 1125 | else |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1126 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1127 | BlockSP block_sp(new Block (MakeUserID(die->GetOffset()))); |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1128 | parent_block->AddChild(block_sp); |
| 1129 | block = block_sp.get(); |
| 1130 | } |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1131 | DWARFDebugRanges::RangeList ranges; |
| 1132 | const char *name = NULL; |
| 1133 | const char *mangled_name = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1134 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1135 | int decl_file = 0; |
| 1136 | int decl_line = 0; |
| 1137 | int decl_column = 0; |
| 1138 | int call_file = 0; |
| 1139 | int call_line = 0; |
| 1140 | int call_column = 0; |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1141 | if (die->GetDIENamesAndRanges (this, |
| 1142 | dwarf_cu, |
| 1143 | name, |
| 1144 | mangled_name, |
| 1145 | ranges, |
| 1146 | decl_file, decl_line, decl_column, |
| 1147 | call_file, call_line, call_column)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1148 | { |
| 1149 | if (tag == DW_TAG_subprogram) |
| 1150 | { |
| 1151 | assert (subprogram_low_pc == LLDB_INVALID_ADDRESS); |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1152 | subprogram_low_pc = ranges.GetMinRangeBase(0); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1153 | } |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1154 | else if (tag == DW_TAG_inlined_subroutine) |
| 1155 | { |
| 1156 | // We get called here for inlined subroutines in two ways. |
| 1157 | // The first time is when we are making the Function object |
| 1158 | // for this inlined concrete instance. Since we're creating a top level block at |
| 1159 | // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to |
| 1160 | // adjust the containing address. |
| 1161 | // The second time is when we are parsing the blocks inside the function that contains |
| 1162 | // the inlined concrete instance. Since these will be blocks inside the containing "real" |
| 1163 | // function the offset will be for that function. |
| 1164 | if (subprogram_low_pc == LLDB_INVALID_ADDRESS) |
| 1165 | { |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1166 | subprogram_low_pc = ranges.GetMinRangeBase(0); |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1167 | } |
| 1168 | } |
| 1169 | |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1170 | AddRangesToBlock (*block, ranges, subprogram_low_pc); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1171 | |
| 1172 | if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL)) |
| 1173 | { |
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1174 | std::unique_ptr<Declaration> decl_ap; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1175 | if (decl_file != 0 || decl_line != 0 || decl_column != 0) |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1176 | decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), |
| 1177 | decl_line, decl_column)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1178 | |
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1179 | std::unique_ptr<Declaration> call_ap; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1180 | if (call_file != 0 || call_line != 0 || call_column != 0) |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1181 | call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file), |
| 1182 | call_line, call_column)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1183 | |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1184 | block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | ++blocks_added; |
| 1188 | |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1189 | if (die->HasChildren()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1190 | { |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1191 | blocks_added += ParseFunctionBlocks (sc, |
| 1192 | block, |
| 1193 | dwarf_cu, |
| 1194 | die->GetFirstChild(), |
| 1195 | subprogram_low_pc, |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1196 | depth + 1); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1197 | } |
| 1198 | } |
| 1199 | } |
| 1200 | break; |
| 1201 | default: |
| 1202 | break; |
| 1203 | } |
| 1204 | |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1205 | // Only parse siblings of the block if we are not at depth zero. A depth |
| 1206 | // of zero indicates we are currently parsing the top level |
| 1207 | // DW_TAG_subprogram DIE |
| 1208 | |
| 1209 | if (depth == 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1210 | die = NULL; |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1211 | else |
| 1212 | die = die->GetSibling(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1213 | } |
| 1214 | return blocks_added; |
| 1215 | } |
| 1216 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1217 | bool |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1218 | SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu, |
| 1219 | const DWARFDebugInfoEntry *die, |
| 1220 | ClangASTContext::TemplateParameterInfos &template_param_infos) |
| 1221 | { |
| 1222 | const dw_tag_t tag = die->Tag(); |
| 1223 | |
| 1224 | switch (tag) |
| 1225 | { |
| 1226 | case DW_TAG_template_type_parameter: |
| 1227 | case DW_TAG_template_value_parameter: |
| 1228 | { |
| 1229 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| 1230 | |
| 1231 | DWARFDebugInfoEntry::Attributes attributes; |
| 1232 | const size_t num_attributes = die->GetAttributes (this, |
| 1233 | dwarf_cu, |
| 1234 | fixed_form_sizes, |
| 1235 | attributes); |
| 1236 | const char *name = NULL; |
| 1237 | Type *lldb_type = NULL; |
| 1238 | clang_type_t clang_type = NULL; |
| 1239 | uint64_t uval64 = 0; |
| 1240 | bool uval64_valid = false; |
| 1241 | if (num_attributes > 0) |
| 1242 | { |
| 1243 | DWARFFormValue form_value; |
| 1244 | for (size_t i=0; i<num_attributes; ++i) |
| 1245 | { |
| 1246 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 1247 | |
| 1248 | switch (attr) |
| 1249 | { |
| 1250 | case DW_AT_name: |
| 1251 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1252 | name = form_value.AsCString(&get_debug_str_data()); |
| 1253 | break; |
| 1254 | |
| 1255 | case DW_AT_type: |
| 1256 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1257 | { |
| 1258 | const dw_offset_t type_die_offset = form_value.Reference(dwarf_cu); |
| 1259 | lldb_type = ResolveTypeUID(type_die_offset); |
| 1260 | if (lldb_type) |
| 1261 | clang_type = lldb_type->GetClangForwardType(); |
| 1262 | } |
| 1263 | break; |
| 1264 | |
| 1265 | case DW_AT_const_value: |
| 1266 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1267 | { |
| 1268 | uval64_valid = true; |
| 1269 | uval64 = form_value.Unsigned(); |
| 1270 | } |
| 1271 | break; |
| 1272 | default: |
| 1273 | break; |
| 1274 | } |
| 1275 | } |
| 1276 | |
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1277 | clang::ASTContext *ast = GetClangASTContext().getASTContext(); |
| 1278 | if (!clang_type) |
| 1279 | clang_type = ast->VoidTy.getAsOpaquePtr(); |
| 1280 | |
| 1281 | if (clang_type) |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1282 | { |
| 1283 | bool is_signed = false; |
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1284 | if (name && name[0]) |
| 1285 | template_param_infos.names.push_back(name); |
| 1286 | else |
| 1287 | template_param_infos.names.push_back(NULL); |
| 1288 | |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1289 | clang::QualType clang_qual_type (clang::QualType::getFromOpaquePtr (clang_type)); |
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1290 | if (tag == DW_TAG_template_value_parameter && |
| 1291 | lldb_type != NULL && |
| 1292 | ClangASTContext::IsIntegerType (clang_type, is_signed) && |
| 1293 | uval64_valid) |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1294 | { |
| 1295 | llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed); |
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1296 | template_param_infos.args.push_back (clang::TemplateArgument (*ast, |
| Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1297 | llvm::APSInt(apint), |
| 1298 | clang_qual_type)); |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1299 | } |
| 1300 | else |
| 1301 | { |
| 1302 | template_param_infos.args.push_back (clang::TemplateArgument (clang_qual_type)); |
| 1303 | } |
| 1304 | } |
| 1305 | else |
| 1306 | { |
| 1307 | return false; |
| 1308 | } |
| 1309 | |
| 1310 | } |
| 1311 | } |
| 1312 | return true; |
| 1313 | |
| 1314 | default: |
| 1315 | break; |
| 1316 | } |
| 1317 | return false; |
| 1318 | } |
| 1319 | |
| 1320 | bool |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1321 | SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu, |
| 1322 | const DWARFDebugInfoEntry *parent_die, |
| 1323 | ClangASTContext::TemplateParameterInfos &template_param_infos) |
| 1324 | { |
| 1325 | |
| 1326 | if (parent_die == NULL) |
| Filipe Cabecinhas | 52008c6 | 2012-05-23 16:24:11 +0000 | [diff] [blame] | 1327 | return false; |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1328 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1329 | Args template_parameter_names; |
| 1330 | for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); |
| 1331 | die != NULL; |
| 1332 | die = die->GetSibling()) |
| 1333 | { |
| 1334 | const dw_tag_t tag = die->Tag(); |
| 1335 | |
| 1336 | switch (tag) |
| 1337 | { |
| 1338 | case DW_TAG_template_type_parameter: |
| 1339 | case DW_TAG_template_value_parameter: |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1340 | ParseTemplateDIE (dwarf_cu, die, template_param_infos); |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1341 | break; |
| 1342 | |
| 1343 | default: |
| 1344 | break; |
| 1345 | } |
| 1346 | } |
| 1347 | if (template_param_infos.args.empty()) |
| 1348 | return false; |
| 1349 | return template_param_infos.args.size() == template_param_infos.names.size(); |
| 1350 | } |
| 1351 | |
| 1352 | clang::ClassTemplateDecl * |
| 1353 | SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx, |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1354 | lldb::AccessType access_type, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1355 | const char *parent_name, |
| 1356 | int tag_decl_kind, |
| 1357 | const ClangASTContext::TemplateParameterInfos &template_param_infos) |
| 1358 | { |
| 1359 | if (template_param_infos.IsValid()) |
| 1360 | { |
| 1361 | std::string template_basename(parent_name); |
| 1362 | template_basename.erase (template_basename.find('<')); |
| 1363 | ClangASTContext &ast = GetClangASTContext(); |
| 1364 | |
| 1365 | return ast.CreateClassTemplateDecl (decl_ctx, |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1366 | access_type, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1367 | template_basename.c_str(), |
| 1368 | tag_decl_kind, |
| 1369 | template_param_infos); |
| 1370 | } |
| 1371 | return NULL; |
| 1372 | } |
| 1373 | |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1374 | class SymbolFileDWARF::DelayedAddObjCClassProperty |
| 1375 | { |
| 1376 | public: |
| 1377 | DelayedAddObjCClassProperty |
| 1378 | ( |
| 1379 | clang::ASTContext *ast, |
| 1380 | lldb::clang_type_t class_opaque_type, |
| 1381 | const char *property_name, |
| 1382 | lldb::clang_type_t property_opaque_type, // The property type is only required if you don't have an ivar decl |
| 1383 | clang::ObjCIvarDecl *ivar_decl, |
| 1384 | const char *property_setter_name, |
| 1385 | const char *property_getter_name, |
| 1386 | uint32_t property_attributes, |
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1387 | const ClangASTMetadata *metadata |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1388 | ) : |
| 1389 | m_ast (ast), |
| 1390 | m_class_opaque_type (class_opaque_type), |
| 1391 | m_property_name (property_name), |
| 1392 | m_property_opaque_type (property_opaque_type), |
| 1393 | m_ivar_decl (ivar_decl), |
| 1394 | m_property_setter_name (property_setter_name), |
| 1395 | m_property_getter_name (property_getter_name), |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1396 | m_property_attributes (property_attributes) |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1397 | { |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1398 | if (metadata != NULL) |
| 1399 | { |
| 1400 | m_metadata_ap.reset(new ClangASTMetadata()); |
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1401 | *m_metadata_ap = *metadata; |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1402 | } |
| 1403 | } |
| 1404 | |
| 1405 | DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs) |
| 1406 | { |
| Daniel Malea | d4c5be6 | 2012-11-12 21:02:14 +0000 | [diff] [blame] | 1407 | *this = rhs; |
| 1408 | } |
| 1409 | |
| 1410 | DelayedAddObjCClassProperty& operator= (const DelayedAddObjCClassProperty &rhs) |
| 1411 | { |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1412 | m_ast = rhs.m_ast; |
| 1413 | m_class_opaque_type = rhs.m_class_opaque_type; |
| 1414 | m_property_name = rhs.m_property_name; |
| 1415 | m_property_opaque_type = rhs.m_property_opaque_type; |
| 1416 | m_ivar_decl = rhs.m_ivar_decl; |
| 1417 | m_property_setter_name = rhs.m_property_setter_name; |
| 1418 | m_property_getter_name = rhs.m_property_getter_name; |
| 1419 | m_property_attributes = rhs.m_property_attributes; |
| 1420 | |
| 1421 | if (rhs.m_metadata_ap.get()) |
| 1422 | { |
| 1423 | m_metadata_ap.reset (new ClangASTMetadata()); |
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1424 | *m_metadata_ap = *rhs.m_metadata_ap; |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1425 | } |
| Daniel Malea | d4c5be6 | 2012-11-12 21:02:14 +0000 | [diff] [blame] | 1426 | return *this; |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1427 | } |
| 1428 | |
| 1429 | bool Finalize() const |
| 1430 | { |
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1431 | return ClangASTContext::AddObjCClassProperty (m_ast, |
| 1432 | m_class_opaque_type, |
| 1433 | m_property_name, |
| 1434 | m_property_opaque_type, |
| 1435 | m_ivar_decl, |
| 1436 | m_property_setter_name, |
| 1437 | m_property_getter_name, |
| 1438 | m_property_attributes, |
| 1439 | m_metadata_ap.get()); |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1440 | } |
| 1441 | private: |
| 1442 | clang::ASTContext *m_ast; |
| 1443 | lldb::clang_type_t m_class_opaque_type; |
| 1444 | const char *m_property_name; |
| 1445 | lldb::clang_type_t m_property_opaque_type; |
| 1446 | clang::ObjCIvarDecl *m_ivar_decl; |
| 1447 | const char *m_property_setter_name; |
| 1448 | const char *m_property_getter_name; |
| 1449 | uint32_t m_property_attributes; |
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1450 | std::unique_ptr<ClangASTMetadata> m_metadata_ap; |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1451 | }; |
| 1452 | |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1453 | struct BitfieldInfo |
| 1454 | { |
| 1455 | uint64_t bit_size; |
| 1456 | uint64_t bit_offset; |
| 1457 | |
| 1458 | BitfieldInfo () : |
| 1459 | bit_size (LLDB_INVALID_ADDRESS), |
| 1460 | bit_offset (LLDB_INVALID_ADDRESS) |
| 1461 | { |
| 1462 | } |
| 1463 | |
| 1464 | bool IsValid () |
| 1465 | { |
| 1466 | return (bit_size != LLDB_INVALID_ADDRESS) && |
| 1467 | (bit_offset != LLDB_INVALID_ADDRESS); |
| 1468 | } |
| 1469 | }; |
| 1470 | |
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1471 | |
| 1472 | bool |
| 1473 | SymbolFileDWARF::ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu, |
| 1474 | const DWARFDebugInfoEntry *parent_die) |
| 1475 | { |
| 1476 | if (parent_die) |
| 1477 | { |
| 1478 | for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 1479 | { |
| 1480 | dw_tag_t tag = die->Tag(); |
| 1481 | bool check_virtuality = false; |
| 1482 | switch (tag) |
| 1483 | { |
| 1484 | case DW_TAG_inheritance: |
| 1485 | case DW_TAG_subprogram: |
| 1486 | check_virtuality = true; |
| 1487 | break; |
| 1488 | default: |
| 1489 | break; |
| 1490 | } |
| 1491 | if (check_virtuality) |
| 1492 | { |
| 1493 | if (die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_virtuality, 0) != 0) |
| 1494 | return true; |
| 1495 | } |
| 1496 | } |
| 1497 | } |
| 1498 | return false; |
| 1499 | } |
| 1500 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1501 | size_t |
| 1502 | SymbolFileDWARF::ParseChildMembers |
| 1503 | ( |
| 1504 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1505 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1506 | const DWARFDebugInfoEntry *parent_die, |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1507 | clang_type_t class_clang_type, |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1508 | const LanguageType class_language, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1509 | std::vector<clang::CXXBaseSpecifier *>& base_classes, |
| 1510 | std::vector<int>& member_accessibilities, |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1511 | DWARFDIECollection& member_function_dies, |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1512 | DelayedPropertyList& delayed_properties, |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1513 | AccessType& default_accessibility, |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1514 | bool &is_a_class, |
| 1515 | LayoutInfo &layout_info |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1516 | ) |
| 1517 | { |
| 1518 | if (parent_die == NULL) |
| 1519 | return 0; |
| 1520 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1521 | size_t count = 0; |
| 1522 | const DWARFDebugInfoEntry *die; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 1523 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1524 | uint32_t member_idx = 0; |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1525 | BitfieldInfo last_field_info; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 1526 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1527 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 1528 | { |
| 1529 | dw_tag_t tag = die->Tag(); |
| 1530 | |
| 1531 | switch (tag) |
| 1532 | { |
| 1533 | case DW_TAG_member: |
| Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1534 | case DW_TAG_APPLE_property: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1535 | { |
| 1536 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1537 | const size_t num_attributes = die->GetAttributes (this, |
| 1538 | dwarf_cu, |
| 1539 | fixed_form_sizes, |
| 1540 | attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1541 | if (num_attributes > 0) |
| 1542 | { |
| 1543 | Declaration decl; |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1544 | //DWARFExpression location; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1545 | const char *name = NULL; |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1546 | const char *prop_name = NULL; |
| 1547 | const char *prop_getter_name = NULL; |
| 1548 | const char *prop_setter_name = NULL; |
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1549 | uint32_t prop_attributes = 0; |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1550 | |
| 1551 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1552 | bool is_artificial = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1553 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1554 | AccessType accessibility = eAccessNone; |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1555 | uint32_t member_byte_offset = UINT32_MAX; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1556 | size_t byte_size = 0; |
| 1557 | size_t bit_offset = 0; |
| 1558 | size_t bit_size = 0; |
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1559 | 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] | 1560 | uint32_t i; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1561 | for (i=0; i<num_attributes && !is_artificial; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1562 | { |
| 1563 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 1564 | DWARFFormValue form_value; |
| 1565 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1566 | { |
| 1567 | switch (attr) |
| 1568 | { |
| 1569 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 1570 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 1571 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 1572 | case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; |
| 1573 | case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; |
| 1574 | case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break; |
| 1575 | case DW_AT_bit_size: bit_size = form_value.Unsigned(); break; |
| 1576 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; |
| 1577 | case DW_AT_data_member_location: |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1578 | if (form_value.BlockData()) |
| 1579 | { |
| 1580 | Value initialValue(0); |
| 1581 | Value memberOffset(0); |
| 1582 | const DataExtractor& debug_info_data = get_debug_info_data(); |
| 1583 | uint32_t block_length = form_value.Unsigned(); |
| 1584 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 1585 | if (DWARFExpression::Evaluate(NULL, // ExecutionContext * |
| 1586 | NULL, // clang::ASTContext * |
| 1587 | NULL, // ClangExpressionVariableList * |
| 1588 | NULL, // ClangExpressionDeclMap * |
| 1589 | NULL, // RegisterContext * |
| 1590 | debug_info_data, |
| 1591 | block_offset, |
| 1592 | block_length, |
| 1593 | eRegisterKindDWARF, |
| 1594 | &initialValue, |
| 1595 | memberOffset, |
| 1596 | NULL)) |
| 1597 | { |
| 1598 | member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt(); |
| 1599 | } |
| 1600 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1601 | break; |
| 1602 | |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1603 | case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break; |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 1604 | case DW_AT_artificial: is_artificial = form_value.Boolean(); break; |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1605 | case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break; |
| 1606 | case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break; |
| 1607 | case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break; |
| 1608 | case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break; |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 1609 | case DW_AT_external: is_external = form_value.Boolean(); break; |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1610 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1611 | default: |
| Greg Clayton | 1b02c17 | 2012-03-14 21:00:47 +0000 | [diff] [blame] | 1612 | case DW_AT_declaration: |
| 1613 | case DW_AT_description: |
| 1614 | case DW_AT_mutable: |
| 1615 | case DW_AT_visibility: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1616 | case DW_AT_sibling: |
| 1617 | break; |
| 1618 | } |
| 1619 | } |
| 1620 | } |
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1621 | |
| 1622 | if (prop_name) |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1623 | { |
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1624 | ConstString fixed_getter; |
| 1625 | ConstString fixed_setter; |
| 1626 | |
| 1627 | // Check if the property getter/setter were provided as full |
| 1628 | // names. We want basenames, so we extract them. |
| 1629 | |
| 1630 | if (prop_getter_name && prop_getter_name[0] == '-') |
| 1631 | { |
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 1632 | ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true); |
| 1633 | prop_getter_name = prop_getter_method.GetSelector().GetCString(); |
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1634 | } |
| 1635 | |
| 1636 | if (prop_setter_name && prop_setter_name[0] == '-') |
| 1637 | { |
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 1638 | ObjCLanguageRuntime::MethodName prop_setter_method(prop_setter_name, true); |
| 1639 | prop_setter_name = prop_setter_method.GetSelector().GetCString(); |
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1640 | } |
| 1641 | |
| 1642 | // If the names haven't been provided, they need to be |
| 1643 | // filled in. |
| 1644 | |
| 1645 | if (!prop_getter_name) |
| 1646 | { |
| 1647 | prop_getter_name = prop_name; |
| 1648 | } |
| 1649 | if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly)) |
| 1650 | { |
| 1651 | StreamString ss; |
| 1652 | |
| 1653 | ss.Printf("set%c%s:", |
| 1654 | toupper(prop_name[0]), |
| 1655 | &prop_name[1]); |
| 1656 | |
| 1657 | fixed_setter.SetCString(ss.GetData()); |
| 1658 | prop_setter_name = fixed_setter.GetCString(); |
| 1659 | } |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1660 | } |
| 1661 | |
| 1662 | // Clang has a DWARF generation bug where sometimes it |
| Greg Clayton | 4495393 | 2011-10-25 01:25:35 +0000 | [diff] [blame] | 1663 | // represents fields that are references with bad byte size |
| 1664 | // and bit size/offset information such as: |
| 1665 | // |
| 1666 | // DW_AT_byte_size( 0x00 ) |
| 1667 | // DW_AT_bit_size( 0x40 ) |
| 1668 | // DW_AT_bit_offset( 0xffffffffffffffc0 ) |
| 1669 | // |
| 1670 | // So check the bit offset to make sure it is sane, and if |
| 1671 | // the values are not sane, remove them. If we don't do this |
| 1672 | // then we will end up with a crash if we try to use this |
| 1673 | // type in an expression when clang becomes unhappy with its |
| 1674 | // recycled debug info. |
| Sean Callanan | 5a477cf | 2010-10-30 01:56:10 +0000 | [diff] [blame] | 1675 | |
| Greg Clayton | 4495393 | 2011-10-25 01:25:35 +0000 | [diff] [blame] | 1676 | if (bit_offset > 128) |
| 1677 | { |
| 1678 | bit_size = 0; |
| 1679 | bit_offset = 0; |
| 1680 | } |
| 1681 | |
| 1682 | // FIXME: Make Clang ignore Objective-C accessibility for expressions |
| Sean Callanan | 5a477cf | 2010-10-30 01:56:10 +0000 | [diff] [blame] | 1683 | if (class_language == eLanguageTypeObjC || |
| 1684 | class_language == eLanguageTypeObjC_plus_plus) |
| 1685 | accessibility = eAccessNone; |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1686 | |
| 1687 | if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name)) |
| 1688 | { |
| 1689 | // Not all compilers will mark the vtable pointer |
| 1690 | // member as artificial (llvm-gcc). We can't have |
| 1691 | // the virtual members in our classes otherwise it |
| 1692 | // throws off all child offsets since we end up |
| 1693 | // having and extra pointer sized member in our |
| 1694 | // class layouts. |
| 1695 | is_artificial = true; |
| 1696 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1697 | |
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1698 | // Skip static members |
| 1699 | if (is_external && member_byte_offset == UINT32_MAX) |
| Greg Clayton | 973b6c9 | 2013-04-11 16:57:51 +0000 | [diff] [blame] | 1700 | { |
| 1701 | Type *var_type = ResolveTypeUID(encoding_uid); |
| 1702 | |
| 1703 | if (var_type) |
| 1704 | { |
| 1705 | GetClangASTContext().AddVariableToRecordType (class_clang_type, |
| 1706 | name, |
| 1707 | var_type->GetClangLayoutType(), |
| 1708 | accessibility); |
| 1709 | } |
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1710 | break; |
| Greg Clayton | 973b6c9 | 2013-04-11 16:57:51 +0000 | [diff] [blame] | 1711 | } |
| Greg Clayton | e528efd7 | 2013-02-26 23:45:18 +0000 | [diff] [blame] | 1712 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1713 | if (is_artificial == false) |
| 1714 | { |
| 1715 | Type *member_type = ResolveTypeUID(encoding_uid); |
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 1716 | |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1717 | clang::FieldDecl *field_decl = NULL; |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1718 | if (tag == DW_TAG_member) |
| Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1719 | { |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1720 | if (member_type) |
| 1721 | { |
| 1722 | if (accessibility == eAccessNone) |
| 1723 | accessibility = default_accessibility; |
| 1724 | member_accessibilities.push_back(accessibility); |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1725 | |
| 1726 | BitfieldInfo this_field_info; |
| 1727 | |
| 1728 | this_field_info.bit_size = bit_size; |
| 1729 | |
| 1730 | if (member_byte_offset != UINT32_MAX || bit_size != 0) |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1731 | { |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1732 | ///////////////////////////////////////////////////////////// |
| 1733 | // How to locate a field given the DWARF debug information |
| 1734 | // |
| 1735 | // AT_byte_size indicates the size of the word in which the |
| 1736 | // bit offset must be interpreted. |
| 1737 | // |
| 1738 | // AT_data_member_location indicates the byte offset of the |
| 1739 | // word from the base address of the structure. |
| 1740 | // |
| 1741 | // AT_bit_offset indicates how many bits into the word |
| 1742 | // (according to the host endianness) the low-order bit of |
| 1743 | // the field starts. AT_bit_offset can be negative. |
| 1744 | // |
| 1745 | // AT_bit_size indicates the size of the field in bits. |
| 1746 | ///////////////////////////////////////////////////////////// |
| 1747 | |
| 1748 | this_field_info.bit_offset = 0; |
| 1749 | |
| 1750 | this_field_info.bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8)); |
| 1751 | |
| 1752 | if (GetObjectFile()->GetByteOrder() == eByteOrderLittle) |
| 1753 | { |
| 1754 | this_field_info.bit_offset += byte_size * 8; |
| 1755 | this_field_info.bit_offset -= (bit_offset + bit_size); |
| 1756 | } |
| 1757 | else |
| 1758 | { |
| 1759 | this_field_info.bit_offset += bit_offset; |
| 1760 | } |
| 1761 | } |
| 1762 | |
| 1763 | // If the member to be emitted did not start on a character boundary and there is |
| 1764 | // empty space between the last field and this one, then we need to emit an |
| 1765 | // anonymous member filling up the space up to its start. There are three cases |
| 1766 | // here: |
| 1767 | // |
| 1768 | // 1 If the previous member ended on a character boundary, then we can emit an |
| 1769 | // anonymous member starting at the most recent character boundary. |
| 1770 | // |
| 1771 | // 2 If the previous member did not end on a character boundary and the distance |
| 1772 | // from the end of the previous member to the current member is less than a |
| 1773 | // word width, then we can emit an anonymous member starting right after the |
| 1774 | // previous member and right before this member. |
| 1775 | // |
| 1776 | // 3 If the previous member did not end on a character boundary and the distance |
| 1777 | // from the end of the previous member to the current member is greater than |
| 1778 | // or equal a word width, then we act as in Case 1. |
| 1779 | |
| 1780 | const uint64_t character_width = 8; |
| 1781 | const uint64_t word_width = 32; |
| 1782 | |
| 1783 | if (this_field_info.IsValid()) |
| 1784 | { |
| 1785 | // Objective-C has invalid DW_AT_bit_offset values in older versions |
| 1786 | // 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] | 1787 | // if we have a new enough clang. |
| 1788 | bool detect_unnamed_bitfields = true; |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1789 | |
| Greg Clayton | 37c36e4 | 2012-11-27 00:59:26 +0000 | [diff] [blame] | 1790 | if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus) |
| 1791 | detect_unnamed_bitfields = dwarf_cu->Supports_unnamed_objc_bitfields (); |
| 1792 | |
| 1793 | if (detect_unnamed_bitfields) |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1794 | { |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1795 | BitfieldInfo anon_field_info; |
| 1796 | |
| 1797 | if ((this_field_info.bit_offset % character_width) != 0) // not char aligned |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1798 | { |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1799 | uint64_t last_field_end = 0; |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1800 | |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1801 | if (last_field_info.IsValid()) |
| 1802 | 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] | 1803 | |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1804 | if (this_field_info.bit_offset != last_field_end) |
| 1805 | { |
| 1806 | if (((last_field_end % character_width) == 0) || // case 1 |
| 1807 | (this_field_info.bit_offset - last_field_end >= word_width)) // case 3 |
| 1808 | { |
| 1809 | anon_field_info.bit_size = this_field_info.bit_offset % character_width; |
| 1810 | anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size; |
| 1811 | } |
| 1812 | else // case 2 |
| 1813 | { |
| 1814 | anon_field_info.bit_size = this_field_info.bit_offset - last_field_end; |
| 1815 | anon_field_info.bit_offset = last_field_end; |
| 1816 | } |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1817 | } |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1818 | } |
| 1819 | |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1820 | if (anon_field_info.IsValid()) |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1821 | { |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1822 | clang::FieldDecl *unnamed_bitfield_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type, |
| 1823 | NULL, |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1824 | GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width), |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1825 | accessibility, |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1826 | anon_field_info.bit_size); |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1827 | |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1828 | 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] | 1829 | } |
| 1830 | } |
| 1831 | } |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1832 | |
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 1833 | clang_type_t member_clang_type = member_type->GetClangLayoutType(); |
| 1834 | |
| 1835 | { |
| 1836 | // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>). |
| 1837 | // If the current field is at the end of the structure, then there is definitely no room for extra |
| 1838 | // elements and we override the type to array[0]. |
| 1839 | |
| 1840 | clang_type_t member_array_element_type; |
| 1841 | uint64_t member_array_size; |
| 1842 | bool member_array_is_incomplete; |
| 1843 | |
| 1844 | if (GetClangASTContext().IsArrayType(member_clang_type, |
| 1845 | &member_array_element_type, |
| 1846 | &member_array_size, |
| 1847 | &member_array_is_incomplete) && |
| 1848 | !member_array_is_incomplete) |
| 1849 | { |
| 1850 | uint64_t parent_byte_size = parent_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, UINT64_MAX); |
| 1851 | |
| 1852 | if (member_byte_offset >= parent_byte_size) |
| 1853 | { |
| 1854 | if (member_array_size != 1) |
| 1855 | { |
| 1856 | 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, |
| 1857 | MakeUserID(die->GetOffset()), |
| 1858 | name, |
| 1859 | encoding_uid, |
| 1860 | MakeUserID(parent_die->GetOffset())); |
| 1861 | } |
| 1862 | |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 1863 | member_clang_type = GetClangASTContext().CreateArrayType(member_array_element_type, 0, false); |
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 1864 | } |
| 1865 | } |
| 1866 | } |
| 1867 | |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 1868 | field_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type, |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1869 | name, |
| Sean Callanan | fa3ab45 | 2012-12-14 00:54:13 +0000 | [diff] [blame] | 1870 | member_clang_type, |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1871 | accessibility, |
| 1872 | bit_size); |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 1873 | |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 1874 | GetClangASTContext().SetMetadataAsUserID (field_decl, MakeUserID(die->GetOffset())); |
| Sean Callanan | faa0bb3 | 2012-12-05 23:37:14 +0000 | [diff] [blame] | 1875 | |
| 1876 | if (this_field_info.IsValid()) |
| 1877 | { |
| 1878 | layout_info.field_offsets.insert(std::make_pair(field_decl, this_field_info.bit_offset)); |
| 1879 | last_field_info = this_field_info; |
| 1880 | } |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1881 | } |
| 1882 | else |
| 1883 | { |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1884 | if (name) |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1885 | 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] | 1886 | MakeUserID(die->GetOffset()), |
| 1887 | name, |
| 1888 | encoding_uid); |
| 1889 | else |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1890 | 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] | 1891 | MakeUserID(die->GetOffset()), |
| 1892 | encoding_uid); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1893 | } |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1894 | } |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1895 | |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1896 | if (prop_name != NULL) |
| 1897 | { |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1898 | clang::ObjCIvarDecl *ivar_decl = NULL; |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1899 | |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1900 | if (field_decl) |
| 1901 | { |
| 1902 | ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl); |
| 1903 | assert (ivar_decl != NULL); |
| 1904 | } |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1905 | |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1906 | ClangASTMetadata metadata; |
| 1907 | metadata.SetUserID (MakeUserID(die->GetOffset())); |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1908 | delayed_properties.push_back(DelayedAddObjCClassProperty(GetClangASTContext().getASTContext(), |
| 1909 | class_clang_type, |
| 1910 | prop_name, |
| 1911 | member_type->GetClangLayoutType(), |
| 1912 | ivar_decl, |
| 1913 | prop_setter_name, |
| 1914 | prop_getter_name, |
| 1915 | prop_attributes, |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1916 | &metadata)); |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 1917 | |
| Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 1918 | if (ivar_decl) |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 1919 | GetClangASTContext().SetMetadataAsUserID (ivar_decl, MakeUserID(die->GetOffset())); |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1920 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1921 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1922 | } |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1923 | ++member_idx; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1924 | } |
| 1925 | break; |
| 1926 | |
| 1927 | case DW_TAG_subprogram: |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1928 | // Let the type parsing code handle this one for us. |
| 1929 | member_function_dies.Append (die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1930 | break; |
| 1931 | |
| 1932 | case DW_TAG_inheritance: |
| 1933 | { |
| 1934 | is_a_class = true; |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1935 | if (default_accessibility == eAccessNone) |
| 1936 | default_accessibility = eAccessPrivate; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1937 | // TODO: implement DW_TAG_inheritance type parsing |
| 1938 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1939 | const size_t num_attributes = die->GetAttributes (this, |
| 1940 | dwarf_cu, |
| 1941 | fixed_form_sizes, |
| 1942 | attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1943 | if (num_attributes > 0) |
| 1944 | { |
| 1945 | Declaration decl; |
| 1946 | DWARFExpression location; |
| 1947 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1948 | AccessType accessibility = default_accessibility; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1949 | bool is_virtual = false; |
| 1950 | bool is_base_of_class = true; |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 1951 | off_t member_byte_offset = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1952 | uint32_t i; |
| 1953 | for (i=0; i<num_attributes; ++i) |
| 1954 | { |
| 1955 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 1956 | DWARFFormValue form_value; |
| 1957 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1958 | { |
| 1959 | switch (attr) |
| 1960 | { |
| 1961 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 1962 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 1963 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 1964 | case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 1965 | case DW_AT_data_member_location: |
| 1966 | if (form_value.BlockData()) |
| 1967 | { |
| 1968 | Value initialValue(0); |
| 1969 | Value memberOffset(0); |
| 1970 | const DataExtractor& debug_info_data = get_debug_info_data(); |
| 1971 | uint32_t block_length = form_value.Unsigned(); |
| 1972 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 1973 | if (DWARFExpression::Evaluate (NULL, |
| 1974 | NULL, |
| 1975 | NULL, |
| 1976 | NULL, |
| 1977 | NULL, |
| 1978 | debug_info_data, |
| 1979 | block_offset, |
| 1980 | block_length, |
| 1981 | eRegisterKindDWARF, |
| 1982 | &initialValue, |
| 1983 | memberOffset, |
| 1984 | NULL)) |
| 1985 | { |
| 1986 | member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt(); |
| 1987 | } |
| 1988 | } |
| 1989 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1990 | |
| 1991 | case DW_AT_accessibility: |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1992 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1993 | break; |
| 1994 | |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 1995 | case DW_AT_virtuality: is_virtual = form_value.Boolean(); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1996 | default: |
| 1997 | case DW_AT_sibling: |
| 1998 | break; |
| 1999 | } |
| 2000 | } |
| 2001 | } |
| 2002 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 2003 | Type *base_class_type = ResolveTypeUID(encoding_uid); |
| 2004 | assert(base_class_type); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2005 | |
| Greg Clayton | f4ecaa5 | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 2006 | clang_type_t base_class_clang_type = base_class_type->GetClangFullType(); |
| 2007 | assert (base_class_clang_type); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2008 | if (class_language == eLanguageTypeObjC) |
| 2009 | { |
| Greg Clayton | f4ecaa5 | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 2010 | GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2011 | } |
| 2012 | else |
| 2013 | { |
| Greg Clayton | f4ecaa5 | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 2014 | base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type, |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 2015 | accessibility, |
| 2016 | is_virtual, |
| 2017 | is_base_of_class)); |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2018 | |
| 2019 | if (is_virtual) |
| 2020 | { |
| 2021 | layout_info.vbase_offsets.insert(std::make_pair(ClangASTType::GetAsCXXRecordDecl(class_clang_type), |
| 2022 | clang::CharUnits::fromQuantity(member_byte_offset))); |
| 2023 | } |
| 2024 | else |
| 2025 | { |
| 2026 | layout_info.base_offsets.insert(std::make_pair(ClangASTType::GetAsCXXRecordDecl(class_clang_type), |
| 2027 | clang::CharUnits::fromQuantity(member_byte_offset))); |
| 2028 | } |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2029 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2030 | } |
| 2031 | } |
| 2032 | break; |
| 2033 | |
| 2034 | default: |
| 2035 | break; |
| 2036 | } |
| 2037 | } |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2038 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2039 | return count; |
| 2040 | } |
| 2041 | |
| 2042 | |
| 2043 | clang::DeclContext* |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 2044 | SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2045 | { |
| 2046 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2047 | if (debug_info && UserIDMatches(type_uid)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2048 | { |
| 2049 | DWARFCompileUnitSP cu_sp; |
| 2050 | const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp); |
| 2051 | if (die) |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 2052 | return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL); |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 2053 | } |
| 2054 | return NULL; |
| 2055 | } |
| 2056 | |
| 2057 | clang::DeclContext* |
| 2058 | SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid) |
| 2059 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2060 | if (UserIDMatches(type_uid)) |
| 2061 | return GetClangDeclContextForDIEOffset (sc, type_uid); |
| 2062 | return NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2063 | } |
| 2064 | |
| 2065 | Type* |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2066 | SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2067 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2068 | if (UserIDMatches(type_uid)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2069 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2070 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2071 | if (debug_info) |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2072 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2073 | DWARFCompileUnitSP cu_sp; |
| 2074 | const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp); |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2075 | const bool assert_not_being_parsed = true; |
| 2076 | return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2077 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2078 | } |
| 2079 | return NULL; |
| 2080 | } |
| 2081 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2082 | Type* |
| 2083 | SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed) |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2084 | { |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2085 | if (die != NULL) |
| 2086 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2087 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2088 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2089 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2090 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'", |
| 2091 | die->GetOffset(), |
| 2092 | DW_TAG_value_to_name(die->Tag()), |
| 2093 | die->GetName(this, cu)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2094 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2095 | // We might be coming in in the middle of a type tree (a class |
| 2096 | // withing a class, an enum within a class), so parse any needed |
| 2097 | // parent DIEs before we get to this one... |
| 2098 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); |
| 2099 | switch (decl_ctx_die->Tag()) |
| 2100 | { |
| 2101 | case DW_TAG_structure_type: |
| 2102 | case DW_TAG_union_type: |
| 2103 | case DW_TAG_class_type: |
| 2104 | { |
| 2105 | // Get the type, which could be a forward declaration |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2106 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2107 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2108 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x", |
| 2109 | die->GetOffset(), |
| 2110 | DW_TAG_value_to_name(die->Tag()), |
| 2111 | die->GetName(this, cu), |
| 2112 | decl_ctx_die->GetOffset()); |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2113 | // |
| 2114 | // Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed); |
| 2115 | // if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag())) |
| 2116 | // { |
| 2117 | // if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2118 | // GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2119 | // "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function", |
| 2120 | // die->GetOffset(), |
| 2121 | // DW_TAG_value_to_name(die->Tag()), |
| 2122 | // die->GetName(this, cu), |
| 2123 | // decl_ctx_die->GetOffset()); |
| 2124 | // // Ask the type to complete itself if it already hasn't since if we |
| 2125 | // // want a function (method or static) from a class, the class must |
| 2126 | // // create itself and add it's own methods and class functions. |
| 2127 | // if (parent_type) |
| 2128 | // parent_type->GetClangFullType(); |
| 2129 | // } |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2130 | } |
| 2131 | break; |
| 2132 | |
| 2133 | default: |
| 2134 | break; |
| 2135 | } |
| 2136 | return ResolveType (cu, die); |
| 2137 | } |
| 2138 | return NULL; |
| 2139 | } |
| 2140 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2141 | // This function is used when SymbolFileDWARFDebugMap owns a bunch of |
| 2142 | // SymbolFileDWARF objects to detect if this DWARF file is the one that |
| 2143 | // can resolve a clang_type. |
| 2144 | bool |
| 2145 | SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type) |
| 2146 | { |
| 2147 | clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type); |
| 2148 | const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers); |
| 2149 | return die != NULL; |
| 2150 | } |
| 2151 | |
| 2152 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2153 | lldb::clang_type_t |
| 2154 | SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type) |
| 2155 | { |
| 2156 | // 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] | 2157 | clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type); |
| 2158 | 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] | 2159 | if (die == NULL) |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2160 | { |
| 2161 | // We have already resolved this type... |
| 2162 | return clang_type; |
| 2163 | } |
| 2164 | // Once we start resolving this type, remove it from the forward declaration |
| 2165 | // map in case anyone child members or other types require this type to get resolved. |
| 2166 | // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition |
| 2167 | // are done. |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2168 | m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers); |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2169 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2170 | |
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 2171 | // Disable external storage for this type so we don't get anymore |
| 2172 | // clang::ExternalASTSource queries for this type. |
| 2173 | ClangASTContext::SetHasExternalStorage (clang_type, false); |
| 2174 | |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2175 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2176 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2177 | DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get(); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2178 | Type *type = m_die_to_type.lookup (die); |
| 2179 | |
| 2180 | const dw_tag_t tag = die->Tag(); |
| 2181 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2182 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2183 | if (log) |
| Greg Clayton | baf95da | 2012-03-30 23:50:54 +0000 | [diff] [blame] | 2184 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2185 | GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2186 | "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...", |
| Greg Clayton | d61c0fc | 2012-04-23 22:55:20 +0000 | [diff] [blame] | 2187 | MakeUserID(die->GetOffset()), |
| 2188 | DW_TAG_value_to_name(tag), |
| 2189 | type->GetName().AsCString()); |
| Greg Clayton | baf95da | 2012-03-30 23:50:54 +0000 | [diff] [blame] | 2190 | |
| Greg Clayton | baf95da | 2012-03-30 23:50:54 +0000 | [diff] [blame] | 2191 | } |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2192 | assert (clang_type); |
| 2193 | DWARFDebugInfoEntry::Attributes attributes; |
| 2194 | |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 2195 | ClangASTContext &ast = GetClangASTContext(); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2196 | |
| 2197 | switch (tag) |
| 2198 | { |
| 2199 | case DW_TAG_structure_type: |
| 2200 | case DW_TAG_union_type: |
| 2201 | case DW_TAG_class_type: |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2202 | { |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2203 | LayoutInfo layout_info; |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2204 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2205 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2206 | if (die->HasChildren()) |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2207 | { |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2208 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2209 | LanguageType class_language = eLanguageTypeUnknown; |
| 2210 | bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type); |
| 2211 | if (is_objc_class) |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2212 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2213 | class_language = eLanguageTypeObjC; |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2214 | // For objective C we don't start the definition when |
| 2215 | // the class is created. |
| 2216 | ast.StartTagDeclarationDefinition (clang_type); |
| 2217 | } |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2218 | |
| 2219 | int tag_decl_kind = -1; |
| 2220 | AccessType default_accessibility = eAccessNone; |
| 2221 | if (tag == DW_TAG_structure_type) |
| 2222 | { |
| 2223 | tag_decl_kind = clang::TTK_Struct; |
| 2224 | default_accessibility = eAccessPublic; |
| 2225 | } |
| 2226 | else if (tag == DW_TAG_union_type) |
| 2227 | { |
| 2228 | tag_decl_kind = clang::TTK_Union; |
| 2229 | default_accessibility = eAccessPublic; |
| 2230 | } |
| 2231 | else if (tag == DW_TAG_class_type) |
| 2232 | { |
| 2233 | tag_decl_kind = clang::TTK_Class; |
| 2234 | default_accessibility = eAccessPrivate; |
| 2235 | } |
| 2236 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2237 | SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2238 | std::vector<clang::CXXBaseSpecifier *> base_classes; |
| 2239 | std::vector<int> member_accessibilities; |
| 2240 | bool is_a_class = false; |
| 2241 | // Parse members and base classes first |
| 2242 | DWARFDIECollection member_function_dies; |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2243 | |
| 2244 | DelayedPropertyList delayed_properties; |
| Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2245 | ParseChildMembers (sc, |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2246 | dwarf_cu, |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2247 | die, |
| 2248 | clang_type, |
| 2249 | class_language, |
| 2250 | base_classes, |
| 2251 | member_accessibilities, |
| 2252 | member_function_dies, |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2253 | delayed_properties, |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2254 | default_accessibility, |
| 2255 | is_a_class, |
| 2256 | layout_info); |
| 2257 | |
| 2258 | // Now parse any methods if there were any... |
| 2259 | size_t num_functions = member_function_dies.Size(); |
| 2260 | if (num_functions > 0) |
| 2261 | { |
| 2262 | for (size_t i=0; i<num_functions; ++i) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2263 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2264 | ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i)); |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2265 | } |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2266 | } |
| 2267 | |
| 2268 | if (class_language == eLanguageTypeObjC) |
| 2269 | { |
| Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 2270 | std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(ast.getASTContext(), clang_type)); |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2271 | if (!class_str.empty()) |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2272 | { |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2273 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2274 | DIEArray method_die_offsets; |
| 2275 | if (m_using_apple_tables) |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2276 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2277 | if (m_apple_objc_ap.get()) |
| 2278 | m_apple_objc_ap->FindByName(class_str.c_str(), method_die_offsets); |
| 2279 | } |
| 2280 | else |
| 2281 | { |
| 2282 | if (!m_indexed) |
| 2283 | Index (); |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2284 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2285 | ConstString class_name (class_str.c_str()); |
| 2286 | m_objc_class_selectors_index.Find (class_name, method_die_offsets); |
| 2287 | } |
| 2288 | |
| 2289 | if (!method_die_offsets.empty()) |
| 2290 | { |
| 2291 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2292 | |
| 2293 | DWARFCompileUnit* method_cu = NULL; |
| 2294 | const size_t num_matches = method_die_offsets.size(); |
| 2295 | for (size_t i=0; i<num_matches; ++i) |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2296 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2297 | const dw_offset_t die_offset = method_die_offsets[i]; |
| 2298 | DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu); |
| 2299 | |
| 2300 | if (method_die) |
| 2301 | ResolveType (method_cu, method_die); |
| 2302 | else |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2303 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2304 | if (m_using_apple_tables) |
| 2305 | { |
| 2306 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n", |
| 2307 | die_offset, class_str.c_str()); |
| 2308 | } |
| 2309 | } |
| 2310 | } |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2311 | } |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2312 | |
| 2313 | for (DelayedPropertyList::const_iterator pi = delayed_properties.begin(), pe = delayed_properties.end(); |
| 2314 | pi != pe; |
| 2315 | ++pi) |
| 2316 | pi->Finalize(); |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2317 | } |
| 2318 | } |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2319 | |
| 2320 | // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we |
| 2321 | // need to tell the clang type it is actually a class. |
| 2322 | if (class_language != eLanguageTypeObjC) |
| 2323 | { |
| 2324 | if (is_a_class && tag_decl_kind != clang::TTK_Class) |
| 2325 | ast.SetTagTypeKind (clang_type, clang::TTK_Class); |
| 2326 | } |
| 2327 | |
| 2328 | // Since DW_TAG_structure_type gets used for both classes |
| 2329 | // and structures, we may need to set any DW_TAG_member |
| 2330 | // fields to have a "private" access if none was specified. |
| 2331 | // When we parsed the child members we tracked that actual |
| 2332 | // accessibility value for each DW_TAG_member in the |
| 2333 | // "member_accessibilities" array. If the value for the |
| 2334 | // member is zero, then it was set to the "default_accessibility" |
| 2335 | // which for structs was "public". Below we correct this |
| 2336 | // by setting any fields to "private" that weren't correctly |
| 2337 | // set. |
| 2338 | if (is_a_class && !member_accessibilities.empty()) |
| 2339 | { |
| 2340 | // This is a class and all members that didn't have |
| 2341 | // their access specified are private. |
| 2342 | ast.SetDefaultAccessForRecordFields (clang_type, |
| 2343 | eAccessPrivate, |
| 2344 | &member_accessibilities.front(), |
| 2345 | member_accessibilities.size()); |
| 2346 | } |
| 2347 | |
| 2348 | if (!base_classes.empty()) |
| 2349 | { |
| 2350 | ast.SetBaseClassesForClassType (clang_type, |
| 2351 | &base_classes.front(), |
| 2352 | base_classes.size()); |
| 2353 | |
| 2354 | // Clang will copy each CXXBaseSpecifier in "base_classes" |
| 2355 | // so we have to free them all. |
| 2356 | ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(), |
| 2357 | base_classes.size()); |
| 2358 | } |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2359 | } |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2360 | } |
| Sean Callanan | e8c0cfb | 2012-03-02 01:03:45 +0000 | [diff] [blame] | 2361 | |
| 2362 | ast.BuildIndirectFields (clang_type); |
| 2363 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2364 | ast.CompleteTagDeclarationDefinition (clang_type); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2365 | |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2366 | if (!layout_info.field_offsets.empty() || |
| 2367 | !layout_info.base_offsets.empty() || |
| 2368 | !layout_info.vbase_offsets.empty() ) |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2369 | { |
| 2370 | if (type) |
| 2371 | layout_info.bit_size = type->GetByteSize() * 8; |
| 2372 | if (layout_info.bit_size == 0) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2373 | 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] | 2374 | |
| 2375 | clang::CXXRecordDecl *record_decl = ClangASTType::GetAsCXXRecordDecl(clang_type); |
| 2376 | if (record_decl) |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2377 | { |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2378 | if (log) |
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2379 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2380 | GetObjectFile()->GetModule()->LogMessage (log, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2381 | "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] | 2382 | clang_type, |
| 2383 | record_decl, |
| 2384 | layout_info.bit_size, |
| 2385 | layout_info.alignment, |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2386 | (uint32_t)layout_info.field_offsets.size(), |
| 2387 | (uint32_t)layout_info.base_offsets.size(), |
| 2388 | (uint32_t)layout_info.vbase_offsets.size()); |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2389 | |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2390 | uint32_t idx; |
| 2391 | { |
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2392 | 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] | 2393 | 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] | 2394 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2395 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2396 | "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = { bit_offset=%u, name='%s' }", |
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2397 | clang_type, |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2398 | idx, |
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2399 | (uint32_t)pos->second, |
| 2400 | pos->first->getNameAsString().c_str()); |
| 2401 | } |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2402 | } |
| 2403 | |
| 2404 | { |
| 2405 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos, base_end = layout_info.base_offsets.end(); |
| 2406 | for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end; ++base_pos, ++idx) |
| 2407 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2408 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2409 | "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] = { byte_offset=%u, name='%s' }", |
| 2410 | clang_type, |
| 2411 | idx, |
| 2412 | (uint32_t)base_pos->second.getQuantity(), |
| 2413 | base_pos->first->getNameAsString().c_str()); |
| 2414 | } |
| 2415 | } |
| 2416 | { |
| 2417 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos, vbase_end = layout_info.vbase_offsets.end(); |
| 2418 | for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end; ++vbase_pos, ++idx) |
| 2419 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2420 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 2421 | "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) vbase[%u] = { byte_offset=%u, name='%s' }", |
| 2422 | clang_type, |
| 2423 | idx, |
| 2424 | (uint32_t)vbase_pos->second.getQuantity(), |
| 2425 | vbase_pos->first->getNameAsString().c_str()); |
| 2426 | } |
| 2427 | } |
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2428 | } |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2429 | m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info)); |
| 2430 | } |
| 2431 | } |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2432 | } |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2433 | |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2434 | return clang_type; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2435 | |
| 2436 | case DW_TAG_enumeration_type: |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 2437 | ast.StartTagDeclarationDefinition (clang_type); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2438 | if (die->HasChildren()) |
| 2439 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2440 | SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); |
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 2441 | bool is_signed = false; |
| 2442 | ast.IsIntegerType(clang_type, is_signed); |
| 2443 | ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), dwarf_cu, die); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2444 | } |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 2445 | ast.CompleteTagDeclarationDefinition (clang_type); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2446 | return clang_type; |
| 2447 | |
| 2448 | default: |
| 2449 | assert(false && "not a forward clang type decl!"); |
| 2450 | break; |
| 2451 | } |
| 2452 | return NULL; |
| 2453 | } |
| 2454 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2455 | Type* |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2456 | 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] | 2457 | { |
| 2458 | if (type_die != NULL) |
| 2459 | { |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 2460 | Type *type = m_die_to_type.lookup (type_die); |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2461 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2462 | if (type == NULL) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2463 | type = GetTypeForDIE (dwarf_cu, type_die).get(); |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2464 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2465 | if (assert_not_being_parsed) |
| Jim Ingham | c354928 | 2012-01-11 02:21:12 +0000 | [diff] [blame] | 2466 | { |
| 2467 | if (type != DIE_IS_BEING_PARSED) |
| 2468 | return type; |
| 2469 | |
| 2470 | 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] | 2471 | type_die->GetOffset(), |
| 2472 | DW_TAG_value_to_name(type_die->Tag()), |
| 2473 | type_die->GetName(this, dwarf_cu)); |
| Jim Ingham | c354928 | 2012-01-11 02:21:12 +0000 | [diff] [blame] | 2474 | |
| 2475 | } |
| 2476 | else |
| 2477 | return type; |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2478 | } |
| 2479 | return NULL; |
| 2480 | } |
| 2481 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2482 | CompileUnit* |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2483 | SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2484 | { |
| 2485 | // Check if the symbol vendor already knows about this compile unit? |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2486 | if (dwarf_cu->GetUserData() == NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2487 | { |
| 2488 | // The symbol vendor doesn't know about this compile unit, we |
| 2489 | // need to parse and add it to the symbol vendor object. |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2490 | return ParseCompileUnit(dwarf_cu, cu_idx).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2491 | } |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2492 | return (CompileUnit*)dwarf_cu->GetUserData(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2493 | } |
| 2494 | |
| 2495 | bool |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2496 | SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2497 | { |
| Greg Clayton | 7231035 | 2013-02-23 04:12:47 +0000 | [diff] [blame] | 2498 | sc.Clear(false); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2499 | // Check if the symbol vendor already knows about this compile unit? |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2500 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2501 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2502 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2503 | if (sc.function == NULL) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2504 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2505 | |
| 2506 | if (sc.function) |
| 2507 | { |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 2508 | sc.module_sp = sc.function->CalculateSymbolContextModule(); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2509 | return true; |
| 2510 | } |
| 2511 | |
| 2512 | return false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2513 | } |
| 2514 | |
| 2515 | uint32_t |
| 2516 | SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) |
| 2517 | { |
| 2518 | Timer scoped_timer(__PRETTY_FUNCTION__, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2519 | "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] | 2520 | so_addr.GetSection().get(), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2521 | so_addr.GetOffset(), |
| 2522 | resolve_scope); |
| 2523 | uint32_t resolved = 0; |
| 2524 | if (resolve_scope & ( eSymbolContextCompUnit | |
| 2525 | eSymbolContextFunction | |
| 2526 | eSymbolContextBlock | |
| 2527 | eSymbolContextLineEntry)) |
| 2528 | { |
| 2529 | lldb::addr_t file_vm_addr = so_addr.GetFileAddress(); |
| 2530 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2531 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2532 | if (debug_info) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2533 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2534 | 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] | 2535 | if (cu_offset != DW_INVALID_OFFSET) |
| 2536 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2537 | uint32_t cu_idx = DW_INVALID_INDEX; |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2538 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get(); |
| 2539 | if (dwarf_cu) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2540 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2541 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2542 | if (sc.comp_unit) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2543 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2544 | resolved |= eSymbolContextCompUnit; |
| 2545 | |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2546 | bool force_check_line_table = false; |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2547 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) |
| 2548 | { |
| 2549 | DWARFDebugInfoEntry *function_die = NULL; |
| 2550 | DWARFDebugInfoEntry *block_die = NULL; |
| 2551 | if (resolve_scope & eSymbolContextBlock) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2552 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2553 | dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die); |
| 2554 | } |
| 2555 | else |
| 2556 | { |
| 2557 | dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL); |
| 2558 | } |
| 2559 | |
| 2560 | if (function_die != NULL) |
| 2561 | { |
| 2562 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); |
| 2563 | if (sc.function == NULL) |
| 2564 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die); |
| 2565 | } |
| 2566 | else |
| 2567 | { |
| 2568 | // We might have had a compile unit that had discontiguous |
| 2569 | // address ranges where the gaps are symbols that don't have |
| 2570 | // any debug info. Discontiguous compile unit address ranges |
| 2571 | // should only happen when there aren't other functions from |
| 2572 | // other compile units in these gaps. This helps keep the size |
| 2573 | // of the aranges down. |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2574 | force_check_line_table = true; |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2575 | } |
| 2576 | |
| 2577 | if (sc.function != NULL) |
| 2578 | { |
| 2579 | resolved |= eSymbolContextFunction; |
| 2580 | |
| 2581 | if (resolve_scope & eSymbolContextBlock) |
| 2582 | { |
| 2583 | Block& block = sc.function->GetBlock (true); |
| 2584 | |
| 2585 | if (block_die != NULL) |
| 2586 | sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); |
| 2587 | else |
| 2588 | sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); |
| 2589 | if (sc.block) |
| 2590 | resolved |= eSymbolContextBlock; |
| 2591 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2592 | } |
| 2593 | } |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2594 | |
| 2595 | if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table) |
| 2596 | { |
| 2597 | LineTable *line_table = sc.comp_unit->GetLineTable(); |
| 2598 | if (line_table != NULL) |
| 2599 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 2600 | // And address that makes it into this function should be in terms |
| 2601 | // of this debug file if there is no debug map, or it will be an |
| 2602 | // address in the .o file which needs to be fixed up to be in terms |
| 2603 | // of the debug map executable. Either way, calling FixupAddress() |
| 2604 | // will work for us. |
| 2605 | Address exe_so_addr (so_addr); |
| 2606 | if (FixupAddress(exe_so_addr)) |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2607 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 2608 | if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry)) |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2609 | { |
| 2610 | resolved |= eSymbolContextLineEntry; |
| 2611 | } |
| 2612 | } |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 2613 | } |
| 2614 | } |
| 2615 | |
| 2616 | if (force_check_line_table && !(resolved & eSymbolContextLineEntry)) |
| 2617 | { |
| 2618 | // We might have had a compile unit that had discontiguous |
| 2619 | // address ranges where the gaps are symbols that don't have |
| 2620 | // any debug info. Discontiguous compile unit address ranges |
| 2621 | // should only happen when there aren't other functions from |
| 2622 | // other compile units in these gaps. This helps keep the size |
| 2623 | // of the aranges down. |
| 2624 | sc.comp_unit = NULL; |
| 2625 | resolved &= ~eSymbolContextCompUnit; |
| 2626 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2627 | } |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2628 | else |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2629 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2630 | GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.", |
| 2631 | cu_offset, |
| 2632 | cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2633 | } |
| 2634 | } |
| 2635 | } |
| 2636 | } |
| 2637 | } |
| 2638 | return resolved; |
| 2639 | } |
| 2640 | |
| 2641 | |
| 2642 | |
| 2643 | uint32_t |
| 2644 | SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) |
| 2645 | { |
| 2646 | const uint32_t prev_size = sc_list.GetSize(); |
| 2647 | if (resolve_scope & eSymbolContextCompUnit) |
| 2648 | { |
| 2649 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2650 | if (debug_info) |
| 2651 | { |
| 2652 | uint32_t cu_idx; |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2653 | DWARFCompileUnit* dwarf_cu = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2654 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2655 | 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] | 2656 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2657 | CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 2658 | const bool full_match = file_spec.GetDirectory(); |
| 2659 | 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] | 2660 | if (check_inlines || file_spec_matches_cu_file_spec) |
| 2661 | { |
| 2662 | SymbolContext sc (m_obj_file->GetModule()); |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2663 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2664 | if (sc.comp_unit) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2665 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2666 | uint32_t file_idx = UINT32_MAX; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2667 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2668 | // If we are looking for inline functions only and we don't |
| 2669 | // find it in the support files, we are done. |
| 2670 | if (check_inlines) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2671 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2672 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); |
| 2673 | if (file_idx == UINT32_MAX) |
| 2674 | continue; |
| 2675 | } |
| 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 | if (line != 0) |
| 2678 | { |
| 2679 | LineTable *line_table = sc.comp_unit->GetLineTable(); |
| 2680 | |
| 2681 | if (line_table != NULL && line != 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2682 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2683 | // We will have already looked up the file index if |
| 2684 | // we are searching for inline entries. |
| 2685 | if (!check_inlines) |
| 2686 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2687 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2688 | if (file_idx != UINT32_MAX) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2689 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2690 | uint32_t found_line; |
| 2691 | uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry); |
| 2692 | found_line = sc.line_entry.line; |
| 2693 | |
| 2694 | while (line_idx != UINT32_MAX) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2695 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2696 | sc.function = NULL; |
| 2697 | sc.block = NULL; |
| 2698 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2699 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2700 | const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress(); |
| 2701 | if (file_vm_addr != LLDB_INVALID_ADDRESS) |
| 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 | DWARFDebugInfoEntry *function_die = NULL; |
| 2704 | DWARFDebugInfoEntry *block_die = NULL; |
| 2705 | 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] | 2706 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2707 | if (function_die != NULL) |
| 2708 | { |
| 2709 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); |
| 2710 | if (sc.function == NULL) |
| 2711 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die); |
| 2712 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2713 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2714 | if (sc.function != NULL) |
| 2715 | { |
| 2716 | Block& block = sc.function->GetBlock (true); |
| 2717 | |
| 2718 | if (block_die != NULL) |
| 2719 | sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); |
| 2720 | else |
| 2721 | sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); |
| 2722 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2723 | } |
| 2724 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2725 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2726 | sc_list.Append(sc); |
| 2727 | line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry); |
| 2728 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2729 | } |
| 2730 | } |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2731 | else if (file_spec_matches_cu_file_spec && !check_inlines) |
| 2732 | { |
| 2733 | // only append the context if we aren't looking for inline call sites |
| 2734 | // by file and line and if the file spec matches that of the compile unit |
| 2735 | sc_list.Append(sc); |
| 2736 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2737 | } |
| 2738 | else if (file_spec_matches_cu_file_spec && !check_inlines) |
| 2739 | { |
| 2740 | // only append the context if we aren't looking for inline call sites |
| 2741 | // by file and line and if the file spec matches that of the compile unit |
| 2742 | sc_list.Append(sc); |
| 2743 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2744 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2745 | if (!check_inlines) |
| 2746 | break; |
| 2747 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2748 | } |
| 2749 | } |
| 2750 | } |
| 2751 | } |
| 2752 | return sc_list.GetSize() - prev_size; |
| 2753 | } |
| 2754 | |
| 2755 | void |
| 2756 | SymbolFileDWARF::Index () |
| 2757 | { |
| 2758 | if (m_indexed) |
| 2759 | return; |
| 2760 | m_indexed = true; |
| 2761 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 2762 | "SymbolFileDWARF::Index (%s)", |
| 2763 | GetObjectFile()->GetFileSpec().GetFilename().AsCString()); |
| 2764 | |
| 2765 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2766 | if (debug_info) |
| 2767 | { |
| 2768 | uint32_t cu_idx = 0; |
| 2769 | const uint32_t num_compile_units = GetNumCompileUnits(); |
| 2770 | for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) |
| 2771 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2772 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2773 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2774 | bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2775 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2776 | dwarf_cu->Index (cu_idx, |
| 2777 | m_function_basename_index, |
| 2778 | m_function_fullname_index, |
| 2779 | m_function_method_index, |
| 2780 | m_function_selector_index, |
| 2781 | m_objc_class_selectors_index, |
| 2782 | m_global_index, |
| 2783 | m_type_index, |
| 2784 | m_namespace_index); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2785 | |
| 2786 | // Keep memory down by clearing DIEs if this generate function |
| 2787 | // caused them to be parsed |
| 2788 | if (clear_dies) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2789 | dwarf_cu->ClearDIEs (true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2790 | } |
| 2791 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2792 | m_function_basename_index.Finalize(); |
| 2793 | m_function_fullname_index.Finalize(); |
| 2794 | m_function_method_index.Finalize(); |
| 2795 | m_function_selector_index.Finalize(); |
| 2796 | m_objc_class_selectors_index.Finalize(); |
| 2797 | m_global_index.Finalize(); |
| 2798 | m_type_index.Finalize(); |
| 2799 | m_namespace_index.Finalize(); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2800 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2801 | #if defined (ENABLE_DEBUG_PRINTF) |
| Greg Clayton | 7bd65b9 | 2011-02-09 23:39:34 +0000 | [diff] [blame] | 2802 | StreamFile s(stdout, false); |
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 2803 | s.Printf ("DWARF index for '%s':", |
| 2804 | GetObjectFile()->GetFileSpec().GetPath().c_str()); |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 2805 | s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s); |
| 2806 | s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s); |
| 2807 | s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s); |
| 2808 | s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s); |
| 2809 | s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s); |
| 2810 | s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s); |
| Greg Clayton | 69b0488 | 2010-10-15 02:03:22 +0000 | [diff] [blame] | 2811 | s.Printf("\nTypes:\n"); m_type_index.Dump (&s); |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 2812 | s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2813 | #endif |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2814 | } |
| 2815 | } |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2816 | |
| 2817 | bool |
| 2818 | SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl) |
| 2819 | { |
| 2820 | if (namespace_decl == NULL) |
| 2821 | { |
| 2822 | // Invalid namespace decl which means we aren't matching only things |
| 2823 | // in this symbol file, so return true to indicate it matches this |
| 2824 | // symbol file. |
| 2825 | return true; |
| 2826 | } |
| 2827 | |
| 2828 | clang::ASTContext *namespace_ast = namespace_decl->GetASTContext(); |
| 2829 | |
| 2830 | if (namespace_ast == NULL) |
| 2831 | return true; // No AST in the "namespace_decl", return true since it |
| 2832 | // could then match any symbol file, including this one |
| 2833 | |
| 2834 | if (namespace_ast == GetClangASTContext().getASTContext()) |
| 2835 | return true; // The ASTs match, return true |
| 2836 | |
| 2837 | // The namespace AST was valid, and it does not match... |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2838 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Sean Callanan | c41e68b | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 2839 | |
| 2840 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2841 | GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file"); |
| Sean Callanan | c41e68b | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 2842 | |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2843 | return false; |
| 2844 | } |
| 2845 | |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2846 | bool |
| 2847 | SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl, |
| 2848 | DWARFCompileUnit* cu, |
| 2849 | const DWARFDebugInfoEntry* die) |
| 2850 | { |
| 2851 | // No namespace specified, so the answesr i |
| 2852 | if (namespace_decl == NULL) |
| 2853 | return true; |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2854 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2855 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2856 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2857 | const DWARFDebugInfoEntry *decl_ctx_die = NULL; |
| 2858 | clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die); |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2859 | if (decl_ctx_die) |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2860 | { |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2861 | clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl(); |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2862 | |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2863 | if (clang_namespace_decl) |
| 2864 | { |
| 2865 | if (decl_ctx_die->Tag() != DW_TAG_namespace) |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2866 | { |
| 2867 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2868 | 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] | 2869 | return false; |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2870 | } |
| 2871 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2872 | if (clang_namespace_decl == die_clang_decl_ctx) |
| 2873 | return true; |
| 2874 | else |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2875 | return false; |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2876 | } |
| 2877 | else |
| 2878 | { |
| 2879 | // We have a namespace_decl that was not NULL but it contained |
| 2880 | // a NULL "clang::NamespaceDecl", so this means the global namespace |
| 2881 | // So as long the the contained decl context DIE isn't a namespace |
| 2882 | // we should be ok. |
| 2883 | if (decl_ctx_die->Tag() != DW_TAG_namespace) |
| 2884 | return true; |
| 2885 | } |
| 2886 | } |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2887 | |
| 2888 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2889 | 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] | 2890 | |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2891 | return false; |
| 2892 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2893 | uint32_t |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2894 | 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] | 2895 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2896 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2897 | |
| 2898 | if (log) |
| 2899 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2900 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2901 | "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)", |
| 2902 | name.GetCString(), |
| 2903 | namespace_decl, |
| 2904 | append, |
| 2905 | max_matches); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2906 | } |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2907 | |
| 2908 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) |
| 2909 | return 0; |
| 2910 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2911 | DWARFDebugInfo* info = DebugInfo(); |
| 2912 | if (info == NULL) |
| 2913 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2914 | |
| 2915 | // If we aren't appending the results to this list, then clear the list |
| 2916 | if (!append) |
| 2917 | variables.Clear(); |
| 2918 | |
| 2919 | // Remember how many variables are in the list before we search in case |
| 2920 | // we are appending the results to a variable list. |
| 2921 | const uint32_t original_size = variables.GetSize(); |
| 2922 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2923 | DIEArray die_offsets; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2924 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2925 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2926 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2927 | if (m_apple_names_ap.get()) |
| 2928 | { |
| 2929 | const char *name_cstr = name.GetCString(); |
| 2930 | const char *base_name_start; |
| 2931 | const char *base_name_end = NULL; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2932 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2933 | if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end)) |
| 2934 | base_name_start = name_cstr; |
| 2935 | |
| 2936 | m_apple_names_ap->FindByName (base_name_start, die_offsets); |
| 2937 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2938 | } |
| 2939 | else |
| 2940 | { |
| 2941 | // Index the DWARF if we haven't already |
| 2942 | if (!m_indexed) |
| 2943 | Index (); |
| 2944 | |
| 2945 | m_global_index.Find (name, die_offsets); |
| 2946 | } |
| 2947 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2948 | const size_t num_die_matches = die_offsets.size(); |
| 2949 | if (num_die_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2950 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2951 | SymbolContext sc; |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 2952 | sc.module_sp = m_obj_file->GetModule(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2953 | assert (sc.module_sp); |
| 2954 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2955 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2956 | DWARFCompileUnit* dwarf_cu = NULL; |
| 2957 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2958 | bool done = false; |
| 2959 | for (size_t i=0; i<num_die_matches && !done; ++i) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2960 | { |
| 2961 | const dw_offset_t die_offset = die_offsets[i]; |
| 2962 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2963 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2964 | if (die) |
| 2965 | { |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2966 | switch (die->Tag()) |
| 2967 | { |
| 2968 | default: |
| 2969 | case DW_TAG_subprogram: |
| 2970 | case DW_TAG_inlined_subroutine: |
| 2971 | case DW_TAG_try_block: |
| 2972 | case DW_TAG_catch_block: |
| 2973 | break; |
| 2974 | |
| 2975 | case DW_TAG_variable: |
| 2976 | { |
| 2977 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2978 | |
| 2979 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 2980 | continue; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2981 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2982 | ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2983 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2984 | if (variables.GetSize() - original_size >= max_matches) |
| 2985 | done = true; |
| 2986 | } |
| 2987 | break; |
| 2988 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2989 | } |
| 2990 | else |
| 2991 | { |
| 2992 | if (m_using_apple_tables) |
| 2993 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2994 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n", |
| 2995 | die_offset, name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2996 | } |
| 2997 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2998 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2999 | } |
| 3000 | |
| 3001 | // Return the number of variable that were appended to the list |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3002 | const uint32_t num_matches = variables.GetSize() - original_size; |
| 3003 | if (log && num_matches > 0) |
| 3004 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3005 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3006 | "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u", |
| 3007 | name.GetCString(), |
| 3008 | namespace_decl, |
| 3009 | append, |
| 3010 | max_matches, |
| 3011 | num_matches); |
| 3012 | } |
| 3013 | return num_matches; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3014 | } |
| 3015 | |
| 3016 | uint32_t |
| 3017 | SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables) |
| 3018 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3019 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3020 | |
| 3021 | if (log) |
| 3022 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3023 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3024 | "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)", |
| 3025 | regex.GetText(), |
| 3026 | append, |
| 3027 | max_matches); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3028 | } |
| 3029 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3030 | DWARFDebugInfo* info = DebugInfo(); |
| 3031 | if (info == NULL) |
| 3032 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3033 | |
| 3034 | // If we aren't appending the results to this list, then clear the list |
| 3035 | if (!append) |
| 3036 | variables.Clear(); |
| 3037 | |
| 3038 | // Remember how many variables are in the list before we search in case |
| 3039 | // we are appending the results to a variable list. |
| 3040 | const uint32_t original_size = variables.GetSize(); |
| 3041 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3042 | DIEArray die_offsets; |
| 3043 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3044 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3045 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3046 | if (m_apple_names_ap.get()) |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3047 | { |
| 3048 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 3049 | if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) |
| 3050 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| 3051 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3052 | } |
| 3053 | else |
| 3054 | { |
| 3055 | // Index the DWARF if we haven't already |
| 3056 | if (!m_indexed) |
| 3057 | Index (); |
| 3058 | |
| 3059 | m_global_index.Find (regex, die_offsets); |
| 3060 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3061 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3062 | SymbolContext sc; |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 3063 | sc.module_sp = m_obj_file->GetModule(); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3064 | assert (sc.module_sp); |
| 3065 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3066 | DWARFCompileUnit* dwarf_cu = NULL; |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3067 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3068 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3069 | if (num_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3070 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3071 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3072 | for (size_t i=0; i<num_matches; ++i) |
| 3073 | { |
| 3074 | const dw_offset_t die_offset = die_offsets[i]; |
| 3075 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3076 | |
| 3077 | if (die) |
| 3078 | { |
| 3079 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3080 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3081 | ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3082 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3083 | if (variables.GetSize() - original_size >= max_matches) |
| 3084 | break; |
| 3085 | } |
| 3086 | else |
| 3087 | { |
| 3088 | if (m_using_apple_tables) |
| 3089 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3090 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n", |
| 3091 | die_offset, regex.GetText()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3092 | } |
| 3093 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3094 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3095 | } |
| 3096 | |
| 3097 | // Return the number of variable that were appended to the list |
| 3098 | return variables.GetSize() - original_size; |
| 3099 | } |
| 3100 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3101 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3102 | bool |
| 3103 | SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset, |
| 3104 | DWARFCompileUnit *&dwarf_cu, |
| 3105 | SymbolContextList& sc_list) |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3106 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3107 | const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| 3108 | return ResolveFunction (dwarf_cu, die, sc_list); |
| 3109 | } |
| 3110 | |
| 3111 | |
| 3112 | bool |
| 3113 | SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu, |
| 3114 | const DWARFDebugInfoEntry *die, |
| 3115 | SymbolContextList& sc_list) |
| 3116 | { |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3117 | SymbolContext sc; |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3118 | |
| 3119 | if (die == NULL) |
| 3120 | return false; |
| 3121 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3122 | // If we were passed a die that is not a function, just return false... |
| 3123 | if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine) |
| 3124 | return false; |
| 3125 | |
| 3126 | const DWARFDebugInfoEntry* inlined_die = NULL; |
| 3127 | if (die->Tag() == DW_TAG_inlined_subroutine) |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3128 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3129 | inlined_die = die; |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3130 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3131 | while ((die = die->GetParent()) != NULL) |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3132 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3133 | if (die->Tag() == DW_TAG_subprogram) |
| 3134 | break; |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3135 | } |
| 3136 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3137 | assert (die->Tag() == DW_TAG_subprogram); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3138 | if (GetFunction (cu, die, sc)) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3139 | { |
| 3140 | Address addr; |
| 3141 | // Parse all blocks if needed |
| 3142 | if (inlined_die) |
| 3143 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 3144 | sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset())); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3145 | assert (sc.block != NULL); |
| 3146 | if (sc.block->GetStartAddress (addr) == false) |
| 3147 | addr.Clear(); |
| 3148 | } |
| 3149 | else |
| 3150 | { |
| 3151 | sc.block = NULL; |
| 3152 | addr = sc.function->GetAddressRange().GetBaseAddress(); |
| 3153 | } |
| 3154 | |
| 3155 | if (addr.IsValid()) |
| 3156 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3157 | sc_list.Append(sc); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3158 | return true; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3159 | } |
| 3160 | } |
| 3161 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3162 | return false; |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3163 | } |
| 3164 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3165 | void |
| 3166 | SymbolFileDWARF::FindFunctions (const ConstString &name, |
| 3167 | const NameToDIE &name_to_die, |
| 3168 | SymbolContextList& sc_list) |
| 3169 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3170 | DIEArray die_offsets; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3171 | if (name_to_die.Find (name, die_offsets)) |
| 3172 | { |
| 3173 | ParseFunctions (die_offsets, sc_list); |
| 3174 | } |
| 3175 | } |
| 3176 | |
| 3177 | |
| 3178 | void |
| 3179 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, |
| 3180 | const NameToDIE &name_to_die, |
| 3181 | SymbolContextList& sc_list) |
| 3182 | { |
| 3183 | DIEArray die_offsets; |
| 3184 | if (name_to_die.Find (regex, die_offsets)) |
| 3185 | { |
| 3186 | ParseFunctions (die_offsets, sc_list); |
| 3187 | } |
| 3188 | } |
| 3189 | |
| 3190 | |
| 3191 | void |
| 3192 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, |
| 3193 | const DWARFMappedHash::MemoryTable &memory_table, |
| 3194 | SymbolContextList& sc_list) |
| 3195 | { |
| 3196 | DIEArray die_offsets; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3197 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 3198 | if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3199 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3200 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3201 | ParseFunctions (die_offsets, sc_list); |
| 3202 | } |
| 3203 | } |
| 3204 | |
| 3205 | void |
| 3206 | SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets, |
| 3207 | SymbolContextList& sc_list) |
| 3208 | { |
| 3209 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3210 | if (num_matches) |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3211 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3212 | SymbolContext sc; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3213 | |
| 3214 | DWARFCompileUnit* dwarf_cu = NULL; |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3215 | for (size_t i=0; i<num_matches; ++i) |
| Greg Clayton | d7e0546 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 3216 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3217 | const dw_offset_t die_offset = die_offsets[i]; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3218 | ResolveFunction (die_offset, dwarf_cu, sc_list); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3219 | } |
| 3220 | } |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3221 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3222 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3223 | bool |
| 3224 | SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die, |
| 3225 | const DWARFCompileUnit *dwarf_cu, |
| 3226 | uint32_t name_type_mask, |
| 3227 | const char *partial_name, |
| 3228 | const char *base_name_start, |
| 3229 | const char *base_name_end) |
| 3230 | { |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3231 | // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes: |
| 3232 | if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3233 | { |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 3234 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset()); |
| 3235 | if (!containing_decl_ctx) |
| 3236 | return false; |
| 3237 | |
| 3238 | bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()); |
| 3239 | |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3240 | if (name_type_mask == eFunctionNameTypeMethod) |
| 3241 | { |
| 3242 | if (is_cxx_method == false) |
| 3243 | return false; |
| 3244 | } |
| 3245 | |
| 3246 | if (name_type_mask == eFunctionNameTypeBase) |
| 3247 | { |
| 3248 | if (is_cxx_method == true) |
| 3249 | return false; |
| 3250 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3251 | } |
| 3252 | |
| 3253 | // Now we need to check whether the name we got back for this type matches the extra specifications |
| 3254 | // that were in the name we're looking up: |
| 3255 | if (base_name_start != partial_name || *base_name_end != '\0') |
| 3256 | { |
| 3257 | // First see if the stuff to the left matches the full name. To do that let's see if |
| 3258 | // we can pull out the mips linkage name attribute: |
| 3259 | |
| 3260 | Mangled best_name; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3261 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3262 | DWARFFormValue form_value; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3263 | die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| 3264 | uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name); |
| Greg Clayton | 7141554 | 2012-12-08 00:24:40 +0000 | [diff] [blame] | 3265 | if (idx == UINT32_MAX) |
| 3266 | idx = attributes.FindAttributeIndex(DW_AT_linkage_name); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3267 | if (idx != UINT32_MAX) |
| 3268 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3269 | if (attributes.ExtractFormValueAtIndex(this, idx, form_value)) |
| 3270 | { |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3271 | const char *mangled_name = form_value.AsCString(&get_debug_str_data()); |
| 3272 | if (mangled_name) |
| 3273 | best_name.SetValue (ConstString(mangled_name), true); |
| 3274 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3275 | } |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3276 | |
| 3277 | if (!best_name) |
| 3278 | { |
| 3279 | idx = attributes.FindAttributeIndex(DW_AT_name); |
| 3280 | if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value)) |
| 3281 | { |
| 3282 | const char *name = form_value.AsCString(&get_debug_str_data()); |
| 3283 | best_name.SetValue (ConstString(name), false); |
| 3284 | } |
| 3285 | } |
| 3286 | |
| 3287 | if (best_name.GetDemangledName()) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3288 | { |
| 3289 | const char *demangled = best_name.GetDemangledName().GetCString(); |
| 3290 | if (demangled) |
| 3291 | { |
| 3292 | std::string name_no_parens(partial_name, base_name_end - partial_name); |
| Jim Ingham | 85c13d7 | 2012-03-02 02:24:42 +0000 | [diff] [blame] | 3293 | const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str()); |
| 3294 | if (partial_in_demangled == NULL) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3295 | return false; |
| Jim Ingham | 85c13d7 | 2012-03-02 02:24:42 +0000 | [diff] [blame] | 3296 | else |
| 3297 | { |
| 3298 | // Sort out the case where our name is something like "Process::Destroy" and the match is |
| 3299 | // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on |
| 3300 | // namespace boundaries... |
| 3301 | |
| 3302 | if (partial_name[0] == ':' && partial_name[1] == ':') |
| 3303 | { |
| 3304 | // The partial name was already on a namespace boundary so all matches are good. |
| 3305 | return true; |
| 3306 | } |
| 3307 | else if (partial_in_demangled == demangled) |
| 3308 | { |
| 3309 | // They both start the same, so this is an good match. |
| 3310 | return true; |
| 3311 | } |
| 3312 | else |
| 3313 | { |
| 3314 | if (partial_in_demangled - demangled == 1) |
| 3315 | { |
| 3316 | // Only one character difference, can't be a namespace boundary... |
| 3317 | return false; |
| 3318 | } |
| 3319 | else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':') |
| 3320 | { |
| 3321 | // We are on a namespace boundary, so this is also good. |
| 3322 | return true; |
| 3323 | } |
| 3324 | else |
| 3325 | return false; |
| 3326 | } |
| 3327 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3328 | } |
| 3329 | } |
| 3330 | } |
| 3331 | |
| 3332 | return true; |
| 3333 | } |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3334 | |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3335 | uint32_t |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3336 | SymbolFileDWARF::FindFunctions (const ConstString &name, |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3337 | const lldb_private::ClangNamespaceDecl *namespace_decl, |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3338 | uint32_t name_type_mask, |
| 3339 | bool include_inlines, |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3340 | bool append, |
| 3341 | SymbolContextList& sc_list) |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3342 | { |
| 3343 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 3344 | "SymbolFileDWARF::FindFunctions (name = '%s')", |
| 3345 | name.AsCString()); |
| 3346 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3347 | // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup() |
| 3348 | assert ((name_type_mask & eFunctionNameTypeAuto) == 0); |
| 3349 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3350 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3351 | |
| 3352 | if (log) |
| 3353 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3354 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3355 | "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)", |
| 3356 | name.GetCString(), |
| 3357 | name_type_mask, |
| 3358 | append); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3359 | } |
| 3360 | |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3361 | // If we aren't appending the results to this list, then clear the list |
| 3362 | if (!append) |
| 3363 | sc_list.Clear(); |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3364 | |
| 3365 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) |
| 3366 | return 0; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3367 | |
| 3368 | // If name is empty then we won't find anything. |
| 3369 | if (name.IsEmpty()) |
| 3370 | return 0; |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3371 | |
| 3372 | // Remember how many sc_list are in the list before we search in case |
| 3373 | // we are appending the results to a variable list. |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3374 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3375 | const char *name_cstr = name.GetCString(); |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3376 | |
| 3377 | const uint32_t original_size = sc_list.GetSize(); |
| 3378 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3379 | DWARFDebugInfo* info = DebugInfo(); |
| 3380 | if (info == NULL) |
| 3381 | return 0; |
| 3382 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3383 | DWARFCompileUnit *dwarf_cu = NULL; |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3384 | std::set<const DWARFDebugInfoEntry *> resolved_dies; |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3385 | if (m_using_apple_tables) |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 3386 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3387 | if (m_apple_names_ap.get()) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3388 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3389 | |
| 3390 | DIEArray die_offsets; |
| 3391 | |
| 3392 | uint32_t num_matches = 0; |
| 3393 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3394 | if (name_type_mask & eFunctionNameTypeFull) |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3395 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3396 | // If they asked for the full name, match what they typed. At some point we may |
| 3397 | // want to canonicalize this (strip double spaces, etc. For now, we just add all the |
| 3398 | // dies that we find by exact match. |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3399 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3400 | for (uint32_t i = 0; i < num_matches; i++) |
| 3401 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3402 | const dw_offset_t die_offset = die_offsets[i]; |
| 3403 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3404 | if (die) |
| 3405 | { |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3406 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3407 | continue; |
| 3408 | |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3409 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) |
| 3410 | continue; |
| 3411 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3412 | if (resolved_dies.find(die) == resolved_dies.end()) |
| 3413 | { |
| 3414 | if (ResolveFunction (dwarf_cu, die, sc_list)) |
| 3415 | resolved_dies.insert(die); |
| 3416 | } |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3417 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3418 | else |
| 3419 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3420 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 3421 | die_offset, name_cstr); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3422 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3423 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3424 | } |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3425 | |
| 3426 | if (name_type_mask & eFunctionNameTypeSelector) |
| 3427 | { |
| 3428 | if (namespace_decl && *namespace_decl) |
| 3429 | return 0; // no selectors in namespaces |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3430 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3431 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); |
| 3432 | // Now make sure these are actually ObjC methods. In this case we can simply look up the name, |
| 3433 | // and if it is an ObjC method name, we're good. |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3434 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3435 | for (uint32_t i = 0; i < num_matches; i++) |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3436 | { |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3437 | const dw_offset_t die_offset = die_offsets[i]; |
| 3438 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| 3439 | if (die) |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3440 | { |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3441 | const char *die_name = die->GetName(this, dwarf_cu); |
| 3442 | if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name)) |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3443 | { |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3444 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) |
| 3445 | continue; |
| 3446 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3447 | if (resolved_dies.find(die) == resolved_dies.end()) |
| 3448 | { |
| 3449 | if (ResolveFunction (dwarf_cu, die, sc_list)) |
| 3450 | resolved_dies.insert(die); |
| 3451 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3452 | } |
| 3453 | } |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3454 | else |
| 3455 | { |
| 3456 | GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 3457 | die_offset, name_cstr); |
| 3458 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3459 | } |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3460 | die_offsets.clear(); |
| 3461 | } |
| 3462 | |
| 3463 | if (((name_type_mask & eFunctionNameTypeMethod) && !namespace_decl) || name_type_mask & eFunctionNameTypeBase) |
| 3464 | { |
| 3465 | // The apple_names table stores just the "base name" of C++ methods in the table. So we have to |
| 3466 | // extract the base name, look that up, and if there is any other information in the name we were |
| 3467 | // passed in we have to post-filter based on that. |
| 3468 | |
| 3469 | // FIXME: Arrange the logic above so that we don't calculate the base name twice: |
| 3470 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); |
| 3471 | |
| 3472 | for (uint32_t i = 0; i < num_matches; i++) |
| 3473 | { |
| 3474 | const dw_offset_t die_offset = die_offsets[i]; |
| 3475 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| 3476 | if (die) |
| 3477 | { |
| 3478 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) |
| 3479 | continue; |
| 3480 | |
| 3481 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3482 | continue; |
| 3483 | |
| 3484 | // If we get to here, the die is good, and we should add it: |
| 3485 | if (resolved_dies.find(die) == resolved_dies.end()) |
| 3486 | if (ResolveFunction (dwarf_cu, die, sc_list)) |
| 3487 | { |
| 3488 | bool keep_die = true; |
| 3489 | if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod)) |
| 3490 | { |
| 3491 | // We are looking for either basenames or methods, so we need to |
| 3492 | // trim out the ones we won't want by looking at the type |
| 3493 | SymbolContext sc; |
| 3494 | if (sc_list.GetLastContext(sc)) |
| 3495 | { |
| 3496 | if (sc.block) |
| 3497 | { |
| 3498 | // We have an inlined function |
| 3499 | } |
| 3500 | else if (sc.function) |
| 3501 | { |
| 3502 | Type *type = sc.function->GetType(); |
| 3503 | |
| 3504 | clang::DeclContext* decl_ctx = GetClangDeclContextContainingTypeUID (type->GetID()); |
| 3505 | if (decl_ctx->isRecord()) |
| 3506 | { |
| 3507 | if (name_type_mask & eFunctionNameTypeBase) |
| 3508 | { |
| 3509 | sc_list.RemoveContextAtIndex(sc_list.GetSize()-1); |
| 3510 | keep_die = false; |
| 3511 | } |
| 3512 | } |
| 3513 | else |
| 3514 | { |
| 3515 | if (name_type_mask & eFunctionNameTypeMethod) |
| 3516 | { |
| 3517 | sc_list.RemoveContextAtIndex(sc_list.GetSize()-1); |
| 3518 | keep_die = false; |
| 3519 | } |
| 3520 | } |
| 3521 | } |
| 3522 | } |
| 3523 | } |
| 3524 | if (keep_die) |
| 3525 | resolved_dies.insert(die); |
| 3526 | } |
| 3527 | } |
| 3528 | else |
| 3529 | { |
| 3530 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 3531 | die_offset, name_cstr); |
| 3532 | } |
| 3533 | } |
| 3534 | die_offsets.clear(); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3535 | } |
| 3536 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3537 | } |
| 3538 | else |
| 3539 | { |
| 3540 | |
| 3541 | // Index the DWARF if we haven't already |
| 3542 | if (!m_indexed) |
| 3543 | Index (); |
| 3544 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3545 | if (name_type_mask & eFunctionNameTypeFull) |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 3546 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3547 | FindFunctions (name, m_function_fullname_index, sc_list); |
| 3548 | |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 3549 | // Temporary workaround for global/anonymous namespace functions on linux |
| 3550 | #if defined (__linux__) |
| 3551 | // If we didn't find any functions in the global namespace try |
| 3552 | // looking in the basename index but ignore any returned |
| 3553 | // functions that have a namespace (ie. mangled names starting with |
| 3554 | // '_ZN') but keep functions which have an anonymous namespace |
| 3555 | if (sc_list.GetSize() == 0) |
| 3556 | { |
| 3557 | SymbolContextList temp_sc_list; |
| 3558 | FindFunctions (name, m_function_basename_index, temp_sc_list); |
| 3559 | if (!namespace_decl) |
| 3560 | { |
| 3561 | SymbolContext sc; |
| 3562 | for (uint32_t i = 0; i < temp_sc_list.GetSize(); i++) |
| 3563 | { |
| 3564 | if (temp_sc_list.GetContextAtIndex(i, sc)) |
| 3565 | { |
| Matt Kopec | a189d49 | 2013-05-10 22:55:24 +0000 | [diff] [blame] | 3566 | ConstString mangled_name = sc.GetFunctionName(Mangled::ePreferMangled); |
| 3567 | ConstString demangled_name = sc.GetFunctionName(Mangled::ePreferDemangled); |
| Matt Kopec | 04e5d58 | 2013-05-14 19:00:41 +0000 | [diff] [blame] | 3568 | if (strncmp(mangled_name.GetCString(), "_ZN", 3) || |
| 3569 | !strncmp(demangled_name.GetCString(), "(anonymous namespace)", 21)) |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 3570 | { |
| 3571 | sc_list.Append(sc); |
| 3572 | } |
| 3573 | } |
| 3574 | } |
| 3575 | } |
| 3576 | } |
| 3577 | #endif |
| 3578 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3579 | DIEArray die_offsets; |
| 3580 | DWARFCompileUnit *dwarf_cu = NULL; |
| 3581 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3582 | if (name_type_mask & eFunctionNameTypeBase) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3583 | { |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3584 | uint32_t num_base = m_function_basename_index.Find(name, die_offsets); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3585 | for (uint32_t i = 0; i < num_base; i++) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3586 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3587 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); |
| 3588 | if (die) |
| 3589 | { |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3590 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) |
| 3591 | continue; |
| 3592 | |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3593 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3594 | continue; |
| 3595 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3596 | // 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] | 3597 | if (resolved_dies.find(die) == resolved_dies.end()) |
| 3598 | { |
| 3599 | if (ResolveFunction (dwarf_cu, die, sc_list)) |
| 3600 | resolved_dies.insert(die); |
| 3601 | } |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3602 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3603 | } |
| 3604 | die_offsets.clear(); |
| 3605 | } |
| 3606 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3607 | if (name_type_mask & eFunctionNameTypeMethod) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3608 | { |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3609 | if (namespace_decl && *namespace_decl) |
| 3610 | return 0; // no methods in namespaces |
| 3611 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3612 | uint32_t num_base = m_function_method_index.Find(name, die_offsets); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3613 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3614 | for (uint32_t i = 0; i < num_base; i++) |
| 3615 | { |
| 3616 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); |
| 3617 | if (die) |
| 3618 | { |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 3619 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) |
| 3620 | continue; |
| 3621 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3622 | // 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] | 3623 | if (resolved_dies.find(die) == resolved_dies.end()) |
| 3624 | { |
| 3625 | if (ResolveFunction (dwarf_cu, die, sc_list)) |
| 3626 | resolved_dies.insert(die); |
| 3627 | } |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3628 | } |
| 3629 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3630 | } |
| 3631 | die_offsets.clear(); |
| 3632 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3633 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 3634 | if ((name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl)) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3635 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3636 | FindFunctions (name, m_function_selector_index, sc_list); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3637 | } |
| 3638 | |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 3639 | } |
| 3640 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3641 | // Return the number of variable that were appended to the list |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3642 | const uint32_t num_matches = sc_list.GetSize() - original_size; |
| 3643 | |
| 3644 | if (log && num_matches > 0) |
| 3645 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3646 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3647 | "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list) => %u", |
| 3648 | name.GetCString(), |
| 3649 | name_type_mask, |
| 3650 | append, |
| 3651 | num_matches); |
| 3652 | } |
| 3653 | return num_matches; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3654 | } |
| 3655 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3656 | uint32_t |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3657 | 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] | 3658 | { |
| 3659 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 3660 | "SymbolFileDWARF::FindFunctions (regex = '%s')", |
| 3661 | regex.GetText()); |
| 3662 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3663 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3664 | |
| 3665 | if (log) |
| 3666 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3667 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3668 | "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)", |
| 3669 | regex.GetText(), |
| 3670 | append); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3671 | } |
| 3672 | |
| 3673 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3674 | // If we aren't appending the results to this list, then clear the list |
| 3675 | if (!append) |
| 3676 | sc_list.Clear(); |
| 3677 | |
| 3678 | // Remember how many sc_list are in the list before we search in case |
| 3679 | // we are appending the results to a variable list. |
| 3680 | uint32_t original_size = sc_list.GetSize(); |
| 3681 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3682 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3683 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3684 | if (m_apple_names_ap.get()) |
| 3685 | FindFunctions (regex, *m_apple_names_ap, sc_list); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3686 | } |
| 3687 | else |
| 3688 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3689 | // Index the DWARF if we haven't already |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3690 | if (!m_indexed) |
| 3691 | Index (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3692 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3693 | FindFunctions (regex, m_function_basename_index, sc_list); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3694 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3695 | FindFunctions (regex, m_function_fullname_index, sc_list); |
| 3696 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3697 | |
| 3698 | // Return the number of variable that were appended to the list |
| 3699 | return sc_list.GetSize() - original_size; |
| 3700 | } |
| Jim Ingham | 318c9f2 | 2011-08-26 19:44:13 +0000 | [diff] [blame] | 3701 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3702 | uint32_t |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3703 | SymbolFileDWARF::FindTypes (const SymbolContext& sc, |
| 3704 | const ConstString &name, |
| 3705 | const lldb_private::ClangNamespaceDecl *namespace_decl, |
| 3706 | bool append, |
| 3707 | uint32_t max_matches, |
| 3708 | TypeList& types) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3709 | { |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3710 | DWARFDebugInfo* info = DebugInfo(); |
| 3711 | if (info == NULL) |
| 3712 | return 0; |
| 3713 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3714 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3715 | |
| 3716 | if (log) |
| 3717 | { |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3718 | if (namespace_decl) |
| 3719 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3720 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3721 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)", |
| 3722 | name.GetCString(), |
| 3723 | namespace_decl->GetNamespaceDecl(), |
| 3724 | namespace_decl->GetQualifiedName().c_str(), |
| 3725 | append, |
| 3726 | max_matches); |
| 3727 | } |
| 3728 | else |
| 3729 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3730 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3731 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)", |
| 3732 | name.GetCString(), |
| 3733 | append, |
| 3734 | max_matches); |
| 3735 | } |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3736 | } |
| 3737 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3738 | // If we aren't appending the results to this list, then clear the list |
| 3739 | if (!append) |
| 3740 | types.Clear(); |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3741 | |
| 3742 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) |
| 3743 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3744 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3745 | DIEArray die_offsets; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3746 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3747 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3748 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3749 | if (m_apple_types_ap.get()) |
| 3750 | { |
| 3751 | const char *name_cstr = name.GetCString(); |
| 3752 | m_apple_types_ap->FindByName (name_cstr, die_offsets); |
| 3753 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3754 | } |
| 3755 | else |
| 3756 | { |
| 3757 | if (!m_indexed) |
| 3758 | Index (); |
| 3759 | |
| 3760 | m_type_index.Find (name, die_offsets); |
| 3761 | } |
| 3762 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3763 | const size_t num_die_matches = die_offsets.size(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3764 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3765 | if (num_die_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3766 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3767 | const uint32_t initial_types_size = types.GetSize(); |
| 3768 | DWARFCompileUnit* dwarf_cu = NULL; |
| 3769 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3770 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3771 | for (size_t i=0; i<num_die_matches; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3772 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3773 | const dw_offset_t die_offset = die_offsets[i]; |
| 3774 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| 3775 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3776 | if (die) |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 3777 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3778 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3779 | continue; |
| 3780 | |
| 3781 | Type *matching_type = ResolveType (dwarf_cu, die); |
| 3782 | if (matching_type) |
| 3783 | { |
| 3784 | // 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] | 3785 | types.InsertUnique (matching_type->shared_from_this()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3786 | if (types.GetSize() >= max_matches) |
| 3787 | break; |
| 3788 | } |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 3789 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3790 | else |
| 3791 | { |
| 3792 | if (m_using_apple_tables) |
| 3793 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3794 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 3795 | die_offset, name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3796 | } |
| 3797 | } |
| 3798 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3799 | } |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3800 | const uint32_t num_matches = types.GetSize() - initial_types_size; |
| 3801 | if (log && num_matches) |
| 3802 | { |
| 3803 | if (namespace_decl) |
| 3804 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3805 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3806 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u", |
| 3807 | name.GetCString(), |
| 3808 | namespace_decl->GetNamespaceDecl(), |
| 3809 | namespace_decl->GetQualifiedName().c_str(), |
| 3810 | append, |
| 3811 | max_matches, |
| 3812 | num_matches); |
| 3813 | } |
| 3814 | else |
| 3815 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3816 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3817 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u", |
| 3818 | name.GetCString(), |
| 3819 | append, |
| 3820 | max_matches, |
| 3821 | num_matches); |
| 3822 | } |
| 3823 | } |
| 3824 | return num_matches; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3825 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3826 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3827 | } |
| 3828 | |
| 3829 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3830 | ClangNamespaceDecl |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3831 | SymbolFileDWARF::FindNamespace (const SymbolContext& sc, |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3832 | const ConstString &name, |
| 3833 | const lldb_private::ClangNamespaceDecl *parent_namespace_decl) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3834 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3835 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3836 | |
| 3837 | if (log) |
| 3838 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3839 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3840 | "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")", |
| 3841 | name.GetCString()); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3842 | } |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3843 | |
| 3844 | if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl)) |
| 3845 | return ClangNamespaceDecl(); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3846 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3847 | ClangNamespaceDecl namespace_decl; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3848 | DWARFDebugInfo* info = DebugInfo(); |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3849 | if (info) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3850 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3851 | DIEArray die_offsets; |
| 3852 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3853 | // Index if we already haven't to make sure the compile units |
| 3854 | // get indexed and make their global DIE index list |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3855 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3856 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3857 | if (m_apple_namespaces_ap.get()) |
| 3858 | { |
| 3859 | const char *name_cstr = name.GetCString(); |
| 3860 | m_apple_namespaces_ap->FindByName (name_cstr, die_offsets); |
| 3861 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3862 | } |
| 3863 | else |
| 3864 | { |
| 3865 | if (!m_indexed) |
| 3866 | Index (); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3867 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3868 | m_namespace_index.Find (name, die_offsets); |
| 3869 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3870 | |
| 3871 | DWARFCompileUnit* dwarf_cu = NULL; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3872 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3873 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3874 | if (num_matches) |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3875 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3876 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3877 | for (size_t i=0; i<num_matches; ++i) |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3878 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3879 | const dw_offset_t die_offset = die_offsets[i]; |
| 3880 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3881 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3882 | if (die) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3883 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3884 | if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die)) |
| 3885 | continue; |
| 3886 | |
| 3887 | clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die); |
| 3888 | if (clang_namespace_decl) |
| 3889 | { |
| 3890 | namespace_decl.SetASTContext (GetClangASTContext().getASTContext()); |
| 3891 | namespace_decl.SetNamespaceDecl (clang_namespace_decl); |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3892 | break; |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3893 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3894 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3895 | else |
| 3896 | { |
| 3897 | if (m_using_apple_tables) |
| 3898 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3899 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n", |
| 3900 | die_offset, name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3901 | } |
| 3902 | } |
| 3903 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3904 | } |
| 3905 | } |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3906 | } |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3907 | if (log && namespace_decl.GetNamespaceDecl()) |
| 3908 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3909 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3910 | "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"", |
| 3911 | name.GetCString(), |
| 3912 | namespace_decl.GetNamespaceDecl(), |
| 3913 | namespace_decl.GetQualifiedName().c_str()); |
| 3914 | } |
| 3915 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3916 | return namespace_decl; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3917 | } |
| 3918 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3919 | uint32_t |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3920 | 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] | 3921 | { |
| 3922 | // Remember how many sc_list are in the list before we search in case |
| 3923 | // we are appending the results to a variable list. |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3924 | uint32_t original_size = types.GetSize(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3925 | |
| 3926 | const uint32_t num_die_offsets = die_offsets.size(); |
| 3927 | // Parse all of the types we found from the pubtypes matches |
| 3928 | uint32_t i; |
| 3929 | uint32_t num_matches = 0; |
| 3930 | for (i = 0; i < num_die_offsets; ++i) |
| 3931 | { |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3932 | Type *matching_type = ResolveTypeUID (die_offsets[i]); |
| 3933 | if (matching_type) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3934 | { |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3935 | // 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] | 3936 | types.InsertUnique (matching_type->shared_from_this()); |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3937 | ++num_matches; |
| 3938 | if (num_matches >= max_matches) |
| 3939 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3940 | } |
| 3941 | } |
| 3942 | |
| 3943 | // Return the number of variable that were appended to the list |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3944 | return types.GetSize() - original_size; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3945 | } |
| 3946 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3947 | |
| 3948 | size_t |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3949 | SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc, |
| 3950 | clang::DeclContext *containing_decl_ctx, |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3951 | DWARFCompileUnit* dwarf_cu, |
| 3952 | const DWARFDebugInfoEntry *parent_die, |
| 3953 | bool skip_artificial, |
| 3954 | bool &is_static, |
| 3955 | TypeList* type_list, |
| 3956 | std::vector<clang_type_t>& function_param_types, |
| 3957 | std::vector<clang::ParmVarDecl*>& function_param_decls, |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 3958 | unsigned &type_quals, |
| 3959 | ClangASTContext::TemplateParameterInfos &template_param_infos) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3960 | { |
| 3961 | if (parent_die == NULL) |
| 3962 | return 0; |
| 3963 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3964 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| 3965 | |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3966 | size_t arg_idx = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3967 | const DWARFDebugInfoEntry *die; |
| 3968 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 3969 | { |
| 3970 | dw_tag_t tag = die->Tag(); |
| 3971 | switch (tag) |
| 3972 | { |
| 3973 | case DW_TAG_formal_parameter: |
| 3974 | { |
| 3975 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3976 | 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] | 3977 | if (num_attributes > 0) |
| 3978 | { |
| 3979 | const char *name = NULL; |
| 3980 | Declaration decl; |
| 3981 | dw_offset_t param_type_die_offset = DW_INVALID_OFFSET; |
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 3982 | bool is_artificial = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3983 | // one of None, Auto, Register, Extern, Static, PrivateExtern |
| 3984 | |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 3985 | clang::StorageClass storage = clang::SC_None; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3986 | uint32_t i; |
| 3987 | for (i=0; i<num_attributes; ++i) |
| 3988 | { |
| 3989 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 3990 | DWARFFormValue form_value; |
| 3991 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 3992 | { |
| 3993 | switch (attr) |
| 3994 | { |
| 3995 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 3996 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 3997 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 3998 | case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; |
| 3999 | case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break; |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 4000 | case DW_AT_artificial: is_artificial = form_value.Boolean(); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4001 | case DW_AT_location: |
| 4002 | // if (form_value.BlockData()) |
| 4003 | // { |
| 4004 | // const DataExtractor& debug_info_data = debug_info(); |
| 4005 | // uint32_t block_length = form_value.Unsigned(); |
| 4006 | // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length); |
| 4007 | // } |
| 4008 | // else |
| 4009 | // { |
| 4010 | // } |
| 4011 | // break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4012 | case DW_AT_const_value: |
| 4013 | case DW_AT_default_value: |
| 4014 | case DW_AT_description: |
| 4015 | case DW_AT_endianity: |
| 4016 | case DW_AT_is_optional: |
| 4017 | case DW_AT_segment: |
| 4018 | case DW_AT_variable_parameter: |
| 4019 | default: |
| 4020 | case DW_AT_abstract_origin: |
| 4021 | case DW_AT_sibling: |
| 4022 | break; |
| 4023 | } |
| 4024 | } |
| 4025 | } |
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 4026 | |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4027 | bool skip = false; |
| 4028 | if (skip_artificial) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4029 | { |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4030 | if (is_artificial) |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4031 | { |
| 4032 | // In order to determine if a C++ member function is |
| 4033 | // "const" we have to look at the const-ness of "this"... |
| 4034 | // Ugly, but that |
| 4035 | if (arg_idx == 0) |
| 4036 | { |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 4037 | if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind())) |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 4038 | { |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4039 | // Often times compilers omit the "this" name for the |
| 4040 | // specification DIEs, so we can't rely upon the name |
| 4041 | // being in the formal parameter DIE... |
| 4042 | if (name == NULL || ::strcmp(name, "this")==0) |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4043 | { |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 4044 | Type *this_type = ResolveTypeUID (param_type_die_offset); |
| 4045 | if (this_type) |
| 4046 | { |
| 4047 | uint32_t encoding_mask = this_type->GetEncodingMask(); |
| 4048 | if (encoding_mask & Type::eEncodingIsPointerUID) |
| 4049 | { |
| 4050 | is_static = false; |
| 4051 | |
| 4052 | if (encoding_mask & (1u << Type::eEncodingIsConstUID)) |
| 4053 | type_quals |= clang::Qualifiers::Const; |
| 4054 | if (encoding_mask & (1u << Type::eEncodingIsVolatileUID)) |
| 4055 | type_quals |= clang::Qualifiers::Volatile; |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4056 | } |
| 4057 | } |
| 4058 | } |
| 4059 | } |
| 4060 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4061 | skip = true; |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4062 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4063 | else |
| 4064 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4065 | |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4066 | // HACK: Objective C formal parameters "self" and "_cmd" |
| 4067 | // are not marked as artificial in the DWARF... |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4068 | CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| 4069 | if (comp_unit) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4070 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4071 | switch (comp_unit->GetLanguage()) |
| 4072 | { |
| 4073 | case eLanguageTypeObjC: |
| 4074 | case eLanguageTypeObjC_plus_plus: |
| 4075 | if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0)) |
| 4076 | skip = true; |
| 4077 | break; |
| 4078 | default: |
| 4079 | break; |
| 4080 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4081 | } |
| 4082 | } |
| 4083 | } |
| 4084 | |
| 4085 | if (!skip) |
| 4086 | { |
| 4087 | Type *type = ResolveTypeUID(param_type_die_offset); |
| 4088 | if (type) |
| 4089 | { |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 4090 | function_param_types.push_back (type->GetClangForwardType()); |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4091 | |
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 4092 | clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name, |
| 4093 | type->GetClangForwardType(), |
| 4094 | storage); |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4095 | assert(param_var_decl); |
| 4096 | function_param_decls.push_back(param_var_decl); |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 4097 | |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 4098 | GetClangASTContext().SetMetadataAsUserID (param_var_decl, MakeUserID(die->GetOffset())); |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4099 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4100 | } |
| 4101 | } |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4102 | arg_idx++; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4103 | } |
| 4104 | break; |
| 4105 | |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 4106 | case DW_TAG_template_type_parameter: |
| 4107 | case DW_TAG_template_value_parameter: |
| 4108 | ParseTemplateDIE (dwarf_cu, die,template_param_infos); |
| 4109 | break; |
| 4110 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4111 | default: |
| 4112 | break; |
| 4113 | } |
| 4114 | } |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 4115 | return arg_idx; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4116 | } |
| 4117 | |
| 4118 | size_t |
| 4119 | SymbolFileDWARF::ParseChildEnumerators |
| 4120 | ( |
| 4121 | const SymbolContext& sc, |
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 4122 | clang_type_t enumerator_clang_type, |
| 4123 | bool is_signed, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4124 | uint32_t enumerator_byte_size, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4125 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4126 | const DWARFDebugInfoEntry *parent_die |
| 4127 | ) |
| 4128 | { |
| 4129 | if (parent_die == NULL) |
| 4130 | return 0; |
| 4131 | |
| 4132 | size_t enumerators_added = 0; |
| 4133 | const DWARFDebugInfoEntry *die; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4134 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| 4135 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4136 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 4137 | { |
| 4138 | const dw_tag_t tag = die->Tag(); |
| 4139 | if (tag == DW_TAG_enumerator) |
| 4140 | { |
| 4141 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4142 | 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] | 4143 | if (num_child_attributes > 0) |
| 4144 | { |
| 4145 | const char *name = NULL; |
| 4146 | bool got_value = false; |
| 4147 | int64_t enum_value = 0; |
| 4148 | Declaration decl; |
| 4149 | |
| 4150 | uint32_t i; |
| 4151 | for (i=0; i<num_child_attributes; ++i) |
| 4152 | { |
| 4153 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 4154 | DWARFFormValue form_value; |
| 4155 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 4156 | { |
| 4157 | switch (attr) |
| 4158 | { |
| 4159 | case DW_AT_const_value: |
| 4160 | got_value = true; |
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 4161 | if (is_signed) |
| 4162 | enum_value = form_value.Signed(); |
| 4163 | else |
| 4164 | enum_value = form_value.Unsigned(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4165 | break; |
| 4166 | |
| 4167 | case DW_AT_name: |
| 4168 | name = form_value.AsCString(&get_debug_str_data()); |
| 4169 | break; |
| 4170 | |
| 4171 | case DW_AT_description: |
| 4172 | default: |
| 4173 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 4174 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 4175 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 4176 | case DW_AT_sibling: |
| 4177 | break; |
| 4178 | } |
| 4179 | } |
| 4180 | } |
| 4181 | |
| 4182 | if (name && name[0] && got_value) |
| 4183 | { |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 4184 | GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type, |
| 4185 | enumerator_clang_type, |
| 4186 | decl, |
| 4187 | name, |
| 4188 | enum_value, |
| 4189 | enumerator_byte_size * 8); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4190 | ++enumerators_added; |
| 4191 | } |
| 4192 | } |
| 4193 | } |
| 4194 | } |
| 4195 | return enumerators_added; |
| 4196 | } |
| 4197 | |
| 4198 | void |
| 4199 | SymbolFileDWARF::ParseChildArrayInfo |
| 4200 | ( |
| 4201 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4202 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4203 | const DWARFDebugInfoEntry *parent_die, |
| 4204 | int64_t& first_index, |
| 4205 | std::vector<uint64_t>& element_orders, |
| 4206 | uint32_t& byte_stride, |
| 4207 | uint32_t& bit_stride |
| 4208 | ) |
| 4209 | { |
| 4210 | if (parent_die == NULL) |
| 4211 | return; |
| 4212 | |
| 4213 | const DWARFDebugInfoEntry *die; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4214 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4215 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 4216 | { |
| 4217 | const dw_tag_t tag = die->Tag(); |
| 4218 | switch (tag) |
| 4219 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4220 | case DW_TAG_subrange_type: |
| 4221 | { |
| 4222 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4223 | 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] | 4224 | if (num_child_attributes > 0) |
| 4225 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4226 | uint64_t num_elements = 0; |
| 4227 | uint64_t lower_bound = 0; |
| 4228 | uint64_t upper_bound = 0; |
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4229 | bool upper_bound_valid = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4230 | uint32_t i; |
| 4231 | for (i=0; i<num_child_attributes; ++i) |
| 4232 | { |
| 4233 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 4234 | DWARFFormValue form_value; |
| 4235 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 4236 | { |
| 4237 | switch (attr) |
| 4238 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4239 | case DW_AT_name: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4240 | break; |
| 4241 | |
| 4242 | case DW_AT_count: |
| 4243 | num_elements = form_value.Unsigned(); |
| 4244 | break; |
| 4245 | |
| 4246 | case DW_AT_bit_stride: |
| 4247 | bit_stride = form_value.Unsigned(); |
| 4248 | break; |
| 4249 | |
| 4250 | case DW_AT_byte_stride: |
| 4251 | byte_stride = form_value.Unsigned(); |
| 4252 | break; |
| 4253 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4254 | case DW_AT_lower_bound: |
| 4255 | lower_bound = form_value.Unsigned(); |
| 4256 | break; |
| 4257 | |
| 4258 | case DW_AT_upper_bound: |
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4259 | upper_bound_valid = true; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4260 | upper_bound = form_value.Unsigned(); |
| 4261 | break; |
| 4262 | |
| 4263 | default: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4264 | case DW_AT_abstract_origin: |
| 4265 | case DW_AT_accessibility: |
| 4266 | case DW_AT_allocated: |
| 4267 | case DW_AT_associated: |
| 4268 | case DW_AT_data_location: |
| 4269 | case DW_AT_declaration: |
| 4270 | case DW_AT_description: |
| 4271 | case DW_AT_sibling: |
| 4272 | case DW_AT_threads_scaled: |
| 4273 | case DW_AT_type: |
| 4274 | case DW_AT_visibility: |
| 4275 | break; |
| 4276 | } |
| 4277 | } |
| 4278 | } |
| 4279 | |
| Greg Clayton | e6a0779 | 2012-12-05 21:59:39 +0000 | [diff] [blame] | 4280 | if (num_elements == 0) |
| 4281 | { |
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4282 | if (upper_bound_valid && upper_bound >= lower_bound) |
| Greg Clayton | e6a0779 | 2012-12-05 21:59:39 +0000 | [diff] [blame] | 4283 | num_elements = upper_bound - lower_bound + 1; |
| 4284 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4285 | |
| Sean Callanan | ec979ba | 2012-10-22 23:56:48 +0000 | [diff] [blame] | 4286 | element_orders.push_back (num_elements); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4287 | } |
| 4288 | } |
| 4289 | break; |
| 4290 | } |
| 4291 | } |
| 4292 | } |
| 4293 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4294 | TypeSP |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4295 | SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4296 | { |
| 4297 | TypeSP type_sp; |
| 4298 | if (die != NULL) |
| 4299 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4300 | assert(dwarf_cu != NULL); |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4301 | Type *type_ptr = m_die_to_type.lookup (die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4302 | if (type_ptr == NULL) |
| 4303 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4304 | CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4305 | assert (lldb_cu); |
| 4306 | SymbolContext sc(lldb_cu); |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4307 | type_sp = ParseType(sc, dwarf_cu, die, NULL); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4308 | } |
| 4309 | else if (type_ptr != DIE_IS_BEING_PARSED) |
| 4310 | { |
| 4311 | // Grab the existing type from the master types lists |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 4312 | type_sp = type_ptr->shared_from_this(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4313 | } |
| 4314 | |
| 4315 | } |
| 4316 | return type_sp; |
| 4317 | } |
| 4318 | |
| 4319 | clang::DeclContext * |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4320 | SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4321 | { |
| 4322 | if (die_offset != DW_INVALID_OFFSET) |
| 4323 | { |
| 4324 | DWARFCompileUnitSP cu_sp; |
| 4325 | const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4326 | return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4327 | } |
| 4328 | return NULL; |
| 4329 | } |
| 4330 | |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4331 | clang::DeclContext * |
| 4332 | SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset) |
| 4333 | { |
| 4334 | if (die_offset != DW_INVALID_OFFSET) |
| 4335 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4336 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 4337 | if (debug_info) |
| 4338 | { |
| 4339 | DWARFCompileUnitSP cu_sp; |
| 4340 | const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp); |
| 4341 | if (die) |
| 4342 | return GetClangDeclContextForDIE (sc, cu_sp.get(), die); |
| 4343 | } |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4344 | } |
| 4345 | return NULL; |
| 4346 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4347 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4348 | clang::NamespaceDecl * |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4349 | SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4350 | { |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4351 | if (die && die->Tag() == DW_TAG_namespace) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4352 | { |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4353 | // See if we already parsed this namespace DIE and associated it with a |
| 4354 | // uniqued namespace declaration |
| 4355 | clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]); |
| 4356 | if (namespace_decl) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4357 | return namespace_decl; |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4358 | else |
| 4359 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4360 | const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL); |
| 4361 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL); |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4362 | namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx); |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4363 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4364 | if (log) |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4365 | { |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4366 | if (namespace_name) |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4367 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4368 | GetObjectFile()->GetModule()->LogMessage (log, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4369 | "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] | 4370 | GetClangASTContext().getASTContext(), |
| 4371 | MakeUserID(die->GetOffset()), |
| 4372 | namespace_name, |
| 4373 | namespace_decl, |
| 4374 | namespace_decl->getOriginalNamespace()); |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4375 | } |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4376 | else |
| 4377 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4378 | GetObjectFile()->GetModule()->LogMessage (log, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4379 | "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] | 4380 | GetClangASTContext().getASTContext(), |
| 4381 | MakeUserID(die->GetOffset()), |
| 4382 | namespace_decl, |
| 4383 | namespace_decl->getOriginalNamespace()); |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4384 | } |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4385 | } |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4386 | |
| 4387 | if (namespace_decl) |
| 4388 | LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die); |
| 4389 | return namespace_decl; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4390 | } |
| 4391 | } |
| 4392 | return NULL; |
| 4393 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4394 | |
| 4395 | clang::DeclContext * |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4396 | SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4397 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4398 | clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die); |
| 4399 | if (clang_decl_ctx) |
| 4400 | return clang_decl_ctx; |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4401 | // If this DIE has a specification, or an abstract origin, then trace to those. |
| 4402 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4403 | 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] | 4404 | if (die_offset != DW_INVALID_OFFSET) |
| 4405 | return GetClangDeclContextForDIEOffset (sc, die_offset); |
| 4406 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4407 | 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] | 4408 | if (die_offset != DW_INVALID_OFFSET) |
| 4409 | return GetClangDeclContextForDIEOffset (sc, die_offset); |
| 4410 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4411 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 4412 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4413 | 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] | 4414 | // This is the DIE we want. Parse it, then query our map. |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4415 | bool assert_not_being_parsed = true; |
| 4416 | ResolveTypeUID (cu, die, assert_not_being_parsed); |
| 4417 | |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4418 | clang_decl_ctx = GetCachedClangDeclContextForDIE (die); |
| 4419 | |
| 4420 | return clang_decl_ctx; |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4421 | } |
| 4422 | |
| 4423 | clang::DeclContext * |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4424 | 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] | 4425 | { |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4426 | if (m_clang_tu_decl == NULL) |
| 4427 | m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4428 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4429 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4430 | |
| 4431 | if (decl_ctx_die_copy) |
| 4432 | *decl_ctx_die_copy = decl_ctx_die; |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4433 | |
| 4434 | if (decl_ctx_die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4435 | { |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4436 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4437 | DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die); |
| 4438 | if (pos != m_die_to_decl_ctx.end()) |
| 4439 | return pos->second; |
| 4440 | |
| 4441 | switch (decl_ctx_die->Tag()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4442 | { |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4443 | case DW_TAG_compile_unit: |
| 4444 | return m_clang_tu_decl; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4445 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4446 | case DW_TAG_namespace: |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4447 | return ResolveNamespaceDIE (cu, decl_ctx_die); |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4448 | break; |
| 4449 | |
| 4450 | case DW_TAG_structure_type: |
| 4451 | case DW_TAG_union_type: |
| 4452 | case DW_TAG_class_type: |
| 4453 | { |
| 4454 | Type* type = ResolveType (cu, decl_ctx_die); |
| 4455 | if (type) |
| 4456 | { |
| 4457 | clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ()); |
| 4458 | if (decl_ctx) |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4459 | { |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4460 | LinkDeclContextToDIE (decl_ctx, decl_ctx_die); |
| 4461 | if (decl_ctx) |
| 4462 | return decl_ctx; |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4463 | } |
| 4464 | } |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4465 | } |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4466 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4467 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4468 | default: |
| 4469 | break; |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4470 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4471 | } |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 4472 | return m_clang_tu_decl; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4473 | } |
| 4474 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4475 | |
| 4476 | const DWARFDebugInfoEntry * |
| 4477 | SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) |
| 4478 | { |
| 4479 | if (cu && die) |
| 4480 | { |
| 4481 | const DWARFDebugInfoEntry * const decl_die = die; |
| 4482 | |
| 4483 | while (die != NULL) |
| 4484 | { |
| 4485 | // If this is the original DIE that we are searching for a declaration |
| 4486 | // for, then don't look in the cache as we don't want our own decl |
| 4487 | // context to be our decl context... |
| 4488 | if (decl_die != die) |
| 4489 | { |
| 4490 | switch (die->Tag()) |
| 4491 | { |
| 4492 | case DW_TAG_compile_unit: |
| 4493 | case DW_TAG_namespace: |
| 4494 | case DW_TAG_structure_type: |
| 4495 | case DW_TAG_union_type: |
| 4496 | case DW_TAG_class_type: |
| 4497 | return die; |
| 4498 | |
| 4499 | default: |
| 4500 | break; |
| 4501 | } |
| 4502 | } |
| 4503 | |
| 4504 | dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET); |
| 4505 | if (die_offset != DW_INVALID_OFFSET) |
| 4506 | { |
| 4507 | DWARFCompileUnit *spec_cu = cu; |
| 4508 | const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu); |
| 4509 | const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die); |
| 4510 | if (spec_die_decl_ctx_die) |
| 4511 | return spec_die_decl_ctx_die; |
| 4512 | } |
| 4513 | |
| 4514 | die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET); |
| 4515 | if (die_offset != DW_INVALID_OFFSET) |
| 4516 | { |
| 4517 | DWARFCompileUnit *abs_cu = cu; |
| 4518 | const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu); |
| 4519 | const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die); |
| 4520 | if (abs_die_decl_ctx_die) |
| 4521 | return abs_die_decl_ctx_die; |
| 4522 | } |
| 4523 | |
| 4524 | die = die->GetParent(); |
| 4525 | } |
| 4526 | } |
| 4527 | return NULL; |
| 4528 | } |
| 4529 | |
| 4530 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4531 | Symbol * |
| 4532 | SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name) |
| 4533 | { |
| 4534 | Symbol *objc_class_symbol = NULL; |
| 4535 | if (m_obj_file) |
| 4536 | { |
| 4537 | Symtab *symtab = m_obj_file->GetSymtab(); |
| 4538 | if (symtab) |
| 4539 | { |
| 4540 | objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name, |
| 4541 | eSymbolTypeObjCClass, |
| 4542 | Symtab::eDebugNo, |
| 4543 | Symtab::eVisibilityAny); |
| 4544 | } |
| 4545 | } |
| 4546 | return objc_class_symbol; |
| 4547 | } |
| 4548 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4549 | // Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't |
| 4550 | // then we can end up looking through all class types for a complete type and never find |
| 4551 | // the full definition. We need to know if this attribute is supported, so we determine |
| 4552 | // this here and cache th result. We also need to worry about the debug map DWARF file |
| 4553 | // if we are doing darwin DWARF in .o file debugging. |
| 4554 | bool |
| 4555 | SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu) |
| 4556 | { |
| 4557 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate) |
| 4558 | { |
| 4559 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo; |
| 4560 | if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type()) |
| 4561 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; |
| 4562 | else |
| 4563 | { |
| 4564 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 4565 | const uint32_t num_compile_units = GetNumCompileUnits(); |
| 4566 | for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) |
| 4567 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4568 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); |
| 4569 | 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] | 4570 | { |
| 4571 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; |
| 4572 | break; |
| 4573 | } |
| 4574 | } |
| 4575 | } |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 4576 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ()) |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4577 | return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this); |
| 4578 | } |
| 4579 | return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes; |
| 4580 | } |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4581 | |
| 4582 | // This function can be used when a DIE is found that is a forward declaration |
| 4583 | // DIE and we want to try and find a type that has the complete definition. |
| 4584 | TypeSP |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4585 | SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die, |
| 4586 | const ConstString &type_name, |
| 4587 | bool must_be_implementation) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4588 | { |
| 4589 | |
| 4590 | TypeSP type_sp; |
| 4591 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4592 | if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name))) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4593 | return type_sp; |
| 4594 | |
| 4595 | DIEArray die_offsets; |
| 4596 | |
| 4597 | if (m_using_apple_tables) |
| 4598 | { |
| 4599 | if (m_apple_types_ap.get()) |
| 4600 | { |
| 4601 | const char *name_cstr = type_name.GetCString(); |
| Greg Clayton | 68221ec | 2012-01-18 20:58:12 +0000 | [diff] [blame] | 4602 | m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4603 | } |
| 4604 | } |
| 4605 | else |
| 4606 | { |
| 4607 | if (!m_indexed) |
| 4608 | Index (); |
| 4609 | |
| 4610 | m_type_index.Find (type_name, die_offsets); |
| 4611 | } |
| 4612 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4613 | const size_t num_matches = die_offsets.size(); |
| 4614 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4615 | DWARFCompileUnit* type_cu = NULL; |
| 4616 | const DWARFDebugInfoEntry* type_die = NULL; |
| 4617 | if (num_matches) |
| 4618 | { |
| 4619 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 4620 | for (size_t i=0; i<num_matches; ++i) |
| 4621 | { |
| 4622 | const dw_offset_t die_offset = die_offsets[i]; |
| 4623 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); |
| 4624 | |
| 4625 | if (type_die) |
| 4626 | { |
| 4627 | bool try_resolving_type = false; |
| 4628 | |
| 4629 | // Don't try and resolve the DIE we are looking for with the DIE itself! |
| 4630 | if (type_die != die) |
| 4631 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4632 | switch (type_die->Tag()) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4633 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4634 | case DW_TAG_class_type: |
| 4635 | case DW_TAG_structure_type: |
| 4636 | try_resolving_type = true; |
| 4637 | break; |
| 4638 | default: |
| 4639 | break; |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4640 | } |
| 4641 | } |
| 4642 | |
| 4643 | if (try_resolving_type) |
| 4644 | { |
| Sean Callanan | a9bc065 | 2012-01-19 02:17:40 +0000 | [diff] [blame] | 4645 | 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] | 4646 | 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] | 4647 | |
| 4648 | if (try_resolving_type) |
| 4649 | { |
| 4650 | Type *resolved_type = ResolveType (type_cu, type_die, false); |
| 4651 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) |
| 4652 | { |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4653 | 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] | 4654 | MakeUserID(die->GetOffset()), |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4655 | MakeUserID(dwarf_cu->GetOffset()), |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4656 | m_obj_file->GetFileSpec().GetFilename().AsCString(), |
| 4657 | MakeUserID(type_die->GetOffset()), |
| 4658 | MakeUserID(type_cu->GetOffset())); |
| 4659 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4660 | if (die) |
| 4661 | m_die_to_type[die] = resolved_type; |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 4662 | type_sp = resolved_type->shared_from_this(); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4663 | break; |
| 4664 | } |
| 4665 | } |
| 4666 | } |
| 4667 | } |
| 4668 | else |
| 4669 | { |
| 4670 | if (m_using_apple_tables) |
| 4671 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4672 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 4673 | die_offset, type_name.GetCString()); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4674 | } |
| 4675 | } |
| 4676 | |
| 4677 | } |
| 4678 | } |
| 4679 | return type_sp; |
| 4680 | } |
| 4681 | |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4682 | |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4683 | //---------------------------------------------------------------------- |
| 4684 | // This function helps to ensure that the declaration contexts match for |
| 4685 | // two different DIEs. Often times debug information will refer to a |
| 4686 | // forward declaration of a type (the equivalent of "struct my_struct;". |
| 4687 | // There will often be a declaration of that type elsewhere that has the |
| 4688 | // full definition. When we go looking for the full type "my_struct", we |
| 4689 | // will find one or more matches in the accelerator tables and we will |
| 4690 | // then need to make sure the type was in the same declaration context |
| 4691 | // as the original DIE. This function can efficiently compare two DIEs |
| 4692 | // and will return true when the declaration context matches, and false |
| 4693 | // when they don't. |
| 4694 | //---------------------------------------------------------------------- |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4695 | bool |
| 4696 | SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1, |
| 4697 | DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2) |
| 4698 | { |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4699 | if (die1 == die2) |
| 4700 | return true; |
| 4701 | |
| 4702 | #if defined (LLDB_CONFIGURATION_DEBUG) |
| 4703 | // You can't and shouldn't call this function with a compile unit from |
| 4704 | // two different SymbolFileDWARF instances. |
| 4705 | assert (DebugInfo()->ContainsCompileUnit (cu1)); |
| 4706 | assert (DebugInfo()->ContainsCompileUnit (cu2)); |
| 4707 | #endif |
| 4708 | |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4709 | DWARFDIECollection decl_ctx_1; |
| 4710 | DWARFDIECollection decl_ctx_2; |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4711 | //The declaration DIE stack is a stack of the declaration context |
| 4712 | // DIEs all the way back to the compile unit. If a type "T" is |
| 4713 | // declared inside a class "B", and class "B" is declared inside |
| 4714 | // a class "A" and class "A" is in a namespace "lldb", and the |
| 4715 | // namespace is in a compile unit, there will be a stack of DIEs: |
| 4716 | // |
| 4717 | // [0] DW_TAG_class_type for "B" |
| 4718 | // [1] DW_TAG_class_type for "A" |
| 4719 | // [2] DW_TAG_namespace for "lldb" |
| 4720 | // [3] DW_TAG_compile_unit for the source file. |
| 4721 | // |
| 4722 | // We grab both contexts and make sure that everything matches |
| 4723 | // all the way back to the compiler unit. |
| 4724 | |
| 4725 | // First lets grab the decl contexts for both DIEs |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4726 | die1->GetDeclContextDIEs (this, cu1, decl_ctx_1); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 4727 | die2->GetDeclContextDIEs (this, cu2, decl_ctx_2); |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4728 | // Make sure the context arrays have the same size, otherwise |
| 4729 | // we are done |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4730 | const size_t count1 = decl_ctx_1.Size(); |
| 4731 | const size_t count2 = decl_ctx_2.Size(); |
| 4732 | if (count1 != count2) |
| 4733 | return false; |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4734 | |
| 4735 | // Make sure the DW_TAG values match all the way back up the the |
| 4736 | // compile unit. If they don't, then we are done. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4737 | const DWARFDebugInfoEntry *decl_ctx_die1; |
| 4738 | const DWARFDebugInfoEntry *decl_ctx_die2; |
| 4739 | size_t i; |
| 4740 | for (i=0; i<count1; i++) |
| 4741 | { |
| 4742 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); |
| 4743 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); |
| 4744 | if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag()) |
| 4745 | return false; |
| 4746 | } |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4747 | #if defined LLDB_CONFIGURATION_DEBUG |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4748 | |
| 4749 | // Make sure the top item in the decl context die array is always |
| 4750 | // DW_TAG_compile_unit. If it isn't then something went wrong in |
| 4751 | // the DWARFDebugInfoEntry::GetDeclContextDIEs() function... |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4752 | assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit); |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4753 | |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4754 | #endif |
| 4755 | // Always skip the compile unit when comparing by only iterating up to |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4756 | // "count - 1". Here we compare the names as we go. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4757 | for (i=0; i<count1 - 1; i++) |
| 4758 | { |
| 4759 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); |
| 4760 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); |
| 4761 | const char *name1 = decl_ctx_die1->GetName(this, cu1); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 4762 | const char *name2 = decl_ctx_die2->GetName(this, cu2); |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4763 | // If the string was from a DW_FORM_strp, then the pointer will often |
| 4764 | // be the same! |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 4765 | if (name1 == name2) |
| 4766 | continue; |
| 4767 | |
| 4768 | // Name pointers are not equal, so only compare the strings |
| 4769 | // if both are not NULL. |
| 4770 | if (name1 && name2) |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4771 | { |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 4772 | // If the strings don't compare, we are done... |
| 4773 | if (strcmp(name1, name2) != 0) |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4774 | return false; |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 4775 | } |
| 4776 | else |
| 4777 | { |
| 4778 | // One name was NULL while the other wasn't |
| 4779 | return false; |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4780 | } |
| 4781 | } |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4782 | // We made it through all of the checks and the declaration contexts |
| 4783 | // are equal. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4784 | return true; |
| 4785 | } |
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 4786 | |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4787 | // This function can be used when a DIE is found that is a forward declaration |
| 4788 | // 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] | 4789 | // "cu" and "die" must be from this SymbolFileDWARF |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4790 | TypeSP |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4791 | SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu, |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4792 | const DWARFDebugInfoEntry *die, |
| 4793 | const ConstString &type_name) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4794 | { |
| 4795 | TypeSP type_sp; |
| 4796 | |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4797 | #if defined (LLDB_CONFIGURATION_DEBUG) |
| 4798 | // You can't and shouldn't call this function with a compile unit from |
| 4799 | // another SymbolFileDWARF instance. |
| 4800 | assert (DebugInfo()->ContainsCompileUnit (cu)); |
| 4801 | #endif |
| 4802 | |
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 4803 | if (cu == NULL || die == NULL || !type_name) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4804 | return type_sp; |
| 4805 | |
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 4806 | std::string qualified_name; |
| 4807 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4808 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4809 | if (log) |
| 4810 | { |
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4811 | die->GetQualifiedName(this, cu, qualified_name); |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4812 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4813 | "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x (%s), name='%s')", |
| 4814 | die->GetOffset(), |
| 4815 | qualified_name.c_str(), |
| 4816 | type_name.GetCString()); |
| 4817 | } |
| 4818 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4819 | DIEArray die_offsets; |
| 4820 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4821 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4822 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4823 | if (m_apple_types_ap.get()) |
| 4824 | { |
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 4825 | const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag); |
| 4826 | const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash); |
| 4827 | if (has_tag && has_qualified_name_hash) |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4828 | { |
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 4829 | if (qualified_name.empty()) |
| 4830 | die->GetQualifiedName(this, cu, qualified_name); |
| 4831 | |
| 4832 | const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name.c_str()); |
| 4833 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4834 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()"); |
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 4835 | m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), die->Tag(), qualified_name_hash, die_offsets); |
| 4836 | } |
| 4837 | else if (has_tag > 1) |
| 4838 | { |
| 4839 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4840 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()"); |
| Greg Clayton | ae920b6 | 2012-01-06 00:17:16 +0000 | [diff] [blame] | 4841 | m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets); |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4842 | } |
| 4843 | else |
| 4844 | { |
| 4845 | m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets); |
| 4846 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4847 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4848 | } |
| 4849 | else |
| 4850 | { |
| 4851 | if (!m_indexed) |
| 4852 | Index (); |
| 4853 | |
| 4854 | m_type_index.Find (type_name, die_offsets); |
| 4855 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4856 | |
| 4857 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | 6997489 | 2010-12-03 21:42:06 +0000 | [diff] [blame] | 4858 | |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4859 | const dw_tag_t die_tag = die->Tag(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4860 | |
| 4861 | DWARFCompileUnit* type_cu = NULL; |
| 4862 | const DWARFDebugInfoEntry* type_die = NULL; |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4863 | if (num_matches) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4864 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4865 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4866 | for (size_t i=0; i<num_matches; ++i) |
| 4867 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4868 | const dw_offset_t die_offset = die_offsets[i]; |
| 4869 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4870 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4871 | if (type_die) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4872 | { |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4873 | bool try_resolving_type = false; |
| 4874 | |
| 4875 | // Don't try and resolve the DIE we are looking for with the DIE itself! |
| 4876 | if (type_die != die) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4877 | { |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4878 | const dw_tag_t type_die_tag = type_die->Tag(); |
| 4879 | // Make sure the tags match |
| 4880 | if (type_die_tag == die_tag) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4881 | { |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4882 | // The tags match, lets try resolving this type |
| 4883 | try_resolving_type = true; |
| 4884 | } |
| 4885 | else |
| 4886 | { |
| 4887 | // The tags don't match, but we need to watch our for a |
| 4888 | // forward declaration for a struct and ("struct foo") |
| 4889 | // ends up being a class ("class foo { ... };") or |
| 4890 | // vice versa. |
| 4891 | switch (type_die_tag) |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4892 | { |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4893 | case DW_TAG_class_type: |
| 4894 | // We had a "class foo", see if we ended up with a "struct foo { ... };" |
| 4895 | try_resolving_type = (die_tag == DW_TAG_structure_type); |
| 4896 | break; |
| 4897 | case DW_TAG_structure_type: |
| 4898 | // We had a "struct foo", see if we ended up with a "class foo { ... };" |
| 4899 | try_resolving_type = (die_tag == DW_TAG_class_type); |
| 4900 | break; |
| 4901 | default: |
| 4902 | // Tags don't match, don't event try to resolve |
| 4903 | // using this type whose name matches.... |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4904 | break; |
| 4905 | } |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4906 | } |
| 4907 | } |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4908 | |
| 4909 | if (try_resolving_type) |
| 4910 | { |
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4911 | if (log) |
| 4912 | { |
| 4913 | std::string qualified_name; |
| 4914 | type_die->GetQualifiedName(this, cu, qualified_name); |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4915 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4916 | "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') trying die=0x%8.8x (%s)", |
| 4917 | die->GetOffset(), |
| 4918 | type_name.GetCString(), |
| 4919 | type_die->GetOffset(), |
| 4920 | qualified_name.c_str()); |
| 4921 | } |
| 4922 | |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4923 | // Make sure the decl contexts match all the way up |
| 4924 | if (DIEDeclContextsMatch(cu, die, type_cu, type_die)) |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4925 | { |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4926 | Type *resolved_type = ResolveType (type_cu, type_die, false); |
| 4927 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) |
| 4928 | { |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4929 | 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] | 4930 | MakeUserID(die->GetOffset()), |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4931 | MakeUserID(dwarf_cu->GetOffset()), |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4932 | m_obj_file->GetFileSpec().GetFilename().AsCString(), |
| 4933 | MakeUserID(type_die->GetOffset()), |
| 4934 | MakeUserID(type_cu->GetOffset())); |
| 4935 | |
| 4936 | m_die_to_type[die] = resolved_type; |
| Greg Clayton | ff7692a | 2012-02-02 18:16:59 +0000 | [diff] [blame] | 4937 | type_sp = resolved_type->shared_from_this(); |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4938 | break; |
| 4939 | } |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4940 | } |
| 4941 | } |
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4942 | else |
| 4943 | { |
| 4944 | if (log) |
| 4945 | { |
| 4946 | std::string qualified_name; |
| 4947 | type_die->GetQualifiedName(this, cu, qualified_name); |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4948 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4949 | "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') ignoring die=0x%8.8x (%s)", |
| 4950 | die->GetOffset(), |
| 4951 | type_name.GetCString(), |
| 4952 | type_die->GetOffset(), |
| 4953 | qualified_name.c_str()); |
| 4954 | } |
| 4955 | } |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4956 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4957 | else |
| 4958 | { |
| 4959 | if (m_using_apple_tables) |
| 4960 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4961 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 4962 | die_offset, type_name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4963 | } |
| 4964 | } |
| 4965 | |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4966 | } |
| 4967 | } |
| 4968 | return type_sp; |
| 4969 | } |
| 4970 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4971 | TypeSP |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4972 | SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx) |
| 4973 | { |
| 4974 | TypeSP type_sp; |
| 4975 | |
| 4976 | const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize(); |
| 4977 | if (dwarf_decl_ctx_count > 0) |
| 4978 | { |
| 4979 | const ConstString type_name(dwarf_decl_ctx[0].name); |
| 4980 | const dw_tag_t tag = dwarf_decl_ctx[0].tag; |
| 4981 | |
| 4982 | if (type_name) |
| 4983 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4984 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS)); |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4985 | if (log) |
| 4986 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4987 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4988 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')", |
| 4989 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), |
| 4990 | dwarf_decl_ctx.GetQualifiedName()); |
| 4991 | } |
| 4992 | |
| 4993 | DIEArray die_offsets; |
| 4994 | |
| 4995 | if (m_using_apple_tables) |
| 4996 | { |
| 4997 | if (m_apple_types_ap.get()) |
| 4998 | { |
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 4999 | const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag); |
| 5000 | const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash); |
| 5001 | if (has_tag && has_qualified_name_hash) |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5002 | { |
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 5003 | const char *qualified_name = dwarf_decl_ctx.GetQualifiedName(); |
| 5004 | const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name); |
| 5005 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5006 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()"); |
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 5007 | m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets); |
| 5008 | } |
| 5009 | else if (has_tag) |
| 5010 | { |
| 5011 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5012 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()"); |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5013 | m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets); |
| 5014 | } |
| 5015 | else |
| 5016 | { |
| 5017 | m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets); |
| 5018 | } |
| 5019 | } |
| 5020 | } |
| 5021 | else |
| 5022 | { |
| 5023 | if (!m_indexed) |
| 5024 | Index (); |
| 5025 | |
| 5026 | m_type_index.Find (type_name, die_offsets); |
| 5027 | } |
| 5028 | |
| 5029 | const size_t num_matches = die_offsets.size(); |
| 5030 | |
| 5031 | |
| 5032 | DWARFCompileUnit* type_cu = NULL; |
| 5033 | const DWARFDebugInfoEntry* type_die = NULL; |
| 5034 | if (num_matches) |
| 5035 | { |
| 5036 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 5037 | for (size_t i=0; i<num_matches; ++i) |
| 5038 | { |
| 5039 | const dw_offset_t die_offset = die_offsets[i]; |
| 5040 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); |
| 5041 | |
| 5042 | if (type_die) |
| 5043 | { |
| 5044 | bool try_resolving_type = false; |
| 5045 | |
| 5046 | // Don't try and resolve the DIE we are looking for with the DIE itself! |
| 5047 | const dw_tag_t type_tag = type_die->Tag(); |
| 5048 | // Make sure the tags match |
| 5049 | if (type_tag == tag) |
| 5050 | { |
| 5051 | // The tags match, lets try resolving this type |
| 5052 | try_resolving_type = true; |
| 5053 | } |
| 5054 | else |
| 5055 | { |
| 5056 | // The tags don't match, but we need to watch our for a |
| 5057 | // forward declaration for a struct and ("struct foo") |
| 5058 | // ends up being a class ("class foo { ... };") or |
| 5059 | // vice versa. |
| 5060 | switch (type_tag) |
| 5061 | { |
| 5062 | case DW_TAG_class_type: |
| 5063 | // We had a "class foo", see if we ended up with a "struct foo { ... };" |
| 5064 | try_resolving_type = (tag == DW_TAG_structure_type); |
| 5065 | break; |
| 5066 | case DW_TAG_structure_type: |
| 5067 | // We had a "struct foo", see if we ended up with a "class foo { ... };" |
| 5068 | try_resolving_type = (tag == DW_TAG_class_type); |
| 5069 | break; |
| 5070 | default: |
| 5071 | // Tags don't match, don't event try to resolve |
| 5072 | // using this type whose name matches.... |
| 5073 | break; |
| 5074 | } |
| 5075 | } |
| 5076 | |
| 5077 | if (try_resolving_type) |
| 5078 | { |
| 5079 | DWARFDeclContext type_dwarf_decl_ctx; |
| 5080 | type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx); |
| 5081 | |
| 5082 | if (log) |
| 5083 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5084 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5085 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)", |
| 5086 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), |
| 5087 | dwarf_decl_ctx.GetQualifiedName(), |
| 5088 | type_die->GetOffset(), |
| 5089 | type_dwarf_decl_ctx.GetQualifiedName()); |
| 5090 | } |
| 5091 | |
| 5092 | // Make sure the decl contexts match all the way up |
| 5093 | if (dwarf_decl_ctx == type_dwarf_decl_ctx) |
| 5094 | { |
| 5095 | Type *resolved_type = ResolveType (type_cu, type_die, false); |
| 5096 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) |
| 5097 | { |
| 5098 | type_sp = resolved_type->shared_from_this(); |
| 5099 | break; |
| 5100 | } |
| 5101 | } |
| 5102 | } |
| 5103 | else |
| 5104 | { |
| 5105 | if (log) |
| 5106 | { |
| 5107 | std::string qualified_name; |
| 5108 | type_die->GetQualifiedName(this, type_cu, qualified_name); |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5109 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5110 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)", |
| 5111 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), |
| 5112 | dwarf_decl_ctx.GetQualifiedName(), |
| 5113 | type_die->GetOffset(), |
| 5114 | qualified_name.c_str()); |
| 5115 | } |
| 5116 | } |
| 5117 | } |
| 5118 | else |
| 5119 | { |
| 5120 | if (m_using_apple_tables) |
| 5121 | { |
| 5122 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 5123 | die_offset, type_name.GetCString()); |
| 5124 | } |
| 5125 | } |
| 5126 | |
| 5127 | } |
| 5128 | } |
| 5129 | } |
| 5130 | } |
| 5131 | return type_sp; |
| 5132 | } |
| 5133 | |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5134 | bool |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5135 | SymbolFileDWARF::CopyUniqueClassMethodTypes (SymbolFileDWARF *src_symfile, |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5136 | Type *class_type, |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5137 | DWARFCompileUnit* src_cu, |
| 5138 | const DWARFDebugInfoEntry *src_class_die, |
| 5139 | DWARFCompileUnit* dst_cu, |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5140 | const DWARFDebugInfoEntry *dst_class_die, |
| 5141 | llvm::SmallVectorImpl <const DWARFDebugInfoEntry *> &failures) |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5142 | { |
| 5143 | if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die) |
| 5144 | return false; |
| 5145 | if (src_class_die->Tag() != dst_class_die->Tag()) |
| 5146 | return false; |
| 5147 | |
| 5148 | // We need to complete the class type so we can get all of the method types |
| 5149 | // parsed so we can then unique those types to their equivalent counterparts |
| 5150 | // in "dst_cu" and "dst_class_die" |
| 5151 | class_type->GetClangFullType(); |
| 5152 | |
| 5153 | const DWARFDebugInfoEntry *src_die; |
| 5154 | const DWARFDebugInfoEntry *dst_die; |
| 5155 | UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die; |
| 5156 | UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die; |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5157 | UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die_artificial; |
| 5158 | UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die_artificial; |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5159 | for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling()) |
| 5160 | { |
| 5161 | if (src_die->Tag() == DW_TAG_subprogram) |
| 5162 | { |
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5163 | // Make sure this is a declaration and not a concrete instance by looking |
| 5164 | // for DW_AT_declaration set to 1. Sometimes concrete function instances |
| 5165 | // are placed inside the class definitions and shouldn't be included in |
| 5166 | // the list of things are are tracking here. |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5167 | 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] | 5168 | { |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5169 | const char *src_name = src_die->GetMangledName (src_symfile, src_cu); |
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5170 | if (src_name) |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5171 | { |
| 5172 | ConstString src_const_name(src_name); |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5173 | if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_artificial, 0)) |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5174 | src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die); |
| 5175 | else |
| 5176 | src_name_to_die.Append(src_const_name.GetCString(), src_die); |
| 5177 | } |
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5178 | } |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5179 | } |
| 5180 | } |
| 5181 | for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling()) |
| 5182 | { |
| 5183 | if (dst_die->Tag() == DW_TAG_subprogram) |
| 5184 | { |
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5185 | // Make sure this is a declaration and not a concrete instance by looking |
| 5186 | // for DW_AT_declaration set to 1. Sometimes concrete function instances |
| 5187 | // are placed inside the class definitions and shouldn't be included in |
| 5188 | // the list of things are are tracking here. |
| 5189 | if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_declaration, 0) == 1) |
| 5190 | { |
| 5191 | const char *dst_name = dst_die->GetMangledName (this, dst_cu); |
| 5192 | if (dst_name) |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5193 | { |
| 5194 | ConstString dst_const_name(dst_name); |
| 5195 | if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_artificial, 0)) |
| 5196 | dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die); |
| 5197 | else |
| 5198 | dst_name_to_die.Append(dst_const_name.GetCString(), dst_die); |
| 5199 | } |
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 5200 | } |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5201 | } |
| 5202 | } |
| 5203 | const uint32_t src_size = src_name_to_die.GetSize (); |
| 5204 | const uint32_t dst_size = dst_name_to_die.GetSize (); |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5205 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION)); |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5206 | |
| 5207 | // Is everything kosher so we can go through the members at top speed? |
| 5208 | bool fast_path = true; |
| 5209 | |
| 5210 | if (src_size != dst_size) |
| 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 | if (src_size != 0 && dst_size != 0) |
| 5213 | { |
| 5214 | if (log) |
| 5215 | 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)", |
| 5216 | src_class_die->GetOffset(), |
| 5217 | dst_class_die->GetOffset(), |
| 5218 | src_size, |
| 5219 | dst_size); |
| 5220 | } |
| 5221 | |
| 5222 | fast_path = false; |
| 5223 | } |
| 5224 | |
| 5225 | uint32_t idx; |
| 5226 | |
| 5227 | if (fast_path) |
| 5228 | { |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5229 | for (idx = 0; idx < src_size; ++idx) |
| 5230 | { |
| 5231 | src_die = src_name_to_die.GetValueAtIndexUnchecked (idx); |
| 5232 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx); |
| 5233 | |
| 5234 | if (src_die->Tag() != dst_die->Tag()) |
| 5235 | { |
| 5236 | if (log) |
| 5237 | 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)", |
| 5238 | src_class_die->GetOffset(), |
| 5239 | dst_class_die->GetOffset(), |
| 5240 | src_die->GetOffset(), |
| 5241 | DW_TAG_value_to_name(src_die->Tag()), |
| 5242 | dst_die->GetOffset(), |
| 5243 | DW_TAG_value_to_name(src_die->Tag())); |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5244 | fast_path = false; |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5245 | } |
| 5246 | |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5247 | const char *src_name = src_die->GetMangledName (src_symfile, src_cu); |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5248 | const char *dst_name = dst_die->GetMangledName (this, dst_cu); |
| 5249 | |
| 5250 | // Make sure the names match |
| 5251 | if (src_name == dst_name || (strcmp (src_name, dst_name) == 0)) |
| 5252 | continue; |
| 5253 | |
| 5254 | if (log) |
| 5255 | 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)", |
| 5256 | src_class_die->GetOffset(), |
| 5257 | dst_class_die->GetOffset(), |
| 5258 | src_die->GetOffset(), |
| 5259 | src_name, |
| 5260 | dst_die->GetOffset(), |
| 5261 | dst_name); |
| 5262 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5263 | fast_path = false; |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5264 | } |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5265 | } |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5266 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5267 | // Now do the work of linking the DeclContexts and Types. |
| 5268 | if (fast_path) |
| 5269 | { |
| 5270 | // We can do this quickly. Just run across the tables index-for-index since |
| 5271 | // we know each node has matching names and tags. |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5272 | for (idx = 0; idx < src_size; ++idx) |
| 5273 | { |
| 5274 | src_die = src_name_to_die.GetValueAtIndexUnchecked (idx); |
| 5275 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx); |
| 5276 | |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5277 | 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] | 5278 | if (src_decl_ctx) |
| 5279 | { |
| 5280 | if (log) |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5281 | 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] | 5282 | LinkDeclContextToDIE (src_decl_ctx, dst_die); |
| 5283 | } |
| 5284 | else |
| 5285 | { |
| 5286 | if (log) |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5287 | 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] | 5288 | } |
| 5289 | |
| 5290 | Type *src_child_type = m_die_to_type[src_die]; |
| 5291 | if (src_child_type) |
| 5292 | { |
| 5293 | if (log) |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5294 | 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] | 5295 | m_die_to_type[dst_die] = src_child_type; |
| 5296 | } |
| 5297 | else |
| 5298 | { |
| 5299 | if (log) |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5300 | 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()); |
| 5301 | } |
| 5302 | } |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5303 | } |
| 5304 | else |
| 5305 | { |
| 5306 | // We must do this slowly. For each member of the destination, look |
| 5307 | // up a member in the source with the same name, check its tag, and |
| 5308 | // unique them if everything matches up. Report failures. |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5309 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5310 | if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty()) |
| 5311 | { |
| 5312 | src_name_to_die.Sort(); |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5313 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5314 | for (idx = 0; idx < dst_size; ++idx) |
| 5315 | { |
| 5316 | const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx); |
| 5317 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx); |
| 5318 | src_die = src_name_to_die.Find(dst_name, NULL); |
| 5319 | |
| 5320 | if (src_die && (src_die->Tag() == dst_die->Tag())) |
| 5321 | { |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 5322 | 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] | 5323 | if (src_decl_ctx) |
| 5324 | { |
| 5325 | if (log) |
| 5326 | log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset()); |
| 5327 | LinkDeclContextToDIE (src_decl_ctx, dst_die); |
| 5328 | } |
| 5329 | else |
| 5330 | { |
| 5331 | if (log) |
| 5332 | 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()); |
| 5333 | } |
| 5334 | |
| 5335 | Type *src_child_type = m_die_to_type[src_die]; |
| 5336 | if (src_child_type) |
| 5337 | { |
| 5338 | if (log) |
| 5339 | 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()); |
| 5340 | m_die_to_type[dst_die] = src_child_type; |
| 5341 | } |
| 5342 | else |
| 5343 | { |
| 5344 | if (log) |
| 5345 | 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()); |
| 5346 | } |
| 5347 | } |
| 5348 | else |
| 5349 | { |
| 5350 | if (log) |
| 5351 | 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] | 5352 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5353 | failures.push_back(dst_die); |
| 5354 | } |
| 5355 | } |
| 5356 | } |
| 5357 | } |
| 5358 | |
| 5359 | const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize (); |
| 5360 | const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize (); |
| 5361 | |
| 5362 | UniqueCStringMap<const DWARFDebugInfoEntry *> name_to_die_artificial_not_in_src; |
| 5363 | |
| 5364 | if (src_size_artificial && dst_size_artificial) |
| 5365 | { |
| 5366 | dst_name_to_die_artificial.Sort(); |
| 5367 | |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5368 | for (idx = 0; idx < src_size_artificial; ++idx) |
| 5369 | { |
| 5370 | const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx); |
| 5371 | src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx); |
| 5372 | dst_die = dst_name_to_die_artificial.Find(src_name_artificial, NULL); |
| 5373 | |
| 5374 | if (dst_die) |
| 5375 | { |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5376 | // Both classes have the artificial types, link them |
| 5377 | clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die]; |
| 5378 | if (src_decl_ctx) |
| 5379 | { |
| 5380 | if (log) |
| 5381 | log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset()); |
| 5382 | LinkDeclContextToDIE (src_decl_ctx, dst_die); |
| 5383 | } |
| 5384 | else |
| 5385 | { |
| 5386 | if (log) |
| 5387 | 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()); |
| 5388 | } |
| 5389 | |
| 5390 | Type *src_child_type = m_die_to_type[src_die]; |
| 5391 | if (src_child_type) |
| 5392 | { |
| 5393 | if (log) |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5394 | 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] | 5395 | m_die_to_type[dst_die] = src_child_type; |
| 5396 | } |
| 5397 | else |
| 5398 | { |
| 5399 | if (log) |
| 5400 | 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()); |
| 5401 | } |
| 5402 | } |
| 5403 | } |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5404 | } |
| Greg Clayton | 65ec103 | 2012-11-12 21:27:20 +0000 | [diff] [blame] | 5405 | |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5406 | if (dst_size_artificial) |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5407 | { |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5408 | for (idx = 0; idx < dst_size_artificial; ++idx) |
| 5409 | { |
| 5410 | const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx); |
| 5411 | dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx); |
| 5412 | if (log) |
| 5413 | log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die->GetOffset(), dst_name_artificial); |
| 5414 | |
| 5415 | failures.push_back(dst_die); |
| 5416 | } |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5417 | } |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 5418 | |
| 5419 | return (failures.size() != 0); |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5420 | } |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5421 | |
| 5422 | TypeSP |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5423 | 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] | 5424 | { |
| 5425 | TypeSP type_sp; |
| 5426 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5427 | if (type_is_new_ptr) |
| 5428 | *type_is_new_ptr = false; |
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5429 | |
| 5430 | #if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE) |
| 5431 | static DIEStack g_die_stack; |
| 5432 | DIEStack::ScopedPopper scoped_die_logger(g_die_stack); |
| 5433 | #endif |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5434 | |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 5435 | AccessType accessibility = eAccessNone; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5436 | if (die != NULL) |
| 5437 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5438 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5439 | if (log) |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5440 | { |
| 5441 | const DWARFDebugInfoEntry *context_die; |
| 5442 | clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die); |
| 5443 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5444 | 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] | 5445 | die->GetOffset(), |
| 5446 | context, |
| 5447 | context_die->GetOffset(), |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5448 | DW_TAG_value_to_name(die->Tag()), |
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5449 | die->GetName(this, dwarf_cu)); |
| 5450 | |
| 5451 | #if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE) |
| 5452 | scoped_die_logger.Push (dwarf_cu, die); |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5453 | g_die_stack.LogDIEs(log, this); |
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5454 | #endif |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5455 | } |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5456 | // |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5457 | // Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5458 | // if (log && dwarf_cu) |
| 5459 | // { |
| 5460 | // StreamString s; |
| 5461 | // die->DumpLocation (this, dwarf_cu, s); |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5462 | // GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData()); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5463 | // |
| 5464 | // } |
| Jim Ingham | 16746d1 | 2011-08-25 23:21:43 +0000 | [diff] [blame] | 5465 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5466 | Type *type_ptr = m_die_to_type.lookup (die); |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5467 | TypeList* type_list = GetTypeList(); |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5468 | if (type_ptr == NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5469 | { |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5470 | ClangASTContext &ast = GetClangASTContext(); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5471 | if (type_is_new_ptr) |
| 5472 | *type_is_new_ptr = true; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5473 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5474 | const dw_tag_t tag = die->Tag(); |
| 5475 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5476 | bool is_forward_declaration = false; |
| 5477 | DWARFDebugInfoEntry::Attributes attributes; |
| 5478 | const char *type_name_cstr = NULL; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5479 | ConstString type_name_const_str; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5480 | Type::ResolveState resolve_state = Type::eResolveStateUnresolved; |
| Greg Clayton | faac111 | 2013-03-14 18:31:44 +0000 | [diff] [blame] | 5481 | uint64_t byte_size = 0; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5482 | Declaration decl; |
| 5483 | |
| Greg Clayton | 4957bf6 | 2010-09-30 21:49:03 +0000 | [diff] [blame] | 5484 | Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5485 | clang_type_t clang_type = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5486 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5487 | dw_attr_t attr; |
| 5488 | |
| 5489 | switch (tag) |
| 5490 | { |
| 5491 | case DW_TAG_base_type: |
| 5492 | case DW_TAG_pointer_type: |
| 5493 | case DW_TAG_reference_type: |
| Sean Callanan | ce8af86 | 2012-05-21 23:31:51 +0000 | [diff] [blame] | 5494 | case DW_TAG_rvalue_reference_type: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5495 | case DW_TAG_typedef: |
| 5496 | case DW_TAG_const_type: |
| 5497 | case DW_TAG_restrict_type: |
| 5498 | case DW_TAG_volatile_type: |
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5499 | case DW_TAG_unspecified_type: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5500 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5501 | // 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] | 5502 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5503 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5504 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5505 | uint32_t encoding = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5506 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; |
| 5507 | |
| 5508 | if (num_attributes > 0) |
| 5509 | { |
| 5510 | uint32_t i; |
| 5511 | for (i=0; i<num_attributes; ++i) |
| 5512 | { |
| 5513 | attr = attributes.AttributeAtIndex(i); |
| 5514 | DWARFFormValue form_value; |
| 5515 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 5516 | { |
| 5517 | switch (attr) |
| 5518 | { |
| 5519 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 5520 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 5521 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 5522 | case DW_AT_name: |
| Jim Ingham | 337030f | 2011-04-15 23:41:23 +0000 | [diff] [blame] | 5523 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5524 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Jim Ingham | 337030f | 2011-04-15 23:41:23 +0000 | [diff] [blame] | 5525 | // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't |
| 5526 | // include the "&"... |
| 5527 | if (tag == DW_TAG_reference_type) |
| 5528 | { |
| 5529 | if (strchr (type_name_cstr, '&') == NULL) |
| 5530 | type_name_cstr = NULL; |
| 5531 | } |
| 5532 | if (type_name_cstr) |
| 5533 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5534 | break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 5535 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5536 | case DW_AT_encoding: encoding = form_value.Unsigned(); break; |
| 5537 | case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; |
| 5538 | default: |
| 5539 | case DW_AT_sibling: |
| 5540 | break; |
| 5541 | } |
| 5542 | } |
| 5543 | } |
| 5544 | } |
| 5545 | |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5546 | 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] | 5547 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5548 | switch (tag) |
| 5549 | { |
| 5550 | default: |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5551 | break; |
| 5552 | |
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5553 | case DW_TAG_unspecified_type: |
| 5554 | if (strcmp(type_name_cstr, "nullptr_t") == 0) |
| 5555 | { |
| 5556 | resolve_state = Type::eResolveStateFull; |
| 5557 | clang_type = ast.getASTContext()->NullPtrTy.getAsOpaquePtr(); |
| 5558 | break; |
| 5559 | } |
| 5560 | // Fall through to base type below in case we can handle the type there... |
| 5561 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5562 | case DW_TAG_base_type: |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5563 | resolve_state = Type::eResolveStateFull; |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5564 | clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr, |
| 5565 | encoding, |
| 5566 | byte_size * 8); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5567 | break; |
| 5568 | |
| Sean Callanan | ce8af86 | 2012-05-21 23:31:51 +0000 | [diff] [blame] | 5569 | case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break; |
| 5570 | case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break; |
| 5571 | case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break; |
| 5572 | case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break; |
| 5573 | case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break; |
| 5574 | case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break; |
| 5575 | case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5576 | } |
| 5577 | |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5578 | 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] | 5579 | { |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5580 | bool translation_unit_is_objc = (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus); |
| 5581 | |
| 5582 | if (translation_unit_is_objc) |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 5583 | { |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5584 | if (type_name_cstr != NULL) |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5585 | { |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5586 | static ConstString g_objc_type_name_id("id"); |
| 5587 | static ConstString g_objc_type_name_Class("Class"); |
| 5588 | static ConstString g_objc_type_name_selector("SEL"); |
| 5589 | |
| 5590 | if (type_name_const_str == g_objc_type_name_id) |
| 5591 | { |
| 5592 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5593 | 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] | 5594 | die->GetOffset(), |
| 5595 | DW_TAG_value_to_name(die->Tag()), |
| 5596 | die->GetName(this, dwarf_cu)); |
| 5597 | clang_type = ast.GetBuiltInType_objc_id(); |
| 5598 | encoding_data_type = Type::eEncodingIsUID; |
| 5599 | encoding_uid = LLDB_INVALID_UID; |
| 5600 | resolve_state = Type::eResolveStateFull; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5601 | |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5602 | } |
| 5603 | else if (type_name_const_str == g_objc_type_name_Class) |
| 5604 | { |
| 5605 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5606 | 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] | 5607 | die->GetOffset(), |
| 5608 | DW_TAG_value_to_name(die->Tag()), |
| 5609 | die->GetName(this, dwarf_cu)); |
| 5610 | clang_type = ast.GetBuiltInType_objc_Class(); |
| 5611 | encoding_data_type = Type::eEncodingIsUID; |
| 5612 | encoding_uid = LLDB_INVALID_UID; |
| 5613 | resolve_state = Type::eResolveStateFull; |
| 5614 | } |
| 5615 | else if (type_name_const_str == g_objc_type_name_selector) |
| 5616 | { |
| 5617 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5618 | 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] | 5619 | die->GetOffset(), |
| 5620 | DW_TAG_value_to_name(die->Tag()), |
| 5621 | die->GetName(this, dwarf_cu)); |
| 5622 | clang_type = ast.GetBuiltInType_objc_selector(); |
| 5623 | encoding_data_type = Type::eEncodingIsUID; |
| 5624 | encoding_uid = LLDB_INVALID_UID; |
| 5625 | resolve_state = Type::eResolveStateFull; |
| 5626 | } |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5627 | } |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5628 | else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid != LLDB_INVALID_UID) |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5629 | { |
| Sean Callanan | 8258705 | 2013-01-03 00:05:56 +0000 | [diff] [blame] | 5630 | // Clang sometimes erroneously emits id as objc_object*. In that case we fix up the type to "id". |
| 5631 | |
| 5632 | DWARFDebugInfoEntry* encoding_die = dwarf_cu->GetDIEPtr(encoding_uid); |
| 5633 | |
| 5634 | if (encoding_die && encoding_die->Tag() == DW_TAG_structure_type) |
| 5635 | { |
| 5636 | if (const char *struct_name = encoding_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL)) |
| 5637 | { |
| 5638 | if (!strcmp(struct_name, "objc_object")) |
| 5639 | { |
| 5640 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5641 | 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] | 5642 | die->GetOffset(), |
| 5643 | DW_TAG_value_to_name(die->Tag()), |
| 5644 | die->GetName(this, dwarf_cu)); |
| 5645 | clang_type = ast.GetBuiltInType_objc_id(); |
| 5646 | encoding_data_type = Type::eEncodingIsUID; |
| 5647 | encoding_uid = LLDB_INVALID_UID; |
| 5648 | resolve_state = Type::eResolveStateFull; |
| 5649 | } |
| 5650 | } |
| 5651 | } |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5652 | } |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 5653 | } |
| 5654 | } |
| 5655 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5656 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5657 | this, |
| 5658 | type_name_const_str, |
| 5659 | byte_size, |
| 5660 | NULL, |
| 5661 | encoding_uid, |
| 5662 | encoding_data_type, |
| 5663 | &decl, |
| 5664 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5665 | resolve_state)); |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5666 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5667 | m_die_to_type[die] = type_sp.get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5668 | |
| 5669 | // Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false); |
| 5670 | // if (encoding_type != NULL) |
| 5671 | // { |
| 5672 | // if (encoding_type != DIE_IS_BEING_PARSED) |
| 5673 | // type_sp->SetEncodingType(encoding_type); |
| 5674 | // else |
| 5675 | // m_indirect_fixups.push_back(type_sp.get()); |
| 5676 | // } |
| 5677 | } |
| 5678 | break; |
| 5679 | |
| 5680 | case DW_TAG_structure_type: |
| 5681 | case DW_TAG_union_type: |
| 5682 | case DW_TAG_class_type: |
| 5683 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5684 | // 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] | 5685 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 5686 | bool byte_size_valid = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5687 | |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5688 | LanguageType class_language = eLanguageTypeUnknown; |
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 5689 | bool is_complete_objc_class = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5690 | //bool struct_is_class = false; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5691 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5692 | if (num_attributes > 0) |
| 5693 | { |
| 5694 | uint32_t i; |
| 5695 | for (i=0; i<num_attributes; ++i) |
| 5696 | { |
| 5697 | attr = attributes.AttributeAtIndex(i); |
| 5698 | DWARFFormValue form_value; |
| 5699 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 5700 | { |
| 5701 | switch (attr) |
| 5702 | { |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5703 | case DW_AT_decl_file: |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5704 | if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid()) |
| 5705 | { |
| 5706 | // llvm-gcc outputs invalid DW_AT_decl_file attributes that always |
| 5707 | // point to the compile unit file, so we clear this invalid value |
| 5708 | // so that we can still unique types efficiently. |
| 5709 | decl.SetFile(FileSpec ("<invalid>", false)); |
| 5710 | } |
| 5711 | else |
| 5712 | decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5713 | break; |
| 5714 | |
| 5715 | case DW_AT_decl_line: |
| 5716 | decl.SetLine(form_value.Unsigned()); |
| 5717 | break; |
| 5718 | |
| 5719 | case DW_AT_decl_column: |
| 5720 | decl.SetColumn(form_value.Unsigned()); |
| 5721 | break; |
| 5722 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5723 | case DW_AT_name: |
| 5724 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5725 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5726 | break; |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5727 | |
| 5728 | case DW_AT_byte_size: |
| 5729 | byte_size = form_value.Unsigned(); |
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 5730 | byte_size_valid = true; |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5731 | break; |
| 5732 | |
| 5733 | case DW_AT_accessibility: |
| 5734 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); |
| 5735 | break; |
| 5736 | |
| 5737 | case DW_AT_declaration: |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 5738 | is_forward_declaration = form_value.Boolean(); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5739 | break; |
| 5740 | |
| 5741 | case DW_AT_APPLE_runtime_class: |
| 5742 | class_language = (LanguageType)form_value.Signed(); |
| 5743 | break; |
| 5744 | |
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 5745 | case DW_AT_APPLE_objc_complete_type: |
| 5746 | is_complete_objc_class = form_value.Signed(); |
| 5747 | break; |
| 5748 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5749 | case DW_AT_allocated: |
| 5750 | case DW_AT_associated: |
| 5751 | case DW_AT_data_location: |
| 5752 | case DW_AT_description: |
| 5753 | case DW_AT_start_scope: |
| 5754 | case DW_AT_visibility: |
| 5755 | default: |
| 5756 | case DW_AT_sibling: |
| 5757 | break; |
| 5758 | } |
| 5759 | } |
| 5760 | } |
| 5761 | } |
| 5762 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5763 | UniqueDWARFASTType unique_ast_entry; |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5764 | |
| Greg Clayton | 123edca | 2012-03-02 00:07:15 +0000 | [diff] [blame] | 5765 | // Only try and unique the type if it has a name. |
| 5766 | if (type_name_const_str && |
| 5767 | GetUniqueDWARFASTTypeMap().Find (type_name_const_str, |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5768 | this, |
| 5769 | dwarf_cu, |
| 5770 | die, |
| 5771 | decl, |
| 5772 | byte_size_valid ? byte_size : -1, |
| 5773 | unique_ast_entry)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5774 | { |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5775 | // We have already parsed this type or from another |
| 5776 | // compile unit. GCC loves to use the "one definition |
| 5777 | // rule" which can result in multiple definitions |
| 5778 | // of the same class over and over in each compile |
| 5779 | // unit. |
| 5780 | type_sp = unique_ast_entry.m_type_sp; |
| 5781 | if (type_sp) |
| Greg Clayton | c615ce4 | 2010-11-09 04:42:43 +0000 | [diff] [blame] | 5782 | { |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5783 | m_die_to_type[die] = type_sp.get(); |
| 5784 | return type_sp; |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5785 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5786 | } |
| 5787 | |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5788 | 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] | 5789 | |
| 5790 | int tag_decl_kind = -1; |
| 5791 | AccessType default_accessibility = eAccessNone; |
| 5792 | if (tag == DW_TAG_structure_type) |
| 5793 | { |
| 5794 | tag_decl_kind = clang::TTK_Struct; |
| 5795 | default_accessibility = eAccessPublic; |
| 5796 | } |
| 5797 | else if (tag == DW_TAG_union_type) |
| 5798 | { |
| 5799 | tag_decl_kind = clang::TTK_Union; |
| 5800 | default_accessibility = eAccessPublic; |
| 5801 | } |
| 5802 | else if (tag == DW_TAG_class_type) |
| 5803 | { |
| 5804 | tag_decl_kind = clang::TTK_Class; |
| 5805 | default_accessibility = eAccessPrivate; |
| 5806 | } |
| Greg Clayton | 3a5f29a | 2011-11-30 02:48:28 +0000 | [diff] [blame] | 5807 | |
| 5808 | if (byte_size_valid && byte_size == 0 && type_name_cstr && |
| 5809 | die->HasChildren() == false && |
| 5810 | sc.comp_unit->GetLanguage() == eLanguageTypeObjC) |
| 5811 | { |
| 5812 | // Work around an issue with clang at the moment where |
| 5813 | // forward declarations for objective C classes are emitted |
| 5814 | // as: |
| 5815 | // DW_TAG_structure_type [2] |
| 5816 | // DW_AT_name( "ForwardObjcClass" ) |
| 5817 | // DW_AT_byte_size( 0x00 ) |
| 5818 | // DW_AT_decl_file( "..." ) |
| 5819 | // DW_AT_decl_line( 1 ) |
| 5820 | // |
| 5821 | // Note that there is no DW_AT_declaration and there are |
| 5822 | // no children, and the byte size is zero. |
| 5823 | is_forward_declaration = true; |
| 5824 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5825 | |
| Sean Callanan | 7457f8d | 2012-04-25 01:03:57 +0000 | [diff] [blame] | 5826 | if (class_language == eLanguageTypeObjC || |
| 5827 | class_language == eLanguageTypeObjC_plus_plus) |
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 5828 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5829 | 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] | 5830 | { |
| 5831 | // We have a valid eSymbolTypeObjCClass class symbol whose |
| 5832 | // name matches the current objective C class that we |
| 5833 | // are trying to find and this DIE isn't the complete |
| 5834 | // definition (we checked is_complete_objc_class above and |
| 5835 | // know it is false), so the real definition is in here somewhere |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5836 | type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true); |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5837 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 5838 | if (!type_sp && GetDebugMapSymfile ()) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5839 | { |
| 5840 | // We weren't able to find a full declaration in |
| 5841 | // this DWARF, see if we have a declaration anywhere |
| 5842 | // else... |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5843 | 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] | 5844 | } |
| 5845 | |
| 5846 | if (type_sp) |
| 5847 | { |
| 5848 | if (log) |
| 5849 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5850 | GetObjectFile()->GetModule()->LogMessage (log, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5851 | "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] | 5852 | this, |
| 5853 | die->GetOffset(), |
| 5854 | DW_TAG_value_to_name(tag), |
| 5855 | type_name_cstr, |
| 5856 | type_sp->GetID()); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5857 | } |
| 5858 | |
| 5859 | // We found a real definition for this type elsewhere |
| 5860 | // so lets use it and cache the fact that we found |
| 5861 | // a complete type for this die |
| 5862 | m_die_to_type[die] = type_sp.get(); |
| 5863 | return type_sp; |
| 5864 | } |
| 5865 | } |
| 5866 | } |
| 5867 | |
| 5868 | |
| 5869 | if (is_forward_declaration) |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5870 | { |
| 5871 | // We have a forward declaration to a type and we need |
| 5872 | // to try and find a full declaration. We look in the |
| 5873 | // current type index just in case we have a forward |
| 5874 | // declaration followed by an actual declarations in the |
| 5875 | // DWARF. If this fails, we need to look elsewhere... |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 5876 | if (log) |
| 5877 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5878 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5879 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type", |
| 5880 | this, |
| 5881 | die->GetOffset(), |
| 5882 | DW_TAG_value_to_name(tag), |
| 5883 | type_name_cstr); |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 5884 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5885 | |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5886 | DWARFDeclContext die_decl_ctx; |
| 5887 | die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx); |
| 5888 | |
| 5889 | //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str); |
| 5890 | type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5891 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 5892 | if (!type_sp && GetDebugMapSymfile ()) |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5893 | { |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5894 | // We weren't able to find a full declaration in |
| 5895 | // this DWARF, see if we have a declaration anywhere |
| 5896 | // else... |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5897 | type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5898 | } |
| 5899 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5900 | if (type_sp) |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5901 | { |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 5902 | if (log) |
| 5903 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5904 | GetObjectFile()->GetModule()->LogMessage (log, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5905 | "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] | 5906 | this, |
| 5907 | die->GetOffset(), |
| 5908 | DW_TAG_value_to_name(tag), |
| 5909 | type_name_cstr, |
| 5910 | type_sp->GetID()); |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 5911 | } |
| 5912 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5913 | // We found a real definition for this type elsewhere |
| 5914 | // so lets use it and cache the fact that we found |
| 5915 | // a complete type for this die |
| 5916 | m_die_to_type[die] = type_sp.get(); |
| 5917 | return type_sp; |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5918 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5919 | } |
| 5920 | assert (tag_decl_kind != -1); |
| 5921 | bool clang_type_was_created = false; |
| 5922 | clang_type = m_forward_decl_die_to_clang_type.lookup (die); |
| 5923 | if (clang_type == NULL) |
| 5924 | { |
| Sean Callanan | 4d04c6a | 2012-02-09 22:54:11 +0000 | [diff] [blame] | 5925 | const DWARFDebugInfoEntry *decl_ctx_die; |
| 5926 | |
| 5927 | clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die); |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 5928 | if (accessibility == eAccessNone && decl_ctx) |
| 5929 | { |
| 5930 | // Check the decl context that contains this class/struct/union. |
| 5931 | // If it is a class we must give it an accessability. |
| 5932 | const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind(); |
| 5933 | if (DeclKindIsCXXClass (containing_decl_kind)) |
| 5934 | accessibility = default_accessibility; |
| 5935 | } |
| 5936 | |
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 5937 | ClangASTMetadata metadata; |
| 5938 | metadata.SetUserID(MakeUserID(die->GetOffset())); |
| 5939 | metadata.SetIsDynamicCXXType(ClassOrStructIsVirtual (dwarf_cu, die)); |
| 5940 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5941 | if (type_name_cstr && strchr (type_name_cstr, '<')) |
| 5942 | { |
| 5943 | ClangASTContext::TemplateParameterInfos template_param_infos; |
| 5944 | if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos)) |
| 5945 | { |
| 5946 | clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx, |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 5947 | accessibility, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5948 | type_name_cstr, |
| 5949 | tag_decl_kind, |
| 5950 | template_param_infos); |
| 5951 | |
| 5952 | clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx, |
| 5953 | class_template_decl, |
| 5954 | tag_decl_kind, |
| 5955 | template_param_infos); |
| 5956 | clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl); |
| 5957 | clang_type_was_created = true; |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 5958 | |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 5959 | GetClangASTContext().SetMetadata (class_template_decl, metadata); |
| 5960 | GetClangASTContext().SetMetadata (class_specialization_decl, metadata); |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5961 | } |
| 5962 | } |
| 5963 | |
| 5964 | if (!clang_type_was_created) |
| 5965 | { |
| 5966 | clang_type_was_created = true; |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 5967 | clang_type = ast.CreateRecordType (decl_ctx, |
| 5968 | accessibility, |
| 5969 | type_name_cstr, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5970 | tag_decl_kind, |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 5971 | class_language, |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 5972 | &metadata); |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5973 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5974 | } |
| 5975 | |
| 5976 | // Store a forward declaration to this class type in case any |
| 5977 | // parameters in any class methods need it for the clang |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 5978 | // types for function prototypes. |
| 5979 | LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5980 | type_sp.reset (new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5981 | this, |
| 5982 | type_name_const_str, |
| 5983 | byte_size, |
| 5984 | NULL, |
| 5985 | LLDB_INVALID_UID, |
| 5986 | Type::eEncodingIsUID, |
| 5987 | &decl, |
| 5988 | clang_type, |
| 5989 | Type::eResolveStateForward)); |
| Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 5990 | |
| 5991 | type_sp->SetIsCompleteObjCClass(is_complete_objc_class); |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5992 | |
| 5993 | |
| 5994 | // Add our type to the unique type map so we don't |
| 5995 | // end up creating many copies of the same type over |
| 5996 | // and over in the ASTContext for our module |
| 5997 | unique_ast_entry.m_type_sp = type_sp; |
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 5998 | unique_ast_entry.m_symfile = this; |
| 5999 | unique_ast_entry.m_cu = dwarf_cu; |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6000 | unique_ast_entry.m_die = die; |
| 6001 | unique_ast_entry.m_declaration = decl; |
| Sean Callanan | 5970059 | 2012-02-13 22:30:16 +0000 | [diff] [blame] | 6002 | unique_ast_entry.m_byte_size = byte_size; |
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 6003 | GetUniqueDWARFASTTypeMap().Insert (type_name_const_str, |
| 6004 | unique_ast_entry); |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6005 | |
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6006 | if (!is_forward_declaration) |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 6007 | { |
| 6008 | // Always start the definition for a class type so that |
| 6009 | // if the class has child classes or types that require |
| 6010 | // the class to be created for use as their decl contexts |
| 6011 | // the class will be ready to accept these child definitions. |
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6012 | if (die->HasChildren() == false) |
| 6013 | { |
| 6014 | // No children for this struct/union/class, lets finish it |
| 6015 | ast.StartTagDeclarationDefinition (clang_type); |
| 6016 | ast.CompleteTagDeclarationDefinition (clang_type); |
| Sean Callanan | 433cd22 | 2012-10-19 01:37:25 +0000 | [diff] [blame] | 6017 | |
| 6018 | if (tag == DW_TAG_structure_type) // this only applies in C |
| 6019 | { |
| 6020 | clang::QualType qual_type = clang::QualType::getFromOpaquePtr (clang_type); |
| 6021 | const clang::RecordType *record_type = qual_type->getAs<clang::RecordType> (); |
| 6022 | |
| 6023 | if (record_type) |
| 6024 | { |
| 6025 | clang::RecordDecl *record_decl = record_type->getDecl(); |
| 6026 | |
| 6027 | if (record_decl) |
| 6028 | { |
| 6029 | LayoutInfo layout_info; |
| 6030 | |
| 6031 | layout_info.alignment = 0; |
| 6032 | layout_info.bit_size = 0; |
| 6033 | |
| 6034 | m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info)); |
| 6035 | } |
| 6036 | } |
| 6037 | } |
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6038 | } |
| 6039 | else if (clang_type_was_created) |
| 6040 | { |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 6041 | // Start the definition if the class is not objective C since |
| 6042 | // the underlying decls respond to isCompleteDefinition(). Objective |
| 6043 | // C decls dont' respond to isCompleteDefinition() so we can't |
| 6044 | // start the declaration definition right away. For C++ classs/union/structs |
| 6045 | // we want to start the definition in case the class is needed as the |
| 6046 | // declaration context for a contained class or type without the need |
| 6047 | // to complete that type.. |
| 6048 | |
| Sean Callanan | 7457f8d | 2012-04-25 01:03:57 +0000 | [diff] [blame] | 6049 | if (class_language != eLanguageTypeObjC && |
| 6050 | class_language != eLanguageTypeObjC_plus_plus) |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 6051 | ast.StartTagDeclarationDefinition (clang_type); |
| 6052 | |
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 6053 | // Leave this as a forward declaration until we need |
| 6054 | // to know the details of the type. lldb_private::Type |
| 6055 | // will automatically call the SymbolFile virtual function |
| 6056 | // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)" |
| 6057 | // When the definition needs to be defined. |
| 6058 | m_forward_decl_die_to_clang_type[die] = clang_type; |
| 6059 | m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die; |
| 6060 | ClangASTContext::SetHasExternalStorage (clang_type, true); |
| 6061 | } |
| Greg Clayton | c615ce4 | 2010-11-09 04:42:43 +0000 | [diff] [blame] | 6062 | } |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 6063 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6064 | } |
| 6065 | break; |
| 6066 | |
| 6067 | case DW_TAG_enumeration_type: |
| 6068 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6069 | // 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] | 6070 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6071 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6072 | lldb::user_id_t encoding_uid = DW_INVALID_OFFSET; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6073 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6074 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6075 | if (num_attributes > 0) |
| 6076 | { |
| 6077 | uint32_t i; |
| 6078 | |
| 6079 | for (i=0; i<num_attributes; ++i) |
| 6080 | { |
| 6081 | attr = attributes.AttributeAtIndex(i); |
| 6082 | DWARFFormValue form_value; |
| 6083 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 6084 | { |
| 6085 | switch (attr) |
| 6086 | { |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 6087 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 6088 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 6089 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6090 | case DW_AT_name: |
| 6091 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6092 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6093 | break; |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 6094 | case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6095 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; |
| 6096 | case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 6097 | case DW_AT_declaration: break; //is_forward_declaration = form_value.Boolean(); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6098 | case DW_AT_allocated: |
| 6099 | case DW_AT_associated: |
| 6100 | case DW_AT_bit_stride: |
| 6101 | case DW_AT_byte_stride: |
| 6102 | case DW_AT_data_location: |
| 6103 | case DW_AT_description: |
| 6104 | case DW_AT_start_scope: |
| 6105 | case DW_AT_visibility: |
| 6106 | case DW_AT_specification: |
| 6107 | case DW_AT_abstract_origin: |
| 6108 | case DW_AT_sibling: |
| 6109 | break; |
| 6110 | } |
| 6111 | } |
| 6112 | } |
| 6113 | |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6114 | 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] | 6115 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6116 | clang_type_t enumerator_clang_type = NULL; |
| 6117 | clang_type = m_forward_decl_die_to_clang_type.lookup (die); |
| 6118 | if (clang_type == NULL) |
| 6119 | { |
| Greg Clayton | 5d14fc0 | 2013-03-06 06:23:54 +0000 | [diff] [blame] | 6120 | if (encoding_uid != DW_INVALID_OFFSET) |
| 6121 | { |
| 6122 | Type *enumerator_type = ResolveTypeUID(encoding_uid); |
| 6123 | if (enumerator_type) |
| 6124 | enumerator_clang_type = enumerator_type->GetClangFullType(); |
| 6125 | } |
| 6126 | |
| 6127 | if (enumerator_clang_type == NULL) |
| 6128 | enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL, |
| 6129 | DW_ATE_signed, |
| 6130 | byte_size * 8); |
| 6131 | |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 6132 | clang_type = ast.CreateEnumerationType (type_name_cstr, |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6133 | GetClangDeclContextContainingDIE (dwarf_cu, die, NULL), |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 6134 | decl, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6135 | enumerator_clang_type); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6136 | } |
| 6137 | else |
| 6138 | { |
| 6139 | enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6140 | } |
| 6141 | |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6142 | LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die); |
| 6143 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6144 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6145 | this, |
| 6146 | type_name_const_str, |
| 6147 | byte_size, |
| 6148 | NULL, |
| 6149 | encoding_uid, |
| 6150 | Type::eEncodingIsUID, |
| 6151 | &decl, |
| 6152 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6153 | Type::eResolveStateForward)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6154 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 6155 | ast.StartTagDeclarationDefinition (clang_type); |
| 6156 | if (die->HasChildren()) |
| 6157 | { |
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 6158 | SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); |
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 6159 | bool is_signed = false; |
| Greg Clayton | 5d14fc0 | 2013-03-06 06:23:54 +0000 | [diff] [blame] | 6160 | ast.IsIntegerType(enumerator_clang_type, is_signed); |
| Greg Clayton | 3e06753 | 2013-03-05 23:54:39 +0000 | [diff] [blame] | 6161 | 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] | 6162 | } |
| 6163 | ast.CompleteTagDeclarationDefinition (clang_type); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6164 | } |
| 6165 | } |
| 6166 | break; |
| 6167 | |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 6168 | case DW_TAG_inlined_subroutine: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6169 | case DW_TAG_subprogram: |
| 6170 | case DW_TAG_subroutine_type: |
| 6171 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6172 | // 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] | 6173 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6174 | |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6175 | //const char *mangled = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6176 | dw_offset_t type_die_offset = DW_INVALID_OFFSET; |
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 6177 | bool is_variadic = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6178 | bool is_inline = false; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6179 | bool is_static = false; |
| 6180 | bool is_virtual = false; |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6181 | bool is_explicit = false; |
| Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 6182 | bool is_artificial = false; |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6183 | dw_offset_t specification_die_offset = DW_INVALID_OFFSET; |
| 6184 | dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET; |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6185 | dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6186 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6187 | unsigned type_quals = 0; |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 6188 | clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6189 | |
| 6190 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6191 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6192 | if (num_attributes > 0) |
| 6193 | { |
| 6194 | uint32_t i; |
| 6195 | for (i=0; i<num_attributes; ++i) |
| 6196 | { |
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 6197 | attr = attributes.AttributeAtIndex(i); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6198 | DWARFFormValue form_value; |
| 6199 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 6200 | { |
| 6201 | switch (attr) |
| 6202 | { |
| 6203 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 6204 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 6205 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 6206 | case DW_AT_name: |
| 6207 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6208 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6209 | break; |
| 6210 | |
| Greg Clayton | 7141554 | 2012-12-08 00:24:40 +0000 | [diff] [blame] | 6211 | case DW_AT_linkage_name: |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6212 | 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] | 6213 | 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] | 6214 | case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 6215 | case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break; |
| 6216 | case DW_AT_inline: is_inline = form_value.Boolean(); break; |
| 6217 | case DW_AT_virtuality: is_virtual = form_value.Boolean(); break; |
| 6218 | case DW_AT_explicit: is_explicit = form_value.Boolean(); break; |
| 6219 | case DW_AT_artificial: is_artificial = form_value.Boolean(); break; |
| Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 6220 | |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6221 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6222 | case DW_AT_external: |
| 6223 | if (form_value.Unsigned()) |
| 6224 | { |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 6225 | if (storage == clang::SC_None) |
| 6226 | storage = clang::SC_Extern; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6227 | else |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 6228 | storage = clang::SC_PrivateExtern; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6229 | } |
| 6230 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6231 | |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6232 | case DW_AT_specification: |
| 6233 | specification_die_offset = form_value.Reference(dwarf_cu); |
| 6234 | break; |
| 6235 | |
| 6236 | case DW_AT_abstract_origin: |
| 6237 | abstract_origin_die_offset = form_value.Reference(dwarf_cu); |
| 6238 | break; |
| 6239 | |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6240 | case DW_AT_object_pointer: |
| 6241 | object_pointer_die_offset = form_value.Reference(dwarf_cu); |
| 6242 | break; |
| 6243 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6244 | case DW_AT_allocated: |
| 6245 | case DW_AT_associated: |
| 6246 | case DW_AT_address_class: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6247 | case DW_AT_calling_convention: |
| 6248 | case DW_AT_data_location: |
| 6249 | case DW_AT_elemental: |
| 6250 | case DW_AT_entry_pc: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6251 | case DW_AT_frame_base: |
| 6252 | case DW_AT_high_pc: |
| 6253 | case DW_AT_low_pc: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6254 | case DW_AT_prototyped: |
| 6255 | case DW_AT_pure: |
| 6256 | case DW_AT_ranges: |
| 6257 | case DW_AT_recursive: |
| 6258 | case DW_AT_return_addr: |
| 6259 | case DW_AT_segment: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6260 | case DW_AT_start_scope: |
| 6261 | case DW_AT_static_link: |
| 6262 | case DW_AT_trampoline: |
| 6263 | case DW_AT_visibility: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6264 | case DW_AT_vtable_elem_location: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6265 | case DW_AT_description: |
| 6266 | case DW_AT_sibling: |
| 6267 | break; |
| 6268 | } |
| 6269 | } |
| 6270 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6271 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6272 | |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6273 | std::string object_pointer_name; |
| 6274 | if (object_pointer_die_offset != DW_INVALID_OFFSET) |
| 6275 | { |
| 6276 | // Get the name from the object pointer die |
| 6277 | StreamString s; |
| 6278 | if (DWARFDebugInfoEntry::GetName (this, dwarf_cu, object_pointer_die_offset, s)) |
| 6279 | { |
| 6280 | object_pointer_name.assign(s.GetData()); |
| 6281 | } |
| 6282 | } |
| 6283 | |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6284 | 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] | 6285 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6286 | clang_type_t return_clang_type = NULL; |
| 6287 | Type *func_type = NULL; |
| 6288 | |
| 6289 | if (type_die_offset != DW_INVALID_OFFSET) |
| 6290 | func_type = ResolveTypeUID(type_die_offset); |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6291 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6292 | if (func_type) |
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 6293 | return_clang_type = func_type->GetClangForwardType(); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6294 | else |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6295 | return_clang_type = ast.GetBuiltInType_void(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6296 | |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 6297 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6298 | std::vector<clang_type_t> function_param_types; |
| 6299 | std::vector<clang::ParmVarDecl*> function_param_decls; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6300 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6301 | // Parse the function children for the parameters |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 6302 | |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6303 | const DWARFDebugInfoEntry *decl_ctx_die = NULL; |
| 6304 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die); |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6305 | const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind(); |
| 6306 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 6307 | const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind); |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6308 | // Start off static. This will be set to false in ParseChildParameters(...) |
| 6309 | // if we find a "this" paramters as the first parameter |
| 6310 | if (is_cxx_method) |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 6311 | is_static = true; |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 6312 | ClangASTContext::TemplateParameterInfos template_param_infos; |
| 6313 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6314 | if (die->HasChildren()) |
| 6315 | { |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6316 | bool skip_artificial = true; |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6317 | ParseChildParameters (sc, |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6318 | containing_decl_ctx, |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6319 | dwarf_cu, |
| 6320 | die, |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 6321 | skip_artificial, |
| 6322 | is_static, |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6323 | type_list, |
| 6324 | function_param_types, |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 6325 | function_param_decls, |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 6326 | type_quals, |
| 6327 | template_param_infos); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6328 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6329 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6330 | // clang_type will get the function prototype clang type after this call |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6331 | clang_type = ast.CreateFunctionType (return_clang_type, |
| Greg Clayton | 9cb25c4 | 2012-10-30 17:02:18 +0000 | [diff] [blame] | 6332 | function_param_types.data(), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6333 | function_param_types.size(), |
| 6334 | is_variadic, |
| 6335 | type_quals); |
| 6336 | |
| Sean Callanan | de9ce87 | 2013-05-09 23:13:13 +0000 | [diff] [blame] | 6337 | bool ignore_containing_context = false; |
| 6338 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6339 | if (type_name_cstr) |
| 6340 | { |
| 6341 | bool type_handled = false; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6342 | if (tag == DW_TAG_subprogram) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6343 | { |
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 6344 | ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true); |
| 6345 | if (objc_method.IsValid(true)) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6346 | { |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6347 | SymbolContext empty_sc; |
| 6348 | clang_type_t class_opaque_type = NULL; |
| Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 6349 | ConstString class_name(objc_method.GetClassName()); |
| Greg Clayton | 7c81042 | 2012-01-18 23:40:49 +0000 | [diff] [blame] | 6350 | if (class_name) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6351 | { |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6352 | TypeList types; |
| Greg Clayton | 278a16b | 2012-01-19 00:52:59 +0000 | [diff] [blame] | 6353 | TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false)); |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6354 | |
| 6355 | if (complete_objc_class_type_sp) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6356 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 6357 | clang_type_t type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType(); |
| 6358 | if (ClangASTContext::IsObjCClassType (type_clang_forward_type)) |
| 6359 | class_opaque_type = type_clang_forward_type; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6360 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6361 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6362 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6363 | if (class_opaque_type) |
| 6364 | { |
| 6365 | // If accessibility isn't set to anything valid, assume public for |
| 6366 | // now... |
| 6367 | if (accessibility == eAccessNone) |
| 6368 | accessibility = eAccessPublic; |
| 6369 | |
| Sean Callanan | 464a5b5 | 2012-10-04 22:06:29 +0000 | [diff] [blame] | 6370 | clang::ObjCMethodDecl *objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type, |
| 6371 | type_name_cstr, |
| 6372 | clang_type, |
| Greg Clayton | 1bbcc03 | 2013-03-08 02:42:06 +0000 | [diff] [blame] | 6373 | accessibility, |
| 6374 | is_artificial); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6375 | type_handled = objc_method_decl != NULL; |
| Sean Callanan | 464a5b5 | 2012-10-04 22:06:29 +0000 | [diff] [blame] | 6376 | if (type_handled) |
| 6377 | { |
| 6378 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die); |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6379 | GetClangASTContext().SetMetadataAsUserID (objc_method_decl, MakeUserID(die->GetOffset())); |
| Sean Callanan | 464a5b5 | 2012-10-04 22:06:29 +0000 | [diff] [blame] | 6380 | } |
| Sean Callanan | c3a1d56 | 2013-02-06 23:21:59 +0000 | [diff] [blame] | 6381 | else |
| 6382 | { |
| Jason Molenda | c1a6583 | 2013-03-07 22:44:42 +0000 | [diff] [blame] | 6383 | 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] | 6384 | die->GetOffset(), |
| 6385 | tag, |
| 6386 | DW_TAG_value_to_name(tag)); |
| 6387 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6388 | } |
| 6389 | } |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 6390 | else if (is_cxx_method) |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6391 | { |
| 6392 | // Look at the parent of this DIE and see if is is |
| 6393 | // a class or struct and see if this is actually a |
| 6394 | // C++ method |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6395 | Type *class_type = ResolveType (dwarf_cu, decl_ctx_die); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6396 | if (class_type) |
| 6397 | { |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6398 | if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset())) |
| 6399 | { |
| 6400 | // We uniqued the parent class of this function to another class |
| 6401 | // so we now need to associate all dies under "decl_ctx_die" to |
| 6402 | // DIEs in the DIE for "class_type"... |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 6403 | SymbolFileDWARF *class_symfile = NULL; |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6404 | DWARFCompileUnitSP class_type_cu_sp; |
| Greg Clayton | 5d650c6a | 2013-02-26 01:31:37 +0000 | [diff] [blame] | 6405 | const DWARFDebugInfoEntry *class_type_die = NULL; |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6406 | |
| 6407 | SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile(); |
| 6408 | if (debug_map_symfile) |
| 6409 | { |
| 6410 | class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID())); |
| 6411 | class_type_die = class_symfile->DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp); |
| 6412 | } |
| 6413 | else |
| 6414 | { |
| 6415 | class_symfile = this; |
| 6416 | class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp); |
| 6417 | } |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6418 | if (class_type_die) |
| 6419 | { |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6420 | llvm::SmallVector<const DWARFDebugInfoEntry *, 0> failures; |
| 6421 | |
| 6422 | CopyUniqueClassMethodTypes (class_symfile, |
| 6423 | class_type, |
| 6424 | class_type_cu_sp.get(), |
| 6425 | class_type_die, |
| 6426 | dwarf_cu, |
| 6427 | decl_ctx_die, |
| 6428 | failures); |
| 6429 | |
| 6430 | // FIXME do something with these failures that's smarter than |
| 6431 | // just dropping them on the ground. Unfortunately classes don't |
| 6432 | // like having stuff added to them after their definitions are |
| 6433 | // complete... |
| 6434 | |
| 6435 | type_ptr = m_die_to_type[die]; |
| 6436 | if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6437 | { |
| Sean Callanan | 2367f8a | 2013-02-26 01:12:25 +0000 | [diff] [blame] | 6438 | type_sp = type_ptr->shared_from_this(); |
| 6439 | break; |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6440 | } |
| 6441 | } |
| 6442 | } |
| 6443 | |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6444 | if (specification_die_offset != DW_INVALID_OFFSET) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6445 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6446 | // We have a specification which we are going to base our function |
| 6447 | // prototype off of, so we need this type to be completed so that the |
| 6448 | // m_die_to_decl_ctx for the method in the specification has a valid |
| 6449 | // clang decl context. |
| Greg Clayton | 8eb732e | 2011-12-13 04:34:06 +0000 | [diff] [blame] | 6450 | class_type->GetClangForwardType(); |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6451 | // If we have a specification, then the function type should have been |
| 6452 | // made with the specification and not with this die. |
| 6453 | DWARFCompileUnitSP spec_cu_sp; |
| 6454 | const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp); |
| Eric Christopher | 6cc6e60 | 2012-03-25 19:37:33 +0000 | [diff] [blame] | 6455 | clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die); |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6456 | if (spec_clang_decl_ctx) |
| 6457 | { |
| 6458 | LinkDeclContextToDIE(spec_clang_decl_ctx, die); |
| 6459 | } |
| 6460 | else |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6461 | { |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6462 | 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] | 6463 | MakeUserID(die->GetOffset()), |
| 6464 | specification_die_offset); |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6465 | } |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6466 | type_handled = true; |
| 6467 | } |
| 6468 | else if (abstract_origin_die_offset != DW_INVALID_OFFSET) |
| 6469 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6470 | // We have a specification which we are going to base our function |
| 6471 | // prototype off of, so we need this type to be completed so that the |
| 6472 | // m_die_to_decl_ctx for the method in the abstract origin has a valid |
| 6473 | // clang decl context. |
| Greg Clayton | 8eb732e | 2011-12-13 04:34:06 +0000 | [diff] [blame] | 6474 | class_type->GetClangForwardType(); |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6475 | |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6476 | DWARFCompileUnitSP abs_cu_sp; |
| 6477 | 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] | 6478 | clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die); |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6479 | if (abs_clang_decl_ctx) |
| 6480 | { |
| 6481 | LinkDeclContextToDIE (abs_clang_decl_ctx, die); |
| 6482 | } |
| 6483 | else |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6484 | { |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6485 | 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] | 6486 | MakeUserID(die->GetOffset()), |
| 6487 | abstract_origin_die_offset); |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6488 | } |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6489 | type_handled = true; |
| 6490 | } |
| 6491 | else |
| 6492 | { |
| 6493 | clang_type_t class_opaque_type = class_type->GetClangForwardType(); |
| 6494 | if (ClangASTContext::IsCXXClassType (class_opaque_type)) |
| Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 6495 | { |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6496 | if (ClangASTContext::IsBeingDefined (class_opaque_type)) |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6497 | { |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6498 | // Neither GCC 4.2 nor clang++ currently set a valid accessibility |
| 6499 | // in the DWARF for C++ methods... Default to public for now... |
| 6500 | if (accessibility == eAccessNone) |
| 6501 | accessibility = eAccessPublic; |
| 6502 | |
| 6503 | if (!is_static && !die->HasChildren()) |
| 6504 | { |
| 6505 | // We have a C++ member function with no children (this pointer!) |
| 6506 | // and clang will get mad if we try and make a function that isn't |
| 6507 | // well formed in the DWARF, so we will just skip it... |
| 6508 | type_handled = true; |
| 6509 | } |
| 6510 | else |
| 6511 | { |
| 6512 | clang::CXXMethodDecl *cxx_method_decl; |
| 6513 | // REMOVE THE CRASH DESCRIPTION BELOW |
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 6514 | Host::SetCrashDescriptionWithFormat ("SymbolFileDWARF::ParseType() is adding a method %s to class %s in DIE 0x%8.8" PRIx64 " from %s", |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6515 | type_name_cstr, |
| 6516 | class_type->GetName().GetCString(), |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6517 | MakeUserID(die->GetOffset()), |
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 6518 | m_obj_file->GetFileSpec().GetPath().c_str()); |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6519 | |
| Sean Callanan | c1b732d | 2011-11-01 18:07:13 +0000 | [diff] [blame] | 6520 | const bool is_attr_used = false; |
| 6521 | |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6522 | cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type, |
| 6523 | type_name_cstr, |
| 6524 | clang_type, |
| 6525 | accessibility, |
| 6526 | is_virtual, |
| 6527 | is_static, |
| 6528 | is_inline, |
| Sean Callanan | c1b732d | 2011-11-01 18:07:13 +0000 | [diff] [blame] | 6529 | is_explicit, |
| Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 6530 | is_attr_used, |
| 6531 | is_artificial); |
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6532 | |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6533 | type_handled = cxx_method_decl != NULL; |
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6534 | |
| 6535 | if (type_handled) |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6536 | { |
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6537 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die); |
| 6538 | |
| 6539 | Host::SetCrashDescription (NULL); |
| 6540 | |
| 6541 | |
| 6542 | ClangASTMetadata metadata; |
| 6543 | metadata.SetUserID(MakeUserID(die->GetOffset())); |
| 6544 | |
| 6545 | if (!object_pointer_name.empty()) |
| 6546 | { |
| 6547 | metadata.SetObjectPtrName(object_pointer_name.c_str()); |
| 6548 | if (log) |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6549 | log->Printf ("Setting object pointer name: %s on method object %p.\n", |
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6550 | object_pointer_name.c_str(), |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6551 | cxx_method_decl); |
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame] | 6552 | } |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6553 | GetClangASTContext().SetMetadata (cxx_method_decl, metadata); |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6554 | } |
| Sean Callanan | b0640dc | 2013-04-09 23:22:08 +0000 | [diff] [blame] | 6555 | else |
| 6556 | { |
| Sean Callanan | de9ce87 | 2013-05-09 23:13:13 +0000 | [diff] [blame] | 6557 | ignore_containing_context = true; |
| Sean Callanan | b0640dc | 2013-04-09 23:22:08 +0000 | [diff] [blame] | 6558 | } |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6559 | } |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6560 | } |
| 6561 | else |
| 6562 | { |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6563 | // We were asked to parse the type for a method in a class, yet the |
| 6564 | // class hasn't been asked to complete itself through the |
| 6565 | // clang::ExternalASTSource protocol, so we need to just have the |
| 6566 | // class complete itself and do things the right way, then our |
| 6567 | // DIE should then have an entry in the m_die_to_type map. First |
| 6568 | // we need to modify the m_die_to_type so it doesn't think we are |
| 6569 | // trying to parse this DIE anymore... |
| 6570 | m_die_to_type[die] = NULL; |
| 6571 | |
| 6572 | // Now we get the full type to force our class type to complete itself |
| 6573 | // using the clang::ExternalASTSource protocol which will parse all |
| 6574 | // base classes and all methods (including the method for this DIE). |
| 6575 | class_type->GetClangFullType(); |
| Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 6576 | |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6577 | // The type for this DIE should have been filled in the function call above |
| 6578 | type_ptr = m_die_to_type[die]; |
| Greg Clayton | e5476db | 2012-06-01 20:32:35 +0000 | [diff] [blame] | 6579 | if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6580 | { |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 6581 | type_sp = type_ptr->shared_from_this(); |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6582 | break; |
| 6583 | } |
| Sean Callanan | 02eee4d | 2012-04-12 23:10:00 +0000 | [diff] [blame] | 6584 | |
| 6585 | // FIXME This is fixing some even uglier behavior but we really need to |
| 6586 | // uniq the methods of each class as well as the class itself. |
| 6587 | // <rdar://problem/11240464> |
| 6588 | type_handled = true; |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6589 | } |
| Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 6590 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6591 | } |
| 6592 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6593 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6594 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6595 | |
| 6596 | if (!type_handled) |
| 6597 | { |
| 6598 | // We just have a function that isn't part of a class |
| Sean Callanan | de9ce87 | 2013-05-09 23:13:13 +0000 | [diff] [blame] | 6599 | clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (ignore_containing_context ? GetClangASTContext().GetTranslationUnitDecl() : containing_decl_ctx, |
| Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 6600 | type_name_cstr, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6601 | clang_type, |
| 6602 | storage, |
| 6603 | is_inline); |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 6604 | |
| 6605 | // if (template_param_infos.GetSize() > 0) |
| 6606 | // { |
| 6607 | // clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx, |
| 6608 | // function_decl, |
| 6609 | // type_name_cstr, |
| 6610 | // template_param_infos); |
| 6611 | // |
| 6612 | // ast.CreateFunctionTemplateSpecializationInfo (function_decl, |
| 6613 | // func_template_decl, |
| 6614 | // template_param_infos); |
| 6615 | // } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6616 | // Add the decl to our DIE to decl context map |
| 6617 | assert (function_decl); |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6618 | LinkDeclContextToDIE(function_decl, die); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6619 | if (!function_param_decls.empty()) |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6620 | ast.SetFunctionParameters (function_decl, |
| 6621 | &function_param_decls.front(), |
| 6622 | function_param_decls.size()); |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 6623 | |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6624 | ClangASTMetadata metadata; |
| 6625 | metadata.SetUserID(MakeUserID(die->GetOffset())); |
| 6626 | |
| 6627 | if (!object_pointer_name.empty()) |
| 6628 | { |
| 6629 | metadata.SetObjectPtrName(object_pointer_name.c_str()); |
| Jim Ingham | 2cffda3f | 2012-10-30 23:34:07 +0000 | [diff] [blame] | 6630 | if (log) |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6631 | log->Printf ("Setting object pointer name: %s on function object %p.", |
| Jim Ingham | 2cffda3f | 2012-10-30 23:34:07 +0000 | [diff] [blame] | 6632 | object_pointer_name.c_str(), |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6633 | function_decl); |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6634 | } |
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 6635 | GetClangASTContext().SetMetadata (function_decl, metadata); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6636 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6637 | } |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6638 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6639 | this, |
| 6640 | type_name_const_str, |
| 6641 | 0, |
| 6642 | NULL, |
| 6643 | LLDB_INVALID_UID, |
| 6644 | Type::eEncodingIsUID, |
| 6645 | &decl, |
| 6646 | clang_type, |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6647 | Type::eResolveStateFull)); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6648 | assert(type_sp.get()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6649 | } |
| 6650 | break; |
| 6651 | |
| 6652 | case DW_TAG_array_type: |
| 6653 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6654 | // 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] | 6655 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6656 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6657 | lldb::user_id_t type_die_offset = DW_INVALID_OFFSET; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6658 | int64_t first_index = 0; |
| 6659 | uint32_t byte_stride = 0; |
| 6660 | uint32_t bit_stride = 0; |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 6661 | bool is_vector = false; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6662 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6663 | |
| 6664 | if (num_attributes > 0) |
| 6665 | { |
| 6666 | uint32_t i; |
| 6667 | for (i=0; i<num_attributes; ++i) |
| 6668 | { |
| 6669 | attr = attributes.AttributeAtIndex(i); |
| 6670 | DWARFFormValue form_value; |
| 6671 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 6672 | { |
| 6673 | switch (attr) |
| 6674 | { |
| 6675 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 6676 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 6677 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 6678 | case DW_AT_name: |
| 6679 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6680 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6681 | break; |
| 6682 | |
| 6683 | 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] | 6684 | case DW_AT_byte_size: break; // byte_size = form_value.Unsigned(); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6685 | case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break; |
| 6686 | case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break; |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 6687 | case DW_AT_GNU_vector: is_vector = form_value.Boolean(); break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6688 | case DW_AT_accessibility: break; // accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 6689 | case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6690 | case DW_AT_allocated: |
| 6691 | case DW_AT_associated: |
| 6692 | case DW_AT_data_location: |
| 6693 | case DW_AT_description: |
| 6694 | case DW_AT_ordering: |
| 6695 | case DW_AT_start_scope: |
| 6696 | case DW_AT_visibility: |
| 6697 | case DW_AT_specification: |
| 6698 | case DW_AT_abstract_origin: |
| 6699 | case DW_AT_sibling: |
| 6700 | break; |
| 6701 | } |
| 6702 | } |
| 6703 | } |
| 6704 | |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6705 | 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] | 6706 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6707 | Type *element_type = ResolveTypeUID(type_die_offset); |
| 6708 | |
| 6709 | if (element_type) |
| 6710 | { |
| 6711 | std::vector<uint64_t> element_orders; |
| 6712 | ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride); |
| 6713 | if (byte_stride == 0 && bit_stride == 0) |
| 6714 | byte_stride = element_type->GetByteSize(); |
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 6715 | clang_type_t array_element_type = element_type->GetClangForwardType(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6716 | uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride; |
| 6717 | uint64_t num_elements = 0; |
| 6718 | std::vector<uint64_t>::const_reverse_iterator pos; |
| 6719 | std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend(); |
| 6720 | for (pos = element_orders.rbegin(); pos != end; ++pos) |
| 6721 | { |
| 6722 | num_elements = *pos; |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6723 | clang_type = ast.CreateArrayType (array_element_type, |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 6724 | num_elements, |
| 6725 | is_vector); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6726 | array_element_type = clang_type; |
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 6727 | 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] | 6728 | } |
| 6729 | ConstString empty_name; |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6730 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6731 | this, |
| 6732 | empty_name, |
| 6733 | array_element_bit_stride / 8, |
| 6734 | NULL, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6735 | type_die_offset, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6736 | Type::eEncodingIsUID, |
| 6737 | &decl, |
| 6738 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6739 | Type::eResolveStateFull)); |
| 6740 | type_sp->SetEncodingType (element_type); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6741 | } |
| 6742 | } |
| 6743 | } |
| 6744 | break; |
| 6745 | |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6746 | case DW_TAG_ptr_to_member_type: |
| 6747 | { |
| 6748 | dw_offset_t type_die_offset = DW_INVALID_OFFSET; |
| 6749 | dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET; |
| 6750 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6751 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6752 | |
| 6753 | if (num_attributes > 0) { |
| 6754 | uint32_t i; |
| 6755 | for (i=0; i<num_attributes; ++i) |
| 6756 | { |
| 6757 | attr = attributes.AttributeAtIndex(i); |
| 6758 | DWARFFormValue form_value; |
| 6759 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 6760 | { |
| 6761 | switch (attr) |
| 6762 | { |
| 6763 | case DW_AT_type: |
| 6764 | type_die_offset = form_value.Reference(dwarf_cu); break; |
| 6765 | case DW_AT_containing_type: |
| 6766 | containing_type_die_offset = form_value.Reference(dwarf_cu); break; |
| 6767 | } |
| 6768 | } |
| 6769 | } |
| 6770 | |
| 6771 | Type *pointee_type = ResolveTypeUID(type_die_offset); |
| 6772 | Type *class_type = ResolveTypeUID(containing_type_die_offset); |
| 6773 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6774 | clang_type_t pointee_clang_type = pointee_type->GetClangForwardType(); |
| 6775 | clang_type_t class_clang_type = class_type->GetClangLayoutType(); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6776 | |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6777 | clang_type = ast.CreateMemberPointerType(pointee_clang_type, |
| 6778 | class_clang_type); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6779 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6780 | byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(), |
| 6781 | clang_type) / 8; |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6782 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6783 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6784 | this, |
| 6785 | type_name_const_str, |
| 6786 | byte_size, |
| 6787 | NULL, |
| 6788 | LLDB_INVALID_UID, |
| 6789 | Type::eEncodingIsUID, |
| 6790 | NULL, |
| 6791 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6792 | Type::eResolveStateForward)); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6793 | } |
| 6794 | |
| 6795 | break; |
| 6796 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6797 | default: |
| Greg Clayton | 84afacd | 2012-11-07 23:09:32 +0000 | [diff] [blame] | 6798 | 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", |
| 6799 | die->GetOffset(), |
| 6800 | tag, |
| 6801 | DW_TAG_value_to_name(tag)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6802 | break; |
| 6803 | } |
| 6804 | |
| 6805 | if (type_sp.get()) |
| 6806 | { |
| 6807 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); |
| 6808 | dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
| 6809 | |
| 6810 | SymbolContextScope * symbol_context_scope = NULL; |
| 6811 | if (sc_parent_tag == DW_TAG_compile_unit) |
| 6812 | { |
| 6813 | symbol_context_scope = sc.comp_unit; |
| 6814 | } |
| 6815 | else if (sc.function != NULL) |
| 6816 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6817 | 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] | 6818 | if (symbol_context_scope == NULL) |
| 6819 | symbol_context_scope = sc.function; |
| 6820 | } |
| 6821 | |
| 6822 | if (symbol_context_scope != NULL) |
| 6823 | { |
| 6824 | type_sp->SetSymbolContextScope(symbol_context_scope); |
| 6825 | } |
| 6826 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6827 | // We are ready to put this type into the uniqued list up at the module level |
| 6828 | type_list->Insert (type_sp); |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 6829 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6830 | m_die_to_type[die] = type_sp.get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6831 | } |
| 6832 | } |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 6833 | else if (type_ptr != DIE_IS_BEING_PARSED) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6834 | { |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 6835 | type_sp = type_ptr->shared_from_this(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6836 | } |
| 6837 | } |
| 6838 | return type_sp; |
| 6839 | } |
| 6840 | |
| 6841 | size_t |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6842 | SymbolFileDWARF::ParseTypes |
| 6843 | ( |
| 6844 | const SymbolContext& sc, |
| 6845 | DWARFCompileUnit* dwarf_cu, |
| 6846 | const DWARFDebugInfoEntry *die, |
| 6847 | bool parse_siblings, |
| 6848 | bool parse_children |
| 6849 | ) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6850 | { |
| 6851 | size_t types_added = 0; |
| 6852 | while (die != NULL) |
| 6853 | { |
| 6854 | bool type_is_new = false; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6855 | if (ParseType(sc, dwarf_cu, die, &type_is_new).get()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6856 | { |
| 6857 | if (type_is_new) |
| 6858 | ++types_added; |
| 6859 | } |
| 6860 | |
| 6861 | if (parse_children && die->HasChildren()) |
| 6862 | { |
| 6863 | if (die->Tag() == DW_TAG_subprogram) |
| 6864 | { |
| 6865 | SymbolContext child_sc(sc); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6866 | child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6867 | types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true); |
| 6868 | } |
| 6869 | else |
| 6870 | types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true); |
| 6871 | } |
| 6872 | |
| 6873 | if (parse_siblings) |
| 6874 | die = die->GetSibling(); |
| 6875 | else |
| 6876 | die = NULL; |
| 6877 | } |
| 6878 | return types_added; |
| 6879 | } |
| 6880 | |
| 6881 | |
| 6882 | size_t |
| 6883 | SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc) |
| 6884 | { |
| 6885 | assert(sc.comp_unit && sc.function); |
| 6886 | size_t functions_added = 0; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 6887 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6888 | if (dwarf_cu) |
| 6889 | { |
| 6890 | dw_offset_t function_die_offset = sc.function->GetID(); |
| 6891 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset); |
| 6892 | if (function_die) |
| 6893 | { |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 6894 | 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] | 6895 | } |
| 6896 | } |
| 6897 | |
| 6898 | return functions_added; |
| 6899 | } |
| 6900 | |
| 6901 | |
| 6902 | size_t |
| 6903 | SymbolFileDWARF::ParseTypes (const SymbolContext &sc) |
| 6904 | { |
| 6905 | // At least a compile unit must be valid |
| 6906 | assert(sc.comp_unit); |
| 6907 | size_t types_added = 0; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 6908 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6909 | if (dwarf_cu) |
| 6910 | { |
| 6911 | if (sc.function) |
| 6912 | { |
| 6913 | dw_offset_t function_die_offset = sc.function->GetID(); |
| 6914 | const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset); |
| 6915 | if (func_die && func_die->HasChildren()) |
| 6916 | { |
| 6917 | types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true); |
| 6918 | } |
| 6919 | } |
| 6920 | else |
| 6921 | { |
| 6922 | const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE(); |
| 6923 | if (dwarf_cu_die && dwarf_cu_die->HasChildren()) |
| 6924 | { |
| 6925 | types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true); |
| 6926 | } |
| 6927 | } |
| 6928 | } |
| 6929 | |
| 6930 | return types_added; |
| 6931 | } |
| 6932 | |
| 6933 | size_t |
| 6934 | SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc) |
| 6935 | { |
| 6936 | if (sc.comp_unit != NULL) |
| 6937 | { |
| Greg Clayton | 4b3dc10 | 2010-11-01 20:32:12 +0000 | [diff] [blame] | 6938 | DWARFDebugInfo* info = DebugInfo(); |
| 6939 | if (info == NULL) |
| 6940 | return 0; |
| 6941 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6942 | if (sc.function) |
| 6943 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 6944 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnitContainingDIE(sc.function->GetID()).get(); |
| 6945 | |
| 6946 | if (dwarf_cu == NULL) |
| 6947 | return 0; |
| 6948 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6949 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID()); |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 6950 | |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 6951 | dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS); |
| 6952 | if (func_lo_pc != LLDB_INVALID_ADDRESS) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6953 | { |
| 6954 | 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] | 6955 | |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6956 | // Let all blocks know they have parse all their variables |
| 6957 | sc.function->GetBlock (false).SetDidParseVariables (true, true); |
| 6958 | return num_variables; |
| 6959 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6960 | } |
| 6961 | else if (sc.comp_unit) |
| 6962 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 6963 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()).get(); |
| 6964 | |
| 6965 | if (dwarf_cu == NULL) |
| 6966 | return 0; |
| 6967 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6968 | uint32_t vars_added = 0; |
| 6969 | VariableListSP variables (sc.comp_unit->GetVariableList(false)); |
| 6970 | |
| 6971 | if (variables.get() == NULL) |
| 6972 | { |
| 6973 | variables.reset(new VariableList()); |
| 6974 | sc.comp_unit->SetVariableList(variables); |
| 6975 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 6976 | DWARFCompileUnit* match_dwarf_cu = NULL; |
| 6977 | const DWARFDebugInfoEntry* die = NULL; |
| 6978 | DIEArray die_offsets; |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 6979 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6980 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 6981 | if (m_apple_names_ap.get()) |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6982 | { |
| 6983 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 6984 | if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(), |
| 6985 | dwarf_cu->GetNextCompileUnitOffset(), |
| 6986 | hash_data_array)) |
| 6987 | { |
| 6988 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| 6989 | } |
| 6990 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6991 | } |
| 6992 | else |
| 6993 | { |
| 6994 | // Index if we already haven't to make sure the compile units |
| 6995 | // get indexed and make their global DIE index list |
| 6996 | if (!m_indexed) |
| 6997 | Index (); |
| 6998 | |
| 6999 | m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(), |
| 7000 | dwarf_cu->GetNextCompileUnitOffset(), |
| 7001 | die_offsets); |
| 7002 | } |
| 7003 | |
| 7004 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7005 | if (num_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7006 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7007 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 7008 | for (size_t i=0; i<num_matches; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7009 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7010 | const dw_offset_t die_offset = die_offsets[i]; |
| 7011 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 7012 | if (die) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7013 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 7014 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS)); |
| 7015 | if (var_sp) |
| 7016 | { |
| 7017 | variables->AddVariableIfUnique (var_sp); |
| 7018 | ++vars_added; |
| 7019 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7020 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 7021 | else |
| 7022 | { |
| 7023 | if (m_using_apple_tables) |
| 7024 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 7025 | 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] | 7026 | } |
| 7027 | } |
| 7028 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7029 | } |
| 7030 | } |
| 7031 | } |
| 7032 | return vars_added; |
| 7033 | } |
| 7034 | } |
| 7035 | return 0; |
| 7036 | } |
| 7037 | |
| 7038 | |
| 7039 | VariableSP |
| 7040 | SymbolFileDWARF::ParseVariableDIE |
| 7041 | ( |
| 7042 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 7043 | DWARFCompileUnit* dwarf_cu, |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 7044 | const DWARFDebugInfoEntry *die, |
| 7045 | const lldb::addr_t func_low_pc |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7046 | ) |
| 7047 | { |
| 7048 | |
| Greg Clayton | 83c5cd9 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 7049 | VariableSP var_sp (m_die_to_variable_sp[die]); |
| 7050 | if (var_sp) |
| 7051 | return var_sp; // Already been parsed! |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7052 | |
| 7053 | const dw_tag_t tag = die->Tag(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7054 | |
| 7055 | if ((tag == DW_TAG_variable) || |
| 7056 | (tag == DW_TAG_constant) || |
| 7057 | (tag == DW_TAG_formal_parameter && sc.function)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7058 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7059 | DWARFDebugInfoEntry::Attributes attributes; |
| 7060 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| 7061 | if (num_attributes > 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7062 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7063 | const char *name = NULL; |
| 7064 | const char *mangled = NULL; |
| 7065 | Declaration decl; |
| 7066 | uint32_t i; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7067 | lldb::user_id_t type_uid = LLDB_INVALID_UID; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7068 | DWARFExpression location; |
| 7069 | bool is_external = false; |
| 7070 | bool is_artificial = false; |
| 7071 | bool location_is_const_value_data = false; |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7072 | bool has_explicit_location = false; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 7073 | //AccessType accessibility = eAccessNone; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7074 | |
| 7075 | for (i=0; i<num_attributes; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7076 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7077 | dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 7078 | DWARFFormValue form_value; |
| 7079 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7080 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7081 | switch (attr) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7082 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7083 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 7084 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 7085 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 7086 | 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] | 7087 | case DW_AT_linkage_name: |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7088 | 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] | 7089 | case DW_AT_type: type_uid = form_value.Reference(dwarf_cu); break; |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 7090 | case DW_AT_external: is_external = form_value.Boolean(); break; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7091 | case DW_AT_const_value: |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7092 | // If we have already found a DW_AT_location attribute, ignore this attribute. |
| 7093 | if (!has_explicit_location) |
| 7094 | { |
| 7095 | location_is_const_value_data = true; |
| 7096 | // The constant value will be either a block, a data value or a string. |
| 7097 | const DataExtractor& debug_info_data = get_debug_info_data(); |
| 7098 | if (DWARFFormValue::IsBlockForm(form_value.Form())) |
| 7099 | { |
| 7100 | // Retrieve the value as a block expression. |
| 7101 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 7102 | uint32_t block_length = form_value.Unsigned(); |
| 7103 | location.CopyOpcodeData(debug_info_data, block_offset, block_length); |
| 7104 | } |
| 7105 | else if (DWARFFormValue::IsDataForm(form_value.Form())) |
| 7106 | { |
| 7107 | // Retrieve the value as a data expression. |
| 7108 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| 7109 | uint32_t data_offset = attributes.DIEOffsetAtIndex(i); |
| 7110 | uint32_t data_length = fixed_form_sizes[form_value.Form()]; |
| 7111 | location.CopyOpcodeData(debug_info_data, data_offset, data_length); |
| 7112 | } |
| 7113 | else |
| 7114 | { |
| 7115 | // Retrieve the value as a string expression. |
| 7116 | if (form_value.Form() == DW_FORM_strp) |
| 7117 | { |
| 7118 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| 7119 | uint32_t data_offset = attributes.DIEOffsetAtIndex(i); |
| 7120 | uint32_t data_length = fixed_form_sizes[form_value.Form()]; |
| 7121 | location.CopyOpcodeData(debug_info_data, data_offset, data_length); |
| 7122 | } |
| 7123 | else |
| 7124 | { |
| 7125 | const char *str = form_value.AsCString(&debug_info_data); |
| 7126 | uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart(); |
| 7127 | uint32_t string_length = strlen(str) + 1; |
| 7128 | location.CopyOpcodeData(debug_info_data, string_offset, string_length); |
| 7129 | } |
| 7130 | } |
| 7131 | } |
| 7132 | break; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7133 | case DW_AT_location: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7134 | { |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 7135 | location_is_const_value_data = false; |
| 7136 | has_explicit_location = true; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7137 | if (form_value.BlockData()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7138 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7139 | const DataExtractor& debug_info_data = get_debug_info_data(); |
| 7140 | |
| 7141 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 7142 | uint32_t block_length = form_value.Unsigned(); |
| Greg Clayton | 7f4c743 | 2012-08-11 00:49:14 +0000 | [diff] [blame] | 7143 | location.CopyOpcodeData(get_debug_info_data(), block_offset, block_length); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7144 | } |
| 7145 | else |
| 7146 | { |
| 7147 | const DataExtractor& debug_loc_data = get_debug_loc_data(); |
| 7148 | const dw_offset_t debug_loc_offset = form_value.Unsigned(); |
| 7149 | |
| 7150 | size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset); |
| 7151 | if (loc_list_length > 0) |
| 7152 | { |
| Greg Clayton | 7f4c743 | 2012-08-11 00:49:14 +0000 | [diff] [blame] | 7153 | location.CopyOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7154 | assert (func_low_pc != LLDB_INVALID_ADDRESS); |
| 7155 | location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress()); |
| 7156 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7157 | } |
| 7158 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7159 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7160 | |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 7161 | case DW_AT_artificial: is_artificial = form_value.Boolean(); break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 7162 | 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] | 7163 | case DW_AT_declaration: |
| 7164 | case DW_AT_description: |
| 7165 | case DW_AT_endianity: |
| 7166 | case DW_AT_segment: |
| 7167 | case DW_AT_start_scope: |
| 7168 | case DW_AT_visibility: |
| 7169 | default: |
| 7170 | case DW_AT_abstract_origin: |
| 7171 | case DW_AT_sibling: |
| 7172 | case DW_AT_specification: |
| 7173 | break; |
| 7174 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7175 | } |
| 7176 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7177 | |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame^] | 7178 | ValueType scope = eValueTypeInvalid; |
| 7179 | |
| 7180 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); |
| 7181 | dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
| 7182 | SymbolContextScope * symbol_context_scope = NULL; |
| 7183 | |
| 7184 | // DWARF doesn't specify if a DW_TAG_variable is a local, global |
| 7185 | // or static variable, so we have to do a little digging by |
| 7186 | // looking at the location of a varaible to see if it contains |
| 7187 | // a DW_OP_addr opcode _somewhere_ in the definition. I say |
| 7188 | // somewhere because clang likes to combine small global variables |
| 7189 | // into the same symbol and have locations like: |
| 7190 | // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus |
| 7191 | // So if we don't have a DW_TAG_formal_parameter, we can look at |
| 7192 | // the location to see if it contains a DW_OP_addr opcode, and |
| 7193 | // then we can correctly classify our variables. |
| 7194 | if (tag == DW_TAG_formal_parameter) |
| 7195 | scope = eValueTypeVariableArgument; |
| 7196 | else |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7197 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame^] | 7198 | bool op_error = false; |
| 7199 | // Check if the location has a DW_OP_addr with any address value... |
| 7200 | lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS; |
| 7201 | if (!location_is_const_value_data) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7202 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame^] | 7203 | location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error); |
| 7204 | if (op_error) |
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 7205 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame^] | 7206 | StreamString strm; |
| 7207 | location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL); |
| 7208 | GetObjectFile()->GetModule()->ReportError ("0x%8.8x: %s has an invalid location: %s", die->GetOffset(), DW_TAG_value_to_name(die->Tag()), strm.GetString().c_str()); |
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 7209 | } |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame^] | 7210 | } |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7211 | |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame^] | 7212 | if (location_DW_OP_addr != LLDB_INVALID_ADDRESS) |
| 7213 | { |
| 7214 | if (is_external) |
| 7215 | scope = eValueTypeVariableGlobal; |
| 7216 | else |
| 7217 | scope = eValueTypeVariableStatic; |
| 7218 | |
| 7219 | |
| 7220 | SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile (); |
| 7221 | |
| 7222 | if (debug_map_symfile) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7223 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame^] | 7224 | // When leaving the DWARF in the .o files on darwin, |
| 7225 | // when we have a global variable that wasn't initialized, |
| 7226 | // the .o file might not have allocated a virtual |
| 7227 | // address for the global variable. In this case it will |
| 7228 | // have created a symbol for the global variable |
| 7229 | // that is undefined/data and external and the value will |
| 7230 | // be the byte size of the variable. When we do the |
| 7231 | // address map in SymbolFileDWARFDebugMap we rely on |
| 7232 | // having an address, we need to do some magic here |
| 7233 | // so we can get the correct address for our global |
| 7234 | // variable. The address for all of these entries |
| 7235 | // will be zero, and there will be an undefined symbol |
| 7236 | // in this object file, and the executable will have |
| 7237 | // a matching symbol with a good address. So here we |
| 7238 | // dig up the correct address and replace it in the |
| 7239 | // location for the variable, and set the variable's |
| 7240 | // symbol context scope to be that of the main executable |
| 7241 | // so the file address will resolve correctly. |
| 7242 | bool linked_oso_file_addr = false; |
| 7243 | if (is_external && location_DW_OP_addr == 0) |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7244 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame^] | 7245 | |
| 7246 | // we have a possible uninitialized extern global |
| 7247 | ConstString const_name(mangled ? mangled : name); |
| 7248 | ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile(); |
| 7249 | if (debug_map_objfile) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7250 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame^] | 7251 | Symtab *debug_map_symtab = debug_map_objfile->GetSymtab(); |
| 7252 | if (debug_map_symtab) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7253 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame^] | 7254 | Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name, |
| 7255 | eSymbolTypeData, |
| 7256 | Symtab::eDebugYes, |
| 7257 | Symtab::eVisibilityExtern); |
| 7258 | if (exe_symbol) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7259 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame^] | 7260 | if (exe_symbol->ValueIsAddress()) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7261 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame^] | 7262 | const addr_t exe_file_addr = exe_symbol->GetAddress().GetFileAddress(); |
| 7263 | if (exe_file_addr != LLDB_INVALID_ADDRESS) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7264 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame^] | 7265 | if (location.Update_DW_OP_addr (exe_file_addr)) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7266 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame^] | 7267 | linked_oso_file_addr = true; |
| 7268 | symbol_context_scope = exe_symbol; |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7269 | } |
| 7270 | } |
| 7271 | } |
| 7272 | } |
| 7273 | } |
| 7274 | } |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame^] | 7275 | } |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7276 | |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame^] | 7277 | if (!linked_oso_file_addr) |
| 7278 | { |
| 7279 | // The DW_OP_addr is not zero, but it contains a .o file address which |
| 7280 | // needs to be linked up correctly. |
| 7281 | const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr); |
| 7282 | if (exe_file_addr != LLDB_INVALID_ADDRESS) |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7283 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame^] | 7284 | // Update the file address for this variable |
| 7285 | location.Update_DW_OP_addr (exe_file_addr); |
| 7286 | } |
| 7287 | else |
| 7288 | { |
| 7289 | // Variable didn't make it into the final executable |
| 7290 | return var_sp; |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 7291 | } |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 7292 | } |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 7293 | } |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 7294 | } |
| 7295 | else |
| 7296 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame^] | 7297 | scope = eValueTypeVariableLocal; |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 7298 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7299 | } |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame^] | 7300 | |
| 7301 | if (symbol_context_scope == NULL) |
| 7302 | { |
| 7303 | switch (parent_tag) |
| 7304 | { |
| 7305 | case DW_TAG_subprogram: |
| 7306 | case DW_TAG_inlined_subroutine: |
| 7307 | case DW_TAG_lexical_block: |
| 7308 | if (sc.function) |
| 7309 | { |
| 7310 | symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); |
| 7311 | if (symbol_context_scope == NULL) |
| 7312 | symbol_context_scope = sc.function; |
| 7313 | } |
| 7314 | break; |
| 7315 | |
| 7316 | default: |
| 7317 | symbol_context_scope = sc.comp_unit; |
| 7318 | break; |
| 7319 | } |
| 7320 | } |
| 7321 | |
| 7322 | if (symbol_context_scope) |
| 7323 | { |
| 7324 | var_sp.reset (new Variable (MakeUserID(die->GetOffset()), |
| 7325 | name, |
| 7326 | mangled, |
| 7327 | SymbolFileTypeSP (new SymbolFileType(*this, type_uid)), |
| 7328 | scope, |
| 7329 | symbol_context_scope, |
| 7330 | &decl, |
| 7331 | location, |
| 7332 | is_external, |
| 7333 | is_artificial)); |
| 7334 | |
| 7335 | var_sp->SetLocationIsConstantValueData (location_is_const_value_data); |
| 7336 | } |
| 7337 | else |
| 7338 | { |
| 7339 | // Not ready to parse this variable yet. It might be a global |
| 7340 | // or static variable that is in a function scope and the function |
| 7341 | // in the symbol context wasn't filled in yet |
| 7342 | return var_sp; |
| 7343 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7344 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 7345 | // Cache var_sp even if NULL (the variable was just a specification or |
| 7346 | // was missing vital information to be able to be displayed in the debugger |
| 7347 | // (missing location due to optimization, etc)) so we don't re-parse |
| 7348 | // this DIE over and over later... |
| 7349 | m_die_to_variable_sp[die] = var_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7350 | } |
| 7351 | return var_sp; |
| 7352 | } |
| 7353 | |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7354 | |
| 7355 | const DWARFDebugInfoEntry * |
| 7356 | SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset, |
| 7357 | dw_offset_t spec_block_die_offset, |
| 7358 | DWARFCompileUnit **result_die_cu_handle) |
| 7359 | { |
| 7360 | // Give the concrete function die specified by "func_die_offset", find the |
| 7361 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points |
| 7362 | // to "spec_block_die_offset" |
| 7363 | DWARFDebugInfo* info = DebugInfo(); |
| 7364 | |
| 7365 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle); |
| 7366 | if (die) |
| 7367 | { |
| 7368 | assert (*result_die_cu_handle); |
| 7369 | return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle); |
| 7370 | } |
| 7371 | return NULL; |
| 7372 | } |
| 7373 | |
| 7374 | |
| 7375 | const DWARFDebugInfoEntry * |
| 7376 | SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu, |
| 7377 | const DWARFDebugInfoEntry *die, |
| 7378 | dw_offset_t spec_block_die_offset, |
| 7379 | DWARFCompileUnit **result_die_cu_handle) |
| 7380 | { |
| 7381 | if (die) |
| 7382 | { |
| 7383 | switch (die->Tag()) |
| 7384 | { |
| 7385 | case DW_TAG_subprogram: |
| 7386 | case DW_TAG_inlined_subroutine: |
| 7387 | case DW_TAG_lexical_block: |
| 7388 | { |
| 7389 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset) |
| 7390 | { |
| 7391 | *result_die_cu_handle = dwarf_cu; |
| 7392 | return die; |
| 7393 | } |
| 7394 | |
| 7395 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset) |
| 7396 | { |
| 7397 | *result_die_cu_handle = dwarf_cu; |
| 7398 | return die; |
| 7399 | } |
| 7400 | } |
| 7401 | break; |
| 7402 | } |
| 7403 | |
| 7404 | // Give the concrete function die specified by "func_die_offset", find the |
| 7405 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points |
| 7406 | // to "spec_block_die_offset" |
| 7407 | for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling()) |
| 7408 | { |
| 7409 | const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu, |
| 7410 | child_die, |
| 7411 | spec_block_die_offset, |
| 7412 | result_die_cu_handle); |
| 7413 | if (result_die) |
| 7414 | return result_die; |
| 7415 | } |
| 7416 | } |
| 7417 | |
| 7418 | *result_die_cu_handle = NULL; |
| 7419 | return NULL; |
| 7420 | } |
| 7421 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7422 | size_t |
| 7423 | SymbolFileDWARF::ParseVariables |
| 7424 | ( |
| 7425 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 7426 | DWARFCompileUnit* dwarf_cu, |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 7427 | const lldb::addr_t func_low_pc, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7428 | const DWARFDebugInfoEntry *orig_die, |
| 7429 | bool parse_siblings, |
| 7430 | bool parse_children, |
| 7431 | VariableList* cc_variable_list |
| 7432 | ) |
| 7433 | { |
| 7434 | if (orig_die == NULL) |
| 7435 | return 0; |
| 7436 | |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7437 | VariableListSP variable_list_sp; |
| 7438 | |
| 7439 | size_t vars_added = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7440 | const DWARFDebugInfoEntry *die = orig_die; |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7441 | while (die != NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7442 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7443 | dw_tag_t tag = die->Tag(); |
| 7444 | |
| 7445 | // Check to see if we have already parsed this variable or constant? |
| 7446 | if (m_die_to_variable_sp[die]) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7447 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7448 | if (cc_variable_list) |
| 7449 | cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7450 | } |
| 7451 | else |
| 7452 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7453 | // We haven't already parsed it, lets do that now. |
| 7454 | if ((tag == DW_TAG_variable) || |
| 7455 | (tag == DW_TAG_constant) || |
| 7456 | (tag == DW_TAG_formal_parameter && sc.function)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7457 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7458 | if (variable_list_sp.get() == NULL) |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7459 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7460 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die); |
| 7461 | dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
| 7462 | switch (parent_tag) |
| 7463 | { |
| 7464 | case DW_TAG_compile_unit: |
| 7465 | if (sc.comp_unit != NULL) |
| 7466 | { |
| 7467 | variable_list_sp = sc.comp_unit->GetVariableList(false); |
| 7468 | if (variable_list_sp.get() == NULL) |
| 7469 | { |
| 7470 | variable_list_sp.reset(new VariableList()); |
| 7471 | sc.comp_unit->SetVariableList(variable_list_sp); |
| 7472 | } |
| 7473 | } |
| 7474 | else |
| 7475 | { |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 7476 | 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] | 7477 | MakeUserID(sc_parent_die->GetOffset()), |
| 7478 | DW_TAG_value_to_name (parent_tag), |
| 7479 | MakeUserID(orig_die->GetOffset()), |
| 7480 | DW_TAG_value_to_name (orig_die->Tag())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7481 | } |
| 7482 | break; |
| 7483 | |
| 7484 | case DW_TAG_subprogram: |
| 7485 | case DW_TAG_inlined_subroutine: |
| 7486 | case DW_TAG_lexical_block: |
| 7487 | if (sc.function != NULL) |
| 7488 | { |
| 7489 | // Check to see if we already have parsed the variables for the given scope |
| 7490 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7491 | Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7492 | if (block == NULL) |
| 7493 | { |
| 7494 | // This must be a specification or abstract origin with |
| 7495 | // a concrete block couterpart in the current function. We need |
| 7496 | // to find the concrete block so we can correctly add the |
| 7497 | // variable to it |
| 7498 | DWARFCompileUnit *concrete_block_die_cu = dwarf_cu; |
| 7499 | const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(), |
| 7500 | sc_parent_die->GetOffset(), |
| 7501 | &concrete_block_die_cu); |
| 7502 | if (concrete_block_die) |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7503 | block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7504 | } |
| 7505 | |
| 7506 | if (block != NULL) |
| 7507 | { |
| 7508 | const bool can_create = false; |
| 7509 | variable_list_sp = block->GetBlockVariableList (can_create); |
| 7510 | if (variable_list_sp.get() == NULL) |
| 7511 | { |
| 7512 | variable_list_sp.reset(new VariableList()); |
| 7513 | block->SetVariableList(variable_list_sp); |
| 7514 | } |
| 7515 | } |
| 7516 | } |
| 7517 | break; |
| 7518 | |
| 7519 | default: |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 7520 | 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] | 7521 | MakeUserID(orig_die->GetOffset()), |
| 7522 | DW_TAG_value_to_name (orig_die->Tag())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7523 | break; |
| 7524 | } |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7525 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7526 | |
| 7527 | if (variable_list_sp) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7528 | { |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7529 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc)); |
| 7530 | if (var_sp) |
| 7531 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7532 | variable_list_sp->AddVariableIfUnique (var_sp); |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7533 | if (cc_variable_list) |
| 7534 | cc_variable_list->AddVariableIfUnique (var_sp); |
| 7535 | ++vars_added; |
| 7536 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7537 | } |
| 7538 | } |
| 7539 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7540 | |
| 7541 | bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram); |
| 7542 | |
| 7543 | if (!skip_children && parse_children && die->HasChildren()) |
| 7544 | { |
| 7545 | vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list); |
| 7546 | } |
| 7547 | |
| 7548 | if (parse_siblings) |
| 7549 | die = die->GetSibling(); |
| 7550 | else |
| 7551 | die = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7552 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7553 | return vars_added; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7554 | } |
| 7555 | |
| 7556 | //------------------------------------------------------------------ |
| 7557 | // PluginInterface protocol |
| 7558 | //------------------------------------------------------------------ |
| Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 7559 | ConstString |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7560 | SymbolFileDWARF::GetPluginName() |
| 7561 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7562 | return GetPluginNameStatic(); |
| 7563 | } |
| 7564 | |
| 7565 | uint32_t |
| 7566 | SymbolFileDWARF::GetPluginVersion() |
| 7567 | { |
| 7568 | return 1; |
| 7569 | } |
| 7570 | |
| 7571 | void |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 7572 | SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl) |
| 7573 | { |
| 7574 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 7575 | clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); |
| 7576 | if (clang_type) |
| 7577 | symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); |
| 7578 | } |
| 7579 | |
| 7580 | void |
| 7581 | SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl) |
| 7582 | { |
| 7583 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 7584 | clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); |
| 7585 | if (clang_type) |
| 7586 | symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); |
| 7587 | } |
| 7588 | |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7589 | void |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7590 | SymbolFileDWARF::DumpIndexes () |
| 7591 | { |
| 7592 | StreamFile s(stdout, false); |
| 7593 | |
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 7594 | s.Printf ("DWARF index for (%s) '%s':", |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7595 | GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(), |
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 7596 | GetObjectFile()->GetFileSpec().GetPath().c_str()); |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7597 | s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s); |
| 7598 | s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s); |
| 7599 | s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s); |
| 7600 | s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s); |
| 7601 | s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s); |
| 7602 | s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s); |
| 7603 | s.Printf("\nTypes:\n"); m_type_index.Dump (&s); |
| 7604 | s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s); |
| 7605 | } |
| 7606 | |
| 7607 | void |
| 7608 | SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context, |
| 7609 | const char *name, |
| 7610 | llvm::SmallVectorImpl <clang::NamedDecl *> *results) |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7611 | { |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7612 | DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context); |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7613 | |
| 7614 | if (iter == m_decl_ctx_to_die.end()) |
| 7615 | return; |
| 7616 | |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7617 | 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] | 7618 | { |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7619 | const DWARFDebugInfoEntry *context_die = *pos; |
| 7620 | |
| 7621 | if (!results) |
| 7622 | return; |
| 7623 | |
| 7624 | DWARFDebugInfo* info = DebugInfo(); |
| 7625 | |
| 7626 | DIEArray die_offsets; |
| 7627 | |
| 7628 | DWARFCompileUnit* dwarf_cu = NULL; |
| 7629 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 7630 | |
| 7631 | if (m_using_apple_tables) |
| 7632 | { |
| 7633 | if (m_apple_types_ap.get()) |
| 7634 | m_apple_types_ap->FindByName (name, die_offsets); |
| 7635 | } |
| 7636 | else |
| 7637 | { |
| 7638 | if (!m_indexed) |
| 7639 | Index (); |
| 7640 | |
| 7641 | m_type_index.Find (ConstString(name), die_offsets); |
| 7642 | } |
| 7643 | |
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 7644 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7645 | |
| 7646 | if (num_matches) |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7647 | { |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7648 | for (size_t i = 0; i < num_matches; ++i) |
| 7649 | { |
| 7650 | const dw_offset_t die_offset = die_offsets[i]; |
| 7651 | die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7652 | |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7653 | if (die->GetParent() != context_die) |
| 7654 | continue; |
| 7655 | |
| 7656 | Type *matching_type = ResolveType (dwarf_cu, die); |
| 7657 | |
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 7658 | lldb::clang_type_t type = matching_type->GetClangForwardType(); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7659 | clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type); |
| 7660 | |
| 7661 | if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr())) |
| 7662 | { |
| 7663 | clang::TagDecl *tag_decl = tag_type->getDecl(); |
| 7664 | results->push_back(tag_decl); |
| 7665 | } |
| 7666 | else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr())) |
| 7667 | { |
| 7668 | clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl(); |
| 7669 | results->push_back(typedef_decl); |
| 7670 | } |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7671 | } |
| 7672 | } |
| 7673 | } |
| 7674 | } |
| 7675 | |
| 7676 | void |
| 7677 | SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton, |
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 7678 | const clang::DeclContext *decl_context, |
| 7679 | clang::DeclarationName decl_name, |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7680 | llvm::SmallVectorImpl <clang::NamedDecl *> *results) |
| 7681 | { |
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 7682 | |
| 7683 | switch (decl_context->getDeclKind()) |
| 7684 | { |
| 7685 | case clang::Decl::Namespace: |
| 7686 | case clang::Decl::TranslationUnit: |
| 7687 | { |
| 7688 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 7689 | symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results); |
| 7690 | } |
| 7691 | break; |
| 7692 | default: |
| 7693 | break; |
| 7694 | } |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7695 | } |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7696 | |
| 7697 | bool |
| 7698 | SymbolFileDWARF::LayoutRecordType (void *baton, |
| 7699 | const clang::RecordDecl *record_decl, |
| 7700 | uint64_t &size, |
| 7701 | uint64_t &alignment, |
| 7702 | llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, |
| 7703 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, |
| 7704 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) |
| 7705 | { |
| 7706 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 7707 | return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets); |
| 7708 | } |
| 7709 | |
| 7710 | |
| 7711 | bool |
| 7712 | SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl, |
| 7713 | uint64_t &bit_size, |
| 7714 | uint64_t &alignment, |
| 7715 | llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, |
| 7716 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, |
| 7717 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) |
| 7718 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 7719 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7720 | RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl); |
| 7721 | bool success = false; |
| 7722 | base_offsets.clear(); |
| 7723 | vbase_offsets.clear(); |
| 7724 | if (pos != m_record_decl_to_layout_map.end()) |
| 7725 | { |
| 7726 | bit_size = pos->second.bit_size; |
| 7727 | alignment = pos->second.alignment; |
| 7728 | field_offsets.swap(pos->second.field_offsets); |
| Greg Clayton | 2508b9b | 2012-11-01 23:20:02 +0000 | [diff] [blame] | 7729 | base_offsets.swap (pos->second.base_offsets); |
| 7730 | vbase_offsets.swap (pos->second.vbase_offsets); |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7731 | m_record_decl_to_layout_map.erase(pos); |
| 7732 | success = true; |
| 7733 | } |
| 7734 | else |
| 7735 | { |
| 7736 | bit_size = 0; |
| 7737 | alignment = 0; |
| 7738 | field_offsets.clear(); |
| 7739 | } |
| 7740 | |
| 7741 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 7742 | GetObjectFile()->GetModule()->LogMessage (log, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 7743 | "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] | 7744 | record_decl, |
| 7745 | bit_size, |
| 7746 | alignment, |
| 7747 | (uint32_t)field_offsets.size(), |
| 7748 | (uint32_t)base_offsets.size(), |
| 7749 | (uint32_t)vbase_offsets.size(), |
| 7750 | success); |
| 7751 | return success; |
| 7752 | } |
| 7753 | |
| 7754 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 7755 | SymbolFileDWARFDebugMap * |
| 7756 | SymbolFileDWARF::GetDebugMapSymfile () |
| 7757 | { |
| 7758 | if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired()) |
| 7759 | { |
| 7760 | lldb::ModuleSP module_sp (m_debug_map_module_wp.lock()); |
| 7761 | if (module_sp) |
| 7762 | { |
| 7763 | SymbolVendor *sym_vendor = module_sp->GetSymbolVendor(); |
| 7764 | if (sym_vendor) |
| 7765 | m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile(); |
| 7766 | } |
| 7767 | } |
| 7768 | return m_debug_map_symfile; |
| 7769 | } |
| 7770 | |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7771 | |