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