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