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