| 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(); |
| Greg Clayton | 43e0af0 | 2012-09-18 18:04:04 +0000 | [diff] [blame] | 129 | log_strm.Printf("DIEStack[%llu]:\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); |
| Greg Clayton | 43e0af0 | 2012-09-18 18:04:04 +0000 | [diff] [blame] | 136 | log_strm.Printf ("[%llu] 0x%8.8x: %s name='%s'\n", |
| 137 | (uint64_t)i, |
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 138 | die->GetOffset(), |
| 139 | DW_TAG_value_to_name(die->Tag()), |
| 140 | qualified_name.c_str()); |
| 141 | } |
| 142 | log->PutCString(log_strm.GetData()); |
| 143 | } |
| 144 | void Pop () |
| 145 | { |
| 146 | m_dies.pop_back(); |
| 147 | } |
| 148 | |
| 149 | class ScopedPopper |
| 150 | { |
| 151 | public: |
| 152 | ScopedPopper (DIEStack &die_stack) : |
| 153 | m_die_stack (die_stack), |
| 154 | m_valid (false) |
| 155 | { |
| 156 | } |
| 157 | |
| 158 | void |
| 159 | Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) |
| 160 | { |
| 161 | m_valid = true; |
| 162 | m_die_stack.Push (cu, die); |
| 163 | } |
| 164 | |
| 165 | ~ScopedPopper () |
| 166 | { |
| 167 | if (m_valid) |
| 168 | m_die_stack.Pop(); |
| 169 | } |
| 170 | |
| 171 | |
| 172 | |
| 173 | protected: |
| 174 | DIEStack &m_die_stack; |
| 175 | bool m_valid; |
| 176 | }; |
| 177 | |
| 178 | protected: |
| 179 | struct DIEInfo { |
| 180 | DIEInfo (DWARFCompileUnit *c, const DWARFDebugInfoEntry *d) : |
| 181 | cu(c), |
| 182 | die(d) |
| 183 | { |
| 184 | } |
| 185 | DWARFCompileUnit *cu; |
| 186 | const DWARFDebugInfoEntry *die; |
| 187 | }; |
| 188 | typedef std::vector<DIEInfo> Stack; |
| 189 | Stack m_dies; |
| 190 | }; |
| 191 | #endif |
| 192 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 193 | void |
| 194 | SymbolFileDWARF::Initialize() |
| 195 | { |
| 196 | LogChannelDWARF::Initialize(); |
| 197 | PluginManager::RegisterPlugin (GetPluginNameStatic(), |
| 198 | GetPluginDescriptionStatic(), |
| 199 | CreateInstance); |
| 200 | } |
| 201 | |
| 202 | void |
| 203 | SymbolFileDWARF::Terminate() |
| 204 | { |
| 205 | PluginManager::UnregisterPlugin (CreateInstance); |
| 206 | LogChannelDWARF::Initialize(); |
| 207 | } |
| 208 | |
| 209 | |
| 210 | const char * |
| 211 | SymbolFileDWARF::GetPluginNameStatic() |
| 212 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 213 | return "dwarf"; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | const char * |
| 217 | SymbolFileDWARF::GetPluginDescriptionStatic() |
| 218 | { |
| 219 | return "DWARF and DWARF3 debug symbol file reader."; |
| 220 | } |
| 221 | |
| 222 | |
| 223 | SymbolFile* |
| 224 | SymbolFileDWARF::CreateInstance (ObjectFile* obj_file) |
| 225 | { |
| 226 | return new SymbolFileDWARF(obj_file); |
| 227 | } |
| 228 | |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 229 | TypeList * |
| 230 | SymbolFileDWARF::GetTypeList () |
| 231 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 232 | if (GetDebugMapSymfile ()) |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 233 | return m_debug_map_symfile->GetTypeList(); |
| 234 | return m_obj_file->GetModule()->GetTypeList(); |
| 235 | |
| 236 | } |
| 237 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 238 | //---------------------------------------------------------------------- |
| 239 | // Gets the first parent that is a lexical block, function or inlined |
| 240 | // subroutine, or compile unit. |
| 241 | //---------------------------------------------------------------------- |
| 242 | static const DWARFDebugInfoEntry * |
| 243 | GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die) |
| 244 | { |
| 245 | const DWARFDebugInfoEntry *die; |
| 246 | for (die = child_die->GetParent(); die != NULL; die = die->GetParent()) |
| 247 | { |
| 248 | dw_tag_t tag = die->Tag(); |
| 249 | |
| 250 | switch (tag) |
| 251 | { |
| 252 | case DW_TAG_compile_unit: |
| 253 | case DW_TAG_subprogram: |
| 254 | case DW_TAG_inlined_subroutine: |
| 255 | case DW_TAG_lexical_block: |
| 256 | return die; |
| 257 | } |
| 258 | } |
| 259 | return NULL; |
| 260 | } |
| 261 | |
| 262 | |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 263 | SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) : |
| 264 | SymbolFile (objfile), |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 265 | UserID (0), // Used by SymbolFileDWARFDebugMap to when this class parses .o files to contain the .o file index/ID |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 266 | m_debug_map_module_wp (), |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 267 | m_debug_map_symfile (NULL), |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 268 | m_clang_tu_decl (NULL), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 269 | m_flags(), |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 270 | m_data_debug_abbrev (), |
| 271 | m_data_debug_aranges (), |
| 272 | m_data_debug_frame (), |
| 273 | m_data_debug_info (), |
| 274 | m_data_debug_line (), |
| 275 | m_data_debug_loc (), |
| 276 | m_data_debug_ranges (), |
| 277 | m_data_debug_str (), |
| Greg Clayton | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 278 | m_data_apple_names (), |
| 279 | m_data_apple_types (), |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 280 | m_data_apple_namespaces (), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 281 | m_abbr(), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 282 | m_info(), |
| 283 | m_line(), |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 284 | m_apple_names_ap (), |
| 285 | m_apple_types_ap (), |
| 286 | m_apple_namespaces_ap (), |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 287 | m_apple_objc_ap (), |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 288 | m_function_basename_index(), |
| 289 | m_function_fullname_index(), |
| 290 | m_function_method_index(), |
| 291 | m_function_selector_index(), |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 292 | m_objc_class_selectors_index(), |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 293 | m_global_index(), |
| Greg Clayton | 69b0488 | 2010-10-15 02:03:22 +0000 | [diff] [blame] | 294 | m_type_index(), |
| 295 | m_namespace_index(), |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 296 | m_indexed (false), |
| 297 | m_is_external_ast_source (false), |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 298 | m_using_apple_tables (false), |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 299 | m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate), |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 300 | m_ranges(), |
| 301 | m_unique_ast_type_map () |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 302 | { |
| 303 | } |
| 304 | |
| 305 | SymbolFileDWARF::~SymbolFileDWARF() |
| 306 | { |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 307 | if (m_is_external_ast_source) |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 308 | { |
| 309 | ModuleSP module_sp (m_obj_file->GetModule()); |
| 310 | if (module_sp) |
| 311 | module_sp->GetClangASTContext().RemoveExternalSource (); |
| 312 | } |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | static const ConstString & |
| 316 | GetDWARFMachOSegmentName () |
| 317 | { |
| 318 | static ConstString g_dwarf_section_name ("__DWARF"); |
| 319 | return g_dwarf_section_name; |
| 320 | } |
| 321 | |
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 322 | UniqueDWARFASTTypeMap & |
| 323 | SymbolFileDWARF::GetUniqueDWARFASTTypeMap () |
| 324 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 325 | if (GetDebugMapSymfile ()) |
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 326 | return m_debug_map_symfile->GetUniqueDWARFASTTypeMap (); |
| 327 | return m_unique_ast_type_map; |
| 328 | } |
| 329 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 330 | ClangASTContext & |
| 331 | SymbolFileDWARF::GetClangASTContext () |
| 332 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 333 | if (GetDebugMapSymfile ()) |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 334 | return m_debug_map_symfile->GetClangASTContext (); |
| 335 | |
| 336 | ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext(); |
| 337 | if (!m_is_external_ast_source) |
| 338 | { |
| 339 | m_is_external_ast_source = true; |
| 340 | llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap ( |
| 341 | new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl, |
| 342 | SymbolFileDWARF::CompleteObjCInterfaceDecl, |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 343 | SymbolFileDWARF::FindExternalVisibleDeclsByName, |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 344 | SymbolFileDWARF::LayoutRecordType, |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 345 | this)); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 346 | ast.SetExternalSource (ast_source_ap); |
| 347 | } |
| 348 | return ast; |
| 349 | } |
| 350 | |
| 351 | void |
| 352 | SymbolFileDWARF::InitializeObject() |
| 353 | { |
| 354 | // Install our external AST source callbacks so we can complete Clang types. |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 355 | ModuleSP module_sp (m_obj_file->GetModule()); |
| 356 | if (module_sp) |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 357 | { |
| 358 | const SectionList *section_list = m_obj_file->GetSectionList(); |
| 359 | |
| 360 | const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get(); |
| 361 | |
| 362 | // Memory map the DWARF mach-o segment so we have everything mmap'ed |
| 363 | // to keep our heap memory usage down. |
| 364 | if (section) |
| Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 365 | m_obj_file->MemoryMapSectionData(section, m_dwarf_data); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 366 | } |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 367 | get_apple_names_data(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 368 | if (m_data_apple_names.GetByteSize() > 0) |
| 369 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 370 | m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names")); |
| 371 | if (m_apple_names_ap->IsValid()) |
| 372 | m_using_apple_tables = true; |
| 373 | else |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 374 | m_apple_names_ap.reset(); |
| 375 | } |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 376 | get_apple_types_data(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 377 | if (m_data_apple_types.GetByteSize() > 0) |
| 378 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 379 | m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types")); |
| 380 | if (m_apple_types_ap->IsValid()) |
| 381 | m_using_apple_tables = true; |
| 382 | else |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 383 | m_apple_types_ap.reset(); |
| 384 | } |
| 385 | |
| 386 | get_apple_namespaces_data(); |
| 387 | if (m_data_apple_namespaces.GetByteSize() > 0) |
| 388 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 389 | m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces")); |
| 390 | if (m_apple_namespaces_ap->IsValid()) |
| 391 | m_using_apple_tables = true; |
| 392 | else |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 393 | m_apple_namespaces_ap.reset(); |
| 394 | } |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 395 | |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 396 | get_apple_objc_data(); |
| 397 | if (m_data_apple_objc.GetByteSize() > 0) |
| 398 | { |
| 399 | m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc")); |
| 400 | if (m_apple_objc_ap->IsValid()) |
| 401 | m_using_apple_tables = true; |
| 402 | else |
| 403 | m_apple_objc_ap.reset(); |
| 404 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | bool |
| 408 | SymbolFileDWARF::SupportedVersion(uint16_t version) |
| 409 | { |
| 410 | return version == 2 || version == 3; |
| 411 | } |
| 412 | |
| 413 | uint32_t |
| Sean Callanan | bfaf54d | 2011-12-03 04:38:43 +0000 | [diff] [blame] | 414 | SymbolFileDWARF::CalculateAbilities () |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 415 | { |
| 416 | uint32_t abilities = 0; |
| 417 | if (m_obj_file != NULL) |
| 418 | { |
| 419 | const Section* section = NULL; |
| 420 | const SectionList *section_list = m_obj_file->GetSectionList(); |
| 421 | if (section_list == NULL) |
| 422 | return 0; |
| 423 | |
| 424 | uint64_t debug_abbrev_file_size = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 425 | uint64_t debug_info_file_size = 0; |
| 426 | uint64_t debug_line_file_size = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 427 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 428 | section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 429 | |
| 430 | if (section) |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 431 | section_list = §ion->GetChildren (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 432 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 433 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 434 | if (section != NULL) |
| 435 | { |
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 436 | debug_info_file_size = section->GetFileSize(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 437 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 438 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 439 | if (section) |
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 440 | debug_abbrev_file_size = section->GetFileSize(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 441 | else |
| 442 | m_flags.Set (flagsGotDebugAbbrevData); |
| 443 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 444 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 445 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 446 | m_flags.Set (flagsGotDebugArangesData); |
| 447 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 448 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 449 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 450 | m_flags.Set (flagsGotDebugFrameData); |
| 451 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 452 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 453 | if (section) |
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 454 | debug_line_file_size = section->GetFileSize(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 455 | else |
| 456 | m_flags.Set (flagsGotDebugLineData); |
| 457 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 458 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 459 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 460 | m_flags.Set (flagsGotDebugLocData); |
| 461 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 462 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 463 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 464 | m_flags.Set (flagsGotDebugMacInfoData); |
| 465 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 466 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 467 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 468 | m_flags.Set (flagsGotDebugPubNamesData); |
| 469 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 470 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 471 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 472 | m_flags.Set (flagsGotDebugPubTypesData); |
| 473 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 474 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 475 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 476 | m_flags.Set (flagsGotDebugRangesData); |
| 477 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 478 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 479 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 480 | m_flags.Set (flagsGotDebugStrData); |
| 481 | } |
| Greg Clayton | 6c59661 | 2012-05-18 21:47:20 +0000 | [diff] [blame] | 482 | else |
| 483 | { |
| 484 | const char *symfile_dir_cstr = m_obj_file->GetFileSpec().GetDirectory().GetCString(); |
| 485 | if (symfile_dir_cstr) |
| 486 | { |
| 487 | if (strcasestr(symfile_dir_cstr, ".dsym")) |
| 488 | { |
| 489 | if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo) |
| 490 | { |
| 491 | // We have a dSYM file that didn't have a any debug info. |
| 492 | // If the string table has a size of 1, then it was made from |
| 493 | // an executable with no debug info, or from an executable that |
| 494 | // was stripped. |
| 495 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get(); |
| 496 | if (section && section->GetFileSize() == 1) |
| 497 | { |
| 498 | m_obj_file->GetModule()->ReportWarning ("empty dSYM file detected, dSYM was created with an executable with no debug info."); |
| 499 | } |
| 500 | } |
| 501 | } |
| 502 | } |
| 503 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 504 | |
| 505 | if (debug_abbrev_file_size > 0 && debug_info_file_size > 0) |
| 506 | abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes; |
| 507 | |
| 508 | if (debug_line_file_size > 0) |
| 509 | abilities |= LineTables; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 510 | } |
| 511 | return abilities; |
| 512 | } |
| 513 | |
| 514 | const DataExtractor& |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 515 | SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 516 | { |
| 517 | if (m_flags.IsClear (got_flag)) |
| 518 | { |
| 519 | m_flags.Set (got_flag); |
| 520 | const SectionList *section_list = m_obj_file->GetSectionList(); |
| 521 | if (section_list) |
| 522 | { |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 523 | SectionSP section_sp (section_list->FindSectionByType(sect_type, true)); |
| 524 | if (section_sp) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 525 | { |
| 526 | // See if we memory mapped the DWARF segment? |
| 527 | if (m_dwarf_data.GetByteSize()) |
| 528 | { |
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 529 | data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetFileSize()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 530 | } |
| 531 | else |
| 532 | { |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 533 | if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 534 | data.Clear(); |
| 535 | } |
| 536 | } |
| 537 | } |
| 538 | } |
| 539 | return data; |
| 540 | } |
| 541 | |
| 542 | const DataExtractor& |
| 543 | SymbolFileDWARF::get_debug_abbrev_data() |
| 544 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 545 | return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | const DataExtractor& |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 549 | SymbolFileDWARF::get_debug_aranges_data() |
| 550 | { |
| 551 | return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges); |
| 552 | } |
| 553 | |
| 554 | const DataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 555 | SymbolFileDWARF::get_debug_frame_data() |
| 556 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 557 | return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | const DataExtractor& |
| 561 | SymbolFileDWARF::get_debug_info_data() |
| 562 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 563 | return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | const DataExtractor& |
| 567 | SymbolFileDWARF::get_debug_line_data() |
| 568 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 569 | return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | const DataExtractor& |
| 573 | SymbolFileDWARF::get_debug_loc_data() |
| 574 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 575 | return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | const DataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 579 | SymbolFileDWARF::get_debug_ranges_data() |
| 580 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 581 | return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | const DataExtractor& |
| 585 | SymbolFileDWARF::get_debug_str_data() |
| 586 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 587 | return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 588 | } |
| 589 | |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 590 | const DataExtractor& |
| Greg Clayton | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 591 | SymbolFileDWARF::get_apple_names_data() |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 592 | { |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 593 | return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names); |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | const DataExtractor& |
| Greg Clayton | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 597 | SymbolFileDWARF::get_apple_types_data() |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 598 | { |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 599 | return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types); |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 600 | } |
| 601 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 602 | const DataExtractor& |
| 603 | SymbolFileDWARF::get_apple_namespaces_data() |
| 604 | { |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 605 | return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces); |
| 606 | } |
| 607 | |
| 608 | const DataExtractor& |
| 609 | SymbolFileDWARF::get_apple_objc_data() |
| 610 | { |
| 611 | return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 612 | } |
| 613 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 614 | |
| 615 | DWARFDebugAbbrev* |
| 616 | SymbolFileDWARF::DebugAbbrev() |
| 617 | { |
| 618 | if (m_abbr.get() == NULL) |
| 619 | { |
| 620 | const DataExtractor &debug_abbrev_data = get_debug_abbrev_data(); |
| 621 | if (debug_abbrev_data.GetByteSize() > 0) |
| 622 | { |
| 623 | m_abbr.reset(new DWARFDebugAbbrev()); |
| 624 | if (m_abbr.get()) |
| 625 | m_abbr->Parse(debug_abbrev_data); |
| 626 | } |
| 627 | } |
| 628 | return m_abbr.get(); |
| 629 | } |
| 630 | |
| 631 | const DWARFDebugAbbrev* |
| 632 | SymbolFileDWARF::DebugAbbrev() const |
| 633 | { |
| 634 | return m_abbr.get(); |
| 635 | } |
| 636 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 637 | |
| 638 | DWARFDebugInfo* |
| 639 | SymbolFileDWARF::DebugInfo() |
| 640 | { |
| 641 | if (m_info.get() == NULL) |
| 642 | { |
| 643 | Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this); |
| 644 | if (get_debug_info_data().GetByteSize() > 0) |
| 645 | { |
| 646 | m_info.reset(new DWARFDebugInfo()); |
| 647 | if (m_info.get()) |
| 648 | { |
| 649 | m_info->SetDwarfData(this); |
| 650 | } |
| 651 | } |
| 652 | } |
| 653 | return m_info.get(); |
| 654 | } |
| 655 | |
| 656 | const DWARFDebugInfo* |
| 657 | SymbolFileDWARF::DebugInfo() const |
| 658 | { |
| 659 | return m_info.get(); |
| 660 | } |
| 661 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 662 | DWARFCompileUnit* |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 663 | SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 664 | { |
| 665 | DWARFDebugInfo* info = DebugInfo(); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 666 | if (info) |
| 667 | { |
| 668 | if (GetDebugMapSymfile ()) |
| 669 | { |
| 670 | // The debug map symbol file made the compile units for this DWARF |
| 671 | // file which is .o file with DWARF in it, and we should have |
| 672 | // only 1 compile unit which is at offset zero in the DWARF. |
| 673 | // TODO: modify to support LTO .o files where each .o file might |
| 674 | // have multiple DW_TAG_compile_unit tags. |
| 675 | return info->GetCompileUnit(0).get(); |
| 676 | } |
| 677 | else |
| 678 | { |
| 679 | // Just a normal DWARF file whose user ID for the compile unit is |
| 680 | // the DWARF offset itself |
| 681 | return info->GetCompileUnit((dw_offset_t)comp_unit->GetID()).get(); |
| 682 | } |
| 683 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 684 | return NULL; |
| 685 | } |
| 686 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 687 | |
| 688 | DWARFDebugRanges* |
| 689 | SymbolFileDWARF::DebugRanges() |
| 690 | { |
| 691 | if (m_ranges.get() == NULL) |
| 692 | { |
| 693 | Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this); |
| 694 | if (get_debug_ranges_data().GetByteSize() > 0) |
| 695 | { |
| 696 | m_ranges.reset(new DWARFDebugRanges()); |
| 697 | if (m_ranges.get()) |
| 698 | m_ranges->Extract(this); |
| 699 | } |
| 700 | } |
| 701 | return m_ranges.get(); |
| 702 | } |
| 703 | |
| 704 | const DWARFDebugRanges* |
| 705 | SymbolFileDWARF::DebugRanges() const |
| 706 | { |
| 707 | return m_ranges.get(); |
| 708 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 709 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 710 | lldb::CompUnitSP |
| 711 | SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 712 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 713 | CompUnitSP cu_sp; |
| 714 | if (dwarf_cu) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 715 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 716 | CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData(); |
| 717 | if (comp_unit) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 718 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 719 | // We already parsed this compile unit, had out a shared pointer to it |
| 720 | cu_sp = comp_unit->shared_from_this(); |
| 721 | } |
| 722 | else |
| 723 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 724 | if (GetDebugMapSymfile ()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 725 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 726 | // Let the debug map create the compile unit |
| 727 | cu_sp = m_debug_map_symfile->GetCompileUnit(this); |
| 728 | dwarf_cu->SetUserData(cu_sp.get()); |
| 729 | } |
| 730 | else |
| 731 | { |
| 732 | ModuleSP module_sp (m_obj_file->GetModule()); |
| 733 | if (module_sp) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 734 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 735 | const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly (); |
| 736 | if (cu_die) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 737 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 738 | const char * cu_die_name = cu_die->GetName(this, dwarf_cu); |
| 739 | const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL); |
| 740 | LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0); |
| 741 | if (cu_die_name) |
| 742 | { |
| 743 | std::string ramapped_file; |
| 744 | FileSpec cu_file_spec; |
| Jim Ingham | 0909e5f | 2010-09-16 00:57:33 +0000 | [diff] [blame] | 745 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 746 | if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0') |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 747 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 748 | // If we have a full path to the compile unit, we don't need to resolve |
| 749 | // the file. This can be expensive e.g. when the source files are NFS mounted. |
| 750 | if (module_sp->RemapSourceFile(cu_die_name, ramapped_file)) |
| 751 | cu_file_spec.SetFile (ramapped_file.c_str(), false); |
| 752 | else |
| 753 | cu_file_spec.SetFile (cu_die_name, false); |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 754 | } |
| 755 | else |
| 756 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 757 | std::string fullpath(cu_comp_dir); |
| 758 | if (*fullpath.rbegin() != '/') |
| 759 | fullpath += '/'; |
| 760 | fullpath += cu_die_name; |
| 761 | if (module_sp->RemapSourceFile (fullpath.c_str(), ramapped_file)) |
| 762 | cu_file_spec.SetFile (ramapped_file.c_str(), false); |
| 763 | else |
| 764 | cu_file_spec.SetFile (fullpath.c_str(), false); |
| 765 | } |
| 766 | |
| 767 | cu_sp.reset(new CompileUnit (module_sp, |
| 768 | dwarf_cu, |
| 769 | cu_file_spec, |
| 770 | MakeUserID(dwarf_cu->GetOffset()), |
| 771 | cu_language)); |
| 772 | if (cu_sp) |
| 773 | { |
| 774 | dwarf_cu->SetUserData(cu_sp.get()); |
| 775 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 776 | // Figure out the compile unit index if we weren't given one |
| 777 | if (cu_idx == UINT32_MAX) |
| 778 | DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx); |
| 779 | |
| 780 | m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp); |
| 781 | } |
| 782 | } |
| 783 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 784 | } |
| 785 | } |
| 786 | } |
| 787 | } |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 788 | return cu_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 789 | } |
| 790 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 791 | uint32_t |
| 792 | SymbolFileDWARF::GetNumCompileUnits() |
| 793 | { |
| 794 | DWARFDebugInfo* info = DebugInfo(); |
| 795 | if (info) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 796 | return info->GetNumCompileUnits(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 797 | return 0; |
| 798 | } |
| 799 | |
| 800 | CompUnitSP |
| 801 | SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx) |
| 802 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 803 | CompUnitSP cu_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 804 | DWARFDebugInfo* info = DebugInfo(); |
| 805 | if (info) |
| 806 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 807 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx); |
| 808 | if (dwarf_cu) |
| 809 | cu_sp = ParseCompileUnit(dwarf_cu, cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 810 | } |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 811 | return cu_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | static void |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 815 | AddRangesToBlock (Block& block, |
| 816 | DWARFDebugRanges::RangeList& ranges, |
| 817 | addr_t block_base_addr) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 818 | { |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 819 | const size_t num_ranges = ranges.GetSize(); |
| 820 | for (size_t i = 0; i<num_ranges; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 821 | { |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 822 | const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i); |
| 823 | const addr_t range_base = range.GetRangeBase(); |
| 824 | assert (range_base >= block_base_addr); |
| 825 | block.AddRange(Block::Range (range_base - block_base_addr, range.GetByteSize()));; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 826 | } |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 827 | block.FinalizeRanges (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | |
| 831 | Function * |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 832 | SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 833 | { |
| 834 | DWARFDebugRanges::RangeList func_ranges; |
| 835 | const char *name = NULL; |
| 836 | const char *mangled = NULL; |
| 837 | int decl_file = 0; |
| 838 | int decl_line = 0; |
| 839 | int decl_column = 0; |
| 840 | int call_file = 0; |
| 841 | int call_line = 0; |
| 842 | int call_column = 0; |
| 843 | DWARFExpression frame_base; |
| 844 | |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 845 | assert (die->Tag() == DW_TAG_subprogram); |
| 846 | |
| 847 | if (die->Tag() != DW_TAG_subprogram) |
| 848 | return NULL; |
| 849 | |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 850 | if (die->GetDIENamesAndRanges (this, |
| 851 | dwarf_cu, |
| 852 | name, |
| 853 | mangled, |
| 854 | func_ranges, |
| 855 | decl_file, |
| 856 | decl_line, |
| 857 | decl_column, |
| 858 | call_file, |
| 859 | call_line, |
| 860 | call_column, |
| 861 | &frame_base)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 862 | { |
| 863 | // Union of all ranges in the function DIE (if the function is discontiguous) |
| 864 | AddressRange func_range; |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 865 | lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0); |
| 866 | lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 867 | if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr) |
| 868 | { |
| 869 | func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList()); |
| 870 | if (func_range.GetBaseAddress().IsValid()) |
| 871 | func_range.SetByteSize(highest_func_addr - lowest_func_addr); |
| 872 | } |
| 873 | |
| 874 | if (func_range.GetBaseAddress().IsValid()) |
| 875 | { |
| 876 | Mangled func_name; |
| 877 | if (mangled) |
| Greg Clayton | 037520e | 2012-07-18 23:18:10 +0000 | [diff] [blame] | 878 | func_name.SetValue(ConstString(mangled), true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 879 | else if (name) |
| Greg Clayton | 037520e | 2012-07-18 23:18:10 +0000 | [diff] [blame] | 880 | func_name.SetValue(ConstString(name), false); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 881 | |
| 882 | FunctionSP func_sp; |
| 883 | std::auto_ptr<Declaration> decl_ap; |
| 884 | if (decl_file != 0 || decl_line != 0 || decl_column != 0) |
| Greg Clayton | d7e0546 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 885 | decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), |
| 886 | decl_line, |
| 887 | decl_column)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 888 | |
| Greg Clayton | 0bd4e1b | 2011-09-30 20:52:25 +0000 | [diff] [blame] | 889 | // Supply the type _only_ if it has already been parsed |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 890 | Type *func_type = m_die_to_type.lookup (die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 891 | |
| 892 | assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED); |
| 893 | |
| 894 | func_range.GetBaseAddress().ResolveLinkedAddress(); |
| 895 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 896 | const user_id_t func_user_id = MakeUserID(die->GetOffset()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 897 | func_sp.reset(new Function (sc.comp_unit, |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 898 | func_user_id, // UserID is the DIE offset |
| 899 | func_user_id, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 900 | func_name, |
| 901 | func_type, |
| 902 | func_range)); // first address range |
| 903 | |
| 904 | if (func_sp.get() != NULL) |
| 905 | { |
| Greg Clayton | 0bd4e1b | 2011-09-30 20:52:25 +0000 | [diff] [blame] | 906 | if (frame_base.IsValid()) |
| 907 | func_sp->GetFrameBaseExpression() = frame_base; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 908 | sc.comp_unit->AddFunction(func_sp); |
| 909 | return func_sp.get(); |
| 910 | } |
| 911 | } |
| 912 | } |
| 913 | return NULL; |
| 914 | } |
| 915 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 916 | lldb::LanguageType |
| 917 | SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc) |
| 918 | { |
| 919 | assert (sc.comp_unit); |
| 920 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| 921 | if (dwarf_cu) |
| 922 | { |
| 923 | const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly(); |
| Jim Ingham | 28eb571 | 2012-10-12 17:34:26 +0000 | [diff] [blame] | 924 | if (die) |
| 925 | { |
| 926 | const uint32_t language = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0); |
| 927 | if (language) |
| 928 | return (lldb::LanguageType)language; |
| 929 | } |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 930 | } |
| 931 | return eLanguageTypeUnknown; |
| 932 | } |
| 933 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 934 | size_t |
| 935 | SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc) |
| 936 | { |
| 937 | assert (sc.comp_unit); |
| 938 | size_t functions_added = 0; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 939 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 940 | if (dwarf_cu) |
| 941 | { |
| 942 | DWARFDIECollection function_dies; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 943 | 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] | 944 | size_t func_idx; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 945 | for (func_idx = 0; func_idx < num_functions; ++func_idx) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 946 | { |
| 947 | const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 948 | if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 949 | { |
| 950 | if (ParseCompileUnitFunction(sc, dwarf_cu, die)) |
| 951 | ++functions_added; |
| 952 | } |
| 953 | } |
| 954 | //FixupTypes(); |
| 955 | } |
| 956 | return functions_added; |
| 957 | } |
| 958 | |
| 959 | bool |
| 960 | SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files) |
| 961 | { |
| 962 | assert (sc.comp_unit); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 963 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 964 | assert (dwarf_cu); |
| 965 | const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 966 | |
| 967 | if (cu_die) |
| 968 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 969 | const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL); |
| 970 | 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] | 971 | |
| 972 | // All file indexes in DWARF are one based and a file of index zero is |
| 973 | // supposed to be the compile unit itself. |
| 974 | support_files.Append (*sc.comp_unit); |
| 975 | |
| Greg Clayton | d804d28 | 2012-03-15 21:01:31 +0000 | [diff] [blame] | 976 | return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 977 | } |
| 978 | return false; |
| 979 | } |
| 980 | |
| 981 | struct ParseDWARFLineTableCallbackInfo |
| 982 | { |
| 983 | LineTable* line_table; |
| 984 | const SectionList *section_list; |
| 985 | lldb::addr_t prev_sect_file_base_addr; |
| 986 | lldb::addr_t curr_sect_file_base_addr; |
| 987 | bool is_oso_for_debug_map; |
| 988 | bool prev_in_final_executable; |
| 989 | DWARFDebugLine::Row prev_row; |
| 990 | SectionSP prev_section_sp; |
| 991 | SectionSP curr_section_sp; |
| 992 | }; |
| 993 | |
| 994 | //---------------------------------------------------------------------- |
| 995 | // ParseStatementTableCallback |
| 996 | //---------------------------------------------------------------------- |
| 997 | static void |
| 998 | ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData) |
| 999 | { |
| 1000 | LineTable* line_table = ((ParseDWARFLineTableCallbackInfo*)userData)->line_table; |
| 1001 | if (state.row == DWARFDebugLine::State::StartParsingLineTable) |
| 1002 | { |
| 1003 | // Just started parsing the line table |
| 1004 | } |
| 1005 | else if (state.row == DWARFDebugLine::State::DoneParsingLineTable) |
| 1006 | { |
| 1007 | // Done parsing line table, nothing to do for the cleanup |
| 1008 | } |
| 1009 | else |
| 1010 | { |
| 1011 | ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData; |
| 1012 | // We have a new row, lets append it |
| 1013 | |
| 1014 | if (info->curr_section_sp.get() == NULL || info->curr_section_sp->ContainsFileAddress(state.address) == false) |
| 1015 | { |
| 1016 | info->prev_section_sp = info->curr_section_sp; |
| 1017 | info->prev_sect_file_base_addr = info->curr_sect_file_base_addr; |
| 1018 | // If this is an end sequence entry, then we subtract one from the |
| 1019 | // address to make sure we get an address that is not the end of |
| 1020 | // a section. |
| 1021 | if (state.end_sequence && state.address != 0) |
| 1022 | info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address - 1); |
| 1023 | else |
| 1024 | info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address); |
| 1025 | |
| 1026 | if (info->curr_section_sp.get()) |
| 1027 | info->curr_sect_file_base_addr = info->curr_section_sp->GetFileAddress (); |
| 1028 | else |
| 1029 | info->curr_sect_file_base_addr = 0; |
| 1030 | } |
| 1031 | if (info->curr_section_sp.get()) |
| 1032 | { |
| 1033 | lldb::addr_t curr_line_section_offset = state.address - info->curr_sect_file_base_addr; |
| 1034 | // Check for the fancy section magic to determine if we |
| 1035 | |
| 1036 | if (info->is_oso_for_debug_map) |
| 1037 | { |
| 1038 | // When this is a debug map object file that contains DWARF |
| 1039 | // (referenced from an N_OSO debug map nlist entry) we will have |
| 1040 | // a file address in the file range for our section from the |
| 1041 | // original .o file, and a load address in the executable that |
| 1042 | // contains the debug map. |
| 1043 | // |
| 1044 | // If the sections for the file range and load range are |
| 1045 | // different, we have a remapped section for the function and |
| 1046 | // this address is resolved. If they are the same, then the |
| 1047 | // function for this address didn't make it into the final |
| 1048 | // executable. |
| Jim Ingham | f94e179 | 2012-08-11 00:35:26 +0000 | [diff] [blame] | 1049 | bool curr_in_final_executable = (bool) info->curr_section_sp->GetLinkedSection (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1050 | |
| 1051 | // If we are doing DWARF with debug map, then we need to carefully |
| 1052 | // add each line table entry as there may be gaps as functions |
| 1053 | // get moved around or removed. |
| 1054 | if (!info->prev_row.end_sequence && info->prev_section_sp.get()) |
| 1055 | { |
| 1056 | if (info->prev_in_final_executable) |
| 1057 | { |
| 1058 | bool terminate_previous_entry = false; |
| 1059 | if (!curr_in_final_executable) |
| 1060 | { |
| 1061 | // Check for the case where the previous line entry |
| 1062 | // in a function made it into the final executable, |
| 1063 | // yet the current line entry falls in a function |
| 1064 | // that didn't. The line table used to be contiguous |
| 1065 | // through this address range but now it isn't. We |
| 1066 | // need to terminate the previous line entry so |
| 1067 | // that we can reconstruct the line range correctly |
| 1068 | // for it and to keep the line table correct. |
| 1069 | terminate_previous_entry = true; |
| 1070 | } |
| 1071 | else if (info->curr_section_sp.get() != info->prev_section_sp.get()) |
| 1072 | { |
| 1073 | // Check for cases where the line entries used to be |
| 1074 | // contiguous address ranges, but now they aren't. |
| 1075 | // This can happen when order files specify the |
| 1076 | // ordering of the functions. |
| 1077 | lldb::addr_t prev_line_section_offset = info->prev_row.address - info->prev_sect_file_base_addr; |
| 1078 | Section *curr_sect = info->curr_section_sp.get(); |
| 1079 | Section *prev_sect = info->prev_section_sp.get(); |
| 1080 | assert (curr_sect->GetLinkedSection()); |
| 1081 | assert (prev_sect->GetLinkedSection()); |
| 1082 | lldb::addr_t object_file_addr_delta = state.address - info->prev_row.address; |
| 1083 | lldb::addr_t curr_linked_file_addr = curr_sect->GetLinkedFileAddress() + curr_line_section_offset; |
| 1084 | lldb::addr_t prev_linked_file_addr = prev_sect->GetLinkedFileAddress() + prev_line_section_offset; |
| 1085 | lldb::addr_t linked_file_addr_delta = curr_linked_file_addr - prev_linked_file_addr; |
| 1086 | if (object_file_addr_delta != linked_file_addr_delta) |
| 1087 | terminate_previous_entry = true; |
| 1088 | } |
| 1089 | |
| 1090 | if (terminate_previous_entry) |
| 1091 | { |
| 1092 | line_table->InsertLineEntry (info->prev_section_sp, |
| 1093 | state.address - info->prev_sect_file_base_addr, |
| 1094 | info->prev_row.line, |
| 1095 | info->prev_row.column, |
| 1096 | info->prev_row.file, |
| 1097 | false, // is_stmt |
| 1098 | false, // basic_block |
| 1099 | false, // state.prologue_end |
| 1100 | false, // state.epilogue_begin |
| 1101 | true); // end_sequence); |
| 1102 | } |
| 1103 | } |
| 1104 | } |
| 1105 | |
| 1106 | if (curr_in_final_executable) |
| 1107 | { |
| 1108 | line_table->InsertLineEntry (info->curr_section_sp, |
| 1109 | curr_line_section_offset, |
| 1110 | state.line, |
| 1111 | state.column, |
| 1112 | state.file, |
| 1113 | state.is_stmt, |
| 1114 | state.basic_block, |
| 1115 | state.prologue_end, |
| 1116 | state.epilogue_begin, |
| 1117 | state.end_sequence); |
| 1118 | info->prev_section_sp = info->curr_section_sp; |
| 1119 | } |
| 1120 | else |
| 1121 | { |
| 1122 | // If the current address didn't make it into the final |
| 1123 | // executable, the current section will be the __text |
| 1124 | // segment in the .o file, so we need to clear this so |
| 1125 | // we can catch the next function that did make it into |
| 1126 | // the final executable. |
| 1127 | info->prev_section_sp.reset(); |
| 1128 | info->curr_section_sp.reset(); |
| 1129 | } |
| 1130 | |
| 1131 | info->prev_in_final_executable = curr_in_final_executable; |
| 1132 | } |
| 1133 | else |
| 1134 | { |
| 1135 | // We are not in an object file that contains DWARF for an |
| 1136 | // N_OSO, this is just a normal DWARF file. The DWARF spec |
| 1137 | // guarantees that the addresses will be in increasing order |
| 1138 | // so, since we store line tables in file address order, we |
| 1139 | // can always just append the line entry without needing to |
| 1140 | // search for the correct insertion point (we don't need to |
| 1141 | // use LineEntry::InsertLineEntry()). |
| 1142 | line_table->AppendLineEntry (info->curr_section_sp, |
| 1143 | curr_line_section_offset, |
| 1144 | state.line, |
| 1145 | state.column, |
| 1146 | state.file, |
| 1147 | state.is_stmt, |
| 1148 | state.basic_block, |
| 1149 | state.prologue_end, |
| 1150 | state.epilogue_begin, |
| 1151 | state.end_sequence); |
| 1152 | } |
| 1153 | } |
| 1154 | |
| 1155 | info->prev_row = state; |
| 1156 | } |
| 1157 | } |
| 1158 | |
| 1159 | bool |
| 1160 | SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc) |
| 1161 | { |
| 1162 | assert (sc.comp_unit); |
| 1163 | if (sc.comp_unit->GetLineTable() != NULL) |
| 1164 | return true; |
| 1165 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1166 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1167 | if (dwarf_cu) |
| 1168 | { |
| 1169 | const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly(); |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1170 | if (dwarf_cu_die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1171 | { |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1172 | const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET); |
| 1173 | if (cu_line_offset != DW_INVALID_OFFSET) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1174 | { |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1175 | std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit)); |
| 1176 | if (line_table_ap.get()) |
| 1177 | { |
| 1178 | ParseDWARFLineTableCallbackInfo info = { |
| 1179 | line_table_ap.get(), |
| 1180 | m_obj_file->GetSectionList(), |
| 1181 | 0, |
| 1182 | 0, |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1183 | GetDebugMapSymfile () != NULL, |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1184 | false, |
| 1185 | DWARFDebugLine::Row(), |
| 1186 | SectionSP(), |
| 1187 | SectionSP() |
| 1188 | }; |
| 1189 | uint32_t offset = cu_line_offset; |
| 1190 | DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info); |
| 1191 | sc.comp_unit->SetLineTable(line_table_ap.release()); |
| 1192 | return true; |
| 1193 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1194 | } |
| 1195 | } |
| 1196 | } |
| 1197 | return false; |
| 1198 | } |
| 1199 | |
| 1200 | size_t |
| 1201 | SymbolFileDWARF::ParseFunctionBlocks |
| 1202 | ( |
| 1203 | const SymbolContext& sc, |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1204 | Block *parent_block, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1205 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1206 | const DWARFDebugInfoEntry *die, |
| 1207 | addr_t subprogram_low_pc, |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1208 | uint32_t depth |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1209 | ) |
| 1210 | { |
| 1211 | size_t blocks_added = 0; |
| 1212 | while (die != NULL) |
| 1213 | { |
| 1214 | dw_tag_t tag = die->Tag(); |
| 1215 | |
| 1216 | switch (tag) |
| 1217 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1218 | case DW_TAG_inlined_subroutine: |
| Greg Clayton | b4d3733 | 2011-08-12 16:22:48 +0000 | [diff] [blame] | 1219 | case DW_TAG_subprogram: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1220 | case DW_TAG_lexical_block: |
| 1221 | { |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1222 | Block *block = NULL; |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1223 | if (tag == DW_TAG_subprogram) |
| 1224 | { |
| 1225 | // Skip any DW_TAG_subprogram DIEs that are inside |
| 1226 | // of a normal or inlined functions. These will be |
| 1227 | // parsed on their own as separate entities. |
| 1228 | |
| 1229 | if (depth > 0) |
| 1230 | break; |
| 1231 | |
| 1232 | block = parent_block; |
| 1233 | } |
| 1234 | else |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1235 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1236 | BlockSP block_sp(new Block (MakeUserID(die->GetOffset()))); |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1237 | parent_block->AddChild(block_sp); |
| 1238 | block = block_sp.get(); |
| 1239 | } |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1240 | DWARFDebugRanges::RangeList ranges; |
| 1241 | const char *name = NULL; |
| 1242 | const char *mangled_name = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1243 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1244 | int decl_file = 0; |
| 1245 | int decl_line = 0; |
| 1246 | int decl_column = 0; |
| 1247 | int call_file = 0; |
| 1248 | int call_line = 0; |
| 1249 | int call_column = 0; |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1250 | if (die->GetDIENamesAndRanges (this, |
| 1251 | dwarf_cu, |
| 1252 | name, |
| 1253 | mangled_name, |
| 1254 | ranges, |
| 1255 | decl_file, decl_line, decl_column, |
| 1256 | call_file, call_line, call_column)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1257 | { |
| 1258 | if (tag == DW_TAG_subprogram) |
| 1259 | { |
| 1260 | assert (subprogram_low_pc == LLDB_INVALID_ADDRESS); |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1261 | subprogram_low_pc = ranges.GetMinRangeBase(0); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1262 | } |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1263 | else if (tag == DW_TAG_inlined_subroutine) |
| 1264 | { |
| 1265 | // We get called here for inlined subroutines in two ways. |
| 1266 | // The first time is when we are making the Function object |
| 1267 | // for this inlined concrete instance. Since we're creating a top level block at |
| 1268 | // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to |
| 1269 | // adjust the containing address. |
| 1270 | // The second time is when we are parsing the blocks inside the function that contains |
| 1271 | // the inlined concrete instance. Since these will be blocks inside the containing "real" |
| 1272 | // function the offset will be for that function. |
| 1273 | if (subprogram_low_pc == LLDB_INVALID_ADDRESS) |
| 1274 | { |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1275 | subprogram_low_pc = ranges.GetMinRangeBase(0); |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1276 | } |
| 1277 | } |
| 1278 | |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1279 | AddRangesToBlock (*block, ranges, subprogram_low_pc); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1280 | |
| 1281 | if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL)) |
| 1282 | { |
| 1283 | std::auto_ptr<Declaration> decl_ap; |
| 1284 | if (decl_file != 0 || decl_line != 0 || decl_column != 0) |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1285 | decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), |
| 1286 | decl_line, decl_column)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1287 | |
| 1288 | std::auto_ptr<Declaration> call_ap; |
| 1289 | if (call_file != 0 || call_line != 0 || call_column != 0) |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1290 | call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file), |
| 1291 | call_line, call_column)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1292 | |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1293 | block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1294 | } |
| 1295 | |
| 1296 | ++blocks_added; |
| 1297 | |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1298 | if (die->HasChildren()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1299 | { |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1300 | blocks_added += ParseFunctionBlocks (sc, |
| 1301 | block, |
| 1302 | dwarf_cu, |
| 1303 | die->GetFirstChild(), |
| 1304 | subprogram_low_pc, |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1305 | depth + 1); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1306 | } |
| 1307 | } |
| 1308 | } |
| 1309 | break; |
| 1310 | default: |
| 1311 | break; |
| 1312 | } |
| 1313 | |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1314 | // Only parse siblings of the block if we are not at depth zero. A depth |
| 1315 | // of zero indicates we are currently parsing the top level |
| 1316 | // DW_TAG_subprogram DIE |
| 1317 | |
| 1318 | if (depth == 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1319 | die = NULL; |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1320 | else |
| 1321 | die = die->GetSibling(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1322 | } |
| 1323 | return blocks_added; |
| 1324 | } |
| 1325 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1326 | bool |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1327 | SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu, |
| 1328 | const DWARFDebugInfoEntry *die, |
| 1329 | ClangASTContext::TemplateParameterInfos &template_param_infos) |
| 1330 | { |
| 1331 | const dw_tag_t tag = die->Tag(); |
| 1332 | |
| 1333 | switch (tag) |
| 1334 | { |
| 1335 | case DW_TAG_template_type_parameter: |
| 1336 | case DW_TAG_template_value_parameter: |
| 1337 | { |
| 1338 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| 1339 | |
| 1340 | DWARFDebugInfoEntry::Attributes attributes; |
| 1341 | const size_t num_attributes = die->GetAttributes (this, |
| 1342 | dwarf_cu, |
| 1343 | fixed_form_sizes, |
| 1344 | attributes); |
| 1345 | const char *name = NULL; |
| 1346 | Type *lldb_type = NULL; |
| 1347 | clang_type_t clang_type = NULL; |
| 1348 | uint64_t uval64 = 0; |
| 1349 | bool uval64_valid = false; |
| 1350 | if (num_attributes > 0) |
| 1351 | { |
| 1352 | DWARFFormValue form_value; |
| 1353 | for (size_t i=0; i<num_attributes; ++i) |
| 1354 | { |
| 1355 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 1356 | |
| 1357 | switch (attr) |
| 1358 | { |
| 1359 | case DW_AT_name: |
| 1360 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1361 | name = form_value.AsCString(&get_debug_str_data()); |
| 1362 | break; |
| 1363 | |
| 1364 | case DW_AT_type: |
| 1365 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1366 | { |
| 1367 | const dw_offset_t type_die_offset = form_value.Reference(dwarf_cu); |
| 1368 | lldb_type = ResolveTypeUID(type_die_offset); |
| 1369 | if (lldb_type) |
| 1370 | clang_type = lldb_type->GetClangForwardType(); |
| 1371 | } |
| 1372 | break; |
| 1373 | |
| 1374 | case DW_AT_const_value: |
| 1375 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1376 | { |
| 1377 | uval64_valid = true; |
| 1378 | uval64 = form_value.Unsigned(); |
| 1379 | } |
| 1380 | break; |
| 1381 | default: |
| 1382 | break; |
| 1383 | } |
| 1384 | } |
| 1385 | |
| 1386 | if (name && lldb_type && clang_type) |
| 1387 | { |
| 1388 | bool is_signed = false; |
| 1389 | template_param_infos.names.push_back(name); |
| 1390 | clang::QualType clang_qual_type (clang::QualType::getFromOpaquePtr (clang_type)); |
| 1391 | if (tag == DW_TAG_template_value_parameter && ClangASTContext::IsIntegerType (clang_type, is_signed) && uval64_valid) |
| 1392 | { |
| 1393 | llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed); |
| Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1394 | template_param_infos.args.push_back (clang::TemplateArgument (*GetClangASTContext().getASTContext(), |
| 1395 | llvm::APSInt(apint), |
| 1396 | clang_qual_type)); |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1397 | } |
| 1398 | else |
| 1399 | { |
| 1400 | template_param_infos.args.push_back (clang::TemplateArgument (clang_qual_type)); |
| 1401 | } |
| 1402 | } |
| 1403 | else |
| 1404 | { |
| 1405 | return false; |
| 1406 | } |
| 1407 | |
| 1408 | } |
| 1409 | } |
| 1410 | return true; |
| 1411 | |
| 1412 | default: |
| 1413 | break; |
| 1414 | } |
| 1415 | return false; |
| 1416 | } |
| 1417 | |
| 1418 | bool |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1419 | SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu, |
| 1420 | const DWARFDebugInfoEntry *parent_die, |
| 1421 | ClangASTContext::TemplateParameterInfos &template_param_infos) |
| 1422 | { |
| 1423 | |
| 1424 | if (parent_die == NULL) |
| Filipe Cabecinhas | 52008c6 | 2012-05-23 16:24:11 +0000 | [diff] [blame] | 1425 | return false; |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1426 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1427 | Args template_parameter_names; |
| 1428 | for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); |
| 1429 | die != NULL; |
| 1430 | die = die->GetSibling()) |
| 1431 | { |
| 1432 | const dw_tag_t tag = die->Tag(); |
| 1433 | |
| 1434 | switch (tag) |
| 1435 | { |
| 1436 | case DW_TAG_template_type_parameter: |
| 1437 | case DW_TAG_template_value_parameter: |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1438 | ParseTemplateDIE (dwarf_cu, die, template_param_infos); |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1439 | break; |
| 1440 | |
| 1441 | default: |
| 1442 | break; |
| 1443 | } |
| 1444 | } |
| 1445 | if (template_param_infos.args.empty()) |
| 1446 | return false; |
| 1447 | return template_param_infos.args.size() == template_param_infos.names.size(); |
| 1448 | } |
| 1449 | |
| 1450 | clang::ClassTemplateDecl * |
| 1451 | SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx, |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1452 | lldb::AccessType access_type, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1453 | const char *parent_name, |
| 1454 | int tag_decl_kind, |
| 1455 | const ClangASTContext::TemplateParameterInfos &template_param_infos) |
| 1456 | { |
| 1457 | if (template_param_infos.IsValid()) |
| 1458 | { |
| 1459 | std::string template_basename(parent_name); |
| 1460 | template_basename.erase (template_basename.find('<')); |
| 1461 | ClangASTContext &ast = GetClangASTContext(); |
| 1462 | |
| 1463 | return ast.CreateClassTemplateDecl (decl_ctx, |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1464 | access_type, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1465 | template_basename.c_str(), |
| 1466 | tag_decl_kind, |
| 1467 | template_param_infos); |
| 1468 | } |
| 1469 | return NULL; |
| 1470 | } |
| 1471 | |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1472 | class SymbolFileDWARF::DelayedAddObjCClassProperty |
| 1473 | { |
| 1474 | public: |
| 1475 | DelayedAddObjCClassProperty |
| 1476 | ( |
| 1477 | clang::ASTContext *ast, |
| 1478 | lldb::clang_type_t class_opaque_type, |
| 1479 | const char *property_name, |
| 1480 | lldb::clang_type_t property_opaque_type, // The property type is only required if you don't have an ivar decl |
| 1481 | clang::ObjCIvarDecl *ivar_decl, |
| 1482 | const char *property_setter_name, |
| 1483 | const char *property_getter_name, |
| 1484 | uint32_t property_attributes, |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1485 | const ClangASTMetadata *metadata |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1486 | ) : |
| 1487 | m_ast (ast), |
| 1488 | m_class_opaque_type (class_opaque_type), |
| 1489 | m_property_name (property_name), |
| 1490 | m_property_opaque_type (property_opaque_type), |
| 1491 | m_ivar_decl (ivar_decl), |
| 1492 | m_property_setter_name (property_setter_name), |
| 1493 | m_property_getter_name (property_getter_name), |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1494 | m_property_attributes (property_attributes) |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1495 | { |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1496 | if (metadata != NULL) |
| 1497 | { |
| 1498 | m_metadata_ap.reset(new ClangASTMetadata()); |
| 1499 | *(m_metadata_ap.get()) = *metadata; |
| 1500 | } |
| 1501 | } |
| 1502 | |
| 1503 | DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs) |
| 1504 | { |
| 1505 | m_ast = rhs.m_ast; |
| 1506 | m_class_opaque_type = rhs.m_class_opaque_type; |
| 1507 | m_property_name = rhs.m_property_name; |
| 1508 | m_property_opaque_type = rhs.m_property_opaque_type; |
| 1509 | m_ivar_decl = rhs.m_ivar_decl; |
| 1510 | m_property_setter_name = rhs.m_property_setter_name; |
| 1511 | m_property_getter_name = rhs.m_property_getter_name; |
| 1512 | m_property_attributes = rhs.m_property_attributes; |
| 1513 | |
| 1514 | if (rhs.m_metadata_ap.get()) |
| 1515 | { |
| 1516 | m_metadata_ap.reset (new ClangASTMetadata()); |
| 1517 | *(m_metadata_ap.get()) = *(rhs.m_metadata_ap.get()); |
| 1518 | } |
| 1519 | |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1520 | } |
| 1521 | |
| 1522 | bool Finalize() const |
| 1523 | { |
| 1524 | return ClangASTContext::AddObjCClassProperty(m_ast, |
| 1525 | m_class_opaque_type, |
| 1526 | m_property_name, |
| 1527 | m_property_opaque_type, |
| 1528 | m_ivar_decl, |
| 1529 | m_property_setter_name, |
| 1530 | m_property_getter_name, |
| 1531 | m_property_attributes, |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1532 | m_metadata_ap.get()); |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1533 | } |
| 1534 | private: |
| 1535 | clang::ASTContext *m_ast; |
| 1536 | lldb::clang_type_t m_class_opaque_type; |
| 1537 | const char *m_property_name; |
| 1538 | lldb::clang_type_t m_property_opaque_type; |
| 1539 | clang::ObjCIvarDecl *m_ivar_decl; |
| 1540 | const char *m_property_setter_name; |
| 1541 | const char *m_property_getter_name; |
| 1542 | uint32_t m_property_attributes; |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1543 | std::auto_ptr<ClangASTMetadata> m_metadata_ap; |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1544 | }; |
| 1545 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1546 | size_t |
| 1547 | SymbolFileDWARF::ParseChildMembers |
| 1548 | ( |
| 1549 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1550 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1551 | const DWARFDebugInfoEntry *parent_die, |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1552 | clang_type_t class_clang_type, |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1553 | const LanguageType class_language, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1554 | std::vector<clang::CXXBaseSpecifier *>& base_classes, |
| 1555 | std::vector<int>& member_accessibilities, |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1556 | DWARFDIECollection& member_function_dies, |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1557 | DelayedPropertyList& delayed_properties, |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1558 | AccessType& default_accessibility, |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1559 | bool &is_a_class, |
| 1560 | LayoutInfo &layout_info |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1561 | ) |
| 1562 | { |
| 1563 | if (parent_die == NULL) |
| 1564 | return 0; |
| 1565 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1566 | size_t count = 0; |
| 1567 | const DWARFDebugInfoEntry *die; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 1568 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1569 | uint32_t member_idx = 0; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 1570 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1571 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 1572 | { |
| 1573 | dw_tag_t tag = die->Tag(); |
| 1574 | |
| 1575 | switch (tag) |
| 1576 | { |
| 1577 | case DW_TAG_member: |
| Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1578 | case DW_TAG_APPLE_property: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1579 | { |
| 1580 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1581 | const size_t num_attributes = die->GetAttributes (this, |
| 1582 | dwarf_cu, |
| 1583 | fixed_form_sizes, |
| 1584 | attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1585 | if (num_attributes > 0) |
| 1586 | { |
| 1587 | Declaration decl; |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1588 | //DWARFExpression location; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1589 | const char *name = NULL; |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1590 | const char *prop_name = NULL; |
| 1591 | const char *prop_getter_name = NULL; |
| 1592 | const char *prop_setter_name = NULL; |
| 1593 | uint32_t prop_attributes = 0; |
| 1594 | |
| 1595 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1596 | bool is_artificial = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1597 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1598 | AccessType accessibility = eAccessNone; |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1599 | uint32_t member_byte_offset = UINT32_MAX; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1600 | size_t byte_size = 0; |
| 1601 | size_t bit_offset = 0; |
| 1602 | size_t bit_size = 0; |
| 1603 | uint32_t i; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1604 | for (i=0; i<num_attributes && !is_artificial; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1605 | { |
| 1606 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 1607 | DWARFFormValue form_value; |
| 1608 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1609 | { |
| 1610 | switch (attr) |
| 1611 | { |
| 1612 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 1613 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 1614 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 1615 | case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; |
| 1616 | case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; |
| 1617 | case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break; |
| 1618 | case DW_AT_bit_size: bit_size = form_value.Unsigned(); break; |
| 1619 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; |
| 1620 | case DW_AT_data_member_location: |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1621 | if (form_value.BlockData()) |
| 1622 | { |
| 1623 | Value initialValue(0); |
| 1624 | Value memberOffset(0); |
| 1625 | const DataExtractor& debug_info_data = get_debug_info_data(); |
| 1626 | uint32_t block_length = form_value.Unsigned(); |
| 1627 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 1628 | if (DWARFExpression::Evaluate(NULL, // ExecutionContext * |
| 1629 | NULL, // clang::ASTContext * |
| 1630 | NULL, // ClangExpressionVariableList * |
| 1631 | NULL, // ClangExpressionDeclMap * |
| 1632 | NULL, // RegisterContext * |
| 1633 | debug_info_data, |
| 1634 | block_offset, |
| 1635 | block_length, |
| 1636 | eRegisterKindDWARF, |
| 1637 | &initialValue, |
| 1638 | memberOffset, |
| 1639 | NULL)) |
| 1640 | { |
| 1641 | member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt(); |
| 1642 | } |
| 1643 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1644 | break; |
| 1645 | |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1646 | case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break; |
| Greg Clayton | 1b02c17 | 2012-03-14 21:00:47 +0000 | [diff] [blame] | 1647 | case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break; |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1648 | case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break; |
| 1649 | case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break; |
| 1650 | case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break; |
| 1651 | case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break; |
| 1652 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1653 | default: |
| Greg Clayton | 1b02c17 | 2012-03-14 21:00:47 +0000 | [diff] [blame] | 1654 | case DW_AT_declaration: |
| 1655 | case DW_AT_description: |
| 1656 | case DW_AT_mutable: |
| 1657 | case DW_AT_visibility: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1658 | case DW_AT_sibling: |
| 1659 | break; |
| 1660 | } |
| 1661 | } |
| 1662 | } |
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1663 | |
| 1664 | if (prop_name) |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1665 | { |
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1666 | ConstString fixed_getter; |
| 1667 | ConstString fixed_setter; |
| 1668 | |
| 1669 | // Check if the property getter/setter were provided as full |
| 1670 | // names. We want basenames, so we extract them. |
| 1671 | |
| 1672 | if (prop_getter_name && prop_getter_name[0] == '-') |
| 1673 | { |
| 1674 | ObjCLanguageRuntime::ParseMethodName (prop_getter_name, |
| 1675 | NULL, |
| 1676 | &fixed_getter, |
| 1677 | NULL, |
| 1678 | NULL); |
| 1679 | prop_getter_name = fixed_getter.GetCString(); |
| 1680 | } |
| 1681 | |
| 1682 | if (prop_setter_name && prop_setter_name[0] == '-') |
| 1683 | { |
| 1684 | ObjCLanguageRuntime::ParseMethodName (prop_setter_name, |
| 1685 | NULL, |
| 1686 | &fixed_setter, |
| 1687 | NULL, |
| 1688 | NULL); |
| 1689 | prop_setter_name = fixed_setter.GetCString(); |
| 1690 | } |
| 1691 | |
| 1692 | // If the names haven't been provided, they need to be |
| 1693 | // filled in. |
| 1694 | |
| 1695 | if (!prop_getter_name) |
| 1696 | { |
| 1697 | prop_getter_name = prop_name; |
| 1698 | } |
| 1699 | if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly)) |
| 1700 | { |
| 1701 | StreamString ss; |
| 1702 | |
| 1703 | ss.Printf("set%c%s:", |
| 1704 | toupper(prop_name[0]), |
| 1705 | &prop_name[1]); |
| 1706 | |
| 1707 | fixed_setter.SetCString(ss.GetData()); |
| 1708 | prop_setter_name = fixed_setter.GetCString(); |
| 1709 | } |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1710 | } |
| 1711 | |
| 1712 | // Clang has a DWARF generation bug where sometimes it |
| Greg Clayton | 4495393 | 2011-10-25 01:25:35 +0000 | [diff] [blame] | 1713 | // represents fields that are references with bad byte size |
| 1714 | // and bit size/offset information such as: |
| 1715 | // |
| 1716 | // DW_AT_byte_size( 0x00 ) |
| 1717 | // DW_AT_bit_size( 0x40 ) |
| 1718 | // DW_AT_bit_offset( 0xffffffffffffffc0 ) |
| 1719 | // |
| 1720 | // So check the bit offset to make sure it is sane, and if |
| 1721 | // the values are not sane, remove them. If we don't do this |
| 1722 | // then we will end up with a crash if we try to use this |
| 1723 | // type in an expression when clang becomes unhappy with its |
| 1724 | // recycled debug info. |
| Sean Callanan | 5a477cf | 2010-10-30 01:56:10 +0000 | [diff] [blame] | 1725 | |
| Greg Clayton | 4495393 | 2011-10-25 01:25:35 +0000 | [diff] [blame] | 1726 | if (bit_offset > 128) |
| 1727 | { |
| 1728 | bit_size = 0; |
| 1729 | bit_offset = 0; |
| 1730 | } |
| 1731 | |
| 1732 | // FIXME: Make Clang ignore Objective-C accessibility for expressions |
| Sean Callanan | 5a477cf | 2010-10-30 01:56:10 +0000 | [diff] [blame] | 1733 | if (class_language == eLanguageTypeObjC || |
| 1734 | class_language == eLanguageTypeObjC_plus_plus) |
| 1735 | accessibility = eAccessNone; |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1736 | |
| 1737 | if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name)) |
| 1738 | { |
| 1739 | // Not all compilers will mark the vtable pointer |
| 1740 | // member as artificial (llvm-gcc). We can't have |
| 1741 | // the virtual members in our classes otherwise it |
| 1742 | // throws off all child offsets since we end up |
| 1743 | // having and extra pointer sized member in our |
| 1744 | // class layouts. |
| 1745 | is_artificial = true; |
| 1746 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1747 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1748 | if (is_artificial == false) |
| 1749 | { |
| 1750 | Type *member_type = ResolveTypeUID(encoding_uid); |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1751 | clang::FieldDecl *field_decl = NULL; |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1752 | if (tag == DW_TAG_member) |
| Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1753 | { |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1754 | if (member_type) |
| 1755 | { |
| 1756 | if (accessibility == eAccessNone) |
| 1757 | accessibility = default_accessibility; |
| 1758 | member_accessibilities.push_back(accessibility); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1759 | |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1760 | field_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type, |
| 1761 | name, |
| 1762 | member_type->GetClangLayoutType(), |
| 1763 | accessibility, |
| 1764 | bit_size); |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 1765 | |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1766 | GetClangASTContext().SetMetadataAsUserID ((uintptr_t)field_decl, MakeUserID(die->GetOffset())); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1767 | } |
| 1768 | else |
| 1769 | { |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1770 | if (name) |
| 1771 | GetObjectFile()->GetModule()->ReportError ("0x%8.8llx: DW_TAG_member '%s' refers to type 0x%8.8llx which was unable to be parsed", |
| 1772 | MakeUserID(die->GetOffset()), |
| 1773 | name, |
| 1774 | encoding_uid); |
| 1775 | else |
| 1776 | GetObjectFile()->GetModule()->ReportError ("0x%8.8llx: DW_TAG_member refers to type 0x%8.8llx which was unable to be parsed", |
| 1777 | MakeUserID(die->GetOffset()), |
| 1778 | encoding_uid); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1779 | } |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1780 | |
| 1781 | if (member_byte_offset != UINT32_MAX || bit_size != 0) |
| 1782 | { |
| 1783 | ///////////////////////////////////////////////////////////// |
| 1784 | // How to locate a field given the DWARF debug information |
| 1785 | // |
| 1786 | // AT_byte_size indicates the size of the word in which the |
| 1787 | // bit offset must be interpreted. |
| 1788 | // |
| 1789 | // AT_data_member_location indicates the byte offset of the |
| 1790 | // word from the base address of the structure. |
| 1791 | // |
| 1792 | // AT_bit_offset indicates how many bits into the word |
| 1793 | // (according to the host endianness) the low-order bit of |
| 1794 | // the field starts. AT_bit_offset can be negative. |
| 1795 | // |
| 1796 | // AT_bit_size indicates the size of the field in bits. |
| 1797 | ///////////////////////////////////////////////////////////// |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1798 | |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1799 | ByteOrder object_endian = GetObjectFile()->GetModule()->GetArchitecture().GetDefaultEndian(); |
| 1800 | |
| 1801 | uint64_t total_bit_offset = 0; |
| 1802 | |
| 1803 | total_bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8)); |
| 1804 | |
| 1805 | if (object_endian == eByteOrderLittle) |
| 1806 | { |
| 1807 | total_bit_offset += byte_size * 8; |
| 1808 | total_bit_offset -= (bit_offset + bit_size); |
| 1809 | } |
| 1810 | else |
| 1811 | { |
| 1812 | total_bit_offset += bit_offset; |
| 1813 | } |
| 1814 | |
| 1815 | layout_info.field_offsets.insert(std::make_pair(field_decl, total_bit_offset)); |
| 1816 | } |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1817 | } |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1818 | |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1819 | if (prop_name != NULL) |
| 1820 | { |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1821 | clang::ObjCIvarDecl *ivar_decl = NULL; |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1822 | |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1823 | if (field_decl) |
| 1824 | { |
| 1825 | ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl); |
| 1826 | assert (ivar_decl != NULL); |
| 1827 | } |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1828 | |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1829 | ClangASTMetadata metadata; |
| 1830 | metadata.SetUserID (MakeUserID(die->GetOffset())); |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1831 | delayed_properties.push_back(DelayedAddObjCClassProperty(GetClangASTContext().getASTContext(), |
| 1832 | class_clang_type, |
| 1833 | prop_name, |
| 1834 | member_type->GetClangLayoutType(), |
| 1835 | ivar_decl, |
| 1836 | prop_setter_name, |
| 1837 | prop_getter_name, |
| 1838 | prop_attributes, |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1839 | &metadata)); |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 1840 | |
| Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 1841 | if (ivar_decl) |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1842 | GetClangASTContext().SetMetadataAsUserID ((uintptr_t)ivar_decl, MakeUserID(die->GetOffset())); |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1843 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1844 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1845 | } |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1846 | ++member_idx; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1847 | } |
| 1848 | break; |
| 1849 | |
| 1850 | case DW_TAG_subprogram: |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1851 | // Let the type parsing code handle this one for us. |
| 1852 | member_function_dies.Append (die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1853 | break; |
| 1854 | |
| 1855 | case DW_TAG_inheritance: |
| 1856 | { |
| 1857 | is_a_class = true; |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1858 | if (default_accessibility == eAccessNone) |
| 1859 | default_accessibility = eAccessPrivate; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1860 | // TODO: implement DW_TAG_inheritance type parsing |
| 1861 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1862 | const size_t num_attributes = die->GetAttributes (this, |
| 1863 | dwarf_cu, |
| 1864 | fixed_form_sizes, |
| 1865 | attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1866 | if (num_attributes > 0) |
| 1867 | { |
| 1868 | Declaration decl; |
| 1869 | DWARFExpression location; |
| 1870 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1871 | AccessType accessibility = default_accessibility; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1872 | bool is_virtual = false; |
| 1873 | bool is_base_of_class = true; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 1874 | //off_t member_offset = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1875 | uint32_t i; |
| 1876 | for (i=0; i<num_attributes; ++i) |
| 1877 | { |
| 1878 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 1879 | DWARFFormValue form_value; |
| 1880 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1881 | { |
| 1882 | switch (attr) |
| 1883 | { |
| 1884 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 1885 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 1886 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 1887 | case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 1888 | // case DW_AT_data_member_location: |
| 1889 | // if (form_value.BlockData()) |
| 1890 | // { |
| 1891 | // Value initialValue(0); |
| 1892 | // Value memberOffset(0); |
| 1893 | // const DataExtractor& debug_info_data = get_debug_info_data(); |
| 1894 | // uint32_t block_length = form_value.Unsigned(); |
| 1895 | // uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 1896 | // if (DWARFExpression::Evaluate (NULL, |
| 1897 | // NULL, |
| 1898 | // NULL, |
| 1899 | // NULL, |
| 1900 | // NULL, |
| 1901 | // debug_info_data, |
| 1902 | // block_offset, |
| 1903 | // block_length, |
| 1904 | // eRegisterKindDWARF, |
| 1905 | // &initialValue, |
| 1906 | // memberOffset, |
| 1907 | // NULL)) |
| 1908 | // { |
| 1909 | // member_offset = memberOffset.ResolveValue(NULL, NULL).UInt(); |
| 1910 | // } |
| 1911 | // } |
| 1912 | // break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1913 | |
| 1914 | case DW_AT_accessibility: |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1915 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1916 | break; |
| 1917 | |
| 1918 | case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break; |
| 1919 | default: |
| 1920 | case DW_AT_sibling: |
| 1921 | break; |
| 1922 | } |
| 1923 | } |
| 1924 | } |
| 1925 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 1926 | Type *base_class_type = ResolveTypeUID(encoding_uid); |
| 1927 | assert(base_class_type); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1928 | |
| Greg Clayton | f4ecaa5 | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 1929 | clang_type_t base_class_clang_type = base_class_type->GetClangFullType(); |
| 1930 | assert (base_class_clang_type); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1931 | if (class_language == eLanguageTypeObjC) |
| 1932 | { |
| Greg Clayton | f4ecaa5 | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 1933 | GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1934 | } |
| 1935 | else |
| 1936 | { |
| Greg Clayton | f4ecaa5 | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 1937 | base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type, |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1938 | accessibility, |
| 1939 | is_virtual, |
| 1940 | is_base_of_class)); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1941 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1942 | } |
| 1943 | } |
| 1944 | break; |
| 1945 | |
| 1946 | default: |
| 1947 | break; |
| 1948 | } |
| 1949 | } |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1950 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1951 | return count; |
| 1952 | } |
| 1953 | |
| 1954 | |
| 1955 | clang::DeclContext* |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 1956 | SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1957 | { |
| 1958 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1959 | if (debug_info && UserIDMatches(type_uid)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1960 | { |
| 1961 | DWARFCompileUnitSP cu_sp; |
| 1962 | const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp); |
| 1963 | if (die) |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 1964 | return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL); |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 1965 | } |
| 1966 | return NULL; |
| 1967 | } |
| 1968 | |
| 1969 | clang::DeclContext* |
| 1970 | SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid) |
| 1971 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1972 | if (UserIDMatches(type_uid)) |
| 1973 | return GetClangDeclContextForDIEOffset (sc, type_uid); |
| 1974 | return NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1975 | } |
| 1976 | |
| 1977 | Type* |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 1978 | SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1979 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1980 | if (UserIDMatches(type_uid)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1981 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1982 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 1983 | if (debug_info) |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 1984 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1985 | DWARFCompileUnitSP cu_sp; |
| 1986 | const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp); |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1987 | const bool assert_not_being_parsed = true; |
| 1988 | return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 1989 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1990 | } |
| 1991 | return NULL; |
| 1992 | } |
| 1993 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1994 | Type* |
| 1995 | SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed) |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1996 | { |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1997 | if (die != NULL) |
| 1998 | { |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1999 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| 2000 | if (log) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2001 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 2002 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'", |
| 2003 | die->GetOffset(), |
| 2004 | DW_TAG_value_to_name(die->Tag()), |
| 2005 | die->GetName(this, cu)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2006 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2007 | // We might be coming in in the middle of a type tree (a class |
| 2008 | // withing a class, an enum within a class), so parse any needed |
| 2009 | // parent DIEs before we get to this one... |
| 2010 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); |
| 2011 | switch (decl_ctx_die->Tag()) |
| 2012 | { |
| 2013 | case DW_TAG_structure_type: |
| 2014 | case DW_TAG_union_type: |
| 2015 | case DW_TAG_class_type: |
| 2016 | { |
| 2017 | // Get the type, which could be a forward declaration |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2018 | if (log) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2019 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 2020 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x", |
| 2021 | die->GetOffset(), |
| 2022 | DW_TAG_value_to_name(die->Tag()), |
| 2023 | die->GetName(this, cu), |
| 2024 | decl_ctx_die->GetOffset()); |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2025 | // |
| 2026 | // Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed); |
| 2027 | // if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag())) |
| 2028 | // { |
| 2029 | // if (log) |
| 2030 | // GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 2031 | // "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function", |
| 2032 | // die->GetOffset(), |
| 2033 | // DW_TAG_value_to_name(die->Tag()), |
| 2034 | // die->GetName(this, cu), |
| 2035 | // decl_ctx_die->GetOffset()); |
| 2036 | // // Ask the type to complete itself if it already hasn't since if we |
| 2037 | // // want a function (method or static) from a class, the class must |
| 2038 | // // create itself and add it's own methods and class functions. |
| 2039 | // if (parent_type) |
| 2040 | // parent_type->GetClangFullType(); |
| 2041 | // } |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2042 | } |
| 2043 | break; |
| 2044 | |
| 2045 | default: |
| 2046 | break; |
| 2047 | } |
| 2048 | return ResolveType (cu, die); |
| 2049 | } |
| 2050 | return NULL; |
| 2051 | } |
| 2052 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2053 | // This function is used when SymbolFileDWARFDebugMap owns a bunch of |
| 2054 | // SymbolFileDWARF objects to detect if this DWARF file is the one that |
| 2055 | // can resolve a clang_type. |
| 2056 | bool |
| 2057 | SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type) |
| 2058 | { |
| 2059 | clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type); |
| 2060 | const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers); |
| 2061 | return die != NULL; |
| 2062 | } |
| 2063 | |
| 2064 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2065 | lldb::clang_type_t |
| 2066 | SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type) |
| 2067 | { |
| 2068 | // 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] | 2069 | clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type); |
| 2070 | 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] | 2071 | if (die == NULL) |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2072 | { |
| 2073 | // We have already resolved this type... |
| 2074 | return clang_type; |
| 2075 | } |
| 2076 | // Once we start resolving this type, remove it from the forward declaration |
| 2077 | // map in case anyone child members or other types require this type to get resolved. |
| 2078 | // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition |
| 2079 | // are done. |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2080 | m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers); |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2081 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2082 | |
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 2083 | // Disable external storage for this type so we don't get anymore |
| 2084 | // clang::ExternalASTSource queries for this type. |
| 2085 | ClangASTContext::SetHasExternalStorage (clang_type, false); |
| 2086 | |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2087 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2088 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2089 | DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get(); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2090 | Type *type = m_die_to_type.lookup (die); |
| 2091 | |
| 2092 | const dw_tag_t tag = die->Tag(); |
| 2093 | |
| Greg Clayton | baf95da | 2012-03-30 23:50:54 +0000 | [diff] [blame] | 2094 | LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2095 | if (log) |
| Greg Clayton | baf95da | 2012-03-30 23:50:54 +0000 | [diff] [blame] | 2096 | { |
| Greg Clayton | d61c0fc | 2012-04-23 22:55:20 +0000 | [diff] [blame] | 2097 | GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log.get(), |
| 2098 | "0x%8.8llx: %s '%s' resolving forward declaration...", |
| 2099 | MakeUserID(die->GetOffset()), |
| 2100 | DW_TAG_value_to_name(tag), |
| 2101 | type->GetName().AsCString()); |
| Greg Clayton | baf95da | 2012-03-30 23:50:54 +0000 | [diff] [blame] | 2102 | |
| Greg Clayton | baf95da | 2012-03-30 23:50:54 +0000 | [diff] [blame] | 2103 | } |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2104 | assert (clang_type); |
| 2105 | DWARFDebugInfoEntry::Attributes attributes; |
| 2106 | |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 2107 | ClangASTContext &ast = GetClangASTContext(); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2108 | |
| 2109 | switch (tag) |
| 2110 | { |
| 2111 | case DW_TAG_structure_type: |
| 2112 | case DW_TAG_union_type: |
| 2113 | case DW_TAG_class_type: |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2114 | { |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2115 | LayoutInfo layout_info; |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2116 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2117 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2118 | if (die->HasChildren()) |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2119 | { |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2120 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2121 | LanguageType class_language = eLanguageTypeUnknown; |
| 2122 | bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type); |
| 2123 | if (is_objc_class) |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2124 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2125 | class_language = eLanguageTypeObjC; |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2126 | // For objective C we don't start the definition when |
| 2127 | // the class is created. |
| 2128 | ast.StartTagDeclarationDefinition (clang_type); |
| 2129 | } |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2130 | |
| 2131 | int tag_decl_kind = -1; |
| 2132 | AccessType default_accessibility = eAccessNone; |
| 2133 | if (tag == DW_TAG_structure_type) |
| 2134 | { |
| 2135 | tag_decl_kind = clang::TTK_Struct; |
| 2136 | default_accessibility = eAccessPublic; |
| 2137 | } |
| 2138 | else if (tag == DW_TAG_union_type) |
| 2139 | { |
| 2140 | tag_decl_kind = clang::TTK_Union; |
| 2141 | default_accessibility = eAccessPublic; |
| 2142 | } |
| 2143 | else if (tag == DW_TAG_class_type) |
| 2144 | { |
| 2145 | tag_decl_kind = clang::TTK_Class; |
| 2146 | default_accessibility = eAccessPrivate; |
| 2147 | } |
| 2148 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2149 | SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2150 | std::vector<clang::CXXBaseSpecifier *> base_classes; |
| 2151 | std::vector<int> member_accessibilities; |
| 2152 | bool is_a_class = false; |
| 2153 | // Parse members and base classes first |
| 2154 | DWARFDIECollection member_function_dies; |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2155 | |
| 2156 | DelayedPropertyList delayed_properties; |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2157 | |
| 2158 | ParseChildMembers (sc, |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2159 | dwarf_cu, |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2160 | die, |
| 2161 | clang_type, |
| 2162 | class_language, |
| 2163 | base_classes, |
| 2164 | member_accessibilities, |
| 2165 | member_function_dies, |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2166 | delayed_properties, |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2167 | default_accessibility, |
| 2168 | is_a_class, |
| 2169 | layout_info); |
| 2170 | |
| 2171 | // Now parse any methods if there were any... |
| 2172 | size_t num_functions = member_function_dies.Size(); |
| 2173 | if (num_functions > 0) |
| 2174 | { |
| 2175 | for (size_t i=0; i<num_functions; ++i) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2176 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2177 | ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i)); |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2178 | } |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2179 | } |
| 2180 | |
| 2181 | if (class_language == eLanguageTypeObjC) |
| 2182 | { |
| Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 2183 | std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(ast.getASTContext(), clang_type)); |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2184 | if (!class_str.empty()) |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2185 | { |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2186 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2187 | DIEArray method_die_offsets; |
| 2188 | if (m_using_apple_tables) |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2189 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2190 | if (m_apple_objc_ap.get()) |
| 2191 | m_apple_objc_ap->FindByName(class_str.c_str(), method_die_offsets); |
| 2192 | } |
| 2193 | else |
| 2194 | { |
| 2195 | if (!m_indexed) |
| 2196 | Index (); |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2197 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2198 | ConstString class_name (class_str.c_str()); |
| 2199 | m_objc_class_selectors_index.Find (class_name, method_die_offsets); |
| 2200 | } |
| 2201 | |
| 2202 | if (!method_die_offsets.empty()) |
| 2203 | { |
| 2204 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2205 | |
| 2206 | DWARFCompileUnit* method_cu = NULL; |
| 2207 | const size_t num_matches = method_die_offsets.size(); |
| 2208 | for (size_t i=0; i<num_matches; ++i) |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2209 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2210 | const dw_offset_t die_offset = method_die_offsets[i]; |
| 2211 | DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu); |
| 2212 | |
| 2213 | if (method_die) |
| 2214 | ResolveType (method_cu, method_die); |
| 2215 | else |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2216 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2217 | if (m_using_apple_tables) |
| 2218 | { |
| 2219 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n", |
| 2220 | die_offset, class_str.c_str()); |
| 2221 | } |
| 2222 | } |
| 2223 | } |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2224 | } |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2225 | |
| 2226 | for (DelayedPropertyList::const_iterator pi = delayed_properties.begin(), pe = delayed_properties.end(); |
| 2227 | pi != pe; |
| 2228 | ++pi) |
| 2229 | pi->Finalize(); |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2230 | } |
| 2231 | } |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2232 | |
| 2233 | // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we |
| 2234 | // need to tell the clang type it is actually a class. |
| 2235 | if (class_language != eLanguageTypeObjC) |
| 2236 | { |
| 2237 | if (is_a_class && tag_decl_kind != clang::TTK_Class) |
| 2238 | ast.SetTagTypeKind (clang_type, clang::TTK_Class); |
| 2239 | } |
| 2240 | |
| 2241 | // Since DW_TAG_structure_type gets used for both classes |
| 2242 | // and structures, we may need to set any DW_TAG_member |
| 2243 | // fields to have a "private" access if none was specified. |
| 2244 | // When we parsed the child members we tracked that actual |
| 2245 | // accessibility value for each DW_TAG_member in the |
| 2246 | // "member_accessibilities" array. If the value for the |
| 2247 | // member is zero, then it was set to the "default_accessibility" |
| 2248 | // which for structs was "public". Below we correct this |
| 2249 | // by setting any fields to "private" that weren't correctly |
| 2250 | // set. |
| 2251 | if (is_a_class && !member_accessibilities.empty()) |
| 2252 | { |
| 2253 | // This is a class and all members that didn't have |
| 2254 | // their access specified are private. |
| 2255 | ast.SetDefaultAccessForRecordFields (clang_type, |
| 2256 | eAccessPrivate, |
| 2257 | &member_accessibilities.front(), |
| 2258 | member_accessibilities.size()); |
| 2259 | } |
| 2260 | |
| 2261 | if (!base_classes.empty()) |
| 2262 | { |
| 2263 | ast.SetBaseClassesForClassType (clang_type, |
| 2264 | &base_classes.front(), |
| 2265 | base_classes.size()); |
| 2266 | |
| 2267 | // Clang will copy each CXXBaseSpecifier in "base_classes" |
| 2268 | // so we have to free them all. |
| 2269 | ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(), |
| 2270 | base_classes.size()); |
| 2271 | } |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2272 | } |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2273 | } |
| Sean Callanan | e8c0cfb | 2012-03-02 01:03:45 +0000 | [diff] [blame] | 2274 | |
| 2275 | ast.BuildIndirectFields (clang_type); |
| 2276 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2277 | ast.CompleteTagDeclarationDefinition (clang_type); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2278 | |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2279 | if (!layout_info.field_offsets.empty()) |
| 2280 | { |
| 2281 | if (type) |
| 2282 | layout_info.bit_size = type->GetByteSize() * 8; |
| 2283 | if (layout_info.bit_size == 0) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2284 | layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8; |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2285 | clang::QualType qual_type(clang::QualType::getFromOpaquePtr(clang_type)); |
| 2286 | const clang::RecordType *record_type = clang::dyn_cast<clang::RecordType>(qual_type.getTypePtr()); |
| 2287 | if (record_type) |
| 2288 | { |
| 2289 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 2290 | |
| 2291 | if (log) |
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2292 | { |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2293 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2294 | "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) caching layout info for record_decl = %p, bit_size = %llu, alignment = %llu, field_offsets[%u], base_offsets[0], vbase_offsets[0])", |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2295 | clang_type, |
| 2296 | record_decl, |
| 2297 | layout_info.bit_size, |
| 2298 | layout_info.alignment, |
| 2299 | (uint32_t)layout_info.field_offsets.size()); |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2300 | |
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2301 | llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end(); |
| 2302 | for (pos = layout_info.field_offsets.begin(); pos != end; ++pos) |
| 2303 | { |
| 2304 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 2305 | "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field = { bit_offset=%u, name='%s' }", |
| 2306 | clang_type, |
| 2307 | (uint32_t)pos->second, |
| 2308 | pos->first->getNameAsString().c_str()); |
| 2309 | } |
| 2310 | } |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2311 | m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info)); |
| 2312 | } |
| 2313 | } |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2314 | } |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2315 | |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2316 | return clang_type; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2317 | |
| 2318 | case DW_TAG_enumeration_type: |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 2319 | ast.StartTagDeclarationDefinition (clang_type); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2320 | if (die->HasChildren()) |
| 2321 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2322 | SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); |
| 2323 | ParseChildEnumerators(sc, clang_type, type->GetByteSize(), dwarf_cu, die); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2324 | } |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 2325 | ast.CompleteTagDeclarationDefinition (clang_type); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2326 | return clang_type; |
| 2327 | |
| 2328 | default: |
| 2329 | assert(false && "not a forward clang type decl!"); |
| 2330 | break; |
| 2331 | } |
| 2332 | return NULL; |
| 2333 | } |
| 2334 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2335 | Type* |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2336 | 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] | 2337 | { |
| 2338 | if (type_die != NULL) |
| 2339 | { |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 2340 | Type *type = m_die_to_type.lookup (type_die); |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2341 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2342 | if (type == NULL) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2343 | type = GetTypeForDIE (dwarf_cu, type_die).get(); |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2344 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2345 | if (assert_not_being_parsed) |
| Jim Ingham | c354928 | 2012-01-11 02:21:12 +0000 | [diff] [blame] | 2346 | { |
| 2347 | if (type != DIE_IS_BEING_PARSED) |
| 2348 | return type; |
| 2349 | |
| 2350 | 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] | 2351 | type_die->GetOffset(), |
| 2352 | DW_TAG_value_to_name(type_die->Tag()), |
| 2353 | type_die->GetName(this, dwarf_cu)); |
| Jim Ingham | c354928 | 2012-01-11 02:21:12 +0000 | [diff] [blame] | 2354 | |
| 2355 | } |
| 2356 | else |
| 2357 | return type; |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2358 | } |
| 2359 | return NULL; |
| 2360 | } |
| 2361 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2362 | CompileUnit* |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2363 | SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2364 | { |
| 2365 | // Check if the symbol vendor already knows about this compile unit? |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2366 | if (dwarf_cu->GetUserData() == NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2367 | { |
| 2368 | // The symbol vendor doesn't know about this compile unit, we |
| 2369 | // need to parse and add it to the symbol vendor object. |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2370 | return ParseCompileUnit(dwarf_cu, cu_idx).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2371 | } |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2372 | return (CompileUnit*)dwarf_cu->GetUserData(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2373 | } |
| 2374 | |
| 2375 | bool |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2376 | SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2377 | { |
| 2378 | sc.Clear(); |
| 2379 | // Check if the symbol vendor already knows about this compile unit? |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2380 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2381 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2382 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2383 | if (sc.function == NULL) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2384 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2385 | |
| 2386 | if (sc.function) |
| 2387 | { |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 2388 | sc.module_sp = sc.function->CalculateSymbolContextModule(); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2389 | return true; |
| 2390 | } |
| 2391 | |
| 2392 | return false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2393 | } |
| 2394 | |
| 2395 | uint32_t |
| 2396 | SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) |
| 2397 | { |
| 2398 | Timer scoped_timer(__PRETTY_FUNCTION__, |
| 2399 | "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%llx }, resolve_scope = 0x%8.8x)", |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 2400 | so_addr.GetSection().get(), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2401 | so_addr.GetOffset(), |
| 2402 | resolve_scope); |
| 2403 | uint32_t resolved = 0; |
| 2404 | if (resolve_scope & ( eSymbolContextCompUnit | |
| 2405 | eSymbolContextFunction | |
| 2406 | eSymbolContextBlock | |
| 2407 | eSymbolContextLineEntry)) |
| 2408 | { |
| 2409 | lldb::addr_t file_vm_addr = so_addr.GetFileAddress(); |
| 2410 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2411 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2412 | if (debug_info) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2413 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2414 | 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] | 2415 | if (cu_offset != DW_INVALID_OFFSET) |
| 2416 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2417 | uint32_t cu_idx = DW_INVALID_INDEX; |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2418 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get(); |
| 2419 | if (dwarf_cu) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2420 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2421 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2422 | if (sc.comp_unit) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2423 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2424 | resolved |= eSymbolContextCompUnit; |
| 2425 | |
| 2426 | if (resolve_scope & eSymbolContextLineEntry) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2427 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2428 | LineTable *line_table = sc.comp_unit->GetLineTable(); |
| 2429 | if (line_table != NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2430 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2431 | if (so_addr.IsLinkedAddress()) |
| 2432 | { |
| 2433 | Address linked_addr (so_addr); |
| 2434 | linked_addr.ResolveLinkedAddress(); |
| 2435 | if (line_table->FindLineEntryByAddress (linked_addr, sc.line_entry)) |
| 2436 | { |
| 2437 | resolved |= eSymbolContextLineEntry; |
| 2438 | } |
| 2439 | } |
| 2440 | else if (line_table->FindLineEntryByAddress (so_addr, sc.line_entry)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2441 | { |
| 2442 | resolved |= eSymbolContextLineEntry; |
| 2443 | } |
| 2444 | } |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2445 | } |
| 2446 | |
| 2447 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) |
| 2448 | { |
| 2449 | DWARFDebugInfoEntry *function_die = NULL; |
| 2450 | DWARFDebugInfoEntry *block_die = NULL; |
| 2451 | if (resolve_scope & eSymbolContextBlock) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2452 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2453 | dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die); |
| 2454 | } |
| 2455 | else |
| 2456 | { |
| 2457 | dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL); |
| 2458 | } |
| 2459 | |
| 2460 | if (function_die != NULL) |
| 2461 | { |
| 2462 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); |
| 2463 | if (sc.function == NULL) |
| 2464 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die); |
| 2465 | } |
| 2466 | else |
| 2467 | { |
| 2468 | // We might have had a compile unit that had discontiguous |
| 2469 | // address ranges where the gaps are symbols that don't have |
| 2470 | // any debug info. Discontiguous compile unit address ranges |
| 2471 | // should only happen when there aren't other functions from |
| 2472 | // other compile units in these gaps. This helps keep the size |
| 2473 | // of the aranges down. |
| 2474 | sc.comp_unit = NULL; |
| 2475 | resolved &= ~eSymbolContextCompUnit; |
| 2476 | } |
| 2477 | |
| 2478 | if (sc.function != NULL) |
| 2479 | { |
| 2480 | resolved |= eSymbolContextFunction; |
| 2481 | |
| 2482 | if (resolve_scope & eSymbolContextBlock) |
| 2483 | { |
| 2484 | Block& block = sc.function->GetBlock (true); |
| 2485 | |
| 2486 | if (block_die != NULL) |
| 2487 | sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); |
| 2488 | else |
| 2489 | sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); |
| 2490 | if (sc.block) |
| 2491 | resolved |= eSymbolContextBlock; |
| 2492 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2493 | } |
| 2494 | } |
| 2495 | } |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2496 | else |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2497 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2498 | GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.", |
| 2499 | cu_offset, |
| 2500 | cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2501 | } |
| 2502 | } |
| 2503 | } |
| 2504 | } |
| 2505 | } |
| 2506 | return resolved; |
| 2507 | } |
| 2508 | |
| 2509 | |
| 2510 | |
| 2511 | uint32_t |
| 2512 | SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) |
| 2513 | { |
| 2514 | const uint32_t prev_size = sc_list.GetSize(); |
| 2515 | if (resolve_scope & eSymbolContextCompUnit) |
| 2516 | { |
| 2517 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2518 | if (debug_info) |
| 2519 | { |
| 2520 | uint32_t cu_idx; |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2521 | DWARFCompileUnit* dwarf_cu = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2522 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2523 | 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] | 2524 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2525 | CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 2526 | const bool full_match = file_spec.GetDirectory(); |
| 2527 | 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] | 2528 | if (check_inlines || file_spec_matches_cu_file_spec) |
| 2529 | { |
| 2530 | SymbolContext sc (m_obj_file->GetModule()); |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2531 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2532 | if (sc.comp_unit) |
| 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 | uint32_t file_idx = UINT32_MAX; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2535 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2536 | // If we are looking for inline functions only and we don't |
| 2537 | // find it in the support files, we are done. |
| 2538 | if (check_inlines) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2539 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2540 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); |
| 2541 | if (file_idx == UINT32_MAX) |
| 2542 | continue; |
| 2543 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2544 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2545 | if (line != 0) |
| 2546 | { |
| 2547 | LineTable *line_table = sc.comp_unit->GetLineTable(); |
| 2548 | |
| 2549 | if (line_table != NULL && line != 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2550 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2551 | // We will have already looked up the file index if |
| 2552 | // we are searching for inline entries. |
| 2553 | if (!check_inlines) |
| 2554 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2555 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2556 | if (file_idx != UINT32_MAX) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2557 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2558 | uint32_t found_line; |
| 2559 | uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry); |
| 2560 | found_line = sc.line_entry.line; |
| 2561 | |
| 2562 | while (line_idx != UINT32_MAX) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2563 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2564 | sc.function = NULL; |
| 2565 | sc.block = NULL; |
| 2566 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2567 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2568 | const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress(); |
| 2569 | if (file_vm_addr != LLDB_INVALID_ADDRESS) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2570 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2571 | DWARFDebugInfoEntry *function_die = NULL; |
| 2572 | DWARFDebugInfoEntry *block_die = NULL; |
| 2573 | 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] | 2574 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2575 | if (function_die != NULL) |
| 2576 | { |
| 2577 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); |
| 2578 | if (sc.function == NULL) |
| 2579 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die); |
| 2580 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2581 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2582 | if (sc.function != NULL) |
| 2583 | { |
| 2584 | Block& block = sc.function->GetBlock (true); |
| 2585 | |
| 2586 | if (block_die != NULL) |
| 2587 | sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); |
| 2588 | else |
| 2589 | sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); |
| 2590 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2591 | } |
| 2592 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2593 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2594 | sc_list.Append(sc); |
| 2595 | line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry); |
| 2596 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2597 | } |
| 2598 | } |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2599 | else if (file_spec_matches_cu_file_spec && !check_inlines) |
| 2600 | { |
| 2601 | // only append the context if we aren't looking for inline call sites |
| 2602 | // by file and line and if the file spec matches that of the compile unit |
| 2603 | sc_list.Append(sc); |
| 2604 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2605 | } |
| 2606 | else if (file_spec_matches_cu_file_spec && !check_inlines) |
| 2607 | { |
| 2608 | // only append the context if we aren't looking for inline call sites |
| 2609 | // by file and line and if the file spec matches that of the compile unit |
| 2610 | sc_list.Append(sc); |
| 2611 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2612 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2613 | if (!check_inlines) |
| 2614 | break; |
| 2615 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2616 | } |
| 2617 | } |
| 2618 | } |
| 2619 | } |
| 2620 | return sc_list.GetSize() - prev_size; |
| 2621 | } |
| 2622 | |
| 2623 | void |
| 2624 | SymbolFileDWARF::Index () |
| 2625 | { |
| 2626 | if (m_indexed) |
| 2627 | return; |
| 2628 | m_indexed = true; |
| 2629 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 2630 | "SymbolFileDWARF::Index (%s)", |
| 2631 | GetObjectFile()->GetFileSpec().GetFilename().AsCString()); |
| 2632 | |
| 2633 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2634 | if (debug_info) |
| 2635 | { |
| 2636 | uint32_t cu_idx = 0; |
| 2637 | const uint32_t num_compile_units = GetNumCompileUnits(); |
| 2638 | for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) |
| 2639 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2640 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2641 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2642 | bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2643 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2644 | dwarf_cu->Index (cu_idx, |
| 2645 | m_function_basename_index, |
| 2646 | m_function_fullname_index, |
| 2647 | m_function_method_index, |
| 2648 | m_function_selector_index, |
| 2649 | m_objc_class_selectors_index, |
| 2650 | m_global_index, |
| 2651 | m_type_index, |
| 2652 | m_namespace_index); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2653 | |
| 2654 | // Keep memory down by clearing DIEs if this generate function |
| 2655 | // caused them to be parsed |
| 2656 | if (clear_dies) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2657 | dwarf_cu->ClearDIEs (true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2658 | } |
| 2659 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2660 | m_function_basename_index.Finalize(); |
| 2661 | m_function_fullname_index.Finalize(); |
| 2662 | m_function_method_index.Finalize(); |
| 2663 | m_function_selector_index.Finalize(); |
| 2664 | m_objc_class_selectors_index.Finalize(); |
| 2665 | m_global_index.Finalize(); |
| 2666 | m_type_index.Finalize(); |
| 2667 | m_namespace_index.Finalize(); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2668 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2669 | #if defined (ENABLE_DEBUG_PRINTF) |
| Greg Clayton | 7bd65b9 | 2011-02-09 23:39:34 +0000 | [diff] [blame] | 2670 | StreamFile s(stdout, false); |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 2671 | s.Printf ("DWARF index for '%s/%s':", |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2672 | GetObjectFile()->GetFileSpec().GetDirectory().AsCString(), |
| 2673 | GetObjectFile()->GetFileSpec().GetFilename().AsCString()); |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 2674 | s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s); |
| 2675 | s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s); |
| 2676 | s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s); |
| 2677 | s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s); |
| 2678 | s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s); |
| 2679 | s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s); |
| Greg Clayton | 69b0488 | 2010-10-15 02:03:22 +0000 | [diff] [blame] | 2680 | s.Printf("\nTypes:\n"); m_type_index.Dump (&s); |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 2681 | s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2682 | #endif |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2683 | } |
| 2684 | } |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2685 | |
| 2686 | bool |
| 2687 | SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl) |
| 2688 | { |
| 2689 | if (namespace_decl == NULL) |
| 2690 | { |
| 2691 | // Invalid namespace decl which means we aren't matching only things |
| 2692 | // in this symbol file, so return true to indicate it matches this |
| 2693 | // symbol file. |
| 2694 | return true; |
| 2695 | } |
| 2696 | |
| 2697 | clang::ASTContext *namespace_ast = namespace_decl->GetASTContext(); |
| 2698 | |
| 2699 | if (namespace_ast == NULL) |
| 2700 | return true; // No AST in the "namespace_decl", return true since it |
| 2701 | // could then match any symbol file, including this one |
| 2702 | |
| 2703 | if (namespace_ast == GetClangASTContext().getASTContext()) |
| 2704 | return true; // The ASTs match, return true |
| 2705 | |
| 2706 | // The namespace AST was valid, and it does not match... |
| Sean Callanan | c41e68b | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 2707 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 2708 | |
| 2709 | if (log) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2710 | GetObjectFile()->GetModule()->LogMessage(log.get(), "Valid namespace does not match symbol file"); |
| Sean Callanan | c41e68b | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 2711 | |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2712 | return false; |
| 2713 | } |
| 2714 | |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2715 | bool |
| 2716 | SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl, |
| 2717 | DWARFCompileUnit* cu, |
| 2718 | const DWARFDebugInfoEntry* die) |
| 2719 | { |
| 2720 | // No namespace specified, so the answesr i |
| 2721 | if (namespace_decl == NULL) |
| 2722 | return true; |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2723 | |
| 2724 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2725 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2726 | const DWARFDebugInfoEntry *decl_ctx_die = NULL; |
| 2727 | clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die); |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2728 | if (decl_ctx_die) |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2729 | { |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2730 | clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl(); |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2731 | |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2732 | if (clang_namespace_decl) |
| 2733 | { |
| 2734 | if (decl_ctx_die->Tag() != DW_TAG_namespace) |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2735 | { |
| 2736 | if (log) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2737 | GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent is not a namespace"); |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2738 | return false; |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2739 | } |
| 2740 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2741 | if (clang_namespace_decl == die_clang_decl_ctx) |
| 2742 | return true; |
| 2743 | else |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2744 | return false; |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2745 | } |
| 2746 | else |
| 2747 | { |
| 2748 | // We have a namespace_decl that was not NULL but it contained |
| 2749 | // a NULL "clang::NamespaceDecl", so this means the global namespace |
| 2750 | // So as long the the contained decl context DIE isn't a namespace |
| 2751 | // we should be ok. |
| 2752 | if (decl_ctx_die->Tag() != DW_TAG_namespace) |
| 2753 | return true; |
| 2754 | } |
| 2755 | } |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2756 | |
| 2757 | if (log) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2758 | GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent doesn't exist"); |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2759 | |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2760 | return false; |
| 2761 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2762 | uint32_t |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2763 | 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] | 2764 | { |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2765 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 2766 | |
| 2767 | if (log) |
| 2768 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2769 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 2770 | "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)", |
| 2771 | name.GetCString(), |
| 2772 | namespace_decl, |
| 2773 | append, |
| 2774 | max_matches); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2775 | } |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2776 | |
| 2777 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) |
| 2778 | return 0; |
| 2779 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2780 | DWARFDebugInfo* info = DebugInfo(); |
| 2781 | if (info == NULL) |
| 2782 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2783 | |
| 2784 | // If we aren't appending the results to this list, then clear the list |
| 2785 | if (!append) |
| 2786 | variables.Clear(); |
| 2787 | |
| 2788 | // Remember how many variables are in the list before we search in case |
| 2789 | // we are appending the results to a variable list. |
| 2790 | const uint32_t original_size = variables.GetSize(); |
| 2791 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2792 | DIEArray die_offsets; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2793 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2794 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2795 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2796 | if (m_apple_names_ap.get()) |
| 2797 | { |
| 2798 | const char *name_cstr = name.GetCString(); |
| 2799 | const char *base_name_start; |
| 2800 | const char *base_name_end = NULL; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2801 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2802 | if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end)) |
| 2803 | base_name_start = name_cstr; |
| 2804 | |
| 2805 | m_apple_names_ap->FindByName (base_name_start, die_offsets); |
| 2806 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2807 | } |
| 2808 | else |
| 2809 | { |
| 2810 | // Index the DWARF if we haven't already |
| 2811 | if (!m_indexed) |
| 2812 | Index (); |
| 2813 | |
| 2814 | m_global_index.Find (name, die_offsets); |
| 2815 | } |
| 2816 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2817 | const size_t num_die_matches = die_offsets.size(); |
| 2818 | if (num_die_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2819 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2820 | SymbolContext sc; |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 2821 | sc.module_sp = m_obj_file->GetModule(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2822 | assert (sc.module_sp); |
| 2823 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2824 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2825 | DWARFCompileUnit* dwarf_cu = NULL; |
| 2826 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2827 | bool done = false; |
| 2828 | for (size_t i=0; i<num_die_matches && !done; ++i) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2829 | { |
| 2830 | const dw_offset_t die_offset = die_offsets[i]; |
| 2831 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2832 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2833 | if (die) |
| 2834 | { |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2835 | switch (die->Tag()) |
| 2836 | { |
| 2837 | default: |
| 2838 | case DW_TAG_subprogram: |
| 2839 | case DW_TAG_inlined_subroutine: |
| 2840 | case DW_TAG_try_block: |
| 2841 | case DW_TAG_catch_block: |
| 2842 | break; |
| 2843 | |
| 2844 | case DW_TAG_variable: |
| 2845 | { |
| 2846 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2847 | |
| 2848 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 2849 | continue; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2850 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2851 | ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2852 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2853 | if (variables.GetSize() - original_size >= max_matches) |
| 2854 | done = true; |
| 2855 | } |
| 2856 | break; |
| 2857 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2858 | } |
| 2859 | else |
| 2860 | { |
| 2861 | if (m_using_apple_tables) |
| 2862 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2863 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n", |
| 2864 | die_offset, name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2865 | } |
| 2866 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2867 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2868 | } |
| 2869 | |
| 2870 | // Return the number of variable that were appended to the list |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2871 | const uint32_t num_matches = variables.GetSize() - original_size; |
| 2872 | if (log && num_matches > 0) |
| 2873 | { |
| 2874 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 2875 | "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u", |
| 2876 | name.GetCString(), |
| 2877 | namespace_decl, |
| 2878 | append, |
| 2879 | max_matches, |
| 2880 | num_matches); |
| 2881 | } |
| 2882 | return num_matches; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2883 | } |
| 2884 | |
| 2885 | uint32_t |
| 2886 | SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables) |
| 2887 | { |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2888 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 2889 | |
| 2890 | if (log) |
| 2891 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2892 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 2893 | "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)", |
| 2894 | regex.GetText(), |
| 2895 | append, |
| 2896 | max_matches); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2897 | } |
| 2898 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2899 | DWARFDebugInfo* info = DebugInfo(); |
| 2900 | if (info == NULL) |
| 2901 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2902 | |
| 2903 | // If we aren't appending the results to this list, then clear the list |
| 2904 | if (!append) |
| 2905 | variables.Clear(); |
| 2906 | |
| 2907 | // Remember how many variables are in the list before we search in case |
| 2908 | // we are appending the results to a variable list. |
| 2909 | const uint32_t original_size = variables.GetSize(); |
| 2910 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2911 | DIEArray die_offsets; |
| 2912 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2913 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2914 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2915 | if (m_apple_names_ap.get()) |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 2916 | { |
| 2917 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 2918 | if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) |
| 2919 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| 2920 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2921 | } |
| 2922 | else |
| 2923 | { |
| 2924 | // Index the DWARF if we haven't already |
| 2925 | if (!m_indexed) |
| 2926 | Index (); |
| 2927 | |
| 2928 | m_global_index.Find (regex, die_offsets); |
| 2929 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2930 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2931 | SymbolContext sc; |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 2932 | sc.module_sp = m_obj_file->GetModule(); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2933 | assert (sc.module_sp); |
| 2934 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2935 | DWARFCompileUnit* dwarf_cu = NULL; |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2936 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2937 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2938 | if (num_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2939 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2940 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2941 | for (size_t i=0; i<num_matches; ++i) |
| 2942 | { |
| 2943 | const dw_offset_t die_offset = die_offsets[i]; |
| 2944 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2945 | |
| 2946 | if (die) |
| 2947 | { |
| 2948 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2949 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2950 | ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2951 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2952 | if (variables.GetSize() - original_size >= max_matches) |
| 2953 | break; |
| 2954 | } |
| 2955 | else |
| 2956 | { |
| 2957 | if (m_using_apple_tables) |
| 2958 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2959 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n", |
| 2960 | die_offset, regex.GetText()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2961 | } |
| 2962 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2963 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2964 | } |
| 2965 | |
| 2966 | // Return the number of variable that were appended to the list |
| 2967 | return variables.GetSize() - original_size; |
| 2968 | } |
| 2969 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2970 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2971 | bool |
| 2972 | SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset, |
| 2973 | DWARFCompileUnit *&dwarf_cu, |
| 2974 | SymbolContextList& sc_list) |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2975 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2976 | const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| 2977 | return ResolveFunction (dwarf_cu, die, sc_list); |
| 2978 | } |
| 2979 | |
| 2980 | |
| 2981 | bool |
| 2982 | SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu, |
| 2983 | const DWARFDebugInfoEntry *die, |
| 2984 | SymbolContextList& sc_list) |
| 2985 | { |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2986 | SymbolContext sc; |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2987 | |
| 2988 | if (die == NULL) |
| 2989 | return false; |
| 2990 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2991 | // If we were passed a die that is not a function, just return false... |
| 2992 | if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine) |
| 2993 | return false; |
| 2994 | |
| 2995 | const DWARFDebugInfoEntry* inlined_die = NULL; |
| 2996 | if (die->Tag() == DW_TAG_inlined_subroutine) |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2997 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2998 | inlined_die = die; |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2999 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3000 | while ((die = die->GetParent()) != NULL) |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3001 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3002 | if (die->Tag() == DW_TAG_subprogram) |
| 3003 | break; |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3004 | } |
| 3005 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3006 | assert (die->Tag() == DW_TAG_subprogram); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3007 | if (GetFunction (cu, die, sc)) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3008 | { |
| 3009 | Address addr; |
| 3010 | // Parse all blocks if needed |
| 3011 | if (inlined_die) |
| 3012 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 3013 | sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset())); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3014 | assert (sc.block != NULL); |
| 3015 | if (sc.block->GetStartAddress (addr) == false) |
| 3016 | addr.Clear(); |
| 3017 | } |
| 3018 | else |
| 3019 | { |
| 3020 | sc.block = NULL; |
| 3021 | addr = sc.function->GetAddressRange().GetBaseAddress(); |
| 3022 | } |
| 3023 | |
| 3024 | if (addr.IsValid()) |
| 3025 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3026 | sc_list.Append(sc); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3027 | return true; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3028 | } |
| 3029 | } |
| 3030 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3031 | return false; |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3032 | } |
| 3033 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3034 | void |
| 3035 | SymbolFileDWARF::FindFunctions (const ConstString &name, |
| 3036 | const NameToDIE &name_to_die, |
| 3037 | SymbolContextList& sc_list) |
| 3038 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3039 | DIEArray die_offsets; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3040 | if (name_to_die.Find (name, die_offsets)) |
| 3041 | { |
| 3042 | ParseFunctions (die_offsets, sc_list); |
| 3043 | } |
| 3044 | } |
| 3045 | |
| 3046 | |
| 3047 | void |
| 3048 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, |
| 3049 | const NameToDIE &name_to_die, |
| 3050 | SymbolContextList& sc_list) |
| 3051 | { |
| 3052 | DIEArray die_offsets; |
| 3053 | if (name_to_die.Find (regex, die_offsets)) |
| 3054 | { |
| 3055 | ParseFunctions (die_offsets, sc_list); |
| 3056 | } |
| 3057 | } |
| 3058 | |
| 3059 | |
| 3060 | void |
| 3061 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, |
| 3062 | const DWARFMappedHash::MemoryTable &memory_table, |
| 3063 | SymbolContextList& sc_list) |
| 3064 | { |
| 3065 | DIEArray die_offsets; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3066 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 3067 | if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3068 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3069 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3070 | ParseFunctions (die_offsets, sc_list); |
| 3071 | } |
| 3072 | } |
| 3073 | |
| 3074 | void |
| 3075 | SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets, |
| 3076 | SymbolContextList& sc_list) |
| 3077 | { |
| 3078 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3079 | if (num_matches) |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3080 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3081 | SymbolContext sc; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3082 | |
| 3083 | DWARFCompileUnit* dwarf_cu = NULL; |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3084 | for (size_t i=0; i<num_matches; ++i) |
| Greg Clayton | d7e0546 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 3085 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3086 | const dw_offset_t die_offset = die_offsets[i]; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3087 | ResolveFunction (die_offset, dwarf_cu, sc_list); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3088 | } |
| 3089 | } |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3090 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3091 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3092 | bool |
| 3093 | SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die, |
| 3094 | const DWARFCompileUnit *dwarf_cu, |
| 3095 | uint32_t name_type_mask, |
| 3096 | const char *partial_name, |
| 3097 | const char *base_name_start, |
| 3098 | const char *base_name_end) |
| 3099 | { |
| 3100 | // If we are looking only for methods, throw away all the ones that aren't in C++ classes: |
| 3101 | if (name_type_mask == eFunctionNameTypeMethod |
| 3102 | || name_type_mask == eFunctionNameTypeBase) |
| 3103 | { |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 3104 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset()); |
| 3105 | if (!containing_decl_ctx) |
| 3106 | return false; |
| 3107 | |
| 3108 | bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()); |
| 3109 | |
| 3110 | if (!is_cxx_method && name_type_mask == eFunctionNameTypeMethod) |
| 3111 | return false; |
| 3112 | if (is_cxx_method && name_type_mask == eFunctionNameTypeBase) |
| 3113 | return false; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3114 | } |
| 3115 | |
| 3116 | // Now we need to check whether the name we got back for this type matches the extra specifications |
| 3117 | // that were in the name we're looking up: |
| 3118 | if (base_name_start != partial_name || *base_name_end != '\0') |
| 3119 | { |
| 3120 | // First see if the stuff to the left matches the full name. To do that let's see if |
| 3121 | // we can pull out the mips linkage name attribute: |
| 3122 | |
| 3123 | Mangled best_name; |
| 3124 | |
| 3125 | DWARFDebugInfoEntry::Attributes attributes; |
| 3126 | die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| 3127 | uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name); |
| 3128 | if (idx != UINT32_MAX) |
| 3129 | { |
| 3130 | DWARFFormValue form_value; |
| 3131 | if (attributes.ExtractFormValueAtIndex(this, idx, form_value)) |
| 3132 | { |
| 3133 | const char *name = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 037520e | 2012-07-18 23:18:10 +0000 | [diff] [blame] | 3134 | best_name.SetValue (ConstString(name), true); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3135 | } |
| 3136 | } |
| 3137 | if (best_name) |
| 3138 | { |
| 3139 | const char *demangled = best_name.GetDemangledName().GetCString(); |
| 3140 | if (demangled) |
| 3141 | { |
| 3142 | std::string name_no_parens(partial_name, base_name_end - partial_name); |
| Jim Ingham | 85c13d7 | 2012-03-02 02:24:42 +0000 | [diff] [blame] | 3143 | const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str()); |
| 3144 | if (partial_in_demangled == NULL) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3145 | return false; |
| Jim Ingham | 85c13d7 | 2012-03-02 02:24:42 +0000 | [diff] [blame] | 3146 | else |
| 3147 | { |
| 3148 | // Sort out the case where our name is something like "Process::Destroy" and the match is |
| 3149 | // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on |
| 3150 | // namespace boundaries... |
| 3151 | |
| 3152 | if (partial_name[0] == ':' && partial_name[1] == ':') |
| 3153 | { |
| 3154 | // The partial name was already on a namespace boundary so all matches are good. |
| 3155 | return true; |
| 3156 | } |
| 3157 | else if (partial_in_demangled == demangled) |
| 3158 | { |
| 3159 | // They both start the same, so this is an good match. |
| 3160 | return true; |
| 3161 | } |
| 3162 | else |
| 3163 | { |
| 3164 | if (partial_in_demangled - demangled == 1) |
| 3165 | { |
| 3166 | // Only one character difference, can't be a namespace boundary... |
| 3167 | return false; |
| 3168 | } |
| 3169 | else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':') |
| 3170 | { |
| 3171 | // We are on a namespace boundary, so this is also good. |
| 3172 | return true; |
| 3173 | } |
| 3174 | else |
| 3175 | return false; |
| 3176 | } |
| 3177 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3178 | } |
| 3179 | } |
| 3180 | } |
| 3181 | |
| 3182 | return true; |
| 3183 | } |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3184 | |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3185 | uint32_t |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3186 | SymbolFileDWARF::FindFunctions (const ConstString &name, |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3187 | const lldb_private::ClangNamespaceDecl *namespace_decl, |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3188 | uint32_t name_type_mask, |
| 3189 | bool include_inlines, |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3190 | bool append, |
| 3191 | SymbolContextList& sc_list) |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3192 | { |
| 3193 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 3194 | "SymbolFileDWARF::FindFunctions (name = '%s')", |
| 3195 | name.AsCString()); |
| 3196 | |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3197 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 3198 | |
| 3199 | if (log) |
| 3200 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3201 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3202 | "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)", |
| 3203 | name.GetCString(), |
| 3204 | name_type_mask, |
| 3205 | append); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3206 | } |
| 3207 | |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3208 | // If we aren't appending the results to this list, then clear the list |
| 3209 | if (!append) |
| 3210 | sc_list.Clear(); |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3211 | |
| 3212 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) |
| 3213 | return 0; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3214 | |
| 3215 | // If name is empty then we won't find anything. |
| 3216 | if (name.IsEmpty()) |
| 3217 | return 0; |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3218 | |
| 3219 | // Remember how many sc_list are in the list before we search in case |
| 3220 | // we are appending the results to a variable list. |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3221 | |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3222 | const uint32_t original_size = sc_list.GetSize(); |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3223 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3224 | const char *name_cstr = name.GetCString(); |
| 3225 | uint32_t effective_name_type_mask = eFunctionNameTypeNone; |
| 3226 | const char *base_name_start = name_cstr; |
| 3227 | const char *base_name_end = name_cstr + strlen(name_cstr); |
| 3228 | |
| 3229 | if (name_type_mask & eFunctionNameTypeAuto) |
| 3230 | { |
| 3231 | if (CPPLanguageRuntime::IsCPPMangledName (name_cstr)) |
| 3232 | effective_name_type_mask = eFunctionNameTypeFull; |
| 3233 | else if (ObjCLanguageRuntime::IsPossibleObjCMethodName (name_cstr)) |
| 3234 | effective_name_type_mask = eFunctionNameTypeFull; |
| 3235 | else |
| 3236 | { |
| 3237 | if (ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr)) |
| 3238 | effective_name_type_mask |= eFunctionNameTypeSelector; |
| 3239 | |
| 3240 | if (CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end)) |
| 3241 | effective_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase); |
| 3242 | } |
| 3243 | } |
| 3244 | else |
| 3245 | { |
| 3246 | effective_name_type_mask = name_type_mask; |
| 3247 | if (effective_name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase) |
| 3248 | { |
| 3249 | // If they've asked for a CPP method or function name and it can't be that, we don't |
| 3250 | // even need to search for CPP methods or names. |
| 3251 | if (!CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end)) |
| 3252 | { |
| 3253 | effective_name_type_mask &= ~(eFunctionNameTypeMethod | eFunctionNameTypeBase); |
| 3254 | if (effective_name_type_mask == eFunctionNameTypeNone) |
| 3255 | return 0; |
| 3256 | } |
| 3257 | } |
| 3258 | |
| 3259 | if (effective_name_type_mask & eFunctionNameTypeSelector) |
| 3260 | { |
| 3261 | if (!ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr)) |
| 3262 | { |
| 3263 | effective_name_type_mask &= ~(eFunctionNameTypeSelector); |
| 3264 | if (effective_name_type_mask == eFunctionNameTypeNone) |
| 3265 | return 0; |
| 3266 | } |
| 3267 | } |
| 3268 | } |
| 3269 | |
| 3270 | DWARFDebugInfo* info = DebugInfo(); |
| 3271 | if (info == NULL) |
| 3272 | return 0; |
| 3273 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3274 | DWARFCompileUnit *dwarf_cu = NULL; |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3275 | if (m_using_apple_tables) |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 3276 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3277 | if (m_apple_names_ap.get()) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3278 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3279 | |
| 3280 | DIEArray die_offsets; |
| 3281 | |
| 3282 | uint32_t num_matches = 0; |
| 3283 | |
| 3284 | if (effective_name_type_mask & eFunctionNameTypeFull) |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3285 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3286 | // If they asked for the full name, match what they typed. At some point we may |
| 3287 | // want to canonicalize this (strip double spaces, etc. For now, we just add all the |
| 3288 | // dies that we find by exact match. |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3289 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3290 | for (uint32_t i = 0; i < num_matches; i++) |
| 3291 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3292 | const dw_offset_t die_offset = die_offsets[i]; |
| 3293 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3294 | if (die) |
| 3295 | { |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3296 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3297 | continue; |
| 3298 | |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3299 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) |
| 3300 | continue; |
| 3301 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3302 | ResolveFunction (dwarf_cu, die, sc_list); |
| 3303 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3304 | else |
| 3305 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3306 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 3307 | die_offset, name_cstr); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3308 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3309 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3310 | } |
| 3311 | else |
| 3312 | { |
| 3313 | if (effective_name_type_mask & eFunctionNameTypeSelector) |
| 3314 | { |
| 3315 | if (namespace_decl && *namespace_decl) |
| 3316 | return 0; // no selectors in namespaces |
| 3317 | |
| 3318 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); |
| 3319 | // Now make sure these are actually ObjC methods. In this case we can simply look up the name, |
| 3320 | // and if it is an ObjC method name, we're good. |
| 3321 | |
| 3322 | for (uint32_t i = 0; i < num_matches; i++) |
| 3323 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3324 | const dw_offset_t die_offset = die_offsets[i]; |
| 3325 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3326 | if (die) |
| 3327 | { |
| 3328 | const char *die_name = die->GetName(this, dwarf_cu); |
| 3329 | if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name)) |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3330 | { |
| 3331 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) |
| 3332 | continue; |
| 3333 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3334 | ResolveFunction (dwarf_cu, die, sc_list); |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3335 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3336 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3337 | else |
| 3338 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3339 | GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 3340 | die_offset, name_cstr); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3341 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3342 | } |
| 3343 | die_offsets.clear(); |
| 3344 | } |
| 3345 | |
| 3346 | if (effective_name_type_mask & eFunctionNameTypeMethod |
| 3347 | || effective_name_type_mask & eFunctionNameTypeBase) |
| 3348 | { |
| 3349 | if ((effective_name_type_mask & eFunctionNameTypeMethod) && |
| 3350 | (namespace_decl && *namespace_decl)) |
| 3351 | return 0; // no methods in namespaces |
| 3352 | |
| 3353 | // The apple_names table stores just the "base name" of C++ methods in the table. So we have to |
| 3354 | // extract the base name, look that up, and if there is any other information in the name we were |
| 3355 | // passed in we have to post-filter based on that. |
| 3356 | |
| 3357 | // FIXME: Arrange the logic above so that we don't calculate the base name twice: |
| 3358 | std::string base_name(base_name_start, base_name_end - base_name_start); |
| 3359 | num_matches = m_apple_names_ap->FindByName (base_name.c_str(), die_offsets); |
| 3360 | |
| 3361 | for (uint32_t i = 0; i < num_matches; i++) |
| 3362 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3363 | const dw_offset_t die_offset = die_offsets[i]; |
| 3364 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3365 | if (die) |
| 3366 | { |
| 3367 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3368 | continue; |
| 3369 | |
| 3370 | if (!FunctionDieMatchesPartialName(die, |
| 3371 | dwarf_cu, |
| 3372 | effective_name_type_mask, |
| 3373 | name_cstr, |
| 3374 | base_name_start, |
| 3375 | base_name_end)) |
| 3376 | continue; |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3377 | |
| 3378 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) |
| 3379 | continue; |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3380 | |
| 3381 | // If we get to here, the die is good, and we should add it: |
| 3382 | ResolveFunction (dwarf_cu, die, sc_list); |
| 3383 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3384 | else |
| 3385 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3386 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 3387 | die_offset, name_cstr); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3388 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3389 | } |
| 3390 | die_offsets.clear(); |
| 3391 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3392 | } |
| 3393 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3394 | } |
| 3395 | else |
| 3396 | { |
| 3397 | |
| 3398 | // Index the DWARF if we haven't already |
| 3399 | if (!m_indexed) |
| 3400 | Index (); |
| 3401 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3402 | if (name_type_mask & eFunctionNameTypeFull) |
| 3403 | FindFunctions (name, m_function_fullname_index, sc_list); |
| 3404 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3405 | std::string base_name(base_name_start, base_name_end - base_name_start); |
| 3406 | ConstString base_name_const(base_name.c_str()); |
| 3407 | DIEArray die_offsets; |
| 3408 | DWARFCompileUnit *dwarf_cu = NULL; |
| 3409 | |
| 3410 | if (effective_name_type_mask & eFunctionNameTypeBase) |
| 3411 | { |
| 3412 | uint32_t num_base = m_function_basename_index.Find(base_name_const, die_offsets); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3413 | for (uint32_t i = 0; i < num_base; i++) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3414 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3415 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); |
| 3416 | if (die) |
| 3417 | { |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3418 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3419 | continue; |
| 3420 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3421 | if (!FunctionDieMatchesPartialName(die, |
| 3422 | dwarf_cu, |
| 3423 | effective_name_type_mask, |
| 3424 | name_cstr, |
| 3425 | base_name_start, |
| 3426 | base_name_end)) |
| 3427 | continue; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3428 | |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3429 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) |
| 3430 | continue; |
| 3431 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3432 | // If we get to here, the die is good, and we should add it: |
| 3433 | ResolveFunction (dwarf_cu, die, sc_list); |
| 3434 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3435 | } |
| 3436 | die_offsets.clear(); |
| 3437 | } |
| 3438 | |
| Jim Ingham | ea8005a | 2011-10-11 01:18:11 +0000 | [diff] [blame] | 3439 | if (effective_name_type_mask & eFunctionNameTypeMethod) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3440 | { |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3441 | if (namespace_decl && *namespace_decl) |
| 3442 | return 0; // no methods in namespaces |
| 3443 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3444 | uint32_t num_base = m_function_method_index.Find(base_name_const, die_offsets); |
| 3445 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3446 | for (uint32_t i = 0; i < num_base; i++) |
| 3447 | { |
| 3448 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); |
| 3449 | if (die) |
| 3450 | { |
| 3451 | if (!FunctionDieMatchesPartialName(die, |
| 3452 | dwarf_cu, |
| 3453 | effective_name_type_mask, |
| 3454 | name_cstr, |
| 3455 | base_name_start, |
| 3456 | base_name_end)) |
| 3457 | continue; |
| 3458 | |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3459 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) |
| 3460 | continue; |
| 3461 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3462 | // If we get to here, the die is good, and we should add it: |
| 3463 | ResolveFunction (dwarf_cu, die, sc_list); |
| 3464 | } |
| 3465 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3466 | } |
| 3467 | die_offsets.clear(); |
| 3468 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3469 | |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3470 | if ((effective_name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl)) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3471 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3472 | FindFunctions (name, m_function_selector_index, sc_list); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3473 | } |
| 3474 | |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 3475 | } |
| 3476 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3477 | // Return the number of variable that were appended to the list |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3478 | const uint32_t num_matches = sc_list.GetSize() - original_size; |
| 3479 | |
| 3480 | if (log && num_matches > 0) |
| 3481 | { |
| 3482 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3483 | "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list) => %u", |
| 3484 | name.GetCString(), |
| 3485 | name_type_mask, |
| 3486 | append, |
| 3487 | num_matches); |
| 3488 | } |
| 3489 | return num_matches; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3490 | } |
| 3491 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3492 | uint32_t |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3493 | 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] | 3494 | { |
| 3495 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 3496 | "SymbolFileDWARF::FindFunctions (regex = '%s')", |
| 3497 | regex.GetText()); |
| 3498 | |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3499 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 3500 | |
| 3501 | if (log) |
| 3502 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3503 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3504 | "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)", |
| 3505 | regex.GetText(), |
| 3506 | append); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3507 | } |
| 3508 | |
| 3509 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3510 | // If we aren't appending the results to this list, then clear the list |
| 3511 | if (!append) |
| 3512 | sc_list.Clear(); |
| 3513 | |
| 3514 | // Remember how many sc_list are in the list before we search in case |
| 3515 | // we are appending the results to a variable list. |
| 3516 | uint32_t original_size = sc_list.GetSize(); |
| 3517 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3518 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3519 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3520 | if (m_apple_names_ap.get()) |
| 3521 | FindFunctions (regex, *m_apple_names_ap, sc_list); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3522 | } |
| 3523 | else |
| 3524 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3525 | // Index the DWARF if we haven't already |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3526 | if (!m_indexed) |
| 3527 | Index (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3528 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3529 | FindFunctions (regex, m_function_basename_index, sc_list); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3530 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3531 | FindFunctions (regex, m_function_fullname_index, sc_list); |
| 3532 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3533 | |
| 3534 | // Return the number of variable that were appended to the list |
| 3535 | return sc_list.GetSize() - original_size; |
| 3536 | } |
| Jim Ingham | 318c9f2 | 2011-08-26 19:44:13 +0000 | [diff] [blame] | 3537 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3538 | uint32_t |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3539 | SymbolFileDWARF::FindTypes (const SymbolContext& sc, |
| 3540 | const ConstString &name, |
| 3541 | const lldb_private::ClangNamespaceDecl *namespace_decl, |
| 3542 | bool append, |
| 3543 | uint32_t max_matches, |
| 3544 | TypeList& types) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3545 | { |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3546 | DWARFDebugInfo* info = DebugInfo(); |
| 3547 | if (info == NULL) |
| 3548 | return 0; |
| 3549 | |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3550 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 3551 | |
| 3552 | if (log) |
| 3553 | { |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3554 | if (namespace_decl) |
| 3555 | { |
| 3556 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3557 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)", |
| 3558 | name.GetCString(), |
| 3559 | namespace_decl->GetNamespaceDecl(), |
| 3560 | namespace_decl->GetQualifiedName().c_str(), |
| 3561 | append, |
| 3562 | max_matches); |
| 3563 | } |
| 3564 | else |
| 3565 | { |
| 3566 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3567 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)", |
| 3568 | name.GetCString(), |
| 3569 | append, |
| 3570 | max_matches); |
| 3571 | } |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3572 | } |
| 3573 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3574 | // If we aren't appending the results to this list, then clear the list |
| 3575 | if (!append) |
| 3576 | types.Clear(); |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3577 | |
| 3578 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) |
| 3579 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3580 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3581 | DIEArray die_offsets; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3582 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3583 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3584 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3585 | if (m_apple_types_ap.get()) |
| 3586 | { |
| 3587 | const char *name_cstr = name.GetCString(); |
| 3588 | m_apple_types_ap->FindByName (name_cstr, die_offsets); |
| 3589 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3590 | } |
| 3591 | else |
| 3592 | { |
| 3593 | if (!m_indexed) |
| 3594 | Index (); |
| 3595 | |
| 3596 | m_type_index.Find (name, die_offsets); |
| 3597 | } |
| 3598 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3599 | const size_t num_die_matches = die_offsets.size(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3600 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3601 | if (num_die_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3602 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3603 | const uint32_t initial_types_size = types.GetSize(); |
| 3604 | DWARFCompileUnit* dwarf_cu = NULL; |
| 3605 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3606 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3607 | for (size_t i=0; i<num_die_matches; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3608 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3609 | const dw_offset_t die_offset = die_offsets[i]; |
| 3610 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| 3611 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3612 | if (die) |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 3613 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3614 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3615 | continue; |
| 3616 | |
| 3617 | Type *matching_type = ResolveType (dwarf_cu, die); |
| 3618 | if (matching_type) |
| 3619 | { |
| 3620 | // 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] | 3621 | types.InsertUnique (matching_type->shared_from_this()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3622 | if (types.GetSize() >= max_matches) |
| 3623 | break; |
| 3624 | } |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 3625 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3626 | else |
| 3627 | { |
| 3628 | if (m_using_apple_tables) |
| 3629 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3630 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 3631 | die_offset, name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3632 | } |
| 3633 | } |
| 3634 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3635 | } |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3636 | const uint32_t num_matches = types.GetSize() - initial_types_size; |
| 3637 | if (log && num_matches) |
| 3638 | { |
| 3639 | if (namespace_decl) |
| 3640 | { |
| 3641 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3642 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u", |
| 3643 | name.GetCString(), |
| 3644 | namespace_decl->GetNamespaceDecl(), |
| 3645 | namespace_decl->GetQualifiedName().c_str(), |
| 3646 | append, |
| 3647 | max_matches, |
| 3648 | num_matches); |
| 3649 | } |
| 3650 | else |
| 3651 | { |
| 3652 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3653 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u", |
| 3654 | name.GetCString(), |
| 3655 | append, |
| 3656 | max_matches, |
| 3657 | num_matches); |
| 3658 | } |
| 3659 | } |
| 3660 | return num_matches; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3661 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3662 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3663 | } |
| 3664 | |
| 3665 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3666 | ClangNamespaceDecl |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3667 | SymbolFileDWARF::FindNamespace (const SymbolContext& sc, |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3668 | const ConstString &name, |
| 3669 | const lldb_private::ClangNamespaceDecl *parent_namespace_decl) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3670 | { |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3671 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 3672 | |
| 3673 | if (log) |
| 3674 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3675 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3676 | "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")", |
| 3677 | name.GetCString()); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3678 | } |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3679 | |
| 3680 | if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl)) |
| 3681 | return ClangNamespaceDecl(); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3682 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3683 | ClangNamespaceDecl namespace_decl; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3684 | DWARFDebugInfo* info = DebugInfo(); |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3685 | if (info) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3686 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3687 | DIEArray die_offsets; |
| 3688 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3689 | // Index if we already haven't to make sure the compile units |
| 3690 | // get indexed and make their global DIE index list |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3691 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3692 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3693 | if (m_apple_namespaces_ap.get()) |
| 3694 | { |
| 3695 | const char *name_cstr = name.GetCString(); |
| 3696 | m_apple_namespaces_ap->FindByName (name_cstr, die_offsets); |
| 3697 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3698 | } |
| 3699 | else |
| 3700 | { |
| 3701 | if (!m_indexed) |
| 3702 | Index (); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3703 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3704 | m_namespace_index.Find (name, die_offsets); |
| 3705 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3706 | |
| 3707 | DWARFCompileUnit* dwarf_cu = NULL; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3708 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3709 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3710 | if (num_matches) |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3711 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3712 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3713 | for (size_t i=0; i<num_matches; ++i) |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3714 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3715 | const dw_offset_t die_offset = die_offsets[i]; |
| 3716 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3717 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3718 | if (die) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3719 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3720 | if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die)) |
| 3721 | continue; |
| 3722 | |
| 3723 | clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die); |
| 3724 | if (clang_namespace_decl) |
| 3725 | { |
| 3726 | namespace_decl.SetASTContext (GetClangASTContext().getASTContext()); |
| 3727 | namespace_decl.SetNamespaceDecl (clang_namespace_decl); |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3728 | break; |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3729 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3730 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3731 | else |
| 3732 | { |
| 3733 | if (m_using_apple_tables) |
| 3734 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3735 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n", |
| 3736 | die_offset, name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3737 | } |
| 3738 | } |
| 3739 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3740 | } |
| 3741 | } |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3742 | } |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3743 | if (log && namespace_decl.GetNamespaceDecl()) |
| 3744 | { |
| 3745 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3746 | "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"", |
| 3747 | name.GetCString(), |
| 3748 | namespace_decl.GetNamespaceDecl(), |
| 3749 | namespace_decl.GetQualifiedName().c_str()); |
| 3750 | } |
| 3751 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3752 | return namespace_decl; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3753 | } |
| 3754 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3755 | uint32_t |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3756 | 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] | 3757 | { |
| 3758 | // Remember how many sc_list are in the list before we search in case |
| 3759 | // we are appending the results to a variable list. |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3760 | uint32_t original_size = types.GetSize(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3761 | |
| 3762 | const uint32_t num_die_offsets = die_offsets.size(); |
| 3763 | // Parse all of the types we found from the pubtypes matches |
| 3764 | uint32_t i; |
| 3765 | uint32_t num_matches = 0; |
| 3766 | for (i = 0; i < num_die_offsets; ++i) |
| 3767 | { |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3768 | Type *matching_type = ResolveTypeUID (die_offsets[i]); |
| 3769 | if (matching_type) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3770 | { |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3771 | // 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] | 3772 | types.InsertUnique (matching_type->shared_from_this()); |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3773 | ++num_matches; |
| 3774 | if (num_matches >= max_matches) |
| 3775 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3776 | } |
| 3777 | } |
| 3778 | |
| 3779 | // Return the number of variable that were appended to the list |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3780 | return types.GetSize() - original_size; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3781 | } |
| 3782 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3783 | |
| 3784 | size_t |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3785 | SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc, |
| 3786 | clang::DeclContext *containing_decl_ctx, |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3787 | DWARFCompileUnit* dwarf_cu, |
| 3788 | const DWARFDebugInfoEntry *parent_die, |
| 3789 | bool skip_artificial, |
| 3790 | bool &is_static, |
| 3791 | TypeList* type_list, |
| 3792 | std::vector<clang_type_t>& function_param_types, |
| 3793 | std::vector<clang::ParmVarDecl*>& function_param_decls, |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 3794 | unsigned &type_quals, |
| 3795 | ClangASTContext::TemplateParameterInfos &template_param_infos) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3796 | { |
| 3797 | if (parent_die == NULL) |
| 3798 | return 0; |
| 3799 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3800 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| 3801 | |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3802 | size_t arg_idx = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3803 | const DWARFDebugInfoEntry *die; |
| 3804 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 3805 | { |
| 3806 | dw_tag_t tag = die->Tag(); |
| 3807 | switch (tag) |
| 3808 | { |
| 3809 | case DW_TAG_formal_parameter: |
| 3810 | { |
| 3811 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3812 | 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] | 3813 | if (num_attributes > 0) |
| 3814 | { |
| 3815 | const char *name = NULL; |
| 3816 | Declaration decl; |
| 3817 | dw_offset_t param_type_die_offset = DW_INVALID_OFFSET; |
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 3818 | bool is_artificial = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3819 | // one of None, Auto, Register, Extern, Static, PrivateExtern |
| 3820 | |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 3821 | clang::StorageClass storage = clang::SC_None; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3822 | uint32_t i; |
| 3823 | for (i=0; i<num_attributes; ++i) |
| 3824 | { |
| 3825 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 3826 | DWARFFormValue form_value; |
| 3827 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 3828 | { |
| 3829 | switch (attr) |
| 3830 | { |
| 3831 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 3832 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 3833 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 3834 | case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; |
| 3835 | case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break; |
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 3836 | case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3837 | case DW_AT_location: |
| 3838 | // if (form_value.BlockData()) |
| 3839 | // { |
| 3840 | // const DataExtractor& debug_info_data = debug_info(); |
| 3841 | // uint32_t block_length = form_value.Unsigned(); |
| 3842 | // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length); |
| 3843 | // } |
| 3844 | // else |
| 3845 | // { |
| 3846 | // } |
| 3847 | // break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3848 | case DW_AT_const_value: |
| 3849 | case DW_AT_default_value: |
| 3850 | case DW_AT_description: |
| 3851 | case DW_AT_endianity: |
| 3852 | case DW_AT_is_optional: |
| 3853 | case DW_AT_segment: |
| 3854 | case DW_AT_variable_parameter: |
| 3855 | default: |
| 3856 | case DW_AT_abstract_origin: |
| 3857 | case DW_AT_sibling: |
| 3858 | break; |
| 3859 | } |
| 3860 | } |
| 3861 | } |
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 3862 | |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3863 | bool skip = false; |
| 3864 | if (skip_artificial) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3865 | { |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3866 | if (is_artificial) |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3867 | { |
| 3868 | // In order to determine if a C++ member function is |
| 3869 | // "const" we have to look at the const-ness of "this"... |
| 3870 | // Ugly, but that |
| 3871 | if (arg_idx == 0) |
| 3872 | { |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 3873 | if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind())) |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 3874 | { |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3875 | // Often times compilers omit the "this" name for the |
| 3876 | // specification DIEs, so we can't rely upon the name |
| 3877 | // being in the formal parameter DIE... |
| 3878 | if (name == NULL || ::strcmp(name, "this")==0) |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3879 | { |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3880 | Type *this_type = ResolveTypeUID (param_type_die_offset); |
| 3881 | if (this_type) |
| 3882 | { |
| 3883 | uint32_t encoding_mask = this_type->GetEncodingMask(); |
| 3884 | if (encoding_mask & Type::eEncodingIsPointerUID) |
| 3885 | { |
| 3886 | is_static = false; |
| 3887 | |
| 3888 | if (encoding_mask & (1u << Type::eEncodingIsConstUID)) |
| 3889 | type_quals |= clang::Qualifiers::Const; |
| 3890 | if (encoding_mask & (1u << Type::eEncodingIsVolatileUID)) |
| 3891 | type_quals |= clang::Qualifiers::Volatile; |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3892 | } |
| 3893 | } |
| 3894 | } |
| 3895 | } |
| 3896 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3897 | skip = true; |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3898 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3899 | else |
| 3900 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3901 | |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3902 | // HACK: Objective C formal parameters "self" and "_cmd" |
| 3903 | // are not marked as artificial in the DWARF... |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3904 | CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| 3905 | if (comp_unit) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3906 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3907 | switch (comp_unit->GetLanguage()) |
| 3908 | { |
| 3909 | case eLanguageTypeObjC: |
| 3910 | case eLanguageTypeObjC_plus_plus: |
| 3911 | if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0)) |
| 3912 | skip = true; |
| 3913 | break; |
| 3914 | default: |
| 3915 | break; |
| 3916 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3917 | } |
| 3918 | } |
| 3919 | } |
| 3920 | |
| 3921 | if (!skip) |
| 3922 | { |
| 3923 | Type *type = ResolveTypeUID(param_type_die_offset); |
| 3924 | if (type) |
| 3925 | { |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 3926 | function_param_types.push_back (type->GetClangForwardType()); |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3927 | |
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 3928 | clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name, |
| 3929 | type->GetClangForwardType(), |
| 3930 | storage); |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3931 | assert(param_var_decl); |
| 3932 | function_param_decls.push_back(param_var_decl); |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 3933 | |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 3934 | GetClangASTContext().SetMetadataAsUserID ((uintptr_t)param_var_decl, MakeUserID(die->GetOffset())); |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3935 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3936 | } |
| 3937 | } |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3938 | arg_idx++; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3939 | } |
| 3940 | break; |
| 3941 | |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 3942 | case DW_TAG_template_type_parameter: |
| 3943 | case DW_TAG_template_value_parameter: |
| 3944 | ParseTemplateDIE (dwarf_cu, die,template_param_infos); |
| 3945 | break; |
| 3946 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3947 | default: |
| 3948 | break; |
| 3949 | } |
| 3950 | } |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3951 | return arg_idx; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3952 | } |
| 3953 | |
| 3954 | size_t |
| 3955 | SymbolFileDWARF::ParseChildEnumerators |
| 3956 | ( |
| 3957 | const SymbolContext& sc, |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 3958 | clang_type_t enumerator_clang_type, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3959 | uint32_t enumerator_byte_size, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3960 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3961 | const DWARFDebugInfoEntry *parent_die |
| 3962 | ) |
| 3963 | { |
| 3964 | if (parent_die == NULL) |
| 3965 | return 0; |
| 3966 | |
| 3967 | size_t enumerators_added = 0; |
| 3968 | const DWARFDebugInfoEntry *die; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3969 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| 3970 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3971 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 3972 | { |
| 3973 | const dw_tag_t tag = die->Tag(); |
| 3974 | if (tag == DW_TAG_enumerator) |
| 3975 | { |
| 3976 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3977 | 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] | 3978 | if (num_child_attributes > 0) |
| 3979 | { |
| 3980 | const char *name = NULL; |
| 3981 | bool got_value = false; |
| 3982 | int64_t enum_value = 0; |
| 3983 | Declaration decl; |
| 3984 | |
| 3985 | uint32_t i; |
| 3986 | for (i=0; i<num_child_attributes; ++i) |
| 3987 | { |
| 3988 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 3989 | DWARFFormValue form_value; |
| 3990 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 3991 | { |
| 3992 | switch (attr) |
| 3993 | { |
| 3994 | case DW_AT_const_value: |
| 3995 | got_value = true; |
| 3996 | enum_value = form_value.Unsigned(); |
| 3997 | break; |
| 3998 | |
| 3999 | case DW_AT_name: |
| 4000 | name = form_value.AsCString(&get_debug_str_data()); |
| 4001 | break; |
| 4002 | |
| 4003 | case DW_AT_description: |
| 4004 | default: |
| 4005 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 4006 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 4007 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 4008 | case DW_AT_sibling: |
| 4009 | break; |
| 4010 | } |
| 4011 | } |
| 4012 | } |
| 4013 | |
| 4014 | if (name && name[0] && got_value) |
| 4015 | { |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 4016 | GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type, |
| 4017 | enumerator_clang_type, |
| 4018 | decl, |
| 4019 | name, |
| 4020 | enum_value, |
| 4021 | enumerator_byte_size * 8); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4022 | ++enumerators_added; |
| 4023 | } |
| 4024 | } |
| 4025 | } |
| 4026 | } |
| 4027 | return enumerators_added; |
| 4028 | } |
| 4029 | |
| 4030 | void |
| 4031 | SymbolFileDWARF::ParseChildArrayInfo |
| 4032 | ( |
| 4033 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4034 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4035 | const DWARFDebugInfoEntry *parent_die, |
| 4036 | int64_t& first_index, |
| 4037 | std::vector<uint64_t>& element_orders, |
| 4038 | uint32_t& byte_stride, |
| 4039 | uint32_t& bit_stride |
| 4040 | ) |
| 4041 | { |
| 4042 | if (parent_die == NULL) |
| 4043 | return; |
| 4044 | |
| 4045 | const DWARFDebugInfoEntry *die; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4046 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4047 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 4048 | { |
| 4049 | const dw_tag_t tag = die->Tag(); |
| 4050 | switch (tag) |
| 4051 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4052 | case DW_TAG_subrange_type: |
| 4053 | { |
| 4054 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4055 | 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] | 4056 | if (num_child_attributes > 0) |
| 4057 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4058 | uint64_t num_elements = 0; |
| 4059 | uint64_t lower_bound = 0; |
| 4060 | uint64_t upper_bound = 0; |
| 4061 | uint32_t i; |
| 4062 | for (i=0; i<num_child_attributes; ++i) |
| 4063 | { |
| 4064 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 4065 | DWARFFormValue form_value; |
| 4066 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 4067 | { |
| 4068 | switch (attr) |
| 4069 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4070 | case DW_AT_name: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4071 | break; |
| 4072 | |
| 4073 | case DW_AT_count: |
| 4074 | num_elements = form_value.Unsigned(); |
| 4075 | break; |
| 4076 | |
| 4077 | case DW_AT_bit_stride: |
| 4078 | bit_stride = form_value.Unsigned(); |
| 4079 | break; |
| 4080 | |
| 4081 | case DW_AT_byte_stride: |
| 4082 | byte_stride = form_value.Unsigned(); |
| 4083 | break; |
| 4084 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4085 | case DW_AT_lower_bound: |
| 4086 | lower_bound = form_value.Unsigned(); |
| 4087 | break; |
| 4088 | |
| 4089 | case DW_AT_upper_bound: |
| 4090 | upper_bound = form_value.Unsigned(); |
| 4091 | break; |
| 4092 | |
| 4093 | default: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4094 | case DW_AT_abstract_origin: |
| 4095 | case DW_AT_accessibility: |
| 4096 | case DW_AT_allocated: |
| 4097 | case DW_AT_associated: |
| 4098 | case DW_AT_data_location: |
| 4099 | case DW_AT_declaration: |
| 4100 | case DW_AT_description: |
| 4101 | case DW_AT_sibling: |
| 4102 | case DW_AT_threads_scaled: |
| 4103 | case DW_AT_type: |
| 4104 | case DW_AT_visibility: |
| 4105 | break; |
| 4106 | } |
| 4107 | } |
| 4108 | } |
| 4109 | |
| 4110 | if (upper_bound > lower_bound) |
| 4111 | num_elements = upper_bound - lower_bound + 1; |
| 4112 | |
| Sean Callanan | ec979ba | 2012-10-22 23:56:48 +0000 | [diff] [blame] | 4113 | element_orders.push_back (num_elements); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4114 | } |
| 4115 | } |
| 4116 | break; |
| 4117 | } |
| 4118 | } |
| 4119 | } |
| 4120 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4121 | TypeSP |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4122 | SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4123 | { |
| 4124 | TypeSP type_sp; |
| 4125 | if (die != NULL) |
| 4126 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4127 | assert(dwarf_cu != NULL); |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4128 | Type *type_ptr = m_die_to_type.lookup (die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4129 | if (type_ptr == NULL) |
| 4130 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4131 | CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4132 | assert (lldb_cu); |
| 4133 | SymbolContext sc(lldb_cu); |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4134 | type_sp = ParseType(sc, dwarf_cu, die, NULL); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4135 | } |
| 4136 | else if (type_ptr != DIE_IS_BEING_PARSED) |
| 4137 | { |
| 4138 | // Grab the existing type from the master types lists |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 4139 | type_sp = type_ptr->shared_from_this(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4140 | } |
| 4141 | |
| 4142 | } |
| 4143 | return type_sp; |
| 4144 | } |
| 4145 | |
| 4146 | clang::DeclContext * |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4147 | SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4148 | { |
| 4149 | if (die_offset != DW_INVALID_OFFSET) |
| 4150 | { |
| 4151 | DWARFCompileUnitSP cu_sp; |
| 4152 | const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4153 | return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4154 | } |
| 4155 | return NULL; |
| 4156 | } |
| 4157 | |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4158 | clang::DeclContext * |
| 4159 | SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset) |
| 4160 | { |
| 4161 | if (die_offset != DW_INVALID_OFFSET) |
| 4162 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4163 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 4164 | if (debug_info) |
| 4165 | { |
| 4166 | DWARFCompileUnitSP cu_sp; |
| 4167 | const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp); |
| 4168 | if (die) |
| 4169 | return GetClangDeclContextForDIE (sc, cu_sp.get(), die); |
| 4170 | } |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4171 | } |
| 4172 | return NULL; |
| 4173 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4174 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4175 | clang::NamespaceDecl * |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4176 | SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4177 | { |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4178 | if (die && die->Tag() == DW_TAG_namespace) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4179 | { |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4180 | // See if we already parsed this namespace DIE and associated it with a |
| 4181 | // uniqued namespace declaration |
| 4182 | clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]); |
| 4183 | if (namespace_decl) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4184 | return namespace_decl; |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4185 | else |
| 4186 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4187 | const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL); |
| 4188 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL); |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4189 | namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx); |
| 4190 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| 4191 | if (log) |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4192 | { |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4193 | if (namespace_name) |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4194 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4195 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 4196 | "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)", |
| 4197 | GetClangASTContext().getASTContext(), |
| 4198 | MakeUserID(die->GetOffset()), |
| 4199 | namespace_name, |
| 4200 | namespace_decl, |
| 4201 | namespace_decl->getOriginalNamespace()); |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4202 | } |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4203 | else |
| 4204 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4205 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 4206 | "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)", |
| 4207 | GetClangASTContext().getASTContext(), |
| 4208 | MakeUserID(die->GetOffset()), |
| 4209 | namespace_decl, |
| 4210 | namespace_decl->getOriginalNamespace()); |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4211 | } |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4212 | } |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4213 | |
| 4214 | if (namespace_decl) |
| 4215 | LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die); |
| 4216 | return namespace_decl; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4217 | } |
| 4218 | } |
| 4219 | return NULL; |
| 4220 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4221 | |
| 4222 | clang::DeclContext * |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4223 | SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4224 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4225 | clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die); |
| 4226 | if (clang_decl_ctx) |
| 4227 | return clang_decl_ctx; |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4228 | // If this DIE has a specification, or an abstract origin, then trace to those. |
| 4229 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4230 | 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] | 4231 | if (die_offset != DW_INVALID_OFFSET) |
| 4232 | return GetClangDeclContextForDIEOffset (sc, die_offset); |
| 4233 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4234 | 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] | 4235 | if (die_offset != DW_INVALID_OFFSET) |
| 4236 | return GetClangDeclContextForDIEOffset (sc, die_offset); |
| 4237 | |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 4238 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| 4239 | if (log) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4240 | GetObjectFile()->GetModule()->LogMessage(log.get(), "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] | 4241 | // This is the DIE we want. Parse it, then query our map. |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4242 | bool assert_not_being_parsed = true; |
| 4243 | ResolveTypeUID (cu, die, assert_not_being_parsed); |
| 4244 | |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4245 | clang_decl_ctx = GetCachedClangDeclContextForDIE (die); |
| 4246 | |
| 4247 | return clang_decl_ctx; |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4248 | } |
| 4249 | |
| 4250 | clang::DeclContext * |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4251 | 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] | 4252 | { |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4253 | if (m_clang_tu_decl == NULL) |
| 4254 | m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4255 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4256 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4257 | |
| 4258 | if (decl_ctx_die_copy) |
| 4259 | *decl_ctx_die_copy = decl_ctx_die; |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4260 | |
| 4261 | if (decl_ctx_die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4262 | { |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4263 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4264 | DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die); |
| 4265 | if (pos != m_die_to_decl_ctx.end()) |
| 4266 | return pos->second; |
| 4267 | |
| 4268 | switch (decl_ctx_die->Tag()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4269 | { |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4270 | case DW_TAG_compile_unit: |
| 4271 | return m_clang_tu_decl; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4272 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4273 | case DW_TAG_namespace: |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4274 | return ResolveNamespaceDIE (cu, decl_ctx_die); |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4275 | break; |
| 4276 | |
| 4277 | case DW_TAG_structure_type: |
| 4278 | case DW_TAG_union_type: |
| 4279 | case DW_TAG_class_type: |
| 4280 | { |
| 4281 | Type* type = ResolveType (cu, decl_ctx_die); |
| 4282 | if (type) |
| 4283 | { |
| 4284 | clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ()); |
| 4285 | if (decl_ctx) |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4286 | { |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4287 | LinkDeclContextToDIE (decl_ctx, decl_ctx_die); |
| 4288 | if (decl_ctx) |
| 4289 | return decl_ctx; |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4290 | } |
| 4291 | } |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4292 | } |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4293 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4294 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4295 | default: |
| 4296 | break; |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4297 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4298 | } |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 4299 | return m_clang_tu_decl; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4300 | } |
| 4301 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4302 | |
| 4303 | const DWARFDebugInfoEntry * |
| 4304 | SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) |
| 4305 | { |
| 4306 | if (cu && die) |
| 4307 | { |
| 4308 | const DWARFDebugInfoEntry * const decl_die = die; |
| 4309 | |
| 4310 | while (die != NULL) |
| 4311 | { |
| 4312 | // If this is the original DIE that we are searching for a declaration |
| 4313 | // for, then don't look in the cache as we don't want our own decl |
| 4314 | // context to be our decl context... |
| 4315 | if (decl_die != die) |
| 4316 | { |
| 4317 | switch (die->Tag()) |
| 4318 | { |
| 4319 | case DW_TAG_compile_unit: |
| 4320 | case DW_TAG_namespace: |
| 4321 | case DW_TAG_structure_type: |
| 4322 | case DW_TAG_union_type: |
| 4323 | case DW_TAG_class_type: |
| 4324 | return die; |
| 4325 | |
| 4326 | default: |
| 4327 | break; |
| 4328 | } |
| 4329 | } |
| 4330 | |
| 4331 | dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET); |
| 4332 | if (die_offset != DW_INVALID_OFFSET) |
| 4333 | { |
| 4334 | DWARFCompileUnit *spec_cu = cu; |
| 4335 | const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu); |
| 4336 | const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die); |
| 4337 | if (spec_die_decl_ctx_die) |
| 4338 | return spec_die_decl_ctx_die; |
| 4339 | } |
| 4340 | |
| 4341 | die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET); |
| 4342 | if (die_offset != DW_INVALID_OFFSET) |
| 4343 | { |
| 4344 | DWARFCompileUnit *abs_cu = cu; |
| 4345 | const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu); |
| 4346 | const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die); |
| 4347 | if (abs_die_decl_ctx_die) |
| 4348 | return abs_die_decl_ctx_die; |
| 4349 | } |
| 4350 | |
| 4351 | die = die->GetParent(); |
| 4352 | } |
| 4353 | } |
| 4354 | return NULL; |
| 4355 | } |
| 4356 | |
| 4357 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4358 | Symbol * |
| 4359 | SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name) |
| 4360 | { |
| 4361 | Symbol *objc_class_symbol = NULL; |
| 4362 | if (m_obj_file) |
| 4363 | { |
| 4364 | Symtab *symtab = m_obj_file->GetSymtab(); |
| 4365 | if (symtab) |
| 4366 | { |
| 4367 | objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name, |
| 4368 | eSymbolTypeObjCClass, |
| 4369 | Symtab::eDebugNo, |
| 4370 | Symtab::eVisibilityAny); |
| 4371 | } |
| 4372 | } |
| 4373 | return objc_class_symbol; |
| 4374 | } |
| 4375 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4376 | // Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't |
| 4377 | // then we can end up looking through all class types for a complete type and never find |
| 4378 | // the full definition. We need to know if this attribute is supported, so we determine |
| 4379 | // this here and cache th result. We also need to worry about the debug map DWARF file |
| 4380 | // if we are doing darwin DWARF in .o file debugging. |
| 4381 | bool |
| 4382 | SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu) |
| 4383 | { |
| 4384 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate) |
| 4385 | { |
| 4386 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo; |
| 4387 | if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type()) |
| 4388 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; |
| 4389 | else |
| 4390 | { |
| 4391 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 4392 | const uint32_t num_compile_units = GetNumCompileUnits(); |
| 4393 | for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) |
| 4394 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4395 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); |
| 4396 | 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] | 4397 | { |
| 4398 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; |
| 4399 | break; |
| 4400 | } |
| 4401 | } |
| 4402 | } |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 4403 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ()) |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4404 | return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this); |
| 4405 | } |
| 4406 | return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes; |
| 4407 | } |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4408 | |
| 4409 | // This function can be used when a DIE is found that is a forward declaration |
| 4410 | // DIE and we want to try and find a type that has the complete definition. |
| 4411 | TypeSP |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4412 | SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die, |
| 4413 | const ConstString &type_name, |
| 4414 | bool must_be_implementation) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4415 | { |
| 4416 | |
| 4417 | TypeSP type_sp; |
| 4418 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4419 | if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name))) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4420 | return type_sp; |
| 4421 | |
| 4422 | DIEArray die_offsets; |
| 4423 | |
| 4424 | if (m_using_apple_tables) |
| 4425 | { |
| 4426 | if (m_apple_types_ap.get()) |
| 4427 | { |
| 4428 | const char *name_cstr = type_name.GetCString(); |
| Greg Clayton | 68221ec | 2012-01-18 20:58:12 +0000 | [diff] [blame] | 4429 | m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4430 | } |
| 4431 | } |
| 4432 | else |
| 4433 | { |
| 4434 | if (!m_indexed) |
| 4435 | Index (); |
| 4436 | |
| 4437 | m_type_index.Find (type_name, die_offsets); |
| 4438 | } |
| 4439 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4440 | const size_t num_matches = die_offsets.size(); |
| 4441 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4442 | DWARFCompileUnit* type_cu = NULL; |
| 4443 | const DWARFDebugInfoEntry* type_die = NULL; |
| 4444 | if (num_matches) |
| 4445 | { |
| 4446 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 4447 | for (size_t i=0; i<num_matches; ++i) |
| 4448 | { |
| 4449 | const dw_offset_t die_offset = die_offsets[i]; |
| 4450 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); |
| 4451 | |
| 4452 | if (type_die) |
| 4453 | { |
| 4454 | bool try_resolving_type = false; |
| 4455 | |
| 4456 | // Don't try and resolve the DIE we are looking for with the DIE itself! |
| 4457 | if (type_die != die) |
| 4458 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4459 | switch (type_die->Tag()) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4460 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4461 | case DW_TAG_class_type: |
| 4462 | case DW_TAG_structure_type: |
| 4463 | try_resolving_type = true; |
| 4464 | break; |
| 4465 | default: |
| 4466 | break; |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4467 | } |
| 4468 | } |
| 4469 | |
| 4470 | if (try_resolving_type) |
| 4471 | { |
| Sean Callanan | a9bc065 | 2012-01-19 02:17:40 +0000 | [diff] [blame] | 4472 | 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] | 4473 | 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] | 4474 | |
| 4475 | if (try_resolving_type) |
| 4476 | { |
| 4477 | Type *resolved_type = ResolveType (type_cu, type_die, false); |
| 4478 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) |
| 4479 | { |
| 4480 | DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n", |
| 4481 | MakeUserID(die->GetOffset()), |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4482 | MakeUserID(dwarf_cu->GetOffset()), |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4483 | m_obj_file->GetFileSpec().GetFilename().AsCString(), |
| 4484 | MakeUserID(type_die->GetOffset()), |
| 4485 | MakeUserID(type_cu->GetOffset())); |
| 4486 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4487 | if (die) |
| 4488 | m_die_to_type[die] = resolved_type; |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 4489 | type_sp = resolved_type->shared_from_this(); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4490 | break; |
| 4491 | } |
| 4492 | } |
| 4493 | } |
| 4494 | } |
| 4495 | else |
| 4496 | { |
| 4497 | if (m_using_apple_tables) |
| 4498 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4499 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 4500 | die_offset, type_name.GetCString()); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4501 | } |
| 4502 | } |
| 4503 | |
| 4504 | } |
| 4505 | } |
| 4506 | return type_sp; |
| 4507 | } |
| 4508 | |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4509 | |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4510 | //---------------------------------------------------------------------- |
| 4511 | // This function helps to ensure that the declaration contexts match for |
| 4512 | // two different DIEs. Often times debug information will refer to a |
| 4513 | // forward declaration of a type (the equivalent of "struct my_struct;". |
| 4514 | // There will often be a declaration of that type elsewhere that has the |
| 4515 | // full definition. When we go looking for the full type "my_struct", we |
| 4516 | // will find one or more matches in the accelerator tables and we will |
| 4517 | // then need to make sure the type was in the same declaration context |
| 4518 | // as the original DIE. This function can efficiently compare two DIEs |
| 4519 | // and will return true when the declaration context matches, and false |
| 4520 | // when they don't. |
| 4521 | //---------------------------------------------------------------------- |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4522 | bool |
| 4523 | SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1, |
| 4524 | DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2) |
| 4525 | { |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4526 | if (die1 == die2) |
| 4527 | return true; |
| 4528 | |
| 4529 | #if defined (LLDB_CONFIGURATION_DEBUG) |
| 4530 | // You can't and shouldn't call this function with a compile unit from |
| 4531 | // two different SymbolFileDWARF instances. |
| 4532 | assert (DebugInfo()->ContainsCompileUnit (cu1)); |
| 4533 | assert (DebugInfo()->ContainsCompileUnit (cu2)); |
| 4534 | #endif |
| 4535 | |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4536 | DWARFDIECollection decl_ctx_1; |
| 4537 | DWARFDIECollection decl_ctx_2; |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4538 | //The declaration DIE stack is a stack of the declaration context |
| 4539 | // DIEs all the way back to the compile unit. If a type "T" is |
| 4540 | // declared inside a class "B", and class "B" is declared inside |
| 4541 | // a class "A" and class "A" is in a namespace "lldb", and the |
| 4542 | // namespace is in a compile unit, there will be a stack of DIEs: |
| 4543 | // |
| 4544 | // [0] DW_TAG_class_type for "B" |
| 4545 | // [1] DW_TAG_class_type for "A" |
| 4546 | // [2] DW_TAG_namespace for "lldb" |
| 4547 | // [3] DW_TAG_compile_unit for the source file. |
| 4548 | // |
| 4549 | // We grab both contexts and make sure that everything matches |
| 4550 | // all the way back to the compiler unit. |
| 4551 | |
| 4552 | // First lets grab the decl contexts for both DIEs |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4553 | die1->GetDeclContextDIEs (this, cu1, decl_ctx_1); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 4554 | die2->GetDeclContextDIEs (this, cu2, decl_ctx_2); |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4555 | // Make sure the context arrays have the same size, otherwise |
| 4556 | // we are done |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4557 | const size_t count1 = decl_ctx_1.Size(); |
| 4558 | const size_t count2 = decl_ctx_2.Size(); |
| 4559 | if (count1 != count2) |
| 4560 | return false; |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4561 | |
| 4562 | // Make sure the DW_TAG values match all the way back up the the |
| 4563 | // compile unit. If they don't, then we are done. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4564 | const DWARFDebugInfoEntry *decl_ctx_die1; |
| 4565 | const DWARFDebugInfoEntry *decl_ctx_die2; |
| 4566 | size_t i; |
| 4567 | for (i=0; i<count1; i++) |
| 4568 | { |
| 4569 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); |
| 4570 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); |
| 4571 | if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag()) |
| 4572 | return false; |
| 4573 | } |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4574 | #if defined LLDB_CONFIGURATION_DEBUG |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4575 | |
| 4576 | // Make sure the top item in the decl context die array is always |
| 4577 | // DW_TAG_compile_unit. If it isn't then something went wrong in |
| 4578 | // the DWARFDebugInfoEntry::GetDeclContextDIEs() function... |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4579 | assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit); |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4580 | |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4581 | #endif |
| 4582 | // Always skip the compile unit when comparing by only iterating up to |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4583 | // "count - 1". Here we compare the names as we go. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4584 | for (i=0; i<count1 - 1; i++) |
| 4585 | { |
| 4586 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); |
| 4587 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); |
| 4588 | const char *name1 = decl_ctx_die1->GetName(this, cu1); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 4589 | const char *name2 = decl_ctx_die2->GetName(this, cu2); |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4590 | // If the string was from a DW_FORM_strp, then the pointer will often |
| 4591 | // be the same! |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 4592 | if (name1 == name2) |
| 4593 | continue; |
| 4594 | |
| 4595 | // Name pointers are not equal, so only compare the strings |
| 4596 | // if both are not NULL. |
| 4597 | if (name1 && name2) |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4598 | { |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 4599 | // If the strings don't compare, we are done... |
| 4600 | if (strcmp(name1, name2) != 0) |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4601 | return false; |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 4602 | } |
| 4603 | else |
| 4604 | { |
| 4605 | // One name was NULL while the other wasn't |
| 4606 | return false; |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4607 | } |
| 4608 | } |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4609 | // We made it through all of the checks and the declaration contexts |
| 4610 | // are equal. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4611 | return true; |
| 4612 | } |
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 4613 | |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4614 | // This function can be used when a DIE is found that is a forward declaration |
| 4615 | // 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] | 4616 | // "cu" and "die" must be from this SymbolFileDWARF |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4617 | TypeSP |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4618 | SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu, |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4619 | const DWARFDebugInfoEntry *die, |
| 4620 | const ConstString &type_name) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4621 | { |
| 4622 | TypeSP type_sp; |
| 4623 | |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4624 | #if defined (LLDB_CONFIGURATION_DEBUG) |
| 4625 | // You can't and shouldn't call this function with a compile unit from |
| 4626 | // another SymbolFileDWARF instance. |
| 4627 | assert (DebugInfo()->ContainsCompileUnit (cu)); |
| 4628 | #endif |
| 4629 | |
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 4630 | if (cu == NULL || die == NULL || !type_name) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4631 | return type_sp; |
| 4632 | |
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4633 | LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS)); |
| 4634 | if (log) |
| 4635 | { |
| 4636 | std::string qualified_name; |
| 4637 | die->GetQualifiedName(this, cu, qualified_name); |
| 4638 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 4639 | "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x (%s), name='%s')", |
| 4640 | die->GetOffset(), |
| 4641 | qualified_name.c_str(), |
| 4642 | type_name.GetCString()); |
| 4643 | } |
| 4644 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4645 | DIEArray die_offsets; |
| 4646 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4647 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4648 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4649 | if (m_apple_types_ap.get()) |
| 4650 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4651 | if (m_apple_types_ap->GetHeader().header_data.atoms.size() > 1) |
| 4652 | { |
| Greg Clayton | ae920b6 | 2012-01-06 00:17:16 +0000 | [diff] [blame] | 4653 | m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets); |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4654 | } |
| 4655 | else |
| 4656 | { |
| 4657 | m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets); |
| 4658 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4659 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4660 | } |
| 4661 | else |
| 4662 | { |
| 4663 | if (!m_indexed) |
| 4664 | Index (); |
| 4665 | |
| 4666 | m_type_index.Find (type_name, die_offsets); |
| 4667 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4668 | |
| 4669 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | 6997489 | 2010-12-03 21:42:06 +0000 | [diff] [blame] | 4670 | |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4671 | const dw_tag_t die_tag = die->Tag(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4672 | |
| 4673 | DWARFCompileUnit* type_cu = NULL; |
| 4674 | const DWARFDebugInfoEntry* type_die = NULL; |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4675 | if (num_matches) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4676 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4677 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4678 | for (size_t i=0; i<num_matches; ++i) |
| 4679 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4680 | const dw_offset_t die_offset = die_offsets[i]; |
| 4681 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4682 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4683 | if (type_die) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4684 | { |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4685 | bool try_resolving_type = false; |
| 4686 | |
| 4687 | // Don't try and resolve the DIE we are looking for with the DIE itself! |
| 4688 | if (type_die != die) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4689 | { |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4690 | const dw_tag_t type_die_tag = type_die->Tag(); |
| 4691 | // Make sure the tags match |
| 4692 | if (type_die_tag == die_tag) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4693 | { |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4694 | // The tags match, lets try resolving this type |
| 4695 | try_resolving_type = true; |
| 4696 | } |
| 4697 | else |
| 4698 | { |
| 4699 | // The tags don't match, but we need to watch our for a |
| 4700 | // forward declaration for a struct and ("struct foo") |
| 4701 | // ends up being a class ("class foo { ... };") or |
| 4702 | // vice versa. |
| 4703 | switch (type_die_tag) |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4704 | { |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4705 | case DW_TAG_class_type: |
| 4706 | // We had a "class foo", see if we ended up with a "struct foo { ... };" |
| 4707 | try_resolving_type = (die_tag == DW_TAG_structure_type); |
| 4708 | break; |
| 4709 | case DW_TAG_structure_type: |
| 4710 | // We had a "struct foo", see if we ended up with a "class foo { ... };" |
| 4711 | try_resolving_type = (die_tag == DW_TAG_class_type); |
| 4712 | break; |
| 4713 | default: |
| 4714 | // Tags don't match, don't event try to resolve |
| 4715 | // using this type whose name matches.... |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4716 | break; |
| 4717 | } |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4718 | } |
| 4719 | } |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4720 | |
| 4721 | if (try_resolving_type) |
| 4722 | { |
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4723 | if (log) |
| 4724 | { |
| 4725 | std::string qualified_name; |
| 4726 | type_die->GetQualifiedName(this, cu, qualified_name); |
| 4727 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 4728 | "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') trying die=0x%8.8x (%s)", |
| 4729 | die->GetOffset(), |
| 4730 | type_name.GetCString(), |
| 4731 | type_die->GetOffset(), |
| 4732 | qualified_name.c_str()); |
| 4733 | } |
| 4734 | |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4735 | // Make sure the decl contexts match all the way up |
| 4736 | if (DIEDeclContextsMatch(cu, die, type_cu, type_die)) |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4737 | { |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4738 | Type *resolved_type = ResolveType (type_cu, type_die, false); |
| 4739 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) |
| 4740 | { |
| 4741 | DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n", |
| 4742 | MakeUserID(die->GetOffset()), |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4743 | MakeUserID(dwarf_cu->GetOffset()), |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4744 | m_obj_file->GetFileSpec().GetFilename().AsCString(), |
| 4745 | MakeUserID(type_die->GetOffset()), |
| 4746 | MakeUserID(type_cu->GetOffset())); |
| 4747 | |
| 4748 | m_die_to_type[die] = resolved_type; |
| Greg Clayton | ff7692a | 2012-02-02 18:16:59 +0000 | [diff] [blame] | 4749 | type_sp = resolved_type->shared_from_this(); |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4750 | break; |
| 4751 | } |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4752 | } |
| 4753 | } |
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4754 | else |
| 4755 | { |
| 4756 | if (log) |
| 4757 | { |
| 4758 | std::string qualified_name; |
| 4759 | type_die->GetQualifiedName(this, cu, qualified_name); |
| 4760 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 4761 | "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') ignoring die=0x%8.8x (%s)", |
| 4762 | die->GetOffset(), |
| 4763 | type_name.GetCString(), |
| 4764 | type_die->GetOffset(), |
| 4765 | qualified_name.c_str()); |
| 4766 | } |
| 4767 | } |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4768 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4769 | else |
| 4770 | { |
| 4771 | if (m_using_apple_tables) |
| 4772 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4773 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 4774 | die_offset, type_name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4775 | } |
| 4776 | } |
| 4777 | |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4778 | } |
| 4779 | } |
| 4780 | return type_sp; |
| 4781 | } |
| 4782 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4783 | TypeSP |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4784 | SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx) |
| 4785 | { |
| 4786 | TypeSP type_sp; |
| 4787 | |
| 4788 | const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize(); |
| 4789 | if (dwarf_decl_ctx_count > 0) |
| 4790 | { |
| 4791 | const ConstString type_name(dwarf_decl_ctx[0].name); |
| 4792 | const dw_tag_t tag = dwarf_decl_ctx[0].tag; |
| 4793 | |
| 4794 | if (type_name) |
| 4795 | { |
| 4796 | LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS)); |
| 4797 | if (log) |
| 4798 | { |
| 4799 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 4800 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')", |
| 4801 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), |
| 4802 | dwarf_decl_ctx.GetQualifiedName()); |
| 4803 | } |
| 4804 | |
| 4805 | DIEArray die_offsets; |
| 4806 | |
| 4807 | if (m_using_apple_tables) |
| 4808 | { |
| 4809 | if (m_apple_types_ap.get()) |
| 4810 | { |
| 4811 | if (m_apple_types_ap->GetHeader().header_data.atoms.size() > 1) |
| 4812 | { |
| 4813 | m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets); |
| 4814 | } |
| 4815 | else |
| 4816 | { |
| 4817 | m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets); |
| 4818 | } |
| 4819 | } |
| 4820 | } |
| 4821 | else |
| 4822 | { |
| 4823 | if (!m_indexed) |
| 4824 | Index (); |
| 4825 | |
| 4826 | m_type_index.Find (type_name, die_offsets); |
| 4827 | } |
| 4828 | |
| 4829 | const size_t num_matches = die_offsets.size(); |
| 4830 | |
| 4831 | |
| 4832 | DWARFCompileUnit* type_cu = NULL; |
| 4833 | const DWARFDebugInfoEntry* type_die = NULL; |
| 4834 | if (num_matches) |
| 4835 | { |
| 4836 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 4837 | for (size_t i=0; i<num_matches; ++i) |
| 4838 | { |
| 4839 | const dw_offset_t die_offset = die_offsets[i]; |
| 4840 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); |
| 4841 | |
| 4842 | if (type_die) |
| 4843 | { |
| 4844 | bool try_resolving_type = false; |
| 4845 | |
| 4846 | // Don't try and resolve the DIE we are looking for with the DIE itself! |
| 4847 | const dw_tag_t type_tag = type_die->Tag(); |
| 4848 | // Make sure the tags match |
| 4849 | if (type_tag == tag) |
| 4850 | { |
| 4851 | // The tags match, lets try resolving this type |
| 4852 | try_resolving_type = true; |
| 4853 | } |
| 4854 | else |
| 4855 | { |
| 4856 | // The tags don't match, but we need to watch our for a |
| 4857 | // forward declaration for a struct and ("struct foo") |
| 4858 | // ends up being a class ("class foo { ... };") or |
| 4859 | // vice versa. |
| 4860 | switch (type_tag) |
| 4861 | { |
| 4862 | case DW_TAG_class_type: |
| 4863 | // We had a "class foo", see if we ended up with a "struct foo { ... };" |
| 4864 | try_resolving_type = (tag == DW_TAG_structure_type); |
| 4865 | break; |
| 4866 | case DW_TAG_structure_type: |
| 4867 | // We had a "struct foo", see if we ended up with a "class foo { ... };" |
| 4868 | try_resolving_type = (tag == DW_TAG_class_type); |
| 4869 | break; |
| 4870 | default: |
| 4871 | // Tags don't match, don't event try to resolve |
| 4872 | // using this type whose name matches.... |
| 4873 | break; |
| 4874 | } |
| 4875 | } |
| 4876 | |
| 4877 | if (try_resolving_type) |
| 4878 | { |
| 4879 | DWARFDeclContext type_dwarf_decl_ctx; |
| 4880 | type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx); |
| 4881 | |
| 4882 | if (log) |
| 4883 | { |
| 4884 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 4885 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)", |
| 4886 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), |
| 4887 | dwarf_decl_ctx.GetQualifiedName(), |
| 4888 | type_die->GetOffset(), |
| 4889 | type_dwarf_decl_ctx.GetQualifiedName()); |
| 4890 | } |
| 4891 | |
| 4892 | // Make sure the decl contexts match all the way up |
| 4893 | if (dwarf_decl_ctx == type_dwarf_decl_ctx) |
| 4894 | { |
| 4895 | Type *resolved_type = ResolveType (type_cu, type_die, false); |
| 4896 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) |
| 4897 | { |
| 4898 | type_sp = resolved_type->shared_from_this(); |
| 4899 | break; |
| 4900 | } |
| 4901 | } |
| 4902 | } |
| 4903 | else |
| 4904 | { |
| 4905 | if (log) |
| 4906 | { |
| 4907 | std::string qualified_name; |
| 4908 | type_die->GetQualifiedName(this, type_cu, qualified_name); |
| 4909 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 4910 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)", |
| 4911 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), |
| 4912 | dwarf_decl_ctx.GetQualifiedName(), |
| 4913 | type_die->GetOffset(), |
| 4914 | qualified_name.c_str()); |
| 4915 | } |
| 4916 | } |
| 4917 | } |
| 4918 | else |
| 4919 | { |
| 4920 | if (m_using_apple_tables) |
| 4921 | { |
| 4922 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 4923 | die_offset, type_name.GetCString()); |
| 4924 | } |
| 4925 | } |
| 4926 | |
| 4927 | } |
| 4928 | } |
| 4929 | } |
| 4930 | } |
| 4931 | return type_sp; |
| 4932 | } |
| 4933 | |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 4934 | bool |
| 4935 | SymbolFileDWARF::CopyUniqueClassMethodTypes (Type *class_type, |
| 4936 | DWARFCompileUnit* src_cu, |
| 4937 | const DWARFDebugInfoEntry *src_class_die, |
| 4938 | DWARFCompileUnit* dst_cu, |
| 4939 | const DWARFDebugInfoEntry *dst_class_die) |
| 4940 | { |
| 4941 | if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die) |
| 4942 | return false; |
| 4943 | if (src_class_die->Tag() != dst_class_die->Tag()) |
| 4944 | return false; |
| 4945 | |
| 4946 | // We need to complete the class type so we can get all of the method types |
| 4947 | // parsed so we can then unique those types to their equivalent counterparts |
| 4948 | // in "dst_cu" and "dst_class_die" |
| 4949 | class_type->GetClangFullType(); |
| 4950 | |
| 4951 | const DWARFDebugInfoEntry *src_die; |
| 4952 | const DWARFDebugInfoEntry *dst_die; |
| 4953 | UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die; |
| 4954 | UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die; |
| 4955 | for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling()) |
| 4956 | { |
| 4957 | if (src_die->Tag() == DW_TAG_subprogram) |
| 4958 | { |
| 4959 | const char *src_name = src_die->GetMangledName (this, src_cu); |
| 4960 | if (src_name) |
| 4961 | src_name_to_die.Append(ConstString(src_name).GetCString(), src_die); |
| 4962 | } |
| 4963 | } |
| 4964 | for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling()) |
| 4965 | { |
| 4966 | if (dst_die->Tag() == DW_TAG_subprogram) |
| 4967 | { |
| 4968 | const char *dst_name = dst_die->GetMangledName (this, dst_cu); |
| 4969 | if (dst_name) |
| 4970 | dst_name_to_die.Append(ConstString(dst_name).GetCString(), dst_die); |
| 4971 | } |
| 4972 | } |
| 4973 | const uint32_t src_size = src_name_to_die.GetSize (); |
| 4974 | const uint32_t dst_size = dst_name_to_die.GetSize (); |
| 4975 | LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION)); |
| 4976 | |
| 4977 | if (src_size && dst_size) |
| 4978 | { |
| Sean Callanan | 210b815 | 2012-07-07 00:29:33 +0000 | [diff] [blame] | 4979 | if (src_size != dst_size) |
| 4980 | { |
| 4981 | if (log) |
| 4982 | log->Printf("warning: tried to unique class DIE 0x%8.8x to 0x%8.8x, but they didn't have the same size (src=%d, dst=%d)", |
| 4983 | src_class_die->GetOffset(), |
| 4984 | dst_class_die->GetOffset(), |
| 4985 | src_size, |
| 4986 | dst_size); |
| 4987 | |
| 4988 | return false; |
| 4989 | } |
| 4990 | |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 4991 | uint32_t idx; |
| 4992 | for (idx = 0; idx < src_size; ++idx) |
| 4993 | { |
| 4994 | src_die = src_name_to_die.GetValueAtIndexUnchecked (idx); |
| 4995 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx); |
| 4996 | |
| 4997 | if (src_die->Tag() != dst_die->Tag()) |
| 4998 | { |
| 4999 | if (log) |
| 5000 | 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)", |
| 5001 | src_class_die->GetOffset(), |
| 5002 | dst_class_die->GetOffset(), |
| 5003 | src_die->GetOffset(), |
| 5004 | DW_TAG_value_to_name(src_die->Tag()), |
| 5005 | dst_die->GetOffset(), |
| 5006 | DW_TAG_value_to_name(src_die->Tag())); |
| 5007 | return false; |
| 5008 | } |
| 5009 | |
| 5010 | const char *src_name = src_die->GetMangledName (this, src_cu); |
| 5011 | const char *dst_name = dst_die->GetMangledName (this, dst_cu); |
| 5012 | |
| 5013 | // Make sure the names match |
| 5014 | if (src_name == dst_name || (strcmp (src_name, dst_name) == 0)) |
| 5015 | continue; |
| 5016 | |
| 5017 | if (log) |
| 5018 | 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)", |
| 5019 | src_class_die->GetOffset(), |
| 5020 | dst_class_die->GetOffset(), |
| 5021 | src_die->GetOffset(), |
| 5022 | src_name, |
| 5023 | dst_die->GetOffset(), |
| 5024 | dst_name); |
| 5025 | |
| 5026 | return false; |
| 5027 | } |
| 5028 | |
| 5029 | for (idx = 0; idx < src_size; ++idx) |
| 5030 | { |
| 5031 | src_die = src_name_to_die.GetValueAtIndexUnchecked (idx); |
| 5032 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx); |
| 5033 | |
| 5034 | clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die]; |
| 5035 | if (src_decl_ctx) |
| 5036 | { |
| 5037 | if (log) |
| 5038 | log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x\n", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset()); |
| 5039 | LinkDeclContextToDIE (src_decl_ctx, dst_die); |
| 5040 | } |
| 5041 | else |
| 5042 | { |
| 5043 | if (log) |
| 5044 | log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found\n", src_die->GetOffset(), dst_die->GetOffset()); |
| 5045 | } |
| 5046 | |
| 5047 | Type *src_child_type = m_die_to_type[src_die]; |
| 5048 | if (src_child_type) |
| 5049 | { |
| 5050 | if (log) |
| 5051 | log->Printf ("uniquing type %p (uid=0x%llx) from 0x%8.8x for 0x%8.8x\n", src_child_type, src_child_type->GetID(), src_die->GetOffset(), dst_die->GetOffset()); |
| 5052 | m_die_to_type[dst_die] = src_child_type; |
| 5053 | } |
| 5054 | else |
| 5055 | { |
| 5056 | if (log) |
| 5057 | log->Printf ("warning: tried to unique lldb_private::Type from 0x%8.8x for 0x%8.8x, but none was found\n", src_die->GetOffset(), dst_die->GetOffset()); |
| 5058 | } |
| 5059 | } |
| 5060 | return true; |
| 5061 | } |
| 5062 | else |
| 5063 | { |
| 5064 | if (log) |
| 5065 | log->Printf("warning: tried to unique class DIE 0x%8.8x to 0x%8.8x, but 0x%8.8x has %u methods and 0x%8.8x has %u", |
| 5066 | src_class_die->GetOffset(), |
| 5067 | dst_class_die->GetOffset(), |
| 5068 | src_die->GetOffset(), |
| 5069 | src_size, |
| 5070 | dst_die->GetOffset(), |
| 5071 | dst_size); |
| 5072 | } |
| 5073 | return false; |
| 5074 | } |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5075 | |
| 5076 | TypeSP |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5077 | 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] | 5078 | { |
| 5079 | TypeSP type_sp; |
| 5080 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5081 | if (type_is_new_ptr) |
| 5082 | *type_is_new_ptr = false; |
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5083 | |
| 5084 | #if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE) |
| 5085 | static DIEStack g_die_stack; |
| 5086 | DIEStack::ScopedPopper scoped_die_logger(g_die_stack); |
| 5087 | #endif |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5088 | |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 5089 | AccessType accessibility = eAccessNone; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5090 | if (die != NULL) |
| 5091 | { |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 5092 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5093 | if (log) |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5094 | { |
| 5095 | const DWARFDebugInfoEntry *context_die; |
| 5096 | clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die); |
| 5097 | |
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5098 | GetObjectFile()->GetModule()->LogMessage (log.get(), "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] | 5099 | die->GetOffset(), |
| 5100 | context, |
| 5101 | context_die->GetOffset(), |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5102 | DW_TAG_value_to_name(die->Tag()), |
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5103 | die->GetName(this, dwarf_cu)); |
| 5104 | |
| 5105 | #if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE) |
| 5106 | scoped_die_logger.Push (dwarf_cu, die); |
| 5107 | g_die_stack.LogDIEs(log.get(), this); |
| 5108 | #endif |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5109 | } |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5110 | // |
| 5111 | // LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| 5112 | // if (log && dwarf_cu) |
| 5113 | // { |
| 5114 | // StreamString s; |
| 5115 | // die->DumpLocation (this, dwarf_cu, s); |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5116 | // GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData()); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5117 | // |
| 5118 | // } |
| Jim Ingham | 16746d1 | 2011-08-25 23:21:43 +0000 | [diff] [blame] | 5119 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5120 | Type *type_ptr = m_die_to_type.lookup (die); |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5121 | TypeList* type_list = GetTypeList(); |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5122 | if (type_ptr == NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5123 | { |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5124 | ClangASTContext &ast = GetClangASTContext(); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5125 | if (type_is_new_ptr) |
| 5126 | *type_is_new_ptr = true; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5127 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5128 | const dw_tag_t tag = die->Tag(); |
| 5129 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5130 | bool is_forward_declaration = false; |
| 5131 | DWARFDebugInfoEntry::Attributes attributes; |
| 5132 | const char *type_name_cstr = NULL; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5133 | ConstString type_name_const_str; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5134 | Type::ResolveState resolve_state = Type::eResolveStateUnresolved; |
| 5135 | size_t byte_size = 0; |
| 5136 | Declaration decl; |
| 5137 | |
| Greg Clayton | 4957bf6 | 2010-09-30 21:49:03 +0000 | [diff] [blame] | 5138 | Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5139 | clang_type_t clang_type = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5140 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5141 | dw_attr_t attr; |
| 5142 | |
| 5143 | switch (tag) |
| 5144 | { |
| 5145 | case DW_TAG_base_type: |
| 5146 | case DW_TAG_pointer_type: |
| 5147 | case DW_TAG_reference_type: |
| Sean Callanan | ce8af86 | 2012-05-21 23:31:51 +0000 | [diff] [blame] | 5148 | case DW_TAG_rvalue_reference_type: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5149 | case DW_TAG_typedef: |
| 5150 | case DW_TAG_const_type: |
| 5151 | case DW_TAG_restrict_type: |
| 5152 | case DW_TAG_volatile_type: |
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5153 | case DW_TAG_unspecified_type: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5154 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5155 | // 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] | 5156 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5157 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5158 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5159 | uint32_t encoding = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5160 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; |
| 5161 | |
| 5162 | if (num_attributes > 0) |
| 5163 | { |
| 5164 | uint32_t i; |
| 5165 | for (i=0; i<num_attributes; ++i) |
| 5166 | { |
| 5167 | attr = attributes.AttributeAtIndex(i); |
| 5168 | DWARFFormValue form_value; |
| 5169 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 5170 | { |
| 5171 | switch (attr) |
| 5172 | { |
| 5173 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 5174 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 5175 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 5176 | case DW_AT_name: |
| Jim Ingham | 337030f | 2011-04-15 23:41:23 +0000 | [diff] [blame] | 5177 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5178 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Jim Ingham | 337030f | 2011-04-15 23:41:23 +0000 | [diff] [blame] | 5179 | // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't |
| 5180 | // include the "&"... |
| 5181 | if (tag == DW_TAG_reference_type) |
| 5182 | { |
| 5183 | if (strchr (type_name_cstr, '&') == NULL) |
| 5184 | type_name_cstr = NULL; |
| 5185 | } |
| 5186 | if (type_name_cstr) |
| 5187 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5188 | break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 5189 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5190 | case DW_AT_encoding: encoding = form_value.Unsigned(); break; |
| 5191 | case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; |
| 5192 | default: |
| 5193 | case DW_AT_sibling: |
| 5194 | break; |
| 5195 | } |
| 5196 | } |
| 5197 | } |
| 5198 | } |
| 5199 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5200 | DEBUG_PRINTF ("0x%8.8llx: %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] | 5201 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5202 | switch (tag) |
| 5203 | { |
| 5204 | default: |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5205 | break; |
| 5206 | |
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5207 | case DW_TAG_unspecified_type: |
| 5208 | if (strcmp(type_name_cstr, "nullptr_t") == 0) |
| 5209 | { |
| 5210 | resolve_state = Type::eResolveStateFull; |
| 5211 | clang_type = ast.getASTContext()->NullPtrTy.getAsOpaquePtr(); |
| 5212 | break; |
| 5213 | } |
| 5214 | // Fall through to base type below in case we can handle the type there... |
| 5215 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5216 | case DW_TAG_base_type: |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5217 | resolve_state = Type::eResolveStateFull; |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5218 | clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr, |
| 5219 | encoding, |
| 5220 | byte_size * 8); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5221 | break; |
| 5222 | |
| Sean Callanan | ce8af86 | 2012-05-21 23:31:51 +0000 | [diff] [blame] | 5223 | case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break; |
| 5224 | case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break; |
| 5225 | case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break; |
| 5226 | case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break; |
| 5227 | case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break; |
| 5228 | case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break; |
| 5229 | case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5230 | } |
| 5231 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5232 | if (clang_type == NULL && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID)) |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 5233 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5234 | if (type_name_cstr != NULL && sc.comp_unit != NULL && |
| 5235 | (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus)) |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 5236 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5237 | static ConstString g_objc_type_name_id("id"); |
| 5238 | static ConstString g_objc_type_name_Class("Class"); |
| 5239 | static ConstString g_objc_type_name_selector("SEL"); |
| 5240 | |
| 5241 | if (type_name_const_str == g_objc_type_name_id) |
| 5242 | { |
| 5243 | if (log) |
| 5244 | GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'id' built-in type.", |
| 5245 | die->GetOffset(), |
| 5246 | DW_TAG_value_to_name(die->Tag()), |
| 5247 | die->GetName(this, dwarf_cu)); |
| 5248 | clang_type = ast.GetBuiltInType_objc_id(); |
| 5249 | encoding_data_type = Type::eEncodingIsUID; |
| 5250 | encoding_uid = LLDB_INVALID_UID; |
| 5251 | resolve_state = Type::eResolveStateFull; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5252 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5253 | } |
| 5254 | else if (type_name_const_str == g_objc_type_name_Class) |
| 5255 | { |
| 5256 | if (log) |
| 5257 | GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'Class' built-in type.", |
| 5258 | die->GetOffset(), |
| 5259 | DW_TAG_value_to_name(die->Tag()), |
| 5260 | die->GetName(this, dwarf_cu)); |
| 5261 | clang_type = ast.GetBuiltInType_objc_Class(); |
| 5262 | encoding_data_type = Type::eEncodingIsUID; |
| 5263 | encoding_uid = LLDB_INVALID_UID; |
| 5264 | resolve_state = Type::eResolveStateFull; |
| 5265 | } |
| 5266 | else if (type_name_const_str == g_objc_type_name_selector) |
| 5267 | { |
| 5268 | if (log) |
| 5269 | GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'selector' built-in type.", |
| 5270 | die->GetOffset(), |
| 5271 | DW_TAG_value_to_name(die->Tag()), |
| 5272 | die->GetName(this, dwarf_cu)); |
| 5273 | clang_type = ast.GetBuiltInType_objc_selector(); |
| 5274 | encoding_data_type = Type::eEncodingIsUID; |
| 5275 | encoding_uid = LLDB_INVALID_UID; |
| 5276 | resolve_state = Type::eResolveStateFull; |
| 5277 | } |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 5278 | } |
| 5279 | } |
| 5280 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5281 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5282 | this, |
| 5283 | type_name_const_str, |
| 5284 | byte_size, |
| 5285 | NULL, |
| 5286 | encoding_uid, |
| 5287 | encoding_data_type, |
| 5288 | &decl, |
| 5289 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5290 | resolve_state)); |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5291 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5292 | m_die_to_type[die] = type_sp.get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5293 | |
| 5294 | // Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false); |
| 5295 | // if (encoding_type != NULL) |
| 5296 | // { |
| 5297 | // if (encoding_type != DIE_IS_BEING_PARSED) |
| 5298 | // type_sp->SetEncodingType(encoding_type); |
| 5299 | // else |
| 5300 | // m_indirect_fixups.push_back(type_sp.get()); |
| 5301 | // } |
| 5302 | } |
| 5303 | break; |
| 5304 | |
| 5305 | case DW_TAG_structure_type: |
| 5306 | case DW_TAG_union_type: |
| 5307 | case DW_TAG_class_type: |
| 5308 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5309 | // 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] | 5310 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 5311 | bool byte_size_valid = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5312 | |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5313 | LanguageType class_language = eLanguageTypeUnknown; |
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 5314 | bool is_complete_objc_class = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5315 | //bool struct_is_class = false; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5316 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5317 | if (num_attributes > 0) |
| 5318 | { |
| 5319 | uint32_t i; |
| 5320 | for (i=0; i<num_attributes; ++i) |
| 5321 | { |
| 5322 | attr = attributes.AttributeAtIndex(i); |
| 5323 | DWARFFormValue form_value; |
| 5324 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 5325 | { |
| 5326 | switch (attr) |
| 5327 | { |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5328 | case DW_AT_decl_file: |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5329 | if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid()) |
| 5330 | { |
| 5331 | // llvm-gcc outputs invalid DW_AT_decl_file attributes that always |
| 5332 | // point to the compile unit file, so we clear this invalid value |
| 5333 | // so that we can still unique types efficiently. |
| 5334 | decl.SetFile(FileSpec ("<invalid>", false)); |
| 5335 | } |
| 5336 | else |
| 5337 | decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5338 | break; |
| 5339 | |
| 5340 | case DW_AT_decl_line: |
| 5341 | decl.SetLine(form_value.Unsigned()); |
| 5342 | break; |
| 5343 | |
| 5344 | case DW_AT_decl_column: |
| 5345 | decl.SetColumn(form_value.Unsigned()); |
| 5346 | break; |
| 5347 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5348 | case DW_AT_name: |
| 5349 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5350 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5351 | break; |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5352 | |
| 5353 | case DW_AT_byte_size: |
| 5354 | byte_size = form_value.Unsigned(); |
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 5355 | byte_size_valid = true; |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5356 | break; |
| 5357 | |
| 5358 | case DW_AT_accessibility: |
| 5359 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); |
| 5360 | break; |
| 5361 | |
| 5362 | case DW_AT_declaration: |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 5363 | is_forward_declaration = form_value.Unsigned() != 0; |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5364 | break; |
| 5365 | |
| 5366 | case DW_AT_APPLE_runtime_class: |
| 5367 | class_language = (LanguageType)form_value.Signed(); |
| 5368 | break; |
| 5369 | |
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 5370 | case DW_AT_APPLE_objc_complete_type: |
| 5371 | is_complete_objc_class = form_value.Signed(); |
| 5372 | break; |
| 5373 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5374 | case DW_AT_allocated: |
| 5375 | case DW_AT_associated: |
| 5376 | case DW_AT_data_location: |
| 5377 | case DW_AT_description: |
| 5378 | case DW_AT_start_scope: |
| 5379 | case DW_AT_visibility: |
| 5380 | default: |
| 5381 | case DW_AT_sibling: |
| 5382 | break; |
| 5383 | } |
| 5384 | } |
| 5385 | } |
| 5386 | } |
| 5387 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5388 | UniqueDWARFASTType unique_ast_entry; |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5389 | |
| Greg Clayton | 123edca | 2012-03-02 00:07:15 +0000 | [diff] [blame] | 5390 | // Only try and unique the type if it has a name. |
| 5391 | if (type_name_const_str && |
| 5392 | GetUniqueDWARFASTTypeMap().Find (type_name_const_str, |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5393 | this, |
| 5394 | dwarf_cu, |
| 5395 | die, |
| 5396 | decl, |
| 5397 | byte_size_valid ? byte_size : -1, |
| 5398 | unique_ast_entry)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5399 | { |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5400 | // We have already parsed this type or from another |
| 5401 | // compile unit. GCC loves to use the "one definition |
| 5402 | // rule" which can result in multiple definitions |
| 5403 | // of the same class over and over in each compile |
| 5404 | // unit. |
| 5405 | type_sp = unique_ast_entry.m_type_sp; |
| 5406 | if (type_sp) |
| Greg Clayton | c615ce4 | 2010-11-09 04:42:43 +0000 | [diff] [blame] | 5407 | { |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5408 | m_die_to_type[die] = type_sp.get(); |
| 5409 | return type_sp; |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5410 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5411 | } |
| 5412 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5413 | DEBUG_PRINTF ("0x%8.8llx: %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] | 5414 | |
| 5415 | int tag_decl_kind = -1; |
| 5416 | AccessType default_accessibility = eAccessNone; |
| 5417 | if (tag == DW_TAG_structure_type) |
| 5418 | { |
| 5419 | tag_decl_kind = clang::TTK_Struct; |
| 5420 | default_accessibility = eAccessPublic; |
| 5421 | } |
| 5422 | else if (tag == DW_TAG_union_type) |
| 5423 | { |
| 5424 | tag_decl_kind = clang::TTK_Union; |
| 5425 | default_accessibility = eAccessPublic; |
| 5426 | } |
| 5427 | else if (tag == DW_TAG_class_type) |
| 5428 | { |
| 5429 | tag_decl_kind = clang::TTK_Class; |
| 5430 | default_accessibility = eAccessPrivate; |
| 5431 | } |
| Greg Clayton | 3a5f29a | 2011-11-30 02:48:28 +0000 | [diff] [blame] | 5432 | |
| 5433 | if (byte_size_valid && byte_size == 0 && type_name_cstr && |
| 5434 | die->HasChildren() == false && |
| 5435 | sc.comp_unit->GetLanguage() == eLanguageTypeObjC) |
| 5436 | { |
| 5437 | // Work around an issue with clang at the moment where |
| 5438 | // forward declarations for objective C classes are emitted |
| 5439 | // as: |
| 5440 | // DW_TAG_structure_type [2] |
| 5441 | // DW_AT_name( "ForwardObjcClass" ) |
| 5442 | // DW_AT_byte_size( 0x00 ) |
| 5443 | // DW_AT_decl_file( "..." ) |
| 5444 | // DW_AT_decl_line( 1 ) |
| 5445 | // |
| 5446 | // Note that there is no DW_AT_declaration and there are |
| 5447 | // no children, and the byte size is zero. |
| 5448 | is_forward_declaration = true; |
| 5449 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5450 | |
| Sean Callanan | 7457f8d | 2012-04-25 01:03:57 +0000 | [diff] [blame] | 5451 | if (class_language == eLanguageTypeObjC || |
| 5452 | class_language == eLanguageTypeObjC_plus_plus) |
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 5453 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5454 | 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] | 5455 | { |
| 5456 | // We have a valid eSymbolTypeObjCClass class symbol whose |
| 5457 | // name matches the current objective C class that we |
| 5458 | // are trying to find and this DIE isn't the complete |
| 5459 | // definition (we checked is_complete_objc_class above and |
| 5460 | // know it is false), so the real definition is in here somewhere |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5461 | type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true); |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5462 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 5463 | if (!type_sp && GetDebugMapSymfile ()) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5464 | { |
| 5465 | // We weren't able to find a full declaration in |
| 5466 | // this DWARF, see if we have a declaration anywhere |
| 5467 | // else... |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5468 | 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] | 5469 | } |
| 5470 | |
| 5471 | if (type_sp) |
| 5472 | { |
| 5473 | if (log) |
| 5474 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5475 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 5476 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an incomplete objc type, complete type is 0x%8.8llx", |
| 5477 | this, |
| 5478 | die->GetOffset(), |
| 5479 | DW_TAG_value_to_name(tag), |
| 5480 | type_name_cstr, |
| 5481 | type_sp->GetID()); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5482 | } |
| 5483 | |
| 5484 | // We found a real definition for this type elsewhere |
| 5485 | // so lets use it and cache the fact that we found |
| 5486 | // a complete type for this die |
| 5487 | m_die_to_type[die] = type_sp.get(); |
| 5488 | return type_sp; |
| 5489 | } |
| 5490 | } |
| 5491 | } |
| 5492 | |
| 5493 | |
| 5494 | if (is_forward_declaration) |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5495 | { |
| 5496 | // We have a forward declaration to a type and we need |
| 5497 | // to try and find a full declaration. We look in the |
| 5498 | // current type index just in case we have a forward |
| 5499 | // declaration followed by an actual declarations in the |
| 5500 | // DWARF. If this fails, we need to look elsewhere... |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 5501 | if (log) |
| 5502 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5503 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 5504 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type", |
| 5505 | this, |
| 5506 | die->GetOffset(), |
| 5507 | DW_TAG_value_to_name(tag), |
| 5508 | type_name_cstr); |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 5509 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5510 | |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5511 | DWARFDeclContext die_decl_ctx; |
| 5512 | die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx); |
| 5513 | |
| 5514 | //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str); |
| 5515 | type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5516 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 5517 | if (!type_sp && GetDebugMapSymfile ()) |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5518 | { |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5519 | // We weren't able to find a full declaration in |
| 5520 | // this DWARF, see if we have a declaration anywhere |
| 5521 | // else... |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5522 | type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5523 | } |
| 5524 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5525 | if (type_sp) |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5526 | { |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 5527 | if (log) |
| 5528 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5529 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 5530 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8llx", |
| 5531 | this, |
| 5532 | die->GetOffset(), |
| 5533 | DW_TAG_value_to_name(tag), |
| 5534 | type_name_cstr, |
| 5535 | type_sp->GetID()); |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 5536 | } |
| 5537 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5538 | // We found a real definition for this type elsewhere |
| 5539 | // so lets use it and cache the fact that we found |
| 5540 | // a complete type for this die |
| 5541 | m_die_to_type[die] = type_sp.get(); |
| 5542 | return type_sp; |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5543 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5544 | } |
| 5545 | assert (tag_decl_kind != -1); |
| 5546 | bool clang_type_was_created = false; |
| 5547 | clang_type = m_forward_decl_die_to_clang_type.lookup (die); |
| 5548 | if (clang_type == NULL) |
| 5549 | { |
| Sean Callanan | 4d04c6a | 2012-02-09 22:54:11 +0000 | [diff] [blame] | 5550 | const DWARFDebugInfoEntry *decl_ctx_die; |
| 5551 | |
| 5552 | clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die); |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 5553 | if (accessibility == eAccessNone && decl_ctx) |
| 5554 | { |
| 5555 | // Check the decl context that contains this class/struct/union. |
| 5556 | // If it is a class we must give it an accessability. |
| 5557 | const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind(); |
| 5558 | if (DeclKindIsCXXClass (containing_decl_kind)) |
| 5559 | accessibility = default_accessibility; |
| 5560 | } |
| 5561 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5562 | if (type_name_cstr && strchr (type_name_cstr, '<')) |
| 5563 | { |
| 5564 | ClangASTContext::TemplateParameterInfos template_param_infos; |
| 5565 | if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos)) |
| 5566 | { |
| 5567 | clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx, |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 5568 | accessibility, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5569 | type_name_cstr, |
| 5570 | tag_decl_kind, |
| 5571 | template_param_infos); |
| 5572 | |
| 5573 | clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx, |
| 5574 | class_template_decl, |
| 5575 | tag_decl_kind, |
| 5576 | template_param_infos); |
| 5577 | clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl); |
| 5578 | clang_type_was_created = true; |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 5579 | |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 5580 | GetClangASTContext().SetMetadataAsUserID ((uintptr_t)class_template_decl, MakeUserID(die->GetOffset())); |
| 5581 | GetClangASTContext().SetMetadataAsUserID ((uintptr_t)class_specialization_decl, MakeUserID(die->GetOffset())); |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5582 | } |
| 5583 | } |
| 5584 | |
| 5585 | if (!clang_type_was_created) |
| 5586 | { |
| 5587 | clang_type_was_created = true; |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 5588 | ClangASTMetadata metadata; |
| 5589 | metadata.SetUserID(MakeUserID(die->GetOffset())); |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 5590 | clang_type = ast.CreateRecordType (decl_ctx, |
| 5591 | accessibility, |
| 5592 | type_name_cstr, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5593 | tag_decl_kind, |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 5594 | class_language, |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 5595 | &metadata); |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5596 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5597 | } |
| 5598 | |
| 5599 | // Store a forward declaration to this class type in case any |
| 5600 | // parameters in any class methods need it for the clang |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 5601 | // types for function prototypes. |
| 5602 | LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5603 | type_sp.reset (new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5604 | this, |
| 5605 | type_name_const_str, |
| 5606 | byte_size, |
| 5607 | NULL, |
| 5608 | LLDB_INVALID_UID, |
| 5609 | Type::eEncodingIsUID, |
| 5610 | &decl, |
| 5611 | clang_type, |
| 5612 | Type::eResolveStateForward)); |
| Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 5613 | |
| 5614 | type_sp->SetIsCompleteObjCClass(is_complete_objc_class); |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5615 | |
| 5616 | |
| 5617 | // Add our type to the unique type map so we don't |
| 5618 | // end up creating many copies of the same type over |
| 5619 | // and over in the ASTContext for our module |
| 5620 | unique_ast_entry.m_type_sp = type_sp; |
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 5621 | unique_ast_entry.m_symfile = this; |
| 5622 | unique_ast_entry.m_cu = dwarf_cu; |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5623 | unique_ast_entry.m_die = die; |
| 5624 | unique_ast_entry.m_declaration = decl; |
| Sean Callanan | 5970059 | 2012-02-13 22:30:16 +0000 | [diff] [blame] | 5625 | unique_ast_entry.m_byte_size = byte_size; |
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 5626 | GetUniqueDWARFASTTypeMap().Insert (type_name_const_str, |
| 5627 | unique_ast_entry); |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5628 | |
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 5629 | if (!is_forward_declaration) |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 5630 | { |
| 5631 | // Always start the definition for a class type so that |
| 5632 | // if the class has child classes or types that require |
| 5633 | // the class to be created for use as their decl contexts |
| 5634 | // the class will be ready to accept these child definitions. |
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 5635 | if (die->HasChildren() == false) |
| 5636 | { |
| 5637 | // No children for this struct/union/class, lets finish it |
| 5638 | ast.StartTagDeclarationDefinition (clang_type); |
| 5639 | ast.CompleteTagDeclarationDefinition (clang_type); |
| Sean Callanan | 433cd22 | 2012-10-19 01:37:25 +0000 | [diff] [blame] | 5640 | |
| 5641 | if (tag == DW_TAG_structure_type) // this only applies in C |
| 5642 | { |
| 5643 | clang::QualType qual_type = clang::QualType::getFromOpaquePtr (clang_type); |
| 5644 | const clang::RecordType *record_type = qual_type->getAs<clang::RecordType> (); |
| 5645 | |
| 5646 | if (record_type) |
| 5647 | { |
| 5648 | clang::RecordDecl *record_decl = record_type->getDecl(); |
| 5649 | |
| 5650 | if (record_decl) |
| 5651 | { |
| 5652 | LayoutInfo layout_info; |
| 5653 | |
| 5654 | layout_info.alignment = 0; |
| 5655 | layout_info.bit_size = 0; |
| 5656 | |
| 5657 | m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info)); |
| 5658 | } |
| 5659 | } |
| 5660 | } |
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 5661 | } |
| 5662 | else if (clang_type_was_created) |
| 5663 | { |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 5664 | // Start the definition if the class is not objective C since |
| 5665 | // the underlying decls respond to isCompleteDefinition(). Objective |
| 5666 | // C decls dont' respond to isCompleteDefinition() so we can't |
| 5667 | // start the declaration definition right away. For C++ classs/union/structs |
| 5668 | // we want to start the definition in case the class is needed as the |
| 5669 | // declaration context for a contained class or type without the need |
| 5670 | // to complete that type.. |
| 5671 | |
| Sean Callanan | 7457f8d | 2012-04-25 01:03:57 +0000 | [diff] [blame] | 5672 | if (class_language != eLanguageTypeObjC && |
| 5673 | class_language != eLanguageTypeObjC_plus_plus) |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 5674 | ast.StartTagDeclarationDefinition (clang_type); |
| 5675 | |
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 5676 | // Leave this as a forward declaration until we need |
| 5677 | // to know the details of the type. lldb_private::Type |
| 5678 | // will automatically call the SymbolFile virtual function |
| 5679 | // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)" |
| 5680 | // When the definition needs to be defined. |
| 5681 | m_forward_decl_die_to_clang_type[die] = clang_type; |
| 5682 | m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die; |
| 5683 | ClangASTContext::SetHasExternalStorage (clang_type, true); |
| 5684 | } |
| Greg Clayton | c615ce4 | 2010-11-09 04:42:43 +0000 | [diff] [blame] | 5685 | } |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 5686 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5687 | } |
| 5688 | break; |
| 5689 | |
| 5690 | case DW_TAG_enumeration_type: |
| 5691 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5692 | // 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] | 5693 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5694 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5695 | lldb::user_id_t encoding_uid = DW_INVALID_OFFSET; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5696 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5697 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5698 | if (num_attributes > 0) |
| 5699 | { |
| 5700 | uint32_t i; |
| 5701 | |
| 5702 | for (i=0; i<num_attributes; ++i) |
| 5703 | { |
| 5704 | attr = attributes.AttributeAtIndex(i); |
| 5705 | DWARFFormValue form_value; |
| 5706 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 5707 | { |
| 5708 | switch (attr) |
| 5709 | { |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 5710 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 5711 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 5712 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5713 | case DW_AT_name: |
| 5714 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5715 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5716 | break; |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 5717 | case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 5718 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; |
| 5719 | case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
| 5720 | case DW_AT_declaration: break; //is_forward_declaration = form_value.Unsigned() != 0; break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5721 | case DW_AT_allocated: |
| 5722 | case DW_AT_associated: |
| 5723 | case DW_AT_bit_stride: |
| 5724 | case DW_AT_byte_stride: |
| 5725 | case DW_AT_data_location: |
| 5726 | case DW_AT_description: |
| 5727 | case DW_AT_start_scope: |
| 5728 | case DW_AT_visibility: |
| 5729 | case DW_AT_specification: |
| 5730 | case DW_AT_abstract_origin: |
| 5731 | case DW_AT_sibling: |
| 5732 | break; |
| 5733 | } |
| 5734 | } |
| 5735 | } |
| 5736 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5737 | DEBUG_PRINTF ("0x%8.8llx: %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] | 5738 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5739 | clang_type_t enumerator_clang_type = NULL; |
| 5740 | clang_type = m_forward_decl_die_to_clang_type.lookup (die); |
| 5741 | if (clang_type == NULL) |
| 5742 | { |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5743 | enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL, |
| 5744 | DW_ATE_signed, |
| 5745 | byte_size * 8); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 5746 | clang_type = ast.CreateEnumerationType (type_name_cstr, |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 5747 | GetClangDeclContextContainingDIE (dwarf_cu, die, NULL), |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 5748 | decl, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5749 | enumerator_clang_type); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5750 | } |
| 5751 | else |
| 5752 | { |
| 5753 | enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type); |
| 5754 | assert (enumerator_clang_type != NULL); |
| 5755 | } |
| 5756 | |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 5757 | LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die); |
| 5758 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5759 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5760 | this, |
| 5761 | type_name_const_str, |
| 5762 | byte_size, |
| 5763 | NULL, |
| 5764 | encoding_uid, |
| 5765 | Type::eEncodingIsUID, |
| 5766 | &decl, |
| 5767 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5768 | Type::eResolveStateForward)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5769 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 5770 | ast.StartTagDeclarationDefinition (clang_type); |
| 5771 | if (die->HasChildren()) |
| 5772 | { |
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 5773 | SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); |
| 5774 | ParseChildEnumerators(cu_sc, clang_type, type_sp->GetByteSize(), dwarf_cu, die); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 5775 | } |
| 5776 | ast.CompleteTagDeclarationDefinition (clang_type); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5777 | } |
| 5778 | } |
| 5779 | break; |
| 5780 | |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 5781 | case DW_TAG_inlined_subroutine: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5782 | case DW_TAG_subprogram: |
| 5783 | case DW_TAG_subroutine_type: |
| 5784 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5785 | // 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] | 5786 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5787 | |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 5788 | //const char *mangled = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5789 | dw_offset_t type_die_offset = DW_INVALID_OFFSET; |
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 5790 | bool is_variadic = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5791 | bool is_inline = false; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5792 | bool is_static = false; |
| 5793 | bool is_virtual = false; |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 5794 | bool is_explicit = false; |
| Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 5795 | bool is_artificial = false; |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5796 | dw_offset_t specification_die_offset = DW_INVALID_OFFSET; |
| 5797 | dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET; |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 5798 | dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5799 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5800 | unsigned type_quals = 0; |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 5801 | clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5802 | |
| 5803 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5804 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5805 | if (num_attributes > 0) |
| 5806 | { |
| 5807 | uint32_t i; |
| 5808 | for (i=0; i<num_attributes; ++i) |
| 5809 | { |
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 5810 | attr = attributes.AttributeAtIndex(i); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5811 | DWARFFormValue form_value; |
| 5812 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 5813 | { |
| 5814 | switch (attr) |
| 5815 | { |
| 5816 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 5817 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 5818 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 5819 | case DW_AT_name: |
| 5820 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5821 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5822 | break; |
| 5823 | |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 5824 | 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] | 5825 | 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] | 5826 | case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 5827 | case DW_AT_declaration: break; // is_forward_declaration = form_value.Unsigned() != 0; break; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5828 | case DW_AT_inline: is_inline = form_value.Unsigned() != 0; break; |
| 5829 | case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break; |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 5830 | case DW_AT_explicit: is_explicit = form_value.Unsigned() != 0; break; |
| Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 5831 | case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break; |
| 5832 | |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 5833 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5834 | case DW_AT_external: |
| 5835 | if (form_value.Unsigned()) |
| 5836 | { |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 5837 | if (storage == clang::SC_None) |
| 5838 | storage = clang::SC_Extern; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5839 | else |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 5840 | storage = clang::SC_PrivateExtern; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5841 | } |
| 5842 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5843 | |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5844 | case DW_AT_specification: |
| 5845 | specification_die_offset = form_value.Reference(dwarf_cu); |
| 5846 | break; |
| 5847 | |
| 5848 | case DW_AT_abstract_origin: |
| 5849 | abstract_origin_die_offset = form_value.Reference(dwarf_cu); |
| 5850 | break; |
| 5851 | |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 5852 | case DW_AT_object_pointer: |
| 5853 | object_pointer_die_offset = form_value.Reference(dwarf_cu); |
| 5854 | break; |
| 5855 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5856 | case DW_AT_allocated: |
| 5857 | case DW_AT_associated: |
| 5858 | case DW_AT_address_class: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5859 | case DW_AT_calling_convention: |
| 5860 | case DW_AT_data_location: |
| 5861 | case DW_AT_elemental: |
| 5862 | case DW_AT_entry_pc: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5863 | case DW_AT_frame_base: |
| 5864 | case DW_AT_high_pc: |
| 5865 | case DW_AT_low_pc: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5866 | case DW_AT_prototyped: |
| 5867 | case DW_AT_pure: |
| 5868 | case DW_AT_ranges: |
| 5869 | case DW_AT_recursive: |
| 5870 | case DW_AT_return_addr: |
| 5871 | case DW_AT_segment: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5872 | case DW_AT_start_scope: |
| 5873 | case DW_AT_static_link: |
| 5874 | case DW_AT_trampoline: |
| 5875 | case DW_AT_visibility: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5876 | case DW_AT_vtable_elem_location: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5877 | case DW_AT_description: |
| 5878 | case DW_AT_sibling: |
| 5879 | break; |
| 5880 | } |
| 5881 | } |
| 5882 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5883 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5884 | |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 5885 | std::string object_pointer_name; |
| 5886 | if (object_pointer_die_offset != DW_INVALID_OFFSET) |
| 5887 | { |
| 5888 | // Get the name from the object pointer die |
| 5889 | StreamString s; |
| 5890 | if (DWARFDebugInfoEntry::GetName (this, dwarf_cu, object_pointer_die_offset, s)) |
| 5891 | { |
| 5892 | object_pointer_name.assign(s.GetData()); |
| 5893 | } |
| 5894 | } |
| 5895 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5896 | DEBUG_PRINTF ("0x%8.8llx: %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] | 5897 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5898 | clang_type_t return_clang_type = NULL; |
| 5899 | Type *func_type = NULL; |
| 5900 | |
| 5901 | if (type_die_offset != DW_INVALID_OFFSET) |
| 5902 | func_type = ResolveTypeUID(type_die_offset); |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 5903 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5904 | if (func_type) |
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 5905 | return_clang_type = func_type->GetClangForwardType(); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5906 | else |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5907 | return_clang_type = ast.GetBuiltInType_void(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5908 | |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 5909 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5910 | std::vector<clang_type_t> function_param_types; |
| 5911 | std::vector<clang::ParmVarDecl*> function_param_decls; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5912 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5913 | // Parse the function children for the parameters |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 5914 | |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 5915 | const DWARFDebugInfoEntry *decl_ctx_die = NULL; |
| 5916 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die); |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 5917 | const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind(); |
| 5918 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5919 | const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind); |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 5920 | // Start off static. This will be set to false in ParseChildParameters(...) |
| 5921 | // if we find a "this" paramters as the first parameter |
| 5922 | if (is_cxx_method) |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 5923 | is_static = true; |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 5924 | ClangASTContext::TemplateParameterInfos template_param_infos; |
| 5925 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5926 | if (die->HasChildren()) |
| 5927 | { |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5928 | bool skip_artificial = true; |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 5929 | ParseChildParameters (sc, |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 5930 | containing_decl_ctx, |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 5931 | dwarf_cu, |
| 5932 | die, |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 5933 | skip_artificial, |
| 5934 | is_static, |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 5935 | type_list, |
| 5936 | function_param_types, |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 5937 | function_param_decls, |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 5938 | type_quals, |
| 5939 | template_param_infos); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5940 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5941 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5942 | // clang_type will get the function prototype clang type after this call |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5943 | clang_type = ast.CreateFunctionType (return_clang_type, |
| Greg Clayton | 9cb25c4 | 2012-10-30 17:02:18 +0000 | [diff] [blame] | 5944 | function_param_types.data(), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5945 | function_param_types.size(), |
| 5946 | is_variadic, |
| 5947 | type_quals); |
| 5948 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5949 | if (type_name_cstr) |
| 5950 | { |
| 5951 | bool type_handled = false; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5952 | if (tag == DW_TAG_subprogram) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5953 | { |
| Greg Clayton | 7c81042 | 2012-01-18 23:40:49 +0000 | [diff] [blame] | 5954 | ConstString class_name; |
| Greg Clayton | e42ae84 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 5955 | ConstString class_name_no_category; |
| 5956 | if (ObjCLanguageRuntime::ParseMethodName (type_name_cstr, &class_name, NULL, NULL, &class_name_no_category)) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5957 | { |
| Greg Clayton | e42ae84 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 5958 | // Use the class name with no category if there is one |
| 5959 | if (class_name_no_category) |
| 5960 | class_name = class_name_no_category; |
| 5961 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5962 | SymbolContext empty_sc; |
| 5963 | clang_type_t class_opaque_type = NULL; |
| Greg Clayton | 7c81042 | 2012-01-18 23:40:49 +0000 | [diff] [blame] | 5964 | if (class_name) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5965 | { |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5966 | TypeList types; |
| Greg Clayton | 278a16b | 2012-01-19 00:52:59 +0000 | [diff] [blame] | 5967 | TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false)); |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5968 | |
| 5969 | if (complete_objc_class_type_sp) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5970 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5971 | clang_type_t type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType(); |
| 5972 | if (ClangASTContext::IsObjCClassType (type_clang_forward_type)) |
| 5973 | class_opaque_type = type_clang_forward_type; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5974 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5975 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5976 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5977 | if (class_opaque_type) |
| 5978 | { |
| 5979 | // If accessibility isn't set to anything valid, assume public for |
| 5980 | // now... |
| 5981 | if (accessibility == eAccessNone) |
| 5982 | accessibility = eAccessPublic; |
| 5983 | |
| Sean Callanan | 464a5b5 | 2012-10-04 22:06:29 +0000 | [diff] [blame] | 5984 | clang::ObjCMethodDecl *objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type, |
| 5985 | type_name_cstr, |
| 5986 | clang_type, |
| 5987 | accessibility); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5988 | type_handled = objc_method_decl != NULL; |
| Sean Callanan | 464a5b5 | 2012-10-04 22:06:29 +0000 | [diff] [blame] | 5989 | if (type_handled) |
| 5990 | { |
| 5991 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die); |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 5992 | GetClangASTContext().SetMetadataAsUserID ((uintptr_t)objc_method_decl, MakeUserID(die->GetOffset())); |
| Sean Callanan | 464a5b5 | 2012-10-04 22:06:29 +0000 | [diff] [blame] | 5993 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5994 | } |
| 5995 | } |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 5996 | else if (is_cxx_method) |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5997 | { |
| 5998 | // Look at the parent of this DIE and see if is is |
| 5999 | // a class or struct and see if this is actually a |
| 6000 | // C++ method |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 6001 | Type *class_type = ResolveType (dwarf_cu, decl_ctx_die); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6002 | if (class_type) |
| 6003 | { |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6004 | if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset())) |
| 6005 | { |
| 6006 | // We uniqued the parent class of this function to another class |
| 6007 | // so we now need to associate all dies under "decl_ctx_die" to |
| 6008 | // DIEs in the DIE for "class_type"... |
| 6009 | DWARFCompileUnitSP class_type_cu_sp; |
| 6010 | const DWARFDebugInfoEntry *class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp); |
| 6011 | if (class_type_die) |
| 6012 | { |
| 6013 | if (CopyUniqueClassMethodTypes (class_type, |
| 6014 | class_type_cu_sp.get(), |
| 6015 | class_type_die, |
| 6016 | dwarf_cu, |
| 6017 | decl_ctx_die)) |
| 6018 | { |
| 6019 | type_ptr = m_die_to_type[die]; |
| Greg Clayton | e5476db | 2012-06-01 20:32:35 +0000 | [diff] [blame] | 6020 | if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 6021 | { |
| 6022 | type_sp = type_ptr->shared_from_this(); |
| 6023 | break; |
| 6024 | } |
| 6025 | } |
| 6026 | } |
| 6027 | } |
| 6028 | |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6029 | if (specification_die_offset != DW_INVALID_OFFSET) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6030 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6031 | // We have a specification which we are going to base our function |
| 6032 | // prototype off of, so we need this type to be completed so that the |
| 6033 | // m_die_to_decl_ctx for the method in the specification has a valid |
| 6034 | // clang decl context. |
| Greg Clayton | 8eb732e | 2011-12-13 04:34:06 +0000 | [diff] [blame] | 6035 | class_type->GetClangForwardType(); |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6036 | // If we have a specification, then the function type should have been |
| 6037 | // made with the specification and not with this die. |
| 6038 | DWARFCompileUnitSP spec_cu_sp; |
| 6039 | const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp); |
| Eric Christopher | 6cc6e60 | 2012-03-25 19:37:33 +0000 | [diff] [blame] | 6040 | clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die); |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6041 | if (spec_clang_decl_ctx) |
| 6042 | { |
| 6043 | LinkDeclContextToDIE(spec_clang_decl_ctx, die); |
| 6044 | } |
| 6045 | else |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6046 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6047 | GetObjectFile()->GetModule()->ReportWarning ("0x%8.8llx: DW_AT_specification(0x%8.8x) has no decl\n", |
| 6048 | MakeUserID(die->GetOffset()), |
| 6049 | specification_die_offset); |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6050 | } |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6051 | type_handled = true; |
| 6052 | } |
| 6053 | else if (abstract_origin_die_offset != DW_INVALID_OFFSET) |
| 6054 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6055 | // We have a specification which we are going to base our function |
| 6056 | // prototype off of, so we need this type to be completed so that the |
| 6057 | // m_die_to_decl_ctx for the method in the abstract origin has a valid |
| 6058 | // clang decl context. |
| Greg Clayton | 8eb732e | 2011-12-13 04:34:06 +0000 | [diff] [blame] | 6059 | class_type->GetClangForwardType(); |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6060 | |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6061 | DWARFCompileUnitSP abs_cu_sp; |
| 6062 | 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] | 6063 | clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die); |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6064 | if (abs_clang_decl_ctx) |
| 6065 | { |
| 6066 | LinkDeclContextToDIE (abs_clang_decl_ctx, die); |
| 6067 | } |
| 6068 | else |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6069 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6070 | GetObjectFile()->GetModule()->ReportWarning ("0x%8.8llx: DW_AT_abstract_origin(0x%8.8x) has no decl\n", |
| 6071 | MakeUserID(die->GetOffset()), |
| 6072 | abstract_origin_die_offset); |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6073 | } |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6074 | type_handled = true; |
| 6075 | } |
| 6076 | else |
| 6077 | { |
| 6078 | clang_type_t class_opaque_type = class_type->GetClangForwardType(); |
| 6079 | if (ClangASTContext::IsCXXClassType (class_opaque_type)) |
| Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 6080 | { |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6081 | if (ClangASTContext::IsBeingDefined (class_opaque_type)) |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6082 | { |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6083 | // Neither GCC 4.2 nor clang++ currently set a valid accessibility |
| 6084 | // in the DWARF for C++ methods... Default to public for now... |
| 6085 | if (accessibility == eAccessNone) |
| 6086 | accessibility = eAccessPublic; |
| 6087 | |
| 6088 | if (!is_static && !die->HasChildren()) |
| 6089 | { |
| 6090 | // We have a C++ member function with no children (this pointer!) |
| 6091 | // and clang will get mad if we try and make a function that isn't |
| 6092 | // well formed in the DWARF, so we will just skip it... |
| 6093 | type_handled = true; |
| 6094 | } |
| 6095 | else |
| 6096 | { |
| 6097 | clang::CXXMethodDecl *cxx_method_decl; |
| 6098 | // REMOVE THE CRASH DESCRIPTION BELOW |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6099 | Host::SetCrashDescriptionWithFormat ("SymbolFileDWARF::ParseType() is adding a method %s to class %s in DIE 0x%8.8llx from %s/%s", |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6100 | type_name_cstr, |
| 6101 | class_type->GetName().GetCString(), |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6102 | MakeUserID(die->GetOffset()), |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6103 | m_obj_file->GetFileSpec().GetDirectory().GetCString(), |
| 6104 | m_obj_file->GetFileSpec().GetFilename().GetCString()); |
| 6105 | |
| Sean Callanan | c1b732d | 2011-11-01 18:07:13 +0000 | [diff] [blame] | 6106 | const bool is_attr_used = false; |
| 6107 | |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6108 | cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type, |
| 6109 | type_name_cstr, |
| 6110 | clang_type, |
| 6111 | accessibility, |
| 6112 | is_virtual, |
| 6113 | is_static, |
| 6114 | is_inline, |
| Sean Callanan | c1b732d | 2011-11-01 18:07:13 +0000 | [diff] [blame] | 6115 | is_explicit, |
| Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 6116 | is_attr_used, |
| 6117 | is_artificial); |
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame^] | 6118 | |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6119 | type_handled = cxx_method_decl != NULL; |
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame^] | 6120 | |
| 6121 | if (type_handled) |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6122 | { |
| Sean Callanan | 4ac7ec7 | 2012-10-31 02:01:58 +0000 | [diff] [blame^] | 6123 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die); |
| 6124 | |
| 6125 | Host::SetCrashDescription (NULL); |
| 6126 | |
| 6127 | |
| 6128 | ClangASTMetadata metadata; |
| 6129 | metadata.SetUserID(MakeUserID(die->GetOffset())); |
| 6130 | |
| 6131 | if (!object_pointer_name.empty()) |
| 6132 | { |
| 6133 | metadata.SetObjectPtrName(object_pointer_name.c_str()); |
| 6134 | if (log) |
| 6135 | log->Printf ("Setting object pointer name: %s on method object 0x%ld.\n", |
| 6136 | object_pointer_name.c_str(), |
| 6137 | (uintptr_t) cxx_method_decl); |
| 6138 | } |
| 6139 | GetClangASTContext().SetMetadata ((uintptr_t)cxx_method_decl, metadata); |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6140 | } |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6141 | } |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6142 | } |
| 6143 | else |
| 6144 | { |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6145 | // We were asked to parse the type for a method in a class, yet the |
| 6146 | // class hasn't been asked to complete itself through the |
| 6147 | // clang::ExternalASTSource protocol, so we need to just have the |
| 6148 | // class complete itself and do things the right way, then our |
| 6149 | // DIE should then have an entry in the m_die_to_type map. First |
| 6150 | // we need to modify the m_die_to_type so it doesn't think we are |
| 6151 | // trying to parse this DIE anymore... |
| 6152 | m_die_to_type[die] = NULL; |
| 6153 | |
| 6154 | // Now we get the full type to force our class type to complete itself |
| 6155 | // using the clang::ExternalASTSource protocol which will parse all |
| 6156 | // base classes and all methods (including the method for this DIE). |
| 6157 | class_type->GetClangFullType(); |
| Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 6158 | |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6159 | // The type for this DIE should have been filled in the function call above |
| 6160 | type_ptr = m_die_to_type[die]; |
| Greg Clayton | e5476db | 2012-06-01 20:32:35 +0000 | [diff] [blame] | 6161 | if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6162 | { |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 6163 | type_sp = type_ptr->shared_from_this(); |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6164 | break; |
| 6165 | } |
| Sean Callanan | 02eee4d | 2012-04-12 23:10:00 +0000 | [diff] [blame] | 6166 | |
| 6167 | // FIXME This is fixing some even uglier behavior but we really need to |
| 6168 | // uniq the methods of each class as well as the class itself. |
| 6169 | // <rdar://problem/11240464> |
| 6170 | type_handled = true; |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6171 | } |
| Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 6172 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6173 | } |
| 6174 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6175 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6176 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6177 | |
| 6178 | if (!type_handled) |
| 6179 | { |
| 6180 | // We just have a function that isn't part of a class |
| Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 6181 | clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (containing_decl_ctx, |
| 6182 | type_name_cstr, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6183 | clang_type, |
| 6184 | storage, |
| 6185 | is_inline); |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 6186 | |
| 6187 | // if (template_param_infos.GetSize() > 0) |
| 6188 | // { |
| 6189 | // clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx, |
| 6190 | // function_decl, |
| 6191 | // type_name_cstr, |
| 6192 | // template_param_infos); |
| 6193 | // |
| 6194 | // ast.CreateFunctionTemplateSpecializationInfo (function_decl, |
| 6195 | // func_template_decl, |
| 6196 | // template_param_infos); |
| 6197 | // } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6198 | // Add the decl to our DIE to decl context map |
| 6199 | assert (function_decl); |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6200 | LinkDeclContextToDIE(function_decl, die); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6201 | if (!function_param_decls.empty()) |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6202 | ast.SetFunctionParameters (function_decl, |
| 6203 | &function_param_decls.front(), |
| 6204 | function_param_decls.size()); |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 6205 | |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6206 | ClangASTMetadata metadata; |
| 6207 | metadata.SetUserID(MakeUserID(die->GetOffset())); |
| 6208 | |
| 6209 | if (!object_pointer_name.empty()) |
| 6210 | { |
| 6211 | metadata.SetObjectPtrName(object_pointer_name.c_str()); |
| Jim Ingham | 2cffda3f | 2012-10-30 23:34:07 +0000 | [diff] [blame] | 6212 | if (log) |
| 6213 | log->Printf ("Setting object pointer name: %s on function object 0x%ld.\n", |
| 6214 | object_pointer_name.c_str(), |
| 6215 | (uintptr_t) function_decl); |
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6216 | } |
| 6217 | GetClangASTContext().SetMetadata ((uintptr_t)function_decl, metadata); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6218 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6219 | } |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6220 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6221 | this, |
| 6222 | type_name_const_str, |
| 6223 | 0, |
| 6224 | NULL, |
| 6225 | LLDB_INVALID_UID, |
| 6226 | Type::eEncodingIsUID, |
| 6227 | &decl, |
| 6228 | clang_type, |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6229 | Type::eResolveStateFull)); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6230 | assert(type_sp.get()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6231 | } |
| 6232 | break; |
| 6233 | |
| 6234 | case DW_TAG_array_type: |
| 6235 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6236 | // 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] | 6237 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6238 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6239 | lldb::user_id_t type_die_offset = DW_INVALID_OFFSET; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6240 | int64_t first_index = 0; |
| 6241 | uint32_t byte_stride = 0; |
| 6242 | uint32_t bit_stride = 0; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6243 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6244 | |
| 6245 | if (num_attributes > 0) |
| 6246 | { |
| 6247 | uint32_t i; |
| 6248 | for (i=0; i<num_attributes; ++i) |
| 6249 | { |
| 6250 | attr = attributes.AttributeAtIndex(i); |
| 6251 | DWARFFormValue form_value; |
| 6252 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 6253 | { |
| 6254 | switch (attr) |
| 6255 | { |
| 6256 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 6257 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 6258 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 6259 | case DW_AT_name: |
| 6260 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6261 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6262 | break; |
| 6263 | |
| 6264 | 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] | 6265 | case DW_AT_byte_size: break; // byte_size = form_value.Unsigned(); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6266 | case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break; |
| 6267 | case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6268 | case DW_AT_accessibility: break; // accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
| 6269 | case DW_AT_declaration: break; // is_forward_declaration = form_value.Unsigned() != 0; break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6270 | case DW_AT_allocated: |
| 6271 | case DW_AT_associated: |
| 6272 | case DW_AT_data_location: |
| 6273 | case DW_AT_description: |
| 6274 | case DW_AT_ordering: |
| 6275 | case DW_AT_start_scope: |
| 6276 | case DW_AT_visibility: |
| 6277 | case DW_AT_specification: |
| 6278 | case DW_AT_abstract_origin: |
| 6279 | case DW_AT_sibling: |
| 6280 | break; |
| 6281 | } |
| 6282 | } |
| 6283 | } |
| 6284 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6285 | DEBUG_PRINTF ("0x%8.8llx: %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] | 6286 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6287 | Type *element_type = ResolveTypeUID(type_die_offset); |
| 6288 | |
| 6289 | if (element_type) |
| 6290 | { |
| 6291 | std::vector<uint64_t> element_orders; |
| 6292 | ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride); |
| 6293 | if (byte_stride == 0 && bit_stride == 0) |
| 6294 | byte_stride = element_type->GetByteSize(); |
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 6295 | clang_type_t array_element_type = element_type->GetClangForwardType(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6296 | uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride; |
| 6297 | uint64_t num_elements = 0; |
| 6298 | std::vector<uint64_t>::const_reverse_iterator pos; |
| 6299 | std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend(); |
| 6300 | for (pos = element_orders.rbegin(); pos != end; ++pos) |
| 6301 | { |
| 6302 | num_elements = *pos; |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6303 | clang_type = ast.CreateArrayType (array_element_type, |
| 6304 | num_elements, |
| 6305 | num_elements * array_element_bit_stride); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6306 | array_element_type = clang_type; |
| 6307 | array_element_bit_stride = array_element_bit_stride * num_elements; |
| 6308 | } |
| 6309 | ConstString empty_name; |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6310 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6311 | this, |
| 6312 | empty_name, |
| 6313 | array_element_bit_stride / 8, |
| 6314 | NULL, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6315 | type_die_offset, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6316 | Type::eEncodingIsUID, |
| 6317 | &decl, |
| 6318 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6319 | Type::eResolveStateFull)); |
| 6320 | type_sp->SetEncodingType (element_type); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6321 | } |
| 6322 | } |
| 6323 | } |
| 6324 | break; |
| 6325 | |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6326 | case DW_TAG_ptr_to_member_type: |
| 6327 | { |
| 6328 | dw_offset_t type_die_offset = DW_INVALID_OFFSET; |
| 6329 | dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET; |
| 6330 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6331 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6332 | |
| 6333 | if (num_attributes > 0) { |
| 6334 | uint32_t i; |
| 6335 | for (i=0; i<num_attributes; ++i) |
| 6336 | { |
| 6337 | attr = attributes.AttributeAtIndex(i); |
| 6338 | DWARFFormValue form_value; |
| 6339 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 6340 | { |
| 6341 | switch (attr) |
| 6342 | { |
| 6343 | case DW_AT_type: |
| 6344 | type_die_offset = form_value.Reference(dwarf_cu); break; |
| 6345 | case DW_AT_containing_type: |
| 6346 | containing_type_die_offset = form_value.Reference(dwarf_cu); break; |
| 6347 | } |
| 6348 | } |
| 6349 | } |
| 6350 | |
| 6351 | Type *pointee_type = ResolveTypeUID(type_die_offset); |
| 6352 | Type *class_type = ResolveTypeUID(containing_type_die_offset); |
| 6353 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6354 | clang_type_t pointee_clang_type = pointee_type->GetClangForwardType(); |
| 6355 | clang_type_t class_clang_type = class_type->GetClangLayoutType(); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6356 | |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6357 | clang_type = ast.CreateMemberPointerType(pointee_clang_type, |
| 6358 | class_clang_type); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6359 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6360 | byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(), |
| 6361 | clang_type) / 8; |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6362 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6363 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6364 | this, |
| 6365 | type_name_const_str, |
| 6366 | byte_size, |
| 6367 | NULL, |
| 6368 | LLDB_INVALID_UID, |
| 6369 | Type::eEncodingIsUID, |
| 6370 | NULL, |
| 6371 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6372 | Type::eResolveStateForward)); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6373 | } |
| 6374 | |
| 6375 | break; |
| 6376 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6377 | default: |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6378 | assert(false && "Unhandled type tag!"); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6379 | break; |
| 6380 | } |
| 6381 | |
| 6382 | if (type_sp.get()) |
| 6383 | { |
| 6384 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); |
| 6385 | dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
| 6386 | |
| 6387 | SymbolContextScope * symbol_context_scope = NULL; |
| 6388 | if (sc_parent_tag == DW_TAG_compile_unit) |
| 6389 | { |
| 6390 | symbol_context_scope = sc.comp_unit; |
| 6391 | } |
| 6392 | else if (sc.function != NULL) |
| 6393 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6394 | 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] | 6395 | if (symbol_context_scope == NULL) |
| 6396 | symbol_context_scope = sc.function; |
| 6397 | } |
| 6398 | |
| 6399 | if (symbol_context_scope != NULL) |
| 6400 | { |
| 6401 | type_sp->SetSymbolContextScope(symbol_context_scope); |
| 6402 | } |
| 6403 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6404 | // We are ready to put this type into the uniqued list up at the module level |
| 6405 | type_list->Insert (type_sp); |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 6406 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6407 | m_die_to_type[die] = type_sp.get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6408 | } |
| 6409 | } |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 6410 | else if (type_ptr != DIE_IS_BEING_PARSED) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6411 | { |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 6412 | type_sp = type_ptr->shared_from_this(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6413 | } |
| 6414 | } |
| 6415 | return type_sp; |
| 6416 | } |
| 6417 | |
| 6418 | size_t |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6419 | SymbolFileDWARF::ParseTypes |
| 6420 | ( |
| 6421 | const SymbolContext& sc, |
| 6422 | DWARFCompileUnit* dwarf_cu, |
| 6423 | const DWARFDebugInfoEntry *die, |
| 6424 | bool parse_siblings, |
| 6425 | bool parse_children |
| 6426 | ) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6427 | { |
| 6428 | size_t types_added = 0; |
| 6429 | while (die != NULL) |
| 6430 | { |
| 6431 | bool type_is_new = false; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6432 | if (ParseType(sc, dwarf_cu, die, &type_is_new).get()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6433 | { |
| 6434 | if (type_is_new) |
| 6435 | ++types_added; |
| 6436 | } |
| 6437 | |
| 6438 | if (parse_children && die->HasChildren()) |
| 6439 | { |
| 6440 | if (die->Tag() == DW_TAG_subprogram) |
| 6441 | { |
| 6442 | SymbolContext child_sc(sc); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6443 | child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6444 | types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true); |
| 6445 | } |
| 6446 | else |
| 6447 | types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true); |
| 6448 | } |
| 6449 | |
| 6450 | if (parse_siblings) |
| 6451 | die = die->GetSibling(); |
| 6452 | else |
| 6453 | die = NULL; |
| 6454 | } |
| 6455 | return types_added; |
| 6456 | } |
| 6457 | |
| 6458 | |
| 6459 | size_t |
| 6460 | SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc) |
| 6461 | { |
| 6462 | assert(sc.comp_unit && sc.function); |
| 6463 | size_t functions_added = 0; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 6464 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6465 | if (dwarf_cu) |
| 6466 | { |
| 6467 | dw_offset_t function_die_offset = sc.function->GetID(); |
| 6468 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset); |
| 6469 | if (function_die) |
| 6470 | { |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 6471 | 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] | 6472 | } |
| 6473 | } |
| 6474 | |
| 6475 | return functions_added; |
| 6476 | } |
| 6477 | |
| 6478 | |
| 6479 | size_t |
| 6480 | SymbolFileDWARF::ParseTypes (const SymbolContext &sc) |
| 6481 | { |
| 6482 | // At least a compile unit must be valid |
| 6483 | assert(sc.comp_unit); |
| 6484 | size_t types_added = 0; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 6485 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6486 | if (dwarf_cu) |
| 6487 | { |
| 6488 | if (sc.function) |
| 6489 | { |
| 6490 | dw_offset_t function_die_offset = sc.function->GetID(); |
| 6491 | const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset); |
| 6492 | if (func_die && func_die->HasChildren()) |
| 6493 | { |
| 6494 | types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true); |
| 6495 | } |
| 6496 | } |
| 6497 | else |
| 6498 | { |
| 6499 | const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE(); |
| 6500 | if (dwarf_cu_die && dwarf_cu_die->HasChildren()) |
| 6501 | { |
| 6502 | types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true); |
| 6503 | } |
| 6504 | } |
| 6505 | } |
| 6506 | |
| 6507 | return types_added; |
| 6508 | } |
| 6509 | |
| 6510 | size_t |
| 6511 | SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc) |
| 6512 | { |
| 6513 | if (sc.comp_unit != NULL) |
| 6514 | { |
| Greg Clayton | 4b3dc10 | 2010-11-01 20:32:12 +0000 | [diff] [blame] | 6515 | DWARFDebugInfo* info = DebugInfo(); |
| 6516 | if (info == NULL) |
| 6517 | return 0; |
| 6518 | |
| 6519 | uint32_t cu_idx = UINT32_MAX; |
| 6520 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID(), &cu_idx).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6521 | |
| 6522 | if (dwarf_cu == NULL) |
| 6523 | return 0; |
| 6524 | |
| 6525 | if (sc.function) |
| 6526 | { |
| 6527 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID()); |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 6528 | |
| 6529 | dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, DW_INVALID_ADDRESS); |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6530 | if (func_lo_pc != DW_INVALID_ADDRESS) |
| 6531 | { |
| 6532 | 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] | 6533 | |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6534 | // Let all blocks know they have parse all their variables |
| 6535 | sc.function->GetBlock (false).SetDidParseVariables (true, true); |
| 6536 | return num_variables; |
| 6537 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6538 | } |
| 6539 | else if (sc.comp_unit) |
| 6540 | { |
| 6541 | uint32_t vars_added = 0; |
| 6542 | VariableListSP variables (sc.comp_unit->GetVariableList(false)); |
| 6543 | |
| 6544 | if (variables.get() == NULL) |
| 6545 | { |
| 6546 | variables.reset(new VariableList()); |
| 6547 | sc.comp_unit->SetVariableList(variables); |
| 6548 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 6549 | DWARFCompileUnit* match_dwarf_cu = NULL; |
| 6550 | const DWARFDebugInfoEntry* die = NULL; |
| 6551 | DIEArray die_offsets; |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 6552 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6553 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 6554 | if (m_apple_names_ap.get()) |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6555 | { |
| 6556 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 6557 | if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(), |
| 6558 | dwarf_cu->GetNextCompileUnitOffset(), |
| 6559 | hash_data_array)) |
| 6560 | { |
| 6561 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| 6562 | } |
| 6563 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6564 | } |
| 6565 | else |
| 6566 | { |
| 6567 | // Index if we already haven't to make sure the compile units |
| 6568 | // get indexed and make their global DIE index list |
| 6569 | if (!m_indexed) |
| 6570 | Index (); |
| 6571 | |
| 6572 | m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(), |
| 6573 | dwarf_cu->GetNextCompileUnitOffset(), |
| 6574 | die_offsets); |
| 6575 | } |
| 6576 | |
| 6577 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 6578 | if (num_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6579 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 6580 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 6581 | for (size_t i=0; i<num_matches; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6582 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 6583 | const dw_offset_t die_offset = die_offsets[i]; |
| 6584 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 6585 | if (die) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 6586 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 6587 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS)); |
| 6588 | if (var_sp) |
| 6589 | { |
| 6590 | variables->AddVariableIfUnique (var_sp); |
| 6591 | ++vars_added; |
| 6592 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 6593 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 6594 | else |
| 6595 | { |
| 6596 | if (m_using_apple_tables) |
| 6597 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6598 | 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] | 6599 | } |
| 6600 | } |
| 6601 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6602 | } |
| 6603 | } |
| 6604 | } |
| 6605 | return vars_added; |
| 6606 | } |
| 6607 | } |
| 6608 | return 0; |
| 6609 | } |
| 6610 | |
| 6611 | |
| 6612 | VariableSP |
| 6613 | SymbolFileDWARF::ParseVariableDIE |
| 6614 | ( |
| 6615 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6616 | DWARFCompileUnit* dwarf_cu, |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 6617 | const DWARFDebugInfoEntry *die, |
| 6618 | const lldb::addr_t func_low_pc |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6619 | ) |
| 6620 | { |
| 6621 | |
| Greg Clayton | 83c5cd9 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 6622 | VariableSP var_sp (m_die_to_variable_sp[die]); |
| 6623 | if (var_sp) |
| 6624 | return var_sp; // Already been parsed! |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6625 | |
| 6626 | const dw_tag_t tag = die->Tag(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6627 | |
| 6628 | if ((tag == DW_TAG_variable) || |
| 6629 | (tag == DW_TAG_constant) || |
| 6630 | (tag == DW_TAG_formal_parameter && sc.function)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6631 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6632 | DWARFDebugInfoEntry::Attributes attributes; |
| 6633 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| 6634 | if (num_attributes > 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6635 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6636 | const char *name = NULL; |
| 6637 | const char *mangled = NULL; |
| 6638 | Declaration decl; |
| 6639 | uint32_t i; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6640 | lldb::user_id_t type_uid = LLDB_INVALID_UID; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6641 | DWARFExpression location; |
| 6642 | bool is_external = false; |
| 6643 | bool is_artificial = false; |
| 6644 | bool location_is_const_value_data = false; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6645 | //AccessType accessibility = eAccessNone; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6646 | |
| 6647 | for (i=0; i<num_attributes; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6648 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6649 | dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 6650 | DWARFFormValue form_value; |
| 6651 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6652 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6653 | switch (attr) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6654 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6655 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 6656 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 6657 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 6658 | case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; |
| 6659 | 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] | 6660 | case DW_AT_type: type_uid = form_value.Reference(dwarf_cu); break; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6661 | case DW_AT_external: is_external = form_value.Unsigned() != 0; break; |
| 6662 | case DW_AT_const_value: |
| 6663 | location_is_const_value_data = true; |
| 6664 | // Fall through... |
| 6665 | case DW_AT_location: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6666 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6667 | if (form_value.BlockData()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6668 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6669 | const DataExtractor& debug_info_data = get_debug_info_data(); |
| 6670 | |
| 6671 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 6672 | uint32_t block_length = form_value.Unsigned(); |
| Greg Clayton | 7f4c743 | 2012-08-11 00:49:14 +0000 | [diff] [blame] | 6673 | location.CopyOpcodeData(get_debug_info_data(), block_offset, block_length); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6674 | } |
| 6675 | else |
| 6676 | { |
| 6677 | const DataExtractor& debug_loc_data = get_debug_loc_data(); |
| 6678 | const dw_offset_t debug_loc_offset = form_value.Unsigned(); |
| 6679 | |
| 6680 | size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset); |
| 6681 | if (loc_list_length > 0) |
| 6682 | { |
| Greg Clayton | 7f4c743 | 2012-08-11 00:49:14 +0000 | [diff] [blame] | 6683 | location.CopyOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6684 | assert (func_low_pc != LLDB_INVALID_ADDRESS); |
| 6685 | location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress()); |
| 6686 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6687 | } |
| 6688 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6689 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6690 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6691 | case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6692 | 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] | 6693 | case DW_AT_declaration: |
| 6694 | case DW_AT_description: |
| 6695 | case DW_AT_endianity: |
| 6696 | case DW_AT_segment: |
| 6697 | case DW_AT_start_scope: |
| 6698 | case DW_AT_visibility: |
| 6699 | default: |
| 6700 | case DW_AT_abstract_origin: |
| 6701 | case DW_AT_sibling: |
| 6702 | case DW_AT_specification: |
| 6703 | break; |
| 6704 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6705 | } |
| 6706 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6707 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6708 | if (location.IsValid()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6709 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6710 | ValueType scope = eValueTypeInvalid; |
| 6711 | |
| 6712 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); |
| 6713 | dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6714 | SymbolContextScope * symbol_context_scope = NULL; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6715 | |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6716 | // DWARF doesn't specify if a DW_TAG_variable is a local, global |
| 6717 | // or static variable, so we have to do a little digging by |
| 6718 | // looking at the location of a varaible to see if it contains |
| 6719 | // a DW_OP_addr opcode _somewhere_ in the definition. I say |
| 6720 | // somewhere because clang likes to combine small global variables |
| 6721 | // into the same symbol and have locations like: |
| 6722 | // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus |
| 6723 | // So if we don't have a DW_TAG_formal_parameter, we can look at |
| 6724 | // the location to see if it contains a DW_OP_addr opcode, and |
| 6725 | // then we can correctly classify our variables. |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6726 | if (tag == DW_TAG_formal_parameter) |
| 6727 | scope = eValueTypeVariableArgument; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6728 | else |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6729 | { |
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 6730 | bool op_error = false; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6731 | // Check if the location has a DW_OP_addr with any address value... |
| 6732 | addr_t location_has_op_addr = false; |
| 6733 | if (!location_is_const_value_data) |
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 6734 | { |
| 6735 | location_has_op_addr = location.LocationContains_DW_OP_addr (LLDB_INVALID_ADDRESS, op_error); |
| 6736 | if (op_error) |
| 6737 | { |
| 6738 | StreamString strm; |
| 6739 | location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL); |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6740 | 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] | 6741 | } |
| 6742 | } |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6743 | |
| 6744 | if (location_has_op_addr) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6745 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6746 | if (is_external) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6747 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6748 | scope = eValueTypeVariableGlobal; |
| 6749 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 6750 | if (GetDebugMapSymfile ()) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6751 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6752 | // When leaving the DWARF in the .o files on darwin, |
| 6753 | // when we have a global variable that wasn't initialized, |
| 6754 | // the .o file might not have allocated a virtual |
| 6755 | // address for the global variable. In this case it will |
| 6756 | // have created a symbol for the global variable |
| 6757 | // that is undefined and external and the value will |
| 6758 | // be the byte size of the variable. When we do the |
| 6759 | // address map in SymbolFileDWARFDebugMap we rely on |
| 6760 | // having an address, we need to do some magic here |
| 6761 | // so we can get the correct address for our global |
| 6762 | // variable. The address for all of these entries |
| 6763 | // will be zero, and there will be an undefined symbol |
| 6764 | // in this object file, and the executable will have |
| 6765 | // a matching symbol with a good address. So here we |
| 6766 | // dig up the correct address and replace it in the |
| 6767 | // location for the variable, and set the variable's |
| 6768 | // symbol context scope to be that of the main executable |
| 6769 | // so the file address will resolve correctly. |
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 6770 | if (location.LocationContains_DW_OP_addr (0, op_error)) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6771 | { |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6772 | |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6773 | // we have a possible uninitialized extern global |
| 6774 | Symtab *symtab = m_obj_file->GetSymtab(); |
| 6775 | if (symtab) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6776 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6777 | ConstString const_name(name); |
| 6778 | Symbol *undefined_symbol = symtab->FindFirstSymbolWithNameAndType (const_name, |
| 6779 | eSymbolTypeUndefined, |
| 6780 | Symtab::eDebugNo, |
| 6781 | Symtab::eVisibilityExtern); |
| 6782 | |
| 6783 | if (undefined_symbol) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6784 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6785 | ObjectFile *debug_map_objfile = m_debug_map_symfile->GetObjectFile(); |
| 6786 | if (debug_map_objfile) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6787 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6788 | Symtab *debug_map_symtab = debug_map_objfile->GetSymtab(); |
| 6789 | Symbol *defined_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name, |
| 6790 | eSymbolTypeData, |
| 6791 | Symtab::eDebugYes, |
| 6792 | Symtab::eVisibilityExtern); |
| 6793 | if (defined_symbol) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6794 | { |
| Greg Clayton | e761213 | 2012-03-07 21:03:09 +0000 | [diff] [blame] | 6795 | if (defined_symbol->ValueIsAddress()) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6796 | { |
| Greg Clayton | e761213 | 2012-03-07 21:03:09 +0000 | [diff] [blame] | 6797 | const addr_t defined_addr = defined_symbol->GetAddress().GetFileAddress(); |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6798 | if (defined_addr != LLDB_INVALID_ADDRESS) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6799 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6800 | if (location.Update_DW_OP_addr (defined_addr)) |
| 6801 | { |
| 6802 | symbol_context_scope = defined_symbol; |
| 6803 | } |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6804 | } |
| 6805 | } |
| 6806 | } |
| 6807 | } |
| 6808 | } |
| 6809 | } |
| 6810 | } |
| 6811 | } |
| 6812 | } |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6813 | else |
| 6814 | { |
| 6815 | scope = eValueTypeVariableStatic; |
| 6816 | } |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6817 | } |
| 6818 | else |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6819 | { |
| 6820 | scope = eValueTypeVariableLocal; |
| 6821 | } |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6822 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6823 | |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6824 | if (symbol_context_scope == NULL) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6825 | { |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6826 | switch (parent_tag) |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6827 | { |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6828 | case DW_TAG_subprogram: |
| 6829 | case DW_TAG_inlined_subroutine: |
| 6830 | case DW_TAG_lexical_block: |
| 6831 | if (sc.function) |
| 6832 | { |
| 6833 | symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); |
| 6834 | if (symbol_context_scope == NULL) |
| 6835 | symbol_context_scope = sc.function; |
| 6836 | } |
| 6837 | break; |
| 6838 | |
| 6839 | default: |
| 6840 | symbol_context_scope = sc.comp_unit; |
| 6841 | break; |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6842 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6843 | } |
| 6844 | |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6845 | if (symbol_context_scope) |
| 6846 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6847 | var_sp.reset (new Variable (MakeUserID(die->GetOffset()), |
| 6848 | name, |
| 6849 | mangled, |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6850 | SymbolFileTypeSP (new SymbolFileType(*this, type_uid)), |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6851 | scope, |
| 6852 | symbol_context_scope, |
| 6853 | &decl, |
| 6854 | location, |
| 6855 | is_external, |
| 6856 | is_artificial)); |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6857 | |
| 6858 | var_sp->SetLocationIsConstantValueData (location_is_const_value_data); |
| 6859 | } |
| 6860 | else |
| 6861 | { |
| 6862 | // Not ready to parse this variable yet. It might be a global |
| 6863 | // or static variable that is in a function scope and the function |
| 6864 | // in the symbol context wasn't filled in yet |
| 6865 | return var_sp; |
| 6866 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6867 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6868 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6869 | // Cache var_sp even if NULL (the variable was just a specification or |
| 6870 | // was missing vital information to be able to be displayed in the debugger |
| 6871 | // (missing location due to optimization, etc)) so we don't re-parse |
| 6872 | // this DIE over and over later... |
| 6873 | m_die_to_variable_sp[die] = var_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6874 | } |
| 6875 | return var_sp; |
| 6876 | } |
| 6877 | |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6878 | |
| 6879 | const DWARFDebugInfoEntry * |
| 6880 | SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset, |
| 6881 | dw_offset_t spec_block_die_offset, |
| 6882 | DWARFCompileUnit **result_die_cu_handle) |
| 6883 | { |
| 6884 | // Give the concrete function die specified by "func_die_offset", find the |
| 6885 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points |
| 6886 | // to "spec_block_die_offset" |
| 6887 | DWARFDebugInfo* info = DebugInfo(); |
| 6888 | |
| 6889 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle); |
| 6890 | if (die) |
| 6891 | { |
| 6892 | assert (*result_die_cu_handle); |
| 6893 | return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle); |
| 6894 | } |
| 6895 | return NULL; |
| 6896 | } |
| 6897 | |
| 6898 | |
| 6899 | const DWARFDebugInfoEntry * |
| 6900 | SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu, |
| 6901 | const DWARFDebugInfoEntry *die, |
| 6902 | dw_offset_t spec_block_die_offset, |
| 6903 | DWARFCompileUnit **result_die_cu_handle) |
| 6904 | { |
| 6905 | if (die) |
| 6906 | { |
| 6907 | switch (die->Tag()) |
| 6908 | { |
| 6909 | case DW_TAG_subprogram: |
| 6910 | case DW_TAG_inlined_subroutine: |
| 6911 | case DW_TAG_lexical_block: |
| 6912 | { |
| 6913 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset) |
| 6914 | { |
| 6915 | *result_die_cu_handle = dwarf_cu; |
| 6916 | return die; |
| 6917 | } |
| 6918 | |
| 6919 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset) |
| 6920 | { |
| 6921 | *result_die_cu_handle = dwarf_cu; |
| 6922 | return die; |
| 6923 | } |
| 6924 | } |
| 6925 | break; |
| 6926 | } |
| 6927 | |
| 6928 | // Give the concrete function die specified by "func_die_offset", find the |
| 6929 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points |
| 6930 | // to "spec_block_die_offset" |
| 6931 | for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling()) |
| 6932 | { |
| 6933 | const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu, |
| 6934 | child_die, |
| 6935 | spec_block_die_offset, |
| 6936 | result_die_cu_handle); |
| 6937 | if (result_die) |
| 6938 | return result_die; |
| 6939 | } |
| 6940 | } |
| 6941 | |
| 6942 | *result_die_cu_handle = NULL; |
| 6943 | return NULL; |
| 6944 | } |
| 6945 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6946 | size_t |
| 6947 | SymbolFileDWARF::ParseVariables |
| 6948 | ( |
| 6949 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6950 | DWARFCompileUnit* dwarf_cu, |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 6951 | const lldb::addr_t func_low_pc, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6952 | const DWARFDebugInfoEntry *orig_die, |
| 6953 | bool parse_siblings, |
| 6954 | bool parse_children, |
| 6955 | VariableList* cc_variable_list |
| 6956 | ) |
| 6957 | { |
| 6958 | if (orig_die == NULL) |
| 6959 | return 0; |
| 6960 | |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6961 | VariableListSP variable_list_sp; |
| 6962 | |
| 6963 | size_t vars_added = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6964 | const DWARFDebugInfoEntry *die = orig_die; |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6965 | while (die != NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6966 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6967 | dw_tag_t tag = die->Tag(); |
| 6968 | |
| 6969 | // Check to see if we have already parsed this variable or constant? |
| 6970 | if (m_die_to_variable_sp[die]) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6971 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6972 | if (cc_variable_list) |
| 6973 | cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6974 | } |
| 6975 | else |
| 6976 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6977 | // We haven't already parsed it, lets do that now. |
| 6978 | if ((tag == DW_TAG_variable) || |
| 6979 | (tag == DW_TAG_constant) || |
| 6980 | (tag == DW_TAG_formal_parameter && sc.function)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6981 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6982 | if (variable_list_sp.get() == NULL) |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 6983 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6984 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die); |
| 6985 | dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
| 6986 | switch (parent_tag) |
| 6987 | { |
| 6988 | case DW_TAG_compile_unit: |
| 6989 | if (sc.comp_unit != NULL) |
| 6990 | { |
| 6991 | variable_list_sp = sc.comp_unit->GetVariableList(false); |
| 6992 | if (variable_list_sp.get() == NULL) |
| 6993 | { |
| 6994 | variable_list_sp.reset(new VariableList()); |
| 6995 | sc.comp_unit->SetVariableList(variable_list_sp); |
| 6996 | } |
| 6997 | } |
| 6998 | else |
| 6999 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 7000 | GetObjectFile()->GetModule()->ReportError ("parent 0x%8.8llx %s with no valid compile unit in symbol context for 0x%8.8llx %s.\n", |
| 7001 | MakeUserID(sc_parent_die->GetOffset()), |
| 7002 | DW_TAG_value_to_name (parent_tag), |
| 7003 | MakeUserID(orig_die->GetOffset()), |
| 7004 | DW_TAG_value_to_name (orig_die->Tag())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7005 | } |
| 7006 | break; |
| 7007 | |
| 7008 | case DW_TAG_subprogram: |
| 7009 | case DW_TAG_inlined_subroutine: |
| 7010 | case DW_TAG_lexical_block: |
| 7011 | if (sc.function != NULL) |
| 7012 | { |
| 7013 | // Check to see if we already have parsed the variables for the given scope |
| 7014 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7015 | Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7016 | if (block == NULL) |
| 7017 | { |
| 7018 | // This must be a specification or abstract origin with |
| 7019 | // a concrete block couterpart in the current function. We need |
| 7020 | // to find the concrete block so we can correctly add the |
| 7021 | // variable to it |
| 7022 | DWARFCompileUnit *concrete_block_die_cu = dwarf_cu; |
| 7023 | const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(), |
| 7024 | sc_parent_die->GetOffset(), |
| 7025 | &concrete_block_die_cu); |
| 7026 | if (concrete_block_die) |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 7027 | block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7028 | } |
| 7029 | |
| 7030 | if (block != NULL) |
| 7031 | { |
| 7032 | const bool can_create = false; |
| 7033 | variable_list_sp = block->GetBlockVariableList (can_create); |
| 7034 | if (variable_list_sp.get() == NULL) |
| 7035 | { |
| 7036 | variable_list_sp.reset(new VariableList()); |
| 7037 | block->SetVariableList(variable_list_sp); |
| 7038 | } |
| 7039 | } |
| 7040 | } |
| 7041 | break; |
| 7042 | |
| 7043 | default: |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 7044 | GetObjectFile()->GetModule()->ReportError ("didn't find appropriate parent DIE for variable list for 0x%8.8llx %s.\n", |
| 7045 | MakeUserID(orig_die->GetOffset()), |
| 7046 | DW_TAG_value_to_name (orig_die->Tag())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7047 | break; |
| 7048 | } |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7049 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7050 | |
| 7051 | if (variable_list_sp) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7052 | { |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7053 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc)); |
| 7054 | if (var_sp) |
| 7055 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7056 | variable_list_sp->AddVariableIfUnique (var_sp); |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 7057 | if (cc_variable_list) |
| 7058 | cc_variable_list->AddVariableIfUnique (var_sp); |
| 7059 | ++vars_added; |
| 7060 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7061 | } |
| 7062 | } |
| 7063 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7064 | |
| 7065 | bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram); |
| 7066 | |
| 7067 | if (!skip_children && parse_children && die->HasChildren()) |
| 7068 | { |
| 7069 | vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list); |
| 7070 | } |
| 7071 | |
| 7072 | if (parse_siblings) |
| 7073 | die = die->GetSibling(); |
| 7074 | else |
| 7075 | die = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7076 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 7077 | return vars_added; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 7078 | } |
| 7079 | |
| 7080 | //------------------------------------------------------------------ |
| 7081 | // PluginInterface protocol |
| 7082 | //------------------------------------------------------------------ |
| 7083 | const char * |
| 7084 | SymbolFileDWARF::GetPluginName() |
| 7085 | { |
| 7086 | return "SymbolFileDWARF"; |
| 7087 | } |
| 7088 | |
| 7089 | const char * |
| 7090 | SymbolFileDWARF::GetShortPluginName() |
| 7091 | { |
| 7092 | return GetPluginNameStatic(); |
| 7093 | } |
| 7094 | |
| 7095 | uint32_t |
| 7096 | SymbolFileDWARF::GetPluginVersion() |
| 7097 | { |
| 7098 | return 1; |
| 7099 | } |
| 7100 | |
| 7101 | void |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 7102 | SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl) |
| 7103 | { |
| 7104 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 7105 | clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); |
| 7106 | if (clang_type) |
| 7107 | symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); |
| 7108 | } |
| 7109 | |
| 7110 | void |
| 7111 | SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl) |
| 7112 | { |
| 7113 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 7114 | clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); |
| 7115 | if (clang_type) |
| 7116 | symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); |
| 7117 | } |
| 7118 | |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7119 | void |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7120 | SymbolFileDWARF::DumpIndexes () |
| 7121 | { |
| 7122 | StreamFile s(stdout, false); |
| 7123 | |
| 7124 | s.Printf ("DWARF index for (%s) '%s/%s':", |
| 7125 | GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(), |
| 7126 | GetObjectFile()->GetFileSpec().GetDirectory().AsCString(), |
| 7127 | GetObjectFile()->GetFileSpec().GetFilename().AsCString()); |
| 7128 | s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s); |
| 7129 | s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s); |
| 7130 | s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s); |
| 7131 | s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s); |
| 7132 | s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s); |
| 7133 | s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s); |
| 7134 | s.Printf("\nTypes:\n"); m_type_index.Dump (&s); |
| 7135 | s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s); |
| 7136 | } |
| 7137 | |
| 7138 | void |
| 7139 | SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context, |
| 7140 | const char *name, |
| 7141 | llvm::SmallVectorImpl <clang::NamedDecl *> *results) |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7142 | { |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7143 | DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context); |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7144 | |
| 7145 | if (iter == m_decl_ctx_to_die.end()) |
| 7146 | return; |
| 7147 | |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7148 | 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] | 7149 | { |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7150 | const DWARFDebugInfoEntry *context_die = *pos; |
| 7151 | |
| 7152 | if (!results) |
| 7153 | return; |
| 7154 | |
| 7155 | DWARFDebugInfo* info = DebugInfo(); |
| 7156 | |
| 7157 | DIEArray die_offsets; |
| 7158 | |
| 7159 | DWARFCompileUnit* dwarf_cu = NULL; |
| 7160 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 7161 | |
| 7162 | if (m_using_apple_tables) |
| 7163 | { |
| 7164 | if (m_apple_types_ap.get()) |
| 7165 | m_apple_types_ap->FindByName (name, die_offsets); |
| 7166 | } |
| 7167 | else |
| 7168 | { |
| 7169 | if (!m_indexed) |
| 7170 | Index (); |
| 7171 | |
| 7172 | m_type_index.Find (ConstString(name), die_offsets); |
| 7173 | } |
| 7174 | |
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 7175 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7176 | |
| 7177 | if (num_matches) |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7178 | { |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7179 | for (size_t i = 0; i < num_matches; ++i) |
| 7180 | { |
| 7181 | const dw_offset_t die_offset = die_offsets[i]; |
| 7182 | die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7183 | |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7184 | if (die->GetParent() != context_die) |
| 7185 | continue; |
| 7186 | |
| 7187 | Type *matching_type = ResolveType (dwarf_cu, die); |
| 7188 | |
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 7189 | lldb::clang_type_t type = matching_type->GetClangForwardType(); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7190 | clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type); |
| 7191 | |
| 7192 | if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr())) |
| 7193 | { |
| 7194 | clang::TagDecl *tag_decl = tag_type->getDecl(); |
| 7195 | results->push_back(tag_decl); |
| 7196 | } |
| 7197 | else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr())) |
| 7198 | { |
| 7199 | clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl(); |
| 7200 | results->push_back(typedef_decl); |
| 7201 | } |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7202 | } |
| 7203 | } |
| 7204 | } |
| 7205 | } |
| 7206 | |
| 7207 | void |
| 7208 | SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton, |
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 7209 | const clang::DeclContext *decl_context, |
| 7210 | clang::DeclarationName decl_name, |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7211 | llvm::SmallVectorImpl <clang::NamedDecl *> *results) |
| 7212 | { |
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 7213 | |
| 7214 | switch (decl_context->getDeclKind()) |
| 7215 | { |
| 7216 | case clang::Decl::Namespace: |
| 7217 | case clang::Decl::TranslationUnit: |
| 7218 | { |
| 7219 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 7220 | symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results); |
| 7221 | } |
| 7222 | break; |
| 7223 | default: |
| 7224 | break; |
| 7225 | } |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7226 | } |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7227 | |
| 7228 | bool |
| 7229 | SymbolFileDWARF::LayoutRecordType (void *baton, |
| 7230 | const clang::RecordDecl *record_decl, |
| 7231 | uint64_t &size, |
| 7232 | uint64_t &alignment, |
| 7233 | llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, |
| 7234 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, |
| 7235 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) |
| 7236 | { |
| 7237 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 7238 | return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets); |
| 7239 | } |
| 7240 | |
| 7241 | |
| 7242 | bool |
| 7243 | SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl, |
| 7244 | uint64_t &bit_size, |
| 7245 | uint64_t &alignment, |
| 7246 | llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, |
| 7247 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, |
| 7248 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) |
| 7249 | { |
| 7250 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| 7251 | RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl); |
| 7252 | bool success = false; |
| 7253 | base_offsets.clear(); |
| 7254 | vbase_offsets.clear(); |
| 7255 | if (pos != m_record_decl_to_layout_map.end()) |
| 7256 | { |
| 7257 | bit_size = pos->second.bit_size; |
| 7258 | alignment = pos->second.alignment; |
| 7259 | field_offsets.swap(pos->second.field_offsets); |
| 7260 | m_record_decl_to_layout_map.erase(pos); |
| 7261 | success = true; |
| 7262 | } |
| 7263 | else |
| 7264 | { |
| 7265 | bit_size = 0; |
| 7266 | alignment = 0; |
| 7267 | field_offsets.clear(); |
| 7268 | } |
| 7269 | |
| 7270 | if (log) |
| 7271 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 7272 | "SymbolFileDWARF::LayoutRecordType (record_decl = %p, bit_size = %llu, alignment = %llu, field_offsets[%u],base_offsets[%u], vbase_offsets[%u]) success = %i", |
| 7273 | record_decl, |
| 7274 | bit_size, |
| 7275 | alignment, |
| 7276 | (uint32_t)field_offsets.size(), |
| 7277 | (uint32_t)base_offsets.size(), |
| 7278 | (uint32_t)vbase_offsets.size(), |
| 7279 | success); |
| 7280 | return success; |
| 7281 | } |
| 7282 | |
| 7283 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 7284 | SymbolFileDWARFDebugMap * |
| 7285 | SymbolFileDWARF::GetDebugMapSymfile () |
| 7286 | { |
| 7287 | if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired()) |
| 7288 | { |
| 7289 | lldb::ModuleSP module_sp (m_debug_map_module_wp.lock()); |
| 7290 | if (module_sp) |
| 7291 | { |
| 7292 | SymbolVendor *sym_vendor = module_sp->GetSymbolVendor(); |
| 7293 | if (sym_vendor) |
| 7294 | m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile(); |
| 7295 | } |
| 7296 | } |
| 7297 | return m_debug_map_symfile; |
| 7298 | } |
| 7299 | |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7300 | |