| 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(); |
| 924 | const uint32_t language = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0); |
| 925 | if (language) |
| 926 | return (lldb::LanguageType)language; |
| 927 | } |
| 928 | return eLanguageTypeUnknown; |
| 929 | } |
| 930 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 931 | size_t |
| 932 | SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc) |
| 933 | { |
| 934 | assert (sc.comp_unit); |
| 935 | size_t functions_added = 0; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 936 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 937 | if (dwarf_cu) |
| 938 | { |
| 939 | DWARFDIECollection function_dies; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 940 | 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] | 941 | size_t func_idx; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 942 | for (func_idx = 0; func_idx < num_functions; ++func_idx) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 943 | { |
| 944 | const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 945 | if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 946 | { |
| 947 | if (ParseCompileUnitFunction(sc, dwarf_cu, die)) |
| 948 | ++functions_added; |
| 949 | } |
| 950 | } |
| 951 | //FixupTypes(); |
| 952 | } |
| 953 | return functions_added; |
| 954 | } |
| 955 | |
| 956 | bool |
| 957 | SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files) |
| 958 | { |
| 959 | assert (sc.comp_unit); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 960 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 961 | assert (dwarf_cu); |
| 962 | const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 963 | |
| 964 | if (cu_die) |
| 965 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 966 | const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL); |
| 967 | 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] | 968 | |
| 969 | // All file indexes in DWARF are one based and a file of index zero is |
| 970 | // supposed to be the compile unit itself. |
| 971 | support_files.Append (*sc.comp_unit); |
| 972 | |
| Greg Clayton | d804d28 | 2012-03-15 21:01:31 +0000 | [diff] [blame] | 973 | 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] | 974 | } |
| 975 | return false; |
| 976 | } |
| 977 | |
| 978 | struct ParseDWARFLineTableCallbackInfo |
| 979 | { |
| 980 | LineTable* line_table; |
| 981 | const SectionList *section_list; |
| 982 | lldb::addr_t prev_sect_file_base_addr; |
| 983 | lldb::addr_t curr_sect_file_base_addr; |
| 984 | bool is_oso_for_debug_map; |
| 985 | bool prev_in_final_executable; |
| 986 | DWARFDebugLine::Row prev_row; |
| 987 | SectionSP prev_section_sp; |
| 988 | SectionSP curr_section_sp; |
| 989 | }; |
| 990 | |
| 991 | //---------------------------------------------------------------------- |
| 992 | // ParseStatementTableCallback |
| 993 | //---------------------------------------------------------------------- |
| 994 | static void |
| 995 | ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData) |
| 996 | { |
| 997 | LineTable* line_table = ((ParseDWARFLineTableCallbackInfo*)userData)->line_table; |
| 998 | if (state.row == DWARFDebugLine::State::StartParsingLineTable) |
| 999 | { |
| 1000 | // Just started parsing the line table |
| 1001 | } |
| 1002 | else if (state.row == DWARFDebugLine::State::DoneParsingLineTable) |
| 1003 | { |
| 1004 | // Done parsing line table, nothing to do for the cleanup |
| 1005 | } |
| 1006 | else |
| 1007 | { |
| 1008 | ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData; |
| 1009 | // We have a new row, lets append it |
| 1010 | |
| 1011 | if (info->curr_section_sp.get() == NULL || info->curr_section_sp->ContainsFileAddress(state.address) == false) |
| 1012 | { |
| 1013 | info->prev_section_sp = info->curr_section_sp; |
| 1014 | info->prev_sect_file_base_addr = info->curr_sect_file_base_addr; |
| 1015 | // If this is an end sequence entry, then we subtract one from the |
| 1016 | // address to make sure we get an address that is not the end of |
| 1017 | // a section. |
| 1018 | if (state.end_sequence && state.address != 0) |
| 1019 | info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address - 1); |
| 1020 | else |
| 1021 | info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address); |
| 1022 | |
| 1023 | if (info->curr_section_sp.get()) |
| 1024 | info->curr_sect_file_base_addr = info->curr_section_sp->GetFileAddress (); |
| 1025 | else |
| 1026 | info->curr_sect_file_base_addr = 0; |
| 1027 | } |
| 1028 | if (info->curr_section_sp.get()) |
| 1029 | { |
| 1030 | lldb::addr_t curr_line_section_offset = state.address - info->curr_sect_file_base_addr; |
| 1031 | // Check for the fancy section magic to determine if we |
| 1032 | |
| 1033 | if (info->is_oso_for_debug_map) |
| 1034 | { |
| 1035 | // When this is a debug map object file that contains DWARF |
| 1036 | // (referenced from an N_OSO debug map nlist entry) we will have |
| 1037 | // a file address in the file range for our section from the |
| 1038 | // original .o file, and a load address in the executable that |
| 1039 | // contains the debug map. |
| 1040 | // |
| 1041 | // If the sections for the file range and load range are |
| 1042 | // different, we have a remapped section for the function and |
| 1043 | // this address is resolved. If they are the same, then the |
| 1044 | // function for this address didn't make it into the final |
| 1045 | // executable. |
| Jim Ingham | f94e179 | 2012-08-11 00:35:26 +0000 | [diff] [blame] | 1046 | bool curr_in_final_executable = (bool) info->curr_section_sp->GetLinkedSection (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1047 | |
| 1048 | // If we are doing DWARF with debug map, then we need to carefully |
| 1049 | // add each line table entry as there may be gaps as functions |
| 1050 | // get moved around or removed. |
| 1051 | if (!info->prev_row.end_sequence && info->prev_section_sp.get()) |
| 1052 | { |
| 1053 | if (info->prev_in_final_executable) |
| 1054 | { |
| 1055 | bool terminate_previous_entry = false; |
| 1056 | if (!curr_in_final_executable) |
| 1057 | { |
| 1058 | // Check for the case where the previous line entry |
| 1059 | // in a function made it into the final executable, |
| 1060 | // yet the current line entry falls in a function |
| 1061 | // that didn't. The line table used to be contiguous |
| 1062 | // through this address range but now it isn't. We |
| 1063 | // need to terminate the previous line entry so |
| 1064 | // that we can reconstruct the line range correctly |
| 1065 | // for it and to keep the line table correct. |
| 1066 | terminate_previous_entry = true; |
| 1067 | } |
| 1068 | else if (info->curr_section_sp.get() != info->prev_section_sp.get()) |
| 1069 | { |
| 1070 | // Check for cases where the line entries used to be |
| 1071 | // contiguous address ranges, but now they aren't. |
| 1072 | // This can happen when order files specify the |
| 1073 | // ordering of the functions. |
| 1074 | lldb::addr_t prev_line_section_offset = info->prev_row.address - info->prev_sect_file_base_addr; |
| 1075 | Section *curr_sect = info->curr_section_sp.get(); |
| 1076 | Section *prev_sect = info->prev_section_sp.get(); |
| 1077 | assert (curr_sect->GetLinkedSection()); |
| 1078 | assert (prev_sect->GetLinkedSection()); |
| 1079 | lldb::addr_t object_file_addr_delta = state.address - info->prev_row.address; |
| 1080 | lldb::addr_t curr_linked_file_addr = curr_sect->GetLinkedFileAddress() + curr_line_section_offset; |
| 1081 | lldb::addr_t prev_linked_file_addr = prev_sect->GetLinkedFileAddress() + prev_line_section_offset; |
| 1082 | lldb::addr_t linked_file_addr_delta = curr_linked_file_addr - prev_linked_file_addr; |
| 1083 | if (object_file_addr_delta != linked_file_addr_delta) |
| 1084 | terminate_previous_entry = true; |
| 1085 | } |
| 1086 | |
| 1087 | if (terminate_previous_entry) |
| 1088 | { |
| 1089 | line_table->InsertLineEntry (info->prev_section_sp, |
| 1090 | state.address - info->prev_sect_file_base_addr, |
| 1091 | info->prev_row.line, |
| 1092 | info->prev_row.column, |
| 1093 | info->prev_row.file, |
| 1094 | false, // is_stmt |
| 1095 | false, // basic_block |
| 1096 | false, // state.prologue_end |
| 1097 | false, // state.epilogue_begin |
| 1098 | true); // end_sequence); |
| 1099 | } |
| 1100 | } |
| 1101 | } |
| 1102 | |
| 1103 | if (curr_in_final_executable) |
| 1104 | { |
| 1105 | line_table->InsertLineEntry (info->curr_section_sp, |
| 1106 | curr_line_section_offset, |
| 1107 | state.line, |
| 1108 | state.column, |
| 1109 | state.file, |
| 1110 | state.is_stmt, |
| 1111 | state.basic_block, |
| 1112 | state.prologue_end, |
| 1113 | state.epilogue_begin, |
| 1114 | state.end_sequence); |
| 1115 | info->prev_section_sp = info->curr_section_sp; |
| 1116 | } |
| 1117 | else |
| 1118 | { |
| 1119 | // If the current address didn't make it into the final |
| 1120 | // executable, the current section will be the __text |
| 1121 | // segment in the .o file, so we need to clear this so |
| 1122 | // we can catch the next function that did make it into |
| 1123 | // the final executable. |
| 1124 | info->prev_section_sp.reset(); |
| 1125 | info->curr_section_sp.reset(); |
| 1126 | } |
| 1127 | |
| 1128 | info->prev_in_final_executable = curr_in_final_executable; |
| 1129 | } |
| 1130 | else |
| 1131 | { |
| 1132 | // We are not in an object file that contains DWARF for an |
| 1133 | // N_OSO, this is just a normal DWARF file. The DWARF spec |
| 1134 | // guarantees that the addresses will be in increasing order |
| 1135 | // so, since we store line tables in file address order, we |
| 1136 | // can always just append the line entry without needing to |
| 1137 | // search for the correct insertion point (we don't need to |
| 1138 | // use LineEntry::InsertLineEntry()). |
| 1139 | line_table->AppendLineEntry (info->curr_section_sp, |
| 1140 | curr_line_section_offset, |
| 1141 | state.line, |
| 1142 | state.column, |
| 1143 | state.file, |
| 1144 | state.is_stmt, |
| 1145 | state.basic_block, |
| 1146 | state.prologue_end, |
| 1147 | state.epilogue_begin, |
| 1148 | state.end_sequence); |
| 1149 | } |
| 1150 | } |
| 1151 | |
| 1152 | info->prev_row = state; |
| 1153 | } |
| 1154 | } |
| 1155 | |
| 1156 | bool |
| 1157 | SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc) |
| 1158 | { |
| 1159 | assert (sc.comp_unit); |
| 1160 | if (sc.comp_unit->GetLineTable() != NULL) |
| 1161 | return true; |
| 1162 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1163 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1164 | if (dwarf_cu) |
| 1165 | { |
| 1166 | const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly(); |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1167 | if (dwarf_cu_die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1168 | { |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1169 | const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET); |
| 1170 | if (cu_line_offset != DW_INVALID_OFFSET) |
| 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 | std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit)); |
| 1173 | if (line_table_ap.get()) |
| 1174 | { |
| 1175 | ParseDWARFLineTableCallbackInfo info = { |
| 1176 | line_table_ap.get(), |
| 1177 | m_obj_file->GetSectionList(), |
| 1178 | 0, |
| 1179 | 0, |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1180 | GetDebugMapSymfile () != NULL, |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1181 | false, |
| 1182 | DWARFDebugLine::Row(), |
| 1183 | SectionSP(), |
| 1184 | SectionSP() |
| 1185 | }; |
| 1186 | uint32_t offset = cu_line_offset; |
| 1187 | DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info); |
| 1188 | sc.comp_unit->SetLineTable(line_table_ap.release()); |
| 1189 | return true; |
| 1190 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1191 | } |
| 1192 | } |
| 1193 | } |
| 1194 | return false; |
| 1195 | } |
| 1196 | |
| 1197 | size_t |
| 1198 | SymbolFileDWARF::ParseFunctionBlocks |
| 1199 | ( |
| 1200 | const SymbolContext& sc, |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1201 | Block *parent_block, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1202 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1203 | const DWARFDebugInfoEntry *die, |
| 1204 | addr_t subprogram_low_pc, |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1205 | uint32_t depth |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1206 | ) |
| 1207 | { |
| 1208 | size_t blocks_added = 0; |
| 1209 | while (die != NULL) |
| 1210 | { |
| 1211 | dw_tag_t tag = die->Tag(); |
| 1212 | |
| 1213 | switch (tag) |
| 1214 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1215 | case DW_TAG_inlined_subroutine: |
| Greg Clayton | b4d3733 | 2011-08-12 16:22:48 +0000 | [diff] [blame] | 1216 | case DW_TAG_subprogram: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1217 | case DW_TAG_lexical_block: |
| 1218 | { |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1219 | Block *block = NULL; |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1220 | if (tag == DW_TAG_subprogram) |
| 1221 | { |
| 1222 | // Skip any DW_TAG_subprogram DIEs that are inside |
| 1223 | // of a normal or inlined functions. These will be |
| 1224 | // parsed on their own as separate entities. |
| 1225 | |
| 1226 | if (depth > 0) |
| 1227 | break; |
| 1228 | |
| 1229 | block = parent_block; |
| 1230 | } |
| 1231 | else |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1232 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1233 | BlockSP block_sp(new Block (MakeUserID(die->GetOffset()))); |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1234 | parent_block->AddChild(block_sp); |
| 1235 | block = block_sp.get(); |
| 1236 | } |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1237 | DWARFDebugRanges::RangeList ranges; |
| 1238 | const char *name = NULL; |
| 1239 | const char *mangled_name = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1240 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1241 | int decl_file = 0; |
| 1242 | int decl_line = 0; |
| 1243 | int decl_column = 0; |
| 1244 | int call_file = 0; |
| 1245 | int call_line = 0; |
| 1246 | int call_column = 0; |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1247 | if (die->GetDIENamesAndRanges (this, |
| 1248 | dwarf_cu, |
| 1249 | name, |
| 1250 | mangled_name, |
| 1251 | ranges, |
| 1252 | decl_file, decl_line, decl_column, |
| 1253 | call_file, call_line, call_column)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1254 | { |
| 1255 | if (tag == DW_TAG_subprogram) |
| 1256 | { |
| 1257 | assert (subprogram_low_pc == LLDB_INVALID_ADDRESS); |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1258 | subprogram_low_pc = ranges.GetMinRangeBase(0); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1259 | } |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1260 | else if (tag == DW_TAG_inlined_subroutine) |
| 1261 | { |
| 1262 | // We get called here for inlined subroutines in two ways. |
| 1263 | // The first time is when we are making the Function object |
| 1264 | // for this inlined concrete instance. Since we're creating a top level block at |
| 1265 | // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to |
| 1266 | // adjust the containing address. |
| 1267 | // The second time is when we are parsing the blocks inside the function that contains |
| 1268 | // the inlined concrete instance. Since these will be blocks inside the containing "real" |
| 1269 | // function the offset will be for that function. |
| 1270 | if (subprogram_low_pc == LLDB_INVALID_ADDRESS) |
| 1271 | { |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1272 | subprogram_low_pc = ranges.GetMinRangeBase(0); |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1273 | } |
| 1274 | } |
| 1275 | |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1276 | AddRangesToBlock (*block, ranges, subprogram_low_pc); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1277 | |
| 1278 | if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL)) |
| 1279 | { |
| 1280 | std::auto_ptr<Declaration> decl_ap; |
| 1281 | if (decl_file != 0 || decl_line != 0 || decl_column != 0) |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1282 | decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), |
| 1283 | decl_line, decl_column)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1284 | |
| 1285 | std::auto_ptr<Declaration> call_ap; |
| 1286 | if (call_file != 0 || call_line != 0 || call_column != 0) |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1287 | call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file), |
| 1288 | call_line, call_column)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1289 | |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1290 | block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1291 | } |
| 1292 | |
| 1293 | ++blocks_added; |
| 1294 | |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1295 | if (die->HasChildren()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1296 | { |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1297 | blocks_added += ParseFunctionBlocks (sc, |
| 1298 | block, |
| 1299 | dwarf_cu, |
| 1300 | die->GetFirstChild(), |
| 1301 | subprogram_low_pc, |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1302 | depth + 1); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1303 | } |
| 1304 | } |
| 1305 | } |
| 1306 | break; |
| 1307 | default: |
| 1308 | break; |
| 1309 | } |
| 1310 | |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1311 | // Only parse siblings of the block if we are not at depth zero. A depth |
| 1312 | // of zero indicates we are currently parsing the top level |
| 1313 | // DW_TAG_subprogram DIE |
| 1314 | |
| 1315 | if (depth == 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1316 | die = NULL; |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1317 | else |
| 1318 | die = die->GetSibling(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1319 | } |
| 1320 | return blocks_added; |
| 1321 | } |
| 1322 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1323 | bool |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1324 | SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu, |
| 1325 | const DWARFDebugInfoEntry *die, |
| 1326 | ClangASTContext::TemplateParameterInfos &template_param_infos) |
| 1327 | { |
| 1328 | const dw_tag_t tag = die->Tag(); |
| 1329 | |
| 1330 | switch (tag) |
| 1331 | { |
| 1332 | case DW_TAG_template_type_parameter: |
| 1333 | case DW_TAG_template_value_parameter: |
| 1334 | { |
| 1335 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| 1336 | |
| 1337 | DWARFDebugInfoEntry::Attributes attributes; |
| 1338 | const size_t num_attributes = die->GetAttributes (this, |
| 1339 | dwarf_cu, |
| 1340 | fixed_form_sizes, |
| 1341 | attributes); |
| 1342 | const char *name = NULL; |
| 1343 | Type *lldb_type = NULL; |
| 1344 | clang_type_t clang_type = NULL; |
| 1345 | uint64_t uval64 = 0; |
| 1346 | bool uval64_valid = false; |
| 1347 | if (num_attributes > 0) |
| 1348 | { |
| 1349 | DWARFFormValue form_value; |
| 1350 | for (size_t i=0; i<num_attributes; ++i) |
| 1351 | { |
| 1352 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 1353 | |
| 1354 | switch (attr) |
| 1355 | { |
| 1356 | case DW_AT_name: |
| 1357 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1358 | name = form_value.AsCString(&get_debug_str_data()); |
| 1359 | break; |
| 1360 | |
| 1361 | case DW_AT_type: |
| 1362 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1363 | { |
| 1364 | const dw_offset_t type_die_offset = form_value.Reference(dwarf_cu); |
| 1365 | lldb_type = ResolveTypeUID(type_die_offset); |
| 1366 | if (lldb_type) |
| 1367 | clang_type = lldb_type->GetClangForwardType(); |
| 1368 | } |
| 1369 | break; |
| 1370 | |
| 1371 | case DW_AT_const_value: |
| 1372 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1373 | { |
| 1374 | uval64_valid = true; |
| 1375 | uval64 = form_value.Unsigned(); |
| 1376 | } |
| 1377 | break; |
| 1378 | default: |
| 1379 | break; |
| 1380 | } |
| 1381 | } |
| 1382 | |
| 1383 | if (name && lldb_type && clang_type) |
| 1384 | { |
| 1385 | bool is_signed = false; |
| 1386 | template_param_infos.names.push_back(name); |
| 1387 | clang::QualType clang_qual_type (clang::QualType::getFromOpaquePtr (clang_type)); |
| 1388 | if (tag == DW_TAG_template_value_parameter && ClangASTContext::IsIntegerType (clang_type, is_signed) && uval64_valid) |
| 1389 | { |
| 1390 | llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed); |
| Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1391 | template_param_infos.args.push_back (clang::TemplateArgument (*GetClangASTContext().getASTContext(), |
| 1392 | llvm::APSInt(apint), |
| 1393 | clang_qual_type)); |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1394 | } |
| 1395 | else |
| 1396 | { |
| 1397 | template_param_infos.args.push_back (clang::TemplateArgument (clang_qual_type)); |
| 1398 | } |
| 1399 | } |
| 1400 | else |
| 1401 | { |
| 1402 | return false; |
| 1403 | } |
| 1404 | |
| 1405 | } |
| 1406 | } |
| 1407 | return true; |
| 1408 | |
| 1409 | default: |
| 1410 | break; |
| 1411 | } |
| 1412 | return false; |
| 1413 | } |
| 1414 | |
| 1415 | bool |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1416 | SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu, |
| 1417 | const DWARFDebugInfoEntry *parent_die, |
| 1418 | ClangASTContext::TemplateParameterInfos &template_param_infos) |
| 1419 | { |
| 1420 | |
| 1421 | if (parent_die == NULL) |
| Filipe Cabecinhas | 52008c6 | 2012-05-23 16:24:11 +0000 | [diff] [blame] | 1422 | return false; |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1423 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1424 | Args template_parameter_names; |
| 1425 | for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); |
| 1426 | die != NULL; |
| 1427 | die = die->GetSibling()) |
| 1428 | { |
| 1429 | const dw_tag_t tag = die->Tag(); |
| 1430 | |
| 1431 | switch (tag) |
| 1432 | { |
| 1433 | case DW_TAG_template_type_parameter: |
| 1434 | case DW_TAG_template_value_parameter: |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1435 | ParseTemplateDIE (dwarf_cu, die, template_param_infos); |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1436 | break; |
| 1437 | |
| 1438 | default: |
| 1439 | break; |
| 1440 | } |
| 1441 | } |
| 1442 | if (template_param_infos.args.empty()) |
| 1443 | return false; |
| 1444 | return template_param_infos.args.size() == template_param_infos.names.size(); |
| 1445 | } |
| 1446 | |
| 1447 | clang::ClassTemplateDecl * |
| 1448 | SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx, |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1449 | lldb::AccessType access_type, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1450 | const char *parent_name, |
| 1451 | int tag_decl_kind, |
| 1452 | const ClangASTContext::TemplateParameterInfos &template_param_infos) |
| 1453 | { |
| 1454 | if (template_param_infos.IsValid()) |
| 1455 | { |
| 1456 | std::string template_basename(parent_name); |
| 1457 | template_basename.erase (template_basename.find('<')); |
| 1458 | ClangASTContext &ast = GetClangASTContext(); |
| 1459 | |
| 1460 | return ast.CreateClassTemplateDecl (decl_ctx, |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1461 | access_type, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1462 | template_basename.c_str(), |
| 1463 | tag_decl_kind, |
| 1464 | template_param_infos); |
| 1465 | } |
| 1466 | return NULL; |
| 1467 | } |
| 1468 | |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1469 | class SymbolFileDWARF::DelayedAddObjCClassProperty |
| 1470 | { |
| 1471 | public: |
| 1472 | DelayedAddObjCClassProperty |
| 1473 | ( |
| 1474 | clang::ASTContext *ast, |
| 1475 | lldb::clang_type_t class_opaque_type, |
| 1476 | const char *property_name, |
| 1477 | lldb::clang_type_t property_opaque_type, // The property type is only required if you don't have an ivar decl |
| 1478 | clang::ObjCIvarDecl *ivar_decl, |
| 1479 | const char *property_setter_name, |
| 1480 | const char *property_getter_name, |
| 1481 | uint32_t property_attributes, |
| 1482 | uint64_t metadata = 0 |
| 1483 | ) : |
| 1484 | m_ast (ast), |
| 1485 | m_class_opaque_type (class_opaque_type), |
| 1486 | m_property_name (property_name), |
| 1487 | m_property_opaque_type (property_opaque_type), |
| 1488 | m_ivar_decl (ivar_decl), |
| 1489 | m_property_setter_name (property_setter_name), |
| 1490 | m_property_getter_name (property_getter_name), |
| 1491 | m_property_attributes (property_attributes), |
| 1492 | m_metadata (metadata) |
| 1493 | { |
| 1494 | } |
| 1495 | |
| 1496 | bool Finalize() const |
| 1497 | { |
| 1498 | return ClangASTContext::AddObjCClassProperty(m_ast, |
| 1499 | m_class_opaque_type, |
| 1500 | m_property_name, |
| 1501 | m_property_opaque_type, |
| 1502 | m_ivar_decl, |
| 1503 | m_property_setter_name, |
| 1504 | m_property_getter_name, |
| 1505 | m_property_attributes, |
| 1506 | m_metadata); |
| 1507 | } |
| 1508 | private: |
| 1509 | clang::ASTContext *m_ast; |
| 1510 | lldb::clang_type_t m_class_opaque_type; |
| 1511 | const char *m_property_name; |
| 1512 | lldb::clang_type_t m_property_opaque_type; |
| 1513 | clang::ObjCIvarDecl *m_ivar_decl; |
| 1514 | const char *m_property_setter_name; |
| 1515 | const char *m_property_getter_name; |
| 1516 | uint32_t m_property_attributes; |
| 1517 | uint64_t m_metadata; |
| 1518 | }; |
| 1519 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1520 | size_t |
| 1521 | SymbolFileDWARF::ParseChildMembers |
| 1522 | ( |
| 1523 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1524 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1525 | const DWARFDebugInfoEntry *parent_die, |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1526 | clang_type_t class_clang_type, |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1527 | const LanguageType class_language, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1528 | std::vector<clang::CXXBaseSpecifier *>& base_classes, |
| 1529 | std::vector<int>& member_accessibilities, |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1530 | DWARFDIECollection& member_function_dies, |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1531 | DelayedPropertyList& delayed_properties, |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1532 | AccessType& default_accessibility, |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1533 | bool &is_a_class, |
| 1534 | LayoutInfo &layout_info |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1535 | ) |
| 1536 | { |
| 1537 | if (parent_die == NULL) |
| 1538 | return 0; |
| 1539 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1540 | size_t count = 0; |
| 1541 | const DWARFDebugInfoEntry *die; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 1542 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1543 | uint32_t member_idx = 0; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 1544 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1545 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 1546 | { |
| 1547 | dw_tag_t tag = die->Tag(); |
| 1548 | |
| 1549 | switch (tag) |
| 1550 | { |
| 1551 | case DW_TAG_member: |
| Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1552 | case DW_TAG_APPLE_property: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1553 | { |
| 1554 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1555 | const size_t num_attributes = die->GetAttributes (this, |
| 1556 | dwarf_cu, |
| 1557 | fixed_form_sizes, |
| 1558 | attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1559 | if (num_attributes > 0) |
| 1560 | { |
| 1561 | Declaration decl; |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1562 | //DWARFExpression location; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1563 | const char *name = NULL; |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1564 | const char *prop_name = NULL; |
| 1565 | const char *prop_getter_name = NULL; |
| 1566 | const char *prop_setter_name = NULL; |
| 1567 | uint32_t prop_attributes = 0; |
| 1568 | |
| 1569 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1570 | bool is_artificial = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1571 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1572 | AccessType accessibility = eAccessNone; |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1573 | uint32_t member_byte_offset = UINT32_MAX; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1574 | size_t byte_size = 0; |
| 1575 | size_t bit_offset = 0; |
| 1576 | size_t bit_size = 0; |
| 1577 | uint32_t i; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1578 | for (i=0; i<num_attributes && !is_artificial; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1579 | { |
| 1580 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 1581 | DWARFFormValue form_value; |
| 1582 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1583 | { |
| 1584 | switch (attr) |
| 1585 | { |
| 1586 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 1587 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 1588 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 1589 | case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; |
| 1590 | case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; |
| 1591 | case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break; |
| 1592 | case DW_AT_bit_size: bit_size = form_value.Unsigned(); break; |
| 1593 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; |
| 1594 | case DW_AT_data_member_location: |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1595 | if (form_value.BlockData()) |
| 1596 | { |
| 1597 | Value initialValue(0); |
| 1598 | Value memberOffset(0); |
| 1599 | const DataExtractor& debug_info_data = get_debug_info_data(); |
| 1600 | uint32_t block_length = form_value.Unsigned(); |
| 1601 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 1602 | if (DWARFExpression::Evaluate(NULL, // ExecutionContext * |
| 1603 | NULL, // clang::ASTContext * |
| 1604 | NULL, // ClangExpressionVariableList * |
| 1605 | NULL, // ClangExpressionDeclMap * |
| 1606 | NULL, // RegisterContext * |
| 1607 | debug_info_data, |
| 1608 | block_offset, |
| 1609 | block_length, |
| 1610 | eRegisterKindDWARF, |
| 1611 | &initialValue, |
| 1612 | memberOffset, |
| 1613 | NULL)) |
| 1614 | { |
| 1615 | member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt(); |
| 1616 | } |
| 1617 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1618 | break; |
| 1619 | |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1620 | 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] | 1621 | case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break; |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1622 | case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break; |
| 1623 | case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break; |
| 1624 | case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break; |
| 1625 | case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break; |
| 1626 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1627 | default: |
| Greg Clayton | 1b02c17 | 2012-03-14 21:00:47 +0000 | [diff] [blame] | 1628 | case DW_AT_declaration: |
| 1629 | case DW_AT_description: |
| 1630 | case DW_AT_mutable: |
| 1631 | case DW_AT_visibility: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1632 | case DW_AT_sibling: |
| 1633 | break; |
| 1634 | } |
| 1635 | } |
| 1636 | } |
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1637 | |
| 1638 | if (prop_name) |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1639 | { |
| Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 1640 | ConstString fixed_getter; |
| 1641 | ConstString fixed_setter; |
| 1642 | |
| 1643 | // Check if the property getter/setter were provided as full |
| 1644 | // names. We want basenames, so we extract them. |
| 1645 | |
| 1646 | if (prop_getter_name && prop_getter_name[0] == '-') |
| 1647 | { |
| 1648 | ObjCLanguageRuntime::ParseMethodName (prop_getter_name, |
| 1649 | NULL, |
| 1650 | &fixed_getter, |
| 1651 | NULL, |
| 1652 | NULL); |
| 1653 | prop_getter_name = fixed_getter.GetCString(); |
| 1654 | } |
| 1655 | |
| 1656 | if (prop_setter_name && prop_setter_name[0] == '-') |
| 1657 | { |
| 1658 | ObjCLanguageRuntime::ParseMethodName (prop_setter_name, |
| 1659 | NULL, |
| 1660 | &fixed_setter, |
| 1661 | NULL, |
| 1662 | NULL); |
| 1663 | prop_setter_name = fixed_setter.GetCString(); |
| 1664 | } |
| 1665 | |
| 1666 | // If the names haven't been provided, they need to be |
| 1667 | // filled in. |
| 1668 | |
| 1669 | if (!prop_getter_name) |
| 1670 | { |
| 1671 | prop_getter_name = prop_name; |
| 1672 | } |
| 1673 | if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly)) |
| 1674 | { |
| 1675 | StreamString ss; |
| 1676 | |
| 1677 | ss.Printf("set%c%s:", |
| 1678 | toupper(prop_name[0]), |
| 1679 | &prop_name[1]); |
| 1680 | |
| 1681 | fixed_setter.SetCString(ss.GetData()); |
| 1682 | prop_setter_name = fixed_setter.GetCString(); |
| 1683 | } |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1684 | } |
| 1685 | |
| 1686 | // Clang has a DWARF generation bug where sometimes it |
| Greg Clayton | 4495393 | 2011-10-25 01:25:35 +0000 | [diff] [blame] | 1687 | // represents fields that are references with bad byte size |
| 1688 | // and bit size/offset information such as: |
| 1689 | // |
| 1690 | // DW_AT_byte_size( 0x00 ) |
| 1691 | // DW_AT_bit_size( 0x40 ) |
| 1692 | // DW_AT_bit_offset( 0xffffffffffffffc0 ) |
| 1693 | // |
| 1694 | // So check the bit offset to make sure it is sane, and if |
| 1695 | // the values are not sane, remove them. If we don't do this |
| 1696 | // then we will end up with a crash if we try to use this |
| 1697 | // type in an expression when clang becomes unhappy with its |
| 1698 | // recycled debug info. |
| Sean Callanan | 5a477cf | 2010-10-30 01:56:10 +0000 | [diff] [blame] | 1699 | |
| Greg Clayton | 4495393 | 2011-10-25 01:25:35 +0000 | [diff] [blame] | 1700 | if (bit_offset > 128) |
| 1701 | { |
| 1702 | bit_size = 0; |
| 1703 | bit_offset = 0; |
| 1704 | } |
| 1705 | |
| 1706 | // FIXME: Make Clang ignore Objective-C accessibility for expressions |
| Sean Callanan | 5a477cf | 2010-10-30 01:56:10 +0000 | [diff] [blame] | 1707 | if (class_language == eLanguageTypeObjC || |
| 1708 | class_language == eLanguageTypeObjC_plus_plus) |
| 1709 | accessibility = eAccessNone; |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1710 | |
| 1711 | if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name)) |
| 1712 | { |
| 1713 | // Not all compilers will mark the vtable pointer |
| 1714 | // member as artificial (llvm-gcc). We can't have |
| 1715 | // the virtual members in our classes otherwise it |
| 1716 | // throws off all child offsets since we end up |
| 1717 | // having and extra pointer sized member in our |
| 1718 | // class layouts. |
| 1719 | is_artificial = true; |
| 1720 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1721 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1722 | if (is_artificial == false) |
| 1723 | { |
| 1724 | Type *member_type = ResolveTypeUID(encoding_uid); |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1725 | clang::FieldDecl *field_decl = NULL; |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1726 | if (tag == DW_TAG_member) |
| Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1727 | { |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1728 | if (member_type) |
| 1729 | { |
| 1730 | if (accessibility == eAccessNone) |
| 1731 | accessibility = default_accessibility; |
| 1732 | member_accessibilities.push_back(accessibility); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1733 | |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1734 | field_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type, |
| 1735 | name, |
| 1736 | member_type->GetClangLayoutType(), |
| 1737 | accessibility, |
| 1738 | bit_size); |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 1739 | |
| 1740 | GetClangASTContext().SetMetadata((uintptr_t)field_decl, MakeUserID(die->GetOffset())); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1741 | } |
| 1742 | else |
| 1743 | { |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1744 | if (name) |
| 1745 | GetObjectFile()->GetModule()->ReportError ("0x%8.8llx: DW_TAG_member '%s' refers to type 0x%8.8llx which was unable to be parsed", |
| 1746 | MakeUserID(die->GetOffset()), |
| 1747 | name, |
| 1748 | encoding_uid); |
| 1749 | else |
| 1750 | GetObjectFile()->GetModule()->ReportError ("0x%8.8llx: DW_TAG_member refers to type 0x%8.8llx which was unable to be parsed", |
| 1751 | MakeUserID(die->GetOffset()), |
| 1752 | encoding_uid); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1753 | } |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1754 | |
| 1755 | if (member_byte_offset != UINT32_MAX || bit_size != 0) |
| 1756 | { |
| 1757 | ///////////////////////////////////////////////////////////// |
| 1758 | // How to locate a field given the DWARF debug information |
| 1759 | // |
| 1760 | // AT_byte_size indicates the size of the word in which the |
| 1761 | // bit offset must be interpreted. |
| 1762 | // |
| 1763 | // AT_data_member_location indicates the byte offset of the |
| 1764 | // word from the base address of the structure. |
| 1765 | // |
| 1766 | // AT_bit_offset indicates how many bits into the word |
| 1767 | // (according to the host endianness) the low-order bit of |
| 1768 | // the field starts. AT_bit_offset can be negative. |
| 1769 | // |
| 1770 | // AT_bit_size indicates the size of the field in bits. |
| 1771 | ///////////////////////////////////////////////////////////// |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1772 | |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1773 | ByteOrder object_endian = GetObjectFile()->GetModule()->GetArchitecture().GetDefaultEndian(); |
| 1774 | |
| 1775 | uint64_t total_bit_offset = 0; |
| 1776 | |
| 1777 | total_bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8)); |
| 1778 | |
| 1779 | if (object_endian == eByteOrderLittle) |
| 1780 | { |
| 1781 | total_bit_offset += byte_size * 8; |
| 1782 | total_bit_offset -= (bit_offset + bit_size); |
| 1783 | } |
| 1784 | else |
| 1785 | { |
| 1786 | total_bit_offset += bit_offset; |
| 1787 | } |
| 1788 | |
| 1789 | layout_info.field_offsets.insert(std::make_pair(field_decl, total_bit_offset)); |
| 1790 | } |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 1791 | } |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1792 | |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1793 | if (prop_name != NULL) |
| 1794 | { |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1795 | clang::ObjCIvarDecl *ivar_decl = NULL; |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1796 | |
| Sean Callanan | 751aac6 | 2012-03-29 19:07:06 +0000 | [diff] [blame] | 1797 | if (field_decl) |
| 1798 | { |
| 1799 | ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl); |
| 1800 | assert (ivar_decl != NULL); |
| 1801 | } |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1802 | |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1803 | delayed_properties.push_back(DelayedAddObjCClassProperty(GetClangASTContext().getASTContext(), |
| 1804 | class_clang_type, |
| 1805 | prop_name, |
| 1806 | member_type->GetClangLayoutType(), |
| 1807 | ivar_decl, |
| 1808 | prop_setter_name, |
| 1809 | prop_getter_name, |
| 1810 | prop_attributes, |
| 1811 | MakeUserID(die->GetOffset()))); |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 1812 | |
| Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 1813 | if (ivar_decl) |
| 1814 | GetClangASTContext().SetMetadata((uintptr_t)ivar_decl, MakeUserID(die->GetOffset())); |
| Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1815 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1816 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1817 | } |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1818 | ++member_idx; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1819 | } |
| 1820 | break; |
| 1821 | |
| 1822 | case DW_TAG_subprogram: |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 1823 | // Let the type parsing code handle this one for us. |
| 1824 | member_function_dies.Append (die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1825 | break; |
| 1826 | |
| 1827 | case DW_TAG_inheritance: |
| 1828 | { |
| 1829 | is_a_class = true; |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1830 | if (default_accessibility == eAccessNone) |
| 1831 | default_accessibility = eAccessPrivate; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1832 | // TODO: implement DW_TAG_inheritance type parsing |
| 1833 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1834 | const size_t num_attributes = die->GetAttributes (this, |
| 1835 | dwarf_cu, |
| 1836 | fixed_form_sizes, |
| 1837 | attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1838 | if (num_attributes > 0) |
| 1839 | { |
| 1840 | Declaration decl; |
| 1841 | DWARFExpression location; |
| 1842 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 1843 | AccessType accessibility = default_accessibility; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1844 | bool is_virtual = false; |
| 1845 | bool is_base_of_class = true; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 1846 | //off_t member_offset = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1847 | uint32_t i; |
| 1848 | for (i=0; i<num_attributes; ++i) |
| 1849 | { |
| 1850 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 1851 | DWARFFormValue form_value; |
| 1852 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 1853 | { |
| 1854 | switch (attr) |
| 1855 | { |
| 1856 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 1857 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 1858 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 1859 | case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 1860 | // case DW_AT_data_member_location: |
| 1861 | // if (form_value.BlockData()) |
| 1862 | // { |
| 1863 | // Value initialValue(0); |
| 1864 | // Value memberOffset(0); |
| 1865 | // const DataExtractor& debug_info_data = get_debug_info_data(); |
| 1866 | // uint32_t block_length = form_value.Unsigned(); |
| 1867 | // uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 1868 | // if (DWARFExpression::Evaluate (NULL, |
| 1869 | // NULL, |
| 1870 | // NULL, |
| 1871 | // NULL, |
| 1872 | // NULL, |
| 1873 | // debug_info_data, |
| 1874 | // block_offset, |
| 1875 | // block_length, |
| 1876 | // eRegisterKindDWARF, |
| 1877 | // &initialValue, |
| 1878 | // memberOffset, |
| 1879 | // NULL)) |
| 1880 | // { |
| 1881 | // member_offset = memberOffset.ResolveValue(NULL, NULL).UInt(); |
| 1882 | // } |
| 1883 | // } |
| 1884 | // break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1885 | |
| 1886 | case DW_AT_accessibility: |
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1887 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1888 | break; |
| 1889 | |
| 1890 | case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break; |
| 1891 | default: |
| 1892 | case DW_AT_sibling: |
| 1893 | break; |
| 1894 | } |
| 1895 | } |
| 1896 | } |
| 1897 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 1898 | Type *base_class_type = ResolveTypeUID(encoding_uid); |
| 1899 | assert(base_class_type); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1900 | |
| Greg Clayton | f4ecaa5 | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 1901 | clang_type_t base_class_clang_type = base_class_type->GetClangFullType(); |
| 1902 | assert (base_class_clang_type); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1903 | if (class_language == eLanguageTypeObjC) |
| 1904 | { |
| Greg Clayton | f4ecaa5 | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 1905 | GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1906 | } |
| 1907 | else |
| 1908 | { |
| Greg Clayton | f4ecaa5 | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 1909 | base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type, |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 1910 | accessibility, |
| 1911 | is_virtual, |
| 1912 | is_base_of_class)); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1913 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1914 | } |
| 1915 | } |
| 1916 | break; |
| 1917 | |
| 1918 | default: |
| 1919 | break; |
| 1920 | } |
| 1921 | } |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 1922 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1923 | return count; |
| 1924 | } |
| 1925 | |
| 1926 | |
| 1927 | clang::DeclContext* |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 1928 | SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1929 | { |
| 1930 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1931 | if (debug_info && UserIDMatches(type_uid)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1932 | { |
| 1933 | DWARFCompileUnitSP cu_sp; |
| 1934 | const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp); |
| 1935 | if (die) |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 1936 | return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL); |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 1937 | } |
| 1938 | return NULL; |
| 1939 | } |
| 1940 | |
| 1941 | clang::DeclContext* |
| 1942 | SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid) |
| 1943 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1944 | if (UserIDMatches(type_uid)) |
| 1945 | return GetClangDeclContextForDIEOffset (sc, type_uid); |
| 1946 | return NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1947 | } |
| 1948 | |
| 1949 | Type* |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 1950 | SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1951 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1952 | if (UserIDMatches(type_uid)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1953 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1954 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 1955 | if (debug_info) |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 1956 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1957 | DWARFCompileUnitSP cu_sp; |
| 1958 | const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp); |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1959 | const bool assert_not_being_parsed = true; |
| 1960 | return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 1961 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1962 | } |
| 1963 | return NULL; |
| 1964 | } |
| 1965 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1966 | Type* |
| 1967 | SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed) |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1968 | { |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1969 | if (die != NULL) |
| 1970 | { |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1971 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| 1972 | if (log) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1973 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 1974 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'", |
| 1975 | die->GetOffset(), |
| 1976 | DW_TAG_value_to_name(die->Tag()), |
| 1977 | die->GetName(this, cu)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1978 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1979 | // We might be coming in in the middle of a type tree (a class |
| 1980 | // withing a class, an enum within a class), so parse any needed |
| 1981 | // parent DIEs before we get to this one... |
| 1982 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); |
| 1983 | switch (decl_ctx_die->Tag()) |
| 1984 | { |
| 1985 | case DW_TAG_structure_type: |
| 1986 | case DW_TAG_union_type: |
| 1987 | case DW_TAG_class_type: |
| 1988 | { |
| 1989 | // Get the type, which could be a forward declaration |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1990 | if (log) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1991 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 1992 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x", |
| 1993 | die->GetOffset(), |
| 1994 | DW_TAG_value_to_name(die->Tag()), |
| 1995 | die->GetName(this, cu), |
| 1996 | decl_ctx_die->GetOffset()); |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 1997 | // |
| 1998 | // Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed); |
| 1999 | // if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag())) |
| 2000 | // { |
| 2001 | // if (log) |
| 2002 | // GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 2003 | // "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function", |
| 2004 | // die->GetOffset(), |
| 2005 | // DW_TAG_value_to_name(die->Tag()), |
| 2006 | // die->GetName(this, cu), |
| 2007 | // decl_ctx_die->GetOffset()); |
| 2008 | // // Ask the type to complete itself if it already hasn't since if we |
| 2009 | // // want a function (method or static) from a class, the class must |
| 2010 | // // create itself and add it's own methods and class functions. |
| 2011 | // if (parent_type) |
| 2012 | // parent_type->GetClangFullType(); |
| 2013 | // } |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2014 | } |
| 2015 | break; |
| 2016 | |
| 2017 | default: |
| 2018 | break; |
| 2019 | } |
| 2020 | return ResolveType (cu, die); |
| 2021 | } |
| 2022 | return NULL; |
| 2023 | } |
| 2024 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2025 | // This function is used when SymbolFileDWARFDebugMap owns a bunch of |
| 2026 | // SymbolFileDWARF objects to detect if this DWARF file is the one that |
| 2027 | // can resolve a clang_type. |
| 2028 | bool |
| 2029 | SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type) |
| 2030 | { |
| 2031 | clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type); |
| 2032 | const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers); |
| 2033 | return die != NULL; |
| 2034 | } |
| 2035 | |
| 2036 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2037 | lldb::clang_type_t |
| 2038 | SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type) |
| 2039 | { |
| 2040 | // 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] | 2041 | clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type); |
| 2042 | 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] | 2043 | if (die == NULL) |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2044 | { |
| 2045 | // We have already resolved this type... |
| 2046 | return clang_type; |
| 2047 | } |
| 2048 | // Once we start resolving this type, remove it from the forward declaration |
| 2049 | // map in case anyone child members or other types require this type to get resolved. |
| 2050 | // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition |
| 2051 | // are done. |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2052 | m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers); |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2053 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2054 | |
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 2055 | // Disable external storage for this type so we don't get anymore |
| 2056 | // clang::ExternalASTSource queries for this type. |
| 2057 | ClangASTContext::SetHasExternalStorage (clang_type, false); |
| 2058 | |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2059 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2060 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2061 | DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get(); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2062 | Type *type = m_die_to_type.lookup (die); |
| 2063 | |
| 2064 | const dw_tag_t tag = die->Tag(); |
| 2065 | |
| Greg Clayton | baf95da | 2012-03-30 23:50:54 +0000 | [diff] [blame] | 2066 | LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 2067 | if (log) |
| Greg Clayton | baf95da | 2012-03-30 23:50:54 +0000 | [diff] [blame] | 2068 | { |
| Greg Clayton | d61c0fc | 2012-04-23 22:55:20 +0000 | [diff] [blame] | 2069 | GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log.get(), |
| 2070 | "0x%8.8llx: %s '%s' resolving forward declaration...", |
| 2071 | MakeUserID(die->GetOffset()), |
| 2072 | DW_TAG_value_to_name(tag), |
| 2073 | type->GetName().AsCString()); |
| Greg Clayton | baf95da | 2012-03-30 23:50:54 +0000 | [diff] [blame] | 2074 | |
| Greg Clayton | baf95da | 2012-03-30 23:50:54 +0000 | [diff] [blame] | 2075 | } |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2076 | assert (clang_type); |
| 2077 | DWARFDebugInfoEntry::Attributes attributes; |
| 2078 | |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 2079 | ClangASTContext &ast = GetClangASTContext(); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2080 | |
| 2081 | switch (tag) |
| 2082 | { |
| 2083 | case DW_TAG_structure_type: |
| 2084 | case DW_TAG_union_type: |
| 2085 | case DW_TAG_class_type: |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2086 | { |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2087 | LayoutInfo layout_info; |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2088 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2089 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2090 | if (die->HasChildren()) |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2091 | { |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2092 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2093 | LanguageType class_language = eLanguageTypeUnknown; |
| 2094 | bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type); |
| 2095 | if (is_objc_class) |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2096 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2097 | class_language = eLanguageTypeObjC; |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2098 | // For objective C we don't start the definition when |
| 2099 | // the class is created. |
| 2100 | ast.StartTagDeclarationDefinition (clang_type); |
| 2101 | } |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2102 | |
| 2103 | int tag_decl_kind = -1; |
| 2104 | AccessType default_accessibility = eAccessNone; |
| 2105 | if (tag == DW_TAG_structure_type) |
| 2106 | { |
| 2107 | tag_decl_kind = clang::TTK_Struct; |
| 2108 | default_accessibility = eAccessPublic; |
| 2109 | } |
| 2110 | else if (tag == DW_TAG_union_type) |
| 2111 | { |
| 2112 | tag_decl_kind = clang::TTK_Union; |
| 2113 | default_accessibility = eAccessPublic; |
| 2114 | } |
| 2115 | else if (tag == DW_TAG_class_type) |
| 2116 | { |
| 2117 | tag_decl_kind = clang::TTK_Class; |
| 2118 | default_accessibility = eAccessPrivate; |
| 2119 | } |
| 2120 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2121 | SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2122 | std::vector<clang::CXXBaseSpecifier *> base_classes; |
| 2123 | std::vector<int> member_accessibilities; |
| 2124 | bool is_a_class = false; |
| 2125 | // Parse members and base classes first |
| 2126 | DWARFDIECollection member_function_dies; |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2127 | |
| 2128 | DelayedPropertyList delayed_properties; |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2129 | |
| 2130 | ParseChildMembers (sc, |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2131 | dwarf_cu, |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2132 | die, |
| 2133 | clang_type, |
| 2134 | class_language, |
| 2135 | base_classes, |
| 2136 | member_accessibilities, |
| 2137 | member_function_dies, |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2138 | delayed_properties, |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2139 | default_accessibility, |
| 2140 | is_a_class, |
| 2141 | layout_info); |
| 2142 | |
| 2143 | // Now parse any methods if there were any... |
| 2144 | size_t num_functions = member_function_dies.Size(); |
| 2145 | if (num_functions > 0) |
| 2146 | { |
| 2147 | for (size_t i=0; i<num_functions; ++i) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2148 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2149 | ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i)); |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2150 | } |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2151 | } |
| 2152 | |
| 2153 | if (class_language == eLanguageTypeObjC) |
| 2154 | { |
| Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 2155 | std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(ast.getASTContext(), clang_type)); |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2156 | if (!class_str.empty()) |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2157 | { |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2158 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2159 | DIEArray method_die_offsets; |
| 2160 | if (m_using_apple_tables) |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2161 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2162 | if (m_apple_objc_ap.get()) |
| 2163 | m_apple_objc_ap->FindByName(class_str.c_str(), method_die_offsets); |
| 2164 | } |
| 2165 | else |
| 2166 | { |
| 2167 | if (!m_indexed) |
| 2168 | Index (); |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2169 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2170 | ConstString class_name (class_str.c_str()); |
| 2171 | m_objc_class_selectors_index.Find (class_name, method_die_offsets); |
| 2172 | } |
| 2173 | |
| 2174 | if (!method_die_offsets.empty()) |
| 2175 | { |
| 2176 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2177 | |
| 2178 | DWARFCompileUnit* method_cu = NULL; |
| 2179 | const size_t num_matches = method_die_offsets.size(); |
| 2180 | for (size_t i=0; i<num_matches; ++i) |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2181 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2182 | const dw_offset_t die_offset = method_die_offsets[i]; |
| 2183 | DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu); |
| 2184 | |
| 2185 | if (method_die) |
| 2186 | ResolveType (method_cu, method_die); |
| 2187 | else |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2188 | { |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2189 | if (m_using_apple_tables) |
| 2190 | { |
| 2191 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n", |
| 2192 | die_offset, class_str.c_str()); |
| 2193 | } |
| 2194 | } |
| 2195 | } |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2196 | } |
| Sean Callanan | a0b80ab | 2012-06-04 22:28:05 +0000 | [diff] [blame] | 2197 | |
| 2198 | for (DelayedPropertyList::const_iterator pi = delayed_properties.begin(), pe = delayed_properties.end(); |
| 2199 | pi != pe; |
| 2200 | ++pi) |
| 2201 | pi->Finalize(); |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2202 | } |
| 2203 | } |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2204 | |
| 2205 | // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we |
| 2206 | // need to tell the clang type it is actually a class. |
| 2207 | if (class_language != eLanguageTypeObjC) |
| 2208 | { |
| 2209 | if (is_a_class && tag_decl_kind != clang::TTK_Class) |
| 2210 | ast.SetTagTypeKind (clang_type, clang::TTK_Class); |
| 2211 | } |
| 2212 | |
| 2213 | // Since DW_TAG_structure_type gets used for both classes |
| 2214 | // and structures, we may need to set any DW_TAG_member |
| 2215 | // fields to have a "private" access if none was specified. |
| 2216 | // When we parsed the child members we tracked that actual |
| 2217 | // accessibility value for each DW_TAG_member in the |
| 2218 | // "member_accessibilities" array. If the value for the |
| 2219 | // member is zero, then it was set to the "default_accessibility" |
| 2220 | // which for structs was "public". Below we correct this |
| 2221 | // by setting any fields to "private" that weren't correctly |
| 2222 | // set. |
| 2223 | if (is_a_class && !member_accessibilities.empty()) |
| 2224 | { |
| 2225 | // This is a class and all members that didn't have |
| 2226 | // their access specified are private. |
| 2227 | ast.SetDefaultAccessForRecordFields (clang_type, |
| 2228 | eAccessPrivate, |
| 2229 | &member_accessibilities.front(), |
| 2230 | member_accessibilities.size()); |
| 2231 | } |
| 2232 | |
| 2233 | if (!base_classes.empty()) |
| 2234 | { |
| 2235 | ast.SetBaseClassesForClassType (clang_type, |
| 2236 | &base_classes.front(), |
| 2237 | base_classes.size()); |
| 2238 | |
| 2239 | // Clang will copy each CXXBaseSpecifier in "base_classes" |
| 2240 | // so we have to free them all. |
| 2241 | ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(), |
| 2242 | base_classes.size()); |
| 2243 | } |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2244 | } |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2245 | } |
| Sean Callanan | e8c0cfb | 2012-03-02 01:03:45 +0000 | [diff] [blame] | 2246 | |
| 2247 | ast.BuildIndirectFields (clang_type); |
| 2248 | |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2249 | ast.CompleteTagDeclarationDefinition (clang_type); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2250 | |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2251 | if (!layout_info.field_offsets.empty()) |
| 2252 | { |
| 2253 | if (type) |
| 2254 | layout_info.bit_size = type->GetByteSize() * 8; |
| 2255 | if (layout_info.bit_size == 0) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2256 | 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] | 2257 | clang::QualType qual_type(clang::QualType::getFromOpaquePtr(clang_type)); |
| 2258 | const clang::RecordType *record_type = clang::dyn_cast<clang::RecordType>(qual_type.getTypePtr()); |
| 2259 | if (record_type) |
| 2260 | { |
| 2261 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 2262 | |
| 2263 | if (log) |
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2264 | { |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2265 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2266 | "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] | 2267 | clang_type, |
| 2268 | record_decl, |
| 2269 | layout_info.bit_size, |
| 2270 | layout_info.alignment, |
| 2271 | (uint32_t)layout_info.field_offsets.size()); |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2272 | |
| Greg Clayton | 821ac6d | 2012-01-28 02:22:27 +0000 | [diff] [blame] | 2273 | llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end(); |
| 2274 | for (pos = layout_info.field_offsets.begin(); pos != end; ++pos) |
| 2275 | { |
| 2276 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 2277 | "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field = { bit_offset=%u, name='%s' }", |
| 2278 | clang_type, |
| 2279 | (uint32_t)pos->second, |
| 2280 | pos->first->getNameAsString().c_str()); |
| 2281 | } |
| 2282 | } |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 2283 | m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info)); |
| 2284 | } |
| 2285 | } |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2286 | } |
| Sean Callanan | 77a1fd3 | 2012-02-27 20:07:01 +0000 | [diff] [blame] | 2287 | |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 2288 | return clang_type; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2289 | |
| 2290 | case DW_TAG_enumeration_type: |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 2291 | ast.StartTagDeclarationDefinition (clang_type); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2292 | if (die->HasChildren()) |
| 2293 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2294 | SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); |
| 2295 | ParseChildEnumerators(sc, clang_type, type->GetByteSize(), dwarf_cu, die); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2296 | } |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 2297 | ast.CompleteTagDeclarationDefinition (clang_type); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2298 | return clang_type; |
| 2299 | |
| 2300 | default: |
| 2301 | assert(false && "not a forward clang type decl!"); |
| 2302 | break; |
| 2303 | } |
| 2304 | return NULL; |
| 2305 | } |
| 2306 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2307 | Type* |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2308 | 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] | 2309 | { |
| 2310 | if (type_die != NULL) |
| 2311 | { |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 2312 | Type *type = m_die_to_type.lookup (type_die); |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2313 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2314 | if (type == NULL) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2315 | type = GetTypeForDIE (dwarf_cu, type_die).get(); |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 2316 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2317 | if (assert_not_being_parsed) |
| Jim Ingham | c354928 | 2012-01-11 02:21:12 +0000 | [diff] [blame] | 2318 | { |
| 2319 | if (type != DIE_IS_BEING_PARSED) |
| 2320 | return type; |
| 2321 | |
| 2322 | 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] | 2323 | type_die->GetOffset(), |
| 2324 | DW_TAG_value_to_name(type_die->Tag()), |
| 2325 | type_die->GetName(this, dwarf_cu)); |
| Jim Ingham | c354928 | 2012-01-11 02:21:12 +0000 | [diff] [blame] | 2326 | |
| 2327 | } |
| 2328 | else |
| 2329 | return type; |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2330 | } |
| 2331 | return NULL; |
| 2332 | } |
| 2333 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2334 | CompileUnit* |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2335 | SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2336 | { |
| 2337 | // Check if the symbol vendor already knows about this compile unit? |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2338 | if (dwarf_cu->GetUserData() == NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2339 | { |
| 2340 | // The symbol vendor doesn't know about this compile unit, we |
| 2341 | // need to parse and add it to the symbol vendor object. |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2342 | return ParseCompileUnit(dwarf_cu, cu_idx).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2343 | } |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2344 | return (CompileUnit*)dwarf_cu->GetUserData(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2345 | } |
| 2346 | |
| 2347 | bool |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2348 | SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2349 | { |
| 2350 | sc.Clear(); |
| 2351 | // Check if the symbol vendor already knows about this compile unit? |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2352 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2353 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2354 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2355 | if (sc.function == NULL) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2356 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2357 | |
| 2358 | if (sc.function) |
| 2359 | { |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 2360 | sc.module_sp = sc.function->CalculateSymbolContextModule(); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2361 | return true; |
| 2362 | } |
| 2363 | |
| 2364 | return false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2365 | } |
| 2366 | |
| 2367 | uint32_t |
| 2368 | SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) |
| 2369 | { |
| 2370 | Timer scoped_timer(__PRETTY_FUNCTION__, |
| 2371 | "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] | 2372 | so_addr.GetSection().get(), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2373 | so_addr.GetOffset(), |
| 2374 | resolve_scope); |
| 2375 | uint32_t resolved = 0; |
| 2376 | if (resolve_scope & ( eSymbolContextCompUnit | |
| 2377 | eSymbolContextFunction | |
| 2378 | eSymbolContextBlock | |
| 2379 | eSymbolContextLineEntry)) |
| 2380 | { |
| 2381 | lldb::addr_t file_vm_addr = so_addr.GetFileAddress(); |
| 2382 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2383 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2384 | if (debug_info) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2385 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2386 | 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] | 2387 | if (cu_offset != DW_INVALID_OFFSET) |
| 2388 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2389 | uint32_t cu_idx = DW_INVALID_INDEX; |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2390 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get(); |
| 2391 | if (dwarf_cu) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2392 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2393 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2394 | if (sc.comp_unit) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2395 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2396 | resolved |= eSymbolContextCompUnit; |
| 2397 | |
| 2398 | if (resolve_scope & eSymbolContextLineEntry) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2399 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2400 | LineTable *line_table = sc.comp_unit->GetLineTable(); |
| 2401 | if (line_table != NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2402 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2403 | if (so_addr.IsLinkedAddress()) |
| 2404 | { |
| 2405 | Address linked_addr (so_addr); |
| 2406 | linked_addr.ResolveLinkedAddress(); |
| 2407 | if (line_table->FindLineEntryByAddress (linked_addr, sc.line_entry)) |
| 2408 | { |
| 2409 | resolved |= eSymbolContextLineEntry; |
| 2410 | } |
| 2411 | } |
| 2412 | else if (line_table->FindLineEntryByAddress (so_addr, sc.line_entry)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2413 | { |
| 2414 | resolved |= eSymbolContextLineEntry; |
| 2415 | } |
| 2416 | } |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2417 | } |
| 2418 | |
| 2419 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) |
| 2420 | { |
| 2421 | DWARFDebugInfoEntry *function_die = NULL; |
| 2422 | DWARFDebugInfoEntry *block_die = NULL; |
| 2423 | if (resolve_scope & eSymbolContextBlock) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2424 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2425 | dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die); |
| 2426 | } |
| 2427 | else |
| 2428 | { |
| 2429 | dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL); |
| 2430 | } |
| 2431 | |
| 2432 | if (function_die != NULL) |
| 2433 | { |
| 2434 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); |
| 2435 | if (sc.function == NULL) |
| 2436 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die); |
| 2437 | } |
| 2438 | else |
| 2439 | { |
| 2440 | // We might have had a compile unit that had discontiguous |
| 2441 | // address ranges where the gaps are symbols that don't have |
| 2442 | // any debug info. Discontiguous compile unit address ranges |
| 2443 | // should only happen when there aren't other functions from |
| 2444 | // other compile units in these gaps. This helps keep the size |
| 2445 | // of the aranges down. |
| 2446 | sc.comp_unit = NULL; |
| 2447 | resolved &= ~eSymbolContextCompUnit; |
| 2448 | } |
| 2449 | |
| 2450 | if (sc.function != NULL) |
| 2451 | { |
| 2452 | resolved |= eSymbolContextFunction; |
| 2453 | |
| 2454 | if (resolve_scope & eSymbolContextBlock) |
| 2455 | { |
| 2456 | Block& block = sc.function->GetBlock (true); |
| 2457 | |
| 2458 | if (block_die != NULL) |
| 2459 | sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); |
| 2460 | else |
| 2461 | sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); |
| 2462 | if (sc.block) |
| 2463 | resolved |= eSymbolContextBlock; |
| 2464 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2465 | } |
| 2466 | } |
| 2467 | } |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2468 | else |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2469 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2470 | GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.", |
| 2471 | cu_offset, |
| 2472 | cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2473 | } |
| 2474 | } |
| 2475 | } |
| 2476 | } |
| 2477 | } |
| 2478 | return resolved; |
| 2479 | } |
| 2480 | |
| 2481 | |
| 2482 | |
| 2483 | uint32_t |
| 2484 | SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) |
| 2485 | { |
| 2486 | const uint32_t prev_size = sc_list.GetSize(); |
| 2487 | if (resolve_scope & eSymbolContextCompUnit) |
| 2488 | { |
| 2489 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2490 | if (debug_info) |
| 2491 | { |
| 2492 | uint32_t cu_idx; |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2493 | DWARFCompileUnit* dwarf_cu = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2494 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2495 | 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] | 2496 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2497 | CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 2498 | const bool full_match = file_spec.GetDirectory(); |
| 2499 | 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] | 2500 | if (check_inlines || file_spec_matches_cu_file_spec) |
| 2501 | { |
| 2502 | SymbolContext sc (m_obj_file->GetModule()); |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2503 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2504 | if (sc.comp_unit) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2505 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2506 | uint32_t file_idx = UINT32_MAX; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2507 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2508 | // If we are looking for inline functions only and we don't |
| 2509 | // find it in the support files, we are done. |
| 2510 | if (check_inlines) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2511 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2512 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); |
| 2513 | if (file_idx == UINT32_MAX) |
| 2514 | continue; |
| 2515 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2516 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2517 | if (line != 0) |
| 2518 | { |
| 2519 | LineTable *line_table = sc.comp_unit->GetLineTable(); |
| 2520 | |
| 2521 | if (line_table != NULL && line != 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2522 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2523 | // We will have already looked up the file index if |
| 2524 | // we are searching for inline entries. |
| 2525 | if (!check_inlines) |
| 2526 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2527 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2528 | if (file_idx != UINT32_MAX) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2529 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2530 | uint32_t found_line; |
| 2531 | uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry); |
| 2532 | found_line = sc.line_entry.line; |
| 2533 | |
| 2534 | while (line_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 | sc.function = NULL; |
| 2537 | sc.block = NULL; |
| 2538 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) |
| 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 | const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress(); |
| 2541 | if (file_vm_addr != LLDB_INVALID_ADDRESS) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2542 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2543 | DWARFDebugInfoEntry *function_die = NULL; |
| 2544 | DWARFDebugInfoEntry *block_die = NULL; |
| 2545 | 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] | 2546 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2547 | if (function_die != NULL) |
| 2548 | { |
| 2549 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); |
| 2550 | if (sc.function == NULL) |
| 2551 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die); |
| 2552 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2553 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2554 | if (sc.function != NULL) |
| 2555 | { |
| 2556 | Block& block = sc.function->GetBlock (true); |
| 2557 | |
| 2558 | if (block_die != NULL) |
| 2559 | sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); |
| 2560 | else |
| 2561 | sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); |
| 2562 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2563 | } |
| 2564 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2565 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2566 | sc_list.Append(sc); |
| 2567 | line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry); |
| 2568 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2569 | } |
| 2570 | } |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2571 | else if (file_spec_matches_cu_file_spec && !check_inlines) |
| 2572 | { |
| 2573 | // only append the context if we aren't looking for inline call sites |
| 2574 | // by file and line and if the file spec matches that of the compile unit |
| 2575 | sc_list.Append(sc); |
| 2576 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2577 | } |
| 2578 | else if (file_spec_matches_cu_file_spec && !check_inlines) |
| 2579 | { |
| 2580 | // only append the context if we aren't looking for inline call sites |
| 2581 | // by file and line and if the file spec matches that of the compile unit |
| 2582 | sc_list.Append(sc); |
| 2583 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2584 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2585 | if (!check_inlines) |
| 2586 | break; |
| 2587 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2588 | } |
| 2589 | } |
| 2590 | } |
| 2591 | } |
| 2592 | return sc_list.GetSize() - prev_size; |
| 2593 | } |
| 2594 | |
| 2595 | void |
| 2596 | SymbolFileDWARF::Index () |
| 2597 | { |
| 2598 | if (m_indexed) |
| 2599 | return; |
| 2600 | m_indexed = true; |
| 2601 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 2602 | "SymbolFileDWARF::Index (%s)", |
| 2603 | GetObjectFile()->GetFileSpec().GetFilename().AsCString()); |
| 2604 | |
| 2605 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2606 | if (debug_info) |
| 2607 | { |
| 2608 | uint32_t cu_idx = 0; |
| 2609 | const uint32_t num_compile_units = GetNumCompileUnits(); |
| 2610 | for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) |
| 2611 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2612 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2613 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2614 | bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2615 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2616 | dwarf_cu->Index (cu_idx, |
| 2617 | m_function_basename_index, |
| 2618 | m_function_fullname_index, |
| 2619 | m_function_method_index, |
| 2620 | m_function_selector_index, |
| 2621 | m_objc_class_selectors_index, |
| 2622 | m_global_index, |
| 2623 | m_type_index, |
| 2624 | m_namespace_index); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2625 | |
| 2626 | // Keep memory down by clearing DIEs if this generate function |
| 2627 | // caused them to be parsed |
| 2628 | if (clear_dies) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2629 | dwarf_cu->ClearDIEs (true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2630 | } |
| 2631 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2632 | m_function_basename_index.Finalize(); |
| 2633 | m_function_fullname_index.Finalize(); |
| 2634 | m_function_method_index.Finalize(); |
| 2635 | m_function_selector_index.Finalize(); |
| 2636 | m_objc_class_selectors_index.Finalize(); |
| 2637 | m_global_index.Finalize(); |
| 2638 | m_type_index.Finalize(); |
| 2639 | m_namespace_index.Finalize(); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2640 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2641 | #if defined (ENABLE_DEBUG_PRINTF) |
| Greg Clayton | 7bd65b9 | 2011-02-09 23:39:34 +0000 | [diff] [blame] | 2642 | StreamFile s(stdout, false); |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 2643 | s.Printf ("DWARF index for '%s/%s':", |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2644 | GetObjectFile()->GetFileSpec().GetDirectory().AsCString(), |
| 2645 | GetObjectFile()->GetFileSpec().GetFilename().AsCString()); |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 2646 | s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s); |
| 2647 | s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s); |
| 2648 | s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s); |
| 2649 | s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s); |
| 2650 | s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s); |
| 2651 | s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s); |
| Greg Clayton | 69b0488 | 2010-10-15 02:03:22 +0000 | [diff] [blame] | 2652 | s.Printf("\nTypes:\n"); m_type_index.Dump (&s); |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 2653 | s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2654 | #endif |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2655 | } |
| 2656 | } |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2657 | |
| 2658 | bool |
| 2659 | SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl) |
| 2660 | { |
| 2661 | if (namespace_decl == NULL) |
| 2662 | { |
| 2663 | // Invalid namespace decl which means we aren't matching only things |
| 2664 | // in this symbol file, so return true to indicate it matches this |
| 2665 | // symbol file. |
| 2666 | return true; |
| 2667 | } |
| 2668 | |
| 2669 | clang::ASTContext *namespace_ast = namespace_decl->GetASTContext(); |
| 2670 | |
| 2671 | if (namespace_ast == NULL) |
| 2672 | return true; // No AST in the "namespace_decl", return true since it |
| 2673 | // could then match any symbol file, including this one |
| 2674 | |
| 2675 | if (namespace_ast == GetClangASTContext().getASTContext()) |
| 2676 | return true; // The ASTs match, return true |
| 2677 | |
| 2678 | // The namespace AST was valid, and it does not match... |
| Sean Callanan | c41e68b | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 2679 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 2680 | |
| 2681 | if (log) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2682 | GetObjectFile()->GetModule()->LogMessage(log.get(), "Valid namespace does not match symbol file"); |
| Sean Callanan | c41e68b | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 2683 | |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2684 | return false; |
| 2685 | } |
| 2686 | |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2687 | bool |
| 2688 | SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl, |
| 2689 | DWARFCompileUnit* cu, |
| 2690 | const DWARFDebugInfoEntry* die) |
| 2691 | { |
| 2692 | // No namespace specified, so the answesr i |
| 2693 | if (namespace_decl == NULL) |
| 2694 | return true; |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2695 | |
| 2696 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2697 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2698 | const DWARFDebugInfoEntry *decl_ctx_die = NULL; |
| 2699 | clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die); |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2700 | if (decl_ctx_die) |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2701 | { |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2702 | clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl(); |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2703 | |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2704 | if (clang_namespace_decl) |
| 2705 | { |
| 2706 | if (decl_ctx_die->Tag() != DW_TAG_namespace) |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2707 | { |
| 2708 | if (log) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2709 | 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] | 2710 | return false; |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2711 | } |
| 2712 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2713 | if (clang_namespace_decl == die_clang_decl_ctx) |
| 2714 | return true; |
| 2715 | else |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2716 | return false; |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2717 | } |
| 2718 | else |
| 2719 | { |
| 2720 | // We have a namespace_decl that was not NULL but it contained |
| 2721 | // a NULL "clang::NamespaceDecl", so this means the global namespace |
| 2722 | // So as long the the contained decl context DIE isn't a namespace |
| 2723 | // we should be ok. |
| 2724 | if (decl_ctx_die->Tag() != DW_TAG_namespace) |
| 2725 | return true; |
| 2726 | } |
| 2727 | } |
| Sean Callanan | ebe6067 | 2011-10-13 21:50:33 +0000 | [diff] [blame] | 2728 | |
| 2729 | if (log) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2730 | 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] | 2731 | |
| Greg Clayton | 2506a7a | 2011-10-12 23:34:26 +0000 | [diff] [blame] | 2732 | return false; |
| 2733 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2734 | uint32_t |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2735 | 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] | 2736 | { |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2737 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 2738 | |
| 2739 | if (log) |
| 2740 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2741 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 2742 | "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)", |
| 2743 | name.GetCString(), |
| 2744 | namespace_decl, |
| 2745 | append, |
| 2746 | max_matches); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2747 | } |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2748 | |
| 2749 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) |
| 2750 | return 0; |
| 2751 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2752 | DWARFDebugInfo* info = DebugInfo(); |
| 2753 | if (info == NULL) |
| 2754 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2755 | |
| 2756 | // If we aren't appending the results to this list, then clear the list |
| 2757 | if (!append) |
| 2758 | variables.Clear(); |
| 2759 | |
| 2760 | // Remember how many variables are in the list before we search in case |
| 2761 | // we are appending the results to a variable list. |
| 2762 | const uint32_t original_size = variables.GetSize(); |
| 2763 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2764 | DIEArray die_offsets; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2765 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2766 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2767 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2768 | if (m_apple_names_ap.get()) |
| 2769 | { |
| 2770 | const char *name_cstr = name.GetCString(); |
| 2771 | const char *base_name_start; |
| 2772 | const char *base_name_end = NULL; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2773 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2774 | if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end)) |
| 2775 | base_name_start = name_cstr; |
| 2776 | |
| 2777 | m_apple_names_ap->FindByName (base_name_start, die_offsets); |
| 2778 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2779 | } |
| 2780 | else |
| 2781 | { |
| 2782 | // Index the DWARF if we haven't already |
| 2783 | if (!m_indexed) |
| 2784 | Index (); |
| 2785 | |
| 2786 | m_global_index.Find (name, die_offsets); |
| 2787 | } |
| 2788 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2789 | const size_t num_die_matches = die_offsets.size(); |
| 2790 | if (num_die_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2791 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2792 | SymbolContext sc; |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 2793 | sc.module_sp = m_obj_file->GetModule(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2794 | assert (sc.module_sp); |
| 2795 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2796 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2797 | DWARFCompileUnit* dwarf_cu = NULL; |
| 2798 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2799 | bool done = false; |
| 2800 | for (size_t i=0; i<num_die_matches && !done; ++i) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2801 | { |
| 2802 | const dw_offset_t die_offset = die_offsets[i]; |
| 2803 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2804 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2805 | if (die) |
| 2806 | { |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2807 | switch (die->Tag()) |
| 2808 | { |
| 2809 | default: |
| 2810 | case DW_TAG_subprogram: |
| 2811 | case DW_TAG_inlined_subroutine: |
| 2812 | case DW_TAG_try_block: |
| 2813 | case DW_TAG_catch_block: |
| 2814 | break; |
| 2815 | |
| 2816 | case DW_TAG_variable: |
| 2817 | { |
| 2818 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2819 | |
| 2820 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 2821 | continue; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2822 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2823 | ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2824 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2825 | if (variables.GetSize() - original_size >= max_matches) |
| 2826 | done = true; |
| 2827 | } |
| 2828 | break; |
| 2829 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2830 | } |
| 2831 | else |
| 2832 | { |
| 2833 | if (m_using_apple_tables) |
| 2834 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2835 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n", |
| 2836 | die_offset, name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2837 | } |
| 2838 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2839 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2840 | } |
| 2841 | |
| 2842 | // Return the number of variable that were appended to the list |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2843 | const uint32_t num_matches = variables.GetSize() - original_size; |
| 2844 | if (log && num_matches > 0) |
| 2845 | { |
| 2846 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 2847 | "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u", |
| 2848 | name.GetCString(), |
| 2849 | namespace_decl, |
| 2850 | append, |
| 2851 | max_matches, |
| 2852 | num_matches); |
| 2853 | } |
| 2854 | return num_matches; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2855 | } |
| 2856 | |
| 2857 | uint32_t |
| 2858 | SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables) |
| 2859 | { |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2860 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 2861 | |
| 2862 | if (log) |
| 2863 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2864 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 2865 | "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)", |
| 2866 | regex.GetText(), |
| 2867 | append, |
| 2868 | max_matches); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2869 | } |
| 2870 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2871 | DWARFDebugInfo* info = DebugInfo(); |
| 2872 | if (info == NULL) |
| 2873 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2874 | |
| 2875 | // If we aren't appending the results to this list, then clear the list |
| 2876 | if (!append) |
| 2877 | variables.Clear(); |
| 2878 | |
| 2879 | // Remember how many variables are in the list before we search in case |
| 2880 | // we are appending the results to a variable list. |
| 2881 | const uint32_t original_size = variables.GetSize(); |
| 2882 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2883 | DIEArray die_offsets; |
| 2884 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2885 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2886 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2887 | if (m_apple_names_ap.get()) |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 2888 | { |
| 2889 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 2890 | if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) |
| 2891 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| 2892 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2893 | } |
| 2894 | else |
| 2895 | { |
| 2896 | // Index the DWARF if we haven't already |
| 2897 | if (!m_indexed) |
| 2898 | Index (); |
| 2899 | |
| 2900 | m_global_index.Find (regex, die_offsets); |
| 2901 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2902 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2903 | SymbolContext sc; |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 2904 | sc.module_sp = m_obj_file->GetModule(); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2905 | assert (sc.module_sp); |
| 2906 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2907 | DWARFCompileUnit* dwarf_cu = NULL; |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2908 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2909 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2910 | if (num_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2911 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2912 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2913 | for (size_t i=0; i<num_matches; ++i) |
| 2914 | { |
| 2915 | const dw_offset_t die_offset = die_offsets[i]; |
| 2916 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2917 | |
| 2918 | if (die) |
| 2919 | { |
| 2920 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2921 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2922 | ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2923 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2924 | if (variables.GetSize() - original_size >= max_matches) |
| 2925 | break; |
| 2926 | } |
| 2927 | else |
| 2928 | { |
| 2929 | if (m_using_apple_tables) |
| 2930 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2931 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n", |
| 2932 | die_offset, regex.GetText()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2933 | } |
| 2934 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2935 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2936 | } |
| 2937 | |
| 2938 | // Return the number of variable that were appended to the list |
| 2939 | return variables.GetSize() - original_size; |
| 2940 | } |
| 2941 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2942 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2943 | bool |
| 2944 | SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset, |
| 2945 | DWARFCompileUnit *&dwarf_cu, |
| 2946 | SymbolContextList& sc_list) |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2947 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2948 | const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| 2949 | return ResolveFunction (dwarf_cu, die, sc_list); |
| 2950 | } |
| 2951 | |
| 2952 | |
| 2953 | bool |
| 2954 | SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu, |
| 2955 | const DWARFDebugInfoEntry *die, |
| 2956 | SymbolContextList& sc_list) |
| 2957 | { |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2958 | SymbolContext sc; |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2959 | |
| 2960 | if (die == NULL) |
| 2961 | return false; |
| 2962 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2963 | // If we were passed a die that is not a function, just return false... |
| 2964 | if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine) |
| 2965 | return false; |
| 2966 | |
| 2967 | const DWARFDebugInfoEntry* inlined_die = NULL; |
| 2968 | if (die->Tag() == DW_TAG_inlined_subroutine) |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2969 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2970 | inlined_die = die; |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2971 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2972 | while ((die = die->GetParent()) != NULL) |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 2973 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2974 | if (die->Tag() == DW_TAG_subprogram) |
| 2975 | break; |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2976 | } |
| 2977 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2978 | assert (die->Tag() == DW_TAG_subprogram); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2979 | if (GetFunction (cu, die, sc)) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2980 | { |
| 2981 | Address addr; |
| 2982 | // Parse all blocks if needed |
| 2983 | if (inlined_die) |
| 2984 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 2985 | sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset())); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2986 | assert (sc.block != NULL); |
| 2987 | if (sc.block->GetStartAddress (addr) == false) |
| 2988 | addr.Clear(); |
| 2989 | } |
| 2990 | else |
| 2991 | { |
| 2992 | sc.block = NULL; |
| 2993 | addr = sc.function->GetAddressRange().GetBaseAddress(); |
| 2994 | } |
| 2995 | |
| 2996 | if (addr.IsValid()) |
| 2997 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2998 | sc_list.Append(sc); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2999 | return true; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3000 | } |
| 3001 | } |
| 3002 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3003 | return false; |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3004 | } |
| 3005 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3006 | void |
| 3007 | SymbolFileDWARF::FindFunctions (const ConstString &name, |
| 3008 | const NameToDIE &name_to_die, |
| 3009 | SymbolContextList& sc_list) |
| 3010 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3011 | DIEArray die_offsets; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3012 | if (name_to_die.Find (name, die_offsets)) |
| 3013 | { |
| 3014 | ParseFunctions (die_offsets, sc_list); |
| 3015 | } |
| 3016 | } |
| 3017 | |
| 3018 | |
| 3019 | void |
| 3020 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, |
| 3021 | const NameToDIE &name_to_die, |
| 3022 | SymbolContextList& sc_list) |
| 3023 | { |
| 3024 | DIEArray die_offsets; |
| 3025 | if (name_to_die.Find (regex, die_offsets)) |
| 3026 | { |
| 3027 | ParseFunctions (die_offsets, sc_list); |
| 3028 | } |
| 3029 | } |
| 3030 | |
| 3031 | |
| 3032 | void |
| 3033 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, |
| 3034 | const DWARFMappedHash::MemoryTable &memory_table, |
| 3035 | SymbolContextList& sc_list) |
| 3036 | { |
| 3037 | DIEArray die_offsets; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3038 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 3039 | if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3040 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3041 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3042 | ParseFunctions (die_offsets, sc_list); |
| 3043 | } |
| 3044 | } |
| 3045 | |
| 3046 | void |
| 3047 | SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets, |
| 3048 | SymbolContextList& sc_list) |
| 3049 | { |
| 3050 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3051 | if (num_matches) |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3052 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3053 | SymbolContext sc; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3054 | |
| 3055 | DWARFCompileUnit* dwarf_cu = NULL; |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3056 | for (size_t i=0; i<num_matches; ++i) |
| Greg Clayton | d7e0546 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 3057 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3058 | const dw_offset_t die_offset = die_offsets[i]; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3059 | ResolveFunction (die_offset, dwarf_cu, sc_list); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3060 | } |
| 3061 | } |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3062 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3063 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3064 | bool |
| 3065 | SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die, |
| 3066 | const DWARFCompileUnit *dwarf_cu, |
| 3067 | uint32_t name_type_mask, |
| 3068 | const char *partial_name, |
| 3069 | const char *base_name_start, |
| 3070 | const char *base_name_end) |
| 3071 | { |
| 3072 | // If we are looking only for methods, throw away all the ones that aren't in C++ classes: |
| 3073 | if (name_type_mask == eFunctionNameTypeMethod |
| 3074 | || name_type_mask == eFunctionNameTypeBase) |
| 3075 | { |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 3076 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset()); |
| 3077 | if (!containing_decl_ctx) |
| 3078 | return false; |
| 3079 | |
| 3080 | bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()); |
| 3081 | |
| 3082 | if (!is_cxx_method && name_type_mask == eFunctionNameTypeMethod) |
| 3083 | return false; |
| 3084 | if (is_cxx_method && name_type_mask == eFunctionNameTypeBase) |
| 3085 | return false; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3086 | } |
| 3087 | |
| 3088 | // Now we need to check whether the name we got back for this type matches the extra specifications |
| 3089 | // that were in the name we're looking up: |
| 3090 | if (base_name_start != partial_name || *base_name_end != '\0') |
| 3091 | { |
| 3092 | // First see if the stuff to the left matches the full name. To do that let's see if |
| 3093 | // we can pull out the mips linkage name attribute: |
| 3094 | |
| 3095 | Mangled best_name; |
| 3096 | |
| 3097 | DWARFDebugInfoEntry::Attributes attributes; |
| 3098 | die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| 3099 | uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name); |
| 3100 | if (idx != UINT32_MAX) |
| 3101 | { |
| 3102 | DWARFFormValue form_value; |
| 3103 | if (attributes.ExtractFormValueAtIndex(this, idx, form_value)) |
| 3104 | { |
| 3105 | const char *name = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 037520e | 2012-07-18 23:18:10 +0000 | [diff] [blame] | 3106 | best_name.SetValue (ConstString(name), true); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3107 | } |
| 3108 | } |
| 3109 | if (best_name) |
| 3110 | { |
| 3111 | const char *demangled = best_name.GetDemangledName().GetCString(); |
| 3112 | if (demangled) |
| 3113 | { |
| 3114 | std::string name_no_parens(partial_name, base_name_end - partial_name); |
| Jim Ingham | 85c13d7 | 2012-03-02 02:24:42 +0000 | [diff] [blame] | 3115 | const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str()); |
| 3116 | if (partial_in_demangled == NULL) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3117 | return false; |
| Jim Ingham | 85c13d7 | 2012-03-02 02:24:42 +0000 | [diff] [blame] | 3118 | else |
| 3119 | { |
| 3120 | // Sort out the case where our name is something like "Process::Destroy" and the match is |
| 3121 | // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on |
| 3122 | // namespace boundaries... |
| 3123 | |
| 3124 | if (partial_name[0] == ':' && partial_name[1] == ':') |
| 3125 | { |
| 3126 | // The partial name was already on a namespace boundary so all matches are good. |
| 3127 | return true; |
| 3128 | } |
| 3129 | else if (partial_in_demangled == demangled) |
| 3130 | { |
| 3131 | // They both start the same, so this is an good match. |
| 3132 | return true; |
| 3133 | } |
| 3134 | else |
| 3135 | { |
| 3136 | if (partial_in_demangled - demangled == 1) |
| 3137 | { |
| 3138 | // Only one character difference, can't be a namespace boundary... |
| 3139 | return false; |
| 3140 | } |
| 3141 | else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':') |
| 3142 | { |
| 3143 | // We are on a namespace boundary, so this is also good. |
| 3144 | return true; |
| 3145 | } |
| 3146 | else |
| 3147 | return false; |
| 3148 | } |
| 3149 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3150 | } |
| 3151 | } |
| 3152 | } |
| 3153 | |
| 3154 | return true; |
| 3155 | } |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3156 | |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3157 | uint32_t |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3158 | SymbolFileDWARF::FindFunctions (const ConstString &name, |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3159 | const lldb_private::ClangNamespaceDecl *namespace_decl, |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3160 | uint32_t name_type_mask, |
| 3161 | bool include_inlines, |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3162 | bool append, |
| 3163 | SymbolContextList& sc_list) |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3164 | { |
| 3165 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 3166 | "SymbolFileDWARF::FindFunctions (name = '%s')", |
| 3167 | name.AsCString()); |
| 3168 | |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3169 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 3170 | |
| 3171 | if (log) |
| 3172 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3173 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3174 | "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)", |
| 3175 | name.GetCString(), |
| 3176 | name_type_mask, |
| 3177 | append); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3178 | } |
| 3179 | |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3180 | // If we aren't appending the results to this list, then clear the list |
| 3181 | if (!append) |
| 3182 | sc_list.Clear(); |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3183 | |
| 3184 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) |
| 3185 | return 0; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3186 | |
| 3187 | // If name is empty then we won't find anything. |
| 3188 | if (name.IsEmpty()) |
| 3189 | return 0; |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3190 | |
| 3191 | // Remember how many sc_list are in the list before we search in case |
| 3192 | // we are appending the results to a variable list. |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3193 | |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 3194 | const uint32_t original_size = sc_list.GetSize(); |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 3195 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3196 | const char *name_cstr = name.GetCString(); |
| 3197 | uint32_t effective_name_type_mask = eFunctionNameTypeNone; |
| 3198 | const char *base_name_start = name_cstr; |
| 3199 | const char *base_name_end = name_cstr + strlen(name_cstr); |
| 3200 | |
| 3201 | if (name_type_mask & eFunctionNameTypeAuto) |
| 3202 | { |
| 3203 | if (CPPLanguageRuntime::IsCPPMangledName (name_cstr)) |
| 3204 | effective_name_type_mask = eFunctionNameTypeFull; |
| 3205 | else if (ObjCLanguageRuntime::IsPossibleObjCMethodName (name_cstr)) |
| 3206 | effective_name_type_mask = eFunctionNameTypeFull; |
| 3207 | else |
| 3208 | { |
| 3209 | if (ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr)) |
| 3210 | effective_name_type_mask |= eFunctionNameTypeSelector; |
| 3211 | |
| 3212 | if (CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end)) |
| 3213 | effective_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase); |
| 3214 | } |
| 3215 | } |
| 3216 | else |
| 3217 | { |
| 3218 | effective_name_type_mask = name_type_mask; |
| 3219 | if (effective_name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase) |
| 3220 | { |
| 3221 | // If they've asked for a CPP method or function name and it can't be that, we don't |
| 3222 | // even need to search for CPP methods or names. |
| 3223 | if (!CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end)) |
| 3224 | { |
| 3225 | effective_name_type_mask &= ~(eFunctionNameTypeMethod | eFunctionNameTypeBase); |
| 3226 | if (effective_name_type_mask == eFunctionNameTypeNone) |
| 3227 | return 0; |
| 3228 | } |
| 3229 | } |
| 3230 | |
| 3231 | if (effective_name_type_mask & eFunctionNameTypeSelector) |
| 3232 | { |
| 3233 | if (!ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr)) |
| 3234 | { |
| 3235 | effective_name_type_mask &= ~(eFunctionNameTypeSelector); |
| 3236 | if (effective_name_type_mask == eFunctionNameTypeNone) |
| 3237 | return 0; |
| 3238 | } |
| 3239 | } |
| 3240 | } |
| 3241 | |
| 3242 | DWARFDebugInfo* info = DebugInfo(); |
| 3243 | if (info == NULL) |
| 3244 | return 0; |
| 3245 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3246 | DWARFCompileUnit *dwarf_cu = NULL; |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3247 | if (m_using_apple_tables) |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 3248 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3249 | if (m_apple_names_ap.get()) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3250 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3251 | |
| 3252 | DIEArray die_offsets; |
| 3253 | |
| 3254 | uint32_t num_matches = 0; |
| 3255 | |
| 3256 | if (effective_name_type_mask & eFunctionNameTypeFull) |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3257 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3258 | // If they asked for the full name, match what they typed. At some point we may |
| 3259 | // want to canonicalize this (strip double spaces, etc. For now, we just add all the |
| 3260 | // dies that we find by exact match. |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3261 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3262 | for (uint32_t i = 0; i < num_matches; i++) |
| 3263 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3264 | const dw_offset_t die_offset = die_offsets[i]; |
| 3265 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3266 | if (die) |
| 3267 | { |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3268 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3269 | continue; |
| 3270 | |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3271 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) |
| 3272 | continue; |
| 3273 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3274 | ResolveFunction (dwarf_cu, die, sc_list); |
| 3275 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3276 | else |
| 3277 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3278 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 3279 | die_offset, name_cstr); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3280 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3281 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3282 | } |
| 3283 | else |
| 3284 | { |
| 3285 | if (effective_name_type_mask & eFunctionNameTypeSelector) |
| 3286 | { |
| 3287 | if (namespace_decl && *namespace_decl) |
| 3288 | return 0; // no selectors in namespaces |
| 3289 | |
| 3290 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); |
| 3291 | // Now make sure these are actually ObjC methods. In this case we can simply look up the name, |
| 3292 | // and if it is an ObjC method name, we're good. |
| 3293 | |
| 3294 | for (uint32_t i = 0; i < num_matches; i++) |
| 3295 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3296 | const dw_offset_t die_offset = die_offsets[i]; |
| 3297 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3298 | if (die) |
| 3299 | { |
| 3300 | const char *die_name = die->GetName(this, dwarf_cu); |
| 3301 | if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name)) |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3302 | { |
| 3303 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) |
| 3304 | continue; |
| 3305 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3306 | ResolveFunction (dwarf_cu, die, sc_list); |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3307 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3308 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3309 | else |
| 3310 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3311 | GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 3312 | die_offset, name_cstr); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3313 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3314 | } |
| 3315 | die_offsets.clear(); |
| 3316 | } |
| 3317 | |
| 3318 | if (effective_name_type_mask & eFunctionNameTypeMethod |
| 3319 | || effective_name_type_mask & eFunctionNameTypeBase) |
| 3320 | { |
| 3321 | if ((effective_name_type_mask & eFunctionNameTypeMethod) && |
| 3322 | (namespace_decl && *namespace_decl)) |
| 3323 | return 0; // no methods in namespaces |
| 3324 | |
| 3325 | // The apple_names table stores just the "base name" of C++ methods in the table. So we have to |
| 3326 | // extract the base name, look that up, and if there is any other information in the name we were |
| 3327 | // passed in we have to post-filter based on that. |
| 3328 | |
| 3329 | // FIXME: Arrange the logic above so that we don't calculate the base name twice: |
| 3330 | std::string base_name(base_name_start, base_name_end - base_name_start); |
| 3331 | num_matches = m_apple_names_ap->FindByName (base_name.c_str(), die_offsets); |
| 3332 | |
| 3333 | for (uint32_t i = 0; i < num_matches; i++) |
| 3334 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3335 | const dw_offset_t die_offset = die_offsets[i]; |
| 3336 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3337 | if (die) |
| 3338 | { |
| 3339 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3340 | continue; |
| 3341 | |
| 3342 | if (!FunctionDieMatchesPartialName(die, |
| 3343 | dwarf_cu, |
| 3344 | effective_name_type_mask, |
| 3345 | name_cstr, |
| 3346 | base_name_start, |
| 3347 | base_name_end)) |
| 3348 | continue; |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3349 | |
| 3350 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) |
| 3351 | continue; |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3352 | |
| 3353 | // If we get to here, the die is good, and we should add it: |
| 3354 | ResolveFunction (dwarf_cu, die, sc_list); |
| 3355 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3356 | else |
| 3357 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3358 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 3359 | die_offset, name_cstr); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3360 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3361 | } |
| 3362 | die_offsets.clear(); |
| 3363 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3364 | } |
| 3365 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3366 | } |
| 3367 | else |
| 3368 | { |
| 3369 | |
| 3370 | // Index the DWARF if we haven't already |
| 3371 | if (!m_indexed) |
| 3372 | Index (); |
| 3373 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3374 | if (name_type_mask & eFunctionNameTypeFull) |
| 3375 | FindFunctions (name, m_function_fullname_index, sc_list); |
| 3376 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3377 | std::string base_name(base_name_start, base_name_end - base_name_start); |
| 3378 | ConstString base_name_const(base_name.c_str()); |
| 3379 | DIEArray die_offsets; |
| 3380 | DWARFCompileUnit *dwarf_cu = NULL; |
| 3381 | |
| 3382 | if (effective_name_type_mask & eFunctionNameTypeBase) |
| 3383 | { |
| 3384 | 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] | 3385 | for (uint32_t i = 0; i < num_base; i++) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3386 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3387 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); |
| 3388 | if (die) |
| 3389 | { |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3390 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3391 | continue; |
| 3392 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3393 | if (!FunctionDieMatchesPartialName(die, |
| 3394 | dwarf_cu, |
| 3395 | effective_name_type_mask, |
| 3396 | name_cstr, |
| 3397 | base_name_start, |
| 3398 | base_name_end)) |
| 3399 | continue; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3400 | |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3401 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) |
| 3402 | continue; |
| 3403 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3404 | // If we get to here, the die is good, and we should add it: |
| 3405 | ResolveFunction (dwarf_cu, die, sc_list); |
| 3406 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3407 | } |
| 3408 | die_offsets.clear(); |
| 3409 | } |
| 3410 | |
| Jim Ingham | ea8005a | 2011-10-11 01:18:11 +0000 | [diff] [blame] | 3411 | if (effective_name_type_mask & eFunctionNameTypeMethod) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3412 | { |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3413 | if (namespace_decl && *namespace_decl) |
| 3414 | return 0; // no methods in namespaces |
| 3415 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3416 | uint32_t num_base = m_function_method_index.Find(base_name_const, die_offsets); |
| 3417 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3418 | for (uint32_t i = 0; i < num_base; i++) |
| 3419 | { |
| 3420 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); |
| 3421 | if (die) |
| 3422 | { |
| 3423 | if (!FunctionDieMatchesPartialName(die, |
| 3424 | dwarf_cu, |
| 3425 | effective_name_type_mask, |
| 3426 | name_cstr, |
| 3427 | base_name_start, |
| 3428 | base_name_end)) |
| 3429 | continue; |
| 3430 | |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3431 | if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) |
| 3432 | continue; |
| 3433 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 3434 | // If we get to here, the die is good, and we should add it: |
| 3435 | ResolveFunction (dwarf_cu, die, sc_list); |
| 3436 | } |
| 3437 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3438 | } |
| 3439 | die_offsets.clear(); |
| 3440 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3441 | |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3442 | if ((effective_name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl)) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3443 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3444 | FindFunctions (name, m_function_selector_index, sc_list); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3445 | } |
| 3446 | |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 3447 | } |
| 3448 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3449 | // Return the number of variable that were appended to the list |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3450 | const uint32_t num_matches = sc_list.GetSize() - original_size; |
| 3451 | |
| 3452 | if (log && num_matches > 0) |
| 3453 | { |
| 3454 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3455 | "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list) => %u", |
| 3456 | name.GetCString(), |
| 3457 | name_type_mask, |
| 3458 | append, |
| 3459 | num_matches); |
| 3460 | } |
| 3461 | return num_matches; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3462 | } |
| 3463 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3464 | uint32_t |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 3465 | 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] | 3466 | { |
| 3467 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 3468 | "SymbolFileDWARF::FindFunctions (regex = '%s')", |
| 3469 | regex.GetText()); |
| 3470 | |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3471 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 3472 | |
| 3473 | if (log) |
| 3474 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3475 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3476 | "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)", |
| 3477 | regex.GetText(), |
| 3478 | append); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3479 | } |
| 3480 | |
| 3481 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3482 | // If we aren't appending the results to this list, then clear the list |
| 3483 | if (!append) |
| 3484 | sc_list.Clear(); |
| 3485 | |
| 3486 | // Remember how many sc_list are in the list before we search in case |
| 3487 | // we are appending the results to a variable list. |
| 3488 | uint32_t original_size = sc_list.GetSize(); |
| 3489 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3490 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3491 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3492 | if (m_apple_names_ap.get()) |
| 3493 | FindFunctions (regex, *m_apple_names_ap, sc_list); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3494 | } |
| 3495 | else |
| 3496 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 3497 | // Index the DWARF if we haven't already |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3498 | if (!m_indexed) |
| 3499 | Index (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3500 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3501 | FindFunctions (regex, m_function_basename_index, sc_list); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3502 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3503 | FindFunctions (regex, m_function_fullname_index, sc_list); |
| 3504 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3505 | |
| 3506 | // Return the number of variable that were appended to the list |
| 3507 | return sc_list.GetSize() - original_size; |
| 3508 | } |
| Jim Ingham | 318c9f2 | 2011-08-26 19:44:13 +0000 | [diff] [blame] | 3509 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3510 | uint32_t |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3511 | SymbolFileDWARF::FindTypes (const SymbolContext& sc, |
| 3512 | const ConstString &name, |
| 3513 | const lldb_private::ClangNamespaceDecl *namespace_decl, |
| 3514 | bool append, |
| 3515 | uint32_t max_matches, |
| 3516 | TypeList& types) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3517 | { |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3518 | DWARFDebugInfo* info = DebugInfo(); |
| 3519 | if (info == NULL) |
| 3520 | return 0; |
| 3521 | |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3522 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 3523 | |
| 3524 | if (log) |
| 3525 | { |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3526 | if (namespace_decl) |
| 3527 | { |
| 3528 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3529 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)", |
| 3530 | name.GetCString(), |
| 3531 | namespace_decl->GetNamespaceDecl(), |
| 3532 | namespace_decl->GetQualifiedName().c_str(), |
| 3533 | append, |
| 3534 | max_matches); |
| 3535 | } |
| 3536 | else |
| 3537 | { |
| 3538 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3539 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)", |
| 3540 | name.GetCString(), |
| 3541 | append, |
| 3542 | max_matches); |
| 3543 | } |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3544 | } |
| 3545 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3546 | // If we aren't appending the results to this list, then clear the list |
| 3547 | if (!append) |
| 3548 | types.Clear(); |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3549 | |
| 3550 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) |
| 3551 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3552 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3553 | DIEArray die_offsets; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3554 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3555 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3556 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3557 | if (m_apple_types_ap.get()) |
| 3558 | { |
| 3559 | const char *name_cstr = name.GetCString(); |
| 3560 | m_apple_types_ap->FindByName (name_cstr, die_offsets); |
| 3561 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3562 | } |
| 3563 | else |
| 3564 | { |
| 3565 | if (!m_indexed) |
| 3566 | Index (); |
| 3567 | |
| 3568 | m_type_index.Find (name, die_offsets); |
| 3569 | } |
| 3570 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3571 | const size_t num_die_matches = die_offsets.size(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3572 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3573 | if (num_die_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3574 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3575 | const uint32_t initial_types_size = types.GetSize(); |
| 3576 | DWARFCompileUnit* dwarf_cu = NULL; |
| 3577 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3578 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3579 | for (size_t i=0; i<num_die_matches; ++i) |
| 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 | const dw_offset_t die_offset = die_offsets[i]; |
| 3582 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| 3583 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3584 | if (die) |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 3585 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3586 | if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) |
| 3587 | continue; |
| 3588 | |
| 3589 | Type *matching_type = ResolveType (dwarf_cu, die); |
| 3590 | if (matching_type) |
| 3591 | { |
| 3592 | // 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] | 3593 | types.InsertUnique (matching_type->shared_from_this()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3594 | if (types.GetSize() >= max_matches) |
| 3595 | break; |
| 3596 | } |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 3597 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3598 | else |
| 3599 | { |
| 3600 | if (m_using_apple_tables) |
| 3601 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3602 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 3603 | die_offset, name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3604 | } |
| 3605 | } |
| 3606 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3607 | } |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3608 | const uint32_t num_matches = types.GetSize() - initial_types_size; |
| 3609 | if (log && num_matches) |
| 3610 | { |
| 3611 | if (namespace_decl) |
| 3612 | { |
| 3613 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3614 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u", |
| 3615 | name.GetCString(), |
| 3616 | namespace_decl->GetNamespaceDecl(), |
| 3617 | namespace_decl->GetQualifiedName().c_str(), |
| 3618 | append, |
| 3619 | max_matches, |
| 3620 | num_matches); |
| 3621 | } |
| 3622 | else |
| 3623 | { |
| 3624 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3625 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u", |
| 3626 | name.GetCString(), |
| 3627 | append, |
| 3628 | max_matches, |
| 3629 | num_matches); |
| 3630 | } |
| 3631 | } |
| 3632 | return num_matches; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3633 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3634 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3635 | } |
| 3636 | |
| 3637 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3638 | ClangNamespaceDecl |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3639 | SymbolFileDWARF::FindNamespace (const SymbolContext& sc, |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3640 | const ConstString &name, |
| 3641 | const lldb_private::ClangNamespaceDecl *parent_namespace_decl) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3642 | { |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3643 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 3644 | |
| 3645 | if (log) |
| 3646 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3647 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3648 | "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")", |
| 3649 | name.GetCString()); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3650 | } |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3651 | |
| 3652 | if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl)) |
| 3653 | return ClangNamespaceDecl(); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3654 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3655 | ClangNamespaceDecl namespace_decl; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3656 | DWARFDebugInfo* info = DebugInfo(); |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3657 | if (info) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3658 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3659 | DIEArray die_offsets; |
| 3660 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3661 | // Index if we already haven't to make sure the compile units |
| 3662 | // get indexed and make their global DIE index list |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3663 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3664 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3665 | if (m_apple_namespaces_ap.get()) |
| 3666 | { |
| 3667 | const char *name_cstr = name.GetCString(); |
| 3668 | m_apple_namespaces_ap->FindByName (name_cstr, die_offsets); |
| 3669 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3670 | } |
| 3671 | else |
| 3672 | { |
| 3673 | if (!m_indexed) |
| 3674 | Index (); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3675 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3676 | m_namespace_index.Find (name, die_offsets); |
| 3677 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3678 | |
| 3679 | DWARFCompileUnit* dwarf_cu = NULL; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3680 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3681 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3682 | if (num_matches) |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3683 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3684 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3685 | for (size_t i=0; i<num_matches; ++i) |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3686 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3687 | const dw_offset_t die_offset = die_offsets[i]; |
| 3688 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3689 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3690 | if (die) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3691 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3692 | if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die)) |
| 3693 | continue; |
| 3694 | |
| 3695 | clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die); |
| 3696 | if (clang_namespace_decl) |
| 3697 | { |
| 3698 | namespace_decl.SetASTContext (GetClangASTContext().getASTContext()); |
| 3699 | namespace_decl.SetNamespaceDecl (clang_namespace_decl); |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3700 | break; |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3701 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3702 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3703 | else |
| 3704 | { |
| 3705 | if (m_using_apple_tables) |
| 3706 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3707 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n", |
| 3708 | die_offset, name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3709 | } |
| 3710 | } |
| 3711 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3712 | } |
| 3713 | } |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3714 | } |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3715 | if (log && namespace_decl.GetNamespaceDecl()) |
| 3716 | { |
| 3717 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 3718 | "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"", |
| 3719 | name.GetCString(), |
| 3720 | namespace_decl.GetNamespaceDecl(), |
| 3721 | namespace_decl.GetQualifiedName().c_str()); |
| 3722 | } |
| 3723 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3724 | return namespace_decl; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3725 | } |
| 3726 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3727 | uint32_t |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3728 | 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] | 3729 | { |
| 3730 | // Remember how many sc_list are in the list before we search in case |
| 3731 | // we are appending the results to a variable list. |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3732 | uint32_t original_size = types.GetSize(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3733 | |
| 3734 | const uint32_t num_die_offsets = die_offsets.size(); |
| 3735 | // Parse all of the types we found from the pubtypes matches |
| 3736 | uint32_t i; |
| 3737 | uint32_t num_matches = 0; |
| 3738 | for (i = 0; i < num_die_offsets; ++i) |
| 3739 | { |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3740 | Type *matching_type = ResolveTypeUID (die_offsets[i]); |
| 3741 | if (matching_type) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3742 | { |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3743 | // 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] | 3744 | types.InsertUnique (matching_type->shared_from_this()); |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3745 | ++num_matches; |
| 3746 | if (num_matches >= max_matches) |
| 3747 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3748 | } |
| 3749 | } |
| 3750 | |
| 3751 | // Return the number of variable that were appended to the list |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3752 | return types.GetSize() - original_size; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3753 | } |
| 3754 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3755 | |
| 3756 | size_t |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3757 | SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc, |
| 3758 | clang::DeclContext *containing_decl_ctx, |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3759 | DWARFCompileUnit* dwarf_cu, |
| 3760 | const DWARFDebugInfoEntry *parent_die, |
| 3761 | bool skip_artificial, |
| 3762 | bool &is_static, |
| 3763 | TypeList* type_list, |
| 3764 | std::vector<clang_type_t>& function_param_types, |
| 3765 | std::vector<clang::ParmVarDecl*>& function_param_decls, |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 3766 | unsigned &type_quals, |
| 3767 | ClangASTContext::TemplateParameterInfos &template_param_infos) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3768 | { |
| 3769 | if (parent_die == NULL) |
| 3770 | return 0; |
| 3771 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3772 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| 3773 | |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3774 | size_t arg_idx = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3775 | const DWARFDebugInfoEntry *die; |
| 3776 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 3777 | { |
| 3778 | dw_tag_t tag = die->Tag(); |
| 3779 | switch (tag) |
| 3780 | { |
| 3781 | case DW_TAG_formal_parameter: |
| 3782 | { |
| 3783 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3784 | 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] | 3785 | if (num_attributes > 0) |
| 3786 | { |
| 3787 | const char *name = NULL; |
| 3788 | Declaration decl; |
| 3789 | dw_offset_t param_type_die_offset = DW_INVALID_OFFSET; |
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 3790 | bool is_artificial = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3791 | // one of None, Auto, Register, Extern, Static, PrivateExtern |
| 3792 | |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 3793 | clang::StorageClass storage = clang::SC_None; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3794 | uint32_t i; |
| 3795 | for (i=0; i<num_attributes; ++i) |
| 3796 | { |
| 3797 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 3798 | DWARFFormValue form_value; |
| 3799 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 3800 | { |
| 3801 | switch (attr) |
| 3802 | { |
| 3803 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 3804 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 3805 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 3806 | case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; |
| 3807 | 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] | 3808 | case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3809 | case DW_AT_location: |
| 3810 | // if (form_value.BlockData()) |
| 3811 | // { |
| 3812 | // const DataExtractor& debug_info_data = debug_info(); |
| 3813 | // uint32_t block_length = form_value.Unsigned(); |
| 3814 | // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length); |
| 3815 | // } |
| 3816 | // else |
| 3817 | // { |
| 3818 | // } |
| 3819 | // break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3820 | case DW_AT_const_value: |
| 3821 | case DW_AT_default_value: |
| 3822 | case DW_AT_description: |
| 3823 | case DW_AT_endianity: |
| 3824 | case DW_AT_is_optional: |
| 3825 | case DW_AT_segment: |
| 3826 | case DW_AT_variable_parameter: |
| 3827 | default: |
| 3828 | case DW_AT_abstract_origin: |
| 3829 | case DW_AT_sibling: |
| 3830 | break; |
| 3831 | } |
| 3832 | } |
| 3833 | } |
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 3834 | |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3835 | bool skip = false; |
| 3836 | if (skip_artificial) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3837 | { |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3838 | if (is_artificial) |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3839 | { |
| 3840 | // In order to determine if a C++ member function is |
| 3841 | // "const" we have to look at the const-ness of "this"... |
| 3842 | // Ugly, but that |
| 3843 | if (arg_idx == 0) |
| 3844 | { |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 3845 | if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind())) |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 3846 | { |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3847 | // Often times compilers omit the "this" name for the |
| 3848 | // specification DIEs, so we can't rely upon the name |
| 3849 | // being in the formal parameter DIE... |
| 3850 | if (name == NULL || ::strcmp(name, "this")==0) |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3851 | { |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 3852 | Type *this_type = ResolveTypeUID (param_type_die_offset); |
| 3853 | if (this_type) |
| 3854 | { |
| 3855 | uint32_t encoding_mask = this_type->GetEncodingMask(); |
| 3856 | if (encoding_mask & Type::eEncodingIsPointerUID) |
| 3857 | { |
| 3858 | is_static = false; |
| 3859 | |
| 3860 | if (encoding_mask & (1u << Type::eEncodingIsConstUID)) |
| 3861 | type_quals |= clang::Qualifiers::Const; |
| 3862 | if (encoding_mask & (1u << Type::eEncodingIsVolatileUID)) |
| 3863 | type_quals |= clang::Qualifiers::Volatile; |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3864 | } |
| 3865 | } |
| 3866 | } |
| 3867 | } |
| 3868 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3869 | skip = true; |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3870 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3871 | else |
| 3872 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3873 | |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3874 | // HACK: Objective C formal parameters "self" and "_cmd" |
| 3875 | // are not marked as artificial in the DWARF... |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3876 | CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| 3877 | if (comp_unit) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3878 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3879 | switch (comp_unit->GetLanguage()) |
| 3880 | { |
| 3881 | case eLanguageTypeObjC: |
| 3882 | case eLanguageTypeObjC_plus_plus: |
| 3883 | if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0)) |
| 3884 | skip = true; |
| 3885 | break; |
| 3886 | default: |
| 3887 | break; |
| 3888 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3889 | } |
| 3890 | } |
| 3891 | } |
| 3892 | |
| 3893 | if (!skip) |
| 3894 | { |
| 3895 | Type *type = ResolveTypeUID(param_type_die_offset); |
| 3896 | if (type) |
| 3897 | { |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 3898 | function_param_types.push_back (type->GetClangForwardType()); |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3899 | |
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 3900 | clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name, |
| 3901 | type->GetClangForwardType(), |
| 3902 | storage); |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3903 | assert(param_var_decl); |
| 3904 | function_param_decls.push_back(param_var_decl); |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 3905 | |
| 3906 | GetClangASTContext().SetMetadata((uintptr_t)param_var_decl, MakeUserID(die->GetOffset())); |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3907 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3908 | } |
| 3909 | } |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3910 | arg_idx++; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3911 | } |
| 3912 | break; |
| 3913 | |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 3914 | case DW_TAG_template_type_parameter: |
| 3915 | case DW_TAG_template_value_parameter: |
| 3916 | ParseTemplateDIE (dwarf_cu, die,template_param_infos); |
| 3917 | break; |
| 3918 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3919 | default: |
| 3920 | break; |
| 3921 | } |
| 3922 | } |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 3923 | return arg_idx; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3924 | } |
| 3925 | |
| 3926 | size_t |
| 3927 | SymbolFileDWARF::ParseChildEnumerators |
| 3928 | ( |
| 3929 | const SymbolContext& sc, |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 3930 | clang_type_t enumerator_clang_type, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3931 | uint32_t enumerator_byte_size, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3932 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3933 | const DWARFDebugInfoEntry *parent_die |
| 3934 | ) |
| 3935 | { |
| 3936 | if (parent_die == NULL) |
| 3937 | return 0; |
| 3938 | |
| 3939 | size_t enumerators_added = 0; |
| 3940 | const DWARFDebugInfoEntry *die; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3941 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| 3942 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3943 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 3944 | { |
| 3945 | const dw_tag_t tag = die->Tag(); |
| 3946 | if (tag == DW_TAG_enumerator) |
| 3947 | { |
| 3948 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 3949 | 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] | 3950 | if (num_child_attributes > 0) |
| 3951 | { |
| 3952 | const char *name = NULL; |
| 3953 | bool got_value = false; |
| 3954 | int64_t enum_value = 0; |
| 3955 | Declaration decl; |
| 3956 | |
| 3957 | uint32_t i; |
| 3958 | for (i=0; i<num_child_attributes; ++i) |
| 3959 | { |
| 3960 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 3961 | DWARFFormValue form_value; |
| 3962 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 3963 | { |
| 3964 | switch (attr) |
| 3965 | { |
| 3966 | case DW_AT_const_value: |
| 3967 | got_value = true; |
| 3968 | enum_value = form_value.Unsigned(); |
| 3969 | break; |
| 3970 | |
| 3971 | case DW_AT_name: |
| 3972 | name = form_value.AsCString(&get_debug_str_data()); |
| 3973 | break; |
| 3974 | |
| 3975 | case DW_AT_description: |
| 3976 | default: |
| 3977 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 3978 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 3979 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 3980 | case DW_AT_sibling: |
| 3981 | break; |
| 3982 | } |
| 3983 | } |
| 3984 | } |
| 3985 | |
| 3986 | if (name && name[0] && got_value) |
| 3987 | { |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 3988 | GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type, |
| 3989 | enumerator_clang_type, |
| 3990 | decl, |
| 3991 | name, |
| 3992 | enum_value, |
| 3993 | enumerator_byte_size * 8); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3994 | ++enumerators_added; |
| 3995 | } |
| 3996 | } |
| 3997 | } |
| 3998 | } |
| 3999 | return enumerators_added; |
| 4000 | } |
| 4001 | |
| 4002 | void |
| 4003 | SymbolFileDWARF::ParseChildArrayInfo |
| 4004 | ( |
| 4005 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4006 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4007 | const DWARFDebugInfoEntry *parent_die, |
| 4008 | int64_t& first_index, |
| 4009 | std::vector<uint64_t>& element_orders, |
| 4010 | uint32_t& byte_stride, |
| 4011 | uint32_t& bit_stride |
| 4012 | ) |
| 4013 | { |
| 4014 | if (parent_die == NULL) |
| 4015 | return; |
| 4016 | |
| 4017 | const DWARFDebugInfoEntry *die; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4018 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4019 | for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 4020 | { |
| 4021 | const dw_tag_t tag = die->Tag(); |
| 4022 | switch (tag) |
| 4023 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4024 | case DW_TAG_subrange_type: |
| 4025 | { |
| 4026 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 4027 | 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] | 4028 | if (num_child_attributes > 0) |
| 4029 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4030 | uint64_t num_elements = 0; |
| 4031 | uint64_t lower_bound = 0; |
| 4032 | uint64_t upper_bound = 0; |
| 4033 | uint32_t i; |
| 4034 | for (i=0; i<num_child_attributes; ++i) |
| 4035 | { |
| 4036 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 4037 | DWARFFormValue form_value; |
| 4038 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 4039 | { |
| 4040 | switch (attr) |
| 4041 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4042 | case DW_AT_name: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4043 | break; |
| 4044 | |
| 4045 | case DW_AT_count: |
| 4046 | num_elements = form_value.Unsigned(); |
| 4047 | break; |
| 4048 | |
| 4049 | case DW_AT_bit_stride: |
| 4050 | bit_stride = form_value.Unsigned(); |
| 4051 | break; |
| 4052 | |
| 4053 | case DW_AT_byte_stride: |
| 4054 | byte_stride = form_value.Unsigned(); |
| 4055 | break; |
| 4056 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4057 | case DW_AT_lower_bound: |
| 4058 | lower_bound = form_value.Unsigned(); |
| 4059 | break; |
| 4060 | |
| 4061 | case DW_AT_upper_bound: |
| 4062 | upper_bound = form_value.Unsigned(); |
| 4063 | break; |
| 4064 | |
| 4065 | default: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4066 | case DW_AT_abstract_origin: |
| 4067 | case DW_AT_accessibility: |
| 4068 | case DW_AT_allocated: |
| 4069 | case DW_AT_associated: |
| 4070 | case DW_AT_data_location: |
| 4071 | case DW_AT_declaration: |
| 4072 | case DW_AT_description: |
| 4073 | case DW_AT_sibling: |
| 4074 | case DW_AT_threads_scaled: |
| 4075 | case DW_AT_type: |
| 4076 | case DW_AT_visibility: |
| 4077 | break; |
| 4078 | } |
| 4079 | } |
| 4080 | } |
| 4081 | |
| 4082 | if (upper_bound > lower_bound) |
| 4083 | num_elements = upper_bound - lower_bound + 1; |
| 4084 | |
| 4085 | if (num_elements > 0) |
| 4086 | element_orders.push_back (num_elements); |
| 4087 | } |
| 4088 | } |
| 4089 | break; |
| 4090 | } |
| 4091 | } |
| 4092 | } |
| 4093 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4094 | TypeSP |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4095 | SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4096 | { |
| 4097 | TypeSP type_sp; |
| 4098 | if (die != NULL) |
| 4099 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4100 | assert(dwarf_cu != NULL); |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 4101 | Type *type_ptr = m_die_to_type.lookup (die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4102 | if (type_ptr == NULL) |
| 4103 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4104 | CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4105 | assert (lldb_cu); |
| 4106 | SymbolContext sc(lldb_cu); |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4107 | type_sp = ParseType(sc, dwarf_cu, die, NULL); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4108 | } |
| 4109 | else if (type_ptr != DIE_IS_BEING_PARSED) |
| 4110 | { |
| 4111 | // Grab the existing type from the master types lists |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 4112 | type_sp = type_ptr->shared_from_this(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4113 | } |
| 4114 | |
| 4115 | } |
| 4116 | return type_sp; |
| 4117 | } |
| 4118 | |
| 4119 | clang::DeclContext * |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4120 | SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4121 | { |
| 4122 | if (die_offset != DW_INVALID_OFFSET) |
| 4123 | { |
| 4124 | DWARFCompileUnitSP cu_sp; |
| 4125 | const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4126 | return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4127 | } |
| 4128 | return NULL; |
| 4129 | } |
| 4130 | |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4131 | clang::DeclContext * |
| 4132 | SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset) |
| 4133 | { |
| 4134 | if (die_offset != DW_INVALID_OFFSET) |
| 4135 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4136 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 4137 | if (debug_info) |
| 4138 | { |
| 4139 | DWARFCompileUnitSP cu_sp; |
| 4140 | const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp); |
| 4141 | if (die) |
| 4142 | return GetClangDeclContextForDIE (sc, cu_sp.get(), die); |
| 4143 | } |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4144 | } |
| 4145 | return NULL; |
| 4146 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4147 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4148 | clang::NamespaceDecl * |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4149 | SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4150 | { |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4151 | if (die && die->Tag() == DW_TAG_namespace) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4152 | { |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4153 | // See if we already parsed this namespace DIE and associated it with a |
| 4154 | // uniqued namespace declaration |
| 4155 | clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]); |
| 4156 | if (namespace_decl) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4157 | return namespace_decl; |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4158 | else |
| 4159 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4160 | const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL); |
| 4161 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL); |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4162 | namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx); |
| 4163 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| 4164 | if (log) |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4165 | { |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4166 | if (namespace_name) |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4167 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4168 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 4169 | "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)", |
| 4170 | GetClangASTContext().getASTContext(), |
| 4171 | MakeUserID(die->GetOffset()), |
| 4172 | namespace_name, |
| 4173 | namespace_decl, |
| 4174 | namespace_decl->getOriginalNamespace()); |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4175 | } |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4176 | else |
| 4177 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4178 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 4179 | "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)", |
| 4180 | GetClangASTContext().getASTContext(), |
| 4181 | MakeUserID(die->GetOffset()), |
| 4182 | namespace_decl, |
| 4183 | namespace_decl->getOriginalNamespace()); |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4184 | } |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4185 | } |
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 4186 | |
| 4187 | if (namespace_decl) |
| 4188 | LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die); |
| 4189 | return namespace_decl; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 4190 | } |
| 4191 | } |
| 4192 | return NULL; |
| 4193 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4194 | |
| 4195 | clang::DeclContext * |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4196 | SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4197 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4198 | clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die); |
| 4199 | if (clang_decl_ctx) |
| 4200 | return clang_decl_ctx; |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4201 | // If this DIE has a specification, or an abstract origin, then trace to those. |
| 4202 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4203 | 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] | 4204 | if (die_offset != DW_INVALID_OFFSET) |
| 4205 | return GetClangDeclContextForDIEOffset (sc, die_offset); |
| 4206 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4207 | 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] | 4208 | if (die_offset != DW_INVALID_OFFSET) |
| 4209 | return GetClangDeclContextForDIEOffset (sc, die_offset); |
| 4210 | |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 4211 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| 4212 | if (log) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4213 | 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] | 4214 | // This is the DIE we want. Parse it, then query our map. |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 4215 | bool assert_not_being_parsed = true; |
| 4216 | ResolveTypeUID (cu, die, assert_not_being_parsed); |
| 4217 | |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4218 | clang_decl_ctx = GetCachedClangDeclContextForDIE (die); |
| 4219 | |
| 4220 | return clang_decl_ctx; |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 4221 | } |
| 4222 | |
| 4223 | clang::DeclContext * |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4224 | 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] | 4225 | { |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4226 | if (m_clang_tu_decl == NULL) |
| 4227 | m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4228 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4229 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4230 | |
| 4231 | if (decl_ctx_die_copy) |
| 4232 | *decl_ctx_die_copy = decl_ctx_die; |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4233 | |
| 4234 | if (decl_ctx_die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4235 | { |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 4236 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4237 | DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die); |
| 4238 | if (pos != m_die_to_decl_ctx.end()) |
| 4239 | return pos->second; |
| 4240 | |
| 4241 | switch (decl_ctx_die->Tag()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4242 | { |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4243 | case DW_TAG_compile_unit: |
| 4244 | return m_clang_tu_decl; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4245 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4246 | case DW_TAG_namespace: |
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 4247 | return ResolveNamespaceDIE (cu, decl_ctx_die); |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4248 | break; |
| 4249 | |
| 4250 | case DW_TAG_structure_type: |
| 4251 | case DW_TAG_union_type: |
| 4252 | case DW_TAG_class_type: |
| 4253 | { |
| 4254 | Type* type = ResolveType (cu, decl_ctx_die); |
| 4255 | if (type) |
| 4256 | { |
| 4257 | clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ()); |
| 4258 | if (decl_ctx) |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4259 | { |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4260 | LinkDeclContextToDIE (decl_ctx, decl_ctx_die); |
| 4261 | if (decl_ctx) |
| 4262 | return decl_ctx; |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4263 | } |
| 4264 | } |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4265 | } |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4266 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4267 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4268 | default: |
| 4269 | break; |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 4270 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4271 | } |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 4272 | return m_clang_tu_decl; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4273 | } |
| 4274 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 4275 | |
| 4276 | const DWARFDebugInfoEntry * |
| 4277 | SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) |
| 4278 | { |
| 4279 | if (cu && die) |
| 4280 | { |
| 4281 | const DWARFDebugInfoEntry * const decl_die = die; |
| 4282 | |
| 4283 | while (die != NULL) |
| 4284 | { |
| 4285 | // If this is the original DIE that we are searching for a declaration |
| 4286 | // for, then don't look in the cache as we don't want our own decl |
| 4287 | // context to be our decl context... |
| 4288 | if (decl_die != die) |
| 4289 | { |
| 4290 | switch (die->Tag()) |
| 4291 | { |
| 4292 | case DW_TAG_compile_unit: |
| 4293 | case DW_TAG_namespace: |
| 4294 | case DW_TAG_structure_type: |
| 4295 | case DW_TAG_union_type: |
| 4296 | case DW_TAG_class_type: |
| 4297 | return die; |
| 4298 | |
| 4299 | default: |
| 4300 | break; |
| 4301 | } |
| 4302 | } |
| 4303 | |
| 4304 | dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET); |
| 4305 | if (die_offset != DW_INVALID_OFFSET) |
| 4306 | { |
| 4307 | DWARFCompileUnit *spec_cu = cu; |
| 4308 | const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu); |
| 4309 | const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die); |
| 4310 | if (spec_die_decl_ctx_die) |
| 4311 | return spec_die_decl_ctx_die; |
| 4312 | } |
| 4313 | |
| 4314 | die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET); |
| 4315 | if (die_offset != DW_INVALID_OFFSET) |
| 4316 | { |
| 4317 | DWARFCompileUnit *abs_cu = cu; |
| 4318 | const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu); |
| 4319 | const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die); |
| 4320 | if (abs_die_decl_ctx_die) |
| 4321 | return abs_die_decl_ctx_die; |
| 4322 | } |
| 4323 | |
| 4324 | die = die->GetParent(); |
| 4325 | } |
| 4326 | } |
| 4327 | return NULL; |
| 4328 | } |
| 4329 | |
| 4330 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4331 | Symbol * |
| 4332 | SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name) |
| 4333 | { |
| 4334 | Symbol *objc_class_symbol = NULL; |
| 4335 | if (m_obj_file) |
| 4336 | { |
| 4337 | Symtab *symtab = m_obj_file->GetSymtab(); |
| 4338 | if (symtab) |
| 4339 | { |
| 4340 | objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name, |
| 4341 | eSymbolTypeObjCClass, |
| 4342 | Symtab::eDebugNo, |
| 4343 | Symtab::eVisibilityAny); |
| 4344 | } |
| 4345 | } |
| 4346 | return objc_class_symbol; |
| 4347 | } |
| 4348 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4349 | // Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't |
| 4350 | // then we can end up looking through all class types for a complete type and never find |
| 4351 | // the full definition. We need to know if this attribute is supported, so we determine |
| 4352 | // this here and cache th result. We also need to worry about the debug map DWARF file |
| 4353 | // if we are doing darwin DWARF in .o file debugging. |
| 4354 | bool |
| 4355 | SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu) |
| 4356 | { |
| 4357 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate) |
| 4358 | { |
| 4359 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo; |
| 4360 | if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type()) |
| 4361 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; |
| 4362 | else |
| 4363 | { |
| 4364 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 4365 | const uint32_t num_compile_units = GetNumCompileUnits(); |
| 4366 | for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) |
| 4367 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4368 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); |
| 4369 | 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] | 4370 | { |
| 4371 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; |
| 4372 | break; |
| 4373 | } |
| 4374 | } |
| 4375 | } |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 4376 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ()) |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4377 | return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this); |
| 4378 | } |
| 4379 | return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes; |
| 4380 | } |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4381 | |
| 4382 | // This function can be used when a DIE is found that is a forward declaration |
| 4383 | // DIE and we want to try and find a type that has the complete definition. |
| 4384 | TypeSP |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4385 | SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die, |
| 4386 | const ConstString &type_name, |
| 4387 | bool must_be_implementation) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4388 | { |
| 4389 | |
| 4390 | TypeSP type_sp; |
| 4391 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4392 | if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name))) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4393 | return type_sp; |
| 4394 | |
| 4395 | DIEArray die_offsets; |
| 4396 | |
| 4397 | if (m_using_apple_tables) |
| 4398 | { |
| 4399 | if (m_apple_types_ap.get()) |
| 4400 | { |
| 4401 | const char *name_cstr = type_name.GetCString(); |
| Greg Clayton | 68221ec | 2012-01-18 20:58:12 +0000 | [diff] [blame] | 4402 | m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4403 | } |
| 4404 | } |
| 4405 | else |
| 4406 | { |
| 4407 | if (!m_indexed) |
| 4408 | Index (); |
| 4409 | |
| 4410 | m_type_index.Find (type_name, die_offsets); |
| 4411 | } |
| 4412 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4413 | const size_t num_matches = die_offsets.size(); |
| 4414 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4415 | DWARFCompileUnit* type_cu = NULL; |
| 4416 | const DWARFDebugInfoEntry* type_die = NULL; |
| 4417 | if (num_matches) |
| 4418 | { |
| 4419 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 4420 | for (size_t i=0; i<num_matches; ++i) |
| 4421 | { |
| 4422 | const dw_offset_t die_offset = die_offsets[i]; |
| 4423 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); |
| 4424 | |
| 4425 | if (type_die) |
| 4426 | { |
| 4427 | bool try_resolving_type = false; |
| 4428 | |
| 4429 | // Don't try and resolve the DIE we are looking for with the DIE itself! |
| 4430 | if (type_die != die) |
| 4431 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4432 | switch (type_die->Tag()) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4433 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4434 | case DW_TAG_class_type: |
| 4435 | case DW_TAG_structure_type: |
| 4436 | try_resolving_type = true; |
| 4437 | break; |
| 4438 | default: |
| 4439 | break; |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4440 | } |
| 4441 | } |
| 4442 | |
| 4443 | if (try_resolving_type) |
| 4444 | { |
| Sean Callanan | a9bc065 | 2012-01-19 02:17:40 +0000 | [diff] [blame] | 4445 | 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] | 4446 | 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] | 4447 | |
| 4448 | if (try_resolving_type) |
| 4449 | { |
| 4450 | Type *resolved_type = ResolveType (type_cu, type_die, false); |
| 4451 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) |
| 4452 | { |
| 4453 | DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n", |
| 4454 | MakeUserID(die->GetOffset()), |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4455 | MakeUserID(dwarf_cu->GetOffset()), |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4456 | m_obj_file->GetFileSpec().GetFilename().AsCString(), |
| 4457 | MakeUserID(type_die->GetOffset()), |
| 4458 | MakeUserID(type_cu->GetOffset())); |
| 4459 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 4460 | if (die) |
| 4461 | m_die_to_type[die] = resolved_type; |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 4462 | type_sp = resolved_type->shared_from_this(); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4463 | break; |
| 4464 | } |
| 4465 | } |
| 4466 | } |
| 4467 | } |
| 4468 | else |
| 4469 | { |
| 4470 | if (m_using_apple_tables) |
| 4471 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4472 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 4473 | die_offset, type_name.GetCString()); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 4474 | } |
| 4475 | } |
| 4476 | |
| 4477 | } |
| 4478 | } |
| 4479 | return type_sp; |
| 4480 | } |
| 4481 | |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4482 | |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4483 | //---------------------------------------------------------------------- |
| 4484 | // This function helps to ensure that the declaration contexts match for |
| 4485 | // two different DIEs. Often times debug information will refer to a |
| 4486 | // forward declaration of a type (the equivalent of "struct my_struct;". |
| 4487 | // There will often be a declaration of that type elsewhere that has the |
| 4488 | // full definition. When we go looking for the full type "my_struct", we |
| 4489 | // will find one or more matches in the accelerator tables and we will |
| 4490 | // then need to make sure the type was in the same declaration context |
| 4491 | // as the original DIE. This function can efficiently compare two DIEs |
| 4492 | // and will return true when the declaration context matches, and false |
| 4493 | // when they don't. |
| 4494 | //---------------------------------------------------------------------- |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4495 | bool |
| 4496 | SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1, |
| 4497 | DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2) |
| 4498 | { |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4499 | if (die1 == die2) |
| 4500 | return true; |
| 4501 | |
| 4502 | #if defined (LLDB_CONFIGURATION_DEBUG) |
| 4503 | // You can't and shouldn't call this function with a compile unit from |
| 4504 | // two different SymbolFileDWARF instances. |
| 4505 | assert (DebugInfo()->ContainsCompileUnit (cu1)); |
| 4506 | assert (DebugInfo()->ContainsCompileUnit (cu2)); |
| 4507 | #endif |
| 4508 | |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4509 | DWARFDIECollection decl_ctx_1; |
| 4510 | DWARFDIECollection decl_ctx_2; |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4511 | //The declaration DIE stack is a stack of the declaration context |
| 4512 | // DIEs all the way back to the compile unit. If a type "T" is |
| 4513 | // declared inside a class "B", and class "B" is declared inside |
| 4514 | // a class "A" and class "A" is in a namespace "lldb", and the |
| 4515 | // namespace is in a compile unit, there will be a stack of DIEs: |
| 4516 | // |
| 4517 | // [0] DW_TAG_class_type for "B" |
| 4518 | // [1] DW_TAG_class_type for "A" |
| 4519 | // [2] DW_TAG_namespace for "lldb" |
| 4520 | // [3] DW_TAG_compile_unit for the source file. |
| 4521 | // |
| 4522 | // We grab both contexts and make sure that everything matches |
| 4523 | // all the way back to the compiler unit. |
| 4524 | |
| 4525 | // First lets grab the decl contexts for both DIEs |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4526 | die1->GetDeclContextDIEs (this, cu1, decl_ctx_1); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 4527 | die2->GetDeclContextDIEs (this, cu2, decl_ctx_2); |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4528 | // Make sure the context arrays have the same size, otherwise |
| 4529 | // we are done |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4530 | const size_t count1 = decl_ctx_1.Size(); |
| 4531 | const size_t count2 = decl_ctx_2.Size(); |
| 4532 | if (count1 != count2) |
| 4533 | return false; |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4534 | |
| 4535 | // Make sure the DW_TAG values match all the way back up the the |
| 4536 | // compile unit. If they don't, then we are done. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4537 | const DWARFDebugInfoEntry *decl_ctx_die1; |
| 4538 | const DWARFDebugInfoEntry *decl_ctx_die2; |
| 4539 | size_t i; |
| 4540 | for (i=0; i<count1; i++) |
| 4541 | { |
| 4542 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); |
| 4543 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); |
| 4544 | if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag()) |
| 4545 | return false; |
| 4546 | } |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4547 | #if defined LLDB_CONFIGURATION_DEBUG |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4548 | |
| 4549 | // Make sure the top item in the decl context die array is always |
| 4550 | // DW_TAG_compile_unit. If it isn't then something went wrong in |
| 4551 | // the DWARFDebugInfoEntry::GetDeclContextDIEs() function... |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4552 | assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit); |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4553 | |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4554 | #endif |
| 4555 | // Always skip the compile unit when comparing by only iterating up to |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4556 | // "count - 1". Here we compare the names as we go. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4557 | for (i=0; i<count1 - 1; i++) |
| 4558 | { |
| 4559 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); |
| 4560 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); |
| 4561 | const char *name1 = decl_ctx_die1->GetName(this, cu1); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 4562 | const char *name2 = decl_ctx_die2->GetName(this, cu2); |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4563 | // If the string was from a DW_FORM_strp, then the pointer will often |
| 4564 | // be the same! |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 4565 | if (name1 == name2) |
| 4566 | continue; |
| 4567 | |
| 4568 | // Name pointers are not equal, so only compare the strings |
| 4569 | // if both are not NULL. |
| 4570 | if (name1 && name2) |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4571 | { |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 4572 | // If the strings don't compare, we are done... |
| 4573 | if (strcmp(name1, name2) != 0) |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4574 | return false; |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 4575 | } |
| 4576 | else |
| 4577 | { |
| 4578 | // One name was NULL while the other wasn't |
| 4579 | return false; |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4580 | } |
| 4581 | } |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 4582 | // We made it through all of the checks and the declaration contexts |
| 4583 | // are equal. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4584 | return true; |
| 4585 | } |
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 4586 | |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4587 | // This function can be used when a DIE is found that is a forward declaration |
| 4588 | // 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] | 4589 | // "cu" and "die" must be from this SymbolFileDWARF |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4590 | TypeSP |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4591 | SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu, |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4592 | const DWARFDebugInfoEntry *die, |
| 4593 | const ConstString &type_name) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4594 | { |
| 4595 | TypeSP type_sp; |
| 4596 | |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4597 | #if defined (LLDB_CONFIGURATION_DEBUG) |
| 4598 | // You can't and shouldn't call this function with a compile unit from |
| 4599 | // another SymbolFileDWARF instance. |
| 4600 | assert (DebugInfo()->ContainsCompileUnit (cu)); |
| 4601 | #endif |
| 4602 | |
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 4603 | if (cu == NULL || die == NULL || !type_name) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4604 | return type_sp; |
| 4605 | |
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4606 | LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS)); |
| 4607 | if (log) |
| 4608 | { |
| 4609 | std::string qualified_name; |
| 4610 | die->GetQualifiedName(this, cu, qualified_name); |
| 4611 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 4612 | "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x (%s), name='%s')", |
| 4613 | die->GetOffset(), |
| 4614 | qualified_name.c_str(), |
| 4615 | type_name.GetCString()); |
| 4616 | } |
| 4617 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4618 | DIEArray die_offsets; |
| 4619 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4620 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4621 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4622 | if (m_apple_types_ap.get()) |
| 4623 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4624 | if (m_apple_types_ap->GetHeader().header_data.atoms.size() > 1) |
| 4625 | { |
| Greg Clayton | ae920b6 | 2012-01-06 00:17:16 +0000 | [diff] [blame] | 4626 | m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets); |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4627 | } |
| 4628 | else |
| 4629 | { |
| 4630 | m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets); |
| 4631 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 4632 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4633 | } |
| 4634 | else |
| 4635 | { |
| 4636 | if (!m_indexed) |
| 4637 | Index (); |
| 4638 | |
| 4639 | m_type_index.Find (type_name, die_offsets); |
| 4640 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4641 | |
| 4642 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | 6997489 | 2010-12-03 21:42:06 +0000 | [diff] [blame] | 4643 | |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4644 | const dw_tag_t die_tag = die->Tag(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4645 | |
| 4646 | DWARFCompileUnit* type_cu = NULL; |
| 4647 | const DWARFDebugInfoEntry* type_die = NULL; |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4648 | if (num_matches) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4649 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4650 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4651 | for (size_t i=0; i<num_matches; ++i) |
| 4652 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 4653 | const dw_offset_t die_offset = die_offsets[i]; |
| 4654 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4655 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4656 | if (type_die) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4657 | { |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4658 | bool try_resolving_type = false; |
| 4659 | |
| 4660 | // Don't try and resolve the DIE we are looking for with the DIE itself! |
| 4661 | if (type_die != die) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4662 | { |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4663 | const dw_tag_t type_die_tag = type_die->Tag(); |
| 4664 | // Make sure the tags match |
| 4665 | if (type_die_tag == die_tag) |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4666 | { |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4667 | // The tags match, lets try resolving this type |
| 4668 | try_resolving_type = true; |
| 4669 | } |
| 4670 | else |
| 4671 | { |
| 4672 | // The tags don't match, but we need to watch our for a |
| 4673 | // forward declaration for a struct and ("struct foo") |
| 4674 | // ends up being a class ("class foo { ... };") or |
| 4675 | // vice versa. |
| 4676 | switch (type_die_tag) |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4677 | { |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4678 | case DW_TAG_class_type: |
| 4679 | // We had a "class foo", see if we ended up with a "struct foo { ... };" |
| 4680 | try_resolving_type = (die_tag == DW_TAG_structure_type); |
| 4681 | break; |
| 4682 | case DW_TAG_structure_type: |
| 4683 | // We had a "struct foo", see if we ended up with a "class foo { ... };" |
| 4684 | try_resolving_type = (die_tag == DW_TAG_class_type); |
| 4685 | break; |
| 4686 | default: |
| 4687 | // Tags don't match, don't event try to resolve |
| 4688 | // using this type whose name matches.... |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4689 | break; |
| 4690 | } |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4691 | } |
| 4692 | } |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4693 | |
| 4694 | if (try_resolving_type) |
| 4695 | { |
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4696 | if (log) |
| 4697 | { |
| 4698 | std::string qualified_name; |
| 4699 | type_die->GetQualifiedName(this, cu, qualified_name); |
| 4700 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 4701 | "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') trying die=0x%8.8x (%s)", |
| 4702 | die->GetOffset(), |
| 4703 | type_name.GetCString(), |
| 4704 | type_die->GetOffset(), |
| 4705 | qualified_name.c_str()); |
| 4706 | } |
| 4707 | |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4708 | // Make sure the decl contexts match all the way up |
| 4709 | if (DIEDeclContextsMatch(cu, die, type_cu, type_die)) |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4710 | { |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4711 | Type *resolved_type = ResolveType (type_cu, type_die, false); |
| 4712 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) |
| 4713 | { |
| 4714 | DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n", |
| 4715 | MakeUserID(die->GetOffset()), |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 4716 | MakeUserID(dwarf_cu->GetOffset()), |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4717 | m_obj_file->GetFileSpec().GetFilename().AsCString(), |
| 4718 | MakeUserID(type_die->GetOffset()), |
| 4719 | MakeUserID(type_cu->GetOffset())); |
| 4720 | |
| 4721 | m_die_to_type[die] = resolved_type; |
| Greg Clayton | ff7692a | 2012-02-02 18:16:59 +0000 | [diff] [blame] | 4722 | type_sp = resolved_type->shared_from_this(); |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 4723 | break; |
| 4724 | } |
| Greg Clayton | 934cb05 | 2011-12-03 00:27:05 +0000 | [diff] [blame] | 4725 | } |
| 4726 | } |
| Greg Clayton | 9bbddbf | 2012-04-20 20:35:47 +0000 | [diff] [blame] | 4727 | else |
| 4728 | { |
| 4729 | if (log) |
| 4730 | { |
| 4731 | std::string qualified_name; |
| 4732 | type_die->GetQualifiedName(this, cu, qualified_name); |
| 4733 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 4734 | "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') ignoring die=0x%8.8x (%s)", |
| 4735 | die->GetOffset(), |
| 4736 | type_name.GetCString(), |
| 4737 | type_die->GetOffset(), |
| 4738 | qualified_name.c_str()); |
| 4739 | } |
| 4740 | } |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4741 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4742 | else |
| 4743 | { |
| 4744 | if (m_using_apple_tables) |
| 4745 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4746 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 4747 | die_offset, type_name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 4748 | } |
| 4749 | } |
| 4750 | |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 4751 | } |
| 4752 | } |
| 4753 | return type_sp; |
| 4754 | } |
| 4755 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4756 | TypeSP |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 4757 | SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx) |
| 4758 | { |
| 4759 | TypeSP type_sp; |
| 4760 | |
| 4761 | const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize(); |
| 4762 | if (dwarf_decl_ctx_count > 0) |
| 4763 | { |
| 4764 | const ConstString type_name(dwarf_decl_ctx[0].name); |
| 4765 | const dw_tag_t tag = dwarf_decl_ctx[0].tag; |
| 4766 | |
| 4767 | if (type_name) |
| 4768 | { |
| 4769 | LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS)); |
| 4770 | if (log) |
| 4771 | { |
| 4772 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 4773 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')", |
| 4774 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), |
| 4775 | dwarf_decl_ctx.GetQualifiedName()); |
| 4776 | } |
| 4777 | |
| 4778 | DIEArray die_offsets; |
| 4779 | |
| 4780 | if (m_using_apple_tables) |
| 4781 | { |
| 4782 | if (m_apple_types_ap.get()) |
| 4783 | { |
| 4784 | if (m_apple_types_ap->GetHeader().header_data.atoms.size() > 1) |
| 4785 | { |
| 4786 | m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets); |
| 4787 | } |
| 4788 | else |
| 4789 | { |
| 4790 | m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets); |
| 4791 | } |
| 4792 | } |
| 4793 | } |
| 4794 | else |
| 4795 | { |
| 4796 | if (!m_indexed) |
| 4797 | Index (); |
| 4798 | |
| 4799 | m_type_index.Find (type_name, die_offsets); |
| 4800 | } |
| 4801 | |
| 4802 | const size_t num_matches = die_offsets.size(); |
| 4803 | |
| 4804 | |
| 4805 | DWARFCompileUnit* type_cu = NULL; |
| 4806 | const DWARFDebugInfoEntry* type_die = NULL; |
| 4807 | if (num_matches) |
| 4808 | { |
| 4809 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 4810 | for (size_t i=0; i<num_matches; ++i) |
| 4811 | { |
| 4812 | const dw_offset_t die_offset = die_offsets[i]; |
| 4813 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); |
| 4814 | |
| 4815 | if (type_die) |
| 4816 | { |
| 4817 | bool try_resolving_type = false; |
| 4818 | |
| 4819 | // Don't try and resolve the DIE we are looking for with the DIE itself! |
| 4820 | const dw_tag_t type_tag = type_die->Tag(); |
| 4821 | // Make sure the tags match |
| 4822 | if (type_tag == tag) |
| 4823 | { |
| 4824 | // The tags match, lets try resolving this type |
| 4825 | try_resolving_type = true; |
| 4826 | } |
| 4827 | else |
| 4828 | { |
| 4829 | // The tags don't match, but we need to watch our for a |
| 4830 | // forward declaration for a struct and ("struct foo") |
| 4831 | // ends up being a class ("class foo { ... };") or |
| 4832 | // vice versa. |
| 4833 | switch (type_tag) |
| 4834 | { |
| 4835 | case DW_TAG_class_type: |
| 4836 | // We had a "class foo", see if we ended up with a "struct foo { ... };" |
| 4837 | try_resolving_type = (tag == DW_TAG_structure_type); |
| 4838 | break; |
| 4839 | case DW_TAG_structure_type: |
| 4840 | // We had a "struct foo", see if we ended up with a "class foo { ... };" |
| 4841 | try_resolving_type = (tag == DW_TAG_class_type); |
| 4842 | break; |
| 4843 | default: |
| 4844 | // Tags don't match, don't event try to resolve |
| 4845 | // using this type whose name matches.... |
| 4846 | break; |
| 4847 | } |
| 4848 | } |
| 4849 | |
| 4850 | if (try_resolving_type) |
| 4851 | { |
| 4852 | DWARFDeclContext type_dwarf_decl_ctx; |
| 4853 | type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx); |
| 4854 | |
| 4855 | if (log) |
| 4856 | { |
| 4857 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 4858 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)", |
| 4859 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), |
| 4860 | dwarf_decl_ctx.GetQualifiedName(), |
| 4861 | type_die->GetOffset(), |
| 4862 | type_dwarf_decl_ctx.GetQualifiedName()); |
| 4863 | } |
| 4864 | |
| 4865 | // Make sure the decl contexts match all the way up |
| 4866 | if (dwarf_decl_ctx == type_dwarf_decl_ctx) |
| 4867 | { |
| 4868 | Type *resolved_type = ResolveType (type_cu, type_die, false); |
| 4869 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) |
| 4870 | { |
| 4871 | type_sp = resolved_type->shared_from_this(); |
| 4872 | break; |
| 4873 | } |
| 4874 | } |
| 4875 | } |
| 4876 | else |
| 4877 | { |
| 4878 | if (log) |
| 4879 | { |
| 4880 | std::string qualified_name; |
| 4881 | type_die->GetQualifiedName(this, type_cu, qualified_name); |
| 4882 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 4883 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)", |
| 4884 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), |
| 4885 | dwarf_decl_ctx.GetQualifiedName(), |
| 4886 | type_die->GetOffset(), |
| 4887 | qualified_name.c_str()); |
| 4888 | } |
| 4889 | } |
| 4890 | } |
| 4891 | else |
| 4892 | { |
| 4893 | if (m_using_apple_tables) |
| 4894 | { |
| 4895 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 4896 | die_offset, type_name.GetCString()); |
| 4897 | } |
| 4898 | } |
| 4899 | |
| 4900 | } |
| 4901 | } |
| 4902 | } |
| 4903 | } |
| 4904 | return type_sp; |
| 4905 | } |
| 4906 | |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 4907 | bool |
| 4908 | SymbolFileDWARF::CopyUniqueClassMethodTypes (Type *class_type, |
| 4909 | DWARFCompileUnit* src_cu, |
| 4910 | const DWARFDebugInfoEntry *src_class_die, |
| 4911 | DWARFCompileUnit* dst_cu, |
| 4912 | const DWARFDebugInfoEntry *dst_class_die) |
| 4913 | { |
| 4914 | if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die) |
| 4915 | return false; |
| 4916 | if (src_class_die->Tag() != dst_class_die->Tag()) |
| 4917 | return false; |
| 4918 | |
| 4919 | // We need to complete the class type so we can get all of the method types |
| 4920 | // parsed so we can then unique those types to their equivalent counterparts |
| 4921 | // in "dst_cu" and "dst_class_die" |
| 4922 | class_type->GetClangFullType(); |
| 4923 | |
| 4924 | const DWARFDebugInfoEntry *src_die; |
| 4925 | const DWARFDebugInfoEntry *dst_die; |
| 4926 | UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die; |
| 4927 | UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die; |
| 4928 | for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling()) |
| 4929 | { |
| 4930 | if (src_die->Tag() == DW_TAG_subprogram) |
| 4931 | { |
| 4932 | const char *src_name = src_die->GetMangledName (this, src_cu); |
| 4933 | if (src_name) |
| 4934 | src_name_to_die.Append(ConstString(src_name).GetCString(), src_die); |
| 4935 | } |
| 4936 | } |
| 4937 | for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling()) |
| 4938 | { |
| 4939 | if (dst_die->Tag() == DW_TAG_subprogram) |
| 4940 | { |
| 4941 | const char *dst_name = dst_die->GetMangledName (this, dst_cu); |
| 4942 | if (dst_name) |
| 4943 | dst_name_to_die.Append(ConstString(dst_name).GetCString(), dst_die); |
| 4944 | } |
| 4945 | } |
| 4946 | const uint32_t src_size = src_name_to_die.GetSize (); |
| 4947 | const uint32_t dst_size = dst_name_to_die.GetSize (); |
| 4948 | LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION)); |
| 4949 | |
| 4950 | if (src_size && dst_size) |
| 4951 | { |
| Sean Callanan | 210b815 | 2012-07-07 00:29:33 +0000 | [diff] [blame] | 4952 | if (src_size != dst_size) |
| 4953 | { |
| 4954 | if (log) |
| 4955 | 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)", |
| 4956 | src_class_die->GetOffset(), |
| 4957 | dst_class_die->GetOffset(), |
| 4958 | src_size, |
| 4959 | dst_size); |
| 4960 | |
| 4961 | return false; |
| 4962 | } |
| 4963 | |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 4964 | uint32_t idx; |
| 4965 | for (idx = 0; idx < src_size; ++idx) |
| 4966 | { |
| 4967 | src_die = src_name_to_die.GetValueAtIndexUnchecked (idx); |
| 4968 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx); |
| 4969 | |
| 4970 | if (src_die->Tag() != dst_die->Tag()) |
| 4971 | { |
| 4972 | if (log) |
| 4973 | 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)", |
| 4974 | src_class_die->GetOffset(), |
| 4975 | dst_class_die->GetOffset(), |
| 4976 | src_die->GetOffset(), |
| 4977 | DW_TAG_value_to_name(src_die->Tag()), |
| 4978 | dst_die->GetOffset(), |
| 4979 | DW_TAG_value_to_name(src_die->Tag())); |
| 4980 | return false; |
| 4981 | } |
| 4982 | |
| 4983 | const char *src_name = src_die->GetMangledName (this, src_cu); |
| 4984 | const char *dst_name = dst_die->GetMangledName (this, dst_cu); |
| 4985 | |
| 4986 | // Make sure the names match |
| 4987 | if (src_name == dst_name || (strcmp (src_name, dst_name) == 0)) |
| 4988 | continue; |
| 4989 | |
| 4990 | if (log) |
| 4991 | 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)", |
| 4992 | src_class_die->GetOffset(), |
| 4993 | dst_class_die->GetOffset(), |
| 4994 | src_die->GetOffset(), |
| 4995 | src_name, |
| 4996 | dst_die->GetOffset(), |
| 4997 | dst_name); |
| 4998 | |
| 4999 | return false; |
| 5000 | } |
| 5001 | |
| 5002 | for (idx = 0; idx < src_size; ++idx) |
| 5003 | { |
| 5004 | src_die = src_name_to_die.GetValueAtIndexUnchecked (idx); |
| 5005 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx); |
| 5006 | |
| 5007 | clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die]; |
| 5008 | if (src_decl_ctx) |
| 5009 | { |
| 5010 | if (log) |
| 5011 | log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x\n", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset()); |
| 5012 | LinkDeclContextToDIE (src_decl_ctx, dst_die); |
| 5013 | } |
| 5014 | else |
| 5015 | { |
| 5016 | if (log) |
| 5017 | 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()); |
| 5018 | } |
| 5019 | |
| 5020 | Type *src_child_type = m_die_to_type[src_die]; |
| 5021 | if (src_child_type) |
| 5022 | { |
| 5023 | if (log) |
| 5024 | 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()); |
| 5025 | m_die_to_type[dst_die] = src_child_type; |
| 5026 | } |
| 5027 | else |
| 5028 | { |
| 5029 | if (log) |
| 5030 | 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()); |
| 5031 | } |
| 5032 | } |
| 5033 | return true; |
| 5034 | } |
| 5035 | else |
| 5036 | { |
| 5037 | if (log) |
| 5038 | 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", |
| 5039 | src_class_die->GetOffset(), |
| 5040 | dst_class_die->GetOffset(), |
| 5041 | src_die->GetOffset(), |
| 5042 | src_size, |
| 5043 | dst_die->GetOffset(), |
| 5044 | dst_size); |
| 5045 | } |
| 5046 | return false; |
| 5047 | } |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5048 | |
| 5049 | TypeSP |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5050 | 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] | 5051 | { |
| 5052 | TypeSP type_sp; |
| 5053 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5054 | if (type_is_new_ptr) |
| 5055 | *type_is_new_ptr = false; |
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5056 | |
| 5057 | #if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE) |
| 5058 | static DIEStack g_die_stack; |
| 5059 | DIEStack::ScopedPopper scoped_die_logger(g_die_stack); |
| 5060 | #endif |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5061 | |
| Sean Callanan | c7fbf73 | 2010-08-06 00:32:49 +0000 | [diff] [blame] | 5062 | AccessType accessibility = eAccessNone; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5063 | if (die != NULL) |
| 5064 | { |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 5065 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5066 | if (log) |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5067 | { |
| 5068 | const DWARFDebugInfoEntry *context_die; |
| 5069 | clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die); |
| 5070 | |
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5071 | 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] | 5072 | die->GetOffset(), |
| 5073 | context, |
| 5074 | context_die->GetOffset(), |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5075 | DW_TAG_value_to_name(die->Tag()), |
| Greg Clayton | 1fba8711 | 2012-02-09 20:03:49 +0000 | [diff] [blame] | 5076 | die->GetName(this, dwarf_cu)); |
| 5077 | |
| 5078 | #if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE) |
| 5079 | scoped_die_logger.Push (dwarf_cu, die); |
| 5080 | g_die_stack.LogDIEs(log.get(), this); |
| 5081 | #endif |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5082 | } |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5083 | // |
| 5084 | // LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| 5085 | // if (log && dwarf_cu) |
| 5086 | // { |
| 5087 | // StreamString s; |
| 5088 | // die->DumpLocation (this, dwarf_cu, s); |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5089 | // GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData()); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 5090 | // |
| 5091 | // } |
| Jim Ingham | 16746d1 | 2011-08-25 23:21:43 +0000 | [diff] [blame] | 5092 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5093 | Type *type_ptr = m_die_to_type.lookup (die); |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5094 | TypeList* type_list = GetTypeList(); |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5095 | if (type_ptr == NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5096 | { |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5097 | ClangASTContext &ast = GetClangASTContext(); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5098 | if (type_is_new_ptr) |
| 5099 | *type_is_new_ptr = true; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5100 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5101 | const dw_tag_t tag = die->Tag(); |
| 5102 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5103 | bool is_forward_declaration = false; |
| 5104 | DWARFDebugInfoEntry::Attributes attributes; |
| 5105 | const char *type_name_cstr = NULL; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5106 | ConstString type_name_const_str; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5107 | Type::ResolveState resolve_state = Type::eResolveStateUnresolved; |
| 5108 | size_t byte_size = 0; |
| 5109 | Declaration decl; |
| 5110 | |
| Greg Clayton | 4957bf6 | 2010-09-30 21:49:03 +0000 | [diff] [blame] | 5111 | Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5112 | clang_type_t clang_type = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5113 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5114 | dw_attr_t attr; |
| 5115 | |
| 5116 | switch (tag) |
| 5117 | { |
| 5118 | case DW_TAG_base_type: |
| 5119 | case DW_TAG_pointer_type: |
| 5120 | case DW_TAG_reference_type: |
| Sean Callanan | ce8af86 | 2012-05-21 23:31:51 +0000 | [diff] [blame] | 5121 | case DW_TAG_rvalue_reference_type: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5122 | case DW_TAG_typedef: |
| 5123 | case DW_TAG_const_type: |
| 5124 | case DW_TAG_restrict_type: |
| 5125 | case DW_TAG_volatile_type: |
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5126 | case DW_TAG_unspecified_type: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5127 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5128 | // 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] | 5129 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5130 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5131 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5132 | uint32_t encoding = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5133 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; |
| 5134 | |
| 5135 | if (num_attributes > 0) |
| 5136 | { |
| 5137 | uint32_t i; |
| 5138 | for (i=0; i<num_attributes; ++i) |
| 5139 | { |
| 5140 | attr = attributes.AttributeAtIndex(i); |
| 5141 | DWARFFormValue form_value; |
| 5142 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 5143 | { |
| 5144 | switch (attr) |
| 5145 | { |
| 5146 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 5147 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 5148 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 5149 | case DW_AT_name: |
| Jim Ingham | 337030f | 2011-04-15 23:41:23 +0000 | [diff] [blame] | 5150 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5151 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Jim Ingham | 337030f | 2011-04-15 23:41:23 +0000 | [diff] [blame] | 5152 | // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't |
| 5153 | // include the "&"... |
| 5154 | if (tag == DW_TAG_reference_type) |
| 5155 | { |
| 5156 | if (strchr (type_name_cstr, '&') == NULL) |
| 5157 | type_name_cstr = NULL; |
| 5158 | } |
| 5159 | if (type_name_cstr) |
| 5160 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5161 | break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 5162 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5163 | case DW_AT_encoding: encoding = form_value.Unsigned(); break; |
| 5164 | case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; |
| 5165 | default: |
| 5166 | case DW_AT_sibling: |
| 5167 | break; |
| 5168 | } |
| 5169 | } |
| 5170 | } |
| 5171 | } |
| 5172 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5173 | 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] | 5174 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5175 | switch (tag) |
| 5176 | { |
| 5177 | default: |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5178 | break; |
| 5179 | |
| Greg Clayton | d443641 | 2011-10-28 21:00:00 +0000 | [diff] [blame] | 5180 | case DW_TAG_unspecified_type: |
| 5181 | if (strcmp(type_name_cstr, "nullptr_t") == 0) |
| 5182 | { |
| 5183 | resolve_state = Type::eResolveStateFull; |
| 5184 | clang_type = ast.getASTContext()->NullPtrTy.getAsOpaquePtr(); |
| 5185 | break; |
| 5186 | } |
| 5187 | // Fall through to base type below in case we can handle the type there... |
| 5188 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5189 | case DW_TAG_base_type: |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5190 | resolve_state = Type::eResolveStateFull; |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5191 | clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr, |
| 5192 | encoding, |
| 5193 | byte_size * 8); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5194 | break; |
| 5195 | |
| Sean Callanan | ce8af86 | 2012-05-21 23:31:51 +0000 | [diff] [blame] | 5196 | case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break; |
| 5197 | case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break; |
| 5198 | case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break; |
| 5199 | case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break; |
| 5200 | case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break; |
| 5201 | case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break; |
| 5202 | case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5203 | } |
| 5204 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5205 | 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] | 5206 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5207 | if (type_name_cstr != NULL && sc.comp_unit != NULL && |
| 5208 | (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus)) |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 5209 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5210 | static ConstString g_objc_type_name_id("id"); |
| 5211 | static ConstString g_objc_type_name_Class("Class"); |
| 5212 | static ConstString g_objc_type_name_selector("SEL"); |
| 5213 | |
| 5214 | if (type_name_const_str == g_objc_type_name_id) |
| 5215 | { |
| 5216 | if (log) |
| 5217 | GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'id' built-in type.", |
| 5218 | die->GetOffset(), |
| 5219 | DW_TAG_value_to_name(die->Tag()), |
| 5220 | die->GetName(this, dwarf_cu)); |
| 5221 | clang_type = ast.GetBuiltInType_objc_id(); |
| 5222 | encoding_data_type = Type::eEncodingIsUID; |
| 5223 | encoding_uid = LLDB_INVALID_UID; |
| 5224 | resolve_state = Type::eResolveStateFull; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5225 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5226 | } |
| 5227 | else if (type_name_const_str == g_objc_type_name_Class) |
| 5228 | { |
| 5229 | if (log) |
| 5230 | GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'Class' built-in type.", |
| 5231 | die->GetOffset(), |
| 5232 | DW_TAG_value_to_name(die->Tag()), |
| 5233 | die->GetName(this, dwarf_cu)); |
| 5234 | clang_type = ast.GetBuiltInType_objc_Class(); |
| 5235 | encoding_data_type = Type::eEncodingIsUID; |
| 5236 | encoding_uid = LLDB_INVALID_UID; |
| 5237 | resolve_state = Type::eResolveStateFull; |
| 5238 | } |
| 5239 | else if (type_name_const_str == g_objc_type_name_selector) |
| 5240 | { |
| 5241 | if (log) |
| 5242 | GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'selector' built-in type.", |
| 5243 | die->GetOffset(), |
| 5244 | DW_TAG_value_to_name(die->Tag()), |
| 5245 | die->GetName(this, dwarf_cu)); |
| 5246 | clang_type = ast.GetBuiltInType_objc_selector(); |
| 5247 | encoding_data_type = Type::eEncodingIsUID; |
| 5248 | encoding_uid = LLDB_INVALID_UID; |
| 5249 | resolve_state = Type::eResolveStateFull; |
| 5250 | } |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 5251 | } |
| 5252 | } |
| 5253 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5254 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5255 | this, |
| 5256 | type_name_const_str, |
| 5257 | byte_size, |
| 5258 | NULL, |
| 5259 | encoding_uid, |
| 5260 | encoding_data_type, |
| 5261 | &decl, |
| 5262 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5263 | resolve_state)); |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5264 | |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 5265 | m_die_to_type[die] = type_sp.get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5266 | |
| 5267 | // Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false); |
| 5268 | // if (encoding_type != NULL) |
| 5269 | // { |
| 5270 | // if (encoding_type != DIE_IS_BEING_PARSED) |
| 5271 | // type_sp->SetEncodingType(encoding_type); |
| 5272 | // else |
| 5273 | // m_indirect_fixups.push_back(type_sp.get()); |
| 5274 | // } |
| 5275 | } |
| 5276 | break; |
| 5277 | |
| 5278 | case DW_TAG_structure_type: |
| 5279 | case DW_TAG_union_type: |
| 5280 | case DW_TAG_class_type: |
| 5281 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5282 | // 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] | 5283 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 5284 | bool byte_size_valid = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5285 | |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5286 | LanguageType class_language = eLanguageTypeUnknown; |
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 5287 | bool is_complete_objc_class = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5288 | //bool struct_is_class = false; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5289 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5290 | if (num_attributes > 0) |
| 5291 | { |
| 5292 | uint32_t i; |
| 5293 | for (i=0; i<num_attributes; ++i) |
| 5294 | { |
| 5295 | attr = attributes.AttributeAtIndex(i); |
| 5296 | DWARFFormValue form_value; |
| 5297 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 5298 | { |
| 5299 | switch (attr) |
| 5300 | { |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5301 | case DW_AT_decl_file: |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5302 | if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid()) |
| 5303 | { |
| 5304 | // llvm-gcc outputs invalid DW_AT_decl_file attributes that always |
| 5305 | // point to the compile unit file, so we clear this invalid value |
| 5306 | // so that we can still unique types efficiently. |
| 5307 | decl.SetFile(FileSpec ("<invalid>", false)); |
| 5308 | } |
| 5309 | else |
| 5310 | decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5311 | break; |
| 5312 | |
| 5313 | case DW_AT_decl_line: |
| 5314 | decl.SetLine(form_value.Unsigned()); |
| 5315 | break; |
| 5316 | |
| 5317 | case DW_AT_decl_column: |
| 5318 | decl.SetColumn(form_value.Unsigned()); |
| 5319 | break; |
| 5320 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5321 | case DW_AT_name: |
| 5322 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5323 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5324 | break; |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5325 | |
| 5326 | case DW_AT_byte_size: |
| 5327 | byte_size = form_value.Unsigned(); |
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 5328 | byte_size_valid = true; |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5329 | break; |
| 5330 | |
| 5331 | case DW_AT_accessibility: |
| 5332 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); |
| 5333 | break; |
| 5334 | |
| 5335 | case DW_AT_declaration: |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 5336 | is_forward_declaration = form_value.Unsigned() != 0; |
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5337 | break; |
| 5338 | |
| 5339 | case DW_AT_APPLE_runtime_class: |
| 5340 | class_language = (LanguageType)form_value.Signed(); |
| 5341 | break; |
| 5342 | |
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 5343 | case DW_AT_APPLE_objc_complete_type: |
| 5344 | is_complete_objc_class = form_value.Signed(); |
| 5345 | break; |
| 5346 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5347 | case DW_AT_allocated: |
| 5348 | case DW_AT_associated: |
| 5349 | case DW_AT_data_location: |
| 5350 | case DW_AT_description: |
| 5351 | case DW_AT_start_scope: |
| 5352 | case DW_AT_visibility: |
| 5353 | default: |
| 5354 | case DW_AT_sibling: |
| 5355 | break; |
| 5356 | } |
| 5357 | } |
| 5358 | } |
| 5359 | } |
| 5360 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5361 | UniqueDWARFASTType unique_ast_entry; |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5362 | |
| Greg Clayton | 123edca | 2012-03-02 00:07:15 +0000 | [diff] [blame] | 5363 | // Only try and unique the type if it has a name. |
| 5364 | if (type_name_const_str && |
| 5365 | GetUniqueDWARFASTTypeMap().Find (type_name_const_str, |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5366 | this, |
| 5367 | dwarf_cu, |
| 5368 | die, |
| 5369 | decl, |
| 5370 | byte_size_valid ? byte_size : -1, |
| 5371 | unique_ast_entry)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5372 | { |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5373 | // We have already parsed this type or from another |
| 5374 | // compile unit. GCC loves to use the "one definition |
| 5375 | // rule" which can result in multiple definitions |
| 5376 | // of the same class over and over in each compile |
| 5377 | // unit. |
| 5378 | type_sp = unique_ast_entry.m_type_sp; |
| 5379 | if (type_sp) |
| Greg Clayton | c615ce4 | 2010-11-09 04:42:43 +0000 | [diff] [blame] | 5380 | { |
| Sean Callanan | 8e8072d | 2012-02-07 21:13:38 +0000 | [diff] [blame] | 5381 | m_die_to_type[die] = type_sp.get(); |
| 5382 | return type_sp; |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5383 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5384 | } |
| 5385 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5386 | 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] | 5387 | |
| 5388 | int tag_decl_kind = -1; |
| 5389 | AccessType default_accessibility = eAccessNone; |
| 5390 | if (tag == DW_TAG_structure_type) |
| 5391 | { |
| 5392 | tag_decl_kind = clang::TTK_Struct; |
| 5393 | default_accessibility = eAccessPublic; |
| 5394 | } |
| 5395 | else if (tag == DW_TAG_union_type) |
| 5396 | { |
| 5397 | tag_decl_kind = clang::TTK_Union; |
| 5398 | default_accessibility = eAccessPublic; |
| 5399 | } |
| 5400 | else if (tag == DW_TAG_class_type) |
| 5401 | { |
| 5402 | tag_decl_kind = clang::TTK_Class; |
| 5403 | default_accessibility = eAccessPrivate; |
| 5404 | } |
| Greg Clayton | 3a5f29a | 2011-11-30 02:48:28 +0000 | [diff] [blame] | 5405 | |
| 5406 | if (byte_size_valid && byte_size == 0 && type_name_cstr && |
| 5407 | die->HasChildren() == false && |
| 5408 | sc.comp_unit->GetLanguage() == eLanguageTypeObjC) |
| 5409 | { |
| 5410 | // Work around an issue with clang at the moment where |
| 5411 | // forward declarations for objective C classes are emitted |
| 5412 | // as: |
| 5413 | // DW_TAG_structure_type [2] |
| 5414 | // DW_AT_name( "ForwardObjcClass" ) |
| 5415 | // DW_AT_byte_size( 0x00 ) |
| 5416 | // DW_AT_decl_file( "..." ) |
| 5417 | // DW_AT_decl_line( 1 ) |
| 5418 | // |
| 5419 | // Note that there is no DW_AT_declaration and there are |
| 5420 | // no children, and the byte size is zero. |
| 5421 | is_forward_declaration = true; |
| 5422 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5423 | |
| Sean Callanan | 7457f8d | 2012-04-25 01:03:57 +0000 | [diff] [blame] | 5424 | if (class_language == eLanguageTypeObjC || |
| 5425 | class_language == eLanguageTypeObjC_plus_plus) |
| Greg Clayton | 1877484 | 2011-11-29 23:40:34 +0000 | [diff] [blame] | 5426 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5427 | 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] | 5428 | { |
| 5429 | // We have a valid eSymbolTypeObjCClass class symbol whose |
| 5430 | // name matches the current objective C class that we |
| 5431 | // are trying to find and this DIE isn't the complete |
| 5432 | // definition (we checked is_complete_objc_class above and |
| 5433 | // know it is false), so the real definition is in here somewhere |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5434 | type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true); |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5435 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 5436 | if (!type_sp && GetDebugMapSymfile ()) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5437 | { |
| 5438 | // We weren't able to find a full declaration in |
| 5439 | // this DWARF, see if we have a declaration anywhere |
| 5440 | // else... |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5441 | 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] | 5442 | } |
| 5443 | |
| 5444 | if (type_sp) |
| 5445 | { |
| 5446 | if (log) |
| 5447 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5448 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 5449 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an incomplete objc type, complete type is 0x%8.8llx", |
| 5450 | this, |
| 5451 | die->GetOffset(), |
| 5452 | DW_TAG_value_to_name(tag), |
| 5453 | type_name_cstr, |
| 5454 | type_sp->GetID()); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 5455 | } |
| 5456 | |
| 5457 | // We found a real definition for this type elsewhere |
| 5458 | // so lets use it and cache the fact that we found |
| 5459 | // a complete type for this die |
| 5460 | m_die_to_type[die] = type_sp.get(); |
| 5461 | return type_sp; |
| 5462 | } |
| 5463 | } |
| 5464 | } |
| 5465 | |
| 5466 | |
| 5467 | if (is_forward_declaration) |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5468 | { |
| 5469 | // We have a forward declaration to a type and we need |
| 5470 | // to try and find a full declaration. We look in the |
| 5471 | // current type index just in case we have a forward |
| 5472 | // declaration followed by an actual declarations in the |
| 5473 | // DWARF. If this fails, we need to look elsewhere... |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 5474 | if (log) |
| 5475 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5476 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 5477 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type", |
| 5478 | this, |
| 5479 | die->GetOffset(), |
| 5480 | DW_TAG_value_to_name(tag), |
| 5481 | type_name_cstr); |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 5482 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5483 | |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5484 | DWARFDeclContext die_decl_ctx; |
| 5485 | die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx); |
| 5486 | |
| 5487 | //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str); |
| 5488 | type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5489 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 5490 | if (!type_sp && GetDebugMapSymfile ()) |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5491 | { |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5492 | // We weren't able to find a full declaration in |
| 5493 | // this DWARF, see if we have a declaration anywhere |
| 5494 | // else... |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 5495 | type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5496 | } |
| 5497 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5498 | if (type_sp) |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5499 | { |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 5500 | if (log) |
| 5501 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5502 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 5503 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8llx", |
| 5504 | this, |
| 5505 | die->GetOffset(), |
| 5506 | DW_TAG_value_to_name(tag), |
| 5507 | type_name_cstr, |
| 5508 | type_sp->GetID()); |
| Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 5509 | } |
| 5510 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5511 | // We found a real definition for this type elsewhere |
| 5512 | // so lets use it and cache the fact that we found |
| 5513 | // a complete type for this die |
| 5514 | m_die_to_type[die] = type_sp.get(); |
| 5515 | return type_sp; |
| Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 5516 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5517 | } |
| 5518 | assert (tag_decl_kind != -1); |
| 5519 | bool clang_type_was_created = false; |
| 5520 | clang_type = m_forward_decl_die_to_clang_type.lookup (die); |
| 5521 | if (clang_type == NULL) |
| 5522 | { |
| Sean Callanan | 4d04c6a | 2012-02-09 22:54:11 +0000 | [diff] [blame] | 5523 | const DWARFDebugInfoEntry *decl_ctx_die; |
| 5524 | |
| 5525 | clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die); |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 5526 | if (accessibility == eAccessNone && decl_ctx) |
| 5527 | { |
| 5528 | // Check the decl context that contains this class/struct/union. |
| 5529 | // If it is a class we must give it an accessability. |
| 5530 | const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind(); |
| 5531 | if (DeclKindIsCXXClass (containing_decl_kind)) |
| 5532 | accessibility = default_accessibility; |
| 5533 | } |
| 5534 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5535 | if (type_name_cstr && strchr (type_name_cstr, '<')) |
| 5536 | { |
| 5537 | ClangASTContext::TemplateParameterInfos template_param_infos; |
| 5538 | if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos)) |
| 5539 | { |
| 5540 | clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx, |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 5541 | accessibility, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5542 | type_name_cstr, |
| 5543 | tag_decl_kind, |
| 5544 | template_param_infos); |
| 5545 | |
| 5546 | clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx, |
| 5547 | class_template_decl, |
| 5548 | tag_decl_kind, |
| 5549 | template_param_infos); |
| 5550 | clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl); |
| 5551 | clang_type_was_created = true; |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 5552 | |
| 5553 | GetClangASTContext().SetMetadata((uintptr_t)class_template_decl, MakeUserID(die->GetOffset())); |
| 5554 | GetClangASTContext().SetMetadata((uintptr_t)class_specialization_decl, MakeUserID(die->GetOffset())); |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5555 | } |
| 5556 | } |
| 5557 | |
| 5558 | if (!clang_type_was_created) |
| 5559 | { |
| 5560 | clang_type_was_created = true; |
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 5561 | clang_type = ast.CreateRecordType (decl_ctx, |
| 5562 | accessibility, |
| 5563 | type_name_cstr, |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5564 | tag_decl_kind, |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 5565 | class_language, |
| Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 5566 | MakeUserID(die->GetOffset())); |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5567 | } |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5568 | } |
| 5569 | |
| 5570 | // Store a forward declaration to this class type in case any |
| 5571 | // parameters in any class methods need it for the clang |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 5572 | // types for function prototypes. |
| 5573 | LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5574 | type_sp.reset (new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5575 | this, |
| 5576 | type_name_const_str, |
| 5577 | byte_size, |
| 5578 | NULL, |
| 5579 | LLDB_INVALID_UID, |
| 5580 | Type::eEncodingIsUID, |
| 5581 | &decl, |
| 5582 | clang_type, |
| 5583 | Type::eResolveStateForward)); |
| Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 5584 | |
| 5585 | type_sp->SetIsCompleteObjCClass(is_complete_objc_class); |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5586 | |
| 5587 | |
| 5588 | // Add our type to the unique type map so we don't |
| 5589 | // end up creating many copies of the same type over |
| 5590 | // and over in the ASTContext for our module |
| 5591 | unique_ast_entry.m_type_sp = type_sp; |
| Greg Clayton | 3690964 | 2011-03-15 04:38:20 +0000 | [diff] [blame] | 5592 | unique_ast_entry.m_symfile = this; |
| 5593 | unique_ast_entry.m_cu = dwarf_cu; |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5594 | unique_ast_entry.m_die = die; |
| 5595 | unique_ast_entry.m_declaration = decl; |
| Sean Callanan | 5970059 | 2012-02-13 22:30:16 +0000 | [diff] [blame] | 5596 | unique_ast_entry.m_byte_size = byte_size; |
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 5597 | GetUniqueDWARFASTTypeMap().Insert (type_name_const_str, |
| 5598 | unique_ast_entry); |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 5599 | |
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 5600 | if (!is_forward_declaration) |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 5601 | { |
| 5602 | // Always start the definition for a class type so that |
| 5603 | // if the class has child classes or types that require |
| 5604 | // the class to be created for use as their decl contexts |
| 5605 | // the class will be ready to accept these child definitions. |
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 5606 | if (die->HasChildren() == false) |
| 5607 | { |
| 5608 | // No children for this struct/union/class, lets finish it |
| 5609 | ast.StartTagDeclarationDefinition (clang_type); |
| 5610 | ast.CompleteTagDeclarationDefinition (clang_type); |
| 5611 | } |
| 5612 | else if (clang_type_was_created) |
| 5613 | { |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 5614 | // Start the definition if the class is not objective C since |
| 5615 | // the underlying decls respond to isCompleteDefinition(). Objective |
| 5616 | // C decls dont' respond to isCompleteDefinition() so we can't |
| 5617 | // start the declaration definition right away. For C++ classs/union/structs |
| 5618 | // we want to start the definition in case the class is needed as the |
| 5619 | // declaration context for a contained class or type without the need |
| 5620 | // to complete that type.. |
| 5621 | |
| Sean Callanan | 7457f8d | 2012-04-25 01:03:57 +0000 | [diff] [blame] | 5622 | if (class_language != eLanguageTypeObjC && |
| 5623 | class_language != eLanguageTypeObjC_plus_plus) |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 5624 | ast.StartTagDeclarationDefinition (clang_type); |
| 5625 | |
| Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 5626 | // Leave this as a forward declaration until we need |
| 5627 | // to know the details of the type. lldb_private::Type |
| 5628 | // will automatically call the SymbolFile virtual function |
| 5629 | // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)" |
| 5630 | // When the definition needs to be defined. |
| 5631 | m_forward_decl_die_to_clang_type[die] = clang_type; |
| 5632 | m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die; |
| 5633 | ClangASTContext::SetHasExternalStorage (clang_type, true); |
| 5634 | } |
| Greg Clayton | c615ce4 | 2010-11-09 04:42:43 +0000 | [diff] [blame] | 5635 | } |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 5636 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5637 | } |
| 5638 | break; |
| 5639 | |
| 5640 | case DW_TAG_enumeration_type: |
| 5641 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5642 | // 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] | 5643 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5644 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5645 | lldb::user_id_t encoding_uid = DW_INVALID_OFFSET; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5646 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5647 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5648 | if (num_attributes > 0) |
| 5649 | { |
| 5650 | uint32_t i; |
| 5651 | |
| 5652 | for (i=0; i<num_attributes; ++i) |
| 5653 | { |
| 5654 | attr = attributes.AttributeAtIndex(i); |
| 5655 | DWARFFormValue form_value; |
| 5656 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 5657 | { |
| 5658 | switch (attr) |
| 5659 | { |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 5660 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 5661 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 5662 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5663 | case DW_AT_name: |
| 5664 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5665 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5666 | break; |
| Greg Clayton | 7a34528 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 5667 | case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 5668 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; |
| 5669 | case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
| 5670 | 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] | 5671 | case DW_AT_allocated: |
| 5672 | case DW_AT_associated: |
| 5673 | case DW_AT_bit_stride: |
| 5674 | case DW_AT_byte_stride: |
| 5675 | case DW_AT_data_location: |
| 5676 | case DW_AT_description: |
| 5677 | case DW_AT_start_scope: |
| 5678 | case DW_AT_visibility: |
| 5679 | case DW_AT_specification: |
| 5680 | case DW_AT_abstract_origin: |
| 5681 | case DW_AT_sibling: |
| 5682 | break; |
| 5683 | } |
| 5684 | } |
| 5685 | } |
| 5686 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5687 | 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] | 5688 | |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5689 | clang_type_t enumerator_clang_type = NULL; |
| 5690 | clang_type = m_forward_decl_die_to_clang_type.lookup (die); |
| 5691 | if (clang_type == NULL) |
| 5692 | { |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5693 | enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL, |
| 5694 | DW_ATE_signed, |
| 5695 | byte_size * 8); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 5696 | clang_type = ast.CreateEnumerationType (type_name_cstr, |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 5697 | GetClangDeclContextContainingDIE (dwarf_cu, die, NULL), |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 5698 | decl, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5699 | enumerator_clang_type); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5700 | } |
| 5701 | else |
| 5702 | { |
| 5703 | enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type); |
| 5704 | assert (enumerator_clang_type != NULL); |
| 5705 | } |
| 5706 | |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 5707 | LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die); |
| 5708 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5709 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5710 | this, |
| 5711 | type_name_const_str, |
| 5712 | byte_size, |
| 5713 | NULL, |
| 5714 | encoding_uid, |
| 5715 | Type::eEncodingIsUID, |
| 5716 | &decl, |
| 5717 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 5718 | Type::eResolveStateForward)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5719 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 5720 | ast.StartTagDeclarationDefinition (clang_type); |
| 5721 | if (die->HasChildren()) |
| 5722 | { |
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 5723 | SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); |
| 5724 | ParseChildEnumerators(cu_sc, clang_type, type_sp->GetByteSize(), dwarf_cu, die); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 5725 | } |
| 5726 | ast.CompleteTagDeclarationDefinition (clang_type); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5727 | } |
| 5728 | } |
| 5729 | break; |
| 5730 | |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 5731 | case DW_TAG_inlined_subroutine: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5732 | case DW_TAG_subprogram: |
| 5733 | case DW_TAG_subroutine_type: |
| 5734 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5735 | // 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] | 5736 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5737 | |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 5738 | //const char *mangled = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5739 | dw_offset_t type_die_offset = DW_INVALID_OFFSET; |
| Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 5740 | bool is_variadic = false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5741 | bool is_inline = false; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5742 | bool is_static = false; |
| 5743 | bool is_virtual = false; |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 5744 | bool is_explicit = false; |
| Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 5745 | bool is_artificial = false; |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5746 | dw_offset_t specification_die_offset = DW_INVALID_OFFSET; |
| 5747 | dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5748 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5749 | unsigned type_quals = 0; |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 5750 | clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5751 | |
| 5752 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 5753 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5754 | if (num_attributes > 0) |
| 5755 | { |
| 5756 | uint32_t i; |
| 5757 | for (i=0; i<num_attributes; ++i) |
| 5758 | { |
| Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 5759 | attr = attributes.AttributeAtIndex(i); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5760 | DWARFFormValue form_value; |
| 5761 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 5762 | { |
| 5763 | switch (attr) |
| 5764 | { |
| 5765 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 5766 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 5767 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 5768 | case DW_AT_name: |
| 5769 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5770 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5771 | break; |
| 5772 | |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 5773 | 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] | 5774 | 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] | 5775 | 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] | 5776 | 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] | 5777 | case DW_AT_inline: is_inline = form_value.Unsigned() != 0; break; |
| 5778 | case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break; |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 5779 | case DW_AT_explicit: is_explicit = form_value.Unsigned() != 0; break; |
| Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 5780 | case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break; |
| 5781 | |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 5782 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5783 | case DW_AT_external: |
| 5784 | if (form_value.Unsigned()) |
| 5785 | { |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 5786 | if (storage == clang::SC_None) |
| 5787 | storage = clang::SC_Extern; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5788 | else |
| Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 5789 | storage = clang::SC_PrivateExtern; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5790 | } |
| 5791 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5792 | |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5793 | case DW_AT_specification: |
| 5794 | specification_die_offset = form_value.Reference(dwarf_cu); |
| 5795 | break; |
| 5796 | |
| 5797 | case DW_AT_abstract_origin: |
| 5798 | abstract_origin_die_offset = form_value.Reference(dwarf_cu); |
| 5799 | break; |
| 5800 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5801 | case DW_AT_allocated: |
| 5802 | case DW_AT_associated: |
| 5803 | case DW_AT_address_class: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5804 | case DW_AT_calling_convention: |
| 5805 | case DW_AT_data_location: |
| 5806 | case DW_AT_elemental: |
| 5807 | case DW_AT_entry_pc: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5808 | case DW_AT_frame_base: |
| 5809 | case DW_AT_high_pc: |
| 5810 | case DW_AT_low_pc: |
| 5811 | case DW_AT_object_pointer: |
| 5812 | case DW_AT_prototyped: |
| 5813 | case DW_AT_pure: |
| 5814 | case DW_AT_ranges: |
| 5815 | case DW_AT_recursive: |
| 5816 | case DW_AT_return_addr: |
| 5817 | case DW_AT_segment: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5818 | case DW_AT_start_scope: |
| 5819 | case DW_AT_static_link: |
| 5820 | case DW_AT_trampoline: |
| 5821 | case DW_AT_visibility: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5822 | case DW_AT_vtable_elem_location: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5823 | case DW_AT_description: |
| 5824 | case DW_AT_sibling: |
| 5825 | break; |
| 5826 | } |
| 5827 | } |
| 5828 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5829 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5830 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 5831 | 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] | 5832 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5833 | clang_type_t return_clang_type = NULL; |
| 5834 | Type *func_type = NULL; |
| 5835 | |
| 5836 | if (type_die_offset != DW_INVALID_OFFSET) |
| 5837 | func_type = ResolveTypeUID(type_die_offset); |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 5838 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5839 | if (func_type) |
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 5840 | return_clang_type = func_type->GetClangForwardType(); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5841 | else |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5842 | return_clang_type = ast.GetBuiltInType_void(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5843 | |
| Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 5844 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5845 | std::vector<clang_type_t> function_param_types; |
| 5846 | std::vector<clang::ParmVarDecl*> function_param_decls; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5847 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5848 | // Parse the function children for the parameters |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 5849 | |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 5850 | const DWARFDebugInfoEntry *decl_ctx_die = NULL; |
| 5851 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die); |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 5852 | const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind(); |
| 5853 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5854 | const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind); |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 5855 | // Start off static. This will be set to false in ParseChildParameters(...) |
| 5856 | // if we find a "this" paramters as the first parameter |
| 5857 | if (is_cxx_method) |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 5858 | is_static = true; |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 5859 | ClangASTContext::TemplateParameterInfos template_param_infos; |
| 5860 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5861 | if (die->HasChildren()) |
| 5862 | { |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5863 | bool skip_artificial = true; |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5864 | ParseChildParameters (sc, |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 5865 | containing_decl_ctx, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5866 | dwarf_cu, |
| 5867 | die, |
| Sean Callanan | 763d72a | 2011-08-02 22:21:50 +0000 | [diff] [blame] | 5868 | skip_artificial, |
| 5869 | is_static, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5870 | type_list, |
| 5871 | function_param_types, |
| Greg Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 5872 | function_param_decls, |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 5873 | type_quals, |
| 5874 | template_param_infos); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5875 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5876 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5877 | // clang_type will get the function prototype clang type after this call |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 5878 | clang_type = ast.CreateFunctionType (return_clang_type, |
| 5879 | &function_param_types[0], |
| 5880 | function_param_types.size(), |
| 5881 | is_variadic, |
| 5882 | type_quals); |
| 5883 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5884 | if (type_name_cstr) |
| 5885 | { |
| 5886 | bool type_handled = false; |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5887 | if (tag == DW_TAG_subprogram) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5888 | { |
| Greg Clayton | 7c81042 | 2012-01-18 23:40:49 +0000 | [diff] [blame] | 5889 | ConstString class_name; |
| Greg Clayton | e42ae84 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 5890 | ConstString class_name_no_category; |
| 5891 | 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] | 5892 | { |
| Greg Clayton | e42ae84 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 5893 | // Use the class name with no category if there is one |
| 5894 | if (class_name_no_category) |
| 5895 | class_name = class_name_no_category; |
| 5896 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5897 | SymbolContext empty_sc; |
| 5898 | clang_type_t class_opaque_type = NULL; |
| Greg Clayton | 7c81042 | 2012-01-18 23:40:49 +0000 | [diff] [blame] | 5899 | if (class_name) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5900 | { |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5901 | TypeList types; |
| Greg Clayton | 278a16b | 2012-01-19 00:52:59 +0000 | [diff] [blame] | 5902 | TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false)); |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5903 | |
| 5904 | if (complete_objc_class_type_sp) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5905 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 5906 | clang_type_t type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType(); |
| 5907 | if (ClangASTContext::IsObjCClassType (type_clang_forward_type)) |
| 5908 | class_opaque_type = type_clang_forward_type; |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5909 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5910 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5911 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5912 | if (class_opaque_type) |
| 5913 | { |
| 5914 | // If accessibility isn't set to anything valid, assume public for |
| 5915 | // now... |
| 5916 | if (accessibility == eAccessNone) |
| 5917 | accessibility = eAccessPublic; |
| 5918 | |
| Sean Callanan | 464a5b5 | 2012-10-04 22:06:29 +0000 | [diff] [blame^] | 5919 | clang::ObjCMethodDecl *objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type, |
| 5920 | type_name_cstr, |
| 5921 | clang_type, |
| 5922 | accessibility); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5923 | type_handled = objc_method_decl != NULL; |
| Sean Callanan | 464a5b5 | 2012-10-04 22:06:29 +0000 | [diff] [blame^] | 5924 | if (type_handled) |
| 5925 | { |
| 5926 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die); |
| 5927 | GetClangASTContext().SetMetadata((uintptr_t)objc_method_decl, MakeUserID(die->GetOffset())); |
| 5928 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5929 | } |
| 5930 | } |
| Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 5931 | else if (is_cxx_method) |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5932 | { |
| 5933 | // Look at the parent of this DIE and see if is is |
| 5934 | // a class or struct and see if this is actually a |
| 5935 | // C++ method |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 5936 | Type *class_type = ResolveType (dwarf_cu, decl_ctx_die); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 5937 | if (class_type) |
| 5938 | { |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5939 | if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset())) |
| 5940 | { |
| 5941 | // We uniqued the parent class of this function to another class |
| 5942 | // so we now need to associate all dies under "decl_ctx_die" to |
| 5943 | // DIEs in the DIE for "class_type"... |
| 5944 | DWARFCompileUnitSP class_type_cu_sp; |
| 5945 | const DWARFDebugInfoEntry *class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp); |
| 5946 | if (class_type_die) |
| 5947 | { |
| 5948 | if (CopyUniqueClassMethodTypes (class_type, |
| 5949 | class_type_cu_sp.get(), |
| 5950 | class_type_die, |
| 5951 | dwarf_cu, |
| 5952 | decl_ctx_die)) |
| 5953 | { |
| 5954 | type_ptr = m_die_to_type[die]; |
| Greg Clayton | e5476db | 2012-06-01 20:32:35 +0000 | [diff] [blame] | 5955 | if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) |
| Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 5956 | { |
| 5957 | type_sp = type_ptr->shared_from_this(); |
| 5958 | break; |
| 5959 | } |
| 5960 | } |
| 5961 | } |
| 5962 | } |
| 5963 | |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5964 | if (specification_die_offset != DW_INVALID_OFFSET) |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 5965 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 5966 | // We have a specification which we are going to base our function |
| 5967 | // prototype off of, so we need this type to be completed so that the |
| 5968 | // m_die_to_decl_ctx for the method in the specification has a valid |
| 5969 | // clang decl context. |
| Greg Clayton | 8eb732e | 2011-12-13 04:34:06 +0000 | [diff] [blame] | 5970 | class_type->GetClangForwardType(); |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5971 | // If we have a specification, then the function type should have been |
| 5972 | // made with the specification and not with this die. |
| 5973 | DWARFCompileUnitSP spec_cu_sp; |
| 5974 | const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp); |
| Eric Christopher | 6cc6e60 | 2012-03-25 19:37:33 +0000 | [diff] [blame] | 5975 | clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die); |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 5976 | if (spec_clang_decl_ctx) |
| 5977 | { |
| 5978 | LinkDeclContextToDIE(spec_clang_decl_ctx, die); |
| 5979 | } |
| 5980 | else |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 5981 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 5982 | GetObjectFile()->GetModule()->ReportWarning ("0x%8.8llx: DW_AT_specification(0x%8.8x) has no decl\n", |
| 5983 | MakeUserID(die->GetOffset()), |
| 5984 | specification_die_offset); |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 5985 | } |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5986 | type_handled = true; |
| 5987 | } |
| 5988 | else if (abstract_origin_die_offset != DW_INVALID_OFFSET) |
| 5989 | { |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 5990 | // We have a specification which we are going to base our function |
| 5991 | // prototype off of, so we need this type to be completed so that the |
| 5992 | // m_die_to_decl_ctx for the method in the abstract origin has a valid |
| 5993 | // clang decl context. |
| Greg Clayton | 8eb732e | 2011-12-13 04:34:06 +0000 | [diff] [blame] | 5994 | class_type->GetClangForwardType(); |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 5995 | |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 5996 | DWARFCompileUnitSP abs_cu_sp; |
| 5997 | 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] | 5998 | clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die); |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 5999 | if (abs_clang_decl_ctx) |
| 6000 | { |
| 6001 | LinkDeclContextToDIE (abs_clang_decl_ctx, die); |
| 6002 | } |
| 6003 | else |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6004 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6005 | GetObjectFile()->GetModule()->ReportWarning ("0x%8.8llx: DW_AT_abstract_origin(0x%8.8x) has no decl\n", |
| 6006 | MakeUserID(die->GetOffset()), |
| 6007 | abstract_origin_die_offset); |
| Jim Ingham | c166304 | 2011-09-29 22:12:35 +0000 | [diff] [blame] | 6008 | } |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6009 | type_handled = true; |
| 6010 | } |
| 6011 | else |
| 6012 | { |
| 6013 | clang_type_t class_opaque_type = class_type->GetClangForwardType(); |
| 6014 | if (ClangASTContext::IsCXXClassType (class_opaque_type)) |
| Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 6015 | { |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6016 | if (ClangASTContext::IsBeingDefined (class_opaque_type)) |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6017 | { |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6018 | // Neither GCC 4.2 nor clang++ currently set a valid accessibility |
| 6019 | // in the DWARF for C++ methods... Default to public for now... |
| 6020 | if (accessibility == eAccessNone) |
| 6021 | accessibility = eAccessPublic; |
| 6022 | |
| 6023 | if (!is_static && !die->HasChildren()) |
| 6024 | { |
| 6025 | // We have a C++ member function with no children (this pointer!) |
| 6026 | // and clang will get mad if we try and make a function that isn't |
| 6027 | // well formed in the DWARF, so we will just skip it... |
| 6028 | type_handled = true; |
| 6029 | } |
| 6030 | else |
| 6031 | { |
| 6032 | clang::CXXMethodDecl *cxx_method_decl; |
| 6033 | // REMOVE THE CRASH DESCRIPTION BELOW |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6034 | 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] | 6035 | type_name_cstr, |
| 6036 | class_type->GetName().GetCString(), |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6037 | MakeUserID(die->GetOffset()), |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6038 | m_obj_file->GetFileSpec().GetDirectory().GetCString(), |
| 6039 | m_obj_file->GetFileSpec().GetFilename().GetCString()); |
| 6040 | |
| Sean Callanan | c1b732d | 2011-11-01 18:07:13 +0000 | [diff] [blame] | 6041 | const bool is_attr_used = false; |
| 6042 | |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6043 | cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type, |
| 6044 | type_name_cstr, |
| 6045 | clang_type, |
| 6046 | accessibility, |
| 6047 | is_virtual, |
| 6048 | is_static, |
| 6049 | is_inline, |
| Sean Callanan | c1b732d | 2011-11-01 18:07:13 +0000 | [diff] [blame] | 6050 | is_explicit, |
| Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 6051 | is_attr_used, |
| 6052 | is_artificial); |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6053 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die); |
| 6054 | |
| Greg Clayton | f49e65a | 2011-11-10 18:31:53 +0000 | [diff] [blame] | 6055 | Host::SetCrashDescription (NULL); |
| 6056 | |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6057 | type_handled = cxx_method_decl != NULL; |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 6058 | |
| 6059 | GetClangASTContext().SetMetadata((uintptr_t)cxx_method_decl, MakeUserID(die->GetOffset())); |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6060 | } |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6061 | } |
| 6062 | else |
| 6063 | { |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6064 | // We were asked to parse the type for a method in a class, yet the |
| 6065 | // class hasn't been asked to complete itself through the |
| 6066 | // clang::ExternalASTSource protocol, so we need to just have the |
| 6067 | // class complete itself and do things the right way, then our |
| 6068 | // DIE should then have an entry in the m_die_to_type map. First |
| 6069 | // we need to modify the m_die_to_type so it doesn't think we are |
| 6070 | // trying to parse this DIE anymore... |
| 6071 | m_die_to_type[die] = NULL; |
| 6072 | |
| 6073 | // Now we get the full type to force our class type to complete itself |
| 6074 | // using the clang::ExternalASTSource protocol which will parse all |
| 6075 | // base classes and all methods (including the method for this DIE). |
| 6076 | class_type->GetClangFullType(); |
| Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 6077 | |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6078 | // The type for this DIE should have been filled in the function call above |
| 6079 | type_ptr = m_die_to_type[die]; |
| Greg Clayton | e5476db | 2012-06-01 20:32:35 +0000 | [diff] [blame] | 6080 | if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6081 | { |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 6082 | type_sp = type_ptr->shared_from_this(); |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6083 | break; |
| 6084 | } |
| Sean Callanan | 02eee4d | 2012-04-12 23:10:00 +0000 | [diff] [blame] | 6085 | |
| 6086 | // FIXME This is fixing some even uglier behavior but we really need to |
| 6087 | // uniq the methods of each class as well as the class itself. |
| 6088 | // <rdar://problem/11240464> |
| 6089 | type_handled = true; |
| Greg Clayton | 72da397 | 2011-08-16 18:40:23 +0000 | [diff] [blame] | 6090 | } |
| Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 6091 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6092 | } |
| 6093 | } |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6094 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6095 | } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6096 | |
| 6097 | if (!type_handled) |
| 6098 | { |
| 6099 | // We just have a function that isn't part of a class |
| Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 6100 | clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (containing_decl_ctx, |
| 6101 | type_name_cstr, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6102 | clang_type, |
| 6103 | storage, |
| 6104 | is_inline); |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 6105 | |
| 6106 | // if (template_param_infos.GetSize() > 0) |
| 6107 | // { |
| 6108 | // clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx, |
| 6109 | // function_decl, |
| 6110 | // type_name_cstr, |
| 6111 | // template_param_infos); |
| 6112 | // |
| 6113 | // ast.CreateFunctionTemplateSpecializationInfo (function_decl, |
| 6114 | // func_template_decl, |
| 6115 | // template_param_infos); |
| 6116 | // } |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6117 | // Add the decl to our DIE to decl context map |
| 6118 | assert (function_decl); |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6119 | LinkDeclContextToDIE(function_decl, die); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6120 | if (!function_param_decls.empty()) |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6121 | ast.SetFunctionParameters (function_decl, |
| 6122 | &function_param_decls.front(), |
| 6123 | function_param_decls.size()); |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 6124 | |
| 6125 | GetClangASTContext().SetMetadata((uintptr_t)function_decl, MakeUserID(die->GetOffset())); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6126 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6127 | } |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6128 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6129 | this, |
| 6130 | type_name_const_str, |
| 6131 | 0, |
| 6132 | NULL, |
| 6133 | LLDB_INVALID_UID, |
| 6134 | Type::eEncodingIsUID, |
| 6135 | &decl, |
| 6136 | clang_type, |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6137 | Type::eResolveStateFull)); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6138 | assert(type_sp.get()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6139 | } |
| 6140 | break; |
| 6141 | |
| 6142 | case DW_TAG_array_type: |
| 6143 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6144 | // 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] | 6145 | m_die_to_type[die] = DIE_IS_BEING_PARSED; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6146 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6147 | lldb::user_id_t type_die_offset = DW_INVALID_OFFSET; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6148 | int64_t first_index = 0; |
| 6149 | uint32_t byte_stride = 0; |
| 6150 | uint32_t bit_stride = 0; |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6151 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6152 | |
| 6153 | if (num_attributes > 0) |
| 6154 | { |
| 6155 | uint32_t i; |
| 6156 | for (i=0; i<num_attributes; ++i) |
| 6157 | { |
| 6158 | attr = attributes.AttributeAtIndex(i); |
| 6159 | DWARFFormValue form_value; |
| 6160 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 6161 | { |
| 6162 | switch (attr) |
| 6163 | { |
| 6164 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 6165 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 6166 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 6167 | case DW_AT_name: |
| 6168 | type_name_cstr = form_value.AsCString(&get_debug_str_data()); |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 6169 | type_name_const_str.SetCString(type_name_cstr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6170 | break; |
| 6171 | |
| 6172 | 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] | 6173 | case DW_AT_byte_size: break; // byte_size = form_value.Unsigned(); break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6174 | case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break; |
| 6175 | case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6176 | case DW_AT_accessibility: break; // accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
| 6177 | 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] | 6178 | case DW_AT_allocated: |
| 6179 | case DW_AT_associated: |
| 6180 | case DW_AT_data_location: |
| 6181 | case DW_AT_description: |
| 6182 | case DW_AT_ordering: |
| 6183 | case DW_AT_start_scope: |
| 6184 | case DW_AT_visibility: |
| 6185 | case DW_AT_specification: |
| 6186 | case DW_AT_abstract_origin: |
| 6187 | case DW_AT_sibling: |
| 6188 | break; |
| 6189 | } |
| 6190 | } |
| 6191 | } |
| 6192 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6193 | 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] | 6194 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6195 | Type *element_type = ResolveTypeUID(type_die_offset); |
| 6196 | |
| 6197 | if (element_type) |
| 6198 | { |
| 6199 | std::vector<uint64_t> element_orders; |
| 6200 | ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride); |
| 6201 | if (byte_stride == 0 && bit_stride == 0) |
| 6202 | byte_stride = element_type->GetByteSize(); |
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 6203 | clang_type_t array_element_type = element_type->GetClangForwardType(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6204 | uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride; |
| 6205 | uint64_t num_elements = 0; |
| 6206 | std::vector<uint64_t>::const_reverse_iterator pos; |
| 6207 | std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend(); |
| 6208 | for (pos = element_orders.rbegin(); pos != end; ++pos) |
| 6209 | { |
| 6210 | num_elements = *pos; |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6211 | clang_type = ast.CreateArrayType (array_element_type, |
| 6212 | num_elements, |
| 6213 | num_elements * array_element_bit_stride); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6214 | array_element_type = clang_type; |
| 6215 | array_element_bit_stride = array_element_bit_stride * num_elements; |
| 6216 | } |
| 6217 | ConstString empty_name; |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6218 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6219 | this, |
| 6220 | empty_name, |
| 6221 | array_element_bit_stride / 8, |
| 6222 | NULL, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6223 | type_die_offset, |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6224 | Type::eEncodingIsUID, |
| 6225 | &decl, |
| 6226 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6227 | Type::eResolveStateFull)); |
| 6228 | type_sp->SetEncodingType (element_type); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6229 | } |
| 6230 | } |
| 6231 | } |
| 6232 | break; |
| 6233 | |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6234 | case DW_TAG_ptr_to_member_type: |
| 6235 | { |
| 6236 | dw_offset_t type_die_offset = DW_INVALID_OFFSET; |
| 6237 | dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET; |
| 6238 | |
| Greg Clayton | d88d759 | 2010-09-15 08:33:30 +0000 | [diff] [blame] | 6239 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6240 | |
| 6241 | if (num_attributes > 0) { |
| 6242 | uint32_t i; |
| 6243 | for (i=0; i<num_attributes; ++i) |
| 6244 | { |
| 6245 | attr = attributes.AttributeAtIndex(i); |
| 6246 | DWARFFormValue form_value; |
| 6247 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| 6248 | { |
| 6249 | switch (attr) |
| 6250 | { |
| 6251 | case DW_AT_type: |
| 6252 | type_die_offset = form_value.Reference(dwarf_cu); break; |
| 6253 | case DW_AT_containing_type: |
| 6254 | containing_type_die_offset = form_value.Reference(dwarf_cu); break; |
| 6255 | } |
| 6256 | } |
| 6257 | } |
| 6258 | |
| 6259 | Type *pointee_type = ResolveTypeUID(type_die_offset); |
| 6260 | Type *class_type = ResolveTypeUID(containing_type_die_offset); |
| 6261 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6262 | clang_type_t pointee_clang_type = pointee_type->GetClangForwardType(); |
| 6263 | clang_type_t class_clang_type = class_type->GetClangLayoutType(); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6264 | |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6265 | clang_type = ast.CreateMemberPointerType(pointee_clang_type, |
| 6266 | class_clang_type); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6267 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6268 | byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(), |
| 6269 | clang_type) / 8; |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6270 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6271 | type_sp.reset( new Type (MakeUserID(die->GetOffset()), |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 6272 | this, |
| 6273 | type_name_const_str, |
| 6274 | byte_size, |
| 6275 | NULL, |
| 6276 | LLDB_INVALID_UID, |
| 6277 | Type::eEncodingIsUID, |
| 6278 | NULL, |
| 6279 | clang_type, |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 6280 | Type::eResolveStateForward)); |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6281 | } |
| 6282 | |
| 6283 | break; |
| 6284 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6285 | default: |
| Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 6286 | assert(false && "Unhandled type tag!"); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6287 | break; |
| 6288 | } |
| 6289 | |
| 6290 | if (type_sp.get()) |
| 6291 | { |
| 6292 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); |
| 6293 | dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
| 6294 | |
| 6295 | SymbolContextScope * symbol_context_scope = NULL; |
| 6296 | if (sc_parent_tag == DW_TAG_compile_unit) |
| 6297 | { |
| 6298 | symbol_context_scope = sc.comp_unit; |
| 6299 | } |
| 6300 | else if (sc.function != NULL) |
| 6301 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6302 | 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] | 6303 | if (symbol_context_scope == NULL) |
| 6304 | symbol_context_scope = sc.function; |
| 6305 | } |
| 6306 | |
| 6307 | if (symbol_context_scope != NULL) |
| 6308 | { |
| 6309 | type_sp->SetSymbolContextScope(symbol_context_scope); |
| 6310 | } |
| 6311 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6312 | // We are ready to put this type into the uniqued list up at the module level |
| 6313 | type_list->Insert (type_sp); |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 6314 | |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 6315 | m_die_to_type[die] = type_sp.get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6316 | } |
| 6317 | } |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 6318 | else if (type_ptr != DIE_IS_BEING_PARSED) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6319 | { |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 6320 | type_sp = type_ptr->shared_from_this(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6321 | } |
| 6322 | } |
| 6323 | return type_sp; |
| 6324 | } |
| 6325 | |
| 6326 | size_t |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6327 | SymbolFileDWARF::ParseTypes |
| 6328 | ( |
| 6329 | const SymbolContext& sc, |
| 6330 | DWARFCompileUnit* dwarf_cu, |
| 6331 | const DWARFDebugInfoEntry *die, |
| 6332 | bool parse_siblings, |
| 6333 | bool parse_children |
| 6334 | ) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6335 | { |
| 6336 | size_t types_added = 0; |
| 6337 | while (die != NULL) |
| 6338 | { |
| 6339 | bool type_is_new = false; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6340 | if (ParseType(sc, dwarf_cu, die, &type_is_new).get()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6341 | { |
| 6342 | if (type_is_new) |
| 6343 | ++types_added; |
| 6344 | } |
| 6345 | |
| 6346 | if (parse_children && die->HasChildren()) |
| 6347 | { |
| 6348 | if (die->Tag() == DW_TAG_subprogram) |
| 6349 | { |
| 6350 | SymbolContext child_sc(sc); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6351 | child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6352 | types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true); |
| 6353 | } |
| 6354 | else |
| 6355 | types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true); |
| 6356 | } |
| 6357 | |
| 6358 | if (parse_siblings) |
| 6359 | die = die->GetSibling(); |
| 6360 | else |
| 6361 | die = NULL; |
| 6362 | } |
| 6363 | return types_added; |
| 6364 | } |
| 6365 | |
| 6366 | |
| 6367 | size_t |
| 6368 | SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc) |
| 6369 | { |
| 6370 | assert(sc.comp_unit && sc.function); |
| 6371 | size_t functions_added = 0; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 6372 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6373 | if (dwarf_cu) |
| 6374 | { |
| 6375 | dw_offset_t function_die_offset = sc.function->GetID(); |
| 6376 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset); |
| 6377 | if (function_die) |
| 6378 | { |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 6379 | 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] | 6380 | } |
| 6381 | } |
| 6382 | |
| 6383 | return functions_added; |
| 6384 | } |
| 6385 | |
| 6386 | |
| 6387 | size_t |
| 6388 | SymbolFileDWARF::ParseTypes (const SymbolContext &sc) |
| 6389 | { |
| 6390 | // At least a compile unit must be valid |
| 6391 | assert(sc.comp_unit); |
| 6392 | size_t types_added = 0; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 6393 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6394 | if (dwarf_cu) |
| 6395 | { |
| 6396 | if (sc.function) |
| 6397 | { |
| 6398 | dw_offset_t function_die_offset = sc.function->GetID(); |
| 6399 | const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset); |
| 6400 | if (func_die && func_die->HasChildren()) |
| 6401 | { |
| 6402 | types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true); |
| 6403 | } |
| 6404 | } |
| 6405 | else |
| 6406 | { |
| 6407 | const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE(); |
| 6408 | if (dwarf_cu_die && dwarf_cu_die->HasChildren()) |
| 6409 | { |
| 6410 | types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true); |
| 6411 | } |
| 6412 | } |
| 6413 | } |
| 6414 | |
| 6415 | return types_added; |
| 6416 | } |
| 6417 | |
| 6418 | size_t |
| 6419 | SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc) |
| 6420 | { |
| 6421 | if (sc.comp_unit != NULL) |
| 6422 | { |
| Greg Clayton | 4b3dc10 | 2010-11-01 20:32:12 +0000 | [diff] [blame] | 6423 | DWARFDebugInfo* info = DebugInfo(); |
| 6424 | if (info == NULL) |
| 6425 | return 0; |
| 6426 | |
| 6427 | uint32_t cu_idx = UINT32_MAX; |
| 6428 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID(), &cu_idx).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6429 | |
| 6430 | if (dwarf_cu == NULL) |
| 6431 | return 0; |
| 6432 | |
| 6433 | if (sc.function) |
| 6434 | { |
| 6435 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID()); |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 6436 | |
| 6437 | 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] | 6438 | if (func_lo_pc != DW_INVALID_ADDRESS) |
| 6439 | { |
| 6440 | 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] | 6441 | |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6442 | // Let all blocks know they have parse all their variables |
| 6443 | sc.function->GetBlock (false).SetDidParseVariables (true, true); |
| 6444 | return num_variables; |
| 6445 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6446 | } |
| 6447 | else if (sc.comp_unit) |
| 6448 | { |
| 6449 | uint32_t vars_added = 0; |
| 6450 | VariableListSP variables (sc.comp_unit->GetVariableList(false)); |
| 6451 | |
| 6452 | if (variables.get() == NULL) |
| 6453 | { |
| 6454 | variables.reset(new VariableList()); |
| 6455 | sc.comp_unit->SetVariableList(variables); |
| 6456 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 6457 | DWARFCompileUnit* match_dwarf_cu = NULL; |
| 6458 | const DWARFDebugInfoEntry* die = NULL; |
| 6459 | DIEArray die_offsets; |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 6460 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6461 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 6462 | if (m_apple_names_ap.get()) |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6463 | { |
| 6464 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 6465 | if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(), |
| 6466 | dwarf_cu->GetNextCompileUnitOffset(), |
| 6467 | hash_data_array)) |
| 6468 | { |
| 6469 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| 6470 | } |
| 6471 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6472 | } |
| 6473 | else |
| 6474 | { |
| 6475 | // Index if we already haven't to make sure the compile units |
| 6476 | // get indexed and make their global DIE index list |
| 6477 | if (!m_indexed) |
| 6478 | Index (); |
| 6479 | |
| 6480 | m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(), |
| 6481 | dwarf_cu->GetNextCompileUnitOffset(), |
| 6482 | die_offsets); |
| 6483 | } |
| 6484 | |
| 6485 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 6486 | if (num_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6487 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 6488 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 6489 | for (size_t i=0; i<num_matches; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6490 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 6491 | const dw_offset_t die_offset = die_offsets[i]; |
| 6492 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 6493 | if (die) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 6494 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 6495 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS)); |
| 6496 | if (var_sp) |
| 6497 | { |
| 6498 | variables->AddVariableIfUnique (var_sp); |
| 6499 | ++vars_added; |
| 6500 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 6501 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 6502 | else |
| 6503 | { |
| 6504 | if (m_using_apple_tables) |
| 6505 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6506 | 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] | 6507 | } |
| 6508 | } |
| 6509 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6510 | } |
| 6511 | } |
| 6512 | } |
| 6513 | return vars_added; |
| 6514 | } |
| 6515 | } |
| 6516 | return 0; |
| 6517 | } |
| 6518 | |
| 6519 | |
| 6520 | VariableSP |
| 6521 | SymbolFileDWARF::ParseVariableDIE |
| 6522 | ( |
| 6523 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6524 | DWARFCompileUnit* dwarf_cu, |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 6525 | const DWARFDebugInfoEntry *die, |
| 6526 | const lldb::addr_t func_low_pc |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6527 | ) |
| 6528 | { |
| 6529 | |
| Greg Clayton | 83c5cd9 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 6530 | VariableSP var_sp (m_die_to_variable_sp[die]); |
| 6531 | if (var_sp) |
| 6532 | return var_sp; // Already been parsed! |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6533 | |
| 6534 | const dw_tag_t tag = die->Tag(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6535 | |
| 6536 | if ((tag == DW_TAG_variable) || |
| 6537 | (tag == DW_TAG_constant) || |
| 6538 | (tag == DW_TAG_formal_parameter && sc.function)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6539 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6540 | DWARFDebugInfoEntry::Attributes attributes; |
| 6541 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| 6542 | if (num_attributes > 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6543 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6544 | const char *name = NULL; |
| 6545 | const char *mangled = NULL; |
| 6546 | Declaration decl; |
| 6547 | uint32_t i; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6548 | lldb::user_id_t type_uid = LLDB_INVALID_UID; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6549 | DWARFExpression location; |
| 6550 | bool is_external = false; |
| 6551 | bool is_artificial = false; |
| 6552 | bool location_is_const_value_data = false; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6553 | //AccessType accessibility = eAccessNone; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6554 | |
| 6555 | for (i=0; i<num_attributes; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6556 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6557 | dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 6558 | DWARFFormValue form_value; |
| 6559 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6560 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6561 | switch (attr) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6562 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6563 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 6564 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 6565 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 6566 | case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; |
| 6567 | 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] | 6568 | case DW_AT_type: type_uid = form_value.Reference(dwarf_cu); break; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6569 | case DW_AT_external: is_external = form_value.Unsigned() != 0; break; |
| 6570 | case DW_AT_const_value: |
| 6571 | location_is_const_value_data = true; |
| 6572 | // Fall through... |
| 6573 | case DW_AT_location: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6574 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6575 | if (form_value.BlockData()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6576 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6577 | const DataExtractor& debug_info_data = get_debug_info_data(); |
| 6578 | |
| 6579 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 6580 | uint32_t block_length = form_value.Unsigned(); |
| Greg Clayton | 7f4c743 | 2012-08-11 00:49:14 +0000 | [diff] [blame] | 6581 | location.CopyOpcodeData(get_debug_info_data(), block_offset, block_length); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6582 | } |
| 6583 | else |
| 6584 | { |
| 6585 | const DataExtractor& debug_loc_data = get_debug_loc_data(); |
| 6586 | const dw_offset_t debug_loc_offset = form_value.Unsigned(); |
| 6587 | |
| 6588 | size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset); |
| 6589 | if (loc_list_length > 0) |
| 6590 | { |
| Greg Clayton | 7f4c743 | 2012-08-11 00:49:14 +0000 | [diff] [blame] | 6591 | location.CopyOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6592 | assert (func_low_pc != LLDB_INVALID_ADDRESS); |
| 6593 | location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress()); |
| 6594 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6595 | } |
| 6596 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6597 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6598 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6599 | case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 6600 | 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] | 6601 | case DW_AT_declaration: |
| 6602 | case DW_AT_description: |
| 6603 | case DW_AT_endianity: |
| 6604 | case DW_AT_segment: |
| 6605 | case DW_AT_start_scope: |
| 6606 | case DW_AT_visibility: |
| 6607 | default: |
| 6608 | case DW_AT_abstract_origin: |
| 6609 | case DW_AT_sibling: |
| 6610 | case DW_AT_specification: |
| 6611 | break; |
| 6612 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6613 | } |
| 6614 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6615 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6616 | if (location.IsValid()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6617 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6618 | ValueType scope = eValueTypeInvalid; |
| 6619 | |
| 6620 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); |
| 6621 | 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] | 6622 | SymbolContextScope * symbol_context_scope = NULL; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6623 | |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6624 | // DWARF doesn't specify if a DW_TAG_variable is a local, global |
| 6625 | // or static variable, so we have to do a little digging by |
| 6626 | // looking at the location of a varaible to see if it contains |
| 6627 | // a DW_OP_addr opcode _somewhere_ in the definition. I say |
| 6628 | // somewhere because clang likes to combine small global variables |
| 6629 | // into the same symbol and have locations like: |
| 6630 | // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus |
| 6631 | // So if we don't have a DW_TAG_formal_parameter, we can look at |
| 6632 | // the location to see if it contains a DW_OP_addr opcode, and |
| 6633 | // then we can correctly classify our variables. |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6634 | if (tag == DW_TAG_formal_parameter) |
| 6635 | scope = eValueTypeVariableArgument; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6636 | else |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6637 | { |
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 6638 | bool op_error = false; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6639 | // Check if the location has a DW_OP_addr with any address value... |
| 6640 | addr_t location_has_op_addr = false; |
| 6641 | if (!location_is_const_value_data) |
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 6642 | { |
| 6643 | location_has_op_addr = location.LocationContains_DW_OP_addr (LLDB_INVALID_ADDRESS, op_error); |
| 6644 | if (op_error) |
| 6645 | { |
| 6646 | StreamString strm; |
| 6647 | location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL); |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6648 | 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] | 6649 | } |
| 6650 | } |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6651 | |
| 6652 | if (location_has_op_addr) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6653 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6654 | if (is_external) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6655 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6656 | scope = eValueTypeVariableGlobal; |
| 6657 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 6658 | if (GetDebugMapSymfile ()) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6659 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6660 | // When leaving the DWARF in the .o files on darwin, |
| 6661 | // when we have a global variable that wasn't initialized, |
| 6662 | // the .o file might not have allocated a virtual |
| 6663 | // address for the global variable. In this case it will |
| 6664 | // have created a symbol for the global variable |
| 6665 | // that is undefined and external and the value will |
| 6666 | // be the byte size of the variable. When we do the |
| 6667 | // address map in SymbolFileDWARFDebugMap we rely on |
| 6668 | // having an address, we need to do some magic here |
| 6669 | // so we can get the correct address for our global |
| 6670 | // variable. The address for all of these entries |
| 6671 | // will be zero, and there will be an undefined symbol |
| 6672 | // in this object file, and the executable will have |
| 6673 | // a matching symbol with a good address. So here we |
| 6674 | // dig up the correct address and replace it in the |
| 6675 | // location for the variable, and set the variable's |
| 6676 | // symbol context scope to be that of the main executable |
| 6677 | // so the file address will resolve correctly. |
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 6678 | if (location.LocationContains_DW_OP_addr (0, op_error)) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6679 | { |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6680 | |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6681 | // we have a possible uninitialized extern global |
| 6682 | Symtab *symtab = m_obj_file->GetSymtab(); |
| 6683 | if (symtab) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6684 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6685 | ConstString const_name(name); |
| 6686 | Symbol *undefined_symbol = symtab->FindFirstSymbolWithNameAndType (const_name, |
| 6687 | eSymbolTypeUndefined, |
| 6688 | Symtab::eDebugNo, |
| 6689 | Symtab::eVisibilityExtern); |
| 6690 | |
| 6691 | if (undefined_symbol) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6692 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6693 | ObjectFile *debug_map_objfile = m_debug_map_symfile->GetObjectFile(); |
| 6694 | if (debug_map_objfile) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6695 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6696 | Symtab *debug_map_symtab = debug_map_objfile->GetSymtab(); |
| 6697 | Symbol *defined_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name, |
| 6698 | eSymbolTypeData, |
| 6699 | Symtab::eDebugYes, |
| 6700 | Symtab::eVisibilityExtern); |
| 6701 | if (defined_symbol) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6702 | { |
| Greg Clayton | e761213 | 2012-03-07 21:03:09 +0000 | [diff] [blame] | 6703 | if (defined_symbol->ValueIsAddress()) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6704 | { |
| Greg Clayton | e761213 | 2012-03-07 21:03:09 +0000 | [diff] [blame] | 6705 | const addr_t defined_addr = defined_symbol->GetAddress().GetFileAddress(); |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6706 | if (defined_addr != LLDB_INVALID_ADDRESS) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6707 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6708 | if (location.Update_DW_OP_addr (defined_addr)) |
| 6709 | { |
| 6710 | symbol_context_scope = defined_symbol; |
| 6711 | } |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6712 | } |
| 6713 | } |
| 6714 | } |
| 6715 | } |
| 6716 | } |
| 6717 | } |
| 6718 | } |
| 6719 | } |
| 6720 | } |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6721 | else |
| 6722 | { |
| 6723 | scope = eValueTypeVariableStatic; |
| 6724 | } |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6725 | } |
| 6726 | else |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6727 | { |
| 6728 | scope = eValueTypeVariableLocal; |
| 6729 | } |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6730 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6731 | |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6732 | if (symbol_context_scope == NULL) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6733 | { |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6734 | switch (parent_tag) |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6735 | { |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 6736 | case DW_TAG_subprogram: |
| 6737 | case DW_TAG_inlined_subroutine: |
| 6738 | case DW_TAG_lexical_block: |
| 6739 | if (sc.function) |
| 6740 | { |
| 6741 | symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); |
| 6742 | if (symbol_context_scope == NULL) |
| 6743 | symbol_context_scope = sc.function; |
| 6744 | } |
| 6745 | break; |
| 6746 | |
| 6747 | default: |
| 6748 | symbol_context_scope = sc.comp_unit; |
| 6749 | break; |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6750 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6751 | } |
| 6752 | |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6753 | if (symbol_context_scope) |
| 6754 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6755 | var_sp.reset (new Variable (MakeUserID(die->GetOffset()), |
| 6756 | name, |
| 6757 | mangled, |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 6758 | SymbolFileTypeSP (new SymbolFileType(*this, type_uid)), |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6759 | scope, |
| 6760 | symbol_context_scope, |
| 6761 | &decl, |
| 6762 | location, |
| 6763 | is_external, |
| 6764 | is_artificial)); |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 6765 | |
| 6766 | var_sp->SetLocationIsConstantValueData (location_is_const_value_data); |
| 6767 | } |
| 6768 | else |
| 6769 | { |
| 6770 | // Not ready to parse this variable yet. It might be a global |
| 6771 | // or static variable that is in a function scope and the function |
| 6772 | // in the symbol context wasn't filled in yet |
| 6773 | return var_sp; |
| 6774 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6775 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6776 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 6777 | // Cache var_sp even if NULL (the variable was just a specification or |
| 6778 | // was missing vital information to be able to be displayed in the debugger |
| 6779 | // (missing location due to optimization, etc)) so we don't re-parse |
| 6780 | // this DIE over and over later... |
| 6781 | m_die_to_variable_sp[die] = var_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6782 | } |
| 6783 | return var_sp; |
| 6784 | } |
| 6785 | |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6786 | |
| 6787 | const DWARFDebugInfoEntry * |
| 6788 | SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset, |
| 6789 | dw_offset_t spec_block_die_offset, |
| 6790 | DWARFCompileUnit **result_die_cu_handle) |
| 6791 | { |
| 6792 | // Give the concrete function die specified by "func_die_offset", find the |
| 6793 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points |
| 6794 | // to "spec_block_die_offset" |
| 6795 | DWARFDebugInfo* info = DebugInfo(); |
| 6796 | |
| 6797 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle); |
| 6798 | if (die) |
| 6799 | { |
| 6800 | assert (*result_die_cu_handle); |
| 6801 | return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle); |
| 6802 | } |
| 6803 | return NULL; |
| 6804 | } |
| 6805 | |
| 6806 | |
| 6807 | const DWARFDebugInfoEntry * |
| 6808 | SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu, |
| 6809 | const DWARFDebugInfoEntry *die, |
| 6810 | dw_offset_t spec_block_die_offset, |
| 6811 | DWARFCompileUnit **result_die_cu_handle) |
| 6812 | { |
| 6813 | if (die) |
| 6814 | { |
| 6815 | switch (die->Tag()) |
| 6816 | { |
| 6817 | case DW_TAG_subprogram: |
| 6818 | case DW_TAG_inlined_subroutine: |
| 6819 | case DW_TAG_lexical_block: |
| 6820 | { |
| 6821 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset) |
| 6822 | { |
| 6823 | *result_die_cu_handle = dwarf_cu; |
| 6824 | return die; |
| 6825 | } |
| 6826 | |
| 6827 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset) |
| 6828 | { |
| 6829 | *result_die_cu_handle = dwarf_cu; |
| 6830 | return die; |
| 6831 | } |
| 6832 | } |
| 6833 | break; |
| 6834 | } |
| 6835 | |
| 6836 | // Give the concrete function die specified by "func_die_offset", find the |
| 6837 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points |
| 6838 | // to "spec_block_die_offset" |
| 6839 | for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling()) |
| 6840 | { |
| 6841 | const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu, |
| 6842 | child_die, |
| 6843 | spec_block_die_offset, |
| 6844 | result_die_cu_handle); |
| 6845 | if (result_die) |
| 6846 | return result_die; |
| 6847 | } |
| 6848 | } |
| 6849 | |
| 6850 | *result_die_cu_handle = NULL; |
| 6851 | return NULL; |
| 6852 | } |
| 6853 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6854 | size_t |
| 6855 | SymbolFileDWARF::ParseVariables |
| 6856 | ( |
| 6857 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6858 | DWARFCompileUnit* dwarf_cu, |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 6859 | const lldb::addr_t func_low_pc, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6860 | const DWARFDebugInfoEntry *orig_die, |
| 6861 | bool parse_siblings, |
| 6862 | bool parse_children, |
| 6863 | VariableList* cc_variable_list |
| 6864 | ) |
| 6865 | { |
| 6866 | if (orig_die == NULL) |
| 6867 | return 0; |
| 6868 | |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6869 | VariableListSP variable_list_sp; |
| 6870 | |
| 6871 | size_t vars_added = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6872 | const DWARFDebugInfoEntry *die = orig_die; |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6873 | while (die != NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6874 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6875 | dw_tag_t tag = die->Tag(); |
| 6876 | |
| 6877 | // Check to see if we have already parsed this variable or constant? |
| 6878 | if (m_die_to_variable_sp[die]) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6879 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6880 | if (cc_variable_list) |
| 6881 | cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6882 | } |
| 6883 | else |
| 6884 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6885 | // We haven't already parsed it, lets do that now. |
| 6886 | if ((tag == DW_TAG_variable) || |
| 6887 | (tag == DW_TAG_constant) || |
| 6888 | (tag == DW_TAG_formal_parameter && sc.function)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6889 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6890 | if (variable_list_sp.get() == NULL) |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 6891 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6892 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die); |
| 6893 | dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
| 6894 | switch (parent_tag) |
| 6895 | { |
| 6896 | case DW_TAG_compile_unit: |
| 6897 | if (sc.comp_unit != NULL) |
| 6898 | { |
| 6899 | variable_list_sp = sc.comp_unit->GetVariableList(false); |
| 6900 | if (variable_list_sp.get() == NULL) |
| 6901 | { |
| 6902 | variable_list_sp.reset(new VariableList()); |
| 6903 | sc.comp_unit->SetVariableList(variable_list_sp); |
| 6904 | } |
| 6905 | } |
| 6906 | else |
| 6907 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6908 | GetObjectFile()->GetModule()->ReportError ("parent 0x%8.8llx %s with no valid compile unit in symbol context for 0x%8.8llx %s.\n", |
| 6909 | MakeUserID(sc_parent_die->GetOffset()), |
| 6910 | DW_TAG_value_to_name (parent_tag), |
| 6911 | MakeUserID(orig_die->GetOffset()), |
| 6912 | DW_TAG_value_to_name (orig_die->Tag())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6913 | } |
| 6914 | break; |
| 6915 | |
| 6916 | case DW_TAG_subprogram: |
| 6917 | case DW_TAG_inlined_subroutine: |
| 6918 | case DW_TAG_lexical_block: |
| 6919 | if (sc.function != NULL) |
| 6920 | { |
| 6921 | // Check to see if we already have parsed the variables for the given scope |
| 6922 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6923 | Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6924 | if (block == NULL) |
| 6925 | { |
| 6926 | // This must be a specification or abstract origin with |
| 6927 | // a concrete block couterpart in the current function. We need |
| 6928 | // to find the concrete block so we can correctly add the |
| 6929 | // variable to it |
| 6930 | DWARFCompileUnit *concrete_block_die_cu = dwarf_cu; |
| 6931 | const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(), |
| 6932 | sc_parent_die->GetOffset(), |
| 6933 | &concrete_block_die_cu); |
| 6934 | if (concrete_block_die) |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 6935 | block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6936 | } |
| 6937 | |
| 6938 | if (block != NULL) |
| 6939 | { |
| 6940 | const bool can_create = false; |
| 6941 | variable_list_sp = block->GetBlockVariableList (can_create); |
| 6942 | if (variable_list_sp.get() == NULL) |
| 6943 | { |
| 6944 | variable_list_sp.reset(new VariableList()); |
| 6945 | block->SetVariableList(variable_list_sp); |
| 6946 | } |
| 6947 | } |
| 6948 | } |
| 6949 | break; |
| 6950 | |
| 6951 | default: |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 6952 | GetObjectFile()->GetModule()->ReportError ("didn't find appropriate parent DIE for variable list for 0x%8.8llx %s.\n", |
| 6953 | MakeUserID(orig_die->GetOffset()), |
| 6954 | DW_TAG_value_to_name (orig_die->Tag())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6955 | break; |
| 6956 | } |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 6957 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6958 | |
| 6959 | if (variable_list_sp) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6960 | { |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 6961 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc)); |
| 6962 | if (var_sp) |
| 6963 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6964 | variable_list_sp->AddVariableIfUnique (var_sp); |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 6965 | if (cc_variable_list) |
| 6966 | cc_variable_list->AddVariableIfUnique (var_sp); |
| 6967 | ++vars_added; |
| 6968 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6969 | } |
| 6970 | } |
| 6971 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6972 | |
| 6973 | bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram); |
| 6974 | |
| 6975 | if (!skip_children && parse_children && die->HasChildren()) |
| 6976 | { |
| 6977 | vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list); |
| 6978 | } |
| 6979 | |
| 6980 | if (parse_siblings) |
| 6981 | die = die->GetSibling(); |
| 6982 | else |
| 6983 | die = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6984 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 6985 | return vars_added; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6986 | } |
| 6987 | |
| 6988 | //------------------------------------------------------------------ |
| 6989 | // PluginInterface protocol |
| 6990 | //------------------------------------------------------------------ |
| 6991 | const char * |
| 6992 | SymbolFileDWARF::GetPluginName() |
| 6993 | { |
| 6994 | return "SymbolFileDWARF"; |
| 6995 | } |
| 6996 | |
| 6997 | const char * |
| 6998 | SymbolFileDWARF::GetShortPluginName() |
| 6999 | { |
| 7000 | return GetPluginNameStatic(); |
| 7001 | } |
| 7002 | |
| 7003 | uint32_t |
| 7004 | SymbolFileDWARF::GetPluginVersion() |
| 7005 | { |
| 7006 | return 1; |
| 7007 | } |
| 7008 | |
| 7009 | void |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 7010 | SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl) |
| 7011 | { |
| 7012 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 7013 | clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); |
| 7014 | if (clang_type) |
| 7015 | symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); |
| 7016 | } |
| 7017 | |
| 7018 | void |
| 7019 | SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl) |
| 7020 | { |
| 7021 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 7022 | clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); |
| 7023 | if (clang_type) |
| 7024 | symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); |
| 7025 | } |
| 7026 | |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7027 | void |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7028 | SymbolFileDWARF::DumpIndexes () |
| 7029 | { |
| 7030 | StreamFile s(stdout, false); |
| 7031 | |
| 7032 | s.Printf ("DWARF index for (%s) '%s/%s':", |
| 7033 | GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(), |
| 7034 | GetObjectFile()->GetFileSpec().GetDirectory().AsCString(), |
| 7035 | GetObjectFile()->GetFileSpec().GetFilename().AsCString()); |
| 7036 | s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s); |
| 7037 | s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s); |
| 7038 | s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s); |
| 7039 | s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s); |
| 7040 | s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s); |
| 7041 | s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s); |
| 7042 | s.Printf("\nTypes:\n"); m_type_index.Dump (&s); |
| 7043 | s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s); |
| 7044 | } |
| 7045 | |
| 7046 | void |
| 7047 | SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context, |
| 7048 | const char *name, |
| 7049 | llvm::SmallVectorImpl <clang::NamedDecl *> *results) |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7050 | { |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 7051 | DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context); |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7052 | |
| 7053 | if (iter == m_decl_ctx_to_die.end()) |
| 7054 | return; |
| 7055 | |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7056 | 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] | 7057 | { |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7058 | const DWARFDebugInfoEntry *context_die = *pos; |
| 7059 | |
| 7060 | if (!results) |
| 7061 | return; |
| 7062 | |
| 7063 | DWARFDebugInfo* info = DebugInfo(); |
| 7064 | |
| 7065 | DIEArray die_offsets; |
| 7066 | |
| 7067 | DWARFCompileUnit* dwarf_cu = NULL; |
| 7068 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 7069 | |
| 7070 | if (m_using_apple_tables) |
| 7071 | { |
| 7072 | if (m_apple_types_ap.get()) |
| 7073 | m_apple_types_ap->FindByName (name, die_offsets); |
| 7074 | } |
| 7075 | else |
| 7076 | { |
| 7077 | if (!m_indexed) |
| 7078 | Index (); |
| 7079 | |
| 7080 | m_type_index.Find (ConstString(name), die_offsets); |
| 7081 | } |
| 7082 | |
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 7083 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7084 | |
| 7085 | if (num_matches) |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7086 | { |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7087 | for (size_t i = 0; i < num_matches; ++i) |
| 7088 | { |
| 7089 | const dw_offset_t die_offset = die_offsets[i]; |
| 7090 | die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 7091 | |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7092 | if (die->GetParent() != context_die) |
| 7093 | continue; |
| 7094 | |
| 7095 | Type *matching_type = ResolveType (dwarf_cu, die); |
| 7096 | |
| Greg Clayton | 42ce2f3 | 2011-12-12 21:50:19 +0000 | [diff] [blame] | 7097 | lldb::clang_type_t type = matching_type->GetClangForwardType(); |
| Greg Clayton | cb5860a | 2011-10-13 23:49:28 +0000 | [diff] [blame] | 7098 | clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type); |
| 7099 | |
| 7100 | if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr())) |
| 7101 | { |
| 7102 | clang::TagDecl *tag_decl = tag_type->getDecl(); |
| 7103 | results->push_back(tag_decl); |
| 7104 | } |
| 7105 | else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr())) |
| 7106 | { |
| 7107 | clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl(); |
| 7108 | results->push_back(typedef_decl); |
| 7109 | } |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7110 | } |
| 7111 | } |
| 7112 | } |
| 7113 | } |
| 7114 | |
| 7115 | void |
| 7116 | SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton, |
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 7117 | const clang::DeclContext *decl_context, |
| 7118 | clang::DeclarationName decl_name, |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7119 | llvm::SmallVectorImpl <clang::NamedDecl *> *results) |
| 7120 | { |
| Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 7121 | |
| 7122 | switch (decl_context->getDeclKind()) |
| 7123 | { |
| 7124 | case clang::Decl::Namespace: |
| 7125 | case clang::Decl::TranslationUnit: |
| 7126 | { |
| 7127 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 7128 | symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results); |
| 7129 | } |
| 7130 | break; |
| 7131 | default: |
| 7132 | break; |
| 7133 | } |
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 7134 | } |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7135 | |
| 7136 | bool |
| 7137 | SymbolFileDWARF::LayoutRecordType (void *baton, |
| 7138 | const clang::RecordDecl *record_decl, |
| 7139 | uint64_t &size, |
| 7140 | uint64_t &alignment, |
| 7141 | llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, |
| 7142 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, |
| 7143 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) |
| 7144 | { |
| 7145 | SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; |
| 7146 | return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets); |
| 7147 | } |
| 7148 | |
| 7149 | |
| 7150 | bool |
| 7151 | SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl, |
| 7152 | uint64_t &bit_size, |
| 7153 | uint64_t &alignment, |
| 7154 | llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, |
| 7155 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, |
| 7156 | llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) |
| 7157 | { |
| 7158 | LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| 7159 | RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl); |
| 7160 | bool success = false; |
| 7161 | base_offsets.clear(); |
| 7162 | vbase_offsets.clear(); |
| 7163 | if (pos != m_record_decl_to_layout_map.end()) |
| 7164 | { |
| 7165 | bit_size = pos->second.bit_size; |
| 7166 | alignment = pos->second.alignment; |
| 7167 | field_offsets.swap(pos->second.field_offsets); |
| 7168 | m_record_decl_to_layout_map.erase(pos); |
| 7169 | success = true; |
| 7170 | } |
| 7171 | else |
| 7172 | { |
| 7173 | bit_size = 0; |
| 7174 | alignment = 0; |
| 7175 | field_offsets.clear(); |
| 7176 | } |
| 7177 | |
| 7178 | if (log) |
| 7179 | GetObjectFile()->GetModule()->LogMessage (log.get(), |
| 7180 | "SymbolFileDWARF::LayoutRecordType (record_decl = %p, bit_size = %llu, alignment = %llu, field_offsets[%u],base_offsets[%u], vbase_offsets[%u]) success = %i", |
| 7181 | record_decl, |
| 7182 | bit_size, |
| 7183 | alignment, |
| 7184 | (uint32_t)field_offsets.size(), |
| 7185 | (uint32_t)base_offsets.size(), |
| 7186 | (uint32_t)vbase_offsets.size(), |
| 7187 | success); |
| 7188 | return success; |
| 7189 | } |
| 7190 | |
| 7191 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 7192 | SymbolFileDWARFDebugMap * |
| 7193 | SymbolFileDWARF::GetDebugMapSymfile () |
| 7194 | { |
| 7195 | if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired()) |
| 7196 | { |
| 7197 | lldb::ModuleSP module_sp (m_debug_map_module_wp.lock()); |
| 7198 | if (module_sp) |
| 7199 | { |
| 7200 | SymbolVendor *sym_vendor = module_sp->GetSymbolVendor(); |
| 7201 | if (sym_vendor) |
| 7202 | m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile(); |
| 7203 | } |
| 7204 | } |
| 7205 | return m_debug_map_symfile; |
| 7206 | } |
| 7207 | |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 7208 | |