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