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" |
| 10 | #include "lldb/API/SBLineEntry.h" |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 11 | #include "lldb/API/SBStream.h" |
Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 12 | #include "lldb/Core/Module.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 13 | #include "lldb/Symbol/CompileUnit.h" |
| 14 | #include "lldb/Symbol/LineEntry.h" |
| 15 | #include "lldb/Symbol/LineTable.h" |
Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 16 | #include "lldb/Symbol/SymbolVendor.h" |
| 17 | #include "lldb/Symbol/Type.h" |
Zachary Turner | 6f9e690 | 2017-03-03 20:56:28 +0000 | [diff] [blame] | 18 | #include "lldb/Utility/Log.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | |
| 20 | using namespace lldb; |
| 21 | using namespace lldb_private; |
| 22 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 23 | SBCompileUnit::SBCompileUnit() : m_opaque_ptr(NULL) {} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 25 | SBCompileUnit::SBCompileUnit(lldb_private::CompileUnit *lldb_object_ptr) |
| 26 | : m_opaque_ptr(lldb_object_ptr) {} |
| 27 | |
| 28 | SBCompileUnit::SBCompileUnit(const SBCompileUnit &rhs) |
| 29 | : m_opaque_ptr(rhs.m_opaque_ptr) {} |
| 30 | |
| 31 | const SBCompileUnit &SBCompileUnit::operator=(const SBCompileUnit &rhs) { |
| 32 | m_opaque_ptr = rhs.m_opaque_ptr; |
| 33 | return *this; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 34 | } |
| 35 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 36 | SBCompileUnit::~SBCompileUnit() { m_opaque_ptr = NULL; } |
| 37 | |
| 38 | SBFileSpec SBCompileUnit::GetFileSpec() const { |
| 39 | SBFileSpec file_spec; |
| 40 | if (m_opaque_ptr) |
| 41 | file_spec.SetFileSpec(*m_opaque_ptr); |
| 42 | return file_spec; |
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 | uint32_t SBCompileUnit::GetNumLineEntries() const { |
| 46 | if (m_opaque_ptr) { |
| 47 | LineTable *line_table = m_opaque_ptr->GetLineTable(); |
| 48 | if (line_table) |
| 49 | return line_table->GetSize(); |
| 50 | } |
| 51 | return 0; |
Greg Clayton | efabb12 | 2010-11-05 23:17:00 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 54 | SBLineEntry SBCompileUnit::GetLineEntryAtIndex(uint32_t idx) const { |
| 55 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Greg Clayton | efabb12 | 2010-11-05 23:17:00 +0000 | [diff] [blame] | 56 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 57 | SBLineEntry sb_line_entry; |
| 58 | if (m_opaque_ptr) { |
| 59 | LineTable *line_table = m_opaque_ptr->GetLineTable(); |
| 60 | if (line_table) { |
| 61 | LineEntry line_entry; |
| 62 | if (line_table->GetLineEntryAtIndex(idx, line_entry)) |
| 63 | sb_line_entry.SetLineEntry(line_entry); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 64 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | if (log) { |
| 68 | SBStream sstr; |
| 69 | sb_line_entry.GetDescription(sstr); |
| 70 | log->Printf("SBCompileUnit(%p)::GetLineEntryAtIndex (idx=%u) => " |
| 71 | "SBLineEntry(%p): '%s'", |
| 72 | static_cast<void *>(m_opaque_ptr), idx, |
| 73 | static_cast<void *>(sb_line_entry.get()), sstr.GetData()); |
| 74 | } |
| 75 | |
| 76 | return sb_line_entry; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 77 | } |
| 78 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 79 | uint32_t SBCompileUnit::FindLineEntryIndex(uint32_t start_idx, uint32_t line, |
| 80 | SBFileSpec *inline_file_spec) const { |
| 81 | const bool exact = true; |
| 82 | return FindLineEntryIndex(start_idx, line, inline_file_spec, exact); |
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, |
| 87 | bool exact) const { |
| 88 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 89 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 90 | uint32_t index = UINT32_MAX; |
| 91 | if (m_opaque_ptr) { |
| 92 | FileSpec file_spec; |
| 93 | if (inline_file_spec && inline_file_spec->IsValid()) |
| 94 | file_spec = inline_file_spec->ref(); |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 95 | else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 96 | file_spec = *m_opaque_ptr; |
| 97 | |
| 98 | index = m_opaque_ptr->FindLineEntry( |
| 99 | start_idx, line, inline_file_spec ? inline_file_spec->get() : NULL, |
| 100 | exact, NULL); |
| 101 | } |
| 102 | |
| 103 | if (log) { |
| 104 | SBStream sstr; |
| 105 | if (index == UINT32_MAX) { |
| 106 | log->Printf("SBCompileUnit(%p)::FindLineEntryIndex (start_idx=%u, " |
| 107 | "line=%u, SBFileSpec(%p)) => NOT FOUND", |
| 108 | static_cast<void *>(m_opaque_ptr), start_idx, line, |
| 109 | inline_file_spec |
| 110 | ? static_cast<const void *>(inline_file_spec->get()) |
| 111 | : NULL); |
| 112 | } else { |
| 113 | log->Printf("SBCompileUnit(%p)::FindLineEntryIndex (start_idx=%u, " |
| 114 | "line=%u, SBFileSpec(%p)) => %u", |
| 115 | static_cast<void *>(m_opaque_ptr), start_idx, line, |
| 116 | inline_file_spec |
| 117 | ? static_cast<const void *>(inline_file_spec->get()) |
| 118 | : NULL, |
| 119 | index); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | return index; |
| 124 | } |
| 125 | |
| 126 | uint32_t SBCompileUnit::GetNumSupportFiles() const { |
| 127 | if (m_opaque_ptr) { |
| 128 | FileSpecList &support_files = m_opaque_ptr->GetSupportFiles(); |
| 129 | return support_files.GetSize(); |
| 130 | } |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | lldb::SBTypeList SBCompileUnit::GetTypes(uint32_t type_mask) { |
| 135 | SBTypeList sb_type_list; |
| 136 | |
Zachary Turner | 117b1fa | 2018-10-25 20:45:40 +0000 | [diff] [blame] | 137 | if (!m_opaque_ptr) |
| 138 | return sb_type_list; |
| 139 | |
| 140 | ModuleSP module_sp(m_opaque_ptr->GetModule()); |
| 141 | if (!module_sp) |
| 142 | return sb_type_list; |
| 143 | |
| 144 | SymbolVendor *vendor = module_sp->GetSymbolVendor(); |
| 145 | if (!vendor) |
| 146 | return sb_type_list; |
| 147 | |
| 148 | TypeClass type_class = static_cast<TypeClass>(type_mask); |
| 149 | TypeList type_list; |
| 150 | vendor->GetTypes(m_opaque_ptr, type_class, type_list); |
| 151 | sb_type_list.m_opaque_ap->Append(type_list); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 152 | return sb_type_list; |
| 153 | } |
| 154 | |
| 155 | SBFileSpec SBCompileUnit::GetSupportFileAtIndex(uint32_t idx) const { |
| 156 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 157 | |
| 158 | SBFileSpec sb_file_spec; |
| 159 | if (m_opaque_ptr) { |
| 160 | FileSpecList &support_files = m_opaque_ptr->GetSupportFiles(); |
| 161 | FileSpec file_spec = support_files.GetFileSpecAtIndex(idx); |
| 162 | sb_file_spec.SetFileSpec(file_spec); |
| 163 | } |
| 164 | |
| 165 | if (log) { |
| 166 | SBStream sstr; |
| 167 | sb_file_spec.GetDescription(sstr); |
| 168 | log->Printf("SBCompileUnit(%p)::GetGetFileSpecAtIndex (idx=%u) => " |
| 169 | "SBFileSpec(%p): '%s'", |
| 170 | static_cast<void *>(m_opaque_ptr), idx, |
| 171 | static_cast<const void *>(sb_file_spec.get()), sstr.GetData()); |
| 172 | } |
| 173 | |
| 174 | return sb_file_spec; |
| 175 | } |
| 176 | |
| 177 | uint32_t SBCompileUnit::FindSupportFileIndex(uint32_t start_idx, |
| 178 | const SBFileSpec &sb_file, |
| 179 | bool full) { |
| 180 | if (m_opaque_ptr) { |
| 181 | FileSpecList &support_files = m_opaque_ptr->GetSupportFiles(); |
| 182 | return support_files.FindFileIndex(start_idx, sb_file.ref(), full); |
| 183 | } |
| 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | lldb::LanguageType SBCompileUnit::GetLanguage() { |
| 188 | if (m_opaque_ptr) |
| 189 | return m_opaque_ptr->GetLanguage(); |
| 190 | return lldb::eLanguageTypeUnknown; |
| 191 | } |
| 192 | |
| 193 | bool SBCompileUnit::IsValid() const { return m_opaque_ptr != NULL; } |
| 194 | |
| 195 | bool SBCompileUnit::operator==(const SBCompileUnit &rhs) const { |
| 196 | return m_opaque_ptr == rhs.m_opaque_ptr; |
| 197 | } |
| 198 | |
| 199 | bool SBCompileUnit::operator!=(const SBCompileUnit &rhs) const { |
| 200 | return m_opaque_ptr != rhs.m_opaque_ptr; |
| 201 | } |
| 202 | |
| 203 | const lldb_private::CompileUnit *SBCompileUnit::operator->() const { |
| 204 | return m_opaque_ptr; |
| 205 | } |
| 206 | |
| 207 | const lldb_private::CompileUnit &SBCompileUnit::operator*() const { |
| 208 | return *m_opaque_ptr; |
| 209 | } |
| 210 | |
| 211 | lldb_private::CompileUnit *SBCompileUnit::get() { return m_opaque_ptr; } |
| 212 | |
| 213 | void SBCompileUnit::reset(lldb_private::CompileUnit *lldb_object_ptr) { |
| 214 | m_opaque_ptr = lldb_object_ptr; |
| 215 | } |
| 216 | |
| 217 | bool SBCompileUnit::GetDescription(SBStream &description) { |
| 218 | Stream &strm = description.ref(); |
| 219 | |
| 220 | if (m_opaque_ptr) { |
| 221 | m_opaque_ptr->Dump(&strm, false); |
| 222 | } else |
| 223 | strm.PutCString("No value"); |
| 224 | |
| 225 | return true; |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 226 | } |