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