Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- SBCompileUnit.cpp ---------------------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "lldb/API/SBCompileUnit.h" |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 10 | #include "SBReproducerPrivate.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 11 | #include "lldb/API/SBLineEntry.h" |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 12 | #include "lldb/API/SBStream.h" |
Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 13 | #include "lldb/Core/Module.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 14 | #include "lldb/Symbol/CompileUnit.h" |
| 15 | #include "lldb/Symbol/LineEntry.h" |
| 16 | #include "lldb/Symbol/LineTable.h" |
Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 17 | #include "lldb/Symbol/SymbolVendor.h" |
| 18 | #include "lldb/Symbol/Type.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | |
| 20 | using namespace lldb; |
| 21 | using namespace lldb_private; |
| 22 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 23 | SBCompileUnit::SBCompileUnit() : m_opaque_ptr(NULL) { |
| 24 | LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBCompileUnit); |
| 25 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 26 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 27 | SBCompileUnit::SBCompileUnit(lldb_private::CompileUnit *lldb_object_ptr) |
| 28 | : m_opaque_ptr(lldb_object_ptr) {} |
| 29 | |
| 30 | SBCompileUnit::SBCompileUnit(const SBCompileUnit &rhs) |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 31 | : m_opaque_ptr(rhs.m_opaque_ptr) { |
| 32 | LLDB_RECORD_CONSTRUCTOR(SBCompileUnit, (const lldb::SBCompileUnit &), rhs); |
| 33 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 34 | |
| 35 | const SBCompileUnit &SBCompileUnit::operator=(const SBCompileUnit &rhs) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 36 | LLDB_RECORD_METHOD(const lldb::SBCompileUnit &, |
| 37 | SBCompileUnit, operator=,(const lldb::SBCompileUnit &), |
| 38 | rhs); |
| 39 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 40 | m_opaque_ptr = rhs.m_opaque_ptr; |
| 41 | return *this; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 44 | SBCompileUnit::~SBCompileUnit() { m_opaque_ptr = NULL; } |
| 45 | |
| 46 | SBFileSpec SBCompileUnit::GetFileSpec() const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 47 | LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBFileSpec, SBCompileUnit, |
| 48 | GetFileSpec); |
| 49 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 50 | SBFileSpec file_spec; |
| 51 | if (m_opaque_ptr) |
| 52 | file_spec.SetFileSpec(*m_opaque_ptr); |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 53 | return LLDB_RECORD_RESULT(file_spec); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 56 | uint32_t SBCompileUnit::GetNumLineEntries() const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 57 | LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBCompileUnit, GetNumLineEntries); |
| 58 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 59 | if (m_opaque_ptr) { |
| 60 | LineTable *line_table = m_opaque_ptr->GetLineTable(); |
Jason Molenda | b459f18 | 2019-03-06 02:32:45 +0000 | [diff] [blame] | 61 | if (line_table) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 62 | return line_table->GetSize(); |
Jason Molenda | b459f18 | 2019-03-06 02:32:45 +0000 | [diff] [blame] | 63 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 64 | } |
| 65 | return 0; |
Greg Clayton | efabb12 | 2010-11-05 23:17:00 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 68 | SBLineEntry SBCompileUnit::GetLineEntryAtIndex(uint32_t idx) const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 69 | LLDB_RECORD_METHOD_CONST(lldb::SBLineEntry, SBCompileUnit, |
| 70 | GetLineEntryAtIndex, (uint32_t), idx); |
| 71 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 72 | SBLineEntry sb_line_entry; |
| 73 | if (m_opaque_ptr) { |
| 74 | LineTable *line_table = m_opaque_ptr->GetLineTable(); |
| 75 | if (line_table) { |
| 76 | LineEntry line_entry; |
| 77 | if (line_table->GetLineEntryAtIndex(idx, line_entry)) |
| 78 | sb_line_entry.SetLineEntry(line_entry); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 79 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 82 | return LLDB_RECORD_RESULT(sb_line_entry); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 85 | uint32_t SBCompileUnit::FindLineEntryIndex(uint32_t start_idx, uint32_t line, |
| 86 | SBFileSpec *inline_file_spec) const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 87 | LLDB_RECORD_METHOD_CONST(uint32_t, SBCompileUnit, FindLineEntryIndex, |
| 88 | (uint32_t, uint32_t, lldb::SBFileSpec *), start_idx, |
| 89 | line, inline_file_spec); |
| 90 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 91 | const bool exact = true; |
| 92 | return FindLineEntryIndex(start_idx, line, inline_file_spec, exact); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 95 | uint32_t SBCompileUnit::FindLineEntryIndex(uint32_t start_idx, uint32_t line, |
| 96 | SBFileSpec *inline_file_spec, |
| 97 | bool exact) const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 98 | LLDB_RECORD_METHOD_CONST(uint32_t, SBCompileUnit, FindLineEntryIndex, |
| 99 | (uint32_t, uint32_t, lldb::SBFileSpec *, bool), |
| 100 | start_idx, line, inline_file_spec, exact); |
| 101 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 102 | uint32_t index = UINT32_MAX; |
| 103 | if (m_opaque_ptr) { |
| 104 | FileSpec file_spec; |
| 105 | if (inline_file_spec && inline_file_spec->IsValid()) |
| 106 | file_spec = inline_file_spec->ref(); |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 107 | else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 108 | file_spec = *m_opaque_ptr; |
| 109 | |
| 110 | index = m_opaque_ptr->FindLineEntry( |
| 111 | start_idx, line, inline_file_spec ? inline_file_spec->get() : NULL, |
| 112 | exact, NULL); |
| 113 | } |
| 114 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 115 | return index; |
| 116 | } |
| 117 | |
| 118 | uint32_t SBCompileUnit::GetNumSupportFiles() const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 119 | LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBCompileUnit, GetNumSupportFiles); |
| 120 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 121 | if (m_opaque_ptr) { |
| 122 | FileSpecList &support_files = m_opaque_ptr->GetSupportFiles(); |
| 123 | return support_files.GetSize(); |
| 124 | } |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | lldb::SBTypeList SBCompileUnit::GetTypes(uint32_t type_mask) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 129 | LLDB_RECORD_METHOD(lldb::SBTypeList, SBCompileUnit, GetTypes, (uint32_t), |
| 130 | type_mask); |
| 131 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 132 | SBTypeList sb_type_list; |
| 133 | |
Zachary Turner | 117b1fa | 2018-10-25 20:45:40 +0000 | [diff] [blame] | 134 | if (!m_opaque_ptr) |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 135 | return LLDB_RECORD_RESULT(sb_type_list); |
Zachary Turner | 117b1fa | 2018-10-25 20:45:40 +0000 | [diff] [blame] | 136 | |
| 137 | ModuleSP module_sp(m_opaque_ptr->GetModule()); |
| 138 | if (!module_sp) |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 139 | return LLDB_RECORD_RESULT(sb_type_list); |
Zachary Turner | 117b1fa | 2018-10-25 20:45:40 +0000 | [diff] [blame] | 140 | |
| 141 | SymbolVendor *vendor = module_sp->GetSymbolVendor(); |
| 142 | if (!vendor) |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 143 | return LLDB_RECORD_RESULT(sb_type_list); |
Zachary Turner | 117b1fa | 2018-10-25 20:45:40 +0000 | [diff] [blame] | 144 | |
| 145 | TypeClass type_class = static_cast<TypeClass>(type_mask); |
| 146 | TypeList type_list; |
| 147 | vendor->GetTypes(m_opaque_ptr, type_class, type_list); |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 148 | sb_type_list.m_opaque_up->Append(type_list); |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 149 | return LLDB_RECORD_RESULT(sb_type_list); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | SBFileSpec SBCompileUnit::GetSupportFileAtIndex(uint32_t idx) const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 153 | LLDB_RECORD_METHOD_CONST(lldb::SBFileSpec, SBCompileUnit, |
| 154 | GetSupportFileAtIndex, (uint32_t), idx); |
| 155 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 156 | SBFileSpec sb_file_spec; |
| 157 | if (m_opaque_ptr) { |
| 158 | FileSpecList &support_files = m_opaque_ptr->GetSupportFiles(); |
| 159 | FileSpec file_spec = support_files.GetFileSpecAtIndex(idx); |
| 160 | sb_file_spec.SetFileSpec(file_spec); |
| 161 | } |
| 162 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 163 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 164 | return LLDB_RECORD_RESULT(sb_file_spec); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | uint32_t SBCompileUnit::FindSupportFileIndex(uint32_t start_idx, |
| 168 | const SBFileSpec &sb_file, |
| 169 | bool full) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 170 | LLDB_RECORD_METHOD(uint32_t, SBCompileUnit, FindSupportFileIndex, |
| 171 | (uint32_t, const lldb::SBFileSpec &, bool), start_idx, |
| 172 | sb_file, full); |
| 173 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 174 | if (m_opaque_ptr) { |
| 175 | FileSpecList &support_files = m_opaque_ptr->GetSupportFiles(); |
| 176 | return support_files.FindFileIndex(start_idx, sb_file.ref(), full); |
| 177 | } |
| 178 | return 0; |
| 179 | } |
| 180 | |
| 181 | lldb::LanguageType SBCompileUnit::GetLanguage() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 182 | LLDB_RECORD_METHOD_NO_ARGS(lldb::LanguageType, SBCompileUnit, GetLanguage); |
| 183 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 184 | if (m_opaque_ptr) |
| 185 | return m_opaque_ptr->GetLanguage(); |
| 186 | return lldb::eLanguageTypeUnknown; |
| 187 | } |
| 188 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 189 | bool SBCompileUnit::IsValid() const { |
| 190 | LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCompileUnit, IsValid); |
Pavel Labath | 7f5237b | 2019-03-11 13:58:46 +0000 | [diff] [blame] | 191 | return this->operator bool(); |
| 192 | } |
| 193 | SBCompileUnit::operator bool() const { |
| 194 | LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCompileUnit, operator bool); |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 195 | |
| 196 | return m_opaque_ptr != NULL; |
| 197 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 198 | |
| 199 | bool SBCompileUnit::operator==(const SBCompileUnit &rhs) const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 200 | LLDB_RECORD_METHOD_CONST( |
| 201 | bool, SBCompileUnit, operator==,(const lldb::SBCompileUnit &), rhs); |
| 202 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 203 | return m_opaque_ptr == rhs.m_opaque_ptr; |
| 204 | } |
| 205 | |
| 206 | bool SBCompileUnit::operator!=(const SBCompileUnit &rhs) const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 207 | LLDB_RECORD_METHOD_CONST( |
| 208 | bool, SBCompileUnit, operator!=,(const lldb::SBCompileUnit &), rhs); |
| 209 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 210 | return m_opaque_ptr != rhs.m_opaque_ptr; |
| 211 | } |
| 212 | |
| 213 | const lldb_private::CompileUnit *SBCompileUnit::operator->() const { |
| 214 | return m_opaque_ptr; |
| 215 | } |
| 216 | |
| 217 | const lldb_private::CompileUnit &SBCompileUnit::operator*() const { |
| 218 | return *m_opaque_ptr; |
| 219 | } |
| 220 | |
| 221 | lldb_private::CompileUnit *SBCompileUnit::get() { return m_opaque_ptr; } |
| 222 | |
| 223 | void SBCompileUnit::reset(lldb_private::CompileUnit *lldb_object_ptr) { |
| 224 | m_opaque_ptr = lldb_object_ptr; |
| 225 | } |
| 226 | |
| 227 | bool SBCompileUnit::GetDescription(SBStream &description) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 228 | LLDB_RECORD_METHOD(bool, SBCompileUnit, GetDescription, (lldb::SBStream &), |
| 229 | description); |
| 230 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 231 | Stream &strm = description.ref(); |
| 232 | |
| 233 | if (m_opaque_ptr) { |
| 234 | m_opaque_ptr->Dump(&strm, false); |
| 235 | } else |
| 236 | strm.PutCString("No value"); |
| 237 | |
| 238 | return true; |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 239 | } |
Michal Gorny | ae211ec | 2019-03-19 17:13:13 +0000 | [diff] [blame] | 240 | |
| 241 | namespace lldb_private { |
| 242 | namespace repro { |
| 243 | |
| 244 | template <> |
| 245 | void RegisterMethods<SBCompileUnit>(Registry &R) { |
| 246 | LLDB_REGISTER_CONSTRUCTOR(SBCompileUnit, ()); |
| 247 | LLDB_REGISTER_CONSTRUCTOR(SBCompileUnit, (const lldb::SBCompileUnit &)); |
| 248 | LLDB_REGISTER_METHOD( |
| 249 | const lldb::SBCompileUnit &, |
| 250 | SBCompileUnit, operator=,(const lldb::SBCompileUnit &)); |
| 251 | LLDB_REGISTER_METHOD_CONST(lldb::SBFileSpec, SBCompileUnit, GetFileSpec, |
| 252 | ()); |
| 253 | LLDB_REGISTER_METHOD_CONST(uint32_t, SBCompileUnit, GetNumLineEntries, ()); |
| 254 | LLDB_REGISTER_METHOD_CONST(lldb::SBLineEntry, SBCompileUnit, |
| 255 | GetLineEntryAtIndex, (uint32_t)); |
| 256 | LLDB_REGISTER_METHOD_CONST(uint32_t, SBCompileUnit, FindLineEntryIndex, |
| 257 | (uint32_t, uint32_t, lldb::SBFileSpec *)); |
| 258 | LLDB_REGISTER_METHOD_CONST(uint32_t, SBCompileUnit, FindLineEntryIndex, |
| 259 | (uint32_t, uint32_t, lldb::SBFileSpec *, bool)); |
| 260 | LLDB_REGISTER_METHOD_CONST(uint32_t, SBCompileUnit, GetNumSupportFiles, ()); |
| 261 | LLDB_REGISTER_METHOD(lldb::SBTypeList, SBCompileUnit, GetTypes, (uint32_t)); |
| 262 | LLDB_REGISTER_METHOD_CONST(lldb::SBFileSpec, SBCompileUnit, |
| 263 | GetSupportFileAtIndex, (uint32_t)); |
| 264 | LLDB_REGISTER_METHOD(uint32_t, SBCompileUnit, FindSupportFileIndex, |
| 265 | (uint32_t, const lldb::SBFileSpec &, bool)); |
| 266 | LLDB_REGISTER_METHOD(lldb::LanguageType, SBCompileUnit, GetLanguage, ()); |
| 267 | LLDB_REGISTER_METHOD_CONST(bool, SBCompileUnit, IsValid, ()); |
| 268 | LLDB_REGISTER_METHOD_CONST(bool, SBCompileUnit, operator bool, ()); |
| 269 | LLDB_REGISTER_METHOD_CONST( |
| 270 | bool, SBCompileUnit, operator==,(const lldb::SBCompileUnit &)); |
| 271 | LLDB_REGISTER_METHOD_CONST( |
| 272 | bool, SBCompileUnit, operator!=,(const lldb::SBCompileUnit &)); |
| 273 | LLDB_REGISTER_METHOD(bool, SBCompileUnit, GetDescription, |
| 274 | (lldb::SBStream &)); |
| 275 | } |
| 276 | |
| 277 | } |
| 278 | } |