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