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