| 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 | |
| Robert Flack | eb83fab | 2015-05-15 18:59:59 +0000 | [diff] [blame] | 29 | #include "lldb/Core/ArchSpec.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | #include "lldb/Core/Module.h" |
| Sean Callanan | f0c5aeb | 2015-04-20 16:31:29 +0000 | [diff] [blame] | 31 | #include "lldb/Core/ModuleList.h" |
| 32 | #include "lldb/Core/ModuleSpec.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 33 | #include "lldb/Core/PluginManager.h" |
| 34 | #include "lldb/Core/RegularExpression.h" |
| 35 | #include "lldb/Core/Scalar.h" |
| 36 | #include "lldb/Core/Section.h" |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 37 | #include "lldb/Core/StreamFile.h" |
| Jim Ingham | 318c9f2 | 2011-08-26 19:44:13 +0000 | [diff] [blame] | 38 | #include "lldb/Core/StreamString.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 39 | #include "lldb/Core/Timer.h" |
| 40 | #include "lldb/Core/Value.h" |
| 41 | |
| Sean Callanan | f0c5aeb | 2015-04-20 16:31:29 +0000 | [diff] [blame] | 42 | #include "lldb/Expression/ClangModulesDeclVendor.h" |
| 43 | |
| Oleksiy Vyalov | 5d9c50b | 2015-07-21 02:09:42 +0000 | [diff] [blame] | 44 | #include "lldb/Host/FileSystem.h" |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 45 | #include "lldb/Host/Host.h" |
| 46 | |
| Oleksiy Vyalov | abb5a35 | 2015-07-29 22:18:16 +0000 | [diff] [blame] | 47 | #include "lldb/Interpreter/OptionValueFileSpecList.h" |
| 48 | #include "lldb/Interpreter/OptionValueProperties.h" |
| 49 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 50 | #include "lldb/Symbol/Block.h" |
| 51 | #include "lldb/Symbol/CompileUnit.h" |
| 52 | #include "lldb/Symbol/LineTable.h" |
| 53 | #include "lldb/Symbol/ObjectFile.h" |
| 54 | #include "lldb/Symbol/SymbolVendor.h" |
| 55 | #include "lldb/Symbol/VariableList.h" |
| 56 | |
| Jim Ingham | aa816b8 | 2015-09-02 01:59:14 +0000 | [diff] [blame] | 57 | #include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h" |
| 58 | #include "Plugins/Language/ObjC/ObjCLanguage.h" |
| Jim Ingham | b7f6b2f | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 59 | |
| Jim Ingham | 0e0984e | 2015-09-02 01:06:46 +0000 | [diff] [blame] | 60 | #include "lldb/Target/Language.h" |
| 61 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 62 | #include "DWARFASTParser.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 63 | #include "DWARFCompileUnit.h" |
| 64 | #include "DWARFDebugAbbrev.h" |
| 65 | #include "DWARFDebugAranges.h" |
| 66 | #include "DWARFDebugInfo.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 67 | #include "DWARFDebugLine.h" |
| 68 | #include "DWARFDebugPubnames.h" |
| 69 | #include "DWARFDebugRanges.h" |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 70 | #include "DWARFDeclContext.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 71 | #include "DWARFDIECollection.h" |
| 72 | #include "DWARFFormValue.h" |
| 73 | #include "DWARFLocationList.h" |
| 74 | #include "LogChannelDWARF.h" |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 75 | #include "SymbolFileDWARFDwo.h" |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 76 | #include "SymbolFileDWARFDebugMap.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 77 | |
| 78 | #include <map> |
| 79 | |
| Matthew Gardiner | e81df3b | 2014-08-26 06:57:23 +0000 | [diff] [blame] | 80 | #include <ctype.h> |
| 81 | #include <string.h> |
| 82 | |
| Greg Clayton | 62742b1 | 2010-11-11 01:09:45 +0000 | [diff] [blame] | 83 | //#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 84 | |
| 85 | #ifdef ENABLE_DEBUG_PRINTF |
| 86 | #include <stdio.h> |
| Ed Maste | a0191d1 | 2013-10-17 20:42:56 +0000 | [diff] [blame] | 87 | #define DEBUG_PRINTF(fmt, ...) printf(fmt, __VA_ARGS__) |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 88 | #else |
| 89 | #define DEBUG_PRINTF(fmt, ...) |
| 90 | #endif |
| 91 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 92 | using namespace lldb; |
| 93 | using namespace lldb_private; |
| 94 | |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 95 | //static inline bool |
| 96 | //child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag) |
| 97 | //{ |
| 98 | // switch (tag) |
| 99 | // { |
| 100 | // default: |
| 101 | // break; |
| 102 | // case DW_TAG_subprogram: |
| 103 | // case DW_TAG_inlined_subroutine: |
| 104 | // case DW_TAG_class_type: |
| 105 | // case DW_TAG_structure_type: |
| 106 | // case DW_TAG_union_type: |
| 107 | // return true; |
| 108 | // } |
| 109 | // return false; |
| 110 | //} |
| 111 | // |
| Oleksiy Vyalov | abb5a35 | 2015-07-29 22:18:16 +0000 | [diff] [blame] | 112 | |
| 113 | namespace { |
| 114 | |
| 115 | PropertyDefinition |
| 116 | g_properties[] = |
| 117 | { |
| 118 | { "comp-dir-symlink-paths" , OptionValue::eTypeFileSpecList, true, 0 , nullptr, nullptr, "If the DW_AT_comp_dir matches any of these paths the symbolic links will be resolved at DWARF parse time." }, |
| 119 | { nullptr , OptionValue::eTypeInvalid , false, 0, nullptr, nullptr, nullptr } |
| 120 | }; |
| 121 | |
| 122 | enum |
| 123 | { |
| 124 | ePropertySymLinkPaths |
| 125 | }; |
| 126 | |
| 127 | |
| 128 | class PluginProperties : public Properties |
| 129 | { |
| 130 | public: |
| 131 | static ConstString |
| 132 | GetSettingName() |
| 133 | { |
| 134 | return SymbolFileDWARF::GetPluginNameStatic(); |
| 135 | } |
| 136 | |
| 137 | PluginProperties() |
| 138 | { |
| 139 | m_collection_sp.reset (new OptionValueProperties(GetSettingName())); |
| 140 | m_collection_sp->Initialize(g_properties); |
| 141 | } |
| 142 | |
| 143 | FileSpecList& |
| 144 | GetSymLinkPaths() |
| 145 | { |
| 146 | OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList(nullptr, true, ePropertySymLinkPaths); |
| 147 | assert(option_value); |
| 148 | return option_value->GetCurrentValue(); |
| 149 | } |
| 150 | |
| 151 | }; |
| 152 | |
| 153 | typedef std::shared_ptr<PluginProperties> SymbolFileDWARFPropertiesSP; |
| 154 | |
| 155 | static const SymbolFileDWARFPropertiesSP& |
| 156 | GetGlobalPluginProperties() |
| 157 | { |
| 158 | static const auto g_settings_sp(std::make_shared<PluginProperties>()); |
| 159 | return g_settings_sp; |
| 160 | } |
| 161 | |
| 162 | } // anonymous namespace end |
| 163 | |
| 164 | |
| Matthew Gardiner | e81df3b | 2014-08-26 06:57:23 +0000 | [diff] [blame] | 165 | static const char* |
| 166 | removeHostnameFromPathname(const char* path_from_dwarf) |
| 167 | { |
| 168 | if (!path_from_dwarf || !path_from_dwarf[0]) |
| 169 | { |
| 170 | return path_from_dwarf; |
| 171 | } |
| Enrico Granata | 99e5e22 | 2015-07-27 21:27:02 +0000 | [diff] [blame] | 172 | |
| Matthew Gardiner | e81df3b | 2014-08-26 06:57:23 +0000 | [diff] [blame] | 173 | const char *colon_pos = strchr(path_from_dwarf, ':'); |
| Enrico Granata | 99e5e22 | 2015-07-27 21:27:02 +0000 | [diff] [blame] | 174 | if (nullptr == colon_pos) |
| 175 | { |
| 176 | return path_from_dwarf; |
| 177 | } |
| 178 | |
| 179 | const char *slash_pos = strchr(path_from_dwarf, '/'); |
| 180 | if (slash_pos && (slash_pos < colon_pos)) |
| Matthew Gardiner | e81df3b | 2014-08-26 06:57:23 +0000 | [diff] [blame] | 181 | { |
| 182 | return path_from_dwarf; |
| 183 | } |
| 184 | |
| 185 | // check whether we have a windows path, and so the first character |
| 186 | // is a drive-letter not a hostname. |
| 187 | if ( |
| 188 | colon_pos == path_from_dwarf + 1 && |
| 189 | isalpha(*path_from_dwarf) && |
| 190 | strlen(path_from_dwarf) > 2 && |
| 191 | '\\' == path_from_dwarf[2]) |
| 192 | { |
| 193 | return path_from_dwarf; |
| 194 | } |
| Enrico Granata | 99e5e22 | 2015-07-27 21:27:02 +0000 | [diff] [blame] | 195 | |
| Matthew Gardiner | e81df3b | 2014-08-26 06:57:23 +0000 | [diff] [blame] | 196 | return colon_pos + 1; |
| 197 | } |
| 198 | |
| Oleksiy Vyalov | 5d9c50b | 2015-07-21 02:09:42 +0000 | [diff] [blame] | 199 | static const char* |
| 200 | resolveCompDir(const char* path_from_dwarf) |
| 201 | { |
| 202 | if (!path_from_dwarf) |
| 203 | return nullptr; |
| 204 | |
| 205 | // DWARF2/3 suggests the form hostname:pathname for compilation directory. |
| 206 | // Remove the host part if present. |
| 207 | const char* local_path = removeHostnameFromPathname(path_from_dwarf); |
| 208 | if (!local_path) |
| 209 | return nullptr; |
| 210 | |
| 211 | bool is_symlink = false; |
| Oleksiy Vyalov | abb5a35 | 2015-07-29 22:18:16 +0000 | [diff] [blame] | 212 | FileSpec local_path_spec(local_path, false); |
| 213 | const auto& file_specs = GetGlobalPluginProperties()->GetSymLinkPaths(); |
| 214 | for (size_t i = 0; i < file_specs.GetSize() && !is_symlink; ++i) |
| 215 | is_symlink = FileSpec::Equal(file_specs.GetFileSpecAtIndex(i), local_path_spec, true); |
| Oleksiy Vyalov | 5d9c50b | 2015-07-21 02:09:42 +0000 | [diff] [blame] | 216 | |
| 217 | if (!is_symlink) |
| 218 | return local_path; |
| 219 | |
| Oleksiy Vyalov | 5d9c50b | 2015-07-21 02:09:42 +0000 | [diff] [blame] | 220 | if (!local_path_spec.IsSymbolicLink()) |
| 221 | return local_path; |
| 222 | |
| 223 | FileSpec resolved_local_path_spec; |
| 224 | const auto error = FileSystem::Readlink(local_path_spec, resolved_local_path_spec); |
| 225 | if (error.Success()) |
| 226 | return resolved_local_path_spec.GetCString(); |
| 227 | |
| 228 | return nullptr; |
| 229 | } |
| 230 | |
| 231 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 232 | void |
| 233 | SymbolFileDWARF::Initialize() |
| 234 | { |
| 235 | LogChannelDWARF::Initialize(); |
| 236 | PluginManager::RegisterPlugin (GetPluginNameStatic(), |
| 237 | GetPluginDescriptionStatic(), |
| Oleksiy Vyalov | abb5a35 | 2015-07-29 22:18:16 +0000 | [diff] [blame] | 238 | CreateInstance, |
| 239 | DebuggerInitialize); |
| 240 | } |
| 241 | |
| 242 | void |
| 243 | SymbolFileDWARF::DebuggerInitialize(Debugger &debugger) |
| 244 | { |
| 245 | if (!PluginManager::GetSettingForSymbolFilePlugin(debugger, PluginProperties::GetSettingName())) |
| 246 | { |
| 247 | const bool is_global_setting = true; |
| 248 | PluginManager::CreateSettingForSymbolFilePlugin(debugger, |
| 249 | GetGlobalPluginProperties()->GetValueProperties(), |
| 250 | ConstString ("Properties for the dwarf symbol-file plug-in."), |
| 251 | is_global_setting); |
| 252 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | void |
| 256 | SymbolFileDWARF::Terminate() |
| 257 | { |
| 258 | PluginManager::UnregisterPlugin (CreateInstance); |
| 259 | LogChannelDWARF::Initialize(); |
| 260 | } |
| 261 | |
| 262 | |
| Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 263 | lldb_private::ConstString |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 264 | SymbolFileDWARF::GetPluginNameStatic() |
| 265 | { |
| Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 266 | static ConstString g_name("dwarf"); |
| 267 | return g_name; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | const char * |
| 271 | SymbolFileDWARF::GetPluginDescriptionStatic() |
| 272 | { |
| 273 | return "DWARF and DWARF3 debug symbol file reader."; |
| 274 | } |
| 275 | |
| 276 | |
| 277 | SymbolFile* |
| 278 | SymbolFileDWARF::CreateInstance (ObjectFile* obj_file) |
| 279 | { |
| 280 | return new SymbolFileDWARF(obj_file); |
| 281 | } |
| 282 | |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 283 | TypeList * |
| 284 | SymbolFileDWARF::GetTypeList () |
| 285 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 286 | if (GetDebugMapSymfile ()) |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 287 | return m_debug_map_symfile->GetTypeList(); |
| 288 | return m_obj_file->GetModule()->GetTypeList(); |
| 289 | |
| 290 | } |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 291 | void |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 292 | SymbolFileDWARF::GetTypes (const DWARFDIE &die, |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 293 | dw_offset_t min_die_offset, |
| 294 | dw_offset_t max_die_offset, |
| 295 | uint32_t type_mask, |
| 296 | TypeSet &type_set) |
| 297 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 298 | if (die) |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 299 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 300 | const dw_offset_t die_offset = die.GetOffset(); |
| 301 | |
| 302 | if (die_offset >= max_die_offset) |
| 303 | return; |
| 304 | |
| 305 | if (die_offset >= min_die_offset) |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 306 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 307 | const dw_tag_t tag = die.Tag(); |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 308 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 309 | bool add_type = false; |
| 310 | |
| 311 | switch (tag) |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 312 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 313 | case DW_TAG_array_type: add_type = (type_mask & eTypeClassArray ) != 0; break; |
| 314 | case DW_TAG_unspecified_type: |
| 315 | case DW_TAG_base_type: add_type = (type_mask & eTypeClassBuiltin ) != 0; break; |
| 316 | case DW_TAG_class_type: add_type = (type_mask & eTypeClassClass ) != 0; break; |
| 317 | case DW_TAG_structure_type: add_type = (type_mask & eTypeClassStruct ) != 0; break; |
| 318 | case DW_TAG_union_type: add_type = (type_mask & eTypeClassUnion ) != 0; break; |
| 319 | case DW_TAG_enumeration_type: add_type = (type_mask & eTypeClassEnumeration ) != 0; break; |
| 320 | case DW_TAG_subroutine_type: |
| 321 | case DW_TAG_subprogram: |
| 322 | case DW_TAG_inlined_subroutine: add_type = (type_mask & eTypeClassFunction ) != 0; break; |
| 323 | case DW_TAG_pointer_type: add_type = (type_mask & eTypeClassPointer ) != 0; break; |
| 324 | case DW_TAG_rvalue_reference_type: |
| 325 | case DW_TAG_reference_type: add_type = (type_mask & eTypeClassReference ) != 0; break; |
| 326 | case DW_TAG_typedef: add_type = (type_mask & eTypeClassTypedef ) != 0; break; |
| 327 | case DW_TAG_ptr_to_member_type: add_type = (type_mask & eTypeClassMemberPointer ) != 0; break; |
| 328 | } |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 329 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 330 | if (add_type) |
| 331 | { |
| 332 | const bool assert_not_being_parsed = true; |
| 333 | Type *type = ResolveTypeUID (die, assert_not_being_parsed); |
| 334 | if (type) |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 335 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 336 | if (type_set.find(type) == type_set.end()) |
| 337 | type_set.insert(type); |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 338 | } |
| 339 | } |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | for (DWARFDIE child_die = die.GetFirstChild(); |
| 343 | child_die.IsValid(); |
| 344 | child_die = child_die.GetSibling()) |
| 345 | { |
| 346 | GetTypes (child_die, min_die_offset, max_die_offset, type_mask, type_set); |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 347 | } |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | size_t |
| 352 | SymbolFileDWARF::GetTypes (SymbolContextScope *sc_scope, |
| 353 | uint32_t type_mask, |
| 354 | TypeList &type_list) |
| 355 | |
| 356 | { |
| 357 | TypeSet type_set; |
| 358 | |
| 359 | CompileUnit *comp_unit = NULL; |
| 360 | DWARFCompileUnit* dwarf_cu = NULL; |
| 361 | if (sc_scope) |
| 362 | comp_unit = sc_scope->CalculateSymbolContextCompileUnit(); |
| 363 | |
| 364 | if (comp_unit) |
| 365 | { |
| 366 | dwarf_cu = GetDWARFCompileUnit(comp_unit); |
| 367 | if (dwarf_cu == 0) |
| 368 | return 0; |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 369 | GetTypes (dwarf_cu->DIE(), |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 370 | dwarf_cu->GetOffset(), |
| 371 | dwarf_cu->GetNextCompileUnitOffset(), |
| 372 | type_mask, |
| 373 | type_set); |
| 374 | } |
| 375 | else |
| 376 | { |
| 377 | DWARFDebugInfo* info = DebugInfo(); |
| 378 | if (info) |
| 379 | { |
| 380 | const size_t num_cus = info->GetNumCompileUnits(); |
| 381 | for (size_t cu_idx=0; cu_idx<num_cus; ++cu_idx) |
| 382 | { |
| 383 | dwarf_cu = info->GetCompileUnitAtIndex(cu_idx); |
| 384 | if (dwarf_cu) |
| 385 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 386 | GetTypes (dwarf_cu->DIE(), |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 387 | 0, |
| 388 | UINT32_MAX, |
| 389 | type_mask, |
| 390 | type_set); |
| 391 | } |
| 392 | } |
| 393 | } |
| 394 | } |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 395 | |
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 396 | std::set<CompilerType> clang_type_set; |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 397 | size_t num_types_added = 0; |
| 398 | for (Type *type : type_set) |
| 399 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 400 | CompilerType clang_type = type->GetForwardCompilerType (); |
| Greg Clayton | 0fc4f31 | 2013-06-20 01:23:18 +0000 | [diff] [blame] | 401 | if (clang_type_set.find(clang_type) == clang_type_set.end()) |
| 402 | { |
| 403 | clang_type_set.insert(clang_type); |
| 404 | type_list.Insert (type->shared_from_this()); |
| 405 | ++num_types_added; |
| 406 | } |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 407 | } |
| 408 | return num_types_added; |
| 409 | } |
| 410 | |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 411 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 412 | //---------------------------------------------------------------------- |
| 413 | // Gets the first parent that is a lexical block, function or inlined |
| 414 | // subroutine, or compile unit. |
| 415 | //---------------------------------------------------------------------- |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 416 | DWARFDIE |
| 417 | SymbolFileDWARF::GetParentSymbolContextDIE(const DWARFDIE &child_die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 418 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 419 | DWARFDIE die; |
| 420 | for (die = child_die.GetParent(); die; die = die.GetParent()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 421 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 422 | dw_tag_t tag = die.Tag(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 423 | |
| 424 | switch (tag) |
| 425 | { |
| 426 | case DW_TAG_compile_unit: |
| 427 | case DW_TAG_subprogram: |
| 428 | case DW_TAG_inlined_subroutine: |
| 429 | case DW_TAG_lexical_block: |
| 430 | return die; |
| 431 | } |
| 432 | } |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 433 | return DWARFDIE(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 437 | SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) : |
| 438 | SymbolFile (objfile), |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 439 | 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] | 440 | m_debug_map_module_wp (), |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 441 | m_debug_map_symfile (NULL), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 442 | m_flags(), |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 443 | m_data_debug_abbrev (), |
| 444 | m_data_debug_aranges (), |
| 445 | m_data_debug_frame (), |
| 446 | m_data_debug_info (), |
| 447 | m_data_debug_line (), |
| 448 | m_data_debug_loc (), |
| 449 | m_data_debug_ranges (), |
| 450 | m_data_debug_str (), |
| Greg Clayton | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 451 | m_data_apple_names (), |
| 452 | m_data_apple_types (), |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 453 | m_data_apple_namespaces (), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 454 | m_abbr(), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 455 | m_info(), |
| 456 | m_line(), |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 457 | m_apple_names_ap (), |
| 458 | m_apple_types_ap (), |
| 459 | m_apple_namespaces_ap (), |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 460 | m_apple_objc_ap (), |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 461 | m_function_basename_index(), |
| 462 | m_function_fullname_index(), |
| 463 | m_function_method_index(), |
| 464 | m_function_selector_index(), |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 465 | m_objc_class_selectors_index(), |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 466 | m_global_index(), |
| Greg Clayton | 69b0488 | 2010-10-15 02:03:22 +0000 | [diff] [blame] | 467 | m_type_index(), |
| 468 | m_namespace_index(), |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 469 | m_indexed (false), |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 470 | m_using_apple_tables (false), |
| Sean Callanan | f0c5aeb | 2015-04-20 16:31:29 +0000 | [diff] [blame] | 471 | m_fetched_external_modules (false), |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 472 | m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate), |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 473 | m_ranges(), |
| 474 | m_unique_ast_type_map () |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 475 | { |
| 476 | } |
| 477 | |
| 478 | SymbolFileDWARF::~SymbolFileDWARF() |
| 479 | { |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | static const ConstString & |
| 483 | GetDWARFMachOSegmentName () |
| 484 | { |
| 485 | static ConstString g_dwarf_section_name ("__DWARF"); |
| 486 | return g_dwarf_section_name; |
| 487 | } |
| 488 | |
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 489 | UniqueDWARFASTTypeMap & |
| 490 | SymbolFileDWARF::GetUniqueDWARFASTTypeMap () |
| 491 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 492 | if (GetDebugMapSymfile ()) |
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 493 | return m_debug_map_symfile->GetUniqueDWARFASTTypeMap (); |
| 494 | return m_unique_ast_type_map; |
| 495 | } |
| 496 | |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 497 | ClangASTContext & |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 498 | SymbolFileDWARF::GetClangASTContext () |
| 499 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 500 | if (GetDebugMapSymfile ()) |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 501 | return m_debug_map_symfile->GetClangASTContext (); |
| Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 502 | else |
| 503 | return m_obj_file->GetModule()->GetClangASTContext(); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 504 | } |
| 505 | |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 506 | TypeSystem * |
| 507 | SymbolFileDWARF::GetTypeSystemForLanguage (LanguageType language) |
| 508 | { |
| 509 | SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile (); |
| 510 | if (debug_map_symfile) |
| 511 | return debug_map_symfile->GetTypeSystemForLanguage (language); |
| 512 | else |
| Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 513 | return m_obj_file->GetModule()->GetTypeSystemForLanguage (language); |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 514 | } |
| 515 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 516 | void |
| 517 | SymbolFileDWARF::InitializeObject() |
| 518 | { |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 519 | ModuleSP module_sp (m_obj_file->GetModule()); |
| 520 | if (module_sp) |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 521 | { |
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 522 | const SectionList *section_list = module_sp->GetSectionList(); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 523 | |
| 524 | const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get(); |
| 525 | |
| 526 | // Memory map the DWARF mach-o segment so we have everything mmap'ed |
| 527 | // to keep our heap memory usage down. |
| 528 | if (section) |
| Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 529 | m_obj_file->MemoryMapSectionData(section, m_dwarf_data); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 530 | } |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 531 | get_apple_names_data(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 532 | if (m_data_apple_names.GetByteSize() > 0) |
| 533 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 534 | m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names")); |
| 535 | if (m_apple_names_ap->IsValid()) |
| 536 | m_using_apple_tables = true; |
| 537 | else |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 538 | m_apple_names_ap.reset(); |
| 539 | } |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 540 | get_apple_types_data(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 541 | if (m_data_apple_types.GetByteSize() > 0) |
| 542 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 543 | m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types")); |
| 544 | if (m_apple_types_ap->IsValid()) |
| 545 | m_using_apple_tables = true; |
| 546 | else |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 547 | m_apple_types_ap.reset(); |
| 548 | } |
| 549 | |
| 550 | get_apple_namespaces_data(); |
| 551 | if (m_data_apple_namespaces.GetByteSize() > 0) |
| 552 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 553 | m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces")); |
| 554 | if (m_apple_namespaces_ap->IsValid()) |
| 555 | m_using_apple_tables = true; |
| 556 | else |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 557 | m_apple_namespaces_ap.reset(); |
| 558 | } |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 559 | |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 560 | get_apple_objc_data(); |
| 561 | if (m_data_apple_objc.GetByteSize() > 0) |
| 562 | { |
| 563 | m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc")); |
| 564 | if (m_apple_objc_ap->IsValid()) |
| 565 | m_using_apple_tables = true; |
| 566 | else |
| 567 | m_apple_objc_ap.reset(); |
| 568 | } |
| Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 569 | |
| 570 | // Set the symbol file to this file if we don't have a debug map symbol |
| 571 | // file as our main symbol file. This allows the clang ASTContext to complete |
| 572 | // types using this symbol file when it needs to complete classes and structures. |
| 573 | if (GetDebugMapSymfile () == nullptr) |
| 574 | GetClangASTContext().SetSymbolFile(this); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | bool |
| 578 | SymbolFileDWARF::SupportedVersion(uint16_t version) |
| 579 | { |
| Greg Clayton | abcbfe5 | 2013-04-04 00:00:36 +0000 | [diff] [blame] | 580 | return version == 2 || version == 3 || version == 4; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | uint32_t |
| Sean Callanan | bfaf54d | 2011-12-03 04:38:43 +0000 | [diff] [blame] | 584 | SymbolFileDWARF::CalculateAbilities () |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 585 | { |
| 586 | uint32_t abilities = 0; |
| 587 | if (m_obj_file != NULL) |
| 588 | { |
| 589 | const Section* section = NULL; |
| 590 | const SectionList *section_list = m_obj_file->GetSectionList(); |
| 591 | if (section_list == NULL) |
| 592 | return 0; |
| 593 | |
| 594 | uint64_t debug_abbrev_file_size = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 595 | uint64_t debug_info_file_size = 0; |
| 596 | uint64_t debug_line_file_size = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 597 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 598 | section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 599 | |
| 600 | if (section) |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 601 | section_list = §ion->GetChildren (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 602 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 603 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 604 | if (section != NULL) |
| 605 | { |
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 606 | debug_info_file_size = section->GetFileSize(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 607 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 608 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 609 | if (section) |
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 610 | debug_abbrev_file_size = section->GetFileSize(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 611 | else |
| 612 | m_flags.Set (flagsGotDebugAbbrevData); |
| 613 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 614 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 615 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 616 | m_flags.Set (flagsGotDebugArangesData); |
| 617 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 618 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 619 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 620 | m_flags.Set (flagsGotDebugFrameData); |
| 621 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 622 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 623 | if (section) |
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 624 | debug_line_file_size = section->GetFileSize(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 625 | else |
| 626 | m_flags.Set (flagsGotDebugLineData); |
| 627 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 628 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 629 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 630 | m_flags.Set (flagsGotDebugLocData); |
| 631 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 632 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 633 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 634 | m_flags.Set (flagsGotDebugMacInfoData); |
| 635 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 636 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 637 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 638 | m_flags.Set (flagsGotDebugPubNamesData); |
| 639 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 640 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 641 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 642 | m_flags.Set (flagsGotDebugPubTypesData); |
| 643 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 644 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 645 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 646 | m_flags.Set (flagsGotDebugRangesData); |
| 647 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 648 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 649 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 650 | m_flags.Set (flagsGotDebugStrData); |
| 651 | } |
| Greg Clayton | 6c59661 | 2012-05-18 21:47:20 +0000 | [diff] [blame] | 652 | else |
| 653 | { |
| 654 | const char *symfile_dir_cstr = m_obj_file->GetFileSpec().GetDirectory().GetCString(); |
| 655 | if (symfile_dir_cstr) |
| 656 | { |
| 657 | if (strcasestr(symfile_dir_cstr, ".dsym")) |
| 658 | { |
| 659 | if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo) |
| 660 | { |
| 661 | // We have a dSYM file that didn't have a any debug info. |
| 662 | // If the string table has a size of 1, then it was made from |
| 663 | // an executable with no debug info, or from an executable that |
| 664 | // was stripped. |
| 665 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get(); |
| 666 | if (section && section->GetFileSize() == 1) |
| 667 | { |
| 668 | m_obj_file->GetModule()->ReportWarning ("empty dSYM file detected, dSYM was created with an executable with no debug info."); |
| 669 | } |
| 670 | } |
| 671 | } |
| 672 | } |
| 673 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 674 | |
| 675 | if (debug_abbrev_file_size > 0 && debug_info_file_size > 0) |
| 676 | abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes; |
| 677 | |
| 678 | if (debug_line_file_size > 0) |
| 679 | abilities |= LineTables; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 680 | } |
| 681 | return abilities; |
| 682 | } |
| 683 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 684 | const DWARFDataExtractor& |
| 685 | SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DWARFDataExtractor &data) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 686 | { |
| 687 | if (m_flags.IsClear (got_flag)) |
| 688 | { |
| Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 689 | ModuleSP module_sp (m_obj_file->GetModule()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 690 | m_flags.Set (got_flag); |
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 691 | const SectionList *section_list = module_sp->GetSectionList(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 692 | if (section_list) |
| 693 | { |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 694 | SectionSP section_sp (section_list->FindSectionByType(sect_type, true)); |
| 695 | if (section_sp) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 696 | { |
| 697 | // See if we memory mapped the DWARF segment? |
| 698 | if (m_dwarf_data.GetByteSize()) |
| 699 | { |
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 700 | data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetFileSize()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 701 | } |
| 702 | else |
| 703 | { |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 704 | if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 705 | data.Clear(); |
| 706 | } |
| 707 | } |
| 708 | } |
| 709 | } |
| 710 | return data; |
| 711 | } |
| 712 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 713 | const DWARFDataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 714 | SymbolFileDWARF::get_debug_abbrev_data() |
| 715 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 716 | return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 717 | } |
| 718 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 719 | const DWARFDataExtractor& |
| Tamas Berghammer | c178d4c | 2015-08-25 11:45:58 +0000 | [diff] [blame] | 720 | SymbolFileDWARF::get_debug_addr_data() |
| 721 | { |
| 722 | return GetCachedSectionData (flagsGotDebugAddrData, eSectionTypeDWARFDebugAddr, m_data_debug_addr); |
| 723 | } |
| 724 | |
| 725 | const DWARFDataExtractor& |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 726 | SymbolFileDWARF::get_debug_aranges_data() |
| 727 | { |
| 728 | return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges); |
| 729 | } |
| 730 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 731 | const DWARFDataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 732 | SymbolFileDWARF::get_debug_frame_data() |
| 733 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 734 | return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 735 | } |
| 736 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 737 | const DWARFDataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 738 | SymbolFileDWARF::get_debug_info_data() |
| 739 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 740 | return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 741 | } |
| 742 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 743 | const DWARFDataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 744 | SymbolFileDWARF::get_debug_line_data() |
| 745 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 746 | return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 747 | } |
| 748 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 749 | const DWARFDataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 750 | SymbolFileDWARF::get_debug_loc_data() |
| 751 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 752 | return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 753 | } |
| 754 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 755 | const DWARFDataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 756 | SymbolFileDWARF::get_debug_ranges_data() |
| 757 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 758 | return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 759 | } |
| 760 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 761 | const DWARFDataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 762 | SymbolFileDWARF::get_debug_str_data() |
| 763 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 764 | return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 765 | } |
| 766 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 767 | const DWARFDataExtractor& |
| Tamas Berghammer | c178d4c | 2015-08-25 11:45:58 +0000 | [diff] [blame] | 768 | SymbolFileDWARF::get_debug_str_offsets_data() |
| 769 | { |
| 770 | return GetCachedSectionData (flagsGotDebugStrOffsetsData, eSectionTypeDWARFDebugStrOffsets, m_data_debug_str_offsets); |
| 771 | } |
| 772 | |
| 773 | const DWARFDataExtractor& |
| Greg Clayton | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 774 | SymbolFileDWARF::get_apple_names_data() |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 775 | { |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 776 | return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names); |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 777 | } |
| 778 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 779 | const DWARFDataExtractor& |
| Greg Clayton | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 780 | SymbolFileDWARF::get_apple_types_data() |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 781 | { |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 782 | return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types); |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 783 | } |
| 784 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 785 | const DWARFDataExtractor& |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 786 | SymbolFileDWARF::get_apple_namespaces_data() |
| 787 | { |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 788 | return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces); |
| 789 | } |
| 790 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 791 | const DWARFDataExtractor& |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 792 | SymbolFileDWARF::get_apple_objc_data() |
| 793 | { |
| 794 | return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 795 | } |
| 796 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 797 | |
| 798 | DWARFDebugAbbrev* |
| 799 | SymbolFileDWARF::DebugAbbrev() |
| 800 | { |
| 801 | if (m_abbr.get() == NULL) |
| 802 | { |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 803 | const DWARFDataExtractor &debug_abbrev_data = get_debug_abbrev_data(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 804 | if (debug_abbrev_data.GetByteSize() > 0) |
| 805 | { |
| 806 | m_abbr.reset(new DWARFDebugAbbrev()); |
| 807 | if (m_abbr.get()) |
| 808 | m_abbr->Parse(debug_abbrev_data); |
| 809 | } |
| 810 | } |
| 811 | return m_abbr.get(); |
| 812 | } |
| 813 | |
| 814 | const DWARFDebugAbbrev* |
| 815 | SymbolFileDWARF::DebugAbbrev() const |
| 816 | { |
| 817 | return m_abbr.get(); |
| 818 | } |
| 819 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 820 | |
| 821 | DWARFDebugInfo* |
| 822 | SymbolFileDWARF::DebugInfo() |
| 823 | { |
| 824 | if (m_info.get() == NULL) |
| 825 | { |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 826 | Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", |
| 827 | __PRETTY_FUNCTION__, static_cast<void*>(this)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 828 | if (get_debug_info_data().GetByteSize() > 0) |
| 829 | { |
| 830 | m_info.reset(new DWARFDebugInfo()); |
| 831 | if (m_info.get()) |
| 832 | { |
| 833 | m_info->SetDwarfData(this); |
| 834 | } |
| 835 | } |
| 836 | } |
| 837 | return m_info.get(); |
| 838 | } |
| 839 | |
| 840 | const DWARFDebugInfo* |
| 841 | SymbolFileDWARF::DebugInfo() const |
| 842 | { |
| 843 | return m_info.get(); |
| 844 | } |
| 845 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 846 | DWARFCompileUnit* |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 847 | SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 848 | { |
| Greg Clayton | ea4a5bb | 2015-09-04 22:29:46 +0000 | [diff] [blame] | 849 | if (!comp_unit) |
| 850 | return nullptr; |
| 851 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 852 | DWARFDebugInfo* info = DebugInfo(); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 853 | if (info) |
| 854 | { |
| 855 | if (GetDebugMapSymfile ()) |
| 856 | { |
| 857 | // The debug map symbol file made the compile units for this DWARF |
| 858 | // file which is .o file with DWARF in it, and we should have |
| 859 | // only 1 compile unit which is at offset zero in the DWARF. |
| 860 | // TODO: modify to support LTO .o files where each .o file might |
| 861 | // have multiple DW_TAG_compile_unit tags. |
| Greg Clayton | 68c00bd | 2015-02-05 02:10:29 +0000 | [diff] [blame] | 862 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 863 | DWARFCompileUnit *dwarf_cu = info->GetCompileUnit(0); |
| Greg Clayton | 68c00bd | 2015-02-05 02:10:29 +0000 | [diff] [blame] | 864 | if (dwarf_cu && dwarf_cu->GetUserData() == NULL) |
| 865 | dwarf_cu->SetUserData(comp_unit); |
| 866 | return dwarf_cu; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 867 | } |
| 868 | else |
| 869 | { |
| 870 | // Just a normal DWARF file whose user ID for the compile unit is |
| 871 | // the DWARF offset itself |
| Greg Clayton | 68c00bd | 2015-02-05 02:10:29 +0000 | [diff] [blame] | 872 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 873 | DWARFCompileUnit *dwarf_cu = info->GetCompileUnit((dw_offset_t)comp_unit->GetID()); |
| Greg Clayton | 68c00bd | 2015-02-05 02:10:29 +0000 | [diff] [blame] | 874 | if (dwarf_cu && dwarf_cu->GetUserData() == NULL) |
| 875 | dwarf_cu->SetUserData(comp_unit); |
| 876 | return dwarf_cu; |
| 877 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 878 | } |
| 879 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 880 | return NULL; |
| 881 | } |
| 882 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 883 | |
| 884 | DWARFDebugRanges* |
| 885 | SymbolFileDWARF::DebugRanges() |
| 886 | { |
| 887 | if (m_ranges.get() == NULL) |
| 888 | { |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 889 | Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", |
| 890 | __PRETTY_FUNCTION__, static_cast<void*>(this)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 891 | if (get_debug_ranges_data().GetByteSize() > 0) |
| 892 | { |
| 893 | m_ranges.reset(new DWARFDebugRanges()); |
| 894 | if (m_ranges.get()) |
| 895 | m_ranges->Extract(this); |
| 896 | } |
| 897 | } |
| 898 | return m_ranges.get(); |
| 899 | } |
| 900 | |
| 901 | const DWARFDebugRanges* |
| 902 | SymbolFileDWARF::DebugRanges() const |
| 903 | { |
| 904 | return m_ranges.get(); |
| 905 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 906 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 907 | lldb::CompUnitSP |
| 908 | SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 909 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 910 | CompUnitSP cu_sp; |
| 911 | if (dwarf_cu) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 912 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 913 | CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData(); |
| 914 | if (comp_unit) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 915 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 916 | // We already parsed this compile unit, had out a shared pointer to it |
| 917 | cu_sp = comp_unit->shared_from_this(); |
| 918 | } |
| 919 | else |
| 920 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 921 | if (dwarf_cu->GetSymbolFileDWARF() != this) |
| 922 | { |
| 923 | return dwarf_cu->GetSymbolFileDWARF()->ParseCompileUnit(dwarf_cu, cu_idx); |
| 924 | } |
| 925 | else if (GetDebugMapSymfile ()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 926 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 927 | // Let the debug map create the compile unit |
| 928 | cu_sp = m_debug_map_symfile->GetCompileUnit(this); |
| 929 | dwarf_cu->SetUserData(cu_sp.get()); |
| 930 | } |
| 931 | else |
| 932 | { |
| 933 | ModuleSP module_sp (m_obj_file->GetModule()); |
| 934 | if (module_sp) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 935 | { |
| Greg Clayton | 5ce1a84 | 2015-08-27 18:09:44 +0000 | [diff] [blame] | 936 | const DWARFDIE cu_die = dwarf_cu->GetCompileUnitDIEOnly (); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 937 | if (cu_die) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 938 | { |
| Greg Clayton | 5ce1a84 | 2015-08-27 18:09:44 +0000 | [diff] [blame] | 939 | FileSpec cu_file_spec{cu_die.GetName(), false}; |
| Chaoren Lin | 0c5a9c1 | 2015-06-05 00:28:06 +0000 | [diff] [blame] | 940 | if (cu_file_spec) |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 941 | { |
| Chaoren Lin | 0c5a9c1 | 2015-06-05 00:28:06 +0000 | [diff] [blame] | 942 | // If we have a full path to the compile unit, we don't need to resolve |
| 943 | // the file. This can be expensive e.g. when the source files are NFS mounted. |
| Chaoren Lin | 372e906 | 2015-06-09 17:54:27 +0000 | [diff] [blame] | 944 | if (cu_file_spec.IsRelative()) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 945 | { |
| Greg Clayton | 5ce1a84 | 2015-08-27 18:09:44 +0000 | [diff] [blame] | 946 | const char *cu_comp_dir{cu_die.GetAttributeValueAsString(DW_AT_comp_dir, nullptr)}; |
| Oleksiy Vyalov | 5d9c50b | 2015-07-21 02:09:42 +0000 | [diff] [blame] | 947 | cu_file_spec.PrependPathComponent(resolveCompDir(cu_comp_dir)); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 948 | } |
| 949 | |
| Chaoren Lin | 0c5a9c1 | 2015-06-05 00:28:06 +0000 | [diff] [blame] | 950 | std::string remapped_file; |
| 951 | if (module_sp->RemapSourceFile(cu_file_spec.GetCString(), remapped_file)) |
| 952 | cu_file_spec.SetFile(remapped_file, false); |
| David Srbecky | d515e94 | 2015-07-08 14:00:04 +0000 | [diff] [blame] | 953 | } |
| Chaoren Lin | 0c5a9c1 | 2015-06-05 00:28:06 +0000 | [diff] [blame] | 954 | |
| Greg Clayton | 5ce1a84 | 2015-08-27 18:09:44 +0000 | [diff] [blame] | 955 | LanguageType cu_language = DWARFCompileUnit::LanguageTypeFromDWARF(cu_die.GetAttributeValueAsUnsigned(DW_AT_language, 0)); |
| Chaoren Lin | 0c5a9c1 | 2015-06-05 00:28:06 +0000 | [diff] [blame] | 956 | |
| Jason Molenda | c709958 | 2015-07-31 05:47:00 +0000 | [diff] [blame] | 957 | bool is_optimized = dwarf_cu->GetIsOptimized (); |
| David Srbecky | d515e94 | 2015-07-08 14:00:04 +0000 | [diff] [blame] | 958 | cu_sp.reset(new CompileUnit (module_sp, |
| 959 | dwarf_cu, |
| 960 | cu_file_spec, |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 961 | dwarf_cu->GetID(), |
| Jason Molenda | 6ab659a | 2015-07-29 00:42:47 +0000 | [diff] [blame] | 962 | cu_language, |
| 963 | is_optimized)); |
| David Srbecky | d515e94 | 2015-07-08 14:00:04 +0000 | [diff] [blame] | 964 | if (cu_sp) |
| 965 | { |
| 966 | // If we just created a compile unit with an invalid file spec, try and get the |
| 967 | // first entry in the supports files from the line table as that should be the |
| 968 | // compile unit. |
| 969 | if (!cu_file_spec) |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 970 | { |
| David Srbecky | d515e94 | 2015-07-08 14:00:04 +0000 | [diff] [blame] | 971 | cu_file_spec = cu_sp->GetSupportFiles().GetFileSpecAtIndex(1); |
| 972 | if (cu_file_spec) |
| 973 | { |
| 974 | (FileSpec &)(*cu_sp) = cu_file_spec; |
| 975 | // Also fix the invalid file spec which was copied from the compile unit. |
| 976 | cu_sp->GetSupportFiles().Replace(0, cu_file_spec); |
| 977 | } |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 978 | } |
| David Srbecky | d515e94 | 2015-07-08 14:00:04 +0000 | [diff] [blame] | 979 | |
| 980 | dwarf_cu->SetUserData(cu_sp.get()); |
| 981 | |
| 982 | // Figure out the compile unit index if we weren't given one |
| 983 | if (cu_idx == UINT32_MAX) |
| 984 | DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx); |
| 985 | |
| 986 | m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp); |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 987 | } |
| 988 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 989 | } |
| 990 | } |
| 991 | } |
| 992 | } |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 993 | return cu_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 994 | } |
| 995 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 996 | uint32_t |
| 997 | SymbolFileDWARF::GetNumCompileUnits() |
| 998 | { |
| 999 | DWARFDebugInfo* info = DebugInfo(); |
| 1000 | if (info) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1001 | return info->GetNumCompileUnits(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1002 | return 0; |
| 1003 | } |
| 1004 | |
| 1005 | CompUnitSP |
| 1006 | SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx) |
| 1007 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1008 | CompUnitSP cu_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1009 | DWARFDebugInfo* info = DebugInfo(); |
| 1010 | if (info) |
| 1011 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1012 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx); |
| 1013 | if (dwarf_cu) |
| 1014 | cu_sp = ParseCompileUnit(dwarf_cu, cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1015 | } |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1016 | return cu_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1017 | } |
| 1018 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1019 | Function * |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1020 | SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, const DWARFDIE &die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1021 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1022 | if (die.IsValid()) |
| 1023 | { |
| 1024 | TypeSystem *type_system = GetTypeSystemForLanguage(die.GetCU()->GetLanguageType()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1025 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1026 | if (type_system) |
| 1027 | { |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1028 | DWARFASTParser *dwarf_ast = type_system->GetDWARFParser(); |
| 1029 | if (dwarf_ast) |
| 1030 | return dwarf_ast->ParseFunctionFromDWARF(sc, die); |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1031 | } |
| 1032 | } |
| 1033 | return nullptr; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1034 | } |
| 1035 | |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1036 | bool |
| 1037 | SymbolFileDWARF::FixupAddress (Address &addr) |
| 1038 | { |
| 1039 | SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile (); |
| 1040 | if (debug_map_symfile) |
| 1041 | { |
| 1042 | return debug_map_symfile->LinkOSOAddress(addr); |
| 1043 | } |
| 1044 | // This is a normal DWARF file, no address fixups need to happen |
| 1045 | return true; |
| 1046 | } |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1047 | lldb::LanguageType |
| 1048 | SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc) |
| 1049 | { |
| 1050 | assert (sc.comp_unit); |
| 1051 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| 1052 | if (dwarf_cu) |
| Greg Clayton | 5ce1a84 | 2015-08-27 18:09:44 +0000 | [diff] [blame] | 1053 | return dwarf_cu->GetLanguageType(); |
| 1054 | else |
| 1055 | return eLanguageTypeUnknown; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1056 | } |
| 1057 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1058 | size_t |
| 1059 | SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc) |
| 1060 | { |
| 1061 | assert (sc.comp_unit); |
| 1062 | size_t functions_added = 0; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1063 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1064 | if (dwarf_cu) |
| 1065 | { |
| 1066 | DWARFDIECollection function_dies; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1067 | 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] | 1068 | size_t func_idx; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1069 | for (func_idx = 0; func_idx < num_functions; ++func_idx) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1070 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1071 | DWARFDIE die = function_dies.GetDIEAtIndex(func_idx); |
| 1072 | if (sc.comp_unit->FindFunctionByUID (die.GetID()).get() == NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1073 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1074 | if (ParseCompileUnitFunction(sc, die)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1075 | ++functions_added; |
| 1076 | } |
| 1077 | } |
| 1078 | //FixupTypes(); |
| 1079 | } |
| 1080 | return functions_added; |
| 1081 | } |
| 1082 | |
| 1083 | bool |
| 1084 | SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files) |
| 1085 | { |
| 1086 | assert (sc.comp_unit); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1087 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1088 | if (dwarf_cu) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1089 | { |
| Greg Clayton | 5ce1a84 | 2015-08-27 18:09:44 +0000 | [diff] [blame] | 1090 | const DWARFDIE cu_die = dwarf_cu->GetCompileUnitDIEOnly(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1091 | |
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1092 | if (cu_die) |
| 1093 | { |
| Greg Clayton | 5ce1a84 | 2015-08-27 18:09:44 +0000 | [diff] [blame] | 1094 | const char * cu_comp_dir = resolveCompDir(cu_die.GetAttributeValueAsString(DW_AT_comp_dir, nullptr)); |
| Matthew Gardiner | e81df3b | 2014-08-26 06:57:23 +0000 | [diff] [blame] | 1095 | |
| Greg Clayton | 5ce1a84 | 2015-08-27 18:09:44 +0000 | [diff] [blame] | 1096 | const dw_offset_t stmt_list = cu_die.GetAttributeValueAsUnsigned(DW_AT_stmt_list, DW_INVALID_OFFSET); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1097 | |
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1098 | // All file indexes in DWARF are one based and a file of index zero is |
| 1099 | // supposed to be the compile unit itself. |
| 1100 | support_files.Append (*sc.comp_unit); |
| 1101 | |
| 1102 | return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files); |
| 1103 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1104 | } |
| 1105 | return false; |
| 1106 | } |
| 1107 | |
| Sean Callanan | f0c5aeb | 2015-04-20 16:31:29 +0000 | [diff] [blame] | 1108 | bool |
| 1109 | SymbolFileDWARF::ParseImportedModules (const lldb_private::SymbolContext &sc, std::vector<lldb_private::ConstString> &imported_modules) |
| 1110 | { |
| 1111 | assert (sc.comp_unit); |
| 1112 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| 1113 | if (dwarf_cu) |
| 1114 | { |
| 1115 | if (ClangModulesDeclVendor::LanguageSupportsClangModules(sc.comp_unit->GetLanguage())) |
| 1116 | { |
| 1117 | UpdateExternalModuleListIfNeeded(); |
| 1118 | for (const std::pair<uint64_t, const ClangModuleInfo> &external_type_module : m_external_type_modules) |
| 1119 | { |
| 1120 | imported_modules.push_back(external_type_module.second.m_name); |
| 1121 | } |
| 1122 | } |
| 1123 | } |
| 1124 | return false; |
| 1125 | } |
| 1126 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1127 | struct ParseDWARFLineTableCallbackInfo |
| 1128 | { |
| 1129 | LineTable* line_table; |
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1130 | std::unique_ptr<LineSequence> sequence_ap; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1131 | }; |
| 1132 | |
| 1133 | //---------------------------------------------------------------------- |
| 1134 | // ParseStatementTableCallback |
| 1135 | //---------------------------------------------------------------------- |
| 1136 | static void |
| 1137 | ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData) |
| 1138 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1139 | if (state.row == DWARFDebugLine::State::StartParsingLineTable) |
| 1140 | { |
| 1141 | // Just started parsing the line table |
| 1142 | } |
| 1143 | else if (state.row == DWARFDebugLine::State::DoneParsingLineTable) |
| 1144 | { |
| 1145 | // Done parsing line table, nothing to do for the cleanup |
| 1146 | } |
| 1147 | else |
| 1148 | { |
| 1149 | ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData; |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1150 | LineTable* line_table = info->line_table; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1151 | |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1152 | // If this is our first time here, we need to create a |
| 1153 | // sequence container. |
| 1154 | if (!info->sequence_ap.get()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1155 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1156 | info->sequence_ap.reset(line_table->CreateLineSequenceContainer()); |
| 1157 | assert(info->sequence_ap.get()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1158 | } |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1159 | line_table->AppendLineEntryToSequence (info->sequence_ap.get(), |
| 1160 | state.address, |
| 1161 | state.line, |
| 1162 | state.column, |
| 1163 | state.file, |
| 1164 | state.is_stmt, |
| 1165 | state.basic_block, |
| 1166 | state.prologue_end, |
| 1167 | state.epilogue_begin, |
| 1168 | state.end_sequence); |
| 1169 | if (state.end_sequence) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1170 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1171 | // First, put the current sequence into the line table. |
| 1172 | line_table->InsertSequence(info->sequence_ap.get()); |
| 1173 | // Then, empty it to prepare for the next sequence. |
| 1174 | info->sequence_ap->Clear(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1175 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | bool |
| 1180 | SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc) |
| 1181 | { |
| 1182 | assert (sc.comp_unit); |
| 1183 | if (sc.comp_unit->GetLineTable() != NULL) |
| 1184 | return true; |
| 1185 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1186 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1187 | if (dwarf_cu) |
| 1188 | { |
| Greg Clayton | 5ce1a84 | 2015-08-27 18:09:44 +0000 | [diff] [blame] | 1189 | const DWARFDIE dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly(); |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1190 | if (dwarf_cu_die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1191 | { |
| Greg Clayton | 5ce1a84 | 2015-08-27 18:09:44 +0000 | [diff] [blame] | 1192 | const dw_offset_t cu_line_offset = dwarf_cu_die.GetAttributeValueAsUnsigned(DW_AT_stmt_list, DW_INVALID_OFFSET); |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1193 | if (cu_line_offset != DW_INVALID_OFFSET) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1194 | { |
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1195 | std::unique_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit)); |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1196 | if (line_table_ap.get()) |
| 1197 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1198 | ParseDWARFLineTableCallbackInfo info; |
| 1199 | info.line_table = line_table_ap.get(); |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1200 | lldb::offset_t offset = cu_line_offset; |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1201 | DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info); |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1202 | if (m_debug_map_symfile) |
| 1203 | { |
| 1204 | // We have an object file that has a line table with addresses |
| 1205 | // that are not linked. We need to link the line table and convert |
| 1206 | // the addresses that are relative to the .o file into addresses |
| 1207 | // for the main executable. |
| 1208 | sc.comp_unit->SetLineTable (m_debug_map_symfile->LinkOSOLineTable (this, line_table_ap.get())); |
| 1209 | } |
| 1210 | else |
| 1211 | { |
| 1212 | sc.comp_unit->SetLineTable(line_table_ap.release()); |
| 1213 | return true; |
| 1214 | } |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1215 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1216 | } |
| 1217 | } |
| 1218 | } |
| 1219 | return false; |
| 1220 | } |
| 1221 | |
| 1222 | size_t |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1223 | SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext& sc, |
| 1224 | Block *parent_block, |
| 1225 | const DWARFDIE &orig_die, |
| 1226 | addr_t subprogram_low_pc, |
| 1227 | uint32_t depth) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1228 | { |
| 1229 | size_t blocks_added = 0; |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1230 | DWARFDIE die = orig_die; |
| 1231 | while (die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1232 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1233 | dw_tag_t tag = die.Tag(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1234 | |
| 1235 | switch (tag) |
| 1236 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1237 | case DW_TAG_inlined_subroutine: |
| Greg Clayton | b4d3733 | 2011-08-12 16:22:48 +0000 | [diff] [blame] | 1238 | case DW_TAG_subprogram: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1239 | case DW_TAG_lexical_block: |
| 1240 | { |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1241 | Block *block = NULL; |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1242 | if (tag == DW_TAG_subprogram) |
| 1243 | { |
| 1244 | // Skip any DW_TAG_subprogram DIEs that are inside |
| 1245 | // of a normal or inlined functions. These will be |
| 1246 | // parsed on their own as separate entities. |
| 1247 | |
| 1248 | if (depth > 0) |
| 1249 | break; |
| 1250 | |
| 1251 | block = parent_block; |
| 1252 | } |
| 1253 | else |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1254 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1255 | BlockSP block_sp(new Block (die.GetID())); |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1256 | parent_block->AddChild(block_sp); |
| 1257 | block = block_sp.get(); |
| 1258 | } |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1259 | DWARFRangeList ranges; |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1260 | const char *name = NULL; |
| 1261 | const char *mangled_name = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1262 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1263 | int decl_file = 0; |
| 1264 | int decl_line = 0; |
| 1265 | int decl_column = 0; |
| 1266 | int call_file = 0; |
| 1267 | int call_line = 0; |
| 1268 | int call_column = 0; |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1269 | if (die.GetDIENamesAndRanges (name, |
| 1270 | mangled_name, |
| 1271 | ranges, |
| 1272 | decl_file, decl_line, decl_column, |
| 1273 | call_file, call_line, call_column, nullptr)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1274 | { |
| 1275 | if (tag == DW_TAG_subprogram) |
| 1276 | { |
| 1277 | assert (subprogram_low_pc == LLDB_INVALID_ADDRESS); |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1278 | subprogram_low_pc = ranges.GetMinRangeBase(0); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1279 | } |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1280 | else if (tag == DW_TAG_inlined_subroutine) |
| 1281 | { |
| 1282 | // We get called here for inlined subroutines in two ways. |
| 1283 | // The first time is when we are making the Function object |
| 1284 | // for this inlined concrete instance. Since we're creating a top level block at |
| 1285 | // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to |
| 1286 | // adjust the containing address. |
| 1287 | // The second time is when we are parsing the blocks inside the function that contains |
| 1288 | // the inlined concrete instance. Since these will be blocks inside the containing "real" |
| 1289 | // function the offset will be for that function. |
| 1290 | if (subprogram_low_pc == LLDB_INVALID_ADDRESS) |
| 1291 | { |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1292 | subprogram_low_pc = ranges.GetMinRangeBase(0); |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1293 | } |
| 1294 | } |
| Greg Clayton | 103f309 | 2015-01-15 03:04:37 +0000 | [diff] [blame] | 1295 | |
| 1296 | const size_t num_ranges = ranges.GetSize(); |
| 1297 | for (size_t i = 0; i<num_ranges; ++i) |
| 1298 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1299 | const DWARFRangeList::Entry &range = ranges.GetEntryRef (i); |
| Greg Clayton | 103f309 | 2015-01-15 03:04:37 +0000 | [diff] [blame] | 1300 | const addr_t range_base = range.GetRangeBase(); |
| 1301 | if (range_base >= subprogram_low_pc) |
| 1302 | block->AddRange(Block::Range (range_base - subprogram_low_pc, range.GetByteSize())); |
| 1303 | else |
| 1304 | { |
| 1305 | GetObjectFile()->GetModule()->ReportError ("0x%8.8" PRIx64 ": adding range [0x%" PRIx64 "-0x%" PRIx64 ") which has a base that is less than the function's low PC 0x%" PRIx64 ". Please file a bug and attach the file at the start of this error message", |
| 1306 | block->GetID(), |
| 1307 | range_base, |
| 1308 | range.GetRangeEnd(), |
| 1309 | subprogram_low_pc); |
| 1310 | } |
| 1311 | } |
| 1312 | block->FinalizeRanges (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1313 | |
| 1314 | if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL)) |
| 1315 | { |
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1316 | std::unique_ptr<Declaration> decl_ap; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1317 | if (decl_file != 0 || decl_line != 0 || decl_column != 0) |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1318 | decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), |
| 1319 | decl_line, decl_column)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1320 | |
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1321 | std::unique_ptr<Declaration> call_ap; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1322 | if (call_file != 0 || call_line != 0 || call_column != 0) |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1323 | call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file), |
| 1324 | call_line, call_column)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1325 | |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1326 | block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1327 | } |
| 1328 | |
| 1329 | ++blocks_added; |
| 1330 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1331 | if (die.HasChildren()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1332 | { |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1333 | blocks_added += ParseFunctionBlocks (sc, |
| 1334 | block, |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1335 | die.GetFirstChild(), |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1336 | subprogram_low_pc, |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1337 | depth + 1); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1338 | } |
| 1339 | } |
| 1340 | } |
| 1341 | break; |
| 1342 | default: |
| 1343 | break; |
| 1344 | } |
| 1345 | |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1346 | // Only parse siblings of the block if we are not at depth zero. A depth |
| 1347 | // of zero indicates we are currently parsing the top level |
| 1348 | // DW_TAG_subprogram DIE |
| 1349 | |
| 1350 | if (depth == 0) |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1351 | die.Clear(); |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1352 | else |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1353 | die = die.GetSibling(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1354 | } |
| 1355 | return blocks_added; |
| 1356 | } |
| 1357 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1358 | bool |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1359 | SymbolFileDWARF::ClassOrStructIsVirtual (const DWARFDIE &parent_die) |
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1360 | { |
| 1361 | if (parent_die) |
| 1362 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1363 | for (DWARFDIE die = parent_die.GetFirstChild(); die; die = die.GetSibling()) |
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1364 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1365 | dw_tag_t tag = die.Tag(); |
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1366 | bool check_virtuality = false; |
| 1367 | switch (tag) |
| 1368 | { |
| 1369 | case DW_TAG_inheritance: |
| 1370 | case DW_TAG_subprogram: |
| 1371 | check_virtuality = true; |
| 1372 | break; |
| 1373 | default: |
| 1374 | break; |
| 1375 | } |
| 1376 | if (check_virtuality) |
| 1377 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1378 | if (die.GetAttributeValueAsUnsigned(DW_AT_virtuality, 0) != 0) |
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1379 | return true; |
| 1380 | } |
| 1381 | } |
| 1382 | } |
| 1383 | return false; |
| 1384 | } |
| 1385 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 1386 | CompilerDeclContext |
| 1387 | SymbolFileDWARF::GetDeclContextForUID (lldb::user_id_t type_uid) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1388 | { |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 1389 | if (UserIDMatches(type_uid)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1390 | { |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 1391 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 1392 | if (debug_info) |
| 1393 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 1394 | DWARFDIE die = debug_info->GetDIE(DIERef(type_uid)); |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 1395 | if (die) |
| 1396 | { |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1397 | DWARFASTParser *dwarf_ast = die.GetDWARFParser(); |
| 1398 | if (dwarf_ast) |
| 1399 | return dwarf_ast->GetDeclContextForUIDFromDWARF(die); |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 1400 | } |
| 1401 | } |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 1402 | } |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 1403 | return CompilerDeclContext(); |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 1404 | } |
| 1405 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 1406 | CompilerDeclContext |
| 1407 | SymbolFileDWARF::GetDeclContextContainingUID (lldb::user_id_t type_uid) |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 1408 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1409 | if (UserIDMatches(type_uid)) |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 1410 | { |
| 1411 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 1412 | if (debug_info) |
| 1413 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 1414 | DWARFDIE die = debug_info->GetDIE(DIERef(type_uid)); |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 1415 | if (die) |
| 1416 | { |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1417 | DWARFASTParser *dwarf_ast = die.GetDWARFParser(); |
| 1418 | if (dwarf_ast) |
| 1419 | return dwarf_ast->GetDeclContextContainingUIDFromDWARF(die); |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 1420 | } |
| 1421 | } |
| 1422 | } |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 1423 | return CompilerDeclContext(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1424 | } |
| 1425 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 1426 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1427 | Type* |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 1428 | SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1429 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1430 | if (UserIDMatches(type_uid)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1431 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1432 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 1433 | if (debug_info) |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 1434 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 1435 | DWARFDIE type_die = debug_info->GetDIE (DIERef(type_uid)); |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1436 | if (type_die) |
| 1437 | { |
| 1438 | const bool assert_not_being_parsed = true; |
| 1439 | return ResolveTypeUID (type_die, assert_not_being_parsed); |
| 1440 | } |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 1441 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1442 | } |
| 1443 | return NULL; |
| 1444 | } |
| 1445 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1446 | Type* |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1447 | SymbolFileDWARF::ResolveTypeUID (const DWARFDIE &die, bool assert_not_being_parsed) |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1448 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1449 | if (die) |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1450 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1451 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1452 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1453 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1454 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'", |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1455 | die.GetOffset(), |
| 1456 | die.GetTagAsCString(), |
| 1457 | die.GetName()); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1458 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1459 | // We might be coming in in the middle of a type tree (a class |
| 1460 | // withing a class, an enum within a class), so parse any needed |
| 1461 | // parent DIEs before we get to this one... |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1462 | DWARFDIE decl_ctx_die = GetDeclContextDIEContainingDIE (die); |
| 1463 | if (decl_ctx_die) |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1464 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1465 | if (log) |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1466 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1467 | switch (decl_ctx_die.Tag()) |
| 1468 | { |
| 1469 | case DW_TAG_structure_type: |
| 1470 | case DW_TAG_union_type: |
| 1471 | case DW_TAG_class_type: |
| 1472 | { |
| 1473 | // Get the type, which could be a forward declaration |
| 1474 | if (log) |
| 1475 | GetObjectFile()->GetModule()->LogMessage (log, |
| 1476 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x", |
| 1477 | die.GetOffset(), |
| 1478 | die.GetTagAsCString(), |
| 1479 | die.GetName(), |
| 1480 | decl_ctx_die.GetOffset()); |
| 1481 | } |
| 1482 | break; |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1483 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1484 | default: |
| 1485 | break; |
| 1486 | } |
| 1487 | } |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1488 | } |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1489 | return ResolveType (die); |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1490 | } |
| 1491 | return NULL; |
| 1492 | } |
| 1493 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1494 | // This function is used when SymbolFileDWARFDebugMap owns a bunch of |
| 1495 | // SymbolFileDWARF objects to detect if this DWARF file is the one that |
| 1496 | // can resolve a clang_type. |
| 1497 | bool |
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1498 | SymbolFileDWARF::HasForwardDeclForClangType (const CompilerType &clang_type) |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1499 | { |
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1500 | CompilerType clang_type_no_qualifiers = ClangASTContext::RemoveFastQualifiers(clang_type); |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 1501 | return GetForwardDeclClangTypeToDie().count (clang_type_no_qualifiers.GetOpaqueQualType()); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1502 | } |
| 1503 | |
| 1504 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1505 | bool |
| Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 1506 | SymbolFileDWARF::CompleteType (CompilerType &clang_type) |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1507 | { |
| 1508 | // We have a struct/union/class/enum that needs to be fully resolved. |
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1509 | CompilerType clang_type_no_qualifiers = ClangASTContext::RemoveFastQualifiers(clang_type); |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 1510 | auto die_it = GetForwardDeclClangTypeToDie().find (clang_type_no_qualifiers.GetOpaqueQualType()); |
| 1511 | if (die_it == GetForwardDeclClangTypeToDie().end()) |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1512 | { |
| 1513 | // We have already resolved this type... |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1514 | return true; |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1515 | } |
| 1516 | // Once we start resolving this type, remove it from the forward declaration |
| 1517 | // map in case anyone child members or other types require this type to get resolved. |
| 1518 | // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition |
| 1519 | // are done. |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 1520 | GetForwardDeclClangTypeToDie().erase (clang_type_no_qualifiers.GetOpaqueQualType()); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1521 | |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 1522 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 1523 | |
| 1524 | DWARFDIE dwarf_die = debug_info->GetDIE(die_it->getSecond()); |
| 1525 | Type *type = GetDIEToType().lookup (dwarf_die.GetDIE()); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1526 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1527 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1528 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1529 | GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1530 | "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...", |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1531 | dwarf_die.GetID(), |
| 1532 | dwarf_die.GetTagAsCString(), |
| Greg Clayton | d61c0fc | 2012-04-23 22:55:20 +0000 | [diff] [blame] | 1533 | type->GetName().AsCString()); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1534 | assert (clang_type); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1535 | DWARFASTParser *dwarf_ast = dwarf_die.GetDWARFParser(); |
| 1536 | if (dwarf_ast) |
| 1537 | return dwarf_ast->CompleteTypeFromDWARF (dwarf_die, type, clang_type); |
| Ashok Thirumurthi | a4658a5 | 2013-07-30 14:58:39 +0000 | [diff] [blame] | 1538 | return false; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1539 | } |
| 1540 | |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 1541 | Type* |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1542 | SymbolFileDWARF::ResolveType (const DWARFDIE &die, bool assert_not_being_parsed) |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 1543 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1544 | if (die) |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 1545 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 1546 | Type *type = GetDIEToType().lookup (die.GetDIE()); |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1547 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 1548 | if (type == NULL) |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1549 | type = GetTypeForDIE (die).get(); |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1550 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1551 | if (assert_not_being_parsed) |
| Jim Ingham | c354928 | 2012-01-11 02:21:12 +0000 | [diff] [blame] | 1552 | { |
| 1553 | if (type != DIE_IS_BEING_PARSED) |
| 1554 | return type; |
| 1555 | |
| 1556 | GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s", |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1557 | die.GetOffset(), |
| 1558 | die.GetTagAsCString(), |
| 1559 | die.GetName()); |
| Jim Ingham | c354928 | 2012-01-11 02:21:12 +0000 | [diff] [blame] | 1560 | |
| 1561 | } |
| 1562 | else |
| 1563 | return type; |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 1564 | } |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1565 | return nullptr; |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 1566 | } |
| 1567 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1568 | CompileUnit* |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1569 | SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1570 | { |
| 1571 | // Check if the symbol vendor already knows about this compile unit? |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1572 | if (dwarf_cu->GetUserData() == NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1573 | { |
| 1574 | // The symbol vendor doesn't know about this compile unit, we |
| 1575 | // need to parse and add it to the symbol vendor object. |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1576 | return ParseCompileUnit(dwarf_cu, cu_idx).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1577 | } |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1578 | return (CompileUnit*)dwarf_cu->GetUserData(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1579 | } |
| 1580 | |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 1581 | size_t |
| 1582 | SymbolFileDWARF::GetObjCMethodDIEOffsets (ConstString class_name, DIEArray &method_die_offsets) |
| 1583 | { |
| 1584 | method_die_offsets.clear(); |
| 1585 | if (m_using_apple_tables) |
| 1586 | { |
| 1587 | if (m_apple_objc_ap.get()) |
| 1588 | m_apple_objc_ap->FindByName(class_name.GetCString(), method_die_offsets); |
| 1589 | } |
| 1590 | else |
| 1591 | { |
| 1592 | if (!m_indexed) |
| 1593 | Index (); |
| 1594 | |
| 1595 | m_objc_class_selectors_index.Find (class_name, method_die_offsets); |
| 1596 | } |
| 1597 | return method_die_offsets.size(); |
| 1598 | } |
| 1599 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1600 | bool |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1601 | SymbolFileDWARF::GetFunction (const DWARFDIE &die, SymbolContext& sc) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1602 | { |
| Greg Clayton | 7231035 | 2013-02-23 04:12:47 +0000 | [diff] [blame] | 1603 | sc.Clear(false); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1604 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1605 | if (die) |
| 1606 | { |
| 1607 | // Check if the symbol vendor already knows about this compile unit? |
| 1608 | sc.comp_unit = GetCompUnitForDWARFCompUnit(die.GetCU(), UINT32_MAX); |
| 1609 | |
| 1610 | sc.function = sc.comp_unit->FindFunctionByUID (die.GetID()).get(); |
| 1611 | if (sc.function == NULL) |
| 1612 | sc.function = ParseCompileUnitFunction(sc, die); |
| 1613 | |
| 1614 | if (sc.function) |
| 1615 | { |
| 1616 | sc.module_sp = sc.function->CalculateSymbolContextModule(); |
| 1617 | return true; |
| 1618 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 1619 | } |
| 1620 | |
| 1621 | return false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1622 | } |
| 1623 | |
| Sean Callanan | f0c5aeb | 2015-04-20 16:31:29 +0000 | [diff] [blame] | 1624 | void |
| 1625 | SymbolFileDWARF::UpdateExternalModuleListIfNeeded() |
| 1626 | { |
| 1627 | if (m_fetched_external_modules) |
| 1628 | return; |
| 1629 | m_fetched_external_modules = true; |
| 1630 | |
| 1631 | DWARFDebugInfo * debug_info = DebugInfo(); |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 1632 | |
| Sean Callanan | f0c5aeb | 2015-04-20 16:31:29 +0000 | [diff] [blame] | 1633 | const uint32_t num_compile_units = GetNumCompileUnits(); |
| 1634 | for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) |
| 1635 | { |
| 1636 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); |
| 1637 | |
| Greg Clayton | 5ce1a84 | 2015-08-27 18:09:44 +0000 | [diff] [blame] | 1638 | const DWARFDIE die = dwarf_cu->GetCompileUnitDIEOnly(); |
| 1639 | if (die && die.HasChildren() == false) |
| Sean Callanan | f0c5aeb | 2015-04-20 16:31:29 +0000 | [diff] [blame] | 1640 | { |
| Greg Clayton | 5ce1a84 | 2015-08-27 18:09:44 +0000 | [diff] [blame] | 1641 | const uint64_t name_strp = die.GetAttributeValueAsUnsigned (DW_AT_name, UINT64_MAX); |
| 1642 | const uint64_t dwo_path_strp = die.GetAttributeValueAsUnsigned (DW_AT_GNU_dwo_name, UINT64_MAX); |
| Sean Callanan | f0c5aeb | 2015-04-20 16:31:29 +0000 | [diff] [blame] | 1643 | |
| 1644 | if (name_strp != UINT64_MAX) |
| 1645 | { |
| 1646 | if (m_external_type_modules.find(dwo_path_strp) == m_external_type_modules.end()) |
| 1647 | { |
| 1648 | const char *name = get_debug_str_data().PeekCStr(name_strp); |
| 1649 | const char *dwo_path = get_debug_str_data().PeekCStr(dwo_path_strp); |
| 1650 | if (name || dwo_path) |
| 1651 | { |
| 1652 | ModuleSP module_sp; |
| 1653 | if (dwo_path) |
| 1654 | { |
| 1655 | ModuleSpec dwo_module_spec; |
| 1656 | dwo_module_spec.GetFileSpec().SetFile(dwo_path, false); |
| 1657 | dwo_module_spec.GetArchitecture() = m_obj_file->GetModule()->GetArchitecture(); |
| 1658 | //printf ("Loading dwo = '%s'\n", dwo_path); |
| 1659 | Error error = ModuleList::GetSharedModule (dwo_module_spec, module_sp, NULL, NULL, NULL); |
| 1660 | } |
| 1661 | |
| 1662 | if (dwo_path_strp != LLDB_INVALID_UID) |
| 1663 | { |
| 1664 | m_external_type_modules[dwo_path_strp] = ClangModuleInfo { ConstString(name), module_sp }; |
| 1665 | } |
| 1666 | else |
| 1667 | { |
| 1668 | // This hack should be removed promptly once clang emits both. |
| 1669 | m_external_type_modules[name_strp] = ClangModuleInfo { ConstString(name), module_sp }; |
| 1670 | } |
| 1671 | } |
| 1672 | } |
| 1673 | } |
| 1674 | } |
| 1675 | } |
| 1676 | } |
| Greg Clayton | 2501e5e | 2015-01-15 02:59:20 +0000 | [diff] [blame] | 1677 | |
| 1678 | SymbolFileDWARF::GlobalVariableMap & |
| 1679 | SymbolFileDWARF::GetGlobalAranges() |
| 1680 | { |
| 1681 | if (!m_global_aranges_ap) |
| 1682 | { |
| 1683 | m_global_aranges_ap.reset (new GlobalVariableMap()); |
| 1684 | |
| 1685 | ModuleSP module_sp = GetObjectFile()->GetModule(); |
| 1686 | if (module_sp) |
| 1687 | { |
| 1688 | const size_t num_cus = module_sp->GetNumCompileUnits(); |
| 1689 | for (size_t i = 0; i < num_cus; ++i) |
| 1690 | { |
| 1691 | CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(i); |
| 1692 | if (cu_sp) |
| 1693 | { |
| 1694 | VariableListSP globals_sp = cu_sp->GetVariableList(true); |
| 1695 | if (globals_sp) |
| 1696 | { |
| 1697 | const size_t num_globals = globals_sp->GetSize(); |
| 1698 | for (size_t g = 0; g < num_globals; ++g) |
| 1699 | { |
| 1700 | VariableSP var_sp = globals_sp->GetVariableAtIndex(g); |
| 1701 | if (var_sp && !var_sp->GetLocationIsConstantValueData()) |
| 1702 | { |
| 1703 | const DWARFExpression &location = var_sp->LocationExpression(); |
| 1704 | Value location_result; |
| 1705 | Error error; |
| 1706 | if (location.Evaluate(NULL, NULL, NULL, LLDB_INVALID_ADDRESS, NULL, location_result, &error)) |
| 1707 | { |
| 1708 | if (location_result.GetValueType() == Value::eValueTypeFileAddress) |
| 1709 | { |
| 1710 | lldb::addr_t file_addr = location_result.GetScalar().ULongLong(); |
| 1711 | lldb::addr_t byte_size = 1; |
| 1712 | if (var_sp->GetType()) |
| 1713 | byte_size = var_sp->GetType()->GetByteSize(); |
| 1714 | m_global_aranges_ap->Append(GlobalVariableMap::Entry(file_addr, byte_size, var_sp.get())); |
| 1715 | } |
| 1716 | } |
| 1717 | } |
| 1718 | } |
| 1719 | } |
| 1720 | } |
| 1721 | } |
| 1722 | } |
| 1723 | m_global_aranges_ap->Sort(); |
| 1724 | } |
| 1725 | return *m_global_aranges_ap; |
| 1726 | } |
| 1727 | |
| 1728 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1729 | uint32_t |
| 1730 | SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) |
| 1731 | { |
| 1732 | Timer scoped_timer(__PRETTY_FUNCTION__, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1733 | "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%" PRIx64 " }, resolve_scope = 0x%8.8x)", |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1734 | static_cast<void*>(so_addr.GetSection().get()), |
| 1735 | so_addr.GetOffset(), resolve_scope); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1736 | uint32_t resolved = 0; |
| Greg Clayton | 2501e5e | 2015-01-15 02:59:20 +0000 | [diff] [blame] | 1737 | if (resolve_scope & ( eSymbolContextCompUnit | |
| 1738 | eSymbolContextFunction | |
| 1739 | eSymbolContextBlock | |
| 1740 | eSymbolContextLineEntry | |
| 1741 | eSymbolContextVariable )) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1742 | { |
| 1743 | lldb::addr_t file_vm_addr = so_addr.GetFileAddress(); |
| 1744 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1745 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 1746 | if (debug_info) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1747 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1748 | const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr); |
| Greg Clayton | 2501e5e | 2015-01-15 02:59:20 +0000 | [diff] [blame] | 1749 | if (cu_offset == DW_INVALID_OFFSET) |
| 1750 | { |
| 1751 | // Global variables are not in the compile unit address ranges. The only way to |
| 1752 | // currently find global variables is to iterate over the .debug_pubnames or the |
| 1753 | // __apple_names table and find all items in there that point to DW_TAG_variable |
| 1754 | // DIEs and then find the address that matches. |
| 1755 | if (resolve_scope & eSymbolContextVariable) |
| 1756 | { |
| 1757 | GlobalVariableMap &map = GetGlobalAranges(); |
| 1758 | const GlobalVariableMap::Entry *entry = map.FindEntryThatContains(file_vm_addr); |
| 1759 | if (entry && entry->data) |
| 1760 | { |
| 1761 | Variable *variable = entry->data; |
| 1762 | SymbolContextScope *scc = variable->GetSymbolContextScope(); |
| 1763 | if (scc) |
| 1764 | { |
| 1765 | scc->CalculateSymbolContext(&sc); |
| 1766 | sc.variable = variable; |
| 1767 | } |
| 1768 | return sc.GetResolvedMask(); |
| 1769 | } |
| 1770 | } |
| 1771 | } |
| 1772 | else |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1773 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1774 | uint32_t cu_idx = DW_INVALID_INDEX; |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1775 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx); |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1776 | if (dwarf_cu) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1777 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1778 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1779 | if (sc.comp_unit) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1780 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1781 | resolved |= eSymbolContextCompUnit; |
| 1782 | |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 1783 | bool force_check_line_table = false; |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1784 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) |
| 1785 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1786 | DWARFDIE function_die = dwarf_cu->LookupAddress(file_vm_addr); |
| 1787 | DWARFDIE block_die; |
| 1788 | if (function_die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1789 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1790 | sc.function = sc.comp_unit->FindFunctionByUID (function_die.GetID()).get(); |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1791 | if (sc.function == NULL) |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1792 | sc.function = ParseCompileUnitFunction(sc, function_die); |
| 1793 | |
| 1794 | if (sc.function && (resolve_scope & eSymbolContextBlock)) |
| 1795 | block_die = function_die.LookupDeepestBlock(file_vm_addr); |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1796 | } |
| 1797 | else |
| 1798 | { |
| 1799 | // We might have had a compile unit that had discontiguous |
| 1800 | // address ranges where the gaps are symbols that don't have |
| 1801 | // any debug info. Discontiguous compile unit address ranges |
| 1802 | // should only happen when there aren't other functions from |
| 1803 | // other compile units in these gaps. This helps keep the size |
| 1804 | // of the aranges down. |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 1805 | force_check_line_table = true; |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | if (sc.function != NULL) |
| 1809 | { |
| 1810 | resolved |= eSymbolContextFunction; |
| 1811 | |
| 1812 | if (resolve_scope & eSymbolContextBlock) |
| 1813 | { |
| 1814 | Block& block = sc.function->GetBlock (true); |
| 1815 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1816 | if (block_die) |
| 1817 | sc.block = block.FindBlockByID (block_die.GetID()); |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1818 | else |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1819 | sc.block = block.FindBlockByID (function_die.GetID()); |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1820 | if (sc.block) |
| 1821 | resolved |= eSymbolContextBlock; |
| 1822 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1823 | } |
| 1824 | } |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 1825 | |
| 1826 | if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table) |
| 1827 | { |
| 1828 | LineTable *line_table = sc.comp_unit->GetLineTable(); |
| 1829 | if (line_table != NULL) |
| 1830 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1831 | // And address that makes it into this function should be in terms |
| 1832 | // of this debug file if there is no debug map, or it will be an |
| 1833 | // address in the .o file which needs to be fixed up to be in terms |
| 1834 | // of the debug map executable. Either way, calling FixupAddress() |
| 1835 | // will work for us. |
| 1836 | Address exe_so_addr (so_addr); |
| 1837 | if (FixupAddress(exe_so_addr)) |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 1838 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1839 | if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry)) |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 1840 | { |
| 1841 | resolved |= eSymbolContextLineEntry; |
| 1842 | } |
| 1843 | } |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 1844 | } |
| 1845 | } |
| 1846 | |
| 1847 | if (force_check_line_table && !(resolved & eSymbolContextLineEntry)) |
| 1848 | { |
| 1849 | // We might have had a compile unit that had discontiguous |
| 1850 | // address ranges where the gaps are symbols that don't have |
| 1851 | // any debug info. Discontiguous compile unit address ranges |
| 1852 | // should only happen when there aren't other functions from |
| 1853 | // other compile units in these gaps. This helps keep the size |
| 1854 | // of the aranges down. |
| 1855 | sc.comp_unit = NULL; |
| 1856 | resolved &= ~eSymbolContextCompUnit; |
| 1857 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1858 | } |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1859 | else |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1860 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1861 | GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.", |
| 1862 | cu_offset, |
| 1863 | cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1864 | } |
| 1865 | } |
| 1866 | } |
| 1867 | } |
| 1868 | } |
| 1869 | return resolved; |
| 1870 | } |
| 1871 | |
| 1872 | |
| 1873 | |
| 1874 | uint32_t |
| 1875 | SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) |
| 1876 | { |
| 1877 | const uint32_t prev_size = sc_list.GetSize(); |
| 1878 | if (resolve_scope & eSymbolContextCompUnit) |
| 1879 | { |
| 1880 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 1881 | if (debug_info) |
| 1882 | { |
| 1883 | uint32_t cu_idx; |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1884 | DWARFCompileUnit* dwarf_cu = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1885 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1886 | 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] | 1887 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1888 | CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); |
| Sean Callanan | ddd7a2a | 2013-10-03 22:27:29 +0000 | [diff] [blame] | 1889 | const bool full_match = (bool)file_spec.GetDirectory(); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1890 | 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] | 1891 | if (check_inlines || file_spec_matches_cu_file_spec) |
| 1892 | { |
| 1893 | SymbolContext sc (m_obj_file->GetModule()); |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1894 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1895 | if (sc.comp_unit) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1896 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1897 | uint32_t file_idx = UINT32_MAX; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1898 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1899 | // If we are looking for inline functions only and we don't |
| 1900 | // find it in the support files, we are done. |
| 1901 | if (check_inlines) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1902 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1903 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); |
| 1904 | if (file_idx == UINT32_MAX) |
| 1905 | continue; |
| 1906 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1907 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1908 | if (line != 0) |
| 1909 | { |
| 1910 | LineTable *line_table = sc.comp_unit->GetLineTable(); |
| 1911 | |
| 1912 | if (line_table != NULL && line != 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1913 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1914 | // We will have already looked up the file index if |
| 1915 | // we are searching for inline entries. |
| 1916 | if (!check_inlines) |
| 1917 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1918 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1919 | if (file_idx != UINT32_MAX) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1920 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1921 | uint32_t found_line; |
| 1922 | uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry); |
| 1923 | found_line = sc.line_entry.line; |
| 1924 | |
| 1925 | while (line_idx != UINT32_MAX) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1926 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1927 | sc.function = NULL; |
| 1928 | sc.block = NULL; |
| 1929 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1930 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1931 | const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress(); |
| 1932 | if (file_vm_addr != LLDB_INVALID_ADDRESS) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1933 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1934 | DWARFDIE function_die = dwarf_cu->LookupAddress(file_vm_addr); |
| 1935 | DWARFDIE block_die; |
| 1936 | if (function_die) |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1937 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1938 | sc.function = sc.comp_unit->FindFunctionByUID (function_die.GetID()).get(); |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1939 | if (sc.function == NULL) |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1940 | sc.function = ParseCompileUnitFunction(sc, function_die); |
| 1941 | |
| 1942 | if (sc.function && (resolve_scope & eSymbolContextBlock)) |
| 1943 | block_die = function_die.LookupDeepestBlock(file_vm_addr); |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1944 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1945 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1946 | if (sc.function != NULL) |
| 1947 | { |
| 1948 | Block& block = sc.function->GetBlock (true); |
| 1949 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1950 | if (block_die) |
| 1951 | sc.block = block.FindBlockByID (block_die.GetID()); |
| 1952 | else if (function_die) |
| 1953 | sc.block = block.FindBlockByID (function_die.GetID()); |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1954 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1955 | } |
| 1956 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1957 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1958 | sc_list.Append(sc); |
| 1959 | line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry); |
| 1960 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1961 | } |
| 1962 | } |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1963 | else if (file_spec_matches_cu_file_spec && !check_inlines) |
| 1964 | { |
| 1965 | // only append the context if we aren't looking for inline call sites |
| 1966 | // by file and line and if the file spec matches that of the compile unit |
| 1967 | sc_list.Append(sc); |
| 1968 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1969 | } |
| 1970 | else if (file_spec_matches_cu_file_spec && !check_inlines) |
| 1971 | { |
| 1972 | // only append the context if we aren't looking for inline call sites |
| 1973 | // by file and line and if the file spec matches that of the compile unit |
| 1974 | sc_list.Append(sc); |
| 1975 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1976 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1977 | if (!check_inlines) |
| 1978 | break; |
| 1979 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1980 | } |
| 1981 | } |
| 1982 | } |
| 1983 | } |
| 1984 | return sc_list.GetSize() - prev_size; |
| 1985 | } |
| 1986 | |
| 1987 | void |
| 1988 | SymbolFileDWARF::Index () |
| 1989 | { |
| 1990 | if (m_indexed) |
| 1991 | return; |
| 1992 | m_indexed = true; |
| 1993 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 1994 | "SymbolFileDWARF::Index (%s)", |
| Jim Ingham | 4af5961 | 2014-12-19 19:20:44 +0000 | [diff] [blame] | 1995 | GetObjectFile()->GetFileSpec().GetFilename().AsCString("<Unknown>")); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1996 | |
| 1997 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 1998 | if (debug_info) |
| 1999 | { |
| 2000 | uint32_t cu_idx = 0; |
| 2001 | const uint32_t num_compile_units = GetNumCompileUnits(); |
| 2002 | for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) |
| 2003 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2004 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2005 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2006 | bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2007 | |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 2008 | dwarf_cu->Index (m_function_basename_index, |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2009 | m_function_fullname_index, |
| 2010 | m_function_method_index, |
| 2011 | m_function_selector_index, |
| 2012 | m_objc_class_selectors_index, |
| 2013 | m_global_index, |
| 2014 | m_type_index, |
| 2015 | m_namespace_index); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2016 | |
| 2017 | // Keep memory down by clearing DIEs if this generate function |
| 2018 | // caused them to be parsed |
| 2019 | if (clear_dies) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2020 | dwarf_cu->ClearDIEs (true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2021 | } |
| 2022 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2023 | m_function_basename_index.Finalize(); |
| 2024 | m_function_fullname_index.Finalize(); |
| 2025 | m_function_method_index.Finalize(); |
| 2026 | m_function_selector_index.Finalize(); |
| 2027 | m_objc_class_selectors_index.Finalize(); |
| 2028 | m_global_index.Finalize(); |
| 2029 | m_type_index.Finalize(); |
| 2030 | m_namespace_index.Finalize(); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2031 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2032 | #if defined (ENABLE_DEBUG_PRINTF) |
| Greg Clayton | 7bd65b9 | 2011-02-09 23:39:34 +0000 | [diff] [blame] | 2033 | StreamFile s(stdout, false); |
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 2034 | s.Printf ("DWARF index for '%s':", |
| 2035 | GetObjectFile()->GetFileSpec().GetPath().c_str()); |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 2036 | s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s); |
| 2037 | s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s); |
| 2038 | s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s); |
| 2039 | s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s); |
| 2040 | s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s); |
| 2041 | s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s); |
| Greg Clayton | 69b0488 | 2010-10-15 02:03:22 +0000 | [diff] [blame] | 2042 | s.Printf("\nTypes:\n"); m_type_index.Dump (&s); |
| Bruce Mitchener | e171da5 | 2015-07-22 00:16:02 +0000 | [diff] [blame] | 2043 | s.Printf("\nNamespaces:\n") m_namespace_index.Dump (&s); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2044 | #endif |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2045 | } |
| 2046 | } |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2047 | |
| 2048 | bool |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2049 | SymbolFileDWARF::DeclContextMatchesThisSymbolFile (const lldb_private::CompilerDeclContext *decl_ctx) |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2050 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2051 | if (decl_ctx == nullptr || !decl_ctx->IsValid()) |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2052 | { |
| 2053 | // Invalid namespace decl which means we aren't matching only things |
| 2054 | // in this symbol file, so return true to indicate it matches this |
| 2055 | // symbol file. |
| 2056 | return true; |
| 2057 | } |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2058 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2059 | if ((TypeSystem *)&GetClangASTContext() == decl_ctx->GetTypeSystem()) |
| 2060 | return true; // The type systems match, return true |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2061 | |
| 2062 | // The namespace AST was valid, and it does not match... |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2063 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Sean Callanan | c41e68b | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 2064 | |
| 2065 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2066 | GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file"); |
| Sean Callanan | c41e68b | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 2067 | |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2068 | return false; |
| 2069 | } |
| 2070 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2071 | uint32_t |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2072 | SymbolFileDWARF::FindGlobalVariables (const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, VariableList& variables) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2073 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2074 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2075 | |
| 2076 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2077 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2078 | "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", parent_decl_ctx=%p, append=%u, max_matches=%u, variables)", |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2079 | name.GetCString(), |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2080 | static_cast<const void*>(parent_decl_ctx), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2081 | append, max_matches); |
| 2082 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2083 | if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx)) |
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 2084 | return 0; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2085 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2086 | DWARFDebugInfo* info = DebugInfo(); |
| 2087 | if (info == NULL) |
| 2088 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2089 | |
| 2090 | // If we aren't appending the results to this list, then clear the list |
| 2091 | if (!append) |
| 2092 | variables.Clear(); |
| 2093 | |
| 2094 | // Remember how many variables are in the list before we search in case |
| 2095 | // we are appending the results to a variable list. |
| 2096 | const uint32_t original_size = variables.GetSize(); |
| 2097 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2098 | DIEArray die_offsets; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2099 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2100 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2101 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2102 | if (m_apple_names_ap.get()) |
| 2103 | { |
| 2104 | const char *name_cstr = name.GetCString(); |
| Jim Ingham | fa39bb4 | 2014-10-25 00:33:55 +0000 | [diff] [blame] | 2105 | llvm::StringRef basename; |
| 2106 | llvm::StringRef context; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2107 | |
| Jim Ingham | aa816b8 | 2015-09-02 01:59:14 +0000 | [diff] [blame] | 2108 | if (!CPlusPlusLanguage::ExtractContextAndIdentifier(name_cstr, context, basename)) |
| Jim Ingham | fa39bb4 | 2014-10-25 00:33:55 +0000 | [diff] [blame] | 2109 | basename = name_cstr; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2110 | |
| Jim Ingham | fa39bb4 | 2014-10-25 00:33:55 +0000 | [diff] [blame] | 2111 | m_apple_names_ap->FindByName (basename.data(), die_offsets); |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2112 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2113 | } |
| 2114 | else |
| 2115 | { |
| 2116 | // Index the DWARF if we haven't already |
| 2117 | if (!m_indexed) |
| 2118 | Index (); |
| 2119 | |
| 2120 | m_global_index.Find (name, die_offsets); |
| 2121 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2122 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2123 | const size_t num_die_matches = die_offsets.size(); |
| 2124 | if (num_die_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2125 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2126 | SymbolContext sc; |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 2127 | sc.module_sp = m_obj_file->GetModule(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2128 | assert (sc.module_sp); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2129 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2130 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2131 | bool done = false; |
| 2132 | for (size_t i=0; i<num_die_matches && !done; ++i) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2133 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 2134 | const DIERef& die_ref = die_offsets[i]; |
| 2135 | DWARFDIE die = debug_info->GetDIE (die_ref); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2136 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2137 | if (die) |
| 2138 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2139 | switch (die.Tag()) |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2140 | { |
| 2141 | default: |
| 2142 | case DW_TAG_subprogram: |
| 2143 | case DW_TAG_inlined_subroutine: |
| 2144 | case DW_TAG_try_block: |
| 2145 | case DW_TAG_catch_block: |
| 2146 | break; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2147 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2148 | case DW_TAG_variable: |
| 2149 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2150 | sc.comp_unit = GetCompUnitForDWARFCompUnit(die.GetCU(), UINT32_MAX); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2151 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2152 | if (parent_decl_ctx) |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 2153 | { |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 2154 | DWARFASTParser *dwarf_ast = die.GetDWARFParser(); |
| 2155 | if (dwarf_ast) |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2156 | { |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 2157 | CompilerDeclContext actual_parent_decl_ctx = dwarf_ast->GetDeclContextContainingUIDFromDWARF (die); |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2158 | if (!actual_parent_decl_ctx || actual_parent_decl_ctx != *parent_decl_ctx) |
| 2159 | continue; |
| 2160 | } |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 2161 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2162 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2163 | ParseVariables(sc, die, LLDB_INVALID_ADDRESS, false, false, &variables); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2164 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2165 | if (variables.GetSize() - original_size >= max_matches) |
| 2166 | done = true; |
| 2167 | } |
| 2168 | break; |
| 2169 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2170 | } |
| 2171 | else |
| 2172 | { |
| 2173 | if (m_using_apple_tables) |
| 2174 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2175 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n", |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 2176 | die_ref.die_offset, name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2177 | } |
| 2178 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2179 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2180 | } |
| 2181 | |
| 2182 | // Return the number of variable that were appended to the list |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2183 | const uint32_t num_matches = variables.GetSize() - original_size; |
| 2184 | if (log && num_matches > 0) |
| 2185 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2186 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2187 | "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", parent_decl_ctx=%p, append=%u, max_matches=%u, variables) => %u", |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2188 | name.GetCString(), |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2189 | static_cast<const void*>(parent_decl_ctx), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2190 | append, max_matches, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2191 | num_matches); |
| 2192 | } |
| 2193 | return num_matches; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2194 | } |
| 2195 | |
| 2196 | uint32_t |
| 2197 | SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables) |
| 2198 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2199 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2200 | |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2201 | if (log) |
| 2202 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2203 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2204 | "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)", |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2205 | regex.GetText(), append, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2206 | max_matches); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2207 | } |
| 2208 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2209 | DWARFDebugInfo* info = DebugInfo(); |
| 2210 | if (info == NULL) |
| 2211 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2212 | |
| 2213 | // If we aren't appending the results to this list, then clear the list |
| 2214 | if (!append) |
| 2215 | variables.Clear(); |
| 2216 | |
| 2217 | // Remember how many variables are in the list before we search in case |
| 2218 | // we are appending the results to a variable list. |
| 2219 | const uint32_t original_size = variables.GetSize(); |
| 2220 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2221 | DIEArray die_offsets; |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 2222 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2223 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2224 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2225 | if (m_apple_names_ap.get()) |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 2226 | { |
| 2227 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 2228 | if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) |
| 2229 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| 2230 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2231 | } |
| 2232 | else |
| 2233 | { |
| 2234 | // Index the DWARF if we haven't already |
| 2235 | if (!m_indexed) |
| 2236 | Index (); |
| 2237 | |
| 2238 | m_global_index.Find (regex, die_offsets); |
| 2239 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2240 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2241 | SymbolContext sc; |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 2242 | sc.module_sp = m_obj_file->GetModule(); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2243 | assert (sc.module_sp); |
| 2244 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2245 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2246 | if (num_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2247 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2248 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2249 | for (size_t i=0; i<num_matches; ++i) |
| 2250 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 2251 | const DIERef& die_ref = die_offsets[i]; |
| 2252 | DWARFDIE die = debug_info->GetDIE (die_ref); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2253 | |
| 2254 | if (die) |
| 2255 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2256 | sc.comp_unit = GetCompUnitForDWARFCompUnit(die.GetCU(), UINT32_MAX); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2257 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2258 | ParseVariables(sc, die, LLDB_INVALID_ADDRESS, false, false, &variables); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2259 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2260 | if (variables.GetSize() - original_size >= max_matches) |
| 2261 | break; |
| 2262 | } |
| 2263 | else |
| 2264 | { |
| 2265 | if (m_using_apple_tables) |
| 2266 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2267 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n", |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 2268 | die_ref.die_offset, regex.GetText()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2269 | } |
| 2270 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2271 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2272 | } |
| 2273 | |
| 2274 | // Return the number of variable that were appended to the list |
| 2275 | return variables.GetSize() - original_size; |
| 2276 | } |
| 2277 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2278 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2279 | bool |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 2280 | SymbolFileDWARF::ResolveFunction (const DIERef& die_ref, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2281 | bool include_inlines, |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2282 | SymbolContextList& sc_list) |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2283 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 2284 | DWARFDIE die = DebugInfo()->GetDIE (die_ref); |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2285 | return ResolveFunction (die, include_inlines, sc_list); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2286 | } |
| 2287 | |
| 2288 | |
| 2289 | bool |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2290 | SymbolFileDWARF::ResolveFunction (const DWARFDIE &orig_die, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2291 | bool include_inlines, |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2292 | SymbolContextList& sc_list) |
| 2293 | { |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2294 | SymbolContext sc; |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2295 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2296 | if (!orig_die) |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2297 | return false; |
| 2298 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2299 | // If we were passed a die that is not a function, just return false... |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2300 | if (!(orig_die.Tag() == DW_TAG_subprogram || (include_inlines && orig_die.Tag() == DW_TAG_inlined_subroutine))) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2301 | return false; |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2302 | |
| 2303 | DWARFDIE die = orig_die; |
| 2304 | DWARFDIE inlined_die; |
| 2305 | if (die.Tag() == DW_TAG_inlined_subroutine) |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2306 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2307 | inlined_die = die; |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2308 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2309 | while (1) |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 2310 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2311 | die = die.GetParent(); |
| 2312 | |
| 2313 | if (die) |
| 2314 | { |
| 2315 | if (die.Tag() == DW_TAG_subprogram) |
| 2316 | break; |
| 2317 | } |
| 2318 | else |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2319 | break; |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2320 | } |
| 2321 | } |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2322 | assert (die && die.Tag() == DW_TAG_subprogram); |
| 2323 | if (GetFunction (die, sc)) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2324 | { |
| 2325 | Address addr; |
| 2326 | // Parse all blocks if needed |
| 2327 | if (inlined_die) |
| 2328 | { |
| Greg Clayton | f7bb1fb | 2015-01-15 03:13:44 +0000 | [diff] [blame] | 2329 | Block &function_block = sc.function->GetBlock (true); |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2330 | sc.block = function_block.FindBlockByID (inlined_die.GetID()); |
| Greg Clayton | f7bb1fb | 2015-01-15 03:13:44 +0000 | [diff] [blame] | 2331 | if (sc.block == NULL) |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2332 | sc.block = function_block.FindBlockByID (inlined_die.GetOffset()); |
| Greg Clayton | f7bb1fb | 2015-01-15 03:13:44 +0000 | [diff] [blame] | 2333 | if (sc.block == NULL || sc.block->GetStartAddress (addr) == false) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2334 | addr.Clear(); |
| 2335 | } |
| 2336 | else |
| 2337 | { |
| 2338 | sc.block = NULL; |
| 2339 | addr = sc.function->GetAddressRange().GetBaseAddress(); |
| 2340 | } |
| 2341 | |
| 2342 | if (addr.IsValid()) |
| 2343 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2344 | sc_list.Append(sc); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2345 | return true; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2346 | } |
| 2347 | } |
| 2348 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2349 | return false; |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2350 | } |
| 2351 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2352 | void |
| 2353 | SymbolFileDWARF::FindFunctions (const ConstString &name, |
| 2354 | const NameToDIE &name_to_die, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2355 | bool include_inlines, |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2356 | SymbolContextList& sc_list) |
| 2357 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2358 | DIEArray die_offsets; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2359 | if (name_to_die.Find (name, die_offsets)) |
| 2360 | { |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2361 | ParseFunctions (die_offsets, include_inlines, sc_list); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2362 | } |
| 2363 | } |
| 2364 | |
| 2365 | |
| 2366 | void |
| 2367 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, |
| 2368 | const NameToDIE &name_to_die, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2369 | bool include_inlines, |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2370 | SymbolContextList& sc_list) |
| 2371 | { |
| 2372 | DIEArray die_offsets; |
| 2373 | if (name_to_die.Find (regex, die_offsets)) |
| 2374 | { |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2375 | ParseFunctions (die_offsets, include_inlines, sc_list); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2376 | } |
| 2377 | } |
| 2378 | |
| 2379 | |
| 2380 | void |
| 2381 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, |
| 2382 | const DWARFMappedHash::MemoryTable &memory_table, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2383 | bool include_inlines, |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2384 | SymbolContextList& sc_list) |
| 2385 | { |
| 2386 | DIEArray die_offsets; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 2387 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 2388 | if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2389 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 2390 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2391 | ParseFunctions (die_offsets, include_inlines, sc_list); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2392 | } |
| 2393 | } |
| 2394 | |
| 2395 | void |
| 2396 | SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2397 | bool include_inlines, |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2398 | SymbolContextList& sc_list) |
| 2399 | { |
| 2400 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2401 | if (num_matches) |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2402 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2403 | for (size_t i=0; i<num_matches; ++i) |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 2404 | ResolveFunction (die_offsets[i], include_inlines, sc_list); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2405 | } |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2406 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2407 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2408 | bool |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2409 | SymbolFileDWARF::DIEInDeclContext (const CompilerDeclContext *decl_ctx, |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2410 | const DWARFDIE &die) |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2411 | { |
| 2412 | // If we have no parent decl context to match this DIE matches, and if the parent |
| 2413 | // decl context isn't valid, we aren't trying to look for any particular decl |
| 2414 | // context so any die matches. |
| 2415 | if (decl_ctx == nullptr || !decl_ctx->IsValid()) |
| 2416 | return true; |
| 2417 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2418 | if (die) |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2419 | { |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 2420 | DWARFASTParser *dwarf_ast = die.GetDWARFParser(); |
| 2421 | if (dwarf_ast) |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2422 | { |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 2423 | CompilerDeclContext actual_decl_ctx = dwarf_ast->GetDeclContextContainingUIDFromDWARF (die); |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2424 | if (actual_decl_ctx) |
| 2425 | return actual_decl_ctx == *decl_ctx; |
| 2426 | } |
| 2427 | } |
| 2428 | return false; |
| 2429 | } |
| 2430 | |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2431 | uint32_t |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2432 | SymbolFileDWARF::FindFunctions (const ConstString &name, |
| 2433 | const CompilerDeclContext *parent_decl_ctx, |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 2434 | uint32_t name_type_mask, |
| 2435 | bool include_inlines, |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 2436 | bool append, |
| 2437 | SymbolContextList& sc_list) |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2438 | { |
| 2439 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 2440 | "SymbolFileDWARF::FindFunctions (name = '%s')", |
| 2441 | name.AsCString()); |
| 2442 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2443 | // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup() |
| 2444 | assert ((name_type_mask & eFunctionNameTypeAuto) == 0); |
| 2445 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2446 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2447 | |
| 2448 | if (log) |
| 2449 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2450 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2451 | "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)", |
| 2452 | name.GetCString(), |
| 2453 | name_type_mask, |
| 2454 | append); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2455 | } |
| 2456 | |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2457 | // If we aren't appending the results to this list, then clear the list |
| 2458 | if (!append) |
| 2459 | sc_list.Clear(); |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2460 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2461 | if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx)) |
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 2462 | return 0; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2463 | |
| 2464 | // If name is empty then we won't find anything. |
| 2465 | if (name.IsEmpty()) |
| 2466 | return 0; |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2467 | |
| 2468 | // Remember how many sc_list are in the list before we search in case |
| 2469 | // we are appending the results to a variable list. |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2470 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2471 | const char *name_cstr = name.GetCString(); |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2472 | |
| 2473 | const uint32_t original_size = sc_list.GetSize(); |
| 2474 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2475 | DWARFDebugInfo* info = DebugInfo(); |
| 2476 | if (info == NULL) |
| 2477 | return 0; |
| 2478 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2479 | std::set<const DWARFDebugInfoEntry *> resolved_dies; |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2480 | if (m_using_apple_tables) |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 2481 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2482 | if (m_apple_names_ap.get()) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2483 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2484 | |
| 2485 | DIEArray die_offsets; |
| 2486 | |
| 2487 | uint32_t num_matches = 0; |
| 2488 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2489 | if (name_type_mask & eFunctionNameTypeFull) |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2490 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2491 | // If they asked for the full name, match what they typed. At some point we may |
| 2492 | // want to canonicalize this (strip double spaces, etc. For now, we just add all the |
| 2493 | // dies that we find by exact match. |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2494 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2495 | for (uint32_t i = 0; i < num_matches; i++) |
| 2496 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 2497 | const DIERef& die_ref = die_offsets[i]; |
| 2498 | DWARFDIE die = info->GetDIE (die_ref); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2499 | if (die) |
| 2500 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2501 | if (!DIEInDeclContext(parent_decl_ctx, die)) |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2502 | continue; // The containing decl contexts don't match |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 2503 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2504 | if (resolved_dies.find(die.GetDIE()) == resolved_dies.end()) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2505 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2506 | if (ResolveFunction (die, include_inlines, sc_list)) |
| 2507 | resolved_dies.insert(die.GetDIE()); |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2508 | } |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2509 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2510 | else |
| 2511 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2512 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 2513 | die_ref.die_offset, name_cstr); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2514 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2515 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2516 | } |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2517 | |
| 2518 | if (name_type_mask & eFunctionNameTypeSelector) |
| 2519 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2520 | if (parent_decl_ctx && parent_decl_ctx->IsValid()) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2521 | return 0; // no selectors in namespaces |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2522 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2523 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); |
| 2524 | // Now make sure these are actually ObjC methods. In this case we can simply look up the name, |
| 2525 | // and if it is an ObjC method name, we're good. |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2526 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2527 | for (uint32_t i = 0; i < num_matches; i++) |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2528 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 2529 | const DIERef& die_ref = die_offsets[i]; |
| 2530 | DWARFDIE die = info->GetDIE (die_ref); |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2531 | if (die) |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2532 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2533 | const char *die_name = die.GetName(); |
| Jim Ingham | aa816b8 | 2015-09-02 01:59:14 +0000 | [diff] [blame] | 2534 | if (ObjCLanguage::IsPossibleObjCMethodName(die_name)) |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2535 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2536 | if (resolved_dies.find(die.GetDIE()) == resolved_dies.end()) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2537 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2538 | if (ResolveFunction (die, include_inlines, sc_list)) |
| 2539 | resolved_dies.insert(die.GetDIE()); |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2540 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2541 | } |
| 2542 | } |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2543 | else |
| 2544 | { |
| 2545 | GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 2546 | die_ref.die_offset, name_cstr); |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2547 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2548 | } |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2549 | die_offsets.clear(); |
| 2550 | } |
| 2551 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2552 | if (((name_type_mask & eFunctionNameTypeMethod) && !parent_decl_ctx) || name_type_mask & eFunctionNameTypeBase) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2553 | { |
| 2554 | // The apple_names table stores just the "base name" of C++ methods in the table. So we have to |
| 2555 | // extract the base name, look that up, and if there is any other information in the name we were |
| 2556 | // passed in we have to post-filter based on that. |
| 2557 | |
| 2558 | // FIXME: Arrange the logic above so that we don't calculate the base name twice: |
| 2559 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); |
| 2560 | |
| 2561 | for (uint32_t i = 0; i < num_matches; i++) |
| 2562 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 2563 | const DIERef& die_ref = die_offsets[i]; |
| 2564 | DWARFDIE die = info->GetDIE (die_ref); |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2565 | if (die) |
| 2566 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2567 | if (!DIEInDeclContext(parent_decl_ctx, die)) |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2568 | continue; // The containing decl contexts don't match |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 2569 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2570 | |
| 2571 | // If we get to here, the die is good, and we should add it: |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2572 | if (resolved_dies.find(die.GetDIE()) == resolved_dies.end() && ResolveFunction (die, include_inlines, sc_list)) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2573 | { |
| 2574 | bool keep_die = true; |
| 2575 | if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod)) |
| 2576 | { |
| 2577 | // We are looking for either basenames or methods, so we need to |
| 2578 | // trim out the ones we won't want by looking at the type |
| 2579 | SymbolContext sc; |
| 2580 | if (sc_list.GetLastContext(sc)) |
| 2581 | { |
| 2582 | if (sc.block) |
| 2583 | { |
| 2584 | // We have an inlined function |
| 2585 | } |
| 2586 | else if (sc.function) |
| 2587 | { |
| 2588 | Type *type = sc.function->GetType(); |
| 2589 | |
| Sean Callanan | c370a8a | 2013-09-18 22:59:55 +0000 | [diff] [blame] | 2590 | if (type) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2591 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2592 | CompilerDeclContext decl_ctx = GetDeclContextContainingUID (type->GetID()); |
| 2593 | if (decl_ctx.IsStructUnionOrClass()) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2594 | { |
| Sean Callanan | c370a8a | 2013-09-18 22:59:55 +0000 | [diff] [blame] | 2595 | if (name_type_mask & eFunctionNameTypeBase) |
| 2596 | { |
| 2597 | sc_list.RemoveContextAtIndex(sc_list.GetSize()-1); |
| 2598 | keep_die = false; |
| 2599 | } |
| 2600 | } |
| 2601 | else |
| 2602 | { |
| 2603 | if (name_type_mask & eFunctionNameTypeMethod) |
| 2604 | { |
| 2605 | sc_list.RemoveContextAtIndex(sc_list.GetSize()-1); |
| 2606 | keep_die = false; |
| 2607 | } |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2608 | } |
| 2609 | } |
| 2610 | else |
| 2611 | { |
| Sean Callanan | c370a8a | 2013-09-18 22:59:55 +0000 | [diff] [blame] | 2612 | GetObjectFile()->GetModule()->ReportWarning ("function at die offset 0x%8.8x had no function type", |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 2613 | die_ref.die_offset); |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2614 | } |
| 2615 | } |
| 2616 | } |
| 2617 | } |
| 2618 | if (keep_die) |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2619 | resolved_dies.insert(die.GetDIE()); |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2620 | } |
| 2621 | } |
| 2622 | else |
| 2623 | { |
| 2624 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 2625 | die_ref.die_offset, name_cstr); |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2626 | } |
| 2627 | } |
| 2628 | die_offsets.clear(); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2629 | } |
| 2630 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2631 | } |
| 2632 | else |
| 2633 | { |
| 2634 | |
| 2635 | // Index the DWARF if we haven't already |
| 2636 | if (!m_indexed) |
| 2637 | Index (); |
| 2638 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2639 | if (name_type_mask & eFunctionNameTypeFull) |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 2640 | { |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2641 | FindFunctions (name, m_function_fullname_index, include_inlines, sc_list); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2642 | |
| Ed Maste | fc7baa0 | 2013-09-09 18:00:45 +0000 | [diff] [blame] | 2643 | // FIXME Temporary workaround for global/anonymous namespace |
| Robert Flack | 5cbd3bf | 2015-05-13 18:20:02 +0000 | [diff] [blame] | 2644 | // functions debugging FreeBSD and Linux binaries. |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 2645 | // If we didn't find any functions in the global namespace try |
| 2646 | // looking in the basename index but ignore any returned |
| Robert Flack | eb83fab | 2015-05-15 18:59:59 +0000 | [diff] [blame] | 2647 | // functions that have a namespace but keep functions which |
| 2648 | // have an anonymous namespace |
| 2649 | // TODO: The arch in the object file isn't correct for MSVC |
| 2650 | // binaries on windows, we should find a way to make it |
| 2651 | // correct and handle those symbols as well. |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 2652 | if (sc_list.GetSize() == 0) |
| 2653 | { |
| Robert Flack | eb83fab | 2015-05-15 18:59:59 +0000 | [diff] [blame] | 2654 | ArchSpec arch; |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2655 | if (!parent_decl_ctx && |
| Robert Flack | eb83fab | 2015-05-15 18:59:59 +0000 | [diff] [blame] | 2656 | GetObjectFile()->GetArchitecture(arch) && |
| 2657 | (arch.GetTriple().isOSFreeBSD() || arch.GetTriple().isOSLinux() || |
| 2658 | arch.GetMachine() == llvm::Triple::hexagon)) |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 2659 | { |
| Robert Flack | eb83fab | 2015-05-15 18:59:59 +0000 | [diff] [blame] | 2660 | SymbolContextList temp_sc_list; |
| 2661 | FindFunctions (name, m_function_basename_index, include_inlines, temp_sc_list); |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 2662 | SymbolContext sc; |
| 2663 | for (uint32_t i = 0; i < temp_sc_list.GetSize(); i++) |
| 2664 | { |
| 2665 | if (temp_sc_list.GetContextAtIndex(i, sc)) |
| 2666 | { |
| Matt Kopec | a189d49 | 2013-05-10 22:55:24 +0000 | [diff] [blame] | 2667 | ConstString mangled_name = sc.GetFunctionName(Mangled::ePreferMangled); |
| 2668 | ConstString demangled_name = sc.GetFunctionName(Mangled::ePreferDemangled); |
| Robert Flack | eb83fab | 2015-05-15 18:59:59 +0000 | [diff] [blame] | 2669 | // Mangled names on Linux and FreeBSD are of the form: |
| 2670 | // _ZN18function_namespace13function_nameEv. |
| Matt Kopec | 04e5d58 | 2013-05-14 19:00:41 +0000 | [diff] [blame] | 2671 | if (strncmp(mangled_name.GetCString(), "_ZN", 3) || |
| 2672 | !strncmp(demangled_name.GetCString(), "(anonymous namespace)", 21)) |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 2673 | { |
| 2674 | sc_list.Append(sc); |
| 2675 | } |
| 2676 | } |
| 2677 | } |
| 2678 | } |
| 2679 | } |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 2680 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2681 | DIEArray die_offsets; |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2682 | if (name_type_mask & eFunctionNameTypeBase) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2683 | { |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2684 | uint32_t num_base = m_function_basename_index.Find(name, die_offsets); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2685 | for (uint32_t i = 0; i < num_base; i++) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2686 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2687 | DWARFDIE die = info->GetDIE (die_offsets[i]); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2688 | if (die) |
| 2689 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2690 | if (!DIEInDeclContext(parent_decl_ctx, die)) |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2691 | continue; // The containing decl contexts don't match |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 2692 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2693 | // If we get to here, the die is good, and we should add it: |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2694 | if (resolved_dies.find(die.GetDIE()) == resolved_dies.end()) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2695 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2696 | if (ResolveFunction (die, include_inlines, sc_list)) |
| 2697 | resolved_dies.insert(die.GetDIE()); |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2698 | } |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2699 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2700 | } |
| 2701 | die_offsets.clear(); |
| 2702 | } |
| 2703 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2704 | if (name_type_mask & eFunctionNameTypeMethod) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2705 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2706 | if (parent_decl_ctx && parent_decl_ctx->IsValid()) |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2707 | return 0; // no methods in namespaces |
| 2708 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2709 | uint32_t num_base = m_function_method_index.Find(name, die_offsets); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2710 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2711 | for (uint32_t i = 0; i < num_base; i++) |
| 2712 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2713 | DWARFDIE die = info->GetDIE (die_offsets[i]); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2714 | if (die) |
| 2715 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2716 | // If we get to here, the die is good, and we should add it: |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2717 | if (resolved_dies.find(die.GetDIE()) == resolved_dies.end()) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2718 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2719 | if (ResolveFunction (die, include_inlines, sc_list)) |
| 2720 | resolved_dies.insert(die.GetDIE()); |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2721 | } |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2722 | } |
| 2723 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2724 | } |
| 2725 | die_offsets.clear(); |
| 2726 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2727 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2728 | if ((name_type_mask & eFunctionNameTypeSelector) && (!parent_decl_ctx || !parent_decl_ctx->IsValid())) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2729 | { |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2730 | FindFunctions (name, m_function_selector_index, include_inlines, sc_list); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2731 | } |
| 2732 | |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 2733 | } |
| 2734 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2735 | // Return the number of variable that were appended to the list |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2736 | const uint32_t num_matches = sc_list.GetSize() - original_size; |
| 2737 | |
| 2738 | if (log && num_matches > 0) |
| 2739 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2740 | GetObjectFile()->GetModule()->LogMessage (log, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2741 | "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, include_inlines=%d, append=%u, sc_list) => %u", |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2742 | name.GetCString(), |
| 2743 | name_type_mask, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2744 | include_inlines, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2745 | append, |
| 2746 | num_matches); |
| 2747 | } |
| 2748 | return num_matches; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2749 | } |
| 2750 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2751 | uint32_t |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 2752 | 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] | 2753 | { |
| 2754 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 2755 | "SymbolFileDWARF::FindFunctions (regex = '%s')", |
| 2756 | regex.GetText()); |
| 2757 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2758 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2759 | |
| 2760 | if (log) |
| 2761 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2762 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2763 | "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)", |
| 2764 | regex.GetText(), |
| 2765 | append); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2766 | } |
| 2767 | |
| 2768 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2769 | // If we aren't appending the results to this list, then clear the list |
| 2770 | if (!append) |
| 2771 | sc_list.Clear(); |
| 2772 | |
| 2773 | // Remember how many sc_list are in the list before we search in case |
| 2774 | // we are appending the results to a variable list. |
| 2775 | uint32_t original_size = sc_list.GetSize(); |
| 2776 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2777 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2778 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2779 | if (m_apple_names_ap.get()) |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2780 | FindFunctions (regex, *m_apple_names_ap, include_inlines, sc_list); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2781 | } |
| 2782 | else |
| 2783 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2784 | // Index the DWARF if we haven't already |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2785 | if (!m_indexed) |
| 2786 | Index (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2787 | |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2788 | FindFunctions (regex, m_function_basename_index, include_inlines, sc_list); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2789 | |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2790 | FindFunctions (regex, m_function_fullname_index, include_inlines, sc_list); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2791 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2792 | |
| 2793 | // Return the number of variable that were appended to the list |
| 2794 | return sc_list.GetSize() - original_size; |
| 2795 | } |
| Jim Ingham | 318c9f2 | 2011-08-26 19:44:13 +0000 | [diff] [blame] | 2796 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2797 | uint32_t |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 2798 | SymbolFileDWARF::FindTypes (const SymbolContext& sc, |
| 2799 | const ConstString &name, |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2800 | const CompilerDeclContext *parent_decl_ctx, |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 2801 | bool append, |
| 2802 | uint32_t max_matches, |
| 2803 | TypeList& types) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2804 | { |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2805 | DWARFDebugInfo* info = DebugInfo(); |
| 2806 | if (info == NULL) |
| 2807 | return 0; |
| 2808 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2809 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2810 | |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2811 | if (log) |
| 2812 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2813 | if (parent_decl_ctx) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2814 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2815 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx = %p (\"%s\"), append=%u, max_matches=%u, type_list)", |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2816 | name.GetCString(), |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2817 | static_cast<const void*>(parent_decl_ctx), |
| 2818 | parent_decl_ctx->GetName().AsCString("<NULL>"), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2819 | append, max_matches); |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2820 | else |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2821 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2822 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx = NULL, append=%u, max_matches=%u, type_list)", |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2823 | name.GetCString(), append, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2824 | max_matches); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2825 | } |
| 2826 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2827 | // If we aren't appending the results to this list, then clear the list |
| 2828 | if (!append) |
| 2829 | types.Clear(); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2830 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2831 | if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx)) |
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 2832 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2833 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2834 | DIEArray die_offsets; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2835 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2836 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2837 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2838 | if (m_apple_types_ap.get()) |
| 2839 | { |
| 2840 | const char *name_cstr = name.GetCString(); |
| 2841 | m_apple_types_ap->FindByName (name_cstr, die_offsets); |
| 2842 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2843 | } |
| 2844 | else |
| 2845 | { |
| 2846 | if (!m_indexed) |
| 2847 | Index (); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2848 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2849 | m_type_index.Find (name, die_offsets); |
| 2850 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2851 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2852 | const size_t num_die_matches = die_offsets.size(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2853 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2854 | if (num_die_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2855 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2856 | const uint32_t initial_types_size = types.GetSize(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2857 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2858 | for (size_t i=0; i<num_die_matches; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2859 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 2860 | const DIERef& die_ref = die_offsets[i]; |
| 2861 | DWARFDIE die = debug_info->GetDIE (die_ref); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2862 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2863 | if (die) |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 2864 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2865 | if (!DIEInDeclContext(parent_decl_ctx, die)) |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2866 | continue; // The containing decl contexts don't match |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2867 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2868 | Type *matching_type = ResolveType (die); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2869 | if (matching_type) |
| 2870 | { |
| 2871 | // 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] | 2872 | types.InsertUnique (matching_type->shared_from_this()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2873 | if (types.GetSize() >= max_matches) |
| 2874 | break; |
| 2875 | } |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 2876 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2877 | else |
| 2878 | { |
| 2879 | if (m_using_apple_tables) |
| 2880 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2881 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 2882 | die_ref.die_offset, name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2883 | } |
| 2884 | } |
| 2885 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2886 | } |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2887 | const uint32_t num_matches = types.GetSize() - initial_types_size; |
| 2888 | if (log && num_matches) |
| 2889 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2890 | if (parent_decl_ctx) |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2891 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2892 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2893 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx = %p (\"%s\"), append=%u, max_matches=%u, type_list) => %u", |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2894 | name.GetCString(), |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2895 | static_cast<const void*>(parent_decl_ctx), |
| 2896 | parent_decl_ctx->GetName().AsCString("<NULL>"), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2897 | append, max_matches, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2898 | num_matches); |
| 2899 | } |
| 2900 | else |
| 2901 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2902 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2903 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx = NULL, append=%u, max_matches=%u, type_list) => %u", |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2904 | name.GetCString(), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2905 | append, max_matches, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2906 | num_matches); |
| 2907 | } |
| 2908 | } |
| 2909 | return num_matches; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2910 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2911 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2912 | } |
| 2913 | |
| 2914 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2915 | CompilerDeclContext |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2916 | SymbolFileDWARF::FindNamespace (const SymbolContext& sc, |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2917 | const ConstString &name, |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2918 | const CompilerDeclContext *parent_decl_ctx) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2919 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2920 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2921 | |
| 2922 | if (log) |
| 2923 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2924 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2925 | "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")", |
| 2926 | name.GetCString()); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2927 | } |
| 2928 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2929 | CompilerDeclContext namespace_decl_ctx; |
| 2930 | |
| 2931 | if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx)) |
| 2932 | return namespace_decl_ctx; |
| 2933 | |
| 2934 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2935 | DWARFDebugInfo* info = DebugInfo(); |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 2936 | if (info) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2937 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2938 | DIEArray die_offsets; |
| 2939 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 2940 | // Index if we already haven't to make sure the compile units |
| 2941 | // get indexed and make their global DIE index list |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2942 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2943 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2944 | if (m_apple_namespaces_ap.get()) |
| 2945 | { |
| 2946 | const char *name_cstr = name.GetCString(); |
| 2947 | m_apple_namespaces_ap->FindByName (name_cstr, die_offsets); |
| 2948 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2949 | } |
| 2950 | else |
| 2951 | { |
| 2952 | if (!m_indexed) |
| 2953 | Index (); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2954 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2955 | m_namespace_index.Find (name, die_offsets); |
| 2956 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2957 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2958 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2959 | if (num_matches) |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 2960 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2961 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2962 | for (size_t i=0; i<num_matches; ++i) |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 2963 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 2964 | const DIERef& die_ref = die_offsets[i]; |
| 2965 | DWARFDIE die = debug_info->GetDIE (die_ref); |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2966 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2967 | if (die) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2968 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2969 | if (!DIEInDeclContext (parent_decl_ctx, die)) |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2970 | continue; // The containing decl contexts don't match |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2971 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 2972 | DWARFASTParser *dwarf_ast = die.GetDWARFParser(); |
| 2973 | if (dwarf_ast) |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 2974 | { |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 2975 | namespace_decl_ctx = dwarf_ast->GetDeclContextForUIDFromDWARF (die); |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2976 | if (namespace_decl_ctx) |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 2977 | break; |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2978 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2979 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2980 | else |
| 2981 | { |
| 2982 | if (m_using_apple_tables) |
| 2983 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2984 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n", |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 2985 | die_ref.die_offset, name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2986 | } |
| 2987 | } |
| 2988 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 2989 | } |
| 2990 | } |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 2991 | } |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2992 | if (log && namespace_decl_ctx) |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2993 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2994 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2995 | "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => CompilerDeclContext(%p/%p) \"%s\"", |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2996 | name.GetCString(), |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2997 | static_cast<const void*>(namespace_decl_ctx.GetTypeSystem()), |
| 2998 | static_cast<const void*>(namespace_decl_ctx.GetOpaqueDeclContext()), |
| 2999 | namespace_decl_ctx.GetName().AsCString("<NULL>")); |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3000 | } |
| 3001 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3002 | return namespace_decl_ctx; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3003 | } |
| 3004 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3005 | TypeSP |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3006 | SymbolFileDWARF::GetTypeForDIE (const DWARFDIE &die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3007 | { |
| 3008 | TypeSP type_sp; |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3009 | if (die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3010 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 3011 | Type *type_ptr = GetDIEToType().lookup (die.GetDIE()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3012 | if (type_ptr == NULL) |
| 3013 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3014 | CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(die.GetCU()); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 3015 | assert (lldb_cu); |
| 3016 | SymbolContext sc(lldb_cu); |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3017 | type_sp = ParseType(sc, die, NULL); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3018 | } |
| 3019 | else if (type_ptr != DIE_IS_BEING_PARSED) |
| 3020 | { |
| 3021 | // Grab the existing type from the master types lists |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 3022 | type_sp = type_ptr->shared_from_this(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3023 | } |
| 3024 | |
| 3025 | } |
| 3026 | return type_sp; |
| 3027 | } |
| 3028 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3029 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3030 | DWARFDIE |
| 3031 | SymbolFileDWARF::GetDeclContextDIEContainingDIE (const DWARFDIE &orig_die) |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3032 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3033 | if (orig_die) |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3034 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3035 | DWARFDIE die = orig_die; |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3036 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3037 | while (die) |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3038 | { |
| 3039 | // If this is the original DIE that we are searching for a declaration |
| 3040 | // for, then don't look in the cache as we don't want our own decl |
| 3041 | // context to be our decl context... |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3042 | if (orig_die != die) |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3043 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3044 | switch (die.Tag()) |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3045 | { |
| 3046 | case DW_TAG_compile_unit: |
| 3047 | case DW_TAG_namespace: |
| 3048 | case DW_TAG_structure_type: |
| 3049 | case DW_TAG_union_type: |
| 3050 | case DW_TAG_class_type: |
| 3051 | return die; |
| 3052 | |
| 3053 | default: |
| 3054 | break; |
| 3055 | } |
| 3056 | } |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3057 | |
| 3058 | DWARFDIE spec_die = die.GetReferencedDIE(DW_AT_specification); |
| 3059 | if (spec_die) |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3060 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3061 | DWARFDIE decl_ctx_die = GetDeclContextDIEContainingDIE(spec_die); |
| 3062 | if (decl_ctx_die) |
| 3063 | return decl_ctx_die; |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3064 | } |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3065 | |
| 3066 | DWARFDIE abs_die = die.GetReferencedDIE(DW_AT_abstract_origin); |
| 3067 | if (abs_die) |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3068 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3069 | DWARFDIE decl_ctx_die = GetDeclContextDIEContainingDIE(abs_die); |
| 3070 | if (decl_ctx_die) |
| 3071 | return decl_ctx_die; |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3072 | } |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3073 | |
| 3074 | die = die.GetParent(); |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3075 | } |
| 3076 | } |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3077 | return DWARFDIE(); |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3078 | } |
| 3079 | |
| 3080 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3081 | Symbol * |
| 3082 | SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name) |
| 3083 | { |
| 3084 | Symbol *objc_class_symbol = NULL; |
| 3085 | if (m_obj_file) |
| 3086 | { |
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 3087 | Symtab *symtab = m_obj_file->GetSymtab (); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3088 | if (symtab) |
| 3089 | { |
| 3090 | objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name, |
| 3091 | eSymbolTypeObjCClass, |
| 3092 | Symtab::eDebugNo, |
| 3093 | Symtab::eVisibilityAny); |
| 3094 | } |
| 3095 | } |
| 3096 | return objc_class_symbol; |
| 3097 | } |
| 3098 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 3099 | // Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't |
| 3100 | // then we can end up looking through all class types for a complete type and never find |
| 3101 | // the full definition. We need to know if this attribute is supported, so we determine |
| 3102 | // this here and cache th result. We also need to worry about the debug map DWARF file |
| 3103 | // if we are doing darwin DWARF in .o file debugging. |
| 3104 | bool |
| 3105 | SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu) |
| 3106 | { |
| 3107 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate) |
| 3108 | { |
| 3109 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo; |
| 3110 | if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type()) |
| 3111 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; |
| 3112 | else |
| 3113 | { |
| 3114 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3115 | const uint32_t num_compile_units = GetNumCompileUnits(); |
| 3116 | for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) |
| 3117 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3118 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); |
| 3119 | 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] | 3120 | { |
| 3121 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; |
| 3122 | break; |
| 3123 | } |
| 3124 | } |
| 3125 | } |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 3126 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ()) |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 3127 | return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this); |
| 3128 | } |
| 3129 | return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes; |
| 3130 | } |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3131 | |
| 3132 | // This function can be used when a DIE is found that is a forward declaration |
| 3133 | // DIE and we want to try and find a type that has the complete definition. |
| 3134 | TypeSP |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3135 | SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDIE &die, |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 3136 | const ConstString &type_name, |
| 3137 | bool must_be_implementation) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3138 | { |
| 3139 | |
| 3140 | TypeSP type_sp; |
| 3141 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 3142 | if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name))) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3143 | return type_sp; |
| 3144 | |
| 3145 | DIEArray die_offsets; |
| 3146 | |
| 3147 | if (m_using_apple_tables) |
| 3148 | { |
| 3149 | if (m_apple_types_ap.get()) |
| 3150 | { |
| 3151 | const char *name_cstr = type_name.GetCString(); |
| Greg Clayton | 68221ec | 2012-01-18 20:58:12 +0000 | [diff] [blame] | 3152 | m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3153 | } |
| 3154 | } |
| 3155 | else |
| 3156 | { |
| 3157 | if (!m_indexed) |
| 3158 | Index (); |
| 3159 | |
| 3160 | m_type_index.Find (type_name, die_offsets); |
| 3161 | } |
| 3162 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3163 | const size_t num_matches = die_offsets.size(); |
| 3164 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3165 | if (num_matches) |
| 3166 | { |
| 3167 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3168 | for (size_t i=0; i<num_matches; ++i) |
| 3169 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 3170 | const DIERef& die_ref = die_offsets[i]; |
| 3171 | DWARFDIE type_die = debug_info->GetDIE (die_ref); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3172 | |
| 3173 | if (type_die) |
| 3174 | { |
| 3175 | bool try_resolving_type = false; |
| 3176 | |
| 3177 | // Don't try and resolve the DIE we are looking for with the DIE itself! |
| 3178 | if (type_die != die) |
| 3179 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3180 | switch (type_die.Tag()) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3181 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 3182 | case DW_TAG_class_type: |
| 3183 | case DW_TAG_structure_type: |
| 3184 | try_resolving_type = true; |
| 3185 | break; |
| 3186 | default: |
| 3187 | break; |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3188 | } |
| 3189 | } |
| 3190 | |
| 3191 | if (try_resolving_type) |
| 3192 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3193 | if (must_be_implementation && type_die.Supports_DW_AT_APPLE_objc_complete_type()) |
| 3194 | try_resolving_type = type_die.GetAttributeValueAsUnsigned (DW_AT_APPLE_objc_complete_type, 0); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3195 | |
| 3196 | if (try_resolving_type) |
| 3197 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3198 | Type *resolved_type = ResolveType (type_die, false); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3199 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) |
| 3200 | { |
| Ed Maste | a0191d1 | 2013-10-17 20:42:56 +0000 | [diff] [blame] | 3201 | DEBUG_PRINTF ("resolved 0x%8.8" PRIx64 " from %s to 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ")\n", |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3202 | die.GetID(), |
| Jim Ingham | 4af5961 | 2014-12-19 19:20:44 +0000 | [diff] [blame] | 3203 | m_obj_file->GetFileSpec().GetFilename().AsCString("<Unknown>"), |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3204 | type_die.GetID(), |
| 3205 | type_cu->GetID()); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3206 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 3207 | if (die) |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 3208 | GetDIEToType()[die.GetDIE()] = resolved_type; |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 3209 | type_sp = resolved_type->shared_from_this(); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3210 | break; |
| 3211 | } |
| 3212 | } |
| 3213 | } |
| 3214 | } |
| 3215 | else |
| 3216 | { |
| 3217 | if (m_using_apple_tables) |
| 3218 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3219 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 3220 | die_ref.die_offset, type_name.GetCString()); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3221 | } |
| 3222 | } |
| 3223 | |
| 3224 | } |
| 3225 | } |
| 3226 | return type_sp; |
| 3227 | } |
| 3228 | |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3229 | |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 3230 | //---------------------------------------------------------------------- |
| 3231 | // This function helps to ensure that the declaration contexts match for |
| 3232 | // two different DIEs. Often times debug information will refer to a |
| 3233 | // forward declaration of a type (the equivalent of "struct my_struct;". |
| 3234 | // There will often be a declaration of that type elsewhere that has the |
| 3235 | // full definition. When we go looking for the full type "my_struct", we |
| 3236 | // will find one or more matches in the accelerator tables and we will |
| 3237 | // then need to make sure the type was in the same declaration context |
| 3238 | // as the original DIE. This function can efficiently compare two DIEs |
| 3239 | // and will return true when the declaration context matches, and false |
| 3240 | // when they don't. |
| 3241 | //---------------------------------------------------------------------- |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3242 | bool |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3243 | SymbolFileDWARF::DIEDeclContextsMatch (const DWARFDIE &die1, |
| 3244 | const DWARFDIE &die2) |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3245 | { |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3246 | if (die1 == die2) |
| 3247 | return true; |
| 3248 | |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3249 | DWARFDIECollection decl_ctx_1; |
| 3250 | DWARFDIECollection decl_ctx_2; |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 3251 | //The declaration DIE stack is a stack of the declaration context |
| 3252 | // DIEs all the way back to the compile unit. If a type "T" is |
| 3253 | // declared inside a class "B", and class "B" is declared inside |
| 3254 | // a class "A" and class "A" is in a namespace "lldb", and the |
| 3255 | // namespace is in a compile unit, there will be a stack of DIEs: |
| 3256 | // |
| 3257 | // [0] DW_TAG_class_type for "B" |
| 3258 | // [1] DW_TAG_class_type for "A" |
| 3259 | // [2] DW_TAG_namespace for "lldb" |
| 3260 | // [3] DW_TAG_compile_unit for the source file. |
| 3261 | // |
| 3262 | // We grab both contexts and make sure that everything matches |
| 3263 | // all the way back to the compiler unit. |
| 3264 | |
| 3265 | // First lets grab the decl contexts for both DIEs |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3266 | die1.GetDeclContextDIEs (decl_ctx_1); |
| 3267 | die2.GetDeclContextDIEs (decl_ctx_2); |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 3268 | // Make sure the context arrays have the same size, otherwise |
| 3269 | // we are done |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3270 | const size_t count1 = decl_ctx_1.Size(); |
| 3271 | const size_t count2 = decl_ctx_2.Size(); |
| 3272 | if (count1 != count2) |
| 3273 | return false; |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 3274 | |
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 3275 | // Make sure the DW_TAG values match all the way back up the |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 3276 | // compile unit. If they don't, then we are done. |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3277 | DWARFDIE decl_ctx_die1; |
| 3278 | DWARFDIE decl_ctx_die2; |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3279 | size_t i; |
| 3280 | for (i=0; i<count1; i++) |
| 3281 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3282 | decl_ctx_die1 = decl_ctx_1.GetDIEAtIndex (i); |
| 3283 | decl_ctx_die2 = decl_ctx_2.GetDIEAtIndex (i); |
| 3284 | if (decl_ctx_die1.Tag() != decl_ctx_die2.Tag()) |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3285 | return false; |
| 3286 | } |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3287 | #if defined LLDB_CONFIGURATION_DEBUG |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 3288 | |
| 3289 | // Make sure the top item in the decl context die array is always |
| 3290 | // DW_TAG_compile_unit. If it isn't then something went wrong in |
| Greg Clayton | 5ce1a84 | 2015-08-27 18:09:44 +0000 | [diff] [blame] | 3291 | // the DWARFDIE::GetDeclContextDIEs() function... |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3292 | assert (decl_ctx_1.GetDIEAtIndex (count1 - 1).Tag() == DW_TAG_compile_unit); |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 3293 | |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3294 | #endif |
| 3295 | // Always skip the compile unit when comparing by only iterating up to |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 3296 | // "count - 1". Here we compare the names as we go. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3297 | for (i=0; i<count1 - 1; i++) |
| 3298 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3299 | decl_ctx_die1 = decl_ctx_1.GetDIEAtIndex (i); |
| 3300 | decl_ctx_die2 = decl_ctx_2.GetDIEAtIndex (i); |
| 3301 | const char *name1 = decl_ctx_die1.GetName(); |
| 3302 | const char *name2 = decl_ctx_die2.GetName(); |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3303 | // If the string was from a DW_FORM_strp, then the pointer will often |
| 3304 | // be the same! |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 3305 | if (name1 == name2) |
| 3306 | continue; |
| 3307 | |
| 3308 | // Name pointers are not equal, so only compare the strings |
| 3309 | // if both are not NULL. |
| 3310 | if (name1 && name2) |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3311 | { |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 3312 | // If the strings don't compare, we are done... |
| 3313 | if (strcmp(name1, name2) != 0) |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3314 | return false; |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 3315 | } |
| 3316 | else |
| 3317 | { |
| 3318 | // One name was NULL while the other wasn't |
| 3319 | return false; |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3320 | } |
| 3321 | } |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 3322 | // We made it through all of the checks and the declaration contexts |
| 3323 | // are equal. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3324 | return true; |
| 3325 | } |
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 3326 | |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 3327 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3328 | TypeSP |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3329 | SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx) |
| 3330 | { |
| 3331 | TypeSP type_sp; |
| 3332 | |
| 3333 | const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize(); |
| 3334 | if (dwarf_decl_ctx_count > 0) |
| 3335 | { |
| 3336 | const ConstString type_name(dwarf_decl_ctx[0].name); |
| 3337 | const dw_tag_t tag = dwarf_decl_ctx[0].tag; |
| 3338 | |
| 3339 | if (type_name) |
| 3340 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3341 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS)); |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3342 | if (log) |
| 3343 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3344 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3345 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')", |
| 3346 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), |
| 3347 | dwarf_decl_ctx.GetQualifiedName()); |
| 3348 | } |
| 3349 | |
| 3350 | DIEArray die_offsets; |
| 3351 | |
| 3352 | if (m_using_apple_tables) |
| 3353 | { |
| 3354 | if (m_apple_types_ap.get()) |
| 3355 | { |
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 3356 | const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag); |
| 3357 | const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash); |
| 3358 | if (has_tag && has_qualified_name_hash) |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3359 | { |
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 3360 | const char *qualified_name = dwarf_decl_ctx.GetQualifiedName(); |
| 3361 | const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name); |
| 3362 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3363 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()"); |
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 3364 | m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets); |
| 3365 | } |
| 3366 | else if (has_tag) |
| 3367 | { |
| 3368 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3369 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()"); |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3370 | m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets); |
| 3371 | } |
| 3372 | else |
| 3373 | { |
| 3374 | m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets); |
| 3375 | } |
| 3376 | } |
| 3377 | } |
| 3378 | else |
| 3379 | { |
| 3380 | if (!m_indexed) |
| 3381 | Index (); |
| 3382 | |
| 3383 | m_type_index.Find (type_name, die_offsets); |
| 3384 | } |
| 3385 | |
| 3386 | const size_t num_matches = die_offsets.size(); |
| 3387 | |
| 3388 | |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3389 | if (num_matches) |
| 3390 | { |
| 3391 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3392 | for (size_t i=0; i<num_matches; ++i) |
| 3393 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 3394 | const DIERef& die_ref = die_offsets[i]; |
| 3395 | DWARFDIE type_die = debug_info->GetDIE (die_ref); |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3396 | |
| 3397 | if (type_die) |
| 3398 | { |
| 3399 | bool try_resolving_type = false; |
| 3400 | |
| 3401 | // Don't try and resolve the DIE we are looking for with the DIE itself! |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3402 | const dw_tag_t type_tag = type_die.Tag(); |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3403 | // Make sure the tags match |
| 3404 | if (type_tag == tag) |
| 3405 | { |
| 3406 | // The tags match, lets try resolving this type |
| 3407 | try_resolving_type = true; |
| 3408 | } |
| 3409 | else |
| 3410 | { |
| 3411 | // The tags don't match, but we need to watch our for a |
| 3412 | // forward declaration for a struct and ("struct foo") |
| 3413 | // ends up being a class ("class foo { ... };") or |
| 3414 | // vice versa. |
| 3415 | switch (type_tag) |
| 3416 | { |
| 3417 | case DW_TAG_class_type: |
| 3418 | // We had a "class foo", see if we ended up with a "struct foo { ... };" |
| 3419 | try_resolving_type = (tag == DW_TAG_structure_type); |
| 3420 | break; |
| 3421 | case DW_TAG_structure_type: |
| 3422 | // We had a "struct foo", see if we ended up with a "class foo { ... };" |
| 3423 | try_resolving_type = (tag == DW_TAG_class_type); |
| 3424 | break; |
| 3425 | default: |
| 3426 | // Tags don't match, don't event try to resolve |
| 3427 | // using this type whose name matches.... |
| 3428 | break; |
| 3429 | } |
| 3430 | } |
| 3431 | |
| 3432 | if (try_resolving_type) |
| 3433 | { |
| 3434 | DWARFDeclContext type_dwarf_decl_ctx; |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3435 | type_die.GetDWARFDeclContext (type_dwarf_decl_ctx); |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3436 | |
| 3437 | if (log) |
| 3438 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3439 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3440 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)", |
| 3441 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), |
| 3442 | dwarf_decl_ctx.GetQualifiedName(), |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3443 | type_die.GetOffset(), |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3444 | type_dwarf_decl_ctx.GetQualifiedName()); |
| 3445 | } |
| 3446 | |
| 3447 | // Make sure the decl contexts match all the way up |
| 3448 | if (dwarf_decl_ctx == type_dwarf_decl_ctx) |
| 3449 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3450 | Type *resolved_type = ResolveType (type_die, false); |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3451 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) |
| 3452 | { |
| 3453 | type_sp = resolved_type->shared_from_this(); |
| 3454 | break; |
| 3455 | } |
| 3456 | } |
| 3457 | } |
| 3458 | else |
| 3459 | { |
| 3460 | if (log) |
| 3461 | { |
| 3462 | std::string qualified_name; |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3463 | type_die.GetQualifiedName(qualified_name); |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3464 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3465 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)", |
| 3466 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), |
| 3467 | dwarf_decl_ctx.GetQualifiedName(), |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3468 | type_die.GetOffset(), |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3469 | qualified_name.c_str()); |
| 3470 | } |
| 3471 | } |
| 3472 | } |
| 3473 | else |
| 3474 | { |
| 3475 | if (m_using_apple_tables) |
| 3476 | { |
| 3477 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 3478 | die_ref.die_offset, type_name.GetCString()); |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3479 | } |
| 3480 | } |
| 3481 | |
| 3482 | } |
| 3483 | } |
| 3484 | } |
| 3485 | } |
| 3486 | return type_sp; |
| 3487 | } |
| 3488 | |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3489 | TypeSP |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3490 | SymbolFileDWARF::ParseType (const SymbolContext& sc, const DWARFDIE &die, bool *type_is_new_ptr) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3491 | { |
| Greg Clayton | 196e8cd | 2015-08-17 20:31:46 +0000 | [diff] [blame] | 3492 | TypeSP type_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3493 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3494 | if (die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3495 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3496 | TypeSystem *type_system = GetTypeSystemForLanguage(die.GetCU()->GetLanguageType()); |
| 3497 | |
| 3498 | if (type_system) |
| Greg Clayton | 196e8cd | 2015-08-17 20:31:46 +0000 | [diff] [blame] | 3499 | { |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 3500 | DWARFASTParser *dwarf_ast = type_system->GetDWARFParser(); |
| 3501 | if (dwarf_ast) |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3502 | { |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 3503 | Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO); |
| 3504 | type_sp = dwarf_ast->ParseTypeFromDWARF (sc, die, log, type_is_new_ptr); |
| 3505 | if (type_sp) |
| 3506 | { |
| 3507 | TypeList* type_list = GetTypeList(); |
| 3508 | if (type_list) |
| 3509 | type_list->Insert(type_sp); |
| 3510 | } |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3511 | } |
| Greg Clayton | 196e8cd | 2015-08-17 20:31:46 +0000 | [diff] [blame] | 3512 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3513 | } |
| Greg Clayton | 196e8cd | 2015-08-17 20:31:46 +0000 | [diff] [blame] | 3514 | |
| 3515 | return type_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3516 | } |
| 3517 | |
| 3518 | size_t |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 3519 | SymbolFileDWARF::ParseTypes |
| 3520 | ( |
| 3521 | const SymbolContext& sc, |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3522 | const DWARFDIE &orig_die, |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 3523 | bool parse_siblings, |
| 3524 | bool parse_children |
| 3525 | ) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3526 | { |
| 3527 | size_t types_added = 0; |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3528 | DWARFDIE die = orig_die; |
| 3529 | while (die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3530 | { |
| 3531 | bool type_is_new = false; |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3532 | if (ParseType(sc, die, &type_is_new).get()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3533 | { |
| 3534 | if (type_is_new) |
| 3535 | ++types_added; |
| 3536 | } |
| 3537 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3538 | if (parse_children && die.HasChildren()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3539 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3540 | if (die.Tag() == DW_TAG_subprogram) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3541 | { |
| 3542 | SymbolContext child_sc(sc); |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3543 | child_sc.function = sc.comp_unit->FindFunctionByUID(die.GetID()).get(); |
| 3544 | types_added += ParseTypes(child_sc, die.GetFirstChild(), true, true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3545 | } |
| 3546 | else |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3547 | types_added += ParseTypes(sc, die.GetFirstChild(), true, true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3548 | } |
| 3549 | |
| 3550 | if (parse_siblings) |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3551 | die = die.GetSibling(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3552 | else |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3553 | die.Clear(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3554 | } |
| 3555 | return types_added; |
| 3556 | } |
| 3557 | |
| 3558 | |
| 3559 | size_t |
| 3560 | SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc) |
| 3561 | { |
| 3562 | assert(sc.comp_unit && sc.function); |
| 3563 | size_t functions_added = 0; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 3564 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3565 | if (dwarf_cu) |
| 3566 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3567 | const dw_offset_t function_die_offset = sc.function->GetID(); |
| 3568 | DWARFDIE function_die = dwarf_cu->GetDIE (function_die_offset); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3569 | if (function_die) |
| 3570 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3571 | ParseFunctionBlocks(sc, &sc.function->GetBlock (false), function_die, LLDB_INVALID_ADDRESS, 0); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3572 | } |
| 3573 | } |
| 3574 | |
| 3575 | return functions_added; |
| 3576 | } |
| 3577 | |
| 3578 | |
| 3579 | size_t |
| 3580 | SymbolFileDWARF::ParseTypes (const SymbolContext &sc) |
| 3581 | { |
| 3582 | // At least a compile unit must be valid |
| 3583 | assert(sc.comp_unit); |
| 3584 | size_t types_added = 0; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 3585 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3586 | if (dwarf_cu) |
| 3587 | { |
| 3588 | if (sc.function) |
| 3589 | { |
| 3590 | dw_offset_t function_die_offset = sc.function->GetID(); |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3591 | DWARFDIE func_die = dwarf_cu->GetDIE(function_die_offset); |
| 3592 | if (func_die && func_die.HasChildren()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3593 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3594 | types_added = ParseTypes(sc, func_die.GetFirstChild(), true, true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3595 | } |
| 3596 | } |
| 3597 | else |
| 3598 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3599 | DWARFDIE dwarf_cu_die = dwarf_cu->DIE(); |
| 3600 | if (dwarf_cu_die && dwarf_cu_die.HasChildren()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3601 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3602 | types_added = ParseTypes(sc, dwarf_cu_die.GetFirstChild(), true, true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3603 | } |
| 3604 | } |
| 3605 | } |
| 3606 | |
| 3607 | return types_added; |
| 3608 | } |
| 3609 | |
| 3610 | size_t |
| 3611 | SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc) |
| 3612 | { |
| 3613 | if (sc.comp_unit != NULL) |
| 3614 | { |
| Greg Clayton | 4b3dc10 | 2010-11-01 20:32:12 +0000 | [diff] [blame] | 3615 | DWARFDebugInfo* info = DebugInfo(); |
| 3616 | if (info == NULL) |
| 3617 | return 0; |
| 3618 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3619 | if (sc.function) |
| 3620 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 3621 | DWARFDIE function_die = info->GetDIE(DIERef(sc.function->GetID())); |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 3622 | |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 3623 | const dw_addr_t func_lo_pc = function_die.GetAttributeValueAsAddress (DW_AT_low_pc, LLDB_INVALID_ADDRESS); |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 3624 | if (func_lo_pc != LLDB_INVALID_ADDRESS) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3625 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3626 | const size_t num_variables = ParseVariables(sc, function_die.GetFirstChild(), func_lo_pc, true, true); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 3627 | |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3628 | // Let all blocks know they have parse all their variables |
| 3629 | sc.function->GetBlock (false).SetDidParseVariables (true, true); |
| 3630 | return num_variables; |
| 3631 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3632 | } |
| 3633 | else if (sc.comp_unit) |
| 3634 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3635 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()); |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 3636 | |
| 3637 | if (dwarf_cu == NULL) |
| 3638 | return 0; |
| 3639 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3640 | uint32_t vars_added = 0; |
| 3641 | VariableListSP variables (sc.comp_unit->GetVariableList(false)); |
| 3642 | |
| 3643 | if (variables.get() == NULL) |
| 3644 | { |
| 3645 | variables.reset(new VariableList()); |
| 3646 | sc.comp_unit->SetVariableList(variables); |
| 3647 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3648 | DIEArray die_offsets; |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3649 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3650 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3651 | if (m_apple_names_ap.get()) |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3652 | { |
| 3653 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 3654 | if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(), |
| 3655 | dwarf_cu->GetNextCompileUnitOffset(), |
| 3656 | hash_data_array)) |
| 3657 | { |
| 3658 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| 3659 | } |
| 3660 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3661 | } |
| 3662 | else |
| 3663 | { |
| 3664 | // Index if we already haven't to make sure the compile units |
| 3665 | // get indexed and make their global DIE index list |
| 3666 | if (!m_indexed) |
| 3667 | Index (); |
| 3668 | |
| 3669 | m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(), |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3670 | die_offsets); |
| 3671 | } |
| 3672 | |
| 3673 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3674 | if (num_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3675 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3676 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3677 | for (size_t i=0; i<num_matches; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3678 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 3679 | const DIERef& die_ref = die_offsets[i]; |
| 3680 | DWARFDIE die = debug_info->GetDIE (die_ref); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3681 | if (die) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3682 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3683 | VariableSP var_sp (ParseVariableDIE(sc, die, LLDB_INVALID_ADDRESS)); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3684 | if (var_sp) |
| 3685 | { |
| 3686 | variables->AddVariableIfUnique (var_sp); |
| 3687 | ++vars_added; |
| 3688 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3689 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3690 | else |
| 3691 | { |
| 3692 | if (m_using_apple_tables) |
| 3693 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 3694 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x)\n", die_ref.die_offset); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3695 | } |
| 3696 | } |
| 3697 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3698 | } |
| 3699 | } |
| 3700 | } |
| 3701 | return vars_added; |
| 3702 | } |
| 3703 | } |
| 3704 | return 0; |
| 3705 | } |
| 3706 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3707 | VariableSP |
| 3708 | SymbolFileDWARF::ParseVariableDIE |
| 3709 | ( |
| 3710 | const SymbolContext& sc, |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3711 | const DWARFDIE &die, |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 3712 | const lldb::addr_t func_low_pc |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3713 | ) |
| 3714 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 3715 | if (die.GetDWARF() != this) |
| 3716 | return die.GetDWARF()->ParseVariableDIE(sc, die, func_low_pc); |
| 3717 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3718 | VariableSP var_sp; |
| 3719 | if (!die) |
| 3720 | return var_sp; |
| 3721 | |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 3722 | var_sp = GetDIEToVariable()[die.GetDIE()]; |
| Greg Clayton | 83c5cd9 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 3723 | if (var_sp) |
| 3724 | return var_sp; // Already been parsed! |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3725 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3726 | const dw_tag_t tag = die.Tag(); |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 3727 | ModuleSP module = GetObjectFile()->GetModule(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3728 | |
| 3729 | if ((tag == DW_TAG_variable) || |
| 3730 | (tag == DW_TAG_constant) || |
| 3731 | (tag == DW_TAG_formal_parameter && sc.function)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3732 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3733 | DWARFAttributes attributes; |
| 3734 | const size_t num_attributes = die.GetAttributes(attributes); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3735 | if (num_attributes > 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3736 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3737 | const char *name = NULL; |
| 3738 | const char *mangled = NULL; |
| 3739 | Declaration decl; |
| 3740 | uint32_t i; |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 3741 | DWARFFormValue type_die_form; |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3742 | DWARFExpression location(die.GetCU()); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3743 | bool is_external = false; |
| 3744 | bool is_artificial = false; |
| 3745 | bool location_is_const_value_data = false; |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 3746 | bool has_explicit_location = false; |
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 3747 | DWARFFormValue const_value; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 3748 | //AccessType accessibility = eAccessNone; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3749 | |
| 3750 | for (i=0; i<num_attributes; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3751 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3752 | dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 3753 | DWARFFormValue form_value; |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 3754 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3755 | if (attributes.ExtractFormValueAtIndex(i, form_value)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3756 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3757 | switch (attr) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3758 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3759 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 3760 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 3761 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3762 | case DW_AT_name: name = form_value.AsCString(); break; |
| Greg Clayton | 7141554 | 2012-12-08 00:24:40 +0000 | [diff] [blame] | 3763 | case DW_AT_linkage_name: |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3764 | case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(); break; |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 3765 | case DW_AT_type: type_die_form = form_value; break; |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 3766 | case DW_AT_external: is_external = form_value.Boolean(); break; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3767 | case DW_AT_const_value: |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 3768 | // If we have already found a DW_AT_location attribute, ignore this attribute. |
| 3769 | if (!has_explicit_location) |
| 3770 | { |
| 3771 | location_is_const_value_data = true; |
| 3772 | // The constant value will be either a block, a data value or a string. |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 3773 | const DWARFDataExtractor& debug_info_data = get_debug_info_data(); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 3774 | if (DWARFFormValue::IsBlockForm(form_value.Form())) |
| 3775 | { |
| 3776 | // Retrieve the value as a block expression. |
| 3777 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 3778 | uint32_t block_length = form_value.Unsigned(); |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 3779 | location.CopyOpcodeData(module, debug_info_data, block_offset, block_length); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 3780 | } |
| 3781 | else if (DWARFFormValue::IsDataForm(form_value.Form())) |
| 3782 | { |
| 3783 | // Retrieve the value as a data expression. |
| Tamas Berghammer | b7c6465 | 2015-08-25 11:45:46 +0000 | [diff] [blame] | 3784 | DWARFFormValue::FixedFormSizes fixed_form_sizes = |
| 3785 | DWARFFormValue::GetFixedFormSizesForAddressSize ( |
| 3786 | attributes.CompileUnitAtIndex(i)->GetAddressByteSize(), |
| 3787 | attributes.CompileUnitAtIndex(i)->IsDWARF64()); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 3788 | uint32_t data_offset = attributes.DIEOffsetAtIndex(i); |
| Tamas Berghammer | b7c6465 | 2015-08-25 11:45:46 +0000 | [diff] [blame] | 3789 | uint32_t data_length = fixed_form_sizes.GetSize(form_value.Form()); |
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 3790 | if (data_length == 0) |
| 3791 | { |
| 3792 | const uint8_t *data_pointer = form_value.BlockData(); |
| 3793 | if (data_pointer) |
| 3794 | { |
| Jason Molenda | 18f5fd3 | 2014-10-16 07:52:17 +0000 | [diff] [blame] | 3795 | form_value.Unsigned(); |
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 3796 | } |
| 3797 | else if (DWARFFormValue::IsDataForm(form_value.Form())) |
| 3798 | { |
| 3799 | // we need to get the byte size of the type later after we create the variable |
| 3800 | const_value = form_value; |
| 3801 | } |
| 3802 | } |
| 3803 | else |
| 3804 | location.CopyOpcodeData(module, debug_info_data, data_offset, data_length); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 3805 | } |
| 3806 | else |
| 3807 | { |
| 3808 | // Retrieve the value as a string expression. |
| 3809 | if (form_value.Form() == DW_FORM_strp) |
| 3810 | { |
| Tamas Berghammer | b7c6465 | 2015-08-25 11:45:46 +0000 | [diff] [blame] | 3811 | DWARFFormValue::FixedFormSizes fixed_form_sizes = |
| 3812 | DWARFFormValue::GetFixedFormSizesForAddressSize ( |
| 3813 | attributes.CompileUnitAtIndex(i)->GetAddressByteSize(), |
| 3814 | attributes.CompileUnitAtIndex(i)->IsDWARF64()); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 3815 | uint32_t data_offset = attributes.DIEOffsetAtIndex(i); |
| Tamas Berghammer | b7c6465 | 2015-08-25 11:45:46 +0000 | [diff] [blame] | 3816 | uint32_t data_length = fixed_form_sizes.GetSize(form_value.Form()); |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 3817 | location.CopyOpcodeData(module, debug_info_data, data_offset, data_length); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 3818 | } |
| 3819 | else |
| 3820 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3821 | const char *str = form_value.AsCString(); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 3822 | uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart(); |
| 3823 | uint32_t string_length = strlen(str) + 1; |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 3824 | location.CopyOpcodeData(module, debug_info_data, string_offset, string_length); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 3825 | } |
| 3826 | } |
| 3827 | } |
| 3828 | break; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3829 | case DW_AT_location: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3830 | { |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 3831 | location_is_const_value_data = false; |
| 3832 | has_explicit_location = true; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3833 | if (form_value.BlockData()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3834 | { |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 3835 | const DWARFDataExtractor& debug_info_data = get_debug_info_data(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3836 | |
| 3837 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 3838 | uint32_t block_length = form_value.Unsigned(); |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 3839 | location.CopyOpcodeData(module, get_debug_info_data(), block_offset, block_length); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3840 | } |
| 3841 | else |
| 3842 | { |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 3843 | const DWARFDataExtractor& debug_loc_data = get_debug_loc_data(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3844 | const dw_offset_t debug_loc_offset = form_value.Unsigned(); |
| 3845 | |
| 3846 | size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset); |
| 3847 | if (loc_list_length > 0) |
| 3848 | { |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 3849 | location.CopyOpcodeData(module, debug_loc_data, debug_loc_offset, loc_list_length); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3850 | assert (func_low_pc != LLDB_INVALID_ADDRESS); |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 3851 | location.SetLocationListSlide (func_low_pc - attributes.CompileUnitAtIndex(i)->GetBaseAddress()); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3852 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3853 | } |
| 3854 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3855 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3856 | |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 3857 | case DW_AT_artificial: is_artificial = form_value.Boolean(); break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 3858 | 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] | 3859 | case DW_AT_declaration: |
| 3860 | case DW_AT_description: |
| 3861 | case DW_AT_endianity: |
| 3862 | case DW_AT_segment: |
| 3863 | case DW_AT_start_scope: |
| 3864 | case DW_AT_visibility: |
| 3865 | default: |
| 3866 | case DW_AT_abstract_origin: |
| 3867 | case DW_AT_sibling: |
| 3868 | case DW_AT_specification: |
| 3869 | break; |
| 3870 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3871 | } |
| 3872 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3873 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3874 | const DWARFDIE parent_context_die = GetDeclContextDIEContainingDIE(die); |
| 3875 | const dw_tag_t parent_tag = die.GetParent().Tag(); |
| 3876 | bool is_static_member = parent_tag == DW_TAG_compile_unit && (parent_context_die.Tag() == DW_TAG_class_type || parent_context_die.Tag() == DW_TAG_structure_type); |
| Paul Herman | 10bc1a4 | 2015-08-18 22:46:57 +0000 | [diff] [blame] | 3877 | |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 3878 | ValueType scope = eValueTypeInvalid; |
| 3879 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3880 | const DWARFDIE sc_parent_die = GetParentSymbolContextDIE(die); |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 3881 | SymbolContextScope * symbol_context_scope = NULL; |
| 3882 | |
| Siva Chandra | 0783ab9 | 2015-03-24 18:32:27 +0000 | [diff] [blame] | 3883 | if (!mangled) |
| 3884 | { |
| 3885 | // LLDB relies on the mangled name (DW_TAG_linkage_name or DW_AT_MIPS_linkage_name) to |
| 3886 | // generate fully qualified names of global variables with commands like "frame var j". |
| 3887 | // For example, if j were an int variable holding a value 4 and declared in a namespace |
| 3888 | // B which in turn is contained in a namespace A, the command "frame var j" returns |
| 3889 | // "(int) A::B::j = 4". If the compiler does not emit a linkage name, we should be able |
| 3890 | // to generate a fully qualified name from the declaration context. |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3891 | if (parent_tag == DW_TAG_compile_unit && |
| Jim Ingham | 0e0984e | 2015-09-02 01:06:46 +0000 | [diff] [blame] | 3892 | Language::LanguageIsCPlusPlus(die.GetLanguage())) |
| Siva Chandra | 0783ab9 | 2015-03-24 18:32:27 +0000 | [diff] [blame] | 3893 | { |
| 3894 | DWARFDeclContext decl_ctx; |
| 3895 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3896 | die.GetDWARFDeclContext(decl_ctx); |
| Siva Chandra | 0783ab9 | 2015-03-24 18:32:27 +0000 | [diff] [blame] | 3897 | mangled = decl_ctx.GetQualifiedNameAsConstString().GetCString(); |
| 3898 | } |
| 3899 | } |
| 3900 | |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 3901 | // DWARF doesn't specify if a DW_TAG_variable is a local, global |
| 3902 | // or static variable, so we have to do a little digging by |
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 3903 | // looking at the location of a variable to see if it contains |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 3904 | // a DW_OP_addr opcode _somewhere_ in the definition. I say |
| 3905 | // somewhere because clang likes to combine small global variables |
| 3906 | // into the same symbol and have locations like: |
| 3907 | // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus |
| 3908 | // So if we don't have a DW_TAG_formal_parameter, we can look at |
| 3909 | // the location to see if it contains a DW_OP_addr opcode, and |
| 3910 | // then we can correctly classify our variables. |
| 3911 | if (tag == DW_TAG_formal_parameter) |
| 3912 | scope = eValueTypeVariableArgument; |
| 3913 | else |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3914 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 3915 | bool op_error = false; |
| 3916 | // Check if the location has a DW_OP_addr with any address value... |
| 3917 | lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS; |
| 3918 | if (!location_is_const_value_data) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 3919 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 3920 | location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error); |
| 3921 | if (op_error) |
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 3922 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 3923 | StreamString strm; |
| 3924 | location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL); |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 3925 | GetObjectFile()->GetModule()->ReportError ("0x%8.8x: %s has an invalid location: %s", die.GetOffset(), die.GetTagAsCString(), strm.GetString().c_str()); |
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 3926 | } |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 3927 | } |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3928 | |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 3929 | if (location_DW_OP_addr != LLDB_INVALID_ADDRESS) |
| 3930 | { |
| 3931 | if (is_external) |
| 3932 | scope = eValueTypeVariableGlobal; |
| 3933 | else |
| 3934 | scope = eValueTypeVariableStatic; |
| 3935 | |
| 3936 | |
| 3937 | SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile (); |
| 3938 | |
| 3939 | if (debug_map_symfile) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 3940 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 3941 | // When leaving the DWARF in the .o files on darwin, |
| 3942 | // when we have a global variable that wasn't initialized, |
| 3943 | // the .o file might not have allocated a virtual |
| 3944 | // address for the global variable. In this case it will |
| 3945 | // have created a symbol for the global variable |
| 3946 | // that is undefined/data and external and the value will |
| 3947 | // be the byte size of the variable. When we do the |
| 3948 | // address map in SymbolFileDWARFDebugMap we rely on |
| 3949 | // having an address, we need to do some magic here |
| 3950 | // so we can get the correct address for our global |
| 3951 | // variable. The address for all of these entries |
| 3952 | // will be zero, and there will be an undefined symbol |
| 3953 | // in this object file, and the executable will have |
| 3954 | // a matching symbol with a good address. So here we |
| 3955 | // dig up the correct address and replace it in the |
| 3956 | // location for the variable, and set the variable's |
| 3957 | // symbol context scope to be that of the main executable |
| 3958 | // so the file address will resolve correctly. |
| 3959 | bool linked_oso_file_addr = false; |
| 3960 | if (is_external && location_DW_OP_addr == 0) |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 3961 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 3962 | // we have a possible uninitialized extern global |
| 3963 | ConstString const_name(mangled ? mangled : name); |
| 3964 | ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile(); |
| 3965 | if (debug_map_objfile) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 3966 | { |
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 3967 | Symtab *debug_map_symtab = debug_map_objfile->GetSymtab(); |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 3968 | if (debug_map_symtab) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 3969 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 3970 | Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name, |
| 3971 | eSymbolTypeData, |
| 3972 | Symtab::eDebugYes, |
| 3973 | Symtab::eVisibilityExtern); |
| 3974 | if (exe_symbol) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 3975 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 3976 | if (exe_symbol->ValueIsAddress()) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 3977 | { |
| Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 3978 | const addr_t exe_file_addr = exe_symbol->GetAddressRef().GetFileAddress(); |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 3979 | if (exe_file_addr != LLDB_INVALID_ADDRESS) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 3980 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 3981 | if (location.Update_DW_OP_addr (exe_file_addr)) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 3982 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 3983 | linked_oso_file_addr = true; |
| 3984 | symbol_context_scope = exe_symbol; |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 3985 | } |
| 3986 | } |
| 3987 | } |
| 3988 | } |
| 3989 | } |
| 3990 | } |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 3991 | } |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 3992 | |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 3993 | if (!linked_oso_file_addr) |
| 3994 | { |
| 3995 | // The DW_OP_addr is not zero, but it contains a .o file address which |
| 3996 | // needs to be linked up correctly. |
| 3997 | const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr); |
| 3998 | if (exe_file_addr != LLDB_INVALID_ADDRESS) |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 3999 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4000 | // Update the file address for this variable |
| 4001 | location.Update_DW_OP_addr (exe_file_addr); |
| 4002 | } |
| 4003 | else |
| 4004 | { |
| 4005 | // Variable didn't make it into the final executable |
| 4006 | return var_sp; |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 4007 | } |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4008 | } |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 4009 | } |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4010 | } |
| 4011 | else |
| 4012 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4013 | scope = eValueTypeVariableLocal; |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4014 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4015 | } |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4016 | |
| 4017 | if (symbol_context_scope == NULL) |
| 4018 | { |
| 4019 | switch (parent_tag) |
| 4020 | { |
| 4021 | case DW_TAG_subprogram: |
| 4022 | case DW_TAG_inlined_subroutine: |
| 4023 | case DW_TAG_lexical_block: |
| 4024 | if (sc.function) |
| 4025 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 4026 | symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(sc_parent_die.GetID()); |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4027 | if (symbol_context_scope == NULL) |
| 4028 | symbol_context_scope = sc.function; |
| 4029 | } |
| 4030 | break; |
| 4031 | |
| 4032 | default: |
| 4033 | symbol_context_scope = sc.comp_unit; |
| 4034 | break; |
| 4035 | } |
| 4036 | } |
| 4037 | |
| 4038 | if (symbol_context_scope) |
| 4039 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 4040 | SymbolFileTypeSP type_sp(new SymbolFileType(*this, DIERef(type_die_form).GetUID())); |
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 4041 | |
| 4042 | if (const_value.Form() && type_sp && type_sp->GetType()) |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 4043 | location.CopyOpcodeData(const_value.Unsigned(), type_sp->GetType()->GetByteSize(), die.GetCU()->GetAddressByteSize()); |
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 4044 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 4045 | var_sp.reset (new Variable (die.GetID(), |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4046 | name, |
| 4047 | mangled, |
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 4048 | type_sp, |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4049 | scope, |
| 4050 | symbol_context_scope, |
| 4051 | &decl, |
| 4052 | location, |
| 4053 | is_external, |
| Paul Herman | 10bc1a4 | 2015-08-18 22:46:57 +0000 | [diff] [blame] | 4054 | is_artificial, |
| 4055 | is_static_member)); |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4056 | |
| 4057 | var_sp->SetLocationIsConstantValueData (location_is_const_value_data); |
| 4058 | } |
| 4059 | else |
| 4060 | { |
| 4061 | // Not ready to parse this variable yet. It might be a global |
| 4062 | // or static variable that is in a function scope and the function |
| 4063 | // in the symbol context wasn't filled in yet |
| 4064 | return var_sp; |
| 4065 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4066 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4067 | // Cache var_sp even if NULL (the variable was just a specification or |
| 4068 | // was missing vital information to be able to be displayed in the debugger |
| 4069 | // (missing location due to optimization, etc)) so we don't re-parse |
| 4070 | // this DIE over and over later... |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 4071 | GetDIEToVariable()[die.GetDIE()] = var_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4072 | } |
| 4073 | return var_sp; |
| 4074 | } |
| 4075 | |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4076 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 4077 | DWARFDIE |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 4078 | SymbolFileDWARF::FindBlockContainingSpecification (const DIERef& func_die_ref, |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 4079 | dw_offset_t spec_block_die_offset) |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4080 | { |
| 4081 | // Give the concrete function die specified by "func_die_offset", find the |
| 4082 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points |
| 4083 | // to "spec_block_die_offset" |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 4084 | return FindBlockContainingSpecification (DebugInfo()->GetDIE (func_die_ref), spec_block_die_offset); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4085 | } |
| 4086 | |
| 4087 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 4088 | DWARFDIE |
| 4089 | SymbolFileDWARF::FindBlockContainingSpecification(const DWARFDIE &die, |
| 4090 | dw_offset_t spec_block_die_offset) |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4091 | { |
| 4092 | if (die) |
| 4093 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 4094 | switch (die.Tag()) |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4095 | { |
| 4096 | case DW_TAG_subprogram: |
| 4097 | case DW_TAG_inlined_subroutine: |
| 4098 | case DW_TAG_lexical_block: |
| 4099 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 4100 | if (die.GetAttributeValueAsReference (DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset) |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4101 | return die; |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4102 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 4103 | if (die.GetAttributeValueAsReference (DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset) |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4104 | return die; |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4105 | } |
| 4106 | break; |
| 4107 | } |
| 4108 | |
| 4109 | // Give the concrete function die specified by "func_die_offset", find the |
| 4110 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points |
| 4111 | // to "spec_block_die_offset" |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 4112 | for (DWARFDIE child_die = die.GetFirstChild(); child_die; child_die = child_die.GetSibling()) |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4113 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 4114 | DWARFDIE result_die = FindBlockContainingSpecification (child_die, spec_block_die_offset); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4115 | if (result_die) |
| 4116 | return result_die; |
| 4117 | } |
| 4118 | } |
| 4119 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 4120 | return DWARFDIE(); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4121 | } |
| 4122 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4123 | size_t |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 4124 | SymbolFileDWARF::ParseVariables (const SymbolContext& sc, |
| 4125 | const DWARFDIE &orig_die, |
| 4126 | const lldb::addr_t func_low_pc, |
| 4127 | bool parse_siblings, |
| 4128 | bool parse_children, |
| 4129 | VariableList* cc_variable_list) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4130 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 4131 | if (!orig_die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4132 | return 0; |
| 4133 | |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4134 | VariableListSP variable_list_sp; |
| 4135 | |
| 4136 | size_t vars_added = 0; |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 4137 | DWARFDIE die = orig_die; |
| 4138 | while (die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4139 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 4140 | dw_tag_t tag = die.Tag(); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4141 | |
| 4142 | // Check to see if we have already parsed this variable or constant? |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 4143 | VariableSP var_sp = GetDIEToVariable()[die.GetDIE()]; |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 4144 | if (var_sp) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4145 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4146 | if (cc_variable_list) |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 4147 | cc_variable_list->AddVariableIfUnique (var_sp); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4148 | } |
| 4149 | else |
| 4150 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4151 | // We haven't already parsed it, lets do that now. |
| 4152 | if ((tag == DW_TAG_variable) || |
| 4153 | (tag == DW_TAG_constant) || |
| 4154 | (tag == DW_TAG_formal_parameter && sc.function)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4155 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4156 | if (variable_list_sp.get() == NULL) |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 4157 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 4158 | DWARFDIE sc_parent_die = GetParentSymbolContextDIE(orig_die); |
| 4159 | dw_tag_t parent_tag = sc_parent_die.Tag(); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4160 | switch (parent_tag) |
| 4161 | { |
| 4162 | case DW_TAG_compile_unit: |
| 4163 | if (sc.comp_unit != NULL) |
| 4164 | { |
| 4165 | variable_list_sp = sc.comp_unit->GetVariableList(false); |
| 4166 | if (variable_list_sp.get() == NULL) |
| 4167 | { |
| 4168 | variable_list_sp.reset(new VariableList()); |
| 4169 | sc.comp_unit->SetVariableList(variable_list_sp); |
| 4170 | } |
| 4171 | } |
| 4172 | else |
| 4173 | { |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4174 | GetObjectFile()->GetModule()->ReportError ("parent 0x%8.8" PRIx64 " %s with no valid compile unit in symbol context for 0x%8.8" PRIx64 " %s.\n", |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 4175 | sc_parent_die.GetID(), |
| 4176 | sc_parent_die.GetTagAsCString(), |
| 4177 | orig_die.GetID(), |
| 4178 | orig_die.GetTagAsCString()); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4179 | } |
| 4180 | break; |
| 4181 | |
| 4182 | case DW_TAG_subprogram: |
| 4183 | case DW_TAG_inlined_subroutine: |
| 4184 | case DW_TAG_lexical_block: |
| 4185 | if (sc.function != NULL) |
| 4186 | { |
| 4187 | // Check to see if we already have parsed the variables for the given scope |
| 4188 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 4189 | Block *block = sc.function->GetBlock(true).FindBlockByID(sc_parent_die.GetID()); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4190 | if (block == NULL) |
| 4191 | { |
| 4192 | // This must be a specification or abstract origin with |
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 4193 | // a concrete block counterpart in the current function. We need |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4194 | // to find the concrete block so we can correctly add the |
| 4195 | // variable to it |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame^] | 4196 | const DWARFDIE concrete_block_die = FindBlockContainingSpecification (DIERef(sc.function->GetID()), |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 4197 | sc_parent_die.GetOffset()); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4198 | if (concrete_block_die) |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 4199 | block = sc.function->GetBlock(true).FindBlockByID(concrete_block_die.GetID()); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4200 | } |
| 4201 | |
| 4202 | if (block != NULL) |
| 4203 | { |
| 4204 | const bool can_create = false; |
| 4205 | variable_list_sp = block->GetBlockVariableList (can_create); |
| 4206 | if (variable_list_sp.get() == NULL) |
| 4207 | { |
| 4208 | variable_list_sp.reset(new VariableList()); |
| 4209 | block->SetVariableList(variable_list_sp); |
| 4210 | } |
| 4211 | } |
| 4212 | } |
| 4213 | break; |
| 4214 | |
| 4215 | default: |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4216 | GetObjectFile()->GetModule()->ReportError ("didn't find appropriate parent DIE for variable list for 0x%8.8" PRIx64 " %s.\n", |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 4217 | orig_die.GetID(), |
| 4218 | orig_die.GetTagAsCString()); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4219 | break; |
| 4220 | } |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 4221 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4222 | |
| 4223 | if (variable_list_sp) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4224 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 4225 | VariableSP var_sp (ParseVariableDIE(sc, die, func_low_pc)); |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 4226 | if (var_sp) |
| 4227 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4228 | variable_list_sp->AddVariableIfUnique (var_sp); |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 4229 | if (cc_variable_list) |
| 4230 | cc_variable_list->AddVariableIfUnique (var_sp); |
| 4231 | ++vars_added; |
| 4232 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4233 | } |
| 4234 | } |
| 4235 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4236 | |
| 4237 | bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram); |
| 4238 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 4239 | if (!skip_children && parse_children && die.HasChildren()) |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4240 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 4241 | vars_added += ParseVariables(sc, die.GetFirstChild(), func_low_pc, true, true, cc_variable_list); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4242 | } |
| 4243 | |
| 4244 | if (parse_siblings) |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 4245 | die = die.GetSibling(); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4246 | else |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 4247 | die.Clear(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4248 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4249 | return vars_added; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4250 | } |
| 4251 | |
| 4252 | //------------------------------------------------------------------ |
| 4253 | // PluginInterface protocol |
| 4254 | //------------------------------------------------------------------ |
| Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 4255 | ConstString |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4256 | SymbolFileDWARF::GetPluginName() |
| 4257 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4258 | return GetPluginNameStatic(); |
| 4259 | } |
| 4260 | |
| 4261 | uint32_t |
| 4262 | SymbolFileDWARF::GetPluginVersion() |
| 4263 | { |
| 4264 | return 1; |
| 4265 | } |
| 4266 | |
| 4267 | void |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 4268 | SymbolFileDWARF::DumpIndexes () |
| 4269 | { |
| 4270 | StreamFile s(stdout, false); |
| 4271 | |
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 4272 | s.Printf ("DWARF index for (%s) '%s':", |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 4273 | GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(), |
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 4274 | GetObjectFile()->GetFileSpec().GetPath().c_str()); |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 4275 | s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s); |
| 4276 | s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s); |
| 4277 | s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s); |
| 4278 | s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s); |
| 4279 | s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s); |
| 4280 | s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s); |
| 4281 | s.Printf("\nTypes:\n"); m_type_index.Dump (&s); |
| Bruce Mitchener | e171da5 | 2015-07-22 00:16:02 +0000 | [diff] [blame] | 4282 | s.Printf("\nNamespaces:\n"); m_namespace_index.Dump (&s); |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 4283 | } |
| 4284 | |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 4285 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 4286 | SymbolFileDWARFDebugMap * |
| 4287 | SymbolFileDWARF::GetDebugMapSymfile () |
| 4288 | { |
| 4289 | if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired()) |
| 4290 | { |
| 4291 | lldb::ModuleSP module_sp (m_debug_map_module_wp.lock()); |
| 4292 | if (module_sp) |
| 4293 | { |
| 4294 | SymbolVendor *sym_vendor = module_sp->GetSymbolVendor(); |
| 4295 | if (sym_vendor) |
| 4296 | m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile(); |
| 4297 | } |
| 4298 | } |
| 4299 | return m_debug_map_symfile; |
| 4300 | } |