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