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" |
Zachary Turner | 6f9e690 | 2017-03-03 20:56:28 +0000 | [diff] [blame] | 19 | #include "lldb/Utility/Log.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | |
| 21 | using namespace lldb; |
| 22 | using namespace lldb_private; |
| 23 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 24 | SBCompileUnit::SBCompileUnit() : m_opaque_ptr(NULL) { |
| 25 | LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBCompileUnit); |
| 26 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 27 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 28 | SBCompileUnit::SBCompileUnit(lldb_private::CompileUnit *lldb_object_ptr) |
| 29 | : m_opaque_ptr(lldb_object_ptr) {} |
| 30 | |
| 31 | SBCompileUnit::SBCompileUnit(const SBCompileUnit &rhs) |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 32 | : m_opaque_ptr(rhs.m_opaque_ptr) { |
| 33 | LLDB_RECORD_CONSTRUCTOR(SBCompileUnit, (const lldb::SBCompileUnit &), rhs); |
| 34 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 35 | |
| 36 | const SBCompileUnit &SBCompileUnit::operator=(const SBCompileUnit &rhs) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 37 | LLDB_RECORD_METHOD(const lldb::SBCompileUnit &, |
| 38 | SBCompileUnit, operator=,(const lldb::SBCompileUnit &), |
| 39 | rhs); |
| 40 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 41 | m_opaque_ptr = rhs.m_opaque_ptr; |
| 42 | return *this; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 45 | SBCompileUnit::~SBCompileUnit() { m_opaque_ptr = NULL; } |
| 46 | |
| 47 | SBFileSpec SBCompileUnit::GetFileSpec() const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 48 | LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBFileSpec, SBCompileUnit, |
| 49 | GetFileSpec); |
| 50 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 51 | SBFileSpec file_spec; |
| 52 | if (m_opaque_ptr) |
| 53 | file_spec.SetFileSpec(*m_opaque_ptr); |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 54 | return LLDB_RECORD_RESULT(file_spec); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 57 | uint32_t SBCompileUnit::GetNumLineEntries() const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 58 | LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBCompileUnit, GetNumLineEntries); |
| 59 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 60 | if (m_opaque_ptr) { |
| 61 | LineTable *line_table = m_opaque_ptr->GetLineTable(); |
Jason Molenda | f228b2c | 2019-03-05 22:17:47 +0000 | [diff] [blame] | 62 | if (line_table) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 63 | return line_table->GetSize(); |
| 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 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Greg Clayton | efabb12 | 2010-11-05 23:17:00 +0000 | [diff] [blame] | 73 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 74 | SBLineEntry sb_line_entry; |
| 75 | if (m_opaque_ptr) { |
| 76 | LineTable *line_table = m_opaque_ptr->GetLineTable(); |
| 77 | if (line_table) { |
| 78 | LineEntry line_entry; |
| 79 | if (line_table->GetLineEntryAtIndex(idx, line_entry)) |
| 80 | sb_line_entry.SetLineEntry(line_entry); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 81 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | if (log) { |
| 85 | SBStream sstr; |
| 86 | sb_line_entry.GetDescription(sstr); |
| 87 | log->Printf("SBCompileUnit(%p)::GetLineEntryAtIndex (idx=%u) => " |
| 88 | "SBLineEntry(%p): '%s'", |
| 89 | static_cast<void *>(m_opaque_ptr), idx, |
| 90 | static_cast<void *>(sb_line_entry.get()), sstr.GetData()); |
| 91 | } |
| 92 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 93 | return LLDB_RECORD_RESULT(sb_line_entry); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 96 | uint32_t SBCompileUnit::FindLineEntryIndex(uint32_t start_idx, uint32_t line, |
| 97 | SBFileSpec *inline_file_spec) 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 *), start_idx, |
| 100 | line, inline_file_spec); |
| 101 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 102 | const bool exact = true; |
| 103 | return FindLineEntryIndex(start_idx, line, inline_file_spec, exact); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 106 | uint32_t SBCompileUnit::FindLineEntryIndex(uint32_t start_idx, uint32_t line, |
| 107 | SBFileSpec *inline_file_spec, |
| 108 | bool exact) const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 109 | LLDB_RECORD_METHOD_CONST(uint32_t, SBCompileUnit, FindLineEntryIndex, |
| 110 | (uint32_t, uint32_t, lldb::SBFileSpec *, bool), |
| 111 | start_idx, line, inline_file_spec, exact); |
| 112 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 113 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 114 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 115 | uint32_t index = UINT32_MAX; |
| 116 | if (m_opaque_ptr) { |
| 117 | FileSpec file_spec; |
| 118 | if (inline_file_spec && inline_file_spec->IsValid()) |
| 119 | file_spec = inline_file_spec->ref(); |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 120 | else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 121 | file_spec = *m_opaque_ptr; |
| 122 | |
| 123 | index = m_opaque_ptr->FindLineEntry( |
| 124 | start_idx, line, inline_file_spec ? inline_file_spec->get() : NULL, |
| 125 | exact, NULL); |
| 126 | } |
| 127 | |
| 128 | if (log) { |
| 129 | SBStream sstr; |
| 130 | if (index == UINT32_MAX) { |
| 131 | log->Printf("SBCompileUnit(%p)::FindLineEntryIndex (start_idx=%u, " |
| 132 | "line=%u, SBFileSpec(%p)) => NOT FOUND", |
| 133 | static_cast<void *>(m_opaque_ptr), start_idx, line, |
| 134 | inline_file_spec |
| 135 | ? static_cast<const void *>(inline_file_spec->get()) |
| 136 | : NULL); |
| 137 | } else { |
| 138 | log->Printf("SBCompileUnit(%p)::FindLineEntryIndex (start_idx=%u, " |
| 139 | "line=%u, SBFileSpec(%p)) => %u", |
| 140 | static_cast<void *>(m_opaque_ptr), start_idx, line, |
| 141 | inline_file_spec |
| 142 | ? static_cast<const void *>(inline_file_spec->get()) |
| 143 | : NULL, |
| 144 | index); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | return index; |
| 149 | } |
| 150 | |
| 151 | uint32_t SBCompileUnit::GetNumSupportFiles() const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 152 | LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBCompileUnit, GetNumSupportFiles); |
| 153 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 154 | if (m_opaque_ptr) { |
| 155 | FileSpecList &support_files = m_opaque_ptr->GetSupportFiles(); |
| 156 | return support_files.GetSize(); |
| 157 | } |
| 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | lldb::SBTypeList SBCompileUnit::GetTypes(uint32_t type_mask) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 162 | LLDB_RECORD_METHOD(lldb::SBTypeList, SBCompileUnit, GetTypes, (uint32_t), |
| 163 | type_mask); |
| 164 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 165 | SBTypeList sb_type_list; |
| 166 | |
Zachary Turner | 117b1fa | 2018-10-25 20:45:40 +0000 | [diff] [blame] | 167 | if (!m_opaque_ptr) |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 168 | return LLDB_RECORD_RESULT(sb_type_list); |
Zachary Turner | 117b1fa | 2018-10-25 20:45:40 +0000 | [diff] [blame] | 169 | |
| 170 | ModuleSP module_sp(m_opaque_ptr->GetModule()); |
| 171 | if (!module_sp) |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 172 | return LLDB_RECORD_RESULT(sb_type_list); |
Zachary Turner | 117b1fa | 2018-10-25 20:45:40 +0000 | [diff] [blame] | 173 | |
| 174 | SymbolVendor *vendor = module_sp->GetSymbolVendor(); |
| 175 | if (!vendor) |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 176 | return LLDB_RECORD_RESULT(sb_type_list); |
Zachary Turner | 117b1fa | 2018-10-25 20:45:40 +0000 | [diff] [blame] | 177 | |
| 178 | TypeClass type_class = static_cast<TypeClass>(type_mask); |
| 179 | TypeList type_list; |
| 180 | vendor->GetTypes(m_opaque_ptr, type_class, type_list); |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 181 | sb_type_list.m_opaque_up->Append(type_list); |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 182 | return LLDB_RECORD_RESULT(sb_type_list); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | SBFileSpec SBCompileUnit::GetSupportFileAtIndex(uint32_t idx) const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 186 | LLDB_RECORD_METHOD_CONST(lldb::SBFileSpec, SBCompileUnit, |
| 187 | GetSupportFileAtIndex, (uint32_t), idx); |
| 188 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 189 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 190 | |
| 191 | SBFileSpec sb_file_spec; |
| 192 | if (m_opaque_ptr) { |
| 193 | FileSpecList &support_files = m_opaque_ptr->GetSupportFiles(); |
| 194 | FileSpec file_spec = support_files.GetFileSpecAtIndex(idx); |
| 195 | sb_file_spec.SetFileSpec(file_spec); |
| 196 | } |
| 197 | |
| 198 | if (log) { |
| 199 | SBStream sstr; |
| 200 | sb_file_spec.GetDescription(sstr); |
| 201 | log->Printf("SBCompileUnit(%p)::GetGetFileSpecAtIndex (idx=%u) => " |
| 202 | "SBFileSpec(%p): '%s'", |
| 203 | static_cast<void *>(m_opaque_ptr), idx, |
| 204 | static_cast<const void *>(sb_file_spec.get()), sstr.GetData()); |
| 205 | } |
| 206 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 207 | return LLDB_RECORD_RESULT(sb_file_spec); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | uint32_t SBCompileUnit::FindSupportFileIndex(uint32_t start_idx, |
| 211 | const SBFileSpec &sb_file, |
| 212 | bool full) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 213 | LLDB_RECORD_METHOD(uint32_t, SBCompileUnit, FindSupportFileIndex, |
| 214 | (uint32_t, const lldb::SBFileSpec &, bool), start_idx, |
| 215 | sb_file, full); |
| 216 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 217 | if (m_opaque_ptr) { |
| 218 | FileSpecList &support_files = m_opaque_ptr->GetSupportFiles(); |
| 219 | return support_files.FindFileIndex(start_idx, sb_file.ref(), full); |
| 220 | } |
| 221 | return 0; |
| 222 | } |
| 223 | |
| 224 | lldb::LanguageType SBCompileUnit::GetLanguage() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 225 | LLDB_RECORD_METHOD_NO_ARGS(lldb::LanguageType, SBCompileUnit, GetLanguage); |
| 226 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 227 | if (m_opaque_ptr) |
| 228 | return m_opaque_ptr->GetLanguage(); |
| 229 | return lldb::eLanguageTypeUnknown; |
| 230 | } |
| 231 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 232 | bool SBCompileUnit::IsValid() const { |
| 233 | LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCompileUnit, IsValid); |
| 234 | |
| 235 | return m_opaque_ptr != NULL; |
| 236 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 237 | |
| 238 | bool SBCompileUnit::operator==(const SBCompileUnit &rhs) const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 239 | LLDB_RECORD_METHOD_CONST( |
| 240 | bool, SBCompileUnit, operator==,(const lldb::SBCompileUnit &), rhs); |
| 241 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 242 | return m_opaque_ptr == rhs.m_opaque_ptr; |
| 243 | } |
| 244 | |
| 245 | bool SBCompileUnit::operator!=(const SBCompileUnit &rhs) const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 246 | LLDB_RECORD_METHOD_CONST( |
| 247 | bool, SBCompileUnit, operator!=,(const lldb::SBCompileUnit &), rhs); |
| 248 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 249 | return m_opaque_ptr != rhs.m_opaque_ptr; |
| 250 | } |
| 251 | |
| 252 | const lldb_private::CompileUnit *SBCompileUnit::operator->() const { |
| 253 | return m_opaque_ptr; |
| 254 | } |
| 255 | |
| 256 | const lldb_private::CompileUnit &SBCompileUnit::operator*() const { |
| 257 | return *m_opaque_ptr; |
| 258 | } |
| 259 | |
| 260 | lldb_private::CompileUnit *SBCompileUnit::get() { return m_opaque_ptr; } |
| 261 | |
| 262 | void SBCompileUnit::reset(lldb_private::CompileUnit *lldb_object_ptr) { |
| 263 | m_opaque_ptr = lldb_object_ptr; |
| 264 | } |
| 265 | |
| 266 | bool SBCompileUnit::GetDescription(SBStream &description) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 267 | LLDB_RECORD_METHOD(bool, SBCompileUnit, GetDescription, (lldb::SBStream &), |
| 268 | description); |
| 269 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 270 | Stream &strm = description.ref(); |
| 271 | |
| 272 | if (m_opaque_ptr) { |
| 273 | m_opaque_ptr->Dump(&strm, false); |
| 274 | } else |
| 275 | strm.PutCString("No value"); |
| 276 | |
| 277 | return true; |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 278 | } |