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