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