| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- SymbolFileDWARF.cpp ------------------------------------*- C++ -*-===// |
| 2 | // |
| Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "SymbolFileDWARF.h" |
| 10 | |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 11 | #include "llvm/Support/Casting.h" |
| Kamil Rytarowski | c5f28e2 | 2017-02-06 17:55:02 +0000 | [diff] [blame] | 12 | #include "llvm/Support/Threading.h" |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 13 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 14 | #include "lldb/Core/Module.h" |
| Sean Callanan | f0c5aeb | 2015-04-20 16:31:29 +0000 | [diff] [blame] | 15 | #include "lldb/Core/ModuleList.h" |
| 16 | #include "lldb/Core/ModuleSpec.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | #include "lldb/Core/PluginManager.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | #include "lldb/Core/Section.h" |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 19 | #include "lldb/Core/StreamFile.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | #include "lldb/Core/Value.h" |
| Pavel Labath | 5f19b90 | 2017-11-13 16:16:33 +0000 | [diff] [blame] | 21 | #include "lldb/Utility/ArchSpec.h" |
| Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 22 | #include "lldb/Utility/RegularExpression.h" |
| Pavel Labath | d821c99 | 2018-08-07 11:07:21 +0000 | [diff] [blame] | 23 | #include "lldb/Utility/Scalar.h" |
| Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 24 | #include "lldb/Utility/StreamString.h" |
| Pavel Labath | 38d0632 | 2017-06-29 14:32:17 +0000 | [diff] [blame] | 25 | #include "lldb/Utility/Timer.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 26 | |
| Sean Callanan | 4dbb271 | 2015-09-25 20:35:58 +0000 | [diff] [blame] | 27 | #include "Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.h" |
| Pavel Labath | e1d1875 | 2018-06-07 10:04:44 +0000 | [diff] [blame] | 28 | #include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h" |
| Sean Callanan | f0c5aeb | 2015-04-20 16:31:29 +0000 | [diff] [blame] | 29 | |
| Oleksiy Vyalov | 5d9c50b | 2015-07-21 02:09:42 +0000 | [diff] [blame] | 30 | #include "lldb/Host/FileSystem.h" |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 31 | #include "lldb/Host/Host.h" |
| 32 | |
| Oleksiy Vyalov | abb5a35 | 2015-07-29 22:18:16 +0000 | [diff] [blame] | 33 | #include "lldb/Interpreter/OptionValueFileSpecList.h" |
| 34 | #include "lldb/Interpreter/OptionValueProperties.h" |
| 35 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 36 | #include "lldb/Symbol/Block.h" |
| Bruce Mitchener | 937e396 | 2015-09-21 16:56:08 +0000 | [diff] [blame] | 37 | #include "lldb/Symbol/ClangASTContext.h" |
| Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 38 | #include "lldb/Symbol/ClangUtil.h" |
| 39 | #include "lldb/Symbol/CompileUnit.h" |
| Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 40 | #include "lldb/Symbol/CompilerDecl.h" |
| 41 | #include "lldb/Symbol/CompilerDeclContext.h" |
| Siva Chandra | d8335e9 | 2015-12-16 00:22:08 +0000 | [diff] [blame] | 42 | #include "lldb/Symbol/DebugMacros.h" |
| Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 43 | #include "lldb/Symbol/LineTable.h" |
| Zachary Turner | 8055291 | 2019-02-27 21:42:10 +0000 | [diff] [blame] | 44 | #include "lldb/Symbol/LocateSymbolFile.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 45 | #include "lldb/Symbol/ObjectFile.h" |
| 46 | #include "lldb/Symbol/SymbolVendor.h" |
| Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 47 | #include "lldb/Symbol/TypeMap.h" |
| Bruce Mitchener | 937e396 | 2015-09-21 16:56:08 +0000 | [diff] [blame] | 48 | #include "lldb/Symbol/TypeSystem.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 49 | #include "lldb/Symbol/VariableList.h" |
| 50 | |
| Jim Ingham | 0e0984e | 2015-09-02 01:06:46 +0000 | [diff] [blame] | 51 | #include "lldb/Target/Language.h" |
| Zachary Turner | a89ce43 | 2019-03-06 18:20:23 +0000 | [diff] [blame] | 52 | #include "lldb/Target/Target.h" |
| Jim Ingham | 0e0984e | 2015-09-02 01:06:46 +0000 | [diff] [blame] | 53 | |
| Pavel Labath | b13f033 | 2018-05-21 14:12:52 +0000 | [diff] [blame] | 54 | #include "AppleDWARFIndex.h" |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 55 | #include "DWARFASTParser.h" |
| Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 56 | #include "DWARFASTParserClang.h" |
| Pavel Labath | ca9c3de | 2019-06-12 11:29:50 +0000 | [diff] [blame] | 57 | #include "DWARFCompileUnit.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 58 | #include "DWARFDebugAbbrev.h" |
| 59 | #include "DWARFDebugAranges.h" |
| 60 | #include "DWARFDebugInfo.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 61 | #include "DWARFDebugLine.h" |
| Siva Chandra | d8335e9 | 2015-12-16 00:22:08 +0000 | [diff] [blame] | 62 | #include "DWARFDebugMacro.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 63 | #include "DWARFDebugRanges.h" |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 64 | #include "DWARFDeclContext.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 65 | #include "DWARFFormValue.h" |
| Pavel Labath | ca9c3de | 2019-06-12 11:29:50 +0000 | [diff] [blame] | 66 | #include "DWARFTypeUnit.h" |
| Pavel Labath | b13f033 | 2018-05-21 14:12:52 +0000 | [diff] [blame] | 67 | #include "DWARFUnit.h" |
| Pavel Labath | 9337b41 | 2018-06-06 11:35:23 +0000 | [diff] [blame] | 68 | #include "DebugNamesDWARFIndex.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 69 | #include "LogChannelDWARF.h" |
| Pavel Labath | b13f033 | 2018-05-21 14:12:52 +0000 | [diff] [blame] | 70 | #include "ManualDWARFIndex.h" |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 71 | #include "SymbolFileDWARFDebugMap.h" |
| Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 72 | #include "SymbolFileDWARFDwo.h" |
| Tamas Berghammer | 963ce48 | 2017-08-25 13:56:14 +0000 | [diff] [blame] | 73 | #include "SymbolFileDWARFDwp.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 74 | |
| Zachary Turner | 7d86ee5 | 2017-03-08 17:56:08 +0000 | [diff] [blame] | 75 | #include "llvm/Support/FileSystem.h" |
| 76 | |
| Adrian Prantl | 0f30a3b | 2019-02-13 18:10:41 +0000 | [diff] [blame] | 77 | #include <algorithm> |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 78 | #include <map> |
| Jonas Devlieghere | 796ac80 | 2019-02-11 23:13:08 +0000 | [diff] [blame] | 79 | #include <memory> |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 80 | |
| Matthew Gardiner | e81df3b | 2014-08-26 06:57:23 +0000 | [diff] [blame] | 81 | #include <ctype.h> |
| 82 | #include <string.h> |
| 83 | |
| Greg Clayton | 62742b1 | 2010-11-11 01:09:45 +0000 | [diff] [blame] | 84 | //#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 85 | |
| 86 | #ifdef ENABLE_DEBUG_PRINTF |
| 87 | #include <stdio.h> |
| Ed Maste | a0191d1 | 2013-10-17 20:42:56 +0000 | [diff] [blame] | 88 | #define DEBUG_PRINTF(fmt, ...) printf(fmt, __VA_ARGS__) |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 89 | #else |
| 90 | #define DEBUG_PRINTF(fmt, ...) |
| 91 | #endif |
| 92 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 93 | using namespace lldb; |
| 94 | using namespace lldb_private; |
| 95 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 96 | // static inline bool |
| 97 | // child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag) |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 98 | //{ |
| 99 | // switch (tag) |
| 100 | // { |
| 101 | // default: |
| 102 | // break; |
| 103 | // case DW_TAG_subprogram: |
| 104 | // case DW_TAG_inlined_subroutine: |
| 105 | // case DW_TAG_class_type: |
| 106 | // case DW_TAG_structure_type: |
| 107 | // case DW_TAG_union_type: |
| 108 | // return true; |
| 109 | // } |
| 110 | // return false; |
| 111 | //} |
| 112 | // |
| Oleksiy Vyalov | abb5a35 | 2015-07-29 22:18:16 +0000 | [diff] [blame] | 113 | |
| 114 | namespace { |
| 115 | |
| Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 116 | static constexpr PropertyDefinition g_properties[] = { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 117 | {"comp-dir-symlink-paths", OptionValue::eTypeFileSpecList, true, 0, nullptr, |
| Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 118 | {}, |
| Pavel Labath | 9337b41 | 2018-06-06 11:35:23 +0000 | [diff] [blame] | 119 | "If the DW_AT_comp_dir matches any of these paths the symbolic " |
| 120 | "links will be resolved at DWARF parse time."}, |
| Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 121 | {"ignore-file-indexes", OptionValue::eTypeBoolean, true, 0, nullptr, {}, |
| Pavel Labath | 9337b41 | 2018-06-06 11:35:23 +0000 | [diff] [blame] | 122 | "Ignore indexes present in the object files and always index DWARF " |
| Tatyana Krasnukha | e40db05 | 2018-09-27 07:11:58 +0000 | [diff] [blame] | 123 | "manually."}}; |
| Oleksiy Vyalov | abb5a35 | 2015-07-29 22:18:16 +0000 | [diff] [blame] | 124 | |
| Pavel Labath | 9337b41 | 2018-06-06 11:35:23 +0000 | [diff] [blame] | 125 | enum { |
| 126 | ePropertySymLinkPaths, |
| 127 | ePropertyIgnoreIndexes, |
| 128 | }; |
| Oleksiy Vyalov | abb5a35 | 2015-07-29 22:18:16 +0000 | [diff] [blame] | 129 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 130 | class PluginProperties : public Properties { |
| 131 | public: |
| 132 | static ConstString GetSettingName() { |
| 133 | return SymbolFileDWARF::GetPluginNameStatic(); |
| 134 | } |
| Oleksiy Vyalov | abb5a35 | 2015-07-29 22:18:16 +0000 | [diff] [blame] | 135 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 136 | PluginProperties() { |
| Jonas Devlieghere | 796ac80 | 2019-02-11 23:13:08 +0000 | [diff] [blame] | 137 | m_collection_sp = std::make_shared<OptionValueProperties>(GetSettingName()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 138 | m_collection_sp->Initialize(g_properties); |
| 139 | } |
| Oleksiy Vyalov | abb5a35 | 2015-07-29 22:18:16 +0000 | [diff] [blame] | 140 | |
| Frederic Riss | acbf005 | 2019-04-23 20:17:04 +0000 | [diff] [blame] | 141 | FileSpecList GetSymLinkPaths() { |
| 142 | const OptionValueFileSpecList *option_value = |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 143 | m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList( |
| 144 | nullptr, true, ePropertySymLinkPaths); |
| 145 | assert(option_value); |
| 146 | return option_value->GetCurrentValue(); |
| 147 | } |
| Pavel Labath | 9337b41 | 2018-06-06 11:35:23 +0000 | [diff] [blame] | 148 | |
| 149 | bool IgnoreFileIndexes() const { |
| 150 | return m_collection_sp->GetPropertyAtIndexAsBoolean( |
| 151 | nullptr, ePropertyIgnoreIndexes, false); |
| 152 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 153 | }; |
| Oleksiy Vyalov | abb5a35 | 2015-07-29 22:18:16 +0000 | [diff] [blame] | 154 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 155 | typedef std::shared_ptr<PluginProperties> SymbolFileDWARFPropertiesSP; |
| Oleksiy Vyalov | abb5a35 | 2015-07-29 22:18:16 +0000 | [diff] [blame] | 156 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 157 | static const SymbolFileDWARFPropertiesSP &GetGlobalPluginProperties() { |
| 158 | static const auto g_settings_sp(std::make_shared<PluginProperties>()); |
| 159 | return g_settings_sp; |
| Matthew Gardiner | e81df3b | 2014-08-26 06:57:23 +0000 | [diff] [blame] | 160 | } |
| 161 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 162 | } // anonymous namespace end |
| Oleksiy Vyalov | 5d9c50b | 2015-07-21 02:09:42 +0000 | [diff] [blame] | 163 | |
| Frederic Riss | acbf005 | 2019-04-23 20:17:04 +0000 | [diff] [blame] | 164 | FileSpecList SymbolFileDWARF::GetSymlinkPaths() { |
| Pavel Labath | 7d36d72 | 2019-01-16 12:30:41 +0000 | [diff] [blame] | 165 | return GetGlobalPluginProperties()->GetSymLinkPaths(); |
| Oleksiy Vyalov | 5d9c50b | 2015-07-21 02:09:42 +0000 | [diff] [blame] | 166 | } |
| 167 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 168 | void SymbolFileDWARF::Initialize() { |
| 169 | LogChannelDWARF::Initialize(); |
| 170 | PluginManager::RegisterPlugin(GetPluginNameStatic(), |
| 171 | GetPluginDescriptionStatic(), CreateInstance, |
| 172 | DebuggerInitialize); |
| Oleksiy Vyalov | abb5a35 | 2015-07-29 22:18:16 +0000 | [diff] [blame] | 173 | } |
| 174 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 175 | void SymbolFileDWARF::DebuggerInitialize(Debugger &debugger) { |
| 176 | if (!PluginManager::GetSettingForSymbolFilePlugin( |
| 177 | debugger, PluginProperties::GetSettingName())) { |
| 178 | const bool is_global_setting = true; |
| 179 | PluginManager::CreateSettingForSymbolFilePlugin( |
| 180 | debugger, GetGlobalPluginProperties()->GetValueProperties(), |
| 181 | ConstString("Properties for the dwarf symbol-file plug-in."), |
| 182 | is_global_setting); |
| 183 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 184 | } |
| 185 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 186 | void SymbolFileDWARF::Terminate() { |
| 187 | PluginManager::UnregisterPlugin(CreateInstance); |
| Pavel Labath | fb0d22d | 2017-02-17 13:27:42 +0000 | [diff] [blame] | 188 | LogChannelDWARF::Terminate(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 191 | lldb_private::ConstString SymbolFileDWARF::GetPluginNameStatic() { |
| 192 | static ConstString g_name("dwarf"); |
| 193 | return g_name; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 194 | } |
| 195 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 196 | const char *SymbolFileDWARF::GetPluginDescriptionStatic() { |
| 197 | return "DWARF and DWARF3 debug symbol file reader."; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 198 | } |
| 199 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 200 | SymbolFile *SymbolFileDWARF::CreateInstance(ObjectFile *obj_file) { |
| Pavel Labath | ff9b426 | 2019-05-17 08:26:58 +0000 | [diff] [blame] | 201 | return new SymbolFileDWARF(obj_file, |
| 202 | /*dwo_section_list*/ nullptr); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 203 | } |
| 204 | |
| Pavel Labath | f46e897 | 2019-07-25 08:22:05 +0000 | [diff] [blame^] | 205 | TypeList &SymbolFileDWARF::GetTypeList() { |
| Jonas Devlieghere | 4f78c4f | 2018-10-22 20:14:36 +0000 | [diff] [blame] | 206 | // This method can be called without going through the symbol vendor so we |
| 207 | // need to lock the module. |
| 208 | std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); |
| Pavel Labath | f46e897 | 2019-07-25 08:22:05 +0000 | [diff] [blame^] | 209 | if (SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile()) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 210 | return debug_map_symfile->GetTypeList(); |
| Pavel Labath | f46e897 | 2019-07-25 08:22:05 +0000 | [diff] [blame^] | 211 | return SymbolFile::GetTypeList(); |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 212 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 213 | void SymbolFileDWARF::GetTypes(const DWARFDIE &die, dw_offset_t min_die_offset, |
| 214 | dw_offset_t max_die_offset, uint32_t type_mask, |
| 215 | TypeSet &type_set) { |
| 216 | if (die) { |
| 217 | const dw_offset_t die_offset = die.GetOffset(); |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 218 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 219 | if (die_offset >= max_die_offset) |
| 220 | return; |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 221 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 222 | if (die_offset >= min_die_offset) { |
| 223 | const dw_tag_t tag = die.Tag(); |
| 224 | |
| 225 | bool add_type = false; |
| 226 | |
| 227 | switch (tag) { |
| 228 | case DW_TAG_array_type: |
| 229 | add_type = (type_mask & eTypeClassArray) != 0; |
| 230 | break; |
| 231 | case DW_TAG_unspecified_type: |
| 232 | case DW_TAG_base_type: |
| 233 | add_type = (type_mask & eTypeClassBuiltin) != 0; |
| 234 | break; |
| 235 | case DW_TAG_class_type: |
| 236 | add_type = (type_mask & eTypeClassClass) != 0; |
| 237 | break; |
| 238 | case DW_TAG_structure_type: |
| 239 | add_type = (type_mask & eTypeClassStruct) != 0; |
| 240 | break; |
| 241 | case DW_TAG_union_type: |
| 242 | add_type = (type_mask & eTypeClassUnion) != 0; |
| 243 | break; |
| 244 | case DW_TAG_enumeration_type: |
| 245 | add_type = (type_mask & eTypeClassEnumeration) != 0; |
| 246 | break; |
| 247 | case DW_TAG_subroutine_type: |
| 248 | case DW_TAG_subprogram: |
| 249 | case DW_TAG_inlined_subroutine: |
| 250 | add_type = (type_mask & eTypeClassFunction) != 0; |
| 251 | break; |
| 252 | case DW_TAG_pointer_type: |
| 253 | add_type = (type_mask & eTypeClassPointer) != 0; |
| 254 | break; |
| 255 | case DW_TAG_rvalue_reference_type: |
| 256 | case DW_TAG_reference_type: |
| 257 | add_type = (type_mask & eTypeClassReference) != 0; |
| 258 | break; |
| 259 | case DW_TAG_typedef: |
| 260 | add_type = (type_mask & eTypeClassTypedef) != 0; |
| 261 | break; |
| 262 | case DW_TAG_ptr_to_member_type: |
| 263 | add_type = (type_mask & eTypeClassMemberPointer) != 0; |
| 264 | break; |
| 265 | } |
| 266 | |
| 267 | if (add_type) { |
| 268 | const bool assert_not_being_parsed = true; |
| 269 | Type *type = ResolveTypeUID(die, assert_not_being_parsed); |
| 270 | if (type) { |
| 271 | if (type_set.find(type) == type_set.end()) |
| 272 | type_set.insert(type); |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 273 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 274 | } |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 275 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 276 | |
| 277 | for (DWARFDIE child_die = die.GetFirstChild(); child_die.IsValid(); |
| 278 | child_die = child_die.GetSibling()) { |
| 279 | GetTypes(child_die, min_die_offset, max_die_offset, type_mask, type_set); |
| 280 | } |
| 281 | } |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 282 | } |
| 283 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 284 | size_t SymbolFileDWARF::GetTypes(SymbolContextScope *sc_scope, |
| Zachary Turner | 117b1fa | 2018-10-25 20:45:40 +0000 | [diff] [blame] | 285 | TypeClass type_mask, TypeList &type_list) |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 286 | |
| 287 | { |
| Jonas Devlieghere | 4f78c4f | 2018-10-22 20:14:36 +0000 | [diff] [blame] | 288 | ASSERT_MODULE_LOCK(this); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 289 | TypeSet type_set; |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 290 | |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 291 | CompileUnit *comp_unit = nullptr; |
| 292 | DWARFUnit *dwarf_cu = nullptr; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 293 | if (sc_scope) |
| 294 | comp_unit = sc_scope->CalculateSymbolContextCompileUnit(); |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 295 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 296 | if (comp_unit) { |
| 297 | dwarf_cu = GetDWARFCompileUnit(comp_unit); |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 298 | if (dwarf_cu == nullptr) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 299 | return 0; |
| 300 | GetTypes(dwarf_cu->DIE(), dwarf_cu->GetOffset(), |
| Jan Kratochvil | 6056273 | 2019-05-10 17:14:37 +0000 | [diff] [blame] | 301 | dwarf_cu->GetNextUnitOffset(), type_mask, type_set); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 302 | } else { |
| 303 | DWARFDebugInfo *info = DebugInfo(); |
| 304 | if (info) { |
| Jan Kratochvil | 6056273 | 2019-05-10 17:14:37 +0000 | [diff] [blame] | 305 | const size_t num_cus = info->GetNumUnits(); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 306 | for (size_t cu_idx = 0; cu_idx < num_cus; ++cu_idx) { |
| Jan Kratochvil | 6056273 | 2019-05-10 17:14:37 +0000 | [diff] [blame] | 307 | dwarf_cu = info->GetUnitAtIndex(cu_idx); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 308 | if (dwarf_cu) { |
| 309 | GetTypes(dwarf_cu->DIE(), 0, UINT32_MAX, type_mask, type_set); |
| Greg Clayton | 0fc4f31 | 2013-06-20 01:23:18 +0000 | [diff] [blame] | 310 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 311 | } |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 312 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | std::set<CompilerType> compiler_type_set; |
| 316 | size_t num_types_added = 0; |
| 317 | for (Type *type : type_set) { |
| 318 | CompilerType compiler_type = type->GetForwardCompilerType(); |
| 319 | if (compiler_type_set.find(compiler_type) == compiler_type_set.end()) { |
| 320 | compiler_type_set.insert(compiler_type); |
| 321 | type_list.Insert(type->shared_from_this()); |
| 322 | ++num_types_added; |
| 323 | } |
| 324 | } |
| 325 | return num_types_added; |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 326 | } |
| 327 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 328 | // Gets the first parent that is a lexical block, function or inlined |
| 329 | // subroutine, or compile unit. |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 330 | DWARFDIE |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 331 | SymbolFileDWARF::GetParentSymbolContextDIE(const DWARFDIE &child_die) { |
| 332 | DWARFDIE die; |
| 333 | for (die = child_die.GetParent(); die; die = die.GetParent()) { |
| 334 | dw_tag_t tag = die.Tag(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 335 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 336 | switch (tag) { |
| 337 | case DW_TAG_compile_unit: |
| Jan Kratochvil | 55c84b1 | 2018-04-30 16:04:32 +0000 | [diff] [blame] | 338 | case DW_TAG_partial_unit: |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 339 | case DW_TAG_subprogram: |
| 340 | case DW_TAG_inlined_subroutine: |
| 341 | case DW_TAG_lexical_block: |
| 342 | return die; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 343 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 344 | } |
| 345 | return DWARFDIE(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 346 | } |
| 347 | |
| Pavel Labath | ff9b426 | 2019-05-17 08:26:58 +0000 | [diff] [blame] | 348 | SymbolFileDWARF::SymbolFileDWARF(ObjectFile *objfile, |
| 349 | SectionList *dwo_section_list) |
| Pavel Labath | f4014e1 | 2019-05-16 11:07:58 +0000 | [diff] [blame] | 350 | : SymbolFile(objfile), |
| 351 | UserID(0x7fffffff00000000), // Used by SymbolFileDWARFDebugMap to |
| 352 | // when this class parses .o files to |
| 353 | // contain the .o file index/ID |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 354 | m_debug_map_module_wp(), m_debug_map_symfile(nullptr), |
| Pavel Labath | ff9b426 | 2019-05-17 08:26:58 +0000 | [diff] [blame] | 355 | m_context(objfile->GetModule()->GetSectionList(), dwo_section_list), |
| Pavel Labath | 00e3968 | 2019-06-14 14:12:25 +0000 | [diff] [blame] | 356 | m_data_debug_loc(), m_abbr(), m_info(), m_fetched_external_modules(false), |
| Pavel Labath | 78cfe1e | 2019-05-29 09:22:36 +0000 | [diff] [blame] | 357 | m_supports_DW_AT_APPLE_objc_complete_type(eLazyBoolCalculate), |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 358 | m_unique_ast_type_map() {} |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 359 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 360 | SymbolFileDWARF::~SymbolFileDWARF() {} |
| 361 | |
| Adrian Prantl | 0e4c482 | 2019-03-06 21:22:25 +0000 | [diff] [blame] | 362 | static ConstString GetDWARFMachOSegmentName() { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 363 | static ConstString g_dwarf_section_name("__DWARF"); |
| 364 | return g_dwarf_section_name; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 365 | } |
| 366 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 367 | UniqueDWARFASTTypeMap &SymbolFileDWARF::GetUniqueDWARFASTTypeMap() { |
| 368 | SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile(); |
| 369 | if (debug_map_symfile) |
| 370 | return debug_map_symfile->GetUniqueDWARFASTTypeMap(); |
| 371 | else |
| 372 | return m_unique_ast_type_map; |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 373 | } |
| 374 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 375 | TypeSystem *SymbolFileDWARF::GetTypeSystemForLanguage(LanguageType language) { |
| 376 | SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile(); |
| 377 | TypeSystem *type_system; |
| 378 | if (debug_map_symfile) { |
| 379 | type_system = debug_map_symfile->GetTypeSystemForLanguage(language); |
| 380 | } else { |
| 381 | type_system = m_obj_file->GetModule()->GetTypeSystemForLanguage(language); |
| 382 | if (type_system) |
| 383 | type_system->SetSymbolFile(this); |
| 384 | } |
| 385 | return type_system; |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 386 | } |
| 387 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 388 | void SymbolFileDWARF::InitializeObject() { |
| Pavel Labath | 9337b41 | 2018-06-06 11:35:23 +0000 | [diff] [blame] | 389 | Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 390 | |
| Pavel Labath | 9337b41 | 2018-06-06 11:35:23 +0000 | [diff] [blame] | 391 | if (!GetGlobalPluginProperties()->IgnoreFileIndexes()) { |
| 392 | DWARFDataExtractor apple_names, apple_namespaces, apple_types, apple_objc; |
| 393 | LoadSectionData(eSectionTypeDWARFAppleNames, apple_names); |
| 394 | LoadSectionData(eSectionTypeDWARFAppleNamespaces, apple_namespaces); |
| 395 | LoadSectionData(eSectionTypeDWARFAppleTypes, apple_types); |
| 396 | LoadSectionData(eSectionTypeDWARFAppleObjC, apple_objc); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 397 | |
| Pavel Labath | 9337b41 | 2018-06-06 11:35:23 +0000 | [diff] [blame] | 398 | m_index = AppleDWARFIndex::Create( |
| 399 | *GetObjectFile()->GetModule(), apple_names, apple_namespaces, |
| Pavel Labath | 0261b94 | 2019-05-20 08:38:47 +0000 | [diff] [blame] | 400 | apple_types, apple_objc, m_context.getOrLoadStrData()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 401 | |
| Pavel Labath | 9337b41 | 2018-06-06 11:35:23 +0000 | [diff] [blame] | 402 | if (m_index) |
| 403 | return; |
| 404 | |
| 405 | DWARFDataExtractor debug_names; |
| 406 | LoadSectionData(eSectionTypeDWARFDebugNames, debug_names); |
| 407 | if (debug_names.GetByteSize() > 0) { |
| 408 | llvm::Expected<std::unique_ptr<DebugNamesDWARFIndex>> index_or = |
| Pavel Labath | 0261b94 | 2019-05-20 08:38:47 +0000 | [diff] [blame] | 409 | DebugNamesDWARFIndex::Create( |
| 410 | *GetObjectFile()->GetModule(), debug_names, |
| 411 | m_context.getOrLoadStrData(), DebugInfo()); |
| Pavel Labath | 9337b41 | 2018-06-06 11:35:23 +0000 | [diff] [blame] | 412 | if (index_or) { |
| 413 | m_index = std::move(*index_or); |
| 414 | return; |
| 415 | } |
| 416 | LLDB_LOG_ERROR(log, index_or.takeError(), |
| 417 | "Unable to read .debug_names data: {0}"); |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | m_index = llvm::make_unique<ManualDWARFIndex>(*GetObjectFile()->GetModule(), |
| 422 | DebugInfo()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | bool SymbolFileDWARF::SupportedVersion(uint16_t version) { |
| George Rimar | c6c7bfc | 2018-09-13 17:06:47 +0000 | [diff] [blame] | 426 | return version >= 2 && version <= 5; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | uint32_t SymbolFileDWARF::CalculateAbilities() { |
| 430 | uint32_t abilities = 0; |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 431 | if (m_obj_file != nullptr) { |
| 432 | const Section *section = nullptr; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 433 | const SectionList *section_list = m_obj_file->GetSectionList(); |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 434 | if (section_list == nullptr) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 435 | return 0; |
| 436 | |
| 437 | uint64_t debug_abbrev_file_size = 0; |
| 438 | uint64_t debug_info_file_size = 0; |
| 439 | uint64_t debug_line_file_size = 0; |
| 440 | |
| 441 | section = section_list->FindSectionByName(GetDWARFMachOSegmentName()).get(); |
| 442 | |
| 443 | if (section) |
| 444 | section_list = §ion->GetChildren(); |
| 445 | |
| 446 | section = |
| 447 | section_list->FindSectionByType(eSectionTypeDWARFDebugInfo, true).get(); |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 448 | if (section != nullptr) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 449 | debug_info_file_size = section->GetFileSize(); |
| 450 | |
| 451 | section = |
| 452 | section_list->FindSectionByType(eSectionTypeDWARFDebugAbbrev, true) |
| 453 | .get(); |
| 454 | if (section) |
| 455 | debug_abbrev_file_size = section->GetFileSize(); |
| 456 | |
| Jan Kratochvil | b14f1da | 2017-07-31 17:02:52 +0000 | [diff] [blame] | 457 | DWARFDebugAbbrev *abbrev = DebugAbbrev(); |
| 458 | if (abbrev) { |
| 459 | std::set<dw_form_t> invalid_forms; |
| 460 | abbrev->GetUnsupportedForms(invalid_forms); |
| 461 | if (!invalid_forms.empty()) { |
| 462 | StreamString error; |
| 463 | error.Printf("unsupported DW_FORM value%s:", invalid_forms.size() > 1 ? "s" : ""); |
| 464 | for (auto form : invalid_forms) |
| 465 | error.Printf(" %#x", form); |
| 466 | m_obj_file->GetModule()->ReportWarning("%s", error.GetString().str().c_str()); |
| 467 | return 0; |
| 468 | } |
| 469 | } |
| 470 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 471 | section = |
| 472 | section_list->FindSectionByType(eSectionTypeDWARFDebugLine, true) |
| 473 | .get(); |
| 474 | if (section) |
| 475 | debug_line_file_size = section->GetFileSize(); |
| 476 | } else { |
| 477 | const char *symfile_dir_cstr = |
| 478 | m_obj_file->GetFileSpec().GetDirectory().GetCString(); |
| 479 | if (symfile_dir_cstr) { |
| 480 | if (strcasestr(symfile_dir_cstr, ".dsym")) { |
| 481 | if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo) { |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 482 | // We have a dSYM file that didn't have a any debug info. If the |
| 483 | // string table has a size of 1, then it was made from an |
| 484 | // executable with no debug info, or from an executable that was |
| 485 | // stripped. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 486 | section = |
| 487 | section_list->FindSectionByType(eSectionTypeDWARFDebugStr, true) |
| 488 | .get(); |
| 489 | if (section && section->GetFileSize() == 1) { |
| 490 | m_obj_file->GetModule()->ReportWarning( |
| 491 | "empty dSYM file detected, dSYM was created with an " |
| 492 | "executable with no debug info."); |
| Tamas Berghammer | 90b4dce | 2015-10-22 11:14:37 +0000 | [diff] [blame] | 493 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 494 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 495 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 496 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 497 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 498 | |
| 499 | if (debug_abbrev_file_size > 0 && debug_info_file_size > 0) |
| 500 | abilities |= CompileUnits | Functions | Blocks | GlobalVariables | |
| 501 | LocalVariables | VariableTypes; |
| 502 | |
| 503 | if (debug_line_file_size > 0) |
| 504 | abilities |= LineTables; |
| 505 | } |
| 506 | return abilities; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 507 | } |
| 508 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 509 | const DWARFDataExtractor & |
| 510 | SymbolFileDWARF::GetCachedSectionData(lldb::SectionType sect_type, |
| 511 | DWARFDataSegment &data_segment) { |
| Kamil Rytarowski | c5f28e2 | 2017-02-06 17:55:02 +0000 | [diff] [blame] | 512 | llvm::call_once(data_segment.m_flag, [this, sect_type, &data_segment] { |
| 513 | this->LoadSectionData(sect_type, std::ref(data_segment.m_data)); |
| 514 | }); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 515 | return data_segment.m_data; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 516 | } |
| 517 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 518 | void SymbolFileDWARF::LoadSectionData(lldb::SectionType sect_type, |
| 519 | DWARFDataExtractor &data) { |
| 520 | ModuleSP module_sp(m_obj_file->GetModule()); |
| 521 | const SectionList *section_list = module_sp->GetSectionList(); |
| Zachary Turner | 6e66512 | 2019-03-20 20:49:25 +0000 | [diff] [blame] | 522 | if (!section_list) |
| 523 | return; |
| 524 | |
| 525 | SectionSP section_sp(section_list->FindSectionByType(sect_type, true)); |
| 526 | if (!section_sp) |
| 527 | return; |
| 528 | |
| 529 | data.Clear(); |
| 530 | m_obj_file->ReadSectionData(section_sp.get(), data); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 531 | } |
| 532 | |
| Pavel Labath | 4c2ef9a | 2019-03-22 16:07:58 +0000 | [diff] [blame] | 533 | const DWARFDataExtractor &SymbolFileDWARF::DebugLocData() { |
| 534 | const DWARFDataExtractor &debugLocData = get_debug_loc_data(); |
| 535 | if (debugLocData.GetByteSize() > 0) |
| 536 | return debugLocData; |
| 537 | return get_debug_loclists_data(); |
| 538 | } |
| 539 | |
| 540 | const DWARFDataExtractor &SymbolFileDWARF::get_debug_loc_data() { |
| 541 | return GetCachedSectionData(eSectionTypeDWARFDebugLoc, m_data_debug_loc); |
| 542 | } |
| 543 | |
| 544 | const DWARFDataExtractor &SymbolFileDWARF::get_debug_loclists_data() { |
| 545 | return GetCachedSectionData(eSectionTypeDWARFDebugLocLists, |
| 546 | m_data_debug_loclists); |
| 547 | } |
| 548 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 549 | DWARFDebugAbbrev *SymbolFileDWARF::DebugAbbrev() { |
| Zachary Turner | bb26a7e | 2019-03-14 19:05:55 +0000 | [diff] [blame] | 550 | if (m_abbr) |
| 551 | return m_abbr.get(); |
| 552 | |
| Pavel Labath | 0261b94 | 2019-05-20 08:38:47 +0000 | [diff] [blame] | 553 | const DWARFDataExtractor &debug_abbrev_data = m_context.getOrLoadAbbrevData(); |
| Zachary Turner | bb26a7e | 2019-03-14 19:05:55 +0000 | [diff] [blame] | 554 | if (debug_abbrev_data.GetByteSize() == 0) |
| 555 | return nullptr; |
| 556 | |
| 557 | auto abbr = llvm::make_unique<DWARFDebugAbbrev>(); |
| 558 | llvm::Error error = abbr->parse(debug_abbrev_data); |
| 559 | if (error) { |
| 560 | Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO); |
| 561 | LLDB_LOG_ERROR(log, std::move(error), |
| 562 | "Unable to read .debug_abbrev section: {0}"); |
| 563 | return nullptr; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 564 | } |
| Zachary Turner | bb26a7e | 2019-03-14 19:05:55 +0000 | [diff] [blame] | 565 | |
| 566 | m_abbr = std::move(abbr); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 567 | return m_abbr.get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 568 | } |
| 569 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 570 | const DWARFDebugAbbrev *SymbolFileDWARF::DebugAbbrev() const { |
| 571 | return m_abbr.get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 572 | } |
| 573 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 574 | DWARFDebugInfo *SymbolFileDWARF::DebugInfo() { |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 575 | if (m_info == nullptr) { |
| Pavel Labath | f9d1647 | 2017-05-15 13:02:37 +0000 | [diff] [blame] | 576 | static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); |
| 577 | Timer scoped_timer(func_cat, "%s this = %p", LLVM_PRETTY_FUNCTION, |
| 578 | static_cast<void *>(this)); |
| Pavel Labath | 6a2eb36 | 2019-06-14 13:01:16 +0000 | [diff] [blame] | 579 | if (m_context.getOrLoadDebugInfoData().GetByteSize() > 0) |
| 580 | m_info = llvm::make_unique<DWARFDebugInfo>(*this, m_context); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 581 | } |
| 582 | return m_info.get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 583 | } |
| 584 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 585 | const DWARFDebugInfo *SymbolFileDWARF::DebugInfo() const { |
| 586 | return m_info.get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 587 | } |
| 588 | |
| Jan Kratochvil | c4d6575 | 2018-03-18 20:11:02 +0000 | [diff] [blame] | 589 | DWARFUnit * |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 590 | SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit) { |
| 591 | if (!comp_unit) |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 592 | return nullptr; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 593 | |
| Alex Langford | 5ada887 | 2019-06-08 00:55:03 +0000 | [diff] [blame] | 594 | DWARFDebugInfo *info = DebugInfo(); |
| 595 | if (info) { |
| 596 | // The compile unit ID is the index of the DWARF unit. |
| 597 | DWARFUnit *dwarf_cu = info->GetUnitAtIndex(comp_unit->GetID()); |
| 598 | if (dwarf_cu && dwarf_cu->GetUserData() == nullptr) |
| 599 | dwarf_cu->SetUserData(comp_unit); |
| 600 | return dwarf_cu; |
| 601 | } |
| 602 | return nullptr; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 603 | } |
| 604 | |
| Pavel Labath | 78cfe1e | 2019-05-29 09:22:36 +0000 | [diff] [blame] | 605 | DWARFDebugRangesBase *SymbolFileDWARF::GetDebugRanges() { |
| 606 | if (!m_ranges) { |
| Pavel Labath | f9d1647 | 2017-05-15 13:02:37 +0000 | [diff] [blame] | 607 | static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); |
| 608 | Timer scoped_timer(func_cat, "%s this = %p", LLVM_PRETTY_FUNCTION, |
| 609 | static_cast<void *>(this)); |
| George Rimar | 6e35712 | 2018-10-10 08:11:15 +0000 | [diff] [blame] | 610 | |
| Pavel Labath | 00e3968 | 2019-06-14 14:12:25 +0000 | [diff] [blame] | 611 | if (m_context.getOrLoadRangesData().GetByteSize() > 0) |
| Pavel Labath | 4c2ef9a | 2019-03-22 16:07:58 +0000 | [diff] [blame] | 612 | m_ranges.reset(new DWARFDebugRanges()); |
| George Rimar | 6e35712 | 2018-10-10 08:11:15 +0000 | [diff] [blame] | 613 | |
| Jonas Devlieghere | 70355ac | 2019-02-12 03:47:39 +0000 | [diff] [blame] | 614 | if (m_ranges) |
| Pavel Labath | 00e3968 | 2019-06-14 14:12:25 +0000 | [diff] [blame] | 615 | m_ranges->Extract(m_context); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 616 | } |
| 617 | return m_ranges.get(); |
| 618 | } |
| 619 | |
| Pavel Labath | 78cfe1e | 2019-05-29 09:22:36 +0000 | [diff] [blame] | 620 | DWARFDebugRangesBase *SymbolFileDWARF::GetDebugRngLists() { |
| 621 | if (!m_rnglists) { |
| 622 | static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); |
| 623 | Timer scoped_timer(func_cat, "%s this = %p", LLVM_PRETTY_FUNCTION, |
| 624 | static_cast<void *>(this)); |
| 625 | |
| Pavel Labath | 00e3968 | 2019-06-14 14:12:25 +0000 | [diff] [blame] | 626 | if (m_context.getOrLoadRngListsData().GetByteSize() > 0) |
| Pavel Labath | 78cfe1e | 2019-05-29 09:22:36 +0000 | [diff] [blame] | 627 | m_rnglists.reset(new DWARFDebugRngLists()); |
| 628 | |
| 629 | if (m_rnglists) |
| Pavel Labath | 00e3968 | 2019-06-14 14:12:25 +0000 | [diff] [blame] | 630 | m_rnglists->Extract(m_context); |
| Pavel Labath | 78cfe1e | 2019-05-29 09:22:36 +0000 | [diff] [blame] | 631 | } |
| 632 | return m_rnglists.get(); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 633 | } |
| 634 | |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 635 | lldb::CompUnitSP SymbolFileDWARF::ParseCompileUnit(DWARFCompileUnit &dwarf_cu) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 636 | CompUnitSP cu_sp; |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 637 | CompileUnit *comp_unit = (CompileUnit *)dwarf_cu.GetUserData(); |
| 638 | if (comp_unit) { |
| 639 | // We already parsed this compile unit, had out a shared pointer to it |
| 640 | cu_sp = comp_unit->shared_from_this(); |
| 641 | } else { |
| Pavel Labath | 6a2eb36 | 2019-06-14 13:01:16 +0000 | [diff] [blame] | 642 | if (&dwarf_cu.GetSymbolFileDWARF() != this) { |
| 643 | return dwarf_cu.GetSymbolFileDWARF().ParseCompileUnit(dwarf_cu); |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 644 | } else if (dwarf_cu.GetOffset() == 0 && GetDebugMapSymfile()) { |
| 645 | // Let the debug map create the compile unit |
| 646 | cu_sp = m_debug_map_symfile->GetCompileUnit(this); |
| 647 | dwarf_cu.SetUserData(cu_sp.get()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 648 | } else { |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 649 | ModuleSP module_sp(m_obj_file->GetModule()); |
| 650 | if (module_sp) { |
| 651 | const DWARFDIE cu_die = dwarf_cu.DIE(); |
| 652 | if (cu_die) { |
| 653 | FileSpec cu_file_spec(cu_die.GetName(), dwarf_cu.GetPathStyle()); |
| 654 | if (cu_file_spec) { |
| 655 | // If we have a full path to the compile unit, we don't need to |
| 656 | // resolve the file. This can be expensive e.g. when the source |
| 657 | // files are NFS mounted. |
| 658 | cu_file_spec.MakeAbsolute(dwarf_cu.GetCompilationDirectory()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 659 | |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 660 | std::string remapped_file; |
| 661 | if (module_sp->RemapSourceFile(cu_file_spec.GetPath(), |
| 662 | remapped_file)) |
| 663 | cu_file_spec.SetFile(remapped_file, FileSpec::Style::native); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 664 | } |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 665 | |
| 666 | LanguageType cu_language = DWARFUnit::LanguageTypeFromDWARF( |
| 667 | cu_die.GetAttributeValueAsUnsigned(DW_AT_language, 0)); |
| 668 | |
| 669 | bool is_optimized = dwarf_cu.GetIsOptimized(); |
| 670 | BuildCuTranslationTable(); |
| 671 | cu_sp = std::make_shared<CompileUnit>( |
| 672 | module_sp, &dwarf_cu, cu_file_spec, |
| 673 | *GetDWARFUnitIndex(dwarf_cu.GetID()), cu_language, |
| 674 | is_optimized ? eLazyBoolYes : eLazyBoolNo); |
| 675 | |
| 676 | dwarf_cu.SetUserData(cu_sp.get()); |
| 677 | |
| Pavel Labath | e011990 | 2019-07-23 09:24:02 +0000 | [diff] [blame] | 678 | SetCompileUnitAtIndex(dwarf_cu.GetID(), cu_sp); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 679 | } |
| 680 | } |
| 681 | } |
| 682 | } |
| 683 | return cu_sp; |
| 684 | } |
| 685 | |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 686 | void SymbolFileDWARF::BuildCuTranslationTable() { |
| 687 | if (!m_lldb_cu_to_dwarf_unit.empty()) |
| 688 | return; |
| 689 | |
| 690 | DWARFDebugInfo *info = DebugInfo(); |
| 691 | if (!info) |
| 692 | return; |
| 693 | |
| 694 | if (!info->ContainsTypeUnits()) { |
| 695 | // We can use a 1-to-1 mapping. No need to build a translation table. |
| 696 | return; |
| 697 | } |
| 698 | for (uint32_t i = 0, num = info->GetNumUnits(); i < num; ++i) { |
| 699 | if (auto *cu = llvm::dyn_cast<DWARFCompileUnit>(info->GetUnitAtIndex(i))) { |
| 700 | cu->SetID(m_lldb_cu_to_dwarf_unit.size()); |
| 701 | m_lldb_cu_to_dwarf_unit.push_back(i); |
| 702 | } |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | llvm::Optional<uint32_t> SymbolFileDWARF::GetDWARFUnitIndex(uint32_t cu_idx) { |
| 707 | BuildCuTranslationTable(); |
| 708 | if (m_lldb_cu_to_dwarf_unit.empty()) |
| 709 | return cu_idx; |
| 710 | if (cu_idx >= m_lldb_cu_to_dwarf_unit.size()) |
| 711 | return llvm::None; |
| 712 | return m_lldb_cu_to_dwarf_unit[cu_idx]; |
| 713 | } |
| 714 | |
| Pavel Labath | e011990 | 2019-07-23 09:24:02 +0000 | [diff] [blame] | 715 | uint32_t SymbolFileDWARF::CalculateNumCompileUnits() { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 716 | DWARFDebugInfo *info = DebugInfo(); |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 717 | if (!info) |
| 718 | return 0; |
| 719 | BuildCuTranslationTable(); |
| 720 | return m_lldb_cu_to_dwarf_unit.empty() ? info->GetNumUnits() |
| 721 | : m_lldb_cu_to_dwarf_unit.size(); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | CompUnitSP SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx) { |
| Jonas Devlieghere | 4f78c4f | 2018-10-22 20:14:36 +0000 | [diff] [blame] | 725 | ASSERT_MODULE_LOCK(this); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 726 | DWARFDebugInfo *info = DebugInfo(); |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 727 | if (!info) |
| 728 | return {}; |
| 729 | |
| 730 | if (llvm::Optional<uint32_t> dwarf_idx = GetDWARFUnitIndex(cu_idx)) { |
| 731 | if (auto *dwarf_cu = llvm::cast_or_null<DWARFCompileUnit>( |
| 732 | info->GetUnitAtIndex(*dwarf_idx))) |
| 733 | return ParseCompileUnit(*dwarf_cu); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 734 | } |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 735 | return {}; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 736 | } |
| 737 | |
| Zachary Turner | 863f8c1 | 2019-01-11 18:03:20 +0000 | [diff] [blame] | 738 | Function *SymbolFileDWARF::ParseFunction(CompileUnit &comp_unit, |
| 739 | const DWARFDIE &die) { |
| Jonas Devlieghere | 4f78c4f | 2018-10-22 20:14:36 +0000 | [diff] [blame] | 740 | ASSERT_MODULE_LOCK(this); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 741 | if (die.IsValid()) { |
| 742 | TypeSystem *type_system = |
| 743 | GetTypeSystemForLanguage(die.GetCU()->GetLanguageType()); |
| 744 | |
| 745 | if (type_system) { |
| 746 | DWARFASTParser *dwarf_ast = type_system->GetDWARFParser(); |
| 747 | if (dwarf_ast) |
| Zachary Turner | 863f8c1 | 2019-01-11 18:03:20 +0000 | [diff] [blame] | 748 | return dwarf_ast->ParseFunctionFromDWARF(comp_unit, die); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 749 | } |
| 750 | } |
| 751 | return nullptr; |
| 752 | } |
| 753 | |
| 754 | bool SymbolFileDWARF::FixupAddress(Address &addr) { |
| 755 | SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile(); |
| 756 | if (debug_map_symfile) { |
| 757 | return debug_map_symfile->LinkOSOAddress(addr); |
| 758 | } |
| 759 | // This is a normal DWARF file, no address fixups need to happen |
| 760 | return true; |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 761 | } |
| Zachary Turner | 863f8c1 | 2019-01-11 18:03:20 +0000 | [diff] [blame] | 762 | lldb::LanguageType SymbolFileDWARF::ParseLanguage(CompileUnit &comp_unit) { |
| Jonas Devlieghere | 4f78c4f | 2018-10-22 20:14:36 +0000 | [diff] [blame] | 763 | ASSERT_MODULE_LOCK(this); |
| Zachary Turner | 863f8c1 | 2019-01-11 18:03:20 +0000 | [diff] [blame] | 764 | DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 765 | if (dwarf_cu) |
| 766 | return dwarf_cu->GetLanguageType(); |
| 767 | else |
| 768 | return eLanguageTypeUnknown; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 769 | } |
| 770 | |
| Zachary Turner | 863f8c1 | 2019-01-11 18:03:20 +0000 | [diff] [blame] | 771 | size_t SymbolFileDWARF::ParseFunctions(CompileUnit &comp_unit) { |
| Jonas Devlieghere | 4f78c4f | 2018-10-22 20:14:36 +0000 | [diff] [blame] | 772 | ASSERT_MODULE_LOCK(this); |
| Zachary Turner | 863f8c1 | 2019-01-11 18:03:20 +0000 | [diff] [blame] | 773 | DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); |
| Zachary Turner | 0eaa6d5 | 2019-03-12 20:50:46 +0000 | [diff] [blame] | 774 | if (!dwarf_cu) |
| 775 | return 0; |
| 776 | |
| 777 | size_t functions_added = 0; |
| 778 | std::vector<DWARFDIE> function_dies; |
| 779 | dwarf_cu->AppendDIEsWithTag(DW_TAG_subprogram, function_dies); |
| 780 | for (const DWARFDIE &die : function_dies) { |
| 781 | if (comp_unit.FindFunctionByUID(die.GetID())) |
| 782 | continue; |
| 783 | if (ParseFunction(comp_unit, die)) |
| 784 | ++functions_added; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 785 | } |
| Zachary Turner | 0eaa6d5 | 2019-03-12 20:50:46 +0000 | [diff] [blame] | 786 | // FixupTypes(); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 787 | return functions_added; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 788 | } |
| 789 | |
| Zachary Turner | 863f8c1 | 2019-01-11 18:03:20 +0000 | [diff] [blame] | 790 | bool SymbolFileDWARF::ParseSupportFiles(CompileUnit &comp_unit, |
| 791 | FileSpecList &support_files) { |
| Jonas Devlieghere | 4f78c4f | 2018-10-22 20:14:36 +0000 | [diff] [blame] | 792 | ASSERT_MODULE_LOCK(this); |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 793 | if (DWARFUnit *unit = GetDWARFCompileUnit(&comp_unit)) { |
| Pavel Labath | ca9c3de | 2019-06-12 11:29:50 +0000 | [diff] [blame] | 794 | const dw_offset_t stmt_list = unit->GetLineTableOffset(); |
| 795 | if (stmt_list != DW_INVALID_OFFSET) { |
| 796 | // All file indexes in DWARF are one based and a file of index zero is |
| 797 | // supposed to be the compile unit itself. |
| 798 | support_files.Append(comp_unit); |
| 799 | return DWARFDebugLine::ParseSupportFiles(comp_unit.GetModule(), |
| 800 | m_context.getOrLoadLineData(), |
| 801 | stmt_list, support_files, unit); |
| Pavel Labath | 4c2ef9a | 2019-03-22 16:07:58 +0000 | [diff] [blame] | 802 | } |
| 803 | } |
| 804 | return false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 805 | } |
| 806 | |
| Pavel Labath | ca9c3de | 2019-06-12 11:29:50 +0000 | [diff] [blame] | 807 | FileSpec SymbolFileDWARF::GetFile(DWARFUnit &unit, size_t file_idx) { |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 808 | if (auto *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(&unit)) { |
| 809 | if (CompileUnit *lldb_cu = GetCompUnitForDWARFCompUnit(*dwarf_cu)) |
| 810 | return lldb_cu->GetSupportFiles().GetFileSpecAtIndex(file_idx); |
| 811 | return FileSpec(); |
| 812 | } |
| 813 | |
| 814 | auto &tu = llvm::cast<DWARFTypeUnit>(unit); |
| 815 | return GetTypeUnitSupportFiles(tu).GetFileSpecAtIndex(file_idx); |
| Pavel Labath | ca9c3de | 2019-06-12 11:29:50 +0000 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | const FileSpecList & |
| 819 | SymbolFileDWARF::GetTypeUnitSupportFiles(DWARFTypeUnit &tu) { |
| 820 | static FileSpecList empty_list; |
| 821 | |
| 822 | dw_offset_t offset = tu.GetLineTableOffset(); |
| 823 | if (offset == DW_INVALID_OFFSET || |
| 824 | offset == llvm::DenseMapInfo<dw_offset_t>::getEmptyKey() || |
| 825 | offset == llvm::DenseMapInfo<dw_offset_t>::getTombstoneKey()) |
| 826 | return empty_list; |
| 827 | |
| 828 | // Many type units can share a line table, so parse the support file list |
| 829 | // once, and cache it based on the offset field. |
| 830 | auto iter_bool = m_type_unit_support_files.try_emplace(offset); |
| 831 | FileSpecList &list = iter_bool.first->second; |
| 832 | if (iter_bool.second) { |
| Jonas Devlieghere | f893d5b | 2019-07-18 20:19:24 +0000 | [diff] [blame] | 833 | list.EmplaceBack(); |
| Pavel Labath | ca9c3de | 2019-06-12 11:29:50 +0000 | [diff] [blame] | 834 | DWARFDebugLine::ParseSupportFiles(GetObjectFile()->GetModule(), |
| 835 | m_context.getOrLoadLineData(), offset, |
| 836 | list, &tu); |
| 837 | } |
| 838 | return list; |
| 839 | } |
| 840 | |
| Zachary Turner | 863f8c1 | 2019-01-11 18:03:20 +0000 | [diff] [blame] | 841 | bool SymbolFileDWARF::ParseIsOptimized(CompileUnit &comp_unit) { |
| Jonas Devlieghere | 4f78c4f | 2018-10-22 20:14:36 +0000 | [diff] [blame] | 842 | ASSERT_MODULE_LOCK(this); |
| Zachary Turner | 863f8c1 | 2019-01-11 18:03:20 +0000 | [diff] [blame] | 843 | DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 844 | if (dwarf_cu) |
| 845 | return dwarf_cu->GetIsOptimized(); |
| 846 | return false; |
| Greg Clayton | ad2b63c | 2016-07-05 23:01:20 +0000 | [diff] [blame] | 847 | } |
| 848 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 849 | bool SymbolFileDWARF::ParseImportedModules( |
| 850 | const lldb_private::SymbolContext &sc, |
| Adrian Prantl | 0f30a3b | 2019-02-13 18:10:41 +0000 | [diff] [blame] | 851 | std::vector<SourceModule> &imported_modules) { |
| Jonas Devlieghere | 4f78c4f | 2018-10-22 20:14:36 +0000 | [diff] [blame] | 852 | ASSERT_MODULE_LOCK(this); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 853 | assert(sc.comp_unit); |
| Jan Kratochvil | c4d6575 | 2018-03-18 20:11:02 +0000 | [diff] [blame] | 854 | DWARFUnit *dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Adrian Prantl | 0f30a3b | 2019-02-13 18:10:41 +0000 | [diff] [blame] | 855 | if (!dwarf_cu) |
| 856 | return false; |
| 857 | if (!ClangModulesDeclVendor::LanguageSupportsClangModules( |
| 858 | sc.comp_unit->GetLanguage())) |
| 859 | return false; |
| 860 | UpdateExternalModuleListIfNeeded(); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 861 | |
| Adrian Prantl | 0f30a3b | 2019-02-13 18:10:41 +0000 | [diff] [blame] | 862 | const DWARFDIE die = dwarf_cu->DIE(); |
| 863 | if (!die) |
| 864 | return false; |
| 865 | |
| 866 | for (DWARFDIE child_die = die.GetFirstChild(); child_die; |
| 867 | child_die = child_die.GetSibling()) { |
| 868 | if (child_die.Tag() != DW_TAG_imported_declaration) |
| 869 | continue; |
| 870 | |
| 871 | DWARFDIE module_die = child_die.GetReferencedDIE(DW_AT_import); |
| 872 | if (module_die.Tag() != DW_TAG_module) |
| 873 | continue; |
| 874 | |
| 875 | if (const char *name = |
| 876 | module_die.GetAttributeValueAsString(DW_AT_name, nullptr)) { |
| 877 | SourceModule module; |
| 878 | module.path.push_back(ConstString(name)); |
| 879 | |
| 880 | DWARFDIE parent_die = module_die; |
| 881 | while ((parent_die = parent_die.GetParent())) { |
| 882 | if (parent_die.Tag() != DW_TAG_module) |
| 883 | break; |
| 884 | if (const char *name = |
| 885 | parent_die.GetAttributeValueAsString(DW_AT_name, nullptr)) |
| 886 | module.path.push_back(ConstString(name)); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 887 | } |
| Adrian Prantl | 0f30a3b | 2019-02-13 18:10:41 +0000 | [diff] [blame] | 888 | std::reverse(module.path.begin(), module.path.end()); |
| 889 | if (const char *include_path = module_die.GetAttributeValueAsString( |
| 890 | DW_AT_LLVM_include_path, nullptr)) |
| 891 | module.search_path = ConstString(include_path); |
| 892 | if (const char *sysroot = module_die.GetAttributeValueAsString( |
| 893 | DW_AT_LLVM_isysroot, nullptr)) |
| 894 | module.sysroot = ConstString(sysroot); |
| 895 | imported_modules.push_back(module); |
| Sean Callanan | f0c5aeb | 2015-04-20 16:31:29 +0000 | [diff] [blame] | 896 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 897 | } |
| Adrian Prantl | 0f30a3b | 2019-02-13 18:10:41 +0000 | [diff] [blame] | 898 | return true; |
| Sean Callanan | f0c5aeb | 2015-04-20 16:31:29 +0000 | [diff] [blame] | 899 | } |
| 900 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 901 | struct ParseDWARFLineTableCallbackInfo { |
| 902 | LineTable *line_table; |
| Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 903 | std::unique_ptr<LineSequence> sequence_up; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 904 | lldb::addr_t addr_mask; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 905 | }; |
| 906 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 907 | // ParseStatementTableCallback |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 908 | static void ParseDWARFLineTableCallback(dw_offset_t offset, |
| 909 | const DWARFDebugLine::State &state, |
| 910 | void *userData) { |
| 911 | if (state.row == DWARFDebugLine::State::StartParsingLineTable) { |
| 912 | // Just started parsing the line table |
| 913 | } else if (state.row == DWARFDebugLine::State::DoneParsingLineTable) { |
| 914 | // Done parsing line table, nothing to do for the cleanup |
| 915 | } else { |
| 916 | ParseDWARFLineTableCallbackInfo *info = |
| 917 | (ParseDWARFLineTableCallbackInfo *)userData; |
| 918 | LineTable *line_table = info->line_table; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 919 | |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 920 | // If this is our first time here, we need to create a sequence container. |
| Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 921 | if (!info->sequence_up) { |
| 922 | info->sequence_up.reset(line_table->CreateLineSequenceContainer()); |
| 923 | assert(info->sequence_up.get()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 924 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 925 | line_table->AppendLineEntryToSequence( |
| Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 926 | info->sequence_up.get(), state.address & info->addr_mask, state.line, |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 927 | state.column, state.file, state.is_stmt, state.basic_block, |
| 928 | state.prologue_end, state.epilogue_begin, state.end_sequence); |
| 929 | if (state.end_sequence) { |
| 930 | // First, put the current sequence into the line table. |
| Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 931 | line_table->InsertSequence(info->sequence_up.get()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 932 | // Then, empty it to prepare for the next sequence. |
| Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 933 | info->sequence_up->Clear(); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 934 | } |
| 935 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 936 | } |
| 937 | |
| Zachary Turner | 863f8c1 | 2019-01-11 18:03:20 +0000 | [diff] [blame] | 938 | bool SymbolFileDWARF::ParseLineTable(CompileUnit &comp_unit) { |
| Jonas Devlieghere | 4f78c4f | 2018-10-22 20:14:36 +0000 | [diff] [blame] | 939 | ASSERT_MODULE_LOCK(this); |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 940 | if (comp_unit.GetLineTable() != nullptr) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 941 | return true; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 942 | |
| Zachary Turner | 863f8c1 | 2019-01-11 18:03:20 +0000 | [diff] [blame] | 943 | DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); |
| Pavel Labath | 4c2ef9a | 2019-03-22 16:07:58 +0000 | [diff] [blame] | 944 | if (dwarf_cu) { |
| 945 | const DWARFBaseDIE dwarf_cu_die = dwarf_cu->GetUnitDIEOnly(); |
| 946 | if (dwarf_cu_die) { |
| 947 | const dw_offset_t cu_line_offset = |
| 948 | dwarf_cu_die.GetAttributeValueAsUnsigned(DW_AT_stmt_list, |
| 949 | DW_INVALID_OFFSET); |
| 950 | if (cu_line_offset != DW_INVALID_OFFSET) { |
| 951 | std::unique_ptr<LineTable> line_table_up(new LineTable(&comp_unit)); |
| 952 | if (line_table_up) { |
| 953 | ParseDWARFLineTableCallbackInfo info; |
| 954 | info.line_table = line_table_up.get(); |
| Jaydeep Patil | 44d07fc | 2015-09-22 06:36:56 +0000 | [diff] [blame] | 955 | |
| Pavel Labath | 4c2ef9a | 2019-03-22 16:07:58 +0000 | [diff] [blame] | 956 | /* |
| 957 | * MIPS: |
| 958 | * The SymbolContext may not have a valid target, thus we may not be |
| 959 | * able |
| 960 | * to call Address::GetOpcodeLoadAddress() which would clear the bit |
| 961 | * #0 |
| 962 | * for MIPS. Use ArchSpec to clear the bit #0. |
| 963 | */ |
| 964 | switch (GetObjectFile()->GetArchitecture().GetMachine()) { |
| 965 | case llvm::Triple::mips: |
| 966 | case llvm::Triple::mipsel: |
| 967 | case llvm::Triple::mips64: |
| 968 | case llvm::Triple::mips64el: |
| 969 | info.addr_mask = ~((lldb::addr_t)1); |
| 970 | break; |
| 971 | default: |
| 972 | info.addr_mask = ~((lldb::addr_t)0); |
| 973 | break; |
| 974 | } |
| Jaydeep Patil | 44d07fc | 2015-09-22 06:36:56 +0000 | [diff] [blame] | 975 | |
| Pavel Labath | 4c2ef9a | 2019-03-22 16:07:58 +0000 | [diff] [blame] | 976 | lldb::offset_t offset = cu_line_offset; |
| Pavel Labath | 0261b94 | 2019-05-20 08:38:47 +0000 | [diff] [blame] | 977 | DWARFDebugLine::ParseStatementTable( |
| 978 | m_context.getOrLoadLineData(), &offset, |
| 979 | ParseDWARFLineTableCallback, &info, dwarf_cu); |
| Pavel Labath | 4c2ef9a | 2019-03-22 16:07:58 +0000 | [diff] [blame] | 980 | SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile(); |
| 981 | if (debug_map_symfile) { |
| 982 | // We have an object file that has a line table with addresses that |
| 983 | // are not linked. We need to link the line table and convert the |
| 984 | // addresses that are relative to the .o file into addresses for |
| 985 | // the main executable. |
| 986 | comp_unit.SetLineTable( |
| 987 | debug_map_symfile->LinkOSOLineTable(this, line_table_up.get())); |
| 988 | } else { |
| 989 | comp_unit.SetLineTable(line_table_up.release()); |
| 990 | return true; |
| 991 | } |
| 992 | } |
| 993 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 994 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 995 | } |
| 996 | return false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 997 | } |
| 998 | |
| Siva Chandra | d8335e9 | 2015-12-16 00:22:08 +0000 | [diff] [blame] | 999 | lldb_private::DebugMacrosSP |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1000 | SymbolFileDWARF::ParseDebugMacros(lldb::offset_t *offset) { |
| 1001 | auto iter = m_debug_macros_map.find(*offset); |
| 1002 | if (iter != m_debug_macros_map.end()) |
| 1003 | return iter->second; |
| Siva Chandra | d8335e9 | 2015-12-16 00:22:08 +0000 | [diff] [blame] | 1004 | |
| Pavel Labath | 0261b94 | 2019-05-20 08:38:47 +0000 | [diff] [blame] | 1005 | const DWARFDataExtractor &debug_macro_data = m_context.getOrLoadMacroData(); |
| Pavel Labath | 4c2ef9a | 2019-03-22 16:07:58 +0000 | [diff] [blame] | 1006 | if (debug_macro_data.GetByteSize() == 0) |
| 1007 | return DebugMacrosSP(); |
| Siva Chandra | d8335e9 | 2015-12-16 00:22:08 +0000 | [diff] [blame] | 1008 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1009 | lldb_private::DebugMacrosSP debug_macros_sp(new lldb_private::DebugMacros()); |
| 1010 | m_debug_macros_map[*offset] = debug_macros_sp; |
| Siva Chandra | d8335e9 | 2015-12-16 00:22:08 +0000 | [diff] [blame] | 1011 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1012 | const DWARFDebugMacroHeader &header = |
| Pavel Labath | 4c2ef9a | 2019-03-22 16:07:58 +0000 | [diff] [blame] | 1013 | DWARFDebugMacroHeader::ParseHeader(debug_macro_data, offset); |
| Pavel Labath | 0261b94 | 2019-05-20 08:38:47 +0000 | [diff] [blame] | 1014 | DWARFDebugMacroEntry::ReadMacroEntries( |
| 1015 | debug_macro_data, m_context.getOrLoadStrData(), header.OffsetIs64Bit(), |
| 1016 | offset, this, debug_macros_sp); |
| Siva Chandra | d8335e9 | 2015-12-16 00:22:08 +0000 | [diff] [blame] | 1017 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1018 | return debug_macros_sp; |
| Siva Chandra | d8335e9 | 2015-12-16 00:22:08 +0000 | [diff] [blame] | 1019 | } |
| 1020 | |
| Zachary Turner | 863f8c1 | 2019-01-11 18:03:20 +0000 | [diff] [blame] | 1021 | bool SymbolFileDWARF::ParseDebugMacros(CompileUnit &comp_unit) { |
| Jonas Devlieghere | 4f78c4f | 2018-10-22 20:14:36 +0000 | [diff] [blame] | 1022 | ASSERT_MODULE_LOCK(this); |
| Siva Chandra | d8335e9 | 2015-12-16 00:22:08 +0000 | [diff] [blame] | 1023 | |
| Zachary Turner | 863f8c1 | 2019-01-11 18:03:20 +0000 | [diff] [blame] | 1024 | DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1025 | if (dwarf_cu == nullptr) |
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1026 | return false; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1027 | |
| Jan Kratochvil | 93afb05 | 2018-05-24 20:51:13 +0000 | [diff] [blame] | 1028 | const DWARFBaseDIE dwarf_cu_die = dwarf_cu->GetUnitDIEOnly(); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1029 | if (!dwarf_cu_die) |
| 1030 | return false; |
| 1031 | |
| 1032 | lldb::offset_t sect_offset = |
| 1033 | dwarf_cu_die.GetAttributeValueAsUnsigned(DW_AT_macros, DW_INVALID_OFFSET); |
| 1034 | if (sect_offset == DW_INVALID_OFFSET) |
| 1035 | sect_offset = dwarf_cu_die.GetAttributeValueAsUnsigned(DW_AT_GNU_macros, |
| 1036 | DW_INVALID_OFFSET); |
| 1037 | if (sect_offset == DW_INVALID_OFFSET) |
| 1038 | return false; |
| 1039 | |
| Zachary Turner | 863f8c1 | 2019-01-11 18:03:20 +0000 | [diff] [blame] | 1040 | comp_unit.SetDebugMacros(ParseDebugMacros(§_offset)); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1041 | |
| 1042 | return true; |
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1043 | } |
| 1044 | |
| Zachary Turner | ffc1b8f | 2019-01-14 22:40:41 +0000 | [diff] [blame] | 1045 | size_t SymbolFileDWARF::ParseBlocksRecursive( |
| 1046 | lldb_private::CompileUnit &comp_unit, Block *parent_block, |
| 1047 | const DWARFDIE &orig_die, addr_t subprogram_low_pc, uint32_t depth) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1048 | size_t blocks_added = 0; |
| 1049 | DWARFDIE die = orig_die; |
| 1050 | while (die) { |
| 1051 | dw_tag_t tag = die.Tag(); |
| Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 1052 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1053 | switch (tag) { |
| 1054 | case DW_TAG_inlined_subroutine: |
| 1055 | case DW_TAG_subprogram: |
| 1056 | case DW_TAG_lexical_block: { |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 1057 | Block *block = nullptr; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1058 | if (tag == DW_TAG_subprogram) { |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1059 | // Skip any DW_TAG_subprogram DIEs that are inside of a normal or |
| 1060 | // inlined functions. These will be parsed on their own as separate |
| 1061 | // entities. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1062 | |
| 1063 | if (depth > 0) |
| 1064 | break; |
| 1065 | |
| 1066 | block = parent_block; |
| 1067 | } else { |
| 1068 | BlockSP block_sp(new Block(die.GetID())); |
| 1069 | parent_block->AddChild(block_sp); |
| 1070 | block = block_sp.get(); |
| 1071 | } |
| 1072 | DWARFRangeList ranges; |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 1073 | const char *name = nullptr; |
| 1074 | const char *mangled_name = nullptr; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1075 | |
| 1076 | int decl_file = 0; |
| 1077 | int decl_line = 0; |
| 1078 | int decl_column = 0; |
| 1079 | int call_file = 0; |
| 1080 | int call_line = 0; |
| 1081 | int call_column = 0; |
| 1082 | if (die.GetDIENamesAndRanges(name, mangled_name, ranges, decl_file, |
| 1083 | decl_line, decl_column, call_file, call_line, |
| 1084 | call_column, nullptr)) { |
| 1085 | if (tag == DW_TAG_subprogram) { |
| 1086 | assert(subprogram_low_pc == LLDB_INVALID_ADDRESS); |
| 1087 | subprogram_low_pc = ranges.GetMinRangeBase(0); |
| 1088 | } else if (tag == DW_TAG_inlined_subroutine) { |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1089 | // We get called here for inlined subroutines in two ways. The first |
| 1090 | // time is when we are making the Function object for this inlined |
| 1091 | // concrete instance. Since we're creating a top level block at |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1092 | // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1093 | // need to adjust the containing address. The second time is when we |
| 1094 | // are parsing the blocks inside the function that contains the |
| 1095 | // inlined concrete instance. Since these will be blocks inside the |
| 1096 | // containing "real" function the offset will be for that function. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1097 | if (subprogram_low_pc == LLDB_INVALID_ADDRESS) { |
| 1098 | subprogram_low_pc = ranges.GetMinRangeBase(0); |
| 1099 | } |
| 1100 | } |
| 1101 | |
| 1102 | const size_t num_ranges = ranges.GetSize(); |
| 1103 | for (size_t i = 0; i < num_ranges; ++i) { |
| 1104 | const DWARFRangeList::Entry &range = ranges.GetEntryRef(i); |
| 1105 | const addr_t range_base = range.GetRangeBase(); |
| 1106 | if (range_base >= subprogram_low_pc) |
| 1107 | block->AddRange(Block::Range(range_base - subprogram_low_pc, |
| 1108 | range.GetByteSize())); |
| 1109 | else { |
| 1110 | GetObjectFile()->GetModule()->ReportError( |
| 1111 | "0x%8.8" PRIx64 ": adding range [0x%" PRIx64 "-0x%" PRIx64 |
| 1112 | ") which has a base that is less than the function's low PC " |
| 1113 | "0x%" PRIx64 ". Please file a bug and attach the file at the " |
| 1114 | "start of this error message", |
| 1115 | block->GetID(), range_base, range.GetRangeEnd(), |
| 1116 | subprogram_low_pc); |
| 1117 | } |
| 1118 | } |
| 1119 | block->FinalizeRanges(); |
| 1120 | |
| 1121 | if (tag != DW_TAG_subprogram && |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 1122 | (name != nullptr || mangled_name != nullptr)) { |
| Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 1123 | std::unique_ptr<Declaration> decl_up; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1124 | if (decl_file != 0 || decl_line != 0 || decl_column != 0) |
| Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 1125 | decl_up.reset(new Declaration( |
| Zachary Turner | ffc1b8f | 2019-01-14 22:40:41 +0000 | [diff] [blame] | 1126 | comp_unit.GetSupportFiles().GetFileSpecAtIndex(decl_file), |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1127 | decl_line, decl_column)); |
| 1128 | |
| Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 1129 | std::unique_ptr<Declaration> call_up; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1130 | if (call_file != 0 || call_line != 0 || call_column != 0) |
| Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 1131 | call_up.reset(new Declaration( |
| Zachary Turner | ffc1b8f | 2019-01-14 22:40:41 +0000 | [diff] [blame] | 1132 | comp_unit.GetSupportFiles().GetFileSpecAtIndex(call_file), |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1133 | call_line, call_column)); |
| 1134 | |
| Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 1135 | block->SetInlinedFunctionInfo(name, mangled_name, decl_up.get(), |
| 1136 | call_up.get()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | ++blocks_added; |
| 1140 | |
| 1141 | if (die.HasChildren()) { |
| Zachary Turner | ffc1b8f | 2019-01-14 22:40:41 +0000 | [diff] [blame] | 1142 | blocks_added += |
| 1143 | ParseBlocksRecursive(comp_unit, block, die.GetFirstChild(), |
| 1144 | subprogram_low_pc, depth + 1); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1145 | } |
| 1146 | } |
| 1147 | } break; |
| 1148 | default: |
| 1149 | break; |
| 1150 | } |
| 1151 | |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1152 | // Only parse siblings of the block if we are not at depth zero. A depth of |
| 1153 | // zero indicates we are currently parsing the top level DW_TAG_subprogram |
| 1154 | // DIE |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1155 | |
| 1156 | if (depth == 0) |
| 1157 | die.Clear(); |
| 1158 | else |
| 1159 | die = die.GetSibling(); |
| 1160 | } |
| 1161 | return blocks_added; |
| Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 1162 | } |
| 1163 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1164 | bool SymbolFileDWARF::ClassOrStructIsVirtual(const DWARFDIE &parent_die) { |
| 1165 | if (parent_die) { |
| 1166 | for (DWARFDIE die = parent_die.GetFirstChild(); die; |
| 1167 | die = die.GetSibling()) { |
| 1168 | dw_tag_t tag = die.Tag(); |
| 1169 | bool check_virtuality = false; |
| 1170 | switch (tag) { |
| 1171 | case DW_TAG_inheritance: |
| 1172 | case DW_TAG_subprogram: |
| 1173 | check_virtuality = true; |
| 1174 | break; |
| 1175 | default: |
| 1176 | break; |
| 1177 | } |
| 1178 | if (check_virtuality) { |
| 1179 | if (die.GetAttributeValueAsUnsigned(DW_AT_virtuality, 0) != 0) |
| 1180 | return true; |
| 1181 | } |
| 1182 | } |
| 1183 | } |
| 1184 | return false; |
| 1185 | } |
| 1186 | |
| 1187 | void SymbolFileDWARF::ParseDeclsForContext(CompilerDeclContext decl_ctx) { |
| 1188 | TypeSystem *type_system = decl_ctx.GetTypeSystem(); |
| 1189 | DWARFASTParser *ast_parser = type_system->GetDWARFParser(); |
| 1190 | std::vector<DWARFDIE> decl_ctx_die_list = |
| 1191 | ast_parser->GetDIEForDeclContext(decl_ctx); |
| 1192 | |
| 1193 | for (DWARFDIE decl_ctx_die : decl_ctx_die_list) |
| 1194 | for (DWARFDIE decl = decl_ctx_die.GetFirstChild(); decl; |
| 1195 | decl = decl.GetSibling()) |
| 1196 | ast_parser->GetDeclForUIDFromDWARF(decl); |
| 1197 | } |
| 1198 | |
| Pavel Labath | 3b92698 | 2019-06-21 07:56:50 +0000 | [diff] [blame] | 1199 | user_id_t SymbolFileDWARF::GetUID(DIERef ref) { |
| 1200 | if (GetDebugMapSymfile()) |
| 1201 | return GetID() | ref.die_offset(); |
| 1202 | |
| 1203 | return user_id_t(GetDwoNum().getValueOr(0x7fffffff)) << 32 | |
| 1204 | ref.die_offset() | |
| 1205 | (lldb::user_id_t(ref.section() == DIERef::Section::DebugTypes) << 63); |
| 1206 | } |
| 1207 | |
| Pavel Labath | 67b45ac | 2019-06-19 07:32:39 +0000 | [diff] [blame] | 1208 | llvm::Optional<SymbolFileDWARF::DecodedUID> |
| 1209 | SymbolFileDWARF::DecodeUID(lldb::user_id_t uid) { |
| Jonas Devlieghere | 4f78c4f | 2018-10-22 20:14:36 +0000 | [diff] [blame] | 1210 | // This method can be called without going through the symbol vendor so we |
| 1211 | // need to lock the module. |
| 1212 | std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1213 | // Anytime we get a "lldb::user_id_t" from an lldb_private::SymbolFile API we |
| 1214 | // must make sure we use the correct DWARF file when resolving things. On |
| 1215 | // MacOSX, when using SymbolFileDWARFDebugMap, we will use multiple |
| 1216 | // SymbolFileDWARF classes, one for each .o file. We can often end up with |
| 1217 | // references to other DWARF objects and we must be ready to receive a |
| 1218 | // "lldb::user_id_t" that specifies a DIE from another SymbolFileDWARF |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1219 | // instance. |
| Pavel Labath | 2841e6e | 2019-05-08 11:43:05 +0000 | [diff] [blame] | 1220 | if (SymbolFileDWARFDebugMap *debug_map = GetDebugMapSymfile()) { |
| 1221 | SymbolFileDWARF *dwarf = debug_map->GetSymbolFileByOSOIndex( |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1222 | debug_map->GetOSOIndexFromUserID(uid)); |
| Pavel Labath | 67b45ac | 2019-06-19 07:32:39 +0000 | [diff] [blame] | 1223 | return DecodedUID{ |
| Pavel Labath | 3b92698 | 2019-06-21 07:56:50 +0000 | [diff] [blame] | 1224 | *dwarf, {llvm::None, DIERef::Section::DebugInfo, dw_offset_t(uid)}}; |
| Pavel Labath | 2841e6e | 2019-05-08 11:43:05 +0000 | [diff] [blame] | 1225 | } |
| Pavel Labath | 381ba9a | 2019-05-13 08:58:34 +0000 | [diff] [blame] | 1226 | dw_offset_t die_offset = uid; |
| Pavel Labath | 381ba9a | 2019-05-13 08:58:34 +0000 | [diff] [blame] | 1227 | if (die_offset == DW_INVALID_OFFSET) |
| Pavel Labath | 67b45ac | 2019-06-19 07:32:39 +0000 | [diff] [blame] | 1228 | return llvm::None; |
| Pavel Labath | 381ba9a | 2019-05-13 08:58:34 +0000 | [diff] [blame] | 1229 | |
| Pavel Labath | 3b92698 | 2019-06-21 07:56:50 +0000 | [diff] [blame] | 1230 | DIERef::Section section = |
| 1231 | uid >> 63 ? DIERef::Section::DebugTypes : DIERef::Section::DebugInfo; |
| 1232 | |
| 1233 | llvm::Optional<uint32_t> dwo_num = uid >> 32 & 0x7fffffff; |
| 1234 | if (*dwo_num == 0x7fffffff) |
| 1235 | dwo_num = llvm::None; |
| 1236 | |
| 1237 | return DecodedUID{*this, {dwo_num, section, die_offset}}; |
| Greg Clayton | 07c8c44 | 2016-04-25 23:39:19 +0000 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | DWARFDIE |
| Pavel Labath | 2841e6e | 2019-05-08 11:43:05 +0000 | [diff] [blame] | 1241 | SymbolFileDWARF::GetDIE(lldb::user_id_t uid) { |
| Jonas Devlieghere | 4f78c4f | 2018-10-22 20:14:36 +0000 | [diff] [blame] | 1242 | // This method can be called without going through the symbol vendor so we |
| 1243 | // need to lock the module. |
| 1244 | std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); |
| Pavel Labath | 2841e6e | 2019-05-08 11:43:05 +0000 | [diff] [blame] | 1245 | |
| Pavel Labath | 67b45ac | 2019-06-19 07:32:39 +0000 | [diff] [blame] | 1246 | llvm::Optional<DecodedUID> decoded = DecodeUID(uid); |
| Pavel Labath | 2841e6e | 2019-05-08 11:43:05 +0000 | [diff] [blame] | 1247 | |
| Pavel Labath | 67b45ac | 2019-06-19 07:32:39 +0000 | [diff] [blame] | 1248 | if (decoded) |
| 1249 | return decoded->dwarf.GetDIE(decoded->ref); |
| Pavel Labath | 2841e6e | 2019-05-08 11:43:05 +0000 | [diff] [blame] | 1250 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1251 | return DWARFDIE(); |
| Greg Clayton | 07c8c44 | 2016-04-25 23:39:19 +0000 | [diff] [blame] | 1252 | } |
| 1253 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1254 | CompilerDecl SymbolFileDWARF::GetDeclForUID(lldb::user_id_t type_uid) { |
| Jonas Devlieghere | 4f78c4f | 2018-10-22 20:14:36 +0000 | [diff] [blame] | 1255 | // This method can be called without going through the symbol vendor so we |
| 1256 | // need to lock the module. |
| 1257 | std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1258 | // Anytime we have a lldb::user_id_t, we must get the DIE by calling |
| Pavel Labath | 2841e6e | 2019-05-08 11:43:05 +0000 | [diff] [blame] | 1259 | // SymbolFileDWARF::GetDIE(). See comments inside the |
| 1260 | // SymbolFileDWARF::GetDIE() for details. |
| 1261 | if (DWARFDIE die = GetDIE(type_uid)) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1262 | return die.GetDecl(); |
| 1263 | return CompilerDecl(); |
| Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 1264 | } |
| 1265 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 1266 | CompilerDeclContext |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1267 | SymbolFileDWARF::GetDeclContextForUID(lldb::user_id_t type_uid) { |
| Jonas Devlieghere | 4f78c4f | 2018-10-22 20:14:36 +0000 | [diff] [blame] | 1268 | // This method can be called without going through the symbol vendor so we |
| 1269 | // need to lock the module. |
| 1270 | std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1271 | // Anytime we have a lldb::user_id_t, we must get the DIE by calling |
| Pavel Labath | 2841e6e | 2019-05-08 11:43:05 +0000 | [diff] [blame] | 1272 | // SymbolFileDWARF::GetDIE(). See comments inside the |
| 1273 | // SymbolFileDWARF::GetDIE() for details. |
| 1274 | if (DWARFDIE die = GetDIE(type_uid)) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1275 | return die.GetDeclContext(); |
| 1276 | return CompilerDeclContext(); |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 1277 | } |
| 1278 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 1279 | CompilerDeclContext |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1280 | SymbolFileDWARF::GetDeclContextContainingUID(lldb::user_id_t type_uid) { |
| Jonas Devlieghere | 4f78c4f | 2018-10-22 20:14:36 +0000 | [diff] [blame] | 1281 | // This method can be called without going through the symbol vendor so we |
| 1282 | // need to lock the module. |
| 1283 | std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1284 | // Anytime we have a lldb::user_id_t, we must get the DIE by calling |
| Pavel Labath | 2841e6e | 2019-05-08 11:43:05 +0000 | [diff] [blame] | 1285 | // SymbolFileDWARF::GetDIE(). See comments inside the |
| 1286 | // SymbolFileDWARF::GetDIE() for details. |
| 1287 | if (DWARFDIE die = GetDIE(type_uid)) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1288 | return die.GetContainingDeclContext(); |
| 1289 | return CompilerDeclContext(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1290 | } |
| 1291 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1292 | Type *SymbolFileDWARF::ResolveTypeUID(lldb::user_id_t type_uid) { |
| Jonas Devlieghere | 4f78c4f | 2018-10-22 20:14:36 +0000 | [diff] [blame] | 1293 | // This method can be called without going through the symbol vendor so we |
| 1294 | // need to lock the module. |
| 1295 | std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1296 | // Anytime we have a lldb::user_id_t, we must get the DIE by calling |
| Pavel Labath | 2841e6e | 2019-05-08 11:43:05 +0000 | [diff] [blame] | 1297 | // SymbolFileDWARF::GetDIE(). See comments inside the |
| 1298 | // SymbolFileDWARF::GetDIE() for details. |
| 1299 | if (DWARFDIE type_die = GetDIE(type_uid)) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1300 | return type_die.ResolveType(); |
| 1301 | else |
| 1302 | return nullptr; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1303 | } |
| 1304 | |
| Adrian Prantl | eca07c5 | 2018-11-05 20:49:07 +0000 | [diff] [blame] | 1305 | llvm::Optional<SymbolFile::ArrayInfo> |
| 1306 | SymbolFileDWARF::GetDynamicArrayInfoForUID( |
| 1307 | lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx) { |
| 1308 | std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); |
| Pavel Labath | 2841e6e | 2019-05-08 11:43:05 +0000 | [diff] [blame] | 1309 | if (DWARFDIE type_die = GetDIE(type_uid)) |
| Adrian Prantl | eca07c5 | 2018-11-05 20:49:07 +0000 | [diff] [blame] | 1310 | return DWARFASTParser::ParseChildArrayInfo(type_die, exe_ctx); |
| 1311 | else |
| 1312 | return llvm::None; |
| 1313 | } |
| 1314 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1315 | Type *SymbolFileDWARF::ResolveTypeUID(const DIERef &die_ref) { |
| 1316 | return ResolveType(GetDIE(die_ref), true); |
| Greg Clayton | 2f869fe | 2016-03-30 20:14:35 +0000 | [diff] [blame] | 1317 | } |
| 1318 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1319 | Type *SymbolFileDWARF::ResolveTypeUID(const DWARFDIE &die, |
| 1320 | bool assert_not_being_parsed) { |
| 1321 | if (die) { |
| 1322 | Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| 1323 | if (log) |
| 1324 | GetObjectFile()->GetModule()->LogMessage( |
| 1325 | log, "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'", |
| 1326 | die.GetOffset(), die.GetTagAsCString(), die.GetName()); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1327 | |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1328 | // We might be coming in in the middle of a type tree (a class within a |
| 1329 | // class, an enum within a class), so parse any needed parent DIEs before |
| 1330 | // we get to this one... |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1331 | DWARFDIE decl_ctx_die = GetDeclContextDIEContainingDIE(die); |
| 1332 | if (decl_ctx_die) { |
| 1333 | if (log) { |
| 1334 | switch (decl_ctx_die.Tag()) { |
| 1335 | case DW_TAG_structure_type: |
| 1336 | case DW_TAG_union_type: |
| 1337 | case DW_TAG_class_type: { |
| 1338 | // Get the type, which could be a forward declaration |
| 1339 | if (log) |
| 1340 | GetObjectFile()->GetModule()->LogMessage( |
| 1341 | log, "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' " |
| 1342 | "resolve parent forward type for 0x%8.8x", |
| 1343 | die.GetOffset(), die.GetTagAsCString(), die.GetName(), |
| 1344 | decl_ctx_die.GetOffset()); |
| 1345 | } break; |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1346 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1347 | default: |
| 1348 | break; |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1349 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1350 | } |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1351 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1352 | return ResolveType(die); |
| 1353 | } |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 1354 | return nullptr; |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1355 | } |
| 1356 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1357 | // This function is used when SymbolFileDWARFDebugMap owns a bunch of |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1358 | // SymbolFileDWARF objects to detect if this DWARF file is the one that can |
| 1359 | // resolve a compiler_type. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1360 | bool SymbolFileDWARF::HasForwardDeclForClangType( |
| 1361 | const CompilerType &compiler_type) { |
| 1362 | CompilerType compiler_type_no_qualifiers = |
| 1363 | ClangUtil::RemoveFastQualifiers(compiler_type); |
| 1364 | if (GetForwardDeclClangTypeToDie().count( |
| 1365 | compiler_type_no_qualifiers.GetOpaqueQualType())) { |
| 1366 | return true; |
| 1367 | } |
| 1368 | TypeSystem *type_system = compiler_type.GetTypeSystem(); |
| Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 1369 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1370 | ClangASTContext *clang_type_system = |
| 1371 | llvm::dyn_cast_or_null<ClangASTContext>(type_system); |
| 1372 | if (!clang_type_system) |
| Ashok Thirumurthi | a4658a5 | 2013-07-30 14:58:39 +0000 | [diff] [blame] | 1373 | return false; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1374 | DWARFASTParserClang *ast_parser = |
| 1375 | static_cast<DWARFASTParserClang *>(clang_type_system->GetDWARFParser()); |
| 1376 | return ast_parser->GetClangASTImporter().CanImport(compiler_type); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1377 | } |
| 1378 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1379 | bool SymbolFileDWARF::CompleteType(CompilerType &compiler_type) { |
| Jonas Devlieghere | 4f78c4f | 2018-10-22 20:14:36 +0000 | [diff] [blame] | 1380 | std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1381 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1382 | ClangASTContext *clang_type_system = |
| 1383 | llvm::dyn_cast_or_null<ClangASTContext>(compiler_type.GetTypeSystem()); |
| 1384 | if (clang_type_system) { |
| 1385 | DWARFASTParserClang *ast_parser = |
| 1386 | static_cast<DWARFASTParserClang *>(clang_type_system->GetDWARFParser()); |
| 1387 | if (ast_parser && |
| 1388 | ast_parser->GetClangASTImporter().CanImport(compiler_type)) |
| 1389 | return ast_parser->GetClangASTImporter().CompleteType(compiler_type); |
| 1390 | } |
| Jim Ingham | c354928 | 2012-01-11 02:21:12 +0000 | [diff] [blame] | 1391 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1392 | // We have a struct/union/class/enum that needs to be fully resolved. |
| 1393 | CompilerType compiler_type_no_qualifiers = |
| 1394 | ClangUtil::RemoveFastQualifiers(compiler_type); |
| 1395 | auto die_it = GetForwardDeclClangTypeToDie().find( |
| 1396 | compiler_type_no_qualifiers.GetOpaqueQualType()); |
| 1397 | if (die_it == GetForwardDeclClangTypeToDie().end()) { |
| 1398 | // We have already resolved this type... |
| 1399 | return true; |
| 1400 | } |
| 1401 | |
| 1402 | DWARFDIE dwarf_die = GetDIE(die_it->getSecond()); |
| 1403 | if (dwarf_die) { |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1404 | // Once we start resolving this type, remove it from the forward |
| 1405 | // declaration map in case anyone child members or other types require this |
| 1406 | // type to get resolved. The type will get resolved when all of the calls |
| 1407 | // to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition are done. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1408 | GetForwardDeclClangTypeToDie().erase(die_it); |
| 1409 | |
| 1410 | Type *type = GetDIEToType().lookup(dwarf_die.GetDIE()); |
| 1411 | |
| 1412 | Log *log(LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | |
| 1413 | DWARF_LOG_TYPE_COMPLETION)); |
| 1414 | if (log) |
| 1415 | GetObjectFile()->GetModule()->LogMessageVerboseBacktrace( |
| 1416 | log, "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...", |
| 1417 | dwarf_die.GetID(), dwarf_die.GetTagAsCString(), |
| 1418 | type->GetName().AsCString()); |
| 1419 | assert(compiler_type); |
| 1420 | DWARFASTParser *dwarf_ast = dwarf_die.GetDWARFParser(); |
| 1421 | if (dwarf_ast) |
| 1422 | return dwarf_ast->CompleteTypeFromDWARF(dwarf_die, type, compiler_type); |
| 1423 | } |
| 1424 | return false; |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 1425 | } |
| 1426 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1427 | Type *SymbolFileDWARF::ResolveType(const DWARFDIE &die, |
| 1428 | bool assert_not_being_parsed, |
| 1429 | bool resolve_function_context) { |
| 1430 | if (die) { |
| 1431 | Type *type = GetTypeForDIE(die, resolve_function_context).get(); |
| 1432 | |
| 1433 | if (assert_not_being_parsed) { |
| 1434 | if (type != DIE_IS_BEING_PARSED) |
| 1435 | return type; |
| 1436 | |
| 1437 | GetObjectFile()->GetModule()->ReportError( |
| 1438 | "Parsing a die that is being parsed die: 0x%8.8x: %s %s", |
| 1439 | die.GetOffset(), die.GetTagAsCString(), die.GetName()); |
| 1440 | |
| 1441 | } else |
| 1442 | return type; |
| 1443 | } |
| 1444 | return nullptr; |
| 1445 | } |
| 1446 | |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 1447 | CompileUnit * |
| 1448 | SymbolFileDWARF::GetCompUnitForDWARFCompUnit(DWARFCompileUnit &dwarf_cu) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1449 | // Check if the symbol vendor already knows about this compile unit? |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 1450 | if (dwarf_cu.GetUserData() == nullptr) { |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1451 | // The symbol vendor doesn't know about this compile unit, we need to parse |
| 1452 | // and add it to the symbol vendor object. |
| Pavel Labath | 519ef6a | 2019-05-27 10:10:59 +0000 | [diff] [blame] | 1453 | return ParseCompileUnit(dwarf_cu).get(); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1454 | } |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 1455 | return (CompileUnit *)dwarf_cu.GetUserData(); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | size_t SymbolFileDWARF::GetObjCMethodDIEOffsets(ConstString class_name, |
| 1459 | DIEArray &method_die_offsets) { |
| 1460 | method_die_offsets.clear(); |
| Pavel Labath | b13f033 | 2018-05-21 14:12:52 +0000 | [diff] [blame] | 1461 | m_index->GetObjCMethods(class_name, method_die_offsets); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1462 | return method_die_offsets.size(); |
| 1463 | } |
| 1464 | |
| 1465 | bool SymbolFileDWARF::GetFunction(const DWARFDIE &die, SymbolContext &sc) { |
| 1466 | sc.Clear(false); |
| 1467 | |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 1468 | if (die && llvm::isa<DWARFCompileUnit>(die.GetCU())) { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1469 | // Check if the symbol vendor already knows about this compile unit? |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 1470 | sc.comp_unit = |
| 1471 | GetCompUnitForDWARFCompUnit(llvm::cast<DWARFCompileUnit>(*die.GetCU())); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1472 | |
| 1473 | sc.function = sc.comp_unit->FindFunctionByUID(die.GetID()).get(); |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 1474 | if (sc.function == nullptr) |
| Zachary Turner | 863f8c1 | 2019-01-11 18:03:20 +0000 | [diff] [blame] | 1475 | sc.function = ParseFunction(*sc.comp_unit, die); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1476 | |
| 1477 | if (sc.function) { |
| 1478 | sc.module_sp = sc.function->CalculateSymbolContextModule(); |
| 1479 | return true; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1480 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | return false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1484 | } |
| 1485 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1486 | lldb::ModuleSP SymbolFileDWARF::GetDWOModule(ConstString name) { |
| 1487 | UpdateExternalModuleListIfNeeded(); |
| 1488 | const auto &pos = m_external_type_modules.find(name); |
| 1489 | if (pos != m_external_type_modules.end()) |
| 1490 | return pos->second; |
| 1491 | else |
| 1492 | return lldb::ModuleSP(); |
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 1493 | } |
| 1494 | |
| Greg Clayton | 2f869fe | 2016-03-30 20:14:35 +0000 | [diff] [blame] | 1495 | DWARFDIE |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1496 | SymbolFileDWARF::GetDIE(const DIERef &die_ref) { |
| Pavel Labath | 3b92698 | 2019-06-21 07:56:50 +0000 | [diff] [blame] | 1497 | if (die_ref.dwo_num()) { |
| 1498 | return DebugInfo() |
| 1499 | ->GetUnitAtIndex(*die_ref.dwo_num()) |
| 1500 | ->GetDwoSymbolFile() |
| 1501 | ->GetDIE(die_ref); |
| 1502 | } |
| 1503 | |
| 1504 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1505 | DWARFDebugInfo *debug_info = DebugInfo(); |
| 1506 | if (debug_info) |
| 1507 | return debug_info->GetDIE(die_ref); |
| 1508 | else |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 1509 | return DWARFDIE(); |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 1510 | } |
| 1511 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1512 | std::unique_ptr<SymbolFileDWARFDwo> |
| 1513 | SymbolFileDWARF::GetDwoSymbolFileForCompileUnit( |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 1514 | DWARFUnit &unit, const DWARFDebugInfoEntry &cu_die) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1515 | // If we are using a dSYM file, we never want the standard DWO files since |
| Adrian Prantl | dce4a9a | 2018-01-04 16:42:05 +0000 | [diff] [blame] | 1516 | // the -gmodules support uses the same DWO machanism to specify full debug |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1517 | // info files for modules. |
| 1518 | if (GetDebugMapSymfile()) |
| 1519 | return nullptr; |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 1520 | |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 1521 | DWARFCompileUnit *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(&unit); |
| 1522 | // Only compile units can be split into two parts. |
| 1523 | if (!dwarf_cu) |
| 1524 | return nullptr; |
| 1525 | |
| Jan Kratochvil | b7a1932 | 2019-05-21 17:38:56 +0000 | [diff] [blame] | 1526 | const char *dwo_name = |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 1527 | cu_die.GetAttributeValueAsString(dwarf_cu, DW_AT_GNU_dwo_name, nullptr); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1528 | if (!dwo_name) |
| 1529 | return nullptr; |
| 1530 | |
| Tamas Berghammer | 963ce48 | 2017-08-25 13:56:14 +0000 | [diff] [blame] | 1531 | SymbolFileDWARFDwp *dwp_symfile = GetDwpSymbolFile(); |
| 1532 | if (dwp_symfile) { |
| Jan Kratochvil | b7a1932 | 2019-05-21 17:38:56 +0000 | [diff] [blame] | 1533 | uint64_t dwo_id = |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 1534 | cu_die.GetAttributeValueAsUnsigned(dwarf_cu, DW_AT_GNU_dwo_id, 0); |
| Tamas Berghammer | 963ce48 | 2017-08-25 13:56:14 +0000 | [diff] [blame] | 1535 | std::unique_ptr<SymbolFileDWARFDwo> dwo_symfile = |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 1536 | dwp_symfile->GetSymbolFileForDwoId(*dwarf_cu, dwo_id); |
| Tamas Berghammer | 963ce48 | 2017-08-25 13:56:14 +0000 | [diff] [blame] | 1537 | if (dwo_symfile) |
| 1538 | return dwo_symfile; |
| 1539 | } |
| 1540 | |
| Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 1541 | FileSpec dwo_file(dwo_name); |
| 1542 | FileSystem::Instance().Resolve(dwo_file); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1543 | if (dwo_file.IsRelative()) { |
| Jan Kratochvil | b7a1932 | 2019-05-21 17:38:56 +0000 | [diff] [blame] | 1544 | const char *comp_dir = |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 1545 | cu_die.GetAttributeValueAsString(dwarf_cu, DW_AT_comp_dir, nullptr); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1546 | if (!comp_dir) |
| 1547 | return nullptr; |
| 1548 | |
| Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 1549 | dwo_file.SetFile(comp_dir, FileSpec::Style::native); |
| 1550 | FileSystem::Instance().Resolve(dwo_file); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1551 | dwo_file.AppendPathComponent(dwo_name); |
| 1552 | } |
| 1553 | |
| Jonas Devlieghere | dbd7fab | 2018-11-01 17:09:25 +0000 | [diff] [blame] | 1554 | if (!FileSystem::Instance().Exists(dwo_file)) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1555 | return nullptr; |
| 1556 | |
| 1557 | const lldb::offset_t file_offset = 0; |
| 1558 | DataBufferSP dwo_file_data_sp; |
| 1559 | lldb::offset_t dwo_file_data_offset = 0; |
| 1560 | ObjectFileSP dwo_obj_file = ObjectFile::FindPlugin( |
| 1561 | GetObjectFile()->GetModule(), &dwo_file, file_offset, |
| Jonas Devlieghere | 59b78bc | 2018-11-01 04:45:28 +0000 | [diff] [blame] | 1562 | FileSystem::Instance().GetByteSize(dwo_file), dwo_file_data_sp, |
| 1563 | dwo_file_data_offset); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1564 | if (dwo_obj_file == nullptr) |
| 1565 | return nullptr; |
| 1566 | |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 1567 | return llvm::make_unique<SymbolFileDWARFDwo>(dwo_obj_file, *dwarf_cu); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 1568 | } |
| 1569 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1570 | void SymbolFileDWARF::UpdateExternalModuleListIfNeeded() { |
| 1571 | if (m_fetched_external_modules) |
| 1572 | return; |
| 1573 | m_fetched_external_modules = true; |
| 1574 | |
| 1575 | DWARFDebugInfo *debug_info = DebugInfo(); |
| 1576 | |
| 1577 | const uint32_t num_compile_units = GetNumCompileUnits(); |
| 1578 | for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) { |
| Jan Kratochvil | 6056273 | 2019-05-10 17:14:37 +0000 | [diff] [blame] | 1579 | DWARFUnit *dwarf_cu = debug_info->GetUnitAtIndex(cu_idx); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1580 | |
| Jan Kratochvil | 93afb05 | 2018-05-24 20:51:13 +0000 | [diff] [blame] | 1581 | const DWARFBaseDIE die = dwarf_cu->GetUnitDIEOnly(); |
| Jonas Devlieghere | a6682a4 | 2018-12-15 00:15:33 +0000 | [diff] [blame] | 1582 | if (die && !die.HasChildren()) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1583 | const char *name = die.GetAttributeValueAsString(DW_AT_name, nullptr); |
| 1584 | |
| 1585 | if (name) { |
| 1586 | ConstString const_name(name); |
| 1587 | if (m_external_type_modules.find(const_name) == |
| 1588 | m_external_type_modules.end()) { |
| 1589 | ModuleSP module_sp; |
| 1590 | const char *dwo_path = |
| 1591 | die.GetAttributeValueAsString(DW_AT_GNU_dwo_name, nullptr); |
| 1592 | if (dwo_path) { |
| 1593 | ModuleSpec dwo_module_spec; |
| Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 1594 | dwo_module_spec.GetFileSpec().SetFile(dwo_path, |
| Jonas Devlieghere | 937348c | 2018-06-13 22:08:14 +0000 | [diff] [blame] | 1595 | FileSpec::Style::native); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1596 | if (dwo_module_spec.GetFileSpec().IsRelative()) { |
| 1597 | const char *comp_dir = |
| 1598 | die.GetAttributeValueAsString(DW_AT_comp_dir, nullptr); |
| 1599 | if (comp_dir) { |
| Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 1600 | dwo_module_spec.GetFileSpec().SetFile(comp_dir, |
| Jonas Devlieghere | 937348c | 2018-06-13 22:08:14 +0000 | [diff] [blame] | 1601 | FileSpec::Style::native); |
| Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 1602 | FileSystem::Instance().Resolve(dwo_module_spec.GetFileSpec()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1603 | dwo_module_spec.GetFileSpec().AppendPathComponent(dwo_path); |
| 1604 | } |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 1605 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1606 | dwo_module_spec.GetArchitecture() = |
| 1607 | m_obj_file->GetModule()->GetArchitecture(); |
| Alexander Shaposhnikov | ff7b03f | 2017-09-12 22:14:36 +0000 | [diff] [blame] | 1608 | |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1609 | // When LLDB loads "external" modules it looks at the presence of |
| 1610 | // DW_AT_GNU_dwo_name. However, when the already created module |
| 1611 | // (corresponding to .dwo itself) is being processed, it will see |
| 1612 | // the presence of DW_AT_GNU_dwo_name (which contains the name of |
| 1613 | // dwo file) and will try to call ModuleList::GetSharedModule |
| 1614 | // again. In some cases (i.e. for empty files) Clang 4.0 generates |
| 1615 | // a *.dwo file which has DW_AT_GNU_dwo_name, but no |
| 1616 | // DW_AT_comp_dir. In this case the method |
| 1617 | // ModuleList::GetSharedModule will fail and the warning will be |
| 1618 | // printed. However, as one can notice in this case we don't |
| 1619 | // actually need to try to load the already loaded module |
| 1620 | // (corresponding to .dwo) so we simply skip it. |
| Raphael Isemann | c53f8db | 2019-05-01 09:49:07 +0000 | [diff] [blame] | 1621 | if (m_obj_file->GetFileSpec().GetFileNameExtension() == ".dwo" && |
| Alexander Shaposhnikov | ff7b03f | 2017-09-12 22:14:36 +0000 | [diff] [blame] | 1622 | llvm::StringRef(m_obj_file->GetFileSpec().GetPath()) |
| 1623 | .endswith(dwo_module_spec.GetFileSpec().GetPath())) { |
| 1624 | continue; |
| 1625 | } |
| 1626 | |
| Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1627 | Status error = ModuleList::GetSharedModule( |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 1628 | dwo_module_spec, module_sp, nullptr, nullptr, nullptr); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1629 | if (!module_sp) { |
| 1630 | GetObjectFile()->GetModule()->ReportWarning( |
| 1631 | "0x%8.8x: unable to locate module needed for external types: " |
| 1632 | "%s\nerror: %s\nDebugging will be degraded due to missing " |
| 1633 | "types. Rebuilding your project will regenerate the needed " |
| 1634 | "module files.", |
| 1635 | die.GetOffset(), |
| 1636 | dwo_module_spec.GetFileSpec().GetPath().c_str(), |
| 1637 | error.AsCString("unknown error")); |
| 1638 | } |
| 1639 | } |
| 1640 | m_external_type_modules[const_name] = module_sp; |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 1641 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1642 | } |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 1643 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1644 | } |
| 1645 | } |
| 1646 | |
| 1647 | SymbolFileDWARF::GlobalVariableMap &SymbolFileDWARF::GetGlobalAranges() { |
| Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 1648 | if (!m_global_aranges_up) { |
| 1649 | m_global_aranges_up.reset(new GlobalVariableMap()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1650 | |
| 1651 | ModuleSP module_sp = GetObjectFile()->GetModule(); |
| 1652 | if (module_sp) { |
| 1653 | const size_t num_cus = module_sp->GetNumCompileUnits(); |
| 1654 | for (size_t i = 0; i < num_cus; ++i) { |
| 1655 | CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(i); |
| 1656 | if (cu_sp) { |
| 1657 | VariableListSP globals_sp = cu_sp->GetVariableList(true); |
| 1658 | if (globals_sp) { |
| 1659 | const size_t num_globals = globals_sp->GetSize(); |
| 1660 | for (size_t g = 0; g < num_globals; ++g) { |
| 1661 | VariableSP var_sp = globals_sp->GetVariableAtIndex(g); |
| 1662 | if (var_sp && !var_sp->GetLocationIsConstantValueData()) { |
| 1663 | const DWARFExpression &location = var_sp->LocationExpression(); |
| 1664 | Value location_result; |
| Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1665 | Status error; |
| Tamas Berghammer | bba2c83 | 2017-08-16 11:45:10 +0000 | [diff] [blame] | 1666 | if (location.Evaluate(nullptr, LLDB_INVALID_ADDRESS, nullptr, |
| 1667 | nullptr, location_result, &error)) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1668 | if (location_result.GetValueType() == |
| 1669 | Value::eValueTypeFileAddress) { |
| 1670 | lldb::addr_t file_addr = |
| 1671 | location_result.GetScalar().ULongLong(); |
| 1672 | lldb::addr_t byte_size = 1; |
| 1673 | if (var_sp->GetType()) |
| Adrian Prantl | d13777a | 2019-01-29 17:52:34 +0000 | [diff] [blame] | 1674 | byte_size = |
| 1675 | var_sp->GetType()->GetByteSize().getValueOr(0); |
| Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 1676 | m_global_aranges_up->Append(GlobalVariableMap::Entry( |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1677 | file_addr, byte_size, var_sp.get())); |
| 1678 | } |
| 1679 | } |
| 1680 | } |
| 1681 | } |
| 1682 | } |
| 1683 | } |
| 1684 | } |
| 1685 | } |
| Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 1686 | m_global_aranges_up->Sort(); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1687 | } |
| Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 1688 | return *m_global_aranges_up; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1689 | } |
| 1690 | |
| 1691 | uint32_t SymbolFileDWARF::ResolveSymbolContext(const Address &so_addr, |
| Zachary Turner | 991e445 | 2018-10-25 20:45:19 +0000 | [diff] [blame] | 1692 | SymbolContextItem resolve_scope, |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1693 | SymbolContext &sc) { |
| Pavel Labath | f9d1647 | 2017-05-15 13:02:37 +0000 | [diff] [blame] | 1694 | static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); |
| 1695 | Timer scoped_timer(func_cat, |
| 1696 | "SymbolFileDWARF::" |
| 1697 | "ResolveSymbolContext (so_addr = { " |
| 1698 | "section = %p, offset = 0x%" PRIx64 |
| 1699 | " }, resolve_scope = 0x%8.8x)", |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1700 | static_cast<void *>(so_addr.GetSection().get()), |
| 1701 | so_addr.GetOffset(), resolve_scope); |
| 1702 | uint32_t resolved = 0; |
| 1703 | if (resolve_scope & |
| 1704 | (eSymbolContextCompUnit | eSymbolContextFunction | eSymbolContextBlock | |
| 1705 | eSymbolContextLineEntry | eSymbolContextVariable)) { |
| 1706 | lldb::addr_t file_vm_addr = so_addr.GetFileAddress(); |
| 1707 | |
| 1708 | DWARFDebugInfo *debug_info = DebugInfo(); |
| 1709 | if (debug_info) { |
| Zachary Turner | 1cbbab9 | 2019-03-15 17:32:05 +0000 | [diff] [blame] | 1710 | llvm::Expected<DWARFDebugAranges &> aranges = |
| 1711 | debug_info->GetCompileUnitAranges(); |
| 1712 | if (!aranges) { |
| Zachary Turner | 611d1f9 | 2019-03-19 20:08:56 +0000 | [diff] [blame] | 1713 | Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO); |
| Zachary Turner | 1cbbab9 | 2019-03-15 17:32:05 +0000 | [diff] [blame] | 1714 | LLDB_LOG_ERROR(log, aranges.takeError(), |
| 1715 | "SymbolFileDWARF::ResolveSymbolContext failed to get cu " |
| 1716 | "aranges. {0}"); |
| 1717 | return 0; |
| 1718 | } |
| 1719 | |
| 1720 | const dw_offset_t cu_offset = aranges->FindAddress(file_vm_addr); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1721 | if (cu_offset == DW_INVALID_OFFSET) { |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1722 | // Global variables are not in the compile unit address ranges. The |
| 1723 | // only way to currently find global variables is to iterate over the |
| 1724 | // .debug_pubnames or the __apple_names table and find all items in |
| 1725 | // there that point to DW_TAG_variable DIEs and then find the address |
| 1726 | // that matches. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1727 | if (resolve_scope & eSymbolContextVariable) { |
| 1728 | GlobalVariableMap &map = GetGlobalAranges(); |
| 1729 | const GlobalVariableMap::Entry *entry = |
| 1730 | map.FindEntryThatContains(file_vm_addr); |
| 1731 | if (entry && entry->data) { |
| 1732 | Variable *variable = entry->data; |
| 1733 | SymbolContextScope *scc = variable->GetSymbolContextScope(); |
| 1734 | if (scc) { |
| 1735 | scc->CalculateSymbolContext(&sc); |
| 1736 | sc.variable = variable; |
| 1737 | } |
| 1738 | return sc.GetResolvedMask(); |
| 1739 | } |
| 1740 | } |
| 1741 | } else { |
| 1742 | uint32_t cu_idx = DW_INVALID_INDEX; |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 1743 | if (auto *dwarf_cu = llvm::dyn_cast_or_null<DWARFCompileUnit>( |
| 1744 | debug_info->GetUnitAtOffset(DIERef::Section::DebugInfo, |
| 1745 | cu_offset, &cu_idx))) { |
| 1746 | sc.comp_unit = GetCompUnitForDWARFCompUnit(*dwarf_cu); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1747 | if (sc.comp_unit) { |
| 1748 | resolved |= eSymbolContextCompUnit; |
| 1749 | |
| 1750 | bool force_check_line_table = false; |
| 1751 | if (resolve_scope & |
| 1752 | (eSymbolContextFunction | eSymbolContextBlock)) { |
| 1753 | DWARFDIE function_die = dwarf_cu->LookupAddress(file_vm_addr); |
| 1754 | DWARFDIE block_die; |
| 1755 | if (function_die) { |
| 1756 | sc.function = |
| 1757 | sc.comp_unit->FindFunctionByUID(function_die.GetID()).get(); |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 1758 | if (sc.function == nullptr) |
| Zachary Turner | 863f8c1 | 2019-01-11 18:03:20 +0000 | [diff] [blame] | 1759 | sc.function = ParseFunction(*sc.comp_unit, function_die); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1760 | |
| 1761 | if (sc.function && (resolve_scope & eSymbolContextBlock)) |
| 1762 | block_die = function_die.LookupDeepestBlock(file_vm_addr); |
| 1763 | } else { |
| 1764 | // We might have had a compile unit that had discontiguous |
| 1765 | // address ranges where the gaps are symbols that don't have |
| 1766 | // any debug info. Discontiguous compile unit address ranges |
| 1767 | // should only happen when there aren't other functions from |
| 1768 | // other compile units in these gaps. This helps keep the size |
| 1769 | // of the aranges down. |
| 1770 | force_check_line_table = true; |
| 1771 | } |
| 1772 | |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 1773 | if (sc.function != nullptr) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1774 | resolved |= eSymbolContextFunction; |
| 1775 | |
| 1776 | if (resolve_scope & eSymbolContextBlock) { |
| 1777 | Block &block = sc.function->GetBlock(true); |
| 1778 | |
| 1779 | if (block_die) |
| 1780 | sc.block = block.FindBlockByID(block_die.GetID()); |
| 1781 | else |
| 1782 | sc.block = block.FindBlockByID(function_die.GetID()); |
| 1783 | if (sc.block) |
| 1784 | resolved |= eSymbolContextBlock; |
| 1785 | } |
| 1786 | } |
| 1787 | } |
| 1788 | |
| 1789 | if ((resolve_scope & eSymbolContextLineEntry) || |
| 1790 | force_check_line_table) { |
| 1791 | LineTable *line_table = sc.comp_unit->GetLineTable(); |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 1792 | if (line_table != nullptr) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1793 | // And address that makes it into this function should be in |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1794 | // terms of this debug file if there is no debug map, or it |
| 1795 | // will be an address in the .o file which needs to be fixed up |
| 1796 | // to be in terms of the debug map executable. Either way, |
| 1797 | // calling FixupAddress() will work for us. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1798 | Address exe_so_addr(so_addr); |
| 1799 | if (FixupAddress(exe_so_addr)) { |
| 1800 | if (line_table->FindLineEntryByAddress(exe_so_addr, |
| 1801 | sc.line_entry)) { |
| 1802 | resolved |= eSymbolContextLineEntry; |
| 1803 | } |
| 1804 | } |
| 1805 | } |
| 1806 | } |
| 1807 | |
| 1808 | if (force_check_line_table && |
| 1809 | !(resolved & eSymbolContextLineEntry)) { |
| 1810 | // We might have had a compile unit that had discontiguous |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1811 | // address ranges where the gaps are symbols that don't have any |
| 1812 | // debug info. Discontiguous compile unit address ranges should |
| 1813 | // only happen when there aren't other functions from other |
| 1814 | // compile units in these gaps. This helps keep the size of the |
| 1815 | // aranges down. |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 1816 | sc.comp_unit = nullptr; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1817 | resolved &= ~eSymbolContextCompUnit; |
| 1818 | } |
| 1819 | } else { |
| 1820 | GetObjectFile()->GetModule()->ReportWarning( |
| 1821 | "0x%8.8x: compile unit %u failed to create a valid " |
| 1822 | "lldb_private::CompileUnit class.", |
| 1823 | cu_offset, cu_idx); |
| 1824 | } |
| 1825 | } |
| 1826 | } |
| 1827 | } |
| 1828 | } |
| 1829 | return resolved; |
| 1830 | } |
| 1831 | |
| 1832 | uint32_t SymbolFileDWARF::ResolveSymbolContext(const FileSpec &file_spec, |
| 1833 | uint32_t line, |
| 1834 | bool check_inlines, |
| Zachary Turner | 991e445 | 2018-10-25 20:45:19 +0000 | [diff] [blame] | 1835 | SymbolContextItem resolve_scope, |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1836 | SymbolContextList &sc_list) { |
| 1837 | const uint32_t prev_size = sc_list.GetSize(); |
| 1838 | if (resolve_scope & eSymbolContextCompUnit) { |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 1839 | for (uint32_t cu_idx = 0, num_cus = GetNumCompileUnits(); cu_idx < num_cus; |
| 1840 | ++cu_idx) { |
| 1841 | CompileUnit *dc_cu = ParseCompileUnitAtIndex(cu_idx).get(); |
| 1842 | if (!dc_cu) |
| 1843 | continue; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1844 | |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 1845 | const bool full_match = (bool)file_spec.GetDirectory(); |
| 1846 | bool file_spec_matches_cu_file_spec = |
| 1847 | FileSpec::Equal(file_spec, *dc_cu, full_match); |
| 1848 | if (check_inlines || file_spec_matches_cu_file_spec) { |
| 1849 | SymbolContext sc(m_obj_file->GetModule()); |
| 1850 | sc.comp_unit = dc_cu; |
| 1851 | uint32_t file_idx = UINT32_MAX; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1852 | |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 1853 | // If we are looking for inline functions only and we don't find it |
| 1854 | // in the support files, we are done. |
| 1855 | if (check_inlines) { |
| 1856 | file_idx = |
| 1857 | sc.comp_unit->GetSupportFiles().FindFileIndex(1, file_spec, true); |
| 1858 | if (file_idx == UINT32_MAX) |
| 1859 | continue; |
| 1860 | } |
| 1861 | |
| 1862 | if (line != 0) { |
| 1863 | LineTable *line_table = sc.comp_unit->GetLineTable(); |
| 1864 | |
| 1865 | if (line_table != nullptr && line != 0) { |
| 1866 | // We will have already looked up the file index if we are |
| 1867 | // searching for inline entries. |
| 1868 | if (!check_inlines) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1869 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex( |
| 1870 | 1, file_spec, true); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1871 | |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 1872 | if (file_idx != UINT32_MAX) { |
| 1873 | uint32_t found_line; |
| 1874 | uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex( |
| 1875 | 0, file_idx, line, false, &sc.line_entry); |
| 1876 | found_line = sc.line_entry.line; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1877 | |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 1878 | while (line_idx != UINT32_MAX) { |
| 1879 | sc.function = nullptr; |
| 1880 | sc.block = nullptr; |
| 1881 | if (resolve_scope & |
| 1882 | (eSymbolContextFunction | eSymbolContextBlock)) { |
| 1883 | const lldb::addr_t file_vm_addr = |
| 1884 | sc.line_entry.range.GetBaseAddress().GetFileAddress(); |
| 1885 | if (file_vm_addr != LLDB_INVALID_ADDRESS) { |
| 1886 | DWARFDIE function_die = |
| 1887 | GetDWARFCompileUnit(dc_cu)->LookupAddress(file_vm_addr); |
| 1888 | DWARFDIE block_die; |
| 1889 | if (function_die) { |
| 1890 | sc.function = |
| 1891 | sc.comp_unit->FindFunctionByUID(function_die.GetID()) |
| 1892 | .get(); |
| 1893 | if (sc.function == nullptr) |
| 1894 | sc.function = |
| 1895 | ParseFunction(*sc.comp_unit, function_die); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1896 | |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 1897 | if (sc.function && (resolve_scope & eSymbolContextBlock)) |
| 1898 | block_die = |
| 1899 | function_die.LookupDeepestBlock(file_vm_addr); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1900 | } |
| 1901 | |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 1902 | if (sc.function != nullptr) { |
| 1903 | Block &block = sc.function->GetBlock(true); |
| 1904 | |
| 1905 | if (block_die) |
| 1906 | sc.block = block.FindBlockByID(block_die.GetID()); |
| 1907 | else if (function_die) |
| 1908 | sc.block = block.FindBlockByID(function_die.GetID()); |
| 1909 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1910 | } |
| 1911 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1912 | |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 1913 | sc_list.Append(sc); |
| 1914 | line_idx = line_table->FindLineEntryIndexByFileIndex( |
| 1915 | line_idx + 1, file_idx, found_line, true, &sc.line_entry); |
| 1916 | } |
| 1917 | } |
| 1918 | } else if (file_spec_matches_cu_file_spec && !check_inlines) { |
| 1919 | // only append the context if we aren't looking for inline call |
| 1920 | // sites by file and line and if the file spec matches that of |
| 1921 | // the compile unit |
| 1922 | sc_list.Append(sc); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1923 | } |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 1924 | } else if (file_spec_matches_cu_file_spec && !check_inlines) { |
| 1925 | // only append the context if we aren't looking for inline call |
| 1926 | // sites by file and line and if the file spec matches that of |
| 1927 | // the compile unit |
| 1928 | sc_list.Append(sc); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1929 | } |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 1930 | |
| 1931 | if (!check_inlines) |
| 1932 | break; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1933 | } |
| 1934 | } |
| 1935 | } |
| 1936 | return sc_list.GetSize() - prev_size; |
| 1937 | } |
| 1938 | |
| Jim Ingham | 7fca8c0 | 2017-04-28 00:51:06 +0000 | [diff] [blame] | 1939 | void SymbolFileDWARF::PreloadSymbols() { |
| Jonas Devlieghere | 4f78c4f | 2018-10-22 20:14:36 +0000 | [diff] [blame] | 1940 | std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); |
| Pavel Labath | b13f033 | 2018-05-21 14:12:52 +0000 | [diff] [blame] | 1941 | m_index->Preload(); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1942 | } |
| 1943 | |
| Jonas Devlieghere | 4f78c4f | 2018-10-22 20:14:36 +0000 | [diff] [blame] | 1944 | std::recursive_mutex &SymbolFileDWARF::GetModuleMutex() const { |
| 1945 | lldb::ModuleSP module_sp(m_debug_map_module_wp.lock()); |
| 1946 | if (module_sp) |
| 1947 | return module_sp->GetMutex(); |
| 1948 | return GetObjectFile()->GetModule()->GetMutex(); |
| 1949 | } |
| 1950 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1951 | bool SymbolFileDWARF::DeclContextMatchesThisSymbolFile( |
| 1952 | const lldb_private::CompilerDeclContext *decl_ctx) { |
| 1953 | if (decl_ctx == nullptr || !decl_ctx->IsValid()) { |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1954 | // Invalid namespace decl which means we aren't matching only things in |
| 1955 | // this symbol file, so return true to indicate it matches this symbol |
| 1956 | // file. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1957 | return true; |
| 1958 | } |
| 1959 | |
| 1960 | TypeSystem *decl_ctx_type_system = decl_ctx->GetTypeSystem(); |
| 1961 | TypeSystem *type_system = GetTypeSystemForLanguage( |
| 1962 | decl_ctx_type_system->GetMinimumLanguage(nullptr)); |
| 1963 | if (decl_ctx_type_system == type_system) |
| 1964 | return true; // The type systems match, return true |
| 1965 | |
| 1966 | // The namespace AST was valid, and it does not match... |
| 1967 | Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 1968 | |
| 1969 | if (log) |
| 1970 | GetObjectFile()->GetModule()->LogMessage( |
| 1971 | log, "Valid namespace does not match symbol file"); |
| 1972 | |
| 1973 | return false; |
| 1974 | } |
| 1975 | |
| 1976 | uint32_t SymbolFileDWARF::FindGlobalVariables( |
| Adrian Prantl | 0e4c482 | 2019-03-06 21:22:25 +0000 | [diff] [blame] | 1977 | ConstString name, const CompilerDeclContext *parent_decl_ctx, |
| Pavel Labath | 34cda14 | 2018-05-31 09:46:26 +0000 | [diff] [blame] | 1978 | uint32_t max_matches, VariableList &variables) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1979 | Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 1980 | |
| 1981 | if (log) |
| 1982 | GetObjectFile()->GetModule()->LogMessage( |
| Pavel Labath | 34cda14 | 2018-05-31 09:46:26 +0000 | [diff] [blame] | 1983 | log, |
| 1984 | "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", " |
| 1985 | "parent_decl_ctx=%p, max_matches=%u, variables)", |
| 1986 | name.GetCString(), static_cast<const void *>(parent_decl_ctx), |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1987 | max_matches); |
| 1988 | |
| 1989 | if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx)) |
| 1990 | return 0; |
| 1991 | |
| 1992 | DWARFDebugInfo *info = DebugInfo(); |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 1993 | if (info == nullptr) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1994 | return 0; |
| 1995 | |
| Pavel Labath | 34cda14 | 2018-05-31 09:46:26 +0000 | [diff] [blame] | 1996 | // Remember how many variables are in the list before we search. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1997 | const uint32_t original_size = variables.GetSize(); |
| 1998 | |
| Pavel Labath | e1d1875 | 2018-06-07 10:04:44 +0000 | [diff] [blame] | 1999 | llvm::StringRef basename; |
| 2000 | llvm::StringRef context; |
| Kuba Mracek | e5e9a6b | 2019-04-18 00:15:44 +0000 | [diff] [blame] | 2001 | bool name_is_mangled = (bool)Mangled(name); |
| Pavel Labath | e1d1875 | 2018-06-07 10:04:44 +0000 | [diff] [blame] | 2002 | |
| 2003 | if (!CPlusPlusLanguage::ExtractContextAndIdentifier(name.GetCString(), |
| 2004 | context, basename)) |
| 2005 | basename = name.GetStringRef(); |
| 2006 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2007 | DIEArray die_offsets; |
| Pavel Labath | e1d1875 | 2018-06-07 10:04:44 +0000 | [diff] [blame] | 2008 | m_index->GetGlobalVariables(ConstString(basename), die_offsets); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2009 | const size_t num_die_matches = die_offsets.size(); |
| 2010 | if (num_die_matches) { |
| 2011 | SymbolContext sc; |
| 2012 | sc.module_sp = m_obj_file->GetModule(); |
| 2013 | assert(sc.module_sp); |
| 2014 | |
| Pavel Labath | e1d1875 | 2018-06-07 10:04:44 +0000 | [diff] [blame] | 2015 | // Loop invariant: Variables up to this index have been checked for context |
| 2016 | // matches. |
| 2017 | uint32_t pruned_idx = original_size; |
| 2018 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2019 | bool done = false; |
| 2020 | for (size_t i = 0; i < num_die_matches && !done; ++i) { |
| 2021 | const DIERef &die_ref = die_offsets[i]; |
| 2022 | DWARFDIE die = GetDIE(die_ref); |
| 2023 | |
| 2024 | if (die) { |
| 2025 | switch (die.Tag()) { |
| 2026 | default: |
| 2027 | case DW_TAG_subprogram: |
| 2028 | case DW_TAG_inlined_subroutine: |
| 2029 | case DW_TAG_try_block: |
| 2030 | case DW_TAG_catch_block: |
| 2031 | break; |
| 2032 | |
| 2033 | case DW_TAG_variable: { |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 2034 | auto *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(die.GetCU()); |
| 2035 | if (!dwarf_cu) |
| 2036 | continue; |
| 2037 | sc.comp_unit = GetCompUnitForDWARFCompUnit(*dwarf_cu); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2038 | |
| 2039 | if (parent_decl_ctx) { |
| 2040 | DWARFASTParser *dwarf_ast = die.GetDWARFParser(); |
| 2041 | if (dwarf_ast) { |
| 2042 | CompilerDeclContext actual_parent_decl_ctx = |
| 2043 | dwarf_ast->GetDeclContextContainingUIDFromDWARF(die); |
| 2044 | if (!actual_parent_decl_ctx || |
| 2045 | actual_parent_decl_ctx != *parent_decl_ctx) |
| 2046 | continue; |
| 2047 | } |
| 2048 | } |
| 2049 | |
| 2050 | ParseVariables(sc, die, LLDB_INVALID_ADDRESS, false, false, |
| 2051 | &variables); |
| Pavel Labath | e1d1875 | 2018-06-07 10:04:44 +0000 | [diff] [blame] | 2052 | while (pruned_idx < variables.GetSize()) { |
| 2053 | VariableSP var_sp = variables.GetVariableAtIndex(pruned_idx); |
| Kuba Mracek | e5e9a6b | 2019-04-18 00:15:44 +0000 | [diff] [blame] | 2054 | if (name_is_mangled || |
| 2055 | var_sp->GetName().GetStringRef().contains(name.GetStringRef())) |
| Pavel Labath | e1d1875 | 2018-06-07 10:04:44 +0000 | [diff] [blame] | 2056 | ++pruned_idx; |
| 2057 | else |
| 2058 | variables.RemoveVariableAtIndex(pruned_idx); |
| 2059 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2060 | |
| 2061 | if (variables.GetSize() - original_size >= max_matches) |
| 2062 | done = true; |
| 2063 | } break; |
| 2064 | } |
| 2065 | } else { |
| Pavel Labath | 78b2cf7 | 2019-06-14 12:01:18 +0000 | [diff] [blame] | 2066 | m_index->ReportInvalidDIERef(die_ref, name.GetStringRef()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2067 | } |
| 2068 | } |
| 2069 | } |
| 2070 | |
| 2071 | // Return the number of variable that were appended to the list |
| 2072 | const uint32_t num_matches = variables.GetSize() - original_size; |
| 2073 | if (log && num_matches > 0) { |
| 2074 | GetObjectFile()->GetModule()->LogMessage( |
| Pavel Labath | 34cda14 | 2018-05-31 09:46:26 +0000 | [diff] [blame] | 2075 | log, |
| 2076 | "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", " |
| 2077 | "parent_decl_ctx=%p, max_matches=%u, variables) => %u", |
| 2078 | name.GetCString(), static_cast<const void *>(parent_decl_ctx), |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2079 | max_matches, num_matches); |
| 2080 | } |
| 2081 | return num_matches; |
| 2082 | } |
| 2083 | |
| 2084 | uint32_t SymbolFileDWARF::FindGlobalVariables(const RegularExpression ®ex, |
| Pavel Labath | 34cda14 | 2018-05-31 09:46:26 +0000 | [diff] [blame] | 2085 | uint32_t max_matches, |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2086 | VariableList &variables) { |
| 2087 | Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 2088 | |
| 2089 | if (log) { |
| 2090 | GetObjectFile()->GetModule()->LogMessage( |
| Pavel Labath | 34cda14 | 2018-05-31 09:46:26 +0000 | [diff] [blame] | 2091 | log, |
| 2092 | "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", " |
| 2093 | "max_matches=%u, variables)", |
| 2094 | regex.GetText().str().c_str(), max_matches); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2095 | } |
| 2096 | |
| 2097 | DWARFDebugInfo *info = DebugInfo(); |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 2098 | if (info == nullptr) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2099 | return 0; |
| 2100 | |
| Pavel Labath | 34cda14 | 2018-05-31 09:46:26 +0000 | [diff] [blame] | 2101 | // Remember how many variables are in the list before we search. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2102 | const uint32_t original_size = variables.GetSize(); |
| 2103 | |
| 2104 | DIEArray die_offsets; |
| Pavel Labath | b13f033 | 2018-05-21 14:12:52 +0000 | [diff] [blame] | 2105 | m_index->GetGlobalVariables(regex, die_offsets); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2106 | |
| 2107 | SymbolContext sc; |
| 2108 | sc.module_sp = m_obj_file->GetModule(); |
| 2109 | assert(sc.module_sp); |
| 2110 | |
| 2111 | const size_t num_matches = die_offsets.size(); |
| 2112 | if (num_matches) { |
| 2113 | for (size_t i = 0; i < num_matches; ++i) { |
| 2114 | const DIERef &die_ref = die_offsets[i]; |
| 2115 | DWARFDIE die = GetDIE(die_ref); |
| 2116 | |
| 2117 | if (die) { |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 2118 | DWARFCompileUnit *dwarf_cu = |
| 2119 | llvm::dyn_cast<DWARFCompileUnit>(die.GetCU()); |
| 2120 | if (!dwarf_cu) |
| 2121 | continue; |
| 2122 | sc.comp_unit = GetCompUnitForDWARFCompUnit(*dwarf_cu); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2123 | |
| 2124 | ParseVariables(sc, die, LLDB_INVALID_ADDRESS, false, false, &variables); |
| 2125 | |
| 2126 | if (variables.GetSize() - original_size >= max_matches) |
| 2127 | break; |
| Pavel Labath | b13f033 | 2018-05-21 14:12:52 +0000 | [diff] [blame] | 2128 | } else |
| Pavel Labath | 78b2cf7 | 2019-06-14 12:01:18 +0000 | [diff] [blame] | 2129 | m_index->ReportInvalidDIERef(die_ref, regex.GetText()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2130 | } |
| 2131 | } |
| 2132 | |
| 2133 | // Return the number of variable that were appended to the list |
| 2134 | return variables.GetSize() - original_size; |
| 2135 | } |
| 2136 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2137 | bool SymbolFileDWARF::ResolveFunction(const DWARFDIE &orig_die, |
| 2138 | bool include_inlines, |
| 2139 | SymbolContextList &sc_list) { |
| 2140 | SymbolContext sc; |
| 2141 | |
| 2142 | if (!orig_die) |
| 2143 | return false; |
| 2144 | |
| 2145 | // If we were passed a die that is not a function, just return false... |
| 2146 | if (!(orig_die.Tag() == DW_TAG_subprogram || |
| 2147 | (include_inlines && orig_die.Tag() == DW_TAG_inlined_subroutine))) |
| 2148 | return false; |
| 2149 | |
| 2150 | DWARFDIE die = orig_die; |
| 2151 | DWARFDIE inlined_die; |
| 2152 | if (die.Tag() == DW_TAG_inlined_subroutine) { |
| 2153 | inlined_die = die; |
| 2154 | |
| Jonas Devlieghere | 09ad8c8 | 2019-05-24 00:44:33 +0000 | [diff] [blame] | 2155 | while (true) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2156 | die = die.GetParent(); |
| 2157 | |
| 2158 | if (die) { |
| 2159 | if (die.Tag() == DW_TAG_subprogram) |
| 2160 | break; |
| 2161 | } else |
| 2162 | break; |
| 2163 | } |
| 2164 | } |
| 2165 | assert(die && die.Tag() == DW_TAG_subprogram); |
| 2166 | if (GetFunction(die, sc)) { |
| 2167 | Address addr; |
| 2168 | // Parse all blocks if needed |
| 2169 | if (inlined_die) { |
| 2170 | Block &function_block = sc.function->GetBlock(true); |
| 2171 | sc.block = function_block.FindBlockByID(inlined_die.GetID()); |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 2172 | if (sc.block == nullptr) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2173 | sc.block = function_block.FindBlockByID(inlined_die.GetOffset()); |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 2174 | if (sc.block == nullptr || !sc.block->GetStartAddress(addr)) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2175 | addr.Clear(); |
| 2176 | } else { |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 2177 | sc.block = nullptr; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2178 | addr = sc.function->GetAddressRange().GetBaseAddress(); |
| 2179 | } |
| 2180 | |
| 2181 | if (addr.IsValid()) { |
| 2182 | sc_list.Append(sc); |
| 2183 | return true; |
| 2184 | } |
| 2185 | } |
| 2186 | |
| 2187 | return false; |
| 2188 | } |
| 2189 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2190 | bool SymbolFileDWARF::DIEInDeclContext(const CompilerDeclContext *decl_ctx, |
| 2191 | const DWARFDIE &die) { |
| 2192 | // If we have no parent decl context to match this DIE matches, and if the |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2193 | // parent decl context isn't valid, we aren't trying to look for any |
| 2194 | // particular decl context so any die matches. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2195 | if (decl_ctx == nullptr || !decl_ctx->IsValid()) |
| 2196 | return true; |
| 2197 | |
| 2198 | if (die) { |
| 2199 | DWARFASTParser *dwarf_ast = die.GetDWARFParser(); |
| 2200 | if (dwarf_ast) { |
| 2201 | CompilerDeclContext actual_decl_ctx = |
| 2202 | dwarf_ast->GetDeclContextContainingUIDFromDWARF(die); |
| 2203 | if (actual_decl_ctx) |
| Raphael Isemann | a946997 | 2019-03-12 07:45:04 +0000 | [diff] [blame] | 2204 | return decl_ctx->IsContainedInLookup(actual_decl_ctx); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2205 | } |
| 2206 | } |
| 2207 | return false; |
| 2208 | } |
| 2209 | |
| Zachary Turner | 117b1fa | 2018-10-25 20:45:40 +0000 | [diff] [blame] | 2210 | uint32_t SymbolFileDWARF::FindFunctions( |
| Adrian Prantl | 0e4c482 | 2019-03-06 21:22:25 +0000 | [diff] [blame] | 2211 | ConstString name, const CompilerDeclContext *parent_decl_ctx, |
| Zachary Turner | 117b1fa | 2018-10-25 20:45:40 +0000 | [diff] [blame] | 2212 | FunctionNameType name_type_mask, bool include_inlines, bool append, |
| 2213 | SymbolContextList &sc_list) { |
| Pavel Labath | f9d1647 | 2017-05-15 13:02:37 +0000 | [diff] [blame] | 2214 | static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); |
| 2215 | Timer scoped_timer(func_cat, "SymbolFileDWARF::FindFunctions (name = '%s')", |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2216 | name.AsCString()); |
| 2217 | |
| 2218 | // eFunctionNameTypeAuto should be pre-resolved by a call to |
| Dawn Perchik | 9d9474ba | 2016-09-30 20:38:33 +0000 | [diff] [blame] | 2219 | // Module::LookupInfo::LookupInfo() |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2220 | assert((name_type_mask & eFunctionNameTypeAuto) == 0); |
| 2221 | |
| 2222 | Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 2223 | |
| 2224 | if (log) { |
| 2225 | GetObjectFile()->GetModule()->LogMessage( |
| 2226 | log, "SymbolFileDWARF::FindFunctions (name=\"%s\", " |
| 2227 | "name_type_mask=0x%x, append=%u, sc_list)", |
| 2228 | name.GetCString(), name_type_mask, append); |
| 2229 | } |
| 2230 | |
| 2231 | // If we aren't appending the results to this list, then clear the list |
| 2232 | if (!append) |
| 2233 | sc_list.Clear(); |
| 2234 | |
| 2235 | if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx)) |
| 2236 | return 0; |
| 2237 | |
| 2238 | // If name is empty then we won't find anything. |
| 2239 | if (name.IsEmpty()) |
| 2240 | return 0; |
| 2241 | |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2242 | // Remember how many sc_list are in the list before we search in case we are |
| 2243 | // appending the results to a variable list. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2244 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2245 | const uint32_t original_size = sc_list.GetSize(); |
| 2246 | |
| Pavel Labath | 5af11ab | 2018-06-05 10:33:56 +0000 | [diff] [blame] | 2247 | llvm::DenseSet<const DWARFDebugInfoEntry *> resolved_dies; |
| 2248 | DIEArray offsets; |
| 2249 | CompilerDeclContext empty_decl_ctx; |
| 2250 | if (!parent_decl_ctx) |
| 2251 | parent_decl_ctx = &empty_decl_ctx; |
| 2252 | |
| 2253 | std::vector<DWARFDIE> dies; |
| Pavel Labath | 3b92698 | 2019-06-21 07:56:50 +0000 | [diff] [blame] | 2254 | m_index->GetFunctions(name, *this, *parent_decl_ctx, name_type_mask, dies); |
| Pavel Labath | 5af11ab | 2018-06-05 10:33:56 +0000 | [diff] [blame] | 2255 | for (const DWARFDIE &die: dies) { |
| 2256 | if (resolved_dies.insert(die.GetDIE()).second) |
| 2257 | ResolveFunction(die, include_inlines, sc_list); |
| 2258 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2259 | |
| 2260 | // Return the number of variable that were appended to the list |
| 2261 | const uint32_t num_matches = sc_list.GetSize() - original_size; |
| 2262 | |
| 2263 | if (log && num_matches > 0) { |
| 2264 | GetObjectFile()->GetModule()->LogMessage( |
| 2265 | log, "SymbolFileDWARF::FindFunctions (name=\"%s\", " |
| 2266 | "name_type_mask=0x%x, include_inlines=%d, append=%u, sc_list) => " |
| 2267 | "%u", |
| 2268 | name.GetCString(), name_type_mask, include_inlines, append, |
| 2269 | num_matches); |
| 2270 | } |
| 2271 | return num_matches; |
| 2272 | } |
| 2273 | |
| 2274 | uint32_t SymbolFileDWARF::FindFunctions(const RegularExpression ®ex, |
| 2275 | bool include_inlines, bool append, |
| 2276 | SymbolContextList &sc_list) { |
| Pavel Labath | f9d1647 | 2017-05-15 13:02:37 +0000 | [diff] [blame] | 2277 | static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); |
| 2278 | Timer scoped_timer(func_cat, "SymbolFileDWARF::FindFunctions (regex = '%s')", |
| Zachary Turner | 95eae42 | 2016-09-21 16:01:28 +0000 | [diff] [blame] | 2279 | regex.GetText().str().c_str()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2280 | |
| 2281 | Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 2282 | |
| 2283 | if (log) { |
| 2284 | GetObjectFile()->GetModule()->LogMessage( |
| 2285 | log, |
| 2286 | "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)", |
| Zachary Turner | 95eae42 | 2016-09-21 16:01:28 +0000 | [diff] [blame] | 2287 | regex.GetText().str().c_str(), append); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2288 | } |
| 2289 | |
| 2290 | // If we aren't appending the results to this list, then clear the list |
| 2291 | if (!append) |
| 2292 | sc_list.Clear(); |
| 2293 | |
| Pavel Labath | b13f033 | 2018-05-21 14:12:52 +0000 | [diff] [blame] | 2294 | DWARFDebugInfo *info = DebugInfo(); |
| 2295 | if (!info) |
| 2296 | return 0; |
| 2297 | |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2298 | // Remember how many sc_list are in the list before we search in case we are |
| 2299 | // appending the results to a variable list. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2300 | uint32_t original_size = sc_list.GetSize(); |
| 2301 | |
| Pavel Labath | 6de9c79 | 2018-06-05 12:13:22 +0000 | [diff] [blame] | 2302 | DIEArray offsets; |
| 2303 | m_index->GetFunctions(regex, offsets); |
| 2304 | |
| Pavel Labath | a3ee1e7 | 2018-06-08 10:31:55 +0000 | [diff] [blame] | 2305 | llvm::DenseSet<const DWARFDebugInfoEntry *> resolved_dies; |
| 2306 | for (DIERef ref : offsets) { |
| 2307 | DWARFDIE die = info->GetDIE(ref); |
| 2308 | if (!die) { |
| Pavel Labath | 78b2cf7 | 2019-06-14 12:01:18 +0000 | [diff] [blame] | 2309 | m_index->ReportInvalidDIERef(ref, regex.GetText()); |
| Pavel Labath | a3ee1e7 | 2018-06-08 10:31:55 +0000 | [diff] [blame] | 2310 | continue; |
| 2311 | } |
| 2312 | if (resolved_dies.insert(die.GetDIE()).second) |
| 2313 | ResolveFunction(die, include_inlines, sc_list); |
| 2314 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2315 | |
| 2316 | // Return the number of variable that were appended to the list |
| 2317 | return sc_list.GetSize() - original_size; |
| 2318 | } |
| 2319 | |
| 2320 | void SymbolFileDWARF::GetMangledNamesForFunction( |
| 2321 | const std::string &scope_qualified_name, |
| 2322 | std::vector<ConstString> &mangled_names) { |
| 2323 | DWARFDebugInfo *info = DebugInfo(); |
| 2324 | uint32_t num_comp_units = 0; |
| 2325 | if (info) |
| Jan Kratochvil | 6056273 | 2019-05-10 17:14:37 +0000 | [diff] [blame] | 2326 | num_comp_units = info->GetNumUnits(); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2327 | |
| 2328 | for (uint32_t i = 0; i < num_comp_units; i++) { |
| Jan Kratochvil | 6056273 | 2019-05-10 17:14:37 +0000 | [diff] [blame] | 2329 | DWARFUnit *cu = info->GetUnitAtIndex(i); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2330 | if (cu == nullptr) |
| 2331 | continue; |
| 2332 | |
| 2333 | SymbolFileDWARFDwo *dwo = cu->GetDwoSymbolFile(); |
| 2334 | if (dwo) |
| 2335 | dwo->GetMangledNamesForFunction(scope_qualified_name, mangled_names); |
| 2336 | } |
| 2337 | |
| Pavel Labath | a71ce4f | 2019-06-17 07:32:56 +0000 | [diff] [blame] | 2338 | for (lldb::user_id_t uid : |
| 2339 | m_function_scope_qualified_name_map.lookup(scope_qualified_name)) { |
| 2340 | DWARFDIE die = GetDIE(uid); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2341 | mangled_names.push_back(ConstString(die.GetMangledName())); |
| 2342 | } |
| 2343 | } |
| 2344 | |
| 2345 | uint32_t SymbolFileDWARF::FindTypes( |
| Adrian Prantl | 0e4c482 | 2019-03-06 21:22:25 +0000 | [diff] [blame] | 2346 | ConstString name, const CompilerDeclContext *parent_decl_ctx, |
| Zachary Turner | 576495e | 2019-01-14 22:41:21 +0000 | [diff] [blame] | 2347 | bool append, uint32_t max_matches, |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2348 | llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files, |
| 2349 | TypeMap &types) { |
| 2350 | // If we aren't appending the results to this list, then clear the list |
| 2351 | if (!append) |
| 2352 | types.Clear(); |
| 2353 | |
| 2354 | // Make sure we haven't already searched this SymbolFile before... |
| 2355 | if (searched_symbol_files.count(this)) |
| 2356 | return 0; |
| 2357 | else |
| 2358 | searched_symbol_files.insert(this); |
| 2359 | |
| 2360 | DWARFDebugInfo *info = DebugInfo(); |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 2361 | if (info == nullptr) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2362 | return 0; |
| 2363 | |
| 2364 | Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 2365 | |
| 2366 | if (log) { |
| 2367 | if (parent_decl_ctx) |
| 2368 | GetObjectFile()->GetModule()->LogMessage( |
| 2369 | log, "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx = " |
| 2370 | "%p (\"%s\"), append=%u, max_matches=%u, type_list)", |
| 2371 | name.GetCString(), static_cast<const void *>(parent_decl_ctx), |
| 2372 | parent_decl_ctx->GetName().AsCString("<NULL>"), append, max_matches); |
| 2373 | else |
| 2374 | GetObjectFile()->GetModule()->LogMessage( |
| 2375 | log, "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx = " |
| 2376 | "NULL, append=%u, max_matches=%u, type_list)", |
| 2377 | name.GetCString(), append, max_matches); |
| 2378 | } |
| 2379 | |
| 2380 | if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx)) |
| 2381 | return 0; |
| 2382 | |
| 2383 | DIEArray die_offsets; |
| Pavel Labath | b13f033 | 2018-05-21 14:12:52 +0000 | [diff] [blame] | 2384 | m_index->GetTypes(name, die_offsets); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2385 | const size_t num_die_matches = die_offsets.size(); |
| 2386 | |
| 2387 | if (num_die_matches) { |
| 2388 | const uint32_t initial_types_size = types.GetSize(); |
| 2389 | for (size_t i = 0; i < num_die_matches; ++i) { |
| 2390 | const DIERef &die_ref = die_offsets[i]; |
| 2391 | DWARFDIE die = GetDIE(die_ref); |
| 2392 | |
| 2393 | if (die) { |
| 2394 | if (!DIEInDeclContext(parent_decl_ctx, die)) |
| 2395 | continue; // The containing decl contexts don't match |
| 2396 | |
| 2397 | Type *matching_type = ResolveType(die, true, true); |
| 2398 | if (matching_type) { |
| 2399 | // We found a type pointer, now find the shared pointer form our type |
| 2400 | // list |
| 2401 | types.InsertUnique(matching_type->shared_from_this()); |
| 2402 | if (types.GetSize() >= max_matches) |
| 2403 | break; |
| 2404 | } |
| 2405 | } else { |
| Pavel Labath | 78b2cf7 | 2019-06-14 12:01:18 +0000 | [diff] [blame] | 2406 | m_index->ReportInvalidDIERef(die_ref, name.GetStringRef()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2407 | } |
| 2408 | } |
| 2409 | const uint32_t num_matches = types.GetSize() - initial_types_size; |
| 2410 | if (log && num_matches) { |
| 2411 | if (parent_decl_ctx) { |
| 2412 | GetObjectFile()->GetModule()->LogMessage( |
| 2413 | log, "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx " |
| 2414 | "= %p (\"%s\"), append=%u, max_matches=%u, type_list) => %u", |
| 2415 | name.GetCString(), static_cast<const void *>(parent_decl_ctx), |
| 2416 | parent_decl_ctx->GetName().AsCString("<NULL>"), append, max_matches, |
| 2417 | num_matches); |
| 2418 | } else { |
| 2419 | GetObjectFile()->GetModule()->LogMessage( |
| 2420 | log, "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx " |
| 2421 | "= NULL, append=%u, max_matches=%u, type_list) => %u", |
| 2422 | name.GetCString(), append, max_matches, num_matches); |
| 2423 | } |
| 2424 | } |
| 2425 | return num_matches; |
| 2426 | } else { |
| 2427 | UpdateExternalModuleListIfNeeded(); |
| 2428 | |
| 2429 | for (const auto &pair : m_external_type_modules) { |
| 2430 | ModuleSP external_module_sp = pair.second; |
| 2431 | if (external_module_sp) { |
| 2432 | SymbolVendor *sym_vendor = external_module_sp->GetSymbolVendor(); |
| 2433 | if (sym_vendor) { |
| 2434 | const uint32_t num_external_matches = |
| Zachary Turner | 576495e | 2019-01-14 22:41:21 +0000 | [diff] [blame] | 2435 | sym_vendor->FindTypes(name, parent_decl_ctx, append, max_matches, |
| 2436 | searched_symbol_files, types); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2437 | if (num_external_matches) |
| 2438 | return num_external_matches; |
| 2439 | } |
| 2440 | } |
| 2441 | } |
| 2442 | } |
| 2443 | |
| 2444 | return 0; |
| 2445 | } |
| 2446 | |
| 2447 | size_t SymbolFileDWARF::FindTypes(const std::vector<CompilerContext> &context, |
| 2448 | bool append, TypeMap &types) { |
| 2449 | if (!append) |
| 2450 | types.Clear(); |
| 2451 | |
| 2452 | if (context.empty()) |
| 2453 | return 0; |
| 2454 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2455 | ConstString name = context.back().name; |
| 2456 | |
| 2457 | if (!name) |
| 2458 | return 0; |
| 2459 | |
| Pavel Labath | b13f033 | 2018-05-21 14:12:52 +0000 | [diff] [blame] | 2460 | DIEArray die_offsets; |
| 2461 | m_index->GetTypes(name, die_offsets); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2462 | const size_t num_die_matches = die_offsets.size(); |
| 2463 | |
| 2464 | if (num_die_matches) { |
| 2465 | size_t num_matches = 0; |
| 2466 | for (size_t i = 0; i < num_die_matches; ++i) { |
| 2467 | const DIERef &die_ref = die_offsets[i]; |
| 2468 | DWARFDIE die = GetDIE(die_ref); |
| 2469 | |
| 2470 | if (die) { |
| 2471 | std::vector<CompilerContext> die_context; |
| Adrian Prantl | 95280c948 | 2019-01-07 22:47:17 +0000 | [diff] [blame] | 2472 | die.GetDeclContext(die_context); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2473 | if (die_context != context) |
| 2474 | continue; |
| 2475 | |
| 2476 | Type *matching_type = ResolveType(die, true, true); |
| 2477 | if (matching_type) { |
| 2478 | // We found a type pointer, now find the shared pointer form our type |
| 2479 | // list |
| 2480 | types.InsertUnique(matching_type->shared_from_this()); |
| 2481 | ++num_matches; |
| 2482 | } |
| 2483 | } else { |
| Pavel Labath | 78b2cf7 | 2019-06-14 12:01:18 +0000 | [diff] [blame] | 2484 | m_index->ReportInvalidDIERef(die_ref, name.GetStringRef()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2485 | } |
| 2486 | } |
| 2487 | return num_matches; |
| 2488 | } |
| 2489 | return 0; |
| 2490 | } |
| 2491 | |
| 2492 | CompilerDeclContext |
| Adrian Prantl | 0e4c482 | 2019-03-06 21:22:25 +0000 | [diff] [blame] | 2493 | SymbolFileDWARF::FindNamespace(ConstString name, |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2494 | const CompilerDeclContext *parent_decl_ctx) { |
| 2495 | Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| 2496 | |
| 2497 | if (log) { |
| 2498 | GetObjectFile()->GetModule()->LogMessage( |
| 2499 | log, "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")", |
| 2500 | name.GetCString()); |
| 2501 | } |
| 2502 | |
| 2503 | CompilerDeclContext namespace_decl_ctx; |
| 2504 | |
| 2505 | if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx)) |
| 2506 | return namespace_decl_ctx; |
| 2507 | |
| 2508 | DWARFDebugInfo *info = DebugInfo(); |
| 2509 | if (info) { |
| 2510 | DIEArray die_offsets; |
| Pavel Labath | b13f033 | 2018-05-21 14:12:52 +0000 | [diff] [blame] | 2511 | m_index->GetNamespaces(name, die_offsets); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2512 | const size_t num_matches = die_offsets.size(); |
| 2513 | if (num_matches) { |
| 2514 | for (size_t i = 0; i < num_matches; ++i) { |
| 2515 | const DIERef &die_ref = die_offsets[i]; |
| 2516 | DWARFDIE die = GetDIE(die_ref); |
| 2517 | |
| 2518 | if (die) { |
| 2519 | if (!DIEInDeclContext(parent_decl_ctx, die)) |
| 2520 | continue; // The containing decl contexts don't match |
| 2521 | |
| 2522 | DWARFASTParser *dwarf_ast = die.GetDWARFParser(); |
| 2523 | if (dwarf_ast) { |
| 2524 | namespace_decl_ctx = dwarf_ast->GetDeclContextForUIDFromDWARF(die); |
| 2525 | if (namespace_decl_ctx) |
| 2526 | break; |
| 2527 | } |
| 2528 | } else { |
| Pavel Labath | 78b2cf7 | 2019-06-14 12:01:18 +0000 | [diff] [blame] | 2529 | m_index->ReportInvalidDIERef(die_ref, name.GetStringRef()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2530 | } |
| 2531 | } |
| 2532 | } |
| 2533 | } |
| 2534 | if (log && namespace_decl_ctx) { |
| 2535 | GetObjectFile()->GetModule()->LogMessage( |
| 2536 | log, "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => " |
| 2537 | "CompilerDeclContext(%p/%p) \"%s\"", |
| 2538 | name.GetCString(), |
| 2539 | static_cast<const void *>(namespace_decl_ctx.GetTypeSystem()), |
| 2540 | static_cast<const void *>(namespace_decl_ctx.GetOpaqueDeclContext()), |
| 2541 | namespace_decl_ctx.GetName().AsCString("<NULL>")); |
| 2542 | } |
| 2543 | |
| 2544 | return namespace_decl_ctx; |
| 2545 | } |
| 2546 | |
| 2547 | TypeSP SymbolFileDWARF::GetTypeForDIE(const DWARFDIE &die, |
| 2548 | bool resolve_function_context) { |
| 2549 | TypeSP type_sp; |
| 2550 | if (die) { |
| 2551 | Type *type_ptr = GetDIEToType().lookup(die.GetDIE()); |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 2552 | if (type_ptr == nullptr) { |
| Pavel Labath | ad17e28 | 2019-06-13 11:22:47 +0000 | [diff] [blame] | 2553 | SymbolContextScope *scope; |
| 2554 | if (auto *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(die.GetCU())) |
| 2555 | scope = GetCompUnitForDWARFCompUnit(*dwarf_cu); |
| 2556 | else |
| 2557 | scope = GetObjectFile()->GetModule().get(); |
| 2558 | assert(scope); |
| 2559 | SymbolContext sc(scope); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2560 | const DWARFDebugInfoEntry *parent_die = die.GetParent().GetDIE(); |
| 2561 | while (parent_die != nullptr) { |
| 2562 | if (parent_die->Tag() == DW_TAG_subprogram) |
| 2563 | break; |
| 2564 | parent_die = parent_die->GetParent(); |
| 2565 | } |
| 2566 | SymbolContext sc_backup = sc; |
| 2567 | if (resolve_function_context && parent_die != nullptr && |
| 2568 | !GetFunction(DWARFDIE(die.GetCU(), parent_die), sc)) |
| 2569 | sc = sc_backup; |
| 2570 | |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 2571 | type_sp = ParseType(sc, die, nullptr); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2572 | } else if (type_ptr != DIE_IS_BEING_PARSED) { |
| 2573 | // Grab the existing type from the master types lists |
| 2574 | type_sp = type_ptr->shared_from_this(); |
| 2575 | } |
| 2576 | } |
| 2577 | return type_sp; |
| 2578 | } |
| 2579 | |
| 2580 | DWARFDIE |
| 2581 | SymbolFileDWARF::GetDeclContextDIEContainingDIE(const DWARFDIE &orig_die) { |
| 2582 | if (orig_die) { |
| 2583 | DWARFDIE die = orig_die; |
| 2584 | |
| 2585 | while (die) { |
| 2586 | // If this is the original DIE that we are searching for a declaration |
| 2587 | // for, then don't look in the cache as we don't want our own decl |
| 2588 | // context to be our decl context... |
| 2589 | if (orig_die != die) { |
| 2590 | switch (die.Tag()) { |
| 2591 | case DW_TAG_compile_unit: |
| Jan Kratochvil | 55c84b1 | 2018-04-30 16:04:32 +0000 | [diff] [blame] | 2592 | case DW_TAG_partial_unit: |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2593 | case DW_TAG_namespace: |
| 2594 | case DW_TAG_structure_type: |
| 2595 | case DW_TAG_union_type: |
| 2596 | case DW_TAG_class_type: |
| 2597 | case DW_TAG_lexical_block: |
| 2598 | case DW_TAG_subprogram: |
| 2599 | return die; |
| Sean Callanan | b494578 | 2017-04-24 22:11:10 +0000 | [diff] [blame] | 2600 | case DW_TAG_inlined_subroutine: { |
| 2601 | DWARFDIE abs_die = die.GetReferencedDIE(DW_AT_abstract_origin); |
| 2602 | if (abs_die) { |
| 2603 | return abs_die; |
| 2604 | } |
| 2605 | break; |
| 2606 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2607 | default: |
| 2608 | break; |
| 2609 | } |
| 2610 | } |
| 2611 | |
| 2612 | DWARFDIE spec_die = die.GetReferencedDIE(DW_AT_specification); |
| 2613 | if (spec_die) { |
| 2614 | DWARFDIE decl_ctx_die = GetDeclContextDIEContainingDIE(spec_die); |
| 2615 | if (decl_ctx_die) |
| 2616 | return decl_ctx_die; |
| 2617 | } |
| 2618 | |
| 2619 | DWARFDIE abs_die = die.GetReferencedDIE(DW_AT_abstract_origin); |
| 2620 | if (abs_die) { |
| 2621 | DWARFDIE decl_ctx_die = GetDeclContextDIEContainingDIE(abs_die); |
| 2622 | if (decl_ctx_die) |
| 2623 | return decl_ctx_die; |
| 2624 | } |
| 2625 | |
| 2626 | die = die.GetParent(); |
| 2627 | } |
| 2628 | } |
| 2629 | return DWARFDIE(); |
| 2630 | } |
| 2631 | |
| 2632 | Symbol * |
| Adrian Prantl | 0e4c482 | 2019-03-06 21:22:25 +0000 | [diff] [blame] | 2633 | SymbolFileDWARF::GetObjCClassSymbol(ConstString objc_class_name) { |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 2634 | Symbol *objc_class_symbol = nullptr; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2635 | if (m_obj_file) { |
| 2636 | Symtab *symtab = m_obj_file->GetSymtab(); |
| 2637 | if (symtab) { |
| 2638 | objc_class_symbol = symtab->FindFirstSymbolWithNameAndType( |
| 2639 | objc_class_name, eSymbolTypeObjCClass, Symtab::eDebugNo, |
| 2640 | Symtab::eVisibilityAny); |
| 2641 | } |
| 2642 | } |
| 2643 | return objc_class_symbol; |
| 2644 | } |
| 2645 | |
| 2646 | // Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2647 | // they don't then we can end up looking through all class types for a complete |
| 2648 | // type and never find the full definition. We need to know if this attribute |
| 2649 | // is supported, so we determine this here and cache th result. We also need to |
| 2650 | // worry about the debug map |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2651 | // DWARF file |
| 2652 | // if we are doing darwin DWARF in .o file debugging. |
| 2653 | bool SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type( |
| Jan Kratochvil | c4d6575 | 2018-03-18 20:11:02 +0000 | [diff] [blame] | 2654 | DWARFUnit *cu) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2655 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate) { |
| 2656 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo; |
| 2657 | if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type()) |
| 2658 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; |
| 2659 | else { |
| 2660 | DWARFDebugInfo *debug_info = DebugInfo(); |
| 2661 | const uint32_t num_compile_units = GetNumCompileUnits(); |
| 2662 | for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) { |
| Jan Kratochvil | 6056273 | 2019-05-10 17:14:37 +0000 | [diff] [blame] | 2663 | DWARFUnit *dwarf_cu = debug_info->GetUnitAtIndex(cu_idx); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2664 | if (dwarf_cu != cu && |
| 2665 | dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type()) { |
| 2666 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; |
| 2667 | break; |
| 2668 | } |
| 2669 | } |
| 2670 | } |
| 2671 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && |
| 2672 | GetDebugMapSymfile()) |
| 2673 | return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type(this); |
| 2674 | } |
| 2675 | return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes; |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 2676 | } |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 2677 | |
| 2678 | // This function can be used when a DIE is found that is a forward declaration |
| 2679 | // DIE and we want to try and find a type that has the complete definition. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2680 | TypeSP SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE( |
| Adrian Prantl | 0e4c482 | 2019-03-06 21:22:25 +0000 | [diff] [blame] | 2681 | const DWARFDIE &die, ConstString type_name, |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2682 | bool must_be_implementation) { |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 2683 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2684 | TypeSP type_sp; |
| 2685 | |
| 2686 | if (!type_name || (must_be_implementation && !GetObjCClassSymbol(type_name))) |
| 2687 | return type_sp; |
| 2688 | |
| 2689 | DIEArray die_offsets; |
| Pavel Labath | b13f033 | 2018-05-21 14:12:52 +0000 | [diff] [blame] | 2690 | m_index->GetCompleteObjCClass(type_name, must_be_implementation, die_offsets); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2691 | |
| 2692 | const size_t num_matches = die_offsets.size(); |
| 2693 | |
| 2694 | if (num_matches) { |
| 2695 | for (size_t i = 0; i < num_matches; ++i) { |
| 2696 | const DIERef &die_ref = die_offsets[i]; |
| 2697 | DWARFDIE type_die = GetDIE(die_ref); |
| 2698 | |
| 2699 | if (type_die) { |
| 2700 | bool try_resolving_type = false; |
| 2701 | |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2702 | // Don't try and resolve the DIE we are looking for with the DIE |
| 2703 | // itself! |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2704 | if (type_die != die) { |
| 2705 | switch (type_die.Tag()) { |
| 2706 | case DW_TAG_class_type: |
| 2707 | case DW_TAG_structure_type: |
| 2708 | try_resolving_type = true; |
| 2709 | break; |
| 2710 | default: |
| 2711 | break; |
| 2712 | } |
| 2713 | } |
| 2714 | |
| 2715 | if (try_resolving_type) { |
| 2716 | if (must_be_implementation && |
| 2717 | type_die.Supports_DW_AT_APPLE_objc_complete_type()) |
| 2718 | try_resolving_type = type_die.GetAttributeValueAsUnsigned( |
| 2719 | DW_AT_APPLE_objc_complete_type, 0); |
| 2720 | |
| 2721 | if (try_resolving_type) { |
| 2722 | Type *resolved_type = ResolveType(type_die, false, true); |
| 2723 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) { |
| 2724 | DEBUG_PRINTF("resolved 0x%8.8" PRIx64 " from %s to 0x%8.8" PRIx64 |
| 2725 | " (cu 0x%8.8" PRIx64 ")\n", |
| 2726 | die.GetID(), |
| 2727 | m_obj_file->GetFileSpec().GetFilename().AsCString( |
| 2728 | "<Unknown>"), |
| 2729 | type_die.GetID(), type_cu->GetID()); |
| 2730 | |
| 2731 | if (die) |
| 2732 | GetDIEToType()[die.GetDIE()] = resolved_type; |
| 2733 | type_sp = resolved_type->shared_from_this(); |
| 2734 | break; |
| 2735 | } |
| 2736 | } |
| 2737 | } |
| 2738 | } else { |
| Pavel Labath | 78b2cf7 | 2019-06-14 12:01:18 +0000 | [diff] [blame] | 2739 | m_index->ReportInvalidDIERef(die_ref, type_name.GetStringRef()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2740 | } |
| 2741 | } |
| 2742 | } |
| 2743 | return type_sp; |
| 2744 | } |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 2745 | |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2746 | // This function helps to ensure that the declaration contexts match for two |
| 2747 | // different DIEs. Often times debug information will refer to a forward |
| 2748 | // declaration of a type (the equivalent of "struct my_struct;". There will |
| 2749 | // often be a declaration of that type elsewhere that has the full definition. |
| 2750 | // When we go looking for the full type "my_struct", we will find one or more |
| 2751 | // matches in the accelerator tables and we will then need to make sure the |
| 2752 | // type was in the same declaration context as the original DIE. This function |
| 2753 | // can efficiently compare two DIEs and will return true when the declaration |
| 2754 | // context matches, and false when they don't. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2755 | bool SymbolFileDWARF::DIEDeclContextsMatch(const DWARFDIE &die1, |
| 2756 | const DWARFDIE &die2) { |
| 2757 | if (die1 == die2) |
| 2758 | return true; |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 2759 | |
| Zachary Turner | 0eaa6d5 | 2019-03-12 20:50:46 +0000 | [diff] [blame] | 2760 | std::vector<DWARFDIE> decl_ctx_1; |
| 2761 | std::vector<DWARFDIE> decl_ctx_2; |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2762 | // The declaration DIE stack is a stack of the declaration context DIEs all |
| 2763 | // the way back to the compile unit. If a type "T" is declared inside a class |
| 2764 | // "B", and class "B" is declared inside a class "A" and class "A" is in a |
| 2765 | // namespace "lldb", and the namespace is in a compile unit, there will be a |
| 2766 | // stack of DIEs: |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2767 | // |
| 2768 | // [0] DW_TAG_class_type for "B" |
| 2769 | // [1] DW_TAG_class_type for "A" |
| 2770 | // [2] DW_TAG_namespace for "lldb" |
| Jan Kratochvil | 55c84b1 | 2018-04-30 16:04:32 +0000 | [diff] [blame] | 2771 | // [3] DW_TAG_compile_unit or DW_TAG_partial_unit for the source file. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2772 | // |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2773 | // We grab both contexts and make sure that everything matches all the way |
| 2774 | // back to the compiler unit. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2775 | |
| 2776 | // First lets grab the decl contexts for both DIEs |
| Zachary Turner | 0eaa6d5 | 2019-03-12 20:50:46 +0000 | [diff] [blame] | 2777 | decl_ctx_1 = die1.GetDeclContextDIEs(); |
| 2778 | decl_ctx_2 = die2.GetDeclContextDIEs(); |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2779 | // Make sure the context arrays have the same size, otherwise we are done |
| Zachary Turner | 0eaa6d5 | 2019-03-12 20:50:46 +0000 | [diff] [blame] | 2780 | const size_t count1 = decl_ctx_1.size(); |
| 2781 | const size_t count2 = decl_ctx_2.size(); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2782 | if (count1 != count2) |
| 2783 | return false; |
| 2784 | |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2785 | // Make sure the DW_TAG values match all the way back up the compile unit. If |
| 2786 | // they don't, then we are done. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2787 | DWARFDIE decl_ctx_die1; |
| 2788 | DWARFDIE decl_ctx_die2; |
| 2789 | size_t i; |
| 2790 | for (i = 0; i < count1; i++) { |
| Zachary Turner | 0eaa6d5 | 2019-03-12 20:50:46 +0000 | [diff] [blame] | 2791 | decl_ctx_die1 = decl_ctx_1[i]; |
| 2792 | decl_ctx_die2 = decl_ctx_2[i]; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2793 | if (decl_ctx_die1.Tag() != decl_ctx_die2.Tag()) |
| 2794 | return false; |
| 2795 | } |
| Adrian Prantl | 28f7466 | 2019-03-07 00:14:20 +0000 | [diff] [blame] | 2796 | #ifndef NDEBUG |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 2797 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2798 | // Make sure the top item in the decl context die array is always |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2799 | // DW_TAG_compile_unit or DW_TAG_partial_unit. If it isn't then |
| 2800 | // something went wrong in the DWARFDIE::GetDeclContextDIEs() |
| 2801 | // function. |
| Zachary Turner | 0eaa6d5 | 2019-03-12 20:50:46 +0000 | [diff] [blame] | 2802 | dw_tag_t cu_tag = decl_ctx_1[count1 - 1].Tag(); |
| Jan Kratochvil | 55c84b1 | 2018-04-30 16:04:32 +0000 | [diff] [blame] | 2803 | UNUSED_IF_ASSERT_DISABLED(cu_tag); |
| 2804 | assert(cu_tag == DW_TAG_compile_unit || cu_tag == DW_TAG_partial_unit); |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 2805 | |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 2806 | #endif |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2807 | // Always skip the compile unit when comparing by only iterating up to "count |
| 2808 | // - 1". Here we compare the names as we go. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2809 | for (i = 0; i < count1 - 1; i++) { |
| Zachary Turner | 0eaa6d5 | 2019-03-12 20:50:46 +0000 | [diff] [blame] | 2810 | decl_ctx_die1 = decl_ctx_1[i]; |
| 2811 | decl_ctx_die2 = decl_ctx_2[i]; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2812 | const char *name1 = decl_ctx_die1.GetName(); |
| 2813 | const char *name2 = decl_ctx_die2.GetName(); |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2814 | // If the string was from a DW_FORM_strp, then the pointer will often be |
| 2815 | // the same! |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2816 | if (name1 == name2) |
| 2817 | continue; |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 2818 | |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2819 | // Name pointers are not equal, so only compare the strings if both are not |
| 2820 | // NULL. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2821 | if (name1 && name2) { |
| 2822 | // If the strings don't compare, we are done... |
| 2823 | if (strcmp(name1, name2) != 0) |
| 2824 | return false; |
| 2825 | } else { |
| 2826 | // One name was NULL while the other wasn't |
| 2827 | return false; |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 2828 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2829 | } |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2830 | // We made it through all of the checks and the declaration contexts are |
| 2831 | // equal. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2832 | return true; |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 2833 | } |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 2834 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2835 | TypeSP SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext( |
| 2836 | const DWARFDeclContext &dwarf_decl_ctx) { |
| 2837 | TypeSP type_sp; |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 2838 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2839 | const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize(); |
| 2840 | if (dwarf_decl_ctx_count > 0) { |
| 2841 | const ConstString type_name(dwarf_decl_ctx[0].name); |
| 2842 | const dw_tag_t tag = dwarf_decl_ctx[0].tag; |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 2843 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2844 | if (type_name) { |
| 2845 | Log *log(LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION | |
| 2846 | DWARF_LOG_LOOKUPS)); |
| 2847 | if (log) { |
| 2848 | GetObjectFile()->GetModule()->LogMessage( |
| 2849 | log, "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%" |
| 2850 | "s, qualified-name='%s')", |
| 2851 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), |
| 2852 | dwarf_decl_ctx.GetQualifiedName()); |
| 2853 | } |
| 2854 | |
| 2855 | DIEArray die_offsets; |
| Pavel Labath | b13f033 | 2018-05-21 14:12:52 +0000 | [diff] [blame] | 2856 | m_index->GetTypes(dwarf_decl_ctx, die_offsets); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2857 | const size_t num_matches = die_offsets.size(); |
| 2858 | |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2859 | // Get the type system that we are looking to find a type for. We will |
| 2860 | // use this to ensure any matches we find are in a language that this |
| 2861 | // type system supports |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2862 | const LanguageType language = dwarf_decl_ctx.GetLanguage(); |
| 2863 | TypeSystem *type_system = (language == eLanguageTypeUnknown) |
| 2864 | ? nullptr |
| 2865 | : GetTypeSystemForLanguage(language); |
| 2866 | |
| 2867 | if (num_matches) { |
| 2868 | for (size_t i = 0; i < num_matches; ++i) { |
| 2869 | const DIERef &die_ref = die_offsets[i]; |
| 2870 | DWARFDIE type_die = GetDIE(die_ref); |
| 2871 | |
| 2872 | if (type_die) { |
| 2873 | // Make sure type_die's langauge matches the type system we are |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2874 | // looking for. We don't want to find a "Foo" type from Java if we |
| 2875 | // are looking for a "Foo" type for C, C++, ObjC, or ObjC++. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2876 | if (type_system && |
| 2877 | !type_system->SupportsLanguage(type_die.GetLanguage())) |
| 2878 | continue; |
| 2879 | bool try_resolving_type = false; |
| 2880 | |
| 2881 | // Don't try and resolve the DIE we are looking for with the DIE |
| 2882 | // itself! |
| 2883 | const dw_tag_t type_tag = type_die.Tag(); |
| 2884 | // Make sure the tags match |
| 2885 | if (type_tag == tag) { |
| 2886 | // The tags match, lets try resolving this type |
| 2887 | try_resolving_type = true; |
| 2888 | } else { |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2889 | // The tags don't match, but we need to watch our for a forward |
| 2890 | // declaration for a struct and ("struct foo") ends up being a |
| 2891 | // class ("class foo { ... };") or vice versa. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2892 | switch (type_tag) { |
| 2893 | case DW_TAG_class_type: |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2894 | // We had a "class foo", see if we ended up with a "struct foo |
| 2895 | // { ... };" |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2896 | try_resolving_type = (tag == DW_TAG_structure_type); |
| 2897 | break; |
| 2898 | case DW_TAG_structure_type: |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2899 | // We had a "struct foo", see if we ended up with a "class foo |
| 2900 | // { ... };" |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2901 | try_resolving_type = (tag == DW_TAG_class_type); |
| 2902 | break; |
| 2903 | default: |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2904 | // Tags don't match, don't event try to resolve using this type |
| 2905 | // whose name matches.... |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2906 | break; |
| 2907 | } |
| 2908 | } |
| 2909 | |
| 2910 | if (try_resolving_type) { |
| 2911 | DWARFDeclContext type_dwarf_decl_ctx; |
| 2912 | type_die.GetDWARFDeclContext(type_dwarf_decl_ctx); |
| 2913 | |
| 2914 | if (log) { |
| 2915 | GetObjectFile()->GetModule()->LogMessage( |
| 2916 | log, "SymbolFileDWARF::" |
| 2917 | "FindDefinitionTypeForDWARFDeclContext(tag=%s, " |
| 2918 | "qualified-name='%s') trying die=0x%8.8x (%s)", |
| 2919 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), |
| 2920 | dwarf_decl_ctx.GetQualifiedName(), type_die.GetOffset(), |
| 2921 | type_dwarf_decl_ctx.GetQualifiedName()); |
| 2922 | } |
| 2923 | |
| 2924 | // Make sure the decl contexts match all the way up |
| 2925 | if (dwarf_decl_ctx == type_dwarf_decl_ctx) { |
| 2926 | Type *resolved_type = ResolveType(type_die, false); |
| 2927 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) { |
| 2928 | type_sp = resolved_type->shared_from_this(); |
| 2929 | break; |
| 2930 | } |
| 2931 | } |
| 2932 | } else { |
| 2933 | if (log) { |
| 2934 | std::string qualified_name; |
| 2935 | type_die.GetQualifiedName(qualified_name); |
| 2936 | GetObjectFile()->GetModule()->LogMessage( |
| 2937 | log, "SymbolFileDWARF::" |
| 2938 | "FindDefinitionTypeForDWARFDeclContext(tag=%s, " |
| 2939 | "qualified-name='%s') ignoring die=0x%8.8x (%s)", |
| 2940 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), |
| 2941 | dwarf_decl_ctx.GetQualifiedName(), type_die.GetOffset(), |
| 2942 | qualified_name.c_str()); |
| 2943 | } |
| 2944 | } |
| 2945 | } else { |
| Pavel Labath | 78b2cf7 | 2019-06-14 12:01:18 +0000 | [diff] [blame] | 2946 | m_index->ReportInvalidDIERef(die_ref, type_name.GetStringRef()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2947 | } |
| 2948 | } |
| 2949 | } |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 2950 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2951 | } |
| 2952 | return type_sp; |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 2953 | } |
| 2954 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2955 | TypeSP SymbolFileDWARF::ParseType(const SymbolContext &sc, const DWARFDIE &die, |
| 2956 | bool *type_is_new_ptr) { |
| Pavel Labath | a71ce4f | 2019-06-17 07:32:56 +0000 | [diff] [blame] | 2957 | if (!die) |
| 2958 | return {}; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2959 | |
| Pavel Labath | a71ce4f | 2019-06-17 07:32:56 +0000 | [diff] [blame] | 2960 | TypeSystem *type_system = |
| 2961 | GetTypeSystemForLanguage(die.GetCU()->GetLanguageType()); |
| 2962 | if (!type_system) |
| 2963 | return {}; |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 2964 | |
| Pavel Labath | a71ce4f | 2019-06-17 07:32:56 +0000 | [diff] [blame] | 2965 | DWARFASTParser *dwarf_ast = type_system->GetDWARFParser(); |
| 2966 | if (!dwarf_ast) |
| 2967 | return {}; |
| Siva Chandra | 9293fc4 | 2016-01-07 23:32:34 +0000 | [diff] [blame] | 2968 | |
| Pavel Labath | a71ce4f | 2019-06-17 07:32:56 +0000 | [diff] [blame] | 2969 | Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO); |
| 2970 | TypeSP type_sp = dwarf_ast->ParseTypeFromDWARF(sc, die, log, type_is_new_ptr); |
| 2971 | if (type_sp) { |
| Pavel Labath | f46e897 | 2019-07-25 08:22:05 +0000 | [diff] [blame^] | 2972 | GetTypeList().Insert(type_sp); |
| Pavel Labath | a71ce4f | 2019-06-17 07:32:56 +0000 | [diff] [blame] | 2973 | |
| 2974 | if (die.Tag() == DW_TAG_subprogram) { |
| 2975 | std::string scope_qualified_name(GetDeclContextForUID(die.GetID()) |
| 2976 | .GetScopeQualifiedName() |
| 2977 | .AsCString("")); |
| 2978 | if (scope_qualified_name.size()) { |
| 2979 | m_function_scope_qualified_name_map[scope_qualified_name].insert( |
| 2980 | die.GetID()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2981 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2982 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2983 | } |
| 2984 | |
| 2985 | return type_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2986 | } |
| 2987 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2988 | size_t SymbolFileDWARF::ParseTypes(const SymbolContext &sc, |
| 2989 | const DWARFDIE &orig_die, |
| 2990 | bool parse_siblings, bool parse_children) { |
| 2991 | size_t types_added = 0; |
| 2992 | DWARFDIE die = orig_die; |
| 2993 | while (die) { |
| 2994 | bool type_is_new = false; |
| 2995 | if (ParseType(sc, die, &type_is_new).get()) { |
| 2996 | if (type_is_new) |
| 2997 | ++types_added; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2998 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2999 | |
| 3000 | if (parse_children && die.HasChildren()) { |
| 3001 | if (die.Tag() == DW_TAG_subprogram) { |
| 3002 | SymbolContext child_sc(sc); |
| 3003 | child_sc.function = sc.comp_unit->FindFunctionByUID(die.GetID()).get(); |
| 3004 | types_added += ParseTypes(child_sc, die.GetFirstChild(), true, true); |
| 3005 | } else |
| 3006 | types_added += ParseTypes(sc, die.GetFirstChild(), true, true); |
| 3007 | } |
| 3008 | |
| 3009 | if (parse_siblings) |
| 3010 | die = die.GetSibling(); |
| 3011 | else |
| 3012 | die.Clear(); |
| 3013 | } |
| 3014 | return types_added; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3015 | } |
| 3016 | |
| Zachary Turner | ffc1b8f | 2019-01-14 22:40:41 +0000 | [diff] [blame] | 3017 | size_t SymbolFileDWARF::ParseBlocksRecursive(Function &func) { |
| Jonas Devlieghere | 4f78c4f | 2018-10-22 20:14:36 +0000 | [diff] [blame] | 3018 | ASSERT_MODULE_LOCK(this); |
| Zachary Turner | ffc1b8f | 2019-01-14 22:40:41 +0000 | [diff] [blame] | 3019 | CompileUnit *comp_unit = func.GetCompileUnit(); |
| 3020 | lldbassert(comp_unit); |
| 3021 | |
| 3022 | DWARFUnit *dwarf_cu = GetDWARFCompileUnit(comp_unit); |
| 3023 | if (!dwarf_cu) |
| 3024 | return 0; |
| 3025 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3026 | size_t functions_added = 0; |
| Zachary Turner | ffc1b8f | 2019-01-14 22:40:41 +0000 | [diff] [blame] | 3027 | const dw_offset_t function_die_offset = func.GetID(); |
| 3028 | DWARFDIE function_die = dwarf_cu->GetDIE(function_die_offset); |
| 3029 | if (function_die) { |
| 3030 | ParseBlocksRecursive(*comp_unit, &func.GetBlock(false), function_die, |
| 3031 | LLDB_INVALID_ADDRESS, 0); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3032 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3033 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3034 | return functions_added; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3035 | } |
| 3036 | |
| Zachary Turner | 863f8c1 | 2019-01-11 18:03:20 +0000 | [diff] [blame] | 3037 | size_t SymbolFileDWARF::ParseTypes(CompileUnit &comp_unit) { |
| Jonas Devlieghere | 4f78c4f | 2018-10-22 20:14:36 +0000 | [diff] [blame] | 3038 | ASSERT_MODULE_LOCK(this); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3039 | size_t types_added = 0; |
| Zachary Turner | ac0d41c | 2019-01-10 20:57:50 +0000 | [diff] [blame] | 3040 | DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3041 | if (dwarf_cu) { |
| Zachary Turner | ac0d41c | 2019-01-10 20:57:50 +0000 | [diff] [blame] | 3042 | DWARFDIE dwarf_cu_die = dwarf_cu->DIE(); |
| 3043 | if (dwarf_cu_die && dwarf_cu_die.HasChildren()) { |
| 3044 | SymbolContext sc; |
| 3045 | sc.comp_unit = &comp_unit; |
| 3046 | types_added = ParseTypes(sc, dwarf_cu_die.GetFirstChild(), true, true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3047 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3048 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3049 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3050 | return types_added; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3051 | } |
| 3052 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3053 | size_t SymbolFileDWARF::ParseVariablesForContext(const SymbolContext &sc) { |
| Jonas Devlieghere | 4f78c4f | 2018-10-22 20:14:36 +0000 | [diff] [blame] | 3054 | ASSERT_MODULE_LOCK(this); |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 3055 | if (sc.comp_unit != nullptr) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3056 | DWARFDebugInfo *info = DebugInfo(); |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 3057 | if (info == nullptr) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3058 | return 0; |
| 3059 | |
| 3060 | if (sc.function) { |
| Pavel Labath | 2841e6e | 2019-05-08 11:43:05 +0000 | [diff] [blame] | 3061 | DWARFDIE function_die = GetDIE(sc.function->GetID()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3062 | |
| 3063 | const dw_addr_t func_lo_pc = function_die.GetAttributeValueAsAddress( |
| 3064 | DW_AT_low_pc, LLDB_INVALID_ADDRESS); |
| 3065 | if (func_lo_pc != LLDB_INVALID_ADDRESS) { |
| 3066 | const size_t num_variables = ParseVariables( |
| 3067 | sc, function_die.GetFirstChild(), func_lo_pc, true, true); |
| 3068 | |
| 3069 | // Let all blocks know they have parse all their variables |
| 3070 | sc.function->GetBlock(false).SetDidParseVariables(true, true); |
| 3071 | return num_variables; |
| 3072 | } |
| 3073 | } else if (sc.comp_unit) { |
| Jan Kratochvil | 6056273 | 2019-05-10 17:14:37 +0000 | [diff] [blame] | 3074 | DWARFUnit *dwarf_cu = info->GetUnitAtIndex(sc.comp_unit->GetID()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3075 | |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 3076 | if (dwarf_cu == nullptr) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3077 | return 0; |
| 3078 | |
| 3079 | uint32_t vars_added = 0; |
| 3080 | VariableListSP variables(sc.comp_unit->GetVariableList(false)); |
| 3081 | |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 3082 | if (variables.get() == nullptr) { |
| Jonas Devlieghere | 796ac80 | 2019-02-11 23:13:08 +0000 | [diff] [blame] | 3083 | variables = std::make_shared<VariableList>(); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3084 | sc.comp_unit->SetVariableList(variables); |
| 3085 | |
| 3086 | DIEArray die_offsets; |
| Pavel Labath | 3b92698 | 2019-06-21 07:56:50 +0000 | [diff] [blame] | 3087 | m_index->GetGlobalVariables(dwarf_cu->GetNonSkeletonUnit(), |
| 3088 | die_offsets); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3089 | const size_t num_matches = die_offsets.size(); |
| 3090 | if (num_matches) { |
| 3091 | for (size_t i = 0; i < num_matches; ++i) { |
| 3092 | const DIERef &die_ref = die_offsets[i]; |
| 3093 | DWARFDIE die = GetDIE(die_ref); |
| 3094 | if (die) { |
| 3095 | VariableSP var_sp( |
| 3096 | ParseVariableDIE(sc, die, LLDB_INVALID_ADDRESS)); |
| 3097 | if (var_sp) { |
| 3098 | variables->AddVariableIfUnique(var_sp); |
| 3099 | ++vars_added; |
| 3100 | } |
| Pavel Labath | b13f033 | 2018-05-21 14:12:52 +0000 | [diff] [blame] | 3101 | } else |
| Pavel Labath | 78b2cf7 | 2019-06-14 12:01:18 +0000 | [diff] [blame] | 3102 | m_index->ReportInvalidDIERef(die_ref, ""); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3103 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3104 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3105 | } |
| 3106 | return vars_added; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3107 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3108 | } |
| 3109 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3110 | } |
| 3111 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3112 | VariableSP SymbolFileDWARF::ParseVariableDIE(const SymbolContext &sc, |
| 3113 | const DWARFDIE &die, |
| 3114 | const lldb::addr_t func_low_pc) { |
| 3115 | if (die.GetDWARF() != this) |
| 3116 | return die.GetDWARF()->ParseVariableDIE(sc, die, func_low_pc); |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 3117 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3118 | VariableSP var_sp; |
| 3119 | if (!die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3120 | return var_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3121 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3122 | var_sp = GetDIEToVariable()[die.GetDIE()]; |
| 3123 | if (var_sp) |
| 3124 | return var_sp; // Already been parsed! |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 3125 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3126 | const dw_tag_t tag = die.Tag(); |
| 3127 | ModuleSP module = GetObjectFile()->GetModule(); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 3128 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3129 | if ((tag == DW_TAG_variable) || (tag == DW_TAG_constant) || |
| 3130 | (tag == DW_TAG_formal_parameter && sc.function)) { |
| 3131 | DWARFAttributes attributes; |
| 3132 | const size_t num_attributes = die.GetAttributes(attributes); |
| 3133 | DWARFDIE spec_die; |
| 3134 | if (num_attributes > 0) { |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 3135 | const char *name = nullptr; |
| 3136 | const char *mangled = nullptr; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3137 | Declaration decl; |
| 3138 | uint32_t i; |
| 3139 | DWARFFormValue type_die_form; |
| Jonas Devlieghere | 04a087a | 2019-05-28 17:34:05 +0000 | [diff] [blame] | 3140 | DWARFExpression location; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3141 | bool is_external = false; |
| 3142 | bool is_artificial = false; |
| 3143 | bool location_is_const_value_data = false; |
| 3144 | bool has_explicit_location = false; |
| 3145 | DWARFFormValue const_value; |
| 3146 | Variable::RangeList scope_ranges; |
| 3147 | // AccessType accessibility = eAccessNone; |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 3148 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3149 | for (i = 0; i < num_attributes; ++i) { |
| 3150 | dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 3151 | DWARFFormValue form_value; |
| 3152 | |
| 3153 | if (attributes.ExtractFormValueAtIndex(i, form_value)) { |
| 3154 | switch (attr) { |
| 3155 | case DW_AT_decl_file: |
| 3156 | decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex( |
| 3157 | form_value.Unsigned())); |
| 3158 | break; |
| 3159 | case DW_AT_decl_line: |
| 3160 | decl.SetLine(form_value.Unsigned()); |
| 3161 | break; |
| 3162 | case DW_AT_decl_column: |
| 3163 | decl.SetColumn(form_value.Unsigned()); |
| 3164 | break; |
| 3165 | case DW_AT_name: |
| 3166 | name = form_value.AsCString(); |
| 3167 | break; |
| 3168 | case DW_AT_linkage_name: |
| 3169 | case DW_AT_MIPS_linkage_name: |
| 3170 | mangled = form_value.AsCString(); |
| 3171 | break; |
| 3172 | case DW_AT_type: |
| 3173 | type_die_form = form_value; |
| 3174 | break; |
| 3175 | case DW_AT_external: |
| 3176 | is_external = form_value.Boolean(); |
| 3177 | break; |
| 3178 | case DW_AT_const_value: |
| 3179 | // If we have already found a DW_AT_location attribute, ignore this |
| 3180 | // attribute. |
| 3181 | if (!has_explicit_location) { |
| 3182 | location_is_const_value_data = true; |
| 3183 | // The constant value will be either a block, a data value or a |
| 3184 | // string. |
| Greg Clayton | f56c30d | 2018-05-09 16:42:53 +0000 | [diff] [blame] | 3185 | auto debug_info_data = die.GetData(); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3186 | if (DWARFFormValue::IsBlockForm(form_value.Form())) { |
| 3187 | // Retrieve the value as a block expression. |
| 3188 | uint32_t block_offset = |
| 3189 | form_value.BlockData() - debug_info_data.GetDataStart(); |
| 3190 | uint32_t block_length = form_value.Unsigned(); |
| Jonas Devlieghere | 04a087a | 2019-05-28 17:34:05 +0000 | [diff] [blame] | 3191 | location = DWARFExpression(module, debug_info_data, die.GetCU(), |
| 3192 | block_offset, block_length); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3193 | } else if (DWARFFormValue::IsDataForm(form_value.Form())) { |
| 3194 | // Retrieve the value as a data expression. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3195 | uint32_t data_offset = attributes.DIEOffsetAtIndex(i); |
| Greg Clayton | 6aad81c | 2019-05-24 22:08:50 +0000 | [diff] [blame] | 3196 | if (auto data_length = form_value.GetFixedSize()) |
| Jonas Devlieghere | 04a087a | 2019-05-28 17:34:05 +0000 | [diff] [blame] | 3197 | location = |
| 3198 | DWARFExpression(module, debug_info_data, die.GetCU(), |
| 3199 | data_offset, *data_length); |
| Greg Clayton | 6aad81c | 2019-05-24 22:08:50 +0000 | [diff] [blame] | 3200 | else { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3201 | const uint8_t *data_pointer = form_value.BlockData(); |
| 3202 | if (data_pointer) { |
| 3203 | form_value.Unsigned(); |
| 3204 | } else if (DWARFFormValue::IsDataForm(form_value.Form())) { |
| 3205 | // we need to get the byte size of the type later after we |
| 3206 | // create the variable |
| 3207 | const_value = form_value; |
| 3208 | } |
| Greg Clayton | 6aad81c | 2019-05-24 22:08:50 +0000 | [diff] [blame] | 3209 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3210 | } else { |
| 3211 | // Retrieve the value as a string expression. |
| 3212 | if (form_value.Form() == DW_FORM_strp) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3213 | uint32_t data_offset = attributes.DIEOffsetAtIndex(i); |
| Greg Clayton | 6aad81c | 2019-05-24 22:08:50 +0000 | [diff] [blame] | 3214 | if (auto data_length = form_value.GetFixedSize()) |
| Jonas Devlieghere | 04a087a | 2019-05-28 17:34:05 +0000 | [diff] [blame] | 3215 | location = |
| 3216 | DWARFExpression(module, debug_info_data, die.GetCU(), |
| 3217 | data_offset, *data_length); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3218 | } else { |
| 3219 | const char *str = form_value.AsCString(); |
| 3220 | uint32_t string_offset = |
| 3221 | str - (const char *)debug_info_data.GetDataStart(); |
| 3222 | uint32_t string_length = strlen(str) + 1; |
| Jonas Devlieghere | 04a087a | 2019-05-28 17:34:05 +0000 | [diff] [blame] | 3223 | location = |
| 3224 | DWARFExpression(module, debug_info_data, die.GetCU(), |
| 3225 | string_offset, string_length); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3226 | } |
| 3227 | } |
| 3228 | } |
| 3229 | break; |
| 3230 | case DW_AT_location: { |
| 3231 | location_is_const_value_data = false; |
| 3232 | has_explicit_location = true; |
| 3233 | if (DWARFFormValue::IsBlockForm(form_value.Form())) { |
| Greg Clayton | f56c30d | 2018-05-09 16:42:53 +0000 | [diff] [blame] | 3234 | auto data = die.GetData(); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3235 | |
| 3236 | uint32_t block_offset = |
| Greg Clayton | f56c30d | 2018-05-09 16:42:53 +0000 | [diff] [blame] | 3237 | form_value.BlockData() - data.GetDataStart(); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3238 | uint32_t block_length = form_value.Unsigned(); |
| Jonas Devlieghere | 04a087a | 2019-05-28 17:34:05 +0000 | [diff] [blame] | 3239 | location = DWARFExpression(module, data, die.GetCU(), |
| 3240 | block_offset, block_length); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3241 | } else { |
| Pavel Labath | 4c2ef9a | 2019-03-22 16:07:58 +0000 | [diff] [blame] | 3242 | const DWARFDataExtractor &debug_loc_data = DebugLocData(); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3243 | const dw_offset_t debug_loc_offset = form_value.Unsigned(); |
| 3244 | |
| 3245 | size_t loc_list_length = DWARFExpression::LocationListSize( |
| Pavel Labath | 4c2ef9a | 2019-03-22 16:07:58 +0000 | [diff] [blame] | 3246 | die.GetCU(), debug_loc_data, debug_loc_offset); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3247 | if (loc_list_length > 0) { |
| Jonas Devlieghere | 04a087a | 2019-05-28 17:34:05 +0000 | [diff] [blame] | 3248 | location = DWARFExpression(module, debug_loc_data, die.GetCU(), |
| 3249 | debug_loc_offset, loc_list_length); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3250 | assert(func_low_pc != LLDB_INVALID_ADDRESS); |
| 3251 | location.SetLocationListSlide( |
| 3252 | func_low_pc - |
| 3253 | attributes.CompileUnitAtIndex(i)->GetBaseAddress()); |
| 3254 | } |
| 3255 | } |
| 3256 | } break; |
| 3257 | case DW_AT_specification: |
| Jan Kratochvil | e8a039d | 2019-05-15 19:22:33 +0000 | [diff] [blame] | 3258 | spec_die = form_value.Reference(); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3259 | break; |
| Pavel Labath | 78cfe1e | 2019-05-29 09:22:36 +0000 | [diff] [blame] | 3260 | case DW_AT_start_scope: |
| 3261 | // TODO: Implement this. |
| 3262 | break; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3263 | case DW_AT_artificial: |
| 3264 | is_artificial = form_value.Boolean(); |
| 3265 | break; |
| 3266 | case DW_AT_accessibility: |
| 3267 | break; // accessibility = |
| 3268 | // DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
| 3269 | case DW_AT_declaration: |
| 3270 | case DW_AT_description: |
| 3271 | case DW_AT_endianity: |
| 3272 | case DW_AT_segment: |
| 3273 | case DW_AT_visibility: |
| 3274 | default: |
| 3275 | case DW_AT_abstract_origin: |
| 3276 | case DW_AT_sibling: |
| 3277 | break; |
| 3278 | } |
| 3279 | } |
| 3280 | } |
| 3281 | |
| 3282 | const DWARFDIE parent_context_die = GetDeclContextDIEContainingDIE(die); |
| 3283 | const dw_tag_t parent_tag = die.GetParent().Tag(); |
| 3284 | bool is_static_member = |
| Jan Kratochvil | 55c84b1 | 2018-04-30 16:04:32 +0000 | [diff] [blame] | 3285 | (parent_tag == DW_TAG_compile_unit || |
| 3286 | parent_tag == DW_TAG_partial_unit) && |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3287 | (parent_context_die.Tag() == DW_TAG_class_type || |
| 3288 | parent_context_die.Tag() == DW_TAG_structure_type); |
| 3289 | |
| 3290 | ValueType scope = eValueTypeInvalid; |
| 3291 | |
| 3292 | const DWARFDIE sc_parent_die = GetParentSymbolContextDIE(die); |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 3293 | SymbolContextScope *symbol_context_scope = nullptr; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3294 | |
| Sam McCall | 3062139 | 2016-11-22 11:40:25 +0000 | [diff] [blame] | 3295 | bool has_explicit_mangled = mangled != nullptr; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3296 | if (!mangled) { |
| 3297 | // LLDB relies on the mangled name (DW_TAG_linkage_name or |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 3298 | // DW_AT_MIPS_linkage_name) to generate fully qualified names |
| 3299 | // of global variables with commands like "frame var j". For |
| 3300 | // example, if j were an int variable holding a value 4 and |
| 3301 | // declared in a namespace B which in turn is contained in a |
| 3302 | // namespace A, the command "frame var j" returns |
| 3303 | // "(int) A::B::j = 4". |
| 3304 | // If the compiler does not emit a linkage name, we should be |
| 3305 | // able to generate a fully qualified name from the |
| 3306 | // declaration context. |
| Jan Kratochvil | 55c84b1 | 2018-04-30 16:04:32 +0000 | [diff] [blame] | 3307 | if ((parent_tag == DW_TAG_compile_unit || |
| 3308 | parent_tag == DW_TAG_partial_unit) && |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3309 | Language::LanguageIsCPlusPlus(die.GetLanguage())) { |
| 3310 | DWARFDeclContext decl_ctx; |
| 3311 | |
| 3312 | die.GetDWARFDeclContext(decl_ctx); |
| 3313 | mangled = decl_ctx.GetQualifiedNameAsConstString().GetCString(); |
| 3314 | } |
| 3315 | } |
| 3316 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3317 | if (tag == DW_TAG_formal_parameter) |
| 3318 | scope = eValueTypeVariableArgument; |
| 3319 | else { |
| Sam McCall | 3062139 | 2016-11-22 11:40:25 +0000 | [diff] [blame] | 3320 | // DWARF doesn't specify if a DW_TAG_variable is a local, global |
| 3321 | // or static variable, so we have to do a little digging: |
| 3322 | // 1) DW_AT_linkage_name implies static lifetime (but may be missing) |
| 3323 | // 2) An empty DW_AT_location is an (optimized-out) static lifetime var. |
| 3324 | // 3) DW_AT_location containing a DW_OP_addr implies static lifetime. |
| 3325 | // Clang likes to combine small global variables into the same symbol |
| 3326 | // with locations like: DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus |
| 3327 | // so we need to look through the whole expression. |
| 3328 | bool is_static_lifetime = |
| 3329 | has_explicit_mangled || |
| 3330 | (has_explicit_location && !location.IsValid()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3331 | // Check if the location has a DW_OP_addr with any address value... |
| 3332 | lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS; |
| 3333 | if (!location_is_const_value_data) { |
| Sam McCall | 3062139 | 2016-11-22 11:40:25 +0000 | [diff] [blame] | 3334 | bool op_error = false; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3335 | location_DW_OP_addr = location.GetLocation_DW_OP_addr(0, op_error); |
| 3336 | if (op_error) { |
| 3337 | StreamString strm; |
| 3338 | location.DumpLocationForAddress(&strm, eDescriptionLevelFull, 0, 0, |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 3339 | nullptr); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3340 | GetObjectFile()->GetModule()->ReportError( |
| 3341 | "0x%8.8x: %s has an invalid location: %s", die.GetOffset(), |
| Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 3342 | die.GetTagAsCString(), strm.GetData()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3343 | } |
| Sam McCall | 3062139 | 2016-11-22 11:40:25 +0000 | [diff] [blame] | 3344 | if (location_DW_OP_addr != LLDB_INVALID_ADDRESS) |
| 3345 | is_static_lifetime = true; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3346 | } |
| 3347 | SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile(); |
| Adrian Prantl | f796e76 | 2018-10-02 17:50:42 +0000 | [diff] [blame] | 3348 | if (debug_map_symfile) |
| 3349 | // Set the module of the expression to the linked module |
| 3350 | // instead of the oject file so the relocated address can be |
| 3351 | // found there. |
| 3352 | location.SetModule(debug_map_symfile->GetObjectFile()->GetModule()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3353 | |
| Sam McCall | 3062139 | 2016-11-22 11:40:25 +0000 | [diff] [blame] | 3354 | if (is_static_lifetime) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3355 | if (is_external) |
| 3356 | scope = eValueTypeVariableGlobal; |
| 3357 | else |
| 3358 | scope = eValueTypeVariableStatic; |
| 3359 | |
| 3360 | if (debug_map_symfile) { |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 3361 | // When leaving the DWARF in the .o files on darwin, when we have a |
| 3362 | // global variable that wasn't initialized, the .o file might not |
| 3363 | // have allocated a virtual address for the global variable. In |
| 3364 | // this case it will have created a symbol for the global variable |
| 3365 | // that is undefined/data and external and the value will be the |
| 3366 | // byte size of the variable. When we do the address map in |
| 3367 | // SymbolFileDWARFDebugMap we rely on having an address, we need to |
| 3368 | // do some magic here so we can get the correct address for our |
| 3369 | // global variable. The address for all of these entries will be |
| 3370 | // zero, and there will be an undefined symbol in this object file, |
| 3371 | // and the executable will have a matching symbol with a good |
| 3372 | // address. So here we dig up the correct address and replace it in |
| 3373 | // the location for the variable, and set the variable's symbol |
| 3374 | // context scope to be that of the main executable so the file |
| 3375 | // address will resolve correctly. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3376 | bool linked_oso_file_addr = false; |
| 3377 | if (is_external && location_DW_OP_addr == 0) { |
| 3378 | // we have a possible uninitialized extern global |
| 3379 | ConstString const_name(mangled ? mangled : name); |
| 3380 | ObjectFile *debug_map_objfile = |
| 3381 | debug_map_symfile->GetObjectFile(); |
| 3382 | if (debug_map_objfile) { |
| 3383 | Symtab *debug_map_symtab = debug_map_objfile->GetSymtab(); |
| 3384 | if (debug_map_symtab) { |
| 3385 | Symbol *exe_symbol = |
| 3386 | debug_map_symtab->FindFirstSymbolWithNameAndType( |
| 3387 | const_name, eSymbolTypeData, Symtab::eDebugYes, |
| 3388 | Symtab::eVisibilityExtern); |
| 3389 | if (exe_symbol) { |
| 3390 | if (exe_symbol->ValueIsAddress()) { |
| 3391 | const addr_t exe_file_addr = |
| 3392 | exe_symbol->GetAddressRef().GetFileAddress(); |
| 3393 | if (exe_file_addr != LLDB_INVALID_ADDRESS) { |
| 3394 | if (location.Update_DW_OP_addr(exe_file_addr)) { |
| 3395 | linked_oso_file_addr = true; |
| 3396 | symbol_context_scope = exe_symbol; |
| 3397 | } |
| 3398 | } |
| 3399 | } |
| 3400 | } |
| 3401 | } |
| 3402 | } |
| 3403 | } |
| 3404 | |
| 3405 | if (!linked_oso_file_addr) { |
| 3406 | // The DW_OP_addr is not zero, but it contains a .o file address |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 3407 | // which needs to be linked up correctly. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3408 | const lldb::addr_t exe_file_addr = |
| 3409 | debug_map_symfile->LinkOSOFileAddress(this, |
| 3410 | location_DW_OP_addr); |
| 3411 | if (exe_file_addr != LLDB_INVALID_ADDRESS) { |
| 3412 | // Update the file address for this variable |
| 3413 | location.Update_DW_OP_addr(exe_file_addr); |
| 3414 | } else { |
| 3415 | // Variable didn't make it into the final executable |
| 3416 | return var_sp; |
| 3417 | } |
| 3418 | } |
| 3419 | } |
| 3420 | } else { |
| 3421 | if (location_is_const_value_data) |
| 3422 | scope = eValueTypeVariableStatic; |
| 3423 | else { |
| 3424 | scope = eValueTypeVariableLocal; |
| 3425 | if (debug_map_symfile) { |
| 3426 | // We need to check for TLS addresses that we need to fixup |
| 3427 | if (location.ContainsThreadLocalStorage()) { |
| 3428 | location.LinkThreadLocalStorage( |
| 3429 | debug_map_symfile->GetObjectFile()->GetModule(), |
| 3430 | [this, debug_map_symfile]( |
| 3431 | lldb::addr_t unlinked_file_addr) -> lldb::addr_t { |
| 3432 | return debug_map_symfile->LinkOSOFileAddress( |
| 3433 | this, unlinked_file_addr); |
| 3434 | }); |
| 3435 | scope = eValueTypeVariableThreadLocal; |
| 3436 | } |
| 3437 | } |
| 3438 | } |
| 3439 | } |
| 3440 | } |
| 3441 | |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 3442 | if (symbol_context_scope == nullptr) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3443 | switch (parent_tag) { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 3444 | case DW_TAG_subprogram: |
| 3445 | case DW_TAG_inlined_subroutine: |
| 3446 | case DW_TAG_lexical_block: |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3447 | if (sc.function) { |
| 3448 | symbol_context_scope = sc.function->GetBlock(true).FindBlockByID( |
| 3449 | sc_parent_die.GetID()); |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 3450 | if (symbol_context_scope == nullptr) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3451 | symbol_context_scope = sc.function; |
| 3452 | } |
| 3453 | break; |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 3454 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3455 | default: |
| 3456 | symbol_context_scope = sc.comp_unit; |
| 3457 | break; |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 3458 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3459 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 3460 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3461 | if (symbol_context_scope) { |
| 3462 | SymbolFileTypeSP type_sp( |
| Pavel Labath | 67b45ac | 2019-06-19 07:32:39 +0000 | [diff] [blame] | 3463 | new SymbolFileType(*this, GetUID(type_die_form.Reference()))); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3464 | |
| 3465 | if (const_value.Form() && type_sp && type_sp->GetType()) |
| Jonas Devlieghere | 04a087a | 2019-05-28 17:34:05 +0000 | [diff] [blame] | 3466 | location.UpdateValue(const_value.Unsigned(), |
| 3467 | type_sp->GetType()->GetByteSize().getValueOr(0), |
| 3468 | die.GetCU()->GetAddressByteSize()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3469 | |
| Jonas Devlieghere | 796ac80 | 2019-02-11 23:13:08 +0000 | [diff] [blame] | 3470 | var_sp = std::make_shared<Variable>( |
| 3471 | die.GetID(), name, mangled, type_sp, scope, symbol_context_scope, |
| 3472 | scope_ranges, &decl, location, is_external, is_artificial, |
| 3473 | is_static_member); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3474 | |
| 3475 | var_sp->SetLocationIsConstantValueData(location_is_const_value_data); |
| 3476 | } else { |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 3477 | // Not ready to parse this variable yet. It might be a global or static |
| 3478 | // variable that is in a function scope and the function in the symbol |
| 3479 | // context wasn't filled in yet |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3480 | return var_sp; |
| 3481 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 3482 | } |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 3483 | // Cache var_sp even if NULL (the variable was just a specification or was |
| 3484 | // missing vital information to be able to be displayed in the debugger |
| 3485 | // (missing location due to optimization, etc)) so we don't re-parse this |
| 3486 | // DIE over and over later... |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3487 | GetDIEToVariable()[die.GetDIE()] = var_sp; |
| 3488 | if (spec_die) |
| 3489 | GetDIEToVariable()[spec_die.GetDIE()] = var_sp; |
| 3490 | } |
| 3491 | return var_sp; |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 3492 | } |
| 3493 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3494 | DWARFDIE |
| 3495 | SymbolFileDWARF::FindBlockContainingSpecification( |
| 3496 | const DIERef &func_die_ref, dw_offset_t spec_block_die_offset) { |
| 3497 | // Give the concrete function die specified by "func_die_offset", find the |
| 3498 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points |
| 3499 | // to "spec_block_die_offset" |
| 3500 | return FindBlockContainingSpecification(DebugInfo()->GetDIE(func_die_ref), |
| 3501 | spec_block_die_offset); |
| 3502 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3503 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3504 | DWARFDIE |
| 3505 | SymbolFileDWARF::FindBlockContainingSpecification( |
| 3506 | const DWARFDIE &die, dw_offset_t spec_block_die_offset) { |
| 3507 | if (die) { |
| 3508 | switch (die.Tag()) { |
| 3509 | case DW_TAG_subprogram: |
| 3510 | case DW_TAG_inlined_subroutine: |
| 3511 | case DW_TAG_lexical_block: { |
| Jan Kratochvil | e8a039d | 2019-05-15 19:22:33 +0000 | [diff] [blame] | 3512 | if (die.GetReferencedDIE(DW_AT_specification).GetOffset() == |
| 3513 | spec_block_die_offset) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3514 | return die; |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 3515 | |
| Jan Kratochvil | e8a039d | 2019-05-15 19:22:33 +0000 | [diff] [blame] | 3516 | if (die.GetReferencedDIE(DW_AT_abstract_origin).GetOffset() == |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3517 | spec_block_die_offset) |
| 3518 | return die; |
| 3519 | } break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3520 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3521 | |
| 3522 | // Give the concrete function die specified by "func_die_offset", find the |
| 3523 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points |
| 3524 | // to "spec_block_die_offset" |
| 3525 | for (DWARFDIE child_die = die.GetFirstChild(); child_die; |
| 3526 | child_die = child_die.GetSibling()) { |
| 3527 | DWARFDIE result_die = |
| 3528 | FindBlockContainingSpecification(child_die, spec_block_die_offset); |
| 3529 | if (result_die) |
| 3530 | return result_die; |
| 3531 | } |
| 3532 | } |
| 3533 | |
| 3534 | return DWARFDIE(); |
| 3535 | } |
| 3536 | |
| 3537 | size_t SymbolFileDWARF::ParseVariables(const SymbolContext &sc, |
| 3538 | const DWARFDIE &orig_die, |
| 3539 | const lldb::addr_t func_low_pc, |
| 3540 | bool parse_siblings, bool parse_children, |
| 3541 | VariableList *cc_variable_list) { |
| 3542 | if (!orig_die) |
| 3543 | return 0; |
| 3544 | |
| 3545 | VariableListSP variable_list_sp; |
| 3546 | |
| 3547 | size_t vars_added = 0; |
| 3548 | DWARFDIE die = orig_die; |
| 3549 | while (die) { |
| 3550 | dw_tag_t tag = die.Tag(); |
| 3551 | |
| 3552 | // Check to see if we have already parsed this variable or constant? |
| 3553 | VariableSP var_sp = GetDIEToVariable()[die.GetDIE()]; |
| 3554 | if (var_sp) { |
| 3555 | if (cc_variable_list) |
| 3556 | cc_variable_list->AddVariableIfUnique(var_sp); |
| 3557 | } else { |
| 3558 | // We haven't already parsed it, lets do that now. |
| 3559 | if ((tag == DW_TAG_variable) || (tag == DW_TAG_constant) || |
| 3560 | (tag == DW_TAG_formal_parameter && sc.function)) { |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 3561 | if (variable_list_sp.get() == nullptr) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3562 | DWARFDIE sc_parent_die = GetParentSymbolContextDIE(orig_die); |
| 3563 | dw_tag_t parent_tag = sc_parent_die.Tag(); |
| 3564 | switch (parent_tag) { |
| 3565 | case DW_TAG_compile_unit: |
| Jan Kratochvil | 55c84b1 | 2018-04-30 16:04:32 +0000 | [diff] [blame] | 3566 | case DW_TAG_partial_unit: |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 3567 | if (sc.comp_unit != nullptr) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3568 | variable_list_sp = sc.comp_unit->GetVariableList(false); |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 3569 | if (variable_list_sp.get() == nullptr) { |
| Jonas Devlieghere | 796ac80 | 2019-02-11 23:13:08 +0000 | [diff] [blame] | 3570 | variable_list_sp = std::make_shared<VariableList>(); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3571 | } |
| 3572 | } else { |
| 3573 | GetObjectFile()->GetModule()->ReportError( |
| 3574 | "parent 0x%8.8" PRIx64 " %s with no valid compile unit in " |
| 3575 | "symbol context for 0x%8.8" PRIx64 |
| 3576 | " %s.\n", |
| 3577 | sc_parent_die.GetID(), sc_parent_die.GetTagAsCString(), |
| 3578 | orig_die.GetID(), orig_die.GetTagAsCString()); |
| 3579 | } |
| 3580 | break; |
| 3581 | |
| 3582 | case DW_TAG_subprogram: |
| 3583 | case DW_TAG_inlined_subroutine: |
| 3584 | case DW_TAG_lexical_block: |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 3585 | if (sc.function != nullptr) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3586 | // Check to see if we already have parsed the variables for the |
| 3587 | // given scope |
| 3588 | |
| 3589 | Block *block = sc.function->GetBlock(true).FindBlockByID( |
| 3590 | sc_parent_die.GetID()); |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 3591 | if (block == nullptr) { |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 3592 | // This must be a specification or abstract origin with a |
| 3593 | // concrete block counterpart in the current function. We need |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3594 | // to find the concrete block so we can correctly add the |
| 3595 | // variable to it |
| 3596 | const DWARFDIE concrete_block_die = |
| 3597 | FindBlockContainingSpecification( |
| Pavel Labath | 2841e6e | 2019-05-08 11:43:05 +0000 | [diff] [blame] | 3598 | GetDIE(sc.function->GetID()), |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3599 | sc_parent_die.GetOffset()); |
| 3600 | if (concrete_block_die) |
| 3601 | block = sc.function->GetBlock(true).FindBlockByID( |
| 3602 | concrete_block_die.GetID()); |
| 3603 | } |
| 3604 | |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 3605 | if (block != nullptr) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3606 | const bool can_create = false; |
| 3607 | variable_list_sp = block->GetBlockVariableList(can_create); |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 3608 | if (variable_list_sp.get() == nullptr) { |
| Jonas Devlieghere | 796ac80 | 2019-02-11 23:13:08 +0000 | [diff] [blame] | 3609 | variable_list_sp = std::make_shared<VariableList>(); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3610 | block->SetVariableList(variable_list_sp); |
| 3611 | } |
| 3612 | } |
| 3613 | } |
| 3614 | break; |
| 3615 | |
| 3616 | default: |
| 3617 | GetObjectFile()->GetModule()->ReportError( |
| 3618 | "didn't find appropriate parent DIE for variable list for " |
| 3619 | "0x%8.8" PRIx64 " %s.\n", |
| 3620 | orig_die.GetID(), orig_die.GetTagAsCString()); |
| 3621 | break; |
| 3622 | } |
| 3623 | } |
| 3624 | |
| 3625 | if (variable_list_sp) { |
| 3626 | VariableSP var_sp(ParseVariableDIE(sc, die, func_low_pc)); |
| 3627 | if (var_sp) { |
| 3628 | variable_list_sp->AddVariableIfUnique(var_sp); |
| 3629 | if (cc_variable_list) |
| 3630 | cc_variable_list->AddVariableIfUnique(var_sp); |
| 3631 | ++vars_added; |
| 3632 | } |
| 3633 | } |
| 3634 | } |
| 3635 | } |
| 3636 | |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 3637 | bool skip_children = (sc.function == nullptr && tag == DW_TAG_subprogram); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3638 | |
| 3639 | if (!skip_children && parse_children && die.HasChildren()) { |
| 3640 | vars_added += ParseVariables(sc, die.GetFirstChild(), func_low_pc, true, |
| 3641 | true, cc_variable_list); |
| 3642 | } |
| 3643 | |
| 3644 | if (parse_siblings) |
| 3645 | die = die.GetSibling(); |
| 3646 | else |
| 3647 | die.Clear(); |
| 3648 | } |
| 3649 | return vars_added; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3650 | } |
| 3651 | |
| Vedant Kumar | 4b36f79 | 2018-10-05 23:23:15 +0000 | [diff] [blame] | 3652 | /// Collect call graph edges present in a function DIE. |
| 3653 | static std::vector<lldb_private::CallEdge> |
| 3654 | CollectCallEdges(DWARFDIE function_die) { |
| 3655 | // Check if the function has a supported call site-related attribute. |
| 3656 | // TODO: In the future it may be worthwhile to support call_all_source_calls. |
| 3657 | uint64_t has_call_edges = |
| 3658 | function_die.GetAttributeValueAsUnsigned(DW_AT_call_all_calls, 0); |
| 3659 | if (!has_call_edges) |
| 3660 | return {}; |
| 3661 | |
| 3662 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP)); |
| 3663 | LLDB_LOG(log, "CollectCallEdges: Found call site info in {0}", |
| 3664 | function_die.GetPubname()); |
| 3665 | |
| 3666 | // Scan the DIE for TAG_call_site entries. |
| 3667 | // TODO: A recursive scan of all blocks in the subprogram is needed in order |
| 3668 | // to be DWARF5-compliant. This may need to be done lazily to be performant. |
| 3669 | // For now, assume that all entries are nested directly under the subprogram |
| 3670 | // (this is the kind of DWARF LLVM produces) and parse them eagerly. |
| 3671 | std::vector<CallEdge> call_edges; |
| 3672 | for (DWARFDIE child = function_die.GetFirstChild(); child.IsValid(); |
| 3673 | child = child.GetSibling()) { |
| 3674 | if (child.Tag() != DW_TAG_call_site) |
| 3675 | continue; |
| 3676 | |
| 3677 | // Extract DW_AT_call_origin (the call target's DIE). |
| 3678 | DWARFDIE call_origin = child.GetReferencedDIE(DW_AT_call_origin); |
| 3679 | if (!call_origin.IsValid()) { |
| 3680 | LLDB_LOG(log, "CollectCallEdges: Invalid call origin in {0}", |
| 3681 | function_die.GetPubname()); |
| 3682 | continue; |
| 3683 | } |
| 3684 | |
| 3685 | // Extract DW_AT_call_return_pc (the PC the call returns to) if it's |
| 3686 | // available. It should only ever be unavailable for tail call edges, in |
| 3687 | // which case use LLDB_INVALID_ADDRESS. |
| 3688 | addr_t return_pc = child.GetAttributeValueAsAddress(DW_AT_call_return_pc, |
| 3689 | LLDB_INVALID_ADDRESS); |
| 3690 | |
| 3691 | LLDB_LOG(log, "CollectCallEdges: Found call origin: {0} (retn-PC: {1:x})", |
| 3692 | call_origin.GetPubname(), return_pc); |
| 3693 | call_edges.emplace_back(call_origin.GetMangledName(), return_pc); |
| 3694 | } |
| 3695 | return call_edges; |
| 3696 | } |
| 3697 | |
| 3698 | std::vector<lldb_private::CallEdge> |
| 3699 | SymbolFileDWARF::ParseCallEdgesInFunction(UserID func_id) { |
| Pavel Labath | 2841e6e | 2019-05-08 11:43:05 +0000 | [diff] [blame] | 3700 | DWARFDIE func_die = GetDIE(func_id.GetID()); |
| Vedant Kumar | 4b36f79 | 2018-10-05 23:23:15 +0000 | [diff] [blame] | 3701 | if (func_die.IsValid()) |
| 3702 | return CollectCallEdges(func_die); |
| 3703 | return {}; |
| 3704 | } |
| 3705 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3706 | // PluginInterface protocol |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3707 | ConstString SymbolFileDWARF::GetPluginName() { return GetPluginNameStatic(); } |
| 3708 | |
| 3709 | uint32_t SymbolFileDWARF::GetPluginVersion() { return 1; } |
| 3710 | |
| Pavel Labath | e011990 | 2019-07-23 09:24:02 +0000 | [diff] [blame] | 3711 | void SymbolFileDWARF::Dump(lldb_private::Stream &s) { |
| 3712 | SymbolFile::Dump(s); |
| 3713 | m_index->Dump(s); |
| 3714 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3715 | |
| Zachary Turner | 4911023 | 2018-11-05 17:40:28 +0000 | [diff] [blame] | 3716 | void SymbolFileDWARF::DumpClangAST(Stream &s) { |
| 3717 | TypeSystem *ts = GetTypeSystemForLanguage(eLanguageTypeC_plus_plus); |
| 3718 | ClangASTContext *clang = llvm::dyn_cast_or_null<ClangASTContext>(ts); |
| 3719 | if (!clang) |
| 3720 | return; |
| 3721 | clang->Dump(s); |
| 3722 | } |
| 3723 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3724 | SymbolFileDWARFDebugMap *SymbolFileDWARF::GetDebugMapSymfile() { |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 3725 | if (m_debug_map_symfile == nullptr && !m_debug_map_module_wp.expired()) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3726 | lldb::ModuleSP module_sp(m_debug_map_module_wp.lock()); |
| 3727 | if (module_sp) { |
| 3728 | SymbolVendor *sym_vendor = module_sp->GetSymbolVendor(); |
| 3729 | if (sym_vendor) |
| 3730 | m_debug_map_symfile = |
| 3731 | (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile(); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 3732 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3733 | } |
| 3734 | return m_debug_map_symfile; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 3735 | } |
| Tamas Berghammer | 1f5e448 | 2015-09-16 12:37:06 +0000 | [diff] [blame] | 3736 | |
| Pavel Labath | 4c2ef9a | 2019-03-22 16:07:58 +0000 | [diff] [blame] | 3737 | DWARFExpression::LocationListFormat |
| 3738 | SymbolFileDWARF::GetLocationListFormat() const { |
| 3739 | if (m_data_debug_loclists.m_data.GetByteSize() > 0) |
| George Rimar | e4dee26 | 2018-10-23 09:46:15 +0000 | [diff] [blame] | 3740 | return DWARFExpression::LocLists; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3741 | return DWARFExpression::RegularLocationList; |
| Tamas Berghammer | 1f5e448 | 2015-09-16 12:37:06 +0000 | [diff] [blame] | 3742 | } |
| Tamas Berghammer | 963ce48 | 2017-08-25 13:56:14 +0000 | [diff] [blame] | 3743 | |
| 3744 | SymbolFileDWARFDwp *SymbolFileDWARF::GetDwpSymbolFile() { |
| 3745 | llvm::call_once(m_dwp_symfile_once_flag, [this]() { |
| Alexander Shaposhnikov | 64b4bcf | 2017-10-10 23:28:34 +0000 | [diff] [blame] | 3746 | ModuleSpec module_spec; |
| 3747 | module_spec.GetFileSpec() = m_obj_file->GetFileSpec(); |
| 3748 | module_spec.GetSymbolFileSpec() = |
| Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 3749 | FileSpec(m_obj_file->GetFileSpec().GetPath() + ".dwp"); |
| Zachary Turner | a89ce43 | 2019-03-06 18:20:23 +0000 | [diff] [blame] | 3750 | |
| 3751 | FileSpecList search_paths = Target::GetDefaultDebugFileSearchPaths(); |
| 3752 | FileSpec dwp_filespec = |
| 3753 | Symbols::LocateExecutableSymbolFile(module_spec, search_paths); |
| Jonas Devlieghere | dbd7fab | 2018-11-01 17:09:25 +0000 | [diff] [blame] | 3754 | if (FileSystem::Instance().Exists(dwp_filespec)) { |
| Tamas Berghammer | 963ce48 | 2017-08-25 13:56:14 +0000 | [diff] [blame] | 3755 | m_dwp_symfile = SymbolFileDWARFDwp::Create(GetObjectFile()->GetModule(), |
| 3756 | dwp_filespec); |
| 3757 | } |
| 3758 | }); |
| 3759 | return m_dwp_symfile.get(); |
| 3760 | } |